summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/plugin.c44
-rw-r--r--src/port.c18
-rw-r--r--src/query.c4
-rw-r--r--src/slv2_internal.h25
-rw-r--r--src/world.c64
5 files changed, 81 insertions, 74 deletions
diff --git a/src/plugin.c b/src/plugin.c
index ec39749..fd58ab3 100644
--- a/src/plugin.c
+++ b/src/plugin.c
@@ -118,18 +118,18 @@ slv2_plugin_query_node(SLV2Plugin p, SLV2Node subject, SLV2Node predicate)
p, subject, predicate, NULL);
if (slv2_matches_end(results)) {
- END_MATCH(results);
+ slv2_match_end(results);
return NULL;
}
SLV2Values result = slv2_values_new();
FOREACH_MATCH(results) {
- SLV2Node node = MATCH_OBJECT(results);
+ SLV2Node node = slv2_match_object(results);
SLV2Value value = slv2_value_new_from_node(p->world, node);
if (value)
raptor_sequence_push(result, value);
}
- END_MATCH(results);
+ slv2_match_end(results);
return result;
}
@@ -181,7 +181,7 @@ slv2_plugin_load_ports_if_necessary(SLV2Plugin p)
NULL);
FOREACH_MATCH(ports) {
- SLV2Node port = MATCH_OBJECT(ports);
+ SLV2Node port = slv2_match_object(ports);
SLV2Value symbol = slv2_plugin_get_unique(
p, port, p->world->lv2_symbol_node);
@@ -222,7 +222,7 @@ slv2_plugin_load_ports_if_necessary(SLV2Plugin p)
SLV2Matches types = slv2_plugin_find_statements(
p, port, p->world->rdf_a_node, NULL);
FOREACH_MATCH(types) {
- SLV2Node type = MATCH_OBJECT(types);
+ SLV2Node type = slv2_match_object(types);
if (librdf_node_is_resource(type)) {
raptor_sequence_push(
this_port->classes,
@@ -231,7 +231,7 @@ slv2_plugin_load_ports_if_necessary(SLV2Plugin p)
SLV2_WARN("port has non-URI rdf:type\n");
}
}
- END_MATCH(types);
+ slv2_match_end(types);
error:
slv2_value_free(symbol);
@@ -246,7 +246,7 @@ slv2_plugin_load_ports_if_necessary(SLV2Plugin p)
break; // Invalid plugin
}
}
- END_MATCH(ports);
+ slv2_match_end(ports);
}
}
@@ -340,13 +340,13 @@ slv2_plugin_get_library_uri(SLV2Plugin p)
p->world->lv2_binary_node,
NULL);
FOREACH_MATCH(results) {
- SLV2Node binary_node = MATCH_OBJECT(results);
+ SLV2Node binary_node = slv2_match_object(results);
if (librdf_node_is_resource(binary_node)) {
p->binary_uri = slv2_value_new_from_node(p->world, binary_node);
break;
}
}
- END_MATCH(results);
+ slv2_match_end(results);
}
return p->binary_uri;
}
@@ -371,7 +371,7 @@ slv2_plugin_get_class(SLV2Plugin p)
p->world->rdf_a_node,
NULL);
FOREACH_MATCH(results) {
- SLV2Node class_node = slv2_node_copy(MATCH_OBJECT(results));
+ SLV2Node class_node = slv2_node_copy(slv2_match_object(results));
if (!librdf_node_is_resource(class_node)) {
continue;
}
@@ -393,7 +393,7 @@ slv2_plugin_get_class(SLV2Plugin p)
slv2_value_free(class);
}
- END_MATCH(results);
+ slv2_match_end(results);
if (p->plugin_class == NULL)
p->plugin_class = p->world->lv2_plugin_class;
@@ -616,20 +616,20 @@ slv2_plugin_has_latency(SLV2Plugin p)
bool ret = false;
FOREACH_MATCH(ports) {
- SLV2Node port = MATCH_OBJECT(ports);
+ SLV2Node port = slv2_match_object(ports);
SLV2Matches reports_latency = slv2_plugin_find_statements(
p,
port,
p->world->lv2_portproperty_node,
p->world->lv2_reportslatency_node);
const bool end = slv2_matches_end(reports_latency);
- END_MATCH(reports_latency);
+ slv2_match_end(reports_latency);
if (!end) {
ret = true;
break;
}
}
- END_MATCH(ports);
+ slv2_match_end(ports);
return ret;
}
@@ -646,7 +646,7 @@ slv2_plugin_get_latency_port_index(SLV2Plugin p)
uint32_t ret = 0;
FOREACH_MATCH(ports) {
- SLV2Node port = MATCH_OBJECT(ports);
+ SLV2Node port = slv2_match_object(ports);
SLV2Matches reports_latency = slv2_plugin_find_statements(
p,
port,
@@ -658,12 +658,12 @@ slv2_plugin_get_latency_port_index(SLV2Plugin p)
ret = slv2_value_as_int(index);
slv2_value_free(index);
- END_MATCH(reports_latency);
+ slv2_match_end(reports_latency);
break;
}
- END_MATCH(reports_latency);
+ slv2_match_end(reports_latency);
}
- END_MATCH(ports);
+ slv2_match_end(ports);
return ret; // FIXME: error handling
}
@@ -765,9 +765,9 @@ slv2_plugin_get_author(SLV2Plugin p)
return NULL;
}
- SLV2Node author = slv2_node_copy(MATCH_OBJECT(maintainers));
+ SLV2Node author = slv2_node_copy(slv2_match_object(maintainers));
- END_MATCH(maintainers);
+ slv2_match_end(maintainers);
return author;
}
@@ -827,7 +827,7 @@ slv2_plugin_get_uis(SLV2Plugin p)
NULL);
FOREACH_MATCH(uis) {
- SLV2Node ui = MATCH_OBJECT(uis);
+ SLV2Node ui = slv2_match_object(uis);
SLV2Value type = slv2_plugin_get_unique(
p, ui, p->world->rdf_a_node);
@@ -857,7 +857,7 @@ slv2_plugin_get_uis(SLV2Plugin p)
raptor_sequence_push(result, slv2_ui);
}
- END_MATCH(uis);
+ slv2_match_end(uis);
slv2_node_free(ui_ui);
diff --git a/src/port.c b/src/port.c
index 0ec8dfc..21c5c55 100644
--- a/src/port.c
+++ b/src/port.c
@@ -75,7 +75,7 @@ slv2_port_get_node(SLV2Plugin p,
NULL);
SLV2Node ret = NULL;
FOREACH_MATCH(ports) {
- SLV2Node node = MATCH_OBJECT(ports);
+ SLV2Node node = slv2_match_object(ports);
SLV2Value symbol = slv2_plugin_get_unique(
p,
slv2_node_copy(node),
@@ -90,7 +90,7 @@ slv2_port_get_node(SLV2Plugin p,
break;
}
}
- END_MATCH(ports);
+ slv2_match_end(ports);
assert(ret);
return ret;
}
@@ -110,7 +110,7 @@ slv2_port_has_property(SLV2Plugin p,
slv2_value_as_node(property));
const bool ret = !slv2_matches_end(results);
- END_MATCH(results);
+ slv2_match_end(results);
return ret;
}
@@ -131,7 +131,7 @@ slv2_port_supports_event(SLV2Plugin p,
slv2_value_as_node(event));
const bool ret = !slv2_matches_end(results);
- END_MATCH(results);
+ slv2_match_end(results);
return ret;
}
@@ -140,7 +140,7 @@ static SLV2Values
slv2_values_from_stream_objects(SLV2Plugin p, SLV2Matches stream)
{
if (slv2_matches_end(stream)) {
- END_MATCH(stream);
+ slv2_match_end(stream);
return NULL;
}
@@ -150,9 +150,9 @@ slv2_values_from_stream_objects(SLV2Plugin p, SLV2Matches stream)
values,
slv2_value_new_from_node(
p->world,
- MATCH_OBJECT(stream)));
+ slv2_match_object(stream)));
}
- END_MATCH(stream);
+ slv2_match_end(stream);
return values;
}
@@ -324,7 +324,7 @@ slv2_port_get_scale_points(SLV2Plugin p,
ret = slv2_scale_points_new();
FOREACH_MATCH(points) {
- SLV2Node point = MATCH_OBJECT(points);
+ SLV2Node point = slv2_match_object(points);
SLV2Value value = slv2_plugin_get_unique(
p,
@@ -340,7 +340,7 @@ slv2_port_get_scale_points(SLV2Plugin p,
raptor_sequence_push(ret, slv2_scale_point_new(value, label));
}
}
- END_MATCH(points);
+ slv2_match_end(points);
assert(!ret || slv2_values_size(ret) > 0);
return ret;
diff --git a/src/query.c b/src/query.c
index 9d1088e..5709ffd 100644
--- a/src/query.c
+++ b/src/query.c
@@ -54,7 +54,7 @@ slv2_values_from_stream_i18n(SLV2Plugin p,
SLV2Values values = slv2_values_new();
SLV2Node nolang = NULL;
FOREACH_MATCH(stream) {
- SLV2Node value = MATCH_OBJECT(stream);
+ SLV2Node value = slv2_match_object(stream);
if (librdf_node_is_literal(value)) {
const char* lang = librdf_node_get_literal_value_language(value);
if (lang) {
@@ -69,7 +69,7 @@ slv2_values_from_stream_i18n(SLV2Plugin p,
}
break;
}
- END_MATCH(stream);
+ slv2_match_end(stream);
if (slv2_values_size(values) == 0) {
// No value with a matching language, use untranslated default
diff --git a/src/slv2_internal.h b/src/slv2_internal.h
index 874c3f5..e9847fe 100644
--- a/src/slv2_internal.h
+++ b/src/slv2_internal.h
@@ -43,19 +43,28 @@ extern "C" {
#define SLV2_NS_XSD (const uint8_t*)"http://www.w3.org/2001/XMLSchema#"
#define SLV2_NS_RDF (const uint8_t*)"http://www.w3.org/1999/02/22-rdf-syntax-ns#"
+typedef librdf_stream* SLV2Matches;
+typedef librdf_node* SLV2Node; ///< RDF node
+
#define FOREACH_MATCH(stream) \
for (; !librdf_stream_end(stream); librdf_stream_next(stream))
-#define MATCH_SUBJECT(stream) \
- librdf_statement_get_subject(librdf_stream_get_object(stream))
-
-#define MATCH_OBJECT(stream) \
- librdf_statement_get_object(librdf_stream_get_object(stream))
+static inline SLV2Node
+slv2_match_subject(SLV2Matches stream) {
+ return librdf_statement_get_subject(librdf_stream_get_object(stream));
+}
-#define END_MATCH(stream) librdf_free_stream(stream)
+static inline SLV2Node
+slv2_match_object(SLV2Matches stream) {
+ return librdf_statement_get_object(librdf_stream_get_object(stream));
+}
+static inline void
+slv2_match_end(SLV2Matches stream)
+{
+ librdf_free_stream(stream);
+}
-typedef librdf_node* SLV2Node; ///< RDF node
/* ********* PORT ********* */
@@ -288,8 +297,6 @@ void slv2_scale_point_free(SLV2ScalePoint point);
/* ********* Query Results********* */
-typedef librdf_stream* SLV2Matches;
-
SLV2Matches slv2_plugin_find_statements(SLV2Plugin plugin,
SLV2Node subject,
SLV2Node predicate,
diff --git a/src/world.c b/src/world.c
index efd7d9e..f32dfaa 100644
--- a/src/world.c
+++ b/src/world.c
@@ -269,20 +269,20 @@ slv2_world_load_bundle(SLV2World world, SLV2Value bundle_uri)
world->rdf_a_node,
world->dyn_manifest_node);
FOREACH_MATCH(dmanifests) {
- SLV2Node dmanifest = MATCH_SUBJECT(dmanifests);
+ SLV2Node dmanifest = slv2_match_subject(dmanifests);
SLV2Matches binaries = slv2_world_find_statements(
world, world->model,
dmanifest,
world->lv2_binary_node,
NULL);
if (slv2_matches_end(binaries)) {
- END_MATCH(binaries);
+ slv2_match_end(binaries);
SLV2_ERRORF("Dynamic manifest in <%s> has no binaries, ignored\n",
slv2_value_as_uri(bundle_uri));
continue;
}
- SLV2Node binary = slv2_node_copy(MATCH_OBJECT(binaries));
+ SLV2Node binary = slv2_node_copy(slv2_match_object(binaries));
const uint8_t* lib_uri = librdf_uri_as_string(librdf_node_get_uri(binary));
const char* lib_path = slv2_uri_to_path((const char*)lib_uri);
if (!lib_path)
@@ -325,7 +325,7 @@ slv2_world_load_bundle(SLV2World world, SLV2Value bundle_uri)
world->rdf_a_node,
world->lv2_plugin_node);
FOREACH_MATCH(dyn_plugins) {
- SLV2Node plugin = MATCH_SUBJECT(dyn_plugins);
+ SLV2Node plugin = slv2_match_subject(dyn_plugins);
// Add ?plugin slv2:dynamic-manifest ?binary to dynamic model
librdf_model_add(
@@ -333,7 +333,7 @@ slv2_world_load_bundle(SLV2World world, SLV2Value bundle_uri)
librdf_new_node_from_uri_string(world->world, SLV2_NS_RDFS "seeAlso"),
slv2_node_copy(binary));
}
- END_MATCH(dyn_plugins);
+ slv2_match_end(dyn_plugins);
// Merge dynamic model into main manifest model
librdf_stream* dyn_manifest_stream = librdf_model_as_stream(dyn_manifest_model);
@@ -342,7 +342,7 @@ slv2_world_load_bundle(SLV2World world, SLV2Value bundle_uri)
librdf_free_model(dyn_manifest_model);
librdf_free_storage(dyn_manifest_storage);
}
- END_MATCH(dmanifests);
+ slv2_match_end(dmanifests);
#endif // SLV2_DYN_MANIFEST
// ?plugin a lv2:Plugin
@@ -352,7 +352,7 @@ slv2_world_load_bundle(SLV2World world, SLV2Value bundle_uri)
world->rdf_a_node,
world->lv2_plugin_node);
FOREACH_MATCH(results) {
- SLV2Node plugin = MATCH_SUBJECT(results);
+ SLV2Node plugin = slv2_match_subject(results);
// Add ?plugin rdfs:seeAlso <manifest.ttl>
librdf_model_add(
@@ -368,7 +368,7 @@ slv2_world_load_bundle(SLV2World world, SLV2Value bundle_uri)
librdf_new_node_from_uri_string(world->world, SLV2_NS_SLV2 "bundleURI"),
slv2_node_copy(bundle_uri->val.uri_val));
}
- END_MATCH(results);
+ slv2_match_end(results);
// ?specification a lv2:Specification
results = slv2_world_find_statements(
@@ -377,7 +377,7 @@ slv2_world_load_bundle(SLV2World world, SLV2Value bundle_uri)
world->rdf_a_node,
world->lv2_specification_node);
FOREACH_MATCH(results) {
- SLV2Node spec = MATCH_SUBJECT(results);
+ SLV2Node spec = slv2_match_subject(results);
// Add ?specification rdfs:seeAlso <manifest.ttl>
librdf_model_add(
@@ -393,7 +393,7 @@ slv2_world_load_bundle(SLV2World world, SLV2Value bundle_uri)
librdf_new_node_from_uri_string(world->world, SLV2_NS_SLV2 "bundleURI"),
slv2_node_copy(bundle_uri->val.uri_val));
}
- END_MATCH(results);
+ slv2_match_end(results);
// Join the temporary model to the main model
librdf_stream* manifest_stream = librdf_model_as_stream(manifest_model);
@@ -496,19 +496,19 @@ slv2_world_load_specifications(SLV2World world)
world->rdf_a_node,
world->lv2_specification_node);
FOREACH_MATCH(specs) {
- SLV2Node spec_node = MATCH_SUBJECT(specs);
+ SLV2Node spec_node = slv2_match_subject(specs);
SLV2Matches files = slv2_world_find_statements(
world, world->model,
spec_node,
world->rdfs_seealso_node,
NULL);
FOREACH_MATCH(files) {
- SLV2Node file_node = MATCH_OBJECT(files);
+ SLV2Node file_node = slv2_match_object(files);
slv2_world_load_file(world, librdf_node_get_uri(file_node));
}
- END_MATCH(files);
+ slv2_match_end(files);
}
- END_MATCH(specs);
+ slv2_match_end(specs);
}
@@ -527,7 +527,7 @@ slv2_world_load_plugin_classes(SLV2World world)
world->rdf_a_node,
world->rdfs_class_node);
FOREACH_MATCH(classes) {
- SLV2Node class_node = MATCH_SUBJECT(classes);
+ SLV2Node class_node = slv2_match_subject(classes);
// Get parents (superclasses)
SLV2Matches parents = slv2_world_find_statements(
@@ -537,12 +537,12 @@ slv2_world_load_plugin_classes(SLV2World world)
NULL);
if (slv2_matches_end(parents)) {
- END_MATCH(parents);
+ slv2_match_end(parents);
continue;
}
- SLV2Node parent_node = slv2_node_copy(MATCH_OBJECT(parents));
- END_MATCH(parents);
+ SLV2Node parent_node = slv2_node_copy(slv2_match_object(parents));
+ slv2_match_end(parents);
if (!librdf_node_is_resource(parent_node)) {
// Class parent is not a resource, ignore (e.g. owl restriction)
@@ -557,13 +557,13 @@ slv2_world_load_plugin_classes(SLV2World world)
NULL);
if (slv2_matches_end(labels)) {
- END_MATCH(labels);
+ slv2_match_end(labels);
continue;
}
- SLV2Node label_node = slv2_node_copy(MATCH_OBJECT(labels));
+ SLV2Node label_node = slv2_node_copy(slv2_match_object(labels));
const uint8_t* label = librdf_node_get_literal_value(label_node);
- END_MATCH(labels);
+ slv2_match_end(labels);
SLV2PluginClasses classes = world->plugin_classes;
const unsigned n_classes = raptor_sequence_size(classes);
@@ -586,7 +586,7 @@ slv2_world_load_plugin_classes(SLV2World world)
slv2_node_free(parent_node);
slv2_node_free(label_node);
}
- END_MATCH(classes);
+ slv2_match_end(classes);
}
@@ -647,7 +647,7 @@ slv2_world_load_all(SLV2World world)
world->rdf_a_node,
world->lv2_plugin_node);
FOREACH_MATCH(plugins) {
- SLV2Node plugin_node = MATCH_SUBJECT(plugins);
+ SLV2Node plugin_node = slv2_match_subject(plugins);
const char* plugin_uri = (const char*)librdf_uri_as_string(
librdf_node_get_uri(plugin_node));
@@ -658,22 +658,22 @@ slv2_world_load_all(SLV2World world)
NULL);
if (slv2_matches_end(bundles)) {
- END_MATCH(bundles);
+ slv2_match_end(bundles);
SLV2_ERRORF("Plugin <%s> has no bundle, ignored\n", plugin_uri);
continue;
}
- SLV2Node bundle_node = slv2_node_copy(MATCH_OBJECT(bundles));
+ SLV2Node bundle_node = slv2_node_copy(slv2_match_object(bundles));
slv2_matches_next(bundles);
if (!slv2_matches_end(bundles)) {
- END_MATCH(bundles);
+ slv2_match_end(bundles);
SLV2_ERRORF("Plugin <%s> found in several bundles, ignored\n",
plugin_uri);
continue;
}
- END_MATCH(bundles);
+ slv2_match_end(bundles);
// Add a new plugin to the world
SLV2Value uri = slv2_value_new_from_node(world, plugin_node);
@@ -700,7 +700,7 @@ slv2_world_load_all(SLV2World world)
world->slv2_dmanifest_node,
NULL);
FOREACH_MATCH(dmanifests) {
- SLV2Node lib_node = MATCH_OBJECT(dmanifests);
+ SLV2Node lib_node = slv2_match_object(dmanifests);
const char* lib_uri = (const char*)librdf_uri_as_string(
librdf_node_get_uri(lib_node));
@@ -708,7 +708,7 @@ slv2_world_load_all(SLV2World world)
plugin->dynman_uri = slv2_value_new_from_node(world, lib_node);
}
}
- END_MATCH(dmanifests);
+ slv2_match_end(dmanifests);
}
#endif
SLV2Matches files = slv2_world_find_statements(
@@ -717,15 +717,15 @@ slv2_world_load_all(SLV2World world)
world->rdfs_seealso_node,
NULL);
FOREACH_MATCH(files) {
- SLV2Node file_node = MATCH_OBJECT(files);
+ SLV2Node file_node = slv2_match_object(files);
raptor_sequence_push(plugin->data_uris,
slv2_value_new_from_node(world, file_node));
}
- END_MATCH(files);
+ slv2_match_end(files);
slv2_node_free(bundle_node);
}
- END_MATCH(plugins);
+ slv2_match_end(plugins);
}