[Spice-devel] [RFC PATCH 06/16] stream-channel: Write a really base channel to implement the streaming

Frediano Ziglio fziglio at redhat.com
Wed Jan 25 12:42:29 UTC 2017


Currently only compile, not used and not much sense

Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
---
 server/Makefile.am      |   2 +-
 server/stream-channel.c | 194 +++++++++++++++++++++++++++++++++++++++++-
 server/stream-channel.h |  52 +++++++++++-
 3 files changed, 248 insertions(+)
 create mode 100644 server/stream-channel.c
 create mode 100644 server/stream-channel.h

diff --git a/server/Makefile.am b/server/Makefile.am
index befa55b..b293101 100644
--- a/server/Makefile.am
+++ b/server/Makefile.am
@@ -168,6 +168,8 @@ libserver_la_SOURCES =				\
 	image-encoders.h					\
 	glib-compat.h				\
 	stream-device.c				\
+	stream-channel.c			\
+	stream-channel.h			\
 	$(spice_built_sources)		\
 	$(NULL)
 
diff --git a/server/stream-channel.c b/server/stream-channel.c
new file mode 100644
index 0000000..8905c7f
--- /dev/null
+++ b/server/stream-channel.c
@@ -0,0 +1,194 @@
+/* -*- Mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- */
+/*
+   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 "red-channel-client.h"
+#include "stream-channel.h"
+#include "reds.h"
+
+#define TYPE_STREAM_CHANNEL_CLIENT stream_channel_client_get_type()
+
+#define STREAM_CHANNEL_CLIENT(obj) \
+    (G_TYPE_CHECK_INSTANCE_CAST((obj), TYPE_STREAM_CHANNEL_CLIENT, StreamChannelClient))
+#define STREAM_CHANNEL_CLIENT_CLASS(klass) \
+    (G_TYPE_CHECK_CLASS_CAST((klass), TYPE_STREAM_CHANNEL_CLIENT, StreamChannelClientClass))
+#define IS_STREAM_CHANNEL_CLIENT(obj) \
+    (G_TYPE_CHECK_INSTANCE_TYPE((obj), TYPE_STREAM_CHANNEL_CLIENT))
+#define IS_STREAM_CHANNEL_CLIENT_CLASS(klass) \
+    (G_TYPE_CHECK_CLASS_TYPE((klass), TYPE_STREAM_CHANNEL_CLIENT))
+#define STREAM_CHANNEL_CLIENT_GET_CLASS(obj) \
+    (G_TYPE_INSTANCE_GET_CLASS((obj), TYPE_STREAM_CHANNEL_CLIENT, StreamChannelClientClass))
+
+typedef struct StreamChannelClient StreamChannelClient;
+typedef struct StreamChannelClientClass StreamChannelClientClass;
+
+struct StreamChannelClient {
+    RedChannelClient parent;
+};
+
+struct StreamChannelClientClass {
+    RedChannelClientClass parent_class;
+};
+
+GType stream_channel_client_get_type(void) G_GNUC_CONST;
+
+G_DEFINE_TYPE(StreamChannelClient, stream_channel_client, RED_TYPE_CHANNEL_CLIENT)
+
+struct StreamChannel {
+    RedChannel parent;
+};
+
+struct StreamChannelClass {
+    RedChannelClass parent_class;
+};
+
+G_DEFINE_TYPE(StreamChannel, stream_channel, RED_TYPE_CHANNEL)
+
+static void
+stream_channel_client_class_init(StreamChannelClientClass *klass)
+{
+}
+
+static void
+stream_channel_client_init(StreamChannelClient *client)
+{
+}
+
+static void
+stream_channel_client_on_disconnect(RedChannelClient *rcc)
+{
+}
+
+static StreamChannelClient*
+stream_channel_client_new(StreamChannel *channel, RedClient *client, RedsStream *stream,
+                          int mig_target,
+                          uint32_t *common_caps, int num_common_caps,
+                          uint32_t *caps, int num_caps)
+{
+    StreamChannelClient *rcc;
+    GArray *common_caps_array = NULL, *caps_array = NULL;
+
+    if (common_caps) {
+        common_caps_array = g_array_sized_new(FALSE, FALSE, sizeof (*common_caps),
+                                              num_common_caps);
+        g_array_append_vals(common_caps_array, common_caps, num_common_caps);
+    }
+    if (caps) {
+        caps_array = g_array_sized_new(FALSE, FALSE, sizeof (*caps), num_caps);
+        g_array_append_vals(caps_array, caps, num_caps);
+    }
+
+    rcc = g_initable_new(TYPE_STREAM_CHANNEL_CLIENT,
+                         NULL, NULL,
+                         "channel", channel,
+                         "client", client,
+                         "stream", stream,
+                         "monitor-latency", FALSE,
+                         "common-caps", common_caps_array,
+                         "caps", caps_array,
+                         NULL);
+
+    if (caps_array) {
+        g_array_unref(caps_array);
+    }
+    if (common_caps_array) {
+        g_array_unref(common_caps_array);
+    }
+
+    return rcc;
+}
+
+static void
+stream_channel_send_item(RedChannelClient *rcc, RedPipeItem *pipe_item)
+{
+    switch (pipe_item->type) {
+    default:
+        spice_error("invalid pipe item type");
+    }
+
+    red_channel_client_begin_send_message(rcc);
+}
+
+StreamChannel*
+stream_channel_new(RedsState *server)
+{
+    return g_object_new(TYPE_STREAM_CHANNEL,
+                        "spice-server", server,
+                        "core-interface", reds_get_core_interface(server),
+                        "channel-type", SPICE_CHANNEL_DISPLAY,
+                        // TODO this id should be after all qxl devices
+                        "id", 1, // TODO proper id
+                        "migration-flags", 0,
+                        "handle-acks", TRUE, // TODO sure ??
+                        NULL);
+}
+
+static void
+stream_channel_connect(RedChannel *red_channel, RedClient *red_client, RedsStream *stream,
+                       int migration,
+                       int num_common_caps, uint32_t *common_caps,
+                       int num_caps, uint32_t *caps)
+{
+    StreamChannel *channel = STREAM_CHANNEL(red_channel);
+    StreamChannelClient *client;
+
+    spice_return_if_fail(stream != NULL);
+
+    client = stream_channel_client_new(channel, red_client, stream,
+                                       migration,
+                                       common_caps, num_common_caps,
+                                       caps, num_caps);
+    spice_return_if_fail(client != NULL);
+}
+
+static void
+stream_channel_constructed(GObject *object)
+{
+    ClientCbs client_cbs = { NULL, };
+    RedChannel *red_channel = RED_CHANNEL(object);
+    RedsState *reds = red_channel_get_server(red_channel);
+
+    G_OBJECT_CLASS(stream_channel_parent_class)->constructed(object);
+
+    client_cbs.connect = stream_channel_connect;
+    red_channel_register_client_cbs(red_channel, &client_cbs, NULL);
+
+    reds_register_channel(reds, red_channel);
+}
+
+static void
+stream_channel_class_init(StreamChannelClass *klass)
+{
+    GObjectClass *object_class = G_OBJECT_CLASS(klass);
+    RedChannelClass *channel_class = RED_CHANNEL_CLASS(klass);
+
+    object_class->constructed = stream_channel_constructed;
+
+    channel_class->parser = spice_get_client_channel_parser(SPICE_CHANNEL_DISPLAY, NULL);
+    channel_class->handle_parsed = red_channel_client_handle_message;
+
+    channel_class->on_disconnect = stream_channel_client_on_disconnect;
+    channel_class->send_item = stream_channel_send_item;
+}
+
+static void
+stream_channel_init(StreamChannel *channel)
+{
+}
diff --git a/server/stream-channel.h b/server/stream-channel.h
new file mode 100644
index 0000000..7390383
--- /dev/null
+++ b/server/stream-channel.h
@@ -0,0 +1,52 @@
+/* -*- Mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- */
+/*
+   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/>.
+*/
+#ifndef STREAM_CHANNEL_H_
+#define STREAM_CHANNEL_H_
+
+#include "red-channel.h"
+
+G_BEGIN_DECLS
+
+/**
+ * This type it's a RedChannel class which implement display
+ * channel with input only by stream.
+ * A pointer to StreamChannel can be converted to a RedChannel.
+ */
+typedef struct StreamChannel StreamChannel;
+typedef struct StreamChannelClass StreamChannelClass;
+
+#define TYPE_STREAM_CHANNEL stream_channel_get_type()
+
+#define STREAM_CHANNEL(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), TYPE_STREAM_CHANNEL, StreamChannel))
+#define STREAM_CHANNEL_CLASS(klass) \
+    (G_TYPE_CHECK_CLASS_CAST((klass), TYPE_STREAM_CHANNEL, StreamChannelClass))
+#define IS_STREAM_CHANNEL(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), TYPE_STREAM_CHANNEL))
+#define IS_STREAM_CHANNEL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), TYPE_STREAM_CHANNEL))
+#define STREAM_CHANNEL_GET_CLASS(obj) \
+    (G_TYPE_INSTANCE_GET_CLASS((obj), TYPE_STREAM_CHANNEL, StreamChannelClass))
+
+GType stream_channel_get_type(void) G_GNUC_CONST;
+
+/**
+ * Create StreamChannel.
+ */
+StreamChannel* stream_channel_new(RedsState *server);
+
+G_END_DECLS
+
+#endif /* STREAM_CHANNEL_H_ */
-- 
git-series 0.9.1


More information about the Spice-devel mailing list