[Spice-devel] [RFCv5 11/47] server/main_channel+reds: make main_channel_init return MainChannelClient

Alon Levy alevy at redhat.com
Sun May 8 06:11:07 PDT 2011


This makes it easier to introduce RedClient in the next patch.
---
 server/main_channel.c |   27 +++++++++++++--------------
 server/main_channel.h |    7 ++++---
 server/reds.c         |   11 ++++++-----
 3 files changed, 23 insertions(+), 22 deletions(-)

diff --git a/server/main_channel.c b/server/main_channel.c
index a5e6e6d..a7fca14 100644
--- a/server/main_channel.c
+++ b/server/main_channel.c
@@ -149,16 +149,14 @@ static void main_disconnect(MainChannel *main_chan)
 
 static int main_channel_client_push_ping(RedChannelClient *rcc, int size);
 
-void main_channel_start_net_test(RedChannelClient *rcc)
+void main_channel_start_net_test(MainChannelClient *mcc)
 {
-    MainChannelClient *mcc = SPICE_CONTAINEROF(rcc, MainChannelClient, base);
-
-    if (!rcc) {
+    if (!mcc) {
         return;
     }
-    if (main_channel_client_push_ping(rcc, NET_TEST_WARMUP_BYTES)
-        && main_channel_client_push_ping(rcc, 0)
-        && main_channel_client_push_ping(rcc, NET_TEST_BYTES)) {
+    if (main_channel_client_push_ping(&mcc->base, NET_TEST_WARMUP_BYTES)
+        && main_channel_client_push_ping(&mcc->base, 0)
+        && main_channel_client_push_ping(&mcc->base, NET_TEST_BYTES)) {
         mcc->net_test_id = mcc->ping_id - 2;
         mcc->net_test_stage = NET_TEST_STAGE_WARMUP;
     }
@@ -461,17 +459,17 @@ static uint64_t main_channel_handle_migrate_data(RedChannelClient *rcc,
     return TRUE;
 }
 
-void main_channel_push_init(RedChannelClient *rcc, int connection_id,
+void main_channel_push_init(MainChannelClient *mcc, int connection_id,
     int display_channels_hint, int current_mouse_mode,
     int is_client_mouse_allowed, int multi_media_time,
     int ram_hint)
 {
     InitPipeItem *item;
 
-    item = main_init_item_new(rcc,
+    item = main_init_item_new(&mcc->base,
              connection_id, display_channels_hint, current_mouse_mode,
              is_client_mouse_allowed, multi_media_time, ram_hint);
-    red_channel_client_pipe_add_push(rcc, &item->base);
+    red_channel_client_pipe_add_push(&mcc->base, &item->base);
 }
 
 static void main_channel_marshall_init(SpiceMarshaller *m,
@@ -821,12 +819,12 @@ static int main_channel_handle_migrate_flush_mark(RedChannelClient *rcc)
     return TRUE;
 }
 
-RedChannelClient *main_channel_link(Channel *channel, RedsStream *stream, int migration,
+MainChannelClient *main_channel_link(Channel *channel, RedsStream *stream, int migration,
                         int num_common_caps, uint32_t *common_caps, int num_caps,
                         uint32_t *caps)
 {
     MainChannel *main_chan;
-    RedChannelClient *rcc;
+    MainChannelClient *mcc;
 
     ASSERT(channel->data == NULL);
     if (channel->data == NULL) {
@@ -850,8 +848,9 @@ RedChannelClient *main_channel_link(Channel *channel, RedsStream *stream, int mi
     }
     main_chan = (MainChannel*)channel->data;
     red_printf("add main channel client");
-    rcc = red_channel_client_create(sizeof(MainChannelClient), &main_chan->base, stream);
-    return rcc;
+    mcc = (MainChannelClient*)
+            red_channel_client_create(sizeof(MainChannelClient), &main_chan->base, stream);
+    return mcc;
 }
 
 int main_channel_getsockname(MainChannel *main_chan, struct sockaddr *sa, socklen_t *salen)
diff --git a/server/main_channel.h b/server/main_channel.h
index 31da720..f715b43 100644
--- a/server/main_channel.h
+++ b/server/main_channel.h
@@ -45,10 +45,11 @@ struct MainMigrateData {
 };
 
 typedef struct MainChannel MainChannel;
+typedef struct MainChannelClient MainChannelClient;
 
 Channel *main_channel_init(void);
 /* This is a 'clone' from the reds.h Channel.link callback */
-RedChannelClient *main_channel_link(struct Channel *,
+MainChannelClient *main_channel_link(struct Channel *,
                  RedsStream *stream, int migration, int num_common_caps,
                  uint32_t *common_caps, int num_caps, uint32_t *caps);
 void main_channel_close(MainChannel *main_chan); // not destroy, just socket close
@@ -59,10 +60,10 @@ void main_channel_push_agent_disconnected(MainChannel *main_chan);
 void main_channel_push_tokens(MainChannel *main_chan, uint32_t num_tokens);
 void main_channel_push_agent_data(MainChannel *main_chan, uint8_t* data, size_t len,
            spice_marshaller_item_free_func free_data, void *opaque);
-void main_channel_start_net_test(RedChannelClient *rcc);
+void main_channel_start_net_test(MainChannelClient *mcc);
 // TODO: huge. Consider making a reds_* interface for these functions
 // and calling from main.
-void main_channel_push_init(RedChannelClient *rcc, int connection_id, int display_channels_hint,
+void main_channel_push_init(MainChannelClient *mcc, int connection_id, int display_channels_hint,
     int current_mouse_mode, int is_client_mouse_allowed, int multi_media_time,
     int ram_hint);
 void main_channel_push_notify(MainChannel *main_chan, uint8_t *mess, const int mess_len);
diff --git a/server/reds.c b/server/reds.c
index eb60e51..9e3133e 100644
--- a/server/reds.c
+++ b/server/reds.c
@@ -1522,7 +1522,7 @@ static void reds_handle_main_link(RedLinkInfo *link)
     SpiceLinkMess *link_mess;
     uint32_t *caps;
     uint32_t connection_id;
-    RedChannelClient *rcc;
+    MainChannelClient *mcc;
 
     red_printf("");
     link_mess = link->link_mess;
@@ -1560,12 +1560,13 @@ static void reds_handle_main_link(RedLinkInfo *link)
     if (!reds->main_channel_factory) {
         reds->main_channel_factory = main_channel_init();
     }
-    rcc = main_channel_link(reds->main_channel_factory,
+    mcc = main_channel_link(reds->main_channel_factory,
                   stream, reds->mig_target, link_mess->num_common_caps,
                   link_mess->num_common_caps ? caps : NULL, link_mess->num_channel_caps,
                   link_mess->num_channel_caps ? caps + link_mess->num_common_caps : NULL);
+    reds->main_channel = (MainChannel*)reds->main_channel_factory->data;
+    ASSERT(reds->main_channel);
     free(link_mess);
-    reds->main_channel = (MainChannel*)rcc->channel;
 
     if (vdagent) {
         SpiceCharDeviceInterface *sif;
@@ -1580,12 +1581,12 @@ static void reds_handle_main_link(RedLinkInfo *link)
 
     if (!reds->mig_target) {
         reds->agent_state.num_client_tokens = REDS_AGENT_WINDOW_SIZE;
-        main_channel_push_init(rcc, connection_id, red_dispatcher_count(),
+        main_channel_push_init(mcc, connection_id, red_dispatcher_count(),
             reds->mouse_mode, reds->is_client_mouse_allowed,
             reds_get_mm_time() - MM_TIME_DELTA,
             red_dispatcher_qxl_ram_size());
 
-        main_channel_start_net_test(rcc);
+        main_channel_start_net_test(mcc);
         /* Now that we have a client, forward any pending agent data */
         while (read_from_vdi_port());
     }
-- 
1.7.5.1



More information about the Spice-devel mailing list