changeset 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 e34907332e46
children d01ba50e3f3e
files src/signals.c
diffstat 1 files changed, 42 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/src/signals.c	Thu Aug 21 03:43:03 2003 +0000
+++ b/src/signals.c	Thu Aug 21 07:37:30 2003 +0000
@@ -55,6 +55,7 @@
 	GaimCallback cb;
 	void *handle;
 	void *data;
+	gboolean use_vargs;
 
 } GaimSignalHandlerData;
 
@@ -168,9 +169,9 @@
 	g_return_if_fail(found);
 }
 
-gulong
-gaim_signal_connect(void *instance, const char *signal, void *handle,
-					GaimCallback func, void *data)
+static gulong
+signal_connect_common(void *instance, const char *signal, void *handle,
+					  GaimCallback func, void *data, gboolean use_vargs)
 {
 	GaimInstanceData *instance_data;
 	GaimSignalData *signal_data;
@@ -200,10 +201,11 @@
 
 	/* Create the signal handler data */
 	handler_data = g_new0(GaimSignalHandlerData, 1);
-	handler_data->id     = signal_data->next_handler_id;
-	handler_data->cb     = func;
-	handler_data->handle = handle;
-	handler_data->data   = data;
+	handler_data->id        = signal_data->next_handler_id;
+	handler_data->cb        = func;
+	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);
 	signal_data->handler_count++;
@@ -211,6 +213,19 @@
 
 	return handler_data->id;
 }
+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);
+}
+
+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);
+}
 
 void
 gaim_signal_disconnect(void *instance, const char *signal,
@@ -352,7 +367,16 @@
 	{
 		handler_data = (GaimSignalHandlerData *)l->data;
 
-		signal_data->marshal(handler_data->cb, args, handler_data->data, NULL);
+		if (handler_data->use_vargs)
+		{
+			((void (*)(va_list, void *))handler_data->cb)(args,
+														  handler_data->data);
+		}
+		else
+		{
+			signal_data->marshal(handler_data->cb, args,
+								 handler_data->data, NULL);
+		}
 	}
 }
 
@@ -401,8 +425,16 @@
 	{
 		handler_data = (GaimSignalHandlerData *)l->data;
 
-		signal_data->marshal(handler_data->cb, args, handler_data->data,
-							 &ret_val);
+		if (handler_data->use_vargs)
+		{
+			ret_val = ((void *(*)(va_list, void *))handler_data->cb)(
+				args, handler_data->data);
+		}
+		else
+		{
+			signal_data->marshal(handler_data->cb, args,
+								 handler_data->data, &ret_val);
+		}
 	}
 
 	return ret_val;