Blame SOURCES/0008-stream-channel-Write-a-base-channel-to-implement-the.patch

ad1357
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
ad1357
From: Frediano Ziglio <fziglio@redhat.com>
ad1357
Date: Sat, 21 Jan 2017 15:29:18 +0000
ad1357
Subject: [spice-server] stream-channel: Write a base channel to implement the
ad1357
 streaming
ad1357
ad1357
Currently only compile, not used and not much sense
ad1357
ad1357
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
ad1357
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
ad1357
---
ad1357
 server/Makefile.am      |   2 +
ad1357
 server/stream-channel.c | 175 ++++++++++++++++++++++++++++++++++++++++++++++++
ad1357
 server/stream-channel.h |  53 +++++++++++++++
ad1357
 3 files changed, 230 insertions(+)
ad1357
 create mode 100644 server/stream-channel.c
ad1357
 create mode 100644 server/stream-channel.h
ad1357
ad1357
diff --git a/server/Makefile.am b/server/Makefile.am
ad1357
index f08ddf883..e2e3ce861 100644
ad1357
--- a/server/Makefile.am
ad1357
+++ b/server/Makefile.am
ad1357
@@ -166,6 +166,8 @@ libserver_la_SOURCES =				\
ad1357
 	stat.h					\
ad1357
 	stream.c				\
ad1357
 	stream.h				\
ad1357
+	stream-channel.c			\
ad1357
+	stream-channel.h			\
ad1357
 	stream-device.c				\
ad1357
 	sw-canvas.c				\
ad1357
 	tree.c					\
ad1357
diff --git a/server/stream-channel.c b/server/stream-channel.c
ad1357
new file mode 100644
ad1357
index 000000000..fd735f562
ad1357
--- /dev/null
ad1357
+++ b/server/stream-channel.c
ad1357
@@ -0,0 +1,175 @@
ad1357
+/* -*- Mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- */
ad1357
+/*
ad1357
+   Copyright (C) 2017 Red Hat, Inc.
ad1357
+
ad1357
+   This library is free software; you can redistribute it and/or
ad1357
+   modify it under the terms of the GNU Lesser General Public
ad1357
+   License as published by the Free Software Foundation; either
ad1357
+   version 2.1 of the License, or (at your option) any later version.
ad1357
+
ad1357
+   This library is distributed in the hope that it will be useful,
ad1357
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
ad1357
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
ad1357
+   Lesser General Public License for more details.
ad1357
+
ad1357
+   You should have received a copy of the GNU Lesser General Public
ad1357
+   License along with this library; if not, see <http://www.gnu.org/licenses/>.
ad1357
+*/
ad1357
+#ifdef HAVE_CONFIG_H
ad1357
+#include <config.h>
ad1357
+#endif
ad1357
+
ad1357
+#include "red-channel-client.h"
ad1357
+#include "stream-channel.h"
ad1357
+#include "reds.h"
ad1357
+#include "common-graphics-channel.h"
ad1357
+
ad1357
+#define TYPE_STREAM_CHANNEL_CLIENT stream_channel_client_get_type()
ad1357
+
ad1357
+#define STREAM_CHANNEL_CLIENT(obj) \
ad1357
+    (G_TYPE_CHECK_INSTANCE_CAST((obj), TYPE_STREAM_CHANNEL_CLIENT, StreamChannelClient))
ad1357
+#define STREAM_CHANNEL_CLIENT_CLASS(klass) \
ad1357
+    (G_TYPE_CHECK_CLASS_CAST((klass), TYPE_STREAM_CHANNEL_CLIENT, StreamChannelClientClass))
ad1357
+#define IS_STREAM_CHANNEL_CLIENT(obj) \
ad1357
+    (G_TYPE_CHECK_INSTANCE_TYPE((obj), TYPE_STREAM_CHANNEL_CLIENT))
ad1357
+#define IS_STREAM_CHANNEL_CLIENT_CLASS(klass) \
ad1357
+    (G_TYPE_CHECK_CLASS_TYPE((klass), TYPE_STREAM_CHANNEL_CLIENT))
ad1357
+#define STREAM_CHANNEL_CLIENT_GET_CLASS(obj) \
ad1357
+    (G_TYPE_INSTANCE_GET_CLASS((obj), TYPE_STREAM_CHANNEL_CLIENT, StreamChannelClientClass))
ad1357
+
ad1357
+typedef struct StreamChannelClient StreamChannelClient;
ad1357
+typedef struct StreamChannelClientClass StreamChannelClientClass;
ad1357
+
ad1357
+/* we need to inherit from CommonGraphicsChannelClient
ad1357
+ * to get buffer handling */
ad1357
+struct StreamChannelClient {
ad1357
+    CommonGraphicsChannelClient parent;
ad1357
+};
ad1357
+
ad1357
+struct StreamChannelClientClass {
ad1357
+    CommonGraphicsChannelClientClass parent_class;
ad1357
+};
ad1357
+
ad1357
+GType stream_channel_client_get_type(void) G_GNUC_CONST;
ad1357
+
ad1357
+G_DEFINE_TYPE(StreamChannelClient, stream_channel_client, TYPE_COMMON_GRAPHICS_CHANNEL_CLIENT)
ad1357
+
ad1357
+struct StreamChannel {
ad1357
+    RedChannel parent;
ad1357
+};
ad1357
+
ad1357
+struct StreamChannelClass {
ad1357
+    RedChannelClass parent_class;
ad1357
+};
ad1357
+
ad1357
+G_DEFINE_TYPE(StreamChannel, stream_channel, RED_TYPE_CHANNEL)
ad1357
+
ad1357
+static void stream_channel_client_on_disconnect(RedChannelClient *rcc);
ad1357
+
ad1357
+static void
ad1357
+stream_channel_client_class_init(StreamChannelClientClass *klass)
ad1357
+{
ad1357
+    RedChannelClientClass *channel_class = RED_CHANNEL_CLIENT_CLASS(klass);
ad1357
+
ad1357
+    channel_class->on_disconnect = stream_channel_client_on_disconnect;
ad1357
+}
ad1357
+
ad1357
+static void
ad1357
+stream_channel_client_init(StreamChannelClient *client)
ad1357
+{
ad1357
+}
ad1357
+
ad1357
+static void
ad1357
+stream_channel_client_on_disconnect(RedChannelClient *rcc)
ad1357
+{
ad1357
+}
ad1357
+
ad1357
+static StreamChannelClient*
ad1357
+stream_channel_client_new(StreamChannel *channel, RedClient *client, RedsStream *stream,
ad1357
+                          int mig_target, RedChannelCapabilities *caps)
ad1357
+{
ad1357
+    StreamChannelClient *rcc;
ad1357
+
ad1357
+    rcc = g_initable_new(TYPE_STREAM_CHANNEL_CLIENT,
ad1357
+                         NULL, NULL,
ad1357
+                         "channel", channel,
ad1357
+                         "client", client,
ad1357
+                         "stream", stream,
ad1357
+                         "monitor-latency", FALSE,
ad1357
+                         "caps", caps,
ad1357
+                         NULL);
ad1357
+
ad1357
+    return rcc;
ad1357
+}
ad1357
+
ad1357
+static void
ad1357
+stream_channel_send_item(RedChannelClient *rcc, RedPipeItem *pipe_item)
ad1357
+{
ad1357
+    switch (pipe_item->type) {
ad1357
+    default:
ad1357
+        spice_error("invalid pipe item type");
ad1357
+    }
ad1357
+
ad1357
+    red_channel_client_begin_send_message(rcc);
ad1357
+}
ad1357
+
ad1357
+StreamChannel*
ad1357
+stream_channel_new(RedsState *server, uint32_t id)
ad1357
+{
ad1357
+    return g_object_new(TYPE_STREAM_CHANNEL,
ad1357
+                        "spice-server", server,
ad1357
+                        "core-interface", reds_get_core_interface(server),
ad1357
+                        "channel-type", SPICE_CHANNEL_DISPLAY,
ad1357
+                        // TODO this id should be after all qxl devices
ad1357
+                        "id", id,
ad1357
+                        "migration-flags", 0,
ad1357
+                        "handle-acks", TRUE, // TODO sure ??
ad1357
+                        NULL);
ad1357
+}
ad1357
+
ad1357
+static void
ad1357
+stream_channel_connect(RedChannel *red_channel, RedClient *red_client, RedsStream *stream,
ad1357
+                       int migration, RedChannelCapabilities *caps)
ad1357
+{
ad1357
+    StreamChannel *channel = STREAM_CHANNEL(red_channel);
ad1357
+    StreamChannelClient *client;
ad1357
+
ad1357
+    spice_return_if_fail(stream != NULL);
ad1357
+
ad1357
+    client = stream_channel_client_new(channel, red_client, stream, migration, caps);
ad1357
+    spice_return_if_fail(client != NULL);
ad1357
+}
ad1357
+
ad1357
+static void
ad1357
+stream_channel_constructed(GObject *object)
ad1357
+{
ad1357
+    ClientCbs client_cbs = { NULL, };
ad1357
+    RedChannel *red_channel = RED_CHANNEL(object);
ad1357
+    RedsState *reds = red_channel_get_server(red_channel);
ad1357
+
ad1357
+    G_OBJECT_CLASS(stream_channel_parent_class)->constructed(object);
ad1357
+
ad1357
+    client_cbs.connect = stream_channel_connect;
ad1357
+    red_channel_register_client_cbs(red_channel, &client_cbs, NULL);
ad1357
+
ad1357
+    reds_register_channel(reds, red_channel);
ad1357
+}
ad1357
+
ad1357
+static void
ad1357
+stream_channel_class_init(StreamChannelClass *klass)
ad1357
+{
ad1357
+    GObjectClass *object_class = G_OBJECT_CLASS(klass);
ad1357
+    RedChannelClass *channel_class = RED_CHANNEL_CLASS(klass);
ad1357
+
ad1357
+    object_class->constructed = stream_channel_constructed;
ad1357
+
ad1357
+    channel_class->parser = spice_get_client_channel_parser(SPICE_CHANNEL_DISPLAY, NULL);
ad1357
+    channel_class->handle_message = red_channel_client_handle_message;
ad1357
+
ad1357
+    channel_class->send_item = stream_channel_send_item;
ad1357
+}
ad1357
+
ad1357
+static void
ad1357
+stream_channel_init(StreamChannel *channel)
ad1357
+{
ad1357
+}
ad1357
diff --git a/server/stream-channel.h b/server/stream-channel.h
ad1357
new file mode 100644
ad1357
index 000000000..e50e17e9e
ad1357
--- /dev/null
ad1357
+++ b/server/stream-channel.h
ad1357
@@ -0,0 +1,53 @@
ad1357
+/* -*- Mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- */
ad1357
+/*
ad1357
+   Copyright (C) 2017 Red Hat, Inc.
ad1357
+
ad1357
+   This library is free software; you can redistribute it and/or
ad1357
+   modify it under the terms of the GNU Lesser General Public
ad1357
+   License as published by the Free Software Foundation; either
ad1357
+   version 2.1 of the License, or (at your option) any later version.
ad1357
+
ad1357
+   This library is distributed in the hope that it will be useful,
ad1357
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
ad1357
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
ad1357
+   Lesser General Public License for more details.
ad1357
+
ad1357
+   You should have received a copy of the GNU Lesser General Public
ad1357
+   License along with this library; if not, see <http://www.gnu.org/licenses/>.
ad1357
+*/
ad1357
+
ad1357
+#ifndef STREAM_CHANNEL_H_
ad1357
+#define STREAM_CHANNEL_H_
ad1357
+
ad1357
+#include "red-channel.h"
ad1357
+
ad1357
+G_BEGIN_DECLS
ad1357
+
ad1357
+/**
ad1357
+ * This type it's a RedChannel class which implement display
ad1357
+ * channel with input only by stream.
ad1357
+ * A pointer to StreamChannel can be converted to a RedChannel.
ad1357
+ */
ad1357
+typedef struct StreamChannel StreamChannel;
ad1357
+typedef struct StreamChannelClass StreamChannelClass;
ad1357
+
ad1357
+#define TYPE_STREAM_CHANNEL stream_channel_get_type()
ad1357
+
ad1357
+#define STREAM_CHANNEL(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), TYPE_STREAM_CHANNEL, StreamChannel))
ad1357
+#define STREAM_CHANNEL_CLASS(klass) \
ad1357
+    (G_TYPE_CHECK_CLASS_CAST((klass), TYPE_STREAM_CHANNEL, StreamChannelClass))
ad1357
+#define IS_STREAM_CHANNEL(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), TYPE_STREAM_CHANNEL))
ad1357
+#define IS_STREAM_CHANNEL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), TYPE_STREAM_CHANNEL))
ad1357
+#define STREAM_CHANNEL_GET_CLASS(obj) \
ad1357
+    (G_TYPE_INSTANCE_GET_CLASS((obj), TYPE_STREAM_CHANNEL, StreamChannelClass))
ad1357
+
ad1357
+GType stream_channel_get_type(void) G_GNUC_CONST;
ad1357
+
ad1357
+/**
ad1357
+ * Create StreamChannel.
ad1357
+ */
ad1357
+StreamChannel* stream_channel_new(RedsState *server, uint32_t id);
ad1357
+
ad1357
+G_END_DECLS
ad1357
+
ad1357
+#endif /* STREAM_CHANNEL_H_ */