Mercurial > pidgin
changeset 10656:9b223bf37ca0
[gaim-migrate @ 12186]
sf patch #1154788, from Will Gorman
I added two new functions to signal_handler.h which
allows one to specify priority when registering a signal
callback.
the functions are:
gulong gaim_signal_connect_priority(void *instance,
const char *signal, void *handle, GaimCallback func,
void *data, int priority);
and
gulong gaim_signal_connect_priority_vargs(void
*instance, const char *signal, void *handle,
GaimCallback func, void *data, int priority);
(thanks Gary for the suggestion)
This allows plugins to specify in what order their
callbacks get called.
committer: Tailor Script <tailor@pidgin.im>
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Sun, 06 Mar 2005 01:27:39 +0000 |
parents | 9699787f1c55 |
children | 3f7508b1531f |
files | src/signals.c src/signals.h |
diffstat | 2 files changed, 80 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/src/signals.c Sun Mar 06 00:57:42 2005 +0000 +++ b/src/signals.c Sun Mar 06 01:27:39 2005 +0000 @@ -66,6 +66,7 @@ void *handle; void *data; gboolean use_vargs; + int priority; } GaimSignalHandlerData; @@ -241,9 +242,17 @@ *ret_value = signal_data->ret_value; } +static gint handler_priority(void * a, void * b) { + GaimSignalHandlerData *ah = (GaimSignalHandlerData*)a; + GaimSignalHandlerData *bh = (GaimSignalHandlerData*)b; + if (ah->priority > bh->priority) return 1; + if (ah->priority < bh->priority) return -1; + return 0; +} + static gulong signal_connect_common(void *instance, const char *signal, void *handle, - GaimCallback func, void *data, gboolean use_vargs) + GaimCallback func, void *data, int priority, gboolean use_vargs) { GaimInstanceData *instance_data; GaimSignalData *signal_data; @@ -278,8 +287,9 @@ handler_data->handle = handle; handler_data->data = data; handler_data->use_vargs = use_vargs; - - signal_data->handlers = g_list_append(signal_data->handlers, handler_data); + handler_data->priority = priority; + + signal_data->handlers = g_list_insert_sorted(signal_data->handlers, handler_data, (GCompareFunc)handler_priority); signal_data->handler_count++; signal_data->next_handler_id++; @@ -287,17 +297,31 @@ } gulong +gaim_signal_connect_priority(void *instance, const char *signal, void *handle, + GaimCallback func, void *data, int priority) +{ + return signal_connect_common(instance, signal, handle, func, data, priority, FALSE); +} + +gulong gaim_signal_connect(void *instance, const char *signal, void *handle, GaimCallback func, void *data) { - return signal_connect_common(instance, signal, handle, func, data, FALSE); + return signal_connect_common(instance, signal, handle, func, data, GAIM_SIGNAL_PRIORITY_DEFAULT, FALSE); +} + +gulong +gaim_signal_connect_priority_vargs(void *instance, const char *signal, void *handle, + GaimCallback func, void *data, int priority) +{ + return signal_connect_common(instance, signal, handle, func, data, priority, TRUE); } gulong gaim_signal_connect_vargs(void *instance, const char *signal, void *handle, GaimCallback func, void *data) { - return signal_connect_common(instance, signal, handle, func, data, TRUE); + return signal_connect_common(instance, signal, handle, func, data, GAIM_SIGNAL_PRIORITY_DEFAULT, TRUE); } void
--- a/src/signals.h Sun Mar 06 00:57:42 2005 +0000 +++ b/src/signals.h Sun Mar 06 01:27:39 2005 +0000 @@ -44,6 +44,13 @@ /*@{*/ /** + * Signal Connect Priorities + */ +#define GAIM_SIGNAL_PRIORITY_DEFAULT 0 +#define GAIM_SIGNAL_PRIORITY_HIGHEST 9999 +#define GAIM_SIGNAL_PRIORITY_LOWEST -9999 + +/** * Registers a signal in an instance. * * @param instance The instance to register the signal for. @@ -101,6 +108,27 @@ * @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 order in which the signal should be added to the list + * + * @return The signal handler ID. + * + * @see gaim_signal_disconnect() + */ +gulong gaim_signal_connect_priority(void *instance, const char *signal, + void *handle, GaimCallback func, void *data, int priority); + +/** + * Connects a signal handler to a signal for a particular object. + * (priority defaults to 0) + * + * Take care not to register a handler function twice. Gaim 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. * @@ -123,6 +151,29 @@ * @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 order in which the signal should be added to the list + * + * @return The signal handler ID. + * + * @see gaim_signal_disconnect() + */ +gulong gaim_signal_connect_priority_vargs(void *instance, const char *signal, + void *handle, GaimCallback func, void *data, int priority); + +/** + * Connects a signal handler to a signal for a particular object. + * (priority defaults to 0) + * The signal handler will take a va_args of arguments, instead of + * individual arguments. + * + * Take care not to register a handler function twice. Gaim 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. *