Use macro to swap data in spice_session_start_migrating()

spice_session_start_migrating() swaps connection details between 2
SpiceSession instances. Instead of doing it manually, use a macro to do
it for us.
This commit is contained in:
Christophe Fergeau 2015-01-27 18:26:12 +01:00
parent 6e86378ec9
commit 01c63439ca

View File

@ -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)