pbutils: add compile time and runtime version checks for gst-plugins-base
authorTim-Philipp Müller <tim.muller@collabora.co.uk>
Mon, 26 Jul 2010 15:04:02 +0000 (17:04 +0200)
committerTim-Philipp Müller <tim.muller@collabora.co.uk>
Mon, 26 Jul 2010 15:25:15 +0000 (17:25 +0200)
So people can check what version of the gst-plugins-base libs they're
building against or linked against.

API: GST_PLUGINS_BASE_VERSION_MAJOR
API: GST_PLUGINS_BASE_VERSION_MINOR
API: GST_PLUGINS_BASE_VERSION_MICRO
API: GST_PLUGINS_BASE_VERSION_NANO
API: GST_CHECK_PLUGINS_BASE_VERSION
API: gst_plugins_base_version()
API: gst_plugins_base_version_string()

.gitignore
configure.ac
docs/libs/gst-plugins-base-libs-sections.txt
gst-libs/gst/pbutils/Makefile.am
gst-libs/gst/pbutils/gstpluginsbaseversion.c [new file with mode: 0644]
gst-libs/gst/pbutils/gstpluginsbaseversion.h.in [new file with mode: 0644]
gst-libs/gst/pbutils/pbutils.h
tests/check/libs/pbutils.c
win32/common/libgstpbutils.def

index 3b739b8..005392e 100644 (file)
@@ -43,6 +43,7 @@ Makefile
 *.gir
 *.typelib
 
+gst-libs/gst/pbutils/gstpluginsbaseversion.h
 gst-libs/gst/tag/mklangtables
 
 tmp-orc.c
index e6195d1..fdc04f0 100644 (file)
@@ -911,6 +911,7 @@ gst-libs/gst/rtsp/Makefile
 gst-libs/gst/sdp/Makefile
 gst-libs/gst/tag/Makefile
 gst-libs/gst/pbutils/Makefile
+gst-libs/gst/pbutils/gstpluginsbaseversion.h
 gst-libs/gst/video/Makefile
 tools/Makefile
 pkgconfig/Makefile
index 8fc9c89..b9dc18c 100644 (file)
@@ -1729,6 +1729,14 @@ gst_tag_get_language_code_iso_639_2T
 <INCLUDE>gst/pbutils/pbutils.h</INCLUDE>
 <SUBSECTION>
 gst_pb_utils_init
+<SUBSECTION>
+GST_PLUGINS_BASE_VERSION_MAJOR
+GST_PLUGINS_BASE_VERSION_MINOR
+GST_PLUGINS_BASE_VERSION_MICRO
+GST_PLUGINS_BASE_VERSION_NANO
+GST_CHECK_PLUGINS_BASE_VERSION
+gst_plugins_base_version
+gst_plugins_base_version_string
 </SECTION>
 
 <SECTION>
index fe635e5..9c98dad 100644 (file)
@@ -18,7 +18,11 @@ built_sources = \
 built_headers = \
        pbutils-enumtypes.h
 
+built_headers_configure = \
+       gstpluginsbaseversion.h
+
 libgstpbutils_@GST_MAJORMINOR@_la_SOURCES = \
+       gstpluginsbaseversion.c \
        pbutils.c         \
        descriptions.c    \
        install-plugins.c \
@@ -31,7 +35,7 @@ libgstpbutils_@GST_MAJORMINOR@includedir = $(includedir)/gstreamer-@GST_MAJORMIN
 libgstpbutils_@GST_MAJORMINOR@include_HEADERS = \
        $(headers_pbutils)
 nodist_libgstpbutils_@GST_MAJORMINOR@include_HEADERS = \
-       pbutils-enumtypes.h
+       $(built_headers) $(built_headers_configure)
 
 libgstpbutils_@GST_MAJORMINOR@_la_LIBADD = $(GST_LIBS)
 libgstpbutils_@GST_MAJORMINOR@_la_CFLAGS = $(GST_PLUGINS_BASE_CFLAGS) $(GST_CFLAGS)
@@ -43,6 +47,8 @@ BUILT_SOURCES = \
 
 CLEANFILES = $(BUILT_SOURCES)
 
+# DISTCLEANFILES is for files generated by configure
+DISTCLEANFILES = $(built_header_configure)
 
 include $(top_srcdir)/common/gst-glib-gen.mak
 
diff --git a/gst-libs/gst/pbutils/gstpluginsbaseversion.c b/gst-libs/gst/pbutils/gstpluginsbaseversion.c
new file mode 100644 (file)
index 0000000..997a0b8
--- /dev/null
@@ -0,0 +1,78 @@
+/* GStreamer base plugins libraries version information
+ * Copyright (C) 2010 Tim-Philipp Müller <tim centricular net>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 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
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+/**
+ * SECTION:gstpluginsbaseversion
+ * @short_description: GStreamer gst-plugins-base libraries version macros.
+ *
+ * Use the GST_PLUGINS_BASE_VERSION_* macros e.g. to check what version of
+ * gst-plugins-base you are building against, and gst_plugins_base_version()
+ * if you need to check at runtime what version of the gst-plugins-base
+ * libraries are being used / you are currently linked against.
+ *
+ * The version macros get defined by including <gst/pbutils/pbutils.h>.
+ */
+
+#include "gstpluginsbaseversion.h"
+
+/**
+ * gst_plugins_base_version:
+ * @major: (out): pointer to a guint to store the major version number, or %NULL
+ * @minor: (out): pointer to a guint to store the minor version number, or %NULL
+ * @micro: (out): pointer to a guint to store the micro version number, or %NULL
+ * @nano:  (out): pointer to a guint to store the nano version number, or %NULL
+ *
+ * Gets the version number of the GStreamer Plugins Base libraries.
+ *
+ * Since: 0.10.31
+ */
+void
+gst_plugins_base_version (guint * major, guint * minor, guint * micro,
+    guint * nano)
+{
+  if (major)
+    *major = GST_PLUGINS_BASE_VERSION_MAJOR;
+  if (minor)
+    *minor = GST_PLUGINS_BASE_VERSION_MINOR;
+  if (micro)
+    *micro = GST_PLUGINS_BASE_VERSION_MICRO;
+  if (nano)
+    *nano = GST_PLUGINS_BASE_VERSION_NANO;
+}
+
+/**
+ * gst_plugins_base_version_string:
+ *
+ * This function returns a string that is useful for describing this version
+ * of GStreamer's gst-plugins-base libraries to the outside world: user agent
+ * strings, logging, about dialogs ...
+ *
+ * Returns: a newly allocated string describing this version of gst-plugins-base
+ *
+ * Since: 0.10.31
+ */
+gchar *
+gst_plugins_base_version_string (void)
+{
+  return g_strdup_printf ("GStreamer Base Plugins %d.%d.%d%s",
+      GST_PLUGINS_BASE_VERSION_MAJOR, GST_PLUGINS_BASE_VERSION_MINOR,
+      GST_PLUGINS_BASE_VERSION_MICRO,
+      ((GST_PLUGINS_BASE_VERSION_NANO == 0) ? "" :
+          ((GST_PLUGINS_BASE_VERSION_NANO == 1) ? " (GIT)" : " (prerelease)")));
+}
diff --git a/gst-libs/gst/pbutils/gstpluginsbaseversion.h.in b/gst-libs/gst/pbutils/gstpluginsbaseversion.h.in
new file mode 100644 (file)
index 0000000..0449321
--- /dev/null
@@ -0,0 +1,84 @@
+/* GStreamer base plugins libraries version information
+ * Copyright (C) 2010 Tim-Philipp Müller <tim centricular net>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 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
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifndef __GST_PLUGINS_BASE_VERSION_H__
+#define __GST_PLUGINS_BASE_VERSION_H__
+
+#include <glib.h>
+
+G_BEGIN_DECLS
+
+/**
+ * GST_PLUGINS_BASE_VERSION_MAJOR:
+ *
+ * The major version of GStreamer's gst-plugins-base libraries at compile time.
+ *
+ * Since: 0.10.31
+ */
+#define GST_PLUGINS_BASE_VERSION_MAJOR (@PACKAGE_VERSION_MAJOR@)
+/**
+ * GST_PLUGINS_BASE_VERSION_MINOR:
+ *
+ * The minor version of GStreamer's gst-plugins-base libraries at compile time.
+ *
+ * Since: 0.10.31
+ */
+#define GST_PLUGINS_BASE_VERSION_MINOR (@PACKAGE_VERSION_MINOR@)
+/**
+ * GST_PLUGINS_BASE_VERSION_MICRO:
+ *
+ * The micro version of GStreamer's gst-plugins-base libraries at compile time.
+ *
+ * Since: 0.10.31
+ */
+#define GST_PLUGINS_BASE_VERSION_MICRO (@PACKAGE_VERSION_MICRO@)
+/**
+ * GST_PLUGINS_BASE_VERSION_NANO:
+ *
+ * The nano version of GStreamer's gst-plugins-base libraries at compile time.
+ * Actual releases have 0, GIT versions have 1, prerelease versions have 2-...
+ *
+ * Since: 0.10.31
+ */
+#define GST_PLUGINS_BASE_VERSION_NANO (@PACKAGE_VERSION_NANO@)
+
+/**
+ * GST_CHECK_PLUGIN_BASE_VERSION:
+ * @major: a number indicating the major version
+ * @minor: a number indicating the minor version
+ * @micro: a number indicating the micro version
+ *
+ * Check whether a GStreamer's gst-plugins-base libraries' version equal to
+ * or greater than major.minor.micro is present.
+ *
+ * Since: 0.10.31
+ */
+#define        GST_CHECK_PLUGINS_BASE_VERSION(major,minor,micro)       \
+    (GST_PLUGINS_BASE_VERSION_MAJOR > (major) || \
+     (GST_PLUGINS_BASE_VERSION_MAJOR == (major) && GST_PLUGINS_BASE_VERSION_MINOR > (minor)) || \
+     (GST_PLUGINS_BASE_VERSION_MAJOR == (major) && GST_PLUGINS_BASE_VERSION_MINOR == (minor) && \
+      GST_PLUGINS_BASE_VERSION_MICRO >= (micro)))
+
+void     gst_plugins_base_version (guint *major, guint *minor, guint *micro, guint *nano);
+
+gchar *  gst_plugins_base_version_string (void);
+
+G_END_DECLS
+
+#endif /* __GST_PLUGINS_BASE_VERSION_H__ */
index 02f7f6b..b0141ec 100644 (file)
@@ -22,6 +22,7 @@
 
 #include <gst/gst.h>
 
+#include <gst/pbutils/gstpluginsbaseversion.h>
 #include <gst/pbutils/descriptions.h>
 #include <gst/pbutils/missing-plugins.h>
 #include <gst/pbutils/install-plugins.h>
index 84f58e7..ae63221 100644 (file)
@@ -704,6 +704,33 @@ GST_START_TEST (test_pb_utils_installer_details)
 
 GST_END_TEST;
 
+GST_START_TEST (test_pb_utils_versions)
+{
+  gchar *s;
+  guint maj, min, mic, nano;
+
+  gst_plugins_base_version (NULL, NULL, NULL, NULL);
+  gst_plugins_base_version (&maj, &min, &mic, &nano);
+  fail_unless_equals_int (maj, GST_PLUGINS_BASE_VERSION_MAJOR);
+  fail_unless_equals_int (min, GST_PLUGINS_BASE_VERSION_MINOR);
+  fail_unless_equals_int (mic, GST_PLUGINS_BASE_VERSION_MICRO);
+  fail_unless_equals_int (nano, GST_PLUGINS_BASE_VERSION_NANO);
+
+  s = gst_plugins_base_version_string ();
+  if (GST_PLUGINS_BASE_VERSION_NANO == 0) {
+    fail_if (strstr (s, "GIT") || strstr (s, "git") || strstr (s, "prerel"));
+  }
+  if (GST_PLUGINS_BASE_VERSION_NANO == 1) {
+    fail_unless (strstr (s, "GIT") || strstr (s, "git"));
+  }
+  if (GST_PLUGINS_BASE_VERSION_NANO >= 2) {
+    fail_unless (strstr (s, "Prerelease") || strstr (s, "prerelease"));
+  }
+  g_free (s);
+}
+
+GST_END_TEST;
+
 static Suite *
 libgstpbutils_suite (void)
 {
@@ -717,6 +744,7 @@ libgstpbutils_suite (void)
   tcase_add_test (tc_chain, test_pb_utils_get_codec_description);
   tcase_add_test (tc_chain, test_pb_utils_install_plugins);
   tcase_add_test (tc_chain, test_pb_utils_installer_details);
+  tcase_add_test (tc_chain, test_pb_utils_versions);
   return s;
 }
 
index 7f4d71b..cacb610 100644 (file)
@@ -30,3 +30,5 @@ EXPORTS
        gst_pb_utils_get_sink_description
        gst_pb_utils_get_source_description
        gst_pb_utils_init
+       gst_plugins_base_version
+       gst_plugins_base_version_string