00001 #ifndef _Supervisor_Supervisor_h
00002 #define _Supervisor_Supervisor_h
00003
00004 #include "otsdaq-core/SOAPUtilities/SOAPMessenger.h"
00005 #include "otsdaq-core/WebUsersUtilities/WebUsers.h"
00006 #include "otsdaq-core/SystemMessenger/SystemMessenger.h"
00007 #include "otsdaq-core/WorkLoopManager/WorkLoopManager.h"
00008 #include "otsdaq-core/FiniteStateMachine/RunControlStateMachine.h"
00009 #include "otsdaq-core/Supervisor/SupervisorsInfo.h"
00010 #include "otsdaq-core/Supervisor/Iterator.h"
00011 #include "otsdaq-core/SupervisorDescriptorInfo/SupervisorDescriptorInfo.h"
00012 #include "otsdaq-core/ConfigurationDataFormats/ConfigurationGroupKey.h"
00013
00014 #pragma GCC diagnostic push
00015 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
00016 #include <xdaq/Application.h>
00017 #pragma GCC diagnostic pop
00018
00019 #include <toolbox/task/WorkLoop.h>
00020 #include <xgi/Method.h>
00021 #include <xdata/String.h>
00022
00023 #include <string>
00024 #include <set>
00025
00026
00027 #define FSM_LAST_CONFIGURED_GROUP_ALIAS_FILE std::string("FSMLastConfiguredGroupAlias.hist")
00028 #define FSM_LAST_STARTED_GROUP_ALIAS_FILE std::string("FSMLastStartedGroupAlias.hist")
00029
00030
00031 namespace ots
00032 {
00033
00034 class ConfigurationManager;
00035 class ConfigurationGroupKey;
00036 class WorkLoopManager;
00037
00038 class Supervisor: public xdaq::Application, public SOAPMessenger, public RunControlStateMachine
00039 {
00040 friend class OtsConfigurationWizardSupervisor;
00041 friend class Iterator;
00042
00043 public:
00044
00045 XDAQ_INSTANTIATOR();
00046
00047 Supervisor (xdaq::ApplicationStub * s) throw (xdaq::exception::Exception);
00048 virtual ~Supervisor(void);
00049
00050 void init (void);
00051 static void URLDisplayThread (Supervisor *);
00052 void Default (xgi::Input* in, xgi::Output* out ) throw (xgi::exception::Exception);
00053
00054
00055 void loginRequest (xgi::Input* in, xgi::Output* out ) throw (xgi::exception::Exception);
00056 void request (xgi::Input* in, xgi::Output* out ) throw (xgi::exception::Exception);
00057 void tooltipRequest (xgi::Input* in, xgi::Output* out ) throw (xgi::exception::Exception);
00058
00059
00060 void stateMachineXgiHandler (xgi::Input* in, xgi::Output* out ) throw (xgi::exception::Exception);
00061 void stateMachineResultXgiHandler (xgi::Input* in, xgi::Output* out ) throw (xgi::exception::Exception);
00062 xoap::MessageReference stateMachineXoapHandler (xoap::MessageReference msg ) throw (xoap::exception::Exception);
00063 xoap::MessageReference stateMachineResultXoapHandler (xoap::MessageReference msg ) throw (xoap::exception::Exception);
00064 bool stateMachineThread (toolbox::task::WorkLoop* workLoop);
00065
00066
00067 void infoRequestHandler (xgi::Input* in, xgi::Output* out ) throw (xgi::exception::Exception);
00068 void infoRequestResultHandler (xgi::Input* in, xgi::Output* out ) throw (xgi::exception::Exception);
00069 bool infoRequestThread (toolbox::task::WorkLoop* workLoop);
00070
00071
00072 xoap::MessageReference supervisorCookieCheck (xoap::MessageReference msg) throw (xoap::exception::Exception);
00073 xoap::MessageReference supervisorGetActiveUsers (xoap::MessageReference msg) throw (xoap::exception::Exception);
00074 xoap::MessageReference supervisorSystemMessage (xoap::MessageReference msg) throw (xoap::exception::Exception);
00075 xoap::MessageReference supervisorGetUserInfo (xoap::MessageReference msg) throw (xoap::exception::Exception);
00076 xoap::MessageReference supervisorSystemLogbookEntry (xoap::MessageReference msg) throw (xoap::exception::Exception);
00077 xoap::MessageReference supervisorLastConfigGroupRequest(xoap::MessageReference msg) throw (xoap::exception::Exception);
00078
00079
00080 void stateInitial (toolbox::fsm::FiniteStateMachine& fsm) throw (toolbox::fsm::exception::Exception);
00081 void statePaused (toolbox::fsm::FiniteStateMachine& fsm) throw (toolbox::fsm::exception::Exception);
00082 void stateRunning (toolbox::fsm::FiniteStateMachine& fsm) throw (toolbox::fsm::exception::Exception);
00083 void stateHalted (toolbox::fsm::FiniteStateMachine& fsm) throw (toolbox::fsm::exception::Exception);
00084 void stateConfigured (toolbox::fsm::FiniteStateMachine& fsm) throw (toolbox::fsm::exception::Exception);
00085 void inError (toolbox::fsm::FiniteStateMachine& fsm) throw (toolbox::fsm::exception::Exception);
00086
00087 void transitionConfiguring (toolbox::Event::Reference e) throw (toolbox::fsm::exception::Exception);
00088 void transitionHalting (toolbox::Event::Reference e) throw (toolbox::fsm::exception::Exception);
00089 void transitionInitializing (toolbox::Event::Reference e) throw (toolbox::fsm::exception::Exception);
00090 void transitionPausing (toolbox::Event::Reference e) throw (toolbox::fsm::exception::Exception);
00091 void transitionResuming (toolbox::Event::Reference e) throw (toolbox::fsm::exception::Exception);
00092 void transitionStarting (toolbox::Event::Reference e) throw (toolbox::fsm::exception::Exception);
00093 void transitionStopping (toolbox::Event::Reference e) throw (toolbox::fsm::exception::Exception);
00094 void enteringError (toolbox::Event::Reference e) throw (toolbox::fsm::exception::Exception);
00095
00096 void getSupervisorsStatus (void) throw (toolbox::fsm::exception::Exception);
00097
00098 void makeSystemLogbookEntry (std::string entryText);
00099
00100
00101
00102 private:
00103 unsigned int getNextRunNumber(const std::string &fsmName = "");
00104 bool setNextRunNumber(unsigned int runNumber, const std::string &fsmName = "");
00105 static std::pair<std::string , ConfigurationGroupKey> loadGroupNameAndKey(const std::string &fileName, std::string &returnedTimeString);
00106 void saveGroupNameAndKey(const std::pair<std::string /*group name*/, ConfigurationGroupKey> &theGroup, const std::string &fileName);
00107 static xoap::MessageReference lastConfigGroupRequestHandler(const SOAPParameters ¶meters);
00108
00109 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);
00110 bool broadcastMessage(xoap::MessageReference msg) throw (toolbox::fsm::exception::Exception);
00111
00112 bool supervisorGuiHasBeenLoaded_ ;
00113
00114
00115 std::string outputDir_ ;
00116 SupervisorDescriptorInfo theSupervisorDescriptorInfo_;
00117 SupervisorsInfo theSupervisorsInfo_ ;
00118 ConfigurationManager* theConfigurationManager_ ;
00119 WebUsers theWebUsers_ ;
00120 SystemMessenger theSysMessenger_ ;
00121
00122 WorkLoopManager stateMachineWorkLoopManager_;
00123 toolbox::BSem stateMachineSemaphore_ ;
00124 WorkLoopManager infoRequestWorkLoopManager_ ;
00125 toolbox::BSem infoRequestSemaphore_ ;
00126
00127 std::string supervisorContextUID_ ;
00128 std::string supervisorApplicationUID_ ;
00129
00130 std::string activeStateMachineName_ ;
00131 std::string activeStateMachineWindowName_ ;
00132 std::pair<std::string , ConfigurationGroupKey> theConfigurationGroup_;
00133
00134 Iterator theIterator_ ;
00135 std::mutex stateMachineAccessMutex_ ;
00136
00137 enum {
00138 VERBOSE_MUTEX = 0
00139 };
00140
00141
00142 void wait(int milliseconds, std::string who="") const;
00143 unsigned long long counterTest_ ;
00144 std::vector<int> vectorTest_ ;
00145 std::string securityType_;
00146
00147 };
00148
00149 }
00150
00151 #endif
00152