/srv/mercurial-server/detachablepurple: c1b2f0310eeb: The object...

Gilles Bedel gillux at cpw.pidgin.im
Fri Jun 15 22:01:43 EDT 2012


Changeset: c1b2f0310eeb0bd8a4b8934ad452f2ba52b95594
Author:	 Gilles Bedel <gillux at cpw.pidgin.im>
Date:	 2012-05-20 15:22 +0000
Branch:	 cpw.gillux.detachablepurple
URL: http://hg.pidgin.im/srv/mercurial-server/detachablepurple/rev/c1b2f0310eeb

Description:

The object loading function now uses the GType instead of the type name.
This way, we ensure the type initialization function has been called before
we try to instatiate a new object of this type. We can't get a GType from
a type name that havn't been registered.

diffstat:

 libpurple/dbus/constructor.c |  28 +++++++++++++---------------
 1 files changed, 13 insertions(+), 15 deletions(-)

diffs (110 lines):

diff --git a/libpurple/dbus/constructor.c b/libpurple/dbus/constructor.c
--- a/libpurple/dbus/constructor.c
+++ b/libpurple/dbus/constructor.c
@@ -136,13 +136,12 @@
 	return klass->instance;
 }
 
-/* Creates a new proxy gobject of type_name, initializing its properties with
- * what's in props.
+/* Creates a new proxy gobject of the given type, initializing its properties
+ * with what's in props.
  */
 static gpointer
-purple_constructor_new_proxy_object(const gchar *type_name, GVariant *props)
+purple_constructor_new_proxy_object(GType type, GVariant *props)
 {
-	GType type;
 	GParameter *params;
 	guint n_params, i = 0;
 	GVariantIter iter;
@@ -153,9 +152,6 @@
 	GObjectClass *class;
 	GParamSpec *pspec;
 
-	/* Retreive the type and its class. */
-	type = g_type_from_name(type_name);
-	g_return_val_if_fail(type != 0, NULL);
 	class = g_type_class_ref(type);
 
 	/* Parse the given properties and build the parmas array. */
@@ -170,7 +166,7 @@
 			purple_dbus_gvariant_to_gvalue(prop_value, &params[i].value,
 			                               G_PARAM_SPEC_VALUE_TYPE(pspec));
 		else
-			purple_debug_warning("dbus", "Ignored an unknown property named '%s' for object type '%s'.\n", prop_name, type_name);
+			purple_debug_warning("dbus", "Ignored an unknown property named '%s' for object type '%s'.\n", prop_name, g_type_name(type));
 		i++;
 
 		g_variant_unref(prop_value);
@@ -252,7 +248,7 @@
 }
 
 static gpointer
-load_pobject(GVariant *vpobject, const char *type_name)
+load_pobject(GVariant *vpobject, GType type)
 {
 	PurpleObject *pobject;
 	gpointer *obj;
@@ -261,8 +257,7 @@
 
 	g_variant_get(vpobject, "(o at a(sv))", &dbus_path, &props);
 
-	obj = purple_constructor_new_proxy_object(type_name, props);
-
+	obj = purple_constructor_new_proxy_object(type, props);
 	pobject = PURPLE_OBJECT(obj);
 	purple_object_set_dbus_path(pobject, dbus_path);
 	/* Note: we are in remote mode so the 2nd parameter doesn't matter. */
@@ -275,7 +270,7 @@
 }
 
 static void
-load_pobjects(GVariant *box, const char *type_name)
+load_pobjects(GVariant *box, GType type)
 {
 	GVariantIter iter;
 	GVariant *array, *pobject;
@@ -285,7 +280,7 @@
 
 	g_variant_iter_init(&iter, array);
 	while ((pobject = g_variant_iter_next_value(&iter)) != NULL) {
-		obj = load_pobject(pobject, type_name);
+		obj = load_pobject(pobject, type);
 		purple_object_set_synchronized(PURPLE_OBJECT(obj), TRUE);
 		g_variant_unref(pobject);
 	}
@@ -315,7 +310,7 @@
 }
 
 static void
-purple_constructor_load_all_pobj(const char *method, const char *type)
+purple_constructor_load_all_pobj(const char *method, GType type)
 {
 	PurpleConstructor* con = purple_constructor_get_instance();
 	GVariant *ret;
@@ -332,7 +327,7 @@
 void
 purple_accounts_get_all_RPC(void)
 {
-	purple_constructor_load_all_pobj("GetAllAccounts", "PurpleAccount");
+	purple_constructor_load_all_pobj("GetAllAccounts", PURPLE_TYPE_ACCOUNT);
 }
 
 void
@@ -356,12 +351,15 @@
                                 const gchar *type_name, const gchar *dbus_path,
                                 GVariant *props)
 {
+	GType type;
 	gpointer *obj;
 
 	/* If we are the one who created this object, we already have it. */
 	if (purple_dbus_get_gobject_by_path(dbus_path))
 		return;
 
+	type = g_type_from_name(type_name);
+	g_return_if_fail(type != 0);
 	obj = purple_constructor_new_proxy_object(type, props);
 	g_variant_unref(props);
 



More information about the Commits mailing list