[Spice-devel] [PATCH spice-server 1/3] Relax conversion to RedChannel

Frediano Ziglio fziglio at redhat.com
Mon Nov 7 11:13:21 UTC 2016


Now RED_CHANNEL is a function call so avoid to call multiple
time for the same conversion in the same functions.
This speed up and reduce code and also reduce source line
length.

Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
---
 server/cursor-channel.c  | 12 ++++++++----
 server/display-channel.c |  7 ++++---
 server/inputs-channel.c  |  9 +++++----
 server/main-channel.c    | 16 ++++++++--------
 server/smartcard.c       |  7 ++++---
 server/spicevmc.c        | 11 ++++++-----
 6 files changed, 35 insertions(+), 27 deletions(-)

diff --git a/server/cursor-channel.c b/server/cursor-channel.c
index 202ec89..2732417 100644
--- a/server/cursor-channel.c
+++ b/server/cursor-channel.c
@@ -321,10 +321,12 @@ void cursor_channel_process_cmd(CursorChannel *cursor, RedCursorCmd *cursor_cmd)
     CursorItem *cursor_item;
     int cursor_show = FALSE;
     QXLInstance *qxl;
+    RedChannel *channel;
 
     spice_return_if_fail(cursor);
     spice_return_if_fail(cursor_cmd);
 
+    channel = RED_CHANNEL(cursor);
     qxl = common_graphics_channel_get_qxl(COMMON_GRAPHICS_CHANNEL(cursor));
     cursor_item = cursor_item_new(qxl, cursor_cmd);
 
@@ -350,11 +352,11 @@ void cursor_channel_process_cmd(CursorChannel *cursor, RedCursorCmd *cursor_cmd)
         return;
     }
 
-    if (red_channel_is_connected(RED_CHANNEL(cursor)) &&
+    if (red_channel_is_connected(channel) &&
         (cursor->mouse_mode == SPICE_MOUSE_MODE_SERVER
          || cursor_cmd->type != QXL_CURSOR_MOVE
          || cursor_show)) {
-        red_channel_pipes_new_add(RED_CHANNEL(cursor),
+        red_channel_pipes_new_add(channel,
                                   new_cursor_pipe_item, cursor_item);
     }
 
@@ -389,7 +391,9 @@ static void cursor_channel_init_client(CursorChannel *cursor, CursorChannelClien
 {
     spice_return_if_fail(cursor);
 
-    if (!red_channel_is_connected(RED_CHANNEL(cursor))
+    RedChannel *channel = RED_CHANNEL(cursor);
+
+    if (!red_channel_is_connected(channel)
         || common_graphics_channel_get_during_target_migrate(COMMON_GRAPHICS_CHANNEL(cursor))) {
         spice_debug("during_target_migrate: skip init");
         return;
@@ -399,7 +403,7 @@ static void cursor_channel_init_client(CursorChannel *cursor, CursorChannelClien
         red_channel_client_pipe_add_type(RED_CHANNEL_CLIENT(client),
                                          RED_PIPE_ITEM_TYPE_CURSOR_INIT);
     else
-        red_channel_pipes_add_type(RED_CHANNEL(cursor), RED_PIPE_ITEM_TYPE_CURSOR_INIT);
+        red_channel_pipes_add_type(channel, RED_PIPE_ITEM_TYPE_CURSOR_INIT);
 }
 
 void cursor_channel_do_init(CursorChannel *cursor)
diff --git a/server/display-channel.c b/server/display-channel.c
index bcdde13..0348dce 100644
--- a/server/display-channel.c
+++ b/server/display-channel.c
@@ -1815,6 +1815,7 @@ void display_channel_destroy_surface_wait(DisplayChannel *display, uint32_t surf
 void display_channel_destroy_surfaces(DisplayChannel *display)
 {
     int i;
+    RedChannel *channel = RED_CHANNEL(display);
 
     spice_debug(NULL);
     //to handle better
@@ -1829,9 +1830,9 @@ void display_channel_destroy_surfaces(DisplayChannel *display)
     }
     spice_warn_if_fail(ring_is_empty(&display->priv->streams));
 
-    if (red_channel_is_connected(RED_CHANNEL(display))) {
-        red_channel_pipes_add_type(RED_CHANNEL(display), RED_PIPE_ITEM_TYPE_INVAL_PALETTE_CACHE);
-        red_channel_pipes_add_empty_msg(RED_CHANNEL(display), SPICE_MSG_DISPLAY_STREAM_DESTROY_ALL);
+    if (red_channel_is_connected(channel)) {
+        red_channel_pipes_add_type(channel, RED_PIPE_ITEM_TYPE_INVAL_PALETTE_CACHE);
+        red_channel_pipes_add_empty_msg(channel, SPICE_MSG_DISPLAY_STREAM_DESTROY_ALL);
     }
 
     display_channel_free_glz_drawables(display);
diff --git a/server/inputs-channel.c b/server/inputs-channel.c
index 7c397a4..c68a94b 100644
--- a/server/inputs-channel.c
+++ b/server/inputs-channel.c
@@ -602,16 +602,17 @@ inputs_channel_constructed(GObject *object)
 {
     ClientCbs client_cbs = { NULL, };
     InputsChannel *self = INPUTS_CHANNEL(object);
-    RedsState *reds = red_channel_get_server(RED_CHANNEL(self));
+    RedChannel *channel = RED_CHANNEL(self);
+    RedsState *reds = red_channel_get_server(channel);
 
     G_OBJECT_CLASS(inputs_channel_parent_class)->constructed(object);
 
     client_cbs.connect = inputs_connect;
     client_cbs.migrate = inputs_migrate;
-    red_channel_register_client_cbs(RED_CHANNEL(self), &client_cbs, NULL);
+    red_channel_register_client_cbs(channel, &client_cbs, NULL);
 
-    red_channel_set_cap(RED_CHANNEL(self), SPICE_INPUTS_CAP_KEY_SCANCODE);
-    reds_register_channel(reds, RED_CHANNEL(self));
+    red_channel_set_cap(channel, SPICE_INPUTS_CAP_KEY_SCANCODE);
+    reds_register_channel(reds, channel);
 
     self->key_modifiers_timer = reds_core_timer_add(reds, key_modifiers_sender, self);
     if (!self->key_modifiers_timer) {
diff --git a/server/main-channel.c b/server/main-channel.c
index b900b62..c7a67a9 100644
--- a/server/main-channel.c
+++ b/server/main-channel.c
@@ -104,12 +104,11 @@ void main_channel_push_mouse_mode(MainChannel *main_chan, int current_mode,
 
 void main_channel_push_agent_connected(MainChannel *main_chan)
 {
-    if (red_channel_test_remote_cap(RED_CHANNEL(main_chan),
-                                    SPICE_MAIN_CAP_AGENT_CONNECTED_TOKENS)) {
-        red_channel_pipes_add_type(RED_CHANNEL(main_chan),
-                                   RED_PIPE_ITEM_TYPE_MAIN_AGENT_CONNECTED_TOKENS);
+    RedChannel *channel = RED_CHANNEL(main_chan);
+    if (red_channel_test_remote_cap(channel, SPICE_MAIN_CAP_AGENT_CONNECTED_TOKENS)) {
+        red_channel_pipes_add_type(channel, RED_PIPE_ITEM_TYPE_MAIN_AGENT_CONNECTED_TOKENS);
     } else {
-        red_channel_pipes_add_empty_msg(RED_CHANNEL(main_chan), SPICE_MSG_MAIN_AGENT_CONNECTED);
+        red_channel_pipes_add_empty_msg(channel, SPICE_MSG_MAIN_AGENT_CONNECTED);
     }
 }
 
@@ -346,15 +345,16 @@ static void
 main_channel_constructed(GObject *object)
 {
     MainChannel *self = MAIN_CHANNEL(object);
+    RedChannel *channel = RED_CHANNEL(self);
     ClientCbs client_cbs = { NULL, };
 
     G_OBJECT_CLASS(main_channel_parent_class)->constructed(object);
 
-    red_channel_set_cap(RED_CHANNEL(self), SPICE_MAIN_CAP_SEMI_SEAMLESS_MIGRATE);
-    red_channel_set_cap(RED_CHANNEL(self), SPICE_MAIN_CAP_SEAMLESS_MIGRATE);
+    red_channel_set_cap(channel, SPICE_MAIN_CAP_SEMI_SEAMLESS_MIGRATE);
+    red_channel_set_cap(channel, SPICE_MAIN_CAP_SEAMLESS_MIGRATE);
 
     client_cbs.migrate = main_channel_client_migrate;
-    red_channel_register_client_cbs(RED_CHANNEL(self), &client_cbs, NULL);
+    red_channel_register_client_cbs(channel, &client_cbs, NULL);
 }
 
 static void
diff --git a/server/smartcard.c b/server/smartcard.c
index 53919c0..29e4849 100644
--- a/server/smartcard.c
+++ b/server/smartcard.c
@@ -571,15 +571,16 @@ static void
 red_smartcard_channel_constructed(GObject *object)
 {
     RedSmartcardChannel *self = RED_SMARTCARD_CHANNEL(object);
-    RedsState *reds = red_channel_get_server(RED_CHANNEL(self));
+    RedChannel *channel = RED_CHANNEL(self);
+    RedsState *reds = red_channel_get_server(channel);
     ClientCbs client_cbs = { NULL, };
 
     G_OBJECT_CLASS(red_smartcard_channel_parent_class)->constructed(object);
 
     client_cbs.connect = smartcard_connect_client;
-    red_channel_register_client_cbs(RED_CHANNEL(self), &client_cbs, NULL);
+    red_channel_register_client_cbs(channel, &client_cbs, NULL);
 
-    reds_register_channel(reds, RED_CHANNEL(self));
+    reds_register_channel(reds, channel);
 }
 
 static void
diff --git a/server/spicevmc.c b/server/spicevmc.c
index 532598d..a815bb6 100644
--- a/server/spicevmc.c
+++ b/server/spicevmc.c
@@ -186,21 +186,22 @@ static void
 red_vmc_channel_constructed(GObject *object)
 {
     RedVmcChannel *self = RED_VMC_CHANNEL(object);
+    RedChannel *channel = RED_CHANNEL(self);
     ClientCbs client_cbs = { NULL, };
-    RedsState *reds = red_channel_get_server(RED_CHANNEL(self));
+    RedsState *reds = red_channel_get_server(channel);
 
     G_OBJECT_CLASS(red_vmc_channel_parent_class)->constructed(object);
 
     client_cbs.connect = spicevmc_connect;
-    red_channel_register_client_cbs(RED_CHANNEL(self), &client_cbs, NULL);
+    red_channel_register_client_cbs(channel, &client_cbs, NULL);
 
 #ifdef USE_LZ4
-    red_channel_set_cap(RED_CHANNEL(self), SPICE_SPICEVMC_CAP_DATA_COMPRESS_LZ4);
+    red_channel_set_cap(channel, SPICE_SPICEVMC_CAP_DATA_COMPRESS_LZ4);
 #endif
 
-    red_channel_init_outgoing_messages_window(RED_CHANNEL(self));
+    red_channel_init_outgoing_messages_window(channel);
 
-    reds_register_channel(reds, RED_CHANNEL(self));
+    reds_register_channel(reds, channel);
 }
 
 static void
-- 
2.7.4



More information about the Spice-devel mailing list