Add a stub device in guest. The aim of this device is make possible for the guest to send a stream through a DisplayChannel (in the sense of protocol channel). This stub allows the guest to send some data and you can see some debug lines of data arrived on host logs. Signed-off-by: Frediano Ziglio <fziglio@xxxxxxxxxx> --- server/Makefile.am | 1 + server/char-device.h | 1 + server/reds.c | 2 + server/stream-device.c | 134 +++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 138 insertions(+) create mode 100644 server/stream-device.c diff --git a/server/Makefile.am b/server/Makefile.am index ef8d31f..495a7a2 100644 --- a/server/Makefile.am +++ b/server/Makefile.am @@ -164,6 +164,7 @@ libserver_la_SOURCES = \ stat.h \ stream.c \ stream.h \ + stream-device.c \ sw-canvas.c \ tree.c \ tree.h \ diff --git a/server/char-device.h b/server/char-device.h index 7fb42a6..3edf17a 100644 --- a/server/char-device.h +++ b/server/char-device.h @@ -239,6 +239,7 @@ RedCharDevice *spicevmc_device_connect(RedsState *reds, uint8_t channel_type); void spicevmc_device_disconnect(RedsState *reds, SpiceCharDeviceInstance *char_device); +RedCharDevice *stream_device_connect(RedsState *reds, SpiceCharDeviceInstance *sin); SpiceCharDeviceInterface *spice_char_device_get_interface(SpiceCharDeviceInstance *instance); diff --git a/server/reds.c b/server/reds.c index 2a8f905..cfa9121 100644 --- a/server/reds.c +++ b/server/reds.c @@ -3158,6 +3158,8 @@ static int spice_server_char_device_add_interface(SpiceServer *reds, else if (strcmp(char_device->subtype, SUBTYPE_PORT) == 0) { if (strcmp(char_device->portname, "org.spice-space.webdav.0") == 0) { dev_state = spicevmc_device_connect(reds, char_device, SPICE_CHANNEL_WEBDAV); + } else if (strcmp(char_device->portname, "com.redhat.stream.0") == 0) { + dev_state = stream_device_connect(reds, char_device); } else { dev_state = spicevmc_device_connect(reds, char_device, SPICE_CHANNEL_PORT); } diff --git a/server/stream-device.c b/server/stream-device.c new file mode 100644 index 0000000..755e8b4 --- /dev/null +++ b/server/stream-device.c @@ -0,0 +1,134 @@ +/* spice-server character device to handle a video stream + + Copyright (C) 2017 Red Hat, Inc. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, see <http://www.gnu.org/licenses/>. +*/ +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#include "char-device.h" + +#define STREAM_TYPE_DEVICE stream_device_get_type() + +#define STREAM_DEVICE(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST((obj), STREAM_TYPE_DEVICE, StreamDevice)) +#define STREAM_DEVICE_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_CAST((klass), STREAM_TYPE_DEVICE, StreamDeviceClass)) +#define RED_IS_CHAR_DEVICE_SPICEVMC(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE((obj), STREAM_TYPE_DEVICE)) +#define RED_IS_CHAR_DEVICE_SPICEVMC_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_TYPE((klass), STREAM_TYPE_DEVICE)) +#define STREAM_DEVICE_GET_CLASS(obj) \ + (G_TYPE_INSTANCE_GET_CLASS((obj), STREAM_TYPE_DEVICE, StreamDeviceClass)) + +typedef struct StreamDevice StreamDevice; +typedef struct StreamDeviceClass StreamDeviceClass; + +struct StreamDevice { + RedCharDevice parent; +}; + +struct StreamDeviceClass { + RedCharDeviceClass parent_class; +}; + +static GType stream_device_get_type(void) G_GNUC_CONST; +static StreamDevice *stream_device_new(SpiceCharDeviceInstance *sin, RedsState *reds); + +G_DEFINE_TYPE(StreamDevice, stream_device, RED_TYPE_CHAR_DEVICE) + +static RedPipeItem * +stream_device_read_msg_from_dev(RedCharDevice *self, SpiceCharDeviceInstance *sin) +{ + SpiceCharDeviceInterface *sif; + int n; + + sif = spice_char_device_get_interface(sin); + + do { + uint8_t buf[256]; + n = sif->read(sin, buf, sizeof(buf)); + spice_debug("readed %d bytes from device", n); + } while (n > 0); + + return NULL; +} + +static void +stream_device_send_msg_to_client(RedCharDevice *self, RedPipeItem *msg, RedClient *client) +{ +} + +static void +stream_device_send_tokens_to_client(RedCharDevice *self, RedClient *client, uint32_t tokens) +{ + spice_printerr("Not implemented!"); +} + +static void +stream_device_remove_client(RedCharDevice *self, RedClient *client) +{ +} + +RedCharDevice * +stream_device_connect(RedsState *reds, SpiceCharDeviceInstance *sin) +{ + SpiceCharDeviceInterface *sif; + + StreamDevice *dev = stream_device_new(sin, reds); + + sif = spice_char_device_get_interface(sin); + if (sif->state) { + sif->state(sin, 1); + } + + return RED_CHAR_DEVICE(dev); +} + +static void +stream_device_dispose(GObject *object) +{ +} + +static void +stream_device_class_init(StreamDeviceClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS(klass); + RedCharDeviceClass *char_dev_class = RED_CHAR_DEVICE_CLASS(klass); + + object_class->dispose = stream_device_dispose; + + char_dev_class->read_one_msg_from_device = stream_device_read_msg_from_dev; + char_dev_class->send_msg_to_client = stream_device_send_msg_to_client; + char_dev_class->send_tokens_to_client = stream_device_send_tokens_to_client; + char_dev_class->remove_client = stream_device_remove_client; +} + +static void +stream_device_init(StreamDevice *self) +{ +} + +static StreamDevice * +stream_device_new(SpiceCharDeviceInstance *sin, RedsState *reds) +{ + return g_object_new(STREAM_TYPE_DEVICE, + "sin", sin, + "spice-server", reds, + "client-tokens-interval", 0ULL, + "self-tokens", ~0ULL, + NULL); +} -- 2.9.3 _______________________________________________ Spice-devel mailing list Spice-devel@xxxxxxxxxxxxxxxxxxxxx https://lists.freedesktop.org/mailman/listinfo/spice-devel