Xm XPCOM interface

Description

The XPCOM interface provides attributes and methods that can be used in JavaScript code in Mozilla.

Attributes

errorInfo

readonly attribute string errorInfo

Holds an informative error message. If no error is present, errorInfo string value is "No error".

errorState

readonly attribute boolean errorState

Get error state of Xm component and loaded machine. Returns false if no error is present, true if an error has occured. Additional error information can be read from attribute errorInfo.

version

readonly attribute string version

Attribute value is a string with component version information. It also shows the number of instances of the Xm component object in sqare brackets.

// Get version and instance counter information.
str= xm.version;
dump (str);
Xm 0.7.1d for GRE 1.6 (2004-02-02) [1]
Meaning: Xm version 0.7.1, compiled with debugging code, compiled for Gecko runtime engine version 1.6 on (date), currently 1 active instance of Xm.

Methods

build

boolean build(in string aFilename)

Loads a machine description file aFilename and builds the machine.
Returns error state: false, if no error occured, otherwise true.

// Get XPCOM interface of Xm component
var XmComp= new Components.Constructor("@arxio.de/cpp_xm;1", "xmi");

// Create Xm interface object
var xm = new XmComp();

// Load machine description file, build up machine
if (xm.build("flipflops.xml")) {
    // display error message
    alert("Error: " + xm.errorInfo);
}

getAttribute

string getAttribute(in string aId, in string aAttName)

Get value of attribute aAttName of element aId.

getBoolean

boolean getBoolean(in string aId, in string aConnId)

Get boolean value of output connector aConnId of of element aId. If the output connector is not of type boolean, the value is casted.

getDouble

double getDouble(in string aId, in string aConnId)

Get double value of output connector aConnId of of element aId. If the output connector is not of type double, the value is casted. (Double type is 64bit floating point).

getInteger

long getInteger(in string aId, in string aConnId)

Get integer value of output connector aConnId of of element aId. If the output connector is not of type integer, the value is casted. (Integer type is 32bit integer).

getString

string getString(in string aId, in string aConnId)

Get string value of output connector aConnId of of element aId. If the output connector is not of type string, the value is casted. (String type is 8 bit char).

process

boolean process()

Perform one process cycle in the virtual machine. All machine elements are evaluated and their output connectors updated with new values.
Returns error state: false, if no error occured, otherwise true.

For very simple state machines, process() is called once after setting the values of the inports. Normally, process() is placed in a function called repeatedley.

// Call a function like this repeatedley to run the machine
// Global variable 'gXm' is the Xm interface object.
function xmProcess() 
{ 
    // Process machine cycle
    if (gXm.process()) {
        alert("Error: " + gXm.errorInfo);
        return;
    }
    
    // Get element output values and update machine GUI accordingly
    state= gXm.getInteger("elementOne", "out");
    gDecks[1].selectedIndex= state;
    
    // Get more output values ...
}     

setAttribute

void setAttribute(in string aId, in string aAttName, in string aValue)

Set value of attribute aAttName of element aId to aValue. If the attribute type is boolean, double or integer, aValue is parsed according to expected content.

setBoolean

void setBoolean(in string aId, in boolean aValue)

Set value of element aId to aValue. The element must be a port, normally logInport. If other ports are addressed, aValue is casted.

setDouble

void setDouble(in string aId, in double aValue)

Set value of element aId to aValue. The element must be a port, normally numInport. If other ports are addressed, aValue is casted.

setInteger

void setInteger(in string aId, in double aValue)

Set value of element aId to aValue. The element must be a port, normally numInport. If other ports are addressed, aValue is casted.

setString

void setString(in string aId, in double aValue)

Set value of element aId to aValue. The element must be a port, normally strInport. If other ports are addressed, aValue is parsed according to expected content.