[Spice-devel] [PATCH v2 5/6] Base FOREACH_CLIENT on GLIST_FOREACH

Frediano Ziglio fziglio at redhat.com
Tue Sep 20 08:05:03 UTC 2016


Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
---
 server/main-channel.c | 20 ++++++++++----------
 server/red-channel.c  | 36 ++++++++++++++++++------------------
 server/red-channel.h  | 12 +++---------
 server/red-worker.c   |  4 ++--
 4 files changed, 33 insertions(+), 39 deletions(-)

diff --git a/server/main-channel.c b/server/main-channel.c
index 4670315..daa123c 100644
--- a/server/main-channel.c
+++ b/server/main-channel.c
@@ -44,10 +44,10 @@ static void main_channel_client_on_disconnect(RedChannelClient *rcc)
 
 RedClient *main_channel_get_client_by_link_id(MainChannel *main_chan, uint32_t connection_id)
 {
-    GList *link, *next;
+    GListIter iter;
     RedChannelClient *rcc;
 
-    FOREACH_CLIENT(main_chan, link, next, rcc) {
+    FOREACH_CLIENT(main_chan, iter, rcc) {
         MainChannelClient *mcc = (MainChannelClient*) rcc;
         if (main_channel_client_get_connection_id(mcc) == connection_id) {
             return red_channel_client_get_client(rcc);
@@ -334,10 +334,10 @@ MainChannel* main_channel_new(RedsState *reds)
 
 static int main_channel_connect_semi_seamless(MainChannel *main_channel)
 {
-    GList *link, *next;
+    GListIter iter;
     RedChannelClient *rcc;
 
-    FOREACH_CLIENT(main_channel, link, next, rcc) {
+    FOREACH_CLIENT(main_channel, iter, rcc) {
         MainChannelClient *mcc = (MainChannelClient*)rcc;
         if (main_channel_client_connect_semi_seamless(mcc))
             main_channel->num_clients_mig_wait++;
@@ -347,12 +347,12 @@ static int main_channel_connect_semi_seamless(MainChannel *main_channel)
 
 static int main_channel_connect_seamless(MainChannel *main_channel)
 {
-    GList *link, *next;
+    GListIter iter;
     RedChannelClient *rcc;
 
     spice_assert(g_list_length(main_channel->base.clients) == 1);
 
-    FOREACH_CLIENT(main_channel, link, next, rcc) {
+    FOREACH_CLIENT(main_channel, iter, rcc) {
         MainChannelClient *mcc = (MainChannelClient*)rcc;
         main_channel_client_connect_seamless(mcc);
         main_channel->num_clients_mig_wait++;
@@ -389,10 +389,10 @@ int main_channel_migrate_connect(MainChannel *main_channel, RedsMigSpice *mig_ta
 
 void main_channel_migrate_cancel_wait(MainChannel *main_chan)
 {
-    GList *link, *next;
+    GListIter iter;
     RedChannelClient *rcc;
 
-    FOREACH_CLIENT(main_chan, link, next, rcc) {
+    FOREACH_CLIENT(main_chan, iter, rcc) {
         MainChannelClient *mcc = (MainChannelClient*)rcc;
         main_channel_client_migrate_cancel_wait(mcc);
     }
@@ -401,7 +401,7 @@ void main_channel_migrate_cancel_wait(MainChannel *main_chan)
 
 int main_channel_migrate_src_complete(MainChannel *main_chan, int success)
 {
-    GList *link, *next;
+    GListIter iter;
     int semi_seamless_count = 0;
     RedChannelClient *rcc;
 
@@ -412,7 +412,7 @@ int main_channel_migrate_src_complete(MainChannel *main_chan, int success)
         return 0;
     }
 
-    FOREACH_CLIENT(main_chan, link, next, rcc) {
+    FOREACH_CLIENT(main_chan, iter, rcc) {
         MainChannelClient *mcc = (MainChannelClient*)rcc;
         if (main_channel_client_migrate_src_complete(mcc, success))
             semi_seamless_count++;
diff --git a/server/red-channel.c b/server/red-channel.c
index f2aa0de..527971a 100644
--- a/server/red-channel.c
+++ b/server/red-channel.c
@@ -87,10 +87,10 @@ void red_channel_add_client(RedChannel *channel, RedChannelClient *rcc)
 
 int red_channel_test_remote_common_cap(RedChannel *channel, uint32_t cap)
 {
-    GList *link, *next;
+    GListIter iter;
     RedChannelClient *rcc;
 
-    FOREACH_CLIENT(channel, link, next, rcc) {
+    FOREACH_CLIENT(channel, iter, rcc) {
         if (!red_channel_client_test_remote_common_cap(rcc, cap)) {
             return FALSE;
         }
@@ -100,10 +100,10 @@ int red_channel_test_remote_common_cap(RedChannel *channel, uint32_t cap)
 
 int red_channel_test_remote_cap(RedChannel *channel, uint32_t cap)
 {
-    GList *link, *next;
+    GListIter iter;
     RedChannelClient *rcc;
 
-    FOREACH_CLIENT(channel, link, next, rcc) {
+    FOREACH_CLIENT(channel, iter, rcc) {
         if (!red_channel_client_test_remote_cap(rcc, cap)) {
             return FALSE;
         }
@@ -486,13 +486,13 @@ void red_channel_apply_clients_data(RedChannel *channel, channel_client_callback
 
 int red_channel_all_blocked(RedChannel *channel)
 {
-    GList *link, *next;
+    GListIter iter;
     RedChannelClient *rcc;
 
     if (!channel || !channel->clients) {
         return FALSE;
     }
-    FOREACH_CLIENT(channel, link, next, rcc) {
+    FOREACH_CLIENT(channel, iter, rcc) {
         if (!red_channel_client_is_blocked(rcc)) {
             return FALSE;
         }
@@ -502,10 +502,10 @@ int red_channel_all_blocked(RedChannel *channel)
 
 int red_channel_any_blocked(RedChannel *channel)
 {
-    GList *link, *next;
+    GListIter iter;
     RedChannelClient *rcc;
 
-    FOREACH_CLIENT(channel, link, next, rcc) {
+    FOREACH_CLIENT(channel, iter, rcc) {
         if (red_channel_client_is_blocked(rcc)) {
             return TRUE;
         }
@@ -529,10 +529,10 @@ int red_channel_get_first_socket(RedChannel *channel)
 
 int red_channel_no_item_being_sent(RedChannel *channel)
 {
-    GList *link, *next;
+    GListIter iter;
     RedChannelClient *rcc;
 
-    FOREACH_CLIENT(channel, link, next, rcc) {
+    FOREACH_CLIENT(channel, iter, rcc) {
         if (!red_channel_client_no_item_being_sent(rcc)) {
             return FALSE;
         }
@@ -740,7 +740,7 @@ static int red_channel_pipes_create_batch(RedChannel *channel,
                                 new_pipe_item_t creator, void *data,
                                 rcc_item_t pipe_add)
 {
-    GList *link, *next;
+    GListIter iter;
     RedChannelClient *rcc;
     RedPipeItem *item;
     int num = 0, n = 0;
@@ -748,7 +748,7 @@ static int red_channel_pipes_create_batch(RedChannel *channel,
     spice_assert(creator != NULL);
     spice_assert(pipe_add != NULL);
 
-    FOREACH_CLIENT(channel, link, next, rcc) {
+    FOREACH_CLIENT(channel, iter, rcc) {
         item = (*creator)(rcc, data, num++);
         if (item) {
             (*pipe_add)(rcc, item);
@@ -783,11 +783,11 @@ void red_channel_pipes_new_add_tail(RedChannel *channel, new_pipe_item_t creator
 
 uint32_t red_channel_max_pipe_size(RedChannel *channel)
 {
-    GList *link, *next;
+    GListIter iter;
     RedChannelClient *rcc;
     uint32_t pipe_size = 0;
 
-    FOREACH_CLIENT(channel, link, next, rcc) {
+    FOREACH_CLIENT(channel, iter, rcc) {
         uint32_t new_size;
         new_size = red_channel_client_get_pipe_size(rcc);
         pipe_size = MAX(pipe_size, new_size);
@@ -797,11 +797,11 @@ uint32_t red_channel_max_pipe_size(RedChannel *channel)
 
 uint32_t red_channel_min_pipe_size(RedChannel *channel)
 {
-    GList *link, *next;
+    GListIter iter;
     RedChannelClient *rcc;
     uint32_t pipe_size = ~0;
 
-    FOREACH_CLIENT(channel, link, next, rcc) {
+    FOREACH_CLIENT(channel, iter, rcc) {
         uint32_t new_size;
         new_size = red_channel_client_get_pipe_size(rcc);
         pipe_size = MIN(pipe_size, new_size);
@@ -811,11 +811,11 @@ uint32_t red_channel_min_pipe_size(RedChannel *channel)
 
 uint32_t red_channel_sum_pipes_size(RedChannel *channel)
 {
-    GList *link, *next;
+    GListIter iter;
     RedChannelClient *rcc;
     uint32_t sum = 0;
 
-    FOREACH_CLIENT(channel, link, next, rcc) {
+    FOREACH_CLIENT(channel, iter, rcc) {
         sum += red_channel_client_get_pipe_size(rcc);
     }
     return sum;
diff --git a/server/red-channel.h b/server/red-channel.h
index 68bfc7a..def5de0 100644
--- a/server/red-channel.h
+++ b/server/red-channel.h
@@ -250,15 +250,9 @@ struct RedChannel {
 #endif
 };
 
-#define FOREACH_CLIENT(channel, _link, _next, _data)                   \
-    for (_link = (channel ? RED_CHANNEL(channel)->clients : NULL), \
-         _next = (_link ? _link->next : NULL), \
-         _data = (_link ? _link->data : NULL); \
-         _link; \
-         _link = _next, \
-         _next = (_link ? _link->next : NULL), \
-         _data = (_link ? _link->data : NULL))
-
+#define FOREACH_CLIENT(_channel, _iter, _data) \
+    GLIST_FOREACH((_channel ? RED_CHANNEL(_channel)->clients : NULL), \
+                  _iter, RedChannelClient, _data)
 
 #define RED_CHANNEL(Channel) ((RedChannel *)(Channel))
 
diff --git a/server/red-worker.c b/server/red-worker.c
index fcd5d90..a79a075 100644
--- a/server/red-worker.c
+++ b/server/red-worker.c
@@ -481,7 +481,7 @@ static void guest_set_client_capabilities(RedWorker *worker)
 {
     int i;
     RedChannelClient *rcc;
-    GList *link, *next;
+    GListIter iter;
     uint8_t caps[SPICE_CAPABILITIES_SIZE] = { 0 };
     int caps_available[] = {
         SPICE_DISPLAY_CAP_SIZED_STREAM,
@@ -514,7 +514,7 @@ static void guest_set_client_capabilities(RedWorker *worker)
         for (i = 0 ; i < sizeof(caps_available) / sizeof(caps_available[0]); ++i) {
             SET_CAP(caps, caps_available[i]);
         }
-        FOREACH_CLIENT(worker->display_channel, link, next, rcc) {
+        FOREACH_CLIENT(worker->display_channel, iter, rcc) {
             for (i = 0 ; i < sizeof(caps_available) / sizeof(caps_available[0]); ++i) {
                 if (!red_channel_client_test_remote_cap(rcc, caps_available[i]))
                     CLEAR_CAP(caps, caps_available[i]);
-- 
2.7.4



More information about the Spice-devel mailing list