gplugin/gplugin

Add gplugin_version_check. Fixes GPLUGIN-109
feature/runtime-version-check
2020-02-22, Gary Kramlich
d2b67454c6db
Parents d6afbe11cdc1
Children 846d3245caf5
Add gplugin_version_check. Fixes GPLUGIN-109
--- a/gplugin/gplugin-version.c Sat Feb 22 04:21:27 2020 -0600
+++ b/gplugin/gplugin-version.c Sat Feb 22 04:42:39 2020 -0600
@@ -160,6 +160,45 @@
*/
/**
+ * gplugin_version_check:
+ * @major: The required major version.
+ * @minro: The required minor version.
+ * @micro: The required micro version.
+ *
+ * Checks that the GPlugin library in use is compatible with the given version.
+ * Generally you would pass in the constants #GPLUGIN_MAJOR_VERSION,
+ * #GPLUGIN_MINOR_VERSION, #GPLUGIN_MICRO_VERSION as the three arguments to
+ * this function; that produces a check that the library in use is compatible
+ * with the version of GPlugin 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 @major.@minor.@micro. Second the running
+ * library must be binary compatible with the version @major.@minor.@micro
+ * (same major version).
+ *
+ * Returns: %NULL if the GPlugin library is compatible with the given version,
+ * or a string describing the version mismatch. The returned string
+ * is owned by GPlugin and must not be modified or freed.
+ */
+const gchar *
+gplugin_version_check(guint major, guint minor, guint micro) {
+ if(major > GPLUGIN_MAJOR_VERSION) {
+ return "gplugin version too old (major mismatch)";
+ }
+ if(major < GPLUGIN_MAJOR_VERSION) {
+ return "gplugin version too new (major mismatch)";
+ }
+ if(minor > GPLUGIN_MINOR_VERSION) {
+ return "gplugin version too old (minor mismatch)";
+ }
+ if(minor == GPLUGIN_MINOR_VERSION && micro > GPLUGIN_MICRO_VERSION) {
+ return "gplugin version too old (micro mismatch)";
+ }
+
+ return NULL;
+}
+
+/**
* gplugin_version_compare:
* @v1: The first version to compare.
* @v2: The second version to compare.
--- a/gplugin/gplugin-version.h.in Sat Feb 22 04:21:27 2020 -0600
+++ b/gplugin/gplugin-version.h.in Sat Feb 22 04:42:39 2020 -0600
@@ -38,6 +38,8 @@
G_BEGIN_DECLS
+const gchar *gplugin_version_check(guint major, guint minor, guint micro);
+
gint gplugin_version_compare(const gchar *v1, const gchar *v2, GError **error);
G_END_DECLS