From: Jonathon Jongsma <jjongsma@xxxxxxxxxx> Also add reds_get_core_interface() accessor for external use. --- server/char-device.c | 32 ++++++++++++++++--------------- server/inputs-channel.c | 7 ++++--- server/main-channel.c | 13 +++++++------ server/reds-private.h | 2 ++ server/reds-stream.c | 12 ++++++------ server/reds.c | 51 ++++++++++++++++++++++++++----------------------- server/reds.h | 3 +-- server/smartcard.c | 3 ++- server/sound.c | 13 +++++++------ server/spicevmc.c | 2 +- 10 files changed, 74 insertions(+), 64 deletions(-) diff --git a/server/char-device.c b/server/char-device.c index aa2eafd..6093599 100644 --- a/server/char-device.c +++ b/server/char-device.c @@ -156,7 +156,7 @@ static void spice_char_device_client_free(SpiceCharDeviceState *dev, RingItem *item, *next; if (dev_client->wait_for_tokens_timer) { - core->timer_remove(dev_client->wait_for_tokens_timer); + reds_get_core_interface(reds)->timer_remove(dev_client->wait_for_tokens_timer); } spice_char_device_client_send_queue_free(dev, dev_client); @@ -262,8 +262,8 @@ static void spice_char_device_add_msg_to_client_queue(SpiceCharDeviceClientState ring_add(&dev_client->send_queue, &msg_item->link); dev_client->send_queue_size++; if (!dev_client->wait_for_tokens_started) { - core->timer_start(dev_client->wait_for_tokens_timer, - SPICE_CHAR_DEVICE_WAIT_TOKENS_TIMEOUT); + reds_get_core_interface(reds)->timer_start(dev_client->wait_for_tokens_timer, + SPICE_CHAR_DEVICE_WAIT_TOKENS_TIMEOUT); dev_client->wait_for_tokens_started = TRUE; } } @@ -370,12 +370,12 @@ static void spice_char_device_send_to_client_tokens_absorb(SpiceCharDeviceClient } if (spice_char_device_can_send_to_client(dev_client)) { - core->timer_cancel(dev_client->wait_for_tokens_timer); + reds_get_core_interface(reds)->timer_cancel(dev_client->wait_for_tokens_timer); dev_client->wait_for_tokens_started = FALSE; spice_char_device_read_from_device(dev_client->dev); } else if (dev_client->send_queue_size) { - core->timer_start(dev_client->wait_for_tokens_timer, - SPICE_CHAR_DEVICE_WAIT_TOKENS_TIMEOUT); + reds_get_core_interface(reds)->timer_start(dev_client->wait_for_tokens_timer, + SPICE_CHAR_DEVICE_WAIT_TOKENS_TIMEOUT); dev_client->wait_for_tokens_started = TRUE; } } @@ -456,7 +456,7 @@ static int spice_char_device_write_to_device(SpiceCharDeviceState *dev) spice_char_device_state_ref(dev); if (dev->write_to_dev_timer) { - core->timer_cancel(dev->write_to_dev_timer); + reds_get_core_interface(reds)->timer_cancel(dev->write_to_dev_timer); } sif = SPICE_CONTAINEROF(dev->sin->base.sif, SpiceCharDeviceInterface, base); @@ -498,8 +498,8 @@ static int spice_char_device_write_to_device(SpiceCharDeviceState *dev) if (dev->running) { if (dev->cur_write_buf) { if (dev->write_to_dev_timer) { - core->timer_start(dev->write_to_dev_timer, - CHAR_DEVICE_WRITE_TO_TIMEOUT); + reds_get_core_interface(reds)->timer_start(dev->write_to_dev_timer, + CHAR_DEVICE_WRITE_TO_TIMEOUT); } } else { spice_assert(ring_is_empty(&dev->write_queue)); @@ -516,7 +516,7 @@ static void spice_char_dev_write_retry(void *opaque) SpiceCharDeviceState *dev = opaque; if (dev->write_to_dev_timer) { - core->timer_cancel(dev->write_to_dev_timer); + reds_get_core_interface(reds)->timer_cancel(dev->write_to_dev_timer); } spice_char_device_write_to_device(dev); } @@ -695,7 +695,8 @@ SpiceCharDeviceState *spice_char_device_state_create(SpiceCharDeviceInstance *si sif = SPICE_CONTAINEROF(char_dev->sin->base.sif, SpiceCharDeviceInterface, base); if (sif->base.minor_version <= 2 || !(sif->flags & SPICE_CHAR_DEVICE_NOTIFY_WRITABLE)) { - char_dev->write_to_dev_timer = core->timer_add(core, spice_char_dev_write_retry, char_dev); + char_dev->write_to_dev_timer = reds_get_core_interface(reds)->timer_add(reds_get_core_interface(reds), + spice_char_dev_write_retry, char_dev); if (!char_dev->write_to_dev_timer) { spice_error("failed creating char dev write timer"); } @@ -743,7 +744,7 @@ void spice_char_device_state_destroy(SpiceCharDeviceState *char_dev) { reds_on_char_device_state_destroy(reds, char_dev); if (char_dev->write_to_dev_timer) { - core->timer_remove(char_dev->write_to_dev_timer); + reds_get_core_interface(reds)->timer_remove(char_dev->write_to_dev_timer); char_dev->write_to_dev_timer = NULL; } write_buffers_queue_free(&char_dev->write_queue); @@ -794,8 +795,9 @@ int spice_char_device_client_add(SpiceCharDeviceState *dev, dev_client->max_send_queue_size = max_send_queue_size; dev_client->do_flow_control = do_flow_control; if (do_flow_control) { - dev_client->wait_for_tokens_timer = core->timer_add(core, device_client_wait_for_tokens_timeout, - dev_client); + dev_client->wait_for_tokens_timer = reds_get_core_interface(reds)->timer_add(reds_get_core_interface(reds), + device_client_wait_for_tokens_timeout, + dev_client); if (!dev_client->wait_for_tokens_timer) { spice_error("failed to create wait for tokens timer"); } @@ -860,7 +862,7 @@ void spice_char_device_stop(SpiceCharDeviceState *dev) dev->running = FALSE; dev->active = FALSE; if (dev->write_to_dev_timer) { - core->timer_cancel(dev->write_to_dev_timer); + reds_get_core_interface(reds)->timer_cancel(dev->write_to_dev_timer); } } diff --git a/server/inputs-channel.c b/server/inputs-channel.c index 319d26c..5e884f4 100644 --- a/server/inputs-channel.c +++ b/server/inputs-channel.c @@ -186,7 +186,7 @@ static void inputs_channel_release_msg_rcv_buf(RedChannelClient *rcc, static void activate_modifiers_watch(void) { - core->timer_start(key_modifiers_timer, KEY_MODIFIERS_TTL); + reds_get_core_interface(reds)->timer_start(key_modifiers_timer, KEY_MODIFIERS_TTL); } static void kbd_push_scan(SpiceKbdInstance *sin, uint8_t scan) @@ -628,7 +628,7 @@ InputsChannel* inputs_channel_new(void) inputs = (InputsChannel *)red_channel_create_parser( sizeof(InputsChannel), - core, + reds_get_core_interface(reds), SPICE_CHANNEL_INPUTS, 0, FALSE, /* handle_acks */ spice_get_client_channel_parser(SPICE_CHANNEL_INPUTS, NULL), @@ -647,7 +647,8 @@ InputsChannel* inputs_channel_new(void) red_channel_set_cap(&inputs->base, SPICE_INPUTS_CAP_KEY_SCANCODE); reds_register_channel(reds, &inputs->base); - if (!(key_modifiers_timer = core->timer_add(core, key_modifiers_sender, inputs))) { + if (!(key_modifiers_timer = reds_get_core_interface(reds)->timer_add(reds_get_core_interface(reds), + key_modifiers_sender, inputs))) { spice_error("key modifiers timer create failed"); } return inputs; diff --git a/server/main-channel.c b/server/main-channel.c index aa2b03c..c2a7b8b 100644 --- a/server/main-channel.c +++ b/server/main-channel.c @@ -1052,9 +1052,9 @@ static void do_ping_client(MainChannelClient *mcc, if (has_interval && interval > 0) { mcc->ping_interval = interval * MSEC_PER_SEC; } - core->timer_start(mcc->ping_timer, mcc->ping_interval); + reds_get_core_interface(reds)->timer_start(mcc->ping_timer, mcc->ping_interval); } else if (!strcmp(opt, "off")) { - core->timer_cancel(mcc->ping_timer); + reds_get_core_interface(reds)->timer_cancel(mcc->ping_timer); } else { return; } @@ -1066,11 +1066,11 @@ static void ping_timer_cb(void *opaque) if (!red_channel_client_is_connected(&mcc->base)) { spice_printerr("not connected to peer, ping off"); - core->timer_cancel(mcc->ping_timer); + reds_get_core_interface(reds)->timer_cancel(mcc->ping_timer); return; } do_ping_client(mcc, NULL, 0, 0); - core->timer_start(mcc->ping_timer, mcc->ping_interval); + reds_get_core_interface(reds)->timer_start(mcc->ping_timer, mcc->ping_interval); } #endif /* RED_STATISTICS */ @@ -1087,7 +1087,8 @@ static MainChannelClient *main_channel_client_create(MainChannel *main_chan, Red mcc->connection_id = connection_id; mcc->bitrate_per_sec = ~0; #ifdef RED_STATISTICS - if (!(mcc->ping_timer = core->timer_add(core, ping_timer_cb, NULL))) { + if (!(mcc->ping_timer = reds_get_core_interface(reds)->timer_add(reds_get_core_interface(reds), + ping_timer_cb, NULL))) { spice_error("ping timer create failed"); } mcc->ping_interval = PING_INTERVAL; @@ -1178,7 +1179,7 @@ MainChannel* main_channel_new(void) channel_cbs.handle_migrate_data = main_channel_handle_migrate_data; // TODO: set the migration flag of the channel - channel = red_channel_create_parser(sizeof(MainChannel), core, + channel = red_channel_create_parser(sizeof(MainChannel), reds_get_core_interface(reds), SPICE_CHANNEL_MAIN, 0, FALSE, /* handle_acks */ spice_get_client_channel_parser(SPICE_CHANNEL_MAIN, NULL), diff --git a/server/reds-private.h b/server/reds-private.h index 2a6f438..f9dde8a 100644 --- a/server/reds-private.h +++ b/server/reds-private.h @@ -236,6 +236,8 @@ struct RedsState { gboolean exit_on_disconnect; RedSSLParameters ssl_parameters; + SpiceCoreInterfaceInternal *core; + }; #endif diff --git a/server/reds-stream.c b/server/reds-stream.c index 2b1c5b9..2eb8f89 100644 --- a/server/reds-stream.c +++ b/server/reds-stream.c @@ -22,6 +22,7 @@ #include "main-dispatcher.h" #include "red-common.h" #include "reds-stream.h" +#include "reds.h" #include "common/log.h" #include <errno.h> @@ -44,8 +45,6 @@ struct AsyncRead { }; typedef struct AsyncRead AsyncRead; -extern SpiceCoreInterfaceInternal *core; - #if HAVE_SASL #include <sasl/sasl.h> @@ -168,7 +167,7 @@ static ssize_t stream_ssl_read_cb(RedsStream *s, void *buf, size_t size) void reds_stream_remove_watch(RedsStream* s) { if (s->watch) { - core->watch_remove(s->watch); + reds_get_core_interface(reds)->watch_remove(s->watch); s->watch = NULL; } } @@ -497,9 +496,10 @@ static void async_read_handler(G_GNUC_UNUSED int fd, switch (errno) { case EAGAIN: if (!async->stream->watch) { - async->stream->watch = core->watch_add(core, async->stream->socket, - SPICE_WATCH_EVENT_READ, - async_read_handler, async); + async->stream->watch = reds_get_core_interface(reds)->watch_add(reds_get_core_interface(reds), + async->stream->socket, + SPICE_WATCH_EVENT_READ, + async_read_handler, async); } return; case EINTR: diff --git a/server/reds.c b/server/reds.c index 8be151c..690985c 100644 --- a/server/reds.c +++ b/server/reds.c @@ -72,8 +72,6 @@ #include "reds-private.h" -SpiceCoreInterfaceInternal *core = NULL; - static SpiceCoreInterface *core_public = NULL; static SpiceTimer *adapter_timer_add(const SpiceCoreInterfaceInternal *iface, SpiceTimerFunc func, void *opaque) @@ -189,7 +187,7 @@ static ChannelSecurityOptions *reds_find_channel_security(RedsState *reds, int i void reds_handle_channel_event(int event, SpiceChannelEventInfo *info) { - core->channel_event(event, info); + reds->core->channel_event(event, info); if (event == SPICE_CHANNEL_EVENT_DISCONNECTED) { free(info); @@ -381,7 +379,7 @@ static void reds_mig_cleanup(RedsState *reds) reds->mig_inprogress = FALSE; reds->mig_wait_connect = FALSE; reds->mig_wait_disconnect = FALSE; - core->timer_cancel(reds->mig_timer); + reds->core->timer_cancel(reds->mig_timer); reds_mig_cleanup_wait_disconnect(reds); } } @@ -2256,10 +2254,10 @@ static void reds_handle_ssl_accept(int fd, int event, void *data) reds_link_free(link); return; case REDS_STREAM_SSL_STATUS_WAIT_FOR_READ: - core->watch_update_mask(link->stream->watch, SPICE_WATCH_EVENT_READ); + reds->core->watch_update_mask(link->stream->watch, SPICE_WATCH_EVENT_READ); return; case REDS_STREAM_SSL_STATUS_WAIT_FOR_WRITE: - core->watch_update_mask(link->stream->watch, SPICE_WATCH_EVENT_WRITE); + reds->core->watch_update_mask(link->stream->watch, SPICE_WATCH_EVENT_WRITE); return; case REDS_STREAM_SSL_STATUS_OK: reds_stream_remove_watch(link->stream); @@ -2337,12 +2335,12 @@ static RedLinkInfo *reds_init_client_ssl_connection(int socket) case REDS_STREAM_SSL_STATUS_ERROR: goto error; case REDS_STREAM_SSL_STATUS_WAIT_FOR_READ: - link->stream->watch = core->watch_add(core, link->stream->socket, SPICE_WATCH_EVENT_READ, - reds_handle_ssl_accept, link); + link->stream->watch = reds->core->watch_add(reds->core, link->stream->socket, SPICE_WATCH_EVENT_READ, + reds_handle_ssl_accept, link); break; case REDS_STREAM_SSL_STATUS_WAIT_FOR_WRITE: - link->stream->watch = core->watch_add(core, link->stream->socket, SPICE_WATCH_EVENT_WRITE, - reds_handle_ssl_accept, link); + link->stream->watch = reds->core->watch_add(reds->core, link->stream->socket, SPICE_WATCH_EVENT_WRITE, + reds_handle_ssl_accept, link); break; } return link; @@ -2534,9 +2532,9 @@ static int reds_init_net(RedsState *reds) if (-1 == reds->listen_socket) { return -1; } - reds->listen_watch = core->watch_add(core, reds->listen_socket, - SPICE_WATCH_EVENT_READ, - reds_accept, NULL); + reds->listen_watch = reds->core->watch_add(reds->core, reds->listen_socket, + SPICE_WATCH_EVENT_READ, + reds_accept, NULL); if (reds->listen_watch == NULL) { spice_warning("set fd handle failed"); return -1; @@ -2549,9 +2547,9 @@ static int reds_init_net(RedsState *reds) if (-1 == reds->secure_listen_socket) { return -1; } - reds->secure_listen_watch = core->watch_add(core, reds->secure_listen_socket, - SPICE_WATCH_EVENT_READ, - reds_accept_ssl_connection, NULL); + reds->secure_listen_watch = reds->core->watch_add(reds->core, reds->secure_listen_socket, + SPICE_WATCH_EVENT_READ, + reds_accept_ssl_connection, reds); if (reds->secure_listen_watch == NULL) { spice_warning("set fd handle failed"); return -1; @@ -2560,9 +2558,9 @@ static int reds_init_net(RedsState *reds) if (reds->spice_listen_socket_fd != -1 ) { reds->listen_socket = reds->spice_listen_socket_fd; - reds->listen_watch = core->watch_add(core, reds->listen_socket, - SPICE_WATCH_EVENT_READ, - reds_accept, NULL); + reds->listen_watch = reds->core->watch_add(reds->core, reds->listen_socket, + SPICE_WATCH_EVENT_READ, + reds_accept, NULL); if (reds->listen_watch == NULL) { spice_warning("set fd handle failed"); return -1; @@ -2797,7 +2795,7 @@ static void reds_mig_started(RedsState *reds) reds->mig_inprogress = TRUE; reds->mig_wait_connect = TRUE; - core->timer_start(reds->mig_timer, MIGRATE_TIMEOUT); + reds->core->timer_start(reds->mig_timer, MIGRATE_TIMEOUT); } static void reds_mig_fill_wait_disconnect(RedsState *reds) @@ -2816,7 +2814,7 @@ static void reds_mig_fill_wait_disconnect(RedsState *reds) ring_add(&reds->mig_wait_disconnect_clients, &wait_client->link); } reds->mig_wait_disconnect = TRUE; - core->timer_start(reds->mig_timer, MIGRATE_TIMEOUT); + reds->core->timer_start(reds->mig_timer, MIGRATE_TIMEOUT); } static void reds_mig_cleanup_wait_disconnect(RedsState *reds) @@ -3308,20 +3306,20 @@ static int do_spice_init(RedsState *reds, SpiceCoreInterface *core_interface) goto err; } core_public = core_interface; - core = &core_interface_adapter; + reds->core = &core_interface_adapter; reds->listen_socket = -1; reds->secure_listen_socket = -1; reds_init_vd_agent_resources(reds); ring_init(&reds->clients); reds->num_clients = 0; - main_dispatcher_init(core); + main_dispatcher_init(reds->core); ring_init(&reds->channels); ring_init(&reds->mig_target_clients); ring_init(&reds->char_devs_states); ring_init(&reds->mig_wait_disconnect_clients); reds->vm_running = TRUE; /* for backward compatibility */ - if (!(reds->mig_timer = core->timer_add(core, migrate_timeout, reds))) { + if (!(reds->mig_timer = reds->core->timer_add(reds->core, migrate_timeout, reds))) { spice_error("migration timer create failed"); } @@ -4021,3 +4019,8 @@ spice_wan_compression_t reds_get_zlib_glz_state(RedsState *reds) { return reds->zlib_glz_state; } + +SpiceCoreInterfaceInternal* reds_get_core_interface(RedsState *reds) +{ + return reds->core; +} diff --git a/server/reds.h b/server/reds.h index 2998d0a..9ee9882 100644 --- a/server/reds.h +++ b/server/reds.h @@ -72,8 +72,6 @@ enum { RED_RENDERER_LAST }; -extern struct SpiceCoreInterfaceInternal *core; - // Temporary measures to make splitting reds.c to inputs-channel.c easier /* should be called only from main_dispatcher */ @@ -112,5 +110,6 @@ void reds_set_client_mm_time_latency(RedsState *reds, RedClient *client, uint32_ uint32_t reds_get_streaming_video(RedsState *reds); spice_wan_compression_t reds_get_jpeg_state(const RedsState *reds); spice_wan_compression_t reds_get_zlib_glz_state(RedsState *reds); +SpiceCoreInterfaceInternal* reds_get_core_interface(RedsState *reds); #endif diff --git a/server/smartcard.c b/server/smartcard.c index 9b8f7c6..0be3235 100644 --- a/server/smartcard.c +++ b/server/smartcard.c @@ -848,7 +848,8 @@ static void smartcard_init(void) channel_cbs.handle_migrate_data = smartcard_channel_client_handle_migrate_data; g_smartcard_channel = (SmartCardChannel*)red_channel_create(sizeof(SmartCardChannel), - core, SPICE_CHANNEL_SMARTCARD, 0, + reds_get_core_interface(reds), + SPICE_CHANNEL_SMARTCARD, 0, FALSE /* handle_acks */, smartcard_channel_handle_message, &channel_cbs, diff --git a/server/sound.c b/server/sound.c index 0890a87..3c77d77 100644 --- a/server/sound.c +++ b/server/sound.c @@ -213,7 +213,7 @@ static void snd_disconnect_channel(SndChannel *channel) channel->cleanup(channel); red_channel_client_disconnect(worker->connection->channel_client); worker->connection->channel_client = NULL; - core->watch_remove(channel->stream->watch); + reds_get_core_interface(reds)->watch_remove(channel->stream->watch); channel->stream->watch = NULL; reds_stream_free(channel->stream); channel->stream = NULL; @@ -266,7 +266,7 @@ static int snd_send_data(SndChannel *channel) if (channel->blocked) { channel->blocked = FALSE; - core->watch_update_mask(channel->stream->watch, SPICE_WATCH_EVENT_READ); + reds_get_core_interface(reds)->watch_update_mask(channel->stream->watch, SPICE_WATCH_EVENT_READ); } break; } @@ -278,8 +278,8 @@ static int snd_send_data(SndChannel *channel) switch (errno) { case EAGAIN: channel->blocked = TRUE; - core->watch_update_mask(channel->stream->watch, SPICE_WATCH_EVENT_READ | - SPICE_WATCH_EVENT_WRITE); + reds_get_core_interface(reds)->watch_update_mask(channel->stream->watch, SPICE_WATCH_EVENT_READ | + SPICE_WATCH_EVENT_WRITE); return FALSE; case EINTR: break; @@ -947,8 +947,9 @@ static SndChannel *__new_channel(SndWorker *worker, int size, uint32_t channel_i channel->receive_data.end = channel->receive_data.buf + sizeof(channel->receive_data.buf); channel->send_data.marshaller = spice_marshaller_new(); - stream->watch = core->watch_add(core, stream->socket, SPICE_WATCH_EVENT_READ, - snd_event, channel); + stream->watch = reds_get_core_interface(reds)->watch_add(reds_get_core_interface(reds), + stream->socket, SPICE_WATCH_EVENT_READ, + snd_event, channel); if (stream->watch == NULL) { spice_printerr("watch_add failed, %s", strerror(errno)); goto error2; diff --git a/server/spicevmc.c b/server/spicevmc.c index 28a65d7..95d840e 100644 --- a/server/spicevmc.c +++ b/server/spicevmc.c @@ -524,7 +524,7 @@ SpiceCharDeviceState *spicevmc_device_connect(SpiceCharDeviceInstance *sin, channel_cbs.handle_migrate_data = spicevmc_channel_client_handle_migrate_data; state = (SpiceVmcState*)red_channel_create(sizeof(SpiceVmcState), - core, channel_type, id[channel_type]++, + reds_get_core_interface(reds), channel_type, id[channel_type]++, FALSE /* handle_acks */, spicevmc_red_channel_client_handle_message, &channel_cbs, -- 2.4.3 _______________________________________________ Spice-devel mailing list Spice-devel@xxxxxxxxxxxxxxxxxxxxx http://lists.freedesktop.org/mailman/listinfo/spice-devel