BeeeOn Gateway  v2020.3.1-2-g6f737dc
Platform to interconnect the IoT world
StopControl.h
1 #pragma once
2 
3 #include <Poco/Condition.h>
4 #include <Poco/Mutex.h>
5 #include <Poco/Timespan.h>
6 
7 namespace BeeeOn {
8 
12 class StopControl {
13 public:
35  class Run {
36  public:
37  Run(StopControl &control);
38  ~Run();
39 
43  bool waitStoppable(const Poco::Timespan &timeout);
44 
48  operator bool() const;
49 
50  private:
51  StopControl &m_control;
52  };
53 
54  StopControl();
55 
63  bool waitStoppable(const Poco::Timespan &timeout);
64 
69  bool shouldStop() const;
70 
75  void requestStop();
76 
80  void requestWakeup();
81 
85  void clear();
86 
87 protected:
91  bool doWait(long ms);
92 
93 private:
94  bool m_stop;
95  mutable Poco::FastMutex m_lock;
96  Poco::Condition m_condition;
97 };
98 
99 }
bool doWait(long ms)
Definition: StopControl.cpp:40
bool shouldStop() const
Definition: StopControl.cpp:66
Helper class for managing a common stoppable loop situation:
Definition: StopControl.h:35
void clear()
Definition: StopControl.cpp:86
bool waitStoppable(const Poco::Timespan &timeout)
Definition: StopControl.cpp:50
StopControl implements the stop mechanism generically.
Definition: StopControl.h:12
void requestWakeup()
Definition: StopControl.cpp:81
void requestStop()
Definition: StopControl.cpp:73
bool waitStoppable(const Poco::Timespan &timeout)
Delegates to StopControl::waitStoppable().
Definition: StopControl.cpp:25