s4:lib/tevent: add lib/events/ compat and let things compile
[ira/wip.git] / lib / tevent / tevent.h
1 /* 
2    Unix SMB/CIFS implementation.
3
4    generalised event loop handling
5
6    Copyright (C) Andrew Tridgell 2005
7    
8    This program is free software; you can redistribute it and/or modify
9    it under the terms of the GNU General Public License as published by
10    the Free Software Foundation; either version 3 of the License, or
11    (at your option) any later version.
12    
13    This program is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16    GNU General Public License for more details.
17    
18    You should have received a copy of the GNU General Public License
19    along with this program.  If not, see <http://www.gnu.org/licenses/>.
20 */
21
22 #ifndef __TEVENT_H__
23 #define __TEVENT_H__
24
25 #include <stdint.h>
26 #include <talloc.h>
27
28 struct event_context;
29 struct event_ops;
30 struct fd_event;
31 struct timed_event;
32 struct aio_event;
33 struct signal_event;
34
35 /* event handler types */
36 typedef void (*event_fd_handler_t)(struct event_context *, struct fd_event *, 
37                                    uint16_t , void *);
38 typedef void (*event_timed_handler_t)(struct event_context *, struct timed_event *, 
39                                       struct timeval , void *);
40 typedef void (*event_signal_handler_t)(struct event_context *, struct signal_event *, 
41                                        int , int, void *, void *);
42 typedef void (*event_aio_handler_t)(struct event_context *, struct aio_event *, 
43                                     int, void *);
44
45 #ifdef _SAMBA_BUILD_
46 struct event_context *s4_event_context_init(TALLOC_CTX *mem_ctx);
47 #endif
48
49 struct event_context *event_context_init(TALLOC_CTX *mem_ctx);
50 struct event_context *event_context_init_byname(TALLOC_CTX *mem_ctx, const char *name);
51 const char **event_backend_list(TALLOC_CTX *mem_ctx);
52 void event_set_default_backend(const char *backend);
53
54 struct fd_event *event_add_fd(struct event_context *ev, TALLOC_CTX *mem_ctx,
55                               int fd, uint16_t flags, event_fd_handler_t handler,
56                               void *private_data);
57
58 struct timed_event *event_add_timed(struct event_context *ev, TALLOC_CTX *mem_ctx,
59                                     struct timeval next_event, 
60                                     event_timed_handler_t handler, 
61                                     void *private_data);
62
63 struct signal_event *event_add_signal(struct event_context *ev, TALLOC_CTX *mem_ctx,
64                                       int signum, int sa_flags,
65                                       event_signal_handler_t handler, 
66                                       void *private_data);
67
68 struct iocb;
69 struct aio_event *event_add_aio(struct event_context *ev,
70                                 TALLOC_CTX *mem_ctx,
71                                 struct iocb *iocb,
72                                 event_aio_handler_t handler,
73                                 void *private_data);
74
75 int event_loop_once(struct event_context *ev);
76 int event_loop_wait(struct event_context *ev);
77
78 uint16_t event_get_fd_flags(struct fd_event *fde);
79 void event_set_fd_flags(struct fd_event *fde, uint16_t flags);
80
81 struct event_context *event_context_find(TALLOC_CTX *mem_ctx);
82
83 /* bits for file descriptor event flags */
84 #define EVENT_FD_READ 1
85 #define EVENT_FD_WRITE 2
86 #define EVENT_FD_AUTOCLOSE 4
87
88 #define EVENT_FD_WRITEABLE(fde) \
89         event_set_fd_flags(fde, event_get_fd_flags(fde) | EVENT_FD_WRITE)
90 #define EVENT_FD_READABLE(fde) \
91         event_set_fd_flags(fde, event_get_fd_flags(fde) | EVENT_FD_READ)
92
93 #define EVENT_FD_NOT_WRITEABLE(fde) \
94         event_set_fd_flags(fde, event_get_fd_flags(fde) & ~EVENT_FD_WRITE)
95 #define EVENT_FD_NOT_READABLE(fde) \
96         event_set_fd_flags(fde, event_get_fd_flags(fde) & ~EVENT_FD_READ)
97
98 #endif /* __TEVENT_H__ */