diff options
author | Jonathon Jongsma <jjongsma@redhat.com> | 2016-08-18 13:12:03 -0500 |
---|---|---|
committer | Jonathon Jongsma <jjongsma@redhat.com> | 2016-08-30 16:53:29 -0500 |
commit | 2fa1c1e3fd230cd756b33e94be27515b070f47bc (patch) | |
tree | fce4db65997ae3d0ccd83a11d43557fd9463419b | |
parent | d5d59d0858e84e1979646092e718915dd5d63412 (diff) |
Use red_channel_client_get_client() everywhere
Instead of having all other classes poke into the RedChannelClient
struct to get the RedClient associated with the channel client, call the
accessor function. This commit allows us to encapsulate RedChannelClient
and move it to its own file soon.
-rw-r--r-- | server/dcc.c | 9 | ||||
-rw-r--r-- | server/main-channel-client.c | 27 | ||||
-rw-r--r-- | server/main-channel.c | 8 | ||||
-rw-r--r-- | server/reds.c | 22 | ||||
-rw-r--r-- | server/smartcard.c | 15 | ||||
-rw-r--r-- | server/sound.c | 2 | ||||
-rw-r--r-- | server/spicevmc.c | 18 | ||||
-rw-r--r-- | server/stream.c | 13 |
8 files changed, 68 insertions, 46 deletions
diff --git a/server/dcc.c b/server/dcc.c index 9c3ab644..8eca28b7 100644 --- a/server/dcc.c +++ b/server/dcc.c @@ -892,18 +892,19 @@ int dcc_pixmap_cache_unlocked_add(DisplayChannelClient *dcc, uint64_t id, static int dcc_handle_init(DisplayChannelClient *dcc, SpiceMsgcDisplayInit *init) { gboolean success; + RedClient *client = red_channel_client_get_client(RED_CHANNEL_CLIENT(dcc)); spice_return_val_if_fail(dcc->expect_init, FALSE); dcc->expect_init = FALSE; spice_return_val_if_fail(!dcc->pixmap_cache, FALSE); - dcc->pixmap_cache = pixmap_cache_get(RED_CHANNEL_CLIENT(dcc)->client, + dcc->pixmap_cache = pixmap_cache_get(client, init->pixmap_cache_id, init->pixmap_cache_size); spice_return_val_if_fail(dcc->pixmap_cache, FALSE); success = image_encoders_get_glz_dictionary(&dcc->encoders, - RED_CHANNEL_CLIENT(dcc)->client, + client, init->glz_dictionary_id, init->glz_dictionary_window_size); spice_return_val_if_fail(success, FALSE); @@ -1007,7 +1008,7 @@ static int dcc_handle_migrate_glz_dictionary(DisplayChannelClient *dcc, SpiceMigrateDataDisplay *migrate) { return image_encoders_restore_glz_dictionary(&dcc->encoders, - RED_CHANNEL_CLIENT(dcc)->client, + red_channel_client_get_client(RED_CHANNEL_CLIENT(dcc)), migrate->glz_dict_id, &migrate->glz_dict_data); } @@ -1083,7 +1084,7 @@ int dcc_handle_migrate_data(DisplayChannelClient *dcc, uint32_t size, void *mess * channel client that froze the cache on the src size receives the migrate * data and unfreezes the cache by setting its size > 0 and by triggering * pixmap_cache_reset */ - dcc->pixmap_cache = pixmap_cache_get(RED_CHANNEL_CLIENT(dcc)->client, + dcc->pixmap_cache = pixmap_cache_get(red_channel_client_get_client(RED_CHANNEL_CLIENT(dcc)), migrate_data->pixmap_cache_id, -1); spice_return_val_if_fail(dcc->pixmap_cache, FALSE); diff --git a/server/main-channel-client.c b/server/main-channel-client.c index 7a96a57b..12151a7f 100644 --- a/server/main-channel-client.c +++ b/server/main-channel-client.c @@ -335,7 +335,8 @@ void main_channel_client_handle_migrate_connected(MainChannelClient *mcc, int success, int seamless) { - spice_printerr("client %p connected: %d seamless %d", mcc->base.client, success, seamless); + RedClient *client = red_channel_client_get_client(&mcc->base); + spice_printerr("client %p connected: %d seamless %d", client, success, seamless); if (mcc->mig_wait_connect) { RedChannel *channel = red_channel_client_get_channel(&mcc->base); MainChannel *main_channel = SPICE_CONTAINEROF(channel, MainChannel, base); @@ -349,7 +350,7 @@ void main_channel_client_handle_migrate_connected(MainChannelClient *mcc, } } else { if (success) { - spice_printerr("client %p MIGRATE_CANCEL", mcc->base.client); + spice_printerr("client %p MIGRATE_CANCEL", client); red_channel_client_pipe_add_empty_msg(&mcc->base, SPICE_MSG_MAIN_MIGRATE_CANCEL); } } @@ -432,7 +433,8 @@ void main_channel_client_handle_pong(MainChannelClient *mcc, SpiceMsgPing *ping, void main_channel_client_handle_migrate_end(MainChannelClient *mcc) { - if (!red_client_during_migrate_at_target(mcc->base.client)) { + RedClient *client = red_channel_client_get_client(&mcc->base); + if (!red_client_during_migrate_at_target(client)) { spice_printerr("unexpected SPICE_MSGC_MIGRATE_END"); return; } @@ -442,13 +444,14 @@ void main_channel_client_handle_migrate_end(MainChannelClient *mcc) "client does not support semi-seamless migration"); return; } - red_client_semi_seamless_migrate_complete(mcc->base.client); + red_client_semi_seamless_migrate_complete(client); } void main_channel_client_migrate_cancel_wait(MainChannelClient *mcc) { if (mcc->mig_wait_connect) { - spice_printerr("client %p cancel wait connect", mcc->base.client); + spice_printerr("client %p cancel wait connect", + red_channel_client_get_client(&mcc->base)); mcc->mig_wait_connect = FALSE; mcc->mig_connect_ok = FALSE; } @@ -475,20 +478,21 @@ gboolean main_channel_client_migrate_src_complete(MainChannelClient *mcc, gboolean success) { gboolean ret = FALSE; + RedClient *client = red_channel_client_get_client(&mcc->base); int semi_seamless_support = red_channel_client_test_remote_cap(&mcc->base, SPICE_MAIN_CAP_SEMI_SEAMLESS_MIGRATE); if (semi_seamless_support && mcc->mig_connect_ok) { if (success) { - spice_printerr("client %p MIGRATE_END", mcc->base.client); + spice_printerr("client %p MIGRATE_END", client); red_channel_client_pipe_add_empty_msg(&mcc->base, SPICE_MSG_MAIN_MIGRATE_END); ret = TRUE; } else { - spice_printerr("client %p MIGRATE_CANCEL", mcc->base.client); + spice_printerr("client %p MIGRATE_CANCEL", client); red_channel_client_pipe_add_empty_msg(&mcc->base, SPICE_MSG_MAIN_MIGRATE_CANCEL); } } else { if (success) { - spice_printerr("client %p SWITCH_HOST", mcc->base.client); + spice_printerr("client %p SWITCH_HOST", client); red_channel_client_pipe_add_type(&mcc->base, RED_PIPE_ITEM_TYPE_MAIN_MIGRATE_SWITCH_HOST); } } @@ -607,10 +611,11 @@ gboolean main_channel_client_connect_semi_seamless(MainChannelClient *mcc) void main_channel_client_connect_seamless(MainChannelClient *mcc) { + RedClient *client = red_channel_client_get_client(&mcc->base); spice_assert(red_channel_client_test_remote_cap(&mcc->base, SPICE_MAIN_CAP_SEAMLESS_MIGRATE)); - if (red_client_during_migrate_at_target(mcc->base.client)) { - spice_printerr("client %p: wait till previous migration completes", mcc->base.client); + if (red_client_during_migrate_at_target(client)) { + spice_printerr("client %p: wait till previous migration completes", client); mcc->mig_wait_prev_complete = TRUE; mcc->mig_wait_prev_try_seamless = TRUE; } else { @@ -865,7 +870,7 @@ void main_channel_client_send_item(RedChannelClient *rcc, RedPipeItem *base) base->type != RED_PIPE_ITEM_TYPE_MAIN_INIT) { spice_printerr("Init msg for client %p was not sent yet " "(client is probably during semi-seamless migration). Ignoring msg type %d", - rcc->client, base->type); + red_channel_client_get_client(rcc), base->type); return; } switch (base->type) { diff --git a/server/main-channel.c b/server/main-channel.c index 7c6c1f78..8bb874bc 100644 --- a/server/main-channel.c +++ b/server/main-channel.c @@ -37,7 +37,8 @@ static void main_channel_client_on_disconnect(RedChannelClient *rcc) { RedsState *reds = red_channel_get_server(red_channel_client_get_channel(rcc)); spice_printerr("rcc=%p", rcc); - main_dispatcher_client_disconnect(reds_get_main_dispatcher(reds), rcc->client); + main_dispatcher_client_disconnect(reds_get_main_dispatcher(reds), + red_channel_client_get_client(rcc)); } RedClient *main_channel_get_client_by_link_id(MainChannel *main_chan, uint32_t connection_id) @@ -48,7 +49,7 @@ RedClient *main_channel_get_client_by_link_id(MainChannel *main_chan, uint32_t c FOREACH_CLIENT(main_chan, link, next, rcc) { MainChannelClient *mcc = (MainChannelClient*) rcc; if (main_channel_client_get_connection_id(mcc) == connection_id) { - return rcc->client; + return red_channel_client_get_client(rcc); } } return NULL; @@ -56,7 +57,8 @@ RedClient *main_channel_get_client_by_link_id(MainChannel *main_chan, uint32_t c static void main_channel_push_channels(MainChannelClient *mcc) { - if (red_client_during_migrate_at_target((main_channel_client_get_base(mcc))->client)) { + RedChannelClient *rcc = main_channel_client_get_base(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"); return; diff --git a/server/reds.c b/server/reds.c index 32068ac6..74f7727b 100644 --- a/server/reds.c +++ b/server/reds.c @@ -1042,12 +1042,14 @@ void reds_on_main_agent_start(RedsState *reds, MainChannelClient *mcc, uint32_t { RedCharDevice *dev_state = RED_CHAR_DEVICE(reds->agent_dev); RedChannelClient *rcc; + RedClient *client; if (!reds->vdagent) { return; } spice_assert(reds->vdagent->st && reds->vdagent->st == dev_state); rcc = main_channel_client_get_base(mcc); + client = red_channel_client_get_client(rcc); reds->agent_dev->priv->client_agent_started = TRUE; /* * Note that in older releases, send_tokens were set to ~0 on both client @@ -1056,11 +1058,11 @@ void reds_on_main_agent_start(RedsState *reds, MainChannelClient *mcc, uint32_t * and vice versa, the sending from the server to the client won't have * flow control, but will have no other problem. */ - if (!red_char_device_client_exists(dev_state, rcc->client)) { + if (!red_char_device_client_exists(dev_state, client)) { int client_added; client_added = red_char_device_client_add(dev_state, - rcc->client, + client, TRUE, /* flow control */ REDS_VDI_PORT_NUM_RECEIVE_BUFFS, REDS_AGENT_WINDOW_SIZE, @@ -1074,7 +1076,7 @@ void reds_on_main_agent_start(RedsState *reds, MainChannelClient *mcc, uint32_t } } else { red_char_device_send_to_client_tokens_set(dev_state, - rcc->client, + client, num_tokens); } @@ -1086,12 +1088,13 @@ 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)); if (!reds->vdagent) { return; } spice_assert(reds->vdagent->st); red_char_device_send_to_client_tokens_add(reds->vdagent->st, - main_channel_client_get_base(mcc)->client, + client, num_tokens); } @@ -1112,7 +1115,7 @@ uint8_t *reds_get_agent_data_buffer(RedsState *reds, MainChannelClient *mcc, siz } spice_assert(dev->priv->recv_from_client_buf == NULL); - client = main_channel_client_get_base(mcc)->client; + client = red_channel_client_get_client(main_channel_client_get_base(mcc)); dev->priv->recv_from_client_buf = red_char_device_write_buffer_get(RED_CHAR_DEVICE(dev), client, size + sizeof(VDIChunkHeader)); @@ -1483,9 +1486,9 @@ 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)); /* red_char_device_client_remove disables waiting for migration data */ - red_char_device_client_remove(RED_CHAR_DEVICE(agent_dev), - main_channel_client_get_base(mcc)->client); + red_char_device_client_remove(RED_CHAR_DEVICE(agent_dev), client); main_channel_push_agent_connected(reds->main_channel); } } @@ -1929,10 +1932,11 @@ int reds_on_migrate_dst_set_seamless(RedsState *reds, MainChannelClient *mcc, ui reds->dst_do_seamless_migrate = FALSE; } else { RedChannelClient *rcc = main_channel_client_get_base(mcc); + RedClient *client = red_channel_client_get_client(rcc); - red_client_set_migration_seamless(rcc->client); + red_client_set_migration_seamless(client); /* linking all the channels that have been connected before migration handshake */ - reds->dst_do_seamless_migrate = reds_link_mig_target_channels(reds, rcc->client); + reds->dst_do_seamless_migrate = reds_link_mig_target_channels(reds, client); } return reds->dst_do_seamless_migrate; } diff --git a/server/smartcard.c b/server/smartcard.c index b69ac173..a8a16c77 100644 --- a/server/smartcard.c +++ b/server/smartcard.c @@ -172,7 +172,8 @@ static void smartcard_send_msg_to_client(RedPipeItem *msg, { RedCharDeviceSmartcard *dev = opaque; - spice_assert(dev->priv->scc && dev->priv->scc->base.client == client); + spice_assert(dev->priv->scc && + red_channel_client_get_client(&dev->priv->scc->base) == client); red_pipe_item_ref(msg); smartcard_channel_client_pipe_add_push(&dev->priv->scc->base, msg); } @@ -187,7 +188,8 @@ static void smartcard_remove_client(RedClient *client, void *opaque) RedCharDeviceSmartcard *dev = opaque; spice_printerr("smartcard dev %p, client %p", dev, client); - spice_assert(dev->priv->scc && dev->priv->scc->base.client == client); + spice_assert(dev->priv->scc && + red_channel_client_get_client(&dev->priv->scc->base) == client); red_channel_client_shutdown(&dev->priv->scc->base); } @@ -318,7 +320,7 @@ static void smartcard_char_device_attach_client(SpiceCharDeviceInstance *char_de dev->priv->scc = scc; scc->smartcard = dev; client_added = red_char_device_client_add(RED_CHAR_DEVICE(dev), - scc->base.client, + red_channel_client_get_client(&scc->base), FALSE, /* no flow control yet */ 0, /* send queue size */ ~0, @@ -364,7 +366,8 @@ static void smartcard_char_device_detach_client(SmartCardChannelClient *scc) } dev = scc->smartcard; spice_assert(dev->priv->scc == scc); - red_char_device_client_remove(RED_CHAR_DEVICE(dev), scc->base.client); + red_char_device_client_remove(RED_CHAR_DEVICE(dev), + red_channel_client_get_client(&scc->base)); scc->smartcard = NULL; dev->priv->scc = NULL; } @@ -393,7 +396,9 @@ static uint8_t *smartcard_channel_alloc_msg_rcv_buf(RedChannelClient *rcc, dev = scc->smartcard; spice_assert(dev->priv->scc || scc->smartcard); spice_assert(!scc->write_buf); - scc->write_buf = red_char_device_write_buffer_get(RED_CHAR_DEVICE(dev), rcc->client, size); + scc->write_buf = red_char_device_write_buffer_get(RED_CHAR_DEVICE(dev), + red_channel_client_get_client(rcc), + size); if (!scc->write_buf) { spice_error("failed to allocate write buffer"); diff --git a/server/sound.c b/server/sound.c index 06fab7f4..84cbab4c 100644 --- a/server/sound.c +++ b/server/sound.c @@ -1143,7 +1143,7 @@ void snd_set_playback_latency(RedClient *client, uint32_t latency) for (; now; now = now->next) { if (now->base_channel->type == SPICE_CHANNEL_PLAYBACK && now->connection && - now->connection->channel_client->client == client) { + red_channel_client_get_client(now->connection->channel_client) == client) { if (red_channel_client_test_remote_cap(now->connection->channel_client, SPICE_PLAYBACK_CAP_LATENCY)) { diff --git a/server/spicevmc.c b/server/spicevmc.c index 08b37300..5e310a6c 100644 --- a/server/spicevmc.c +++ b/server/spicevmc.c @@ -211,7 +211,7 @@ static void spicevmc_chardev_send_msg_to_client(RedPipeItem *msg, { SpiceVmcState *state = opaque; - spice_assert(state->rcc->client == client); + spice_assert(red_channel_client_get_client(state->rcc) == client); red_pipe_item_ref(msg); red_channel_client_pipe_add_push(state->rcc, msg); } @@ -255,7 +255,8 @@ static void spicevmc_char_dev_remove_client(RedClient *client, void *opaque) SpiceVmcState *state = opaque; spice_printerr("vmc state %p, client %p", state, client); - spice_assert(state->rcc && state->rcc->client == client); + spice_assert(state->rcc && + red_channel_client_get_client(state->rcc) == client); red_channel_client_shutdown(state->rcc); } @@ -283,6 +284,7 @@ static void spicevmc_red_channel_client_on_disconnect(RedChannelClient *rcc) { SpiceVmcState *state; SpiceCharDeviceInterface *sif; + RedClient *client = red_channel_client_get_client(rcc); if (!rcc) { return; @@ -294,11 +296,11 @@ static void spicevmc_red_channel_client_on_disconnect(RedChannelClient *rcc) red_char_device_write_buffer_release(state->chardev, &state->recv_from_client_buf); if (state->chardev) { - if (red_char_device_client_exists(state->chardev, rcc->client)) { - red_char_device_client_remove(state->chardev, rcc->client); + if (red_char_device_client_exists(state->chardev, client)) { + red_char_device_client_remove(state->chardev, client); } else { spice_printerr("client %p have already been removed from char dev %p", - rcc->client, state->chardev); + client, state->chardev); } } @@ -349,7 +351,8 @@ static int handle_compressed_msg(SpiceVmcState *state, RedChannelClient *rcc, int decompressed_size; RedCharDeviceWriteBuffer *write_buf; - write_buf = red_char_device_write_buffer_get(state->chardev, rcc->client, + write_buf = red_char_device_write_buffer_get(state->chardev, + red_channel_client_get_client(rcc), compressed_data_msg->uncompressed_size); if (!write_buf) { return FALSE; @@ -424,6 +427,7 @@ static uint8_t *spicevmc_red_channel_alloc_msg_rcv_buf(RedChannelClient *rcc, uint32_t size) { SpiceVmcState *state; + RedClient *client = red_channel_client_get_client(rcc); state = spicevmc_red_channel_client_get_state(rcc); @@ -432,7 +436,7 @@ static uint8_t *spicevmc_red_channel_alloc_msg_rcv_buf(RedChannelClient *rcc, assert(!state->recv_from_client_buf); state->recv_from_client_buf = red_char_device_write_buffer_get(state->chardev, - rcc->client, + client, size); if (!state->recv_from_client_buf) { spice_error("failed to allocate write buffer"); diff --git a/server/stream.c b/server/stream.c index d3021683..48197238 100644 --- a/server/stream.c +++ b/server/stream.c @@ -634,7 +634,7 @@ static uint64_t get_initial_bit_rate(DisplayChannelClient *dcc, Stream *stream) MainChannelClient *mcc; uint64_t net_test_bit_rate; - mcc = red_client_get_main(RED_CHANNEL_CLIENT(dcc)->client); + mcc = red_client_get_main(red_channel_client_get_client(RED_CHANNEL_CLIENT(dcc))); net_test_bit_rate = main_channel_client_is_network_info_initialized(mcc) ? main_channel_client_get_bitrate_per_sec(mcc) : 0; @@ -663,10 +663,11 @@ static uint32_t get_roundtrip_ms(void *opaque) { StreamAgent *agent = opaque; int roundtrip; + RedChannelClient *rcc = RED_CHANNEL_CLIENT(agent->dcc); - roundtrip = red_channel_client_get_roundtrip_ms(RED_CHANNEL_CLIENT(agent->dcc)); + roundtrip = red_channel_client_get_roundtrip_ms(rcc); if (roundtrip < 0) { - MainChannelClient *mcc = red_client_get_main(RED_CHANNEL_CLIENT(agent->dcc)->client); + MainChannelClient *mcc = red_client_get_main(red_channel_client_get_client(rcc)); /* * the main channel client roundtrip might not have been @@ -697,10 +698,10 @@ static void update_client_playback_delay(void *opaque, uint32_t delay_ms) dcc_update_streams_max_latency(dcc, agent); agent->client_required_latency = delay_ms; - if (delay_ms > dcc_get_max_stream_latency(agent->dcc)) { - dcc_set_max_stream_latency(agent->dcc, delay_ms); + if (delay_ms > dcc_get_max_stream_latency(dcc)) { + dcc_set_max_stream_latency(dcc, delay_ms); } - spice_debug("resetting client latency: %u", dcc_get_max_stream_latency(agent->dcc)); + spice_debug("resetting client latency: %u", dcc_get_max_stream_latency(dcc)); main_dispatcher_set_mm_time_latency(reds_get_main_dispatcher(reds), client, dcc_get_max_stream_latency(agent->dcc)); |