[Spice-devel] [PATCH 6/9] server: optionally pass SpiceBaseInstance to watch and timer

Marc-André Lureau marcandre.lureau at gmail.com
Mon Nov 18 02:28:30 PST 2013


From: Marc-André Lureau <marcandre.lureau at redhat.com>

That way, the user code can associate interface loop timers and watchs
with a particular context.
---
 server/char_device.c                           |  5 +++--
 server/inputs_channel.c                        |  2 +-
 server/main_channel.c                          |  2 +-
 server/main_dispatcher.c                       |  2 +-
 server/red_channel.c                           | 13 +++++++------
 server/red_worker.c                            |  4 ++--
 server/reds.c                                  | 16 +++++++++-------
 server/snd_worker.c                            |  2 +-
 server/spice.h                                 |  8 ++++----
 server/spice_timer_queue.c                     |  2 +-
 server/spice_timer_queue.h                     |  2 +-
 server/tests/basic_event_loop.c                |  6 ++++--
 server/tests/test_display_base.c               |  2 +-
 server/tests/test_display_no_ssl.c             |  2 +-
 server/tests/test_display_resolution_changes.c |  2 +-
 server/tests/test_display_width_stride.c       |  2 +-
 server/tests/test_empty_success.c              |  5 +++--
 server/tests/test_playback.c                   |  2 +-
 server/tests/test_vdagent.c                    |  2 +-
 19 files changed, 44 insertions(+), 37 deletions(-)

diff --git a/server/char_device.c b/server/char_device.c
index 660a788..0cd5106 100644
--- a/server/char_device.c
+++ b/server/char_device.c
@@ -652,7 +652,7 @@ SpiceCharDeviceState *spice_char_device_state_create(SpiceCharDeviceInstance *si
     ring_init(&char_dev->write_bufs_pool);
     ring_init(&char_dev->clients);
 
-    char_dev->write_to_dev_timer = core->timer_add(spice_char_dev_write_retry, char_dev);
+    char_dev->write_to_dev_timer = core->timer_add(spice_char_dev_write_retry, char_dev, SPICE_BASE_INSTANCE(sin));
     if (!char_dev->write_to_dev_timer) {
         spice_error("failed creating char dev write timer");
     }
@@ -747,7 +747,8 @@ int spice_char_device_client_add(SpiceCharDeviceState *dev,
     dev_client->do_flow_control = do_flow_control;
     if (do_flow_control) {
         dev_client->wait_for_tokens_timer = core->timer_add(device_client_wait_for_tokens_timeout,
-                                                            dev_client);
+                                                            dev_client,
+                                                            SPICE_BASE_INSTANCE(dev->sin));
         if (!dev_client->wait_for_tokens_timer) {
             spice_error("failed to create wait for tokens timer");
         }
diff --git a/server/inputs_channel.c b/server/inputs_channel.c
index dc3fac4..488e943 100644
--- a/server/inputs_channel.c
+++ b/server/inputs_channel.c
@@ -668,7 +668,7 @@ void inputs_init(void)
     red_channel_set_cap(&g_inputs_channel->base, SPICE_INPUTS_CAP_KEY_SCANCODE);
     reds_register_channel(&g_inputs_channel->base);
 
-    if (!(key_modifiers_timer = core->timer_add(key_modifiers_sender, NULL))) {
+    if (!(key_modifiers_timer = core->timer_add(key_modifiers_sender, NULL, NULL))) {
         spice_error("key modifiers timer create failed");
     }
 }
diff --git a/server/main_channel.c b/server/main_channel.c
index a6ba7d6..05eb11b 100644
--- a/server/main_channel.c
+++ b/server/main_channel.c
@@ -1113,7 +1113,7 @@ 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(ping_timer_cb, NULL))) {
+    if (!(mcc->ping_timer = core->timer_add(ping_timer_cb, NULL, NULL))) {
         spice_error("ping timer create failed");
     }
     mcc->ping_interval = PING_INTERVAL;
diff --git a/server/main_dispatcher.c b/server/main_dispatcher.c
index dbe1037..22f28e7 100644
--- a/server/main_dispatcher.c
+++ b/server/main_dispatcher.c
@@ -184,7 +184,7 @@ void main_dispatcher_init(SpiceCoreInterface *core)
     main_dispatcher.core = core;
     dispatcher_init(&main_dispatcher.base, MAIN_DISPATCHER_NUM_MESSAGES, &main_dispatcher.base);
     core->watch_add(main_dispatcher.base.recv_fd, SPICE_WATCH_EVENT_READ,
-                    dispatcher_handle_read, &main_dispatcher.base);
+                    dispatcher_handle_read, &main_dispatcher.base, NULL);
     dispatcher_register_handler(&main_dispatcher.base, MAIN_DISPATCHER_CHANNEL_EVENT,
                                 main_dispatcher_handle_channel_event,
                                 sizeof(MainDispatcherChannelEventMessage), 0 /* no ack */);
diff --git a/server/red_channel.c b/server/red_channel.c
index f1eb912..632e76c 100644
--- a/server/red_channel.c
+++ b/server/red_channel.c
@@ -844,7 +844,7 @@ void red_channel_client_start_connectivity_monitoring(RedChannelClient *rcc, uin
      */
     if (rcc->latency_monitor.timer == NULL) {
         rcc->latency_monitor.timer = rcc->channel->core->timer_add(
-            red_channel_client_ping_timer, rcc);
+            red_channel_client_ping_timer, rcc, rcc->channel->sin);
         if (!rcc->client->during_target_migrate) {
             red_channel_client_start_ping_timer(rcc, PING_TEST_IDLE_NET_TIMEOUT_MS);
         }
@@ -853,7 +853,7 @@ void red_channel_client_start_connectivity_monitoring(RedChannelClient *rcc, uin
     if (rcc->connectivity_monitor.timer == NULL) {
         rcc->connectivity_monitor.state = CONNECTIVITY_STATE_CONNECTED;
         rcc->connectivity_monitor.timer = rcc->channel->core->timer_add(
-            red_channel_client_connectivity_timer, rcc);
+            red_channel_client_connectivity_timer, rcc, rcc->channel->sin);
         rcc->connectivity_monitor.timeout = timeout_ms;
         if (!rcc->client->during_target_migrate) {
            rcc->channel->core->timer_start(rcc->connectivity_monitor.timer,
@@ -919,8 +919,9 @@ RedChannelClient *red_channel_client_create(int size, RedChannel *channel, RedCl
     rcc->pipe_size = 0;
 
     stream->watch = channel->core->watch_add(stream->socket,
-                                           SPICE_WATCH_EVENT_READ,
-                                           red_channel_client_event, rcc);
+                                             SPICE_WATCH_EVENT_READ,
+                                             red_channel_client_event, rcc,
+                                             channel->sin);
     rcc->id = channel->clients_num;
     red_channel_add_client(channel, rcc);
     red_client_add_channel(client, rcc);
@@ -929,7 +930,7 @@ RedChannelClient *red_channel_client_create(int size, RedChannel *channel, RedCl
 
     if (monitor_latency) {
         rcc->latency_monitor.timer = channel->core->timer_add(
-            red_channel_client_ping_timer, rcc);
+            red_channel_client_ping_timer, rcc, channel->sin);
         if (!client->during_target_migrate) {
             red_channel_client_start_ping_timer(rcc, PING_TEST_IDLE_NET_TIMEOUT_MS);
         }
@@ -1084,7 +1085,7 @@ static void dummy_watch_update_mask(SpiceWatch *watch, int event_mask)
 {
 }
 
-static SpiceWatch *dummy_watch_add(int fd, int event_mask, SpiceWatchFunc func, void *opaque)
+static SpiceWatch *dummy_watch_add(int fd, int event_mask, SpiceWatchFunc func, void *opaque, SpiceBaseInstance *sin)
 {
     return NULL; // apparently allowed?
 }
diff --git a/server/red_worker.c b/server/red_worker.c
index d9c1fc5..91c6ad1 100644
--- a/server/red_worker.c
+++ b/server/red_worker.c
@@ -3112,7 +3112,7 @@ static void red_create_stream(RedWorker *worker, Drawable *drawable)
     SpiceBitmap *bitmap = &drawable->red_drawable->u.copy.src_bitmap->u.bitmap;
     stream->top_down = !!(bitmap->flags & SPICE_BITMAP_FLAGS_TOP_DOWN);
     drawable->stream = stream;
-    stream->input_fps_timer = spice_timer_queue_add(red_stream_input_fps_timer_cb, stream);
+    stream->input_fps_timer = spice_timer_queue_add(red_stream_input_fps_timer_cb, stream, NULL);
     spice_assert(stream->input_fps_timer);
     spice_timer_set(stream->input_fps_timer, RED_STREAM_INPUT_FPS_TIMEOUT);
     stream->num_input_frames = 0;
@@ -10172,7 +10172,7 @@ static void worker_watch_update_mask(SpiceWatch *watch, int event_mask)
     }
 }
 
-static SpiceWatch *worker_watch_add(int fd, int event_mask, SpiceWatchFunc func, void *opaque)
+static SpiceWatch *worker_watch_add(int fd, int event_mask, SpiceWatchFunc func, void *opaque, SpiceBaseInstance *sin)
 {
     /* Since we are a channel core implementation, we always get called from
        red_channel_client_create(), so opaque always is our rcc */
diff --git a/server/reds.c b/server/reds.c
index 6197547..7809439 100644
--- a/server/reds.c
+++ b/server/reds.c
@@ -2105,7 +2105,8 @@ static void async_read_handler(int fd, int event, void *data)
                     if (!obj->stream->watch) {
                         obj->stream->watch = core->watch_add(obj->stream->socket,
                                                            SPICE_WATCH_EVENT_READ,
-                                                           async_read_handler, obj);
+                                                           async_read_handler, obj,
+                                                           NULL);
                     }
                     return;
                 case EINTR:
@@ -2924,7 +2925,7 @@ static RedLinkInfo *reds_init_client_ssl_connection(int socket)
         int eventmask = ssl_error == SSL_ERROR_WANT_READ ?
             SPICE_WATCH_EVENT_READ : SPICE_WATCH_EVENT_WRITE;
         link->stream->watch = core->watch_add(link->stream->socket, eventmask,
-                                            reds_handle_ssl_accept, link);
+                                              reds_handle_ssl_accept, link, NULL);
         return link;
     }
 
@@ -3107,7 +3108,7 @@ static int reds_init_net(void)
         }
         reds->listen_watch = core->watch_add(reds->listen_socket,
                                              SPICE_WATCH_EVENT_READ,
-                                             reds_accept, NULL);
+                                             reds_accept, NULL, NULL);
         if (reds->listen_watch == NULL) {
             spice_warning("set fd handle failed");
             return -1;
@@ -3122,7 +3123,8 @@ static int reds_init_net(void)
         }
         reds->secure_listen_watch = core->watch_add(reds->secure_listen_socket,
                                                     SPICE_WATCH_EVENT_READ,
-                                                    reds_accept_ssl_connection, NULL);
+                                                    reds_accept_ssl_connection,
+                                                    NULL, NULL);
         if (reds->secure_listen_watch == NULL) {
             spice_warning("set fd handle failed");
             return -1;
@@ -3133,7 +3135,7 @@ static int reds_init_net(void)
         reds->listen_socket = spice_listen_socket_fd;
         reds->listen_watch = core->watch_add(reds->listen_socket,
                                              SPICE_WATCH_EVENT_READ,
-                                             reds_accept, NULL);
+                                             reds_accept, NULL, NULL);
         if (reds->listen_watch == NULL) {
             spice_warning("set fd handle failed");
             return -1;
@@ -3882,7 +3884,7 @@ static int do_spice_init(SpiceCoreInterface *core_interface)
     ring_init(&reds->mig_wait_disconnect_clients);
     reds->vm_running = TRUE; /* for backward compatibility */
 
-    if (!(reds->mig_timer = core->timer_add(migrate_timeout, NULL))) {
+    if (!(reds->mig_timer = core->timer_add(migrate_timeout, NULL, NULL))) {
         spice_error("migration timer create failed");
     }
 
@@ -3912,7 +3914,7 @@ static int do_spice_init(SpiceCoreInterface *core_interface)
     }
 #endif
 
-    if (!(reds->mm_timer = core->timer_add(mm_timer_proc, NULL))) {
+    if (!(reds->mm_timer = core->timer_add(mm_timer_proc, NULL, NULL))) {
         spice_error("mm timer create failed");
     }
     reds_enable_mm_timer();
diff --git a/server/snd_worker.c b/server/snd_worker.c
index 41cf4d2..7b3a164 100644
--- a/server/snd_worker.c
+++ b/server/snd_worker.c
@@ -944,7 +944,7 @@ static SndChannel *__new_channel(SndWorker *worker, int size, uint32_t channel_i
     channel->send_data.marshaller = spice_marshaller_new();
 
     stream->watch = core->watch_add(stream->socket, SPICE_WATCH_EVENT_READ,
-                                  snd_event, channel);
+                                    snd_event, channel, NULL);
     if (stream->watch == NULL) {
         spice_printerr("watch_add failed, %s", strerror(errno));
         goto error2;
diff --git a/server/spice.h b/server/spice.h
index 03e7bd8..95053f5 100644
--- a/server/spice.h
+++ b/server/spice.h
@@ -51,8 +51,8 @@ struct SpiceBaseInstance {
 /* core interface */
 
 #define SPICE_INTERFACE_CORE "core"
-#define SPICE_INTERFACE_CORE_MAJOR 1
-#define SPICE_INTERFACE_CORE_MINOR 3
+#define SPICE_INTERFACE_CORE_MAJOR 2
+#define SPICE_INTERFACE_CORE_MINOR 1
 typedef struct SpiceCoreInterface SpiceCoreInterface;
 
 #define SPICE_WATCH_EVENT_READ  (1 << 0)
@@ -90,12 +90,12 @@ typedef struct SpiceChannelEventInfo {
 struct SpiceCoreInterface {
     SpiceBaseInterface base;
 
-    SpiceTimer *(*timer_add)(SpiceTimerFunc func, void *opaque);
+    SpiceTimer *(*timer_add)(SpiceTimerFunc func, void *opaque, SpiceBaseInstance *sin);
     void (*timer_start)(SpiceTimer *timer, uint32_t ms);
     void (*timer_cancel)(SpiceTimer *timer);
     void (*timer_remove)(SpiceTimer *timer);
 
-    SpiceWatch *(*watch_add)(int fd, int event_mask, SpiceWatchFunc func, void *opaque);
+    SpiceWatch *(*watch_add)(int fd, int event_mask, SpiceWatchFunc func, void *opaque, SpiceBaseInstance *sin);
     void (*watch_update_mask)(SpiceWatch *watch, int event_mask);
     void (*watch_remove)(SpiceWatch *watch);
 
diff --git a/server/spice_timer_queue.c b/server/spice_timer_queue.c
index 8f6e9c8..869577a 100644
--- a/server/spice_timer_queue.c
+++ b/server/spice_timer_queue.c
@@ -128,7 +128,7 @@ void spice_timer_queue_destroy(void)
     pthread_mutex_unlock(&queue_list_lock);
 }
 
-SpiceTimer *spice_timer_queue_add(SpiceTimerFunc func, void *opaque)
+SpiceTimer *spice_timer_queue_add(SpiceTimerFunc func, void *opaque, SpiceBaseInstance *sin)
 {
     SpiceTimer *timer = spice_new0(SpiceTimer, 1);
     SpiceTimerQueue *queue = spice_timer_queue_find_with_lock();
diff --git a/server/spice_timer_queue.h b/server/spice_timer_queue.h
index a84f6cd..68c83ea 100644
--- a/server/spice_timer_queue.h
+++ b/server/spice_timer_queue.h
@@ -29,7 +29,7 @@ typedef struct SpiceTimerQueue SpiceTimerQueue;
 int spice_timer_queue_create(void);
 void spice_timer_queue_destroy(void);
 
-SpiceTimer *spice_timer_queue_add(SpiceTimerFunc func, void *opaque);
+SpiceTimer *spice_timer_queue_add(SpiceTimerFunc func, void *opaque, SpiceBaseInstance *sin);
 void spice_timer_set(SpiceTimer *timer, uint32_t ms);
 void spice_timer_cancel(SpiceTimer *timer);
 void spice_timer_remove(SpiceTimer *timer);
diff --git a/server/tests/basic_event_loop.c b/server/tests/basic_event_loop.c
index c6f6698..deb28c5 100644
--- a/server/tests/basic_event_loop.c
+++ b/server/tests/basic_event_loop.c
@@ -32,7 +32,8 @@ typedef struct SpiceTimer {
 
 Ring timers;
 
-static SpiceTimer* timer_add(SpiceTimerFunc func, void *opaque)
+static SpiceTimer* timer_add(SpiceTimerFunc func, void *opaque,
+                             SpiceBaseInstance *instance)
 {
     SpiceTimer *timer = calloc(sizeof(SpiceTimer), 1);
 
@@ -83,7 +84,8 @@ Ring watches;
 
 int watch_count = 0;
 
-static SpiceWatch *watch_add(int fd, int event_mask, SpiceWatchFunc func, void *opaque)
+static SpiceWatch *watch_add(int fd, int event_mask, SpiceWatchFunc func,
+                             void *opaque, SpiceBaseInstance *instance)
 {
     SpiceWatch *watch = malloc(sizeof(SpiceWatch));
 
diff --git a/server/tests/test_display_base.c b/server/tests/test_display_base.c
index ccdd2f2..0377555 100644
--- a/server/tests/test_display_base.c
+++ b/server/tests/test_display_base.c
@@ -866,7 +866,7 @@ Test *test_new(SpiceCoreInterface *core)
     cursor_init();
     path_init(&path, 0, angle_parts);
     test->has_secondary = 0;
-    test->wakeup_timer = core->timer_add(do_wakeup, test);
+    test->wakeup_timer = core->timer_add(do_wakeup, test, NULL);
     return test;
 }
 
diff --git a/server/tests/test_display_no_ssl.c b/server/tests/test_display_no_ssl.c
index 83ab3dc..7831654 100644
--- a/server/tests/test_display_no_ssl.c
+++ b/server/tests/test_display_no_ssl.c
@@ -46,7 +46,7 @@ int main(void)
     test_add_agent_interface(test->server);
     test_set_simple_command_list(test, simple_commands, COUNT(simple_commands));
 
-    ping_timer = core->timer_add(pinger, NULL);
+    ping_timer = core->timer_add(pinger, NULL, NULL);
     core->timer_start(ping_timer, ping_ms);
 
     basic_event_loop_mainloop();
diff --git a/server/tests/test_display_resolution_changes.c b/server/tests/test_display_resolution_changes.c
index 4767ea9..15dc5a9 100644
--- a/server/tests/test_display_resolution_changes.c
+++ b/server/tests/test_display_resolution_changes.c
@@ -59,7 +59,7 @@ int main(void)
     test_add_display_interface(test);
     test_set_command_list(test, commands, COUNT(commands));
 
-    ping_timer = core->timer_add(pinger, test);
+    ping_timer = core->timer_add(pinger, test, NULL);
     core->timer_start(ping_timer, ping_ms);
 
     basic_event_loop_mainloop();
diff --git a/server/tests/test_display_width_stride.c b/server/tests/test_display_width_stride.c
index f938373..4260ee8 100644
--- a/server/tests/test_display_width_stride.c
+++ b/server/tests/test_display_width_stride.c
@@ -92,7 +92,7 @@ int main(void)
     //spice_server_set_image_compression(server, SPICE_IMAGE_COMPRESS_OFF);
     test_add_display_interface(test);
 
-    ping_timer = core->timer_add(pinger, test);
+    ping_timer = core->timer_add(pinger, test, NULL);
     core->timer_start(ping_timer, ping_ms);
 
     basic_event_loop_mainloop();
diff --git a/server/tests/test_empty_success.c b/server/tests/test_empty_success.c
index 0176a52..a43b0aa 100644
--- a/server/tests/test_empty_success.c
+++ b/server/tests/test_empty_success.c
@@ -8,7 +8,7 @@ struct SpiceTimer {
     int a,b;
 };
 
-SpiceTimer* timer_add(SpiceTimerFunc func, void *opaque)
+SpiceTimer* timer_add(SpiceTimerFunc func, void *opaque, SpiceBaseInstance *instance)
 {
     static struct SpiceTimer t = {0,};
 
@@ -27,7 +27,8 @@ void timer_remove(SpiceTimer *timer)
 {
 }
 
-SpiceWatch *watch_add(int fd, int event_mask, SpiceWatchFunc func, void *opaque)
+SpiceWatch *watch_add(int fd, int event_mask, SpiceWatchFunc func,
+                      void *opaque, SpiceBaseInstance *instance)
 {
     return NULL;
 }
diff --git a/server/tests/test_playback.c b/server/tests/test_playback.c
index ed1b766..6bd1927 100644
--- a/server/tests/test_playback.c
+++ b/server/tests/test_playback.c
@@ -104,7 +104,7 @@ int main(void)
     spice_server_playback_start(&playback_instance);
 
     playback_timer_ms = 100;
-    playback_timer = core->timer_add(playback_timer_cb, NULL);
+    playback_timer = core->timer_add(playback_timer_cb, NULL, NULL);
     core->timer_start(playback_timer, playback_timer_ms);
 
     basic_event_loop_mainloop();
diff --git a/server/tests/test_vdagent.c b/server/tests/test_vdagent.c
index af33145..67e44c2 100644
--- a/server/tests/test_vdagent.c
+++ b/server/tests/test_vdagent.c
@@ -98,7 +98,7 @@ int main(void)
     vmc_instance.base.sif = &vmc_interface.base;
     spice_server_add_interface(test->server, &vmc_instance.base);
 
-    ping_timer = core->timer_add(pinger, NULL);
+    ping_timer = core->timer_add(pinger, NULL, NULL);
     core->timer_start(ping_timer, ping_ms);
 
     basic_event_loop_mainloop();
-- 
1.8.3.1



More information about the Spice-devel mailing list