3 * Purple is the legal property of its developers, whose names are too numerous
4 * to list here. Please refer to the COPYRIGHT file distributed with this
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
22 #ifndef _PURPLE_EVENTLOOP_H_
23 #define _PURPLE_EVENTLOOP_H_
26 * @section_id: libpurple-eventloop
27 * @short_description: <filename>eventloop.h</filename>
28 * @title: Event Loop API
32 #include <glib-object.h>
34 #define PURPLE_TYPE_EVENTLOOP_UI_OPS (purple_eventloop_ui_ops_get_type())
37 * PurpleInputCondition:
38 * @PURPLE_INPUT_READ: A read condition.
39 * @PURPLE_INPUT_WRITE: A write condition.
45 PURPLE_INPUT_READ
= 1 << 0,
46 PURPLE_INPUT_WRITE
= 1 << 1
48 } PurpleInputCondition
;
51 * PurpleInputFunction:
53 * The type of callbacks to handle events on file descriptors, as passed to
54 * purple_input_add(). The callback will receive the @user_data passed to
55 * purple_input_add(), the file descriptor on which the event occurred, and the
56 * condition that was satisfied to cause the callback to be invoked.
58 typedef void (*PurpleInputFunction
)(gpointer
, gint
, PurpleInputCondition
);
60 typedef struct _PurpleEventLoopUiOps PurpleEventLoopUiOps
;
63 * PurpleEventLoopUiOps:
64 * @timeout_add: Should create a callback timer with an interval measured in
65 * milliseconds. The supplied @function should be called every
66 * @interval seconds until it returns %FALSE, after which it
67 * should not be called again.
68 * <sbr/>Analogous to g_timeout_add in glib.
69 * <sbr/>Note: On Win32, this function may be called from a thread
70 * other than the libpurple thread. You should make sure to detect
71 * this situation and to only call "function" from the libpurple
73 * <sbr/>See purple_timeout_add().
74 * <sbr/>@interval: the interval in
75 * <emphasis>milliseconds</emphasis> between
77 * <sbr/>@data: arbitrary data to be passed to @function at each
79 * <sbr/>Returns: a handle for the timeout, which can be passed to
81 * @timeout_remove: Should remove a callback timer. Analogous to
82 * g_source_remove() in glib.
83 * <sbr/>See purple_timeout_remove().
84 * <sbr/>@handle: an identifier for a timeout, as returned by
86 * <sbr/>Returns: %TRUE if the timeout identified by @handle
87 * was found and removed.
88 * @input_add: Should add an input handler. Analogous to g_io_add_watch_full()
90 * <sbr/>See purple_input_add().
91 * <sbr/>@fd: a file descriptor to watch for events
92 * <sbr/>@cond: a bitwise OR of events on @fd for which @func
94 * <sbr/>@func: a callback to fire whenever a relevant event on
96 * <sbr/>@user_data: arbitrary data to pass to @fd.
97 * <sbr/>Returns: an identifier for this input handler, which can
98 * be passed to @input_remove.
99 * @input_remove: Should remove an input handler. Analogous to g_source_remove()
101 * <sbr/>See purple_input_remove().
102 * <sbr/>@handle: an identifier, as returned by #input_add.
103 * <sbr/>Returns: %TRUE if the input handler was found and
105 * @input_get_error: If implemented, should get the current error status for an
107 * <sbr/>Implementation of this UI op is optional. Implement
108 * it if the UI's sockets or event loop needs to customize
109 * determination of socket error status. If unimplemented,
110 * <literal>getsockopt(2)</literal> will be used instead.
111 * <sbr/>See purple_input_get_error().
112 * @timeout_add_seconds: If implemented, should create a callback timer with an
113 * interval measured in seconds. Analogous to
114 * g_timeout_add_seconds() in glib.
115 * <sbr/>This allows UIs to group timers for better power
116 * efficiency. For this reason, @interval may be rounded
118 * <sbr/>Implementation of this UI op is optional. If it's
119 * not implemented, calls to purple_timeout_add_seconds()
120 * will be serviced by @timeout_add.
121 * <sbr/>See purple_timeout_add_seconds().
123 * An abstraction of an application's mainloop; libpurple will use this to
124 * watch file descriptors and schedule timed callbacks. If your application
125 * uses the glib mainloop, there is an implementation of this struct in
126 * <filename>libpurple/example/nullclient.c</filename> which you can use
129 struct _PurpleEventLoopUiOps
131 /* TODO Who is responsible for freeing @data? */
132 guint (*timeout_add
)(guint interval
, GSourceFunc function
, gpointer data
);
134 gboolean (*timeout_remove
)(guint handle
);
136 guint (*input_add
)(int fd
, PurpleInputCondition cond
,
137 PurpleInputFunction func
, gpointer user_data
);
139 gboolean (*input_remove
)(guint handle
);
141 int (*input_get_error
)(int fd
, int *error
);
143 guint (*timeout_add_seconds
)(guint interval
, GSourceFunc function
,
147 void (*_purple_reserved1
)(void);
148 void (*_purple_reserved2
)(void);
149 void (*_purple_reserved3
)(void);
150 void (*_purple_reserved4
)(void);
155 /**************************************************************************/
157 /**************************************************************************/
160 * purple_timeout_add:
161 * @interval: The time between calls of the function, in milliseconds.
162 * @function: (scope call): The function to call.
163 * @data: data to pass to @function.
165 * Creates a callback timer.
167 * The timer will repeat until the function returns %FALSE. The
168 * first call will be at the end of the first interval.
170 * If the timer is in a multiple of seconds, use purple_timeout_add_seconds()
171 * instead as it allows UIs to group timers for power efficiency.
173 * Returns: A handle to the timer which can be passed to
174 * purple_timeout_remove() to remove the timer.
176 guint
purple_timeout_add(guint interval
, GSourceFunc function
, gpointer data
);
179 * purple_timeout_add_seconds:
180 * @interval: The time between calls of the function, in seconds.
181 * @function: (scope call): The function to call.
182 * @data: data to pass to @function.
184 * Creates a callback timer.
186 * The timer will repeat until the function returns %FALSE. The
187 * first call will be at the end of the first interval.
189 * This function allows UIs to group timers for better power efficiency. For
190 * this reason, @interval may be rounded by up to a second.
192 * Returns: A handle to the timer which can be passed to
193 * purple_timeout_remove() to remove the timer.
195 guint
purple_timeout_add_seconds(guint interval
, GSourceFunc function
, gpointer data
);
198 * purple_timeout_remove:
199 * @handle: The handle, as returned by purple_timeout_add().
201 * Removes a timeout handler.
203 * Returns: %TRUE if the handler was successfully removed.
205 gboolean
purple_timeout_remove(guint handle
);
209 * @fd: The input file descriptor.
210 * @cond: The condition type.
211 * @func: (scope call): The callback function for data.
212 * @user_data: User-specified data.
214 * Adds an input handler.
216 * See g_io_add_watch_full().
218 * Returns: The resulting handle (will be greater than 0).
220 guint
purple_input_add(int fd
, PurpleInputCondition cond
,
221 PurpleInputFunction func
, gpointer user_data
);
224 * purple_input_remove:
225 * @handle: The handle of the input handler. Note that this is the return
226 * value from purple_input_add(), <emphasis>not</emphasis> the
229 * Removes an input handler.
231 gboolean
purple_input_remove(guint handle
);
234 * purple_input_get_error:
235 * @fd: The input file descriptor.
236 * @error: A pointer to an #int which on return will have the error, or
239 * Get the current error status for an input.
241 * The return value and error follow getsockopt() with a level of SOL_SOCKET and an
242 * option name of SO_ERROR, and this is how the error is determined if the UI does not
243 * implement the input_get_error UI op.
245 * Returns: 0 if there is no error; -1 if there is an error, in which case
246 * #errno will be set.
249 purple_input_get_error(int fd
, int *error
);
253 * @pipefd: Array used to return file descriptors for both ends of pipe.
255 * Creates a pipe - an unidirectional data channel that can be used for
256 * interprocess communication.
258 * File descriptors for both ends of pipe will be written into provided array.
259 * The first one (pipefd[0]) can be used for reading, the second one (pipefd[1])
262 * On Windows it's simulated by creating a pair of connected sockets, on other
263 * systems pipe() is used.
265 * Returns: 0 on success, -1 on error.
268 purple_input_pipe(int pipefd
[2]);
272 /**************************************************************************/
273 /* UI Registration Functions */
274 /**************************************************************************/
277 * purple_eventloop_ui_ops_get_type:
279 * Returns: The #GType for the #PurpleEventLoopUiOps boxed structure.
281 GType
purple_eventloop_ui_ops_get_type(void);
284 * purple_eventloop_set_ui_ops:
285 * @ops: The UI operations structure.
287 * Sets the UI operations structure to be used for accounts.
289 void purple_eventloop_set_ui_ops(PurpleEventLoopUiOps
*ops
);
292 * purple_eventloop_get_ui_ops:
294 * Returns the UI operations structure used for accounts.
296 * Returns: The UI operations structure in use.
298 PurpleEventLoopUiOps
*purple_eventloop_get_ui_ops(void);
302 #endif /* _PURPLE_EVENTLOOP_H_ */