Merge branch 'master' of ssh://jra@git.samba.org/data/git/samba
[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 struct tevent_debug_ops {
115         void (*debug)(void *context, enum tevent_debug_level level,
116                       const char *fmt, va_list ap) PRINTF_ATTRIBUTE(3,0);
117         void *context;
118 };
119
120 void tevent_debug(struct tevent_context *ev, enum tevent_debug_level level,
121                   const char *fmt, ...) PRINTF_ATTRIBUTE(3,4);
122
123 /* aio event is private to the aio backend */
124 struct tevent_aio;
125
126 struct tevent_context {
127         /* the specific events implementation */
128         const struct tevent_ops *ops;
129
130         /* list of timed events - used by common code */
131         struct tevent_timer *timer_events;
132
133         /* this is private for the events_ops implementation */
134         void *additional_data;
135
136         /* number of signal event handlers */
137         int num_signal_handlers;
138
139         /* pipe hack used with signal handlers */
140         struct tevent_fd *pipe_fde;
141
142         /* debugging operations */
143         struct tevent_debug_ops debug_ops;
144 };
145
146
147 bool tevent_register_backend(const char *name, const struct tevent_ops *ops);
148
149 bool ev_timeval_is_zero(const struct timeval *tv);
150 struct tevent_timer *tevent_common_add_timer(struct tevent_context *ev,
151                                              TALLOC_CTX *mem_ctx,
152                                              struct timeval next_event,
153                                              tevent_timer_handler_t handler,
154                                              void *private_data,
155                                              const char *handler_name,
156                                              const char *location);
157 struct timeval tevent_common_loop_timer_delay(struct tevent_context *);
158
159 struct tevent_signal *tevent_common_add_signal(struct tevent_context *ev,
160                                                TALLOC_CTX *mem_ctx,
161                                                int signum,
162                                                int sa_flags,
163                                                tevent_signal_handler_t handler,
164                                                void *private_data,
165                                                const char *handler_name,
166                                                const char *location);
167 int tevent_common_check_signal(struct tevent_context *ev);
168
169 bool tevent_standard_init(void);
170 bool tevent_select_init(void);
171 #ifdef HAVE_EPOLL
172 bool tevent_epoll_init(void);
173 #endif
174 #ifdef HAVE_LINUX_AIO
175 bool tevent_aio_init(void);
176 #endif