BeeeOn Gateway  v2020.3.1-2-g6f737dc
Platform to interconnect the IoT world
SequentialAsyncExecutor.h
1 #pragma once
2 
3 #include <queue>
4 
5 #include <Poco/AtomicCounter.h>
6 #include <Poco/Event.h>
7 #include <Poco/Mutex.h>
8 #include <Poco/Timespan.h>
9 
10 #include "loop/StoppableRunnable.h"
11 #include "util/AsyncExecutor.h"
12 #include "util/Loggable.h"
13 
14 namespace BeeeOn {
15 
17  public StoppableRunnable,
18  public AsyncExecutor,
19  Loggable {
20 public:
21  typedef Poco::SharedPtr<SequentialAsyncExecutor> Ptr;
22 
25 
26  void setStopTimeout(const Poco::Timespan &timeout);
27 
28  void invoke(std::function<void()> f) override;
29 
30  void run() override;
31  void stop() override;
32 
33 protected:
34  void finalize();
35 
36 private:
37  void execute(std::function<void()> task);
38  std::queue<std::function<void()>> m_taskQueue;
39  Poco::Event m_wakeupEvent;
40  Poco::FastMutex m_queueMutex;
41  Poco::AtomicCounter m_stopRequested;
42  Poco::Event m_stoppedEvent;
43  Poco::Timespan m_stopTimeout;
44 };
45 
46 }
Definition: SequentialAsyncExecutor.h:16
Definition: AsyncExecutor.h:12
void invoke(std::function< void()> f) override
Definition: SequentialAsyncExecutor.cpp:45
void stop() override
Definition: SequentialAsyncExecutor.cpp:114
Definition: Loggable.h:19
Definition: StoppableRunnable.h:8