Blame SOURCES/0018-stream-device-Create-channel-when-needed.patch

ad1357
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
ad1357
From: Frediano Ziglio <fziglio@redhat.com>
ad1357
Date: Fri, 25 Aug 2017 00:02:54 +0100
ad1357
Subject: [spice-server] stream-device: Create channel when needed
ad1357
ad1357
This allows a better id allocation as devices are created after
ad1357
fixed ones.
ad1357
Also will allow to support more easily multiple monitor.
ad1357
ad1357
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
ad1357
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
ad1357
---
ad1357
 server/stream-device.c | 38 ++++++++++++++++++++++++++++++++------
ad1357
 1 file changed, 32 insertions(+), 6 deletions(-)
ad1357
ad1357
diff --git a/server/stream-device.c b/server/stream-device.c
ad1357
index 9e401f8ed..ae108788b 100644
ad1357
--- a/server/stream-device.c
ad1357
+++ b/server/stream-device.c
ad1357
@@ -72,7 +72,7 @@ stream_device_read_msg_from_dev(RedCharDevice *self, SpiceCharDeviceInstance *si
ad1357
     int n;
ad1357
     bool handled = false;
ad1357
 
ad1357
-    if (dev->has_error) {
ad1357
+    if (dev->has_error || !dev->stream_channel) {
ad1357
         return NULL;
ad1357
     }
ad1357
 
ad1357
@@ -238,11 +238,7 @@ stream_device_connect(RedsState *reds, SpiceCharDeviceInstance *sin)
ad1357
 {
ad1357
     SpiceCharDeviceInterface *sif;
ad1357
 
ad1357
-    StreamChannel *stream_channel = stream_channel_new(reds, 1); // TODO id
ad1357
-
ad1357
     StreamDevice *dev = stream_device_new(sin, reds);
ad1357
-    dev->stream_channel = stream_channel;
ad1357
-    stream_channel_register_start_cb(stream_channel, stream_device_stream_start, dev);
ad1357
 
ad1357
     sif = spice_char_device_get_interface(sin);
ad1357
     if (sif->state) {
ad1357
@@ -265,6 +261,33 @@ stream_device_dispose(GObject *object)
ad1357
 }
ad1357
 
ad1357
 static void
ad1357
+allocate_channels(StreamDevice *dev)
ad1357
+{
ad1357
+    if (dev->stream_channel) {
ad1357
+        return;
ad1357
+    }
ad1357
+
ad1357
+    SpiceServer* reds = red_char_device_get_server(RED_CHAR_DEVICE(dev));
ad1357
+
ad1357
+    int id = reds_get_free_channel_id(reds, SPICE_CHANNEL_DISPLAY);
ad1357
+    g_return_if_fail(id >= 0);
ad1357
+
ad1357
+    StreamChannel *stream_channel = stream_channel_new(reds, id);
ad1357
+
ad1357
+    dev->stream_channel = stream_channel;
ad1357
+
ad1357
+    stream_channel_register_start_cb(stream_channel, stream_device_stream_start, dev);
ad1357
+}
ad1357
+
ad1357
+static void
ad1357
+reset_channels(StreamDevice *dev)
ad1357
+{
ad1357
+    if (dev->stream_channel) {
ad1357
+        stream_channel_reset(dev->stream_channel);
ad1357
+    }
ad1357
+}
ad1357
+
ad1357
+static void
ad1357
 stream_device_port_event(RedCharDevice *char_dev, uint8_t event)
ad1357
 {
ad1357
     if (event != SPICE_PORT_EVENT_OPENED && event != SPICE_PORT_EVENT_CLOSED) {
ad1357
@@ -275,10 +298,13 @@ stream_device_port_event(RedCharDevice *char_dev, uint8_t event)
ad1357
 
ad1357
     // reset device and channel on close/open
ad1357
     dev->opened = (event == SPICE_PORT_EVENT_OPENED);
ad1357
+    if (dev->opened) {
ad1357
+        allocate_channels(dev);
ad1357
+    }
ad1357
     dev->hdr_pos = 0;
ad1357
     dev->has_error = false;
ad1357
     red_char_device_reset(char_dev);
ad1357
-    stream_channel_reset(dev->stream_channel);
ad1357
+    reset_channels(dev);
ad1357
 }
ad1357
 
ad1357
 static void