From patchwork Tue Jan 12 12:29:33 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gerd Hoffmann X-Patchwork-Id: 566532 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 6CBA314010F for ; Tue, 12 Jan 2016 23:30:24 +1100 (AEDT) Received: from localhost ([::1]:59572 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aIy5e-0007al-65 for incoming@patchwork.ozlabs.org; Tue, 12 Jan 2016 07:30:22 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58759) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aIy56-0006jm-I8 for qemu-devel@nongnu.org; Tue, 12 Jan 2016 07:29:49 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aIy53-0007mP-EO for qemu-devel@nongnu.org; Tue, 12 Jan 2016 07:29:48 -0500 Received: from mx1.redhat.com ([209.132.183.28]:57684) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aIy53-0007m7-9e for qemu-devel@nongnu.org; Tue, 12 Jan 2016 07:29:45 -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 EFE5DC07662E for ; Tue, 12 Jan 2016 12:29:44 +0000 (UTC) Received: from nilsson.home.kraxel.org (ovpn-116-29.ams2.redhat.com [10.36.116.29]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u0CCThVJ005612; Tue, 12 Jan 2016 07:29:44 -0500 Received: by nilsson.home.kraxel.org (Postfix, from userid 500) id 6A83380823; Tue, 12 Jan 2016 13:29:42 +0100 (CET) From: Gerd Hoffmann To: qemu-devel@nongnu.org Date: Tue, 12 Jan 2016 13:29:33 +0100 Message-Id: <1452601779-5790-1-git-send-email-kraxel@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Marcelo Tosatti , Markus Armbruster , Gerd Hoffmann Subject: [Qemu-devel] [PATCH 1/7] console: add qemu_console_lookup_by_device_name X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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. Signed-off-by: Gerd Hoffmann Reviewed-by: Daniel P. Berrange --- 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);