[PATCH] 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.

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, e.g.
it can be useful if the user needs just to check for the minor version
number equal or higher to 4 (i.e. 0.4.0, 0.4.1, 0.4.2 etc.) which
can be used for example to check for some feature support (like
VNC grab keys sequence configuration which is supported since 0.4.1).

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;
release = (ver >> 8) & 0xff;

I think this patch could be useful for mainly for reason mentioned
above.

Michal

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

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

>From decac29970048e07143ff9a2e897394a8f9c4737 Mon Sep 17 00:00:00 2001
From: Michal Novotny <minovotn redhat com>
Date: Thu, 30 Sep 2010 13:43:57 +0200
Subject: [PATCH] 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.

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, e.g.
it can be useful if the user needs just to check for the minor version
number equal or higher to 4 (i.e. 0.4.0, 0.4.1, 0.4.2 etc.) which
can be used for example to check for some feature support (like
VNC grab keys sequence configuration which is supported since 0.4.1).

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;
release = (ver >> 8) & 0xff;

I think this patch could be useful for mainly for reason mentioned
above.

Michal

Signed-off-by: Michal Novotny <minovotn redhat com>
---
 examples/gvncviewer.c   |    7 ++++++-
 src/libgvnc_sym.version |    2 ++
 src/vncutil.c           |   19 +++++++++++++++++++
 src/vncutil.h           |    2 ++
 4 files changed, 29 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..b3faea8 100644
--- a/src/libgvnc_sym.version
+++ b/src/libgvnc_sym.version
@@ -65,6 +65,8 @@
 
 	vnc_util_set_debug;
 	vnc_util_get_debug;
+	vnc_util_get_version;
+	vnc_util_get_version_string;
 
 	vnc_pixel_format_new;
 	vnc_pixel_format_copy;
diff --git a/src/vncutil.c b/src/vncutil.c
index 04dc8dd..7419a9f 100644
--- a/src/vncutil.c
+++ b/src/vncutil.c
@@ -35,6 +35,25 @@ gboolean vnc_util_get_debug(void)
 	return debugFlag;
 }
 
+gint vnc_util_get_version(void)
+{
+	gchar **str;
+	gint i, retVal;
+
+	retVal = 0;
+	str = g_strsplit(VERSION, ".", 3);
+	for (i = 0; i < 3; i++)
+		retVal |= g_ascii_strtoll(str[i], NULL, 10) << ( 32 - (8 * (i + 1)) );
+	g_free(str);
+
+	return retVal;
+}
+
+gchar *vnc_util_get_version_string(void)
+{
+	return g_strdup_printf("%s", VERSION);
+}
+
 /*
  * Local variables:
  *  c-indent-level: 8
diff --git a/src/vncutil.h b/src/vncutil.h
index 9c96de8..106468f 100644
--- a/src/vncutil.h
+++ b/src/vncutil.h
@@ -27,6 +27,8 @@ G_BEGIN_DECLS
 
 void vnc_util_set_debug(gboolean enabled);
 gboolean vnc_util_get_debug(void);
+gint vnc_util_get_version(void);
+gchar *vnc_util_get_version_string(void);
 
 #define VNC_DEBUG(fmt, ...)						\
 	do {								\
-- 
1.7.2.3



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