From: Amit Shah <amit.shah@redhat.com>
To: virtualization@lists.linux-foundation.org
Cc: Amit Shah <amit.shah@redhat.com>,
qemu-devel@nongnu.org, kvm@vger.kernel.org
Subject: [Qemu-devel] [PATCH 3/3] virtio-serial: vnc: support for sending / receiving guest clipboard
Date: Mon, 27 Jul 2009 23:34:36 +0530 [thread overview]
Message-ID: <1248717876-17630-5-git-send-email-amit.shah@redhat.com> (raw)
In-Reply-To: <1248717876-17630-4-git-send-email-amit.shah@redhat.com>
- Send ServerCutText message over to the vnc client from qemu
on every write to the clipboard port via virtio-serial
- On receiving ClientCutText message send over the data to the
guest via virtio-serial.
Signed-off-by: Amit Shah <amit.shah@redhat.com>
---
hw/virtio-serial.c | 15 +++++++++++++++
hw/virtio-serial.h | 4 ++++
vnc.c | 24 ++++++++++++++++++++++++
vnc.h | 2 ++
4 files changed, 45 insertions(+), 0 deletions(-)
diff --git a/hw/virtio-serial.c b/hw/virtio-serial.c
index d77af9b..95c715f 100644
--- a/hw/virtio-serial.c
+++ b/hw/virtio-serial.c
@@ -20,6 +20,7 @@
#include "pci.h"
#include "monitor.h"
#include "qemu-char.h"
+#include "vnc.h"
#include "virtio.h"
#include "virtio-serial.h"
@@ -118,6 +119,10 @@ static size_t flush_buf(uint32_t id, const uint8_t *buf, size_t len)
VirtIOSerialPort *port;
size_t write_len = 0;
+ if (id == VIRTIO_SERIAL_CLIPBOARD_PORT && is_vnc_active()) {
+ vnc_clipboard_data_from_guest(buf, len);
+ return len;
+ }
port = get_port_from_id(id);
if (port && port->hd) {
write_len = qemu_chr_write(port->hd, buf, len);
@@ -211,6 +216,16 @@ static void write_to_port(VirtIOSerialPort *port,
virtio_notify(port->virtserial->vdev, vq);
}
+void virtio_serial_send_clipboard_to_guest(const uint8_t *buf, size_t len)
+{
+ VirtIOSerialPort *port = get_port_from_id(VIRTIO_SERIAL_CLIPBOARD_PORT);
+
+ if (!port) {
+ return;
+ }
+ write_to_port(port, buf, len);
+}
+
/* Readiness of the guest to accept data on a port */
static int cons_can_read(void *opaque)
{
diff --git a/hw/virtio-serial.h b/hw/virtio-serial.h
index 08c4b51..44238f6 100644
--- a/hw/virtio-serial.h
+++ b/hw/virtio-serial.h
@@ -18,6 +18,9 @@
#define VIRTIO_ID_SERIAL 7
#define VIRTIO_SERIAL_BAD_ID (~(uint32_t)0)
+/* Port number to function mapping */
+#define VIRTIO_SERIAL_CLIPBOARD_PORT 3
+
struct virtio_serial_config
{
uint32_t max_nr_ports;
@@ -32,5 +35,6 @@ struct virtio_serial_config
void *virtio_serial_new_port(PCIDevice *dev, int idx);
void virtio_serial_monitor_command(Monitor *mon,
const char *command, const char *param);
+void virtio_serial_send_clipboard_to_guest(const uint8_t *buf, size_t len);
#endif
diff --git a/vnc.c b/vnc.c
index e4e78dc..271b64e 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-serial.h"
#define VNC_REFRESH_INTERVAL (1000 / 30)
@@ -671,6 +672,28 @@ static void vnc_copy(VncState *vs, int src_x, int src_y, int dst_x, int dst_y, i
vnc_flush(vs);
}
+void vnc_clipboard_data_from_guest(const uint8_t *buf, size_t len)
+{
+ VncState *vs;
+ VncDisplay *vd;
+ DisplayState *ds;
+
+ 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);
+ }
+}
+
static void vnc_dpy_copy(DisplayState *ds, int src_x, int src_y, int dst_x, int dst_y, int w, int h)
{
VncDisplay *vd = ds->opaque;
@@ -1239,6 +1262,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_serial_send_clipboard_to_guest(text, len);
}
static void check_pointer_type_change(VncState *vs, int absolute)
diff --git a/vnc.h b/vnc.h
index 9739c35..00afdbb 100644
--- a/vnc.h
+++ b/vnc.h
@@ -303,6 +303,8 @@ int vnc_client_io_error(VncState *vs, int ret, int last_errno);
void start_client_init(VncState *vs);
void start_auth_vnc(VncState *vs);
+void vnc_clipboard_data_from_guest(const uint8_t *buf, size_t len);
+
/* Buffer management */
void buffer_reserve(Buffer *buffer, size_t len);
int buffer_empty(Buffer *buffer);
--
1.6.2.5
next prev parent reply other threads:[~2009-07-27 18:05 UTC|newest]
Thread overview: 62+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-07-27 18:04 [Qemu-devel] virtio-serial: An interface for host-guest communication Amit Shah
2009-07-27 18:04 ` [Qemu-devel] [PATCH 1/1] virtio_serial: A char device for simple guest <-> host communication Amit Shah
2009-07-27 18:04 ` [Qemu-devel] [PATCH 1/3] virtio-serial: virtio device for simple host <-> guest communication Amit Shah
2009-07-27 18:04 ` [Qemu-devel] [PATCH 2/3] vnc: add a is_vnc_active() helper Amit Shah
2009-07-27 18:04 ` Amit Shah [this message]
2009-08-05 0:03 ` [Qemu-devel] Re: [PATCH 1/1] virtio_serial: A char device for simple guest <-> host communication Rusty Russell
2009-08-05 5:12 ` Amit Shah
2009-08-05 9:58 ` Amit Shah
2009-07-27 20:22 ` [Qemu-devel] Re: virtio-serial: An interface for host-guest communication Anthony Liguori
2009-07-27 20:32 ` Daniel P. Berrange
2009-07-27 20:37 ` Anthony Liguori
2009-07-27 20:46 ` Jamie Lokier
2009-07-27 23:44 ` Anthony Liguori
2009-07-28 10:36 ` Amit Shah
[not found] ` <4A6F0048.1000103@codemonkey.ws>
2009-07-29 7:44 ` Amit Shah
2009-07-29 7:48 ` Gleb Natapov
2009-08-05 18:00 ` Jamie Lokier
[not found] ` <20090728140029.GA16067@amd.home.annexia.org>
2009-07-28 14:48 ` Anthony Liguori
2009-07-28 14:55 ` Richard W.M. Jones
2009-07-28 15:00 ` Anthony Liguori
2009-08-03 19:57 ` Anthony Liguori
2009-08-05 17:57 ` Jamie Lokier
2009-08-05 18:00 ` Anthony Liguori
2009-08-06 10:38 ` Amit Shah
2009-08-06 13:29 ` Anthony Liguori
2009-08-06 13:41 ` Amit Shah
2009-08-06 13:58 ` Anthony Liguori
2009-08-06 14:04 ` Amit Shah
2009-08-06 17:37 ` Jamie Lokier
2009-08-07 6:38 ` Amit Shah
2009-08-07 14:14 ` Anthony Liguori
2009-08-10 6:55 ` Amit Shah
2009-08-10 9:47 ` Gerd Hoffmann
2009-08-10 13:02 ` Anthony Liguori
2009-08-10 14:02 ` Gerd Hoffmann
2009-08-10 14:20 ` Anthony Liguori
2009-08-10 15:34 ` Gerd Hoffmann
2009-08-10 16:59 ` Anthony Liguori
2009-08-10 17:27 ` Anthony Liguori
2009-08-12 18:27 ` Paul Brook
2009-08-14 8:15 ` Amit Shah
2009-08-14 13:29 ` Anthony Liguori
2009-08-14 13:41 ` Amit Shah
2009-08-20 13:42 ` Amit Shah
2009-08-20 14:25 ` Daniel P. Berrange
2009-08-20 14:38 ` Amit Shah
2009-08-20 14:42 ` Amit Shah
2009-08-14 13:49 ` Gerd Hoffmann
2009-08-14 16:25 ` Anthony Liguori
2009-08-20 7:31 ` Rusty Russell
2009-08-20 7:44 ` Gerd Hoffmann
2009-08-20 7:55 ` Amit Shah
2009-08-20 17:10 ` Jamie Lokier
2009-08-25 12:43 ` Rusty Russell
2009-08-25 13:00 ` Gerd Hoffmann
2009-08-10 14:20 ` Anthony Liguori
2009-08-10 23:09 ` Rusty Russell
2009-08-11 0:16 ` Anthony Liguori
2009-08-10 14:27 ` Anthony Liguori
2009-08-10 15:57 ` Gerd Hoffmann
2009-08-06 10:35 ` Amit Shah
2009-08-05 18:32 ` Richard W.M. Jones
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=1248717876-17630-5-git-send-email-amit.shah@redhat.com \
--to=amit.shah@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=qemu-devel@nongnu.org \
--cc=virtualization@lists.linux-foundation.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).