2 Unix SMB/CIFS implementation.
4 generalised event loop handling
6 INTERNAL STRUCTS. THERE ARE NO API GUARANTEES.
7 External users should only ever have to include this header when
8 implementing new tevent backends.
10 Copyright (C) Stefan Metzmacher 2005-2009
12 ** NOTE! The following LGPL license applies to the tevent
13 ** library. This does NOT imply that all of Samba is released
16 This library is free software; you can redistribute it and/or
17 modify it under the terms of the GNU Lesser General Public
18 License as published by the Free Software Foundation; either
19 version 3 of the License, or (at your option) any later version.
21 This library is distributed in the hope that it will be useful,
22 but WITHOUT ANY WARRANTY; without even the implied warranty of
23 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
24 Lesser General Public License for more details.
26 You should have received a copy of the GNU Lesser General Public
27 License along with this library; if not, see <http://www.gnu.org/licenses/>.
32 * @brief What to do on completion
34 * This is used for the user of an async request, fn is called when
35 * the request completes, either successfully or with an error.
39 * @brief Completion function
40 * Completion function, to be filled by the API user
44 * @brief Private data for the completion function
50 * @brief Private state pointer for the actual implementation
52 * The implementation doing the work for the async request needs to
53 * keep around current data like for example a fd event. The user of
54 * an async request should not touch this.
59 * @brief A function to overwrite the default print function
61 * The implementation doing the work may want to implement a
62 * custom function to print the text representation of the async
65 tevent_req_print_fn private_print;
68 * @brief Internal state of the request
70 * Callers should only access this via functions and never directly.
74 * @brief The talloc type of the data pointer
76 * This is filled by the tevent_req_create() macro.
78 * This for debugging only.
80 const char *private_type;
83 * @brief The location where the request was created
85 * This uses the __location__ macro via the tevent_req_create()
88 * This for debugging only.
90 const char *create_location;
93 * @brief The location where the request was finished
95 * This uses the __location__ macro via the tevent_req_done(),
96 * tevent_req_error() or tevent_req_nomem() macro.
98 * This for debugging only.
100 const char *finish_location;
103 * @brief The external state - will be queried by the caller
105 * While the async request is being processed, state will remain in
106 * TEVENT_REQ_IN_PROGRESS. A request is finished if
107 * req->state>=TEVENT_REQ_DONE.
109 enum tevent_req_state state;
112 * @brief status code when finished
114 * This status can be queried in the async completion function. It
115 * will be set to 0 when everything went fine.
120 * @brief the immediate event used by tevent_req_post
123 struct tevent_immediate *trigger;
126 * @brief the timer event if tevent_req_set_timeout was used
129 struct tevent_timer *timer;
134 struct tevent_fd *prev, *next;
135 struct tevent_context *event_ctx;
137 uint16_t flags; /* see TEVENT_FD_* flags */
138 tevent_fd_handler_t handler;
139 tevent_fd_close_fn_t close_fn;
140 /* this is private for the specific handler */
142 /* this is for debugging only! */
143 const char *handler_name;
144 const char *location;
145 /* this is private for the events_ops implementation */
146 uint16_t additional_flags;
147 void *additional_data;
150 struct tevent_timer {
151 struct tevent_timer *prev, *next;
152 struct tevent_context *event_ctx;
153 struct timeval next_event;
154 tevent_timer_handler_t handler;
155 /* this is private for the specific handler */
157 /* this is for debugging only! */
158 const char *handler_name;
159 const char *location;
160 /* this is private for the events_ops implementation */
161 void *additional_data;
164 struct tevent_immediate {
165 struct tevent_immediate *prev, *next;
166 struct tevent_context *event_ctx;
167 tevent_immediate_handler_t handler;
168 /* this is private for the specific handler */
170 /* this is for debugging only! */
171 const char *handler_name;
172 const char *create_location;
173 const char *schedule_location;
174 /* this is private for the events_ops implementation */
175 void (*cancel_fn)(struct tevent_immediate *im);
176 void *additional_data;
179 struct tevent_signal {
180 struct tevent_signal *prev, *next;
181 struct tevent_context *event_ctx;
184 tevent_signal_handler_t handler;
185 /* this is private for the specific handler */
187 /* this is for debugging only! */
188 const char *handler_name;
189 const char *location;
190 /* this is private for the events_ops implementation */
191 void *additional_data;
194 struct tevent_debug_ops {
195 void (*debug)(void *context, enum tevent_debug_level level,
196 const char *fmt, va_list ap) PRINTF_ATTRIBUTE(3,0);
200 void tevent_debug(struct tevent_context *ev, enum tevent_debug_level level,
201 const char *fmt, ...) PRINTF_ATTRIBUTE(3,4);
203 struct tevent_context {
204 /* the specific events implementation */
205 const struct tevent_ops *ops;
207 /* list of fd events - used by common code */
208 struct tevent_fd *fd_events;
210 /* list of timed events - used by common code */
211 struct tevent_timer *timer_events;
213 /* list of immediate events - used by common code */
214 struct tevent_immediate *immediate_events;
216 /* list of signal events - used by common code */
217 struct tevent_signal *signal_events;
219 /* this is private for the events_ops implementation */
220 void *additional_data;
222 /* pipe hack used with signal handlers */
223 struct tevent_fd *pipe_fde;
225 /* debugging operations */
226 struct tevent_debug_ops debug_ops;
228 /* info about the nesting status */
232 tevent_nesting_hook hook_fn;
238 int tevent_common_context_destructor(struct tevent_context *ev);
239 int tevent_common_loop_wait(struct tevent_context *ev,
240 const char *location);
242 int tevent_common_fd_destructor(struct tevent_fd *fde);
243 struct tevent_fd *tevent_common_add_fd(struct tevent_context *ev,
247 tevent_fd_handler_t handler,
249 const char *handler_name,
250 const char *location);
251 void tevent_common_fd_set_close_fn(struct tevent_fd *fde,
252 tevent_fd_close_fn_t close_fn);
253 uint16_t tevent_common_fd_get_flags(struct tevent_fd *fde);
254 void tevent_common_fd_set_flags(struct tevent_fd *fde, uint16_t flags);
256 struct tevent_timer *tevent_common_add_timer(struct tevent_context *ev,
258 struct timeval next_event,
259 tevent_timer_handler_t handler,
261 const char *handler_name,
262 const char *location);
263 struct timeval tevent_common_loop_timer_delay(struct tevent_context *);
265 void tevent_common_schedule_immediate(struct tevent_immediate *im,
266 struct tevent_context *ev,
267 tevent_immediate_handler_t handler,
269 const char *handler_name,
270 const char *location);
271 bool tevent_common_loop_immediate(struct tevent_context *ev);
273 struct tevent_signal *tevent_common_add_signal(struct tevent_context *ev,
277 tevent_signal_handler_t handler,
279 const char *handler_name,
280 const char *location);
281 int tevent_common_check_signal(struct tevent_context *ev);
283 bool tevent_standard_init(void);
284 bool tevent_select_init(void);
286 bool tevent_epoll_init(void);