$treeview $search $mathjax $extrastylesheet
otsdaq
v2_03_00
$projectbrief
|
$projectbrief
|
$searchbox |
00001 #ifndef _ots_FiniteStateMachine_h 00002 #define _ots_FiniteStateMachine_h 00003 00004 #include <toolbox/fsm/FiniteStateMachine.h> 00005 #include <xoap/MessageReference.h> 00006 00007 namespace ots 00008 { 00009 class FiniteStateMachine : public toolbox::fsm::FiniteStateMachine 00010 { 00011 public: 00012 FiniteStateMachine(const std::string& stateMachineName); 00013 ~FiniteStateMachine(void); 00014 00015 using toolbox::fsm::FiniteStateMachine::addStateTransition; 00016 00017 template<class OBJECT> 00018 void addStateTransition(toolbox::fsm::State from, 00019 toolbox::fsm::State to, 00020 const std::string& input, 00021 const std::string& transitionName, 00022 OBJECT* obj, 00023 void (OBJECT::*func)(toolbox::Event::Reference)) 00024 00025 { 00026 stateTransitionNameTable_[from][input] = transitionName; 00027 toolbox::fsm::FiniteStateMachine::addStateTransition(from, to, input, obj, func); 00028 } 00029 00030 template<class OBJECT> 00031 void addStateTransition(toolbox::fsm::State from, 00032 toolbox::fsm::State to, 00033 const std::string& input, 00034 const std::string& transitionName, 00035 const std::string& transitionParameter, 00036 OBJECT* obj, 00037 void (OBJECT::*func)(toolbox::Event::Reference)) 00038 00039 { 00040 stateTransitionParameterTable_[from][input] = transitionParameter; 00041 addStateTransition(from, to, input, transitionName, obj, func); 00042 } 00043 00044 toolbox::fsm::State getProvenanceState(void); 00045 toolbox::fsm::State getTransitionFinalState(const std::string& transition); 00046 00047 std::string getProvenanceStateName(void); 00048 std::string getCurrentStateName(void); 00049 time_t getTimeInState(void); 00050 std::string getCurrentTransitionName(const std::string& transition); 00051 std::string getTransitionName(const toolbox::fsm::State from, 00052 const std::string& transition); 00053 std::string getTransitionParameter(const toolbox::fsm::State from, 00054 const std::string& transition); 00055 std::string getTransitionFinalStateName(const std::string& transition); 00056 const std::string& getErrorMessage() const; 00057 const std::string& getStateMachineName(void) const { return stateMachineName_; } 00058 void setStateMachineName(const std::string& name) { stateMachineName_ = name; } 00059 00060 const xoap::MessageReference& getCurrentMessage(void); 00061 00062 bool execTransition(const std::string& transition); 00063 bool execTransition(const std::string& transition, 00064 const xoap::MessageReference& message); 00065 bool isInTransition(void); 00066 void setInitialState(toolbox::fsm::State state); 00067 void setErrorMessage(const std::string& errMessage, bool append = true); 00068 00069 protected: 00070 time_t stateEntranceTime_; 00071 00072 // The volatile keyword indicates that a field might be modified by multiple 00073 // concurrently executing threads. Fields that are declared volatile are not subject 00074 // to compiler optimizations that assume access by a single thread. This ensures that 00075 // the most up-to-date value is present in the field at all times. If you don't mark 00076 // it volatile, the generated code might optimize the value into a registry and your 00077 // thread will never see the change The atomicity has nothing to do with the 00078 // visibility between threads... just because an operation is executed in one CPU 00079 // cycle (atomic) it doesn't mean that the result will be visible to the other threads 00080 // unless the value is marked volatile 00081 volatile bool inTransition_; 00082 toolbox::fsm::State provenanceState_; 00083 std::map<toolbox::fsm::State, 00084 std::map<std::string, std::string, std::less<std::string> > > 00085 stateTransitionNameTable_; 00086 std::map<toolbox::fsm::State, 00087 std::map<std::string, std::string, std::less<std::string> > > 00088 stateTransitionParameterTable_; 00089 00090 xoap::MessageReference theMessage_; 00091 std::string theErrorMessage_; 00092 std::string stateMachineName_; 00093 00094 private: 00095 }; 00096 00097 } // namespace ots 00098 00099 #endif