From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40521) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aK7Rh-00065K-Ty for qemu-devel@nongnu.org; Fri, 15 Jan 2016 11:41:54 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aK7Rh-0005kb-0U for qemu-devel@nongnu.org; Fri, 15 Jan 2016 11:41:53 -0500 Received: from mx1.redhat.com ([209.132.183.28]:52718) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aK7Rg-0005kS-Ok for qemu-devel@nongnu.org; Fri, 15 Jan 2016 11:41:52 -0500 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (Postfix) with ESMTPS id 559E1C09FAB4 for ; Fri, 15 Jan 2016 16:41:52 +0000 (UTC) From: Markus Armbruster References: <1452601779-5790-1-git-send-email-kraxel@redhat.com> <874mee6cek.fsf@blackfin.pond.sub.org> Date: Fri, 15 Jan 2016 17:41:49 +0100 In-Reply-To: <874mee6cek.fsf@blackfin.pond.sub.org> (Markus Armbruster's message of "Fri, 15 Jan 2016 17:22:11 +0100") Message-ID: <87io2u3icy.fsf@blackfin.pond.sub.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH 1/7] console: add qemu_console_lookup_by_device_name List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Gerd Hoffmann Cc: Marcelo Tosatti , qemu-devel@nongnu.org Markus Armbruster writes: > Gerd Hoffmann 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 >> --- >> 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, consol= e_ch_t *chardata); >>=20=20 >> QemuConsole *qemu_console_lookup_by_index(unsigned int index); >> QemuConsole *qemu_console_lookup_by_device(DeviceState *dev, uint32_t h= ead); >> +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(Device= State *dev, uint32_t head) >> return NULL; >> } >>=20=20 >> +QemuConsole *qemu_console_lookup_by_device_name(const char *device_id, >> + uint32_t head, Error **= errp) >> +{ >> + DeviceState *dev; >> + QemuConsole *con; >> + >> + dev =3D qdev_find_recursive(sysbus_get_default(), device_id); >> + if (dev =3D=3D NULL) { >> + error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND, >> + "Device '%s' not found", device_id); >> + return NULL; >> + } >> + >> + con =3D qemu_console_lookup_by_device(dev, head); >> + if (con =3D=3D NULL) { >> + error_setg(errp, "Device %s (head %d) is not bound to a QemuCon= sole", >> + device_id, head); >> + return NULL; >> + } >> + >> + return con; >> +} >> + >> bool qemu_console_is_visible(QemuConsole *con) >> { >> return (con =3D=3D 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 =E2=80=98qemu_input_handler_bind=E2=80=99: ui/input.c:87:11: warning: implicit declaration of function =E2=80=98qemu_c= onsole_lookup_by_device_name=E2=80=99 [-Wimplicit-function-declaration] con =3D qemu_console_lookup_by_device_name(device_id, head, &err); ^