/soc/2013/ankitkv/gobjectification: 6868ad1739a3: Refactored dbu...

Ankit Vani a at nevitus.org
Thu Jul 18 17:22:05 EDT 2013


Changeset: 6868ad1739a3753c56bad2c921a71212c2fe29a4
Author:	 Ankit Vani <a at nevitus.org>
Date:	 2013-07-19 02:51 +0530
Branch:	 soc.2013.gobjectification
URL: https://hg.pidgin.im/soc/2013/ankitkv/gobjectification/rev/6868ad1739a3

Description:

Refactored dbus-server, signals, sound, status to use GType and GValue instead of PurpleValue

diffstat:

 libpurple/dbus-server.c |  67 +++++++++++++++++++----------------
 libpurple/signals.c     |  51 ++++++++++----------------
 libpurple/sound.c       |   5 +--
 libpurple/status.c      |  92 ++++++++++++++++++++++++------------------------
 4 files changed, 103 insertions(+), 112 deletions(-)

diffs (truncated from 591 to 300 lines):

diff --git a/libpurple/dbus-server.c b/libpurple/dbus-server.c
--- a/libpurple/dbus-server.c
+++ b/libpurple/dbus-server.c
@@ -629,13 +629,11 @@ purple_dbus_dispatch_init(void)
 
 	purple_signal_register(purple_dbus_get_handle(), "dbus-method-called",
 			 purple_marshal_BOOLEAN__POINTER_POINTER,
-			 purple_value_new(PURPLE_TYPE_BOOLEAN), 2,
-			 purple_value_new(PURPLE_TYPE_POINTER),
-			 purple_value_new(PURPLE_TYPE_POINTER));
+			 G_TYPE_BOOLEAN, 2, G_TYPE_POINTER, G_TYPE_POINTER);
 
 	purple_signal_register(purple_dbus_get_handle(), "dbus-introspect",
-			 purple_marshal_VOID__POINTER, NULL, 1,
-			 purple_value_new_outgoing(PURPLE_TYPE_POINTER));
+			 purple_marshal_VOID__POINTER, G_TYPE_NONE, 1,
+			 G_TYPE_POINTER); /* pointer to a pointer */
 
 	PURPLE_DBUS_REGISTER_BINDINGS(purple_dbus_get_handle());
 }
@@ -675,7 +673,7 @@ purple_dbus_convert_signal_name(const ch
 
 static gboolean
 purple_dbus_message_append_purple_values(DBusMessageIter *iter,
-		int number, PurpleValue **purple_values, va_list data)
+		int number, GType *types, va_list data)
 {
 	int i;
 	gboolean error = FALSE;
@@ -691,37 +689,36 @@ purple_dbus_message_append_purple_values
 		gboolean xboolean;
 		gpointer ptr = NULL;
 		gpointer val;
-
+#if 0
 		if (purple_value_is_outgoing(purple_values[i]))
 		{
 			ptr = my_arg(gpointer);
 			g_return_val_if_fail(ptr, TRUE);
 		}
-
-		switch (purple_value_get_type(purple_values[i]))
+#endif
+		switch (types[i])
 		{
-		case PURPLE_TYPE_INT:
-		case PURPLE_TYPE_ENUM:
+		case G_TYPE_INT:
 			xint = my_arg(gint);
 			dbus_message_iter_append_basic(iter, DBUS_TYPE_INT32, &xint);
 			break;
-		case PURPLE_TYPE_UINT:
+		case G_TYPE_UINT:
 			xuint = my_arg(guint);
 			dbus_message_iter_append_basic(iter, DBUS_TYPE_UINT32, &xuint);
 			break;
-		case PURPLE_TYPE_INT64:
+		case G_TYPE_INT64:
 			xint64 = my_arg(gint64);
 			dbus_message_iter_append_basic(iter, DBUS_TYPE_INT64, &xint64);
 			break;
-		case PURPLE_TYPE_UINT64:
+		case G_TYPE_UINT64:
 			xuint64 = my_arg(guint64);
 			dbus_message_iter_append_basic(iter, DBUS_TYPE_UINT64, &xuint64);
 			break;
-		case PURPLE_TYPE_BOOLEAN:
+		case G_TYPE_BOOLEAN:
 			xboolean = my_arg(gboolean);
 			dbus_message_iter_append_basic(iter, DBUS_TYPE_BOOLEAN, &xboolean);
 			break;
-		case PURPLE_TYPE_STRING:
+		case G_TYPE_STRING:
 			str = null_to_empty(my_arg(char*));
 			if (!g_utf8_validate(str, -1, NULL)) {
 				gchar *tmp;
@@ -733,19 +730,27 @@ purple_dbus_message_append_purple_values
 				dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, &str);
 			}
 			break;
-		case PURPLE_TYPE_SUBTYPE: /* registered pointers only! */
-		case PURPLE_TYPE_POINTER:
-		case PURPLE_TYPE_OBJECT:
-		case PURPLE_TYPE_BOXED:
-			val = my_arg(gpointer);
-			id = purple_dbus_pointer_to_id(val);
-			if (id == 0 && val != NULL)
-				error = TRUE;      /* Some error happened. */
-			dbus_message_iter_append_basic(iter,
-					(sizeof(id) == sizeof(dbus_int32_t)) ? DBUS_TYPE_INT32 : DBUS_TYPE_INT64, &id);
-			break;
-		default: /* no conversion implemented */
-			g_return_val_if_reached(TRUE);
+		default:
+			if (G_TYPE_IS_OBJECT(types[i])  ||
+			    G_TYPE_IS_BOXED(types[i])   ||
+			    types[i] == G_TYPE_POINTER   )
+			{
+				val = my_arg(gpointer);
+				id = purple_dbus_pointer_to_id(val);
+				if (id == 0 && val != NULL)
+					error = TRUE;      /* Some error happened. */
+				dbus_message_iter_append_basic(iter,
+						(sizeof(id) == sizeof(dbus_int32_t)) ? DBUS_TYPE_INT32 : DBUS_TYPE_INT64, &id);
+			}
+			else if (G_TYPE_IS_ENUM(types[i]))
+			{
+				xint = my_arg(gint);
+				dbus_message_iter_append_basic(iter, DBUS_TYPE_INT32, &xint);
+			}
+			else  /* no conversion implemented */
+			{
+				g_return_val_if_reached(TRUE);
+			}
 		}
 	}
 	return error;
@@ -755,7 +760,7 @@ purple_dbus_message_append_purple_values
 
 void
 purple_dbus_signal_emit_purple(const char *name, int num_values,
-		PurpleValue **values, va_list vargs)
+		GType *types, va_list vargs)
 {
 	DBusMessage *signal;
 	DBusMessageIter iter;
@@ -782,7 +787,7 @@ purple_dbus_signal_emit_purple(const cha
 	signal = dbus_message_new_signal(DBUS_PATH_PURPLE, DBUS_INTERFACE_PURPLE, newname);
 	dbus_message_iter_init_append(signal, &iter);
 
-	if (purple_dbus_message_append_purple_values(&iter, num_values, values, vargs))
+	if (purple_dbus_message_append_purple_values(&iter, num_values, types, vargs))
 		if (purple_debug_is_verbose())
 			purple_debug_warning("dbus",
 				"The signal \"%s\" caused some dbus error."
diff --git a/libpurple/signals.c b/libpurple/signals.c
--- a/libpurple/signals.c
+++ b/libpurple/signals.c
@@ -50,8 +50,8 @@ typedef struct
 	PurpleSignalMarshalFunc marshal;
 
 	int num_values;
-	PurpleValue **values;
-	PurpleValue *ret_value;
+	GType *value_types;
+	GType ret_type;
 
 	GList *handlers;
 	size_t handler_count;
@@ -86,25 +86,14 @@ destroy_signal_data(PurpleSignalData *si
 	g_list_foreach(signal_data->handlers, (GFunc)g_free, NULL);
 	g_list_free(signal_data->handlers);
 
-	if (signal_data->values != NULL)
-	{
-		int i;
-
-		for (i = 0; i < signal_data->num_values; i++)
-			purple_value_destroy((PurpleValue *)signal_data->values[i]);
-
-		g_free(signal_data->values);
-	}
-
-	if (signal_data->ret_value != NULL)
-		purple_value_destroy(signal_data->ret_value);
+	g_free(signal_data->value_types);
 	g_free(signal_data);
 }
 
 gulong
 purple_signal_register(void *instance, const char *signal,
 					 PurpleSignalMarshalFunc marshal,
-					 PurpleValue *ret_value, int num_values, ...)
+					 GType ret_type, int num_values, ...)
 {
 	PurpleInstanceData *instance_data;
 	PurpleSignalData *signal_data;
@@ -135,19 +124,19 @@ purple_signal_register(void *instance, c
 	signal_data->id              = instance_data->next_signal_id;
 	signal_data->marshal         = marshal;
 	signal_data->next_handler_id = 1;
-	signal_data->ret_value       = ret_value;
+	signal_data->ret_type        = ret_type;
 	signal_data->num_values      = num_values;
 
 	if (num_values > 0)
 	{
 		int i;
 
-		signal_data->values = g_new0(PurpleValue *, num_values);
+		signal_data->value_types = g_new0(GType, num_values);
 
 		va_start(args, num_values);
 
 		for (i = 0; i < num_values; i++)
-			signal_data->values[i] = va_arg(args, PurpleValue *);
+			signal_data->value_types[i] = va_arg(args, GType);
 
 		va_end(args);
 	}
@@ -202,17 +191,17 @@ purple_signals_unregister_by_instance(vo
 }
 
 void
-purple_signal_get_values(void *instance, const char *signal,
-					   PurpleValue **ret_value,
-					   int *num_values, PurpleValue ***values)
+purple_signal_get_types(void *instance, const char *signal,
+					   GType *ret_type,
+					   int *num_values, GType **value_types)
 {
 	PurpleInstanceData *instance_data;
 	PurpleSignalData *signal_data;
 
-	g_return_if_fail(instance   != NULL);
-	g_return_if_fail(signal     != NULL);
-	g_return_if_fail(num_values != NULL);
-	g_return_if_fail(values     != NULL);
+	g_return_if_fail(instance    != NULL);
+	g_return_if_fail(signal      != NULL);
+	g_return_if_fail(num_values  != NULL);
+	g_return_if_fail(value_types != NULL);
 
 	/* Get the instance data */
 	instance_data =
@@ -226,11 +215,11 @@ purple_signal_get_values(void *instance,
 
 	g_return_if_fail(signal_data != NULL);
 
-	*num_values = signal_data->num_values;
-	*values     = signal_data->values;
+	*num_values  = signal_data->num_values;
+	*value_types = signal_data->value_types;
 
-	if (ret_value != NULL)
-		*ret_value = signal_data->ret_value;
+	if (ret_type != NULL)
+		*ret_type = signal_data->ret_type;
 }
 
 static gint handler_priority(void * a, void * b) {
@@ -487,7 +476,7 @@ purple_signal_emit_vargs(void *instance,
 
 #ifdef HAVE_DBUS
 	purple_dbus_signal_emit_purple(signal, signal_data->num_values,
-				   signal_data->values, args);
+				   signal_data->value_types, args);
 #endif	/* HAVE_DBUS */
 
 }
@@ -539,7 +528,7 @@ purple_signal_emit_vargs_return_1(void *
 #ifdef HAVE_DBUS
 	G_VA_COPY(tmp, args);
 	purple_dbus_signal_emit_purple(signal, signal_data->num_values,
-				   signal_data->values, tmp);
+				   signal_data->value_types, tmp);
 	va_end(tmp);
 #endif	/* HAVE_DBUS */
 
diff --git a/libpurple/sound.c b/libpurple/sound.c
--- a/libpurple/sound.c
+++ b/libpurple/sound.c
@@ -128,10 +128,7 @@ purple_sound_init()
 
 	purple_signal_register(handle, "playing-sound-event",
 	                     purple_marshal_BOOLEAN__INT_POINTER,
-	                     purple_value_new(PURPLE_TYPE_BOOLEAN), 2,
-	                     purple_value_new(PURPLE_TYPE_INT),
-	                     purple_value_new(PURPLE_TYPE_SUBTYPE,
-	                                    PURPLE_SUBTYPE_ACCOUNT));
+	                     G_TYPE_BOOLEAN, 2, G_TYPE_INT, PURPLE_TYPE_ACCOUNT);
 
 	purple_prefs_add_none("/purple/sound");
 	purple_prefs_add_int("/purple/sound/while_status", STATUS_AVAILABLE);
diff --git a/libpurple/status.c b/libpurple/status.c
--- a/libpurple/status.c
+++ b/libpurple/status.c
@@ -59,7 +59,7 @@ struct _PurpleStatusAttr
 {
 	char *id;
 	char *name;
-	PurpleValue *value_type;
+	GValue *value_type;
 };
 
 /**
@@ -114,7 +114,7 @@ struct _PurpleStatus
 	 * The current values of the attributes for this status.  The
 	 * key is a string containing the name of the attribute.  It is
 	 * a borrowed reference from the list of attrs in the
-	 * PurpleStatusType.  The value is a PurpleValue.
+	 * PurpleStatusType.  The value is a GValue.
 	 */
 	GHashTable *attr_values;
 };
@@ -259,7 +259,7 @@ purple_status_type_new(PurpleStatusPrimi
 
 static void
 status_type_add_attr(PurpleStatusType *status_type, const char *id,
-		const char *name, PurpleValue *value)



More information about the Commits mailing list