qemu

FORK: QEMU emulator
git clone https://git.neptards.moe/neptards/qemu.git
Log | Files | Refs | Submodules | LICENSE

dbus.c (1854B)


      1 /*
      2  * Helpers for using D-Bus
      3  *
      4  * Copyright (C) 2019 Red Hat, Inc.
      5  *
      6  * This work is licensed under the terms of the GNU GPL, version 2.  See
      7  * the COPYING file in the top-level directory.
      8  */
      9 
     10 #include "qemu/osdep.h"
     11 #include "qemu/dbus.h"
     12 #include "qemu/error-report.h"
     13 #include "qapi/error.h"
     14 
     15 /*
     16  * qemu_dbus_get_queued_owners() - return the list of queued unique names
     17  * @connection: A GDBusConnection
     18  * @name: a service name
     19  *
     20  * Return: a GStrv of unique names, or NULL on failure.
     21  */
     22 GStrv
     23 qemu_dbus_get_queued_owners(GDBusConnection *connection, const char *name,
     24                             Error **errp)
     25 {
     26     g_autoptr(GDBusProxy) proxy = NULL;
     27     g_autoptr(GVariant) result = NULL;
     28     g_autoptr(GVariant) child = NULL;
     29     g_autoptr(GError) err = NULL;
     30 
     31     proxy = g_dbus_proxy_new_sync(connection, G_DBUS_PROXY_FLAGS_NONE, NULL,
     32                                   "org.freedesktop.DBus",
     33                                   "/org/freedesktop/DBus",
     34                                   "org.freedesktop.DBus",
     35                                   NULL, &err);
     36     if (!proxy) {
     37         error_setg(errp, "Failed to create DBus proxy: %s", err->message);
     38         return NULL;
     39     }
     40 
     41     result = g_dbus_proxy_call_sync(proxy, "ListQueuedOwners",
     42                                     g_variant_new("(s)", name),
     43                                     G_DBUS_CALL_FLAGS_NO_AUTO_START,
     44                                     -1, NULL, &err);
     45     if (!result) {
     46         if (g_error_matches(err,
     47                             G_DBUS_ERROR,
     48                             G_DBUS_ERROR_NAME_HAS_NO_OWNER)) {
     49             return g_new0(char *, 1);
     50         }
     51         error_setg(errp, "Failed to call ListQueuedOwners: %s", err->message);
     52         return NULL;
     53     }
     54 
     55     child = g_variant_get_child_value(result, 0);
     56     return g_variant_dup_strv(child, NULL);
     57 }