[virt-tools-list] [PATCH virt-viewer 3/9] Move libvirt reconnect polling to VirtViewer

Christophe Fergeau cfergeau at redhat.com
Fri Nov 14 10:54:54 UTC 2014


ACK.

Christophe

On Thu, Nov 13, 2014 at 06:20:39PM +0100, Marc-André Lureau wrote:
> This is libvirt specific, no need to share it in the VirtViewerApp base
> class.
> ---
>  src/virt-viewer-app.c | 35 -----------------------------------
>  src/virt-viewer-app.h |  1 -
>  src/virt-viewer.c     | 41 +++++++++++++++++++++++++++++++++++++----
>  3 files changed, 37 insertions(+), 40 deletions(-)
> 
> diff --git a/src/virt-viewer-app.c b/src/virt-viewer-app.c
> index 262d75e..e2d9636 100644
> --- a/src/virt-viewer-app.c
> +++ b/src/virt-viewer-app.c
> @@ -127,7 +127,6 @@ struct _VirtViewerAppPrivate {
>      gboolean active;
>      gboolean connected;
>      gboolean cancelled;
> -    guint reconnect_poll; /* source id */
>      char *unixsock;
>      char *guri; /* prefered over ghost:gport */
>      char *ghost;
> @@ -1322,40 +1321,6 @@ virt_viewer_app_retryauth(gpointer opaque)
>      return FALSE;
>  }
>  
> -static gboolean
> -virt_viewer_app_connect_timer(void *opaque)
> -{
> -    VirtViewerApp *self = opaque;
> -    VirtViewerAppPrivate *priv = self->priv;
> -
> -    g_debug("Connect timer fired");
> -
> -    if (!priv->active &&
> -        virt_viewer_app_initial_connect(self, NULL) < 0)
> -        gtk_main_quit();
> -
> -    if (priv->active) {
> -        priv->reconnect_poll = 0;
> -        return FALSE;
> -    }
> -
> -    return TRUE;
> -}
> -
> -void
> -virt_viewer_app_start_reconnect_poll(VirtViewerApp *self)
> -{
> -    g_return_if_fail(VIRT_VIEWER_IS_APP(self));
> -    VirtViewerAppPrivate *priv = self->priv;
> -
> -    g_debug("reconnect_poll: %d", priv->reconnect_poll);
> -
> -    if (priv->reconnect_poll != 0)
> -        return;
> -
> -    priv->reconnect_poll = g_timeout_add(500, virt_viewer_app_connect_timer, self);
> -}
> -
>  static void
>  virt_viewer_app_default_deactivated(VirtViewerApp *self, gboolean connect_error)
>  {
> diff --git a/src/virt-viewer-app.h b/src/virt-viewer-app.h
> index b68e50c..f127b32 100644
> --- a/src/virt-viewer-app.h
> +++ b/src/virt-viewer-app.h
> @@ -71,7 +71,6 @@ void virt_viewer_app_free_connect_info(VirtViewerApp *self);
>  int virt_viewer_app_create_session(VirtViewerApp *self, const gchar *type);
>  gboolean virt_viewer_app_activate(VirtViewerApp *self, GError **error);
>  gboolean virt_viewer_app_initial_connect(VirtViewerApp *self, GError **error);
> -void virt_viewer_app_start_reconnect_poll(VirtViewerApp *self);
>  void virt_viewer_app_set_zoom_level(VirtViewerApp *self, gint zoom_level);
>  gboolean virt_viewer_app_get_direct(VirtViewerApp *self);
>  void virt_viewer_app_set_direct(VirtViewerApp *self, gboolean direct);
> diff --git a/src/virt-viewer.c b/src/virt-viewer.c
> index dc16b3f..19aa6ed 100644
> --- a/src/virt-viewer.c
> +++ b/src/virt-viewer.c
> @@ -59,6 +59,7 @@ struct _VirtViewerPrivate {
>      gboolean waitvm;
>      gboolean reconnect;
>      gboolean auth_cancelled;
> +    guint reconnect_poll; /* source id */
>  };
>  
>  G_DEFINE_TYPE (VirtViewer, virt_viewer, VIRT_VIEWER_TYPE_APP)
> @@ -115,6 +116,39 @@ virt_viewer_init(VirtViewer *self)
>      self->priv = GET_PRIVATE(self);
>  }
>  
> +static gboolean
> +virt_viewer_connect_timer(void *opaque)
> +{
> +    VirtViewer *self = VIRT_VIEWER(opaque);
> +    VirtViewerApp *app = VIRT_VIEWER_APP(self);
> +
> +    g_debug("Connect timer fired");
> +
> +    if (!virt_viewer_app_is_active(app) &&
> +        !virt_viewer_app_initial_connect(app, NULL))
> +        gtk_main_quit();
> +
> +    if (virt_viewer_app_is_active(app)) {
> +        self->priv->reconnect_poll = 0;
> +        return FALSE;
> +    }
> +
> +    return TRUE;
> +}
> +
> +static void
> +virt_viewer_start_reconnect_poll(VirtViewer *self)
> +{
> +    VirtViewerPrivate *priv = self->priv;
> +
> +    g_debug("reconnect_poll: %d", priv->reconnect_poll);
> +
> +    if (priv->reconnect_poll != 0)
> +        return;
> +
> +    priv->reconnect_poll = g_timeout_add(500, virt_viewer_connect_timer, self);
> +}
> +
>  static void
>  virt_viewer_deactivated(VirtViewerApp *app, gboolean connect_error)
>  {
> @@ -129,7 +163,7 @@ virt_viewer_deactivated(VirtViewerApp *app, gboolean connect_error)
>      if (priv->reconnect) {
>          if (!priv->withEvents) {
>              g_debug("No domain events, falling back to polling");
> -            virt_viewer_app_start_reconnect_poll(app);
> +            virt_viewer_start_reconnect_poll(self);
>          }
>  
>          virt_viewer_app_show_status(app, _("Waiting for guest domain to re-start"));
> @@ -512,7 +546,6 @@ virt_viewer_conn_event(virConnectPtr conn G_GNUC_UNUSED,
>                         void *opaque)
>  {
>      VirtViewer *self = opaque;
> -    VirtViewerApp *app = VIRT_VIEWER_APP(self);
>      VirtViewerPrivate *priv = self->priv;
>  
>      g_debug("Got connection event %d", reason);
> @@ -520,7 +553,7 @@ virt_viewer_conn_event(virConnectPtr conn G_GNUC_UNUSED,
>      virConnectClose(priv->conn);
>      priv->conn = NULL;
>  
> -    virt_viewer_app_start_reconnect_poll(app);
> +    virt_viewer_start_reconnect_poll(self);
>  }
>  
>  static void
> @@ -831,7 +864,7 @@ virt_viewer_connect(VirtViewerApp *app)
>      if (!priv->withEvents &&
>          !virt_viewer_app_is_active(app)) {
>          g_debug("No domain events, falling back to polling");
> -        virt_viewer_app_start_reconnect_poll(app);
> +        virt_viewer_start_reconnect_poll(self);
>      }
>  
>      if (virConnectRegisterCloseCallback(priv->conn,
> -- 
> 1.9.3
> 
> _______________________________________________
> virt-tools-list mailing list
> virt-tools-list at redhat.com
> https://www.redhat.com/mailman/listinfo/virt-tools-list
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/virt-tools-list/attachments/20141114/9e5542d6/attachment.sig>


More information about the virt-tools-list mailing list