|
Evan@653
|
1 |
/** |
|
Evan@653
|
2 |
* @file eventloop.h Purple Event Loop API |
|
Evan@653
|
3 |
* @ingroup core |
|
Evan@653
|
4 |
*/ |
|
Evan@653
|
5 |
|
|
Evan@653
|
6 |
/* purple |
|
Evan@653
|
7 |
* |
|
Evan@653
|
8 |
* Purple is the legal property of its developers, whose names are too numerous |
|
Evan@653
|
9 |
* to list here. Please refer to the COPYRIGHT file distributed with this |
|
Evan@653
|
10 |
* source distribution. |
|
Evan@653
|
11 |
* |
|
Evan@653
|
12 |
* This program is free software; you can redistribute it and/or modify |
|
Evan@653
|
13 |
* it under the terms of the GNU General Public License as published by |
|
Evan@653
|
14 |
* the Free Software Foundation; either version 2 of the License, or |
|
Evan@653
|
15 |
* (at your option) any later version. |
|
Evan@653
|
16 |
* |
|
Evan@653
|
17 |
* This program is distributed in the hope that it will be useful, |
|
Evan@653
|
18 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
Evan@653
|
19 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
Evan@653
|
20 |
* GNU General Public License for more details. |
|
Evan@653
|
21 |
* |
|
Evan@653
|
22 |
* You should have received a copy of the GNU General Public License |
|
Evan@653
|
23 |
* along with this program; if not, write to the Free Software |
|
Evan@653
|
24 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA |
|
Evan@653
|
25 |
*/ |
|
Evan@653
|
26 |
#ifndef _PURPLE_EVENTLOOP_H_ |
|
Evan@653
|
27 |
#define _PURPLE_EVENTLOOP_H_ |
|
Evan@653
|
28 |
|
|
Evan@653
|
29 |
#include <glib.h> |
|
Evan@653
|
30 |
|
|
Evan@653
|
31 |
#ifdef __cplusplus |
|
Evan@653
|
32 |
extern "C" { |
|
Evan@653
|
33 |
#endif |
|
Evan@653
|
34 |
|
|
Evan@653
|
35 |
/** |
|
Evan@653
|
36 |
* An input condition. |
|
Evan@653
|
37 |
*/ |
|
Evan@653
|
38 |
typedef enum |
|
Evan@653
|
39 |
{ |
|
Evan@653
|
40 |
PURPLE_INPUT_READ = 1 << 0, /**< A read condition. */ |
|
Evan@653
|
41 |
PURPLE_INPUT_WRITE = 1 << 1 /**< A write condition. */ |
|
Evan@653
|
42 |
|
|
Evan@653
|
43 |
} PurpleInputCondition; |
|
Evan@653
|
44 |
|
|
Evan@653
|
45 |
/** The type of callbacks to handle events on file descriptors, as passed to |
|
Evan@653
|
46 |
* purple_input_add(). The callback will receive the @c user_data passed to |
|
Evan@653
|
47 |
* purple_input_add(), the file descriptor on which the event occurred, and the |
|
Evan@653
|
48 |
* condition that was satisfied to cause the callback to be invoked. |
|
Evan@653
|
49 |
*/ |
|
Evan@653
|
50 |
typedef void (*PurpleInputFunction)(gpointer, gint, PurpleInputCondition); |
|
Evan@653
|
51 |
|
|
Evan@653
|
52 |
/** @copydoc _PurpleEventLoopUiOps */ |
|
Evan@653
|
53 |
typedef struct _PurpleEventLoopUiOps PurpleEventLoopUiOps; |
|
Evan@653
|
54 |
|
|
Evan@653
|
55 |
/** An abstraction of an application's mainloop; libpurple will use this to |
|
Evan@653
|
56 |
* watch file descriptors and schedule timed callbacks. If your application |
|
Evan@653
|
57 |
* uses the glib mainloop, there is an implementation of this struct in |
|
Evan@653
|
58 |
* <tt>libpurple/example/nullclient.c</tt> which you can use verbatim. |
|
Evan@653
|
59 |
*/ |
|
Evan@653
|
60 |
struct _PurpleEventLoopUiOps |
|
Evan@653
|
61 |
{ |
|
Evan@653
|
62 |
/** |
|
Evan@653
|
63 |
* Should create a callback timer with an interval measured in |
|
Evan@653
|
64 |
* milliseconds. The supplied @a function should be called every @a |
|
Evan@653
|
65 |
* interval seconds until it returns @c FALSE, after which it should not |
|
Evan@653
|
66 |
* be called again. |
|
Evan@653
|
67 |
* |
|
Evan@653
|
68 |
* Analogous to g_timeout_add in glib. |
|
Evan@653
|
69 |
* |
|
Evan@653
|
70 |
* Note: On Win32, this function may be called from a thread other than |
|
Evan@653
|
71 |
* the libpurple thread. You should make sure to detect this situation |
|
Evan@653
|
72 |
* and to only call "function" from the libpurple thread. |
|
Evan@653
|
73 |
* |
|
Evan@653
|
74 |
* @param interval the interval in <em>milliseconds</em> between calls |
|
Evan@653
|
75 |
* to @a function. |
|
Evan@653
|
76 |
* @param data arbitrary data to be passed to @a function at each |
|
Evan@653
|
77 |
* call. |
|
Evan@653
|
78 |
* @todo Who is responsible for freeing @a data? |
|
Evan@653
|
79 |
* |
|
Evan@653
|
80 |
* @return a handle for the timeout, which can be passed to |
|
Evan@653
|
81 |
* #timeout_remove. |
|
Evan@653
|
82 |
* |
|
Evan@653
|
83 |
* @see purple_timeout_add |
|
Evan@653
|
84 |
**/ |
|
Evan@653
|
85 |
guint (*timeout_add)(guint interval, GSourceFunc function, gpointer data); |
|
Evan@653
|
86 |
|
|
Evan@653
|
87 |
/** |
|
Evan@653
|
88 |
* Should remove a callback timer. Analogous to g_source_remove in glib. |
|
Evan@653
|
89 |
* @param handle an identifier for a timeout, as returned by |
|
Evan@653
|
90 |
* #timeout_add. |
|
Evan@653
|
91 |
* @return @c TRUE if the timeout identified by @a handle was |
|
Evan@653
|
92 |
* found and removed. |
|
Evan@653
|
93 |
* @see purple_timeout_remove |
|
Evan@653
|
94 |
*/ |
|
Evan@653
|
95 |
gboolean (*timeout_remove)(guint handle); |
|
Evan@653
|
96 |
|
|
Evan@653
|
97 |
/** |
|
Evan@653
|
98 |
* Should add an input handler. Analogous to g_io_add_watch_full in |
|
Evan@653
|
99 |
* glib. |
|
Evan@653
|
100 |
* |
|
Evan@653
|
101 |
* @param fd a file descriptor to watch for events |
|
Evan@653
|
102 |
* @param cond a bitwise OR of events on @a fd for which @a func |
|
Evan@653
|
103 |
* should be called. |
|
Evan@653
|
104 |
* @param func a callback to fire whenever a relevant event on @a |
|
Evan@653
|
105 |
* fd occurs. |
|
Evan@653
|
106 |
* @param user_data arbitrary data to pass to @a fd. |
|
Evan@653
|
107 |
* @return an identifier for this input handler, which can be |
|
Evan@653
|
108 |
* passed to #input_remove. |
|
Evan@653
|
109 |
* |
|
Evan@653
|
110 |
* @see purple_input_add |
|
Evan@653
|
111 |
*/ |
|
Evan@653
|
112 |
guint (*input_add)(int fd, PurpleInputCondition cond, |
|
Evan@653
|
113 |
PurpleInputFunction func, gpointer user_data); |
|
Evan@653
|
114 |
|
|
Evan@653
|
115 |
/** |
|
Evan@653
|
116 |
* Should remove an input handler. Analogous to g_source_remove in glib. |
|
Evan@653
|
117 |
* @param handle an identifier, as returned by #input_add. |
|
Evan@653
|
118 |
* @return @c TRUE if the input handler was found and removed. |
|
Evan@653
|
119 |
* @see purple_input_remove |
|
Evan@653
|
120 |
*/ |
|
Evan@653
|
121 |
gboolean (*input_remove)(guint handle); |
|
Evan@1427
|
122 |
|
|
Evan@1427
|
123 |
|
|
Evan@653
|
124 |
/** |
|
Evan@653
|
125 |
* If implemented, should get the current error status for an input. |
|
Evan@653
|
126 |
* |
|
Evan@653
|
127 |
* Implementation of this UI op is optional. Implement it if the UI's |
|
Evan@653
|
128 |
* sockets or event loop needs to customize determination of socket |
|
Evan@653
|
129 |
* error status. If unimplemented, <tt>getsockopt(2)</tt> will be used |
|
Evan@653
|
130 |
* instead. |
|
Evan@653
|
131 |
* |
|
Evan@653
|
132 |
* @see purple_input_get_error |
|
Evan@653
|
133 |
*/ |
|
Evan@653
|
134 |
int (*input_get_error)(int fd, int *error); |
|
Evan@653
|
135 |
|
|
Evan@653
|
136 |
/** |
|
Evan@653
|
137 |
* If implemented, should create a callback timer with an interval |
|
Evan@653
|
138 |
* measured in seconds. Analogous to g_timeout_add_seconds in glib. |
|
Evan@653
|
139 |
* |
|
Evan@653
|
140 |
* This allows UIs to group timers for better power efficiency. For |
|
Evan@653
|
141 |
* this reason, @a interval may be rounded by up to a second. |
|
Evan@653
|
142 |
* |
|
Evan@653
|
143 |
* Implementation of this UI op is optional. If it's not implemented, |
|
Evan@653
|
144 |
* calls to purple_timeout_add_seconds() will be serviced by |
|
Evan@653
|
145 |
* #timeout_add. |
|
Evan@653
|
146 |
* |
|
Evan@653
|
147 |
* @see purple_timeout_add_seconds() |
|
Evan@653
|
148 |
* @since 2.1.0 |
|
Evan@653
|
149 |
**/ |
|
Evan@653
|
150 |
guint (*timeout_add_seconds)(guint interval, GSourceFunc function, |
|
Evan@653
|
151 |
gpointer data); |
|
Evan@653
|
152 |
|
|
Evan@653
|
153 |
void (*_purple_reserved2)(void); |
|
Evan@653
|
154 |
void (*_purple_reserved3)(void); |
|
Evan@653
|
155 |
void (*_purple_reserved4)(void); |
|
Evan@653
|
156 |
}; |
|
Evan@653
|
157 |
|
|
Evan@653
|
158 |
/**************************************************************************/ |
|
Evan@653
|
159 |
/** @name Event Loop API */ |
|
Evan@653
|
160 |
/**************************************************************************/ |
|
Evan@653
|
161 |
/*@{*/ |
|
Evan@653
|
162 |
/** |
|
Evan@653
|
163 |
* Creates a callback timer. |
|
Evan@1427
|
164 |
* |
|
Evan@653
|
165 |
* The timer will repeat until the function returns @c FALSE. The |
|
Evan@653
|
166 |
* first call will be at the end of the first interval. |
|
Evan@653
|
167 |
* |
|
Evan@653
|
168 |
* If the timer is in a multiple of seconds, use purple_timeout_add_seconds() |
|
Evan@653
|
169 |
* instead as it allows UIs to group timers for power efficiency. |
|
Evan@653
|
170 |
* |
|
Evan@653
|
171 |
* @param interval The time between calls of the function, in |
|
Evan@653
|
172 |
* milliseconds. |
|
Evan@653
|
173 |
* @param function The function to call. |
|
Evan@653
|
174 |
* @param data data to pass to @a function. |
|
Evan@653
|
175 |
* @return A handle to the timer which can be passed to |
|
Evan@653
|
176 |
* purple_timeout_remove() to remove the timer. |
|
Evan@653
|
177 |
*/ |
|
Evan@653
|
178 |
guint purple_timeout_add(guint interval, GSourceFunc function, gpointer data); |
|
Evan@653
|
179 |
|
|
Evan@653
|
180 |
/** |
|
Evan@653
|
181 |
* Creates a callback timer. |
|
Evan@653
|
182 |
* |
|
Evan@653
|
183 |
* The timer will repeat until the function returns @c FALSE. The |
|
Evan@653
|
184 |
* first call will be at the end of the first interval. |
|
Evan@653
|
185 |
* |
|
Evan@653
|
186 |
* This function allows UIs to group timers for better power efficiency. For |
|
Evan@653
|
187 |
* this reason, @a interval may be rounded by up to a second. |
|
Evan@1427
|
188 |
* |
|
Evan@653
|
189 |
* @param interval The time between calls of the function, in |
|
Evan@653
|
190 |
* seconds. |
|
Evan@653
|
191 |
* @param function The function to call. |
|
Evan@653
|
192 |
* @param data data to pass to @a function. |
|
Evan@1427
|
193 |
* @return A handle to the timer which can be passed to |
|
Evan@653
|
194 |
* purple_timeout_remove() to remove the timer. |
|
Evan@653
|
195 |
* |
|
Evan@653
|
196 |
* @since 2.1.0 |
|
Evan@653
|
197 |
*/ |
|
Evan@653
|
198 |
guint purple_timeout_add_seconds(guint interval, GSourceFunc function, gpointer data); |
|
Evan@653
|
199 |
|
|
Evan@653
|
200 |
/** |
|
Evan@653
|
201 |
* Removes a timeout handler. |
|
Evan@653
|
202 |
* |
|
Evan@653
|
203 |
* @param handle The handle, as returned by purple_timeout_add(). |
|
Evan@653
|
204 |
* |
|
Evan@653
|
205 |
* @return @c TRUE if the handler was successfully removed. |
|
Evan@653
|
206 |
*/ |
|
Evan@653
|
207 |
gboolean purple_timeout_remove(guint handle); |
|
Evan@653
|
208 |
|
|
Evan@653
|
209 |
/** |
|
Evan@653
|
210 |
* Adds an input handler. |
|
Evan@653
|
211 |
* |
|
Evan@653
|
212 |
* @param fd The input file descriptor. |
|
Evan@653
|
213 |
* @param cond The condition type. |
|
Evan@653
|
214 |
* @param func The callback function for data. |
|
Evan@653
|
215 |
* @param user_data User-specified data. |
|
Evan@653
|
216 |
* |
|
Evan@653
|
217 |
* @return The resulting handle (will be greater than 0). |
|
Evan@653
|
218 |
* @see g_io_add_watch_full |
|
Evan@653
|
219 |
*/ |
|
Evan@653
|
220 |
guint purple_input_add(int fd, PurpleInputCondition cond, |
|
Evan@653
|
221 |
PurpleInputFunction func, gpointer user_data); |
|
Evan@653
|
222 |
|
|
Evan@653
|
223 |
/** |
|
Evan@653
|
224 |
* Removes an input handler. |
|
Evan@653
|
225 |
* |
|
Evan@653
|
226 |
* @param handle The handle of the input handler. Note that this is the return |
|
Evan@653
|
227 |
* value from purple_input_add(), <i>not</i> the file descriptor. |
|
Evan@653
|
228 |
*/ |
|
Evan@653
|
229 |
gboolean purple_input_remove(guint handle); |
|
Evan@653
|
230 |
|
|
Evan@653
|
231 |
/** |
|
Evan@653
|
232 |
* Get the current error status for an input. |
|
Evan@653
|
233 |
* |
|
Evan@653
|
234 |
* The return value and error follow getsockopt() with a level of SOL_SOCKET and an |
|
Evan@653
|
235 |
* option name of SO_ERROR, and this is how the error is determined if the UI does not |
|
Evan@653
|
236 |
* implement the input_get_error UI op. |
|
Evan@653
|
237 |
* |
|
Evan@653
|
238 |
* @param fd The input file descriptor. |
|
Evan@653
|
239 |
* @param error A pointer to an @c int which on return will have the error, or |
|
Evan@653
|
240 |
* @c 0 if no error. |
|
Evan@653
|
241 |
* |
|
Evan@653
|
242 |
* @return @c 0 if there is no error; @c -1 if there is an error, in which case |
|
Evan@653
|
243 |
* @a errno will be set. |
|
Evan@653
|
244 |
*/ |
|
Evan@653
|
245 |
int |
|
Evan@653
|
246 |
purple_input_get_error(int fd, int *error); |
|
Evan@653
|
247 |
|
|
Evan@653
|
248 |
|
|
Evan@653
|
249 |
/*@}*/ |
|
Evan@653
|
250 |
|
|
Evan@653
|
251 |
|
|
Evan@653
|
252 |
/**************************************************************************/ |
|
Evan@653
|
253 |
/** @name UI Registration Functions */ |
|
Evan@653
|
254 |
/**************************************************************************/ |
|
Evan@653
|
255 |
/*@{*/ |
|
Evan@653
|
256 |
/** |
|
Evan@653
|
257 |
* Sets the UI operations structure to be used for accounts. |
|
Evan@653
|
258 |
* |
|
Evan@653
|
259 |
* @param ops The UI operations structure. |
|
Evan@653
|
260 |
*/ |
|
Evan@653
|
261 |
void purple_eventloop_set_ui_ops(PurpleEventLoopUiOps *ops); |
|
Evan@653
|
262 |
|
|
Evan@653
|
263 |
/** |
|
Evan@653
|
264 |
* Returns the UI operations structure used for accounts. |
|
Evan@653
|
265 |
* |
|
Evan@653
|
266 |
* @return The UI operations structure in use. |
|
Evan@653
|
267 |
*/ |
|
Evan@653
|
268 |
PurpleEventLoopUiOps *purple_eventloop_get_ui_ops(void); |
|
Evan@653
|
269 |
|
|
Evan@653
|
270 |
/*@}*/ |
|
Evan@653
|
271 |
|
|
Evan@653
|
272 |
#ifdef __cplusplus |
|
Evan@653
|
273 |
} |
|
Evan@653
|
274 |
#endif |
|
Evan@653
|
275 |
|
|
Evan@653
|
276 |
#endif /* _PURPLE_EVENTLOOP_H_ */ |