CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
SMEventScheduler.cc
Go to the documentation of this file.
1 //
3 // SMEventScheduler.h
4 // -------
5 //
6 // Holds and executes a list FIFO of FSM transition events.
7 //
8 // Created on: Dec 13, 2011
9 // Andrei Spataru : aspataru@cern.ch
11 
13 
14 #include <string>
15 #include <iostream>
16 
17 using namespace evf::rb_statemachine;
18 using namespace evf;
19 
20 using std::string;
21 using std::cout;
22 using std::endl;
23 
25  fsm_(fsm), commands_(comms), continueWorkloop_(true) {
26 
28 }
29 
32 }
33 
34 //______________________________________________________________________________
36  try {
37  //improve log instead of cout
38  cout << "Start 'SCHEDULER EVENT PROCESSING' workloop" << endl;
39  wlProcessingEvents_ = toolbox::task::getWorkLoopFactory()->getWorkLoop(
40  "Scheduler Processing Events", "waiting");
41  if (!wlProcessingEvents_->isActive())
42  wlProcessingEvents_->activate();
43  asProcessingEvents_ = toolbox::task::bind(this,
44  &SMEventScheduler::processing, "SchedulerProcessing");
46  } catch (xcept::Exception& e) {
47  string msg = "Failed to start workloop 'SCHEDULER EVENT PROCESSING'.";
48  //improve log instead of cout
49  cout << msg << endl;
50  }
51 }
52 
53 //______________________________________________________________________________
54 bool SMEventScheduler::processing(toolbox::task::WorkLoop* wl) {
55  // deqEvent() blocks until a command is present in the queue
56  EventPtr topEvent = commands_.deqEvent();
57 
58  // 0. lock state transition
59  fsm_->transitionWriteLock();
60  // 1. process top event from the queue
61  fsm_->process_event(*topEvent);
62  // 1.5 unlock state transition
63  fsm_->transitionUnlock();
64 
65  // 2. update state of the FSM, also notifying RCMS
66  /*
67  * XXX casting away constness for the state Notification call
68  * done because state stateChanged in rcmsStateListener is not const
69  * stateNotify does not change BaseState& so operation is safe
70  */
71  const_cast<BaseState&> (fsm_->getCurrentState()).do_stateNotify();
72 
73  // 3. perform state-specific action
74  fsm_->getCurrentState().do_stateAction();
75 
76  return continueWorkloop_;
77 }
boost::shared_ptr< boost::statechart::event_base > EventPtr
Definition: CommandQueue.h:23
toolbox::task::WorkLoop * wlProcessingEvents_
bool processing(toolbox::task::WorkLoop *wl)
SMEventScheduler(RBStateMachinePtr fsm, CommandQueue &commands_)
boost::shared_ptr< RBStateMachine > RBStateMachinePtr
toolbox::task::ActionSignature * asProcessingEvents_
tuple cout
Definition: gather_cfg.py:121