tevent: pass down handler_name and location to the backend layer
[metze/samba/wip.git] / lib / tevent / tevent_internal.h
1 /* 
2    Unix SMB/CIFS implementation.
3
4    generalised event loop handling
5
6    Internal structs
7
8    Copyright (C) Stefan Metzmacher 2005
9    
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.
14    
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.
19    
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/>.
22 */
23
24 struct tevent_ops {
25         /* conntext init */
26         int (*context_init)(struct tevent_context *ev);
27
28         /* fd_event functions */
29         struct tevent_fd *(*add_fd)(struct tevent_context *ev,
30                                     TALLOC_CTX *mem_ctx,
31                                     int fd, uint16_t flags,
32                                     tevent_fd_handler_t handler,
33                                     void *private_data,
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);
38
39         /* timed_event functions */
40         struct tevent_timer *(*add_timer)(struct tevent_context *ev,
41                                           TALLOC_CTX *mem_ctx,
42                                           struct timeval next_event,
43                                           tevent_timer_handler_t handler,
44                                           void *private_data,
45                                           const char *handler_name,
46                                           const char *location);
47         /* disk aio event functions */
48         struct tevent_aio *(*add_aio)(struct tevent_context *ev,
49                                       TALLOC_CTX *mem_ctx,
50                                       struct iocb *iocb,
51                                       tevent_aio_handler_t handler,
52                                       void *private_data,
53                                       const char *handler_name,
54                                       const char *location);
55         /* signal functions */
56         struct tevent_signal *(*add_signal)(struct tevent_context *ev,
57                                             TALLOC_CTX *mem_ctx,
58                                             int signum, int sa_flags,
59                                             tevent_signal_handler_t handler,
60                                             void *private_data,
61                                             const char *handler_name,
62                                             const char *location);
63
64         /* loop functions */
65         int (*loop_once)(struct tevent_context *ev);
66         int (*loop_wait)(struct tevent_context *ev);
67 };
68
69 struct tevent_fd {
70         struct tevent_fd *prev, *next;
71         struct tevent_context *event_ctx;
72         int fd;
73         uint16_t flags; /* see EVENT_FD_* flags */
74         tevent_fd_handler_t handler;
75         /* this is private for the specific handler */
76         void *private_data;
77         /* this is for debugging only! */
78         const char *handler_name;
79         const char *location;
80         /* this is private for the events_ops implementation */
81         uint16_t additional_flags;
82         void *additional_data;
83 };
84
85 struct tevent_timer {
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 */
91         void *private_data;
92         /* this is for debugging only! */
93         const char *handler_name;
94         const char *location;
95         /* this is private for the events_ops implementation */
96         void *additional_data;
97 };
98
99 struct tevent_signal {
100         struct tevent_signal *prev, *next;
101         struct tevent_context *event_ctx;
102         int signum;
103         int sa_flags;
104         tevent_signal_handler_t handler;
105         /* this is private for the specific handler */
106         void *private_data;
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;
112 };
113
114 /* DEBUG */
115 enum ev_debug_level {EV_DEBUG_FATAL, EV_DEBUG_ERROR,
116                       EV_DEBUG_WARNING, EV_DEBUG_TRACE};
117
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);
121         void *context;
122 };
123
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),
127                  void *context);
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, ...);
130
131 /* aio event is private to the aio backend */
132 struct tevent_aio;
133
134 struct tevent_context {
135         /* the specific events implementation */
136         const struct tevent_ops *ops;
137
138         /* list of timed events - used by common code */
139         struct tevent_timer *timer_events;
140
141         /* this is private for the events_ops implementation */
142         void *additional_data;
143
144         /* number of signal event handlers */
145         int num_signal_handlers;
146
147         /* pipe hack used with signal handlers */
148         struct tevent_fd *pipe_fde;
149
150         /* debugging operations */
151         struct ev_debug_ops debug_ops;
152 };
153
154
155 bool tevent_register_backend(const char *name, const struct tevent_ops *ops);
156
157 bool ev_timeval_is_zero(const struct timeval *tv);
158 struct tevent_timer *tevent_common_add_timer(struct tevent_context *ev,
159                                              TALLOC_CTX *mem_ctx,
160                                              struct timeval next_event,
161                                              tevent_timer_handler_t handler,
162                                              void *private_data,
163                                              const char *handler_name,
164                                              const char *location);
165 struct timeval tevent_common_loop_timer_delay(struct tevent_context *);
166
167 struct tevent_signal *tevent_common_add_signal(struct tevent_context *ev,
168                                                TALLOC_CTX *mem_ctx,
169                                                int signum,
170                                                int sa_flags,
171                                                tevent_signal_handler_t handler,
172                                                void *private_data,
173                                                const char *handler_name,
174                                                const char *location);
175 int tevent_common_check_signal(struct tevent_context *ev);
176
177 bool tevent_standard_init(void);
178 bool tevent_select_init(void);
179 #ifdef HAVE_EPOLL
180 bool tevent_epoll_init(void);
181 #endif
182 #ifdef HAVE_LINUX_AIO
183 bool tevent_aio_init(void);
184 #endif