CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
States.h
Go to the documentation of this file.
1 // $Id: States.h,v 1.2 2011/03/07 15:41:54 mommsen Exp $
3 
4 #ifndef EventFilter_SMProxyServer_States_h
5 #define EventFilter_SMProxyServer_States_h
6 
8 
9 #include "xcept/Exception.h"
10 
11 #include <boost/mpl/list.hpp>
12 #include <boost/thread/thread.hpp>
13 #include <boost/scoped_ptr.hpp>
14 #include <boost/statechart/custom_reaction.hpp>
15 #include <boost/statechart/event.hpp>
16 #include <boost/statechart/state.hpp>
17 #include <boost/statechart/transition.hpp>
18 
19 #include <string>
20 
21 
22 namespace smproxy
23 {
24 
26  // Forward declarations of state classes //
28 
29  // Outer states:
30  class Failed;
31  class AllOk;
32  // Inner states of AllOk
33  class Constructed;
34  class Halted;
35  class Configuring;
36  class Ready;
37  class Enabled;
38  class Stopping;
39  class Halting;
40  // Inner states of Enabled
41  class Starting;
42  class Running;
43 
44 
46  // Internal transition events //
48 
49  class ConfiguringDone: public boost::statechart::event<ConfiguringDone> {};
50  class StartingDone: public boost::statechart::event<StartingDone> {};
51  class StoppingDone: public boost::statechart::event<StoppingDone> {};
52  class HaltingDone: public boost::statechart::event<HaltingDone> {};
53 
54 
56  // Wrapper state template //
58 
59  template< class MostDerived,
60  class Context,
61  class InnerInitial = boost::mpl::list<>,
62  boost::statechart::history_mode historyMode = boost::statechart::has_no_history >
63  class State : public StateName,
64  public boost::statechart::state<MostDerived, Context, InnerInitial, historyMode>
65  {
66  public:
67  std::string stateName() const
68  { return stateName_; }
69 
70  protected:
71  typedef boost::statechart::state<MostDerived, Context, InnerInitial, historyMode> boost_state;
72  typedef State my_state;
73 
74  State(const std::string stateName, typename boost_state::my_context& c) :
75  boost_state(c), stateName_(stateName) {};
76  virtual ~State() {};
77 
78  virtual void entryAction() {};
79  virtual void exitAction() {};
80 
81  const std::string stateName_;
82 
84  {
85  std::string msg = "Failed to enter " + stateName_ + " state";
86  try
87  {
88  entryAction();
89  }
90  catch( xcept::Exception& e )
91  {
92  XCEPT_DECLARE_NESTED(exception::StateTransition,
93  sentinelException, msg, e );
94  this->post_event( Fail(sentinelException) );
95  }
96  catch( std::exception& e )
97  {
98  msg += ": ";
99  msg += e.what();
100  XCEPT_DECLARE(exception::StateTransition,
101  sentinelException, msg );
102  this->post_event( Fail(sentinelException) );
103  }
104  catch(...)
105  {
106  msg += ": unknown exception";
107  XCEPT_DECLARE(exception::StateTransition,
108  sentinelException, msg );
109  this->post_event( Fail(sentinelException) );
110  }
111  };
112 
114  {
115  std::string msg = "Failed to leave " + stateName_ + " state";
116  try
117  {
118  exitAction();
119  }
120  catch( xcept::Exception& e )
121  {
122  XCEPT_DECLARE_NESTED(exception::StateTransition,
123  sentinelException, msg, e );
124  this->post_event( Fail(sentinelException) );
125  }
126  catch( std::exception& e )
127  {
128  msg += ": ";
129  msg += e.what();
130  XCEPT_DECLARE(exception::StateTransition,
131  sentinelException, msg );
132  this->post_event( Fail(sentinelException) );
133  }
134  catch(...)
135  {
136  msg += ": unknown exception";
137  XCEPT_DECLARE(exception::StateTransition,
138  sentinelException, msg );
139  this->post_event( Fail(sentinelException) );
140  }
141  };
142 
143  };
144 
145 
147  // State classes //
149 
153  class Failed: public State<Failed,StateMachine>
154  {
155 
156  public:
157 
158  typedef boost::mpl::list<
159  boost::statechart::transition<Fail,Failed>
161 
162  Failed(my_context c) : my_state("Failed", c)
163  { safeEntryAction(); }
164  virtual ~Failed()
165  { safeExitAction(); }
166 
167  };
168 
172  class AllOk: public State<AllOk,StateMachine,Constructed>
173  {
174 
175  public:
176 
177  typedef boost::mpl::list<
178  boost::statechart::transition<Fail,Failed,StateMachine,&StateMachine::failEvent>
180 
181  AllOk(my_context c) : my_state("AllOk", c)
182  { safeEntryAction(); }
183  virtual ~AllOk()
184  { safeExitAction(); }
185 
186  };
187 
188 
192  class Constructed: public State<Constructed,AllOk>
193  {
194 
195  public:
196 
197  typedef boost::mpl::list<
198  boost::statechart::transition<Configure,Configuring>
200 
201  Constructed(my_context c) : my_state("Constructed", c)
202  { safeEntryAction(); }
203  virtual ~Constructed()
204  { safeExitAction(); }
205 
206  };
207 
208 
212  class Halted: public State<Halted,AllOk>
213  {
214 
215  public:
216 
217  typedef boost::mpl::list<
218  boost::statechart::transition<Configure,Configuring>
220 
221  Halted(my_context c) : my_state("Halted", c)
222  { safeEntryAction(); }
223  virtual ~Halted()
224  { safeExitAction(); }
225 
226  virtual void entryAction()
227  { outermost_context().setExternallyVisibleStateName("Halted"); }
228 
229  };
230 
231 
235  class Configuring: public State<Configuring,AllOk>
236  {
237 
238  public:
239 
240  typedef boost::mpl::list<
241  boost::statechart::transition<ConfiguringDone,Ready>
243 
244  Configuring(my_context c) : my_state("Configuring", c)
245  { safeEntryAction(); }
246  virtual ~Configuring()
247  { safeExitAction(); }
248 
249  virtual void entryAction();
250  virtual void exitAction();
251  void activity();
252 
253  private:
254  boost::scoped_ptr<boost::thread> configuringThread_;
255 
256  };
257 
258 
262  class Ready: public State<Ready,AllOk>
263  {
264 
265  public:
266 
267  typedef boost::mpl::list<
268  boost::statechart::transition<Enable,Enabled>,
269  boost::statechart::transition<Halt,Halted>
271 
272  Ready(my_context c) : my_state("Ready", c)
273  { safeEntryAction(); }
274  virtual ~Ready()
275  { safeExitAction(); }
276 
277  virtual void entryAction()
278  { outermost_context().setExternallyVisibleStateName("Ready"); }
279 
280  };
281 
282 
286  class Enabled: public State<Enabled,AllOk,Starting>
287  {
288 
289  public:
290 
291  typedef boost::mpl::list<
292  boost::statechart::transition<Stop,Stopping>,
293  boost::statechart::transition<Halt,Halting>
295 
296  Enabled(my_context c) : my_state("Enabled", c)
297  { safeEntryAction(); }
298  virtual ~Enabled()
299  { safeExitAction(); }
300 
301  // virtual void entryAction();
302  // virtual void exitAction();
303 
304  };
305 
306 
310  class Stopping: public State<Stopping,AllOk>
311  {
312 
313  public:
314 
315  typedef boost::mpl::list<
316  boost::statechart::transition<StoppingDone,Ready>
318 
319  Stopping(my_context c) : my_state("Stopping", c)
320  { safeEntryAction(); }
321  virtual ~Stopping()
322  { safeExitAction(); }
323 
324  virtual void entryAction();
325  virtual void exitAction();
326  void activity();
327 
328  private:
329  boost::scoped_ptr<boost::thread> stoppingThread_;
330 
331  };
332 
333 
337  class Halting: public State<Halting,AllOk>
338  {
339 
340  public:
341 
342  typedef boost::mpl::list<
343  boost::statechart::transition<HaltingDone,Halted>
345 
346  Halting(my_context c) : my_state("Halting", c)
347  { safeEntryAction(); }
348  virtual ~Halting()
349  { safeExitAction(); }
350 
351  virtual void entryAction();
352  virtual void exitAction();
353  void activity();
354 
355  private:
356  boost::scoped_ptr<boost::thread> haltingThread_;
357 
358  };
359 
360 
364  class Starting: public State<Starting,Enabled>
365  {
366 
367  public:
368 
369  typedef boost::mpl::list<
370  boost::statechart::transition<StartingDone,Running>
372 
373  Starting(my_context c) : my_state("Starting", c)
374  { safeEntryAction(); }
375  virtual ~Starting()
376  { safeExitAction(); }
377 
378  virtual void entryAction();
379  virtual void exitAction();
380  void activity();
381 
382  private:
383  boost::scoped_ptr<boost::thread> startingThread_;
384 
385  };
386 
387 
391  class Running: public State<Running,Enabled>
392  {
393 
394  public:
395 
396  Running(my_context c) : my_state("Running", c)
397  { safeEntryAction(); }
398  virtual ~Running()
399  { safeExitAction(); }
400 
401  virtual void entryAction()
402  { outermost_context().setExternallyVisibleStateName("Enabled"); }
403 
404  };
405 
406 
407 } //namespace smproxy
408 
409 #endif //SMProxyServer_States_h
410 
411 
virtual ~Halted()
Definition: States.h:223
virtual ~Configuring()
Definition: States.h:246
virtual ~Halting()
Definition: States.h:348
Enabled(my_context c)
Definition: States.h:296
boost::scoped_ptr< boost::thread > configuringThread_
Definition: States.h:254
const std::string stateName_
Definition: States.h:79
virtual void entryAction()
virtual void exitAction()
Configuring(my_context c)
Definition: States.h:244
reject
Definition: HLTenums.h:23
virtual ~Starting()
Definition: States.h:375
boost::mpl::list< boost::statechart::transition< Configure, Configuring > > reactions
Definition: States.h:219
void safeEntryAction()
Definition: States.h:83
Halting(my_context c)
Definition: States.h:346
virtual ~State()
Definition: States.h:76
boost::statechart::state< MostDerived, Context, InnerInitial, historyMode > boost_state
Definition: States.h:71
virtual ~Failed()
Definition: States.h:164
virtual void exitAction()
virtual ~Enabled()
Definition: States.h:298
Ready(my_context c)
Definition: States.h:272
virtual void entryAction()
Definition: States.h:226
State my_state
Definition: States.h:72
Constructed(my_context c)
Definition: States.h:201
virtual ~AllOk()
Definition: States.h:183
AllOk(my_context c)
Definition: States.h:181
virtual void entryAction()
virtual void exitAction()
virtual ~Constructed()
Definition: States.h:203
virtual void entryAction()
Starting(my_context c)
Definition: States.h:373
State(const std::string stateName, typename boost_state::my_context &c)
Definition: States.h:74
virtual void entryAction()
Definition: States.h:401
boost::scoped_ptr< boost::thread > startingThread_
Definition: States.h:383
boost::mpl::list< boost::statechart::transition< Fail, Failed > > reactions
Definition: States.h:160
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
Failed(my_context c)
Definition: States.h:162
virtual void entryAction()
Definition: States.h:277
Stopping(my_context c)
Definition: States.h:319
Running(my_context c)
Definition: States.h:396
std::string stateName() const
Definition: States.h:67
boost::scoped_ptr< boost::thread > stoppingThread_
Definition: States.h:329
Halted(my_context c)
Definition: States.h:221
void safeExitAction()
Definition: States.h:113
virtual ~Ready()
Definition: States.h:274
boost::mpl::list< boost::statechart::transition< StartingDone, Running > > reactions
Definition: States.h:371
char state
Definition: procUtils.cc:75
boost::mpl::list< boost::statechart::transition< StoppingDone, Ready > > reactions
Definition: States.h:317
virtual ~Running()
Definition: States.h:398
virtual ~Stopping()
Definition: States.h:321
boost::mpl::list< boost::statechart::transition< Enable, Enabled >, boost::statechart::transition< Halt, Halted > > reactions
Definition: States.h:270
virtual void exitAction()
Definition: States.h:79
virtual void entryAction()
Definition: States.h:78
boost::mpl::list< boost::statechart::transition< HaltingDone, Halted > > reactions
Definition: States.h:344
boost::mpl::list< boost::statechart::transition< ConfiguringDone, Ready > > reactions
Definition: States.h:242
virtual void exitAction()
boost::mpl::list< boost::statechart::transition< Stop, Stopping >, boost::statechart::transition< Halt, Halting > > reactions
Definition: States.h:294
boost::mpl::list< boost::statechart::transition< Configure, Configuring > > reactions
Definition: States.h:199
boost::mpl::list< boost::statechart::transition< Fail, Failed, StateMachine,&StateMachine::failEvent > > reactions
Definition: States.h:179
boost::scoped_ptr< boost::thread > haltingThread_
Definition: States.h:356
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger list("!*","!HLTx*"if it matches 2 triggers or more) will accept the event if all the matching triggers are FAIL.It will reject the event if any of the triggers are PASS or EXCEPTION(this matches the behavior of"!*"before the partial wildcard feature was incorporated).Triggers which are in the READY state are completely ignored.(READY should never be returned since the trigger paths have been run
virtual void entryAction()