[statechart] Unhandled events
Hey there, I've been using SC for a while and something has been bugging me - given a state machine with: OuterSt, OneSt and TwoSt as well as OneEv and TwoEv that are handled by OneSt and TwoSt respectively, it is possible to send a wrong event to either of the last two states. Such an "unhandled" event will be forwarded to OuterSt and then quietly eaten. My question is as follows - is it possible to define some kind of "catch all" handler in the OuterSt? I have already fixed a tricky bug in my code where a submitted event was lost, and wonder if there is a simple way to handle these situations? I can certainly add a custom_reaction<>(X) for each possible event to the OuterSt and catch issues that way, but that's far from ideal. Any suggestions would be appreciated. P.S. perhaps a compromise solution would be to add something like this to OuterSt: sc::bug<OneEv> sc::bug<TwoEv> but that would effectively limit handling to issuing an assert(false)... Thanks, Oleg.
My question is as follows - is it possible to define some kind of "catch all" handler in the OuterSt?
Sure. Just define unconsumed_event() member function in your state machine. http://www.boost.org/doc/libs/1_44_0/libs/statechart/doc/reference.html#unco...
On 2010-10-07 06:53, Igor R wrote:
My question is as follows - is it possible to define some kind of "catch all" handler in the OuterSt? Sure. Just define unconsumed_event() member function in your state machine.
http://www.boost.org/doc/libs/1_44_0/libs/statechart/doc/reference.html#unco... Ah, "unconsumed" was the key word :) Thank you, it works well.
P.S. just for archiving purposes, the point here is to add a handler to
the actual state machine class/struct:
struct StateMachine : sc::state_machine
participants (2)
-
Igor R
-
Oleg Smolsky