eloop.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /** @file eloop.h
  2. * @brief Public interface for Event Loop.
  3. */
  4. #ifndef _faux_eloop_h
  5. #define _faux_eloop_h
  6. #include <faux/faux.h>
  7. typedef struct faux_eloop_s faux_eloop_t;
  8. typedef enum {
  9. FAUX_ELOOP_NULL = 0,
  10. FAUX_ELOOP_SIGNAL = 1,
  11. FAUX_ELOOP_SCHED = 2,
  12. FAUX_ELOOP_FD = 3
  13. } faux_eloop_type_e;
  14. typedef struct {
  15. int ev_id;
  16. } faux_eloop_info_sched_t;
  17. typedef struct {
  18. int fd;
  19. short revents;
  20. } faux_eloop_info_fd_t;
  21. typedef struct {
  22. int signo;
  23. } faux_eloop_info_signal_t;
  24. // Callback function prototype
  25. typedef bool_t faux_eloop_cb_f(faux_eloop_t *eloop, faux_eloop_type_e type,
  26. void *associated_data, void *user_data);
  27. C_DECL_BEGIN
  28. faux_eloop_t *faux_eloop_new(faux_eloop_cb_f *default_event_cb);
  29. void faux_eloop_free(faux_eloop_t *eloop);
  30. bool_t faux_eloop_loop(faux_eloop_t *eloop);
  31. bool_t faux_eloop_add_fd(faux_eloop_t *eloop, int fd, short events,
  32. faux_eloop_cb_f *event_cb, void *user_data);
  33. bool_t faux_eloop_del_fd(faux_eloop_t *eloop, int fd);
  34. bool_t faux_eloop_add_signal(faux_eloop_t *eloop, int signo,
  35. faux_eloop_cb_f *event_cb, void *user_data);
  36. bool_t faux_eloop_del_signal(faux_eloop_t *eloop, int signo);
  37. bool_t faux_eloop_add_sched_once(faux_eloop_t *eloop, const struct timespec *time,
  38. int ev_id, faux_eloop_cb_f *event_cb, void *data);
  39. bool_t faux_eloop_add_sched_once_delayed(faux_eloop_t *eloop, const struct timespec *interval,
  40. int ev_id, faux_eloop_cb_f *event_cb, void *data);
  41. bool_t faux_eloop_add_sched_periodic(faux_eloop_t *eloop, const struct timespec *time,
  42. int ev_id, faux_eloop_cb_f *event_cb, void *data,
  43. const struct timespec *period, unsigned int cycle_num);
  44. bool_t faux_eloop_add_sched_periodic_delayed(faux_eloop_t *eloop,
  45. int ev_id, faux_eloop_cb_f *event_cb, void *data,
  46. const struct timespec *period, unsigned int cycle_num);
  47. bool_t faux_eloop_del_sched(faux_eloop_t *eloop, int id);
  48. C_DECL_END
  49. #endif