6072eb5b035990054aba605b1d1a6ec321a76e5b
[metze/samba/wip.git] / lib / poll_funcs / poll_funcs.h
1 /*
2  * Unix SMB/CIFS implementation.
3  * Copyright (C) Volker Lendecke 2013
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17  */
18
19 /**
20  * @file poll_funcs.h
21  *
22  * @brief event loop abstraction
23  */
24
25 /*
26  * This is inspired by AvahiWatch, the avahi event loop abstraction.
27  */
28
29 #ifndef __POLL_FUNCS_H__
30 #define __POLL_FUNCS_H__
31
32 #include "replace.h"
33
34 /**
35  * poll_watch and poll_timeout are undefined here, every implementation can
36  * implement its own structures.
37  */
38
39 struct poll_watch;
40 struct poll_timeout;
41
42 struct poll_funcs {
43
44         /**
45          * @brief Create a new file descriptor watch
46          *
47          * @param[in] funcs The callback array
48          * @param[in] fd The fd to watch
49          * @param[in] events POLLIN and POLLOUT or'ed together
50          * @param[in] callback Function to call by the implementation
51          * @param[in] private_data Pointer to give back to callback
52          *
53          * @return A new poll_watch struct
54          */
55
56         struct poll_watch *(*watch_new)(
57                 const struct poll_funcs *funcs, int fd, short events,
58                 void (*callback)(struct poll_watch *w, int fd,
59                                  short events, void *private_data),
60                 void *private_data);
61
62         /**
63          * @brief Change the watched events for a struct poll_watch
64          *
65          * @param[in] w The poll_watch to change
66          * @param[in] events new POLLIN and POLLOUT or'ed together
67          */
68
69         void (*watch_update)(struct poll_watch *w, short events);
70
71         /**
72          * @brief Read events currently watched
73          *
74          * @param[in] w The poll_watch to inspect
75          *
76          * @returns The events currently watched
77          */
78
79         short (*watch_get_events)(struct poll_watch *w);
80
81         /**
82          * @brief Free a struct poll_watch
83          *
84          * @param[in] w The poll_watch struct to free
85          */
86
87         void (*watch_free)(struct poll_watch *w);
88
89
90         /**
91          * @brief Create a new timeout watch
92          *
93          * @param[in] funcs The callback array
94          * @param[in] tv The time when the timeout should trigger
95          * @param[in] callback Function to call at time "ts"
96          * @param[in] private_data Pointer to give back to callback
97          *
98          * @return A new poll_timeout struct
99          */
100
101         struct poll_timeout *(*timeout_new)(
102                 const struct poll_funcs *funcs, const struct timeval *tv,
103                 void (*callback)(struct poll_timeout *t, void *private_data),
104                 void *private_data);
105
106         /**
107          * @brief Change the timeout of a watch
108          *
109          * @param[in] t The timeout watch to change
110          * @param[in] ts The new trigger time
111          */
112
113         void (*timeout_update)(struct poll_timeout *t,
114                                const struct timespec *ts);
115
116         /**
117          * @brief Free a poll_timeout
118          *
119          * @param[in] t The poll_timeout to free
120          */
121
122         void (*timeout_free)(struct poll_timeout *t);
123
124         /**
125          * @brief private data for use by the implementation
126          */
127
128         void *private_data;
129 };
130
131 #endif