[Spice-devel] [PATCH spice-server 5/6] red-channel: Reuse red_channel_pipes_add
Frediano Ziglio
fziglio at redhat.com
Tue Aug 29 10:53:38 UTC 2017
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>
---
server/red-channel-client.c | 9 +++++++--
server/red-channel-client.h | 1 +
server/red-channel.c | 20 +++++---------------
3 files changed, 13 insertions(+), 17 deletions(-)
diff --git a/server/red-channel-client.c b/server/red-channel-client.c
index 941c9aec..660a46d0 100644
--- a/server/red-channel-client.c
+++ b/server/red-channel-client.c
@@ -1593,13 +1593,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 057732f4..c39b564e 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 6e8e9c6b..490447ed 100644
--- a/server/red-channel.c
+++ b/server/red-channel.c
@@ -442,28 +442,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)
--
2.13.5
More information about the Spice-devel
mailing list