SPSP
Simple publish-subscribe protocol. Connects low power IoT clients to MQTT.
All Classes Files Functions Variables Typedefs Enumerations
timer.hpp
Go to the documentation of this file.
1 
10 #pragma once
11 
12 #include <chrono>
13 #include <condition_variable>
14 #include <exception>
15 #include <functional>
16 #include <mutex>
17 #include <thread>
18 
19 namespace SPSP
20 {
27  class Timer
28  {
29  std::mutex m_mutex;
30  std::chrono::milliseconds m_interval;
31  std::chrono::steady_clock::time_point m_nextExec;
32  bool m_run;
33  std::function<void()> m_cb;
34  std::condition_variable m_cv;
35  std::thread m_thread;
36 
37  public:
47  Timer(const std::chrono::milliseconds interval,
48  std::function<void()> cb);
49 
54  ~Timer();
55 
56  protected:
61  void handlerThread();
62  };
63 } // namespace SPSP
SPSP::Timer
Simple timer for SPSP purposes.
Definition: timer.hpp:27
SPSP::Timer::handlerThread
void handlerThread()
Timer handler thread.
SPSP::Timer::Timer
Timer(const std::chrono::milliseconds interval, std::function< void()> cb)
Constructs a new timer.
SPSP::Timer::~Timer
~Timer()
Destroys the timer.