From 45258dbc4c547cb9c94a114e7e170ed3abac2d2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim-Philipp=20M=C3=BCller?= Date: Fri, 14 Oct 2005 11:09:29 +0000 Subject: [PATCH] Add new API to check plugin feature version requirements. 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 | 12 ++++++ check/gst/gstplugin.c | 45 +++++++++++++++++++++- docs/gst/gstreamer-sections.txt | 2 + gst/gstpluginfeature.c | 68 ++++++++++++++++++++++++++++++++- gst/gstpluginfeature.h | 5 +++ gst/gstregistry.c | 39 +++++++++++++++++++ gst/gstregistry.h | 6 +++ tests/check/gst/gstplugin.c | 45 +++++++++++++++++++++- 8 files changed, 219 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9d197851d8..873f2e7d78 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +2005-10-14 Tim-Philipp Müller + + * 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 * gst/gststructure.c: (gst_structure_to_string): diff --git a/check/gst/gstplugin.c b/check/gst/gstplugin.c index 979bdc48e9..7278069469 100644 --- a/check/gst/gstplugin.c +++ b/check/gst/gstplugin.c @@ -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) { diff --git a/docs/gst/gstreamer-sections.txt b/docs/gst/gstreamer-sections.txt index 202e1d5b3e..02265a4c43 100644 --- a/docs/gst/gstreamer-sections.txt +++ b/docs/gst/gstreamer-sections.txt @@ -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 GstPluginFeatureClass GST_PLUGIN_FEATURE @@ -1614,6 +1615,7 @@ gst_registry_lookup_feature gst_registry_get_plugin_list gst_registry_add_feature +gst_default_registry_check_feature_version gst_default_registry_get_path_list gst_default_registry_add_plugin gst_default_registry_add_path diff --git a/gst/gstpluginfeature.c b/gst/gstpluginfeature.c index c665f2c523..a3227fec53 100644 --- a/gst/gstpluginfeature.c +++ b/gst/gstpluginfeature.c @@ -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, µ) == 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; +} diff --git a/gst/gstpluginfeature.h b/gst/gstpluginfeature.h index 2b30f1956c..d3c339f9bc 100644 --- a/gst/gstpluginfeature.h +++ b/gst/gstpluginfeature.h @@ -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 diff --git a/gst/gstregistry.c b/gst/gstregistry.c index 48404f070e..cffe9a4b8b 100644 --- a/gst/gstregistry.c +++ b/gst/gstregistry.c @@ -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; +} diff --git a/gst/gstregistry.h b/gst/gstregistry.h index 79c7a51455..454639c0cf 100644 --- a/gst/gstregistry.h +++ b/gst/gstregistry.h @@ -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__ */ diff --git a/tests/check/gst/gstplugin.c b/tests/check/gst/gstplugin.c index 979bdc48e9..7278069469 100644 --- a/tests/check/gst/gstplugin.c +++ b/tests/check/gst/gstplugin.c @@ -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) {