[Spice-devel] [spice-gtk 12/13] channel: add spice_channel_get_error()
Christophe Fergeau
cfergeau at redhat.com
Tue Feb 11 09:47:13 PST 2014
On Mon, Feb 03, 2014 at 07:02:43PM +0100, Marc-André Lureau wrote:
> 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);
My understanding of this bit is that spice_channel_get_error() can only be
used in a callback attached to SPICE_CHANNEL_EVENT as after that it will be
cleared? Maybe this needs to be more explicit in the API doc for
spice_channel_get_error().
Christophe
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 181 bytes
Desc: not available
URL: <http://lists.freedesktop.org/archives/spice-devel/attachments/20140211/eed2ee9d/attachment.pgp>
More information about the Spice-devel
mailing list