tevent: use HAVE_EPOLL instead of HAVE_EVENTS_EPOLL
[ira/wip.git] / lib / tevent / tevent_internal.h
1 /* 
2    Unix SMB/CIFS implementation.
3
4    generalised event loop handling
5
6    Internal structs
7
8    Copyright (C) Stefan Metzmacher 2005
9    
10    This program is free software; you can redistribute it and/or modify
11    it under the terms of the GNU General Public License as published by
12    the Free Software Foundation; either version 3 of the License, or
13    (at your option) any later version.
14    
15    This program is distributed in the hope that it will be useful,
16    but WITHOUT ANY WARRANTY; without even the implied warranty of
17    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18    GNU General Public License for more details.
19    
20    You should have received a copy of the GNU General Public License
21    along with this program.  If not, see <http://www.gnu.org/licenses/>.
22 */
23
24 struct tevent_ops {
25         /* conntext init */
26         int (*context_init)(struct tevent_context *ev);
27
28         /* fd_event functions */
29         struct tevent_fd *(*add_fd)(struct tevent_context *ev,
30                                     TALLOC_CTX *mem_ctx,
31                                     int fd, uint16_t flags,
32                                     tevent_fd_handler_t handler,
33                                     void *private_data);
34         uint16_t (*get_fd_flags)(struct tevent_fd *fde);
35         void (*set_fd_flags)(struct tevent_fd *fde, uint16_t flags);
36
37         /* timed_event functions */
38         struct tevent_timer *(*add_timer)(struct tevent_context *ev,
39                                           TALLOC_CTX *mem_ctx,
40                                           struct timeval next_event,
41                                           tevent_timer_handler_t handler,
42                                           void *private_data);
43         /* disk aio event functions */
44         struct tevent_aio *(*add_aio)(struct tevent_context *ev,
45                                       TALLOC_CTX *mem_ctx,
46                                       struct iocb *iocb,
47                                       tevent_aio_handler_t handler,
48                                       void *private_data);
49         /* signal functions */
50         struct tevent_signal *(*add_signal)(struct tevent_context *ev,
51                                             TALLOC_CTX *mem_ctx,
52                                             int signum, int sa_flags,
53                                             tevent_signal_handler_t handler,
54                                             void *private_data);
55
56         /* loop functions */
57         int (*loop_once)(struct tevent_context *ev);
58         int (*loop_wait)(struct tevent_context *ev);
59 };
60
61 struct tevent_fd {
62         struct tevent_fd *prev, *next;
63         struct tevent_context *event_ctx;
64         int fd;
65         uint16_t flags; /* see EVENT_FD_* flags */
66         tevent_fd_handler_t handler;
67         /* this is private for the specific handler */
68         void *private_data;
69         /* this is private for the events_ops implementation */
70         uint16_t additional_flags;
71         void *additional_data;
72 };
73
74 struct tevent_timer {
75         struct tevent_timer *prev, *next;
76         struct tevent_context *event_ctx;
77         struct timeval next_event;
78         tevent_timer_handler_t handler;
79         /* this is private for the specific handler */
80         void *private_data;
81         /* this is private for the events_ops implementation */
82         void *additional_data;
83 };
84
85 struct tevent_signal {
86         struct tevent_signal *prev, *next;
87         struct tevent_context *event_ctx;
88         tevent_signal_handler_t handler;
89         void *private_data;
90         int signum;
91         int sa_flags;
92 };
93
94 /* DEBUG */
95 enum ev_debug_level {EV_DEBUG_FATAL, EV_DEBUG_ERROR,
96                       EV_DEBUG_WARNING, EV_DEBUG_TRACE};
97
98 struct ev_debug_ops {
99         void (*debug)(void *context, enum ev_debug_level level,
100                       const char *fmt, va_list ap) PRINTF_ATTRIBUTE(3,0);
101         void *context;
102 };
103
104 int ev_set_debug(struct tevent_context *ev,
105                  void (*debug)(void *context, enum ev_debug_level level,
106                                 const char *fmt, va_list ap) PRINTF_ATTRIBUTE(3,0),
107                  void *context);
108 int ev_set_debug_stderr(struct tevent_context *ev);
109 void ev_debug(struct tevent_context *ev, enum ev_debug_level level, const char *fmt, ...);
110
111 /* aio event is private to the aio backend */
112 struct tevent_aio;
113
114 struct tevent_context {
115         /* the specific events implementation */
116         const struct tevent_ops *ops;
117
118         /* list of timed events - used by common code */
119         struct tevent_timer *timer_events;
120
121         /* this is private for the events_ops implementation */
122         void *additional_data;
123
124         /* number of signal event handlers */
125         int num_signal_handlers;
126
127         /* pipe hack used with signal handlers */
128         struct tevent_fd *pipe_fde;
129
130         /* debugging operations */
131         struct ev_debug_ops debug_ops;
132 };
133
134
135 bool tevent_register_backend(const char *name, const struct tevent_ops *ops);
136
137 bool ev_timeval_is_zero(const struct timeval *tv);
138 struct tevent_timer *common_event_add_timed(struct tevent_context *,
139                                             TALLOC_CTX *,
140                                             struct timeval,
141                                             tevent_timer_handler_t,
142                                             void *);
143 struct timeval common_event_loop_timer_delay(struct tevent_context *);
144
145 struct tevent_signal *common_event_add_signal(struct tevent_context *ev,
146                                               TALLOC_CTX *mem_ctx,
147                                               int signum,
148                                               int sa_flags,
149                                               tevent_signal_handler_t handler,
150                                               void *private_data);
151 int common_event_check_signal(struct tevent_context *ev);
152
153
154 bool tevent_standard_init(void);
155 bool tevent_select_init(void);
156 #ifdef HAVE_EPOLL
157 bool tevent_epoll_init(void);
158 #endif
159 #ifdef HAVE_LINUX_AIO
160 bool tevent_aio_init(void);
161 #endif