From b7fc1811252adac20f333db7d89b5cc3b1a3bf07 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sun, 30 Jan 2011 01:24:02 +0000 Subject: Non-SPARQL version of slv2_plugin_get_uis. git-svn-id: http://svn.drobilla.net/lad/trunk/slv2@2863 a436a847-0d15-0410-975c-d299462d15a1 --- src/plugin.c | 60 ++++++++++++++++++++++++++++++++++-------------------------- 1 file changed, 34 insertions(+), 26 deletions(-) diff --git a/src/plugin.c b/src/plugin.c index ebc0ae2..58f1c16 100644 --- a/src/plugin.c +++ b/src/plugin.c @@ -893,40 +893,48 @@ slv2_plugin_get_author_homepage(SLV2Plugin plugin) SLV2UIs -slv2_plugin_get_uis(SLV2Plugin plugin) +slv2_plugin_get_uis(SLV2Plugin p) { - const char* const query_str = - "PREFIX uiext: \n" - "SELECT DISTINCT ?uri ?type ?binary WHERE {\n" - "<> uiext:ui ?uri .\n" - "?uri a ?type ;\n" - " uiext:binary ?binary .\n" - "}\n"; +#define NS_UI (const uint8_t*)"http://lv2plug.in/ns/extensions/ui#" - SLV2Results results = slv2_plugin_query_sparql(plugin, query_str); - - SLV2UIs result = slv2_uis_new(); + SLV2UIs result = slv2_uis_new(); + librdf_stream* uis = slv2_plugin_find_statements( + p, + librdf_new_node_from_uri(p->world->world, p->plugin_uri->val.uri_val), + librdf_new_node_from_uri_string(p->world->world, NS_UI "ui"), + NULL); + for (; !librdf_stream_end(uis); librdf_stream_next(uis)) { + librdf_statement* s = librdf_stream_get_object(uis); + librdf_node* ui = librdf_statement_get_object(s); - while (!librdf_query_results_finished(results->rdf_results)) { - librdf_node* uri_node = librdf_query_results_get_binding_value(results->rdf_results, 0); - librdf_node* type_node = librdf_query_results_get_binding_value(results->rdf_results, 1); - librdf_node* binary_node = librdf_query_results_get_binding_value(results->rdf_results, 2); + SLV2Value type = slv2_plugin_get_unique( + p, + librdf_new_node_from_node(ui), + librdf_new_node_from_node(p->world->rdf_a_node)); - SLV2UI ui = slv2_ui_new(plugin->world, - librdf_node_get_uri(uri_node), - librdf_node_get_uri(type_node), - librdf_node_get_uri(binary_node)); + SLV2Value binary = slv2_plugin_get_unique( + p, + librdf_new_node_from_node(ui), + librdf_new_node_from_uri_string(p->world->world, NS_UI "binary")); - raptor_sequence_push(result, ui); + if (!librdf_node_is_resource(ui) + || !slv2_value_is_uri(type) + || !slv2_value_is_uri(binary)) { + SLV2_ERROR("Corrupt UI\n"); + continue; + } + + SLV2UI slv2_ui = slv2_ui_new(p->world, + librdf_node_get_uri(ui), + slv2_value_as_librdf_uri(type), + slv2_value_as_librdf_uri(binary)); - librdf_free_node(uri_node); - librdf_free_node(type_node); - librdf_free_node(binary_node); + raptor_sequence_push(result, slv2_ui); - librdf_query_results_next(results->rdf_results); + slv2_value_free(binary); + slv2_value_free(type); } - - slv2_results_free(results); + librdf_free_stream(uis); if (slv2_uis_size(result) > 0) { return result; -- cgit v1.2.1