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