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



Thanks for your guidance Daniel, nevertheless I don't know how is it working with libvirt to define those macros so I tried to implement it to configure.ac using the AC_DEFINE_UNQUOTED directives and this way it was working fine for me.

Please review, thanks,
Michal

On 10/20/2010 07:46 PM, Daniel P. Berrange wrote:
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


--
Michal Novotny<minovotn redhat com>, RHCE
Virtualization Team (xen userspace), Red Hat



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