#include <StateMachine.h>
Public Member Functions | |
bool | checkIfEnabled () |
xoap::MessageReference | commandCallback (xoap::MessageReference msg) throw (xoap::exception::Exception) |
void | disableRcmsStateNotification () |
void | failed (toolbox::Event::Reference e) throw (toolbox::fsm::exception::Exception) |
void | findRcmsStateListener () |
void | fireEvent (const std::string &evtType, void *originator) |
void | fireFailed (const std::string &errorMsg, void *originator) |
xdata::Boolean * | foundRcmsStateListener () |
template<class T > | |
void | initialize (T *app) |
xdata::Bag < xdaq2rc::ClassnameAndInstance > * | rcmsStateListener () |
void | stateChanged (toolbox::fsm::FiniteStateMachine &fsm) throw (toolbox::fsm::exception::Exception) |
StateMachine (xdaq::Application *app) | |
xdata::String * | stateName () |
virtual | ~StateMachine () |
Private Attributes | |
xdata::InfoSpace * | appInfoSpace_ |
std::string | appNameAndInstance_ |
toolbox::task::ActionSignature * | asConfiguring_ |
toolbox::task::ActionSignature * | asEnabling_ |
toolbox::task::ActionSignature * | asHalting_ |
toolbox::task::ActionSignature * | asStopping_ |
bool | doStateNotification_ |
toolbox::fsm::FiniteStateMachine | fsm_ |
log4cplus::Logger | logger_ |
xdaq2rc::RcmsStateNotifier | rcmsStateNotifier_ |
xdata::String | stateName_ |
toolbox::task::WorkLoop * | workLoopConfiguring_ |
toolbox::task::WorkLoop * | workLoopEnabling_ |
toolbox::task::WorkLoop * | workLoopHalting_ |
toolbox::task::WorkLoop * | workLoopStopping_ |
Definition at line 28 of file StateMachine.h.
StateMachine::StateMachine | ( | xdaq::Application * | app | ) |
Definition at line 36 of file StateMachine.cc.
References appNameAndInstance_.
: logger_(app->getApplicationLogger()) , appInfoSpace_(app->getApplicationInfoSpace()) , doStateNotification_(true) , workLoopConfiguring_(0) , workLoopEnabling_(0) , workLoopStopping_(0) , workLoopHalting_(0) , asConfiguring_(0) , asEnabling_(0) , asStopping_(0) , asHalting_(0) , rcmsStateNotifier_(app->getApplicationLogger(), app->getApplicationDescriptor(), app->getApplicationContext()) { ostringstream oss; oss<<app->getApplicationDescriptor()->getClassName() <<app->getApplicationDescriptor()->getInstance(); appNameAndInstance_ = oss.str(); }
StateMachine::~StateMachine | ( | ) | [virtual] |
Definition at line 60 of file StateMachine.cc.
{ }
bool evf::StateMachine::checkIfEnabled | ( | ) | [inline] |
Definition at line 66 of file StateMachine.h.
References fsm_.
{return fsm_.getCurrentState()=='E';}
xoap::MessageReference StateMachine::commandCallback | ( | xoap::MessageReference | msg | ) | throw (xoap::exception::Exception) |
Definition at line 71 of file StateMachine.cc.
References edmPickEvents::command, alignCSCRings::e, web::browse_db::env, Exception, i, lumiQueryAPI::msg, and python::Node::node.
Referenced by evf::FUEventProcessor::fsmCallback().
{ xoap::SOAPPart part =msg->getSOAPPart(); xoap::SOAPEnvelope env =part.getEnvelope(); xoap::SOAPBody body =env.getBody(); DOMNode *node =body.getDOMNode(); DOMNodeList *bodyList=node->getChildNodes(); DOMNode *command =0; string commandName; for (unsigned int i=0;i<bodyList->getLength();i++) { command = bodyList->item(i); if(command->getNodeType() == DOMNode::ELEMENT_NODE) { commandName = xoap::XMLCh2String(command->getLocalName()); break; } } if (commandName.empty()) { XCEPT_RAISE(xoap::exception::Exception,"Command not found."); } // fire appropriate event and create according response message try { toolbox::Event::Reference e(new toolbox::Event(commandName,this)); fsm_.fireEvent(e); // response string xoap::MessageReference reply = xoap::createMessage(); xoap::SOAPEnvelope envelope = reply->getSOAPPart().getEnvelope(); xoap::SOAPName responseName = envelope.createName(commandName+"Response", "xdaq",XDAQ_NS_URI); xoap::SOAPBodyElement responseElem = envelope.getBody().addBodyElement(responseName); // state string int iState = fsm_.getCurrentState(); string state = fsm_.getStateName(iState); xoap::SOAPName stateName = envelope.createName("state", "xdaq",XDAQ_NS_URI); xoap::SOAPElement stateElem = responseElem.addChildElement(stateName); xoap::SOAPName attributeName = envelope.createName("stateName", "xdaq",XDAQ_NS_URI); stateElem.addAttribute(attributeName,state); return reply; } catch (toolbox::fsm::exception::Exception & e) { XCEPT_RETHROW(xoap::exception::Exception,"invalid command.",e); } }
void evf::StateMachine::disableRcmsStateNotification | ( | ) | [inline] |
Definition at line 64 of file StateMachine.h.
References doStateNotification_.
Referenced by evf::FUEventProcessor::enabling(), evf::FUEventProcessor::forkProcessesFromEDM(), and evf::FUEventProcessor::supervisor().
{doStateNotification_=false;}
void StateMachine::failed | ( | toolbox::Event::Reference | e | ) | throw (toolbox::fsm::exception::Exception) |
Definition at line 184 of file StateMachine.cc.
References alignCSCRings::e, and evf::FsmFailedEvent::errorMessage().
Referenced by initialize().
{ if (typeid(*e) == typeid(toolbox::fsm::FailedEvent)) { toolbox::fsm::FailedEvent &fe=dynamic_cast<toolbox::fsm::FailedEvent&>(*e); LOG4CPLUS_FATAL(logger_,"Failure occurred in transition from '" <<fe.getFromState()<<"' to '"<<fe.getToState() <<"', exception history: " <<xcept::stdformat_exception_history(fe.getException())); } else if (typeid(*e) == typeid(evf::FsmFailedEvent)) { evf::FsmFailedEvent &fe=dynamic_cast<evf::FsmFailedEvent&>(*e); LOG4CPLUS_FATAL(logger_,"fsm failure occured: "<<fe.errorMessage()); } }
void StateMachine::findRcmsStateListener | ( | ) |
Definition at line 218 of file StateMachine.cc.
References appInfoSpace_, and rcmsStateNotifier_.
Referenced by evf::BU::BU(), and evf::FUEventProcessor::FUEventProcessor().
{ rcmsStateNotifier_.findRcmsStateListener(); //might not be needed rcmsStateNotifier_.subscribeToChangesInRcmsStateListener(appInfoSpace_); }
void evf::StateMachine::fireEvent | ( | const std::string & | evtType, |
void * | originator | ||
) |
Referenced by evf::FUEventProcessor::configuring(), evf::BU::configuring(), evf::FUEventProcessor::enableCommon(), evf::BU::enabling(), evf::FUEventProcessor::enabling(), evf::FUEventProcessor::forkProcessesFromEDM(), evf::BU::halting(), evf::FUEventProcessor::halting(), evf::FUEventProcessor::receiving(), evf::FUEventProcessor::stopClassic(), evf::BU::stopping(), and evf::FUEventProcessor::supervisor().
void StateMachine::fireFailed | ( | const std::string & | errorMsg, |
void * | originator | ||
) |
Definition at line 210 of file StateMachine.cc.
References alignCSCRings::e, and fsm_.
Referenced by evf::FUEventProcessor::configuring(), evf::BU::configuring(), evf::FUEventProcessor::doEndRunInEDM(), evf::FUEventProcessor::enableCommon(), evf::FUEventProcessor::enableForkInEDM(), evf::FUEventProcessor::enableMPEPSlave(), evf::BU::enabling(), evf::FUEventProcessor::enabling(), evf::FUEventProcessor::forkProcessesFromEDM(), evf::BU::halting(), evf::FUEventProcessor::halting(), evf::FUEventProcessor::stopClassic(), and evf::BU::stopping().
{ toolbox::Event::Reference e(new evf::FsmFailedEvent(errorMsg,originator)); fsm_.fireEvent(e); }
xdata::Boolean* evf::StateMachine::foundRcmsStateListener | ( | ) | [inline] |
Definition at line 78 of file StateMachine.h.
References rcmsStateNotifier_.
Referenced by evf::BU::exportParameters(), and evf::FUEventProcessor::FUEventProcessor().
{ return rcmsStateNotifier_.getFoundRcmsStateListenerParameter(); }
void evf::StateMachine::initialize | ( | T * | app | ) | [inline] |
Definition at line 84 of file StateMachine.h.
References appNameAndInstance_, asConfiguring_, asEnabling_, asHalting_, asStopping_, failed(), fsm_, stateChanged(), stateName_, workLoopConfiguring_, workLoopEnabling_, workLoopHalting_, and workLoopStopping_.
Referenced by evf::BU::BU(), and evf::FUEventProcessor::FUEventProcessor().
{ // action signatures asConfiguring_ = toolbox::task::bind(app,&T::configuring,"configuring"); asEnabling_ = toolbox::task::bind(app,&T::enabling, "enabling"); asStopping_ = toolbox::task::bind(app,&T::stopping, "stopping"); asHalting_ = toolbox::task::bind(app,&T::halting, "halting"); // work loops workLoopConfiguring_ = toolbox::task::getWorkLoopFactory()->getWorkLoop(appNameAndInstance_+ "_Configuring", "waiting"); workLoopEnabling_ = toolbox::task::getWorkLoopFactory()->getWorkLoop(appNameAndInstance_+ "_Enabling", "waiting"); workLoopStopping_ = toolbox::task::getWorkLoopFactory()->getWorkLoop(appNameAndInstance_+ "_Stopping", "waiting"); workLoopHalting_ = toolbox::task::getWorkLoopFactory()->getWorkLoop(appNameAndInstance_+ "_Halting", "waiting"); // bind SOAP callbacks xoap::bind(app,&T::fsmCallback,"Configure",XDAQ_NS_URI); xoap::bind(app,&T::fsmCallback,"Enable", XDAQ_NS_URI); xoap::bind(app,&T::fsmCallback,"Stop", XDAQ_NS_URI); xoap::bind(app,&T::fsmCallback,"Halt", XDAQ_NS_URI); // define finite state machine, states&transitions fsm_.addState('h', "halting" ,this,&evf::StateMachine::stateChanged); fsm_.addState('H', "Halted" ,this,&evf::StateMachine::stateChanged); fsm_.addState('c', "configuring",this,&evf::StateMachine::stateChanged); fsm_.addState('R', "Ready" ,this,&evf::StateMachine::stateChanged); fsm_.addState('e', "enabling" ,this,&evf::StateMachine::stateChanged); fsm_.addState('E', "Enabled" ,this,&evf::StateMachine::stateChanged); fsm_.addState('s', "stopping" ,this,&evf::StateMachine::stateChanged); fsm_.addStateTransition('H','c',"Configure"); fsm_.addStateTransition('c','R',"ConfigureDone"); fsm_.addStateTransition('R','e',"Enable"); fsm_.addStateTransition('e','E',"EnableDone"); fsm_.addStateTransition('E','s',"Stop"); fsm_.addStateTransition('s','R',"StopDone"); fsm_.addStateTransition('E','h',"Halt"); fsm_.addStateTransition('R','h',"Halt"); fsm_.addStateTransition('h','H',"HaltDone"); fsm_.addStateTransition('c','F',"Fail",this,&evf::StateMachine::failed); fsm_.addStateTransition('e','F',"Fail",this,&evf::StateMachine::failed); fsm_.addStateTransition('s','F',"Fail",this,&evf::StateMachine::failed); fsm_.addStateTransition('h','F',"Fail",this,&evf::StateMachine::failed); fsm_.addStateTransition('E','F',"Fail",this,&evf::StateMachine::failed); fsm_.setFailedStateTransitionAction(this,&evf::StateMachine::failed); fsm_.setFailedStateTransitionChanged(this,&evf::StateMachine::stateChanged); fsm_.setStateName('F',"Failed"); fsm_.setInitialState('H'); fsm_.reset(); stateName_ = fsm_.getStateName(fsm_.getCurrentState()); if (!workLoopConfiguring_->isActive()) workLoopConfiguring_->activate(); if (!workLoopEnabling_->isActive()) workLoopEnabling_ ->activate(); if (!workLoopStopping_->isActive()) workLoopStopping_ ->activate(); if (!workLoopHalting_->isActive()) workLoopHalting_ ->activate(); }
xdata::Bag<xdaq2rc::ClassnameAndInstance>* evf::StateMachine::rcmsStateListener | ( | ) | [inline] |
Definition at line 72 of file StateMachine.h.
References rcmsStateNotifier_.
Referenced by evf::BU::exportParameters(), and evf::FUEventProcessor::FUEventProcessor().
{ return rcmsStateNotifier_.getRcmsStateListenerParameter(); }
void StateMachine::stateChanged | ( | toolbox::fsm::FiniteStateMachine & | fsm | ) | throw (toolbox::fsm::exception::Exception) |
Definition at line 126 of file StateMachine.cc.
References alignCSCRings::e, and Exception.
Referenced by initialize().
{ stateName_ = fsm_.getStateName(fsm_.getCurrentState()); string state = stateName_.toString(); LOG4CPLUS_INFO(logger_,"New state is: "<<state); if (state=="configuring") { try { workLoopConfiguring_->submit(asConfiguring_); } catch (xdaq::exception::Exception& e) { LOG4CPLUS_ERROR(logger_,xcept::stdformat_exception_history(e)); } } else if (state=="enabling") { try { workLoopEnabling_->submit(asEnabling_); } catch (xdaq::exception::Exception& e) { LOG4CPLUS_ERROR(logger_,xcept::stdformat_exception_history(e)); } } else if (state=="stopping") { try { workLoopStopping_->submit(asStopping_); } catch (xdaq::exception::Exception& e) { LOG4CPLUS_ERROR(logger_,xcept::stdformat_exception_history(e)); } } else if (state=="halting") { try { workLoopHalting_->submit(asHalting_); } catch (xdaq::exception::Exception& e) { LOG4CPLUS_ERROR(logger_,xcept::stdformat_exception_history(e)); } } else if (state=="Halted"||state=="Ready"||state=="Enabled"||state=="Failed") { if(doStateNotification_) { try { rcmsStateNotifier_.stateChanged(state,appNameAndInstance_+ " has reached target state " + state); } catch (xcept::Exception& e) { LOG4CPLUS_ERROR(logger_,"Failed to notify state change: " <<xcept::stdformat_exception_history(e)); } } } }
xdata::String* evf::StateMachine::stateName | ( | ) | [inline] |
Definition at line 69 of file StateMachine.h.
References stateName_.
Referenced by evf::FUEventProcessor::actionPerformed(), evf::BU::exportParameters(), evf::FUEventProcessor::forkProcessesFromEDM(), evf::FUEventProcessor::FUEventProcessor(), evf::WebGUI::htmlHeadline(), evf::FUEventProcessor::microState(), evf::FUEventProcessor::receivingAndMonitor(), evf::FUEventProcessor::sigmon(), evf::FUEventProcessor::spotlightWebPage(), evf::FUEventProcessor::summarize(), evf::FUEventProcessor::supervisor(), and evf::FUEventProcessor::updater().
{ return &stateName_; }
xdata::InfoSpace* evf::StateMachine::appInfoSpace_ [private] |
Definition at line 165 of file StateMachine.h.
Referenced by findRcmsStateListener().
std::string evf::StateMachine::appNameAndInstance_ [private] |
Definition at line 166 of file StateMachine.h.
Referenced by initialize(), and StateMachine().
toolbox::task::ActionSignature* evf::StateMachine::asConfiguring_ [private] |
Definition at line 180 of file StateMachine.h.
Referenced by initialize().
toolbox::task::ActionSignature* evf::StateMachine::asEnabling_ [private] |
Definition at line 181 of file StateMachine.h.
Referenced by initialize().
toolbox::task::ActionSignature* evf::StateMachine::asHalting_ [private] |
Definition at line 183 of file StateMachine.h.
Referenced by initialize().
toolbox::task::ActionSignature* evf::StateMachine::asStopping_ [private] |
Definition at line 182 of file StateMachine.h.
Referenced by initialize().
bool evf::StateMachine::doStateNotification_ [private] |
Definition at line 168 of file StateMachine.h.
Referenced by disableRcmsStateNotification().
toolbox::fsm::FiniteStateMachine evf::StateMachine::fsm_ [private] |
Definition at line 171 of file StateMachine.h.
Referenced by checkIfEnabled(), fireFailed(), and initialize().
log4cplus::Logger evf::StateMachine::logger_ [private] |
Definition at line 164 of file StateMachine.h.
xdaq2rc::RcmsStateNotifier evf::StateMachine::rcmsStateNotifier_ [private] |
Definition at line 186 of file StateMachine.h.
Referenced by findRcmsStateListener(), foundRcmsStateListener(), and rcmsStateListener().
xdata::String evf::StateMachine::stateName_ [private] |
Definition at line 167 of file StateMachine.h.
Referenced by initialize(), and stateName().
toolbox::task::WorkLoop* evf::StateMachine::workLoopConfiguring_ [private] |
Definition at line 174 of file StateMachine.h.
Referenced by initialize().
toolbox::task::WorkLoop* evf::StateMachine::workLoopEnabling_ [private] |
Definition at line 175 of file StateMachine.h.
Referenced by initialize().
toolbox::task::WorkLoop* evf::StateMachine::workLoopHalting_ [private] |
Definition at line 177 of file StateMachine.h.
Referenced by initialize().
toolbox::task::WorkLoop* evf::StateMachine::workLoopStopping_ [private] |
Definition at line 176 of file StateMachine.h.
Referenced by initialize().