kdbus: bring back original gio semantic in d-bus name management 87/52487/1 accepted/tizen_base accepted/tizen/base/20151223.052341 accepted/tizen/common/20160107.114028 accepted/tizen/mobile/20151125.125334 accepted/tizen/tv/20151125.125346 accepted/tizen/wearable/20151125.125358 submit/tizen/20151125.071639 submit/tizen_base/20151223.111111 submit/tizen_base/20151223.111112 submit/tizen_common/20151229.142028 submit/tizen_common/20151229.144031 submit/tizen_common/20151229.154718 submit/tizen_common/20160104.112601
authorLukasz Skalski <l.skalski@samsung.com>
Mon, 23 Nov 2015 15:42:58 +0000 (16:42 +0100)
committerLukasz Skalski <l.skalski@samsung.com>
Mon, 23 Nov 2015 15:42:58 +0000 (16:42 +0100)
Since when we have 'dbus1 compatibility layer' we do not have to use
our new API, which offers only synchronous calls. Thanks of that we don't
have to modify gdbusnameowning.c and gdbusnamewatching.c files what causes
that GLib kdbus port is easier to maintain/rebase.

Change-Id: I76bf7b436e3dd82f6cd7e309b4a08b6b49363edd

gio/gdbusnameowning.c
gio/gdbusnamewatching.c

index 245d476..00b2dfd 100644 (file)
@@ -296,23 +296,40 @@ on_name_lost_or_acquired (GDBusConnection  *connection,
 /* ---------------------------------------------------------------------------------------------------- */
 
 static void
-process_request_name_reply (Client                    *client,
-                            GBusRequestNameReplyFlags  request_name_reply)
+request_name_cb (GObject      *source_object,
+                 GAsyncResult *res,
+                 gpointer      user_data)
 {
+  Client *client = user_data;
+  GVariant *result;
+  guint32 request_name_reply;
   gboolean subscribe;
 
+  request_name_reply = 0;
+  result = NULL;
+
+  /* don't use client->connection - it may be NULL already */
+  result = g_dbus_connection_call_finish (G_DBUS_CONNECTION (source_object),
+                                          res,
+                                          NULL);
+  if (result != NULL)
+    {
+      g_variant_get (result, "(u)", &request_name_reply);
+      g_variant_unref (result);
+    }
+
   subscribe = FALSE;
 
   switch (request_name_reply)
     {
-    case G_BUS_REQUEST_NAME_FLAGS_PRIMARY_OWNER:
+    case 1: /* DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER */
       /* We got the name - now listen for NameLost and NameAcquired */
       call_acquired_handler (client);
       subscribe = TRUE;
       client->needs_release = TRUE;
       break;
 
-    case G_BUS_REQUEST_NAME_FLAGS_IN_QUEUE:
+    case 2: /* DBUS_REQUEST_NAME_REPLY_IN_QUEUE */
       /* Waiting in line - listen for NameLost and NameAcquired */
       call_lost_handler (client);
       subscribe = TRUE;
@@ -321,8 +338,8 @@ process_request_name_reply (Client                    *client,
 
     default:
       /* assume we couldn't get the name - explicit fallthrough */
-    case G_BUS_REQUEST_NAME_FLAGS_EXISTS:
-    case G_BUS_REQUEST_NAME_FLAGS_ALREADY_OWNER:
+    case 3: /* DBUS_REQUEST_NAME_REPLY_EXISTS */
+    case 4: /* DBUS_REQUEST_NAME_REPLY_ALREADY_OWNER */
       /* Some other part of the process is already owning the name */
       call_lost_handler (client);
       break;
@@ -370,6 +387,8 @@ process_request_name_reply (Client                    *client,
           g_object_unref (connection);
         }
     }
+
+  client_unref (client);
 }
 
 /* ---------------------------------------------------------------------------------------------------- */
@@ -402,25 +421,27 @@ on_connection_disconnected (GDBusConnection *connection,
 static void
 has_connection (Client *client)
 {
-  GError *error = NULL;
-  GBusRequestNameReplyFlags request_name_reply;
-
-  request_name_reply = G_BUS_REQUEST_NAME_FLAGS_ERROR;
-
   /* listen for disconnection */
   client->disconnected_signal_handler_id = g_signal_connect (client->connection,
                                                              "closed",
                                                              G_CALLBACK (on_connection_disconnected),
                                                              client);
-  /* attempt to acquire the name */
-  request_name_reply = g_dbus_request_name (client->connection, client->name, client->flags, &error);
-  if (request_name_reply == G_BUS_REQUEST_NAME_FLAGS_ERROR)
-    {
-      g_warning ("Error requesting name %s: %s", client->name, error->message);
-      g_error_free (error);
-    }
 
-  process_request_name_reply (client, request_name_reply);
+  /* attempt to acquire the name */
+  g_dbus_connection_call (client->connection,
+                          "org.freedesktop.DBus",  /* bus name */
+                          "/org/freedesktop/DBus", /* object path */
+                          "org.freedesktop.DBus",  /* interface name */
+                          "RequestName",           /* method name */
+                          g_variant_new ("(su)",
+                                         client->name,
+                                         client->flags),
+                          G_VARIANT_TYPE ("(u)"),
+                          G_DBUS_CALL_FLAGS_NONE,
+                          -1,
+                          NULL,
+                          (GAsyncReadyCallback) request_name_cb,
+                          client_ref (client));
 }
 
 
@@ -877,10 +898,9 @@ g_bus_unown_name (guint owner_id)
           client->connection != NULL &&
           !g_dbus_connection_is_closed (client->connection))
         {
-          GBusReleaseNameReplyFlags release_name_reply;
+          GVariant *result;
           GError *error;
-
-          error = NULL;
+          guint32 release_name_reply;
 
           /* TODO: it kinda sucks having to do a sync call to release the name - but if
            * we don't, then a subsequent grab of the name will make the bus daemon return
@@ -888,16 +908,32 @@ g_bus_unown_name (guint owner_id)
            *
            * I believe this is a bug in the bus daemon.
            */
-
-          release_name_reply = g_dbus_release_name (client->connection, client->name, &error);
-          if (release_name_reply == G_BUS_RELEASE_NAME_FLAGS_ERROR)
+          error = NULL;
+          result = g_dbus_connection_call_sync (client->connection,
+                                                "org.freedesktop.DBus",  /* bus name */
+                                                "/org/freedesktop/DBus", /* object path */
+                                                "org.freedesktop.DBus",  /* interface name */
+                                                "ReleaseName",           /* method name */
+                                                g_variant_new ("(s)", client->name),
+                                                G_VARIANT_TYPE ("(u)"),
+                                                G_DBUS_CALL_FLAGS_NONE,
+                                                -1,
+                                                NULL,
+                                                &error);
+          if (result == NULL)
             {
               g_warning ("Error releasing name %s: %s", client->name, error->message);
               g_error_free (error);
             }
           else
-            if (release_name_reply != G_BUS_RELEASE_NAME_FLAGS_RELEASED)
-              g_warning ("Unexpected reply %d when releasing name %s", release_name_reply, client->name);
+            {
+              g_variant_get (result, "(u)", &release_name_reply);
+              if (release_name_reply != 1 /* DBUS_RELEASE_NAME_REPLY_RELEASED */)
+                {
+                  g_warning ("Unexpected reply %d when releasing name %s", release_name_reply, client->name);
+                }
+              g_variant_unref (result);
+            }
         }
 
       if (client->disconnected_signal_handler_id > 0)
index 252a510..07713db 100644 (file)
@@ -322,22 +322,6 @@ on_name_owner_changed (GDBusConnection *connection,
 /* ---------------------------------------------------------------------------------------------------- */
 
 static void
-process_get_name_owner (Client      *client,
-                        const char  *name_owner)
-{
-  if (name_owner != NULL)
-    {
-      g_warn_if_fail (client->name_owner == NULL);
-      client->name_owner = g_strdup (name_owner);
-      call_appeared_handler (client);
-    }
-  else
-    call_vanished_handler (client, FALSE);
-
-  client->initialized = TRUE;
-}
-
-static void
 get_name_owner_cb (GObject      *source_object,
                    GAsyncResult *res,
                    gpointer      user_data)
@@ -357,7 +341,18 @@ get_name_owner_cb (GObject      *source_object,
       g_variant_get (result, "(&s)", &name_owner);
     }
 
-  process_get_name_owner (client, name_owner);
+  if (name_owner != NULL)
+    {
+      g_warn_if_fail (client->name_owner == NULL);
+      client->name_owner = g_strdup (name_owner);
+      call_appeared_handler (client);
+    }
+  else
+    {
+      call_vanished_handler (client, FALSE);
+    }
+
+  client->initialized = TRUE;
 
   if (result != NULL)
     g_variant_unref (result);
@@ -369,53 +364,23 @@ get_name_owner_cb (GObject      *source_object,
 static void
 invoke_get_name_owner (Client *client)
 {
-  if (_g_dbus_connection_is_kdbus (client->connection))
-    {
-      char *name_owner;
-
-      name_owner = g_dbus_get_name_owner (client->connection,
-                                          client->name,
-                                          NULL);
-      process_get_name_owner (client, name_owner);
-      if (name_owner != NULL)
-        g_free (name_owner);
-    }
-  else
-    {
-      g_dbus_connection_call (client->connection,
-                              "org.freedesktop.DBus",  /* bus name */
-                              "/org/freedesktop/DBus", /* object path */
-                              "org.freedesktop.DBus",  /* interface name */
-                              "GetNameOwner",          /* method name */
-                              g_variant_new ("(s)", client->name),
-                              G_VARIANT_TYPE ("(s)"),
-                              G_DBUS_CALL_FLAGS_NONE,
-                              -1,
-                              NULL,
-                              (GAsyncReadyCallback) get_name_owner_cb,
-                              client_ref (client));
-    }
+  g_dbus_connection_call (client->connection,
+                          "org.freedesktop.DBus",  /* bus name */
+                          "/org/freedesktop/DBus", /* object path */
+                          "org.freedesktop.DBus",  /* interface name */
+                          "GetNameOwner",          /* method name */
+                          g_variant_new ("(s)", client->name),
+                          G_VARIANT_TYPE ("(s)"),
+                          G_DBUS_CALL_FLAGS_NONE,
+                          -1,
+                          NULL,
+                          (GAsyncReadyCallback) get_name_owner_cb,
+                          client_ref (client));
 }
 
 /* ---------------------------------------------------------------------------------------------------- */
 
 static void
-process_start_service_by_name (Client                      *client,
-                               GBusStartServiceReplyFlags   result)
-{
-  if (result == G_BUS_START_SERVICE_REPLY_SUCCESS)
-    invoke_get_name_owner (client);
-  else if (result == G_BUS_START_SERVICE_REPLY_ALREADY_RUNNING)
-    invoke_get_name_owner (client);
-  else
-    {
-      g_warning ("Unexpected reply %d from StartServiceByName() method", result);
-      call_vanished_handler (client, FALSE);
-      client->initialized = TRUE;
-    }
-}
-
-static void
 start_service_by_name_cb (GObject      *source_object,
                           GAsyncResult *res,
                           gpointer      user_data)
@@ -433,7 +398,20 @@ start_service_by_name_cb (GObject      *source_object,
       guint32 start_service_result;
       g_variant_get (result, "(u)", &start_service_result);
 
-      process_start_service_by_name (client, (GBusStartServiceReplyFlags) start_service_result);
+      if (start_service_result == 1) /* DBUS_START_REPLY_SUCCESS */
+        {
+          invoke_get_name_owner (client);
+        }
+      else if (start_service_result == 2) /* DBUS_START_REPLY_ALREADY_RUNNING */
+        {
+          invoke_get_name_owner (client);
+        }
+      else
+        {
+          g_warning ("Unexpected reply %d from StartServiceByName() method", start_service_result);
+          call_vanished_handler (client, FALSE);
+          client->initialized = TRUE;
+        }
     }
   else
     {
@@ -479,26 +457,18 @@ has_connection (Client *client)
 
   if (client->flags & G_BUS_NAME_WATCHER_FLAGS_AUTO_START)
     {
-      if (_g_dbus_connection_is_kdbus (client->connection))
-        {
-          GBusStartServiceReplyFlags result;
-
-          result = g_dbus_start_service_by_name (client->connection, client->name, 0, NULL);
-          process_start_service_by_name (client, result);
-        }
-      else
-        g_dbus_connection_call (client->connection,
-                                "org.freedesktop.DBus",  /* bus name */
-                                "/org/freedesktop/DBus", /* object path */
-                                "org.freedesktop.DBus",  /* interface name */
-                                "StartServiceByName",    /* method name */
-                                g_variant_new ("(su)", client->name, 0),
-                                G_VARIANT_TYPE ("(u)"),
-                                G_DBUS_CALL_FLAGS_NONE,
-                                -1,
-                                NULL,
-                                (GAsyncReadyCallback) start_service_by_name_cb,
-                                client_ref (client));
+      g_dbus_connection_call (client->connection,
+                              "org.freedesktop.DBus",  /* bus name */
+                              "/org/freedesktop/DBus", /* object path */
+                              "org.freedesktop.DBus",  /* interface name */
+                              "StartServiceByName",    /* method name */
+                              g_variant_new ("(su)", client->name, 0),
+                              G_VARIANT_TYPE ("(u)"),
+                              G_DBUS_CALL_FLAGS_NONE,
+                              -1,
+                              NULL,
+                              (GAsyncReadyCallback) start_service_by_name_cb,
+                              client_ref (client));
     }
   else
     {