00001 #ifndef _ots_Iterator_h
00002 #define _ots_Iterator_h
00003
00004
00005 #include "otsdaq-core/ConfigurationPluginDataFormats/IterateConfiguration.h"
00006 #include "otsdaq-core/XmlUtilities/HttpXmlDocument.h"
00007 #include <mutex>
00008 #include <string>
00009
00010 namespace ots
00011 {
00012
00013 class Supervisor;
00014 class ConfigurationManagerRW;
00015
00016 class Iterator
00017 {
00018 friend class Supervisor;
00019
00020 public:
00021 Iterator (Supervisor* supervisor);
00022 ~Iterator(void);
00023
00024 void playIterationPlan (HttpXmlDocument& xmldoc, const std::string& planName);
00025 void pauseIterationPlan (HttpXmlDocument& xmldoc);
00026 void haltIterationPlan (HttpXmlDocument& xmldoc);
00027 void getIterationPlanStatus (HttpXmlDocument& xmldoc);
00028
00029 bool handleCommandRequest (HttpXmlDocument& xmldoc, const std::string& command, const std::string& parameter);
00030
00031 private:
00032
00033
00034 struct IteratorWorkLoopStruct
00035 {
00036 IteratorWorkLoopStruct(Iterator* iterator, ConfigurationManagerRW* cfgMgr)
00037 :theIterator_ (iterator)
00038 ,cfgMgr_ (cfgMgr)
00039 ,running_ (false)
00040 ,commandBusy_ (false)
00041 ,doPauseAction_ (false)
00042 ,doHaltAction_ (false)
00043 ,doResumeAction_ (false)
00044 ,commandIndex_ ((unsigned int)-1)
00045 {}
00046
00047 Iterator * theIterator_;
00048 ConfigurationManagerRW* cfgMgr_;
00049
00050 bool running_, commandBusy_;
00051 bool doPauseAction_, doHaltAction_, doResumeAction_;
00052
00053 std::string activePlan_;
00054 std::vector<IterateConfiguration::Command> commands_;
00055 unsigned int commandIndex_;
00056 std::vector<unsigned int> stepIndexStack_;
00057
00058
00059 std::string fsmName_, fsmRunAlias_;
00060 unsigned int fsmNextRunNumber_;
00061
00062 std::vector<std::string> fsmCommandParameters_;
00063
00064
00065 };
00066
00067 static void IteratorWorkLoop (Iterator *iterator);
00068 static void startCommand (IteratorWorkLoopStruct *iteratorStruct);
00069 static bool checkCommand (IteratorWorkLoopStruct *iteratorStruct);
00070
00071 static void startCommandChooseFSM (IteratorWorkLoopStruct *iteratorStruct, const std::string& fsmName);
00072
00073 static void startCommandConfigureActive (IteratorWorkLoopStruct *iteratorStruct);
00074 static void startCommandConfigureAlias (IteratorWorkLoopStruct *iteratorStruct, const std::string& systemAlias);
00075 static void startCommandConfigureGroup (IteratorWorkLoopStruct *iteratorStruct);
00076 static bool checkCommandConfigure (IteratorWorkLoopStruct *iteratorStruct);
00077 static void startCommandModifyActive (IteratorWorkLoopStruct *iteratorStruct);
00078
00079 static void startCommandBeginLabel (IteratorWorkLoopStruct *iteratorStruct);
00080 static void startCommandRepeatLabel (IteratorWorkLoopStruct *iteratorStruct);
00081
00082 static void startCommandRun (IteratorWorkLoopStruct *iteratorStruct);
00083 static bool checkCommandRun (IteratorWorkLoopStruct *iteratorStruct);
00084
00085 static bool haltStateMachine (Supervisor* theSupervisor, const std::string& fsmName);
00086
00087 std::mutex accessMutex_;
00088 volatile bool workloopRunning_;
00089 volatile bool activePlanIsRunning_;
00090 volatile bool iteratorBusy_;
00091 volatile bool commandPlay_, commandPause_, commandHalt_;
00092 std::string activePlanName_, lastStartedPlanName_, lastFinishedPlanName_;
00093 volatile unsigned int activeCommandIndex_;
00094 volatile time_t activeCommandStartTime_;
00095 std::string lastFsmName_;
00096 std::string errorMessage_;
00097
00098 Supervisor* theSupervisor_;
00099 };
00100
00101 }
00102
00103 #endif