21.08.2013 Views

A State-Based Programming Model for Wireless Sensor Networks

A State-Based Programming Model for Wireless Sensor Networks

A State-Based Programming Model for Wireless Sensor Networks

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

106 Chapter 6. Implementation<br />

state definition may be substituted using the incarnate keyword followed by<br />

the name of the actual state declaration. In order to adapt the actual state definition<br />

to the program context of its incarnation, a number of name-substitutions<br />

and additions can be made to the original declaration in the incarnation statement.<br />

The full declaration of a state incarnation has the following <strong>for</strong>m (where<br />

S is the name of the state incarnation, and I is the state to be incarnated):<br />

state S incarnate I (name substitutions) {<br />

additional entry actions<br />

additional transitions<br />

additional preemption actions<br />

}<br />

Additionally, state definitions may be marked with the template keyword<br />

in order to denote that the definition is not a complete program but instead is a<br />

template definition meant <strong>for</strong> incarnation elsewhere in the program. Though not<br />

strictly required, state templates should specify their complete interface including<br />

variables, events, and actions. The example Prog. 6.4 shows the definition<br />

of a template state I (lines 1-9) and its incarnation as a direct substate of the<br />

top-level state P ROG_4 (lines 14-19). Additionally, P ROG_2 (which we have<br />

defined previously in Prog 6.2) is also inserted as a direct substate of P ROG_4<br />

(lines 21-26). We will use this example to explain the various elements of the<br />

above incarnation statement in the following subsections.<br />

Name Substitution<br />

A state can be incarnated as a substate of a regularly defined (i.e., nonincarnated)<br />

state. The incarnation has the same name as the incarnated state<br />

unless given a new name in the incarnation statement. If the a state definition is<br />

incarnated more than once, the incarnation should be given a new name in order<br />

to distinguish it from other incarnations. Lines 14 and 21 of Prog. 6.4 shows<br />

how to rename incarnations.<br />

Just like regular states, incarnated states may access the variables of their superstates.<br />

The external variables of the incarnation (i.e., the ones used but not<br />

defined in the incarnation, see lines 2 and 3) are bound to the variables of the<br />

embedding superstates at compile time. External variables must have the same<br />

name and type as their actual definitions. However, since the incarnated state<br />

and the superstate may be specified by different developers, a naming convention<br />

<strong>for</strong> events and variables would be needed. In order to relieve programmers<br />

from such conventions, OSM supports name substitutions <strong>for</strong> events and external<br />

variables in the incarnation of states. This allows to integrate states that were<br />

developed independently. Line 15 of Prog. 6.4 shows how the external variable x<br />

of the original definition (line 2) is renamed to u in the incarnation. Renaming of<br />

events is done analogously. Lines 16, 22, and 23 show how events are renamed.<br />

Note that in the incarnation of PROG_2 the event names e and f are exchanged<br />

with respect to the original definition.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!