Mercurial > pidgin
comparison src/signals.c @ 6547:adf168f002ad
[gaim-migrate @ 7069]
Added gaim_signal_connect_vargs(), which lets you setup a signal callback
function that takes a va_list instead of actual parameters. Useful for
loader plugins.
committer: Tailor Script <tailor@pidgin.im>
author | Christian Hammond <chipx86@chipx86.com> |
---|---|
date | Thu, 21 Aug 2003 07:37:30 +0000 |
parents | e74e378e86bf |
children | 9e4fa4853cfe |
comparison
equal
deleted
inserted
replaced
6546:e34907332e46 | 6547:adf168f002ad |
---|---|
53 { | 53 { |
54 gulong id; | 54 gulong id; |
55 GaimCallback cb; | 55 GaimCallback cb; |
56 void *handle; | 56 void *handle; |
57 void *data; | 57 void *data; |
58 gboolean use_vargs; | |
58 | 59 |
59 } GaimSignalHandlerData; | 60 } GaimSignalHandlerData; |
60 | 61 |
61 static GHashTable *instance_table = NULL; | 62 static GHashTable *instance_table = NULL; |
62 | 63 |
166 * things registering and unregistering in the right order :) | 167 * things registering and unregistering in the right order :) |
167 */ | 168 */ |
168 g_return_if_fail(found); | 169 g_return_if_fail(found); |
169 } | 170 } |
170 | 171 |
171 gulong | 172 static gulong |
172 gaim_signal_connect(void *instance, const char *signal, void *handle, | 173 signal_connect_common(void *instance, const char *signal, void *handle, |
173 GaimCallback func, void *data) | 174 GaimCallback func, void *data, gboolean use_vargs) |
174 { | 175 { |
175 GaimInstanceData *instance_data; | 176 GaimInstanceData *instance_data; |
176 GaimSignalData *signal_data; | 177 GaimSignalData *signal_data; |
177 GaimSignalHandlerData *handler_data; | 178 GaimSignalHandlerData *handler_data; |
178 | 179 |
198 return 0; | 199 return 0; |
199 } | 200 } |
200 | 201 |
201 /* Create the signal handler data */ | 202 /* Create the signal handler data */ |
202 handler_data = g_new0(GaimSignalHandlerData, 1); | 203 handler_data = g_new0(GaimSignalHandlerData, 1); |
203 handler_data->id = signal_data->next_handler_id; | 204 handler_data->id = signal_data->next_handler_id; |
204 handler_data->cb = func; | 205 handler_data->cb = func; |
205 handler_data->handle = handle; | 206 handler_data->handle = handle; |
206 handler_data->data = data; | 207 handler_data->data = data; |
208 handler_data->use_vargs = use_vargs; | |
207 | 209 |
208 signal_data->handlers = g_list_append(signal_data->handlers, handler_data); | 210 signal_data->handlers = g_list_append(signal_data->handlers, handler_data); |
209 signal_data->handler_count++; | 211 signal_data->handler_count++; |
210 signal_data->next_handler_id++; | 212 signal_data->next_handler_id++; |
211 | 213 |
212 return handler_data->id; | 214 return handler_data->id; |
215 } | |
216 gulong | |
217 gaim_signal_connect(void *instance, const char *signal, void *handle, | |
218 GaimCallback func, void *data) | |
219 { | |
220 return signal_connect_common(instance, signal, handle, func, data, FALSE); | |
221 } | |
222 | |
223 gulong | |
224 gaim_signal_connect_vargs(void *instance, const char *signal, void *handle, | |
225 GaimCallback func, void *data) | |
226 { | |
227 return signal_connect_common(instance, signal, handle, func, data, TRUE); | |
213 } | 228 } |
214 | 229 |
215 void | 230 void |
216 gaim_signal_disconnect(void *instance, const char *signal, | 231 gaim_signal_disconnect(void *instance, const char *signal, |
217 void *handle, GaimCallback func) | 232 void *handle, GaimCallback func) |
350 | 365 |
351 for (l = signal_data->handlers; l != NULL; l = l->next) | 366 for (l = signal_data->handlers; l != NULL; l = l->next) |
352 { | 367 { |
353 handler_data = (GaimSignalHandlerData *)l->data; | 368 handler_data = (GaimSignalHandlerData *)l->data; |
354 | 369 |
355 signal_data->marshal(handler_data->cb, args, handler_data->data, NULL); | 370 if (handler_data->use_vargs) |
371 { | |
372 ((void (*)(va_list, void *))handler_data->cb)(args, | |
373 handler_data->data); | |
374 } | |
375 else | |
376 { | |
377 signal_data->marshal(handler_data->cb, args, | |
378 handler_data->data, NULL); | |
379 } | |
356 } | 380 } |
357 } | 381 } |
358 | 382 |
359 void * | 383 void * |
360 gaim_signal_emit_return_1(void *instance, const char *signal, ...) | 384 gaim_signal_emit_return_1(void *instance, const char *signal, ...) |
399 | 423 |
400 for (l = signal_data->handlers; l != NULL; l = l->next) | 424 for (l = signal_data->handlers; l != NULL; l = l->next) |
401 { | 425 { |
402 handler_data = (GaimSignalHandlerData *)l->data; | 426 handler_data = (GaimSignalHandlerData *)l->data; |
403 | 427 |
404 signal_data->marshal(handler_data->cb, args, handler_data->data, | 428 if (handler_data->use_vargs) |
405 &ret_val); | 429 { |
430 ret_val = ((void *(*)(va_list, void *))handler_data->cb)( | |
431 args, handler_data->data); | |
432 } | |
433 else | |
434 { | |
435 signal_data->marshal(handler_data->cb, args, | |
436 handler_data->data, &ret_val); | |
437 } | |
406 } | 438 } |
407 | 439 |
408 return ret_val; | 440 return ret_val; |
409 } | 441 } |
410 | 442 |