eloop.h 2.3 KB

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