I believe your state machine is incorrectly structured. Consider encapsulating your input and output states within a higher-level state. Assume this super-state is called "io". So, now you have three top-level states: idle, io, and cancel. Place the history transition within io. Now, when you trigger "revert" from the cancel state specify a transition to io. This should give you the desired effect. Dan Kelly djkelly@computer.org
On Apr 12, 2016, at 09:37, juls
wrote: I have a difficulty in understanding the boost statechart history functionality. I have the following state machine.
struct InButtonPressed : sc::event<InButtonPressed> {}; struct OutButtonPressed : sc::event<OutButtonPressed> {}; struct InButtonPressed : sc::event<InButtonPressed> {}; struct InputProceed: sc::event<InputProceed> {}; struct OutputProceed: sc::event<OutputProceed> {}; struct CancelEvent: sc::event<CancelEvent> {}; struct Proceed: sc::event<Proceed> {}; struct Revert: sc::event<InputProceed> {};
struct RH_StateMachine : bsc::state_machine< RH_StateMachine, Idle > {};
struct Idle : bsc::state< Idle, RH_StateMachine> { Idle(my_context ctx) : my_base(ctx){ std::cout << "[+] Idle" << std::endl; } ~Idle(){std::cout << "[-] leaving Idle state... \n";} typedef boost::mpl::list< bsc::transition< InButtonPressed, Input>, bsc::transition< OutButtonPressed, Output>
reactions; };
struct Input : bsc::state< Input, RH_StateMachine> { Input(my_context ctx) : my_base(ctx){ std::cout << "[+] Input" << std::endl; } ~Input(){std::cout << "[-] leaving Input state... \n";} typedef boost::bsc::transition< CancelEvent, Cancel>
reactions; };
struct Output : bsc::state< Output, RH_StateMachine> { Output(my_context ctx) : my_base(ctx){ std::cout << "[+] Output" << std::endl; } ~Output(){std::cout << "[-] leaving Output state... \n";} typedef boost::bsc::transition< CancelEvent, Cancel>
reactions; };
struct Cancel::bsc::state
{ Cancel(my_context ctx) : my_base(ctx){ std::cout << "[+] Cancel" << std::endl; } ~Cancel(){std::cout << "[-] leaving Cancel state... \n";} typedef boost::mpl::list< bsc::transition< Proceed, CanceledConfirmed>, bsc::transition< Revert, *"PREVIOUS_STATE"*> reactions; };
How do i implement transitioning to previous state using deep_history or shallow history, when i can transit to a state from many different states? In the above state machine i want to transit from Cancel state to the previous state when the revert event is triggered, but i have already transited in Cancel state from either Input or Output state... Thank you in advance.
-- View this message in context: http://boost.2283326.n4.nabble.com/Boost-statechart-how-can-i-transit-to-pre... Sent from the Boost - Users mailing list archive at Nabble.com. _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users