Re: [PATCH v3] Introduce vnc_util_get_version() functions to get version



On Thu, Oct 21, 2010 at 12:17:43PM +0200, Michal Novotny wrote:

> >From d7410d7b71bf71d3bcc431e235646aba6c7b20a3 Mon Sep 17 00:00:00 2001
> From: Michal Novotny <minovotn redhat com>
> Date: Thu, 21 Oct 2010 12:07:19 +0200
> Subject: [PATCH v3] Introduce vnc_util_get_version() functions to get version
> X-Spam-Status: Yes, hits=1.000000 required=0.900000, tests=bmf
> X-Spam-Flag: YES
> 
> Hi,
> this is the patch to allow user to get the GTK-VNC version using the
> vnc_util_get_version() and vnc_util_get_version_string() functions.
> Both the functions returns the version numbers based on the VERSION
> definition as created by autotools. Also, in version 2 (previous
> version) a new function called vnc_util_check_version() has been added
> to check whether the version of gtk-vnc is equal or higher to version
> requested. Function vnc_util_check_version() is defined as:
> 
> gboolean vnc_util_check_version(gint major, gint minor, gint micro);
> 
> The version of gtk-vnc is written in a "major.minor.micro" format
> and since the version number didn't change once the package was
> compiled version 3 is using VERSION_{MAJOR,MINOR,MICRO} constants
> being parsed and set by configure itself rather then parsing it
> at run-time.
> 
> Then there are 2 version functions. The difference between those
> functions is that vnc_util_get_version() returns the gint value
> based on bit flags that have to be converted to get the version
> number in the string format. It's designed for further processing of
> the major, minor and release versions.
> 
> If you want to get the version number only (e.g. to let the user
> know the GTK-VNC version he/she is using) you can use the second
> function called the vnc_util_get_version_string() which returns
> the string representation, e.g. 0.4.1.
> 
> For the vnc_util_get_version() function the gint is being returned
> with setting up appropriate bits. You can get the versions using
> following formula:
> 
> ver = vnc_util_get_version();
> major = (ver >> 24) & 0xff;
> minor = (ver >> 16) & 0xff;
> micro = (ver >> 8 ) & 0xff;
> 
> I think this patch could be useful for mainly for reason mentioned
> above. To check whether the user has at least 0.4.1 version of
> gtk-vnc using the vnc_util_check_version(0, 4, 1) is preferred.
> The vnc_util_get_version() function is a low-level function that
> could be useful to get the version number to be converted further.
> 
> Differences between v2 and v3 (this version):
>  - Since the VERSION constant didn't change once the package has
>    been compiled it's being parsed into VERSION_{MAJOR,MINOR,MICRO}
>    components by configure. No logic has been changed since v2, just
>    the implementation changes.
> 
> Michal
> 
> Signed-off-by: Michal Novotny <minovotn redhat com>
> ---
>  configure.ac            |   11 +++++++++++
>  examples/gvncviewer.c   |    7 ++++++-
>  src/libgvnc_sym.version |    3 +++
>  src/vncutil.c           |   20 ++++++++++++++++++++
>  src/vncutil.h           |    3 +++
>  5 files changed, 43 insertions(+), 1 deletions(-)
> 
> diff --git a/configure.ac b/configure.ac
> index d89c09f..c82393e 100644
> --- a/configure.ac
> +++ b/configure.ac
> @@ -47,6 +47,17 @@ MOZILLA_PLUGIN_REQUIRED=1.8
>  GOBJECT_INTROSPECTION_REQUIRED=0.6.2
>  
>  dnl *******************************************************************************
> +dnl Get the version information at compile-time
> +dnl *******************************************************************************
> +VERSION_MAJOR=`echo $VERSION | awk -F. '{print $1}'`
> +VERSION_MINOR=`echo $VERSION | awk -F. '{print $2}'`
> +VERSION_MICRO=`echo $VERSION | awk -F. '{print $3}'`
> +
> +AC_DEFINE_UNQUOTED(VERSION_MAJOR, $VERSION_MAJOR, [Major version number of package])
> +AC_DEFINE_UNQUOTED(VERSION_MINOR, $VERSION_MINOR, [Minor version number of package])
> +AC_DEFINE_UNQUOTED(VERSION_MICRO, $VERSION_MICRO, [Micro version number of package])
> +
> +dnl *******************************************************************************
>  dnl Setup core compilers / build helpers
>  dnl *******************************************************************************
>  
> diff --git a/examples/gvncviewer.c b/examples/gvncviewer.c
> index 1799e32..ffe7e5b 100644
> --- a/examples/gvncviewer.c
> +++ b/examples/gvncviewer.c
> @@ -19,6 +19,7 @@
>   */
>  
>  #include "vncdisplay.h"
> +#include "vncutil.h"
>  #include <gtk/gtk.h>
>  #include <gdk/gdkkeysyms.h>
>  #include <stdlib.h>
> @@ -495,6 +496,7 @@ static gboolean window_state_event(GtkWidget *widget,
>  
>  int main(int argc, char **argv)
>  {
> +	gchar *name;
>  	GOptionContext *context;
>  	GError *error = NULL;
>  	char port[1024], hostname[1024];
> @@ -519,8 +521,11 @@ int main(int argc, char **argv)
>  	GtkWidget *showgrabkeydlg;
>  	const char *help_msg = "Run 'gvncviewer --help' to see a full list of available command line options";
>  
> +	name = g_strdup_printf("- Simple VNC Client on Gtk-VNC %s",
> +                                 vnc_util_get_version_string());
> +
>  	/* Setup command line options */
> -	context = g_option_context_new ("- Simple VNC Client");
> +	context = g_option_context_new (name);
>  	g_option_context_add_main_entries (context, options, NULL);
>  	g_option_context_add_group (context, gtk_get_option_group (TRUE));
>  	g_option_context_add_group (context, vnc_display_get_option_group ());
> diff --git a/src/libgvnc_sym.version b/src/libgvnc_sym.version
> index 8f0ea44..63ff90f 100644
> --- a/src/libgvnc_sym.version
> +++ b/src/libgvnc_sym.version
> @@ -65,6 +65,9 @@
>  
>  	vnc_util_set_debug;
>  	vnc_util_get_debug;
> +	vnc_util_get_version;
> +	vnc_util_get_version_string;
> +	vnc_util_check_version;
>  
>  	vnc_pixel_format_new;
>  	vnc_pixel_format_copy;
> diff --git a/src/vncutil.c b/src/vncutil.c
> index 04dc8dd..bff8f7f 100644
> --- a/src/vncutil.c
> +++ b/src/vncutil.c
> @@ -35,6 +35,26 @@ gboolean vnc_util_get_debug(void)
>  	return debugFlag;
>  }
>  
> +gint vnc_util_get_version(void)
> +{
> +	return (VERSION_MAJOR << 16) |
> +		(VERSION_MINOR << 8) |
> +		VERSION_MICRO;
> +}
> +
> +gboolean vnc_util_check_version(gint major, gint minor, gint micro)
> +{
> +	return ((VERSION_MAJOR > major) || \
> +		((VERSION_MAJOR == major) && (VERSION_MINOR > minor)) || \
> +		((VERSION_MAJOR == major) && (VERSION_MINOR == minor) && \
> +		(VERSION_MICRO >= micro)));
> +}
> +
> +const gchar *vnc_util_get_version_string(void)
> +{
> +	return VERSION;
> +}
> +
>  /*
>   * Local variables:
>   *  c-indent-level: 8
> diff --git a/src/vncutil.h b/src/vncutil.h
> index 9c96de8..db10d99 100644
> --- a/src/vncutil.h
> +++ b/src/vncutil.h
> @@ -27,6 +27,9 @@ G_BEGIN_DECLS
>  
>  void vnc_util_set_debug(gboolean enabled);
>  gboolean vnc_util_get_debug(void);
> +gint vnc_util_get_version(void);
> +const gchar *vnc_util_get_version_string(void);
> +gboolean vnc_util_check_version(gint major, gint minor, gint micro);
>  
>  #define VNC_DEBUG(fmt, ...)						\
>  	do {								\
> -- 

This looks good now, I'll push it to GIT shortly.

Regards,
Daniel
-- 
|: http://berrange.com      -o-    http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org              -o-             http://virt-manager.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org       -o-       http://live.gnome.org/gtk-vnc :|


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]