| 6 |
| * Copyright Nikolai Kudashov, 2015-2018. |
| 7 | */ |
| 8 |
| 9 | #ifndef TIMER_H |
| 10 | #define TIMER_H |
| 11 |
| 12 | #include <stdint.h> |
| 13 | #include <functional> |
| 14 | #include <sys/epoll.h> |
| 15 |
| 16 | class EventObject; |
| 17 |
| 18 | class Timer { |
| 19 |
| 20 | public: |
| 21 | Timer(int32_t instance, std::function<void()> function); |
| 22 | ~Timer(); |
| 23 |
| 24 | void start(); |
| 25 | void stop(); |
| 26 | void setTimeout(uint32_t ms, bool repeat); |
| 27 |
| 28 | private: |
| 29 | void onEvent(); |
| 30 |
| 31 | bool started = false; |
| 32 | bool repeatable = false; |
| 33 | int32_t instanceNum; |
| 34 | uint32_t timeout = 0; |
| 35 | std::function<void()> callback; |
| 36 | EventObject *eventObject; |
| 37 |
| 38 | friend class EventObject; |
| 39 | }; |
| 40 |
| 41 | #endif |
| 42 |