Event.h 856 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #ifndef HV_EVENT_HPP_
  2. #define HV_EVENT_HPP_
  3. #include <functional>
  4. #include <memory>
  5. #include "hloop.h"
  6. namespace hv {
  7. struct Event;
  8. struct Timer;
  9. typedef uint64_t TimerID;
  10. typedef std::function<void(Event*)> EventCallback;
  11. typedef std::function<void(TimerID)> TimerCallback;
  12. struct Event {
  13. hevent_t event;
  14. EventCallback cb;
  15. Event(EventCallback cb = NULL) {
  16. memset(&event, 0, sizeof(hevent_t));
  17. this->cb = cb;
  18. }
  19. };
  20. struct Timer {
  21. htimer_t* timer;
  22. TimerCallback cb;
  23. int repeat;
  24. Timer(htimer_t* timer = NULL, TimerCallback cb = NULL, int repeat = INFINITE) {
  25. this->timer = timer;
  26. this->cb = cb;
  27. this->repeat = repeat;
  28. }
  29. };
  30. typedef std::shared_ptr<Event> EventPtr;
  31. typedef std::shared_ptr<Timer> TimerPtr;
  32. }
  33. #endif // HV_EVENT_HPP_