eloop.h 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. C_DECL_END
  38. #endif