[virt-tools-list] [PATCH virt-viewer] app: Factor out common code

Christophe Fergeau cfergeau at redhat.com
Wed Oct 5 12:37:49 UTC 2016


Hey,

On Wed, Oct 05, 2016 at 11:29:18AM +0200, Pavel Grunt wrote:
> ---
>  src/virt-viewer-app.c | 14 ++++++--------
>  1 file changed, 6 insertions(+), 8 deletions(-)
> 
> diff --git a/src/virt-viewer-app.c b/src/virt-viewer-app.c
> index e8412ac..ee3800b 100644
> --- a/src/virt-viewer-app.c
> +++ b/src/virt-viewer-app.c
> @@ -1032,21 +1032,16 @@ virt_viewer_app_create_session(VirtViewerApp *self, const gchar *type, GError **
>      VirtViewerAppPrivate *priv = self->priv;
>      g_return_val_if_fail(priv->session == NULL, FALSE);
>      g_return_val_if_fail(type != NULL, FALSE);
> +    VirtViewerSession *(*session_new_f)(VirtViewerApp *, GtkWindow *);
>  
>  #ifdef HAVE_GTK_VNC
>      if (g_ascii_strcasecmp(type, "vnc") == 0) {
> -        GtkWindow *window = virt_viewer_window_get_window(priv->main_window);
> -        virt_viewer_app_trace(self, "Guest %s has a %s display",
> -                              priv->guest_name, type);
> -        priv->session = virt_viewer_session_vnc_new(self, window);
> +        session_new_f = virt_viewer_session_vnc_new;
>      } else
>  #endif
>  #ifdef HAVE_SPICE_GTK
>      if (g_ascii_strcasecmp(type, "spice") == 0) {
> -        GtkWindow *window = virt_viewer_window_get_window(priv->main_window);
> -        virt_viewer_app_trace(self, "Guest %s has a %s display",
> -                              priv->guest_name, type);
> -        priv->session = virt_viewer_session_spice_new(self, window);
> +        session_new_f = virt_viewer_session_spice_new;
>      } else
>  #endif
>      {
> @@ -1059,6 +1054,9 @@ virt_viewer_app_create_session(VirtViewerApp *self, const gchar *type, GError **
>          return FALSE;
>      }
>  
> +    virt_viewer_app_trace(self, "Guest %s has a %s display", priv->guest_name, type);
> +    priv->session = session_new_f(self, virt_viewer_window_get_window(priv->main_window));
> +

Introducing a function pointer just to save a few lines of trivial code
seems overkill to me.. Feel free to move the virt_viewer_app_trace()
call if you want, but I'd keep the rest as is.

Christophe
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 801 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/virt-tools-list/attachments/20161005/0f5e48ac/attachment.sig>


More information about the virt-tools-list mailing list