[kdbus] Add support for StartServiceByName
authorLukasz Skalski <l.skalski@samsung.com>
Tue, 12 May 2015 14:38:39 +0000 (14:38 +0000)
committerMaciej Wereski <m.wereski@partner.samsung.com>
Fri, 10 Jul 2015 09:47:45 +0000 (11:47 +0200)
gio/gdbusconnection.c
gio/gdbusconnection.h
gio/gioenums.h
gio/gkdbus.c
gio/gkdbus.h

index 9da1932..0e14c24 100644 (file)
@@ -2083,6 +2083,43 @@ g_dbus_get_connection_uid (GDBusConnection  *connection,
   return uid;
 }
 
+/**
+ * g_dbus_start_service_by_name:
+ *
+ * Since: 2.4x
+ */
+GBusStartServiceReplyFlags
+g_dbus_start_service_by_name (GDBusConnection  *connection,
+                              const gchar      *name,
+                              guint32           flags,
+                              GError          **error)
+{
+  GVariant *result;
+  guint32 ret;
+
+  g_return_val_if_fail (G_IS_DBUS_CONNECTION (connection), -1);
+  g_return_val_if_fail (name == NULL || g_dbus_is_name (name), -1);
+  g_return_val_if_fail (error == NULL || *error == NULL, -1);
+
+  result = NULL;
+  ret = G_BUS_START_SERVICE_REPLY_ERROR;
+
+  if (connection->kdbus_worker)
+    result = _g_kdbus_StartServiceByName (connection->kdbus_worker, connection, name, flags, error);
+  else
+    result = g_dbus_connection_call_sync (connection, "org.freedesktop.DBus", "/",
+                                          "org.freedesktop.DBus", "StartServiceByName",
+                                          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)", &ret);
+      g_variant_unref (result);
+    }
+
+  return (GBusStartServiceReplyFlags) ret;
+}
+
 /* ---------------------------------------------------------------------------------------------------- */
 
 /**
index e9ce950..b5d540c 100644 (file)
@@ -127,6 +127,11 @@ GLIB_AVAILABLE_IN_2_40
 guint32    g_dbus_get_connection_uid                          (GDBusConnection    *connection,
                                                                const gchar        *name,
                                                                GError            **error);
+GLIB_AVAILABLE_IN_2_40
+GBusStartServiceReplyFlags    g_dbus_start_service_by_name    (GDBusConnection    *connection,
+                                                               const gchar        *name,
+                                                               guint32             flags,
+                                                               GError            **error);
 
 /* ---------------------------------------------------------------------------------------------------- */
 
index ff8a738..243f788 100644 (file)
@@ -974,8 +974,8 @@ typedef enum
  * 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
+ * @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().
  *
@@ -990,6 +990,23 @@ typedef enum
 } GBusReleaseNameReplyFlags;
 
 /**
+ * GBusStartServiceReplyFlags:
+ * @G_BUS_START_SERVICE_REPLY_ERROR: Error flag.
+ * @G_BUS_START_SERVICE_REPLY_SUCCESS: The service was successfully started.
+ * @G_BUS_START_SERVICE_REPLY_ALREADY_RUNNING: A connection already owns the given name.
+ *
+ * Flags used in g_dbus_start_service_by_name().
+ *
+ * Since: 2.4x
+ */
+typedef enum
+{
+  G_BUS_START_SERVICE_REPLY_ERROR = 0,
+  G_BUS_START_SERVICE_REPLY_SUCCESS = 1,
+  G_BUS_START_SERVICE_REPLY_ALREADY_RUNNING = 2
+} GBusStartServiceReplyFlags;
+
+/**
  * 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 40b5085..caa13a9 100644 (file)
@@ -1304,6 +1304,54 @@ _g_kdbus_GetConnectionUnixUser (GKDBusWorker  *worker,
 
 
 /**
+ * _g_kdbus_StartServiceByName:
+ *
+ */
+GVariant *
+_g_kdbus_StartServiceByName (GKDBusWorker     *worker,
+                             GDBusConnection  *connection,
+                             const gchar      *name,
+                             guint32           flags,
+                             GError          **error)
+{
+  GVariant *result;
+  guint32 status;
+
+  if (!g_dbus_is_name (name))
+    {
+      g_set_error (error,
+                   G_DBUS_ERROR,
+                   G_DBUS_ERROR_INVALID_ARGS,
+                   "Given bus name \"%s\" is not valid", name);
+      return NULL;
+    }
+
+  if (!g_kdbus_NameHasOwner_internal (worker, name, error))
+    {
+      GVariant *ret;
+
+      ret = g_dbus_connection_call_sync (connection, name, "/",
+                                         "org.freedesktop.DBus.Peer", "Ping",
+                                         NULL, G_VARIANT_TYPE ("(u)"),
+                                         G_DBUS_CALL_FLAGS_NONE, -1, NULL, error);
+      if (ret != NULL)
+        {
+          status = G_BUS_START_SERVICE_REPLY_SUCCESS;
+          g_variant_unref (ret);
+        }
+      else
+        return NULL;
+    }
+  else
+    status = G_BUS_START_SERVICE_REPLY_ALREADY_RUNNING;
+
+  result = g_variant_new ("(u)", status);
+
+  return result;
+}
+
+
+/**
  * g_kdbus_bloom_add_data:
  * Based on bus-bloom.c from systemd
  * http://cgit.freedesktop.org/systemd/systemd/tree/src/libsystemd/sd-bus/bus-bloom.c
index 9230199..3981985 100644 (file)
@@ -115,6 +115,12 @@ GVariant *                              _g_kdbus_GetConnectionUnixUser      (GKD
                                                                              const gchar      *name,
                                                                              GError          **error);
 
+GVariant *                              _g_kdbus_StartServiceByName         (GKDBusWorker     *worker,
+                                                                             GDBusConnection  *connection,
+                                                                             const gchar      *name,
+                                                                             guint32           flags,
+                                                                             GError          **error);
+
 void                                    _g_kdbus_AddMatch                   (GKDBusWorker     *worker,
                                                                              const gchar      *match_rule,
                                                                              guint64           cookie);