Boost logo

Boost :

Subject: [boost] [msm]exit pseudo state and event
From: Takatoshi Kondo (kondo_at_[hidden])
Date: 2011-07-01 03:16:35


Boost.Msm supports the UML2.0 feature "exit pseudo state".
Here is a description about exit pseudo state in the document.

> exit_pseudo_state
> Basic type for exit pseudo states. Exit pseudo states are an
> predefined exit from a submachine and connect two transitions.
> The first argument is the name of the event which will be
> "thrown" out of the exit point. This event does not need to
> be the same as the one sent by the inner region but must be
> convertible from it. The second argument is needed if you
> want your state (and all others used in a concrete state machine)
> to inherit a basic type for logging or providing a common behavior.
> template<class Event,class Base =
> default_base_state, {
> }
> class SMPtrPolicy = no_sm_ptr>
> exit_pseudo_state {
> }

Why the 1st template parameter "Event" is needed?

Consider the attached diagram "11_ExitPointEvent.png".

IMHO, the Exit2 is typical usecase of exit pseudo state.
Outgoing transition from exit pseudo state shouldn't have
any events and guards.
The point is how to divide the concerns.
When we design the Sm1, we can depend only State1,
State1::Exit1, State1::Exit2 and State2.
And we shouldn't depend on which event triggers the
transition to pseudo exit state.
It's State1's concern.

To implement that, I pass the "none" as 1st template parameter.

namespace msmf = boost::msm::front;
struct Exit2:public msm::front::exit_pseudo_state<msmf::none> {};
(See the attached file 11_ExitPointEvent.cpp)

I think it is suitable for the default template parameter.

The example in the Boost.Msm tutorial document, the usage of
exit pseudo state is similar as Exit1 in "11_ExitPointEvent.png".

The behavior that I understand is below.
In State1
1. Event1 is occurred,
2. Transition to Exit1.
3. Event1 is converted to Event2 (Exit1's template argument).
In Sm1
4. Dispatch Event2.
5. Transition to State2.
(Entry, Exit action is omitted)

Is that right?
I'd like to know why such complicated mechanism is needed?
Is the purpose to propagate the event parameter?



Boost list run by bdawes at, gregod at, cpdaniel at, john at