[Spice-devel] [PATCH spice-server 1a/3] red-channel: Use directly a GArray to pass capabilities

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


Capabilities where almost always passed using 2 arguments,
a number of elements and an array but then before using
these were converted to a GArray.
Converting to GArray much earlier allows to easily pass
the capabilities around.

Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
---
I don't know if is worth defining an abstract type
instead of using a simple GArray.
Maybe a "typedef GArray RedCapabilities" could help future
replacement of the GArray?
On the other side this patch moves most of the array boxing
into a single function.
---
 server/cursor-channel-client.c    | 23 +++--------------------
 server/cursor-channel-client.h    |  4 +---
 server/cursor-channel.c           |  6 ++----
 server/cursor-channel.h           |  9 ++++-----
 server/dcc.c                      | 23 +++--------------------
 server/dcc.h                      | 16 +++++-----------
 server/inputs-channel-client.c    | 24 +++---------------------
 server/inputs-channel-client.h    |  5 +----
 server/inputs-channel.c           |  6 ++----
 server/red-channel-client.c       | 22 +++-------------------
 server/red-channel-client.h       |  3 +--
 server/red-channel.c              | 25 +++++++++++++++++++++----
 server/red-channel.h              |  3 +--
 server/red-qxl.c                  | 26 +++++++-------------------
 server/red-qxl.h                  | 12 ++++--------
 server/red-worker.c               | 13 ++++++-------
 server/smartcard-channel-client.c | 24 ++++--------------------
 server/smartcard-channel-client.h |  4 ++--
 server/smartcard.c                |  7 +++----
 server/sound.c                    | 36 ++++++++----------------------------
 server/spicevmc.c                 | 10 +++++-----
 21 files changed, 89 insertions(+), 212 deletions(-)

diff --git a/server/cursor-channel-client.c b/server/cursor-channel-client.c
index 56efd1e..1344719 100644
--- a/server/cursor-channel-client.c
+++ b/server/cursor-channel-client.c
@@ -93,21 +93,9 @@ void cursor_channel_client_migrate(RedChannelClient *rcc)
 
 CursorChannelClient* cursor_channel_client_new(CursorChannel *cursor, RedClient *client, RedsStream *stream,
                                                int mig_target,
-                                               uint32_t *common_caps, int num_common_caps,
-                                               uint32_t *caps, int num_caps)
+                                               GArray *common_caps, GArray *caps)
 {
     CursorChannelClient *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_CURSOR_CHANNEL_CLIENT,
                          NULL, NULL,
@@ -115,16 +103,11 @@ CursorChannelClient* cursor_channel_client_new(CursorChannel *cursor, RedClient
                          "client", client,
                          "stream", stream,
                          "monitor-latency", FALSE,
-                         "common-caps", common_caps_array,
-                         "caps", caps_array,
+                         "common-caps", common_caps,
+                         "caps", caps,
                          NULL);
     common_graphics_channel_set_during_target_migrate(COMMON_GRAPHICS_CHANNEL(cursor), mig_target);
 
-    if (caps_array)
-        g_array_unref(caps_array);
-    if (common_caps_array)
-        g_array_unref(common_caps_array);
-
     return rcc;
 }
 
diff --git a/server/cursor-channel-client.h b/server/cursor-channel-client.h
index d1dd31d..211ea94 100644
--- a/server/cursor-channel-client.h
+++ b/server/cursor-channel-client.h
@@ -63,9 +63,7 @@ CursorChannelClient* cursor_channel_client_new(CursorChannel *cursor,
                                                RedClient *client,
                                                RedsStream *stream,
                                                int mig_target,
-                                               uint32_t *common_caps,
-                                               int num_common_caps,
-                                               uint32_t *caps, int num_caps);
+                                               GArray *common_caps, GArray *caps);
 
 void cursor_channel_client_reset_cursor_cache(RedChannelClient *rcc);
 void cursor_channel_client_on_disconnect(RedChannelClient *rcc);
diff --git a/server/cursor-channel.c b/server/cursor-channel.c
index 4fe3f8d..73d7126 100644
--- a/server/cursor-channel.c
+++ b/server/cursor-channel.c
@@ -406,8 +406,7 @@ void cursor_channel_set_mouse_mode(CursorChannel *cursor, uint32_t mode)
 
 void cursor_channel_connect(CursorChannel *cursor, RedClient *client, RedsStream *stream,
                             int migrate,
-                            uint32_t *common_caps, int num_common_caps,
-                            uint32_t *caps, int num_caps)
+                            GArray *common_caps, GArray *caps)
 {
     CursorChannelClient *ccc;
 
@@ -416,8 +415,7 @@ void cursor_channel_connect(CursorChannel *cursor, RedClient *client, RedsStream
     spice_info("add cursor channel client");
     ccc = cursor_channel_client_new(cursor, client, stream,
                                     migrate,
-                                    common_caps, num_common_caps,
-                                    caps, num_caps);
+                                    common_caps, caps);
     spice_return_if_fail(ccc != NULL);
 
     RedChannelClient *rcc = RED_CHANNEL_CLIENT(ccc);
diff --git a/server/cursor-channel.h b/server/cursor-channel.h
index ec9d44f..2c3948d 100644
--- a/server/cursor-channel.h
+++ b/server/cursor-channel.h
@@ -72,11 +72,10 @@ void                 cursor_channel_set_mouse_mode(CursorChannel *cursor, uint32
  * This is the equivalent of RedChannel client connect callback.
  * See comment on cursor_channel_new.
  */
-void                 cursor_channel_connect     (CursorChannel *cursor, RedClient *client,
-                                                 RedsStream *stream,
-                                                 int migrate,
-                                                 uint32_t *common_caps, int num_common_caps,
-                                                 uint32_t *caps, int num_caps);
+void cursor_channel_connect(CursorChannel *cursor, RedClient *client,
+                            RedsStream *stream,
+                            int migrate,
+                            GArray *common_caps, GArray *caps);
 
 /**
  * Migrate a client channel from a CursorChannel.
diff --git a/server/dcc.c b/server/dcc.c
index 373dad9..3cc9573 100644
--- a/server/dcc.c
+++ b/server/dcc.c
@@ -482,25 +482,13 @@ static void dcc_init_stream_agents(DisplayChannelClient *dcc)
 DisplayChannelClient *dcc_new(DisplayChannel *display,
                               RedClient *client, RedsStream *stream,
                               int mig_target,
-                              uint32_t *common_caps, int num_common_caps,
-                              uint32_t *caps, int num_caps,
+                              GArray *common_caps, GArray *caps,
                               SpiceImageCompression image_compression,
                               spice_wan_compression_t jpeg_state,
                               spice_wan_compression_t zlib_glz_state)
 
 {
     DisplayChannelClient *dcc;
-    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);
-    }
 
     dcc = g_initable_new(TYPE_DISPLAY_CHANNEL_CLIENT,
                          NULL, NULL,
@@ -508,8 +496,8 @@ DisplayChannelClient *dcc_new(DisplayChannel *display,
                          "client", client,
                          "stream", stream,
                          "monitor-latency", TRUE,
-                         "common-caps", common_caps_array,
-                         "caps", caps_array,
+                         "common-caps", common_caps,
+                         "caps", caps,
                          "image-compression", image_compression,
                          "jpeg-state", jpeg_state,
                          "zlib-glz-state", zlib_glz_state,
@@ -518,11 +506,6 @@ DisplayChannelClient *dcc_new(DisplayChannel *display,
     common_graphics_channel_set_during_target_migrate(COMMON_GRAPHICS_CHANNEL(display), mig_target);
     dcc->priv->id = common_graphics_channel_get_qxl(COMMON_GRAPHICS_CHANNEL(display))->id;
 
-    if (common_caps_array)
-        g_array_unref(common_caps_array);
-    if (caps_array)
-        g_array_unref(caps_array);
-
     return dcc;
 }
 
diff --git a/server/dcc.h b/server/dcc.h
index ebdbb8d..19416e3 100644
--- a/server/dcc.h
+++ b/server/dcc.h
@@ -130,17 +130,11 @@ typedef struct RedDrawablePipeItem {
     DisplayChannelClient *dcc;
 } RedDrawablePipeItem;
 
-DisplayChannelClient*      dcc_new                                   (DisplayChannel *display,
-                                                                      RedClient *client,
-                                                                      RedsStream *stream,
-                                                                      int mig_target,
-                                                                      uint32_t *common_caps,
-                                                                      int num_common_caps,
-                                                                      uint32_t *caps,
-                                                                      int num_caps,
-                                                                      SpiceImageCompression image_compression,
-                                                                      spice_wan_compression_t jpeg_state,
-                                                                      spice_wan_compression_t zlib_glz_state);
+DisplayChannelClient* dcc_new(DisplayChannel *display, RedClient *client, RedsStream *stream,
+                              int mig_target, GArray *common_caps, GArray *caps,
+                              SpiceImageCompression image_compression,
+                              spice_wan_compression_t jpeg_state,
+                              spice_wan_compression_t zlib_glz_state);
 void                       dcc_start                                 (DisplayChannelClient *dcc);
 void                       dcc_stop                                  (DisplayChannelClient *dcc);
 int                        dcc_handle_message                        (RedChannelClient *rcc,
diff --git a/server/inputs-channel-client.c b/server/inputs-channel-client.c
index 4a534e8..c8d33ba 100644
--- a/server/inputs-channel-client.c
+++ b/server/inputs-channel-client.c
@@ -48,38 +48,20 @@ RedChannelClient* inputs_channel_client_create(RedChannel *channel,
                                                RedClient *client,
                                                RedsStream *stream,
                                                int monitor_latency,
-                                               int num_common_caps,
-                                               uint32_t *common_caps,
-                                               int num_caps,
-                                               uint32_t *caps)
+                                               GArray *common_caps, GArray *caps)
 {
     RedChannelClient *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_INPUTS_CHANNEL_CLIENT,
                          NULL, NULL,
                          "channel", channel,
                          "client", client,
                          "stream", stream,
                          "monitor-latency", monitor_latency,
-                         "caps", caps_array,
-                         "common-caps", common_caps_array,
+                         "caps", caps,
+                         "common-caps", common_caps,
                          NULL);
 
-    if (caps_array)
-        g_array_unref(caps_array);
-    if (common_caps_array)
-        g_array_unref(common_caps_array);
-
     return rcc;
 }
 
diff --git a/server/inputs-channel-client.h b/server/inputs-channel-client.h
index 7550b3c..a856a58 100644
--- a/server/inputs-channel-client.h
+++ b/server/inputs-channel-client.h
@@ -60,10 +60,7 @@ RedChannelClient* inputs_channel_client_create(RedChannel *channel,
                                                RedClient *client,
                                                RedsStream *stream,
                                                int monitor_latency,
-                                               int num_common_caps,
-                                               uint32_t *common_caps,
-                                               int num_caps,
-                                               uint32_t *caps);
+                                               GArray *common_caps, GArray *caps);
 
 uint16_t inputs_channel_client_get_motion_count(InputsChannelClient* self);
 /* only for migration */
diff --git a/server/inputs-channel.c b/server/inputs-channel.c
index ed92e71..cd92e1a 100644
--- a/server/inputs-channel.c
+++ b/server/inputs-channel.c
@@ -486,8 +486,7 @@ static void inputs_pipe_add_init(RedChannelClient *rcc)
 
 static void inputs_connect(RedChannel *channel, RedClient *client,
                            RedsStream *stream, int migration,
-                           int num_common_caps, uint32_t *common_caps,
-                           int num_caps, uint32_t *caps)
+                           GArray *common_caps, GArray *caps)
 {
     RedChannelClient *rcc;
 
@@ -498,8 +497,7 @@ static void inputs_connect(RedChannel *channel, RedClient *client,
 
     spice_printerr("inputs channel client create");
     rcc = inputs_channel_client_create(channel, client, stream, FALSE,
-                                       num_common_caps, common_caps,
-                                       num_caps, caps);
+                                       common_caps, caps);
     if (!rcc) {
         return;
     }
diff --git a/server/red-channel-client.c b/server/red-channel-client.c
index b583da2..0100af7 100644
--- a/server/red-channel-client.c
+++ b/server/red-channel-client.c
@@ -1013,36 +1013,20 @@ cleanup:
 RedChannelClient *red_channel_client_create(RedChannel *channel, RedClient *client,
                                             RedsStream *stream,
                                             int monitor_latency,
-                                            int num_common_caps, uint32_t *common_caps,
-                                            int num_caps, uint32_t *caps)
+                                            GArray *common_caps, GArray *caps)
 {
     RedChannelClient *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(RED_TYPE_CHANNEL_CLIENT,
                          NULL, NULL,
                          "channel", channel,
                          "client", client,
                          "stream", stream,
                          "monitor-latency", monitor_latency,
-                         "caps", caps_array,
-                         "common-caps", common_caps_array,
+                         "caps", caps,
+                         "common-caps", common_caps,
                          NULL);
 
-    if (caps_array)
-        g_array_unref(caps_array);
-    if (common_caps_array)
-        g_array_unref(common_caps_array);
-
     return rcc;
 }
 
diff --git a/server/red-channel-client.h b/server/red-channel-client.h
index 474a5cd..f5be4a1 100644
--- a/server/red-channel-client.h
+++ b/server/red-channel-client.h
@@ -50,8 +50,7 @@ GType red_channel_client_get_type(void) G_GNUC_CONST;
 RedChannelClient *red_channel_client_create(RedChannel *channel,
                                             RedClient *client, RedsStream *stream,
                                             int monitor_latency,
-                                            int num_common_caps, uint32_t *common_caps,
-                                            int num_caps, uint32_t *caps);
+                                            GArray *common_caps, GArray *caps);
 
 gboolean red_channel_client_is_connected(RedChannelClient *rcc);
 void red_channel_client_default_migrate(RedChannelClient *rcc);
diff --git a/server/red-channel.c b/server/red-channel.c
index 67a570d..3720990 100644
--- a/server/red-channel.c
+++ b/server/red-channel.c
@@ -219,8 +219,7 @@ red_channel_constructed(GObject *object)
 static void red_channel_client_default_connect(RedChannel *channel, RedClient *client,
                                                RedsStream *stream,
                                                int migration,
-                                               int num_common_caps, uint32_t *common_caps,
-                                               int num_caps, uint32_t *caps)
+                                               GArray *common_caps, GArray *caps)
 {
     spice_error("not implemented");
 }
@@ -516,9 +515,27 @@ void red_channel_connect(RedChannel *channel, RedClient *client,
                          RedsStream *stream, int migration, int num_common_caps,
                          uint32_t *common_caps, int num_caps, uint32_t *caps)
 {
+    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);
+    }
+
     channel->priv->client_cbs.connect(channel, client, stream, migration,
-                                      num_common_caps, common_caps, num_caps,
-                                      caps);
+                                      common_caps_array, caps_array);
+
+    if (caps_array) {
+        g_array_unref(caps_array);
+    }
+    if (common_caps_array) {
+        g_array_unref(common_caps_array);
+    }
 }
 
 void red_channel_apply_clients(RedChannel *channel, channel_client_callback cb)
diff --git a/server/red-channel.h b/server/red-channel.h
index 79aee01..38fbdbc 100644
--- a/server/red-channel.h
+++ b/server/red-channel.h
@@ -60,8 +60,7 @@ typedef uint64_t (*channel_handle_migrate_data_get_serial_proc)(RedChannelClient
 
 
 typedef void (*channel_client_connect_proc)(RedChannel *channel, RedClient *client, RedsStream *stream,
-                                            int migration, int num_common_caps, uint32_t *common_caps,
-                                            int num_caps, uint32_t *caps);
+                                            int migration, GArray *common_caps, GArray *caps);
 typedef void (*channel_client_disconnect_proc)(RedChannelClient *base);
 typedef void (*channel_client_migrate_proc)(RedChannelClient *base);
 
diff --git a/server/red-qxl.c b/server/red-qxl.c
index b6b3770..12ae87f 100644
--- a/server/red-qxl.c
+++ b/server/red-qxl.c
@@ -76,8 +76,7 @@ int red_qxl_check_qxl_version(QXLInstance *qxl, int major, int minor)
 
 static void red_qxl_set_display_peer(RedChannel *channel, RedClient *client,
                                      RedsStream *stream, int migration,
-                                     int num_common_caps, uint32_t *common_caps, int num_caps,
-                                     uint32_t *caps)
+                                     GArray *common_caps, GArray *caps)
 {
     RedWorkerMessageDisplayConnect payload = {0,};
     Dispatcher *dispatcher;
@@ -87,13 +86,8 @@ static void red_qxl_set_display_peer(RedChannel *channel, RedClient *client,
     payload.client = client;
     payload.stream = stream;
     payload.migration = migration;
-    payload.num_common_caps = num_common_caps;
-    payload.common_caps = spice_malloc(sizeof(uint32_t)*num_common_caps);
-    payload.num_caps = num_caps;
-    payload.caps = spice_malloc(sizeof(uint32_t)*num_caps);
-
-    memcpy(payload.common_caps, common_caps, sizeof(uint32_t)*num_common_caps);
-    memcpy(payload.caps, caps, sizeof(uint32_t)*num_caps);
+    payload.common_caps = g_array_ref(common_caps);
+    payload.caps = g_array_ref(caps);
 
     dispatcher_send_message(dispatcher,
                             RED_WORKER_MESSAGE_DISPLAY_CONNECT,
@@ -142,9 +136,8 @@ static void red_qxl_display_migrate(RedChannelClient *rcc)
 }
 
 static void red_qxl_set_cursor_peer(RedChannel *channel, RedClient *client, RedsStream *stream,
-                                    int migration, int num_common_caps,
-                                    uint32_t *common_caps, int num_caps,
-                                    uint32_t *caps)
+                                    int migration,
+                                    GArray *common_caps, GArray *caps)
 {
     RedWorkerMessageCursorConnect payload = {0,};
     Dispatcher *dispatcher = (Dispatcher *)g_object_get_data(G_OBJECT(channel), "dispatcher");
@@ -152,13 +145,8 @@ static void red_qxl_set_cursor_peer(RedChannel *channel, RedClient *client, Reds
     payload.client = client;
     payload.stream = stream;
     payload.migration = migration;
-    payload.num_common_caps = num_common_caps;
-    payload.common_caps = spice_malloc(sizeof(uint32_t)*num_common_caps);
-    payload.num_caps = num_caps;
-    payload.caps = spice_malloc(sizeof(uint32_t)*num_caps);
-
-    memcpy(payload.common_caps, common_caps, sizeof(uint32_t)*num_common_caps);
-    memcpy(payload.caps, caps, sizeof(uint32_t)*num_caps);
+    payload.common_caps = g_array_ref(common_caps);
+    payload.caps = g_array_ref(caps);
 
     dispatcher_send_message(dispatcher,
                             RED_WORKER_MESSAGE_CURSOR_CONNECT,
diff --git a/server/red-qxl.h b/server/red-qxl.h
index 0c9498a..4d3c3de 100644
--- a/server/red-qxl.h
+++ b/server/red-qxl.h
@@ -126,11 +126,9 @@ enum {
 typedef struct RedWorkerMessageDisplayConnect {
     RedClient * client;
     RedsStream * stream;
-    uint32_t *common_caps; // red_worker should free
-    uint32_t *caps;        // red_worker should free
+    GArray *common_caps; // red_worker should release
+    GArray *caps;        // red_worker should release
     int migration;
-    int num_common_caps;
-    int num_caps;
 } RedWorkerMessageDisplayConnect;
 
 typedef struct RedWorkerMessageDisplayDisconnect {
@@ -145,10 +143,8 @@ typedef struct RedWorkerMessageCursorConnect {
     RedClient *client;
     RedsStream *stream;
     int migration;
-    uint32_t *common_caps; // red_worker should free
-    int num_common_caps;
-    uint32_t *caps;        // red_worker should free
-    int num_caps;
+    GArray *common_caps; // red_worker should release
+    GArray *caps;        // red_worker should release
 } RedWorkerMessageCursorConnect;
 
 typedef struct RedWorkerMessageCursorDisconnect {
diff --git a/server/red-worker.c b/server/red-worker.c
index e5adbaa..779a6c1 100644
--- a/server/red-worker.c
+++ b/server/red-worker.c
@@ -736,7 +736,7 @@ static void handle_dev_display_connect(void *opaque, void *payload)
     spice_return_if_fail(display);
 
     dcc = dcc_new(display, msg->client, msg->stream, msg->migration,
-                  msg->common_caps, msg->num_common_caps, msg->caps, msg->num_caps,
+                  msg->common_caps, msg->caps,
                   worker->image_compression, worker->jpeg_state, worker->zlib_glz_state);
     if (!dcc) {
         return;
@@ -745,8 +745,8 @@ static void handle_dev_display_connect(void *opaque, void *payload)
     guest_set_client_capabilities(worker);
     dcc_start(dcc);
 
-    free(msg->caps);
-    free(msg->common_caps);
+    g_array_unref(msg->caps);
+    g_array_unref(msg->common_caps);
 }
 
 static void handle_dev_display_disconnect(void *opaque, void *payload)
@@ -832,10 +832,9 @@ static void handle_dev_cursor_connect(void *opaque, void *payload)
     spice_info("cursor connect");
     cursor_channel_connect(worker->cursor_channel,
                            msg->client, msg->stream, msg->migration,
-                           msg->common_caps, msg->num_common_caps,
-                           msg->caps, msg->num_caps);
-    free(msg->caps);
-    free(msg->common_caps);
+                           msg->common_caps, msg->caps);
+    g_array_unref(msg->caps);
+    g_array_unref(msg->common_caps);
 }
 
 static void handle_dev_cursor_disconnect(void *opaque, void *payload)
diff --git a/server/smartcard-channel-client.c b/server/smartcard-channel-client.c
index 6234844..2c99309 100644
--- a/server/smartcard-channel-client.c
+++ b/server/smartcard-channel-client.c
@@ -103,21 +103,10 @@ smart_card_channel_client_init(SmartCardChannelClient *self)
 SmartCardChannelClient* smartcard_channel_client_create(RedChannel *channel,
                                                         RedClient *client, RedsStream *stream,
                                                         int monitor_latency,
-                                                        int num_common_caps, uint32_t *common_caps,
-                                                        int num_caps, uint32_t *caps)
+                                                        GArray *common_caps,
+                                                        GArray *caps)
 {
     SmartCardChannelClient *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_SMARTCARD_CHANNEL_CLIENT,
                          NULL, NULL,
@@ -125,15 +114,10 @@ SmartCardChannelClient* smartcard_channel_client_create(RedChannel *channel,
                          "client", client,
                          "stream", stream,
                          "monitor-latency", monitor_latency,
-                         "caps", caps_array,
-                         "common-caps", common_caps_array,
+                         "caps", caps,
+                         "common-caps", common_caps,
                          NULL);
 
-    if (caps_array)
-        g_array_unref(caps_array);
-    if (common_caps_array)
-        g_array_unref(common_caps_array);
-
     return rcc;
 }
 
diff --git a/server/smartcard-channel-client.h b/server/smartcard-channel-client.h
index 9350d7a..56e36ec 100644
--- a/server/smartcard-channel-client.h
+++ b/server/smartcard-channel-client.h
@@ -58,8 +58,8 @@ GType smart_card_channel_client_get_type(void) G_GNUC_CONST;
 SmartCardChannelClient* smartcard_channel_client_create(RedChannel *channel,
                                                         RedClient *client, RedsStream *stream,
                                                         int monitor_latency,
-                                                        int num_common_caps, uint32_t *common_caps,
-                                                        int num_caps, uint32_t *caps);
+                                                        GArray *common_caps,
+                                                        GArray *caps);
 
 uint8_t* smartcard_channel_client_alloc_msg_rcv_buf(RedChannelClient *rcc,
                                                     uint16_t type,
diff --git a/server/smartcard.c b/server/smartcard.c
index 8f12fd9..b444e4d 100644
--- a/server/smartcard.c
+++ b/server/smartcard.c
@@ -528,8 +528,7 @@ int smartcard_char_device_handle_migrate_data(RedCharDeviceSmartcard *smartcard,
 
 static void smartcard_connect_client(RedChannel *channel, RedClient *client,
                                      RedsStream *stream, int migration,
-                                     int num_common_caps, uint32_t *common_caps,
-                                     int num_caps, uint32_t *caps)
+                                     GArray *common_caps, GArray *caps)
 {
     SpiceCharDeviceInstance *char_device =
             smartcard_readers_get_unattached();
@@ -540,8 +539,8 @@ static void smartcard_connect_client(RedChannel *channel, RedClient *client,
                                           client,
                                           stream,
                                           FALSE,
-                                          num_common_caps, common_caps,
-                                          num_caps, caps);
+                                          common_caps,
+                                          caps);
 
     if (!scc) {
         return;
diff --git a/server/sound.c b/server/sound.c
index e83a547..ea8ef0d 100644
--- a/server/sound.c
+++ b/server/sound.c
@@ -1083,11 +1083,9 @@ playback_channel_client_constructed(GObject *object)
 }
 
 static void snd_set_peer(RedChannel *red_channel, RedClient *client, RedsStream *stream,
-                         int num_common_caps, uint32_t *common_caps,
-                         int num_caps, uint32_t *caps, GType type)
+                         GArray *common_caps, GArray *caps, GType type)
 {
     SndChannel *channel = SND_CHANNEL(red_channel);
-    GArray *common_caps_array = NULL, *caps_array = NULL;
     SndChannelClient *snd_client;
 
     if (channel->connection) {
@@ -1095,40 +1093,23 @@ static void snd_set_peer(RedChannel *red_channel, RedClient *client, RedsStream
         channel->connection = 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);
-    }
-
     snd_client = g_initable_new(type,
                                 NULL, NULL,
                                 "channel", channel,
                                 "client", client,
                                 "stream", stream,
-                                "caps", caps_array,
-                                "common-caps", common_caps_array,
+                                "caps", caps,
+                                "common-caps", common_caps,
                                 NULL);
     g_warn_if_fail(snd_client != NULL);
-
-    if (caps_array) {
-        g_array_unref(caps_array);
-    }
-    if (common_caps_array) {
-        g_array_unref(common_caps_array);
-    }
 }
 
 static void snd_set_playback_peer(RedChannel *red_channel, RedClient *client, RedsStream *stream,
-                                  G_GNUC_UNUSED int migration, int num_common_caps, uint32_t *common_caps,
-                                  int num_caps, uint32_t *caps)
+                                  G_GNUC_UNUSED int migration,
+                                  GArray *common_caps, GArray *caps)
 {
     snd_set_peer(red_channel, client, stream,
-                 num_common_caps, common_caps, num_caps, caps,
+                 common_caps, caps,
                  TYPE_PLAYBACK_CHANNEL_CLIENT);
 }
 
@@ -1306,11 +1287,10 @@ record_channel_client_constructed(GObject *object)
 
 static void snd_set_record_peer(RedChannel *red_channel, RedClient *client, RedsStream *stream,
                                 G_GNUC_UNUSED int migration,
-                                int num_common_caps, uint32_t *common_caps,
-                                int num_caps, uint32_t *caps)
+                                GArray *common_caps, GArray *caps)
 {
     snd_set_peer(red_channel, client, stream,
-                 num_common_caps, common_caps, num_caps, caps,
+                 common_caps, caps,
                  TYPE_RECORD_CHANNEL_CLIENT);
 }
 
diff --git a/server/spicevmc.c b/server/spicevmc.c
index e705bc7..cff18d9 100644
--- a/server/spicevmc.c
+++ b/server/spicevmc.c
@@ -182,8 +182,8 @@ static void red_vmc_channel_port_init(RedVmcChannelPort *self)
 G_DEFINE_TYPE(RedVmcChannelPort, red_vmc_channel_port, RED_TYPE_VMC_CHANNEL)
 
 static void spicevmc_connect(RedChannel *channel, RedClient *client,
-                             RedsStream *stream, int migration, int num_common_caps,
-                             uint32_t *common_caps, int num_caps, uint32_t *caps);
+                             RedsStream *stream, int migration,
+                             GArray *common_caps, GArray *caps);
 
 static void
 red_vmc_channel_constructed(GObject *object)
@@ -764,8 +764,8 @@ red_vmc_channel_port_class_init(RedVmcChannelPortClass *klass)
 }
 
 static void spicevmc_connect(RedChannel *channel, RedClient *client,
-    RedsStream *stream, int migration, int num_common_caps,
-    uint32_t *common_caps, int num_caps, uint32_t *caps)
+    RedsStream *stream, int migration,
+    GArray *common_caps, GArray *caps)
 {
     RedChannelClient *rcc;
     RedVmcChannel *vmc_channel;
@@ -787,7 +787,7 @@ static void spicevmc_connect(RedChannel *channel, RedClient *client,
     }
 
     rcc = red_channel_client_create(channel, client, stream, FALSE,
-                                    num_common_caps, common_caps, num_caps, caps);
+                                    common_caps, caps);
     if (!rcc) {
         return;
     }
-- 
2.9.3



More information about the Spice-devel mailing list