From: Amit Shah <amit.shah@redhat.com>
To: qemu-devel@nongnu.org
Cc: Amit Shah <amit.shah@redhat.com>
Subject: [Qemu-devel] [PATCH 6/6] vnc: Add a virtio-console-bus device to send / receive guest clipboard
Date: Tue, 29 Sep 2009 17:34:48 +0530 [thread overview]
Message-ID: <1254225888-17093-7-git-send-email-amit.shah@redhat.com> (raw)
In-Reply-To: <1254225888-17093-6-git-send-email-amit.shah@redhat.com>
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 <amit.shah@redhat.com>
---
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)
--
1.6.2.5
next prev parent reply other threads:[~2009-09-29 12:05 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-09-29 12:04 [Qemu-devel] virtio-console-bus, multiport, virtio-console-port Amit Shah
2009-09-29 12:04 ` [Qemu-devel] [PATCH 1/6] char: Emit 'OPENED' events on char device open Amit Shah
2009-09-29 12:04 ` [Qemu-devel] [PATCH 2/6] qdev: add string property Amit Shah
2009-09-29 12:04 ` [Qemu-devel] [PATCH 3/6] virtio-console: Add a virtio-console bus, support for multiple ports Amit Shah
2009-09-29 12:04 ` [Qemu-devel] [PATCH 4/6] virtio-console-port: Add a new device on the virtio-console-bus for generic host-guest communication Amit Shah
2009-09-29 12:04 ` [Qemu-devel] [PATCH 5/6] vnc: add a is_vnc_active() helper Amit Shah
2009-09-29 12:04 ` Amit Shah [this message]
2009-09-29 18:13 ` [Qemu-devel] [PATCH 6/6] vnc: Add a virtio-console-bus device to send / receive guest clipboard Gerd Hoffmann
2009-09-30 4:50 ` Amit Shah
2009-09-29 18:08 ` [Qemu-devel] [PATCH 4/6] virtio-console-port: Add a new device on the virtio-console-bus for generic host-guest communication Gerd Hoffmann
2009-09-30 8:09 ` Nathan Baum
2009-09-29 18:04 ` [Qemu-devel] [PATCH 3/6] virtio-console: Add a virtio-console bus, support for multiple ports Gerd Hoffmann
2009-09-30 4:47 ` Amit Shah
2009-09-30 8:59 ` Gerd Hoffmann
2009-09-30 15:55 ` Amit Shah
2009-09-30 18:39 ` Gerd Hoffmann
2009-10-01 4:54 ` Amit Shah
2009-10-01 8:38 ` Gerd Hoffmann
2009-10-01 8:56 ` Amit Shah
2009-10-01 10:48 ` Amit Shah
2009-10-01 12:15 ` Gerd Hoffmann
2009-10-07 9:25 ` Amit Shah
2009-10-07 9:51 ` Gerd Hoffmann
2009-10-07 10:06 ` Amit Shah
2009-10-07 11:33 ` Gerd Hoffmann
2009-10-07 11:42 ` Amit Shah
2009-10-07 13:06 ` Gerd Hoffmann
2009-10-07 13:53 ` Amit Shah
2009-10-07 14:03 ` Gerd Hoffmann
2009-10-07 14:00 ` Anthony Liguori
2009-09-30 21:13 ` [Qemu-devel] [PATCH 1/6] char: Emit 'OPENED' events on char device open Anthony Liguori
2009-10-01 4:56 ` Amit Shah
2009-10-01 6:02 ` Amit Shah
2009-10-01 12:54 ` Anthony Liguori
2009-10-01 13:43 ` Gerd Hoffmann
2009-10-01 13:48 ` Anthony Liguori
2009-10-01 15:18 ` Gerd Hoffmann
2009-09-29 14:53 ` [Qemu-devel] virtio-console-bus, multiport, virtio-console-port Amit Shah
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1254225888-17093-7-git-send-email-amit.shah@redhat.com \
--to=amit.shah@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).