[Xfce4-commits] <xfce4-panel:devel> Add version check functions to library.

Nick Schermer noreply at xfce.org
Sun Nov 22 20:36:03 CET 2009


Updating branch refs/heads/devel
         to 0fa301df67814ad6681ebdfdb6651cd6e45afb87 (commit)
       from e4887b4c6255c4f183c225a3ebe5c21ee0d3aba7 (commit)

commit 0fa301df67814ad6681ebdfdb6651cd6e45afb87
Author: Nick Schermer <nick at xfce.org>
Date:   Sun Nov 22 20:30:57 2009 +0100

    Add version check functions to library.

 configure.in.in                         |    1 +
 libxfce4panel/Makefile.am               |    2 +
 libxfce4panel/libxfce4panel-config.c    |   84 +++++++++++++++++++++++++++++++
 libxfce4panel/libxfce4panel-config.h.in |   52 +++++++++++++++++++
 libxfce4panel/libxfce4panel-enums.h     |    1 +
 libxfce4panel/libxfce4panel.h           |    1 +
 6 files changed, 141 insertions(+), 0 deletions(-)

diff --git a/configure.in.in b/configure.in.in
index 6d9697d..47c92a1 100644
--- a/configure.in.in
+++ b/configure.in.in
@@ -182,6 +182,7 @@ Makefile
 common/Makefile
 libxfce4panel/Makefile
 libxfce4panel/libxfce4panel-1.0.pc
+libxfce4panel/libxfce4panel-config.h
 migrate/Makefile
 panel/Makefile
 wrapper/Makefile
diff --git a/libxfce4panel/Makefile.am b/libxfce4panel/Makefile.am
index 68dc148..cf0df65 100644
--- a/libxfce4panel/Makefile.am
+++ b/libxfce4panel/Makefile.am
@@ -21,6 +21,7 @@ libxfce4panel_built_sources = \
 
 libxfce4panel_headers = \
 	libxfce4panel.h \
+	libxfce4panel-config.h \
 	libxfce4panel-deprecated.h \
 	libxfce4panel-enums.h \
 	xfce-arrow-button.h \
@@ -41,6 +42,7 @@ libxfce4panel_include_HEADERS = \
 libxfce4panel_1_0_la_SOURCES = \
 	$(libxfce4panel_built_sources) \
 	$(libxfce4panel_headers) \
+	libxfce4panel-config.c \
 	xfce-arrow-button.c \
 	xfce-hvbox.c \
 	xfce-panel-convenience.c \
diff --git a/libxfce4panel/libxfce4panel-config.c b/libxfce4panel/libxfce4panel-config.c
new file mode 100644
index 0000000..493ed00
--- /dev/null
+++ b/libxfce4panel/libxfce4panel-config.c
@@ -0,0 +1,84 @@
+/*
+ * Copyright (C) 2009 Nick Schermer <nick at xfce.org>
+ *
+ * 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
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <libxfce4panel/libxfce4panel-config.h>
+#include <libxfce4panel/libxfce4panel-alias.h>
+
+
+
+const guint libxfce4panel_major_version = LIBXFCE4PANEL_MAJOR_VERSION;
+const guint libxfce4panel_minor_version = LIBXFCE4PANEL_MINOR_VERSION;
+const guint libxfce4panel_micro_version = LIBXFCE4PANEL_MICRO_VERSION;
+
+
+
+/**
+ * libxfce4panel_check_version:
+ * @required_major: the required major version.
+ * @required_minor: the required minor version.
+ * @required_micro: the required micro version.
+ *
+ * Checks that the <systemitem class="library">libxfce4panel</systemitem> library
+ * in use is compatible with the given version. Generally you would pass in
+ * the constants #LIBXFCE4PANEL_MAJOR_VERSION, #LIBXFCE4PANEL_MINOR_VERSION and
+ * #LIBXFCE4PANEL_MICRO_VERSION as the three arguments to this function; that produces
+ * a check that the library in use is compatible with the version of
+ * <systemitem class="library">libxfce4panel</systemitem> the extension was
+ * compiled against.
+ *
+ * <example>
+ * <title>Checking the runtime version of the Libxfce4ui library</title>
+ * <programlisting>
+ * const gchar *mismatch;
+ * mismatch = libxfce4panel_check_version (LIBXFCE4PANEL_MAJOR_VERSION,
+ *                                      LIBXFCE4PANEL_MINOR_VERSION,
+ *                                      LIBXFCE4PANEL_MICRO_VERSION);
+ * if (G_UNLIKELY (mismatch != NULL))
+ *   g_error ("Version mismatch: %<!---->s", mismatch);
+ * </programlisting>
+ * </example>
+ *
+ * Return value: %NULL if the library is compatible with the given version,
+ *               or a string describing the version mismatch. The returned
+ *               string is owned by the library and must not be freed or
+ *               modified by the caller.
+ **/
+const gchar *
+libxfce4panel_check_version (guint required_major,
+                          guint required_minor,
+                          guint required_micro)
+{
+  if (required_major > LIBXFCE4PANEL_MAJOR_VERSION)
+    return "Xfce Panel version too old (major mismatch)";
+  if (required_major < LIBXFCE4PANEL_MAJOR_VERSION)
+    return "Xfce Panel version too new (major mismatch)";
+  if (required_minor > LIBXFCE4PANEL_MINOR_VERSION)
+    return "Xfce Panel version too old (minor mismatch)";
+  if (required_minor == LIBXFCE4PANEL_MINOR_VERSION && required_micro > LIBXFCE4PANEL_MICRO_VERSION)
+    return "Xfce Panel version too old (micro mismatch)";
+  return NULL;
+}
+
+
+
+#define __LIBXFCE4PANEL_CONFIG_C__
+#include <libxfce4panel/libxfce4panel-aliasdef.c>
diff --git a/libxfce4panel/libxfce4panel-config.h.in b/libxfce4panel/libxfce4panel-config.h.in
new file mode 100644
index 0000000..3970d9b
--- /dev/null
+++ b/libxfce4panel/libxfce4panel-config.h.in
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2009 Nick Schermer <nick at xfce.org>
+ *
+ * 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
+ */
+
+#if !defined(LIBXFCE4PANEL_INSIDE_LIBXFCE4PANEL_H) && !defined(LIBXFCE4PANEL_COMPILATION)
+#error "Only <libxfce4panel/libxfce4panel.h> can be included directly, this file may disappear or change contents"
+#endif
+
+#ifndef __LIBXFCE4PANEL_CONFIG_H__
+#define __LIBXFCE4PANEL_CONFIG_H__
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define LIBXFCE4PANEL_MAJOR_VERSION (@LIBXFCE4PANEL_VERSION_MAJOR@)
+#define LIBXFCE4PANEL_MINOR_VERSION (@LIBXFCE4PANEL_VERSION_MINOR@)
+#define LIBXFCE4PANEL_MICRO_VERSION (@LIBXFCE4PANEL_VERSION_MICRO@)
+
+#define LIBXFCE4PANEL_CHECK_VERSION(major,minor,micro) \
+  (LIBXFCE4PANEL_MAJOR_VERSION > (major) \
+   || (LIBXFCE4PANEL_MAJOR_VERSION == (major) \
+       && LIBXFCE4PANEL_MINOR_VERSION > (minor)) \
+   || (LIBXFCE4PANEL_MAJOR_VERSION == (major) \
+       && LIBXFCE4PANEL_MINOR_VERSION == (minor) \
+       && LIBXFCE4PANEL_MICRO_VERSION >= (micro)))
+
+extern const guint libxfce4panel_major_version;
+extern const guint libxfce4panel_minor_version;
+extern const guint libxfce4panel_micro_version;
+
+const gchar *libxfce4panel_check_version (guint required_major,
+                                          guint required_minor,
+                                          guint required_micro);
+
+G_END_DECLS
+
+#endif /* !__LIBXFCE4PANEL_CONFIG_H__ */
diff --git a/libxfce4panel/libxfce4panel-enums.h b/libxfce4panel/libxfce4panel-enums.h
index dfbb811..bc26d11 100644
--- a/libxfce4panel/libxfce4panel-enums.h
+++ b/libxfce4panel/libxfce4panel-enums.h
@@ -27,6 +27,7 @@
 #include <glib-object.h>
 
 G_BEGIN_DECLS
+
 /**
  * XfceScreenPosition
  * @XFCE_SCREEN_POSITION_NONE       : No position has been set.
diff --git a/libxfce4panel/libxfce4panel.h b/libxfce4panel/libxfce4panel.h
index 0be57fa..3634911 100644
--- a/libxfce4panel/libxfce4panel.h
+++ b/libxfce4panel/libxfce4panel.h
@@ -23,6 +23,7 @@ G_BEGIN_DECLS
 
 #define LIBXFCE4PANEL_INSIDE_LIBXFCE4PANEL_H
 
+#include <libxfce4panel/libxfce4panel-config.h>
 #include <libxfce4panel/libxfce4panel-enums.h>
 #include <libxfce4panel/libxfce4panel-enum-types.h>
 #include <libxfce4panel/xfce-panel-macros.h>



More information about the Xfce4-commits mailing list