2 Unix SMB/CIFS implementation.
4 generalised event loop handling
8 Copyright (C) Stefan Metzmacher 2005-2009
10 ** NOTE! The following LGPL license applies to the tevent
11 ** library. This does NOT imply that all of Samba is released
14 This library is free software; you can redistribute it and/or
15 modify it under the terms of the GNU Lesser General Public
16 License as published by the Free Software Foundation; either
17 version 3 of the License, or (at your option) any later version.
19 This library is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 Lesser General Public License for more details.
24 You should have received a copy of the GNU Lesser General Public
25 License along with this library; if not, see <http://www.gnu.org/licenses/>.
30 * @brief What to do on completion
32 * This is used for the user of an async request, fn is called when
33 * the request completes, either successfully or with an error.
37 * @brief Completion function
38 * Completion function, to be filled by the API user
42 * @brief Private data for the completion function
48 * @brief Private state pointer for the actual implementation
50 * The implementation doing the work for the async request needs to
51 * keep around current data like for example a fd event. The user of
52 * an async request should not touch this.
57 * @brief A function to overwrite the default print function
59 * The implementation doing the work may want to implement a
60 * custom function to print the text representation of the async
63 tevent_req_print_fn private_print
;
66 * @brief Internal state of the request
68 * Callers should only access this via functions and never directly.
72 * @brief The talloc type of the data pointer
74 * This is filled by the tevent_req_create() macro.
76 * This for debugging only.
78 const char *private_type
;
81 * @brief The location where the request was created
83 * This uses the __location__ macro via the tevent_req_create()
86 * This for debugging only.
91 * @brief The external state - will be queried by the caller
93 * While the async request is being processed, state will remain in
94 * TEVENT_REQ_IN_PROGRESS. A request is finished if
95 * req->state>=TEVENT_REQ_DONE.
97 enum tevent_req_state state
;
100 * @brief status code when finished
102 * This status can be queried in the async completion function. It
103 * will be set to 0 when everything went fine.
108 * @brief the immediate event used by tevent_req_post
111 struct tevent_immediate
*trigger
;
114 * @brief the timer event if tevent_req_set_timeout was used
117 struct tevent_timer
*timer
;
123 int (*context_init
)(struct tevent_context
*ev
);
125 /* fd_event functions */
126 struct tevent_fd
*(*add_fd
)(struct tevent_context
*ev
,
128 int fd
, uint16_t flags
,
129 tevent_fd_handler_t handler
,
131 const char *handler_name
,
132 const char *location
);
133 void (*set_fd_close_fn
)(struct tevent_fd
*fde
,
134 tevent_fd_close_fn_t close_fn
);
135 uint16_t (*get_fd_flags
)(struct tevent_fd
*fde
);
136 void (*set_fd_flags
)(struct tevent_fd
*fde
, uint16_t flags
);
138 /* timed_event functions */
139 struct tevent_timer
*(*add_timer
)(struct tevent_context
*ev
,
141 struct timeval next_event
,
142 tevent_timer_handler_t handler
,
144 const char *handler_name
,
145 const char *location
);
147 /* immediate event functions */
148 void (*schedule_immediate
)(struct tevent_immediate
*im
,
149 struct tevent_context
*ev
,
150 tevent_immediate_handler_t handler
,
152 const char *handler_name
,
153 const char *location
);
155 /* signal functions */
156 struct tevent_signal
*(*add_signal
)(struct tevent_context
*ev
,
158 int signum
, int sa_flags
,
159 tevent_signal_handler_t handler
,
161 const char *handler_name
,
162 const char *location
);
165 int (*loop_once
)(struct tevent_context
*ev
, const char *location
);
166 int (*loop_wait
)(struct tevent_context
*ev
, const char *location
);
170 struct tevent_fd
*prev
, *next
;
171 struct tevent_context
*event_ctx
;
173 uint16_t flags
; /* see TEVENT_FD_* flags */
174 tevent_fd_handler_t handler
;
175 tevent_fd_close_fn_t close_fn
;
176 /* this is private for the specific handler */
178 /* this is for debugging only! */
179 const char *handler_name
;
180 const char *location
;
181 /* this is private for the events_ops implementation */
182 uint16_t additional_flags
;
183 void *additional_data
;
186 struct tevent_timer
{
187 struct tevent_timer
*prev
, *next
;
188 struct tevent_context
*event_ctx
;
189 struct timeval next_event
;
190 tevent_timer_handler_t handler
;
191 /* this is private for the specific handler */
193 /* this is for debugging only! */
194 const char *handler_name
;
195 const char *location
;
196 /* this is private for the events_ops implementation */
197 void *additional_data
;
200 struct tevent_immediate
{
201 struct tevent_immediate
*prev
, *next
;
202 struct tevent_context
*event_ctx
;
203 tevent_immediate_handler_t handler
;
204 /* this is private for the specific handler */
206 /* this is for debugging only! */
207 const char *handler_name
;
208 const char *create_location
;
209 const char *schedule_location
;
210 /* this is private for the events_ops implementation */
211 void (*cancel_fn
)(struct tevent_immediate
*im
);
212 void *additional_data
;
215 struct tevent_signal
{
216 struct tevent_signal
*prev
, *next
;
217 struct tevent_context
*event_ctx
;
220 tevent_signal_handler_t handler
;
221 /* this is private for the specific handler */
223 /* this is for debugging only! */
224 const char *handler_name
;
225 const char *location
;
226 /* this is private for the events_ops implementation */
227 void *additional_data
;
230 struct tevent_debug_ops
{
231 void (*debug
)(void *context
, enum tevent_debug_level level
,
232 const char *fmt
, va_list ap
) PRINTF_ATTRIBUTE(3,0);
236 void tevent_debug(struct tevent_context
*ev
, enum tevent_debug_level level
,
237 const char *fmt
, ...) PRINTF_ATTRIBUTE(3,4);
239 struct tevent_context
{
240 /* the specific events implementation */
241 const struct tevent_ops
*ops
;
243 /* list of fd events - used by common code */
244 struct tevent_fd
*fd_events
;
246 /* list of timed events - used by common code */
247 struct tevent_timer
*timer_events
;
249 /* list of immediate events - used by common code */
250 struct tevent_immediate
*immediate_events
;
252 /* list of signal events - used by common code */
253 struct tevent_signal
*signal_events
;
255 /* this is private for the events_ops implementation */
256 void *additional_data
;
258 /* pipe hack used with signal handlers */
259 struct tevent_fd
*pipe_fde
;
261 /* debugging operations */
262 struct tevent_debug_ops debug_ops
;
264 /* info about the nesting status */
268 tevent_nesting_hook hook_fn
;
274 bool tevent_register_backend(const char *name
, const struct tevent_ops
*ops
);
276 int tevent_common_context_destructor(struct tevent_context
*ev
);
277 int tevent_common_loop_wait(struct tevent_context
*ev
,
278 const char *location
);
280 int tevent_common_fd_destructor(struct tevent_fd
*fde
);
281 struct tevent_fd
*tevent_common_add_fd(struct tevent_context
*ev
,
285 tevent_fd_handler_t handler
,
287 const char *handler_name
,
288 const char *location
);
289 void tevent_common_fd_set_close_fn(struct tevent_fd
*fde
,
290 tevent_fd_close_fn_t close_fn
);
291 uint16_t tevent_common_fd_get_flags(struct tevent_fd
*fde
);
292 void tevent_common_fd_set_flags(struct tevent_fd
*fde
, uint16_t flags
);
294 struct tevent_timer
*tevent_common_add_timer(struct tevent_context
*ev
,
296 struct timeval next_event
,
297 tevent_timer_handler_t handler
,
299 const char *handler_name
,
300 const char *location
);
301 struct timeval
tevent_common_loop_timer_delay(struct tevent_context
*);
303 void tevent_common_schedule_immediate(struct tevent_immediate
*im
,
304 struct tevent_context
*ev
,
305 tevent_immediate_handler_t handler
,
307 const char *handler_name
,
308 const char *location
);
309 bool tevent_common_loop_immediate(struct tevent_context
*ev
);
311 struct tevent_signal
*tevent_common_add_signal(struct tevent_context
*ev
,
315 tevent_signal_handler_t handler
,
317 const char *handler_name
,
318 const char *location
);
319 int tevent_common_check_signal(struct tevent_context
*ev
);
321 bool tevent_standard_init(void);
322 bool tevent_select_init(void);
324 bool tevent_epoll_init(void);