[PATCH 11/19] Make use of the new reds_core_timer_* API

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Christophe Fergeau <cfergeau@xxxxxxxxxx>

This makes the code more readable.
---
 server/char-device.c    | 32 +++++++++++++++-----------------
 server/inputs-channel.c |  5 ++---
 server/main-channel.c   | 12 +++++-------
 3 files changed, 22 insertions(+), 27 deletions(-)

diff --git a/server/char-device.c b/server/char-device.c
index 34b835c..9858ab3 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) {
-        reds_get_core_interface(dev->reds)->timer_remove(dev_client->wait_for_tokens_timer);
+        reds_core_timer_remove(dev->reds, 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) {
-        reds_get_core_interface(dev->reds)->timer_start(dev_client->wait_for_tokens_timer,
-                                                   SPICE_CHAR_DEVICE_WAIT_TOKENS_TIMEOUT);
+        reds_core_timer_start(dev->reds, dev_client->wait_for_tokens_timer,
+                              SPICE_CHAR_DEVICE_WAIT_TOKENS_TIMEOUT);
         dev_client->wait_for_tokens_started = TRUE;
     }
 }
@@ -371,12 +371,12 @@ static void spice_char_device_send_to_client_tokens_absorb(SpiceCharDeviceClient
     }
 
     if (spice_char_device_can_send_to_client(dev_client)) {
-        reds_get_core_interface(dev->reds)->timer_cancel(dev_client->wait_for_tokens_timer);
+        reds_core_timer_cancel(dev->reds, 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) {
-        reds_get_core_interface(dev->reds)->timer_start(dev_client->wait_for_tokens_timer,
-                                                        SPICE_CHAR_DEVICE_WAIT_TOKENS_TIMEOUT);
+        reds_core_timer_start(dev->reds, dev_client->wait_for_tokens_timer,
+                              SPICE_CHAR_DEVICE_WAIT_TOKENS_TIMEOUT);
         dev_client->wait_for_tokens_started = TRUE;
     }
 }
@@ -457,7 +457,7 @@ static int spice_char_device_write_to_device(SpiceCharDeviceState *dev)
     spice_char_device_state_ref(dev);
 
     if (dev->write_to_dev_timer) {
-        reds_get_core_interface(dev->reds)->timer_cancel(dev->write_to_dev_timer);
+        reds_core_timer_cancel(dev->reds, dev->write_to_dev_timer);
     }
 
     sif = SPICE_CONTAINEROF(dev->sin->base.sif, SpiceCharDeviceInterface, base);
@@ -499,8 +499,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) {
-                reds_get_core_interface(dev->reds)->timer_start(dev->write_to_dev_timer,
-                                                                CHAR_DEVICE_WRITE_TO_TIMEOUT);
+                reds_core_timer_start(dev->reds, dev->write_to_dev_timer,
+                                      CHAR_DEVICE_WRITE_TO_TIMEOUT);
             }
         } else {
             spice_assert(ring_is_empty(&dev->write_queue));
@@ -517,7 +517,7 @@ static void spice_char_dev_write_retry(void *opaque)
     SpiceCharDeviceState *dev = opaque;
 
     if (dev->write_to_dev_timer) {
-        reds_get_core_interface(dev->reds)->timer_cancel(dev->write_to_dev_timer);
+        reds_core_timer_cancel(dev->reds, dev->write_to_dev_timer);
     }
     spice_char_device_write_to_device(dev);
 }
@@ -698,8 +698,7 @@ 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 = reds_get_core_interface(reds)->timer_add(reds_get_core_interface(reds),
-                                                                                spice_char_dev_write_retry, char_dev);
+        char_dev->write_to_dev_timer = reds_core_timer_add(reds, spice_char_dev_write_retry, char_dev);
         if (!char_dev->write_to_dev_timer) {
             spice_error("failed creating char dev write timer");
         }
@@ -747,7 +746,7 @@ void spice_char_device_state_destroy(SpiceCharDeviceState *char_dev)
 {
     reds_on_char_device_state_destroy(char_dev->reds, char_dev);
     if (char_dev->write_to_dev_timer) {
-        reds_get_core_interface(char_dev->reds)->timer_remove(char_dev->write_to_dev_timer);
+        reds_core_timer_remove(char_dev->reds, char_dev->write_to_dev_timer);
         char_dev->write_to_dev_timer = NULL;
     }
     write_buffers_queue_free(&char_dev->write_queue);
@@ -799,9 +798,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 =
-            reds_get_core_interface(dev->reds)->timer_add(reds_get_core_interface(dev->reds),
-                                                          device_client_wait_for_tokens_timeout,
-                                                          dev_client);
+            reds_core_timer_add(dev->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");
         }
@@ -866,7 +864,7 @@ void spice_char_device_stop(SpiceCharDeviceState *dev)
     dev->running = FALSE;
     dev->active = FALSE;
     if (dev->write_to_dev_timer) {
-        reds_get_core_interface(dev->reds)->timer_cancel(dev->write_to_dev_timer);
+        reds_core_timer_cancel(dev->reds, dev->write_to_dev_timer);
     }
 }
 
diff --git a/server/inputs-channel.c b/server/inputs-channel.c
index df031ef..6533526 100644
--- a/server/inputs-channel.c
+++ b/server/inputs-channel.c
@@ -194,7 +194,7 @@ static void inputs_channel_release_msg_rcv_buf(RedChannelClient *rcc,
 
 static void activate_modifiers_watch(RedsState *reds)
 {
-    reds_get_core_interface(reds)->timer_start(key_modifiers_timer, KEY_MODIFIERS_TTL);
+    reds_core_timer_start(reds, key_modifiers_timer, KEY_MODIFIERS_TTL);
 }
 
 static void kbd_push_scan(SpiceKbdInstance *sin, uint8_t scan)
@@ -657,8 +657,7 @@ InputsChannel* inputs_channel_new(RedsState *reds)
     red_channel_set_cap(&inputs->base, SPICE_INPUTS_CAP_KEY_SCANCODE);
     reds_register_channel(reds, &inputs->base);
 
-    if (!(key_modifiers_timer = reds_get_core_interface(reds)->timer_add(reds_get_core_interface(reds),
-                                                                         key_modifiers_sender, inputs))) {
+    if (!(key_modifiers_timer = reds_core_timer_add(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 6a36ce5..4f3cf71 100644
--- a/server/main-channel.c
+++ b/server/main-channel.c
@@ -1053,9 +1053,9 @@ static void do_ping_client(MainChannelClient *mcc,
         if (has_interval && interval > 0) {
             mcc->ping_interval = interval * MSEC_PER_SEC;
         }
-        reds_get_core_interface(mcc->base.channel->reds)->timer_start(mcc->ping_timer, mcc->ping_interval);
+        reds_core_timer_start(mcc->base.channel->reds, mcc->ping_timer, mcc->ping_interval);
     } else if (!strcmp(opt, "off")) {
-        reds_get_core_interface(mcc->base.channel->reds)->timer_cancel(mcc->ping_timer);
+        reds_core_timer_cancel(mcc->base.channel->reds, mcc->ping_timer);
     } else {
         return;
     }
@@ -1067,11 +1067,11 @@ static void ping_timer_cb(void *opaque)
 
     if (!red_channel_client_is_connected(&mcc->base)) {
         spice_printerr("not connected to peer, ping off");
-        reds_get_core_interface(mcc->base.channel->reds)->timer_cancel(mcc->ping_timer);
+        reds_core_timer_cancel(mcc->base.channel->reds, mcc->ping_timer);
         return;
     }
     do_ping_client(mcc, NULL, 0, 0);
-    reds_get_core_interface(mcc->base.channel->reds)->timer_start(mcc->ping_timer, mcc->ping_interval);
+    reds_core_timer_start(mcc->base.channel->reds, mcc->ping_timer, mcc->ping_interval);
 }
 #endif /* RED_STATISTICS */
 
@@ -1080,7 +1080,6 @@ static MainChannelClient *main_channel_client_create(MainChannel *main_chan, Red
                                                      int num_common_caps, uint32_t *common_caps,
                                                      int num_caps, uint32_t *caps)
 {
-    const SpiceCoreInterfaceInternal *core;
     MainChannelClient *mcc = (MainChannelClient*)
                              red_channel_client_create(sizeof(MainChannelClient), &main_chan->base,
                                                        client, stream, FALSE, num_common_caps,
@@ -1089,8 +1088,7 @@ static MainChannelClient *main_channel_client_create(MainChannel *main_chan, Red
     mcc->connection_id = connection_id;
     mcc->bitrate_per_sec = ~0;
 #ifdef RED_STATISTICS
-    core = reds_get_core_interface(red_channel_get_server(&main_chan->base));
-    if (!(mcc->ping_timer = core->timer_add(core, ping_timer_cb, NULL))) {
+    if (!(mcc->ping_timer = reds_core_timer_add(red_channel_get_server(&main_chan->base), ping_timer_cb, NULL))) {
         spice_error("ping timer create failed");
     }
     mcc->ping_interval = PING_INTERVAL;
-- 
2.5.0

_______________________________________________
Spice-devel mailing list
Spice-devel@xxxxxxxxxxxxxxxxxxxxx
https://lists.freedesktop.org/mailman/listinfo/spice-devel




[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]     [Monitors]