I intend to use boost.msm with the concept of composite containing orthogonal regions. I want to synchronize all orthogonal regions upon exit. In other words: the state following my composite shall be activated if and only if all regions have reached their last state.
UML 2.4 "Superstructure" proposes join pseudo states (i.e. chapter 15.3.8). In boost, there is a fork but I cannot find any implementation of its counterpart join.
Is there no join pseudo state in boost.msm? How would I apply the concept of join pseudo state with boost.msm?
You could use a counter which will increment each time the join state is entered. When this counter equals the number of orthogonal regions, the state following the join state will be activated.
This could be done manually or in a generic way. Below I implemented a generic way where the joining logic is added to the submachine
Sub
by inheriting from the templateJoinSM
.Sub
has 3 orthogonal regions (which in this simple example just consist of one state each, namelyOrthogonal1
,Orthogonal2
andOrthogonal3
). All of these orthogonal states are connected to theJoin
state but no direct connection to theExit
state from theJoin
state is specified withinSub
.This connection is implemented in
JoinSM
. Every time theJoin
state is reached fromSub
, theWaiting
state is activated and the counter is incremented. If the counter reaches the number of orthogonal regions, the EventAllJoined
is fired and the transition toExit
is activated.Since
JoinSM
queries the number of orthogonal regions through the size ofinitial_state
, adding or removing regions inSub
will automatically be reflected in the joining logic.Output:
Live example: http://coliru.stacked-crooked.com/a/6c060d032bc53573