[Spice-devel] [PATCH spice-server 3/3] red-channel: Move alloc_recv_buf and release_recv_buf to RedChannelClient

Frediano Ziglio fziglio at redhat.com
Tue Feb 28 09:43:35 UTC 2017


These vfuncs are more appropriate in RedChannelClient.
The buffer they allocated are related to the client stream
which is managed directly by RedChannelClient.

Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
---
Looking at the patch (mostly spicevmc.c) looks not great as
you have to have a new class but I think that these method
are much better into RedChannelClient. Also this fix multiple
client issues (another prove is on the wrong place).

About VmcChannelClient name... maybe I should add a prefix
(Red/Spice) but looking at the code is not clear the right
one, both are used.
---
 server/common-graphics-channel.c  | 21 ++++++++---
 server/inputs-channel-client.c    | 36 +++++++++++++++++++
 server/inputs-channel.c           | 34 ------------------
 server/main-channel-client.c      | 36 +++++++++++++++++++
 server/main-channel.c             | 36 -------------------
 server/red-channel-client.c       |  9 ++---
 server/red-channel-client.h       |  3 ++
 server/red-channel.c              |  3 +-
 server/red-channel.h              |  6 ----
 server/smartcard-channel-client.c | 23 ++++++++----
 server/smartcard-channel-client.h | 18 ----------
 server/smartcard.c                |  2 --
 server/sound.c                    |  8 +++--
 server/spicevmc.c                 | 75 ++++++++++++++++++++++++++++++++++++---
 14 files changed, 189 insertions(+), 121 deletions(-)

diff --git a/server/common-graphics-channel.c b/server/common-graphics-channel.c
index 6faf1d7..394a68e 100644
--- a/server/common-graphics-channel.c
+++ b/server/common-graphics-channel.c
@@ -35,11 +35,13 @@ G_DEFINE_TYPE(CommonGraphicsChannelClient, common_graphics_channel_client, RED_T
 
 #define GRAPHICS_CHANNEL_PRIVATE(o) \
     (G_TYPE_INSTANCE_GET_PRIVATE((o), TYPE_COMMON_GRAPHICS_CHANNEL, CommonGraphicsChannelPrivate))
+#define GRAPHICS_CHANNEL_CLIENT_PRIVATE(o) \
+    (G_TYPE_INSTANCE_GET_PRIVATE((o), TYPE_COMMON_GRAPHICS_CHANNEL_CLIENT, \
+    CommonGraphicsChannelClientPrivate))
 
 struct CommonGraphicsChannelPrivate
 {
     QXLInstance *qxl;
-    uint8_t recv_buf[CHANNEL_RECEIVE_BUF_SIZE];
     int during_target_migrate; /* TRUE when the client that is associated with the channel
                                   is during migration. Turned off when the vm is started.
                                   The flag is used to avoid sending messages that are artifacts
@@ -47,10 +49,14 @@ struct CommonGraphicsChannelPrivate
                                   of the primary surface) */
 };
 
+struct CommonGraphicsChannelClientPrivate {
+    uint8_t recv_buf[CHANNEL_RECEIVE_BUF_SIZE];
+};
+
+
 static uint8_t *common_alloc_recv_buf(RedChannelClient *rcc, uint16_t type, uint32_t size)
 {
-    RedChannel *channel = red_channel_client_get_channel(rcc);
-    CommonGraphicsChannel *common = COMMON_GRAPHICS_CHANNEL(channel);
+    CommonGraphicsChannelClient *common = COMMON_GRAPHICS_CHANNEL_CLIENT(rcc);
 
     /* SPICE_MSGC_MIGRATE_DATA is the only client message whose size is dynamic */
     if (type == SPICE_MSGC_MIGRATE_DATA) {
@@ -157,8 +163,6 @@ common_graphics_channel_class_init(CommonGraphicsChannelClass *klass)
     object_class->set_property = common_graphics_channel_set_property;
 
     channel_class->config_socket = common_channel_config_socket;
-    channel_class->alloc_recv_buf = common_alloc_recv_buf;
-    channel_class->release_recv_buf = common_release_recv_buf;
 
     g_object_class_install_property(object_class,
                                     PROP_QXL,
@@ -194,9 +198,16 @@ QXLInstance* common_graphics_channel_get_qxl(CommonGraphicsChannel *self)
 static void
 common_graphics_channel_client_init(CommonGraphicsChannelClient *self)
 {
+    self->priv = GRAPHICS_CHANNEL_CLIENT_PRIVATE(self);
 }
 
 static void
 common_graphics_channel_client_class_init(CommonGraphicsChannelClientClass *klass)
 {
+    RedChannelClientClass *client_class = RED_CHANNEL_CLIENT_CLASS(klass);
+
+    g_type_class_add_private(klass, sizeof(CommonGraphicsChannelClientPrivate));
+
+    client_class->alloc_recv_buf = common_alloc_recv_buf;
+    client_class->release_recv_buf = common_release_recv_buf;
 }
diff --git a/server/inputs-channel-client.c b/server/inputs-channel-client.c
index c8d33ba..a2ccf22 100644
--- a/server/inputs-channel-client.c
+++ b/server/inputs-channel-client.c
@@ -27,15 +27,51 @@ G_DEFINE_TYPE(InputsChannelClient, inputs_channel_client, RED_TYPE_CHANNEL_CLIEN
 #define INPUTS_CHANNEL_CLIENT_PRIVATE(o) \
     (G_TYPE_INSTANCE_GET_PRIVATE((o), TYPE_INPUTS_CHANNEL_CLIENT, InputsChannelClientPrivate))
 
+// TODO: RECEIVE_BUF_SIZE used to be the same for inputs_channel and main_channel
+// since it was defined once in reds.c which contained both.
+// Now that they are split we can give a more fitting value for inputs - what
+// should it be?
+#define REDS_AGENT_WINDOW_SIZE 10
+#define REDS_NUM_INTERNAL_AGENT_MESSAGES 1
+
+// approximate max receive message size
+#define RECEIVE_BUF_SIZE \
+    (4096 + (REDS_AGENT_WINDOW_SIZE + REDS_NUM_INTERNAL_AGENT_MESSAGES) * SPICE_AGENT_MAX_DATA_SIZE)
+
 struct InputsChannelClientPrivate
 {
     uint16_t motion_count;
+    uint8_t recv_buf[RECEIVE_BUF_SIZE];
 };
 
+static uint8_t *
+inputs_channel_client_alloc_msg_rcv_buf(RedChannelClient *rcc,
+                                        uint16_t type, uint32_t size)
+{
+    if (size > RECEIVE_BUF_SIZE) {
+        spice_printerr("error: too large incoming message");
+        return NULL;
+    }
+
+    InputsChannelClient *icc = INPUTS_CHANNEL_CLIENT(rcc);
+    return icc->priv->recv_buf;
+}
+
+static void
+inputs_channel_client_release_msg_rcv_buf(RedChannelClient *rcc,
+                                          uint16_t type, uint32_t size, uint8_t *msg)
+{
+}
+
 static void
 inputs_channel_client_class_init(InputsChannelClientClass *klass)
 {
+    RedChannelClientClass *client_class = RED_CHANNEL_CLIENT_CLASS(klass);
+
     g_type_class_add_private(klass, sizeof(InputsChannelClientPrivate));
+
+    client_class->alloc_recv_buf = inputs_channel_client_alloc_msg_rcv_buf;
+    client_class->release_recv_buf = inputs_channel_client_release_msg_rcv_buf;
 }
 
 static void
diff --git a/server/inputs-channel.c b/server/inputs-channel.c
index cd92e1a..674b15d 100644
--- a/server/inputs-channel.c
+++ b/server/inputs-channel.c
@@ -43,22 +43,10 @@
 #include "migration-protocol.h"
 #include "utils.h"
 
-// TODO: RECEIVE_BUF_SIZE used to be the same for inputs_channel and main_channel
-// since it was defined once in reds.c which contained both.
-// Now that they are split we can give a more fitting value for inputs - what
-// should it be?
-#define REDS_AGENT_WINDOW_SIZE 10
-#define REDS_NUM_INTERNAL_AGENT_MESSAGES 1
-
-// approximate max receive message size
-#define RECEIVE_BUF_SIZE \
-    (4096 + (REDS_AGENT_WINDOW_SIZE + REDS_NUM_INTERNAL_AGENT_MESSAGES) * SPICE_AGENT_MAX_DATA_SIZE)
-
 struct InputsChannel
 {
     RedChannel parent;
 
-    uint8_t recv_buf[RECEIVE_BUF_SIZE];
     VDAgentMouseState mouse_state;
     int src_during_migrate;
     SpiceTimer *key_modifiers_timer;
@@ -153,26 +141,6 @@ const VDAgentMouseState *inputs_channel_get_mouse_state(InputsChannel *inputs)
     return &inputs->mouse_state;
 }
 
-static uint8_t *inputs_channel_alloc_msg_rcv_buf(RedChannelClient *rcc,
-                                                 uint16_t type,
-                                                 uint32_t size)
-{
-    InputsChannel *inputs_channel = INPUTS_CHANNEL(red_channel_client_get_channel(rcc));
-
-    if (size > RECEIVE_BUF_SIZE) {
-        spice_printerr("error: too large incoming message");
-        return NULL;
-    }
-    return inputs_channel->recv_buf;
-}
-
-static void inputs_channel_release_msg_rcv_buf(RedChannelClient *rcc,
-                                               uint16_t type,
-                                               uint32_t size,
-                                               uint8_t *msg)
-{
-}
-
 #define OUTGOING_OK 0
 #define OUTGOING_FAILED -1
 #define OUTGOING_BLOCKED 1
@@ -629,8 +597,6 @@ inputs_channel_class_init(InputsChannelClass *klass)
     /* channel callbacks */
     channel_class->on_disconnect = inputs_channel_on_disconnect;
     channel_class->send_item = inputs_channel_send_item;
-    channel_class->alloc_recv_buf = inputs_channel_alloc_msg_rcv_buf;
-    channel_class->release_recv_buf = inputs_channel_release_msg_rcv_buf;
     channel_class->handle_migrate_data = inputs_channel_handle_migrate_data;
     channel_class->handle_migrate_flush_mark = inputs_channel_handle_migrate_flush_mark;
 }
diff --git a/server/main-channel-client.c b/server/main-channel-client.c
index 6aace29..902090b 100644
--- a/server/main-channel-client.c
+++ b/server/main-channel-client.c
@@ -46,6 +46,10 @@ G_DEFINE_TYPE(MainChannelClient, main_channel_client, RED_TYPE_CHANNEL_CLIENT)
 #define MAIN_CHANNEL_CLIENT_PRIVATE(o) \
     (G_TYPE_INSTANCE_GET_PRIVATE((o), TYPE_MAIN_CHANNEL_CLIENT, MainChannelClientPrivate))
 
+// approximate max receive message size for main channel
+#define MAIN_CHANNEL_RECEIVE_BUF_SIZE \
+    (4096 + (REDS_AGENT_WINDOW_SIZE + REDS_NUM_INTERNAL_AGENT_MESSAGES) * SPICE_AGENT_MAX_DATA_SIZE)
+
 struct MainChannelClientPrivate {
     uint32_t connection_id;
     uint32_t ping_id;
@@ -63,6 +67,7 @@ struct MainChannelClientPrivate {
     int mig_wait_prev_try_seamless;
     int init_sent;
     int seamless_mig_dst;
+    uint8_t recv_buf[MAIN_CHANNEL_RECEIVE_BUF_SIZE];
 };
 
 typedef struct RedPingPipeItem {
@@ -194,9 +199,37 @@ static void main_channel_client_finalize(GObject *object)
     G_OBJECT_CLASS(main_channel_client_parent_class)->finalize(object);
 }
 
+static uint8_t *
+main_channel_client_alloc_msg_rcv_buf(RedChannelClient *rcc,
+                                      uint16_t type, uint32_t size)
+{
+    MainChannelClient *mcc = MAIN_CHANNEL_CLIENT(rcc);
+
+    if (type == SPICE_MSGC_MAIN_AGENT_DATA) {
+        RedChannel *channel = red_channel_client_get_channel(rcc);
+        return reds_get_agent_data_buffer(red_channel_get_server(channel), mcc, size);
+    } else if (size > sizeof(mcc->priv->recv_buf)) {
+        /* message too large, caller will log a message and close the connection */
+        return NULL;
+    } else {
+        return mcc->priv->recv_buf;
+    }
+}
+
+static void
+main_channel_client_release_msg_rcv_buf(RedChannelClient *rcc,
+                                        uint16_t type, uint32_t size, uint8_t *msg)
+{
+    if (type == SPICE_MSGC_MAIN_AGENT_DATA) {
+        RedChannel *channel = red_channel_client_get_channel(rcc);
+        reds_release_agent_data_buffer(red_channel_get_server(channel), msg);
+    }
+}
+
 static void main_channel_client_class_init(MainChannelClientClass *klass)
 {
     GObjectClass *object_class = G_OBJECT_CLASS(klass);
+    RedChannelClientClass *client_class = RED_CHANNEL_CLIENT_CLASS(klass);
 
     g_type_class_add_private(klass, sizeof(MainChannelClientPrivate));
 
@@ -205,6 +238,9 @@ static void main_channel_client_class_init(MainChannelClientClass *klass)
     object_class->finalize = main_channel_client_finalize;
     object_class->constructed = main_channel_client_constructed;
 
+    client_class->alloc_recv_buf = main_channel_client_alloc_msg_rcv_buf;
+    client_class->release_recv_buf = main_channel_client_release_msg_rcv_buf;
+
     g_object_class_install_property(object_class,
                                     PROP_CONNECTION_ID,
                                     g_param_spec_uint("connection-id",
diff --git a/server/main-channel.c b/server/main-channel.c
index 3a6e6cd..9306eda 100644
--- a/server/main-channel.c
+++ b/server/main-channel.c
@@ -28,15 +28,10 @@
 #include "main-channel.h"
 #include "main-channel-client.h"
 
-// approximate max receive message size for main channel
-#define MAIN_CHANNEL_RECEIVE_BUF_SIZE \
-    (4096 + (REDS_AGENT_WINDOW_SIZE + REDS_NUM_INTERNAL_AGENT_MESSAGES) * SPICE_AGENT_MAX_DATA_SIZE)
-
 struct MainChannel
 {
     RedChannel parent;
 
-    uint8_t recv_buf[MAIN_CHANNEL_RECEIVE_BUF_SIZE];
     // TODO: add refs and release (afrer all clients completed migration in one way or the other?)
     RedsMigSpice mig_target;
     int num_clients_mig_wait;
@@ -248,35 +243,6 @@ static int main_channel_handle_message(RedChannelClient *rcc, uint16_t type,
     return TRUE;
 }
 
-static uint8_t *main_channel_alloc_msg_rcv_buf(RedChannelClient *rcc,
-                                               uint16_t type,
-                                               uint32_t size)
-{
-    RedChannel *channel = red_channel_client_get_channel(rcc);
-    MainChannel *main_chan = MAIN_CHANNEL(channel);
-    MainChannelClient *mcc = MAIN_CHANNEL_CLIENT(rcc);
-
-    if (type == SPICE_MSGC_MAIN_AGENT_DATA) {
-        return reds_get_agent_data_buffer(red_channel_get_server(channel), mcc, size);
-    } else if (size > sizeof(main_chan->recv_buf)) {
-        /* message too large, caller will log a message and close the connection */
-        return NULL;
-    } else {
-        return main_chan->recv_buf;
-    }
-}
-
-static void main_channel_release_msg_rcv_buf(RedChannelClient *rcc,
-                                               uint16_t type,
-                                               uint32_t size,
-                                               uint8_t *msg)
-{
-    RedChannel *channel = red_channel_client_get_channel(rcc);
-    if (type == SPICE_MSGC_MAIN_AGENT_DATA) {
-        reds_release_agent_data_buffer(red_channel_get_server(channel), msg);
-    }
-}
-
 static int main_channel_handle_migrate_flush_mark(RedChannelClient *rcc)
 {
     RedChannel *channel = red_channel_client_get_channel(rcc);
@@ -352,8 +318,6 @@ main_channel_class_init(MainChannelClass *klass)
     /* channel callbacks */
     channel_class->on_disconnect = main_channel_client_on_disconnect;
     channel_class->send_item = main_channel_client_send_item;
-    channel_class->alloc_recv_buf = main_channel_alloc_msg_rcv_buf;
-    channel_class->release_recv_buf = main_channel_release_msg_rcv_buf;
     channel_class->handle_migrate_flush_mark = main_channel_handle_migrate_flush_mark;
     channel_class->handle_migrate_data = main_channel_handle_migrate_data;
 }
diff --git a/server/red-channel-client.c b/server/red-channel-client.c
index 0100af7..818c78e 100644
--- a/server/red-channel-client.c
+++ b/server/red-channel-client.c
@@ -391,6 +391,9 @@ static void red_channel_client_constructed(GObject *object)
 {
     RedChannelClient *self =  RED_CHANNEL_CLIENT(object);
 
+    RedChannelClientClass *klass = RED_CHANNEL_CLIENT_GET_CLASS(self);
+    spice_assert(klass->alloc_recv_buf && klass->release_recv_buf);
+
     self->priv->outgoing.pos = 0;
     self->priv->outgoing.size = 0;
 
@@ -1095,8 +1098,7 @@ void red_channel_client_shutdown(RedChannelClient *rcc)
 static uint8_t *red_channel_client_alloc_msg_buf(RedChannelClient *rcc,
                                                  uint16_t type, uint32_t size)
 {
-    RedChannel *channel = red_channel_client_get_channel(rcc);
-    RedChannelClass *klass = RED_CHANNEL_GET_CLASS(channel);
+    RedChannelClientClass *klass = RED_CHANNEL_CLIENT_GET_CLASS(rcc);
 
     return klass->alloc_recv_buf(rcc, type, size);
 }
@@ -1105,8 +1107,7 @@ static void red_channel_client_release_msg_buf(RedChannelClient *rcc,
                                                uint16_t type, uint32_t size,
                                                uint8_t *msg)
 {
-    RedChannel *channel = red_channel_client_get_channel(rcc);
-    RedChannelClass *klass = RED_CHANNEL_GET_CLASS(channel);
+    RedChannelClientClass *klass = RED_CHANNEL_CLIENT_GET_CLASS(rcc);
 
     klass->release_recv_buf(rcc, type, size, msg);
 }
diff --git a/server/red-channel-client.h b/server/red-channel-client.h
index f5be4a1..5ede13e 100644
--- a/server/red-channel-client.h
+++ b/server/red-channel-client.h
@@ -168,6 +168,9 @@ struct RedChannelClient
 struct RedChannelClientClass
 {
     GObjectClass parent_class;
+
+    uint8_t *(*alloc_recv_buf)(RedChannelClient *channel, uint16_t type, uint32_t size);
+    void (*release_recv_buf)(RedChannelClient *channel, uint16_t type, uint32_t size, uint8_t *msg);
 };
 
 #define SPICE_SERVER_ERROR spice_server_error_quark()
diff --git a/server/red-channel.c b/server/red-channel.c
index 3720990..b77c6c0 100644
--- a/server/red-channel.c
+++ b/server/red-channel.c
@@ -210,8 +210,7 @@ red_channel_constructed(GObject *object)
 
     G_OBJECT_CLASS(red_channel_parent_class)->constructed(object);
 
-    spice_assert(klass->on_disconnect &&
-                 klass->alloc_recv_buf && klass->release_recv_buf);
+    spice_assert(klass->on_disconnect);
     spice_assert(klass->handle_migrate_data ||
                  !(self->priv->migration_flags & SPICE_MIGRATE_NEED_DATA_TRANSFER));
 }
diff --git a/server/red-channel.h b/server/red-channel.h
index 38fbdbc..0d17a05 100644
--- a/server/red-channel.h
+++ b/server/red-channel.h
@@ -42,12 +42,8 @@ typedef struct RedChannelClient RedChannelClient;
 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);
 typedef int (*channel_handle_message_proc)(RedChannelClient *rcc, uint16_t type,
                                            uint32_t size, void *msg);
-typedef void (*channel_release_msg_recv_buf_proc)(RedChannelClient *channel,
-                                                  uint16_t type, uint32_t size, uint8_t *msg);
 typedef void (*channel_disconnect_proc)(RedChannelClient *rcc);
 typedef int (*channel_configure_socket_proc)(RedChannelClient *rcc);
 typedef void (*channel_send_pipe_item_proc)(RedChannelClient *rcc, RedPipeItem *item);
@@ -121,8 +117,6 @@ struct RedChannelClass
     channel_configure_socket_proc config_socket;
     channel_disconnect_proc on_disconnect;
     channel_send_pipe_item_proc send_item;
-    channel_alloc_msg_recv_buf_proc alloc_recv_buf;
-    channel_release_msg_recv_buf_proc release_recv_buf;
     channel_handle_migrate_flush_mark_proc handle_migrate_flush_mark;
     channel_handle_migrate_data_proc handle_migrate_data;
     channel_handle_migrate_data_get_serial_proc handle_migrate_data_get_serial;
diff --git a/server/smartcard-channel-client.c b/server/smartcard-channel-client.c
index 2c99309..943caf8 100644
--- a/server/smartcard-channel-client.c
+++ b/server/smartcard-channel-client.c
@@ -43,6 +43,12 @@ typedef struct RedErrorItem {
     VSCMsgError  error;
 } RedErrorItem;
 
+static uint8_t *
+smartcard_channel_client_alloc_msg_rcv_buf(RedChannelClient *rcc, uint16_t type, uint32_t size);
+static void
+smartcard_channel_client_release_msg_rcv_buf(RedChannelClient *rcc, uint16_t type,
+                                             uint32_t size, uint8_t *msg);
+
 static void smart_card_channel_client_get_property(GObject *object,
                                                    guint property_id,
                                                    GValue *value,
@@ -88,6 +94,10 @@ static void smart_card_channel_client_class_init(SmartCardChannelClientClass *kl
 
     g_type_class_add_private(klass, sizeof(SmartCardChannelClientPrivate));
 
+    RedChannelClientClass *client_class = RED_CHANNEL_CLIENT_CLASS(klass);
+    client_class->alloc_recv_buf = smartcard_channel_client_alloc_msg_rcv_buf;
+    client_class->release_recv_buf = smartcard_channel_client_release_msg_rcv_buf;
+
     object_class->get_property = smart_card_channel_client_get_property;
     object_class->set_property = smart_card_channel_client_set_property;
     object_class->dispose = smart_card_channel_client_dispose;
@@ -121,9 +131,9 @@ SmartCardChannelClient* smartcard_channel_client_create(RedChannel *channel,
     return rcc;
 }
 
-uint8_t *smartcard_channel_client_alloc_msg_rcv_buf(RedChannelClient *rcc,
-                                                    uint16_t type,
-                                                    uint32_t size)
+static uint8_t *
+smartcard_channel_client_alloc_msg_rcv_buf(RedChannelClient *rcc,
+                                           uint16_t type, uint32_t size)
 {
     SmartCardChannelClient *scc = SMARTCARD_CHANNEL_CLIENT(rcc);
     RedClient *client = red_channel_client_get_client(rcc);
@@ -154,10 +164,9 @@ uint8_t *smartcard_channel_client_alloc_msg_rcv_buf(RedChannelClient *rcc,
     }
 }
 
-void smartcard_channel_client_release_msg_rcv_buf(RedChannelClient *rcc,
-                                                  uint16_t type,
-                                                  uint32_t size,
-                                                  uint8_t *msg)
+static void
+smartcard_channel_client_release_msg_rcv_buf(RedChannelClient *rcc,
+                                             uint16_t type, uint32_t size, uint8_t *msg)
 {
     SmartCardChannelClient *scc = SMARTCARD_CHANNEL_CLIENT(rcc);
 
diff --git a/server/smartcard-channel-client.h b/server/smartcard-channel-client.h
index 56e36ec..dc79906 100644
--- a/server/smartcard-channel-client.h
+++ b/server/smartcard-channel-client.h
@@ -61,15 +61,6 @@ SmartCardChannelClient* smartcard_channel_client_create(RedChannel *channel,
                                                         GArray *common_caps,
                                                         GArray *caps);
 
-uint8_t* smartcard_channel_client_alloc_msg_rcv_buf(RedChannelClient *rcc,
-                                                    uint16_t type,
-                                                    uint32_t size);
-
-void smartcard_channel_client_release_msg_rcv_buf(RedChannelClient *rcc,
-                                                  uint16_t type,
-                                                  uint32_t size,
-                                                  uint8_t *msg);
-
 int smartcard_channel_client_handle_migrate_flush_mark(RedChannelClient *rcc);
 
 void smartcard_channel_client_on_disconnect(RedChannelClient *rcc);
@@ -97,15 +88,6 @@ void smartcard_channel_client_set_char_device(SmartCardChannelClient *scc,
 
 RedCharDeviceSmartcard* smartcard_channel_client_get_char_device(SmartCardChannelClient *scc);
 
-void smartcard_channel_client_release_msg_rcv_buf(RedChannelClient *rcc,
-                                                  uint16_t type,
-                                                  uint32_t size,
-                                                  uint8_t *msg);
-
-uint8_t *smartcard_channel_client_alloc_msg_rcv_buf(RedChannelClient *rcc,
-                                                    uint16_t type,
-                                                    uint32_t size);
-
 G_END_DECLS
 
 #endif /* SMARTCARD_CHANNEL_CLIENT_H__ */
diff --git a/server/smartcard.c b/server/smartcard.c
index b444e4d..d24abd8 100644
--- a/server/smartcard.c
+++ b/server/smartcard.c
@@ -581,8 +581,6 @@ red_smartcard_channel_class_init(RedSmartcardChannelClass *klass)
 
     channel_class->on_disconnect = smartcard_channel_client_on_disconnect;
     channel_class->send_item = smartcard_channel_send_item;
-    channel_class->alloc_recv_buf = smartcard_channel_client_alloc_msg_rcv_buf;
-    channel_class->release_recv_buf = smartcard_channel_client_release_msg_rcv_buf;
     channel_class->handle_migrate_flush_mark = smartcard_channel_client_handle_migrate_flush_mark;
     channel_class->handle_migrate_data = smartcard_channel_client_handle_migrate_data;
 
diff --git a/server/sound.c b/server/sound.c
index ea8ef0d..bc42b05 100644
--- a/server/sound.c
+++ b/server/sound.c
@@ -1341,8 +1341,6 @@ snd_channel_class_init(SndChannelClass *klass)
     object_class->finalize = snd_channel_finalize;
 
     channel_class->config_socket = snd_channel_config_socket;
-    channel_class->alloc_recv_buf = snd_channel_client_alloc_recv_buf;
-    channel_class->release_recv_buf = snd_channel_client_release_recv_buf;
     channel_class->on_disconnect = snd_channel_on_disconnect;
 }
 
@@ -1492,8 +1490,12 @@ void snd_set_playback_compression(int on)
 }
 
 static void
-snd_channel_client_class_init(SndChannelClientClass *self)
+snd_channel_client_class_init(SndChannelClientClass *klass)
 {
+    RedChannelClientClass *client_class = RED_CHANNEL_CLIENT_CLASS(klass);
+
+    client_class->alloc_recv_buf = snd_channel_client_alloc_recv_buf;
+    client_class->release_recv_buf = snd_channel_client_release_recv_buf;
 }
 
 static void
diff --git a/server/spicevmc.c b/server/spicevmc.c
index cff18d9..8695117 100644
--- a/server/spicevmc.c
+++ b/server/spicevmc.c
@@ -181,6 +181,42 @@ static void red_vmc_channel_port_init(RedVmcChannelPort *self)
 }
 G_DEFINE_TYPE(RedVmcChannelPort, red_vmc_channel_port, RED_TYPE_VMC_CHANNEL)
 
+
+#define TYPE_VMC_CHANNEL_CLIENT vmc_channel_client_get_type()
+
+#define VMC_CHANNEL_CLIENT(obj) \
+    (G_TYPE_CHECK_INSTANCE_CAST((obj), TYPE_VMC_CHANNEL_CLIENT, VmcChannelClient))
+#define VMC_CHANNEL_CLIENT_CLASS(klass) \
+    (G_TYPE_CHECK_CLASS_CAST((klass), TYPE_VMC_CHANNEL_CLIENT, VmcChannelClientClass))
+#define COMMON_IS_GRAPHICS_CHANNEL_CLIENT(obj) \
+    (G_TYPE_CHECK_INSTANCE_TYPE((obj), TYPE_VMC_CHANNEL_CLIENT))
+#define COMMON_IS_GRAPHICS_CHANNEL_CLIENT_CLASS(klass) \
+    (G_TYPE_CHECK_CLASS_TYPE((klass), TYPE_VMC_CHANNEL_CLIENT))
+#define VMC_CHANNEL_CLIENT_GET_CLASS(obj) \
+    (G_TYPE_INSTANCE_GET_CLASS((obj), TYPE_VMC_CHANNEL_CLIENT, VmcChannelClientClass))
+
+typedef struct VmcChannelClient VmcChannelClient;
+typedef struct VmcChannelClientClass VmcChannelClientClass;
+typedef struct VmcChannelClientPrivate VmcChannelClientPrivate;
+
+struct VmcChannelClient {
+    RedChannelClient parent;
+};
+
+struct VmcChannelClientClass {
+    RedChannelClientClass parent_class;
+};
+
+GType vmc_channel_client_get_type(void) G_GNUC_CONST;
+
+G_DEFINE_TYPE(VmcChannelClient, vmc_channel_client, RED_TYPE_CHANNEL_CLIENT)
+
+static RedChannelClient *
+vmc_channel_client_create(RedChannel *channel, RedClient *client,
+                          RedsStream *stream,
+                          GArray *common_caps, GArray *caps);
+
+
 static void spicevmc_connect(RedChannel *channel, RedClient *client,
                              RedsStream *stream, int migration,
                              GArray *common_caps, GArray *caps);
@@ -733,8 +769,6 @@ red_vmc_channel_class_init(RedVmcChannelClass *klass)
 
     channel_class->on_disconnect = spicevmc_red_channel_client_on_disconnect;
     channel_class->send_item = spicevmc_red_channel_send_item;
-    channel_class->alloc_recv_buf = spicevmc_red_channel_alloc_msg_rcv_buf;
-    channel_class->release_recv_buf = spicevmc_red_channel_release_msg_rcv_buf;
     channel_class->handle_migrate_flush_mark = spicevmc_channel_client_handle_migrate_flush_mark;
     channel_class->handle_migrate_data = spicevmc_channel_client_handle_migrate_data;
 }
@@ -786,8 +820,7 @@ static void spicevmc_connect(RedChannel *channel, RedClient *client,
         return;
     }
 
-    rcc = red_channel_client_create(channel, client, stream, FALSE,
-                                    common_caps, caps);
+    rcc = vmc_channel_client_create(channel, client, stream, common_caps, caps);
     if (!rcc) {
         return;
     }
@@ -953,3 +986,37 @@ red_char_device_spicevmc_new(SpiceCharDeviceInstance *sin,
                         "channel", channel,
                         NULL);
 }
+
+static void
+vmc_channel_client_init(VmcChannelClient *self)
+{
+}
+
+static void
+vmc_channel_client_class_init(VmcChannelClientClass *klass)
+{
+    RedChannelClientClass *client_class = RED_CHANNEL_CLIENT_CLASS(klass);
+
+    client_class->alloc_recv_buf = spicevmc_red_channel_alloc_msg_rcv_buf;
+    client_class->release_recv_buf = spicevmc_red_channel_release_msg_rcv_buf;
+}
+
+static RedChannelClient *
+vmc_channel_client_create(RedChannel *channel, RedClient *client,
+                          RedsStream *stream,
+                          GArray *common_caps, GArray *caps)
+{
+    RedChannelClient *rcc;
+
+    rcc = g_initable_new(TYPE_VMC_CHANNEL_CLIENT,
+                         NULL, NULL,
+                         "channel", channel,
+                         "client", client,
+                         "stream", stream,
+                         "monitor-latency", false,
+                         "caps", caps,
+                         "common-caps", common_caps,
+                         NULL);
+
+    return rcc;
+}
-- 
2.9.3



More information about the Spice-devel mailing list