[tracker/tracker-0.10] libtracker-sparql: Added TRACKER_CHECK_VERSION and tracker_check_version()



commit 61bc9387eb43917ff358ce51ef24989db944f79d
Author: Martyn Russell <martyn lanedo com>
Date:   Thu Mar 31 20:29:41 2011 +0100

    libtracker-sparql: Added TRACKER_CHECK_VERSION and tracker_check_version()
    
    Now, libtracker-sparql includes tracker-version.h and tracker-sparql.h is a
    real non-generated header which includews the generated vala headers.
    
    We need to wrap the generated headers from valac to include checks ensuring
    the generated header is not included directly, but rather the on header
    for the entire library is included instead (tracker-sparql.h)
    
    So now we have -generated-no-checks.h from valac, and all -generated-no-checks.h
    files get converted to -generated.h with the pre-processor additions inserted
    
    Fixes GB#646365, Add macro to check Tracker version

 configure.ac                                       |   11 +++
 docs/reference/libtracker-sparql/Makefile.am       |    4 +-
 .../libtracker-sparql/libtracker-sparql-docs.sgml  |    2 +
 .../libtracker-sparql-sections.txt                 |   17 ++++
 src/libtracker-sparql/.gitignore                   |    2 +-
 src/libtracker-sparql/Makefile.am                  |   25 +++++-
 src/libtracker-sparql/tracker-sparql.h             |   30 ++++++++
 src/libtracker-sparql/tracker-version.c            |   79 ++++++++++++++++++++
 src/libtracker-sparql/tracker-version.h            |   74 ++++++++++++++++++
 9 files changed, 236 insertions(+), 8 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index e0ee828..a453ab4 100644
--- a/configure.ac
+++ b/configure.ac
@@ -64,6 +64,7 @@ TRACKER_BINARY_AGE=tracker_binary_age
 TRACKER_VERSION=tracker_version
 TRACKER_API_VERSION=tracker_api_version
 TRACKER_BINARY_VERSION=tracker_binary_version
+
 AC_SUBST(TRACKER_MAJOR_VERSION)
 AC_SUBST(TRACKER_MINOR_VERSION)
 AC_SUBST(TRACKER_MICRO_VERSION)
@@ -73,6 +74,16 @@ AC_SUBST(TRACKER_API_VERSION)
 AC_SUBST(TRACKER_VERSION)
 AC_SUBST(TRACKER_BINARY_VERSION)
 
+AC_DEFINE(TRACKER_MAJOR_VERSION, [tracker_major_version],
+          [Define to the Tracker major version])
+AC_DEFINE(TRACKER_MINOR_VERSION, [tracker_minor_version],
+          [Define to the Tracker minor version])
+AC_DEFINE(TRACKER_MICRO_VERSION, [tracker_micro_version],
+          [Define to the Tracker micro version])
+AC_DEFINE(TRACKER_INTERFACE_AGE, [tracker_interface_age],
+          [Define to the Tracker interface age])
+AC_DEFINE(TRACKER_BINARY_AGE, [tracker_binary_age],
+          [Define to the Tracker binary age])
 
 # libtool versioning
 LT_RELEASE=tracker_lt_release
diff --git a/docs/reference/libtracker-sparql/Makefile.am b/docs/reference/libtracker-sparql/Makefile.am
index 308ac39..8ff4af7 100644
--- a/docs/reference/libtracker-sparql/Makefile.am
+++ b/docs/reference/libtracker-sparql/Makefile.am
@@ -18,11 +18,11 @@ SCAN_OPTIONS=--deprecated-guards="TRACKER_DISABLE_DEPRECATED"
 DOC_SOURCE_DIR = ../../../src/libtracker-sparql
 
 # Used for dependencies
-HFILE_GLOB = $(top_srcdir)/src/libtracker-sparql/*.h
+HFILE_GLOB = $(top_srcdir)/src/libtracker-sparql/*.h $(top_srcdir)/config.h
 CFILE_GLOB = $(top_srcdir)/src/libtracker-sparql/*.c
 
 # Header files to ignore when scanning
-IGNORE_HFILES =
+IGNORE_HFILES = $(top_srcdir)/src/libtracker-sparql/tracker-generated-no-check.h
 
 # CFLAGS and LDFLAGS for compiling scan program. Only needed
 # if $(DOC_MODULE).types is non-empty.
diff --git a/docs/reference/libtracker-sparql/libtracker-sparql-docs.sgml b/docs/reference/libtracker-sparql/libtracker-sparql-docs.sgml
index 6931dde..ae54dfe 100644
--- a/docs/reference/libtracker-sparql/libtracker-sparql-docs.sgml
+++ b/docs/reference/libtracker-sparql/libtracker-sparql-docs.sgml
@@ -7,6 +7,7 @@
 <!ENTITY tracker-sparql-connection SYSTEM "xml/tracker-sparql-connection.xml">
 <!ENTITY tracker-sparql-cursor SYSTEM "xml/tracker-sparql-cursor.xml">
 <!ENTITY tracker-misc SYSTEM "xml/tracker-misc.xml">
+<!ENTITY tracker-version SYSTEM "xml/tracker-version.xml">
 <!ENTITY tracker-examples SYSTEM "examples.sgml">
 ]>
 <book id="index">
@@ -37,6 +38,7 @@
     &tracker-sparql-connection;
     &tracker-sparql-cursor;
     &tracker-misc;
+    &tracker-version;
   </part>
 
   <!-- The Examples -->
diff --git a/docs/reference/libtracker-sparql/libtracker-sparql-sections.txt b/docs/reference/libtracker-sparql/libtracker-sparql-sections.txt
index daf848d..81c0fdb 100644
--- a/docs/reference/libtracker-sparql/libtracker-sparql-sections.txt
+++ b/docs/reference/libtracker-sparql/libtracker-sparql-sections.txt
@@ -155,3 +155,20 @@ TrackerSparqlCursorPrivate
 tracker_sparql_cursor_construct
 tracker_sparql_cursor_set_connection
 </SECTION>
+
+<SECTION>
+<TITLE>Version Information</TITLE>
+<FILE>tracker-version</FILE>
+tracker_major_version
+tracker_minor_version
+tracker_micro_version
+tracker_binary_age
+tracker_interface_age
+tracker_check_version
+
+<SUBSECTION>
+TRACKER_MAJOR_VERSION
+TRACKER_MINOR_VERSION
+TRACKER_MICRO_VERSION
+TRACKER_CHECK_VERSION
+</SECTION>
diff --git a/src/libtracker-sparql/.gitignore b/src/libtracker-sparql/.gitignore
index 2925c11..1adeb1a 100644
--- a/src/libtracker-sparql/.gitignore
+++ b/src/libtracker-sparql/.gitignore
@@ -6,5 +6,5 @@ tracker-plugin-loader.c
 tracker-query.c
 tracker-sparql-*.deps
 tracker-sparql*.vapi
-tracker-sparql.h
+tracker-generated*.h
 tracker-utils.c
diff --git a/src/libtracker-sparql/Makefile.am b/src/libtracker-sparql/Makefile.am
index 46d0552..62e935f 100644
--- a/src/libtracker-sparql/Makefile.am
+++ b/src/libtracker-sparql/Makefile.am
@@ -6,7 +6,7 @@ AM_VALAFLAGS =                                         \
 	--gir=Tracker-$(TRACKER_API_VERSION).gir \
 	--library Tracker-$(TRACKER_API_VERSION) \
 	--includedir=libtracker-sparql                 \
-	--header tracker-sparql.h                      \
+	--header $(vala_header:.h=-no-checks.h)        \
 	--vapi tracker-sparql-$(TRACKER_API_VERSION).vapi \
 	--pkg gio-2.0 --pkg gmodule-2.0 --pkg posix    \
 	$(BUILD_VALAFLAGS)                             \
@@ -25,14 +25,28 @@ libtracker_sparql_la_SOURCES =   \
 	tracker-connection.vala                        \
 	tracker-cursor.vala                            \
 	tracker-utils.vala                             \
-	tracker-uri.c
+	tracker-uri.c                                  \
+	tracker-version.c
 
 libtracker_sparql_la_LIBADD =    \
 	$(BUILD_LIBS)                                  \
 	$(LIBTRACKER_SPARQL_LIBS)
 
+# Should only be one file
+vala_header = tracker-generated.h
+
+# We wrap the generated .h file with a check to make sure it's
+# not included directly. All other .[ch] headers have this.
+%-generated.h: %-generated-no-checks.h
+	$(AM_V_GEN)(echo "#if !defined (__LIBTRACKER_SPARQL_INSIDE__) && !defined (TRACKER_COMPILATION)" ; \
+	            echo "#error \"only <libtracker-sparql/tracker-sparql.h> must be included directly.\"" ; \
+	            echo "#endif") > $@
+	$(AM_V_GEN)(cat $< >> $@)
+
 libtracker_sparqlinclude_HEADERS =                     \
-	tracker-sparql.h
+	$(vala_header)                                 \
+	tracker-sparql.h                               \
+	tracker-version.h
 
 tracker-sparql-$(TRACKER_API_VERSION).deps: tracker-sparql.deps
 	$(AM_V_GEN)cp $^ $@
@@ -49,12 +63,13 @@ BUILT_SOURCES =                                        \
 MAINTAINERCLEANFILES =                                 \
 	tracker-sparql-$(TRACKER_API_VERSION).vapi     \
 	tracker-sparql-$(TRACKER_API_VERSION).deps     \
-	tracker-sparql.h
+	$(vala_header:.h=-no-checks.h)
 
 EXTRA_DIST =                                           \
 	tracker-sparql-$(TRACKER_API_VERSION).vapi     \
 	tracker-sparql-$(TRACKER_API_VERSION).deps     \
-	tracker-sparql.deps
+	tracker-sparql.deps                            \
+	$(vala_header:.h=-no-checks.h)
 
 # Introspection foo
 -include $(INTROSPECTION_MAKEFILE)
diff --git a/src/libtracker-sparql/tracker-sparql.h b/src/libtracker-sparql/tracker-sparql.h
new file mode 100644
index 0000000..3f72a83
--- /dev/null
+++ b/src/libtracker-sparql/tracker-sparql.h
@@ -0,0 +1,30 @@
+/*
+ * Copyright (C) 2011, Nokia <ivan frade nokia com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA  02110-1301, USA.
+ */
+
+#ifndef __LIBTRACKER_SPARQL_H__
+#define __LIBTRACKER_SPARQL_H__
+
+#define __LIBTRACKER_SPARQL_H_INSIDE__
+
+#include <libtracker-sparql/tracker-version.h>
+#include <libtracker-sparql/tracker-generated.h>
+
+#undef __LIBTRACKER_SPARQL_H_INSIDE__
+
+#endif /* __LIBTRACKER_SPARQL_H__ */
diff --git a/src/libtracker-sparql/tracker-version.c b/src/libtracker-sparql/tracker-version.c
new file mode 100644
index 0000000..3a943a2
--- /dev/null
+++ b/src/libtracker-sparql/tracker-version.c
@@ -0,0 +1,79 @@
+/*
+ * Copyright (C) 2011, Nokia <ivan frade nokia com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA  02110-1301, USA.
+ */
+
+#include "config.h"
+
+#include <glib.h>
+#include <glib/gi18n.h>
+
+#include "tracker-version.h"
+
+const guint tracker_major_version = TRACKER_MAJOR_VERSION;
+const guint tracker_minor_version = TRACKER_MINOR_VERSION;
+const guint tracker_micro_version = TRACKER_MICRO_VERSION;
+const guint tracker_interface_age = TRACKER_INTERFACE_AGE;
+const guint tracker_binary_age = TRACKER_BINARY_AGE;
+
+/**
+ * tracker_check_version:
+ * @required_major: the required major version.
+ * @required_minor: the required minor version.
+ * @required_micro: the required micro version.
+ *
+ * Checks that the Tracker library in use is compatible with the
+ * given version. Generally you would pass in the constants
+ * #TRACKER_MAJOR_VERSION, #TRACKER_MINOR_VERSION, #TRACKER_MICRO_VERSION
+ * as the three arguments to this function; that produces
+ * a check that the library in use is compatible with
+ * the version of Tracker the application or module was compiled
+ * against.
+ *
+ * Compatibility is defined by two things: first the version
+ * of the running library is newer than the version
+ * @required_major required_minor  required_micro  Second
+ * the running library must be binary compatible with the
+ * version @required_major required_minor  required_micro
+ * (same major version.)
+ *
+ * Return value: %NULL if the Tracker library is compatible with the
+ *   given version, or a string describing the version mismatch.
+ *   The returned string is owned by Tracker and must not be modified
+ *   or freed.
+ *
+ * Since: 0.10
+ **/
+const gchar *
+tracker_check_version (guint required_major,
+                       guint required_minor,
+                       guint required_micro)
+{
+	gint tracker_effective_micro = 100 * TRACKER_MINOR_VERSION + TRACKER_MICRO_VERSION;
+	gint required_effective_micro = 100 * required_minor + required_micro;
+
+	if (required_major > TRACKER_MAJOR_VERSION)
+		return "Tracker version too old (major mismatch)";
+	if (required_major < TRACKER_MAJOR_VERSION)
+		return "Tracker version too new (major mismatch)";
+	if (required_effective_micro < tracker_effective_micro - TRACKER_BINARY_AGE)
+		return "Tracker version too new (micro mismatch)";
+	if (required_effective_micro > tracker_effective_micro)
+		return "Tracker version too old (micro mismatch)";
+
+	return NULL;
+}
diff --git a/src/libtracker-sparql/tracker-version.h b/src/libtracker-sparql/tracker-version.h
new file mode 100644
index 0000000..a822423
--- /dev/null
+++ b/src/libtracker-sparql/tracker-version.h
@@ -0,0 +1,74 @@
+/*
+ * Copyright (C) 2006, Jamie McCracken <jamiemcc gnome org>
+ * Copyright (C) 2008, Nokia <ivan frade nokia com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA  02110-1301, USA.
+ */
+
+#ifndef __LIBTRACKER_SPARQL_VERSION_H__
+#define __LIBTRACKER_SPARQL_VERSION_H__
+
+#include <glib.h>
+
+G_BEGIN_DECLS
+
+#if !defined (__LIBTRACKER_SPARQL_INSIDE__) && !defined (TRACKER_COMPILATION)
+#error "only <libtracker-sparql/tracker-sparql.h> must be included directly."
+#endif
+
+GLIB_VAR const guint tracker_major_version;
+GLIB_VAR const guint tracker_minor_version;
+GLIB_VAR const guint tracker_micro_version;
+GLIB_VAR const guint tracker_interface_age;
+GLIB_VAR const guint tracker_binary_age;
+
+/**
+ * TRACKER_CHECK_VERSION:
+ * @major: the required major version.
+ * @minor: the required minor version.
+ * @micro: the required micro version.
+ *
+ * This macro essentially does the same thing as
+ * tracker_check_version() but as a pre-processor operation rather
+ * than a run-time operation. It will evaluate true or false based the
+ * version passed in and the version available.
+ *
+ * <example>
+ * <title>Simple version check example</title>
+ * An example of how to make sure you have the version of Tracker
+ * installed to run your code.
+ * <programlisting>
+ * if (!TRACKER_CHECK_VERSION (0, 10, 7)) {
+ *         g_error ("Tracker version 0.10.7 or above is needed");
+ * }
+ * </programlisting>
+ * </example>
+ *
+ * Since: 0.10
+ **/
+#define TRACKER_CHECK_VERSION(major,minor,micro)    \
+    (TRACKER_MAJOR_VERSION > (major) || \
+     (TRACKER_MAJOR_VERSION == (major) && TRACKER_MINOR_VERSION > (minor)) || \
+     (TRACKER_MAJOR_VERSION == (major) && TRACKER_MINOR_VERSION == (minor) && \
+      TRACKER_MICRO_VERSION >= (micro)))
+
+const gchar * tracker_check_version (guint required_major,
+                                     guint required_minor,
+                                     guint required_micro);
+
+G_END_DECLS
+
+#endif /* __LIBTRACKER_SPARQL_VERSION_H__ */



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