summaryrefslogtreecommitdiffstats
path: root/src/world.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/world.c')
-rw-r--r--src/world.c116
1 files changed, 58 insertions, 58 deletions
diff --git a/src/world.c b/src/world.c
index 88a1f63..d905e52 100644
--- a/src/world.c
+++ b/src/world.c
@@ -1,6 +1,6 @@
/* SLV2
* Copyright (C) 2007 Dave Robillard <http://drobilla.net>
- *
+ *
* This library is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 2 of the License, or (at your option)
@@ -44,7 +44,7 @@ slv2_world_new_internal(SLV2World world)
world->storage = librdf_new_storage(world->world, "hashes", NULL,
"hash-type='memory'");
}
-
+
if (!world->storage)
goto fail;
@@ -57,27 +57,27 @@ slv2_world_new_internal(SLV2World world)
goto fail;
world->plugin_classes = slv2_plugin_classes_new();
-
+
world->plugins = slv2_plugins_new();
-
+
world->lv2_specification_node = librdf_new_node_from_uri_string(world->world,
(const unsigned char*)"http://lv2plug.in/ns/lv2core#Specification");
-
+
world->lv2_plugin_node = librdf_new_node_from_uri_string(world->world,
(const unsigned char*)"http://lv2plug.in/ns/lv2core#Plugin");
-
+
world->rdf_a_node = librdf_new_node_from_uri_string(world->world,
(const unsigned char*)"http://www.w3.org/1999/02/22-rdf-syntax-ns#type");
-
+
world->xsd_integer_node = librdf_new_node_from_uri_string(world->world,
(const unsigned char*)"http://www.w3.org/2001/XMLSchema#integer");
-
+
world->xsd_decimal_node = librdf_new_node_from_uri_string(world->world,
(const unsigned char*)"http://www.w3.org/2001/XMLSchema#decimal");
-
+
world->lv2_plugin_class = slv2_plugin_class_new(world, NULL,
librdf_node_get_uri(world->lv2_plugin_node), "Plugin");
-
+
return world;
fail:
@@ -96,11 +96,11 @@ slv2_world_new()
free(world);
return NULL;
}
-
+
world->local_world = true;
-
+
librdf_world_open(world->world);
-
+
return slv2_world_new_internal(world);
}
@@ -136,24 +136,24 @@ slv2_world_free(SLV2World world)
slv2_plugin_free(raptor_sequence_get_at(world->plugins, i));
raptor_free_sequence(world->plugins);
world->plugins = NULL;
-
+
raptor_free_sequence(world->plugin_classes);
world->plugin_classes = NULL;
-
+
librdf_free_parser(world->parser);
world->parser = NULL;
-
+
librdf_free_model(world->model);
world->model = NULL;
-
+
librdf_free_storage(world->storage);
world->storage = NULL;
-
+
if (world->local_world)
librdf_free_world(world->world);
world->world = NULL;
-
+
free(world);
}
@@ -181,7 +181,7 @@ slv2_world_load_bundle(SLV2World world, SLV2Value bundle_uri)
librdf_model* manifest_model = librdf_new_model(world->world,
manifest_storage, NULL);
- librdf_parser_parse_into_model(world->parser, manifest_uri, NULL,
+ librdf_parser_parse_into_model(world->parser, manifest_uri, NULL,
manifest_model);
/* Query statement: ?plugin a lv2:Plugin */
@@ -198,16 +198,16 @@ slv2_world_load_bundle(SLV2World world, SLV2Value bundle_uri)
/* Add ?plugin rdfs:seeAlso <manifest.ttl>*/
librdf_node* subject = plugin_node;
- librdf_node* predicate = librdf_new_node_from_uri_string(world->world,
+ librdf_node* predicate = librdf_new_node_from_uri_string(world->world,
(unsigned char*)"http://www.w3.org/2000/01/rdf-schema#seeAlso");
librdf_node* object = librdf_new_node_from_uri(world->world,
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,
+ 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->val.uri_val);
@@ -215,10 +215,10 @@ slv2_world_load_bundle(SLV2World world, SLV2Value bundle_uri)
librdf_stream_next(results);
}
-
+
librdf_free_stream(results);
librdf_free_statement(q);
-
+
/* Query statement: ?specification a lv2:Specification */
q = librdf_new_statement_from_nodes(world->world,
NULL, librdf_new_node_from_node(world->rdf_a_node),
@@ -233,16 +233,16 @@ slv2_world_load_bundle(SLV2World world, SLV2Value bundle_uri)
/* Add ?specification rdfs:seeAlso <manifest.ttl> */
librdf_node* subject = spec_node;
- librdf_node* predicate = librdf_new_node_from_uri_string(world->world,
+ librdf_node* predicate = librdf_new_node_from_uri_string(world->world,
(unsigned char*)"http://www.w3.org/2000/01/rdf-schema#seeAlso");
librdf_node* object = librdf_new_node_from_uri(world->world,
manifest_uri);
-
+
librdf_model_add(world->model, subject, predicate, object);
-
+
/* Add ?specification slv2:bundleURI <file://some/path> */
subject = librdf_new_node_from_node(spec_node);
- predicate = librdf_new_node_from_uri_string(world->world,
+ 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->val.uri_val);
@@ -250,10 +250,10 @@ slv2_world_load_bundle(SLV2World world, SLV2Value bundle_uri)
librdf_stream_next(results);
}
-
+
librdf_free_stream(results);
librdf_free_statement(q);
-
+
/* Join the temporary model to the main model */
librdf_stream* manifest_stream = librdf_model_as_stream(manifest_model);
librdf_model_add_statements(world->model, manifest_stream);
@@ -274,7 +274,7 @@ slv2_world_load_directory(SLV2World world, const char* dir)
DIR* pdir = opendir(dir);
if (!pdir)
return;
-
+
struct dirent* pfile;
while ((pfile = readdir(pdir))) {
if (!strcmp(pfile->d_name, ".") || !strcmp(pfile->d_name, ".."))
@@ -291,7 +291,7 @@ slv2_world_load_directory(SLV2World world, const char* dir)
slv2_world_load_bundle(world, uri_val);
slv2_value_free(uri_val);
}
-
+
free(uri);
}
@@ -305,19 +305,19 @@ slv2_world_load_path(SLV2World world,
{
char* path = slv2_strjoin(lv2_path, ":", NULL);
char* dir = path; // Pointer into path
-
+
// Go through string replacing ':' with '\0', using the substring,
// then replacing it with 'X' and moving on. i.e. strtok on crack.
while (strchr(path, ':') != NULL) {
char* delim = strchr(path, ':');
*delim = '\0';
-
+
slv2_world_load_directory(world, dir);
-
+
*delim = 'X';
dir = delim + 1;
}
-
+
free(path);
}
@@ -356,9 +356,9 @@ slv2_world_load_specifications(SLV2World world)
" ?spec a :Specification ;\n"
" rdfs:seeAlso ?data .\n"
"}\n";
-
+
librdf_query* q = librdf_new_query(world->world, "sparql", NULL, query_string, NULL);
-
+
librdf_query_results* results = librdf_query_execute(q, world->model);
while (!librdf_query_results_finished(results)) {
@@ -385,9 +385,9 @@ slv2_world_load_plugin_classes(SLV2World world)
{
// FIXME: This will need to be a bit more clever when more data is around
// then the ontology (ie classes which aren't LV2 plugin_classes)
-
+
// FIXME: This loads things that aren't plugin categories
-
+
unsigned char* query_string = (unsigned char*)
"PREFIX : <http://lv2plug.in/ns/lv2core#>\n"
"PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>\n"
@@ -395,10 +395,10 @@ slv2_world_load_plugin_classes(SLV2World world)
//" ?plugin a ?class .\n"
" ?class a rdfs:Class; rdfs:subClassOf ?parent; rdfs:label ?label\n"
"}\n"; // ORDER BY ?class\n";
-
+
librdf_query* q = librdf_new_query(world->world, "sparql",
NULL, query_string, NULL);
-
+
librdf_query_results* results = librdf_query_execute(q, world->model);
while (!librdf_query_results_finished(results)) {
@@ -425,7 +425,7 @@ slv2_world_load_plugin_classes(SLV2World world)
}
// FIXME: filter list here
-
+
librdf_free_query_results(results);
librdf_free_query(q);
}
@@ -463,7 +463,7 @@ slv2_world_load_all(SLV2World world)
free(lv2_path);
}
-
+
/* 2. Query out things to cache */
slv2_world_load_specifications(world);
@@ -478,10 +478,10 @@ slv2_world_load_all(SLV2World world)
"SELECT DISTINCT ?plugin ?data ?bundle\n"
"WHERE { ?plugin a :Plugin; slv2:bundleURI ?bundle; rdfs:seeAlso ?data }\n";
//"ORDER BY ?plugin\n";
-
+
librdf_query* q = librdf_new_query(world->world, "sparql",
NULL, query_string, NULL);
-
+
librdf_query_results* results = librdf_query_execute(q, world->model);
while (!librdf_query_results_finished(results)) {
@@ -524,7 +524,7 @@ slv2_world_load_all(SLV2World world)
if (results)
librdf_free_query_results(results);
-
+
librdf_free_query(q);
}
@@ -535,7 +535,7 @@ slv2_world_serialize(const char* filename)
{
librdf_uri* lv2_uri = librdf_new_uri(slv2_rdf_world,
(unsigned char*)"http://lv2plug.in/ns/lv2core#");
-
+
librdf_uri* rdfs_uri = librdf_new_uri(slv2_rdf_world,
(unsigned char*)"http://www.w3.org/2000/01/rdf-schema#");
@@ -590,17 +590,17 @@ slv2_world_get_plugins_by_filter(SLV2World world, bool (*include)(SLV2Plugin))
SLV2Plugins
slv2_world_get_plugins_by_query(SLV2World world, const char* query)
{
- SLV2Plugins list = slv2_plugins_new();
+ SLV2Plugins list = slv2_plugins_new();
librdf_query* rq = librdf_new_query(world->world, "sparql",
NULL, (const unsigned char*)query, NULL);
-
+
librdf_query_results* results = librdf_query_execute(rq, world->model);
-
+
while (!librdf_query_results_finished(results)) {
librdf_node* plugin_node = librdf_query_results_get_binding_value(results, 0);
librdf_uri* plugin_uri = librdf_node_get_uri(plugin_node);
-
+
SLV2Plugin plugin = slv2_plugins_get_by_uri(list,
(const char*)librdf_uri_as_string(plugin_uri));
@@ -609,15 +609,15 @@ slv2_world_get_plugins_by_query(SLV2World world, const char* query)
SLV2Plugin new_plugin = slv2_plugin_new(world, plugin_uri);
raptor_sequence_push(list, new_plugin);
}
-
+
librdf_free_node(plugin_node);
-
+
librdf_query_results_next(results);
- }
-
+ }
+
if (results)
librdf_free_query_results(results);
-
+
librdf_free_query(rq);
return list;