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 void (*set_fd_close_fn)(struct tevent_fd *fde,
37 tevent_fd_close_fn_t close_fn);
38 uint16_t (*get_fd_flags)(struct tevent_fd *fde);
39 void (*set_fd_flags)(struct tevent_fd *fde, uint16_t flags);
41 /* timed_event functions */
42 struct tevent_timer *(*add_timer)(struct tevent_context *ev,
44 struct timeval next_event,
45 tevent_timer_handler_t handler,
47 const char *handler_name,
48 const char *location);
49 /* signal functions */
50 struct tevent_signal *(*add_signal)(struct tevent_context *ev,
52 int signum, int sa_flags,
53 tevent_signal_handler_t handler,
55 const char *handler_name,
56 const char *location);
59 int (*loop_once)(struct tevent_context *ev);
60 int (*loop_wait)(struct tevent_context *ev);
64 struct tevent_fd *prev, *next;
65 struct tevent_context *event_ctx;
67 uint16_t flags; /* see TEVENT_FD_* flags */
68 tevent_fd_handler_t handler;
69 tevent_fd_close_fn_t close_fn;
70 /* this is private for the specific handler */
72 /* this is for debugging only! */
73 const char *handler_name;
75 /* this is private for the events_ops implementation */
76 uint16_t additional_flags;
77 void *additional_data;
81 struct tevent_timer *prev, *next;
82 struct tevent_context *event_ctx;
83 struct timeval next_event;
84 tevent_timer_handler_t handler;
85 /* this is private for the specific handler */
87 /* this is for debugging only! */
88 const char *handler_name;
90 /* this is private for the events_ops implementation */
91 void *additional_data;
94 struct tevent_signal {
95 struct tevent_signal *prev, *next;
96 struct tevent_context *event_ctx;
99 tevent_signal_handler_t handler;
100 /* this is private for the specific handler */
102 /* this is for debugging only! */
103 const char *handler_name;
104 const char *location;
105 /* this is private for the events_ops implementation */
106 void *additional_data;
109 struct tevent_debug_ops {
110 void (*debug)(void *context, enum tevent_debug_level level,
111 const char *fmt, va_list ap) PRINTF_ATTRIBUTE(3,0);
115 void tevent_debug(struct tevent_context *ev, enum tevent_debug_level level,
116 const char *fmt, ...) PRINTF_ATTRIBUTE(3,4);
118 struct tevent_context {
119 /* the specific events implementation */
120 const struct tevent_ops *ops;
122 /* list of fd events - used by common code */
123 struct tevent_fd *fd_events;
125 /* list of timed events - used by common code */
126 struct tevent_timer *timer_events;
128 /* list of signal events - used by common code */
129 struct tevent_signal *signal_events;
131 /* this is private for the events_ops implementation */
132 void *additional_data;
134 /* pipe hack used with signal handlers */
135 struct tevent_fd *pipe_fde;
137 /* debugging operations */
138 struct tevent_debug_ops debug_ops;
142 bool tevent_register_backend(const char *name, const struct tevent_ops *ops);
144 int tevent_common_context_destructor(struct tevent_context *ev);
146 int tevent_common_fd_destructor(struct tevent_fd *fde);
147 struct tevent_fd *tevent_common_add_fd(struct tevent_context *ev,
151 tevent_fd_handler_t handler,
153 const char *handler_name,
154 const char *location);
155 void tevent_common_fd_set_close_fn(struct tevent_fd *fde,
156 tevent_fd_close_fn_t close_fn);
157 uint16_t tevent_common_fd_get_flags(struct tevent_fd *fde);
158 void tevent_common_fd_set_flags(struct tevent_fd *fde, uint16_t flags);
160 struct timeval ev_timeval_zero(void);
161 bool ev_timeval_is_zero(const struct timeval *tv);
162 struct tevent_timer *tevent_common_add_timer(struct tevent_context *ev,
164 struct timeval next_event,
165 tevent_timer_handler_t handler,
167 const char *handler_name,
168 const char *location);
169 struct timeval tevent_common_loop_timer_delay(struct tevent_context *);
171 struct tevent_signal *tevent_common_add_signal(struct tevent_context *ev,
175 tevent_signal_handler_t handler,
177 const char *handler_name,
178 const char *location);
179 int tevent_common_check_signal(struct tevent_context *ev);
181 bool tevent_standard_init(void);
182 bool tevent_select_init(void);
184 bool tevent_epoll_init(void);