aboutsummaryrefslogtreecommitdiff
path: root/ui/console.c
diff options
context:
space:
mode:
authorGerd Hoffmann <kraxel@redhat.com>2016-01-12 11:45:43 +0100
committerGerd Hoffmann <kraxel@redhat.com>2016-03-01 07:51:34 +0100
commitf2c1d54c186c400ec676ec4d29ea4b8bf440c054 (patch)
tree577d745cad7ac0a433b02a8a964438fa966076ae /ui/console.c
parent071608b519adf62bc29c914343a21c5407ab1ac9 (diff)
console: add & use qemu_console_lookup_by_device_name
We have two places needing this, and a third one will come shortly. So factor things out into a helper function to reduce code duplication. Signed-off-by: Gerd Hoffmann <kraxel@redhat.com> Reviewed-by: Daniel P. Berrange <berrange@redhat.com> Reviewed-by: Markus Armbruster <armbru@redhat.com>
Diffstat (limited to 'ui/console.c')
-rw-r--r--ui/console.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/ui/console.c b/ui/console.c
index 7db0fd27c9..ae61382d6e 100644
--- a/ui/console.c
+++ b/ui/console.c
@@ -1790,6 +1790,29 @@ QemuConsole *qemu_console_lookup_by_device(DeviceState *dev, uint32_t head)
return NULL;
}
+QemuConsole *qemu_console_lookup_by_device_name(const char *device_id,
+ uint32_t head, Error **errp)
+{
+ DeviceState *dev;
+ QemuConsole *con;
+
+ dev = qdev_find_recursive(sysbus_get_default(), device_id);
+ if (dev == NULL) {
+ error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND,
+ "Device '%s' not found", device_id);
+ return NULL;
+ }
+
+ con = qemu_console_lookup_by_device(dev, head);
+ if (con == NULL) {
+ error_setg(errp, "Device %s (head %d) is not bound to a QemuConsole",
+ device_id, head);
+ return NULL;
+ }
+
+ return con;
+}
+
bool qemu_console_is_visible(QemuConsole *con)
{
return (con == active_console) || (con->dcls > 0);