Pakman
SerialMaster.h
1 #ifndef SERIALMASTER_H
2 #define SERIALMASTER_H
3 
4 #include <string>
5 #include <queue>
6 
7 #include "core/common.h"
8 
9 #include "AbstractMaster.h"
10 
11 class LongOptions;
12 class Arguments;
13 
27 {
28  public:
29 
36  SerialMaster(const Command& simulator, bool *p_program_terminated);
37 
39  virtual ~SerialMaster() override = default;
40 
42  virtual bool isActive() const override;
43 
45  virtual bool needMorePendingTasks() const override;
46 
51  virtual void pushPendingTask(const std::string& input_string) override;
52 
54  virtual bool finishedTasksEmpty() const override;
55 
57  virtual TaskHandler& frontFinishedTask() override;
58 
60  virtual void popFinishedTask() override;
61 
63  virtual void flush() override;
64 
66  virtual void terminate() override;
67 
69  static std::string help();
70 
75  static void addLongOptions(LongOptions& lopts);
76 
85  static void run(controller_t controller, const Arguments& args);
86 
88  static void cleanup();
89 
90  protected:
91 
93  virtual void iterate() override;
94 
95  private:
96 
104  enum state_t { normal, terminated };
105 
107  // Processes a task from pending queue if there is one and places it in
108  // the finished queue when done.
109  void processTask();
110 
112  // Initial state is normal
113  state_t m_state = normal;
114 
115  // Simulator command
116  const Command m_simulator;
117 
118  // Finished tasks
119  std::queue<TaskHandler> m_finished_tasks;
120 
121  // Pending tasks
122  std::queue<TaskHandler> m_pending_tasks;
123 
124  // Entered iterate()
125  bool m_entered = false;
126 };
127 
128 #endif // SERIALMASTER_H
static void run(controller_t controller, const Arguments &args)
virtual void iterate() override
Definition: SerialMaster.cc:26
controller_t
Definition: common.h:45
virtual bool needMorePendingTasks() const override
Definition: SerialMaster.cc:55
virtual TaskHandler & frontFinishedTask() override
Definition: SerialMaster.cc:73
static void addLongOptions(LongOptions &lopts)
virtual bool finishedTasksEmpty() const override
Definition: SerialMaster.cc:67
static void cleanup()
virtual void popFinishedTask() override
Definition: SerialMaster.cc:79
virtual void pushPendingTask(const std::string &input_string) override
Definition: SerialMaster.cc:61
static std::string help()
SerialMaster(const Command &simulator, bool *p_program_terminated)
Definition: SerialMaster.cc:13
virtual void flush() override
Definition: SerialMaster.cc:85
virtual void terminate() override
Definition: SerialMaster.cc:92
virtual bool isActive() const override
Definition: SerialMaster.cc:20
virtual ~SerialMaster() override=default