1 #ifndef _ots_RunControlStateMachine_h_
2 #define _ots_RunControlStateMachine_h_
4 #include "otsdaq/FiniteStateMachine/FiniteStateMachine.h"
5 #include "otsdaq/ProgressBar/ProgressBar.h"
8 #include "toolbox/lang/Class.h"
21 void setStateMachineName(
const std::string& name) { theStateMachine_.setStateMachineName(name); }
22 const std::string& getErrorMessage(
void)
const {
return theStateMachine_.getErrorMessage(); }
23 void setAsyncSoftErrorMessage(
const std::string& error)
25 asyncSoftFailureReceived_ =
true;
26 theStateMachine_.setErrorMessage(error);
29 template<
class OBJECT>
30 void addStateTransition(toolbox::fsm::State from,
31 toolbox::fsm::State to,
32 const std::string& input,
33 const std::string& transitionName,
35 void (OBJECT::*func)(toolbox::Event::Reference))
38 stateTransitionFunctionTable_[from][input] = func;
39 theStateMachine_.addStateTransition(from, to, input, transitionName, obj, func);
42 template<
class OBJECT>
43 void addStateTransition(toolbox::fsm::State from,
44 toolbox::fsm::State to,
45 const std::string& input,
46 const std::string& transitionName,
47 const std::string& transitionParameter,
49 void (OBJECT::*func)(toolbox::Event::Reference))
52 stateTransitionFunctionTable_[from][input] = func;
53 theStateMachine_.addStateTransition(from, to, input, transitionName, transitionParameter, obj, func);
62 virtual void stateInitial(toolbox::fsm::FiniteStateMachine& ) { ; }
69 virtual void statePaused(toolbox::fsm::FiniteStateMachine& ) { ; }
76 virtual void stateRunning(toolbox::fsm::FiniteStateMachine& ) { ; }
82 virtual void stateHalted(toolbox::fsm::FiniteStateMachine& ) { ; }
85 virtual void stateShutdown(toolbox::fsm::FiniteStateMachine& ) { ; }
92 virtual void stateConfigured(toolbox::fsm::FiniteStateMachine& ) { ; }
94 virtual void inError(toolbox::fsm::FiniteStateMachine& ) { ; }
96 virtual void transitionConfiguring(toolbox::Event::Reference ) { ; }
97 virtual void transitionHalting(toolbox::Event::Reference ) { ; }
98 virtual void transitionShuttingDown(toolbox::Event::Reference ) { ; }
99 virtual void transitionStartingUp(toolbox::Event::Reference ) { ; }
100 virtual void transitionInitializing(toolbox::Event::Reference ) { ; }
101 virtual void transitionPausing(toolbox::Event::Reference ) { ; }
102 virtual void transitionResuming(toolbox::Event::Reference ) { ; }
103 virtual void transitionStarting(toolbox::Event::Reference ) { ; }
104 virtual void transitionStopping(toolbox::Event::Reference ) { ; }
105 virtual void enteringError(toolbox::Event::Reference ) { ; }
108 xoap::MessageReference runControlMessageHandler(xoap::MessageReference message);
110 static const std::string FAILED_STATE_NAME;
111 static const std::string HALTED_STATE_NAME;
113 unsigned int getIterationIndex(
void) {
return iterationIndex_; }
114 unsigned int getSubIterationIndex(
void) {
return subIterationIndex_; }
115 void indicateIterationWork(
void) { iterationWorkFlag_ =
true; }
116 void clearIterationWork(
void) { iterationWorkFlag_ =
false; }
117 bool getIterationWork(
void) {
return iterationWorkFlag_; }
118 void indicateSubIterationWork(
void) { subIterationWorkFlag_ =
true; }
119 void clearSubIterationWork(
void) { subIterationWorkFlag_ =
false; }
120 bool getSubIterationWork(
void) {
return subIterationWorkFlag_; }
126 volatile bool asyncFailureReceived_, asyncSoftFailureReceived_;
128 unsigned int iterationIndex_, subIterationIndex_;
129 bool iterationWorkFlag_, subIterationWorkFlag_;
131 toolbox::fsm::State lastIterationState_;
132 std::string lastIterationCommand_;
133 std::string lastIterationResult_;
134 unsigned int lastIterationIndex_, lastSubIterationIndex_;
136 std::map<toolbox::fsm::State, std::map<std::string, void (RunControlStateMachine::*)(toolbox::Event::Reference), std::less<std::string> > >
137 stateTransitionFunctionTable_;