otsdaq  v2_00_00
GatewaySupervisor.h
1 #ifndef _ots_GatewaySupervisor_h
2 #define _ots_GatewaySupervisor_h
3 
4 #include "otsdaq-core/SupervisorInfo/AllSupervisorInfo.h"
5 #include "otsdaq-core/SOAPUtilities/SOAPMessenger.h"
6 #include "otsdaq-core/WebUsersUtilities/WebUsers.h"
7 #include "otsdaq-core/SystemMessenger/SystemMessenger.h"
8 #include "otsdaq-core/WorkLoopManager/WorkLoopManager.h"
9 #include "otsdaq-core/FiniteStateMachine/RunControlStateMachine.h"
10 #include "otsdaq-core/SupervisorInfo/AllSupervisorInfo.h"
11 #include "otsdaq-core/GatewaySupervisor/Iterator.h"
12 #include "otsdaq-core/ConfigurationDataFormats/ConfigurationGroupKey.h"
13 
14 #pragma GCC diagnostic push
15 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
16 #include <xdaq/Application.h>
17 #pragma GCC diagnostic pop
18 //#include <toolbox/fsm/FiniteStateMachine.h>
19 #include <toolbox/task/WorkLoop.h>
20 #include <xgi/Method.h>
21 #include <xdata/String.h>
22 
23 #include <string>
24 #include <set>
25 
26 //defines used also by OtsConfigurationWizardSupervisor
27 #define FSM_LAST_CONFIGURED_GROUP_ALIAS_FILE std::string("FSMLastConfiguredGroupAlias.hist")
28 #define FSM_LAST_STARTED_GROUP_ALIAS_FILE std::string("FSMLastStartedGroupAlias.hist")
29 
30 
31 namespace ots
32 {
33 
34 class ConfigurationManager;
35 class ConfigurationGroupKey;
36 class WorkLoopManager;
37 
38 class GatewaySupervisor: public xdaq::Application, public SOAPMessenger, public RunControlStateMachine
39 {
40  friend class WizardSupervisor;
41  friend class Iterator;
42 
43 public:
44 
45  XDAQ_INSTANTIATOR();
46 
47  GatewaySupervisor (xdaq::ApplicationStub * s) throw (xdaq::exception::Exception);
48  virtual ~GatewaySupervisor(void);
49 
50  void init (void);
51 
52  void Default (xgi::Input* in, xgi::Output* out ) throw (xgi::exception::Exception);
53 // void TmpTest (xgi::Input* in, xgi::Output* out ) throw (xgi::exception::Exception);
54 
55  void loginRequest (xgi::Input* in, xgi::Output* out ) throw (xgi::exception::Exception);
56  void request (xgi::Input* in, xgi::Output* out ) throw (xgi::exception::Exception);
57  void tooltipRequest (xgi::Input* in, xgi::Output* out ) throw (xgi::exception::Exception);
58 
59  //State Machine requests handlers
60  void stateMachineXgiHandler (xgi::Input* in, xgi::Output* out ) throw (xgi::exception::Exception);
61  void stateMachineResultXgiHandler (xgi::Input* in, xgi::Output* out ) throw (xgi::exception::Exception);
62  xoap::MessageReference stateMachineXoapHandler (xoap::MessageReference msg ) throw (xoap::exception::Exception);
63  xoap::MessageReference stateMachineResultXoapHandler (xoap::MessageReference msg ) throw (xoap::exception::Exception);
64  bool stateMachineThread (toolbox::task::WorkLoop* workLoop);
65 
66  //Status requests handlers
67  void infoRequestHandler (xgi::Input* in, xgi::Output* out ) throw (xgi::exception::Exception);
68  void infoRequestResultHandler (xgi::Input* in, xgi::Output* out ) throw (xgi::exception::Exception);
69  bool infoRequestThread (toolbox::task::WorkLoop* workLoop);
70 
71  //External GatewaySupervisor XOAP handlers
72  xoap::MessageReference supervisorCookieCheck (xoap::MessageReference msg) throw (xoap::exception::Exception);
73  xoap::MessageReference supervisorGetActiveUsers (xoap::MessageReference msg) throw (xoap::exception::Exception);
74  xoap::MessageReference supervisorSystemMessage (xoap::MessageReference msg) throw (xoap::exception::Exception);
75  xoap::MessageReference supervisorGetUserInfo (xoap::MessageReference msg) throw (xoap::exception::Exception);
76  xoap::MessageReference supervisorSystemLogbookEntry (xoap::MessageReference msg) throw (xoap::exception::Exception);
77  xoap::MessageReference supervisorLastConfigGroupRequest(xoap::MessageReference msg) throw (xoap::exception::Exception);
78 
79  //Finite State Machine States
80  void stateInitial (toolbox::fsm::FiniteStateMachine& fsm) throw (toolbox::fsm::exception::Exception);
81  void statePaused (toolbox::fsm::FiniteStateMachine& fsm) throw (toolbox::fsm::exception::Exception);
82  void stateRunning (toolbox::fsm::FiniteStateMachine& fsm) throw (toolbox::fsm::exception::Exception);
83  void stateHalted (toolbox::fsm::FiniteStateMachine& fsm) throw (toolbox::fsm::exception::Exception);
84  void stateConfigured (toolbox::fsm::FiniteStateMachine& fsm) throw (toolbox::fsm::exception::Exception);
85  void inError (toolbox::fsm::FiniteStateMachine& fsm) throw (toolbox::fsm::exception::Exception);
86 
87  void transitionConfiguring (toolbox::Event::Reference e) throw (toolbox::fsm::exception::Exception);
88  void transitionHalting (toolbox::Event::Reference e) throw (toolbox::fsm::exception::Exception);
89  void transitionInitializing (toolbox::Event::Reference e) throw (toolbox::fsm::exception::Exception);
90  void transitionPausing (toolbox::Event::Reference e) throw (toolbox::fsm::exception::Exception);
91  void transitionResuming (toolbox::Event::Reference e) throw (toolbox::fsm::exception::Exception);
92  void transitionStarting (toolbox::Event::Reference e) throw (toolbox::fsm::exception::Exception);
93  void transitionStopping (toolbox::Event::Reference e) throw (toolbox::fsm::exception::Exception);
94  void transitionShuttingDown (toolbox::Event::Reference e) throw (toolbox::fsm::exception::Exception);
95  void transitionStartingUp (toolbox::Event::Reference e) throw (toolbox::fsm::exception::Exception);
96  void enteringError (toolbox::Event::Reference e) throw (toolbox::fsm::exception::Exception);
97 
98  void makeSystemLogbookEntry (std::string entryText);
99 
100  // void simpleFunction () { std::cout << __COUT_HDR_FL__ << "hi\n" << std::endl;}
101 
102 private:
103  unsigned int getNextRunNumber (const std::string &fsmName = "");
104  bool setNextRunNumber (unsigned int runNumber, const std::string &fsmName = "");
105  static std::pair<std::string /*group name*/, ConfigurationGroupKey> loadGroupNameAndKey (const std::string &fileName, std::string &returnedTimeString);
106  void saveGroupNameAndKey (const std::pair<std::string /*group name*/, ConfigurationGroupKey> &theGroup, const std::string &fileName);
107  static xoap::MessageReference lastConfigGroupRequestHandler (const SOAPParameters &parameters);
108  void launchStartOTSCommand (const std::string& command);
109 
110  static void StateChangerWorkLoop (GatewaySupervisor *supervisorPtr);
111  std::string attemptStateMachineTransition (HttpXmlDocument* xmldoc, std::ostringstream* out, const std::string& command, const std::string& fsmName, const std::string& fsmWindowName, const std::string& username, const std::vector<std::string>& parameters);
112  bool broadcastMessage (xoap::MessageReference msg) throw (toolbox::fsm::exception::Exception);
113 
114  bool supervisorGuiHasBeenLoaded_ ; //use to indicate first access by user of ots since execution
115 
116  //Member Variables
117 
118  AllSupervisorInfo allSupervisorInfo_ ;
119  ConfigurationManager* theConfigurationManager_ ;
120  WebUsers theWebUsers_ ;
121  SystemMessenger theSystemMessenger_ ;
122 
123  WorkLoopManager stateMachineWorkLoopManager_;
124  toolbox::BSem stateMachineSemaphore_ ;
125  WorkLoopManager infoRequestWorkLoopManager_ ;
126  toolbox::BSem infoRequestSemaphore_ ;
127 
128  std::string supervisorContextUID_ ;
129  std::string supervisorApplicationUID_ ;
130 
131  std::string activeStateMachineName_ ; //when multiple state machines, this is the name of the state machine which executed the configure transition
132  std::string activeStateMachineWindowName_ ;
133  std::pair<std::string /*group name*/, ConfigurationGroupKey> theConfigurationGroup_; //used to track the active configuration group at states after the configure state
134 
135  Iterator theIterator_ ;
136  std::mutex stateMachineAccessMutex_ ; //for sharing state machine access with iterator thread
137  std::string stateMachineLastCommandInput_ ;
138 
139  enum {
140  VERBOSE_MUTEX = 0
141  };
142 
143  //Trash tests
144  void wait(int milliseconds, std::string who="") const;
145  unsigned long long counterTest_ ;
146  std::vector<int> vectorTest_ ;
147  std::string securityType_;
148 
149 };
150 
151 }
152 
153 #endif
154