2 Unix SMB/CIFS implementation.
4 generalised event loop handling
8 Copyright (C) Stefan Metzmacher 2005
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.
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.
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/>.
26 int (*context_init)(struct tevent_context *ev);
28 /* fd_event functions */
29 struct tevent_fd *(*add_fd)(struct tevent_context *ev,
31 int fd, uint16_t flags,
32 tevent_fd_handler_t handler,
34 const char *handler_name,
35 const char *location);
36 uint16_t (*get_fd_flags)(struct tevent_fd *fde);
37 void (*set_fd_flags)(struct tevent_fd *fde, uint16_t flags);
39 /* timed_event functions */
40 struct tevent_timer *(*add_timer)(struct tevent_context *ev,
42 struct timeval next_event,
43 tevent_timer_handler_t handler,
45 const char *handler_name,
46 const char *location);
47 /* disk aio event functions */
48 struct tevent_aio *(*add_aio)(struct tevent_context *ev,
51 tevent_aio_handler_t handler,
53 const char *handler_name,
54 const char *location);
55 /* signal functions */
56 struct tevent_signal *(*add_signal)(struct tevent_context *ev,
58 int signum, int sa_flags,
59 tevent_signal_handler_t handler,
61 const char *handler_name,
62 const char *location);
65 int (*loop_once)(struct tevent_context *ev);
66 int (*loop_wait)(struct tevent_context *ev);
70 struct tevent_fd *prev, *next;
71 struct tevent_context *event_ctx;
73 uint16_t flags; /* see EVENT_FD_* flags */
74 tevent_fd_handler_t handler;
75 /* this is private for the specific handler */
77 /* this is for debugging only! */
78 const char *handler_name;
80 /* this is private for the events_ops implementation */
81 uint16_t additional_flags;
82 void *additional_data;
86 struct tevent_timer *prev, *next;
87 struct tevent_context *event_ctx;
88 struct timeval next_event;
89 tevent_timer_handler_t handler;
90 /* this is private for the specific handler */
92 /* this is for debugging only! */
93 const char *handler_name;
95 /* this is private for the events_ops implementation */
96 void *additional_data;
99 struct tevent_signal {
100 struct tevent_signal *prev, *next;
101 struct tevent_context *event_ctx;
104 tevent_signal_handler_t handler;
105 /* this is private for the specific handler */
107 /* this is for debugging only! */
108 const char *handler_name;
109 const char *location;
110 /* this is private for the events_ops implementation */
111 void *additional_data;
115 enum ev_debug_level {EV_DEBUG_FATAL, EV_DEBUG_ERROR,
116 EV_DEBUG_WARNING, EV_DEBUG_TRACE};
118 struct ev_debug_ops {
119 void (*debug)(void *context, enum ev_debug_level level,
120 const char *fmt, va_list ap) PRINTF_ATTRIBUTE(3,0);
124 int ev_set_debug(struct tevent_context *ev,
125 void (*debug)(void *context, enum ev_debug_level level,
126 const char *fmt, va_list ap) PRINTF_ATTRIBUTE(3,0),
128 int ev_set_debug_stderr(struct tevent_context *ev);
129 void ev_debug(struct tevent_context *ev, enum ev_debug_level level, const char *fmt, ...);
131 /* aio event is private to the aio backend */
134 struct tevent_context {
135 /* the specific events implementation */
136 const struct tevent_ops *ops;
138 /* list of timed events - used by common code */
139 struct tevent_timer *timer_events;
141 /* this is private for the events_ops implementation */
142 void *additional_data;
144 /* number of signal event handlers */
145 int num_signal_handlers;
147 /* pipe hack used with signal handlers */
148 struct tevent_fd *pipe_fde;
150 /* debugging operations */
151 struct ev_debug_ops debug_ops;
155 bool tevent_register_backend(const char *name, const struct tevent_ops *ops);
157 bool ev_timeval_is_zero(const struct timeval *tv);
158 struct tevent_timer *tevent_common_add_timer(struct tevent_context *ev,
160 struct timeval next_event,
161 tevent_timer_handler_t handler,
163 const char *handler_name,
164 const char *location);
165 struct timeval tevent_common_loop_timer_delay(struct tevent_context *);
167 struct tevent_signal *tevent_common_add_signal(struct tevent_context *ev,
171 tevent_signal_handler_t handler,
173 const char *handler_name,
174 const char *location);
175 int tevent_common_check_signal(struct tevent_context *ev);
177 bool tevent_standard_init(void);
178 bool tevent_select_init(void);
180 bool tevent_epoll_init(void);
182 #ifdef HAVE_LINUX_AIO
183 bool tevent_aio_init(void);