123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370 |
- // Copyright 2010 Christophe Henry
- // henry UNDERSCORE christophe AT hotmail DOT com
- // This is an extended version of the state machine available in the boost::mpl library
- // Distributed under the same license as the original.
- // Copyright for the original version:
- // Copyright 2005 David Abrahams and Aleksey Gurtovoy. Distributed
- // under the Boost Software License, Version 1.0. (See accompanying
- // file LICENSE_1_0.txt or copy at
- // http://www.boost.org/LICENSE_1_0.txt)
- #ifndef LOGGING_FUNCTORS
- #define LOGGING_FUNCTORS
- BOOST_MSM_EUML_ACTION(Empty_Entry)
- {
- template <class Event,class FSM,class STATE>
- void operator()(Event const&,FSM&,STATE& )
- {
- std::cout << "entering: Empty" << std::endl;
- }
- };
- BOOST_MSM_EUML_ACTION(Empty_Exit)
- {
- template <class Event,class FSM,class STATE>
- void operator()(Event const&,FSM&,STATE& )
- {
- std::cout << "leaving: Empty" << std::endl;
- }
- };
- BOOST_MSM_EUML_ACTION(Open_Entry)
- {
- template <class Event,class FSM,class STATE>
- void operator()(Event const&,FSM&,STATE& )
- {
- std::cout << "entering: Open" << std::endl;
- }
- };
- BOOST_MSM_EUML_ACTION(Open_Exit)
- {
- template <class Event,class FSM,class STATE>
- void operator()(Event const&,FSM&,STATE& )
- {
- std::cout << "leaving: Open" << std::endl;
- }
- };
- BOOST_MSM_EUML_ACTION(Stopped_Entry)
- {
- template <class Event,class FSM,class STATE>
- void operator()(Event const&,FSM&,STATE& )
- {
- std::cout << "entering: Stopped" << std::endl;
- }
- };
- BOOST_MSM_EUML_ACTION(Stopped_Exit)
- {
- template <class Event,class FSM,class STATE>
- void operator()(Event const&,FSM&,STATE& )
- {
- std::cout << "leaving: Stopped" << std::endl;
- }
- };
- BOOST_MSM_EUML_ACTION(AllOk_Entry)
- {
- template <class Event,class FSM,class STATE>
- void operator()(Event const&,FSM&,STATE& )
- {
- std::cout << "starting: AllOk" << std::endl;
- }
- };
- BOOST_MSM_EUML_ACTION(AllOk_Exit)
- {
- template <class Event,class FSM,class STATE>
- void operator()(Event const&,FSM&,STATE& )
- {
- std::cout << "finishing: AllOk" << std::endl;
- }
- };
- BOOST_MSM_EUML_ACTION(ErrorMode_Entry)
- {
- template <class Event,class FSM,class STATE>
- void operator()(Event const&,FSM&,STATE& )
- {
- std::cout << "starting: ErrorMode" << std::endl;
- }
- };
- BOOST_MSM_EUML_ACTION(ErrorMode_Exit)
- {
- template <class Event,class FSM,class STATE>
- void operator()(Event const&,FSM&,STATE& )
- {
- std::cout << "finishing: ErrorMode" << std::endl;
- }
- };
- BOOST_MSM_EUML_ACTION(Playing_Entry)
- {
- template <class Event,class FSM,class STATE>
- void operator()(Event const&,FSM&,STATE& )
- {
- std::cout << "entering: Playing" << std::endl;
- }
- };
- BOOST_MSM_EUML_ACTION(Playing_Exit)
- {
- template <class Event,class FSM,class STATE>
- void operator()(Event const&,FSM&,STATE& )
- {
- std::cout << "leaving: Playing" << std::endl;
- }
- };
- BOOST_MSM_EUML_ACTION(Song1_Entry)
- {
- template <class Event,class FSM,class STATE>
- void operator()(Event const&,FSM&,STATE& )
- {
- std::cout << "starting: First song" << std::endl;
- }
- };
- BOOST_MSM_EUML_ACTION(Song1_Exit)
- {
- template <class Event,class FSM,class STATE>
- void operator()(Event const&,FSM&,STATE& )
- {
- std::cout << "finishing: First Song" << std::endl;
- }
- };
- BOOST_MSM_EUML_ACTION(Song2_Entry)
- {
- template <class Event,class FSM,class STATE>
- void operator()(Event const&,FSM&,STATE& )
- {
- std::cout << "starting: Second song" << std::endl;
- }
- };
- BOOST_MSM_EUML_ACTION(Song2_Exit)
- {
- template <class Event,class FSM,class STATE>
- void operator()(Event const&,FSM&,STATE& )
- {
- std::cout << "finishing: Second Song" << std::endl;
- }
- };
- BOOST_MSM_EUML_ACTION(Song3_Entry)
- {
- template <class Event,class FSM,class STATE>
- void operator()(Event const&,FSM&,STATE& )
- {
- std::cout << "starting: Third song" << std::endl;
- }
- };
- BOOST_MSM_EUML_ACTION(Song3_Exit)
- {
- template <class Event,class FSM,class STATE>
- void operator()(Event const&,FSM&,STATE& )
- {
- std::cout << "finishing: Third Song" << std::endl;
- }
- };
- BOOST_MSM_EUML_ACTION(Region2State1_Entry)
- {
- template <class Event,class FSM,class STATE>
- void operator()(Event const&,FSM&,STATE& )
- {
- std::cout << "starting: Region2State1" << std::endl;
- }
- };
- BOOST_MSM_EUML_ACTION(Region2State1_Exit)
- {
- template <class Event,class FSM,class STATE>
- void operator()(Event const&,FSM&,STATE& )
- {
- std::cout << "finishing: Region2State1" << std::endl;
- }
- };
- BOOST_MSM_EUML_ACTION(Region2State2_Entry)
- {
- template <class Event,class FSM,class STATE>
- void operator()(Event const&,FSM&,STATE& )
- {
- std::cout << "starting: Region2State2" << std::endl;
- }
- };
- BOOST_MSM_EUML_ACTION(Region2State2_Exit)
- {
- template <class Event,class FSM,class STATE>
- void operator()(Event const&,FSM&,STATE& )
- {
- std::cout << "finishing: Region2State2" << std::endl;
- }
- };
- // transition actions for Playing
- BOOST_MSM_EUML_ACTION(start_next_song)
- {
- template <class FSM,class EVT,class SourceState,class TargetState>
- void operator()(EVT const& ,FSM&,SourceState& ,TargetState& )
- {
- std::cout << "Playing::start_next_song" << endl;
- }
- };
- BOOST_MSM_EUML_ACTION(start_prev_song)
- {
- template <class FSM,class EVT,class SourceState,class TargetState>
- void operator()(EVT const& ,FSM&,SourceState& ,TargetState& )
- {
- std::cout << "Playing::start_prev_song" << endl;
- }
- };
- // transition actions
- BOOST_MSM_EUML_ACTION(start_playback)
- {
- template <class FSM,class EVT,class SourceState,class TargetState>
- void operator()(EVT const& ,FSM&,SourceState& ,TargetState& )
- {
- cout << "player::start_playback" << endl;
- }
- };
- BOOST_MSM_EUML_ACTION(open_drawer)
- {
- template <class FSM,class EVT,class SourceState,class TargetState>
- void operator()(EVT const& ,FSM&,SourceState& ,TargetState& )
- {
- cout << "player::open_drawer" << endl;
- }
- };
- BOOST_MSM_EUML_ACTION(close_drawer)
- {
- template <class FSM,class EVT,class SourceState,class TargetState>
- void operator()(EVT const& ,FSM&,SourceState& ,TargetState& )
- {
- cout << "player::close_drawer" << endl;
- }
- };
- BOOST_MSM_EUML_ACTION(store_cd_info)
- {
- template <class FSM,class EVT,class SourceState,class TargetState>
- void operator()(EVT const&, FSM& ,SourceState& ,TargetState& )
- {
- cout << "player::store_cd_info" << endl;
- // it is now easy to use the message queue.
- // alternatively to the proces_ in the transition table, we could write:
- // fsm.process_event(play());
- }
- };
- BOOST_MSM_EUML_ACTION(stop_playback)
- {
- template <class FSM,class EVT,class SourceState,class TargetState>
- void operator()(EVT const& ,FSM&,SourceState& ,TargetState& )
- {
- cout << "player::stop_playback" << endl;
- }
- };
- BOOST_MSM_EUML_ACTION(pause_playback)
- {
- template <class FSM,class EVT,class SourceState,class TargetState>
- void operator()(EVT const& ,FSM&,SourceState& ,TargetState& )
- {
- cout << "player::pause_playback" << endl;
- }
- };
- BOOST_MSM_EUML_ACTION(resume_playback)
- {
- template <class FSM,class EVT,class SourceState,class TargetState>
- void operator()(EVT const& ,FSM&,SourceState& ,TargetState& )
- {
- cout << "player::resume_playback" << endl;
- }
- };
- BOOST_MSM_EUML_ACTION(stop_and_open)
- {
- template <class FSM,class EVT,class SourceState,class TargetState>
- void operator()(EVT const& ,FSM&,SourceState& ,TargetState& )
- {
- cout << "player::stop_and_open" << endl;
- }
- };
- BOOST_MSM_EUML_ACTION(stopped_again)
- {
- template <class FSM,class EVT,class SourceState,class TargetState>
- void operator()(EVT const& ,FSM&,SourceState& ,TargetState& )
- {
- cout << "player::stopped_again" << endl;
- }
- };
- BOOST_MSM_EUML_ACTION(report_error)
- {
- template <class FSM,class EVT,class SourceState,class TargetState>
- void operator()(EVT const& ,FSM&,SourceState& ,TargetState& )
- {
- cout << "player::report_error" << endl;
- }
- };
- BOOST_MSM_EUML_ACTION(report_end_error)
- {
- template <class FSM,class EVT,class SourceState,class TargetState>
- void operator()(EVT const& ,FSM&,SourceState& ,TargetState& )
- {
- cout << "player::report_end_error" << endl;
- }
- };
- BOOST_MSM_EUML_ACTION(internal_action1)
- {
- template <class FSM,class EVT,class SourceState,class TargetState>
- void operator()(EVT const&, FSM& ,SourceState& ,TargetState& )
- {
- cout << "Open::internal action1" << endl;
- }
- };
- BOOST_MSM_EUML_ACTION(internal_action2)
- {
- template <class FSM,class EVT,class SourceState,class TargetState>
- void operator()(EVT const&, FSM& ,SourceState& ,TargetState& )
- {
- cout << "Open::internal action2" << endl;
- }
- };
- BOOST_MSM_EUML_ACTION(internal_action)
- {
- template <class FSM,class EVT,class SourceState,class TargetState>
- void operator()(EVT const&, FSM& ,SourceState& ,TargetState& )
- {
- cout << "Open::internal action" << endl;
- }
- };
- enum DiskTypeEnum
- {
- DISK_CD=0,
- DISK_DVD=1
- };
- // Handler called when no_transition detected
- BOOST_MSM_EUML_ACTION(Log_No_Transition)
- {
- template <class FSM,class Event>
- void operator()(Event const& e,FSM&,int state)
- {
- std::cout << "no transition from state " << state
- << " on event " << typeid(e).name() << std::endl;
- }
- };
- BOOST_MSM_EUML_ACTION(internal_guard1)
- {
- template <class FSM,class EVT,class SourceState,class TargetState>
- bool operator()(EVT const&, FSM& ,SourceState& ,TargetState& )
- {
- cout << "Open::internal guard1" << endl;
- return false;
- }
- };
- BOOST_MSM_EUML_ACTION(internal_guard2)
- {
- template <class FSM,class EVT,class SourceState,class TargetState>
- bool operator()(EVT const&, FSM& ,SourceState& ,TargetState& )
- {
- cout << "Open::internal guard2" << endl;
- return false;
- }
- };
- #endif // LOGGING_FUNCTORS
|