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