]> git.ozlabs.org Git - ccan-lca-2011.git/blob - ccan/tevent/tevent_internal.h
lca2011: hacky import of tevent.
[ccan-lca-2011.git] / ccan / tevent / tevent_internal.h
1 #ifndef CCAN_TEVENT_TEVENT_INTERNAL_H
2 #define CCAN_TEVENT_TEVENT_INTERNAL_H
3 /* 
4    Unix SMB/CIFS implementation.
5
6    generalised event loop handling
7
8    INTERNAL STRUCTS. THERE ARE NO API GUARANTEES.
9    External users should only ever have to include this header when 
10    implementing new tevent backends.
11
12    Copyright (C) Stefan Metzmacher 2005-2009
13
14      ** NOTE! The following LGPL license applies to the tevent
15      ** library. This does NOT imply that all of Samba is released
16      ** under the LGPL
17
18    This library is free software; you can redistribute it and/or
19    modify it under the terms of the GNU Lesser General Public
20    License as published by the Free Software Foundation; either
21    version 3 of the License, or (at your option) any later version.
22
23    This library is distributed in the hope that it will be useful,
24    but WITHOUT ANY WARRANTY; without even the implied warranty of
25    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
26    Lesser General Public License for more details.
27
28    You should have received a copy of the GNU Lesser General Public
29    License along with this library; if not, see <http://www.gnu.org/licenses/>.
30 */
31
32 struct tevent_fd {
33         struct tevent_fd *prev, *next;
34         struct tevent_context *event_ctx;
35         int fd;
36         uint16_t flags; /* see TEVENT_FD_* flags */
37         tevent_fd_handler_t handler;
38         tevent_fd_close_fn_t close_fn;
39         /* this is private for the specific handler */
40         void *private_data;
41         /* this is for debugging only! */
42         const char *handler_name;
43         const char *location;
44         /* this is private for the events_ops implementation */
45         uint16_t additional_flags;
46         void *additional_data;
47 };
48
49 struct tevent_timer {
50         struct tevent_timer *prev, *next;
51         struct tevent_context *event_ctx;
52         struct timeval next_event;
53         tevent_timer_handler_t handler;
54         /* this is private for the specific handler */
55         void *private_data;
56         /* this is for debugging only! */
57         const char *handler_name;
58         const char *location;
59         /* this is private for the events_ops implementation */
60         void *additional_data;
61 };
62
63 struct tevent_immediate {
64         struct tevent_immediate *prev, *next;
65         struct tevent_context *event_ctx;
66         tevent_immediate_handler_t handler;
67         /* this is private for the specific handler */
68         void *private_data;
69         /* this is for debugging only! */
70         const char *handler_name;
71         const char *create_location;
72         const char *schedule_location;
73         /* this is private for the events_ops implementation */
74         void (*cancel_fn)(struct tevent_immediate *im);
75         void *additional_data;
76 };
77
78 struct tevent_signal {
79         struct tevent_signal *prev, *next;
80         struct tevent_context *event_ctx;
81         int signum;
82         int sa_flags;
83         tevent_signal_handler_t handler;
84         /* this is private for the specific handler */
85         void *private_data;
86         /* this is for debugging only! */
87         const char *handler_name;
88         const char *location;
89         /* this is private for the events_ops implementation */
90         void *additional_data;
91 };
92
93 struct tevent_debug_ops {
94         void (*debug)(void *context, enum tevent_debug_level level,
95                       const char *fmt, va_list ap) PRINTF_FMT(3,0);
96         void *context;
97 };
98
99 void tevent_debug(struct tevent_context *ev, enum tevent_debug_level level,
100                   const char *fmt, ...) PRINTF_FMT(3,4);
101
102 struct tevent_context {
103         /* the specific events implementation */
104         const struct tevent_ops *ops;
105
106         /* list of fd events - used by common code */
107         struct tevent_fd *fd_events;
108
109         /* list of timed events - used by common code */
110         struct tevent_timer *timer_events;
111
112         /* list of immediate events - used by common code */
113         struct tevent_immediate *immediate_events;
114
115         /* list of signal events - used by common code */
116         struct tevent_signal *signal_events;
117
118         /* this is private for the events_ops implementation */
119         void *additional_data;
120
121         /* pipe hack used with signal handlers */
122         struct tevent_fd *pipe_fde;
123         int pipe_fds[2];
124
125         /* debugging operations */
126         struct tevent_debug_ops debug_ops;
127 };
128
129
130 int tevent_common_context_destructor(struct tevent_context *ev);
131 int tevent_common_loop_wait(struct tevent_context *ev,
132                             const char *location);
133
134 int tevent_common_fd_destructor(struct tevent_fd *fde);
135 struct tevent_fd *tevent_common_add_fd(struct tevent_context *ev,
136                                        TALLOC_CTX *mem_ctx,
137                                        int fd,
138                                        uint16_t flags,
139                                        tevent_fd_handler_t handler,
140                                        void *private_data,
141                                        const char *handler_name,
142                                        const char *location);
143 void tevent_common_fd_set_close_fn(struct tevent_fd *fde,
144                                    tevent_fd_close_fn_t close_fn);
145 uint16_t tevent_common_fd_get_flags(struct tevent_fd *fde);
146 void tevent_common_fd_set_flags(struct tevent_fd *fde, uint16_t flags);
147
148 struct tevent_timer *tevent_common_add_timer(struct tevent_context *ev,
149                                              TALLOC_CTX *mem_ctx,
150                                              struct timeval next_event,
151                                              tevent_timer_handler_t handler,
152                                              void *private_data,
153                                              const char *handler_name,
154                                              const char *location);
155 struct timeval tevent_common_loop_timer_delay(struct tevent_context *);
156
157 void tevent_common_schedule_immediate(struct tevent_immediate *im,
158                                       struct tevent_context *ev,
159                                       tevent_immediate_handler_t handler,
160                                       void *private_data,
161                                       const char *handler_name,
162                                       const char *location);
163 bool tevent_common_loop_immediate(struct tevent_context *ev);
164
165 struct tevent_signal *tevent_common_add_signal(struct tevent_context *ev,
166                                                TALLOC_CTX *mem_ctx,
167                                                int signum,
168                                                int sa_flags,
169                                                tevent_signal_handler_t handler,
170                                                void *private_data,
171                                                const char *handler_name,
172                                                const char *location);
173 int tevent_common_check_signal(struct tevent_context *ev);
174 void tevent_cleanup_pending_signal_handlers(struct tevent_signal *se);
175
176 bool tevent_standard_init(void);
177 bool tevent_select_init(void);
178 #ifdef HAVE_EPOLL
179 bool tevent_epoll_init(void);
180 #endif
181 #endif /* CCAN_TEVENT_TEVENT_INTERNAL_H */