CMS 3D CMS Logo

Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes

dqm::StateMachine Class Reference

#include <StateMachine.h>

List of all members.

Public Member Functions

virtual void configureAction (toolbox::Event::Reference e)=0 throw (toolbox::fsm::exception::Exception)
 transition methods to be implemented by the application
virtual void enableAction (toolbox::Event::Reference e)=0 throw (toolbox::fsm::exception::Exception)
xoap::MessageReference fireEvent (xoap::MessageReference msg) throw (xoap::exception::Exception)
virtual void haltAction (toolbox::Event::Reference e)=0 throw (toolbox::fsm::exception::Exception)
virtual void nullAction (toolbox::Event::Reference e)=0 throw (toolbox::fsm::exception::Exception)
virtual void resumeAction (toolbox::Event::Reference e)=0 throw (toolbox::fsm::exception::Exception)
 StateMachine (xdaq::ApplicationStub *s)
virtual void stopAction (toolbox::Event::Reference e) throw (toolbox::fsm::exception::Exception)
virtual void suspendAction (toolbox::Event::Reference e)=0 throw (toolbox::fsm::exception::Exception)
virtual ~StateMachine ()

Protected Member Functions

void bind (std::string)
void Default (xgi::Input *in, xgi::Output *out) throw (xgi::exception::Exception)
void dispatch (xgi::Input *in, xgi::Output *out) throw (xgi::exception::Exception)
xdata::String * stateName ()

Private Member Functions

void failurePage (xgi::Output *out, xgi::exception::Exception &e) throw (xgi::exception::Exception)
void statePage (xgi::Output *out) throw (xgi::exception::Exception)
void webConfigure (xgi::Input *in) throw (xgi::exception::Exception)
void webEnable (xgi::Input *in) throw (xgi::exception::Exception)
void webHalt (xgi::Input *in) throw (xgi::exception::Exception)
void webResume (xgi::Input *in) throw (xgi::exception::Exception)
void webSuspend (xgi::Input *in) throw (xgi::exception::Exception)

Private Attributes

evf::EPStateMachine fsm_
std::string page_
xgi::WSM wsm_

Detailed Description

Definition at line 18 of file StateMachine.h.


Constructor & Destructor Documentation

StateMachine::StateMachine ( xdaq::ApplicationStub *  s)

Definition at line 15 of file StateMachine.cc.

References bind(), dispatch(), failurePage(), fsm_, evf::EPStateMachine::init(), statePage(), webConfigure(), webEnable(), webHalt(), webResume(), webSuspend(), and wsm_.

                                                 :  
  xdaq::Application(s), 
  fsm_(getApplicationLogger()) 
{      
  wsm_.addState('H', "Halted"   , this, &StateMachine::statePage);
  wsm_.addState('R', "Ready"    , this, &StateMachine::statePage);
  wsm_.addState('E', "Enabled"  , this, &StateMachine::statePage);
  wsm_.addState('S', "Suspended", this, &StateMachine::statePage);
  
  // Define FSM transitions
  wsm_.addStateTransition('H', 'R', "Configure", this,
                          &StateMachine::webConfigure, &StateMachine::failurePage);
  wsm_.addStateTransition('R', 'E', "Enable", this,
                          &StateMachine::webEnable, &StateMachine::failurePage);
  wsm_.addStateTransition('E', 'S', "Suspend", this,
                          &StateMachine::webSuspend, &StateMachine::failurePage);
  wsm_.addStateTransition('S', 'E', "Resume", this,
                          &StateMachine::webResume, &StateMachine::failurePage);
  wsm_.addStateTransition('H', 'H', "Halt", this,
                          &StateMachine::webHalt, &StateMachine::failurePage);
  wsm_.addStateTransition('R', 'H', "Halt", this,
                          &StateMachine::webHalt, &StateMachine::failurePage);
  wsm_.addStateTransition('E', 'H', "Halt", this,
                          &StateMachine::webHalt, &StateMachine::failurePage);
  wsm_.addStateTransition('S', 'H', "Halt", this,
                          &StateMachine::webHalt, &StateMachine::failurePage);
  
  wsm_.setInitialState('H');
  
  fsm_.init<dqm::StateMachine>(this);
  xgi::bind(this, &StateMachine::dispatch, "dispatch");
}
virtual dqm::StateMachine::~StateMachine ( ) [inline, virtual]

Definition at line 24 of file StateMachine.h.

{}

Member Function Documentation

void StateMachine::bind ( std::string  page) [protected]

Definition at line 48 of file StateMachine.cc.

References Default(), and page_.

Referenced by StateMachine().

{
  page_ = page;
  xgi::bind(this, &StateMachine::Default, page);
}   
virtual void dqm::StateMachine::configureAction ( toolbox::Event::Reference  e) throw (toolbox::fsm::exception::Exception) [pure virtual]

transition methods to be implemented by the application

void dqm::StateMachine::Default ( xgi::Input *  in,
xgi::Output *  out 
) throw (xgi::exception::Exception) [inline, protected]

Definition at line 43 of file StateMachine.h.

References dbtoconf::out, and wsm_.

Referenced by bind().

    {
      wsm_.displayPage(out);
    }
void dqm::StateMachine::dispatch ( xgi::Input *  in,
xgi::Output *  out 
) throw (xgi::exception::Exception) [inline, protected]

Definition at line 48 of file StateMachine.h.

References fsm_, recoMuon::in, dbtoconf::out, evf::EPStateMachine::processFSMCommand(), and wsm_.

Referenced by StateMachine().

    {
      cgicc::Cgicc cgi(in);
      cgi.getEnvironment();
      cgicc::const_form_iterator stateInputElement = cgi.getElement("StateInput");
      std::string stateInput = (*stateInputElement).getValue();
      wsm_.fireEvent(stateInput,in,out);
      fsm_.processFSMCommand(stateInput);
    }
virtual void dqm::StateMachine::enableAction ( toolbox::Event::Reference  e) throw (toolbox::fsm::exception::Exception) [pure virtual]
void StateMachine::failurePage ( xgi::Output *  out,
xgi::exception::Exception e 
) throw (xgi::exception::Exception) [private]

Definition at line 151 of file StateMachine.cc.

References beamvalidation::br, ExpressReco_HICollisions_FallBack::e, packageDocSplitter::html, and dbtoconf::out.

Referenced by StateMachine().

{
  if(out)
    {
      *out << cgicc::HTMLDoctype(cgicc::HTMLDoctype::eStrict) << std::endl;
      *out << cgicc::html().set("lang", "en").set("dir","ltr") << std::endl;
      
      xgi::Utils::getPageHeader(*out, "WebStateMachine Home", "Failure");
      
      
      *out << cgicc::br() << e.what() << cgicc::br() << std::endl;
      std::string url = "/";
      url += getApplicationDescriptor()->getURN();

      *out << cgicc::br() << "<a href=\"" << url << "\">" << "retry" << "</a>" << cgicc::br() << std::endl;
      
      xgi::Utils::getPageFooter(*out);
      
    }
}
xoap::MessageReference StateMachine::fireEvent ( xoap::MessageReference  msg) throw (xoap::exception::Exception)

Definition at line 54 of file StateMachine.cc.

References edmPickEvents::command, Exception, i, runTheMatrix::msg, and python::Node::node.

{
  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;
  std::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());
          wsm_.fireEvent(commandName,0,0);
          return fsm_.processFSMCommand(commandName);
        }
    }
  
  XCEPT_RAISE(xoap::exception::Exception, "Command not found");
}
virtual void dqm::StateMachine::haltAction ( toolbox::Event::Reference  e) throw (toolbox::fsm::exception::Exception) [pure virtual]
virtual void dqm::StateMachine::nullAction ( toolbox::Event::Reference  e) throw (toolbox::fsm::exception::Exception) [pure virtual]
virtual void dqm::StateMachine::resumeAction ( toolbox::Event::Reference  e) throw (toolbox::fsm::exception::Exception) [pure virtual]
xdata::String* dqm::StateMachine::stateName ( ) [inline, protected]

Definition at line 58 of file StateMachine.h.

References fsm_, and evf::EPStateMachine::stateName_.

{return &fsm_.stateName_;}
void StateMachine::statePage ( xgi::Output *  out) throw (xgi::exception::Exception) [private]

Definition at line 83 of file StateMachine.cc.

References packageDocSplitter::html, i, collect_tpl::input, and dbtoconf::out.

Referenced by StateMachine().

{
  if(out)
    {
      std::string url = "/";
      url += getApplicationDescriptor()->getURN();
      std::string purl = url + "/" + page_;

      *out << cgicc::HTMLDoctype(cgicc::HTMLDoctype::eStrict) << std::endl;
      *out << cgicc::html().set("lang", "en").set("dir","ltr") << std::endl;
      *out << "<head>" << std::endl;
      *out << "<META HTTP-EQUIV=refresh CONTENT=\"30; URL=";
      *out << purl << "\">" << std::endl;
      *out << "<META HTTP-EQUIV=Window-target CONTENT=\"_self\">" << std::endl;
      *out << "<title> " << "fsm" << "</title>"  << std::endl;
      *out << "</head>" << std::endl;
      *out << "<body>" << std::endl;
      //      xgi::Utils::getPageHeader(*out, "StateMachine", wsm_.getStateName(wsm_.getCurrentState()));
      
      url += "/dispatch";       
      
      // display FSM
      //      cout << "current state " << wsm_.getCurrentState() << endl;
      //      cout << "possible commands" << endl;
      std::set<std::string>::iterator i;
      std::set<std::string> possibleInputs = wsm_.getInputs(wsm_.getCurrentState());
      std::set<std::string> allInputs = wsm_.getInputs();
      
      //      for ( i = possibleInputs.begin(); i != possibleInputs.end(); i++)
      //        cout << (*i) << endl;
      
      *out << cgicc::h3("Finite State Machine").set("style", "font-family: arial") << std::endl;
      *out << "<table border cellpadding=10 cellspacing=0>" << std::endl;
      *out << "<tr>" << std::endl;
      *out << "<th>" << wsm_.getStateName(wsm_.getCurrentState()) << "</th>" << std::endl;
      *out << "</tr>" << std::endl;
      *out << "<tr>" << std::endl;

      for ( i = allInputs.begin(); i != allInputs.end(); i++)
        {
          *out << "<td>"; 
          *out << cgicc::form().set("method","post").set("target","_self").set("action", url).set("enctype","multipart/form-data") << std::endl;
          
          if ( possibleInputs.find(*i) != possibleInputs.end() )
            {
              *out << cgicc::input().set("type", "submit").set("name", "StateInput").set("value", (*i) );
            }
          else
            {
              *out << cgicc::input() .set("type", "submit").set("name", "StateInput").set("value", (*i) ).set("disabled", "true");
            }
          
          *out << cgicc::form();
          *out << "</td>" << std::endl;
        }
      
      *out << "</tr>" << std::endl;
      *out << "</table>" << std::endl;
      *out << cgicc::html();
      //        
      //      xgi::Utils::getPageFooter(*out);
    }
}
virtual void dqm::StateMachine::stopAction ( toolbox::Event::Reference  e) throw (toolbox::fsm::exception::Exception) [inline, virtual]

Definition at line 31 of file StateMachine.h.

{}; //just a noop to keep the compiler happy for the moment
virtual void dqm::StateMachine::suspendAction ( toolbox::Event::Reference  e) throw (toolbox::fsm::exception::Exception) [pure virtual]
void dqm::StateMachine::webConfigure ( xgi::Input *  in) throw (xgi::exception::Exception) [inline, private]

Web Events that trigger state changes

Definition at line 71 of file StateMachine.h.

Referenced by StateMachine().

    {
      
    }
void dqm::StateMachine::webEnable ( xgi::Input *  in) throw (xgi::exception::Exception) [inline, private]

Definition at line 76 of file StateMachine.h.

Referenced by StateMachine().

    {
      
      
    }
void dqm::StateMachine::webHalt ( xgi::Input *  in) throw (xgi::exception::Exception) [inline, private]

Definition at line 91 of file StateMachine.h.

Referenced by StateMachine().

    {
      
      
    }
void dqm::StateMachine::webResume ( xgi::Input *  in) throw (xgi::exception::Exception) [inline, private]

Definition at line 86 of file StateMachine.h.

Referenced by StateMachine().

    {
      
      
    }
void dqm::StateMachine::webSuspend ( xgi::Input *  in) throw (xgi::exception::Exception) [inline, private]

Definition at line 81 of file StateMachine.h.

Referenced by StateMachine().

    {
      
      
    }

Member Data Documentation

Definition at line 100 of file StateMachine.h.

Referenced by dispatch(), StateMachine(), and stateName().

std::string dqm::StateMachine::page_ [private]

Definition at line 101 of file StateMachine.h.

Referenced by bind().

xgi::WSM dqm::StateMachine::wsm_ [private]

Definition at line 99 of file StateMachine.h.

Referenced by Default(), dispatch(), and StateMachine().