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