Add new API to check plugin feature version requirements.
authorTim-Philipp Müller <tim@centricular.net>
Fri, 14 Oct 2005 11:09:29 +0000 (11:09 +0000)
committerTim-Philipp Müller <tim@centricular.net>
Fri, 14 Oct 2005 11:09:29 +0000 (11:09 +0000)
Original commit message from CVS:
* gst/gstpluginfeature.c: (gst_plugin_feature_check_version):
* gst/gstpluginfeature.h:
* gst/gstregistry.c: (gst_default_registry_check_feature_version):
* gst/gstregistry.h:
* docs/gst/gstreamer-sections.txt:
Add new API to check plugin feature version requirements.
* check/gst/gstplugin.c: (test_version_checks), (gst_plugin_suite):
Some basic tests for the above.

ChangeLog
check/gst/gstplugin.c
docs/gst/gstreamer-sections.txt
gst/gstpluginfeature.c
gst/gstpluginfeature.h
gst/gstregistry.c
gst/gstregistry.h
tests/check/gst/gstplugin.c

index 9d19785..873f2e7 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2005-10-14  Tim-Philipp Müller  <tim at centricular dot net>
+
+       * gst/gstpluginfeature.c: (gst_plugin_feature_check_version):
+       * gst/gstpluginfeature.h:
+       * gst/gstregistry.c: (gst_default_registry_check_feature_version):
+       * gst/gstregistry.h:
+       * docs/gst/gstreamer-sections.txt:
+         Add new API to check plugin feature version requirements.
+
+       * check/gst/gstplugin.c: (test_version_checks), (gst_plugin_suite):
+         Some basic tests for the above.         
+
 2005-10-13  Thomas Vander Stichele  <thomas at apestaart dot org>
 
        * gst/gststructure.c: (gst_structure_to_string):
index 979bdc4..7278069 100644 (file)
@@ -247,6 +247,49 @@ GST_START_TEST (test_typefind)
 GST_END_TEST;
 #endif
 
+GST_START_TEST (test_version_checks)
+{
+  fail_if (gst_default_registry_check_feature_version ("identity",
+          GST_VERSION_MAJOR, GST_VERSION_MINOR, GST_VERSION_MICRO) == FALSE,
+      "Unexpected version check result");
+
+  fail_if (gst_default_registry_check_feature_version ("identity",
+          GST_VERSION_MAJOR + 1, GST_VERSION_MINOR, GST_VERSION_MICRO) == TRUE,
+      "Unexpected version check result");
+
+  fail_if (gst_default_registry_check_feature_version ("identity",
+          GST_VERSION_MAJOR, GST_VERSION_MINOR + 1, GST_VERSION_MICRO) == TRUE,
+      "Unexpected version check result");
+
+  fail_if (gst_default_registry_check_feature_version ("identity",
+          GST_VERSION_MAJOR, GST_VERSION_MINOR, GST_VERSION_MICRO + 1) == TRUE,
+      "Unexpected version check result");
+
+  if (GST_VERSION_MAJOR > 0) {
+    fail_if (gst_default_registry_check_feature_version ("identity",
+            GST_VERSION_MAJOR - 1, GST_VERSION_MINOR,
+            GST_VERSION_MICRO) == FALSE, "Unexpected version check result");
+  }
+
+  if (GST_VERSION_MINOR > 0) {
+    fail_if (gst_default_registry_check_feature_version ("identity",
+            GST_VERSION_MAJOR, GST_VERSION_MINOR - 1,
+            GST_VERSION_MICRO) == FALSE, "Unexpected version check result");
+  }
+
+  if (GST_VERSION_MICRO > 0) {
+    fail_if (gst_default_registry_check_feature_version ("identity",
+            GST_VERSION_MAJOR, GST_VERSION_MINOR,
+            GST_VERSION_MICRO - 1) == FALSE, "Unexpected version check result");
+  }
+
+  fail_if (gst_default_registry_check_feature_version ("entityid",
+          GST_VERSION_MAJOR, GST_VERSION_MINOR, GST_VERSION_MICRO) == TRUE,
+      "Unexpected version check result");
+}
+
+GST_END_TEST;
+
 Suite *
 gst_plugin_suite (void)
 {
@@ -264,12 +307,12 @@ gst_plugin_suite (void)
   tcase_add_test (tc_chain, test_find_plugin);
   tcase_add_test (tc_chain, test_find_feature);
   tcase_add_test (tc_chain, test_find_element);
+  tcase_add_test (tc_chain, test_version_checks);
   //tcase_add_test (tc_chain, test_typefind);
 
   return s;
 }
 
-
 int
 main (int argc, char **argv)
 {
index 202e1d5..02265a4 100644 (file)
@@ -1504,6 +1504,7 @@ gst_plugin_feature_get_rank
 gst_plugin_feature_get_name
 gst_plugin_feature_load
 gst_plugin_feature_list_free
+gst_plugin_feature_check_version
 <SUBSECTION Standard>
 GstPluginFeatureClass
 GST_PLUGIN_FEATURE
@@ -1614,6 +1615,7 @@ gst_registry_lookup_feature
 gst_registry_get_plugin_list
 gst_registry_add_feature
 <SUBSECTION Default Registry>
+gst_default_registry_check_feature_version
 gst_default_registry_get_path_list
 gst_default_registry_add_plugin
 gst_default_registry_add_path
index c665f2c..a3227fe 100644 (file)
@@ -199,7 +199,7 @@ gst_plugin_feature_set_rank (GstPluginFeature * feature, guint rank)
 }
 
 /**
- * gst_plugin_feature_get rank:
+ * gst_plugin_feature_get_rank:
  * @feature: a feature
  *
  * Gets the rank of a plugin feature.
@@ -232,3 +232,69 @@ gst_plugin_feature_list_free (GList * list)
   }
   g_list_free (list);
 }
+
+/**
+ * gst_plugin_feature_check_version:
+ * @feature: a feature
+ * @min_major: minimum required major version
+ * @min_minor: minimum required minor version
+ * @min_micro: minimum required micro version
+ *
+ * Checks whether the given plugin feature is at least
+ *  the required version
+ *
+ * Returns: #TRUE if the plugin feature has at least
+ *  the required version, otherwise #FALSE.
+ */
+gboolean
+gst_plugin_feature_check_version (GstPluginFeature * feature,
+    guint min_major, guint min_minor, guint min_micro)
+{
+  GstRegistry *registry;
+  GstPlugin *plugin;
+  gboolean ret = FALSE;
+
+  g_return_val_if_fail (feature != NULL, FALSE);
+  g_return_val_if_fail (GST_IS_PLUGIN_FEATURE (feature), FALSE);
+
+  GST_DEBUG ("Looking up plugin '%s' containing plugin feature '%s'",
+      feature->plugin_name, feature->name);
+
+  registry = gst_registry_get_default ();
+  plugin = gst_registry_find_plugin (registry, feature->plugin_name);
+
+  if (plugin) {
+    const gchar *ver_str;
+    guint major, minor, micro;
+
+    ver_str = gst_plugin_get_version (plugin);
+    g_return_val_if_fail (ver_str != NULL, FALSE);
+
+    if (sscanf (ver_str, "%u.%u.%u", &major, &minor, &micro) == 3) {
+      if (major > min_major)
+        ret = TRUE;
+      else if (major < min_major)
+        ret = FALSE;
+      else if (minor > min_minor)
+        ret = TRUE;
+      else if (minor < min_minor)
+        ret = FALSE;
+      else if (micro > min_micro)
+        ret = TRUE;
+      else
+        ret = (micro == min_micro);
+
+      GST_DEBUG ("Checking whether %u.%u.%u >= %u.%u.%u? %s", major, minor,
+          micro, min_major, min_minor, min_micro, (ret) ? "yes" : "no");
+    } else {
+      GST_WARNING ("Could not parse version string '%s' of plugin '%s'",
+          ver_str, feature->plugin_name);
+    }
+
+    gst_object_unref (plugin);
+  } else {
+    GST_DEBUG ("Could not find plugin '%s'", feature->plugin_name);
+  }
+
+  return ret;
+}
index 2b30f19..d3c339f 100644 (file)
@@ -126,6 +126,11 @@ G_CONST_RETURN gchar *gst_plugin_feature_get_name  (GstPluginFeature *feature);
 
 void            gst_plugin_feature_list_free            (GList *list);
 
+gboolean        gst_plugin_feature_check_version        (GstPluginFeature *feature,
+                                                         guint             min_major,
+                                                         guint             min_minor,
+                                                         guint             min_micro);
+
 G_END_DECLS
 
 
index 48404f0..cffe9a4 100644 (file)
@@ -803,3 +803,42 @@ _gst_registry_cleanup ()
   gst_object_unref (_gst_registry_default);
   _gst_registry_default = NULL;
 }
+
+/**
+ * gst_default_registry_check_feature_version:
+ * @feature_name: the name of the feature (e.g. "oggdemux")
+ * @min_major: the minimum major version number
+ * @min_minor: the minimum minor version number
+ * @min_micro: the minimum micro version number
+ *
+ * Checks whether a plugin feature by the given name exists in the
+ * default registry and whether its version is at least the
+ * version required.
+ *
+ * Returns: #TRUE if the feature could be found and the version is
+ * the same as the required version or newer, and #FALSE otherwise.
+ */
+gboolean
+gst_default_registry_check_feature_version (const gchar * feature_name,
+    guint min_major, guint min_minor, guint min_micro)
+{
+  GstPluginFeature *feature;
+  GstRegistry *registry;
+  gboolean ret = FALSE;
+
+  g_return_val_if_fail (feature_name != NULL, FALSE);
+
+  GST_DEBUG ("Looking up plugin feature '%s'", feature_name);
+
+  registry = gst_registry_get_default ();
+  feature = gst_registry_lookup_feature (registry, feature_name);
+  if (feature) {
+    ret = gst_plugin_feature_check_version (feature, min_major, min_minor,
+        min_micro);
+    gst_object_unref (feature);
+  } else {
+    GST_DEBUG ("Could not find plugin feature '%s'", feature_name);
+  }
+
+  return ret;
+}
index 79c7a51..454639c 100644 (file)
@@ -60,6 +60,7 @@ struct _GstRegistryClass {
   void                         (*plugin_added)         (GstRegistry *registry, GstPlugin *plugin);
   void                         (*feature_added)        (GstRegistry *registry, GstPluginFeature *feature);
 
+  /*< private >*/
   gpointer _gst_reserved[GST_PADDING];
 };
 
@@ -119,6 +120,11 @@ void                    _gst_registry_cleanup           (void);
 #define gst_default_registry_feature_filter(filter,first,user_data) \
   gst_registry_feature_filter (gst_registry_get_default(),filter,first,user_data)
 
+gboolean                gst_default_registry_check_feature_version (const gchar *feature_name,
+                                                                    guint        min_major,
+                                                                    guint        min_minor,
+                                                                    guint        min_micro);
+
 G_END_DECLS
 
 #endif /* __GST_REGISTRY_H__ */
index 979bdc4..7278069 100644 (file)
@@ -247,6 +247,49 @@ GST_START_TEST (test_typefind)
 GST_END_TEST;
 #endif
 
+GST_START_TEST (test_version_checks)
+{
+  fail_if (gst_default_registry_check_feature_version ("identity",
+          GST_VERSION_MAJOR, GST_VERSION_MINOR, GST_VERSION_MICRO) == FALSE,
+      "Unexpected version check result");
+
+  fail_if (gst_default_registry_check_feature_version ("identity",
+          GST_VERSION_MAJOR + 1, GST_VERSION_MINOR, GST_VERSION_MICRO) == TRUE,
+      "Unexpected version check result");
+
+  fail_if (gst_default_registry_check_feature_version ("identity",
+          GST_VERSION_MAJOR, GST_VERSION_MINOR + 1, GST_VERSION_MICRO) == TRUE,
+      "Unexpected version check result");
+
+  fail_if (gst_default_registry_check_feature_version ("identity",
+          GST_VERSION_MAJOR, GST_VERSION_MINOR, GST_VERSION_MICRO + 1) == TRUE,
+      "Unexpected version check result");
+
+  if (GST_VERSION_MAJOR > 0) {
+    fail_if (gst_default_registry_check_feature_version ("identity",
+            GST_VERSION_MAJOR - 1, GST_VERSION_MINOR,
+            GST_VERSION_MICRO) == FALSE, "Unexpected version check result");
+  }
+
+  if (GST_VERSION_MINOR > 0) {
+    fail_if (gst_default_registry_check_feature_version ("identity",
+            GST_VERSION_MAJOR, GST_VERSION_MINOR - 1,
+            GST_VERSION_MICRO) == FALSE, "Unexpected version check result");
+  }
+
+  if (GST_VERSION_MICRO > 0) {
+    fail_if (gst_default_registry_check_feature_version ("identity",
+            GST_VERSION_MAJOR, GST_VERSION_MINOR,
+            GST_VERSION_MICRO - 1) == FALSE, "Unexpected version check result");
+  }
+
+  fail_if (gst_default_registry_check_feature_version ("entityid",
+          GST_VERSION_MAJOR, GST_VERSION_MINOR, GST_VERSION_MICRO) == TRUE,
+      "Unexpected version check result");
+}
+
+GST_END_TEST;
+
 Suite *
 gst_plugin_suite (void)
 {
@@ -264,12 +307,12 @@ gst_plugin_suite (void)
   tcase_add_test (tc_chain, test_find_plugin);
   tcase_add_test (tc_chain, test_find_feature);
   tcase_add_test (tc_chain, test_find_element);
+  tcase_add_test (tc_chain, test_version_checks);
   //tcase_add_test (tc_chain, test_typefind);
 
   return s;
 }
 
-
 int
 main (int argc, char **argv)
 {