Making sure that a triggered operation is called

There might be a problem with the reply from triggered operations if the receiver object is not in a state in which it is able to react to a triggered operation. If a triggered operation is called when not expected, incorrect return values might result.

Rather than use the IS_IN macro to determine what state the receiver is in, you can design your statechart so the triggered operation is never ignored. To do this, create a superstate encompassing the substates in the object, and in the superstate create a static reaction with a trigger to return the proper value. For example, to make sure that a sensor is always read regardless of what state an object is in, create a static reaction in the superstate with the following transition:

opRead/reply(getStatus())

This way, no matter what substate the object is in, it will always return the proper value. Although both the trigger to the superstate and that to a substate are active when in a substate, the trigger on the transition to the superstate is taken because it is higher priority. See Transition selection.


Feedback