sys::Obj sys::Virtual sys::Component sys::App
public class App
[palette=false, niagaraIcon="module://icons/x16/database.png"]
App encapsulates an application database which includes the list of available Types, the Component instances, their configuration, and the Links.
public inline property Buf appName [asStr, config, max=16]
Name of the app, up to 15 ASCII chars long
public Component[] comps
List of application component indexed by id (may be sparse with null items).
public int compsLen
Size of the components array
public long cycleCount
This counter is incremented at the start of each engine cycle
public inline property Buf deviceName [asStr, config, max=16]
Logical name for the device, up to 15 ASCII chars long
public property int guardTime [config, unit="millisecond"]
Time before the end of the scan period in which no new services work should be started in order to allow work in progress to finish before the end of scan.
public property bool hibernationResetsSteadyState [config]
If true, when the App returns from hibernation then the steady state will be reset and the App will not return to steady state until timeToSteadyState has elapsed.
public int[] kitIdMap
public long lastEndWork
Timestamp of end of service's work (also start of sleep time). This timestamp corresponds to the PREVIOUS scan.
lastEndWork - lastStartWork = work time of previous scan
public long lastStartExec
Cache of the timestamp of the start of the component tree execution of the PREVIOUS scan. It is intended that that timing statistics to be computed within the execute method of a component dropped into the component tree, so we need to cache the start of the last component tree execution. Also marks the time that sleep ends on previous scan.
lastStartWork - lastStartExec = execution time of previous scan
public long lastStartWork
Timestamp of start of service work (also marks the end of component tree execution). If timing statistics computed during component tree execution, this timestamp corresponds to the PREVIOUS scan.
lastEndWork - lastStartWork = work time of previous scan
public static const define Log log
Application level logging
public long newStartExec
End of previous scan sleep time is also the start of a new component tree execution This marks start of he CURRENT scan, such that:
newStartExec - lastStartExec = scan time of PREVIOUS scan
public PlatformService platform
PlatformService installed in this application
public property int scanPeriod [config, unit="millisecond"]
Scan cycle period in milliseconds.
public Service services
Linked list of services
public property int timeToSteadyState [config, unit="millisecond"]
Time from app start to steady state, in milliseconds.
public inline Watch[] watches
This array references the active watches by referencing the application specific subclasses currently open.
public Component add(Component parent, Str name, Type t)
Add a component to the application. Return the new Component on success, null on failure.
public Link addLink(Component from, Slot fromSlot, Component to, Slot toSlot)
Add a new Link into the application by registering it in both the "to" and "from" component's linked-list of Links. Return the new Link or null on error.
public void cleanupApp()
Free all the dynamic memory associated with this application.
public void closeWatch(Watch watch)
Close the specific watch by freeing its id to be used again and setting its closed field to false.
public Component getFirstChildOfType(Component parent, Type t)
Gets first child component of a given type. Returns null if no objects found, otherwise returns a Component
public Component getNextSiblingOfType(Component component, Type t)
Gets next sibling of a component that is of type t. Returns null if end of sibling list is reached without finding one.
public action void hibernate() [confirmRequired]
Action to request hibernation. Current execute loop will complete and all services will get a chance to work before hibernation occurs
public bool initApp(int initCompsLen)
Prepare the applications data structures to begin configuration.
public void initWatches(Watch[] subclasses)
Each service which uses watches, should call this method on startup with it's service specific array of Watch subclasses.
public bool isRunning()
Is the application currently running
public bool isSteadyState()
Has the application reached steady state (as defined by timeToSteadyState)
public int load()
Load the application from persistent storage
public int loadApp(InStream in)
Load the app from a binary format input stream. Return 0 on success or non-zero on error.
public bool loadSchema(InStream in)
Check that the schema on the input stream matches the schema of the current runtime.
In this version, we allow the app to depend on fewer kits than the scode, as long as all the app's kits are in the scode.
public Component lookup(int id)
Lookup a component by id or null.
public Link lookupLink(int fromCompId, int fromSlotId, int toCompId, int toSlotId)
Find a link with the specified from and to ids or return null if not found.
public Service lookupService(Type type)
Lookup a service by type (or base type). Return null if there are no registered services which implement the specified type.
public int maxId()
Get the maximum component id used by the application.
public Watch openWatch(Watch[] subclasses)
Allocate a watch for a service using watches. The service should pass in its service specific array of Watch subclasses. If a watch is opened then it is reserved, its closed field is set to false, and the subclass instance is returned. If all the watches are currently open, then return null.
public action void quit() [confirmRequired]
Save the application and then exit the main loop.
public action void reboot() [confirmRequired]
Action to invoke Platform.reboot.
public bool remove(Component c)
Remove the specified component and free it's memory. This method automatically recursively removes any children of the component first. Return true on success, false on failure.
public bool removeLink(Link link)
Remove a Link from the application by unregistering it from both the "to" and "from" component's list linked of Links. Return true on success, false on failure.
public action void restart() [confirmRequired]
Action to invoke Platform.restart.
public int resumeApp()
Run this application - right now this is a simple round robin execution.
public int runApp()
Run this application - right now this is a simple round robin execution.
public action void save()
Save the application back to persistent storage
public int saveApp(OutStream out)
Save the app in binary format to the output stream:
app { u4 magic 0x73617070 "sapp" u4 version 0x0002 0.2 Schema schema Component[] comps u2 0xffff end of comps marker Link[] links u2 0xffff end of links marker u1 '.' end of app marker }
Return 0 on success, non-zero on failure.
public void saveSchema(OutStream out)
Schema is the list of kit names and checksums:
schema { u1 count kits[count] { str name u4 checksum } }
public int startApp(Str[] args, int argsLen)
Start all the components. Return 0 on success, error code on failure.
public void stopApp()
Stop all the components.