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

Pavel Grunt pgrunt at redhat.com
Wed Oct 5 13:41:07 UTC 2016


On Wed, 2016-10-05 at 14:37 +0200, Christophe Fergeau wrote:
> 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

no problem, I'm dropping the patch

Pavel

> 




More information about the virt-tools-list mailing list