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



Hi,
this is the second version of the patch 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 (this 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.
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.
Also, it's being used internally by vnc_util_check_version() too.

Michal

Signed-off-by: Michal Novotny <minovotn redhat com>

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

>From f0443133461d4689191c5bb88beffc54273e3ea6 Mon Sep 17 00:00:00 2001
From: Michal Novotny <minovotn redhat com>
Date: Thu, 30 Sep 2010 15:22:13 +0200
Subject: [PATCH v2] Introduce vnc_util_get_version() functions to get version

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 (this 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.
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.
Also, it's being used internally by vnc_util_check_version() too.

Michal

Signed-off-by: Michal Novotny <minovotn redhat com>
---
 examples/gvncviewer.c   |    7 ++++++-
 src/libgvnc_sym.version |    3 +++
 src/vncutil.c           |   38 ++++++++++++++++++++++++++++++++++++++
 src/vncutil.h           |    3 +++
 4 files changed, 50 insertions(+), 1 deletions(-)

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..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_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;
+}
+
+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;
+
+	return ((vermajor > major) || \
+		((vermajor == major) && (verminor > minor)) || \
+		((vermajor == major) && (verminor == minor) && \
+		(vermicro >= 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 {								\
-- 
1.7.2.3



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