[Spice-devel] [PATCH spice-server v2 3/7] fixup! Convert RedChannelClient hierarchy to GObject

Frediano Ziglio fziglio at redhat.com
Fri Sep 30 13:21:48 UTC 2016


Reduce diff.
Remove some style changes.
Use declarations instead of moving functions.

Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
---
 server/red-channel-client.c       | 171 +++++++++++++++++++-------------------
 server/red-channel.h              |   2 +-
 server/reds.h                     |   1 -
 server/smartcard-channel-client.c |   2 +-
 server/smartcard.c                |  14 ++--
 server/tests/test_display_base.c  |   4 +-
 6 files changed, 99 insertions(+), 95 deletions(-)

diff --git a/server/red-channel-client.c b/server/red-channel-client.c
index cfd35f7..5b209d8 100644
--- a/server/red-channel-client.c
+++ b/server/red-channel-client.c
@@ -37,6 +37,9 @@
 #include "red-channel-client-private.h"
 #include "red-channel.h"
 
+static const SpiceDataHeaderOpaque full_header_wrapper;
+static const SpiceDataHeaderOpaque mini_header_wrapper;
+static void red_channel_client_destroy_remote_caps(RedChannelClient* rcc);
 static void red_channel_client_initable_interface_init(GInitableIface *iface);
 
 G_DEFINE_TYPE_WITH_CODE(RedChannelClient, red_channel_client, G_TYPE_OBJECT,
@@ -86,82 +89,6 @@ typedef struct MarkerPipeItem {
     gboolean *item_in_pipe;
 } MarkerPipeItem;
 
-static uint32_t full_header_get_msg_size(SpiceDataHeaderOpaque *header)
-{
-    return GUINT32_FROM_LE(((SpiceDataHeader *)header->data)->size);
-}
-
-static uint32_t mini_header_get_msg_size(SpiceDataHeaderOpaque *header)
-{
-    return GUINT32_FROM_LE(((SpiceMiniDataHeader *)header->data)->size);
-}
-
-static uint16_t full_header_get_msg_type(SpiceDataHeaderOpaque *header)
-{
-    return GUINT16_FROM_LE(((SpiceDataHeader *)header->data)->type);
-}
-
-static uint16_t mini_header_get_msg_type(SpiceDataHeaderOpaque *header)
-{
-    return GUINT16_FROM_LE(((SpiceMiniDataHeader *)header->data)->type);
-}
-
-static void full_header_set_msg_type(SpiceDataHeaderOpaque *header, uint16_t type)
-{
-    ((SpiceDataHeader *)header->data)->type = GUINT16_TO_LE(type);
-}
-
-static void mini_header_set_msg_type(SpiceDataHeaderOpaque *header, uint16_t type)
-{
-    ((SpiceMiniDataHeader *)header->data)->type = GUINT16_TO_LE(type);
-}
-
-static void full_header_set_msg_size(SpiceDataHeaderOpaque *header, uint32_t size)
-{
-    ((SpiceDataHeader *)header->data)->size = GUINT32_TO_LE(size);
-}
-
-static void mini_header_set_msg_size(SpiceDataHeaderOpaque *header, uint32_t size)
-{
-    ((SpiceMiniDataHeader *)header->data)->size = GUINT32_TO_LE(size);
-}
-
-static void full_header_set_msg_serial(SpiceDataHeaderOpaque *header, uint64_t serial)
-{
-    ((SpiceDataHeader *)header->data)->serial = GUINT64_TO_LE(serial);
-}
-
-static void mini_header_set_msg_serial(SpiceDataHeaderOpaque *header, uint64_t serial)
-{
-    /* ignore serial, not supported by mini header */
-}
-
-static void full_header_set_msg_sub_list(SpiceDataHeaderOpaque *header, uint32_t sub_list)
-{
-    ((SpiceDataHeader *)header->data)->sub_list = GUINT32_TO_LE(sub_list);
-}
-
-static void mini_header_set_msg_sub_list(SpiceDataHeaderOpaque *header, uint32_t sub_list)
-{
-    spice_error("attempt to set header sub list on mini header");
-}
-
-static const SpiceDataHeaderOpaque full_header_wrapper = {NULL, sizeof(SpiceDataHeader),
-                                                          full_header_set_msg_type,
-                                                          full_header_set_msg_size,
-                                                          full_header_set_msg_serial,
-                                                          full_header_set_msg_sub_list,
-                                                          full_header_get_msg_type,
-                                                          full_header_get_msg_size};
-
-static const SpiceDataHeaderOpaque mini_header_wrapper = {NULL, sizeof(SpiceMiniDataHeader),
-                                                          mini_header_set_msg_type,
-                                                          mini_header_set_msg_size,
-                                                          mini_header_set_msg_serial,
-                                                          mini_header_set_msg_sub_list,
-                                                          mini_header_get_msg_type,
-                                                          mini_header_get_msg_size};
-
 static void red_channel_client_start_ping_timer(RedChannelClient *rcc, uint32_t timeout)
 {
     if (!rcc->priv->latency_monitor.timer) {
@@ -292,14 +219,6 @@ red_channel_client_set_property(GObject *object,
     }
 }
 
-static void red_channel_client_destroy_remote_caps(RedChannelClient* rcc)
-{
-    rcc->priv->remote_caps.num_common_caps = 0;
-    free(rcc->priv->remote_caps.common_caps);
-    rcc->priv->remote_caps.num_caps = 0;
-    free(rcc->priv->remote_caps.caps);
-}
-
 static void
 red_channel_client_finalize(GObject *object)
 {
@@ -658,6 +577,14 @@ static gboolean red_channel_client_pipe_remove(RedChannelClient *rcc, RedPipeIte
     return g_queue_remove(&rcc->priv->pipe, item);
 }
 
+static void red_channel_client_destroy_remote_caps(RedChannelClient* rcc)
+{
+    rcc->priv->remote_caps.num_common_caps = 0;
+    free(rcc->priv->remote_caps.common_caps);
+    rcc->priv->remote_caps.num_caps = 0;
+    free(rcc->priv->remote_caps.caps);
+}
+
 int red_channel_client_test_remote_common_cap(RedChannelClient *rcc, uint32_t cap)
 {
     return test_capability(rcc->priv->remote_caps.common_caps,
@@ -821,6 +748,82 @@ static void red_channel_client_event(int fd, int event, void *data)
     g_object_unref(rcc);
 }
 
+static uint32_t full_header_get_msg_size(SpiceDataHeaderOpaque *header)
+{
+    return GUINT32_FROM_LE(((SpiceDataHeader *)header->data)->size);
+}
+
+static uint32_t mini_header_get_msg_size(SpiceDataHeaderOpaque *header)
+{
+    return GUINT32_FROM_LE(((SpiceMiniDataHeader *)header->data)->size);
+}
+
+static uint16_t full_header_get_msg_type(SpiceDataHeaderOpaque *header)
+{
+    return GUINT16_FROM_LE(((SpiceDataHeader *)header->data)->type);
+}
+
+static uint16_t mini_header_get_msg_type(SpiceDataHeaderOpaque *header)
+{
+    return GUINT16_FROM_LE(((SpiceMiniDataHeader *)header->data)->type);
+}
+
+static void full_header_set_msg_type(SpiceDataHeaderOpaque *header, uint16_t type)
+{
+    ((SpiceDataHeader *)header->data)->type = GUINT16_TO_LE(type);
+}
+
+static void mini_header_set_msg_type(SpiceDataHeaderOpaque *header, uint16_t type)
+{
+    ((SpiceMiniDataHeader *)header->data)->type = GUINT16_TO_LE(type);
+}
+
+static void full_header_set_msg_size(SpiceDataHeaderOpaque *header, uint32_t size)
+{
+    ((SpiceDataHeader *)header->data)->size = GUINT32_TO_LE(size);
+}
+
+static void mini_header_set_msg_size(SpiceDataHeaderOpaque *header, uint32_t size)
+{
+    ((SpiceMiniDataHeader *)header->data)->size = GUINT32_TO_LE(size);
+}
+
+static void full_header_set_msg_serial(SpiceDataHeaderOpaque *header, uint64_t serial)
+{
+    ((SpiceDataHeader *)header->data)->serial = GUINT64_TO_LE(serial);
+}
+
+static void mini_header_set_msg_serial(SpiceDataHeaderOpaque *header, uint64_t serial)
+{
+    /* ignore serial, not supported by mini header */
+}
+
+static void full_header_set_msg_sub_list(SpiceDataHeaderOpaque *header, uint32_t sub_list)
+{
+    ((SpiceDataHeader *)header->data)->sub_list = GUINT32_TO_LE(sub_list);
+}
+
+static void mini_header_set_msg_sub_list(SpiceDataHeaderOpaque *header, uint32_t sub_list)
+{
+    spice_error("attempt to set header sub list on mini header");
+}
+
+static const SpiceDataHeaderOpaque full_header_wrapper = {NULL, sizeof(SpiceDataHeader),
+                                                          full_header_set_msg_type,
+                                                          full_header_set_msg_size,
+                                                          full_header_set_msg_serial,
+                                                          full_header_set_msg_sub_list,
+                                                          full_header_get_msg_type,
+                                                          full_header_get_msg_size};
+
+static const SpiceDataHeaderOpaque mini_header_wrapper = {NULL, sizeof(SpiceMiniDataHeader),
+                                                          mini_header_set_msg_type,
+                                                          mini_header_set_msg_size,
+                                                          mini_header_set_msg_serial,
+                                                          mini_header_set_msg_sub_list,
+                                                          mini_header_get_msg_type,
+                                                          mini_header_get_msg_size};
+
 static int red_channel_client_pre_create_validate(RedChannel *channel, RedClient  *client)
 {
     if (red_client_get_channel(client, channel->type, channel->id)) {
diff --git a/server/red-channel.h b/server/red-channel.h
index e76bce2..8818a04 100644
--- a/server/red-channel.h
+++ b/server/red-channel.h
@@ -95,8 +95,8 @@ typedef struct OutgoingHandlerInterface {
 
 typedef struct RedChannel RedChannel;
 typedef struct RedChannelClient RedChannelClient;
-typedef struct MainChannelClient MainChannelClient;
 typedef struct RedClient RedClient;
+typedef struct MainChannelClient MainChannelClient;
 
 typedef uint8_t *(*channel_alloc_msg_recv_buf_proc)(RedChannelClient *channel,
                                                     uint16_t type, uint32_t size);
diff --git a/server/reds.h b/server/reds.h
index 49fc8d9..cd62fc1 100644
--- a/server/reds.h
+++ b/server/reds.h
@@ -27,7 +27,6 @@
 #include "char-device.h"
 #include "spice.h"
 #include "red-channel.h"
-#include "main-channel-client.h"
 #include "main-dispatcher.h"
 #include "migration-protocol.h"
 
diff --git a/server/smartcard-channel-client.c b/server/smartcard-channel-client.c
index 51a2aa7..76b8eed 100644
--- a/server/smartcard-channel-client.c
+++ b/server/smartcard-channel-client.c
@@ -218,7 +218,7 @@ void smartcard_channel_client_send_data(RedChannelClient *rcc,
 
 void smartcard_channel_client_send_error(RedChannelClient *rcc, SpiceMarshaller *m, RedPipeItem *item)
 {
-    RedErrorItem* error_item = (RedErrorItem*)item;
+    RedErrorItem* error_item = SPICE_UPCAST(RedErrorItem, item);
 
     smartcard_channel_client_send_data(rcc, m, item, &error_item->vheader);
 }
diff --git a/server/smartcard.c b/server/smartcard.c
index 769bd40..13eed80 100644
--- a/server/smartcard.c
+++ b/server/smartcard.c
@@ -143,11 +143,12 @@ static void smartcard_send_msg_to_client(RedPipeItem *msg,
                                          void *opaque)
 {
     RedCharDeviceSmartcard *dev = opaque;
-    RedClient *this_client = red_channel_client_get_client(RED_CHANNEL_CLIENT(dev->priv->scc));
+    RedChannelClient *rcc = RED_CHANNEL_CLIENT(dev->priv->scc);
 
-    spice_assert(dev->priv->scc && this_client == client);
+    spice_assert(dev->priv->scc &&
+                 red_channel_client_get_client(rcc) == client);
     red_pipe_item_ref(msg);
-    smartcard_channel_client_pipe_add_push(RED_CHANNEL_CLIENT(dev->priv->scc), msg);
+    smartcard_channel_client_pipe_add_push(rcc, msg);
 }
 
 static void smartcard_send_tokens_to_client(RedClient *client, uint32_t tokens, void *opaque)
@@ -158,11 +159,12 @@ static void smartcard_send_tokens_to_client(RedClient *client, uint32_t tokens,
 static void smartcard_remove_client(RedClient *client, void *opaque)
 {
     RedCharDeviceSmartcard *dev = opaque;
-    RedClient *this_client = red_channel_client_get_client(RED_CHANNEL_CLIENT(dev->priv->scc));
+    RedChannelClient *rcc = RED_CHANNEL_CLIENT(dev->priv->scc);
 
     spice_printerr("smartcard  dev %p, client %p", dev, client);
-    spice_assert(dev->priv->scc && this_client == client);
-    red_channel_client_shutdown(RED_CHANNEL_CLIENT(dev->priv->scc));
+    spice_assert(dev->priv->scc &&
+                 red_channel_client_get_client(rcc) == client);
+    red_channel_client_shutdown(rcc);
 }
 
 RedMsgItem *smartcard_char_device_on_message_from_device(RedCharDeviceSmartcard *dev,
diff --git a/server/tests/test_display_base.c b/server/tests/test_display_base.c
index 674c355..8e577c9 100644
--- a/server/tests/test_display_base.c
+++ b/server/tests/test_display_base.c
@@ -26,10 +26,10 @@
 #include <sys/select.h>
 #include <sys/types.h>
 #include <getopt.h>
-#include <spice/qxl_dev.h>
-#include <common/mem.h>
 
 #include "spice.h"
+#include <spice/qxl_dev.h>
+
 #include "test_display_base.h"
 #include "red-channel.h"
 
-- 
2.7.4



More information about the Spice-devel mailing list