otsdaq  v2_04_02
Iterator.h
1 #ifndef _ots_Iterator_h
2 #define _ots_Iterator_h
3 
4 #include <mutex> //for std::mutex
5 #include <string>
6 #include "otsdaq/TablePlugins/IterateTable.h"
7 #include "otsdaq/XmlUtilities/HttpXmlDocument.h"
8 
9 #include "otsdaq/ConfigurationInterface/ConfigurationManagerRW.h"
10 
11 namespace ots
12 {
13 class GatewaySupervisor;
14 class ConfigurationManagerRW;
15 
16 class Iterator
17 {
18  friend class GatewaySupervisor;
19 
20  public:
21  Iterator(GatewaySupervisor* supervisor);
22  ~Iterator(void);
23 
24  void playIterationPlan(HttpXmlDocument& xmldoc, const std::string& planName);
25  void pauseIterationPlan(HttpXmlDocument& xmldoc);
26  void haltIterationPlan(HttpXmlDocument& xmldoc);
27  void getIterationPlanStatus(HttpXmlDocument& xmldoc);
28 
29  bool handleCommandRequest(HttpXmlDocument& xmldoc,
30  const std::string& command,
31  const std::string& parameter);
32 
33  private:
34  // begin declaration of iterator workloop members
35  struct IteratorWorkLoopStruct
36  {
37  IteratorWorkLoopStruct(Iterator* iterator, ConfigurationManagerRW* cfgMgr)
38  : theIterator_(iterator)
39  , cfgMgr_(cfgMgr)
40  , originalTrackChanges_(false)
41  , running_(false)
42  , commandBusy_(false)
43  , doPauseAction_(false)
44  , doHaltAction_(false)
45  , doResumeAction_(false)
46  , commandIndex_((unsigned int)-1)
47  {
48  }
49 
50  Iterator* theIterator_;
51  ConfigurationManagerRW* cfgMgr_;
52  bool originalTrackChanges_;
53  std::string originalConfigGroup_;
54  TableGroupKey originalConfigKey_;
55 
56  bool running_, commandBusy_;
57  bool doPauseAction_, doHaltAction_, doResumeAction_;
58 
59  std::string activePlan_;
60  std::vector<IterateTable::Command> commands_;
61  std::vector<unsigned int> commandIterations_;
62  unsigned int commandIndex_;
63  std::vector<unsigned int> stepIndexStack_;
64  time_t originalDurationInSeconds_;
65 
66  // associated with FSM
67  std::string fsmName_, fsmRunAlias_;
68  unsigned int fsmNextRunNumber_;
69  bool runIsDone_;
70 
71  std::vector<std::string> fsmCommandParameters_;
72  std::vector<bool> targetsDone_;
73 
74  }; // end declaration of iterator workloop members
75 
76  static void IteratorWorkLoop(Iterator* iterator);
77  static void startCommand(IteratorWorkLoopStruct* iteratorStruct);
78  static bool checkCommand(IteratorWorkLoopStruct* iteratorStruct);
79 
80  static void startCommandChooseFSM(IteratorWorkLoopStruct* iteratorStruct,
81  const std::string& fsmName);
82 
83  static void startCommandConfigureActive(IteratorWorkLoopStruct* iteratorStruct);
84  static void startCommandConfigureAlias(IteratorWorkLoopStruct* iteratorStruct,
85  const std::string& systemAlias);
86  static void startCommandConfigureGroup(IteratorWorkLoopStruct* iteratorStruct);
87  static bool checkCommandConfigure(IteratorWorkLoopStruct* iteratorStruct);
88 
89  static void startCommandModifyActive(IteratorWorkLoopStruct* iteratorStruct);
90 
91  static void startCommandMacro(IteratorWorkLoopStruct* iteratorStruct, bool isFEMacro);
92  static bool checkCommandMacro(IteratorWorkLoopStruct* iteratorStruct, bool isFEMacro);
93 
94  static void startCommandBeginLabel(IteratorWorkLoopStruct* iteratorStruct);
95  static void startCommandRepeatLabel(IteratorWorkLoopStruct* iteratorStruct);
96 
97  static void startCommandRun(IteratorWorkLoopStruct* iteratorStruct);
98  static bool checkCommandRun(IteratorWorkLoopStruct* iteratorStruct);
99 
100  static bool haltIterator(
101  Iterator* iterator,
102  IteratorWorkLoopStruct* iteratorStruct =
103  0); //(GatewaySupervisor* theSupervisor, const std::string& fsmName);
104 
105  std::mutex accessMutex_;
106  volatile bool workloopRunning_;
107  volatile bool activePlanIsRunning_;
108  volatile bool iteratorBusy_;
109  volatile bool commandPlay_, commandPause_,
110  commandHalt_; // commands are set by
111  // supervisor thread, and
112  // cleared by iterator thread
113  std::string activePlanName_, lastStartedPlanName_, lastFinishedPlanName_;
114  volatile unsigned int activeCommandIndex_, activeCommandIteration_;
115  std::vector<unsigned int> depthIterationStack_;
116  volatile time_t activeCommandStartTime_;
117  std::string lastFsmName_;
118  std::string errorMessage_;
119 
120  GatewaySupervisor* theSupervisor_;
121 
122  template<class T> // defined in included .icc source
123  static void helpCommandModifyActive(IteratorWorkLoopStruct* iteratorStruct,
124  const T& setValue,
125  bool doTrackGroupChanges);
126 };
127 
128 #include "otsdaq/GatewaySupervisor/Iterator.icc" //for template definitions
129 
130 } // namespace ots
131 
132 #endif