diff --git a/server/cursor-channel-client.cpp b/server/cursor-channel-client.cpp index 5152f9b7..493563d0 100644 --- a/server/cursor-channel-client.cpp +++ b/server/cursor-channel-client.cpp @@ -60,12 +60,10 @@ void CursorChannelClient::on_disconnect() cursor_channel_client_reset_cursor_cache(this); } -void cursor_channel_client_migrate(RedChannelClient *rcc) +void CursorChannelClient::migrate() { - spice_return_if_fail(rcc); - - rcc->pipe_add_type(RED_PIPE_ITEM_TYPE_INVAL_CURSOR_CACHE); - RedChannelClient::default_migrate(rcc); + pipe_add_type(RED_PIPE_ITEM_TYPE_INVAL_CURSOR_CACHE); + RedChannelClient::migrate(); } CursorChannelClient::CursorChannelClient(RedChannel *channel, diff --git a/server/cursor-channel-client.h b/server/cursor-channel-client.h index 48cdac72..805012ff 100644 --- a/server/cursor-channel-client.h +++ b/server/cursor-channel-client.h @@ -40,6 +40,11 @@ public: protected: virtual void on_disconnect() override; void send_item(RedPipeItem *pipe_item) override; + /** + * Migrate a client channel from a CursorChannel. + * This is the equivalent of RedChannel client migrate callback. + */ + virtual void migrate() override; public: red::unique_link priv; @@ -61,12 +66,6 @@ enum { RED_PIPE_ITEM_TYPE_INVAL_CURSOR_CACHE, }; -/** - * Migrate a client channel from a CursorChannel. - * This is the equivalent of RedChannel client migrate callback. - */ -void cursor_channel_client_migrate(RedChannelClient *client); - G_END_DECLS #endif /* CURSOR_CHANNEL_CLIENT_H_ */ diff --git a/server/cursor-channel.cpp b/server/cursor-channel.cpp index 94d82ce9..d55d3923 100644 --- a/server/cursor-channel.cpp +++ b/server/cursor-channel.cpp @@ -386,7 +386,6 @@ cursor_channel_class_init(CursorChannelClass *klass) // client callbacks channel_class->connect = (channel_client_connect_proc) cursor_channel_connect; - channel_class->migrate = cursor_channel_client_migrate; } static void diff --git a/server/dcc.h b/server/dcc.h index 0f46456d..e1f26802 100644 --- a/server/dcc.h +++ b/server/dcc.h @@ -50,6 +50,7 @@ protected: virtual void on_disconnect() override; virtual void send_item(RedPipeItem *item) override; virtual bool handle_migrate_data(uint32_t size, void *message) override; + virtual void migrate() override; public: red::unique_link priv; diff --git a/server/display-channel.cpp b/server/display-channel.cpp index 6d5c6b91..bfb08407 100644 --- a/server/display-channel.cpp +++ b/server/display-channel.cpp @@ -27,7 +27,6 @@ static void display_channel_connect(RedChannel *channel, RedClient *client, RedStream *stream, int migration, RedChannelCapabilities *caps); static void display_channel_disconnect(RedChannelClient *rcc); -static void display_channel_migrate(RedChannelClient *rcc); enum { PROP0, @@ -2508,7 +2507,6 @@ display_channel_class_init(DisplayChannelClass *klass) // client callbacks channel_class->connect = display_channel_connect; channel_class->disconnect = display_channel_disconnect; - channel_class->migrate = display_channel_migrate; g_object_class_install_property(object_class, PROP_N_SURFACES, @@ -2629,9 +2627,9 @@ static void display_channel_disconnect(RedChannelClient *rcc) rcc->disconnect(); } -static void display_channel_migrate(RedChannelClient *rcc) +void DisplayChannelClient::migrate() { - DisplayChannel *display = DISPLAY_CHANNEL(rcc->get_channel()); + DisplayChannel *display = DISPLAY_CHANNEL(get_channel()); /* We need to stop the streams, and to send upgrade_items to the client. * Otherwise, (1) the client might display lossy regions that we don't track @@ -2644,8 +2642,8 @@ static void display_channel_migrate(RedChannelClient *rcc) * handle_dev_stop already took care of releasing all the dev ram resources. */ video_stream_detach_and_stop(display); - if (rcc->is_connected()) { - RedChannelClient::default_migrate(rcc); + if (is_connected()) { + RedChannelClient::migrate(); } } diff --git a/server/inputs-channel-client.h b/server/inputs-channel-client.h index d1987da8..600d6d98 100644 --- a/server/inputs-channel-client.h +++ b/server/inputs-channel-client.h @@ -56,6 +56,7 @@ protected: virtual void on_disconnect() override; virtual void send_item(RedPipeItem *base) override; virtual bool handle_migrate_data(uint32_t size, void *message) override; + virtual void migrate() override; }; RedChannelClient* inputs_channel_client_create(RedChannel *channel, diff --git a/server/inputs-channel.cpp b/server/inputs-channel.cpp index 84fc46c7..9c69dc40 100644 --- a/server/inputs-channel.cpp +++ b/server/inputs-channel.cpp @@ -488,11 +488,11 @@ static void inputs_connect(RedChannel *channel, RedClient *client, inputs_pipe_add_init(rcc); } -static void inputs_migrate(RedChannelClient *rcc) +void InputsChannelClient::migrate() { - InputsChannel *inputs = INPUTS_CHANNEL(rcc->get_channel()); + InputsChannel *inputs = INPUTS_CHANNEL(get_channel()); inputs->src_during_migrate = TRUE; - RedChannelClient::default_migrate(rcc); + RedChannelClient::migrate(); } static void inputs_channel_push_keyboard_modifiers(InputsChannel *inputs, uint8_t modifiers) @@ -615,7 +615,6 @@ inputs_channel_class_init(InputsChannelClass *klass) // client callbacks channel_class->connect = inputs_connect; - channel_class->migrate = inputs_migrate; } static SpiceKbdInstance* inputs_channel_get_keyboard(InputsChannel *inputs) diff --git a/server/main-channel-client.cpp b/server/main-channel-client.cpp index 5e7c88bb..aa9f17f0 100644 --- a/server/main-channel-client.cpp +++ b/server/main-channel-client.cpp @@ -570,14 +570,11 @@ uint64_t main_channel_client_get_roundtrip_ms(MainChannelClient *mcc) return mcc->priv->latency / 1000; } -XXX_CAST(RedChannelClient, MainChannelClient, MAIN_CHANNEL_CLIENT); - -void main_channel_client_migrate(RedChannelClient *rcc) +void MainChannelClient::migrate() { - RedChannel *channel = rcc->get_channel(); - reds_on_main_channel_migrate(channel->get_server(), - MAIN_CHANNEL_CLIENT(rcc)); - RedChannelClient::default_migrate(rcc); + RedChannel *channel = get_channel(); + reds_on_main_channel_migrate(channel->get_server(), this); + RedChannelClient::migrate(); } gboolean main_channel_client_connect_semi_seamless(MainChannelClient *mcc) diff --git a/server/main-channel-client.h b/server/main-channel-client.h index 93d803f1..7f9a11ad 100644 --- a/server/main-channel-client.h +++ b/server/main-channel-client.h @@ -44,6 +44,7 @@ protected: virtual bool handle_message(uint16_t type, uint32_t size, void *message) override; virtual void send_item(RedPipeItem *item) override; virtual bool handle_migrate_data(uint32_t size, void *message) override; + virtual void migrate() override; public: red::unique_link priv; @@ -66,7 +67,6 @@ void main_channel_client_push_init(MainChannelClient *mcc, int multi_media_time, int ram_hint); void main_channel_client_push_notify(MainChannelClient *mcc, const char *msg); -void main_channel_client_migrate(RedChannelClient *rcc); gboolean main_channel_client_connect_semi_seamless(MainChannelClient *mcc); void main_channel_client_connect_seamless(MainChannelClient *mcc); void main_channel_client_handle_migrate_connected(MainChannelClient *mcc, diff --git a/server/main-channel.cpp b/server/main-channel.cpp index d69c26f0..5be27a7c 100644 --- a/server/main-channel.cpp +++ b/server/main-channel.cpp @@ -277,9 +277,6 @@ main_channel_class_init(MainChannelClass *klass) /* channel callbacks */ channel_class->handle_migrate_flush_mark = main_channel_handle_migrate_flush_mark; - - // client callbacks - channel_class->migrate = main_channel_client_migrate; } static int main_channel_connect_semi_seamless(MainChannel *main_channel) diff --git a/server/red-channel-client.cpp b/server/red-channel-client.cpp index 3f227b5f..dbb0e84a 100644 --- a/server/red-channel-client.cpp +++ b/server/red-channel-client.cpp @@ -912,16 +912,16 @@ bool RedChannelClient::is_waiting_for_migrate_data() const return priv->wait_migrate_data; } -void RedChannelClient::default_migrate(RedChannelClient *rcc) +void RedChannelClient::migrate() { - rcc->priv->cancel_ping_timer(); - red_timer_remove(rcc->priv->latency_monitor.timer); - rcc->priv->latency_monitor.timer = NULL; + priv->cancel_ping_timer(); + red_timer_remove(priv->latency_monitor.timer); + priv->latency_monitor.timer = NULL; - red_timer_remove(rcc->priv->connectivity_monitor.timer); - rcc->priv->connectivity_monitor.timer = NULL; + red_timer_remove(priv->connectivity_monitor.timer); + priv->connectivity_monitor.timer = NULL; - rcc->pipe_add_type(RED_PIPE_ITEM_TYPE_MIGRATE); + pipe_add_type(RED_PIPE_ITEM_TYPE_MIGRATE); } void RedChannelClient::shutdown() diff --git a/server/red-channel-client.h b/server/red-channel-client.h index f58bf4dc..3e1c9fa7 100644 --- a/server/red-channel-client.h +++ b/server/red-channel-client.h @@ -48,7 +48,6 @@ public: virtual bool init(); bool is_connected() const; - static void default_migrate(RedChannelClient *rcc); bool is_waiting_for_migrate_data() const; bool test_remote_common_cap(uint32_t cap) const; bool test_remote_cap(uint32_t cap) const; @@ -152,6 +151,9 @@ public: void ref() { g_atomic_int_inc(&_ref); } void unref() { if (g_atomic_int_dec_and_test(&_ref)) delete this; } + // callback from client + virtual void migrate(); + /* configure socket connected to the client */ virtual bool config_socket() { return true; } virtual uint8_t *alloc_recv_buf(uint16_t type, uint32_t size)=0; diff --git a/server/red-channel.cpp b/server/red-channel.cpp index 8cb389ad..7d9c8537 100644 --- a/server/red-channel.cpp +++ b/server/red-channel.cpp @@ -301,7 +301,6 @@ red_channel_class_init(RedChannelClass *klass) klass->connect = red_channel_client_default_connect; klass->disconnect = red_channel_client_default_disconnect; - klass->migrate = RedChannelClient::default_migrate; } static void @@ -708,10 +707,8 @@ typedef struct RedMessageMigrate { static void handle_dispatcher_migrate(void *opaque, void *payload) { RedMessageMigrate *msg = (RedMessageMigrate*) payload; - RedChannel *channel = msg->rcc->get_channel(); - RedChannelClass *klass = RED_CHANNEL_GET_CLASS(channel); - klass->migrate(msg->rcc); + msg->rcc->migrate(); msg->rcc->unref(); } @@ -719,8 +716,7 @@ void RedChannel::migrate_client(RedChannelClient *rcc) { if (priv->dispatcher == NULL || pthread_equal(pthread_self(), priv->thread_id)) { - RedChannelClass *klass = RED_CHANNEL_GET_CLASS(this); - klass->migrate(rcc); + rcc->migrate(); return; } diff --git a/server/red-channel.h b/server/red-channel.h index 06c4c8af..24c807a0 100644 --- a/server/red-channel.h +++ b/server/red-channel.h @@ -52,7 +52,6 @@ typedef uint64_t (*channel_handle_migrate_data_get_serial_proc)(RedChannelClient typedef void (*channel_client_connect_proc)(RedChannel *channel, RedClient *client, RedStream *stream, int migration, RedChannelCapabilities *caps); typedef void (*channel_client_disconnect_proc)(RedChannelClient *base); -typedef void (*channel_client_migrate_proc)(RedChannelClient *base); static inline gboolean test_capability(const uint32_t *caps, int num_caps, uint32_t cap) @@ -82,7 +81,6 @@ struct RedChannelClass */ channel_client_connect_proc connect; channel_client_disconnect_proc disconnect; - channel_client_migrate_proc migrate; }; #define FOREACH_CLIENT(_channel, _data) \ diff --git a/server/sound.cpp b/server/sound.cpp index 5b0e1590..b70998be 100644 --- a/server/sound.cpp +++ b/server/sound.cpp @@ -105,6 +105,7 @@ public: virtual bool config_socket() override; virtual uint8_t *alloc_recv_buf(uint16_t type, uint32_t size) override; virtual void release_recv_buf(uint16_t type, uint32_t size, uint8_t *msg) override; + virtual void migrate() override; }; static void snd_playback_alloc_frames(PlaybackChannelClient *playback); @@ -1101,12 +1102,10 @@ static void snd_set_playback_peer(RedChannel *red_channel, RedClient *client, Re } } -XXX_CAST(RedChannelClient, SndChannelClient, SND_CHANNEL_CLIENT) - -static void snd_migrate_channel_client(RedChannelClient *rcc) +void SndChannelClient::migrate() { - snd_set_command(SND_CHANNEL_CLIENT(rcc), SND_MIGRATE_MASK); - snd_send(SND_CHANNEL_CLIENT(rcc)); + snd_set_command(this, SND_MIGRATE_MASK); + snd_send(this); } SPICE_GNUC_VISIBLE void spice_server_record_set_volume(SpiceRecordInstance *sin, @@ -1320,7 +1319,6 @@ playback_channel_class_init(PlaybackChannelClass *klass) // client callbacks channel_class->connect = snd_set_playback_peer; - channel_class->migrate = snd_migrate_channel_client; } void snd_attach_playback(RedsState *reds, SpicePlaybackInstance *sin) @@ -1364,7 +1362,6 @@ record_channel_class_init(RecordChannelClass *klass) // client callbacks channel_class->connect = snd_set_record_peer; - channel_class->migrate = snd_migrate_channel_client; } void snd_attach_record(RedsState *reds, SpiceRecordInstance *sin)