[statechart] Unexpected events
I had assumed that if a state_machine definition did not mention any reaction for a particular event in a particular state, occurrence of that event in that state would be flagged as a runtime error. It appears that instead, the event is simply dropped. Can this behavior be changed? It would be tremendously helpful for debugging purposes. Adding an error state and a bunch of transitions into it seems like overkill, especially if the cross product between states and events is large but the "in- and out-degree" of states is small. -Dave
David Greene wrote:
I had assumed that if a state_machine definition did not mention any reaction for a particular event in a particular state, occurrence of that event in that state would be flagged as a runtime error.
It appears that instead, the event is simply dropped.
This is the behavior mandated by the UML standard.
Can this behavior be changed? It would be tremendously helpful for debugging purposes. Adding an error state and a bunch of transitions into it seems like overkill, especially if the cross product between states and events is large but the "in- and out-degree" of states is small.
[untested code] struct EvUnconsumedEvent() : sc::event<EvUnconsumedEvent> {}; // Add the following member to your state_machine // subtype (see reference): void unconsumed_event( const sc::event_base & ) { post_event( new EvUnconsumedEvent() ); } Your machine has two outermost states, e.g. Normal and UnconsumedEventError and a transition triggered by EvUnconsumedEvent leading from Normal to UnconsumedEventError. Of course, Normal would then contain all the states you have now. HTH & Regards, -- Andreas Huber When replying by private email, please remove the words spam and trap from the address shown in the header.
Andreas Huber wrote:
Your machine has two outermost states, e.g. Normal and UnconsumedEventError and a transition triggered by EvUnconsumedEvent leading from Normal to UnconsumedEventError. Of course, Normal would then contain all the states you have now.
Ok, that should work. Thanks! I'm still learning this (to me) strange concept of nested states. -Dave
participants (2)
-
Andreas Huber
-
David Greene