diff options
author | David Robillard <d@drobilla.net> | 2008-12-13 05:23:25 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2008-12-13 05:23:25 +0000 |
commit | baa2354cf47b093117206fd1fc1bae45e46b03c3 (patch) | |
tree | da51033f5060badca53d52aa1bce4c2076cb9fcf /src | |
parent | c854c1f24f41844f0c95e8943738a820d8a283e5 (diff) | |
download | lilv-baa2354cf47b093117206fd1fc1bae45e46b03c3.tar.gz lilv-baa2354cf47b093117206fd1fc1bae45e46b03c3.tar.bz2 lilv-baa2354cf47b093117206fd1fc1bae45e46b03c3.zip |
Factor out "load plugin if necessary" concept.
Test plugin features: 78.1% coverage.
git-svn-id: http://svn.drobilla.net/lad/trunk/slv2@1859 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'src')
-rw-r--r-- | src/plugin.c | 33 | ||||
-rw-r--r-- | src/query.c | 3 | ||||
-rw-r--r-- | src/slv2_internal.h | 1 | ||||
-rw-r--r-- | src/value.c | 3 |
4 files changed, 21 insertions, 19 deletions
diff --git a/src/plugin.c b/src/plugin.c index b9bc9b2..6ac5094 100644 --- a/src/plugin.c +++ b/src/plugin.c @@ -105,6 +105,15 @@ slv2_port_compare_by_index(const void* a, const void* b) #endif +/* private */ +void +slv2_plugin_load_if_necessary(SLV2Plugin p) +{ + if (!p->rdf) + slv2_plugin_load(p); +} + + void slv2_plugin_load(SLV2Plugin p) { @@ -290,8 +299,7 @@ SLV2Value slv2_plugin_get_library_uri(SLV2Plugin p) { assert(p); - if (!p->binary_uri && !p->rdf) - slv2_plugin_load(p); + slv2_plugin_load_if_necessary(p); return p->binary_uri; } @@ -309,9 +317,7 @@ slv2_plugin_get_class(SLV2Plugin p) // FIXME: Typical use case this will bring every single plugin model // into memory - if (!p->rdf) - slv2_plugin_load(p); - + slv2_plugin_load_if_necessary(p); return p->plugin_class; } @@ -525,9 +531,7 @@ slv2_plugin_get_hints(SLV2Plugin p) uint32_t slv2_plugin_get_num_ports(SLV2Plugin p) { - if (!p->rdf) - slv2_plugin_load(p); - + slv2_plugin_load_if_necessary(p); return raptor_sequence_size(p->ports); } @@ -537,12 +541,11 @@ slv2_plugin_get_port_float_values(SLV2Plugin p, const char* qname, float* values) { - if (!p->rdf) - slv2_plugin_load(p); - const unsigned char* query; librdf_query* q; librdf_query_results* results; + + slv2_plugin_load_if_necessary(p); for (int i = 0; i < raptor_sequence_size(p->ports); ++i) values[i] = NAN; @@ -717,9 +720,7 @@ SLV2Port slv2_plugin_get_port_by_index(SLV2Plugin p, uint32_t index) { - if (!p->rdf) - slv2_plugin_load(p); - + slv2_plugin_load_if_necessary(p); return raptor_sequence_get_at(p->ports, (int)index); } @@ -728,9 +729,7 @@ SLV2Port slv2_plugin_get_port_by_symbol(SLV2Plugin p, SLV2Value symbol) { - if (!p->rdf) - slv2_plugin_load(p); - + slv2_plugin_load_if_necessary(p); for (int i=0; i < raptor_sequence_size(p->ports); ++i) { SLV2Port port = raptor_sequence_get_at(p->ports, i); if (slv2_value_equals(port->symbol, symbol)) diff --git a/src/query.c b/src/query.c index 540d11a..f4a6a0d 100644 --- a/src/query.c +++ b/src/query.c @@ -126,8 +126,7 @@ librdf_query_results* slv2_plugin_query(SLV2Plugin plugin, const char* sparql_str) { - if (!plugin->rdf) - slv2_plugin_load(plugin); + slv2_plugin_load_if_necessary(plugin); librdf_uri* base_uri = slv2_value_as_librdf_uri(plugin->plugin_uri); diff --git a/src/slv2_internal.h b/src/slv2_internal.h index a3e8d04..9d5b17a 100644 --- a/src/slv2_internal.h +++ b/src/slv2_internal.h @@ -68,6 +68,7 @@ struct _SLV2Plugin { SLV2Plugin slv2_plugin_new(SLV2World world, SLV2Value uri, librdf_uri* bundle_uri); void slv2_plugin_load(SLV2Plugin p); +void slv2_plugin_load_if_necessary(SLV2Plugin p); void slv2_plugin_free(SLV2Plugin plugin); void slv2_plugin_get_port_float_values(SLV2Plugin p, const char* qname, diff --git a/src/value.c b/src/value.c index 0e474fb..08c27e5 100644 --- a/src/value.c +++ b/src/value.c @@ -168,6 +168,9 @@ slv2_value_new_float(SLV2World world, float val) SLV2Value slv2_value_duplicate(SLV2Value val) { + if (val == NULL) + return val; + SLV2Value result = (SLV2Value)malloc(sizeof(struct _SLV2Value)); result->type = val->type; |