[Telepathy-commits] [telepathy-glib/master] _tp_dbus_daemon_get_name_owner: reimplement in raw libdbus

Simon McVittie simon.mcvittie at collabora.co.uk
Fri Jan 30 07:42:05 PST 2009


We don't want to create a DBusGProxy for the dbus-daemon if we
don't have to.
---
 telepathy-glib/dbus.c |   68 ++++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 56 insertions(+), 12 deletions(-)

diff --git a/telepathy-glib/dbus.c b/telepathy-glib/dbus.c
index 717a50b..c0cdfa0 100644
--- a/telepathy-glib/dbus.c
+++ b/telepathy-glib/dbus.c
@@ -973,18 +973,62 @@ _tp_dbus_daemon_get_name_owner (TpDBusDaemon *self,
                                 gchar **unique_name,
                                 GError **error)
 {
-  DBusGProxy *iface = tp_proxy_borrow_interface_by_id ((TpProxy *) self,
-      TP_IFACE_QUARK_DBUS_DAEMON, error);
-
-  if (iface == NULL)
-    return FALSE;
-
-  return dbus_g_proxy_call_with_timeout (iface, "GetNameOwner", timeout_ms,
-      error,
-      G_TYPE_STRING, well_known_name,
-      G_TYPE_INVALID,
-      G_TYPE_STRING, unique_name,
-      G_TYPE_INVALID);
+  DBusGConnection *gconn = tp_proxy_get_dbus_connection (self);
+  DBusConnection *dbc = dbus_g_connection_get_connection (gconn);
+  DBusMessage *message;
+  DBusMessage *reply;
+  DBusError dbus_error;
+  const char *name_in_reply;
+
+  message = dbus_message_new_method_call (DBUS_SERVICE_DBUS, DBUS_PATH_DBUS,
+      DBUS_INTERFACE_DBUS, "GetNameOwner");
+
+  if (message == NULL)
+    g_error ("Out of memory");
+
+  if (!dbus_message_append_args (message,
+        DBUS_TYPE_STRING, &well_known_name,
+        DBUS_TYPE_INVALID))
+    g_error ("Out of memory");
+
+  dbus_error_init (&dbus_error);
+  reply = dbus_connection_send_with_reply_and_block (dbc, message,
+      timeout_ms, &dbus_error);
+
+  dbus_message_unref (message);
+
+  if (reply == NULL)
+    {
+      if (!tp_strdiff (dbus_error.name, DBUS_ERROR_NO_MEMORY))
+        g_error ("Out of memory");
+
+      /* FIXME: ideally we'd use dbus-glib's error mapping for this */
+      g_set_error (error, TP_DBUS_ERRORS, TP_DBUS_ERROR_NAME_OWNER_LOST,
+          "%s: %s", dbus_error.name, dbus_error.message);
+
+      dbus_error_free (&dbus_error);
+      dbus_message_unref (reply);
+      return FALSE;
+    }
+
+  if (!dbus_message_get_args (reply, &dbus_error,
+        DBUS_TYPE_STRING, &name_in_reply,
+        DBUS_TYPE_INVALID))
+    {
+      g_set_error (error, TP_DBUS_ERRORS, TP_DBUS_ERROR_NAME_OWNER_LOST,
+          "%s: %s", dbus_error.name, dbus_error.message);
+
+      dbus_error_free (&dbus_error);
+      dbus_message_unref (reply);
+      return FALSE;
+    }
+
+  if (unique_name != NULL)
+    *unique_name = g_strdup (name_in_reply);
+
+  dbus_message_unref (reply);
+
+  return TRUE;
 }
 
 /**
-- 
1.5.6.5



More information about the telepathy-commits mailing list