[next] telepathy-glib: _tp_dbus_daemon_get_name_owner: rewrite using GDBus

Simon McVittie smcv at kemper.freedesktop.org
Thu Mar 27 08:42:05 PDT 2014


Module: telepathy-glib
Branch: next
Commit: 13945ec8e54ae225cb9b5d776049b4c1f7eaa928
URL:    http://cgit.freedesktop.org/telepathy/telepathy-glib/commit/?id=13945ec8e54ae225cb9b5d776049b4c1f7eaa928

Author: Simon McVittie <simon.mcvittie at collabora.co.uk>
Date:   Tue Mar 11 18:21:14 2014 +0000

_tp_dbus_daemon_get_name_owner: rewrite using GDBus

Much simpler.

---

 telepathy-glib/dbus-daemon.c |   61 +++++++-----------------------------------
 1 file changed, 9 insertions(+), 52 deletions(-)

diff --git a/telepathy-glib/dbus-daemon.c b/telepathy-glib/dbus-daemon.c
index 31cc9cc..dc4e523 100644
--- a/telepathy-glib/dbus-daemon.c
+++ b/telepathy-glib/dbus-daemon.c
@@ -459,13 +459,8 @@ _tp_dbus_daemon_get_name_owner (TpDBusDaemon *self,
                                 gchar **unique_name,
                                 GError **error)
 {
-  DBusGConnection *gconn;
-  DBusConnection *dbc;
-  DBusMessage *message;
-  DBusMessage *reply;
-  DBusError dbus_error;
-  const char *name_in_reply;
   const GError *invalidated;
+  GVariant *tuple;
 
   g_return_val_if_fail (TP_IS_DBUS_DAEMON (self), FALSE);
   g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
@@ -480,56 +475,18 @@ _tp_dbus_daemon_get_name_owner (TpDBusDaemon *self,
       return FALSE;
     }
 
-  gconn = tp_proxy_get_dbus_connection (self);
-  dbc = dbus_g_connection_get_connection (gconn);
-
-  message = dbus_message_new_method_call (DBUS_SERVICE_DBUS, DBUS_PATH_DBUS,
-      DBUS_INTERFACE_DBUS, "GetNameOwner");
-
-  if (message == NULL)
-    ERROR ("Out of memory");
-
-  if (!dbus_message_append_args (message,
-        DBUS_TYPE_STRING, &well_known_name,
-        DBUS_TYPE_INVALID))
-    ERROR ("Out of memory");
+  tuple = g_dbus_connection_call_sync (tp_proxy_get_dbus_connection (self),
+      "org.freedesktop.DBus", "/org/freedesktop/DBus", "org.freedesktop.DBus",
+      "GetNameOwner", g_variant_new ("(s)", well_known_name),
+      G_VARIANT_TYPE ("(s)"), G_DBUS_CALL_FLAGS_NONE, -1, NULL, error);
 
-  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))
-        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);
-      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 (tuple == NULL)
+    return FALSE;
 
   if (unique_name != NULL)
-    *unique_name = g_strdup (name_in_reply);
-
-  dbus_message_unref (reply);
+    g_variant_get (tuple, "(s)", unique_name);
 
+  g_variant_unref (tuple);
   return TRUE;
 }
 



More information about the telepathy-commits mailing list