[Spice-devel] [spice-gtk 12/13] channel: add spice_channel_get_error()
Marc-André Lureau
marcandre.lureau at gmail.com
Mon Feb 3 10:02:43 PST 2014
From: Marc-André Lureau <marcandre.lureau at redhat.com>
Add a function to retrieve the last GError from a channel, this may be
useful to provide additional error details to the client.
---
doc/reference/spice-gtk-sections.txt | 1 +
gtk/map-file | 1 +
gtk/spice-channel-priv.h | 1 +
gtk/spice-channel.c | 26 ++++++++++++++++++++++++--
gtk/spice-channel.h | 2 ++
gtk/spice-glib-sym-file | 1 +
gtk/spice-session-priv.h | 2 +-
gtk/spice-session.c | 6 +++---
gtk/spicy.c | 6 ++++++
9 files changed, 40 insertions(+), 6 deletions(-)
diff --git a/doc/reference/spice-gtk-sections.txt b/doc/reference/spice-gtk-sections.txt
index 411ca0e..9f0cf67 100644
--- a/doc/reference/spice-gtk-sections.txt
+++ b/doc/reference/spice-gtk-sections.txt
@@ -102,6 +102,7 @@ spice_channel_string_to_type
spice_channel_set_capability
spice_channel_flush_async
spice_channel_flush_finish
+spice_channel_get_error
<SUBSECTION Standard>
SPICE_TYPE_CHANNEL_EVENT
spice_channel_event_get_type
diff --git a/gtk/map-file b/gtk/map-file
index cf65db0..d9e596b 100644
--- a/gtk/map-file
+++ b/gtk/map-file
@@ -7,6 +7,7 @@ spice_channel_connect;
spice_channel_destroy;
spice_channel_disconnect;
spice_channel_event_get_type;
+spice_channel_get_error;
spice_channel_get_type;
spice_channel_new;
spice_channel_open_fd;
diff --git a/gtk/spice-channel-priv.h b/gtk/spice-channel-priv.h
index fd08b2a..591f80e 100644
--- a/gtk/spice-channel-priv.h
+++ b/gtk/spice-channel-priv.h
@@ -136,6 +136,7 @@ struct _SpiceChannelPrivate {
GSList *flushing;
gboolean disable_channel_msg;
+ GError *error;
};
SpiceMsgIn *spice_msg_in_new(SpiceChannel *channel);
diff --git a/gtk/spice-channel.c b/gtk/spice-channel.c
index 87bc471..e8391be 100644
--- a/gtk/spice-channel.c
+++ b/gtk/spice-channel.c
@@ -154,6 +154,8 @@ static void spice_channel_dispose(GObject *gobject)
c->session = NULL;
}
+ g_clear_error(&c->error);
+
/* Chain up to the parent class */
if (G_OBJECT_CLASS(spice_channel_parent_class)->dispose)
G_OBJECT_CLASS(spice_channel_parent_class)->dispose(gobject);
@@ -2211,6 +2213,25 @@ static int spice_channel_load_ca(SpiceChannel *channel)
return count;
}
+/**
+ * spice_channel_get_error:
+ * @channel:
+ *
+ * Retrieves the #GError currently set on channel, if the #SpiceChannel
+ * is in error state.
+ *
+ * Returns: the pointer to the error, or NULL
+ * Since: 0.23
+ **/
+const GError* spice_channel_get_error(SpiceChannel *self)
+{
+ SpiceChannelPrivate *c;
+
+ g_return_val_if_fail(SPICE_IS_CHANNEL(self), NULL);
+ c = self->priv;
+
+ return c->error;
+}
/* coroutine context */
static void *spice_channel_coroutine(void *data)
@@ -2248,15 +2269,16 @@ static void *spice_channel_coroutine(void *data)
reconnect:
- c->conn = spice_session_channel_open_host(c->session, channel, &c->tls);
+ c->conn = spice_session_channel_open_host(c->session, channel, &c->tls, &c->error);
if (c->conn == NULL) {
- if (!c->tls) {
+ if (!c->error && !c->tls) {
CHANNEL_DEBUG(channel, "trying with TLS port");
c->tls = true; /* FIXME: does that really work with provided fd */
goto reconnect;
} else {
CHANNEL_DEBUG(channel, "Connect error");
emit_main_context(channel, SPICE_CHANNEL_EVENT, SPICE_CHANNEL_ERROR_CONNECT);
+ g_clear_error(&c->error);
goto cleanup;
}
}
diff --git a/gtk/spice-channel.h b/gtk/spice-channel.h
index 705dddf..1c303b4 100644
--- a/gtk/spice-channel.h
+++ b/gtk/spice-channel.h
@@ -123,6 +123,8 @@ void spice_channel_set_capability(SpiceChannel *channel, guint32 cap);
const gchar* spice_channel_type_to_string(gint type);
gint spice_channel_string_to_type(const gchar *str);
+const GError* spice_channel_get_error(SpiceChannel *channel);
+
G_END_DECLS
#endif /* __SPICE_CLIENT_CHANNEL_H__ */
diff --git a/gtk/spice-glib-sym-file b/gtk/spice-glib-sym-file
index ac7e871..b90736b 100644
--- a/gtk/spice-glib-sym-file
+++ b/gtk/spice-glib-sym-file
@@ -7,6 +7,7 @@ spice_channel_disconnect
spice_channel_event_get_type
spice_channel_flush_async
spice_channel_flush_finish
+spice_channel_get_error
spice_channel_get_type
spice_channel_new
spice_channel_open_fd
diff --git a/gtk/spice-session-priv.h b/gtk/spice-session-priv.h
index 0dc2bfb..1aae342 100644
--- a/gtk/spice-session-priv.h
+++ b/gtk/spice-session-priv.h
@@ -116,7 +116,7 @@ int spice_session_get_connection_id(SpiceSession *session);
gboolean spice_session_get_client_provided_socket(SpiceSession *session);
GSocketConnection* spice_session_channel_open_host(SpiceSession *session, SpiceChannel *channel,
- gboolean *use_tls);
+ gboolean *use_tls, GError **error);
void spice_session_channel_new(SpiceSession *session, SpiceChannel *channel);
void spice_session_channel_destroy(SpiceSession *session, SpiceChannel *channel);
void spice_session_channel_migrate(SpiceSession *session, SpiceChannel *channel);
diff --git a/gtk/spice-session.c b/gtk/spice-session.c
index e229c64..96f73f5 100644
--- a/gtk/spice-session.c
+++ b/gtk/spice-session.c
@@ -1795,7 +1795,7 @@ static gboolean connect_timeout(gpointer data)
/* coroutine context */
G_GNUC_INTERNAL
GSocketConnection* spice_session_channel_open_host(SpiceSession *session, SpiceChannel *channel,
- gboolean *use_tls)
+ gboolean *use_tls, GError **error)
{
SpiceSessionPrivate *s = SPICE_SESSION_GET_PRIVATE(session);
SpiceChannelPrivate *c = channel->priv;
@@ -1845,8 +1845,8 @@ GSocketConnection* spice_session_channel_open_host(SpiceSession *session, SpiceC
#endif
if (open_host.error != NULL) {
- g_warning("open host: %s", open_host.error->message);
- g_clear_error(&open_host.error);
+ SPICE_DEBUG("open host: %s", open_host.error->message);
+ g_propagate_error(error, open_host.error);
} else if (open_host.connection != NULL) {
GSocket *socket;
socket = g_socket_connection_get_socket(open_host.connection);
diff --git a/gtk/spicy.c b/gtk/spicy.c
index dff9d44..89b0627 100644
--- a/gtk/spicy.c
+++ b/gtk/spicy.c
@@ -1208,6 +1208,7 @@ static void recent_add(SpiceSession *session)
static void main_channel_event(SpiceChannel *channel, SpiceChannelEvent event,
gpointer data)
{
+ const GError *error = NULL;
spice_connection *conn = data;
char password[64];
int rc;
@@ -1231,7 +1232,12 @@ static void main_channel_event(SpiceChannel *channel, SpiceChannelEvent event,
case SPICE_CHANNEL_ERROR_TLS:
case SPICE_CHANNEL_ERROR_LINK:
case SPICE_CHANNEL_ERROR_CONNECT:
+ error = spice_channel_get_error(channel);
g_message("main channel: failed to connect");
+ if (error) {
+ g_message("channel error: %s", error->message);
+ }
+
rc = connect_dialog(conn->session);
if (rc == 0) {
connection_connect(conn);
--
1.8.4.2
More information about the Spice-devel
mailing list