[kdbus] Add RequestName and ReleaseName to new API
authorLukasz Skalski <l.skalski@samsung.com>
Wed, 29 Oct 2014 12:36:35 +0000 (12:36 +0000)
committerMaciej Wereski <m.wereski@partner.samsung.com>
Fri, 10 Jul 2015 09:47:44 +0000 (11:47 +0200)
gio/gdbusconnection.c
gio/gdbusconnection.h
gio/gioenums.h
gio/gkdbus.c

index 37ca4d7..680062e 100644 (file)
@@ -1595,6 +1595,100 @@ g_dbus_connection_close_sync (GDBusConnection  *connection,
 /* ---------------------------------------------------------------------------------------------------- */
 
 /**
+ * g_dbus_request_name:
+ * @connection: a #GDBusConnection
+ * @name: well-known bus name (name to request)
+ * @flags: a set of flags from the GBusNameOwnerFlags enumeration
+ * @error: return location for error or %NULL
+ *
+ * Synchronously acquires name on the bus and returns status code.
+ *
+ * The calling thread is blocked until a reply is received.
+ *
+ * Returns: status code or %G_BUS_REQUEST_NAME_FLAGS_ERROR
+ *     if @error is set.
+ *
+ * Since: 2.4x
+ */
+GBusRequestNameReplyFlags
+g_dbus_request_name (GDBusConnection     *connection,
+                     const gchar         *name,
+                     GBusNameOwnerFlags   flags,
+                     GError             **error)
+{
+  GVariant *result;
+  guint32 request_name_reply;
+
+  g_return_val_if_fail (G_IS_DBUS_CONNECTION (connection), G_BUS_RELEASE_NAME_FLAGS_ERROR);
+  g_return_val_if_fail (g_dbus_is_name (name) && !g_dbus_is_unique_name (name), G_BUS_RELEASE_NAME_FLAGS_ERROR);
+  g_return_val_if_fail (error == NULL || *error == NULL, G_BUS_RELEASE_NAME_FLAGS_ERROR);
+
+  if (G_IS_KDBUS_CONNECTION (connection->stream))
+    result = _g_kdbus_RequestName (connection, name, flags, error);
+  else
+    result = g_dbus_connection_call_sync (connection, "org.freedesktop.DBus", "/org/freedesktop/DBus",
+                                          "org.freedesktop.DBus", "RequestName",
+                                          g_variant_new ("(su)", name, flags), G_VARIANT_TYPE ("(u)"),
+                                          G_DBUS_CALL_FLAGS_NONE, -1, NULL, error);
+
+  if (result != NULL)
+    {
+      g_variant_get (result, "(u)", &request_name_reply);
+      g_variant_unref (result);
+    }
+  else
+    request_name_reply = G_BUS_REQUEST_NAME_FLAGS_ERROR;
+
+  return (GBusRequestNameReplyFlags) request_name_reply;
+}
+
+/**
+ * g_dbus_release_name:
+ * @connection: a #GDBusConnection
+ * @name: well-known bus name (name to release)
+ * @error: return location for error or %NULL
+ *
+ * Synchronously releases name on the bus and returns status code.
+ *
+ * The calling thread is blocked until a reply is received.
+ *
+ * Returns: status code or %G_BUS_RELEASE_NAME_FLAGS_ERROR
+ *     if @error is set.
+ *
+ * Since: 2.4x
+ */
+GBusReleaseNameReplyFlags
+g_dbus_release_name (GDBusConnection     *connection,
+                     const gchar         *name,
+                     GError             **error)
+{
+  GVariant *result;
+  guint32 release_name_reply;
+
+  g_return_val_if_fail (G_IS_DBUS_CONNECTION (connection), G_BUS_RELEASE_NAME_FLAGS_ERROR);
+  g_return_val_if_fail (g_dbus_is_name (name) && !g_dbus_is_unique_name (name), G_BUS_RELEASE_NAME_FLAGS_ERROR);
+  g_return_val_if_fail (error == NULL || *error == NULL, G_BUS_RELEASE_NAME_FLAGS_ERROR);
+
+  if (G_IS_KDBUS_CONNECTION (connection->stream))
+    result = _g_kdbus_ReleaseName (connection, name, error);
+  else
+    result = g_dbus_connection_call_sync (connection, "org.freedesktop.DBus", "/org/freedesktop/DBus",
+                                          "org.freedesktop.DBus", "ReleaseName",
+                                          g_variant_new ("(s)", name), G_VARIANT_TYPE ("(u)"),
+                                          G_DBUS_CALL_FLAGS_NONE, -1, NULL, error);
+
+  if (result != NULL)
+    {
+      g_variant_get (result, "(u)", &release_name_reply);
+      g_variant_unref (result);
+    }
+  else
+    release_name_reply = G_BUS_RELEASE_NAME_FLAGS_ERROR;
+
+  return (GBusReleaseNameReplyFlags) release_name_reply;
+}
+
+/**
  * g_dbus_get_bus_id:
  * @connection: a #GDBusConnection
  * @error: return location for error or %NULL
index eefdb28..19a637e 100644 (file)
@@ -92,6 +92,15 @@ GDBusConnection *g_dbus_connection_new_for_address_sync       (const gchar
 /* ---------------------------------------------------------------------------------------------------- */
 
 GLIB_AVAILABLE_IN_2_40
+guint32    g_dbus_request_name                                (GDBusConnection     *connection,
+                                                               const gchar         *name,
+                                                               GBusNameOwnerFlags   flags,
+                                                               GError             **error);
+GLIB_AVAILABLE_IN_2_40
+guint32    g_dbus_release_name                                (GDBusConnection     *connection,
+                                                               const gchar         *name,
+                                                               GError             **error);
+GLIB_AVAILABLE_IN_2_40
 gchar     *g_dbus_get_bus_id                                  (GDBusConnection    *connection,
                                                                GError            **error);
 GLIB_AVAILABLE_IN_2_40
index 1d4c7c2..ff8a738 100644 (file)
@@ -950,6 +950,46 @@ typedef enum
 } GBusNameOwnerFlags;
 
 /**
+ * GBusRequestNameReplyFlags:
+ * @G_BUS_REQUEST_NAME_FLAGS_ERROR: Error flag.
+ * @G_BUS_REQUEST_NAME_FLAGS_PRIMARY_OWNER: Caller is now the primary owner of the name, replacing any previous owner.
+ * @G_BUS_REQUEST_NAME_FLAGS_IN_QUEUE: The name already had an owner, the application will be placed in a queue.
+ * @G_BUS_REQUEST_NAME_FLAGS_EXISTS: The name already has an owner.
+ * @G_BUS_REQUEST_NAME_FLAGS_ALREADY_OWNER: The application trying to request ownership of a name is already the owner of it.
+ *
+ * Flags used in g_dbus_request_name().
+ *
+ * Since: 2.4x
+ */
+typedef enum
+{
+  G_BUS_REQUEST_NAME_FLAGS_ERROR = 0,
+  G_BUS_REQUEST_NAME_FLAGS_PRIMARY_OWNER = 1,
+  G_BUS_REQUEST_NAME_FLAGS_IN_QUEUE = 2,
+  G_BUS_REQUEST_NAME_FLAGS_EXISTS = 3,
+  G_BUS_REQUEST_NAME_FLAGS_ALREADY_OWNER = 4
+} GBusRequestNameReplyFlags;
+
+/**
+ * GBusReleaseNameReplyFlags:
+ * @G_BUS_RELEASE_NAME_FLAGS_ERROR: Error flag.
+ * @G_BUS_RELEASE_NAME_FLAGS_RELEASED: The caller has released his claim on the given name.
+ * @G_BUS_RELEASE_NAME_FLAGS_NON_EXISTENT: The given name does not exist on this bus
+ * @G_BUS_RELEASE_NAME_FLAGS_NOT_OWNER: The caller not waiting in the queue to own this name
+ *
+ * Flags used in g_dbus_release_name().
+ *
+ * Since: 2.4x
+ */
+typedef enum
+{
+  G_BUS_RELEASE_NAME_FLAGS_ERROR = 0,
+  G_BUS_RELEASE_NAME_FLAGS_RELEASED = 1,
+  G_BUS_RELEASE_NAME_FLAGS_NON_EXISTENT = 2,
+  G_BUS_RELEASE_NAME_FLAGS_NOT_OWNER = 3
+} GBusReleaseNameReplyFlags;
+
+/**
  * GBusNameWatcherFlags:
  * @G_BUS_NAME_WATCHER_FLAGS_NONE: No flags set.
  * @G_BUS_NAME_WATCHER_FLAGS_AUTO_START: If no-one owns the name when
index c51e0f0..a2cde10 100644 (file)
@@ -78,23 +78,6 @@ typedef enum
   G_BUS_CREDS_SELINUX_CONTEXT  = 4
 } GBusCredentialsFlags;
 
-/* GBusNameOwnerReturnFlags */
-typedef enum
-{
-  G_BUS_REQUEST_NAME_REPLY_PRIMARY_OWNER = 1, /* Caller is now the primary owner of the name, replacing any previous owner */
-  G_BUS_REQUEST_NAME_REPLY_IN_QUEUE = 2,      /* The name already had an owner, the application will be placed in a queue */
-  G_BUS_REQUEST_NAME_REPLY_EXISTS = 3,        /* The name already has an owner */
-  G_BUS_REQUEST_NAME_REPLY_ALREADY_OWNER = 4  /* The application trying to request ownership of a name is already the owner of it */
-} GBusNameOwnerReturnFlags;
-
-/* GBusReleaseNameReturnFlags */
-typedef enum
-{
-  G_BUS_RELEASE_NAME_REPLY_RELEASED = 1,     /* The caller has released his claim on the given name */
-  G_BUS_RELEASE_NAME_REPLY_NON_EXISTENT = 2, /* The given name does not exist on this bus*/
-  G_BUS_RELEASE_NAME_REPLY_NOT_OWNER = 3     /* The caller not waiting in the queue to own this name*/
-} GBusReleaseNameReturnFlags;
-
 /* GKdbusPrivate struct */
 struct _GKdbusPrivate
 {
@@ -644,7 +627,7 @@ _g_kdbus_RequestName (GDBusConnection     *connection,
   gssize len, size;
   gint status, ret;
 
-  status = G_BUS_REQUEST_NAME_REPLY_PRIMARY_OWNER;
+  status = G_BUS_REQUEST_NAME_FLAGS_PRIMARY_OWNER;
 
   kdbus = _g_kdbus_connection_get_kdbus (G_KDBUS_CONNECTION (g_dbus_connection_get_stream (connection)));
   if (kdbus == NULL)
@@ -689,9 +672,9 @@ _g_kdbus_RequestName (GDBusConnection     *connection,
   if (ret < 0)
     {
       if (errno == EEXIST)
-        status = G_BUS_REQUEST_NAME_REPLY_EXISTS;
+        status = G_BUS_REQUEST_NAME_FLAGS_EXISTS;
       else if (errno == EALREADY)
-        status = G_BUS_REQUEST_NAME_REPLY_ALREADY_OWNER;
+        status = G_BUS_REQUEST_NAME_FLAGS_ALREADY_OWNER;
       else
         {
           g_set_error (error, G_IO_ERROR,
@@ -703,7 +686,7 @@ _g_kdbus_RequestName (GDBusConnection     *connection,
     }
 
   if (kdbus_name->flags & KDBUS_NAME_IN_QUEUE)
-    status = G_BUS_REQUEST_NAME_REPLY_IN_QUEUE;
+    status = G_BUS_REQUEST_NAME_FLAGS_IN_QUEUE;
 
   result = g_variant_new ("(u)", status);
 
@@ -726,7 +709,7 @@ _g_kdbus_ReleaseName (GDBusConnection     *connection,
   gssize len, size;
   gint status, ret;
 
-  status = G_BUS_RELEASE_NAME_REPLY_RELEASED;
+  status = G_BUS_RELEASE_NAME_FLAGS_RELEASED;
 
   kdbus = _g_kdbus_connection_get_kdbus (G_KDBUS_CONNECTION (g_dbus_connection_get_stream (connection)));
   if (kdbus == NULL)
@@ -768,9 +751,9 @@ _g_kdbus_ReleaseName (GDBusConnection     *connection,
   if (ret < 0)
     {
       if (errno == ESRCH)
-        status = G_BUS_RELEASE_NAME_REPLY_NON_EXISTENT;
+        status = G_BUS_RELEASE_NAME_FLAGS_NON_EXISTENT;
       else if (errno == EADDRINUSE)
-        status = G_BUS_RELEASE_NAME_REPLY_NOT_OWNER;
+        status = G_BUS_RELEASE_NAME_FLAGS_NOT_OWNER;
       else
         {
           g_set_error (error, G_IO_ERROR,