boost msm submachine current_state for accessing sub state -
any idea how, using boost msm 1_60, can current_state(s) of submachine? consider following code, describing outer state machine allows chosing between 2 different traffic lights (standard red, yellow, green 1 , alternating 2 yellow lights instance):
class smbigmom : public msmf::state_machine_def<smbigmom> { public: smbigmom() {}; using initial_state = smselectorstate; class smlightbase : public msmf::state_machine_def<smlightbase> { public: smlightbase() {}; using initial_state = basestate; struct transition_table : mpl::vector<> {}; }; using smbasebackend = msm::back::state_machine<smlightbase>; class smcommonryg : public smlightbase { public: smcommonryg() = default; ~smcommonryg() {}; using initial_state = red; // init state struct transition_table : mpl::vector< // start, event, target, action, guard msmf::row< red, evnext, redyellow, msmf::none, msmf::none >, msmf::row< redyellow, evnext, green, msmf::none, msmf::none >, msmf::row< green, evnext, yellow, msmf::none, msmf::none >, msmf::row< yellow, evnext, red, msmf::none, msmf::none > > {}; }; using smcommonrygbackend = msm::back::state_machine<smcommonryg>; class smyellowalternate : public smlightbase { public: smyellowalternate() = default; ~smyellowalternate() {}; using initial_state = yellow; // init state struct transition_table : mpl::vector< // start, event, target, action, guard msmf::row< yellow, evnext, yellow2, msmf::none, msmf::none >, msmf::row< yellow2, evnext, yellow, msmf::none, msmf::none > > {}; }; using smyellowalternatebackend = msm::back::state_machine<smyellowalternate>; struct transition_table : mpl::vector< msmf::row< smselectorstate, evselectcommonryg, smcommonrygbackend, msmf::none, msmf::none >, msmf::row< smselectorstate, evselectyellowalternate, smyellowalternatebackend, msmf::none, msmf::none > > {};
};
using smbackend = msm::back::state_machine<smbigmom>;
now, can skip ryg via
smbackend osm. osm.process_event(evselectcommonryg());
but how can current state of ryg submachine?
osm.current_state()[0]
returns 1 (as state of outer state machine bigmom...)...
thanks help!
i figured out meanwhile, solution rather simple. just, using functor front end, add action (4th column in row) function called this:
struct submachineaction { tonext() {}; ~tonext() {}; template<class tfsm, class tevent, class tstatein, class tstateout> void operator() (const tevent& p_rev, const tfsm& p_rfsm, tstatein& p_rstatein, tstateout& p_rstateout) { std::cout << "substate: " << p_rfsm.current_state()[0] << std::endl; } };
if have several "master" machines running , need know 1 called submachineaction, can define, instance, base front end class additional identifier (string, int, name it) , derive submachines class. then, following thread, can set identifier, can accessed via p_rfsm in above functor: how pass data current boost meta state machine(msm) substate
hope helps else sometime.
Comments
Post a Comment