CMS 3D CMS Logo

evf::EPStateMachine Class Reference

#include <EventFilter/Utilities/interface/EPStateMachine.h>

List of all members.

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)
 Calls FiniteStateMachine::fireEvent() and keeps stateName_ and state_ in sync.
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)
 Calls FiniteStateMachine::reset() and keeps stateName_ and state_ in sync.
void stateChanged (toolbox::fsm::FiniteStateMachine &fsm) throw (toolbox::fsm::exception::Exception)

Public Attributes

toolbox::fsm::State state_
 Application state as an "integer" - to be used in the application.
xdata::String stateName_
 Application state as a string - to be used an exported parameter for run-control.

Private Attributes

log4cplus::Logger & logger_


Detailed Description

Definition at line 15 of file EPStateMachine.h.


Constructor & Destructor Documentation

evf::EPStateMachine::EPStateMachine ( log4cplus::Logger &  logger  ) 

Definition at line 8 of file EPStateMachine.cc.

00008                                                         : logger_(logger)
00009   {
00010   }


Member Function Documentation

xoap::MessageReference evf::EPStateMachine::createFSMReplyMsg ( const std::string  cmd,
const std::string  state 
)

Definition at line 33 of file EPStateMachine.cc.

References alivecheck_mergeAndRegister::body, and alivecheck_mergeAndRegister::msg.

00035   {
00036     xoap::MessageReference msg = xoap::createMessage();
00037     xoap::SOAPEnvelope     env   = msg->getSOAPPart().getEnvelope();
00038     xoap::SOAPBody         body  = env.getBody();
00039     std::string            rStr  = cmd + "Response";
00040     xoap::SOAPName         rName = env.createName(rStr,"xdaq",XDAQ_NS_URI);
00041     xoap::SOAPBodyElement  rElem = body.addBodyElement(rName);
00042     xoap::SOAPName       sName = env.createName("state","xdaq",XDAQ_NS_URI);
00043     xoap::SOAPElement      sElem = rElem.addChildElement(sName);
00044     xoap::SOAPName   aName = env.createName("stateName","xdaq",XDAQ_NS_URI);
00045   
00046   
00047     sElem.addAttribute(aName, state);
00048   
00049     return msg;
00050   }

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().

00070       {
00071         toolbox::fsm::FailedEvent &fe =
00072           dynamic_cast<toolbox::fsm::FailedEvent&>(*e);
00073         
00074         LOG4CPLUS_FATAL(logger_,
00075                         "Failure occurred when performing transition from: "
00076                         << fe.getFromState() <<  " to: " << fe.getToState()
00077                         << " exception: " << fe.getException().what());
00078       }

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 e, Exception, logger_, state_, and stateName_.

00108       {
00109         try{
00110           FiniteStateMachine::fireEvent(e);
00111         }
00112         catch(toolbox::fsm::exception::Exception ex)
00113           {
00114             LOG4CPLUS_ERROR(logger_,"EPStateMachine fireEvent failed " 
00115                             << ex.what());
00116             }  
00117         catch(...)
00118           {
00119               LOG4CPLUS_ERROR(logger_,"EPStateMachine fireEvent failed " 
00120                               << " Unknown Exception " << " state is " 
00121                               << FiniteStateMachine::getCurrentState());
00122           }
00123         
00124         
00125         state_     = FiniteStateMachine::getCurrentState();
00126         stateName_ = FiniteStateMachine::getStateName(state_);
00127       }

template<class T>
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().

00033         {
00034           // Define FSM states
00035           addState('H', "Halted"   , this, &EPStateMachine::stateChanged);
00036           addState('R', "Ready"    , this, &EPStateMachine::stateChanged);
00037           addState('E', "Enabled"  , this, &EPStateMachine::stateChanged);
00038           addState('S', "Suspended", this, &EPStateMachine::stateChanged);
00039           
00040           // Define FSM transitions
00041           addStateTransition('H', 'R', "Configure", me, &T::configureAction);
00042           addStateTransition('R', 'E', "Enable",    me, &T::enableAction);
00043           addStateTransition('E', 'R', "Stop",      me, &T::stopAction);
00044           addStateTransition('E', 'S', "Suspend",   me, &T::suspendAction);
00045           addStateTransition('S', 'E', "Resume",    me, &T::resumeAction);
00046           addStateTransition('H', 'H', "Halt",      me, &T::nullAction);
00047           addStateTransition('R', 'H', "Halt",      me, &T::haltAction);
00048           addStateTransition('E', 'H', "Halt",      me, &T::haltAction);
00049           addStateTransition('S', 'H', "Halt",      me, &T::haltAction);
00050           
00051           setFailedStateTransitionAction(this,&EPStateMachine::failedTransition);
00052           setFailedStateTransitionChanged(this,&EPStateMachine::stateChanged);
00053           
00054           setInitialState('H');
00055           reset();
00056           
00057           xoap::bind(me,&T::fireEvent,"Configure", XDAQ_NS_URI);
00058           xoap::bind(me,&T::fireEvent,"Stop"     , XDAQ_NS_URI);
00059           xoap::bind(me,&T::fireEvent,"Enable"   , XDAQ_NS_URI);
00060           xoap::bind(me,&T::fireEvent,"Suspend"  , XDAQ_NS_URI);
00061           xoap::bind(me,&T::fireEvent,"Resume"   , XDAQ_NS_URI);
00062           xoap::bind(me,&T::fireEvent,"Halt"     , XDAQ_NS_URI);
00063           xoap::bind(me,&T::fireEvent,"Disable"  , XDAQ_NS_URI); 
00064           xoap::bind(me,&T::fireEvent,"Fail"     , XDAQ_NS_URI); 
00065         }

xoap::MessageReference evf::EPStateMachine::processFSMCommand ( const std::string  cmdName  )  throw (xoap::exception::Exception)

Definition at line 12 of file EPStateMachine.cc.

References e, and Exception.

Referenced by dqm::StateMachine::dispatch(), and dqm::StateMachine::fireEvent().

00014   {
00015     try
00016       {
00017         // Change state, calling the appropriate action method
00018         toolbox::Event::Reference evtRef(new toolbox::Event(cmdName, this));
00019         fireEvent(evtRef);
00020         return createFSMReplyMsg(cmdName, stateName_);
00021       }
00022     catch(xcept::Exception e)
00023       {
00024         XCEPT_RETHROW(xoap::exception::Exception,
00025                       "Failed to process " + cmdName, e);
00026       }
00027     catch(...)
00028       {
00029         XCEPT_RAISE(xoap::exception::Exception,
00030                     "Failed to process " + cmdName + " - Unknown exception");
00031       }
00032   }

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 reset(), state_, and stateName_.

Referenced by init().

00094       {
00095         FiniteStateMachine::reset();
00096         
00097         state_     = FiniteStateMachine::getCurrentState();
00098         stateName_ = FiniteStateMachine::getStateName(state_);
00099       }

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().

00082       {
00083         LOG4CPLUS_INFO(logger_,
00084                        "Changed to state: "
00085                        << getStateName(getCurrentState()));
00086       }


Member Data Documentation

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().


The documentation for this class was generated from the following files:
Generated on Tue Jun 9 18:46:47 2009 for CMSSW by  doxygen 1.5.4