From 588cc25cc9c80ba8b1aafe5f65746d80f9ef54a5 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Fri, 11 Nov 2011 23:10:03 +0000 Subject: Add lilv_plugin_has_extension_data. Add tests for extension data functions. Tolerate (ignore) plugins with broken data with "gaps" in port indices. git-svn-id: http://svn.drobilla.net/lad/trunk/lilv@3611 a436a847-0d15-0410-975c-d299462d15a1 --- lilv/lilv.h | 10 +++++++++- src/plugin.c | 35 +++++++++++++++++++++++++++++++++++ test/lilv_test.c | 11 +++++++++++ 3 files changed, 55 insertions(+), 1 deletion(-) diff --git a/lilv/lilv.h b/lilv/lilv.h index d5e0c8f..e748d1d 100644 --- a/lilv/lilv.h +++ b/lilv/lilv.h @@ -786,7 +786,15 @@ LilvNodes* lilv_plugin_get_optional_features(const LilvPlugin* p); /** - Get the extension data implemented by a plugin. + Return whether or not a plugin provides a specific extension data. +*/ +LILV_API +bool +lilv_plugin_has_extension_data(const LilvPlugin* p, + const LilvNode* uri); + +/** + Get a sequence of all extension data provided by a plugin. This can be used to find which URIs lilv_instance_get_extension_data() will return a value for without instantiating the plugin. */ diff --git a/src/plugin.c b/src/plugin.c index 9fba6f4..88732d1 100644 --- a/src/plugin.c +++ b/src/plugin.c @@ -268,6 +268,17 @@ lilv_plugin_load_ports_if_necessary(const LilvPlugin* const_p) } } lilv_match_end(ports); + + // Check sanity + for (uint32_t i = 0; i < p->num_ports; ++i) { + if (!p->ports[i]) { + LILV_ERRORF("Plugin <%s> is missing port %d/%d\n", + lilv_node_as_uri(p->plugin_uri), i, p->num_ports); + free(p->ports); + p->ports = NULL; + p->num_ports = 0; + } + } } } @@ -644,6 +655,30 @@ lilv_plugin_get_required_features(const LilvPlugin* p) return lilv_plugin_get_value(p, p->world->lv2_requiredFeature_val); } +LILV_API +bool +lilv_plugin_has_extension_data(const LilvPlugin* p, + const LilvNode* uri) +{ + if (!lilv_node_is_uri(uri)) { + LILV_ERRORF("Extension data `%s' is not a URI\n", uri->str_val); + return false; + } + + SordIter* iter = lilv_world_query_internal( + p->world, + p->plugin_uri->val.uri_val, + p->world->lv2_extensionData_val->val.uri_val, + uri->val.uri_val); + + if (iter) { + sord_iter_free(iter); + return true; + } else { + return false; + } +} + LILV_API LilvNodes* lilv_plugin_get_extension_data(const LilvPlugin* p) diff --git a/test/lilv_test.c b/test/lilv_test.c index 85f91da..2e17fb5 100644 --- a/test/lilv_test.c +++ b/test/lilv_test.c @@ -468,6 +468,7 @@ test_plugin(void) LICENSE_GPL " ; " "lv2:optionalFeature lv2:hardRTCapable ; " "lv2:requiredFeature ; " + "lv2:extensionData ;" ":foo 1.6180 ; " ":bar true ; " ":baz false ; " @@ -637,6 +638,16 @@ test_plugin(void) TEST_ASSERT(lilv_uis_size(uis) == 0); lilv_uis_free(uis); + LilvNode* extdata = lilv_new_uri(world, "http://example.org/extdata"); + LilvNode* noextdata = lilv_new_uri(world, "http://example.org/noextdata"); + LilvNodes* extdatas = lilv_plugin_get_extension_data(plug); + TEST_ASSERT(lilv_plugin_has_extension_data(plug, extdata)); + TEST_ASSERT(!lilv_plugin_has_extension_data(plug, noextdata)); + TEST_ASSERT(lilv_nodes_size(extdatas) == 1); + TEST_ASSERT(lilv_node_equals(lilv_nodes_get_first(extdatas), extdata)); + lilv_node_free(extdata); + lilv_nodes_free(extdatas); + lilv_nodes_free(thing_names); lilv_node_free(thing_uri); lilv_node_free(name_p); -- cgit v1.2.1