soc.2010.detachablepurple: ff15f05c: Added a new useful method to PurpleObjec...
gillux at soc.pidgin.im
gillux at soc.pidgin.im
Fri Jul 16 01:17:14 EDT 2010
----------------------------------------------------------------------
Revision: ff15f05ccda09f08db6f7a9f20630d55c4115994
Parent: f5b068e4d8213c2bf3d41286aedb45081232ee65
Author: gillux at soc.pidgin.im
Date: 07/15/10 23:07:25
Branch: im.pidgin.soc.2010.detachablepurple
URL: http://d.pidgin.im/viewmtn/revision/info/ff15f05ccda09f08db6f7a9f20630d55c4115994
Changelog:
Added a new useful method to PurpleObject, which setup its dbus informations
correctly, depending on the current running state (daemon or client).
Also updated a function doc which talked about the old "dummy gobjects" system.
Changes against parent f5b068e4d8213c2bf3d41286aedb45081232ee65
patched libpurple/pobject.c
patched libpurple/pobject.h
-------------- next part --------------
============================================================
--- libpurple/pobject.c e24eb2eb009b9e9445e29a612ce55c4cf9cd4dab
+++ libpurple/pobject.c 3d03250f3176a328e6f5cdbd9db2c22f0571ea03
@@ -18,8 +18,17 @@
* 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 "core.h"
+#include "dbus-maybe.h"
#include "pobject.h"
+#ifdef HAVE_DBUS
+/* Provides DBUS_SERVICE_DBUS etc. */
+# include <dbus/dbus-glib-bindings.h>
+#endif
+
#define PURPLE_OBJECT_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), PURPLE_TYPE_OBJECT, PurpleObjectPrivate))
typedef struct _PurpleObjectPrivate PurpleObjectPrivate;
@@ -226,16 +235,6 @@ purple_object_get_dbus_obj_proxy(PurpleO
return priv->dbus_obj_proxy;
}
-void
-purple_object_set_dbus_obj_proxy(PurpleObject *pobj, gpointer dbus_proxy)
-{
- PurpleObjectPrivate *priv;
-
- g_return_if_fail(pobj);
- priv = PURPLE_OBJECT_GET_PRIVATE(pobj);
- priv->dbus_obj_proxy = dbus_proxy;
-}
-
gpointer
purple_object_get_dbus_props_proxy(PurpleObject *pobj)
{
@@ -246,34 +245,67 @@ purple_object_get_dbus_props_proxy(Purpl
return priv->dbus_props_proxy;
}
-void
-purple_object_set_dbus_props_proxy(PurpleObject *pobj, gpointer dbus_proxy)
+char*
+purple_object_get_dbus_path(PurpleObject *pobj)
{
PurpleObjectPrivate *priv;
- g_return_if_fail(pobj);
+ g_return_val_if_fail(pobj, NULL);
priv = PURPLE_OBJECT_GET_PRIVATE(pobj);
- priv->dbus_props_proxy = dbus_proxy;
+ return priv->dbus_path;
}
-char*
-purple_object_get_dbus_path(PurpleObject *pobj)
+void
+purple_object_set_dbus_path(PurpleObject *pobj, char* path)
{
PurpleObjectPrivate *priv;
- g_return_val_if_fail(pobj, NULL);
+ g_return_if_fail(pobj);
priv = PURPLE_OBJECT_GET_PRIVATE(pobj);
- return priv->dbus_path;
+ priv->dbus_path = g_strdup(path);
}
void
-purple_object_set_dbus_path(PurpleObject *pobj, char* path)
+purple_object_install_dbus_infos(PurpleObject *pobj, char *dbus_interface, char *dbus_path)
{
+#ifdef HAVE_DBUS
+ DBusGProxy* dbus_proxy;
PurpleObjectPrivate *priv;
g_return_if_fail(pobj);
priv = PURPLE_OBJECT_GET_PRIVATE(pobj);
- priv->dbus_path = g_strdup(path);
+
+ if (purple_core_is_remote_mode()) {
+ /* One for the org.freedesktop.DBus.Properties interface */
+ dbus_proxy = dbus_g_proxy_new_for_name(
+ purple_dbus_get_g_connection(),
+ DBUS_PURPLE_SERVICE, dbus_path,
+ DBUS_INTERFACE_PROPERTIES);
+ priv->dbus_props_proxy = dbus_proxy;
+
+ /* One for the provided interface */
+ dbus_proxy = dbus_g_proxy_new_for_name(
+ purple_dbus_get_g_connection(),
+ DBUS_PURPLE_SERVICE, dbus_path,
+ dbus_interface);
+ priv->dbus_obj_proxy = dbus_proxy;
+
+ /* Remember the purple interface */
+ purple_object_set_dbus_obj_interface(pobj, dbus_interface);
+ }
+ else if (purple_core_is_daemon_mode()) {
+ /* Register our object as at dbus_path */
+ dbus_g_connection_register_g_object(
+ purple_dbus_get_g_connection(),
+ dbus_path, G_OBJECT(pobj));
+
+ /* Remember the dbus path we expose our object at */
+ purple_object_set_dbus_path(pobj, dbus_path);
+
+ /* Remember the purple interface */
+ purple_object_set_dbus_obj_interface(pobj, dbus_interface);
+ }
+#endif
}
int purple_object_get_int(PurpleObject *pobj, const char *prop)
============================================================
--- libpurple/pobject.h 0de346cd8149a73652e4b3045382129d77e56208
+++ libpurple/pobject.h c43032d7d789f4d43c5d500346c098e66b4682ac
@@ -61,8 +61,10 @@ gpointer purple_object_get_ui_data(Purpl
/**
* Gets the dbus proxy. This is used in detachable sessions context only.
- * When a client is in remote mode, the gobjects it creates are dummy ones
- * and only hold a dbus proxy, which is a kind of mirror of the remote object.
+ * When a client is in remote mode, the gobjects it creates are kind of mirrors
+ * of the remote object. They hold 2 dbus proxies and the last know state of
+ * the gobject properties. The proxy returned by this function is the one for
+ * the PurpleStuff object, such as im.pidgin.purple.account for PurpleAccount.
*
* We use a gpointer here but we mean a DBusDProxy. It is to avoid to include
* dbus everywhere pobject.h is included.
@@ -89,22 +91,26 @@ void purple_object_set_dbus_obj_interfac
*/
void purple_object_set_dbus_obj_interface(PurpleObject *pobj, char* interface);
+#ifdef HAVE_DBUS
+
/**
- * Sets the dbus proxy. This is used in detachable sessions context only.
- *
- * We use a gpointer here but we mean a DBusDProxy. It is to avoid to include
- * dbus everywhere pobject.h is included.
- *
- * @param pobj The PurpleObject.
- * @param dbus_proxy The DBusGProxy associated with pobj.
+ * Convenience function to install the dbus proxies, the dbus path and the
+ * interface name in a PurpleObject. Depending on the running state of purple
+ * (given by purple_core_get_running_mode()), this function will install the
+ * appropriate informations.
*/
-void purple_object_set_dbus_obj_proxy(PurpleObject *pobj, gpointer dbus_proxy);
+void purple_object_install_dbus_infos(PurpleObject *pobj, char *dbus_interface, char *dbus_path);
-/**
- * The same for the org.freedesktop.DBus.Properties interface.
+#else /* !HAVE_DBUS */
+
+/* Giving this macro, on a system without dbus, a code such as :
+ * purple_object_install_dbus_infos(obj, get_interface(), build_path());
+ * wouldn't even run the get_interface() or build_path() functions.
*/
-void purple_object_set_dbus_props_proxy(PurpleObject *pobj, gpointer dbus_proxy);
+#define purple_object_install_dbus_infos(pobj, interface, path) ((void)0)
+#endif
+
/**
* Gets the dbus path associated with this PurpleObject.
* Each gobjects that are published on DBus have a path name (something like
More information about the Commits
mailing list