From: Jonathon Jongsma <jjong...@redhat.com> In preparation for getting rid of the global 'reds' variable, we need to pass the RedsState variable to all functions where it is needed. For now the callers just pass in the global reds variable.
Functions changed: - reds_register_channel; - reds_unregister_channel; - reds_get_mouse_mode; - reds_set_mouse_mode; - reds_update_mouse_mode; - reds_agent_remove; - reds_find_channel; - reds_mig_cleanup; - reds_reset_vdp; - reds_main_channel_connected; - reds_client_disconnect; - reds_disconnect; - reds_mig_disconnect. Acked-by: Frediano Ziglio <fzig...@redhat.com> --- server/inputs-channel.c | 10 ++--- server/main-dispatcher.c | 2 +- server/red-dispatcher.c | 4 +- server/reds.c | 104 +++++++++++++++++++++++------------------------ server/reds.h | 8 ++-- server/smartcard.c | 2 +- server/sound.c | 6 +-- server/spicevmc.c | 4 +- 8 files changed, 70 insertions(+), 70 deletions(-) diff --git a/server/inputs-channel.c b/server/inputs-channel.c index c21cab8..bb5b203 100644 --- a/server/inputs-channel.c +++ b/server/inputs-channel.c @@ -364,7 +364,7 @@ static int inputs_channel_handle_parsed(RedChannelClient *rcc, uint32_t size, ui red_channel_client_pipe_add_type(rcc, PIPE_ITEM_MOUSE_MOTION_ACK); icc->motion_count = 0; } - if (mouse && reds_get_mouse_mode() == SPICE_MOUSE_MODE_SERVER) { + if (mouse && reds_get_mouse_mode(reds) == SPICE_MOUSE_MODE_SERVER) { SpiceMouseInterface *sif; sif = SPICE_CONTAINEROF(mouse->base.sif, SpiceMouseInterface, base); sif->motion(mouse, @@ -381,7 +381,7 @@ static int inputs_channel_handle_parsed(RedChannelClient *rcc, uint32_t size, ui red_channel_client_pipe_add_type(rcc, PIPE_ITEM_MOUSE_MOTION_ACK); icc->motion_count = 0; } - if (reds_get_mouse_mode() != SPICE_MOUSE_MODE_CLIENT) { + if (reds_get_mouse_mode(reds) != SPICE_MOUSE_MODE_CLIENT) { break; } spice_assert((reds_get_agent_mouse() && reds_has_vdagent()) || tablet); @@ -407,7 +407,7 @@ static int inputs_channel_handle_parsed(RedChannelClient *rcc, uint32_t size, ui } else if (mouse_press->button == SPICE_MOUSE_BUTTON_DOWN) { dz = 1; } - if (reds_get_mouse_mode() == SPICE_MOUSE_MODE_CLIENT) { + if (reds_get_mouse_mode(reds) == SPICE_MOUSE_MODE_CLIENT) { if (reds_get_agent_mouse() && reds_has_vdagent()) { inputs_channel->mouse_state.buttons = RED_MOUSE_BUTTON_STATE_TO_AGENT(mouse_press->buttons_state) | @@ -429,7 +429,7 @@ static int inputs_channel_handle_parsed(RedChannelClient *rcc, uint32_t size, ui } case SPICE_MSGC_INPUTS_MOUSE_RELEASE: { SpiceMsgcMouseRelease *mouse_release = message; - if (reds_get_mouse_mode() == SPICE_MOUSE_MODE_CLIENT) { + if (reds_get_mouse_mode(reds) == SPICE_MOUSE_MODE_CLIENT) { if (reds_get_agent_mouse() && reds_has_vdagent()) { inputs_channel->mouse_state.buttons = RED_MOUSE_BUTTON_STATE_TO_AGENT(mouse_release->buttons_state); @@ -672,7 +672,7 @@ void inputs_init(void) red_channel_register_client_cbs(&g_inputs_channel->base, &client_cbs); red_channel_set_cap(&g_inputs_channel->base, SPICE_INPUTS_CAP_KEY_SCANCODE); - reds_register_channel(&g_inputs_channel->base); + reds_register_channel(reds, &g_inputs_channel->base); if (!(key_modifiers_timer = core->timer_add(core, key_modifiers_sender, NULL))) { spice_error("key modifiers timer create failed"); diff --git a/server/main-dispatcher.c b/server/main-dispatcher.c index 2cb53ef..db87e05 100644 --- a/server/main-dispatcher.c +++ b/server/main-dispatcher.c @@ -136,7 +136,7 @@ static void main_dispatcher_handle_client_disconnect(void *opaque, MainDispatcherClientDisconnectMessage *msg = payload; spice_debug("client=%p", msg->client); - reds_client_disconnect(msg->client); + reds_client_disconnect(reds, msg->client); red_client_unref(msg->client); } diff --git a/server/red-dispatcher.c b/server/red-dispatcher.c index 0810798..dc958d9 100644 --- a/server/red-dispatcher.c +++ b/server/red-dispatcher.c @@ -1044,7 +1044,7 @@ void red_dispatcher_init(QXLInstance *qxl) client_cbs.migrate = red_dispatcher_cursor_migrate; red_channel_register_client_cbs(channel, &client_cbs); red_channel_set_data(channel, red_dispatcher); - reds_register_channel(channel); + reds_register_channel(reds, channel); channel = red_worker_get_display_channel(worker); client_cbs.connect = red_dispatcher_set_display_peer; @@ -1055,7 +1055,7 @@ void red_dispatcher_init(QXLInstance *qxl) red_channel_set_cap(channel, SPICE_DISPLAY_CAP_MONITORS_CONFIG); red_channel_set_cap(channel, SPICE_DISPLAY_CAP_PREF_COMPRESSION); red_channel_set_cap(channel, SPICE_DISPLAY_CAP_STREAM_REPORT); - reds_register_channel(channel); + reds_register_channel(reds, channel); red_worker_run(worker); num_active_workers = 1; diff --git a/server/reds.c b/server/reds.c index 1b877aa..9868928 100644 --- a/server/reds.c +++ b/server/reds.c @@ -376,14 +376,14 @@ void reds_update_stat_value(uint32_t value) #endif -void reds_register_channel(RedChannel *channel) +void reds_register_channel(RedsState *reds, RedChannel *channel) { spice_assert(reds); ring_add(&reds->channels, &channel->link); reds->num_of_channels++; } -void reds_unregister_channel(RedChannel *channel) +void reds_unregister_channel(RedsState *reds, RedChannel *channel) { if (ring_item_is_linked(&channel->link)) { ring_remove(&channel->link); @@ -393,7 +393,7 @@ void reds_unregister_channel(RedChannel *channel) } } -static RedChannel *reds_find_channel(uint32_t type, uint32_t id) +static RedChannel *reds_find_channel(RedsState *reds, uint32_t type, uint32_t id) { RingItem *now; @@ -406,7 +406,7 @@ static RedChannel *reds_find_channel(uint32_t type, uint32_t id) return NULL; } -static void reds_mig_cleanup(void) +static void reds_mig_cleanup(RedsState *reds) { if (reds->mig_inprogress) { @@ -430,7 +430,7 @@ static void reds_mig_cleanup(void) } } -static void reds_reset_vdp(void) +static void reds_reset_vdp(RedsState *reds) { VDIPortState *state = &reds->agent_state; SpiceCharDeviceInterface *sif; @@ -481,12 +481,12 @@ static void reds_reset_vdp(void) } } -static int reds_main_channel_connected(void) +static int reds_main_channel_connected(RedsState *reds) { return main_channel_is_connected(reds->main_channel); } -void reds_client_disconnect(RedClient *client) +void reds_client_disconnect(RedsState *reds, RedClient *client) { RedsMigTargetClient *mig_client; @@ -568,38 +568,38 @@ void reds_client_disconnect(RedClient *client) free(reds->agent_state.mig_data); reds->agent_state.mig_data = NULL; - reds_mig_cleanup(); + reds_mig_cleanup(reds); } } // TODO: go over all usage of reds_disconnect, most/some of it should be converted to // reds_client_disconnect -static void reds_disconnect(void) +static void reds_disconnect(RedsState *reds) { RingItem *link, *next; spice_info(NULL); RING_FOREACH_SAFE(link, next, &reds->clients) { - reds_client_disconnect(SPICE_CONTAINEROF(link, RedClient, link)); + reds_client_disconnect(reds, SPICE_CONTAINEROF(link, RedClient, link)); } - reds_mig_cleanup(); + reds_mig_cleanup(reds); } -static void reds_mig_disconnect(void) +static void reds_mig_disconnect(RedsState *reds) { - if (reds_main_channel_connected()) { - reds_disconnect(); + if (reds_main_channel_connected(reds)) { + reds_disconnect(reds); } else { - reds_mig_cleanup(); + reds_mig_cleanup(reds); } } -int reds_get_mouse_mode(void) +int reds_get_mouse_mode(RedsState *reds) { return reds->mouse_mode; } -static void reds_set_mouse_mode(uint32_t mode) +static void reds_set_mouse_mode(RedsState *reds, uint32_t mode) { if (reds->mouse_mode == mode) { return; @@ -614,7 +614,7 @@ int reds_get_agent_mouse(void) return agent_mouse; } -static void reds_update_mouse_mode(void) +static void reds_update_mouse_mode(RedsState *reds) { int allowed = 0; int qxl_count = red_dispatcher_qxl_count(); @@ -627,7 +627,7 @@ static void reds_update_mouse_mode(void) } reds->is_client_mouse_allowed = allowed; if (reds->mouse_mode == SPICE_MOUSE_MODE_CLIENT && !allowed) { - reds_set_mouse_mode(SPICE_MOUSE_MODE_SERVER); + reds_set_mouse_mode(reds, SPICE_MOUSE_MODE_SERVER); return; } if (reds->main_channel) { @@ -636,15 +636,15 @@ static void reds_update_mouse_mode(void) } } -static void reds_agent_remove(void) +static void reds_agent_remove(RedsState *reds) { // TODO: agent is broken with multiple clients. also need to figure out what to do when // part of the clients are during target migration. - reds_reset_vdp(); + reds_reset_vdp(reds); vdagent = NULL; - reds_update_mouse_mode(); - if (reds_main_channel_connected() && + reds_update_mouse_mode(reds); + if (reds_main_channel_connected(reds) && !red_channel_is_waiting_for_migrate_data(&reds->main_channel->base)) { main_channel_push_agent_disconnected(reds->main_channel); } @@ -677,7 +677,7 @@ static int vdi_port_read_buf_process(int port, VDIReadBuf *buf) case AGENT_MSG_FILTER_DISCARD: return FALSE; case AGENT_MSG_FILTER_PROTO_ERROR: - reds_agent_remove(); + reds_agent_remove(reds); return FALSE; } } @@ -685,7 +685,7 @@ static int vdi_port_read_buf_process(int port, VDIReadBuf *buf) return FALSE; default: spice_warning("invalid port"); - reds_agent_remove(); + reds_agent_remove(reds); return FALSE; } } @@ -1107,7 +1107,7 @@ void reds_on_main_migrate_connected(int seamless) { reds->src_do_seamless_migrate = seamless; if (reds->mig_wait_connect) { - reds_mig_cleanup(); + reds_mig_cleanup(reds); } } @@ -1116,13 +1116,13 @@ void reds_on_main_mouse_mode_request(void *message, size_t size) switch (((SpiceMsgcMainMouseModeRequest *)message)->mode) { case SPICE_MOUSE_MODE_CLIENT: if (reds->is_client_mouse_allowed) { - reds_set_mouse_mode(SPICE_MOUSE_MODE_CLIENT); + reds_set_mouse_mode(reds, SPICE_MOUSE_MODE_CLIENT); } else { spice_info("client mouse is disabled"); } break; case SPICE_MOUSE_MODE_SERVER: - reds_set_mouse_mode(SPICE_MOUSE_MODE_SERVER); + reds_set_mouse_mode(reds, SPICE_MOUSE_MODE_SERVER); break; default: spice_warning("unsupported mouse mode"); @@ -1422,7 +1422,7 @@ static int reds_send_link_ack(RedLinkInfo *link) ack.error = GUINT32_TO_LE(SPICE_LINK_ERR_OK); - channel = reds_find_channel(link->link_mess->channel_type, + channel = reds_find_channel(reds, link->link_mess->channel_type, link->link_mess->channel_id); if (!channel) { if (link->link_mess->channel_type != SPICE_CHANNEL_MAIN) { @@ -1613,7 +1613,7 @@ static void reds_mig_target_client_disconnect_all(void) RING_FOREACH_SAFE(now, next, &reds->mig_target_clients) { RedsMigTargetClient *mig_client = SPICE_CONTAINEROF(now, RedsMigTargetClient, link); - reds_client_disconnect(mig_client->client); + reds_client_disconnect(reds, mig_client->client); } } @@ -1661,7 +1661,7 @@ static void reds_handle_main_link(RedLinkInfo *link) link_mess = link->link_mess; if (!reds->allow_multiple_clients) { - reds_disconnect(); + reds_disconnect(reds); } if (link_mess->connection_id == 0) { @@ -1739,7 +1739,7 @@ void reds_set_client_mouse_allowed(int is_client_mouse_allowed, int x_res, int y reds->monitor_mode.x_res = x_res; reds->monitor_mode.y_res = y_res; reds->dispatcher_allows_client_mouse = is_client_mouse_allowed; - reds_update_mouse_mode(); + reds_update_mouse_mode(reds); if (reds->is_client_mouse_allowed && inputs_has_tablet()) { inputs_set_tablet_logical_size(reds->monitor_mode.x_res, reds->monitor_mode.y_res); } @@ -1804,7 +1804,7 @@ static int reds_link_mig_target_channels(RedClient *client) RedChannel *channel; mig_link = SPICE_CONTAINEROF(item, RedsMigPendingLink, ring_link); - channel = reds_find_channel(mig_link->link_msg->channel_type, + channel = reds_find_channel(reds, mig_link->link_msg->channel_type, mig_link->link_msg->channel_id); if (!channel) { spice_warning("client %p channel (%d, %d) (type, id) wasn't found", @@ -1885,7 +1885,7 @@ static void reds_handle_other_links(RedLinkInfo *link) } // TODO: MC: be less lenient. Tally connections from same connection_id (by same client). - if (!(channel = reds_find_channel(link_mess->channel_type, + if (!(channel = reds_find_channel(reds, link_mess->channel_type, link_mess->channel_id))) { reds_send_link_result(link, SPICE_LINK_ERR_CHANNEL_NOT_AVAILABLE); reds_link_free(link); @@ -2539,7 +2539,7 @@ listen: static void reds_send_mm_time(void) { - if (!reds_main_channel_connected()) { + if (!reds_main_channel_connected(reds)) { return; } spice_debug(NULL); @@ -2783,9 +2783,9 @@ static void reds_exit(void) static inline void on_activating_ticketing(void) { - if (!ticketing_enabled && reds_main_channel_connected()) { + if (!ticketing_enabled && reds_main_channel_connected(reds)) { spice_warning("disconnecting"); - reds_disconnect(); + reds_disconnect(reds); } } @@ -2889,7 +2889,7 @@ static void reds_mig_remove_wait_disconnect_client(RedClient *client) ring_remove(wait_client_item); free(wait_client); if (ring_is_empty(&reds->mig_wait_disconnect_clients)) { - reds_mig_cleanup(); + reds_mig_cleanup(reds); } return; } @@ -2921,7 +2921,7 @@ static void reds_mig_finished(int completed) if (completed) { reds_mig_fill_wait_disconnect(); } else { - reds_mig_cleanup(); + reds_mig_cleanup(reds); } reds_mig_release(); } @@ -2945,9 +2945,9 @@ static void migrate_timeout(void *opaque) main_channel_migrate_cancel_wait(reds->main_channel); /* in case part of the client haven't yet completed the previous migration, disconnect them */ reds_mig_target_client_disconnect_all(); - reds_mig_cleanup(); + reds_mig_cleanup(reds); } else { - reds_mig_disconnect(); + reds_mig_disconnect(reds); } } @@ -2993,14 +2993,14 @@ static SpiceCharDeviceState *attach_to_red_agent(SpiceCharDeviceInstance *sin) } vdagent = sin; - reds_update_mouse_mode(); + reds_update_mouse_mode(reds); sif = SPICE_CONTAINEROF(vdagent->base.sif, SpiceCharDeviceInterface, base); if (sif->state) { sif->state(vdagent, 1); } - if (!reds_main_channel_connected()) { + if (!reds_main_channel_connected(reds)) { return state->base; } @@ -3029,7 +3029,7 @@ static SpiceCharDeviceState *attach_to_red_agent(SpiceCharDeviceInstance *sin) if (!client_added) { spice_warning("failed to add client to agent"); - reds_disconnect(); + reds_disconnect(reds); } } @@ -3169,7 +3169,7 @@ static void spice_server_char_device_remove_interface(SpiceBaseInstance *sin) spice_info("remove CHAR_DEVICE %s", char_device->subtype); if (strcmp(char_device->subtype, SUBTYPE_VDAGENT) == 0) { if (vdagent) { - reds_agent_remove(); + reds_agent_remove(reds); } } #ifdef USE_SMARTCARD @@ -3239,7 +3239,7 @@ SPICE_GNUC_VISIBLE int spice_server_add_interface(SpiceServer *s, if (inputs_set_tablet(SPICE_CONTAINEROF(sin, SpiceTabletInstance, base)) != 0) { return -1; } - reds_update_mouse_mode(); + reds_update_mouse_mode(reds); if (reds->is_client_mouse_allowed) { inputs_set_tablet_logical_size(reds->monitor_mode.x_res, reds->monitor_mode.y_res); } @@ -3296,7 +3296,7 @@ SPICE_GNUC_VISIBLE int spice_server_remove_interface(SpiceBaseInstance *sin) if (strcmp(interface->type, SPICE_INTERFACE_TABLET) == 0) { spice_info("remove SPICE_INTERFACE_TABLET"); inputs_detach_tablet(SPICE_CONTAINEROF(sin, SpiceTabletInstance, base)); - reds_update_mouse_mode(); + reds_update_mouse_mode(reds); } else if (strcmp(interface->type, SPICE_INTERFACE_PLAYBACK) == 0) { spice_info("remove SPICE_INTERFACE_PLAYBACK"); snd_detach_playback(SPICE_CONTAINEROF(sin, SpicePlaybackInstance, base)); @@ -3601,12 +3601,12 @@ SPICE_GNUC_VISIBLE int spice_server_set_ticket(SpiceServer *s, { spice_assert(reds == s); - if (reds_main_channel_connected()) { + if (reds_main_channel_connected(reds)) { if (fail_if_connected) { return -1; } if (disconnect_if_connected) { - reds_disconnect(); + reds_disconnect(reds); } } @@ -3808,7 +3808,7 @@ SPICE_GNUC_VISIBLE int spice_server_set_agent_mouse(SpiceServer *s, int enable) { spice_assert(reds == s); agent_mouse = enable; - reds_update_mouse_mode(); + reds_update_mouse_mode(reds); return 0; } @@ -3944,13 +3944,13 @@ SPICE_GNUC_VISIBLE int spice_server_migrate_end(SpiceServer *s, int completed) sif = SPICE_CONTAINEROF(migration_interface->base.sif, SpiceMigrateInterface, base); if (completed && !reds->expect_migrate && reds->num_clients) { spice_warning("spice_server_migrate_info was not called, disconnecting clients"); - reds_disconnect(); + reds_disconnect(reds); ret = -1; goto complete; } reds->expect_migrate = FALSE; - if (!reds_main_channel_connected()) { + if (!reds_main_channel_connected(reds)) { spice_info("no peer connected"); goto complete; } diff --git a/server/reds.h b/server/reds.h index 8e6e136..e38a99a 100644 --- a/server/reds.h +++ b/server/reds.h @@ -55,9 +55,9 @@ void reds_enable_mm_time(void); uint32_t reds_get_mm_time(void); void reds_set_client_mouse_allowed(int is_client_mouse_allowed, int x_res, int y_res); -void reds_register_channel(RedChannel *channel); -void reds_unregister_channel(RedChannel *channel); -int reds_get_mouse_mode(void); // used by inputs_channel +void reds_register_channel(RedsState *reds, RedChannel *channel); +void reds_unregister_channel(RedsState *reds, RedChannel *channel); +int reds_get_mouse_mode(RedsState *reds); // used by inputs_channel int reds_get_agent_mouse(void); // used by inputs_channel int reds_has_vdagent(void); // used by inputs channel void reds_handle_agent_mouse_event(const VDAgentMouseState *mouse_state); // used by inputs_channel @@ -81,7 +81,7 @@ extern spice_wan_compression_t zlib_glz_state; // Temporary measures to make splitting reds.c to inputs-channel.c easier /* should be called only from main_dispatcher */ -void reds_client_disconnect(RedClient *client); +void reds_client_disconnect(RedsState *reds, RedClient *client); // Temporary (?) for splitting main channel typedef struct MainMigrateData MainMigrateData; diff --git a/server/smartcard.c b/server/smartcard.c index 15ebcc9..9b8f7c6 100644 --- a/server/smartcard.c +++ b/server/smartcard.c @@ -861,5 +861,5 @@ static void smartcard_init(void) client_cbs.connect = smartcard_connect_client; red_channel_register_client_cbs(&g_smartcard_channel->base, &client_cbs); - reds_register_channel(&g_smartcard_channel->base); + reds_register_channel(reds, &g_smartcard_channel->base); } diff --git a/server/sound.c b/server/sound.c index adb27ca..17968e0 100644 --- a/server/sound.c +++ b/server/sound.c @@ -1533,7 +1533,7 @@ void snd_attach_playback(SpicePlaybackInstance *sin) playback_worker->base_channel = channel; add_worker(playback_worker); - reds_register_channel(channel); + reds_register_channel(reds, channel); } void snd_attach_record(SpiceRecordInstance *sin) @@ -1561,7 +1561,7 @@ void snd_attach_record(SpiceRecordInstance *sin) record_worker->base_channel = channel; add_worker(record_worker); - reds_register_channel(channel); + reds_register_channel(reds, channel); } static void snd_detach_common(SndWorker *worker) @@ -1571,7 +1571,7 @@ static void snd_detach_common(SndWorker *worker) } remove_worker(worker); snd_disconnect_channel(worker->connection); - reds_unregister_channel(worker->base_channel); + reds_unregister_channel(reds, worker->base_channel); red_channel_destroy(worker->base_channel); } diff --git a/server/spicevmc.c b/server/spicevmc.c index 115c3b1..28a65d7 100644 --- a/server/spicevmc.c +++ b/server/spicevmc.c @@ -548,7 +548,7 @@ SpiceCharDeviceState *spicevmc_device_connect(SpiceCharDeviceInstance *sin, state); state->chardev_sin = sin; - reds_register_channel(&state->channel); + reds_register_channel(reds, &state->channel); return state->chardev_st; } @@ -566,7 +566,7 @@ void spicevmc_device_disconnect(SpiceCharDeviceInstance *sin) state->chardev_st = NULL; sin->st = NULL; - reds_unregister_channel(&state->channel); + reds_unregister_channel(reds, &state->channel); free(state->pipe_item); red_channel_destroy(&state->channel); } -- 2.4.3 _______________________________________________ Spice-devel mailing list Spice-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/spice-devel