1 #ifndef _ots_GatewaySupervisor_h
2 #define _ots_GatewaySupervisor_h
4 #include "otsdaq/CoreSupervisors/ConfigurationSupervisorBase.h"
5 #include "otsdaq/CoreSupervisors/CorePropertySupervisorBase.h"
6 #include "otsdaq/FiniteStateMachine/RunControlStateMachine.h"
7 #include "otsdaq/GatewaySupervisor/Iterator.h"
8 #include "otsdaq/SOAPUtilities/SOAPMessenger.h"
9 #include "otsdaq/SupervisorInfo/AllSupervisorInfo.h"
12 #include "otsdaq/WebUsersUtilities/WebUsers.h"
13 #include "otsdaq/WorkLoopManager/WorkLoopManager.h"
15 #include "otsdaq/CodeEditor/CodeEditor.h"
16 #include "otsdaq/TablePlugins/DesktopIconTable.h"
18 #pragma GCC diagnostic push
19 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
20 #include <xdaq/Application.h>
21 #pragma GCC diagnostic pop
22 #include "otsdaq/Macros/XDAQApplicationMacros.h"
24 #include <toolbox/task/WorkLoop.h>
25 #include <xdata/String.h>
26 #include <xgi/Method.h>
33 #define FSM_LAST_CONFIGURED_GROUP_ALIAS_FILE std::string("FSMLastConfiguredGroupAlias.hist")
34 #define FSM_LAST_STARTED_GROUP_ALIAS_FILE std::string("FSMLastStartedGroupAlias.hist")
38 class ConfigurationManager;
40 class WorkLoopManager;
65 void Default(xgi::Input* in, xgi::Output* out);
67 void loginRequest(xgi::Input* in, xgi::Output* out);
68 void request(xgi::Input* in, xgi::Output* out);
69 void tooltipRequest(xgi::Input* in, xgi::Output* out);
72 void stateMachineXgiHandler(xgi::Input* in, xgi::Output* out);
73 void stateMachineIterationBreakpoint(xgi::Input* in, xgi::Output* out);
75 static std::string getIconHeaderString(
void);
76 static bool handleAddDesktopIconRequest(
const std::string& author, cgicc::Cgicc& cgiIn,
HttpXmlDocument& xmlOut, std::vector<DesktopIconTable::DesktopIcon>* newIcons =
nullptr);
79 xoap::MessageReference stateMachineXoapHandler(xoap::MessageReference msg);
81 bool stateMachineThread(toolbox::task::WorkLoop* workLoop);
84 void statusRequest(xgi::Input* in, xgi::Output* out);
85 void infoRequestResultHandler(xgi::Input* in, xgi::Output* out);
86 bool infoRequestThread(toolbox::task::WorkLoop* workLoop);
89 xoap::MessageReference supervisorCookieCheck(xoap::MessageReference msg);
90 xoap::MessageReference supervisorGetActiveUsers(xoap::MessageReference msg);
91 xoap::MessageReference supervisorSystemMessage(xoap::MessageReference msg);
92 xoap::MessageReference supervisorGetUserInfo(xoap::MessageReference msg);
93 xoap::MessageReference supervisorSystemLogbookEntry(xoap::MessageReference msg);
94 xoap::MessageReference supervisorLastTableGroupRequest(xoap::MessageReference msg);
97 void stateInitial(toolbox::fsm::FiniteStateMachine& fsm)
override;
98 void statePaused(toolbox::fsm::FiniteStateMachine& fsm)
override;
99 void stateRunning(toolbox::fsm::FiniteStateMachine& fsm)
override;
100 void stateHalted(toolbox::fsm::FiniteStateMachine& fsm)
override;
101 void stateConfigured(toolbox::fsm::FiniteStateMachine& fsm)
override;
102 void inError(toolbox::fsm::FiniteStateMachine& fsm)
override;
104 void transitionConfiguring(toolbox::Event::Reference e)
override;
105 void transitionHalting(toolbox::Event::Reference e)
override;
106 void transitionInitializing(toolbox::Event::Reference e)
override;
107 void transitionPausing(toolbox::Event::Reference e)
override;
108 void transitionResuming(toolbox::Event::Reference e)
override;
109 void transitionStarting(toolbox::Event::Reference e)
override;
110 void transitionStopping(toolbox::Event::Reference e)
override;
111 void transitionShuttingDown(toolbox::Event::Reference e)
override;
112 void transitionStartingUp(toolbox::Event::Reference e)
override;
113 void enteringError(toolbox::Event::Reference e)
override;
115 void makeSystemLogbookEntry(std::string entryText);
117 void checkForAsyncError(
void);
120 virtual void setSupervisorPropertyDefaults(
void)
override;
121 virtual void forceSupervisorPropertyValues(
void)
override;
127 unsigned int getNextRunNumber(
const std::string& fsmName =
"");
128 bool setNextRunNumber(
unsigned int runNumber,
const std::string& fsmName =
"");
130 static xoap::MessageReference lastTableGroupRequestHandler(
const SOAPParameters& parameters);
138 std::ostringstream* out,
139 const std::string& command,
140 const std::string& fsmName,
141 const std::string& fsmWindowName,
142 const std::string& username,
143 const std::vector<std::string>& parameters);
144 void broadcastMessage(xoap::MessageReference msg);
146 struct BroadcastMessageIterationsDoneStruct
152 ~BroadcastMessageIterationsDoneStruct()
154 for (
auto& arr : iterationsDone_)
156 iterationsDone_.clear();
160 void push(
const unsigned int& size)
162 iterationsDone_.push_back(
new bool[size]);
163 arraySizes_.push_back(size);
166 for (
unsigned int i = 0; i < size; ++i)
167 iterationsDone_[iterationsDone_.size() - 1][i] =
false;
170 bool* operator[](
unsigned int i) {
return iterationsDone_[i]; }
171 const bool* operator[](
unsigned int i)
const {
return iterationsDone_[i]; }
172 unsigned int size(
unsigned int i = -1)
174 if (i == (
unsigned int)-1)
175 return iterationsDone_.size();
176 return arraySizes_[i];
180 std::vector<bool*> iterationsDone_;
181 std::vector<unsigned int> arraySizes_;
184 struct BroadcastThreadStruct
187 BroadcastThreadStruct()
200 xoap::MessageReference message,
201 const std::string& command,
202 const unsigned int& iteration,
203 bool& iterationsDone)
207 , iteration_(iteration)
208 , iterationsDone_(iterationsDone)
213 xoap::MessageReference message_;
214 const std::string& command_;
215 const unsigned int& iteration_;
216 bool& iterationsDone_;
223 xoap::MessageReference message,
224 const std::string& command,
225 const unsigned int& iteration,
226 bool& iterationsDone)
230 appInfo, message, command, iteration, iterationsDone));
234 const SupervisorInfo& getAppInfo() {
return messages_[0].appInfo_; }
235 xoap::MessageReference getMessage() {
return messages_[0].message_; }
236 const std::string& getCommand() {
return messages_[0].command_; }
237 const unsigned int& getIteration() {
return messages_[0].iteration_; }
238 std::string& getReply() {
return messages_[0].reply_; }
239 bool& getIterationsDone() {
return messages_[0].iterationsDone_; }
242 std::mutex threadMutex;
243 unsigned int threadIndex_;
244 volatile bool exitThread_, working_, workToDo_, error_;
246 std::vector<BroadcastThreadStruct::BroadcastMessageStruct> messages_;
249 static void broadcastMessageThread(
250 GatewaySupervisor* supervisorPtr,
251 GatewaySupervisor::BroadcastThreadStruct* threadStruct);
252 bool handleBroadcastMessageTarget(
const SupervisorInfo& appInfo,
253 xoap::MessageReference message,
254 const std::string& command,
255 const unsigned int& iteration,
257 unsigned int threadIndex = 0);
259 bool supervisorGuiHasBeenLoaded_;
264 static WebUsers theWebUsers_;
266 WorkLoopManager stateMachineWorkLoopManager_;
267 toolbox::BSem stateMachineSemaphore_;
269 std::string activeStateMachineName_;
272 std::string activeStateMachineWindowName_;
273 std::pair<std::string , TableGroupKey>
274 theConfigurationTableGroup_;
277 Iterator theIterator_;
278 std::mutex stateMachineAccessMutex_;
280 std::string stateMachineLastCommandInput_;
287 CodeEditor codeEditor_;
289 std::mutex broadcastCommandMessageIndexMutex_, broadcastIterationsDoneMutex_;
290 unsigned int broadcastCommandMessageIndex_;
291 bool broadcastIterationsDone_;
292 std::mutex broadcastIterationBreakpointMutex_;
293 unsigned int broadcastIterationBreakpoint_;
297 char tmpStringForConversions_[100];
299 std::string securityType_;