[Spice-commits] 6 commits - server/cursor-channel.c server/display-channel.c server/inputs-channel.c server/main-channel-client.c server/main-channel-client.h server/main-channel.c server/red-channel-client.c server/red-channel-client.h server/red-channel.c server/red-channel.h

Frediano Ziglio fziglio at kemper.freedesktop.org
Wed Sep 6 10:46:05 UTC 2017


 server/cursor-channel.c      |  115 +++++++++++++------------------------------
 server/display-channel.c     |    4 -
 server/inputs-channel.c      |    9 +--
 server/main-channel-client.c |   13 +---
 server/main-channel-client.h |   14 -----
 server/main-channel.c        |   16 +----
 server/red-channel-client.c  |   11 ++--
 server/red-channel-client.h  |    1 
 server/red-channel.c         |   43 ++++++----------
 server/red-channel.h         |    9 ++-
 10 files changed, 84 insertions(+), 151 deletions(-)

New commits:
commit 583a29188084232733fbde0e4810775b7536507a
Author: Frediano Ziglio <fziglio at redhat.com>
Date:   Sat Sep 2 19:45:21 2017 +0100

    cursor-channel: Use a single RedCursorPipeItem to hold the cursor
    
    RedPipeItem already implements reference counting so
    this avoid duplicating code to handle a object with reference
    counting that points to another object with reference counting
    that holds a RedCursorCmd.
    
    Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
    Acked-by: Christophe Fergeau <cfergeau at redhat.com>

diff --git a/server/cursor-channel.c b/server/cursor-channel.c
index 2441e1ed..8db3e86b 100644
--- a/server/cursor-channel.c
+++ b/server/cursor-channel.c
@@ -28,17 +28,17 @@
 #include "reds.h"
 #include "red-qxl.h"
 
-typedef struct CursorItem {
+typedef struct RedCursorPipeItem {
+    RedPipeItem base;
     QXLInstance *qxl;
-    int refs;
     RedCursorCmd *red_cursor;
-} CursorItem;
+} RedCursorPipeItem;
 
 struct CursorChannel
 {
     CommonGraphicsChannel parent;
 
-    CursorItem *item;
+    RedCursorPipeItem *item;
     bool cursor_visible;
     SpicePoint16 cursor_position;
     uint16_t cursor_trail_length;
@@ -51,83 +51,49 @@ struct CursorChannelClass
     CommonGraphicsChannelClass parent_class;
 };
 
-typedef struct RedCursorPipeItem {
-    RedPipeItem base;
-    CursorItem *cursor_item;
-} RedCursorPipeItem;
-
 G_DEFINE_TYPE(CursorChannel, cursor_channel, TYPE_COMMON_GRAPHICS_CHANNEL)
 
 static void cursor_pipe_item_free(RedPipeItem *pipe_item);
 
-static CursorItem *cursor_item_new(QXLInstance *qxl, RedCursorCmd *cmd)
+static RedCursorPipeItem *cursor_pipe_item_new(QXLInstance *qxl, RedCursorCmd *cmd)
 {
-    CursorItem *cursor_item;
+    RedCursorPipeItem *item = g_new0(RedCursorPipeItem, 1);
 
     spice_return_val_if_fail(cmd != NULL, NULL);
 
-    cursor_item = g_new0(CursorItem, 1);
-    cursor_item->qxl = qxl;
-    cursor_item->refs = 1;
-    cursor_item->red_cursor = cmd;
-
-    return cursor_item;
-}
-
-static CursorItem *cursor_item_ref(CursorItem *item)
-{
-    spice_return_val_if_fail(item != NULL, NULL);
-    spice_return_val_if_fail(item->refs > 0, NULL);
-
-    item->refs++;
+    red_pipe_item_init_full(&item->base, RED_PIPE_ITEM_TYPE_CURSOR,
+                            cursor_pipe_item_free);
+    item->qxl = qxl;
+    item->red_cursor = cmd;
 
     return item;
 }
 
-static void cursor_item_unref(CursorItem *item)
+static void cursor_pipe_item_free(RedPipeItem *base)
 {
     RedCursorCmd *cursor_cmd;
+    RedCursorPipeItem *pipe_item = SPICE_UPCAST(RedCursorPipeItem, base);
 
-    spice_return_if_fail(item != NULL);
-
-    if (--item->refs)
-        return;
-
-    cursor_cmd = item->red_cursor;
-    red_qxl_release_resource(item->qxl, cursor_cmd->release_info_ext);
+    cursor_cmd = pipe_item->red_cursor;
+    red_qxl_release_resource(pipe_item->qxl, cursor_cmd->release_info_ext);
     red_put_cursor_cmd(cursor_cmd);
     free(cursor_cmd);
 
-    g_free(item);
-
+    g_free(pipe_item);
 }
 
-static void cursor_channel_set_item(CursorChannel *cursor, CursorItem *item)
+static void cursor_channel_set_item(CursorChannel *cursor, RedCursorPipeItem *item)
 {
-    if (cursor->item)
-        cursor_item_unref(cursor->item);
-
-    cursor->item = item ? cursor_item_ref(item) : NULL;
-}
-
-static RedPipeItem *new_cursor_pipe_item(CursorItem *cursor_item)
-{
-    RedCursorPipeItem *item = spice_malloc0(sizeof(RedCursorPipeItem));
-
-    red_pipe_item_init_full(&item->base, RED_PIPE_ITEM_TYPE_CURSOR,
-                            cursor_pipe_item_free);
-    item->cursor_item = cursor_item;
-    item->cursor_item->refs++;
-    return &item->base;
-}
-
-static void marshaller_unref_cursor_item(uint8_t *data, void *opaque)
-{
-    CursorItem *item = opaque;
-    cursor_item_unref(item);
+    if (item) {
+        red_pipe_item_ref(&item->base);
+    }
+    if (cursor->item) {
+        red_pipe_item_unref(&cursor->item->base);
+    }
+    cursor->item = item;
 }
 
-static void cursor_fill(CursorChannelClient *ccc, CursorItem *cursor,
+static void cursor_fill(CursorChannelClient *ccc, RedCursorPipeItem *cursor,
                         SpiceCursor *red_cursor, SpiceMarshaller *m)
 {
     RedCursorCmd *cursor_cmd;
@@ -152,22 +118,12 @@ static void cursor_fill(CursorChannelClient *ccc, CursorItem *cursor,
 
     if (red_cursor->data_size) {
         SpiceMarshaller *m2 = spice_marshaller_get_submarshaller(m);
-        cursor_item_ref(cursor);
+        red_pipe_item_ref(&cursor->base);
         spice_marshaller_add_by_ref_full(m2, red_cursor->data, red_cursor->data_size,
-                                         marshaller_unref_cursor_item, cursor);
+                                         marshaller_unref_pipe_item, &cursor->base);
     }
 }
 
-static void cursor_pipe_item_free(RedPipeItem *base)
-{
-    spice_return_if_fail(base);
-
-    RedCursorPipeItem *pipe_item = SPICE_UPCAST(RedCursorPipeItem, base);
-
-    cursor_item_unref(pipe_item->cursor_item);
-    free(pipe_item);
-}
-
 static void red_marshall_cursor_init(CursorChannelClient *ccc, SpiceMarshaller *base_marshaller,
                                      RedPipeItem *pipe_item)
 {
@@ -195,7 +151,7 @@ static void cursor_marshall(CursorChannelClient *ccc,
 {
     RedChannelClient *rcc = RED_CHANNEL_CLIENT(ccc);
     CursorChannel *cursor_channel = CURSOR_CHANNEL(red_channel_client_get_channel(rcc));
-    CursorItem *item = cursor_pipe_item->cursor_item;
+    RedCursorPipeItem *item = cursor_pipe_item;
     RedCursorCmd *cmd;
 
     spice_return_if_fail(cursor_channel);
@@ -296,7 +252,7 @@ CursorChannel* cursor_channel_new(RedsState *server, QXLInstance *qxl,
 
 void cursor_channel_process_cmd(CursorChannel *cursor, RedCursorCmd *cursor_cmd)
 {
-    CursorItem *cursor_item;
+    RedCursorPipeItem *cursor_pipe_item;
     bool cursor_show = false;
     QXLInstance *qxl;
 
@@ -304,12 +260,12 @@ void cursor_channel_process_cmd(CursorChannel *cursor, RedCursorCmd *cursor_cmd)
     spice_return_if_fail(cursor_cmd);
 
     qxl = common_graphics_channel_get_qxl(COMMON_GRAPHICS_CHANNEL(cursor));
-    cursor_item = cursor_item_new(qxl, cursor_cmd);
+    cursor_pipe_item = cursor_pipe_item_new(qxl, cursor_cmd);
 
     switch (cursor_cmd->type) {
     case QXL_CURSOR_SET:
         cursor->cursor_visible = !!cursor_cmd->u.set.visible;
-        cursor_channel_set_item(cursor, cursor_item);
+        cursor_channel_set_item(cursor, cursor_pipe_item);
         break;
     case QXL_CURSOR_MOVE:
         cursor_show = !cursor->cursor_visible;
@@ -325,7 +281,7 @@ void cursor_channel_process_cmd(CursorChannel *cursor, RedCursorCmd *cursor_cmd)
         break;
     default:
         spice_warning("invalid cursor command %u", cursor_cmd->type);
-        cursor_item_unref(cursor_item);
+        red_pipe_item_unref(&cursor_pipe_item->base);
         return;
     }
 
@@ -333,10 +289,10 @@ void cursor_channel_process_cmd(CursorChannel *cursor, RedCursorCmd *cursor_cmd)
         (cursor->mouse_mode == SPICE_MOUSE_MODE_SERVER
          || cursor_cmd->type != QXL_CURSOR_MOVE
          || cursor_show)) {
-        red_channel_pipes_add(RED_CHANNEL(cursor), new_cursor_pipe_item(cursor_item));
+        red_channel_pipes_add(RED_CHANNEL(cursor), &cursor_pipe_item->base);
+    } else {
+        red_pipe_item_unref(&cursor_pipe_item->base);
     }
-
-    cursor_item_unref(cursor_item);
 }
 
 void cursor_channel_reset(CursorChannel *cursor)
@@ -419,7 +375,7 @@ cursor_channel_finalize(GObject *object)
     CursorChannel *self = CURSOR_CHANNEL(object);
 
     if (self->item) {
-        cursor_item_unref(self->item);
+        red_pipe_item_unref(&self->item->base);
     }
 
     G_OBJECT_CLASS(cursor_channel_parent_class)->finalize(object);
commit bfaf660a056490292ad7ee1116f6efcd8d9ab0ca
Author: Frediano Ziglio <fziglio at redhat.com>
Date:   Tue Aug 29 11:25:32 2017 +0100

    red-channel: Do not push data calling red_channel_pipes_new_add_push
    
    Now the push is done automatically when a PipeItem is added
    (cfr commit 5c460de1a3972b7cf2b9b2944d0b500c3affc363
    "worker: push data when clients can receive them"),
    forcing a push cause only network fragmentation and is required
    only if you are handling data in a loop instead of using the
    default loop.
    
    Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
    Acked-by: Christophe Fergeau <cfergeau at redhat.com>

diff --git a/server/display-channel.c b/server/display-channel.c
index c745790f..076f6696 100644
--- a/server/display-channel.c
+++ b/server/display-channel.c
@@ -2376,7 +2376,7 @@ void display_channel_update_compression(DisplayChannel *display, DisplayChannelC
 
 void display_channel_gl_scanout(DisplayChannel *display)
 {
-    red_channel_pipes_new_add_push(RED_CHANNEL(display), dcc_gl_scanout_item_new, NULL);
+    red_channel_pipes_new_add(RED_CHANNEL(display), dcc_gl_scanout_item_new, NULL);
 }
 
 static void set_gl_draw_async_count(DisplayChannel *display, int num)
@@ -2396,7 +2396,7 @@ void display_channel_gl_draw(DisplayChannel *display, SpiceMsgDisplayGlDraw *dra
 
     spice_return_if_fail(display->priv->gl_draw_async_count == 0);
 
-    num = red_channel_pipes_new_add_push(RED_CHANNEL(display), dcc_gl_draw_item_new, draw);
+    num = red_channel_pipes_new_add(RED_CHANNEL(display), dcc_gl_draw_item_new, draw);
     set_gl_draw_async_count(display, num);
 }
 
diff --git a/server/red-channel.c b/server/red-channel.c
index a2c068e5..5d832c32 100644
--- a/server/red-channel.c
+++ b/server/red-channel.c
@@ -596,20 +596,11 @@ static int red_channel_pipes_create_batch(RedChannel *channel,
     return n;
 }
 
-int red_channel_pipes_new_add_push(RedChannel *channel,
-                                   new_pipe_item_t creator, void *data)
+int red_channel_pipes_new_add(RedChannel *channel,
+                              new_pipe_item_t creator, void *data)
 {
-    int n = red_channel_pipes_create_batch(channel, creator, data,
-                                           red_channel_client_pipe_add);
-    red_channel_push(channel);
-
-    return n;
-}
-
-void red_channel_pipes_new_add(RedChannel *channel, new_pipe_item_t creator, void *data)
-{
-    red_channel_pipes_create_batch(channel, creator, data,
-                                     red_channel_client_pipe_add);
+    return red_channel_pipes_create_batch(channel, creator, data,
+                                          red_channel_client_pipe_add);
 }
 
 uint32_t red_channel_max_pipe_size(RedChannel *channel)
diff --git a/server/red-channel.h b/server/red-channel.h
index a699f4e2..e8feea2c 100644
--- a/server/red-channel.h
+++ b/server/red-channel.h
@@ -165,8 +165,7 @@ void red_channel_init_outgoing_messages_window(RedChannel *channel);
 
 // helper to push a new item to all channels
 typedef RedPipeItem *(*new_pipe_item_t)(RedChannelClient *rcc, void *data, int num);
-int red_channel_pipes_new_add_push(RedChannel *channel, new_pipe_item_t creator, void *data);
-void red_channel_pipes_new_add(RedChannel *channel, new_pipe_item_t creator, void *data);
+int red_channel_pipes_new_add(RedChannel *channel, new_pipe_item_t creator, void *data);
 
 void red_channel_pipes_add_type(RedChannel *channel, int pipe_item_type);
 
commit ee929dd43a4ce45bebff796f5293efd2936feca9
Author: Frediano Ziglio <fziglio at redhat.com>
Date:   Tue Aug 29 08:49:21 2017 +0100

    red-channel: Reuse red_channel_pipes_add
    
    Implements red_channel_pipes_add_type and
    red_channel_pipes_add_empty_msg using red_channel_pipes_add.
    This avoid duplicating items for each client.
    
    Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
    Acked-by: Jonathon Jongsma <jjongsma at redhat.com>
    Acked-by: Christophe Fergeau <cfergeau at redhat.com>

diff --git a/server/red-channel-client.c b/server/red-channel-client.c
index d145c736..655e41c7 100644
--- a/server/red-channel-client.c
+++ b/server/red-channel-client.c
@@ -1592,13 +1592,18 @@ void red_channel_client_pipe_add_type(RedChannelClient *rcc, int pipe_item_type)
     red_channel_client_pipe_add(rcc, item);
 }
 
-void red_channel_client_pipe_add_empty_msg(RedChannelClient *rcc, int msg_type)
+RedPipeItem *red_channel_client_new_empty_msg(int msg_type)
 {
     RedEmptyMsgPipeItem *item = spice_new(RedEmptyMsgPipeItem, 1);
 
     red_pipe_item_init(&item->base, RED_PIPE_ITEM_TYPE_EMPTY_MSG);
     item->msg = msg_type;
-    red_channel_client_pipe_add(rcc, &item->base);
+    return &item->base;
+}
+
+void red_channel_client_pipe_add_empty_msg(RedChannelClient *rcc, int msg_type)
+{
+    red_channel_client_pipe_add(rcc, red_channel_client_new_empty_msg(msg_type));
 }
 
 gboolean red_channel_client_pipe_is_empty(RedChannelClient *rcc)
diff --git a/server/red-channel-client.h b/server/red-channel-client.h
index 3665dacc..f5e04df7 100644
--- a/server/red-channel-client.h
+++ b/server/red-channel-client.h
@@ -99,6 +99,7 @@ void red_channel_client_pipe_add_tail(RedChannelClient *rcc, RedPipeItem *item);
 void red_channel_client_pipe_add_tail_and_push(RedChannelClient *rcc, RedPipeItem *item);
 /* for types that use this routine -> the pipe item should be freed */
 void red_channel_client_pipe_add_type(RedChannelClient *rcc, int pipe_item_type);
+RedPipeItem *red_channel_client_new_empty_msg(int msg_type);
 void red_channel_client_pipe_add_empty_msg(RedChannelClient *rcc, int msg_type);
 gboolean red_channel_client_pipe_is_empty(RedChannelClient *rcc);
 uint32_t red_channel_client_get_pipe_size(RedChannelClient *rcc);
diff --git a/server/red-channel.c b/server/red-channel.c
index 4229794d..a2c068e5 100644
--- a/server/red-channel.c
+++ b/server/red-channel.c
@@ -441,28 +441,18 @@ void red_channel_pipes_add(RedChannel *channel, RedPipeItem *item)
     red_pipe_item_unref(item);
 }
 
-static void red_channel_client_pipe_add_type_proxy(gpointer data, gpointer user_data)
-{
-    int type = GPOINTER_TO_INT(user_data);
-    red_channel_client_pipe_add_type(data, type);
-}
-
 void red_channel_pipes_add_type(RedChannel *channel, int pipe_item_type)
 {
-    g_list_foreach(channel->priv->clients, red_channel_client_pipe_add_type_proxy,
-                   GINT_TO_POINTER(pipe_item_type));
-}
+    RedPipeItem *item = spice_new(RedPipeItem, 1);
 
-static void red_channel_client_pipe_add_empty_msg_proxy(gpointer data, gpointer user_data)
-{
-    int type = GPOINTER_TO_INT(user_data);
-    red_channel_client_pipe_add_empty_msg(data, type);
+    red_pipe_item_init(item, pipe_item_type);
+
+    red_channel_pipes_add(channel, item);
 }
 
 void red_channel_pipes_add_empty_msg(RedChannel *channel, int msg_type)
 {
-    g_list_foreach(channel->priv->clients, red_channel_client_pipe_add_empty_msg_proxy,
-                   GINT_TO_POINTER(msg_type));
+    red_channel_pipes_add(channel, red_channel_client_new_empty_msg(msg_type));
 }
 
 int red_channel_is_connected(RedChannel *channel)
commit f8212431d2e25cbc0ca93b228fcb0545db8437cd
Author: Frediano Ziglio <fziglio at redhat.com>
Date:   Tue Aug 29 08:26:24 2017 +0100

    Use new red_channel_pipes_add instead of red_channel_pipes_new_add
    
    Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
    Acked-by: Jonathon Jongsma <jjongsma at redhat.com>
    Acked-by: Christophe Fergeau <cfergeau at redhat.com>

diff --git a/server/cursor-channel.c b/server/cursor-channel.c
index 8ac5af47..2441e1ed 100644
--- a/server/cursor-channel.c
+++ b/server/cursor-channel.c
@@ -110,13 +110,13 @@ static void cursor_channel_set_item(CursorChannel *cursor, CursorItem *item)
     cursor->item = item ? cursor_item_ref(item) : NULL;
 }
 
-static RedPipeItem *new_cursor_pipe_item(RedChannelClient *rcc, void *data, int num)
+static RedPipeItem *new_cursor_pipe_item(CursorItem *cursor_item)
 {
     RedCursorPipeItem *item = spice_malloc0(sizeof(RedCursorPipeItem));
 
     red_pipe_item_init_full(&item->base, RED_PIPE_ITEM_TYPE_CURSOR,
                             cursor_pipe_item_free);
-    item->cursor_item = data;
+    item->cursor_item = cursor_item;
     item->cursor_item->refs++;
     return &item->base;
 }
@@ -333,8 +333,7 @@ void cursor_channel_process_cmd(CursorChannel *cursor, RedCursorCmd *cursor_cmd)
         (cursor->mouse_mode == SPICE_MOUSE_MODE_SERVER
          || cursor_cmd->type != QXL_CURSOR_MOVE
          || cursor_show)) {
-        red_channel_pipes_new_add(RED_CHANNEL(cursor),
-                                  new_cursor_pipe_item, cursor_item);
+        red_channel_pipes_add(RED_CHANNEL(cursor), new_cursor_pipe_item(cursor_item));
     }
 
     cursor_item_unref(cursor_item);
diff --git a/server/inputs-channel.c b/server/inputs-channel.c
index 5ddf2b39..8e17cc72 100644
--- a/server/inputs-channel.c
+++ b/server/inputs-channel.c
@@ -194,13 +194,12 @@ static uint8_t kbd_get_leds(SpiceKbdInstance *sin)
     return sif->get_leds(sin);
 }
 
-static RedPipeItem *red_inputs_key_modifiers_item_new(
-    RedChannelClient *rcc, void *data, int num)
+static RedPipeItem *red_inputs_key_modifiers_item_new(uint8_t modifiers)
 {
     RedKeyModifiersPipeItem *item = spice_malloc(sizeof(RedKeyModifiersPipeItem));
 
     red_pipe_item_init(&item->base, RED_PIPE_ITEM_KEY_MODIFIERS);
-    item->modifiers = *(uint8_t *)data;
+    item->modifiers = modifiers;
     return &item->base;
 }
 
@@ -476,8 +475,8 @@ static void inputs_channel_push_keyboard_modifiers(InputsChannel *inputs, uint8_
         inputs->src_during_migrate) {
         return;
     }
-    red_channel_pipes_new_add_push(RED_CHANNEL(inputs),
-        red_inputs_key_modifiers_item_new, (void*)&modifiers);
+    red_channel_pipes_add(RED_CHANNEL(inputs),
+                          red_inputs_key_modifiers_item_new(modifiers));
 }
 
 void inputs_channel_on_keyboard_leds_change(InputsChannel *inputs, uint8_t leds)
diff --git a/server/main-channel-client.c b/server/main-channel-client.c
index 4d841c81..4abab6c6 100644
--- a/server/main-channel-client.c
+++ b/server/main-channel-client.c
@@ -426,26 +426,23 @@ void main_channel_client_push_notify(MainChannelClient *mcc, const char *msg)
     red_channel_client_pipe_add_push(RED_CHANNEL_CLIENT(mcc), item);
 }
 
-RedPipeItem *main_mouse_mode_item_new(RedChannelClient *rcc, void *data, int num)
+RedPipeItem *main_mouse_mode_item_new(SpiceMouseMode current_mode, int is_client_mouse_allowed)
 {
     RedMouseModePipeItem *item = spice_malloc(sizeof(RedMouseModePipeItem));
-    MainMouseModeItemInfo *info = data;
 
     red_pipe_item_init(&item->base, RED_PIPE_ITEM_TYPE_MAIN_MOUSE_MODE);
-    item->current_mode = info->current_mode;
-    item->is_client_mouse_allowed = info->is_client_mouse_allowed;
+    item->current_mode = current_mode;
+    item->is_client_mouse_allowed = is_client_mouse_allowed;
     return &item->base;
 }
 
-RedPipeItem *main_multi_media_time_item_new(RedChannelClient *rcc,
-                                            void *data, int num)
+RedPipeItem *main_multi_media_time_item_new(uint32_t mm_time)
 {
-    MainMultiMediaTimeItemInfo *info = data;
     RedMultiMediaTimePipeItem *item;
 
     item = spice_malloc(sizeof(RedMultiMediaTimePipeItem));
     red_pipe_item_init(&item->base, RED_PIPE_ITEM_TYPE_MAIN_MULTI_MEDIA_TIME);
-    item->time = info->time;
+    item->time = mm_time;
     return &item->base;
 }
 
diff --git a/server/main-channel-client.h b/server/main-channel-client.h
index 0f8e4f49..26b7e20b 100644
--- a/server/main-channel-client.h
+++ b/server/main-channel-client.h
@@ -124,19 +124,9 @@ enum {
     RED_PIPE_ITEM_TYPE_MAIN_AGENT_CONNECTED_TOKENS,
 };
 
-typedef struct MainMouseModeItemInfo {
-    SpiceMouseMode current_mode;
-    int is_client_mouse_allowed;
-} MainMouseModeItemInfo;
+RedPipeItem *main_mouse_mode_item_new(SpiceMouseMode current_mode, int is_client_mouse_allowed);
 
-RedPipeItem *main_mouse_mode_item_new(RedChannelClient *rcc, void *data, int num);
-
-typedef struct MainMultiMediaTimeItemInfo {
-    uint32_t time;
-} MainMultiMediaTimeItemInfo;
-
-RedPipeItem *main_multi_media_time_item_new(RedChannelClient *rcc,
-                                            void *data, int num);
+RedPipeItem *main_multi_media_time_item_new(uint32_t mm_time);
 
 G_END_DECLS
 
diff --git a/server/main-channel.c b/server/main-channel.c
index e72e5d79..9d2590aa 100644
--- a/server/main-channel.c
+++ b/server/main-channel.c
@@ -76,13 +76,8 @@ static void main_channel_push_channels(MainChannelClient *mcc)
 void main_channel_push_mouse_mode(MainChannel *main_chan, SpiceMouseMode current_mode,
                                   int is_client_mouse_allowed)
 {
-    MainMouseModeItemInfo info = {
-        .current_mode=current_mode,
-        .is_client_mouse_allowed=is_client_mouse_allowed,
-    };
-
-    red_channel_pipes_new_add(RED_CHANNEL(main_chan),
-        main_mouse_mode_item_new, &info);
+    red_channel_pipes_add(RED_CHANNEL(main_chan),
+                          main_mouse_mode_item_new(current_mode, is_client_mouse_allowed));
 }
 
 void main_channel_push_agent_connected(MainChannel *main_chan)
@@ -136,12 +131,7 @@ static bool main_channel_handle_migrate_data(RedChannelClient *rcc,
 
 void main_channel_push_multi_media_time(MainChannel *main_chan, uint32_t time)
 {
-    MainMultiMediaTimeItemInfo info = {
-        .time = time,
-    };
-
-    red_channel_pipes_new_add(RED_CHANNEL(main_chan),
-        main_multi_media_time_item_new, &info);
+    red_channel_pipes_add(RED_CHANNEL(main_chan), main_multi_media_time_item_new(time));
 }
 
 static void main_channel_fill_mig_target(MainChannel *main_channel, RedsMigSpice *mig_target)
commit da3a5cc0ca74da7cce6962a3923fc2780a58137e
Author: Frediano Ziglio <fziglio at redhat.com>
Date:   Tue Aug 29 08:23:58 2017 +0100

    red-channel: Add red_channel_pipes_add function
    
    Considering that now RedPipeItem have reference counting
    and that lot of items are just used to store constant
    data to send, using reference counting instead of creating
    different items for each client is easier to do.
    So this new red_channel_pipes_add allows to add a single item
    to all clients.
    
    Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
    Acked-by: Christophe Fergeau <cfergeau at redhat.com>

diff --git a/server/red-channel.c b/server/red-channel.c
index a8ab5230..4229794d 100644
--- a/server/red-channel.c
+++ b/server/red-channel.c
@@ -429,6 +429,18 @@ void red_channel_init_outgoing_messages_window(RedChannel *channel)
                    (GFunc)red_channel_client_init_outgoing_messages_window, NULL);
 }
 
+void red_channel_pipes_add(RedChannel *channel, RedPipeItem *item)
+{
+    RedChannelClient *rcc;
+
+    FOREACH_CLIENT(channel, rcc) {
+        red_pipe_item_ref(item);
+        red_channel_client_pipe_add(rcc, item);
+    }
+
+    red_pipe_item_unref(item);
+}
+
 static void red_channel_client_pipe_add_type_proxy(gpointer data, gpointer user_data)
 {
     int type = GPOINTER_TO_INT(user_data);
diff --git a/server/red-channel.h b/server/red-channel.h
index 8ea5a711..a699f4e2 100644
--- a/server/red-channel.h
+++ b/server/red-channel.h
@@ -172,6 +172,12 @@ void red_channel_pipes_add_type(RedChannel *channel, int pipe_item_type);
 
 void red_channel_pipes_add_empty_msg(RedChannel *channel, int msg_type);
 
+/* Add an item to all the clients connected.
+ * The same item is shared between all clients.
+ * Function will take ownership of the item.
+ */
+void red_channel_pipes_add(RedChannel *channel, RedPipeItem *item);
+
 /* return TRUE if all of the connected clients to this channel are blocked */
 bool red_channel_all_blocked(RedChannel *channel);
 
commit 40c658f5183fa85305213c5efb664faafed24459
Author: Frediano Ziglio <fziglio at redhat.com>
Date:   Tue Aug 29 09:03:33 2017 +0100

    red-channel-client: Remove push call where not necessary
    
    Now the push is done automatically when a PipeItem is added
    (cfr commit 5c460de1a3972b7cf2b9b2944d0b500c3affc363
    "worker: push data when clients can receive them"),
    forcing a push cause only network fragmentation and is required only if
    you are handling data in a polling loop (and thus, you are preventing
    the default event loop from running).
    
    Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
    Acked-by: Christophe Fergeau <cfergeau at redhat.com>

diff --git a/server/main-channel.c b/server/main-channel.c
index c30374c3..e72e5d79 100644
--- a/server/main-channel.c
+++ b/server/main-channel.c
@@ -81,7 +81,7 @@ void main_channel_push_mouse_mode(MainChannel *main_chan, SpiceMouseMode current
         .is_client_mouse_allowed=is_client_mouse_allowed,
     };
 
-    red_channel_pipes_new_add_push(RED_CHANNEL(main_chan),
+    red_channel_pipes_new_add(RED_CHANNEL(main_chan),
         main_mouse_mode_item_new, &info);
 }
 
@@ -140,7 +140,7 @@ void main_channel_push_multi_media_time(MainChannel *main_chan, uint32_t time)
         .time = time,
     };
 
-    red_channel_pipes_new_add_push(RED_CHANNEL(main_chan),
+    red_channel_pipes_new_add(RED_CHANNEL(main_chan),
         main_multi_media_time_item_new, &info);
 }
 
diff --git a/server/red-channel-client.c b/server/red-channel-client.c
index 2612a6db..d145c736 100644
--- a/server/red-channel-client.c
+++ b/server/red-channel-client.c
@@ -1590,7 +1590,6 @@ void red_channel_client_pipe_add_type(RedChannelClient *rcc, int pipe_item_type)
 
     red_pipe_item_init(item, pipe_item_type);
     red_channel_client_pipe_add(rcc, item);
-    red_channel_client_push(rcc);
 }
 
 void red_channel_client_pipe_add_empty_msg(RedChannelClient *rcc, int msg_type)
@@ -1600,7 +1599,6 @@ void red_channel_client_pipe_add_empty_msg(RedChannelClient *rcc, int msg_type)
     red_pipe_item_init(&item->base, RED_PIPE_ITEM_TYPE_EMPTY_MSG);
     item->msg = msg_type;
     red_channel_client_pipe_add(rcc, &item->base);
-    red_channel_client_push(rcc);
 }
 
 gboolean red_channel_client_pipe_is_empty(RedChannelClient *rcc)


More information about the Spice-commits mailing list