/soc/2013/ankitkv/gobjectification: 3335681d8109: Backed out cha...

Ankit Vani a at nevitus.org
Thu Oct 10 07:03:59 EDT 2013


Changeset: 3335681d810939355e0c88d8a0286413ad759a67
Author:	 Ankit Vani <a at nevitus.org>
Date:	 2013-10-10 16:31 +0530
Branch:	 soc.2013.gobjectification.signals
URL: https://hg.pidgin.im/soc/2013/ankitkv/gobjectification/rev/3335681d8109

Description:

Backed out changesets

diffstat:

 libpurple/signals.c |  1201 +++++++++++++++++++++++++++++++++++++++++++++-----
 libpurple/signals.h |   340 +++++++++++++-
 2 files changed, 1391 insertions(+), 150 deletions(-)

diffs (truncated from 1609 to 300 lines):

diff --git a/libpurple/signals.c b/libpurple/signals.c
--- a/libpurple/signals.c
+++ b/libpurple/signals.c
@@ -23,179 +23,1106 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111-1301  USA
  */
+#include "internal.h"
+
+#include "dbus-maybe.h"
+#include "debug.h"
 #include "signals.h"
 
-#include "debug.h"
+/* must include this to use G_VA_COPY */
+#include <string.h>
 
-/******************************************************************************
- * Structs
- *****************************************************************************/
-struct _PurpleSignalHandle {
-	guint signal_id;
-	gulong hook_id;
-};
+typedef struct
+{
+	void *instance;
 
-typedef struct {
-	GType type;
-	GCallback callback;
-	gpointer user_data;
-	GConnectFlags flags;
-	GQuark detail;
-	GType return_type;
+	GHashTable *signals;
+	size_t signal_count;
+
+	gulong next_signal_id;
+
+} PurpleInstanceData;
+
+typedef struct
+{
+	gulong id;
+
+	PurpleSignalMarshalFunc marshal;
+
+	int num_values;
+	GType *value_types;
+	GType ret_type;
+
+	GList *handlers;
+	size_t handler_count;
+
+	gulong next_handler_id;
 } PurpleSignalData;
 
-/******************************************************************************
- * Helpers
- *****************************************************************************/
-static gboolean
-purple_signal_emission_hook(GSignalInvocationHint *hint, guint n_params,
-							  const GValue *pvalues, gpointer data)
+typedef struct
 {
-	PurpleSignalData *sd = data;
-	GObject *obj = NULL;
-	gboolean swap = FALSE, after = FALSE;
-	GClosure *closure = NULL;
+	gulong id;
+	PurpleCallback cb;
+	void *handle;
+	void *data;
+	gboolean use_vargs;
+	int priority;
 
-	obj = g_value_get_object(pvalues);
+} PurpleSignalHandlerData;
 
-	if(!G_TYPE_CHECK_INSTANCE_TYPE(obj, sd->type))
-		return TRUE;
+static GHashTable *instance_table = NULL;
 
-	swap = (sd->flags & G_CONNECT_SWAPPED);
-	after = (sd->flags & G_CONNECT_AFTER);
+static void
+destroy_instance_data(PurpleInstanceData *instance_data)
+{
+	g_hash_table_destroy(instance_data->signals);
 
-	if(swap)
-		closure = g_cclosure_new_swap(sd->callback, sd->user_data, NULL);
-	else
-		closure = g_cclosure_new(sd->callback, sd->user_data, NULL);
+	g_free(instance_data);
+}
 
-	g_signal_connect_closure_by_id(obj, hint->signal_id, sd->detail, closure, after);
+static void
+destroy_signal_data(PurpleSignalData *signal_data)
+{
+	g_list_foreach(signal_data->handlers, (GFunc)g_free, NULL);
+	g_list_free(signal_data->handlers);
 
-	if(sd->return_type != G_TYPE_NONE) {
-		GValue ret;
+	g_free(signal_data->value_types);
+	g_free(signal_data);
+}
 
-		g_value_init(&ret, sd->return_type);
+gulong
+purple_signal_register(void *instance, const char *signal,
+					 PurpleSignalMarshalFunc marshal,
+					 GType ret_type, int num_values, ...)
+{
+	PurpleInstanceData *instance_data;
+	PurpleSignalData *signal_data;
+	va_list args;
 
-		g_closure_invoke(closure, &ret, n_params, pvalues, hint);
-	} else {
-		g_closure_invoke(closure, NULL, n_params, pvalues, hint);
+	g_return_val_if_fail(instance != NULL, 0);
+	g_return_val_if_fail(signal   != NULL, 0);
+	g_return_val_if_fail(marshal  != NULL, 0);
+
+	instance_data =
+		(PurpleInstanceData *)g_hash_table_lookup(instance_table, instance);
+
+	if (instance_data == NULL)
+	{
+		instance_data = g_new0(PurpleInstanceData, 1);
+
+		instance_data->instance = instance;
+		instance_data->next_signal_id = 1;
+
+		instance_data->signals =
+			g_hash_table_new_full(g_str_hash, g_str_equal, g_free,
+								  (GDestroyNotify)destroy_signal_data);
+
+		g_hash_table_insert(instance_table, instance, instance_data);
 	}
 
-	return TRUE;
-}
+	signal_data = g_new0(PurpleSignalData, 1);
+	signal_data->id              = instance_data->next_signal_id;
+	signal_data->marshal         = marshal;
+	signal_data->next_handler_id = 1;
+	signal_data->ret_type        = ret_type;
+	signal_data->num_values      = num_values;
 
-/******************************************************************************
- * PurpleSignal API
- *****************************************************************************/
-PurpleSignalHandle *
-purple_signal_connect_flags(GType type, const gchar *name,
-							  GConnectFlags flags,
-							  GCallback callback, gpointer data)
-{
-	PurpleSignalData *sd = NULL;
-	PurpleSignalHandle *handle = NULL;
-	GQuark detail = 0;
-	GSignalQuery query;
-	guint signal_id = 0;
-	gulong hook_id = 0;
-	gpointer *klass = NULL;
+	if (num_values > 0)
+	{
+		int i;
 
-	klass = g_type_class_ref(type);
+		signal_data->value_types = g_new0(GType, num_values);
 
-	if(!g_signal_parse_name(name, type, &signal_id, &detail, TRUE)) {
-		purple_debug_warning("signals",
-		                     "Failed to find information for signal '%s' on "
-		                     "type '%s'!\n",
-		                     name, g_type_name(type));
+		va_start(args, num_values);
 
+		for (i = 0; i < num_values; i++)
+			signal_data->value_types[i] = va_arg(args, GType);
 
-		g_type_class_unref(klass);
-
-		return NULL;
+		va_end(args);
 	}
 
-	g_signal_query(signal_id, &query);
+	g_hash_table_insert(instance_data->signals,
+						g_strdup(signal), signal_data);
 
-	if(query.signal_id == 0) {
-		purple_debug_warning("signals",
-		                     "Failed to query signal '%s' on type '%s'!\n",
-		                     name, g_type_name(type));
+	instance_data->next_signal_id++;
+	instance_data->signal_count++;
 
-		g_type_class_unref(klass);
-
-		return NULL;
-	}
-
-	sd = g_new(PurpleSignalData, 1);
-	sd->callback = callback;
-	sd->user_data = data;
-	sd->flags = 0;
-	sd->detail = detail;
-	sd->type = type;
-	sd->return_type = query.return_type;
-
-	hook_id = g_signal_add_emission_hook(signal_id, detail,
-										 purple_signal_emission_hook,
-										 sd, g_free);
-
-	g_type_class_unref(klass);
-
-	handle = purple_signal_handle_new(signal_id, hook_id);
-
-	return handle;
+	return signal_data->id;
 }
 
 void
-purple_signal_disconnect(PurpleSignalHandle *handle) {
-	g_return_if_fail(handle);
+purple_signal_unregister(void *instance, const char *signal)
+{
+	PurpleInstanceData *instance_data;
 
-	g_signal_remove_emission_hook(handle->signal_id, handle->hook_id);
+	g_return_if_fail(instance != NULL);
+	g_return_if_fail(signal   != NULL);
 
-	purple_signal_handle_free(handle);
-}
+	instance_data =
+		(PurpleInstanceData *)g_hash_table_lookup(instance_table, instance);
 
-/******************************************************************************
- * PurpleSignalHandle API
- *****************************************************************************/
-GType
-purple_signal_handle_get_type(void) {
-	static GType type = 0;
+	g_return_if_fail(instance_data != NULL);
 
-	if(G_UNLIKELY(type == 0)) {
-		type =
-			g_boxed_type_register_static("PurpleSignalHandle",
-										 (GBoxedCopyFunc)purple_signal_handle_copy,
-										 (GBoxedFreeFunc)purple_signal_handle_free);
+	g_hash_table_remove(instance_data->signals, signal);
 
+	instance_data->signal_count--;
+
+	if (instance_data->signal_count == 0)
+	{
+		/* Unregister the instance. */
+		g_hash_table_remove(instance_table, instance);
 	}
-
-	return type;
-}
-
-PurpleSignalHandle *
-purple_signal_handle_new(guint signal_id, gulong hook_id) {
-	PurpleSignalHandle *handle = NULL;
-
-	handle = g_new(PurpleSignalHandle, 1);
-
-	handle->signal_id = signal_id;
-	handle->hook_id = hook_id;
-
-	return handle;
-}
-
-PurpleSignalHandle *
-purple_signal_handle_copy(const PurpleSignalHandle *handle) {
-	PurpleSignalHandle *copy = NULL;
-
-	g_return_val_if_fail(handle, NULL);
-
-	copy = purple_signal_handle_new(handle->signal_id, handle->hook_id);
-
-	return copy;
 }
 
 void
-purple_signal_handle_free(PurpleSignalHandle *handle) {
-	g_free(handle);
+purple_signals_unregister_by_instance(void *instance)
+{
+	gboolean found;
+



More information about the Commits mailing list