diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/plugin.c | 12 | ||||
-rw-r--r-- | src/plugininstance.c | 9 | ||||
-rw-r--r-- | src/pluginlist.c | 8 | ||||
-rw-r--r-- | src/private_types.h | 27 | ||||
-rw-r--r-- | src/world.c | 57 |
5 files changed, 79 insertions, 34 deletions
diff --git a/src/plugin.c b/src/plugin.c index b3577f2..722caa1 100644 --- a/src/plugin.c +++ b/src/plugin.c @@ -37,7 +37,7 @@ slv2_plugin_new(SLV2World world, librdf_uri* uri, const char* binary_uri) plugin->world = world; plugin->plugin_uri = librdf_new_uri_from_uri(uri); plugin->binary_uri = strdup(binary_uri); - plugin->data_uris = raptor_new_sequence((void (*)(void*))&raptor_free_uri, NULL); + plugin->data_uris = slv2_strings_new(); plugin->ports = raptor_new_sequence((void (*)(void*))&slv2_port_free, NULL); plugin->storage = NULL; plugin->rdf = NULL; @@ -69,7 +69,7 @@ slv2_plugin_free(SLV2Plugin p) p->storage = NULL; } - raptor_free_sequence(p->data_uris); + slv2_strings_free(p->data_uris); free(p); } @@ -81,6 +81,7 @@ slv2_plugin_query(SLV2Plugin plugin, const char* sparql_str); +/* SLV2Plugin slv2_plugin_duplicate(SLV2Plugin p) { @@ -105,6 +106,7 @@ slv2_plugin_duplicate(SLV2Plugin p) return result; } +*/ /** comparator for sorting */ @@ -136,9 +138,11 @@ slv2_plugin_load(SLV2Plugin p) } // Parse all the plugin's data files into RDF model - for (int i=0; i < raptor_sequence_size(p->data_uris); ++i) { - librdf_uri* data_uri = raptor_sequence_get_at(p->data_uris, i); + for (unsigned i=0; i < slv2_strings_size(p->data_uris); ++i) { + const char* data_uri_str = slv2_strings_get_at(p->data_uris, i); + librdf_uri* data_uri = librdf_new_uri(p->world->world, (const unsigned char*)data_uri_str); librdf_parser_parse_into_model(p->world->parser, data_uri, NULL, p->rdf); + librdf_free_uri(data_uri); } // Load ports diff --git a/src/plugininstance.c b/src/plugininstance.c index 6d957b6..013e33c 100644 --- a/src/plugininstance.c +++ b/src/plugininstance.c @@ -16,6 +16,8 @@ * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ +#define _XOPEN_SOURCE 500 + #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -65,7 +67,10 @@ slv2_plugin_instantiate(SLV2Plugin plugin, // Search for plugin by URI // FIXME: Kluge to get bundle path (containing directory of binary) - const char* const bundle_path = strrchr(plugin->binary_uri, '/') + 1; + char* bundle_path = strdup(plugin->binary_uri); + char* const bundle_path_end = strrchr(bundle_path, '/'); + if (bundle_path_end) + *(bundle_path_end+1) = '\0'; printf("Bundle path: %s\n", bundle_path); for (uint32_t i=0; 1; ++i) { @@ -95,6 +100,8 @@ slv2_plugin_instantiate(SLV2Plugin plugin, break; } } + + free(bundle_path); } assert(result); diff --git a/src/pluginlist.c b/src/pluginlist.c index 50bb2ad..d4cd058 100644 --- a/src/pluginlist.c +++ b/src/pluginlist.c @@ -36,14 +36,16 @@ SLV2Plugins slv2_plugins_new() { - return raptor_new_sequence((void (*)(void*))&slv2_plugin_free, NULL); + //return raptor_new_sequence((void (*)(void*))&slv2_plugin_free, NULL); + return raptor_new_sequence(NULL, NULL); } void -slv2_plugins_free(SLV2Plugins list) +slv2_plugins_free(SLV2World world, SLV2Plugins list) { - raptor_free_sequence(list); + if (list != world->plugins) + raptor_free_sequence(list); } #if 0 diff --git a/src/private_types.h b/src/private_types.h index 8f2f89d..48bed0a 100644 --- a/src/private_types.h +++ b/src/private_types.h @@ -37,6 +37,7 @@ struct _Port { //char* node_id; ///< RDF Node ID }; + SLV2Port slv2_port_new(uint32_t index, const char* symbol/*, const char* node_id*/); SLV2Port slv2_port_duplicate(SLV2Port port); void slv2_port_free(SLV2Port port); @@ -60,13 +61,16 @@ struct _Plugin { SLV2Plugin slv2_plugin_new(SLV2World world, librdf_uri* uri, const char* binary_uri); void slv2_plugin_load(SLV2Plugin p); +void slv2_plugin_free(SLV2Plugin plugin); -/** List of references to plugins available for loading */ -struct _PluginList { - size_t num_plugins; - struct _Plugin** plugins; -}; +/** Create a new, empty plugin list. + * + * Returned object must be freed with slv2_plugins_free. + */ +SLV2Plugins +slv2_plugins_new(); + /** Pimpl portion of SLV2Instance */ struct _InstanceImpl { @@ -84,6 +88,19 @@ struct _World { SLV2Plugins plugins; }; +/** Load all bundles found in \a search_path. + * + * \param search_path A colon-delimited list of directories. These directories + * should contain LV2 bundle directories (ie the search path is a list of + * parent directories of bundles, not a list of bundle directories). + * + * If \a search_path is NULL, \a world will be unmodified. + * Use of this function is \b not recommended. Use \ref slv2_world_load_all. + */ +void +slv2_world_load_path(SLV2World world, + const char* search_path); + #ifdef __cplusplus } diff --git a/src/world.c b/src/world.c index afb71ad..e10e7d4 100644 --- a/src/world.c +++ b/src/world.c @@ -59,7 +59,9 @@ slv2_world_free(SLV2World world) /*raptor_free_uri(slv2_ontology_uri); slv2_ontology_uri = NULL;*/ - slv2_plugins_free(world->plugins); + for (int i=0; i < raptor_sequence_size(world->plugins); ++i) + slv2_plugin_free(raptor_sequence_get_at(world->plugins, i)); + raptor_free_sequence(world->plugins); world->plugins = NULL; librdf_free_parser(world->parser); @@ -78,7 +80,25 @@ slv2_world_free(SLV2World world) } -/* private */ +void +slv2_world_load_bundle(SLV2World world, const char* bundle_uri_str) +{ + librdf_uri* bundle_uri = librdf_new_uri(world->world, + (const unsigned char*)bundle_uri_str); + + librdf_uri* manifest_uri = librdf_new_uri_relative_to_base( + bundle_uri, (const unsigned char*)"manifest.ttl"); + + librdf_parser_parse_into_model(world->parser, manifest_uri, NULL, world->model); + + librdf_free_uri(manifest_uri); + librdf_free_uri(bundle_uri); +} + + +/** Load all bundles under a directory. + * Private. + */ void slv2_world_load_directory(SLV2World world, const char* dir) { @@ -91,24 +111,17 @@ slv2_world_load_directory(SLV2World world, const char* dir) if (!strcmp(pfile->d_name, ".") || !strcmp(pfile->d_name, "..")) continue; - char* bundle_uri_str = slv2_strjoin("file://", dir, "/", pfile->d_name, "/", NULL); - librdf_uri* bundle_uri = librdf_new_uri(world->world, (unsigned char*)bundle_uri_str); + char* uri = slv2_strjoin("file://", dir, "/", pfile->d_name, "/", NULL); - DIR* bundle_dir = opendir(bundle_uri_str + 7); + // FIXME: Probably a better way to check if a dir exists + DIR* bundle_dir = opendir(uri + 7); if (bundle_dir != NULL) { closedir(bundle_dir); - - librdf_uri* manifest_uri = librdf_new_uri_relative_to_base( - bundle_uri, (const unsigned char*)"manifest.ttl"); - - librdf_parser_parse_into_model(world->parser, manifest_uri, NULL, world->model); - - librdf_free_uri(manifest_uri); + slv2_world_load_bundle(world, uri); } - free(bundle_uri_str); - librdf_free_uri(bundle_uri); + free(uri); } closedir(pdir); @@ -155,7 +168,8 @@ slv2_world_load_all(SLV2World world) { char* lv2_path = getenv("LV2_PATH"); - // Read all manifest files + /* 1. Read all manifest files into model */ + if (lv2_path) { slv2_world_load_path(world, lv2_path); } else { @@ -171,6 +185,8 @@ slv2_world_load_all(SLV2World world) } + /* 2. Query out things to cache */ + // Find all plugins and associated data files unsigned char* query_string = (unsigned char*) "PREFIX : <http://lv2plug.in/ontology#>\n" @@ -205,7 +221,8 @@ slv2_world_load_all(SLV2World world) plugin->world = world; // FIXME: check for duplicates - raptor_sequence_push(plugin->data_uris, librdf_new_uri_from_uri(data_uri)); + raptor_sequence_push(plugin->data_uris, + strdup((const char*)librdf_uri_as_string(data_uri))); raptor_sequence_push(world->plugins, plugin); @@ -267,16 +284,14 @@ slv2_world_get_all_plugins(SLV2World world) SLV2Plugins slv2_world_get_plugins_by_filter(SLV2World world, bool (*include)(SLV2Plugin)) { - SLV2Plugins all = slv2_world_get_all_plugins(world); SLV2Plugins result = slv2_plugins_new(); - for (int i=0; i < raptor_sequence_size(all); ++i) { - SLV2Plugin p = raptor_sequence_get_at(all, i); + for (int i=0; i < raptor_sequence_size(world->plugins); ++i) { + SLV2Plugin p = raptor_sequence_get_at(world->plugins, i); if (include(p)) - raptor_sequence_push(result, slv2_plugin_duplicate(p)); + raptor_sequence_push(result, p); } - slv2_plugins_free(all); return result; } |