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