otsdaq  v2_04_01
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-core/TablePlugins/IterateTable.h"
7 #include "otsdaq-core/XmlUtilities/HttpXmlDocument.h"
8 
9 #include "otsdaq-core/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 
65  // associated with FSM
66  std::string fsmName_, fsmRunAlias_;
67  unsigned int fsmNextRunNumber_;
68  bool runIsDone_;
69 
70  std::vector<std::string> fsmCommandParameters_;
71  std::vector<bool> targetsDone_;
72 
73  }; // end declaration of iterator workloop members
74 
75  static void IteratorWorkLoop(Iterator* iterator);
76  static void startCommand(IteratorWorkLoopStruct* iteratorStruct);
77  static bool checkCommand(IteratorWorkLoopStruct* iteratorStruct);
78 
79  static void startCommandChooseFSM(IteratorWorkLoopStruct* iteratorStruct,
80  const std::string& fsmName);
81 
82  static void startCommandConfigureActive(IteratorWorkLoopStruct* iteratorStruct);
83  static void startCommandConfigureAlias(IteratorWorkLoopStruct* iteratorStruct,
84  const std::string& systemAlias);
85  static void startCommandConfigureGroup(IteratorWorkLoopStruct* iteratorStruct);
86  static bool checkCommandConfigure(IteratorWorkLoopStruct* iteratorStruct);
87 
88  static void startCommandModifyActive(IteratorWorkLoopStruct* iteratorStruct);
89 
90  static void startCommandMacro(IteratorWorkLoopStruct* iteratorStruct, bool isFEMacro);
91  static bool checkCommandMacro(IteratorWorkLoopStruct* iteratorStruct, bool isFEMacro);
92 
93  static void startCommandBeginLabel(IteratorWorkLoopStruct* iteratorStruct);
94  static void startCommandRepeatLabel(IteratorWorkLoopStruct* iteratorStruct);
95 
96  static void startCommandRun(IteratorWorkLoopStruct* iteratorStruct);
97  static bool checkCommandRun(IteratorWorkLoopStruct* iteratorStruct);
98 
99  static bool haltIterator(
100  Iterator* iterator,
101  IteratorWorkLoopStruct* iteratorStruct =
102  0); //(GatewaySupervisor* theSupervisor, const std::string& fsmName);
103 
104  std::mutex accessMutex_;
105  volatile bool workloopRunning_;
106  volatile bool activePlanIsRunning_;
107  volatile bool iteratorBusy_;
108  volatile bool commandPlay_, commandPause_,
109  commandHalt_; // commands are set by
110  // supervisor thread, and
111  // cleared by iterator thread
112  std::string activePlanName_, lastStartedPlanName_, lastFinishedPlanName_;
113  volatile unsigned int activeCommandIndex_, activeCommandIteration_;
114  std::vector<unsigned int> depthIterationStack_;
115  volatile time_t activeCommandStartTime_;
116  std::string lastFsmName_;
117  std::string errorMessage_;
118 
119  GatewaySupervisor* theSupervisor_;
120 
121  template<class T> // defined in included .icc source
122  static void helpCommandModifyActive(IteratorWorkLoopStruct* iteratorStruct,
123  const T& setValue,
124  bool doTrackGroupChanges);
125 };
126 
127 #include "otsdaq-core/GatewaySupervisor/Iterator.icc" //for template definitions
128 
129 } // namespace ots
130 
131 #endif