otsdaq  v1_01_04
 All Classes Namespaces Functions
Iterator.h
1 #ifndef _ots_Iterator_h
2 #define _ots_Iterator_h
3 
4 
5 #include "otsdaq-core/ConfigurationPluginDataFormats/IterateConfiguration.h"
6 #include "otsdaq-core/XmlUtilities/HttpXmlDocument.h"
7 #include <mutex> //for std::mutex
8 #include <string>
9 
10 namespace ots
11 {
12 
13 class Supervisor;
14 class ConfigurationManagerRW;
15 
16 class Iterator
17 {
18  friend class Supervisor;
19 
20 public:
21  Iterator (Supervisor* 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, const std::string& command, const std::string& parameter);
30 
31 private:
32 
33  //begin declaration of iterator workloop members
34  struct IteratorWorkLoopStruct
35  {
36  IteratorWorkLoopStruct(Iterator* iterator, ConfigurationManagerRW* cfgMgr)
37  :theIterator_ (iterator)
38  ,cfgMgr_ (cfgMgr)
39  ,running_ (false)
40  ,commandBusy_ (false)
41  ,doPauseAction_ (false)
42  ,doHaltAction_ (false)
43  ,doResumeAction_ (false)
44  ,commandIndex_ ((unsigned int)-1)
45  {}
46 
47  Iterator * theIterator_;
48  ConfigurationManagerRW* cfgMgr_;
49 
50  bool running_, commandBusy_;
51  bool doPauseAction_, doHaltAction_, doResumeAction_;
52 
53  std::string activePlan_;
54  std::vector<IterateConfiguration::Command> commands_;
55  unsigned int commandIndex_;
56  std::vector<unsigned int> stepIndexStack_;
57 
58  //associated with FSM
59  std::string fsmName_, fsmRunAlias_;
60  unsigned int fsmNextRunNumber_;
61 
62  std::vector<std::string> fsmCommandParameters_;
63 
64 
65  }; //end declaration of iterator workloop members
66 
67  static void IteratorWorkLoop (Iterator *iterator);
68  static void startCommand (IteratorWorkLoopStruct *iteratorStruct);
69  static bool checkCommand (IteratorWorkLoopStruct *iteratorStruct);
70 
71  static void startCommandChooseFSM (IteratorWorkLoopStruct *iteratorStruct, const std::string& fsmName);
72 
73  static void startCommandConfigureActive (IteratorWorkLoopStruct *iteratorStruct);
74  static void startCommandConfigureAlias (IteratorWorkLoopStruct *iteratorStruct, const std::string& systemAlias);
75  static void startCommandConfigureGroup (IteratorWorkLoopStruct *iteratorStruct);
76  static bool checkCommandConfigure (IteratorWorkLoopStruct *iteratorStruct);
77  static void startCommandModifyActive (IteratorWorkLoopStruct *iteratorStruct);
78 
79  static void startCommandBeginLabel (IteratorWorkLoopStruct *iteratorStruct);
80  static void startCommandRepeatLabel (IteratorWorkLoopStruct *iteratorStruct);
81 
82  static void startCommandRun (IteratorWorkLoopStruct *iteratorStruct);
83  static bool checkCommandRun (IteratorWorkLoopStruct *iteratorStruct);
84 
85  static bool haltStateMachine (Supervisor* theSupervisor, const std::string& fsmName);
86 
87  std::mutex accessMutex_;
88  volatile bool workloopRunning_;
89  volatile bool activePlanIsRunning_;
90  volatile bool iteratorBusy_;
91  volatile bool commandPlay_, commandPause_, commandHalt_; //commands are set by supervisor thread, and cleared by iterator thread
92  std::string activePlanName_, lastStartedPlanName_, lastFinishedPlanName_;
93  volatile unsigned int activeCommandIndex_;
94  volatile time_t activeCommandStartTime_;
95  std::string lastFsmName_;
96  std::string errorMessage_;
97 
98  Supervisor* theSupervisor_;
99 };
100 
101 }
102 
103 #endif