merge relevant lib code from samba4
[vlendec/samba-autobuild/.git] / ctdb / lib / events / events_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 2 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, write to the Free Software
22    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 */
24
25 struct event_ops {
26         /* conntext init */
27         int (*context_init)(struct event_context *ev);
28
29         /* fd_event functions */
30         struct fd_event *(*add_fd)(struct event_context *ev,
31                                    TALLOC_CTX *mem_ctx,
32                                    int fd, uint16_t flags,
33                                    event_fd_handler_t handler,
34                                    void *private_data);
35         uint16_t (*get_fd_flags)(struct fd_event *fde);
36         void (*set_fd_flags)(struct fd_event *fde, uint16_t flags);
37
38         /* timed_event functions */
39         struct timed_event *(*add_timed)(struct event_context *ev,
40                                          TALLOC_CTX *mem_ctx,
41                                          struct timeval next_event,
42                                          event_timed_handler_t handler,
43                                          void *private_data);
44         /* disk aio event functions */
45         struct aio_event *(*add_aio)(struct event_context *ev,
46                                      TALLOC_CTX *mem_ctx,
47                                      struct iocb *iocb, 
48                                      event_aio_handler_t handler, 
49                                      void *private_data);
50         /* signal functions */
51         struct signal_event *(*add_signal)(struct event_context *ev, 
52                                            TALLOC_CTX *mem_ctx,
53                                            int signum, int sa_flags,
54                                            event_signal_handler_t handler, 
55                                            void *private_data);
56
57         /* loop functions */
58         int (*loop_once)(struct event_context *ev);
59         int (*loop_wait)(struct event_context *ev);
60 };
61
62 struct fd_event {
63         struct fd_event *prev, *next;
64         struct event_context *event_ctx;
65         int fd;
66         uint16_t flags; /* see EVENT_FD_* flags */
67         event_fd_handler_t handler;
68         /* this is private for the specific handler */
69         void *private_data;
70         /* this is private for the events_ops implementation */
71         uint16_t additional_flags;
72         void *additional_data;
73 };
74
75 struct timed_event {
76         struct timed_event *prev, *next;
77         struct event_context *event_ctx;
78         struct timeval next_event;
79         event_timed_handler_t handler;
80         /* this is private for the specific handler */
81         void *private_data;
82         /* this is private for the events_ops implementation */
83         void *additional_data;
84 };
85
86 struct signal_event {
87         struct signal_event *prev, *next;
88         struct event_context *event_ctx;
89         event_signal_handler_t handler;
90         void *private_data;
91         int signum;
92         int sa_flags;
93 };
94
95 /* aio event is private to the aio backend */
96 struct aio_event;
97
98 struct event_context {  
99         /* the specific events implementation */
100         const struct event_ops *ops;
101
102         /* list of timed events - used by common code */
103         struct timed_event *timed_events;
104
105         /* this is private for the events_ops implementation */
106         void *additional_data;
107
108         /* number of signal event handlers */
109         int num_signal_handlers;
110
111         /* pipe hack used with signal handlers */
112         struct fd_event *pipe_fde;
113 };
114
115
116 bool event_register_backend(const char *name, const struct event_ops *ops);
117
118 struct timed_event *common_event_add_timed(struct event_context *, TALLOC_CTX *,
119                                            struct timeval, event_timed_handler_t, void *);
120 struct timeval common_event_loop_timer_delay(struct event_context *);
121
122 struct signal_event *common_event_add_signal(struct event_context *ev, 
123                                              TALLOC_CTX *mem_ctx,
124                                              int signum,
125                                              int sa_flags,
126                                              event_signal_handler_t handler, 
127                                              void *private_data);
128 int common_event_check_signal(struct event_context *ev);
129