[Spice-devel] [PATCH spice-gtk 2/5] Introduce SpiceMiniHeaderClass and SpiceFullHeaderClass
Yonit Halperin
yhalperi at redhat.com
Sun Jan 8 00:53:47 PST 2012
Part of adding support for SPICE_COMMON_CAP_MINI_HEADER
---
gtk/Makefile.am | 2 +
gtk/spice-header.c | 208 ++++++++++++++++++++++++++++++++++++++++++++++++++++
gtk/spice-header.h | 123 +++++++++++++++++++++++++++++++
3 files changed, 333 insertions(+), 0 deletions(-)
create mode 100644 gtk/spice-header.c
create mode 100644 gtk/spice-header.h
diff --git a/gtk/Makefile.am b/gtk/Makefile.am
index 85a78a6..072bed5 100644
--- a/gtk/Makefile.am
+++ b/gtk/Makefile.am
@@ -200,6 +200,8 @@ libspice_client_glib_2_0_la_SOURCES = \
spice-channel.c \
spice-channel-cache.h \
spice-channel-priv.h \
+ spice-header.h \
+ spice-header.c \
coroutine.h \
gio-coroutine.c \
gio-coroutine.h \
diff --git a/gtk/spice-header.c b/gtk/spice-header.c
new file mode 100644
index 0000000..3a773ec
--- /dev/null
+++ b/gtk/spice-header.c
@@ -0,0 +1,208 @@
+/* -*- Mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- */
+/*
+ Copyright (C) 2010 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/>.
+*/
+#include <spice/protocol.h>
+
+#include "spice-header.h"
+#include "spice-client.h"
+#include "spice-common.h"
+
+#define SPICE_HEADER_WRAPPER_GET_PRIVATE(obj) \
+ (G_TYPE_INSTANCE_GET_PRIVATE ((obj), SPICE_TYPE_HEADER_WRAPPER, SpiceHeaderWrapperPrivate))
+
+G_DEFINE_TYPE(SpiceHeaderWrapper, spice_header_wrapper, G_TYPE_OBJECT);
+G_DEFINE_TYPE(SpiceMiniHeader, spice_mini_header, SPICE_TYPE_HEADER_WRAPPER);
+G_DEFINE_TYPE(SpiceFullHeader, spice_full_header, SPICE_TYPE_HEADER_WRAPPER);
+
+struct _SpiceHeaderWrapperPrivate {
+ uint8_t *data;
+};
+
+static void spice_header_wrapper_class_init(SpiceHeaderWrapperClass *klass)
+{
+ klass->set_msg_type = NULL;
+ klass->set_msg_size = NULL;
+ klass->get_msg_type = NULL;
+ klass->get_msg_size = NULL;
+ klass->get_header_size = NULL;
+
+ g_type_class_add_private(klass, sizeof(SpiceHeaderWrapperPrivate));
+}
+
+static void spice_header_wrapper_init(SpiceHeaderWrapper *header)
+{
+ header->priv = SPICE_HEADER_WRAPPER_GET_PRIVATE(header);
+ header->priv->data = NULL;
+}
+
+
+void spice_header_wrapper_set_data(SpiceHeaderWrapper *header, uint8_t *data)
+{
+ header->priv->data = data;
+}
+
+void spice_header_wrapper_set_msg_type(SpiceHeaderWrapper *header, uint16_t type)
+{
+ g_return_if_fail(SPICE_IS_HEADER_WRAPPER(header));
+ SPICE_HEADER_WRAPPER_GET_CLASS(header)->set_msg_type(header, type);
+}
+
+void spice_header_wrapper_set_msg_size(SpiceHeaderWrapper *header, uint32_t size)
+{
+ g_return_if_fail(SPICE_IS_HEADER_WRAPPER(header));
+ SPICE_HEADER_WRAPPER_GET_CLASS(header)->set_msg_size(header, size);
+}
+
+uint16_t spice_header_wrapper_get_msg_type(SpiceHeaderWrapper *header)
+{
+ g_return_val_if_fail(SPICE_IS_HEADER_WRAPPER(header), 0);
+ return SPICE_HEADER_WRAPPER_GET_CLASS(header)->get_msg_type(header);
+}
+
+uint32_t spice_header_wrapper_get_msg_size(SpiceHeaderWrapper *header)
+{
+ g_return_val_if_fail(SPICE_IS_HEADER_WRAPPER(header), 0);
+ return SPICE_HEADER_WRAPPER_GET_CLASS(header)->get_msg_size(header);
+}
+
+int spice_header_wrapper_get_header_size(SpiceHeaderWrapper *header)
+{
+ g_return_val_if_fail(SPICE_IS_HEADER_WRAPPER(header), 0);
+ return SPICE_HEADER_WRAPPER_GET_CLASS(header)->get_header_size(header);
+}
+
+static void spice_mini_header_set_msg_type(SpiceHeaderWrapper *header, uint16_t type)
+{
+ g_return_if_fail(header->priv->data != NULL);
+ ((SpiceMiniDataHeader *)header->priv->data)->type = type;
+}
+
+static void spice_mini_header_set_msg_size(SpiceHeaderWrapper *header, uint32_t size)
+{
+ g_return_if_fail(header->priv->data != NULL);
+ ((SpiceMiniDataHeader *)header->priv->data)->size = size;
+}
+
+static uint16_t spice_mini_header_get_msg_type(SpiceHeaderWrapper *header)
+{
+ g_return_val_if_fail(header->priv->data != NULL, 0);
+ return ((SpiceMiniDataHeader *)header->priv->data)->type;
+}
+
+static uint32_t spice_mini_header_get_msg_size(SpiceHeaderWrapper *header)
+{
+ g_return_val_if_fail(header->priv->data != NULL, 0);
+ return ((SpiceMiniDataHeader *)header->priv->data)->size;
+}
+
+static int spice_mini_header_get_header_size(SpiceHeaderWrapper *header)
+{
+ return sizeof(SpiceMiniDataHeader);
+}
+
+static void spice_mini_header_init(SpiceMiniHeader *header)
+{
+}
+
+static void spice_mini_header_class_init(SpiceMiniHeaderClass *klass)
+{
+ SpiceHeaderWrapperClass *parent_class = SPICE_HEADER_WRAPPER_CLASS(klass);
+
+ parent_class->set_msg_type = spice_mini_header_set_msg_type;
+ parent_class->set_msg_size = spice_mini_header_set_msg_size;
+ parent_class->get_msg_type = spice_mini_header_get_msg_type;
+ parent_class->get_msg_size = spice_mini_header_get_msg_size;
+ parent_class->get_header_size = spice_mini_header_get_header_size;
+
+}
+
+static void spice_full_header_set_msg_type(SpiceHeaderWrapper *header, uint16_t type)
+{
+ g_return_if_fail(header->priv->data != NULL);
+ ((SpiceDataHeader *)header->priv->data)->type = type;
+}
+
+static void spice_full_header_set_msg_size(SpiceHeaderWrapper *header, uint32_t size)
+{
+ g_return_if_fail(header->priv->data != NULL);
+ ((SpiceDataHeader *)header->priv->data)->size = size;
+}
+
+static uint16_t spice_full_header_get_msg_type(SpiceHeaderWrapper *header)
+{
+ g_return_val_if_fail(header->priv->data != NULL, 0);
+ return ((SpiceDataHeader *)header->priv->data)->type;
+}
+
+static uint32_t spice_full_header_get_msg_size(SpiceHeaderWrapper *header)
+{
+ g_return_val_if_fail(header->priv->data != NULL, 0);
+ return ((SpiceDataHeader *)header->priv->data)->size;
+}
+
+static int spice_full_header_get_header_size(SpiceHeaderWrapper *header)
+{
+ return sizeof(SpiceDataHeader);
+}
+
+void spice_full_header_set_msg_serial(SpiceFullHeader *header, uint64_t serial)
+{
+ SpiceHeaderWrapper *parent = SPICE_HEADER_WRAPPER(header);
+
+ g_return_if_fail(parent->priv->data != NULL);
+ ((SpiceDataHeader *)parent->priv->data)->serial = serial;
+}
+
+void spice_full_header_set_msg_sub_list(SpiceFullHeader *header, uint32_t sub_list)
+{
+ SpiceHeaderWrapper *parent = SPICE_HEADER_WRAPPER(header);
+
+ g_return_if_fail(parent->priv->data != NULL);
+ ((SpiceDataHeader *)parent->priv->data)->sub_list = sub_list;
+}
+
+uint64_t spice_full_header_get_msg_serial(SpiceFullHeader *header)
+{
+ SpiceHeaderWrapper *parent = SPICE_HEADER_WRAPPER(header);
+
+ g_return_val_if_fail(parent->priv->data != NULL, 0);
+ return ((SpiceDataHeader *)parent->priv->data)->serial;
+}
+
+uint32_t spice_full_header_get_msg_sub_list(SpiceFullHeader *header)
+{
+ SpiceHeaderWrapper *parent = SPICE_HEADER_WRAPPER(header);
+
+ g_return_val_if_fail(parent->priv->data != NULL, 0);
+ return ((SpiceDataHeader *)parent->priv->data)->sub_list;
+}
+
+
+static void spice_full_header_init(SpiceFullHeader *header)
+{
+}
+
+static void spice_full_header_class_init(SpiceFullHeaderClass *klass)
+{
+ SpiceHeaderWrapperClass *parent_class = SPICE_HEADER_WRAPPER_CLASS(klass);
+
+ parent_class->set_msg_type = spice_full_header_set_msg_type;
+ parent_class->set_msg_size = spice_full_header_set_msg_size;
+ parent_class->get_msg_type = spice_full_header_get_msg_type;
+ parent_class->get_msg_size = spice_full_header_get_msg_size;
+ parent_class->get_header_size = spice_full_header_get_header_size;
+}
diff --git a/gtk/spice-header.h b/gtk/spice-header.h
new file mode 100644
index 0000000..d1bd2ba
--- /dev/null
+++ b/gtk/spice-header.h
@@ -0,0 +1,123 @@
+/* -*- Mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- */
+/*
+ Copyright (C) 2010 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 __SPICE_HEADER_H__
+#define __SPICE_HEADER_H__
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define MAX_SPICE_DATA_HEADER_SIZE sizeof(SpiceDataHeader)
+
+#define SPICE_TYPE_HEADER_WRAPPER (spice_header_wrapper_get_type ())
+#define SPICE_HEADER_WRAPPER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj),\
+ SPICE_TYPE_HEADER_WRAPPER, \
+ SpiceHeaderWrapper))
+#define SPICE_HEADER_WRAPPER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass),\
+ SPICE_TYPE_HEADER_WRAPPER,\
+ SpiceHeaderWrapperClass))
+#define SPICE_IS_HEADER_WRAPPER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj),\
+ SPICE_TYPE_HEADER_WRAPPER))
+#define SPICE_IS_HEADER_WRAPPER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass),\
+ SPICE_TYPE_HEADER_WRAPPER))
+#define SPICE_HEADER_WRAPPER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj),\
+ SPICE_TYPE_HEADER_WRAPPER, SpiceHeaderWrapperClass))
+
+typedef struct _SpiceHeaderWrapperPrivate SpiceHeaderWrapperPrivate;
+typedef struct _SpiceHeaderWrapper SpiceHeaderWrapper;
+typedef struct _SpiceHeaderWrapperClass SpiceHeaderWrapperClass;
+
+struct _SpiceHeaderWrapper
+{
+ GObject parent;
+ SpiceHeaderWrapperPrivate *priv;
+};
+
+struct _SpiceHeaderWrapperClass
+{
+ GObjectClass parent_class;
+
+ void (*set_msg_type)(SpiceHeaderWrapper *header, uint16_t type);
+ void (*set_msg_size)(SpiceHeaderWrapper *header, uint32_t size);
+ uint16_t (*get_msg_type)(SpiceHeaderWrapper *header);
+ uint32_t (*get_msg_size)(SpiceHeaderWrapper *header);
+
+ int (*get_header_size)(SpiceHeaderWrapper *header);
+};
+
+void spice_header_wrapper_set_data(SpiceHeaderWrapper *header, uint8_t *data);
+
+void spice_header_wrapper_set_msg_type(SpiceHeaderWrapper *header, uint16_t type);
+void spice_header_wrapper_set_msg_size(SpiceHeaderWrapper *header, uint32_t size);
+uint16_t spice_header_wrapper_get_msg_type(SpiceHeaderWrapper *header);
+uint32_t spice_header_wrapper_get_msg_size(SpiceHeaderWrapper *header);
+int spice_header_wrapper_get_header_size(SpiceHeaderWrapper *header);
+
+GType spice_header_wrapper_get_type(void);
+
+#define SPICE_TYPE_MINI_HEADER (spice_mini_header_get_type())
+#define SPICE_MINI_HEADER(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), SPICE_TYPE_MINI_HEADER, SpiceMiniHeader))
+#define SPICE_MINI_HEADER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), SPICE_TYPE_MINI_HEADER, SpiceMiniHeaderClass))
+#define SPICE_IS_MINI_HEADER(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), SPICE_TYPE_MINI_HEADER))
+#define SPICE_IS_MINI_HEADER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), SPICE_TYPE_MINI_HEADER))
+#define SPICE_MINI_HEADER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), SPICE_TYPE_MINI_HEADER, SpiceMiniHeaderClass))
+
+typedef struct _SpiceMiniHeader SpiceMiniHeader;
+typedef struct _SpiceMiniHeaderClass SpiceMiniHeaderClass;
+
+struct _SpiceMiniHeader {
+ SpiceHeaderWrapper parent;
+
+};
+
+struct _SpiceMiniHeaderClass {
+ SpiceHeaderWrapperClass parent_class;
+
+};
+
+GType spice_mini_header_get_type(void);
+
+#define SPICE_TYPE_FULL_HEADER (spice_full_header_get_type())
+#define SPICE_FULL_HEADER(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), SPICE_TYPE_FULL_HEADER, SpiceFullHeader))
+#define SPICE_FULL_HEADER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), SPICE_TYPE_FULL_HEADER, SpiceFullHeaderClass))
+#define SPICE_IS_FULL_HEADER(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), SPICE_TYPE_FULL_HEADER))
+#define SPICE_IS_FULL_HEADER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), SPICE_TYPE_FULL_HEADER))
+#define SPICE_FULL_HEADER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), SPICE_TYPE_FULL_HEADER, SpiceFullHeaderClass))
+
+typedef struct _SpiceFullHeader SpiceFullHeader;
+typedef struct _SpiceFullHeaderClass SpiceFullHeaderClass;
+
+struct _SpiceFullHeader {
+ SpiceHeaderWrapper parent;
+};
+
+struct _SpiceFullHeaderClass {
+ SpiceHeaderWrapperClass parent_class;
+};
+
+
+void spice_full_header_set_msg_serial(SpiceFullHeader *header, uint64_t serial);
+void spice_full_header_set_msg_sub_list(SpiceFullHeader *header, uint32_t sub_list);
+uint64_t spice_full_header_get_msg_serial(SpiceFullHeader *header);
+uint32_t spice_full_header_get_msg_sub_list(SpiceFullHeader *header);
+
+GType spice_full_header_get_type(void);
+
+G_END_DECLS
+
+#endif /* __SPICE_HEADER_H__ */
--
1.7.6.4
More information about the Spice-devel
mailing list