Event.h 928 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. #define INVALID_TIMER_ID ((TimerID)-1)
  11. typedef std::function<void(Event*)> EventCallback;
  12. typedef std::function<void(TimerID)> TimerCallback;
  13. struct Event {
  14. hevent_t event;
  15. EventCallback cb;
  16. Event(EventCallback cb = NULL) {
  17. memset(&event, 0, sizeof(hevent_t));
  18. this->cb = std::move(cb);
  19. }
  20. };
  21. struct Timer {
  22. htimer_t* timer;
  23. TimerCallback cb;
  24. int repeat;
  25. Timer(htimer_t* timer = NULL, TimerCallback cb = NULL, int repeat = INFINITE) {
  26. this->timer = timer;
  27. this->cb = std::move(cb);
  28. this->repeat = repeat;
  29. }
  30. };
  31. typedef std::shared_ptr<Event> EventPtr;
  32. typedef std::shared_ptr<Timer> TimerPtr;
  33. }
  34. #endif // HV_EVENT_HPP_