#include <EPStateMachine.h>
Public Member Functions | |
xoap::MessageReference | createFSMReplyMsg (const std::string cmd, const std::string state) |
EPStateMachine (log4cplus::Logger &logger) | |
void | failedTransition (toolbox::Event::Reference e) throw (toolbox::fsm::exception::Exception) |
void | fireEvent (toolbox::Event::Reference e) throw (toolbox::fsm::exception::Exception) |
template<class T > | |
void | init (T *me) |
xoap::MessageReference | processFSMCommand (const std::string cmdName) throw (xoap::exception::Exception) |
void | reset () throw (toolbox::fsm::exception::Exception) |
void | stateChanged (toolbox::fsm::FiniteStateMachine &fsm) throw (toolbox::fsm::exception::Exception) |
Public Attributes | |
toolbox::fsm::State | state_ |
xdata::String | stateName_ |
Private Attributes | |
log4cplus::Logger & | logger_ |
Definition at line 15 of file EPStateMachine.h.
evf::EPStateMachine::EPStateMachine | ( | log4cplus::Logger & | logger | ) |
Definition at line 8 of file EPStateMachine.cc.
xoap::MessageReference evf::EPStateMachine::createFSMReplyMsg | ( | const std::string | cmd, |
const std::string | state | ||
) |
Definition at line 33 of file EPStateMachine.cc.
References lumiQueryAPI::msg.
{ xoap::MessageReference msg = xoap::createMessage(); xoap::SOAPEnvelope env = msg->getSOAPPart().getEnvelope(); xoap::SOAPBody body = env.getBody(); std::string rStr = cmd + "Response"; xoap::SOAPName rName = env.createName(rStr,"xdaq",XDAQ_NS_URI); xoap::SOAPBodyElement rElem = body.addBodyElement(rName); xoap::SOAPName sName = env.createName("state","xdaq",XDAQ_NS_URI); xoap::SOAPElement sElem = rElem.addChildElement(sName); xoap::SOAPName aName = env.createName("stateName","xdaq",XDAQ_NS_URI); sElem.addAttribute(aName, state); return msg; }
void evf::EPStateMachine::failedTransition | ( | toolbox::Event::Reference | e | ) | throw (toolbox::fsm::exception::Exception) [inline] |
Definition at line 68 of file EPStateMachine.h.
References logger_.
Referenced by init().
{ toolbox::fsm::FailedEvent &fe = dynamic_cast<toolbox::fsm::FailedEvent&>(*e); LOG4CPLUS_FATAL(logger_, "Failure occurred when performing transition from: " << fe.getFromState() << " to: " << fe.getToState() << " exception: " << fe.getException().what()); }
void evf::EPStateMachine::fireEvent | ( | toolbox::Event::Reference | e | ) | throw (toolbox::fsm::exception::Exception) [inline] |
Calls FiniteStateMachine::fireEvent() and keeps stateName_ and state_ in sync.
Definition at line 106 of file EPStateMachine.h.
References alignCSCRings::e, Exception, logger_, state_, and stateName_.
{ try{ FiniteStateMachine::fireEvent(e); } catch(toolbox::fsm::exception::Exception ex) { LOG4CPLUS_ERROR(logger_,"EPStateMachine fireEvent failed " << ex.what()); } catch(...) { LOG4CPLUS_ERROR(logger_,"EPStateMachine fireEvent failed " << " Unknown Exception " << " state is " << FiniteStateMachine::getCurrentState()); } state_ = FiniteStateMachine::getCurrentState(); stateName_ = FiniteStateMachine::getStateName(state_); }
void evf::EPStateMachine::init | ( | T * | me | ) | [inline] |
Definition at line 32 of file EPStateMachine.h.
References failedTransition(), reset(), and stateChanged().
Referenced by dqm::StateMachine::StateMachine().
{ // Define FSM states addState('H', "Halted" , this, &EPStateMachine::stateChanged); addState('R', "Ready" , this, &EPStateMachine::stateChanged); addState('E', "Enabled" , this, &EPStateMachine::stateChanged); addState('S', "Suspended", this, &EPStateMachine::stateChanged); // Define FSM transitions addStateTransition('H', 'R', "Configure", me, &T::configureAction); addStateTransition('R', 'E', "Enable", me, &T::enableAction); addStateTransition('E', 'R', "Stop", me, &T::stopAction); addStateTransition('E', 'S', "Suspend", me, &T::suspendAction); addStateTransition('S', 'E', "Resume", me, &T::resumeAction); addStateTransition('H', 'H', "Halt", me, &T::nullAction); addStateTransition('R', 'H', "Halt", me, &T::haltAction); addStateTransition('E', 'H', "Halt", me, &T::haltAction); addStateTransition('S', 'H', "Halt", me, &T::haltAction); setFailedStateTransitionAction(this,&EPStateMachine::failedTransition); setFailedStateTransitionChanged(this,&EPStateMachine::stateChanged); setInitialState('H'); reset(); xoap::bind(me,&T::fireEvent,"Configure", XDAQ_NS_URI); xoap::bind(me,&T::fireEvent,"Stop" , XDAQ_NS_URI); xoap::bind(me,&T::fireEvent,"Enable" , XDAQ_NS_URI); xoap::bind(me,&T::fireEvent,"Suspend" , XDAQ_NS_URI); xoap::bind(me,&T::fireEvent,"Resume" , XDAQ_NS_URI); xoap::bind(me,&T::fireEvent,"Halt" , XDAQ_NS_URI); xoap::bind(me,&T::fireEvent,"Disable" , XDAQ_NS_URI); xoap::bind(me,&T::fireEvent,"Fail" , XDAQ_NS_URI); }
xoap::MessageReference evf::EPStateMachine::processFSMCommand | ( | const std::string | cmdName | ) | throw (xoap::exception::Exception) |
Definition at line 12 of file EPStateMachine.cc.
References alignCSCRings::e, and Exception.
Referenced by dqm::StateMachine::dispatch().
{ try { // Change state, calling the appropriate action method toolbox::Event::Reference evtRef(new toolbox::Event(cmdName, this)); fireEvent(evtRef); return createFSMReplyMsg(cmdName, stateName_); } catch(xcept::Exception e) { XCEPT_RETHROW(xoap::exception::Exception, "Failed to process " + cmdName, e); } catch(...) { XCEPT_RAISE(xoap::exception::Exception, "Failed to process " + cmdName + " - Unknown exception"); } }
void evf::EPStateMachine::reset | ( | void | ) | throw (toolbox::fsm::exception::Exception) [inline] |
Calls FiniteStateMachine::reset() and keeps stateName_ and state_ in sync.
Definition at line 93 of file EPStateMachine.h.
References state_, and stateName_.
Referenced by init().
{ FiniteStateMachine::reset(); state_ = FiniteStateMachine::getCurrentState(); stateName_ = FiniteStateMachine::getStateName(state_); }
void evf::EPStateMachine::stateChanged | ( | toolbox::fsm::FiniteStateMachine & | fsm | ) | throw (toolbox::fsm::exception::Exception) [inline] |
Definition at line 80 of file EPStateMachine.h.
References logger_.
Referenced by init().
{ LOG4CPLUS_INFO(logger_, "Changed to state: " << getStateName(getCurrentState())); }
log4cplus::Logger& evf::EPStateMachine::logger_ [private] |
Definition at line 135 of file EPStateMachine.h.
Referenced by failedTransition(), fireEvent(), and stateChanged().
toolbox::fsm::State evf::EPStateMachine::state_ |
Application state as an "integer" - to be used in the application
Definition at line 22 of file EPStateMachine.h.
Referenced by fireEvent(), and reset().
xdata::String evf::EPStateMachine::stateName_ |
Application state as a string - to be used an exported parameter for run-control.
Definition at line 29 of file EPStateMachine.h.
Referenced by fireEvent(), reset(), and dqm::StateMachine::stateName().