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@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
This commit is contained in:
Frediano Ziglio 2017-08-29 08:49:21 +01:00
parent f8212431d2
commit ee929dd43a
3 changed files with 13 additions and 17 deletions

View File

@ -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)

View File

@ -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);

View File

@ -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)