RKH
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Using submachine states
rkh_bunner.jpg


Prev: Running
Next: Getting started with RKH

A submachine state is a kind of a state that actually refers to another defined state machine. A submachine state is logically equivalent to the insertion of the referenced state machine as a composite state in the place of the submachine state. Consequently, every entrance to a submachine state is equivalent to the corresponding entrance to the inserted (referenced) composite state. In particular, it can be entered thruough its initial pseudostate (as any other composite state), or through one of its entry points.

Similary, every exit from a submachine state is equivalent to the corresponding exit from the inserted composite state. It can be exited through one of its exit points. When it is exited through its exit point the effect of the transition targeting the exit point is executed first, followed by the exit behavior of the composite state.

The entry, exit, and behavior actions and internal transitions are defined as part of the state. Submachine state is a decomposition mechanism that allows factoring of common behaviors and their reuse.

The purpose od defining submachine states is to decompose and localize repetitive parts because the same state machine can be referenced from more than one submachine state.

The diagram in following figure shows a fragment from a state machine diagram in which a submachine state (the SB) is referenced.

sbm1.png
Submachine state

In the above example, the transition triggered by event TWO will terminate on entry point ENS12 of the SB state machine. The ONE transition implies taking of the default transition of the SB and executes the act5() action. The transition emanating from the EX1S12 exit point of the submachine will execute the act1() behavior in addition to what is executed within the SB state machine. Idem transition emanating from the EX2S12. This transition must have been triggered within the SB state machine. Finally, the transition emanating from the edge of the submachine state is triggered by event THREE.

The following figure is an example of a state machine SB defined with two exit points, EXPNT1 and EXPNT2, and one entry point ENPNT.

sbm2.png
State machine with two exit points and one entry

point"

In the following figure the state machine shown above is referenced twice in
a submachine state \c S12 and \c S2.

sbm3.png
Submachine state with usage of exit and entry points

The following figure highlights the submachine states S12 and S2. Also, shows its implementation using the RKH framework.

sbm4.jpg
Submachine states

The following figure highlights the submachine state machine SB. Also, shows its implementation using the RKH framework.

sbm5.jpg
Referenced state machine

Prev: Running
Next: Getting started with RKH