Timer.h 777 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. /*
  2. * This is the source code of tgnet library v. 1.1
  3. * It is licensed under GNU GPL v. 2 or later.
  4. * You should have received a copy of the license in this archive (see LICENSE).
  5. *
  6. * Copyright Nikolai Kudashov, 2015-2018.
  7. */
  8. #ifndef TIMER_H
  9. #define TIMER_H
  10. #include <stdint.h>
  11. #include <functional>
  12. #include <sys/epoll.h>
  13. class EventObject;
  14. class Timer {
  15. public:
  16. Timer(int32_t instance, std::function<void()> function);
  17. ~Timer();
  18. void start();
  19. void stop();
  20. void setTimeout(uint32_t ms, bool repeat);
  21. private:
  22. void onEvent();
  23. bool started = false;
  24. bool repeatable = false;
  25. int32_t instanceNum;
  26. uint32_t timeout = 0;
  27. std::function<void()> callback;
  28. EventObject *eventObject;
  29. friend class EventObject;
  30. };
  31. #endif