]> git.proxmox.com Git - mirror_qemu.git/commitdiff
hw/core/qdev.c: add qdev_get_human_name()
authorManos Pitsidianakis <manos.pitsidianakis@linaro.org>
Tue, 30 Jan 2024 07:30:31 +0000 (09:30 +0200)
committerStefan Hajnoczi <stefanha@redhat.com>
Tue, 30 Jan 2024 21:19:00 +0000 (16:19 -0500)
Add a simple method to return some kind of human readable identifier for
use in error messages.

Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
Message-id: 8b566bfced98ae44be1fcc1f8e7215f0c3393aa1.1706598705.git.manos.pitsidianakis@linaro.org
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
hw/core/qdev.c
include/hw/qdev-core.h

index 43d863b0c5b002c7f0a46de2710b5a1a110717a7..c68d0f7c512fd2203326b70df4dd5b0019865225 100644 (file)
@@ -879,6 +879,14 @@ Object *qdev_get_machine(void)
     return dev;
 }
 
+char *qdev_get_human_name(DeviceState *dev)
+{
+    g_assert(dev != NULL);
+
+    return dev->id ?
+           g_strdup(dev->id) : object_get_canonical_path(OBJECT(dev));
+}
+
 static MachineInitPhase machine_phase;
 
 bool phase_check(MachineInitPhase phase)
index 151d9682380d292357a5b28c77824e15050fcb55..66338f479fe7e20197509b541ea3bc59a72e3f34 100644 (file)
@@ -993,6 +993,20 @@ const char *qdev_fw_name(DeviceState *dev);
 void qdev_assert_realized_properly(void);
 Object *qdev_get_machine(void);
 
+/**
+ * qdev_get_human_name() - Return a human-readable name for a device
+ * @dev: The device. Must be a valid and non-NULL pointer.
+ *
+ * .. note::
+ *    This function is intended for user friendly error messages.
+ *
+ * Returns: A newly allocated string containing the device id if not null,
+ * else the object canonical path.
+ *
+ * Use g_free() to free it.
+ */
+char *qdev_get_human_name(DeviceState *dev);
+
 /* FIXME: make this a link<> */
 bool qdev_set_parent_bus(DeviceState *dev, BusState *bus, Error **errp);