hw/isa/isa-bus: Replace hw_error() by assert()
[qemu/ar7.git] / util / dbus.c
blob9099dc5b4ba56e06102c8182193a2d9c268236cf
1 /*
2 * Helpers for using D-Bus
4 * Copyright (C) 2019 Red Hat, Inc.
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 */
10 #include "qemu/osdep.h"
11 #include "qemu/dbus.h"
12 #include "qemu/error-report.h"
13 #include "qapi/error.h"
16 * qemu_dbus_get_queued_owners() - return the list of queued unique names
17 * @connection: A GDBusConnection
18 * @name: a service name
20 * Return: a GStrv of unique names, or NULL on failure.
22 GStrv
23 qemu_dbus_get_queued_owners(GDBusConnection *connection, const char *name,
24 Error **errp)
26 g_autoptr(GDBusProxy) proxy = NULL;
27 g_autoptr(GVariant) result = NULL;
28 g_autoptr(GVariant) child = NULL;
29 g_autoptr(GError) err = NULL;
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;
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);
51 error_setg(errp, "Failed to call ListQueuedOwners: %s", err->message);
52 return NULL;
55 child = g_variant_get_child_value(result, 0);
56 return g_variant_dup_strv(child, NULL);