I have main fsm with two sub-levels.
The problem is, the sub-fsms need data which is held in root fsm, like:
struct SomeAction
{
template
void operator()(EVT&, FSM& fsm, SourceState&,
TargetState&) const
{
// ...
}
};
Instance of fsm here might be root fsm as well as sub-fsm.
I see two possible solutions:
1. use sm_ptr policy and store parent pointer in each sub-fsm
In this case access might look like this:
fsm.parent_->data; (access from 1-level fsm)
fsm.parent_->parent_->data; (access from 2-level fsm)
doesn't look so nice, besides, documentation states that using sm_ptr is
deprecated.
2. recursively traverse all states, detect fsm's and store root pointer
typedef RootFSM::stt stt;
typedef boost::msm::back::generate_state_set<stt>::type all_states;
boost::mpl::for_eachmpl::placeholders::_1 >
(find_sub_fsm<stt>());
template <typename stt>
struct find_sub_fsm
{
template <class StateType>
void operator()(boost::msm::wrap<StateType>& state) const
{
// ???
// state.root_ = &g_root;
// do the recurs
}
};
How to detect that StateType is sub-fsm?
3. Maybe, there is a easier way to communicate between sub-fsm's?