otsdaq  v1_01_04
 All Classes Namespaces Functions
Supervisor.h
1 #ifndef _Supervisor_Supervisor_h
2 #define _Supervisor_Supervisor_h
3 
4 #include "otsdaq-core/SOAPUtilities/SOAPMessenger.h"
5 #include "otsdaq-core/WebUsersUtilities/WebUsers.h"
6 #include "otsdaq-core/SystemMessenger/SystemMessenger.h"
7 #include "otsdaq-core/WorkLoopManager/WorkLoopManager.h"
8 #include "otsdaq-core/FiniteStateMachine/RunControlStateMachine.h"
9 #include "otsdaq-core/Supervisor/SupervisorsInfo.h"
10 #include "otsdaq-core/Supervisor/Iterator.h"
11 #include "otsdaq-core/SupervisorDescriptorInfo/SupervisorDescriptorInfo.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 Supervisor: public xdaq::Application, public SOAPMessenger, public RunControlStateMachine
39 {
40  friend class OtsConfigurationWizardSupervisor;
41  friend class Iterator;
42 
43 public:
44 
45  XDAQ_INSTANTIATOR();
46 
47  Supervisor (xdaq::ApplicationStub * s) throw (xdaq::exception::Exception);
48  virtual ~Supervisor(void);
49 
50  void init (void);
51  static void URLDisplayThread (Supervisor *);
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 Supervisor 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 enteringError (toolbox::Event::Reference e) throw (toolbox::fsm::exception::Exception);
95 
96  void getSupervisorsStatus (void) 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 
109  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);
110  bool broadcastMessage(xoap::MessageReference msg) throw (toolbox::fsm::exception::Exception);
111 
112  bool supervisorGuiHasBeenLoaded_ ; //use to indicate first access by user of ots since execution
113 
114  //Variables
115  std::string outputDir_ ;
116  SupervisorDescriptorInfo theSupervisorDescriptorInfo_;
117  SupervisorsInfo theSupervisorsInfo_ ;
118  ConfigurationManager* theConfigurationManager_ ;
119  WebUsers theWebUsers_ ;
120  SystemMessenger theSysMessenger_ ;
121 
122  WorkLoopManager stateMachineWorkLoopManager_;
123  toolbox::BSem stateMachineSemaphore_ ;
124  WorkLoopManager infoRequestWorkLoopManager_ ;
125  toolbox::BSem infoRequestSemaphore_ ;
126 
127  std::string supervisorContextUID_ ;
128  std::string supervisorApplicationUID_ ;
129 
130  std::string activeStateMachineName_ ; //when multiple state machines, this is the name of the state machine which executed the configure transition
131  std::string activeStateMachineWindowName_ ;
132  std::pair<std::string /*group name*/, ConfigurationGroupKey> theConfigurationGroup_; //used to track the active configuration group at states after the configure state
133 
134  Iterator theIterator_ ;
135  std::mutex stateMachineAccessMutex_ ; //for sharing state machine access with iterator thread
136 
137  enum {
138  VERBOSE_MUTEX = 0
139  };
140 
141  //Trash tests
142  void wait(int milliseconds, std::string who="") const;
143  unsigned long long counterTest_ ;
144  std::vector<int> vectorTest_ ;
145  std::string securityType_;
146 
147 };
148 
149 }
150 
151 #endif
152