From patchwork Tue Sep 29 12:04:48 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amit Shah X-Patchwork-Id: 34423 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 8A828B7C25 for ; Tue, 29 Sep 2009 22:17:00 +1000 (EST) Received: from localhost ([127.0.0.1]:41315 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MsbdZ-0007I6-Kb for incoming@patchwork.ozlabs.org; Tue, 29 Sep 2009 08:16:57 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MsbSx-000530-2C for qemu-devel@nongnu.org; Tue, 29 Sep 2009 08:05:59 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MsbSr-00051c-9Z for qemu-devel@nongnu.org; Tue, 29 Sep 2009 08:05:57 -0400 Received: from [199.232.76.173] (port=56965 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MsbSq-00051F-23 for qemu-devel@nongnu.org; Tue, 29 Sep 2009 08:05:52 -0400 Received: from mx1.redhat.com ([209.132.183.28]:46554) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1MsbSp-0004UT-Af for qemu-devel@nongnu.org; Tue, 29 Sep 2009 08:05:51 -0400 Received: from int-mx04.intmail.prod.int.phx2.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.17]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id n8TC5of6024901 for ; Tue, 29 Sep 2009 08:05:50 -0400 Received: from localhost (vpn-225-25.phx2.redhat.com [10.3.225.25]) by int-mx04.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id n8TC5lJQ021904; Tue, 29 Sep 2009 08:05:48 -0400 From: Amit Shah To: qemu-devel@nongnu.org Date: Tue, 29 Sep 2009 17:34:48 +0530 Message-Id: <1254225888-17093-7-git-send-email-amit.shah@redhat.com> In-Reply-To: <1254225888-17093-6-git-send-email-amit.shah@redhat.com> References: <1254225888-17093-1-git-send-email-amit.shah@redhat.com> <1254225888-17093-2-git-send-email-amit.shah@redhat.com> <1254225888-17093-3-git-send-email-amit.shah@redhat.com> <1254225888-17093-4-git-send-email-amit.shah@redhat.com> <1254225888-17093-5-git-send-email-amit.shah@redhat.com> <1254225888-17093-6-git-send-email-amit.shah@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.17 X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. Cc: Amit Shah Subject: [Qemu-devel] [PATCH 6/6] vnc: Add a virtio-console-bus device to send / receive guest clipboard X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org This is a simple device on the virtio-console-bus that syncs with the guest for clipboard activity. A daemon is needed in the guest to send / receive the clipboard data. This patch is just meant to show how to use the read/write api is exposed for devices that ride on top of the virtio-console-bus. Signed-off-by: Amit Shah --- vnc.c | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 67 insertions(+), 0 deletions(-) diff --git a/vnc.c b/vnc.c index ff2d4a8..b6f9cce 100644 --- a/vnc.c +++ b/vnc.c @@ -29,6 +29,7 @@ #include "qemu_socket.h" #include "qemu-timer.h" #include "acl.h" +#include "hw/virtio-console.h" #define VNC_REFRESH_INTERVAL_BASE 30 #define VNC_REFRESH_INTERVAL_INC 50 @@ -44,6 +45,11 @@ } \ } +typedef struct VirtConVnc { + VirtConPort port; +} VirtConVnc; + +static VirtConVnc *virtcon_vnc; static VncDisplay *vnc_display; /* needed for info vnc */ static DisplayChangeListener *dcl; @@ -659,6 +665,34 @@ static void send_framebuffer_update(VncState *vs, int x, int y, int w, int h) } } +static size_t vnc_clipboard_data_from_guest(VirtConPort *port, + const uint8_t *buf, size_t len) +{ + VncState *vs; + VncDisplay *vd; + DisplayState *ds; + + if (!is_vnc_active()) + return 0; + + ds = vnc_display->ds; + vd = ds->opaque; + + for (vs = vd->clients; vs; vs = vs->next) { + vnc_write_u8(vs, 3); /* ServerCutText */ + vnc_write_u8(vs, 0); /* Padding */ + vnc_write_u8(vs, 0); /* Padding */ + vnc_write_u8(vs, 0); /* Padding */ + vnc_write_u32(vs, len); + while (len--) { + vnc_write_u8(vs, *(buf++)); + } + vnc_flush(vs); + } + return len; +} + + static void vnc_copy(VncState *vs, int src_x, int src_y, int dst_x, int dst_y, int w, int h) { /* send bitblit op to the vnc client */ @@ -1240,6 +1274,7 @@ uint32_t read_u32(uint8_t *data, size_t offset) static void client_cut_text(VncState *vs, size_t len, uint8_t *text) { + virtio_console_write(&virtcon_vnc->port, text, len); } static void check_pointer_type_change(VncState *vs, int absolute) @@ -2197,6 +2232,10 @@ static void vnc_connect(VncDisplay *vd, int csock) vnc_init_timer(vd); + if (virtcon_vnc) { + virtio_console_open(&virtcon_vnc->port); + } + /* vs might be free()ed here */ } @@ -2516,3 +2555,31 @@ int vnc_display_open(DisplayState *ds, const char *display) } return qemu_set_fd_handler2(vs->lsock, NULL, vnc_listen_read, NULL, vs); } + +static int vcon_vnc_initfn(VirtConDevice *dev) +{ + VirtConPort *port; + VirtConVnc *vnc; + + port = DO_UPCAST(VirtConPort, dev, &dev->qdev); + vnc = DO_UPCAST(VirtConVnc, port, port); + virtcon_vnc = vnc; + + port->name = qemu_strdup("org.qemu.clipboard"); + /* We don't want to keep old data lingering if vnc is not connected */ + port->flush_buffers = 1; + return 0; +} + +static VirtConPortInfo virtcon_vnc_info = { + .qdev.name = "virtconvnc", + .qdev.size = sizeof(VirtConVnc), + .init = vcon_vnc_initfn, + .have_data = vnc_clipboard_data_from_guest, +}; + +static void virtcon_port_register(void) +{ + virtcon_port_qdev_register(&virtcon_vnc_info); +} +device_init(virtcon_port_register)