In my project, there is a state machine implemented using boost meta state machine. This main state machine, there is a state (let's call it SubMachineEntry
for simplicity) that represents an entry point to a sub state machine:
namespace msmf = boost::msm::front;
namespace msmb = boost::msm::back;
...
msmf::Row < SomeState, enterSub, SubMachineEntry, msmf::none, msmf::none >
...
using SubMachine = msmb::state_machine<SubMachine_>;
This sub state machine performs some processing and then we go back to the outer state machine, to state
using SubMachineFinished = SubMachine::exit_pt<...>;
, which represents the exit state of the sub machine. My problem is that, before the sub state machine exits, a certain event (toProcessInOuter
) might be dispatched, and it should be processed in outer state machine after sub state machine exits. Putting that event as deferred in all states in the sub state machine does not work, it is not propagated to the state that comes after SubMachineFinished
. Is there a way to implement this forwarding of the event using some mechanism of the boost MSM, without using some custom workaround?
Unfortunately, deferred events at sub-machine cannot evaluate at the parent state-machine on MSM. So you need to write the defer transition at the parent state.
Events are evaluated from the inner state-machine to the outer state-machine. If you want to defer the event, you can write the defer transition in the parent state. I wrote the example that demonstrate it.
See the attached diagram. Let's say
Event2
is the event that you want to defer. You need to write the defer transition toState1
.Here is the whole code:
Running demo: https://wandbox.org/permlink/WQixcoGGQwAWou34