BeeeOn Gateway  v2020.3.1-2-g6f737dc
Platform to interconnect the IoT world
Tool.h
1 #pragma once
2 
3 #include <string>
4 #include <vector>
5 
6 #include <Poco/AtomicCounter.h>
7 #include <Poco/Event.h>
8 #include <Poco/RunnableAdapter.h>
9 #include <Poco/SharedPtr.h>
10 #include <Poco/Thread.h>
11 
12 #include "io/Console.h"
13 #include "loop/StoppableLoop.h"
14 #include "loop/StopControl.h"
15 #include "util/Loggable.h"
16 
17 namespace BeeeOn {
18 
43 class Tool :
44  public StoppableLoop,
45  protected virtual Loggable {
46 public:
47  typedef Poco::SharedPtr<Tool> Ptr;
48 
49  Tool(bool terminate = true, bool repeat = false);
50 
51  void setTerminate(bool terminate);
52  void setRepeat(bool repeat);
53  void setCommand(const std::string &command);
54  void setConsole(Console::Ptr console);
55 
60  void start() override;
61 
67  void stop() override;
68 
69 protected:
78  virtual void main(
79  ConsoleSession &session,
80  const std::vector<std::string> &args) = 0;
81 
85  bool shouldStop() const;
86 
94  void parseAndRun();
95 
100  void startSession(const std::vector<std::string> &args);
101 
105  std::string command() const;
106 
111 
112 private:
113  bool m_terminate;
114  bool m_repeat;
115  std::string m_command;
116  Console::Ptr m_console;
117  StopControl m_stopControl;
118  Poco::RunnableAdapter<Tool> m_runner;
119  Poco::Thread m_thread;
120 };
121 
122 }
The purpose of the class Tool is to provide a common set of features for loops that are to be used as...
Definition: Tool.h:43
void startSession(const std::vector< std::string > &args)
Definition: Tool.cpp:63
Definition: StoppableLoop.h:17
std::string command() const
Definition: Tool.cpp:41
virtual void main(ConsoleSession &session, const std::vector< std::string > &args)=0
StopControl implements the stop mechanism generically.
Definition: StopControl.h:12
void stop() override
Definition: Tool.cpp:51
Definition: Loggable.h:19
void parseAndRun()
Definition: Tool.cpp:73
bool shouldStop() const
Definition: Tool.cpp:105
StopControl & stopControl()
Definition: Tool.cpp:58
Definition: Console.h:70
void start() override
Definition: Tool.cpp:46