eloop.h 2.3 KB

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