diff options
-rw-r--r-- | slv2/plugin.h | 38 | ||||
-rw-r--r-- | slv2/value.h | 2 | ||||
-rw-r--r-- | src/plugin.c | 56 | ||||
-rw-r--r-- | src/plugininstance.c | 5 | ||||
-rw-r--r-- | src/slv2_internal.h | 6 | ||||
-rw-r--r-- | src/world.c | 26 | ||||
-rw-r--r-- | utils/lv2_inspect.c | 1 |
7 files changed, 108 insertions, 26 deletions
diff --git a/slv2/plugin.h b/slv2/plugin.h index 36add35..f77ca16 100644 --- a/slv2/plugin.h +++ b/slv2/plugin.h @@ -80,8 +80,29 @@ const char* slv2_plugin_get_uri(SLV2Plugin plugin); +/** Get the (resolvable) URI of the plugins "main" bundle. + * + * This returns the URI of the bundle where the plugin itself was found. + * Note that the data for a plugin may be spread over many bundles, that is, + * slv2_plugin_get_data_uris may returns URIs which are not below this one. + * + * Typical hosts should not need to use this function. + * + * Note this always returns a fully qualified URI. If you want a local + * filesystem path, use slv2_uri_to_path. + * + * \return a shared string which must not be modified or freed. + * + * Time = O(1) + */ +const char* +slv2_plugin_get_bundle_uri(SLV2Plugin plugin); + + /** Get the (resolvable) URIs of the RDF data files that define a plugin. * + * Typical hosts should not need to use this function. + * * Note this always returns fully qualified URIs. If you want local * filesystem paths, use slv2_uri_to_path. * @@ -340,6 +361,9 @@ slv2_plugin_get_guis(SLV2Plugin plugin); * \param plugin The plugin that the GUI is for. * \param gui A GUI identifier as returned by slv2_plugin_get_guis() (with type SLV2_VALUE_GUI). * + * This function if provided for completeness, but if you want to load a GUI + * as easily as possible, use slv2_plugin_load_gui. + * * Time = Query */ SLV2Value @@ -347,6 +371,20 @@ slv2_plugin_get_gui_library_uri(SLV2Plugin plugin, SLV2Value gui); +/** Load and instantiate a plugin GUI. + * + * The type returned depends on the type of the GUI. For SLV2_GTK2_GUI, the + * return value must be cast to LV2UI_Handle. + * + * NULL returned on error. + * + * Time = Query + O(# of GUIs in GUI shared library) + */ +void* +slv2_plugin_load_gui(SLV2Plugin plugin, + SLV2Value gui); + + /** @} */ #ifdef __cplusplus diff --git a/slv2/value.h b/slv2/value.h index 4fd0cf4..f2db361 100644 --- a/slv2/value.h +++ b/slv2/value.h @@ -57,7 +57,7 @@ slv2_value_equals(SLV2Value value, SLV2Value other); * 1.0 * 1 * - * Returned string is newly allocation and must be freed by caller. + * Returned string is newly allocation and must be freed by caller. */ char* slv2_value_get_turtle_token(SLV2Value value); diff --git a/src/plugin.c b/src/plugin.c index 6e09161..80f59a5 100644 --- a/src/plugin.c +++ b/src/plugin.c @@ -33,12 +33,13 @@ /* private */ SLV2Plugin -slv2_plugin_new(SLV2World world, librdf_uri* uri, const char* binary_uri) +slv2_plugin_new(SLV2World world, librdf_uri* uri, librdf_uri* bundle_uri, librdf_uri* binary_uri) { struct _SLV2Plugin* plugin = malloc(sizeof(struct _SLV2Plugin)); plugin->world = world; plugin->plugin_uri = librdf_new_uri_from_uri(uri); - plugin->binary_uri = strdup(binary_uri); + plugin->bundle_uri = librdf_new_uri_from_uri(bundle_uri); + plugin->binary_uri = librdf_new_uri_from_uri(binary_uri); plugin->plugin_class = NULL; plugin->data_uris = slv2_values_new(); plugin->ports = raptor_new_sequence((void (*)(void*))&slv2_port_free, NULL); @@ -56,8 +57,11 @@ slv2_plugin_free(SLV2Plugin p) librdf_free_uri(p->plugin_uri); p->plugin_uri = NULL; - //free(p->bundle_url); - free(p->binary_uri); + librdf_free_uri(p->bundle_uri); + p->bundle_uri = NULL; + + librdf_free_uri(p->binary_uri); + p->binary_uri = NULL; raptor_free_sequence(p->ports); p->ports = NULL; @@ -73,6 +77,7 @@ slv2_plugin_free(SLV2Plugin p) } slv2_values_free(p->data_uris); + p->data_uris = NULL; free(p); } @@ -238,17 +243,24 @@ slv2_plugin_get_uri(SLV2Plugin p) } -SLV2Values -slv2_plugin_get_data_uris(SLV2Plugin p) +const char* +slv2_plugin_get_bundle_uri(SLV2Plugin p) { - return p->data_uris; + return (const char*)librdf_uri_as_string(p->bundle_uri); } const char* slv2_plugin_get_library_uri(SLV2Plugin p) { - return p->binary_uri; + return (const char*)librdf_uri_as_string(p->binary_uri); +} + + +SLV2Values +slv2_plugin_get_data_uris(SLV2Plugin p) +{ + return p->data_uris; } @@ -387,22 +399,25 @@ slv2_plugin_get_value_for_subject(SLV2Plugin p, /* Hack around broken RASQAL, full URI predicates don't work :/ */ + char* subject_token = slv2_value_get_turtle_token(subject); + if (predicate_type == SLV2_URI) { query = slv2_strjoin( "PREFIX slv2predicate: <", predicate, ">", "SELECT DISTINCT ?value WHERE { \n", - slv2_value_get_turtle_token(subject), " slv2predicate: ?value \n" + subject_token, " slv2predicate: ?value \n" "}\n", NULL); } else { query = slv2_strjoin( "SELECT DISTINCT ?value WHERE { \n", - slv2_value_get_turtle_token(subject), " ", predicate, " ?value \n" + subject_token, " ", predicate, " ?value \n" "}\n", NULL); } SLV2Values result = slv2_plugin_simple_query(p, query, 0); free(query); + free(subject_token); return result; } @@ -442,9 +457,11 @@ slv2_plugin_has_latency(SLV2Plugin p) " lv2:index ?index .\n" "}\n"; - SLV2Values result = slv2_plugin_simple_query(p, query, 0); + SLV2Values results = slv2_plugin_simple_query(p, query, 0); + const bool latent = (slv2_values_size(results) > 0); + slv2_values_free(results); - return (slv2_values_size(result) > 0); + return latent; } @@ -599,3 +616,18 @@ slv2_gui_type_get_uri(SLV2GUIType type) return "http://ll-plugins.nongnu.org/lv2/ext/gtk2gui"; } + +void* +slv2_plugin_load_gui(SLV2Plugin plugin, + SLV2Value gui) +{ + SLV2Value lib_uri = slv2_plugin_get_gui_library_uri(plugin, gui); + + if (!lib_uri) + return NULL; + + //LV2UI_Handle handle = + // + return NULL; +} + diff --git a/src/plugininstance.c b/src/plugininstance.c index d989ef6..90af196 100644 --- a/src/plugininstance.c +++ b/src/plugininstance.c @@ -67,10 +67,7 @@ slv2_plugin_instantiate(SLV2Plugin plugin, // Search for plugin by URI // FIXME: Kluge to get bundle path (containing directory of binary) - char* bundle_path = strdup(plugin->binary_uri); - char* const bundle_path_end = strrchr(bundle_path, '/'); - if (bundle_path_end) - *(bundle_path_end+1) = '\0'; + char* bundle_path = slv2_uri_to_path(strdup(slv2_plugin_get_bundle_uri(plugin))); printf("Bundle path: %s\n", bundle_path); for (uint32_t i=0; 1; ++i) { diff --git a/src/slv2_internal.h b/src/slv2_internal.h index 89325ca..ca1e002 100644 --- a/src/slv2_internal.h +++ b/src/slv2_internal.h @@ -59,8 +59,8 @@ void slv2_port_free(SLV2Port port); struct _SLV2Plugin { struct _SLV2World* world; librdf_uri* plugin_uri; -// char* bundle_url; ///< Bundle directory plugin was loaded from - char* binary_uri; ///< lv2:binary + librdf_uri* bundle_uri; ///< Bundle directory plugin was loaded from + librdf_uri* binary_uri; ///< lv2:binary SLV2PluginClass plugin_class; raptor_sequence* data_uris; ///< rdfs::seeAlso raptor_sequence* ports; @@ -68,7 +68,7 @@ struct _SLV2Plugin { librdf_model* rdf; }; -SLV2Plugin slv2_plugin_new(SLV2World world, librdf_uri* uri, const char* binary_uri); +SLV2Plugin slv2_plugin_new(SLV2World world, librdf_uri* uri, librdf_uri* bundle_uri, librdf_uri* binary_uri); void slv2_plugin_load(SLV2Plugin p); void slv2_plugin_free(SLV2Plugin plugin); diff --git a/src/world.c b/src/world.c index 57bea81..dc2be1a 100644 --- a/src/world.c +++ b/src/world.c @@ -143,6 +143,7 @@ slv2_world_load_bundle(SLV2World world, const char* bundle_uri_str) librdf_parser_parse_into_model(world->parser, manifest_uri, NULL, manifest_model); + /* Query statement: ?plugin a lv2:Plugin */ librdf_statement* q = librdf_new_statement_from_nodes(world->world, NULL, world->rdf_a_node, world->lv2_plugin_node); @@ -151,8 +152,9 @@ slv2_world_load_bundle(SLV2World world, const char* bundle_uri_str) while (!librdf_stream_end(results)) { librdf_statement* s = librdf_stream_get_object(results); - librdf_node* plugin_node = librdf_statement_get_subject(s); + librdf_node* plugin_node = librdf_new_node_from_node(librdf_statement_get_subject(s)); + /* Add ?plugin rdfs:seeAlso "datafile.ttl" */ librdf_node* subject = plugin_node; librdf_node* predicate = librdf_new_node_from_uri_string(world->world, (unsigned char*)"http://www.w3.org/2000/01/rdf-schema#seeAlso"); @@ -160,6 +162,14 @@ slv2_world_load_bundle(SLV2World world, const char* bundle_uri_str) manifest_uri); librdf_model_add(world->model, subject, predicate, object); + + /* Add ?plugin slv2:bundleURI "file://some/path" */ + subject = librdf_new_node_from_node(plugin_node); + predicate = librdf_new_node_from_uri_string(world->world, + (unsigned char*)"http://drobilla.net/ns/slv2#bundleURI"); + object = librdf_new_node_from_uri(world->world, bundle_uri); + + librdf_model_add(world->model, subject, predicate, object); librdf_stream_next(results); } @@ -172,6 +182,7 @@ slv2_world_load_bundle(SLV2World world, const char* bundle_uri_str) librdf_free_stream(manifest_stream); librdf_free_model(manifest_model); + free(q); librdf_free_storage(manifest_storage); librdf_free_uri(manifest_uri); librdf_free_uri(bundle_uri); @@ -345,8 +356,9 @@ slv2_world_load_all(SLV2World world) unsigned char* query_string = (unsigned char*) "PREFIX : <http://lv2plug.in/ontology#>\n" "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>\n" - "SELECT DISTINCT ?plugin ?data ?binary\n" - "WHERE { ?plugin a :Plugin; rdfs:seeAlso ?data\n" + "PREFIX slv2: <http://drobilla.net/ns/slv2#>\n" + "SELECT DISTINCT ?plugin ?data ?bundle ?binary\n" + "WHERE { ?plugin a :Plugin; slv2:bundleURI ?bundle; rdfs:seeAlso ?data\n" "OPTIONAL { ?plugin :binary ?binary } }\n" "ORDER BY ?plugin\n"; @@ -361,7 +373,9 @@ slv2_world_load_all(SLV2World world) librdf_uri* plugin_uri = librdf_node_get_uri(plugin_node); librdf_node* data_node = librdf_query_results_get_binding_value(results, 1); librdf_uri* data_uri = librdf_node_get_uri(data_node); - librdf_node* binary_node = librdf_query_results_get_binding_value(results, 2); + librdf_node* bundle_node = librdf_query_results_get_binding_value(results, 2); + librdf_uri* bundle_uri = librdf_node_get_uri(bundle_node); + librdf_node* binary_node = librdf_query_results_get_binding_value(results, 3); librdf_uri* binary_uri = librdf_node_get_uri(binary_node); SLV2Plugin plugin = slv2_plugins_get_by_uri(world->plugins, @@ -369,8 +383,7 @@ slv2_world_load_all(SLV2World world) // Create a new SLV2Plugin if (!plugin) { - plugin = slv2_plugin_new(world, plugin_uri, - (const char*)librdf_uri_as_string(binary_uri)); + plugin = slv2_plugin_new(world, plugin_uri, bundle_uri, binary_uri); raptor_sequence_push(world->plugins, plugin); } @@ -382,6 +395,7 @@ slv2_world_load_all(SLV2World world) librdf_free_node(plugin_node); librdf_free_node(data_node); + librdf_free_node(bundle_node); librdf_free_node(binary_node); librdf_query_results_next(results); diff --git a/utils/lv2_inspect.c b/utils/lv2_inspect.c index a4ae66b..a3b1b5d 100644 --- a/utils/lv2_inspect.c +++ b/utils/lv2_inspect.c @@ -107,6 +107,7 @@ print_plugin(SLV2Plugin p) printf("\tHas latency: no\n\n"); } + printf("\tBundle: %s\n\n", slv2_plugin_get_bundle_uri(p)); printf("\tBinary: %s\n\n", slv2_plugin_get_library_uri(p)); SLV2Values gui = slv2_plugin_get_guis(p); |