|
Boost Users : |
Subject: [Boost-users] [1.44 MSM meta state machine] accessing objects from actions
From: Hajo Kirchhoff (mailinglists_at_[hidden])
Date: 2010-10-25 03:39:00
Hi all,
what is the recommended way to use objects with an MSM state machine?
I've written a state machine that handles sending data via UDP (asio).
I'm using the functor front end and I have a 'send' action:
struct a_send
{
template <typename Event, typename Fsm, typename S, typename T>
void operator()(Event const& evt, Fsm &fsm, S&, T&)
{
// get next object from queue and post it to asio
}
};
My question is, how are actions supposed to access the objects that the
state machine should work with?
Currently my queue object is a member of the state machine itself, so I
can write
struct Send_ : public msm::front::state_machine_def<Send_>
{
string m_next_line_to_send;
socket m_socket;
string get_next_send_line();
};
and in my a_send action
void operator()(Event &const &evt, Fsm &fsm, S&, T&)
{
fsm.m_next_line_to_send=fsm.get_next_send_line();
fsm.m_socket.async_write(fsm.m_next_line_to_send);
}
This works well as long as I am not using sub-statemachines.
Here is my problem:
I would like to use a substate machine for the actual sending. The main
state machine has the states Disconnected, Working, Error, Shutdown. The
Working state should actually be a substate machine.
The problem is, when a_send gets called by the substate machine Working,
the fsm object is of type Working.
How can I access the member variables of the parent of a substate
machine? Or is there a better way of accessing the objects the state
machine should work with from actions?
The tutorial explains state machines very nicely with the example of a
CD player. But all the actions are empty and nowhere is explained, how
you would actually access a CD player member variable or other such
object so that you could actually manipulate the player to do something.
Regards and thanks
Hajo
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net