[Spice-devel] [spice-gtk 1/3] Use macro to swap data in spice_session_start_migrating()
Christophe Fergeau
cfergeau at redhat.com
Thu Jan 29 02:28:38 PST 2015
spice_session_start_migrating() swaps connection details between 2
SpiceSession instances. Instead of doing it manually, use a macro to do
it for us.
---
gtk/spice-session.c | 30 ++++++++++++++----------------
1 file changed, 14 insertions(+), 16 deletions(-)
diff --git a/gtk/spice-session.c b/gtk/spice-session.c
index 50ad291..7f15d98 100644
--- a/gtk/spice-session.c
+++ b/gtk/spice-session.c
@@ -1559,6 +1559,15 @@ void spice_session_switching_disconnect(SpiceSession *self)
cache_clear_all(self);
}
+#define SWAP_STR(x, y) G_STMT_START { \
+ const gchar *tmp; \
+ const gchar *a = x; \
+ const gchar *b = y; \
+ tmp = a; \
+ a = b; \
+ b = tmp; \
+} G_STMT_END
+
G_GNUC_INTERNAL
void spice_session_start_migrating(SpiceSession *session,
gboolean full_migration)
@@ -1567,7 +1576,6 @@ void spice_session_start_migrating(SpiceSession *session,
SpiceSessionPrivate *s = session->priv;
SpiceSessionPrivate *m;
- gchar *tmp;
g_return_if_fail(s->migration != NULL);
m = s->migration->priv;
@@ -1578,21 +1586,10 @@ void spice_session_start_migrating(SpiceSession *session,
spice_session_set_migration_state(session, SPICE_SESSION_MIGRATION_MIGRATING);
/* swapping connection details happens after MIGRATION_CONNECTING state */
- tmp = s->host;
- s->host = m->host;
- m->host = tmp;
-
- tmp = s->port;
- s->port = m->port;
- m->port = tmp;
-
- tmp = s->tls_port;
- s->tls_port = m->tls_port;
- m->tls_port = tmp;
-
- tmp = s->unix_path;
- s->unix_path = m->unix_path;
- m->unix_path = tmp;
+ SWAP_STR(s->host, m->host);
+ SWAP_STR(s->port, m->port);
+ SWAP_STR(s->tls_port, m->tls_port);
+ SWAP_STR(s->unix_path, m->unix_path);
g_warn_if_fail(ring_get_length(&s->channels) == ring_get_length(&m->channels));
@@ -1600,6 +1597,7 @@ void spice_session_start_migrating(SpiceSession *session,
ring_get_length(&s->channels), ring_get_length(&m->channels));
s->migration_left = spice_session_get_channels(session);
}
+#undef SWAP_STR
G_GNUC_INTERNAL
SpiceChannel* spice_session_lookup_channel(SpiceSession *session, gint id, gint type)
--
2.1.0
More information about the Spice-devel
mailing list