我正在使用新的Boost 1.44.0 MSM庫來生成狀態機。在這個狀態機中有兩類事件class1
和class2
。 class1
事件可以由狀態S1
或S2
進行處理,而class2
事件只能由狀態S2
進行處理。提升MSM只處理內部轉換
一個特殊的class1
事件upgrade_req
請求從狀態S1
升級到狀態S2
。
,我實現了在升壓:: MSM如下:
// State S1 and S2 allow any class1 events
struct class1 {};
// Only state S2 allows class2 events
struct class2 {};
// an upgrade request is a class1 event that requests an upgrade to state 2
struct upgrade_req : public class1 {};
struct MyFSM : public msm::front::state_machine_def<MyFSM>
{
/// State 1. Allows any class1 event
struct S1 : public msm::front::state<>
{
/// functor says "processing event in State 1"
struct ProcessEvent { /* ... */ };
struct internal_transition_table : mpl::vector<
// Event Action Guard
// +-------+-------------+------------+
Internal< class1, ProcessEvent, none >
> {};
}; // S1
/// State 2. Allows any class1 or class2 events
struct S2 : public msm::front::state<>
{
/// functor says "processing event in State 2"
struct ProcessEvent { /* ... */ };
struct internal_transition_table : mpl::vector<
// Event Action Guard
// +-------+-------------+------------+
Internal< class1, ProcessEvent, none >,
Internal< class2, ProcessEvent, none >
> {};
}; // S2
/// everybody starts in state 1
typedef S1 initial_state;
/// send an error if a class2 event was received for state1
struct SendError { /* ... */ };
/// Send a response to the upgrade request
struct SendUpgradeRsp { /* ... */ };
/// functor returns true if the request to upgrade to state 2 is OK.
struct VerifyUpgradeReq { /* ... */ };
struct transition_table : mpl::vector<
// Start Event Next Action Guard
// +------+-------------+------+----------------+------------------+
Row< S1, class1, none, none, none,
Row< S1, class2, S1, SendError, none >,
Row< S1, upgrade_req, S2, SendUpgradRsp, VerifyUpgradeReq >,
Row< S2, class1, none, none, none,
Row< S2, class2, none, none, none >
> {};
}; // MyFSM
我的問題是,當我用這個,因爲它是永遠不會被主MyFSM::transition_table
處理upgrade_req
事件。它只能由S1::internal_transition_table
處理。
例如:
int main(int argc, char* argv[])
{
msm::back::state_machine<MyFSM> sm;
sm.start();
sm.process_event(class1());
sm.process_event(upgrade_req());
sm.process_event(class2());
return 0;
}
我就是願意這樣做的輸出是:在國家
處理事件1.
升級請求確定。在國家2.
但是,
處理事件我所得到的是這樣的:在國家1
處理事件
處理事件的國家1.
錯誤。收到狀態1中的第2類事件。
有沒有人有關於如何解決此問題的建議?
感謝, PaulH