logging_functors.h 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370
  1. // Copyright 2010 Christophe Henry
  2. // henry UNDERSCORE christophe AT hotmail DOT com
  3. // This is an extended version of the state machine available in the boost::mpl library
  4. // Distributed under the same license as the original.
  5. // Copyright for the original version:
  6. // Copyright 2005 David Abrahams and Aleksey Gurtovoy. Distributed
  7. // under the Boost Software License, Version 1.0. (See accompanying
  8. // file LICENSE_1_0.txt or copy at
  9. // http://www.boost.org/LICENSE_1_0.txt)
  10. #ifndef LOGGING_FUNCTORS
  11. #define LOGGING_FUNCTORS
  12. BOOST_MSM_EUML_ACTION(Empty_Entry)
  13. {
  14. template <class Event,class FSM,class STATE>
  15. void operator()(Event const&,FSM&,STATE& )
  16. {
  17. std::cout << "entering: Empty" << std::endl;
  18. }
  19. };
  20. BOOST_MSM_EUML_ACTION(Empty_Exit)
  21. {
  22. template <class Event,class FSM,class STATE>
  23. void operator()(Event const&,FSM&,STATE& )
  24. {
  25. std::cout << "leaving: Empty" << std::endl;
  26. }
  27. };
  28. BOOST_MSM_EUML_ACTION(Open_Entry)
  29. {
  30. template <class Event,class FSM,class STATE>
  31. void operator()(Event const&,FSM&,STATE& )
  32. {
  33. std::cout << "entering: Open" << std::endl;
  34. }
  35. };
  36. BOOST_MSM_EUML_ACTION(Open_Exit)
  37. {
  38. template <class Event,class FSM,class STATE>
  39. void operator()(Event const&,FSM&,STATE& )
  40. {
  41. std::cout << "leaving: Open" << std::endl;
  42. }
  43. };
  44. BOOST_MSM_EUML_ACTION(Stopped_Entry)
  45. {
  46. template <class Event,class FSM,class STATE>
  47. void operator()(Event const&,FSM&,STATE& )
  48. {
  49. std::cout << "entering: Stopped" << std::endl;
  50. }
  51. };
  52. BOOST_MSM_EUML_ACTION(Stopped_Exit)
  53. {
  54. template <class Event,class FSM,class STATE>
  55. void operator()(Event const&,FSM&,STATE& )
  56. {
  57. std::cout << "leaving: Stopped" << std::endl;
  58. }
  59. };
  60. BOOST_MSM_EUML_ACTION(AllOk_Entry)
  61. {
  62. template <class Event,class FSM,class STATE>
  63. void operator()(Event const&,FSM&,STATE& )
  64. {
  65. std::cout << "starting: AllOk" << std::endl;
  66. }
  67. };
  68. BOOST_MSM_EUML_ACTION(AllOk_Exit)
  69. {
  70. template <class Event,class FSM,class STATE>
  71. void operator()(Event const&,FSM&,STATE& )
  72. {
  73. std::cout << "finishing: AllOk" << std::endl;
  74. }
  75. };
  76. BOOST_MSM_EUML_ACTION(ErrorMode_Entry)
  77. {
  78. template <class Event,class FSM,class STATE>
  79. void operator()(Event const&,FSM&,STATE& )
  80. {
  81. std::cout << "starting: ErrorMode" << std::endl;
  82. }
  83. };
  84. BOOST_MSM_EUML_ACTION(ErrorMode_Exit)
  85. {
  86. template <class Event,class FSM,class STATE>
  87. void operator()(Event const&,FSM&,STATE& )
  88. {
  89. std::cout << "finishing: ErrorMode" << std::endl;
  90. }
  91. };
  92. BOOST_MSM_EUML_ACTION(Playing_Entry)
  93. {
  94. template <class Event,class FSM,class STATE>
  95. void operator()(Event const&,FSM&,STATE& )
  96. {
  97. std::cout << "entering: Playing" << std::endl;
  98. }
  99. };
  100. BOOST_MSM_EUML_ACTION(Playing_Exit)
  101. {
  102. template <class Event,class FSM,class STATE>
  103. void operator()(Event const&,FSM&,STATE& )
  104. {
  105. std::cout << "leaving: Playing" << std::endl;
  106. }
  107. };
  108. BOOST_MSM_EUML_ACTION(Song1_Entry)
  109. {
  110. template <class Event,class FSM,class STATE>
  111. void operator()(Event const&,FSM&,STATE& )
  112. {
  113. std::cout << "starting: First song" << std::endl;
  114. }
  115. };
  116. BOOST_MSM_EUML_ACTION(Song1_Exit)
  117. {
  118. template <class Event,class FSM,class STATE>
  119. void operator()(Event const&,FSM&,STATE& )
  120. {
  121. std::cout << "finishing: First Song" << std::endl;
  122. }
  123. };
  124. BOOST_MSM_EUML_ACTION(Song2_Entry)
  125. {
  126. template <class Event,class FSM,class STATE>
  127. void operator()(Event const&,FSM&,STATE& )
  128. {
  129. std::cout << "starting: Second song" << std::endl;
  130. }
  131. };
  132. BOOST_MSM_EUML_ACTION(Song2_Exit)
  133. {
  134. template <class Event,class FSM,class STATE>
  135. void operator()(Event const&,FSM&,STATE& )
  136. {
  137. std::cout << "finishing: Second Song" << std::endl;
  138. }
  139. };
  140. BOOST_MSM_EUML_ACTION(Song3_Entry)
  141. {
  142. template <class Event,class FSM,class STATE>
  143. void operator()(Event const&,FSM&,STATE& )
  144. {
  145. std::cout << "starting: Third song" << std::endl;
  146. }
  147. };
  148. BOOST_MSM_EUML_ACTION(Song3_Exit)
  149. {
  150. template <class Event,class FSM,class STATE>
  151. void operator()(Event const&,FSM&,STATE& )
  152. {
  153. std::cout << "finishing: Third Song" << std::endl;
  154. }
  155. };
  156. BOOST_MSM_EUML_ACTION(Region2State1_Entry)
  157. {
  158. template <class Event,class FSM,class STATE>
  159. void operator()(Event const&,FSM&,STATE& )
  160. {
  161. std::cout << "starting: Region2State1" << std::endl;
  162. }
  163. };
  164. BOOST_MSM_EUML_ACTION(Region2State1_Exit)
  165. {
  166. template <class Event,class FSM,class STATE>
  167. void operator()(Event const&,FSM&,STATE& )
  168. {
  169. std::cout << "finishing: Region2State1" << std::endl;
  170. }
  171. };
  172. BOOST_MSM_EUML_ACTION(Region2State2_Entry)
  173. {
  174. template <class Event,class FSM,class STATE>
  175. void operator()(Event const&,FSM&,STATE& )
  176. {
  177. std::cout << "starting: Region2State2" << std::endl;
  178. }
  179. };
  180. BOOST_MSM_EUML_ACTION(Region2State2_Exit)
  181. {
  182. template <class Event,class FSM,class STATE>
  183. void operator()(Event const&,FSM&,STATE& )
  184. {
  185. std::cout << "finishing: Region2State2" << std::endl;
  186. }
  187. };
  188. // transition actions for Playing
  189. BOOST_MSM_EUML_ACTION(start_next_song)
  190. {
  191. template <class FSM,class EVT,class SourceState,class TargetState>
  192. void operator()(EVT const& ,FSM&,SourceState& ,TargetState& )
  193. {
  194. std::cout << "Playing::start_next_song" << endl;
  195. }
  196. };
  197. BOOST_MSM_EUML_ACTION(start_prev_song)
  198. {
  199. template <class FSM,class EVT,class SourceState,class TargetState>
  200. void operator()(EVT const& ,FSM&,SourceState& ,TargetState& )
  201. {
  202. std::cout << "Playing::start_prev_song" << endl;
  203. }
  204. };
  205. // transition actions
  206. BOOST_MSM_EUML_ACTION(start_playback)
  207. {
  208. template <class FSM,class EVT,class SourceState,class TargetState>
  209. void operator()(EVT const& ,FSM&,SourceState& ,TargetState& )
  210. {
  211. cout << "player::start_playback" << endl;
  212. }
  213. };
  214. BOOST_MSM_EUML_ACTION(open_drawer)
  215. {
  216. template <class FSM,class EVT,class SourceState,class TargetState>
  217. void operator()(EVT const& ,FSM&,SourceState& ,TargetState& )
  218. {
  219. cout << "player::open_drawer" << endl;
  220. }
  221. };
  222. BOOST_MSM_EUML_ACTION(close_drawer)
  223. {
  224. template <class FSM,class EVT,class SourceState,class TargetState>
  225. void operator()(EVT const& ,FSM&,SourceState& ,TargetState& )
  226. {
  227. cout << "player::close_drawer" << endl;
  228. }
  229. };
  230. BOOST_MSM_EUML_ACTION(store_cd_info)
  231. {
  232. template <class FSM,class EVT,class SourceState,class TargetState>
  233. void operator()(EVT const&, FSM& ,SourceState& ,TargetState& )
  234. {
  235. cout << "player::store_cd_info" << endl;
  236. // it is now easy to use the message queue.
  237. // alternatively to the proces_ in the transition table, we could write:
  238. // fsm.process_event(play());
  239. }
  240. };
  241. BOOST_MSM_EUML_ACTION(stop_playback)
  242. {
  243. template <class FSM,class EVT,class SourceState,class TargetState>
  244. void operator()(EVT const& ,FSM&,SourceState& ,TargetState& )
  245. {
  246. cout << "player::stop_playback" << endl;
  247. }
  248. };
  249. BOOST_MSM_EUML_ACTION(pause_playback)
  250. {
  251. template <class FSM,class EVT,class SourceState,class TargetState>
  252. void operator()(EVT const& ,FSM&,SourceState& ,TargetState& )
  253. {
  254. cout << "player::pause_playback" << endl;
  255. }
  256. };
  257. BOOST_MSM_EUML_ACTION(resume_playback)
  258. {
  259. template <class FSM,class EVT,class SourceState,class TargetState>
  260. void operator()(EVT const& ,FSM&,SourceState& ,TargetState& )
  261. {
  262. cout << "player::resume_playback" << endl;
  263. }
  264. };
  265. BOOST_MSM_EUML_ACTION(stop_and_open)
  266. {
  267. template <class FSM,class EVT,class SourceState,class TargetState>
  268. void operator()(EVT const& ,FSM&,SourceState& ,TargetState& )
  269. {
  270. cout << "player::stop_and_open" << endl;
  271. }
  272. };
  273. BOOST_MSM_EUML_ACTION(stopped_again)
  274. {
  275. template <class FSM,class EVT,class SourceState,class TargetState>
  276. void operator()(EVT const& ,FSM&,SourceState& ,TargetState& )
  277. {
  278. cout << "player::stopped_again" << endl;
  279. }
  280. };
  281. BOOST_MSM_EUML_ACTION(report_error)
  282. {
  283. template <class FSM,class EVT,class SourceState,class TargetState>
  284. void operator()(EVT const& ,FSM&,SourceState& ,TargetState& )
  285. {
  286. cout << "player::report_error" << endl;
  287. }
  288. };
  289. BOOST_MSM_EUML_ACTION(report_end_error)
  290. {
  291. template <class FSM,class EVT,class SourceState,class TargetState>
  292. void operator()(EVT const& ,FSM&,SourceState& ,TargetState& )
  293. {
  294. cout << "player::report_end_error" << endl;
  295. }
  296. };
  297. BOOST_MSM_EUML_ACTION(internal_action1)
  298. {
  299. template <class FSM,class EVT,class SourceState,class TargetState>
  300. void operator()(EVT const&, FSM& ,SourceState& ,TargetState& )
  301. {
  302. cout << "Open::internal action1" << endl;
  303. }
  304. };
  305. BOOST_MSM_EUML_ACTION(internal_action2)
  306. {
  307. template <class FSM,class EVT,class SourceState,class TargetState>
  308. void operator()(EVT const&, FSM& ,SourceState& ,TargetState& )
  309. {
  310. cout << "Open::internal action2" << endl;
  311. }
  312. };
  313. BOOST_MSM_EUML_ACTION(internal_action)
  314. {
  315. template <class FSM,class EVT,class SourceState,class TargetState>
  316. void operator()(EVT const&, FSM& ,SourceState& ,TargetState& )
  317. {
  318. cout << "Open::internal action" << endl;
  319. }
  320. };
  321. enum DiskTypeEnum
  322. {
  323. DISK_CD=0,
  324. DISK_DVD=1
  325. };
  326. // Handler called when no_transition detected
  327. BOOST_MSM_EUML_ACTION(Log_No_Transition)
  328. {
  329. template <class FSM,class Event>
  330. void operator()(Event const& e,FSM&,int state)
  331. {
  332. std::cout << "no transition from state " << state
  333. << " on event " << typeid(e).name() << std::endl;
  334. }
  335. };
  336. BOOST_MSM_EUML_ACTION(internal_guard1)
  337. {
  338. template <class FSM,class EVT,class SourceState,class TargetState>
  339. bool operator()(EVT const&, FSM& ,SourceState& ,TargetState& )
  340. {
  341. cout << "Open::internal guard1" << endl;
  342. return false;
  343. }
  344. };
  345. BOOST_MSM_EUML_ACTION(internal_guard2)
  346. {
  347. template <class FSM,class EVT,class SourceState,class TargetState>
  348. bool operator()(EVT const&, FSM& ,SourceState& ,TargetState& )
  349. {
  350. cout << "Open::internal guard2" << endl;
  351. return false;
  352. }
  353. };
  354. #endif // LOGGING_FUNCTORS