Boost.MSM: Exit a composite state after an event has been fired from that composite state?

Hi list,
I'm using boost.msm from the boost 1.52 library and trying to fire an event
from a composite state to enter a state of a top level state machine.
Unfortunatly this doesn't work.
Please consider here for the following code:
namespace {
namespace msm = boost::msm;
namespace msmf = boost::msm::front;
namespace mpl = boost::mpl;
// ----- Events
struct Event1 {};
struct Event2 {};
struct EventSub1 {};
struct EventSub2 {};
// ----- State machine
struct OuterSm_:msmf::state_machine_def
> {};
};
// Pick a back-end
typedef msm::back::state_machine

Hi, <snip code>
You see that the code calls f*sm.process_event(Event2())* within the state *SubState1* of the submachine to make a transition from the top-level state *State1* to *State2* of the outer statemachine. Unfortunately this doesn't work although the *Event2* is defined in the transition table of the outer-statemachine.
On the other hand it a transition from *State1* to state *State2* works in case the event *Event2* is fired outside the submachine ( please refer to the void test() function in the code above).
I actually don't want to define a transition in the transition table of submachine to enter an pseudo exit point like:
msmf::Row < SubState1, Event2, Exit1, msmf::none, msmf::none >
Is there a possibility in MSM to exit a composite state if an event is fired from that composite state?
It's a question which is asked regularly on different forms. It usually boils down to a current limitation, that the FSM template parameter refers to the lowest level fsm, not the outer, and you want to send the event to the outest to get correct handling. Actually I got this asked a few days ago. You need to get to the lower-level fsm a way to call the outest: - let the outer state machine set a pointer to itself into each submachine - hide this inside a boost::function. Unfortunately it means a boost::function for every event - use type_erasure (not in boost yet) to have just one object with several members instead of many boost::function objects I'm aware of this limitation and I want to provide a solution (a variadic list of FSMs) right after the thread thing you just asked. In the meantime you will have to use one of the above solutions.
Thank you in advance for your time and help!
Grüße ;),
:) Grüße, Christophe

Hi Christophe!
Thanks for your fast response again.
I was thinking so solve my problem in another way, but I was again
disappointed.
My idea was to manage a global queue/vector for different event types. The
"global" queue could be used by the submachine to put internal events in
which than would be afterwards extracted from the State machine caller and
emited to the state machine by using the fsm.process_event(...) function.
but unfortunately this seems not to work too. Please consider the following
code snippet to understand me:
#include <iostream>
#include
, msmf::Row < State3, Event3, msmf::none, msmf::none, msmf::none > > {}; };
// Pick a back-end
typedef msm::back::state_machine

Hi,
I think the base problem occurs in the compilation phase, due to the fact, that the template event type of the *process_event(...)* function isn't distinct due to the different types defined in *boost::variant<...>* as state above in the main() function.
Indeed, MSM does not support boost::variant. It knows only concrete event types.
In contrast to that the following code snippet works fine.
.... osm.enqueue_event(Event1()); osm.enqueue_event(Event2()); osm.enqueue_event(Event3());
osm.execute_queued_events();
...
Using the *enqueue_event()* function call has unfortunately the constraint, that for each sub-machine a own event queue is used and for each sub-machine the call execute_queued_events has to be triggered. I don't want this. I want to queue all possible events of the all submachines and to call execute_queued_events function from a central position.
Same as last question, you need to enqueue on the top-level fsm, then it should work. This is no different from what we just discussed. I know it's not fun to keep a pointer to the top-level fsm but for the time being, there is no choice. I don't think trying to work around this will work (I tried ;-) ).
Do you have an idea how I could solve this issue. Does MSM provide a global event queue? If not, it would be necessary to provide each sub-machine with a pointer to the outermost submachine to be able to put events to the event queue. Afterwards "execute_queued_events()" can be called by the control-logic which encloses the overal state machine.
Each fsm has its own event queue, including submachines. If you enqueue into the one of the top-level fsm, it will work fine. Actually, this feature is pretty basic. If you look at the code, it just builds a list of boost::function of functors created by boost::bind. You could easily build your own if this one does not fit your needs, there really is no magic there.
Thank you in advance!
Sorry für die vielen Fragen, muss jedoch abwägen, ob MSM für den produktiven Einsatz in einem noch zu entwickelden Software-Produkt geeignet ist.
Sorry that I answer fast, I'm leaving for 2 weeks tomorrow and will be only online again on the 7th Jan.
Grüße,
RaRi
Cheers, Christophe
participants (2)
-
Christophe Henry
-
RaRi