42d67c31bf80d0af501e77aff7bbe98cece05fa2
[vlendec/samba-autobuild/.git] / ctdb / 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 #ifndef __EVENTS_H__
24 #define __EVENTS_H__
25
26 #include "talloc/talloc.h"
27 #include <stdlib.h>
28
29 struct event_context;
30 struct event_ops;
31 struct fd_event;
32 struct timed_event;
33 struct aio_event;
34 struct signal_event;
35
36 /* event handler types */
37 typedef void (*event_fd_handler_t)(struct event_context *, struct fd_event *, 
38                                    uint16_t , void *);
39 typedef void (*event_timed_handler_t)(struct event_context *, struct timed_event *, 
40                                       struct timeval , void *);
41 typedef void (*event_signal_handler_t)(struct event_context *, struct signal_event *, 
42                                        int , int, void *, void *);
43 typedef void (*event_aio_handler_t)(struct event_context *, struct aio_event *, 
44                                     int, void *);
45
46 struct event_context *event_context_init(TALLOC_CTX *mem_ctx);
47 struct event_context *event_context_init_byname(TALLOC_CTX *mem_ctx, const char *name);
48 const char **event_backend_list(TALLOC_CTX *mem_ctx);
49 void event_set_default_backend(const char *backend);
50
51 struct fd_event *event_add_fd(struct event_context *ev, TALLOC_CTX *mem_ctx,
52                               int fd, uint16_t flags, event_fd_handler_t handler,
53                               void *private);
54
55 struct timed_event *event_add_timed(struct event_context *ev, TALLOC_CTX *mem_ctx,
56                                     struct timeval next_event, 
57                                     event_timed_handler_t handler, 
58                                     void *private);
59
60 struct signal_event *event_add_signal(struct event_context *ev, TALLOC_CTX *mem_ctx,
61                                       int signum, int sa_flags,
62                                       event_signal_handler_t handler, 
63                                       void *private);
64
65 struct iocb;
66 struct aio_event *event_add_aio(struct event_context *ev,
67                                 TALLOC_CTX *mem_ctx,
68                                 struct iocb *iocb,
69                                 event_aio_handler_t handler,
70                                 void *private);
71
72 int event_loop_once(struct event_context *ev);
73 int event_loop_wait(struct event_context *ev);
74
75 uint16_t event_get_fd_flags(struct fd_event *fde);
76 void event_set_fd_flags(struct fd_event *fde, uint16_t flags);
77
78 struct event_context *event_context_find(TALLOC_CTX *mem_ctx);
79
80 /* bits for file descriptor event flags */
81 #define EVENT_FD_READ 1
82 #define EVENT_FD_WRITE 2
83 #define EVENT_FD_AUTOCLOSE 4
84
85 #define EVENT_FD_WRITEABLE(fde) \
86         event_set_fd_flags(fde, event_get_fd_flags(fde) | EVENT_FD_WRITE)
87 #define EVENT_FD_READABLE(fde) \
88         event_set_fd_flags(fde, event_get_fd_flags(fde) | EVENT_FD_READ)
89
90 #define EVENT_FD_NOT_WRITEABLE(fde) \
91         event_set_fd_flags(fde, event_get_fd_flags(fde) & ~EVENT_FD_WRITE)
92 #define EVENT_FD_NOT_READABLE(fde) \
93         event_set_fd_flags(fde, event_get_fd_flags(fde) & ~EVENT_FD_READ)
94
95 #endif /* __EVENTS_H__ */