]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/msm/doc/PDF/examples/logging_functors.h
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)
11 #ifndef LOGGING_FUNCTORS
12 #define LOGGING_FUNCTORS
14 BOOST_MSM_EUML_ACTION(Empty_Entry
)
16 template <class Event
,class FSM
,class STATE
>
17 void operator()(Event
const&,FSM
&,STATE
& )
19 std::cout
<< "entering: Empty" << std::endl
;
22 BOOST_MSM_EUML_ACTION(Empty_Exit
)
24 template <class Event
,class FSM
,class STATE
>
25 void operator()(Event
const&,FSM
&,STATE
& )
27 std::cout
<< "leaving: Empty" << std::endl
;
31 BOOST_MSM_EUML_ACTION(Open_Entry
)
33 template <class Event
,class FSM
,class STATE
>
34 void operator()(Event
const&,FSM
&,STATE
& )
36 std::cout
<< "entering: Open" << std::endl
;
39 BOOST_MSM_EUML_ACTION(Open_Exit
)
41 template <class Event
,class FSM
,class STATE
>
42 void operator()(Event
const&,FSM
&,STATE
& )
44 std::cout
<< "leaving: Open" << std::endl
;
48 BOOST_MSM_EUML_ACTION(Stopped_Entry
)
50 template <class Event
,class FSM
,class STATE
>
51 void operator()(Event
const&,FSM
&,STATE
& )
53 std::cout
<< "entering: Stopped" << std::endl
;
56 BOOST_MSM_EUML_ACTION(Stopped_Exit
)
58 template <class Event
,class FSM
,class STATE
>
59 void operator()(Event
const&,FSM
&,STATE
& )
61 std::cout
<< "leaving: Stopped" << std::endl
;
65 BOOST_MSM_EUML_ACTION(AllOk_Entry
)
67 template <class Event
,class FSM
,class STATE
>
68 void operator()(Event
const&,FSM
&,STATE
& )
70 std::cout
<< "starting: AllOk" << std::endl
;
73 BOOST_MSM_EUML_ACTION(AllOk_Exit
)
75 template <class Event
,class FSM
,class STATE
>
76 void operator()(Event
const&,FSM
&,STATE
& )
78 std::cout
<< "finishing: AllOk" << std::endl
;
82 BOOST_MSM_EUML_ACTION(ErrorMode_Entry
)
84 template <class Event
,class FSM
,class STATE
>
85 void operator()(Event
const&,FSM
&,STATE
& )
87 std::cout
<< "starting: ErrorMode" << std::endl
;
90 BOOST_MSM_EUML_ACTION(ErrorMode_Exit
)
92 template <class Event
,class FSM
,class STATE
>
93 void operator()(Event
const&,FSM
&,STATE
& )
95 std::cout
<< "finishing: ErrorMode" << std::endl
;
99 BOOST_MSM_EUML_ACTION(Playing_Entry
)
101 template <class Event
,class FSM
,class STATE
>
102 void operator()(Event
const&,FSM
&,STATE
& )
104 std::cout
<< "entering: Playing" << std::endl
;
107 BOOST_MSM_EUML_ACTION(Playing_Exit
)
109 template <class Event
,class FSM
,class STATE
>
110 void operator()(Event
const&,FSM
&,STATE
& )
112 std::cout
<< "leaving: Playing" << std::endl
;
116 BOOST_MSM_EUML_ACTION(Song1_Entry
)
118 template <class Event
,class FSM
,class STATE
>
119 void operator()(Event
const&,FSM
&,STATE
& )
121 std::cout
<< "starting: First song" << std::endl
;
124 BOOST_MSM_EUML_ACTION(Song1_Exit
)
126 template <class Event
,class FSM
,class STATE
>
127 void operator()(Event
const&,FSM
&,STATE
& )
129 std::cout
<< "finishing: First Song" << std::endl
;
133 BOOST_MSM_EUML_ACTION(Song2_Entry
)
135 template <class Event
,class FSM
,class STATE
>
136 void operator()(Event
const&,FSM
&,STATE
& )
138 std::cout
<< "starting: Second song" << std::endl
;
141 BOOST_MSM_EUML_ACTION(Song2_Exit
)
143 template <class Event
,class FSM
,class STATE
>
144 void operator()(Event
const&,FSM
&,STATE
& )
146 std::cout
<< "finishing: Second Song" << std::endl
;
150 BOOST_MSM_EUML_ACTION(Song3_Entry
)
152 template <class Event
,class FSM
,class STATE
>
153 void operator()(Event
const&,FSM
&,STATE
& )
155 std::cout
<< "starting: Third song" << std::endl
;
158 BOOST_MSM_EUML_ACTION(Song3_Exit
)
160 template <class Event
,class FSM
,class STATE
>
161 void operator()(Event
const&,FSM
&,STATE
& )
163 std::cout
<< "finishing: Third Song" << std::endl
;
167 BOOST_MSM_EUML_ACTION(Region2State1_Entry
)
169 template <class Event
,class FSM
,class STATE
>
170 void operator()(Event
const&,FSM
&,STATE
& )
172 std::cout
<< "starting: Region2State1" << std::endl
;
175 BOOST_MSM_EUML_ACTION(Region2State1_Exit
)
177 template <class Event
,class FSM
,class STATE
>
178 void operator()(Event
const&,FSM
&,STATE
& )
180 std::cout
<< "finishing: Region2State1" << std::endl
;
183 BOOST_MSM_EUML_ACTION(Region2State2_Entry
)
185 template <class Event
,class FSM
,class STATE
>
186 void operator()(Event
const&,FSM
&,STATE
& )
188 std::cout
<< "starting: Region2State2" << std::endl
;
191 BOOST_MSM_EUML_ACTION(Region2State2_Exit
)
193 template <class Event
,class FSM
,class STATE
>
194 void operator()(Event
const&,FSM
&,STATE
& )
196 std::cout
<< "finishing: Region2State2" << std::endl
;
199 // transition actions for Playing
200 BOOST_MSM_EUML_ACTION(start_next_song
)
202 template <class FSM
,class EVT
,class SourceState
,class TargetState
>
203 void operator()(EVT
const& ,FSM
&,SourceState
& ,TargetState
& )
205 std::cout
<< "Playing::start_next_song" << endl
;
208 BOOST_MSM_EUML_ACTION(start_prev_song
)
210 template <class FSM
,class EVT
,class SourceState
,class TargetState
>
211 void operator()(EVT
const& ,FSM
&,SourceState
& ,TargetState
& )
213 std::cout
<< "Playing::start_prev_song" << endl
;
217 // transition actions
218 BOOST_MSM_EUML_ACTION(start_playback
)
220 template <class FSM
,class EVT
,class SourceState
,class TargetState
>
221 void operator()(EVT
const& ,FSM
&,SourceState
& ,TargetState
& )
223 cout
<< "player::start_playback" << endl
;
226 BOOST_MSM_EUML_ACTION(open_drawer
)
228 template <class FSM
,class EVT
,class SourceState
,class TargetState
>
229 void operator()(EVT
const& ,FSM
&,SourceState
& ,TargetState
& )
231 cout
<< "player::open_drawer" << endl
;
234 BOOST_MSM_EUML_ACTION(close_drawer
)
236 template <class FSM
,class EVT
,class SourceState
,class TargetState
>
237 void operator()(EVT
const& ,FSM
&,SourceState
& ,TargetState
& )
239 cout
<< "player::close_drawer" << endl
;
242 BOOST_MSM_EUML_ACTION(store_cd_info
)
244 template <class FSM
,class EVT
,class SourceState
,class TargetState
>
245 void operator()(EVT
const&, FSM
& ,SourceState
& ,TargetState
& )
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());
253 BOOST_MSM_EUML_ACTION(stop_playback
)
255 template <class FSM
,class EVT
,class SourceState
,class TargetState
>
256 void operator()(EVT
const& ,FSM
&,SourceState
& ,TargetState
& )
258 cout
<< "player::stop_playback" << endl
;
261 BOOST_MSM_EUML_ACTION(pause_playback
)
263 template <class FSM
,class EVT
,class SourceState
,class TargetState
>
264 void operator()(EVT
const& ,FSM
&,SourceState
& ,TargetState
& )
266 cout
<< "player::pause_playback" << endl
;
269 BOOST_MSM_EUML_ACTION(resume_playback
)
271 template <class FSM
,class EVT
,class SourceState
,class TargetState
>
272 void operator()(EVT
const& ,FSM
&,SourceState
& ,TargetState
& )
274 cout
<< "player::resume_playback" << endl
;
277 BOOST_MSM_EUML_ACTION(stop_and_open
)
279 template <class FSM
,class EVT
,class SourceState
,class TargetState
>
280 void operator()(EVT
const& ,FSM
&,SourceState
& ,TargetState
& )
282 cout
<< "player::stop_and_open" << endl
;
285 BOOST_MSM_EUML_ACTION(stopped_again
)
287 template <class FSM
,class EVT
,class SourceState
,class TargetState
>
288 void operator()(EVT
const& ,FSM
&,SourceState
& ,TargetState
& )
290 cout
<< "player::stopped_again" << endl
;
294 BOOST_MSM_EUML_ACTION(report_error
)
296 template <class FSM
,class EVT
,class SourceState
,class TargetState
>
297 void operator()(EVT
const& ,FSM
&,SourceState
& ,TargetState
& )
299 cout
<< "player::report_error" << endl
;
303 BOOST_MSM_EUML_ACTION(report_end_error
)
305 template <class FSM
,class EVT
,class SourceState
,class TargetState
>
306 void operator()(EVT
const& ,FSM
&,SourceState
& ,TargetState
& )
308 cout
<< "player::report_end_error" << endl
;
311 BOOST_MSM_EUML_ACTION(internal_action1
)
313 template <class FSM
,class EVT
,class SourceState
,class TargetState
>
314 void operator()(EVT
const&, FSM
& ,SourceState
& ,TargetState
& )
316 cout
<< "Open::internal action1" << endl
;
319 BOOST_MSM_EUML_ACTION(internal_action2
)
321 template <class FSM
,class EVT
,class SourceState
,class TargetState
>
322 void operator()(EVT
const&, FSM
& ,SourceState
& ,TargetState
& )
324 cout
<< "Open::internal action2" << endl
;
327 BOOST_MSM_EUML_ACTION(internal_action
)
329 template <class FSM
,class EVT
,class SourceState
,class TargetState
>
330 void operator()(EVT
const&, FSM
& ,SourceState
& ,TargetState
& )
332 cout
<< "Open::internal action" << endl
;
341 // Handler called when no_transition detected
342 BOOST_MSM_EUML_ACTION(Log_No_Transition
)
344 template <class FSM
,class Event
>
345 void operator()(Event
const& e
,FSM
&,int state
)
347 std::cout
<< "no transition from state " << state
348 << " on event " << typeid(e
).name() << std::endl
;
352 BOOST_MSM_EUML_ACTION(internal_guard1
)
354 template <class FSM
,class EVT
,class SourceState
,class TargetState
>
355 bool operator()(EVT
const&, FSM
& ,SourceState
& ,TargetState
& )
357 cout
<< "Open::internal guard1" << endl
;
361 BOOST_MSM_EUML_ACTION(internal_guard2
)
363 template <class FSM
,class EVT
,class SourceState
,class TargetState
>
364 bool operator()(EVT
const&, FSM
& ,SourceState
& ,TargetState
& )
366 cout
<< "Open::internal guard2" << endl
;
370 #endif // LOGGING_FUNCTORS