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