From patchwork Thu Mar 21 16:35:15 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alon Levy X-Patchwork-Id: 229762 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 042D62C00B6 for ; Fri, 22 Mar 2013 03:35:54 +1100 (EST) Received: from localhost ([::1]:36672 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UIiT2-00078p-3u for incoming@patchwork.ozlabs.org; Thu, 21 Mar 2013 12:35:52 -0400 Received: from eggs.gnu.org ([208.118.235.92]:52693) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UIiSb-00074O-LU for qemu-devel@nongnu.org; Thu, 21 Mar 2013 12:35:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UIiSX-00019a-L4 for qemu-devel@nongnu.org; Thu, 21 Mar 2013 12:35:25 -0400 Received: from mx1.redhat.com ([209.132.183.28]:41383) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UIiSX-00019G-DI for qemu-devel@nongnu.org; Thu, 21 Mar 2013 12:35:21 -0400 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r2LGZKdE006207 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 21 Mar 2013 12:35:20 -0400 Received: from garlic.tlv.redhat.com (spice-ovirt.tlv.redhat.com [10.35.4.71]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r2LGZGpL001701; Thu, 21 Mar 2013 12:35:19 -0400 From: Alon Levy To: qemu-devel@nongnu.org Date: Thu, 21 Mar 2013 18:35:15 +0200 Message-Id: <1363883716-30289-2-git-send-email-alevy@redhat.com> In-Reply-To: <1363883716-30289-1-git-send-email-alevy@redhat.com> References: <87boadc2yp.fsf@codemonkey.ws> <1363883716-30289-1-git-send-email-alevy@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.25 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: amit.shah@redhat.com, hdegoede@redhat.com, aliguori@us.ibm.com, kraxel@redhat.com Subject: [Qemu-devel] [PATCH 1/2] char: add qemu_chr_be_is_fe_connected 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 Note that the handler is called chr_is_guest_connected and not chr_is_fe_connected, consistent with other members of CharDriverState. Signed-off-by: Alon Levy --- hw/virtio-console.c | 9 +++++++++ include/char/char.h | 11 +++++++++++ qemu-char.c | 9 +++++++++ 3 files changed, 29 insertions(+) diff --git a/hw/virtio-console.c b/hw/virtio-console.c index e2d1c58..643e24e 100644 --- a/hw/virtio-console.c +++ b/hw/virtio-console.c @@ -120,6 +120,13 @@ static void chr_event(void *opaque, int event) } } +static bool chr_is_guest_connected(void *opaque) +{ + VirtConsole *vcon = opaque; + + return vcon->port.guest_connected; +} + static int virtconsole_initfn(VirtIOSerialPort *port) { VirtConsole *vcon = DO_UPCAST(VirtConsole, port, port); @@ -133,6 +140,8 @@ static int virtconsole_initfn(VirtIOSerialPort *port) if (vcon->chr) { qemu_chr_add_handlers(vcon->chr, chr_can_read, chr_read, chr_event, vcon); + /* only user of chr_is_guest_connected so leave it as special cased*/ + vcon->chr->chr_is_guest_connected = chr_is_guest_connected; } return 0; diff --git a/include/char/char.h b/include/char/char.h index 0326b2a..b41ddc0 100644 --- a/include/char/char.h +++ b/include/char/char.h @@ -52,6 +52,7 @@ typedef struct { #define CHR_TIOCM_RTS 0x004 typedef void IOEventHandler(void *opaque, int event); +typedef bool IOIsGuestConnectedHandler(void *opaque); struct CharDriverState { void (*init)(struct CharDriverState *s); @@ -64,6 +65,7 @@ struct CharDriverState { IOEventHandler *chr_event; IOCanReadHandler *chr_can_read; IOReadHandler *chr_read; + IOIsGuestConnectedHandler *chr_is_guest_connected; void *handler_opaque; void (*chr_close)(struct CharDriverState *chr); void (*chr_accept_input)(struct CharDriverState *chr); @@ -229,6 +231,15 @@ void qemu_chr_be_write(CharDriverState *s, uint8_t *buf, int len); */ void qemu_chr_be_event(CharDriverState *s, int event); +/** + * @qemu_chr_be_is_fe_connected: + * + * Back end calls this to check if the front end is connected. + * + * Returns: true if the guest (front end) is connected, false otherwise. + */ +bool qemu_chr_be_is_fe_connected(CharDriverState *s); + void qemu_chr_add_handlers(CharDriverState *s, IOCanReadHandler *fd_can_read, IOReadHandler *fd_read, diff --git a/qemu-char.c b/qemu-char.c index 4e011df..77a501a 100644 --- a/qemu-char.c +++ b/qemu-char.c @@ -120,6 +120,15 @@ void qemu_chr_be_event(CharDriverState *s, int event) s->chr_event(s->handler_opaque, event); } +bool qemu_chr_be_is_fe_connected(CharDriverState *s) +{ + if (s->chr_is_guest_connected) { + return s->chr_is_guest_connected(s->handler_opaque); + } + /* default to always connected */ + return true; +} + static gboolean qemu_chr_generic_open_bh(gpointer opaque) { CharDriverState *s = opaque;