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 int (*context_init)(struct tevent_context *ev);
32 /* fd_event functions */
33 struct tevent_fd *(*add_fd)(struct tevent_context *ev,
35 int fd, uint16_t flags,
36 tevent_fd_handler_t handler,
38 const char *handler_name,
39 const char *location);
40 void (*set_fd_close_fn)(struct tevent_fd *fde,
41 tevent_fd_close_fn_t close_fn);
42 uint16_t (*get_fd_flags)(struct tevent_fd *fde);
43 void (*set_fd_flags)(struct tevent_fd *fde, uint16_t flags);
45 /* timed_event functions */
46 struct tevent_timer *(*add_timer)(struct tevent_context *ev,
48 struct timeval next_event,
49 tevent_timer_handler_t handler,
51 const char *handler_name,
52 const char *location);
53 /* signal functions */
54 struct tevent_signal *(*add_signal)(struct tevent_context *ev,
56 int signum, int sa_flags,
57 tevent_signal_handler_t handler,
59 const char *handler_name,
60 const char *location);
63 int (*loop_once)(struct tevent_context *ev);
64 int (*loop_wait)(struct tevent_context *ev);
68 struct tevent_fd *prev, *next;
69 struct tevent_context *event_ctx;
71 uint16_t flags; /* see TEVENT_FD_* flags */
72 tevent_fd_handler_t handler;
73 tevent_fd_close_fn_t close_fn;
74 /* this is private for the specific handler */
76 /* this is for debugging only! */
77 const char *handler_name;
79 /* this is private for the events_ops implementation */
80 uint16_t additional_flags;
81 void *additional_data;
85 struct tevent_timer *prev, *next;
86 struct tevent_context *event_ctx;
87 struct timeval next_event;
88 tevent_timer_handler_t handler;
89 /* this is private for the specific handler */
91 /* this is for debugging only! */
92 const char *handler_name;
94 /* this is private for the events_ops implementation */
95 void *additional_data;
98 struct tevent_signal {
99 struct tevent_signal *prev, *next;
100 struct tevent_context *event_ctx;
103 tevent_signal_handler_t handler;
104 /* this is private for the specific handler */
106 /* this is for debugging only! */
107 const char *handler_name;
108 const char *location;
109 /* this is private for the events_ops implementation */
110 void *additional_data;
113 struct tevent_debug_ops {
114 void (*debug)(void *context, enum tevent_debug_level level,
115 const char *fmt, va_list ap) PRINTF_ATTRIBUTE(3,0);
119 void tevent_debug(struct tevent_context *ev, enum tevent_debug_level level,
120 const char *fmt, ...) PRINTF_ATTRIBUTE(3,4);
122 struct tevent_context {
123 /* the specific events implementation */
124 const struct tevent_ops *ops;
126 /* list of fd events - used by common code */
127 struct tevent_fd *fd_events;
129 /* list of timed events - used by common code */
130 struct tevent_timer *timer_events;
132 /* list of signal events - used by common code */
133 struct tevent_signal *signal_events;
135 /* this is private for the events_ops implementation */
136 void *additional_data;
138 /* pipe hack used with signal handlers */
139 struct tevent_fd *pipe_fde;
141 /* debugging operations */
142 struct tevent_debug_ops debug_ops;
146 bool tevent_register_backend(const char *name, const struct tevent_ops *ops);
148 int tevent_common_context_destructor(struct tevent_context *ev);
150 int tevent_common_fd_destructor(struct tevent_fd *fde);
151 struct tevent_fd *tevent_common_add_fd(struct tevent_context *ev,
155 tevent_fd_handler_t handler,
157 const char *handler_name,
158 const char *location);
159 void tevent_common_fd_set_close_fn(struct tevent_fd *fde,
160 tevent_fd_close_fn_t close_fn);
161 uint16_t tevent_common_fd_get_flags(struct tevent_fd *fde);
162 void tevent_common_fd_set_flags(struct tevent_fd *fde, uint16_t flags);
164 struct tevent_timer *tevent_common_add_timer(struct tevent_context *ev,
166 struct timeval next_event,
167 tevent_timer_handler_t handler,
169 const char *handler_name,
170 const char *location);
171 struct timeval tevent_common_loop_timer_delay(struct tevent_context *);
173 struct tevent_signal *tevent_common_add_signal(struct tevent_context *ev,
177 tevent_signal_handler_t handler,
179 const char *handler_name,
180 const char *location);
181 int tevent_common_check_signal(struct tevent_context *ev);
183 bool tevent_standard_init(void);
184 bool tevent_select_init(void);
186 bool tevent_epoll_init(void);