soc.2010.detachablepurple: b971801e: Moved the function that grabs the export...

gillux at soc.pidgin.im gillux at soc.pidgin.im
Sat Jul 17 10:38:14 EDT 2010


----------------------------------------------------------------------
Revision: b971801e6e8d1c6ace4c6f43826e32548b57a709
Parent:   ec4a4481a9aac4127b9c8203d5616fb9de1e92a0
Author:   gillux at soc.pidgin.im
Date:     07/17/10 03:20:44
Branch:   im.pidgin.soc.2010.detachablepurple
URL: http://d.pidgin.im/viewmtn/revision/info/b971801e6e8d1c6ace4c6f43826e32548b57a709

Changelog: 

Moved the function that grabs the exported properties names from dbus-server.c
to pobject.c. Using a wrapper for the properties informations installation
dbus-glib function, we can now grab the dbus exported properties without
needing to put the "extern" declaration, as we did in dbus-constructor.c.

Changes against parent ec4a4481a9aac4127b9c8203d5616fb9de1e92a0

  patched  libpurple/dbus-server.c
  patched  libpurple/dbus-server.h
  patched  libpurple/pobject.c
  patched  libpurple/pobject.h

-------------- next part --------------
============================================================
--- libpurple/dbus-server.c	125eec1d615d95ec6d9c0322d2c2fd978c62ac64
+++ libpurple/dbus-server.c	0040b3f2484f13cd2a816f9a84b617c9e8f9732d
@@ -437,30 +437,6 @@ purple_dbus_remotely_set_obj_prop(Purple
 	}
 }
 
-GPtrArray*
-purple_dbus_get_gobj_props(char *interface, const DBusGObjectInfo *infos) {
-	GPtrArray *props_a = g_ptr_array_new();
-	char *props = (char*)infos->exported_properties;
-
-	while (*props) {
-		/* Only read properties that belongs to the correct interface */
-		if (!strcmp(interface, props)) {
-			/* Skip the interface name */
-			while (*(props++));
-			/* Pick the property name */
-			g_ptr_array_add(props_a, g_strdup(props));
-			/* Skip the property name */
-			while (*(props++));
-		} else {
-			/* Skip the interface and property name */
-			while (*(props++));
-			while (*(props++));
-		}
-	}
-
-	return props_a;
-}
-
 gchar*
 purple_dbus_sanitize_dbus_path(const gchar *str)
 {
============================================================
--- libpurple/dbus-server.h	a71515fa2ce59463ba9f91d994a22cf5055697c5
+++ libpurple/dbus-server.h	b21f17e59e986acebee1b146d9499eda91ed9e58
@@ -203,21 +203,6 @@ gboolean purple_dbus_remotely_set_obj_pr
 gboolean purple_dbus_remotely_set_obj_prop(PurpleObject* pobj, const char* prop_name, GValue* prop_value);
 
 /**
- * Grabs the properties of a gobject's DBusGObjectInfo that belong to the
- * specified interface. This should return what <property> tags were defined
- * in the dbus-prototype/<stuff>.xml, inside the matching <interface> block.
- * These properties are the ones we want to export through DBus. The
- * DBusGObjectInfo structs are usually automatically generated by
- *dbus-binding-tool and held in the dbus-*-server.h files.
- *
- * @param interface The interface the properties belong to.
- * @param infos The DBusGObjectInfo informations.
- *
- * @return An array of strings, the properties names.
- */
-GPtrArray* purple_dbus_get_gobj_props(char *interface, const DBusGObjectInfo *infos);
-
-/**
  * Sanitize a given string so that it can be used as a valid dbus path.
  * The dbus spec says it have to consist of [A-Za-z0-9_/] chars.
  * http://dbus.freedesktop.org/doc/dbus-specification.html#message-protocol-marshaling-object-path
============================================================
--- libpurple/pobject.c	3d03250f3176a328e6f5cdbd9db2c22f0571ea03
+++ libpurple/pobject.c	7d5c5928220e28d8a598cebd84699fcf5a7c7db2
@@ -308,6 +308,69 @@ purple_object_install_dbus_infos(PurpleO
 #endif	
 }
 
+static GQuark
+purple_object_type_dbus_metadata_quark(void)
+{
+  static GQuark quark;
+
+  if (!quark)
+    quark = g_quark_from_static_string("PurpleObjectTypeDBusMethods");
+  return quark;
+}
+
+/**
+ * A wrapper for dbus_g_object_type_install_info(), to let us catch these infos too.
+ *
+ * @param object_type GType for the object
+ * @param infos A DBusGObjectInfo pointer, this data is generated by dbus-binding-tool.
+ */
+#ifdef HAVE_DBUS
+void
+purple_object_type_install_dbus_infos(GType object_type, const DBusGObjectInfo *infos)
+{
+	GQuark quark = purple_object_type_dbus_metadata_quark();
+	const DBusGObjectInfo *dbus_infos = infos;
+
+	dbus_g_object_type_install_info(object_type, dbus_infos);
+
+	g_type_set_qdata(object_type, quark, (gpointer)infos);
+}
+#endif
+
+#ifdef HAVE_DBUS
+GPtrArray*
+purple_object_get_dbus_props(GType object_type, char *interface)
+{
+	GPtrArray *props_a;
+	char *props;
+	DBusGObjectInfo* infos;
+
+	props_a = g_ptr_array_new();
+	infos = g_type_get_qdata(object_type,
+				purple_object_type_dbus_metadata_quark());
+	g_return_val_if_fail(infos != NULL, NULL);
+
+	props = (char*)infos->exported_properties;
+	while (*props) {
+		/* Only read properties that belongs to the correct interface */
+		if (!strcmp(interface, props)) {
+			/* Skip the interface name */
+			while (*(props++));
+			/* Pick the property name */
+			g_ptr_array_add(props_a, g_strdup(props));
+			/* Skip the property name */
+			while (*(props++));
+		} else {
+			/* Skip the interface and property name */
+			while (*(props++));
+			while (*(props++));
+		}
+	}
+
+	return props_a;
+}
+#endif /* HAVE_DBUS */
+
 int purple_object_get_int(PurpleObject *pobj, const char *prop)
 {
 	int ret;
============================================================
--- libpurple/pobject.h	c43032d7d789f4d43c5d500346c098e66b4682ac
+++ libpurple/pobject.h	b912158bc42b63336d4eb42cde78a4a9f3a0a3c3
@@ -24,6 +24,10 @@
 #include <glib.h>
 #include <glib-object.h>
 
+#ifdef HAVE_DBUS
+#  include <dbus/dbus-glib-bindings.h>
+#endif
+
 #define PURPLE_TYPE_OBJECT              (purple_object_get_type())
 #define PURPLE_OBJECT(obj)              (G_TYPE_CHECK_INSTANCE_CAST((obj), PURPLE_TYPE_OBJECT, PurpleObject))
 #define PURPLE_OBJECT_CLASS(klass)      (G_TYPE_CHECK_CLASS_CAST((klass), PURPLE_TYPE_OBJECT, PurpleObjectClass))
@@ -101,6 +105,31 @@ void purple_object_install_dbus_infos(Pu
  */
 void purple_object_install_dbus_infos(PurpleObject *pobj, char *dbus_interface, char *dbus_path);
 
+/**
+ * A wrapper for dbus_g_object_type_install_info(), to let us catch these infos too.
+ * This is used to catch the properties we want to export through DBus.
+ * DBusGObjectInfo structs are usually automatically generated by
+ * dbus-binding-tool and held in the dbus-*-server.h files.
+ *
+ * @param object_type GType for the object
+ * @param infos A DBusGObjectInfo pointer, this data is generated by dbus-binding-tool.
+ */
+void purple_object_type_install_dbus_infos(GType object_type, const DBusGObjectInfo *infos);
+
+/**
+ * Grabs the dbus properties of a gobject's that belong to the specified
+ * interface. This should return what <property> tags were defined
+ * in the dbus-prototype/<stuff>.xml, inside the matching <interface> block.
+ * Caller must have previously called purple_object_type_install_dbus_infos()
+ * for this to work.
+ *
+ * @param object_type The object type the properties belong to.
+ * @param interface The interface the properties belong to.
+ *
+ * @return An array of strings, the properties names.
+ */
+GPtrArray* purple_object_get_dbus_props(GType object_type, char *interface);
+
 #else /* !HAVE_DBUS */
 
 /* Giving this macro, on a system without dbus, a code such as :
@@ -109,6 +138,10 @@ void purple_object_install_dbus_infos(Pu
  */
 #define purple_object_install_dbus_infos(pobj, interface, path) ((void)0)
 
+#define purple_object_type_install_dbus_infos(object_type, infos) ((void)0)
+
+#define purple_object_get_dbus_props(object_type, interface) (NULL)
+
 #endif
 
 /**


More information about the Commits mailing list