summaryrefslogtreecommitdiff
path: root/libpurple/signals.h
blob: 77352a042b8a22e88effdfe9d643c4a4075de1ec (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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
/**
 * @file signals.h Signal API
 * @ingroup core
 */

/* purple
 *
 * Purple is the legal property of its developers, whose names are too numerous
 * to list here.  Please refer to the COPYRIGHT file distributed with this
 * source distribution.
 *
 * 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 2 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, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111-1301  USA
 */
#ifndef _PURPLE_SIGNALS_H_
#define _PURPLE_SIGNALS_H_

#include <glib.h>
#include "value.h"

#define PURPLE_CALLBACK(func) ((PurpleCallback)func)

typedef void (*PurpleCallback)(void);
typedef void (*PurpleSignalMarshalFunc)(PurpleCallback cb, va_list args,
									  void *data, void **return_val);

#ifdef __cplusplus
extern "C" {
#endif

/**************************************************************************/
/** @name Signal API                                                      */
/**************************************************************************/
/*@{*/

/** The priority of a signal connected using purple_signal_connect().
 *
 *  @see purple_signal_connect_priority()
 */
#define PURPLE_SIGNAL_PRIORITY_DEFAULT     0
/** The largest signal priority; signals with this priority will be called
 *  <em>last</em>.  (This is highest as in numerical value, not as in order of
 *  importance.)
 *
 *  @see purple_signal_connect_priority().
 */
#define PURPLE_SIGNAL_PRIORITY_HIGHEST  9999
/** The smallest signal priority; signals with this priority will be called
 *  <em>first</em>.  (This is lowest as in numerical value, not as in order of
 *  importance.)
 *
 *  @see purple_signal_connect_priority().
 */
#define PURPLE_SIGNAL_PRIORITY_LOWEST  -9999

/**
 * Registers a signal in an instance.
 *
 * @param instance   The instance to register the signal for.
 * @param signal     The signal name.
 * @param marshal    The marshal function.
 * @param ret_value  The return value type, or NULL for no return value.
 * @param num_values The number of values to be passed to the callbacks.
 * @param ...        The values to pass to the callbacks.
 *
 * @return The signal ID local to that instance, or 0 if the signal
 *         couldn't be registered.
 *
 * @see PurpleValue
 */
gulong purple_signal_register(void *instance, const char *signal,
							PurpleSignalMarshalFunc marshal,
							PurpleValue *ret_value, int num_values, ...);

/**
 * Unregisters a signal in an instance.
 *
 * @param instance The instance to unregister the signal for.
 * @param signal   The signal name.
 */
void purple_signal_unregister(void *instance, const char *signal);

/**
 * Unregisters all signals in an instance.
 *
 * @param instance The instance to unregister the signal for.
 */
void purple_signals_unregister_by_instance(void *instance);

/**
 * Returns a list of value types used for a signal.
 *
 * @param instance   The instance the signal is registered to.
 * @param signal     The signal.
 * @param ret_value  The return value from the last signal handler.
 * @param num_values The returned number of values.
 * @param values     The returned list of values.
 */
void purple_signal_get_values(void *instance, const char *signal,
							PurpleValue **ret_value,
							int *num_values, PurpleValue ***values);

/**
 * Connects a signal handler to a signal for a particular object.
 *
 * Take care not to register a handler function twice. Purple will
 * not correct any mistakes for you in this area.
 *
 * @param instance The instance to connect to.
 * @param signal   The name of the signal to connect.
 * @param handle   The handle of the receiver.
 * @param func     The callback function.
 * @param data     The data to pass to the callback function.
 * @param priority The priority with which the handler should be called. Signal
 *                 handlers are called in ascending numerical order of @a
 *                 priority from #PURPLE_SIGNAL_PRIORITY_LOWEST to
 *                 #PURPLE_SIGNAL_PRIORITY_HIGHEST.
 *
 * @return The signal handler ID.
 *
 * @see purple_signal_disconnect()
 */
gulong purple_signal_connect_priority(void *instance, const char *signal,
	void *handle, PurpleCallback func, void *data, int priority);

/**
 * Connects a signal handler to a signal for a particular object.
 * (Its priority defaults to 0, aka #PURPLE_SIGNAL_PRIORITY_DEFAULT.)
 *
 * Take care not to register a handler function twice. Purple will
 * not correct any mistakes for you in this area.
 *
 * @param instance The instance to connect to.
 * @param signal   The name of the signal to connect.
 * @param handle   The handle of the receiver.
 * @param func     The callback function.
 * @param data     The data to pass to the callback function.
 *
 * @return The signal handler ID.
 *
 * @see purple_signal_disconnect()
 */
gulong purple_signal_connect(void *instance, const char *signal,
	void *handle, PurpleCallback func, void *data);

/**
 * Connects a signal handler to a signal for a particular object.
 *
 * The signal handler will take a va_args of arguments, instead of
 * individual arguments.
 *
 * Take care not to register a handler function twice. Purple will
 * not correct any mistakes for you in this area.
 *
 * @param instance The instance to connect to.
 * @param signal   The name of the signal to connect.
 * @param handle   The handle of the receiver.
 * @param func     The callback function.
 * @param data     The data to pass to the callback function.
 * @param priority The priority with which the handler should be called. Signal
 *                 handlers are called in ascending numerical order of @a
 *                 priority from #PURPLE_SIGNAL_PRIORITY_LOWEST to
 *                 #PURPLE_SIGNAL_PRIORITY_HIGHEST.
 *
 * @return The signal handler ID.
 *
 * @see purple_signal_disconnect()
 */
gulong purple_signal_connect_priority_vargs(void *instance, const char *signal,
	void *handle, PurpleCallback func, void *data, int priority);

/**
 * Connects a signal handler to a signal for a particular object.
 * (Its priority defaults to 0, aka #PURPLE_SIGNAL_PRIORITY_DEFAULT.)
 *
 * The signal handler will take a va_args of arguments, instead of
 * individual arguments.
 *
 * Take care not to register a handler function twice. Purple will
 * not correct any mistakes for you in this area.
 *
 * @param instance The instance to connect to.
 * @param signal   The name of the signal to connect.
 * @param handle   The handle of the receiver.
 * @param func     The callback function.
 * @param data     The data to pass to the callback function.
 *
 * @return The signal handler ID.
 *
 * @see purple_signal_disconnect()
 */
gulong purple_signal_connect_vargs(void *instance, const char *signal,
	void *handle, PurpleCallback func, void *data);

/**
 * Disconnects a signal handler from a signal on an object.
 *
 * @param instance The instance to disconnect from.
 * @param signal   The name of the signal to disconnect.
 * @param handle   The handle of the receiver.
 * @param func     The registered function to disconnect.
 *
 * @see purple_signal_connect()
 */
void purple_signal_disconnect(void *instance, const char *signal,
							void *handle, PurpleCallback func);

/**
 * Removes all callbacks associated with a receiver handle.
 *
 * @param handle The receiver handle.
 */
void purple_signals_disconnect_by_handle(void *handle);

/**
 * Emits a signal.
 *
 * @param instance The instance emitting the signal.
 * @param signal   The signal being emitted.
 *
 * @see purple_signal_connect()
 * @see purple_signal_disconnect()
 */
void purple_signal_emit(void *instance, const char *signal, ...);

/**
 * Emits a signal, using a va_list of arguments.
 *
 * @param instance The instance emitting the signal.
 * @param signal   The signal being emitted.
 * @param args     The arguments list.
 *
 * @see purple_signal_connect()
 * @see purple_signal_disconnect()
 */
void purple_signal_emit_vargs(void *instance, const char *signal, va_list args);

/**
 * Emits a signal and returns the first non-NULL return value.
 *
 * Further signal handlers are NOT called after a handler returns
 * something other than NULL.
 *
 * @param instance The instance emitting the signal.
 * @param signal   The signal being emitted.
 *
 * @return The first non-NULL return value
 */
void *purple_signal_emit_return_1(void *instance, const char *signal, ...);

/**
 * Emits a signal and returns the first non-NULL return value.
 *
 * Further signal handlers are NOT called after a handler returns
 * something other than NULL.
 *
 * @param instance The instance emitting the signal.
 * @param signal   The signal being emitted.
 * @param args     The arguments list.
 *
 * @return The first non-NULL return value
 */
void *purple_signal_emit_vargs_return_1(void *instance, const char *signal,
									  va_list args);

/**
 * Initializes the signals subsystem.
 */
void purple_signals_init(void);

/**
 * Uninitializes the signals subsystem.
 */
void purple_signals_uninit(void);

/*@}*/

/**************************************************************************/
/** @name Marshal Functions                                               */
/**************************************************************************/
/*@{*/

void purple_marshal_VOID(
		PurpleCallback cb, va_list args, void *data, void **return_val);
void purple_marshal_VOID__INT(
		PurpleCallback cb, va_list args, void *data, void **return_val);
void purple_marshal_VOID__INT_INT(
		PurpleCallback cb, va_list args, void *data, void **return_val);
void purple_marshal_VOID__POINTER(
		PurpleCallback cb, va_list args, void *data, void **return_val);
void purple_marshal_VOID__POINTER_UINT(
		PurpleCallback cb, va_list args, void *data, void **return_val);
void purple_marshal_VOID__POINTER_INT_INT(
		PurpleCallback cb, va_list args, void *data, void **return_val);
void purple_marshal_VOID__POINTER_INT_POINTER(
		PurpleCallback cb, va_list args, void *data, void **return_val);
void purple_marshal_VOID__POINTER_POINTER(
		PurpleCallback cb, va_list args, void *data, void **return_val);
void purple_marshal_VOID__POINTER_POINTER_UINT(
		PurpleCallback cb, va_list args, void *data, void **return_val);
void purple_marshal_VOID__POINTER_POINTER_UINT_UINT(
		PurpleCallback cb, va_list args, void *data, void **return_val);
void purple_marshal_VOID__POINTER_POINTER_POINTER(
		PurpleCallback cb, va_list args, void *data, void **return_val);
void purple_marshal_VOID__POINTER_POINTER_POINTER_POINTER(
		PurpleCallback cb, va_list args, void *data, void **return_val);
void purple_marshal_VOID__POINTER_POINTER_POINTER_POINTER_POINTER(
		PurpleCallback cb, va_list args, void *data, void **return_val);
void purple_marshal_VOID__POINTER_POINTER_POINTER_UINT(
		PurpleCallback cb, va_list args, void *data, void **return_val);
void purple_marshal_VOID__POINTER_POINTER_POINTER_POINTER_UINT(
		PurpleCallback cb, va_list args, void *data, void **return_val);
void purple_marshal_VOID__POINTER_POINTER_POINTER_UINT_UINT(
		PurpleCallback cb, va_list args, void *data, void **return_val);

void purple_marshal_INT__INT(
		PurpleCallback cb, va_list args, void *data, void **return_val);
void purple_marshal_INT__INT_INT(
		PurpleCallback cb, va_list args, void *data, void **return_val);
void purple_marshal_INT__POINTER_POINTER(
		PurpleCallback cb, va_list args, void *data, void **return_val);
void purple_marshal_INT__POINTER_POINTER_POINTER_POINTER_POINTER(
		PurpleCallback cb, va_list args, void *data, void **return_val);

void purple_marshal_BOOLEAN__POINTER(
		PurpleCallback cb, va_list args, void *data, void **return_val);
void purple_marshal_BOOLEAN__POINTER_POINTER(
		PurpleCallback cb, va_list args, void *data, void **return_val);
void purple_marshal_BOOLEAN__POINTER_POINTER_POINTER(
		PurpleCallback cb, va_list args, void *data, void **return_val);
void purple_marshal_BOOLEAN__POINTER_POINTER_UINT(
		PurpleCallback cb, va_list args, void *data, void **return_val);
void purple_marshal_BOOLEAN__POINTER_POINTER_POINTER_UINT(
		PurpleCallback cb, va_list args, void *data, void **return_val);
void purple_marshal_BOOLEAN__POINTER_POINTER_POINTER_POINTER(
		PurpleCallback cb, va_list args, void *data, void **return_val);
void purple_marshal_BOOLEAN__POINTER_POINTER_POINTER_POINTER_POINTER(
		PurpleCallback cb, va_list args, void *data, void **return_val);
void purple_marshal_BOOLEAN__POINTER_POINTER_POINTER_POINTER_UINT(
		PurpleCallback cb, va_list args, void *data, void **return_val);

void purple_marshal_BOOLEAN__INT_POINTER(
		PurpleCallback cb, va_list args, void *data, void **return_val);

void purple_marshal_POINTER__POINTER_INT(
		PurpleCallback cb, va_list args, void *data, void **return_val);
void purple_marshal_POINTER__POINTER_INT64(
		PurpleCallback cb, va_list args, void *data, void **return_val);
void purple_marshal_POINTER__POINTER_INT_BOOLEAN(
		PurpleCallback cb, va_list args, void *data, void **return_val);
void purple_marshal_POINTER__POINTER_INT64_BOOLEAN(
		PurpleCallback cb, va_list args, void *data, void **return_val);
void purple_marshal_POINTER__POINTER_POINTER(
		PurpleCallback cb, va_list args, void *data, void **return_val);
/*@}*/

#ifdef __cplusplus
}
#endif

#endif /* _PURPLE_SIGNALS_H_ */