From RTSC-Pedia

Jump to: navigation, search
revision tip
—— LANDSCAPE orientation
[printable version]  offline version generated on 04-Aug-2010 21:08 UTC

ROV Module Writers Guide/Full Examples

Complete examples to test or use as templates

Full Examples

Basic Example

This example demonstrates the most basic features of ROV. Your initial ROV view should be no more complicated than this one.

ModA.xdc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
module ModA {
    metaonly struct BasicView {
        String label;
        Int count;
        Boolean working;
    };
 
    @Facet
    metaonly config ViewInfo.Instance rovViewInfo = 
        ViewInfo.create({
            viewMap: [
                ['Basic', {type: ViewInfo.INSTANCE, viewInitFxn: 'viewInitBasic', structName: 'BasicView'}],
            ]
        });
 
internal:
 
    struct Instance_State {
        UInt16 count;
        Boolean flag;
    };
}


ModA.xs
 
 
 
 
 
 
 
 
 
 
 
 
 
function viewInitBasic (view, obj) {
    var Program = xdc.useModule('xdc.rov.Program');
 
    view.label = Program.getShortName(obj.$label);
    view.count = obj.count;
 
    /* Validate count value */
    if (obj.count > 3) {
        Program.displayError(view, "count", "Error: Count should never be larger than 3.");
    }
 
    view.working = obj.flag;
}

Intermediate Example

This example uses ModA from the Basic Example.

ModB.xdc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
module ModB {
    struct Message {
        UInt16 id;
        String msg;
    };
 
    metaonly struct BasicView {
        String label;
        String messages[];
        Int numSenders;
    };
 
    @Facet
    metaonly config ViewInfo.Instance rovViewInfo = 
        ViewInfo.create({
            viewMap: [
                ['Basic', {type: ViewInfo.INSTANCE, viewInitFxn: 'viewInitBasic', structName: 'BasicView'}]
            ]
        });
 
internal:
 
    struct Instance_State {
        UInt16 numMsgs;
        Message messages[];
        ModA.Handle modAInst;
    };
}


ModB.xs
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
function viewInitBasic (view, obj) {
    view.label = Program.getShortName(obj.$label);
 
    /* Fetch the messages array. */
    try {
        var msgArr = Program.fetchArray(obj.messages$fetchDesc, obj.messages, obj.numMsgs);
    }
    catch (e) {
        Program.displayError(view, "messages", "Error: Problem reading messages array: " + e);
        return;
    }
 
    /* Fetch the message string from each message */
    for each (var msgStruct in msgArr) {
        try {
            var message = Program.fetchString(msgStruct.msg);
        }
        catch (e) {
            Program.displayError(view, "messages", "Error: Problem fetching message: " + e);
            return;
        }
 
        /* Add the message string to the view's messages array. */
        view.messages.$add("(" + msgStruct.id + ") " + message);
    }
 
    /* Get the value for numSenders from the ModA handle */
    var modAView = Program.scanHandleView('ModA', obj.modAInst);
    view.numSenders = modAView.count;
}


Views
Personal tools
package reference