otsdaq  v2_04_01
CoreSupervisorBase.h
1 #ifndef _ots_CoreSupervisorBase_h_
2 #define _ots_CoreSupervisorBase_h_
3 
4 #include "otsdaq-core/FiniteStateMachine/RunControlStateMachine.h"
5 #include "otsdaq-core/SOAPUtilities/SOAPMessenger.h"
6 #include "otsdaq-core/WorkLoopManager/WorkLoopManager.h"
7 
8 #include "otsdaq-core/CoreSupervisors/CorePropertySupervisorBase.h"
9 
10 #include "otsdaq-core/CgiDataUtilities/CgiDataUtilities.h"
11 #include "otsdaq-core/SOAPUtilities/SOAPUtilities.h"
12 #include "otsdaq-core/XmlUtilities/HttpXmlDocument.h"
13 
14 #include "otsdaq-core/FiniteStateMachine/VStateMachine.h"
15 
16 #include "otsdaq-core/WebUsersUtilities/RemoteWebUsers.h"
17 
18 #pragma GCC diagnostic push
19 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
20 #include <xdaq/Application.h>
21 #pragma GCC diagnostic pop
22 #include "otsdaq-core/Macros/XDAQApplicationMacros.h"
23 #include "xgi/Method.h"
24 
25 #include <toolbox/fsm/FailedEvent.h>
26 
27 #include <xdaq/NamespaceURI.h>
28 #include <xoap/Method.h>
29 
30 #include <map>
31 #include <memory>
32 #include <string> /*string and to_string*/
33 #include <vector>
34 
35 namespace ots
36 {
37 // CoreSupervisorBase
38 // This class should be the base class for all client otsdaq, XDAQ-based, supervisors.
39 // That is, all supervisors that need web requests through the ots desktop
40 // with access verified by the Gateway Supervisor,
41 // or that need a state machines driven by the Gateway Supervisor.
42 class CoreSupervisorBase : public xdaq::Application,
43  public SOAPMessenger,
46 {
47  friend class MacroMakerSupervisor; // to allow MacroMakerSupervisor to call
48  // requestWrapper in Macro Maker mode
49 
50  public:
51  CoreSupervisorBase(xdaq::ApplicationStub* stub);
52  virtual ~CoreSupervisorBase(void);
53 
54  void destroy(void);
55 
56  const unsigned int getSupervisorLID(void) const
57  {
58  return getApplicationDescriptor()->getLocalId();
59  }
60 
61  // Here are the common web request handlers:
62  // defaultPage returns the public html page
63  // request checks the login before proceeding to virtual request
64  // - All Supervisors should implement request for their actions (and they will
65  // get the security wrapper for free)
66  // - The security setting defaults can be setup or forced by overriding
67  // setSupervisorPropertyDefaults and forceSupervisorProperties
68  virtual void defaultPage(xgi::Input* in, xgi::Output* out);
69  virtual void request(const std::string& requestType,
70  cgicc::Cgicc& cgiIn,
71  HttpXmlDocument& xmlOut,
72  const WebUsers::RequestUserInfo& userInfo);
73  virtual void nonXmlRequest(const std::string& requestType,
74  cgicc::Cgicc& cgiIn,
75  std::ostream& out,
76  const WebUsers::RequestUserInfo& userInfo);
77 
78  private:
79  xoap::MessageReference workLoopStatusRequestWrapper(xoap::MessageReference message);
80  void defaultPageWrapper(xgi::Input* in, xgi::Output* out);
81  void requestWrapper(xgi::Input* in, xgi::Output* out);
82 
83  public:
84  // State Machine request handlers
85  void stateMachineXgiHandler(xgi::Input* in, xgi::Output* out);
86  void stateMachineResultXgiHandler(xgi::Input* in, xgi::Output* out);
87  xoap::MessageReference stateMachineXoapHandler(xoap::MessageReference message);
88  xoap::MessageReference stateMachineResultXoapHandler(xoap::MessageReference message);
89 
90  xoap::MessageReference stateMachineStateRequest(xoap::MessageReference message);
91  xoap::MessageReference stateMachineErrorMessageRequest(
92  xoap::MessageReference message);
93 
94  virtual xoap::MessageReference workLoopStatusRequest(xoap::MessageReference message);
95 
96  bool stateMachineThread(toolbox::task::WorkLoop* workLoop);
97 
98  virtual void stateInitial(toolbox::fsm::FiniteStateMachine& fsm);
99  virtual void statePaused(toolbox::fsm::FiniteStateMachine& fsm);
100  virtual void stateRunning(toolbox::fsm::FiniteStateMachine& fsm);
101  virtual void stateHalted(toolbox::fsm::FiniteStateMachine& fsm);
102  virtual void stateConfigured(toolbox::fsm::FiniteStateMachine& fsm);
103  virtual void inError(toolbox::fsm::FiniteStateMachine& fsm);
104 
105  virtual void transitionConfiguring(toolbox::Event::Reference e);
106  virtual void transitionHalting(toolbox::Event::Reference e);
107  virtual void transitionInitializing(toolbox::Event::Reference e);
108  virtual void transitionPausing(toolbox::Event::Reference e);
109  virtual void transitionResuming(toolbox::Event::Reference e);
110  virtual void transitionStarting(toolbox::Event::Reference e);
111  virtual void transitionStopping(toolbox::Event::Reference e);
112  virtual void enteringError(toolbox::Event::Reference e);
113 
114  static const std::string WORK_LOOP_DONE, WORK_LOOP_WORKING;
115 
116  protected:
117  WorkLoopManager stateMachineWorkLoopManager_;
118  toolbox::BSem stateMachineSemaphore_;
119  std::vector<VStateMachine*> theStateMachineImplementation_;
120 
121  // for managing transition iterations
122  std::vector<bool> stateMachinesIterationDone_;
123  unsigned int stateMachinesIterationWorkCount_;
124  unsigned int subIterationWorkStateMachineIndex_;
125  void preStateMachineExecution(unsigned int i);
126  void postStateMachineExecution(unsigned int i);
127  void preStateMachineExecutionLoop(void);
128  void postStateMachineExecutionLoop(void);
129 
130  RemoteWebUsers theRemoteWebUsers_;
131 };
132 
133 } // namespace ots
134 
135 #endif