1 #include "otsdaq-core/FiniteStateMachine/RunControlStateMachine.h"
2 #include "otsdaq-core/MessageFacility/MessageFacility.h"
3 #include "otsdaq-core/Macros/CoutHeaderMacros.h"
4 #include "otsdaq-core/SOAPUtilities/SOAPUtilities.h"
5 #include "otsdaq-core/SOAPUtilities/SOAPCommand.h"
7 #include <toolbox/fsm/FailedEvent.h>
8 #include <xoap/Method.h>
9 #include <xdaq/NamespaceURI.h>
17 RunControlStateMachine::RunControlStateMachine(std::string name)
18 : stateMachineName_(name)
20 theStateMachine_.addState(
'I',
"Initial",
this, &RunControlStateMachine::stateInitial);
21 theStateMachine_.addState(
'H',
"Halted",
this, &RunControlStateMachine::stateHalted);
22 theStateMachine_.addState(
'C',
"Configured",
this, &RunControlStateMachine::stateConfigured);
23 theStateMachine_.addState(
'R',
"Running",
this, &RunControlStateMachine::stateRunning);
24 theStateMachine_.addState(
'P',
"Paused",
this, &RunControlStateMachine::statePaused);
32 theStateMachine_.setStateName(
'F',
"Failed");
33 theStateMachine_.setFailedStateTransitionAction (
this, &RunControlStateMachine::enteringError);
34 theStateMachine_.setFailedStateTransitionChanged(
this, &RunControlStateMachine::inError);
37 theStateMachine_.addStateTransition(
'F',
'H',
"Halt" ,
"Halting" ,
this, &RunControlStateMachine::transitionHalting);
41 theStateMachine_.addStateTransition(
'H',
'C',
"Configure" ,
"Configuring" ,
"ConfigurationAlias",
this, &RunControlStateMachine::transitionConfiguring);
44 theStateMachine_.addStateTransition(
'I',
'H',
"Initialize",
"Initializing",
this, &RunControlStateMachine::transitionInitializing);
45 theStateMachine_.addStateTransition(
'H',
'H',
"Halt" ,
"Halting" ,
this, &RunControlStateMachine::transitionHalting);
46 theStateMachine_.addStateTransition(
'C',
'H',
"Halt" ,
"Halting" ,
this, &RunControlStateMachine::transitionHalting);
47 theStateMachine_.addStateTransition(
'R',
'H',
"Abort" ,
"Aborting" ,
this, &RunControlStateMachine::transitionHalting);
48 theStateMachine_.addStateTransition(
'P',
'H',
"Abort" ,
"Aborting" ,
this, &RunControlStateMachine::transitionHalting);
51 theStateMachine_.addStateTransition(
'R',
'P',
"Pause" ,
"Pausing" ,
this, &RunControlStateMachine::transitionPausing);
52 theStateMachine_.addStateTransition(
'P',
'R',
"Resume" ,
"Resuming" ,
this, &RunControlStateMachine::transitionResuming);
53 theStateMachine_.addStateTransition(
'C',
'R',
"Start" ,
"Starting" ,
this, &RunControlStateMachine::transitionStarting);
54 theStateMachine_.addStateTransition(
'R',
'C',
"Stop" ,
"Stopping" ,
this, &RunControlStateMachine::transitionStopping);
55 theStateMachine_.addStateTransition(
'P',
'C',
"Stop" ,
"Stopping" ,
this, &RunControlStateMachine::transitionStopping);
60 xoap::bind(
this, &RunControlStateMachine::runControlMessageHandler,
"Initialize", XDAQ_NS_URI);
61 xoap::bind(
this, &RunControlStateMachine::runControlMessageHandler,
"Configure" , XDAQ_NS_URI);
62 xoap::bind(
this, &RunControlStateMachine::runControlMessageHandler,
"Start" , XDAQ_NS_URI);
63 xoap::bind(
this, &RunControlStateMachine::runControlMessageHandler,
"Stop" , XDAQ_NS_URI);
64 xoap::bind(
this, &RunControlStateMachine::runControlMessageHandler,
"Pause" , XDAQ_NS_URI);
65 xoap::bind(
this, &RunControlStateMachine::runControlMessageHandler,
"Resume" , XDAQ_NS_URI);
66 xoap::bind(
this, &RunControlStateMachine::runControlMessageHandler,
"Halt" , XDAQ_NS_URI);
67 xoap::bind(
this, &RunControlStateMachine::runControlMessageHandler,
"Abort" , XDAQ_NS_URI);
74 RunControlStateMachine::~RunControlStateMachine(
void)
79 void RunControlStateMachine::reset(
void)
81 __MOUT__ << stateMachineName_ <<
" is in transition?" << theStateMachine_.isInTransition() << std::endl;
82 theStateMachine_.setInitialState(
'I');
83 theStateMachine_.reset();
84 __MOUT__ << stateMachineName_ <<
" is in transition?" << theStateMachine_.isInTransition() << std::endl;
88 xoap::MessageReference RunControlStateMachine::runControlMessageHandler(
89 xoap::MessageReference message)
90 throw (xoap::exception::Exception)
92 __MOUT__ <<
"Starting state for " << stateMachineName_ <<
" is " << theStateMachine_.getCurrentStateName() << std::endl;
93 __MOUT__ << SOAPUtilities::translate(message) << std::endl;
94 std::string command = SOAPUtilities::translate(message).getCommand();
96 theProgressBar_.reset(command,stateMachineName_);
97 std::string result = command +
"Done";
101 if(command ==
"Error" || command ==
"Fail")
103 __SS__ << command <<
" was received! Immediately throwing FSM exception." << std::endl;
104 __MOUT_ERR__ <<
"\n" << ss.str();
105 XCEPT_RAISE (toolbox::fsm::exception::Exception, ss.str());
106 return SOAPUtilities::makeSOAPMessageReference(result);
112 theStateMachine_.execTransition(command,message);
115 catch (toolbox::fsm::exception::Exception& e)
117 result = command +
"Failed";
118 __MOUT__ << e.what() << std::endl;
121 theProgressBar_.complete();
122 __MOUT__ <<
"Ending state for " << stateMachineName_ <<
" is " << theStateMachine_.getCurrentStateName() << std::endl;
123 return SOAPUtilities::makeSOAPMessageReference(result);