Add a new page

Maintain

UML supports a deferred events function. Consider the following diagram.
When an event occurs in the state that has a defer description that corresponds to the event, it will be preserved. And when the transition will reach a state that doesn't have a defer description that corresponds to the deferred event, it will be invoked.
For example, when Event1 occurs twice in State1 in the diagram above, they are preserved. And then, when Event2 occurs, they are still preserved. Because State2 also has the defer description. When Event2 occurs once more, transitions occur in order of State3, State4, and State5.
Boost.Msm supports deferred events directly. To use the deferred events, you need to insert the following typedef in the definition of your state machine.

typedefintactivate_deferred_events;

And then, place the msmf::Defer into the Action field in the transition table. As with a normal action, you can write a guard function object. If you write that, the event is preserved only when the guard condition is satisfied.

Let's see more complicated case. An anonymous transition has higher priority than deferred events. Consider the following diagram.
When the Event1 occurs in State1, the event is preserved. And then, when Event2 occurs, the current state transitions to State2. State2 has two outgoing transitions. One has Event1, the other is anonymous transition. According to the priority the anonymous transition is chosen. As a result, transitions occur in order of State3 and State4.

Because an anonymous transition has higher priority than deferred events. In the second example, the transition from State2 to State3 is an anonymous transition. 'Anonymous transition' means transition without event.
When the current state is State2, there are two outgoing transitions. One is the anonymous transition, the other is to State5 transition that have Event1 as a trigger. Then, the anonymous transition is chosen. Deferred event is not consumed. After transitioning to State3, deferred event is fired. So the transition from State3 to State4 is occurred. That why, State5::on_entry() is not displayed.