[Spice-devel] [PATCH 11/11] Use RED_CHANNEL_CLIENT() macro for casting
Jonathon Jongsma
jjongsma at redhat.com
Tue Aug 9 15:33:05 UTC 2016
Also remove (main|inputs)_channel_client_get_base() function to prepare
for porting to GObject.
---
server/cache-item.tmpl.c | 2 +-
server/dcc.c | 8 +++---
server/inputs-channel-client.c | 6 +++--
server/main-channel-client.c | 61 +++++++++++++++++++++---------------------
server/main-channel-client.h | 2 --
server/main-channel.c | 2 +-
server/reds.c | 15 +++++------
7 files changed, 47 insertions(+), 49 deletions(-)
diff --git a/server/cache-item.tmpl.c b/server/cache-item.tmpl.c
index ce38a2a..034f2ea 100644
--- a/server/cache-item.tmpl.c
+++ b/server/cache-item.tmpl.c
@@ -78,7 +78,7 @@ static void FUNC_NAME(remove)(CHANNELCLIENT *channel_client, RedCacheItem *item)
channel_client->priv->VAR_NAME(available) += item->u.cache_data.size;
red_pipe_item_init(&item->u.pipe_data, RED_PIPE_ITEM_TYPE_INVAL_ONE);
- red_channel_client_pipe_add_tail_and_push(&channel_client->base, &item->u.pipe_data); // for now
+ red_channel_client_pipe_add_tail_and_push(RED_CHANNEL_CLIENT(channel_client), &item->u.pipe_data); // for now
}
static int FUNC_NAME(add)(CHANNELCLIENT *channel_client, uint64_t id, size_t size)
diff --git a/server/dcc.c b/server/dcc.c
index 936a081..3850eb6 100644
--- a/server/dcc.c
+++ b/server/dcc.c
@@ -549,7 +549,7 @@ void dcc_push_monitors_config(DisplayChannelClient *dcc)
return;
}
- if (!red_channel_client_test_remote_cap(&dcc->base,
+ if (!red_channel_client_test_remote_cap(RED_CHANNEL_CLIENT(dcc),
SPICE_DISPLAY_CAP_MONITORS_CONFIG)) {
return;
}
@@ -557,8 +557,8 @@ void dcc_push_monitors_config(DisplayChannelClient *dcc)
channel = red_channel_client_get_channel(RED_CHANNEL_CLIENT(dcc));
mci = red_monitors_config_item_new(channel,
monitors_config_ref(dc->monitors_config));
- red_channel_client_pipe_add(&dcc->base, &mci->pipe_item);
- red_channel_client_push(&dcc->base);
+ red_channel_client_pipe_add(RED_CHANNEL_CLIENT(dcc), &mci->pipe_item);
+ red_channel_client_push(RED_CHANNEL_CLIENT(dcc));
}
static RedSurfaceDestroyItem *red_surface_destroy_item_new(RedChannel *channel,
@@ -753,7 +753,7 @@ int dcc_compress_image(DisplayChannelClient *dcc,
goto lz_compress;
#ifdef USE_LZ4
case SPICE_IMAGE_COMPRESSION_LZ4:
- if (red_channel_client_test_remote_cap(&dcc->base,
+ if (red_channel_client_test_remote_cap(RED_CHANNEL_CLIENT(dcc),
SPICE_DISPLAY_CAP_LZ4_COMPRESSION)) {
success = image_encoders_compress_lz4(&dcc->priv->encoders, dest, src, o_comp_data);
break;
diff --git a/server/inputs-channel-client.c b/server/inputs-channel-client.c
index 6712508..b80ae0f 100644
--- a/server/inputs-channel-client.c
+++ b/server/inputs-channel-client.c
@@ -80,7 +80,8 @@ void inputs_channel_client_handle_migrate_data(InputsChannelClient *icc,
for (; icc->priv->motion_count >= SPICE_INPUT_MOTION_ACK_BUNCH;
icc->priv->motion_count -= SPICE_INPUT_MOTION_ACK_BUNCH) {
- red_channel_client_pipe_add_type(&icc->base, RED_PIPE_ITEM_MOUSE_MOTION_ACK);
+ red_channel_client_pipe_add_type(RED_CHANNEL_CLIENT(icc),
+ RED_PIPE_ITEM_MOUSE_MOTION_ACK);
}
}
@@ -90,7 +91,8 @@ void inputs_channel_client_on_mouse_motion(InputsChannelClient *icc)
if (++icc->priv->motion_count % SPICE_INPUT_MOTION_ACK_BUNCH == 0 &&
!inputs_channel_is_src_during_migrate(inputs_channel)) {
- red_channel_client_pipe_add_type(&icc->base, RED_PIPE_ITEM_MOUSE_MOTION_ACK);
+ red_channel_client_pipe_add_type(RED_CHANNEL_CLIENT(icc),
+ RED_PIPE_ITEM_MOUSE_MOTION_ACK);
icc->priv->motion_count = 0;
}
}
diff --git a/server/main-channel-client.c b/server/main-channel-client.c
index 23cf439..eb1682e 100644
--- a/server/main-channel-client.c
+++ b/server/main-channel-client.c
@@ -158,7 +158,8 @@ void main_channel_client_start_net_test(MainChannelClient *mcc, int test_rate)
mcc->priv->net_test_stage = NET_TEST_STAGE_WARMUP;
}
} else {
- red_channel_client_start_connectivity_monitoring(&mcc->base, CLIENT_CONNECTIVITY_TIMEOUT);
+ red_channel_client_start_connectivity_monitoring(RED_CHANNEL_CLIENT(mcc),
+ CLIENT_CONNECTIVITY_TIMEOUT);
}
}
@@ -179,7 +180,7 @@ static int main_channel_client_push_ping(MainChannelClient *mcc, int size)
return FALSE;
}
item = red_ping_item_new(size);
- red_channel_client_pipe_add_push(&mcc->base, item);
+ red_channel_client_pipe_add_push(RED_CHANNEL_CLIENT(mcc), item);
return TRUE;
}
@@ -197,7 +198,7 @@ void main_channel_client_push_agent_tokens(MainChannelClient *mcc, uint32_t num_
{
RedPipeItem *item = main_agent_tokens_item_new(num_tokens);
- red_channel_client_pipe_add_push(&mcc->base, item);
+ red_channel_client_pipe_add_push(RED_CHANNEL_CLIENT(mcc), item);
}
static void main_agent_data_item_free(RedPipeItem *base)
@@ -228,7 +229,7 @@ void main_channel_client_push_agent_data(MainChannelClient *mcc, uint8_t* data,
RedPipeItem *item;
item = main_agent_data_item_new(data, len, free_data, opaque);
- red_channel_client_pipe_add_push(&mcc->base, item);
+ red_channel_client_pipe_add_push(RED_CHANNEL_CLIENT(mcc), item);
}
static RedPipeItem *main_init_item_new(int connection_id,
@@ -262,7 +263,7 @@ void main_channel_client_push_init(MainChannelClient *mcc,
item = main_init_item_new(mcc->priv->connection_id, display_channels_hint,
current_mouse_mode, is_client_mouse_allowed,
multi_media_time, ram_hint);
- red_channel_client_pipe_add_push(&mcc->base, item);
+ red_channel_client_pipe_add_push(RED_CHANNEL_CLIENT(mcc), item);
}
static RedPipeItem *main_name_item_new(const char *name)
@@ -280,12 +281,12 @@ void main_channel_client_push_name(MainChannelClient *mcc, const char *name)
{
RedPipeItem *item;
- if (!red_channel_client_test_remote_cap(&mcc->base,
+ if (!red_channel_client_test_remote_cap(RED_CHANNEL_CLIENT(mcc),
SPICE_MAIN_CAP_NAME_AND_UUID))
return;
item = main_name_item_new(name);
- red_channel_client_pipe_add_push(&mcc->base, item);
+ red_channel_client_pipe_add_push(RED_CHANNEL_CLIENT(mcc), item);
}
static RedPipeItem *main_uuid_item_new(const uint8_t uuid[16])
@@ -302,18 +303,18 @@ void main_channel_client_push_uuid(MainChannelClient *mcc, const uint8_t uuid[16
{
RedPipeItem *item;
- if (!red_channel_client_test_remote_cap(&mcc->base,
+ if (!red_channel_client_test_remote_cap(RED_CHANNEL_CLIENT(mcc),
SPICE_MAIN_CAP_NAME_AND_UUID))
return;
item = main_uuid_item_new(uuid);
- red_channel_client_pipe_add_push(&mcc->base, item);
+ red_channel_client_pipe_add_push(RED_CHANNEL_CLIENT(mcc), item);
}
void main_channel_client_push_notify(MainChannelClient *mcc, const char *msg)
{
RedPipeItem *item = main_notify_item_new(msg, 1);
- red_channel_client_pipe_add_push(&mcc->base, item);
+ red_channel_client_pipe_add_push(RED_CHANNEL_CLIENT(mcc), item);
}
RedPipeItem *main_mouse_mode_item_new(RedChannelClient *rcc, void *data, int num)
@@ -370,10 +371,10 @@ void main_channel_client_handle_migrate_dst_do_seamless(MainChannelClient *mcc,
RedChannel *channel = red_channel_client_get_channel(RED_CHANNEL_CLIENT(mcc));
if (reds_on_migrate_dst_set_seamless(channel->reds, mcc, src_version)) {
mcc->priv->seamless_mig_dst = TRUE;
- red_channel_client_pipe_add_empty_msg(&mcc->base,
+ red_channel_client_pipe_add_empty_msg(RED_CHANNEL_CLIENT(mcc),
SPICE_MSG_MAIN_MIGRATE_DST_SEAMLESS_ACK);
} else {
- red_channel_client_pipe_add_empty_msg(&mcc->base,
+ red_channel_client_pipe_add_empty_msg(RED_CHANNEL_CLIENT(mcc),
SPICE_MSG_MAIN_MIGRATE_DST_SEAMLESS_NACK);
}
}
@@ -405,7 +406,7 @@ void main_channel_client_handle_pong(MainChannelClient *mcc, SpiceMsgPing *ping,
"bandwidth", mcc->priv->latency, roundtrip);
mcc->priv->latency = 0;
mcc->priv->net_test_stage = NET_TEST_STAGE_INVALID;
- red_channel_client_start_connectivity_monitoring(&mcc->base,
+ red_channel_client_start_connectivity_monitoring(RED_CHANNEL_CLIENT(mcc),
CLIENT_CONNECTIVITY_TIMEOUT);
break;
}
@@ -417,7 +418,7 @@ void main_channel_client_handle_pong(MainChannelClient *mcc, SpiceMsgPing *ping,
mcc->priv->bitrate_per_sec,
(double)mcc->priv->bitrate_per_sec / 1024 / 1024,
main_channel_client_is_low_bandwidth(mcc) ? " LOW BANDWIDTH" : "");
- red_channel_client_start_connectivity_monitoring(&mcc->base,
+ red_channel_client_start_connectivity_monitoring(RED_CHANNEL_CLIENT(mcc),
CLIENT_CONNECTIVITY_TIMEOUT);
break;
default:
@@ -446,7 +447,7 @@ void main_channel_client_handle_migrate_end(MainChannelClient *mcc)
spice_printerr("unexpected SPICE_MSGC_MIGRATE_END");
return;
}
- if (!red_channel_client_test_remote_cap(&mcc->base,
+ if (!red_channel_client_test_remote_cap(RED_CHANNEL_CLIENT(mcc),
SPICE_MAIN_CAP_SEMI_SEAMLESS_MIGRATE)) {
spice_printerr("unexpected SPICE_MSGC_MIGRATE_END, "
"client does not support semi-seamless migration");
@@ -472,10 +473,11 @@ void main_channel_client_migrate_dst_complete(MainChannelClient *mcc)
if (mcc->priv->mig_wait_prev_complete) {
if (mcc->priv->mig_wait_prev_try_seamless) {
spice_assert(g_list_length(channel->clients) == 1);
- red_channel_client_pipe_add_type(&mcc->base,
+ red_channel_client_pipe_add_type(RED_CHANNEL_CLIENT(mcc),
RED_PIPE_ITEM_TYPE_MAIN_MIGRATE_BEGIN_SEAMLESS);
} else {
- red_channel_client_pipe_add_type(&mcc->base, RED_PIPE_ITEM_TYPE_MAIN_MIGRATE_BEGIN);
+ red_channel_client_pipe_add_type(RED_CHANNEL_CLIENT(mcc),
+ RED_PIPE_ITEM_TYPE_MAIN_MIGRATE_BEGIN);
}
mcc->priv->mig_wait_connect = TRUE;
mcc->priv->mig_wait_prev_complete = FALSE;
@@ -487,21 +489,24 @@ gboolean main_channel_client_migrate_src_complete(MainChannelClient *mcc,
{
RedClient *client = red_channel_client_get_client(RED_CHANNEL_CLIENT(mcc));
gboolean ret = FALSE;
- int semi_seamless_support = red_channel_client_test_remote_cap(&mcc->base,
+ int semi_seamless_support = red_channel_client_test_remote_cap(RED_CHANNEL_CLIENT(mcc),
SPICE_MAIN_CAP_SEMI_SEAMLESS_MIGRATE);
if (semi_seamless_support && mcc->priv->mig_connect_ok) {
if (success) {
spice_printerr("client %p MIGRATE_END", client);
- red_channel_client_pipe_add_empty_msg(&mcc->base, SPICE_MSG_MAIN_MIGRATE_END);
+ red_channel_client_pipe_add_empty_msg(RED_CHANNEL_CLIENT(mcc),
+ SPICE_MSG_MAIN_MIGRATE_END);
ret = TRUE;
} else {
spice_printerr("client %p MIGRATE_CANCEL", client);
- red_channel_client_pipe_add_empty_msg(&mcc->base, SPICE_MSG_MAIN_MIGRATE_CANCEL);
+ red_channel_client_pipe_add_empty_msg(RED_CHANNEL_CLIENT(mcc),
+ SPICE_MSG_MAIN_MIGRATE_CANCEL);
}
} else {
if (success) {
spice_printerr("client %p SWITCH_HOST", client);
- red_channel_client_pipe_add_type(&mcc->base, RED_PIPE_ITEM_TYPE_MAIN_MIGRATE_SWITCH_HOST);
+ red_channel_client_pipe_add_type(RED_CHANNEL_CLIENT(mcc),
+ RED_PIPE_ITEM_TYPE_MAIN_MIGRATE_SWITCH_HOST);
}
}
mcc->priv->mig_connect_ok = FALSE;
@@ -535,7 +540,7 @@ static void ping_timer_cb(void *opaque)
MainChannelClient *mcc = opaque;
RedChannel *channel = red_channel_client_get_channel(RED_CHANNEL_CLIENT(mcc));
- if (!red_channel_client_is_connected(&mcc->base)) {
+ if (!red_channel_client_is_connected(RED_CHANNEL_CLIENT(mcc))) {
spice_printerr("not connected to peer, ping off");
reds_core_timer_cancel(channel->reds, mcc->priv->ping_timer);
return;
@@ -597,7 +602,7 @@ void main_channel_client_migrate(RedChannelClient *rcc)
gboolean main_channel_client_connect_semi_seamless(MainChannelClient *mcc)
{
- RedChannelClient *rcc = main_channel_client_get_base(mcc);
+ RedChannelClient *rcc = RED_CHANNEL_CLIENT(mcc);
MainChannel* main_channel = SPICE_CONTAINEROF(red_channel_client_get_channel(rcc),
MainChannel, base);
if (red_channel_client_test_remote_cap(rcc,
@@ -622,26 +627,20 @@ gboolean main_channel_client_connect_semi_seamless(MainChannelClient *mcc)
void main_channel_client_connect_seamless(MainChannelClient *mcc)
{
RedClient *client = red_channel_client_get_client(RED_CHANNEL_CLIENT(mcc));
- spice_assert(red_channel_client_test_remote_cap(&mcc->base,
+ spice_assert(red_channel_client_test_remote_cap(RED_CHANNEL_CLIENT(mcc),
SPICE_MAIN_CAP_SEAMLESS_MIGRATE));
if (red_client_during_migrate_at_target(client)) {
spice_printerr("client %p: wait till previous migration completes", client);
mcc->priv->mig_wait_prev_complete = TRUE;
mcc->priv->mig_wait_prev_try_seamless = TRUE;
} else {
- red_channel_client_pipe_add_type(&mcc->base,
+ red_channel_client_pipe_add_type(RED_CHANNEL_CLIENT(mcc),
RED_PIPE_ITEM_TYPE_MAIN_MIGRATE_BEGIN_SEAMLESS);
mcc->priv->mig_wait_connect = TRUE;
}
mcc->priv->mig_connect_ok = FALSE;
}
-RedChannelClient* main_channel_client_get_base(MainChannelClient* mcc)
-{
- spice_assert(mcc);
- return &mcc->base;
-}
-
uint32_t main_channel_client_get_connection_id(MainChannelClient *mcc)
{
return mcc->priv->connection_id;
diff --git a/server/main-channel-client.h b/server/main-channel-client.h
index c74f847..9f05af3 100644
--- a/server/main-channel-client.h
+++ b/server/main-channel-client.h
@@ -66,8 +66,6 @@ int main_channel_client_is_low_bandwidth(MainChannelClient *mcc);
uint64_t main_channel_client_get_bitrate_per_sec(MainChannelClient *mcc);
uint64_t main_channel_client_get_roundtrip_ms(MainChannelClient *mcc);
-RedChannelClient* main_channel_client_get_base(MainChannelClient* mcc);
-
void main_channel_client_push_name(MainChannelClient *mcc, const char *name);
void main_channel_client_push_uuid(MainChannelClient *mcc, const uint8_t uuid[16]);
diff --git a/server/main-channel.c b/server/main-channel.c
index b25dba2..998ca68 100644
--- a/server/main-channel.c
+++ b/server/main-channel.c
@@ -57,7 +57,7 @@ RedClient *main_channel_get_client_by_link_id(MainChannel *main_chan, uint32_t c
static void main_channel_push_channels(MainChannelClient *mcc)
{
- RedChannelClient *rcc = main_channel_client_get_base(mcc);
+ RedChannelClient *rcc = RED_CHANNEL_CLIENT(mcc);
if (red_client_during_migrate_at_target(red_channel_client_get_client(rcc))) {
spice_printerr("warning: ignoring unexpected SPICE_MSGC_MAIN_ATTACH_CHANNELS"
"during migration");
diff --git a/server/reds.c b/server/reds.c
index 90358e4..c4f43c7 100644
--- a/server/reds.c
+++ b/server/reds.c
@@ -933,8 +933,7 @@ static void vdi_port_on_free_self_token(void *opaque)
static void vdi_port_remove_client(RedClient *client, void *opaque)
{
- red_channel_client_shutdown(main_channel_client_get_base(
- red_client_get_main(client)));
+ red_channel_client_shutdown(RED_CHANNEL_CLIENT(red_client_get_main(client)));
}
/****************************************************************************/
@@ -1048,7 +1047,7 @@ void reds_on_main_agent_start(RedsState *reds, MainChannelClient *mcc, uint32_t
return;
}
spice_assert(reds->vdagent->st && reds->vdagent->st == dev_state);
- rcc = main_channel_client_get_base(mcc);
+ rcc = RED_CHANNEL_CLIENT(mcc);
client = red_channel_client_get_client(rcc);
reds->agent_dev->priv->client_agent_started = TRUE;
/*
@@ -1088,7 +1087,7 @@ void reds_on_main_agent_start(RedsState *reds, MainChannelClient *mcc, uint32_t
void reds_on_main_agent_tokens(RedsState *reds, MainChannelClient *mcc, uint32_t num_tokens)
{
- RedClient *client = red_channel_client_get_client(main_channel_client_get_base(mcc));
+ RedClient *client = red_channel_client_get_client(RED_CHANNEL_CLIENT(mcc));
if (!reds->vdagent) {
return;
}
@@ -1115,7 +1114,7 @@ uint8_t *reds_get_agent_data_buffer(RedsState *reds, MainChannelClient *mcc, siz
}
spice_assert(dev->priv->recv_from_client_buf == NULL);
- client = red_channel_client_get_client(main_channel_client_get_base(mcc));
+ client = red_channel_client_get_client(RED_CHANNEL_CLIENT(mcc));
dev->priv->recv_from_client_buf = red_char_device_write_buffer_get(RED_CHAR_DEVICE(dev),
client,
size + sizeof(VDIChunkHeader));
@@ -1199,7 +1198,7 @@ void reds_on_main_agent_data(RedsState *reds, MainChannelClient *mcc, void *mess
reds_on_main_agent_monitors_config(reds, mcc, message, size);
return;
case AGENT_MSG_FILTER_PROTO_ERROR:
- red_channel_client_shutdown(main_channel_client_get_base(mcc));
+ red_channel_client_shutdown(RED_CHANNEL_CLIENT(mcc));
return;
}
@@ -1486,7 +1485,7 @@ int reds_handle_migrate_data(RedsState *reds, MainChannelClient *mcc,
} else {
spice_debug("agent was not attached on the source host");
if (reds->vdagent) {
- RedClient *client = red_channel_client_get_client(main_channel_client_get_base(mcc));
+ RedClient *client = red_channel_client_get_client(RED_CHANNEL_CLIENT(mcc));
/* red_char_device_client_remove disables waiting for migration data */
red_char_device_client_remove(RED_CHAR_DEVICE(agent_dev), client);
main_channel_push_agent_connected(reds->main_channel);
@@ -1931,7 +1930,7 @@ int reds_on_migrate_dst_set_seamless(RedsState *reds, MainChannelClient *mcc, ui
if (reds->allow_multiple_clients || src_version > SPICE_MIGRATION_PROTOCOL_VERSION) {
reds->dst_do_seamless_migrate = FALSE;
} else {
- RedChannelClient *rcc = main_channel_client_get_base(mcc);
+ RedChannelClient *rcc = RED_CHANNEL_CLIENT(mcc);
RedClient *client = red_channel_client_get_client(rcc);
red_client_set_migration_seamless(client);
--
2.7.4
More information about the Spice-devel
mailing list