summaryrefslogtreecommitdiffstats
path: root/source3/lib/poll_funcs/poll_funcs.h
blob: 6072eb5b035990054aba605b1d1a6ec321a76e5b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/*
 * Unix SMB/CIFS implementation.
 * Copyright (C) Volker Lendecke 2013
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

/**
 * @file poll_funcs.h
 *
 * @brief event loop abstraction
 */

/*
 * This is inspired by AvahiWatch, the avahi event loop abstraction.
 */

#ifndef __POLL_FUNCS_H__
#define __POLL_FUNCS_H__

#include "replace.h"

/**
 * poll_watch and poll_timeout are undefined here, every implementation can
 * implement its own structures.
 */

struct poll_watch;
struct poll_timeout;

struct poll_funcs {

	/**
	 * @brief Create a new file descriptor watch
	 *
	 * @param[in] funcs The callback array
	 * @param[in] fd The fd to watch
	 * @param[in] events POLLIN and POLLOUT or'ed together
	 * @param[in] callback Function to call by the implementation
	 * @param[in] private_data Pointer to give back to callback
	 *
	 * @return A new poll_watch struct
	 */

	struct poll_watch *(*watch_new)(
		const struct poll_funcs *funcs, int fd, short events,
		void (*callback)(struct poll_watch *w, int fd,
				 short events, void *private_data),
		void *private_data);

	/**
	 * @brief Change the watched events for a struct poll_watch
	 *
	 * @param[in] w The poll_watch to change
	 * @param[in] events new POLLIN and POLLOUT or'ed together
	 */

	void (*watch_update)(struct poll_watch *w, short events);

	/**
	 * @brief Read events currently watched
	 *
	 * @param[in] w The poll_watch to inspect
	 *
	 * @returns The events currently watched
	 */

	short (*watch_get_events)(struct poll_watch *w);

	/**
	 * @brief Free a struct poll_watch
	 *
	 * @param[in] w The poll_watch struct to free
	 */

	void (*watch_free)(struct poll_watch *w);


	/**
	 * @brief Create a new timeout watch
	 *
	 * @param[in] funcs The callback array
	 * @param[in] tv The time when the timeout should trigger
	 * @param[in] callback Function to call at time "ts"
	 * @param[in] private_data Pointer to give back to callback
	 *
	 * @return A new poll_timeout struct
	 */

	struct poll_timeout *(*timeout_new)(
		const struct poll_funcs *funcs, const struct timeval *tv,
		void (*callback)(struct poll_timeout *t, void *private_data),
		void *private_data);

	/**
	 * @brief Change the timeout of a watch
	 *
	 * @param[in] t The timeout watch to change
	 * @param[in] ts The new trigger time
	 */

	void (*timeout_update)(struct poll_timeout *t,
			       const struct timespec *ts);

	/**
	 * @brief Free a poll_timeout
	 *
	 * @param[in] t The poll_timeout to free
	 */

	void (*timeout_free)(struct poll_timeout *t);

	/**
	 * @brief private data for use by the implementation
	 */

	void *private_data;
};

#endif