CMS 3D CMS Logo

Public Member Functions | Public Attributes | Private Attributes

evf::EPStateMachine Class Reference

#include <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)
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_

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.

                                                        : logger_(logger)
  {
  }

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 MatrixRunner::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 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_);
      }
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().

        {
          // 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 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()));
      }

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

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