eloop.h 2.3 KB

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