[Spice-devel] [PATCH 6/7] Add MainChannelPrivate struct

Jonathon Jongsma jjongsma at redhat.com
Tue Oct 11 22:29:02 UTC 2016


Encapsulate MainChannel a bit better in preparation for proting to
GObject.
---
 server/main-channel-client.c | 24 +++++++++++-------------
 server/main-channel.c        | 43 +++++++++++++++++++++++++++++--------------
 server/main-channel.h        | 11 ++++++++---
 3 files changed, 48 insertions(+), 30 deletions(-)

diff --git a/server/main-channel-client.c b/server/main-channel-client.c
index 0913028..28d2839 100644
--- a/server/main-channel-client.c
+++ b/server/main-channel-client.c
@@ -439,11 +439,7 @@ void main_channel_client_handle_migrate_connected(MainChannelClient *mcc,
 
         mcc->priv->mig_wait_connect = FALSE;
         mcc->priv->mig_connect_ok = success;
-        spice_assert(main_channel->num_clients_mig_wait);
-        spice_assert(!seamless || main_channel->num_clients_mig_wait == 1);
-        if (!--main_channel->num_clients_mig_wait) {
-            reds_on_main_migrate_connected(channel->reds, seamless && success);
-        }
+        main_channel_on_migrate_connected(main_channel, seamless && success);
     } else {
         if (success) {
             spice_printerr("client %p MIGRATE_CANCEL", client);
@@ -876,7 +872,7 @@ static void main_channel_marshall_notify(RedChannelClient *rcc,
 static void main_channel_fill_migrate_dst_info(MainChannel *main_channel,
                                                SpiceMigrationDstInfo *dst_info)
 {
-    RedsMigSpice *mig_dst = &main_channel->mig_target;
+    const RedsMigSpice *mig_dst = main_channel_peek_migration_target(main_channel);
     dst_info->port = mig_dst->port;
     dst_info->sport = mig_dst->sport;
     dst_info->host_size = strlen(mig_dst->host) + 1;
@@ -935,17 +931,19 @@ static void main_channel_marshall_migrate_switch(SpiceMarshaller *m, RedChannelC
     RedChannel *channel = red_channel_client_get_channel(rcc);
     SpiceMsgMainMigrationSwitchHost migrate;
     MainChannel *main_ch;
+    const RedsMigSpice *mig_target;
 
     spice_printerr("");
     red_channel_client_init_send_data(rcc, SPICE_MSG_MAIN_MIGRATE_SWITCH_HOST, item);
     main_ch = SPICE_CONTAINEROF(channel, MainChannel, base);
-    migrate.port = main_ch->mig_target.port;
-    migrate.sport = main_ch->mig_target.sport;
-    migrate.host_size = strlen(main_ch->mig_target.host) + 1;
-    migrate.host_data = (uint8_t *)main_ch->mig_target.host;
-    if (main_ch->mig_target.cert_subject) {
-        migrate.cert_subject_size = strlen(main_ch->mig_target.cert_subject) + 1;
-        migrate.cert_subject_data = (uint8_t *)main_ch->mig_target.cert_subject;
+    mig_target = main_channel_peek_migration_target(main_ch);
+    migrate.port = mig_target->port;
+    migrate.sport = mig_target->sport;
+    migrate.host_size = strlen(mig_target->host) + 1;
+    migrate.host_data = (uint8_t *)mig_target->host;
+    if (mig_target->cert_subject) {
+        migrate.cert_subject_size = strlen(mig_target->cert_subject) + 1;
+        migrate.cert_subject_data = (uint8_t *)mig_target->cert_subject;
     } else {
         migrate.cert_subject_size = 0;
         migrate.cert_subject_data = NULL;
diff --git a/server/main-channel.c b/server/main-channel.c
index a1b8e31..2d4b1cd 100644
--- a/server/main-channel.c
+++ b/server/main-channel.c
@@ -134,16 +134,16 @@ void main_channel_push_multi_media_time(MainChannel *main_chan, int time)
 static void main_channel_fill_mig_target(MainChannel *main_channel, RedsMigSpice *mig_target)
 {
     spice_assert(mig_target);
-    free(main_channel->mig_target.host);
-    main_channel->mig_target.host = spice_strdup(mig_target->host);
-    free(main_channel->mig_target.cert_subject);
+    free(main_channel->priv->mig_target.host);
+    main_channel->priv->mig_target.host = spice_strdup(mig_target->host);
+    free(main_channel->priv->mig_target.cert_subject);
     if (mig_target->cert_subject) {
-        main_channel->mig_target.cert_subject = spice_strdup(mig_target->cert_subject);
+        main_channel->priv->mig_target.cert_subject = spice_strdup(mig_target->cert_subject);
     } else {
-        main_channel->mig_target.cert_subject = NULL;
+        main_channel->priv->mig_target.cert_subject = NULL;
     }
-    main_channel->mig_target.port = mig_target->port;
-    main_channel->mig_target.sport = mig_target->sport;
+    main_channel->priv->mig_target.port = mig_target->port;
+    main_channel->priv->mig_target.sport = mig_target->sport;
 }
 
 void main_channel_migrate_switch(MainChannel *main_chan, RedsMigSpice *mig_target)
@@ -231,7 +231,7 @@ static uint8_t *main_channel_alloc_msg_rcv_buf(RedChannelClient *rcc,
     if (type == SPICE_MSGC_MAIN_AGENT_DATA) {
         return reds_get_agent_data_buffer(channel->reds, mcc, size);
     } else {
-        return main_chan->recv_buf;
+        return main_chan->priv->recv_buf;
     }
 }
 
@@ -340,9 +340,9 @@ static int main_channel_connect_semi_seamless(MainChannel *main_channel)
     FOREACH_CLIENT(main_channel, iter, rcc) {
         MainChannelClient *mcc = MAIN_CHANNEL_CLIENT(rcc);
         if (main_channel_client_connect_semi_seamless(mcc))
-            main_channel->num_clients_mig_wait++;
+            main_channel->priv->num_clients_mig_wait++;
     }
-    return main_channel->num_clients_mig_wait;
+    return main_channel->priv->num_clients_mig_wait;
 }
 
 static int main_channel_connect_seamless(MainChannel *main_channel)
@@ -355,16 +355,16 @@ static int main_channel_connect_seamless(MainChannel *main_channel)
     FOREACH_CLIENT(main_channel, iter, rcc) {
         MainChannelClient *mcc = MAIN_CHANNEL_CLIENT(rcc);
         main_channel_client_connect_seamless(mcc);
-        main_channel->num_clients_mig_wait++;
+        main_channel->priv->num_clients_mig_wait++;
     }
-    return main_channel->num_clients_mig_wait;
+    return main_channel->priv->num_clients_mig_wait;
 }
 
 int main_channel_migrate_connect(MainChannel *main_channel, RedsMigSpice *mig_target,
                                  int try_seamless)
 {
     main_channel_fill_mig_target(main_channel, mig_target);
-    main_channel->num_clients_mig_wait = 0;
+    main_channel->priv->num_clients_mig_wait = 0;
 
     if (!main_channel_is_connected(main_channel)) {
         return 0;
@@ -396,7 +396,7 @@ void main_channel_migrate_cancel_wait(MainChannel *main_chan)
         MainChannelClient *mcc = MAIN_CHANNEL_CLIENT(rcc);
         main_channel_client_migrate_cancel_wait(mcc);
     }
-    main_chan->num_clients_mig_wait = 0;
+    main_chan->priv->num_clients_mig_wait = 0;
 }
 
 int main_channel_migrate_src_complete(MainChannel *main_chan, int success)
@@ -419,3 +419,18 @@ int main_channel_migrate_src_complete(MainChannel *main_chan, int success)
    }
    return semi_seamless_count;
 }
+
+void main_channel_on_migrate_connected(MainChannel *main_channel, gboolean seamless)
+{
+        g_return_if_fail(main_channel->priv->num_clients_mig_wait);
+        g_warn_if_fail(!seamless || main_channel->priv->num_clients_mig_wait == 1);
+        if (!--main_channel->priv->num_clients_mig_wait) {
+            reds_on_main_migrate_connected(red_channel_get_server(RED_CHANNEL(main_channel)),
+                                           seamless);
+        }
+}
+
+const RedsMigSpice* main_channel_peek_migration_target(MainChannel *main_chan)
+{
+    return &main_chan->priv->mig_target;
+}
diff --git a/server/main-channel.h b/server/main-channel.h
index e0858d0..20dd710 100644
--- a/server/main-channel.h
+++ b/server/main-channel.h
@@ -44,13 +44,16 @@ struct RedsMigSpice {
 };
 typedef struct RedsMigSpice RedsMigSpice;
 
-typedef struct MainChannel {
-    RedChannel base;
+typedef struct {
     uint8_t recv_buf[MAIN_CHANNEL_RECEIVE_BUF_SIZE];
     RedsMigSpice mig_target; // TODO: add refs and release (afrer all clients completed migration in one way or the other?)
     int num_clients_mig_wait;
-} MainChannel;
+} MainChannelPrivate;
 
+typedef struct MainChannel {
+    RedChannel base;
+    MainChannelPrivate priv[1];
+} MainChannel;
 
 MainChannel *main_channel_new(RedsState *reds);
 RedClient *main_channel_get_client_by_link_id(MainChannel *main_chan, uint32_t link_id);
@@ -78,7 +81,9 @@ void main_channel_migrate_switch(MainChannel *main_chan, RedsMigSpice *mig_targe
 int main_channel_migrate_connect(MainChannel *main_channel, RedsMigSpice *mig_target,
                                  int try_seamless);
 void main_channel_migrate_cancel_wait(MainChannel *main_chan);
+const RedsMigSpice* main_channel_peek_migration_target(MainChannel *main_chan);
 /* returns the number of clients for which SPICE_MSG_MAIN_MIGRATE_END was sent*/
 int main_channel_migrate_src_complete(MainChannel *main_chan, int success);
+void main_channel_on_migrate_connected(MainChannel *main_channel, gboolean seamless);
 
 #endif
-- 
2.7.4



More information about the Spice-devel mailing list