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.

102 Chapter 6. Implementation<br />

specified action is executed. If the target state is missing, the specification of an<br />

action is mandatory.<br />

Incoming Transitions and Entry Actions<br />

As stated previously, transitions are defined in the scope of the transition’s<br />

source state together with the transition’s exit action. In order to specify entry<br />

actions, part of the transition must be again declared in the transition’s target<br />

state. That is, if a transition is to trigger both an exit and an entry action,<br />

the transition appears twice in the OSM code: It must be defined in the transition’s<br />

source state, together with the exit action. And it must be declared again<br />

as incoming transition in the target state (together with the entry action). Both<br />

declarations denote the same transition, if source state, target state, trigger and<br />

guard are equal. If only the exit action of a transition is required, its declaration<br />

as incoming transition is obsolete.<br />

The reason <strong>for</strong> this seeming redundancy is the intent to reflect OSM’s scoping<br />

of actions in the programming language. In OSM, exit actions are executed in<br />

the context of a transition’s source state, whereas entry actions are executed in<br />

the context of a transition’s target state. This separation is reflected in the syntax<br />

and clearly fosters modularity, as changes to the incoming action do not require<br />

changes in the transition’s source state (and vice versa) at the price of slightly<br />

more code.<br />

The general <strong>for</strong>m of entry actions is (where S is the source state, e is the trigger<br />

event, g is the guard, and aentry() is the entry action to be triggered):<br />

onEntry: S -> [g]e / aentry();<br />

In Prog. 6.1, a transition from B to C triggered by f has an entry action inC1().<br />

The actual transition is defined in line 12. The corresponding entry action is<br />

declared in transition’s target state C in line 18. The declaration of the entry<br />

action includes the transition’s source state B and its trigger f. However, the<br />

declaration of the transition’s exact source state as well as its trigger event and<br />

guard are optional and only required to identify the exact incoming transition<br />

should there be multiple incoming transitions. This in<strong>for</strong>mation can be left out<br />

where this in<strong>for</strong>mation is not required to identify the transition, <strong>for</strong> example if<br />

there is only one incoming transition. In our example, state C has two incoming<br />

actions, both invoked on transitions from the same source state B. There<strong>for</strong>e<br />

the specification of the source state is not strictly required in the declaration and<br />

line 18 could be replaced with “onEntry: f / inC1();” without changing<br />

the program’s semantic. Missing source states, trigger events, and guards, in<br />

entry-action declarations are considered to match all possibilities. There<strong>for</strong>e, in<br />

the declaration “onEntry: / a();” in the definition of a state S, action a()<br />

would be executed each time S was entered. When multiple declarations match,<br />

all matching entry actions are executed.<br />

Entry Actions on Initial <strong>State</strong> Entry<br />

In order to trigger computational actions when entering the initial state of a<br />

state machine (either at the start of the entire program or because a superstate

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

Saved successfully!

Ooh no, something went wrong!