r6968: fixed a typo in the event macros. I'm surprised this one didn't show up earlier!
[bbaumbach/samba-autobuild/.git] / source4 / lib / events / events.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 2 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, write to the Free Software
20    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 */
22
23 struct event_context;
24 struct event_ops;
25 struct fd_event;
26 struct timed_event;
27
28 /* event handler types */
29 typedef void (*event_fd_handler_t)(struct event_context *, struct fd_event *, 
30                                    uint16_t , void *);
31 typedef void (*event_timed_handler_t)(struct event_context *, struct timed_event *, 
32                                       struct timeval , void *);
33
34 struct event_context *event_context_init(TALLOC_CTX *mem_ctx);
35 struct event_context *event_context_init_ops(TALLOC_CTX *mem_ctx, const struct event_ops *ops, void *private_data);
36
37 struct fd_event *event_add_fd(struct event_context *ev, TALLOC_CTX *mem_ctx,
38                               int fd, uint16_t flags, event_fd_handler_t handler,
39                               void *private);
40
41 struct timed_event *event_add_timed(struct event_context *ev, TALLOC_CTX *mem_ctx,
42                                     struct timeval next_event, 
43                                     event_timed_handler_t handler, 
44                                     void *private);
45
46 int event_loop_once(struct event_context *ev);
47 int event_loop_wait(struct event_context *ev);
48
49 uint16_t event_get_fd_flags(struct fd_event *fde);
50 void event_set_fd_flags(struct fd_event *fde, uint16_t flags);
51
52 /* bits for file descriptor event flags */
53 #define EVENT_FD_READ 1
54 #define EVENT_FD_WRITE 2
55
56 #define EVENT_FD_WRITEABLE(fde) \
57         event_set_fd_flags(fde, event_get_fd_flags(fde) | EVENT_FD_WRITE)
58 #define EVENT_FD_READABLE(fde) \
59         event_set_fd_flags(fde, event_get_fd_flags(fde) | EVENT_FD_READ)
60
61 #define EVENT_FD_NOT_WRITEABLE(fde) \
62         event_set_fd_flags(fde, event_get_fd_flags(fde) & ~EVENT_FD_WRITE)
63 #define EVENT_FD_NOT_READABLE(fde) \
64         event_set_fd_flags(fde, event_get_fd_flags(fde) & ~EVENT_FD_READ)