Re: [PATCH v2] Introduce vnc_util_get_version() functions to get version
- From: "Daniel P. Berrange" <dan berrange com>
- To: Michal Novotny <minovotn redhat com>
- Cc: gtk-vnc-list gnome org
- Subject: Re: [PATCH v2] Introduce vnc_util_get_version() functions to get version
- Date: Wed, 20 Oct 2010 18:46:16 +0100
On Thu, Sep 30, 2010 at 03:48:29PM +0200, Michal Novotny wrote:
> diff --git a/src/libgvnc_sym.version b/src/libgvnc_sym.version
> index 8f0ea44..2c0ade8 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..3fe86f7 100644
> --- a/src/vncutil.c
> +++ b/src/vncutil.c
> @@ -35,6 +35,44 @@ gboolean vnc_util_get_debug(void)
> return debugFlag;
> }
>
> +gint vnc_util_get_version(void)
> +{
> + gchar **str;
> + gint ret;
> + gint i;
> +
> + ret = 0;
> + str = g_strsplit(VERSION, ".", 3);
> + for (i = 0; i < 3; i++)
> + ret |= g_ascii_strtoll(str[i], NULL, 10) << ( 32 - (8 * (i + 1) ) );
> + g_strfreev(str);
> +
> + return ret;
> +}
Splitting strings & ascii->int conversion really doesn't
need to be done at runtime here. VERSION never changes
so it can be setup at compile time. eg so it just does
return (VERSION_MAJOR << 16) |
(VERSION_MINOR << 8) |
VERSION_MICRO;
The libvirt configure.ac script has some code for splitting
VERSION into its 3 parts that can be used for this purpose.
> +gboolean vnc_util_check_version(gint major, gint minor, gint micro)
> +{
> + gint version;
> + gint vermajor;
> + gint verminor;
> + gint vermicro;
> +
> + version = vnc_util_get_version();
> + vermajor = (version >> 24) & 0xff;
> + verminor = (version >> 16) & 0xff;
> + vermicro = (version >> 8 ) & 0xff;
This could just be replaced with VERSION_{MAJOR,MINOR,MICRO}
constants set at compile time.
> +
> + return ((vermajor > major) || \
> + ((vermajor == major) && (verminor > minor)) || \
> + ((vermajor == major) && (verminor == minor) && \
> + (vermicro >= micro)));
> +}
> +
> +const gchar *vnc_util_get_version_string(void)
> +{
> + return VERSION;
> +}
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]