Markus Armbruster <arm...@redhat.com> writes: > Gerd Hoffmann <kra...@redhat.com> writes: > >> We have two places needing this, and a third one will come shortly. >> So create a helper function for that so we don't diplicate code. > > "duplicate" > >> >> Signed-off-by: Gerd Hoffmann <kra...@redhat.com> >> --- >> include/ui/console.h | 2 ++ >> ui/console.c | 23 +++++++++++++++++++++++ >> 2 files changed, 25 insertions(+) >> >> diff --git a/include/ui/console.h b/include/ui/console.h >> index adac36d..bbc3b7c 100644 >> --- a/include/ui/console.h >> +++ b/include/ui/console.h >> @@ -377,6 +377,8 @@ void graphic_hw_text_update(QemuConsole *con, >> console_ch_t *chardata); >> >> QemuConsole *qemu_console_lookup_by_index(unsigned int index); >> QemuConsole *qemu_console_lookup_by_device(DeviceState *dev, uint32_t head); >> +QemuConsole *qemu_console_lookup_by_device_name(const char *device_id, >> + uint32_t head, Error >> **errp); >> bool qemu_console_is_visible(QemuConsole *con); >> bool qemu_console_is_graphic(QemuConsole *con); >> bool qemu_console_is_fixedsize(QemuConsole *con); >> diff --git a/ui/console.c b/ui/console.c >> index 4b65c34..ddaa165 100644 >> --- a/ui/console.c >> +++ b/ui/console.c >> @@ -1779,6 +1779,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); > > Peeking ahead in the series... okay, this is factored out of > qemu_input_handler_bind() and vnc_display_open(), with the error message > improved slightly. > > I'd squash PATCH 1-3 together, to make that more obvious.
And add a declaration to a suitable header :) ui/input.c: In function ‘qemu_input_handler_bind’: ui/input.c:87:11: warning: implicit declaration of function ‘qemu_console_lookup_by_device_name’ [-Wimplicit-function-declaration] con = qemu_console_lookup_by_device_name(device_id, head, &err); ^