From d3d736deba06ca2ef655858ac22d8267c5cc6363 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Mon, 19 Feb 2007 00:46:59 +0000 Subject: Header/API cleanups. Removed public exposure of raptor/rasqal. Redefined opaque types properly. git-svn-id: http://svn.drobilla.net/lad/slv2@317 a436a847-0d15-0410-975c-d299462d15a1 --- hosts/lv2_jack_host.c | 6 +- hosts/lv2_simple_jack_host.c | 6 +- slv2/Makefile.am | 1 - slv2/library.h | 5 -- slv2/plugin.h | 54 +++++++++++------- slv2/plugininstance.h | 50 +++++++++-------- slv2/pluginlist.h | 4 +- slv2/port.h | 18 +++--- slv2/query.h | 130 ------------------------------------------- slv2/slv2.h | 3 - slv2/stringlist.h | 14 ++--- slv2/types.h | 1 - slv2/util.h | 8 +-- src/library.c | 2 +- src/plugin.c | 49 ++++++---------- src/plugininstance.c | 6 +- src/pluginlist.c | 8 +-- src/port.c | 38 ++++++------- src/private_types.h | 5 ++ src/query.c | 40 +++---------- src/stringlist.c | 17 ++++-- utils/lv2_inspect.c | 6 +- utils/lv2_list.c | 2 +- 23 files changed, 161 insertions(+), 312 deletions(-) delete mode 100644 slv2/query.h diff --git a/hosts/lv2_jack_host.c b/hosts/lv2_jack_host.c index 6eb682b..6350a3a 100644 --- a/hosts/lv2_jack_host.c +++ b/hosts/lv2_jack_host.c @@ -43,8 +43,8 @@ struct Port { /** This program's data */ struct JackHost { jack_client_t* jack_client; /**< Jack client */ - SLV2Plugin* plugin; /**< Plugin "class" (actually just a few strings) */ - SLV2Instance* instance; /**< Plugin "instance" (loaded shared lib) */ + SLV2Plugin plugin; /**< Plugin "class" (actually just a few strings) */ + SLV2Instance instance; /**< Plugin "instance" (loaded shared lib) */ uint32_t num_ports; /**< Size of the two following arrays: */ struct Port* ports; /** Port array of size num_ports */ }; @@ -310,7 +310,7 @@ void list_plugins(SLV2Plugins list) { for (unsigned i=0; i < slv2_plugins_size(list); ++i) { - const SLV2Plugin* const p = slv2_plugins_get_at(list, i); + SLV2Plugin p = slv2_plugins_get_at(list, i); printf("%s\n", slv2_plugin_get_uri(p)); } } diff --git a/hosts/lv2_simple_jack_host.c b/hosts/lv2_simple_jack_host.c index 6221d2f..8510f40 100644 --- a/hosts/lv2_simple_jack_host.c +++ b/hosts/lv2_simple_jack_host.c @@ -26,8 +26,8 @@ /** This program's data */ struct JackHost { jack_client_t* jack_client; /**< Jack client */ - SLV2Plugin* plugin; /**< Plugin "class" (actually just a few strings) */ - SLV2Instance* instance; /**< Plugin "instance" (loaded shared lib) */ + SLV2Plugin plugin; /**< Plugin "class" (actually just a few strings) */ + SLV2Instance instance; /**< Plugin "instance" (loaded shared lib) */ uint32_t num_ports; /**< Size of the two following arrays: */ jack_port_t** jack_ports; /**< For audio ports, otherwise NULL */ float* controls; /**< For control ports, otherwise 0.0f */ @@ -215,7 +215,7 @@ void list_plugins(SLV2Plugins list) { for (unsigned i=0; i < slv2_plugins_size(list); ++i) { - const SLV2Plugin* const p = slv2_plugins_get_at(list, i); + SLV2Plugin p = slv2_plugins_get_at(list, i); printf("%s\n", slv2_plugin_get_uri(p)); } } diff --git a/slv2/Makefile.am b/slv2/Makefile.am index d2b863e..0a90fb1 100644 --- a/slv2/Makefile.am +++ b/slv2/Makefile.am @@ -6,7 +6,6 @@ slv2include_HEADERS = \ slv2.h \ library.h \ plugin.h \ - query.h \ port.h \ pluginlist.h \ plugininstance.h \ diff --git a/slv2/library.h b/slv2/library.h index 9c94139..c3d68ca 100644 --- a/slv2/library.h +++ b/slv2/library.h @@ -41,11 +41,6 @@ void slv2_finish(); -/** The URI of the lv2.ttl file. - */ -extern raptor_uri* slv2_ontology_uri; - - #ifdef __cplusplus } #endif diff --git a/slv2/plugin.h b/slv2/plugin.h index 27fa982..559c927 100644 --- a/slv2/plugin.h +++ b/slv2/plugin.h @@ -24,13 +24,12 @@ extern "C" { #endif #include -#include #include #include #include -typedef const struct _Plugin SLV2Plugin; +typedef struct _Plugin* SLV2Plugin; /** \defgroup data Plugin - RDF data access @@ -56,7 +55,7 @@ typedef const struct _Plugin SLV2Plugin; * \return true if \a plugin is valid. */ bool -slv2_plugin_verify(const SLV2Plugin* plugin); +slv2_plugin_verify(SLV2Plugin plugin); /** Duplicate a plugin. @@ -66,8 +65,8 @@ slv2_plugin_verify(const SLV2Plugin* plugin); * * \return a newly allocated deep copy of \a plugin. */ -SLV2Plugin* -slv2_plugin_duplicate(const SLV2Plugin* plugin); +SLV2Plugin +slv2_plugin_duplicate(SLV2Plugin plugin); /** Get the URI of \a plugin. @@ -85,7 +84,7 @@ slv2_plugin_duplicate(const SLV2Plugin* plugin); * \return a shared string which must not be modified or free()'d. */ const char* -slv2_plugin_get_uri(const SLV2Plugin* plugin); +slv2_plugin_get_uri(SLV2Plugin plugin); /** Get the (resolvable) URIs of the RDF data files that define a plugin. @@ -97,7 +96,7 @@ slv2_plugin_get_uri(const SLV2Plugin* plugin); * which is shared and must not be modified or free()'d. */ SLV2Strings -slv2_plugin_get_data_uris(const SLV2Plugin* plugin); +slv2_plugin_get_data_uris(SLV2Plugin plugin); /** Get the (resolvable) URI of the shared library for \a plugin. @@ -108,7 +107,7 @@ slv2_plugin_get_data_uris(const SLV2Plugin* plugin); * \return a shared string which must not be modified or free()'d. */ const char* -slv2_plugin_get_library_uri(const SLV2Plugin* plugin); +slv2_plugin_get_library_uri(SLV2Plugin plugin); @@ -119,7 +118,7 @@ slv2_plugin_get_library_uri(const SLV2Plugin* plugin); * the caller. */ char* -slv2_plugin_get_name(const SLV2Plugin* plugin); +slv2_plugin_get_name(SLV2Plugin plugin); /** Request some arbitrary RDF object of the plugin. @@ -136,8 +135,8 @@ slv2_plugin_get_name(const SLV2Plugin* plugin); * returned. */ SLV2Strings -slv2_plugin_get_value(const SLV2Plugin* p, - const char* predicate); +slv2_plugin_get_value(SLV2Plugin p, + const char* predicate); /** Get the LV2 Properties of a plugin. @@ -149,7 +148,7 @@ slv2_plugin_get_value(const SLV2Plugin* p, * Return value must be freed by caller with slv2_value_free. */ SLV2Strings -slv2_plugin_get_properties(const SLV2Plugin* p); +slv2_plugin_get_properties(SLV2Plugin p); /** Get the LV2 Hints of a plugin. @@ -160,13 +159,14 @@ slv2_plugin_get_properties(const SLV2Plugin* p); * Return value must be freed by caller with slv2_value_free. */ SLV2Strings -slv2_plugin_get_hints(const SLV2Plugin* p); +slv2_plugin_get_hints(SLV2Plugin p); /** Get the number of ports on this plugin. */ uint32_t -slv2_plugin_get_num_ports(const SLV2Plugin* p); +slv2_plugin_get_num_ports(SLV2Plugin p); + /** Return whether or not the plugin introduces (and reports) latency. * @@ -174,7 +174,8 @@ slv2_plugin_get_num_ports(const SLV2Plugin* p); * ONLY if this function returns true. */ bool -slv2_plugin_has_latency(const SLV2Plugin* p); +slv2_plugin_has_latency(SLV2Plugin p); + /** Return the index of the plugin's latency port, or the empty string if the * plugin has no latency. @@ -187,7 +188,7 @@ slv2_plugin_has_latency(const SLV2Plugin* p); * rate output port that reports the latency for each cycle in frames. */ uint32_t -slv2_plugin_get_latency_port(const SLV2Plugin* p); +slv2_plugin_get_latency_port(SLV2Plugin p); /** Get a plugin's supported host features / extensions. @@ -195,7 +196,7 @@ slv2_plugin_get_latency_port(const SLV2Plugin* p); * This returns a list of all supported features (both required and optional). */ SLV2Strings -slv2_plugin_get_supported_features(const SLV2Plugin* p); +slv2_plugin_get_supported_features(SLV2Plugin p); /** Get a plugin's requires host features / extensions. @@ -204,7 +205,7 @@ slv2_plugin_get_supported_features(const SLV2Plugin* p); * instantiate method for the plugin to instantiate successfully. */ SLV2Strings -slv2_plugin_get_required_features(const SLV2Plugin* p); +slv2_plugin_get_required_features(SLV2Plugin p); /** Get a plugin's optional host features / extensions. @@ -214,7 +215,22 @@ slv2_plugin_get_required_features(const SLV2Plugin* p); * the plugin will act as it would if it did not support that feature at all. */ SLV2Strings -slv2_plugin_get_optional_features(const SLV2Plugin* p); +slv2_plugin_get_optional_features(SLV2Plugin p); + + +/** Query a plugin for a single variable. + */ +SLV2Strings +slv2_plugin_simple_query(SLV2Plugin plugin, + const char* sparql_str, + const char* variable); + + +/** Query a plugin and return the number of results found. + */ +unsigned +slv2_plugin_query_count(SLV2Plugin plugin, + const char* sparql_str); /** @} */ diff --git a/slv2/plugininstance.h b/slv2/plugininstance.h index e704383..122d536 100644 --- a/slv2/plugininstance.h +++ b/slv2/plugininstance.h @@ -24,21 +24,12 @@ extern "C" { #endif #include -#include #include #include #include typedef struct _InstanceImpl* SLV2InstanceImpl; -/** Instance of a plugin */ -typedef struct _Instance { - const LV2_Descriptor* lv2_descriptor; - LV2_Handle lv2_handle; - SLV2InstanceImpl pimpl; ///< Opaque -} SLV2Instance; - - /** \defgroup lib Plugin Instance - Shared library access * * An SLV2Instance is an instantiated SLV2Plugin (eg a loaded dynamic @@ -49,6 +40,21 @@ typedef struct _Instance { */ +/** Instance of a plugin. + * + * The LV2 descriptor and handle of this are exposed to allow inlining of + * performance critical functions like slv2_instance_run (hiding things in + * lv2.h is pointless anyway). The remaining implementation details are + * in the opaque pimpl member. + */ +typedef struct _Instance { + const LV2_Descriptor* lv2_descriptor; + LV2_Handle lv2_handle; + SLV2InstanceImpl pimpl; ///< Move along now, nothing to see here +}* SLV2Instance; + + + /** Instantiate a plugin. * * The returned object represents shared library objects loaded into memory, @@ -64,8 +70,8 @@ typedef struct _Instance { * * \return NULL if instantiation failed. */ -SLV2Instance* -slv2_plugin_instantiate(const SLV2Plugin* plugin, +SLV2Instance +slv2_plugin_instantiate(SLV2Plugin plugin, uint32_t sample_rate, const LV2_Host_Feature** host_features); @@ -75,7 +81,7 @@ slv2_plugin_instantiate(const SLV2Plugin* plugin, * \a instance is invalid after this call. */ void -slv2_instance_free(SLV2Instance* instance); +slv2_instance_free(SLV2Instance instance); #ifndef LIBSLV2_SOURCE @@ -86,7 +92,7 @@ slv2_instance_free(SLV2Instance* instance); * Returned string is shared and must not be modified or deleted. */ static inline const char* -slv2_instance_get_uri(SLV2Instance* instance) +slv2_instance_get_uri(SLV2Instance instance) { assert(instance); assert(instance->lv2_descriptor); @@ -101,9 +107,9 @@ slv2_instance_get_uri(SLV2Instance* instance) * activation and deactivation does not destroy port connections. */ static inline void -slv2_instance_connect_port(SLV2Instance* instance, - uint32_t port_index, - void* data_location) +slv2_instance_connect_port(SLV2Instance instance, + uint32_t port_index, + void* data_location) { assert(instance); assert(instance->lv2_descriptor); @@ -121,7 +127,7 @@ slv2_instance_connect_port(SLV2Instance* instance, * before calling slv2_instance_run. */ static inline void -slv2_instance_activate(SLV2Instance* instance) +slv2_instance_activate(SLV2Instance instance) { assert(instance); assert(instance->lv2_descriptor); @@ -137,8 +143,8 @@ slv2_instance_activate(SLV2Instance* instance) * guaranteed not to block. */ static inline void -slv2_instance_run(SLV2Instance* instance, - uint32_t sample_count) +slv2_instance_run(SLV2Instance instance, + uint32_t sample_count) { assert(instance); assert(instance->lv2_descriptor); @@ -155,7 +161,7 @@ slv2_instance_run(SLV2Instance* instance, * reset all state information (except port connections). */ static inline void -slv2_instance_deactivate(SLV2Instance* instance) +slv2_instance_deactivate(SLV2Instance instance) { assert(instance); assert(instance->lv2_descriptor); @@ -174,7 +180,7 @@ slv2_instance_deactivate(SLV2Instance* instance) * The returned descriptor is shared and must not be deleted. */ static inline const LV2_Descriptor* -slv2_instance_get_descriptor(SLV2Instance* instance) +slv2_instance_get_descriptor(SLV2Instance instance) { assert(instance); assert(instance->lv2_descriptor); @@ -191,7 +197,7 @@ slv2_instance_get_descriptor(SLV2Instance* instance) * The returned handle is shared and must not be deleted. */ static inline LV2_Handle -slv2_instance_get_handle(SLV2Instance* instance) +slv2_instance_get_handle(SLV2Instance instance) { assert(instance); assert(instance->lv2_descriptor); diff --git a/slv2/pluginlist.h b/slv2/pluginlist.h index 1032a84..3e9b9d4 100644 --- a/slv2/pluginlist.h +++ b/slv2/pluginlist.h @@ -127,7 +127,7 @@ slv2_plugins_size(const SLV2Plugins list); * * \return NULL if plugin with \a url not found in \a list. */ -const SLV2Plugin* +SLV2Plugin slv2_plugins_get_by_uri(const SLV2Plugins list, const char* uri); @@ -144,7 +144,7 @@ slv2_plugins_get_by_uri(const SLV2Plugins list, * * \return NULL if \a index out of range. */ -const SLV2Plugin* +SLV2Plugin slv2_plugins_get_at(const SLV2Plugins list, unsigned index); diff --git a/slv2/port.h b/slv2/port.h index 9106a9c..546a713 100644 --- a/slv2/port.h +++ b/slv2/port.h @@ -47,7 +47,7 @@ slv2_port_by_symbol(const char* symbol); /** Port equivalent to slv2_plugin_get_value. */ SLV2Strings -slv2_port_get_value(SLV2Plugin* plugin, +slv2_port_get_value(SLV2Plugin plugin, SLV2PortID id, const char* property); @@ -55,14 +55,14 @@ slv2_port_get_value(SLV2Plugin* plugin, /** Port equivalent to slv2_plugin_get_properties. */ SLV2Strings -slv2_port_get_properties(const SLV2Plugin* p, +slv2_port_get_properties(SLV2Plugin p, SLV2PortID id); /** Port equivalent to slv2_plugin_get_hints. */ SLV2Strings -slv2_port_get_hints(const SLV2Plugin* p, +slv2_port_get_hints(SLV2Plugin p, SLV2PortID id); @@ -74,7 +74,7 @@ slv2_port_get_hints(const SLV2Plugin* p, * \return NULL when index is out of range */ char* -slv2_port_get_symbol(SLV2Plugin* plugin, +slv2_port_get_symbol(SLV2Plugin plugin, SLV2PortID id); /** Get the name of a port. @@ -84,14 +84,14 @@ slv2_port_get_symbol(SLV2Plugin* plugin, * the caller. */ char* -slv2_port_get_name(SLV2Plugin* plugin, +slv2_port_get_name(SLV2Plugin plugin, SLV2PortID id); /** Get the class (input/output, data type, rate...) of a port. */ SLV2PortClass -slv2_port_get_class(SLV2Plugin* plugin, +slv2_port_get_class(SLV2Plugin plugin, SLV2PortID id); @@ -100,7 +100,7 @@ slv2_port_get_class(SLV2Plugin* plugin, * Only valid for ports with a data type of lv2:float. */ float -slv2_port_get_default_value(SLV2Plugin* plugin, +slv2_port_get_default_value(SLV2Plugin plugin, SLV2PortID id); @@ -109,7 +109,7 @@ slv2_port_get_default_value(SLV2Plugin* plugin, * Only valid for ports with a data type of lv2:float. */ float -slv2_port_get_minimum_value(SLV2Plugin* plugin, +slv2_port_get_minimum_value(SLV2Plugin plugin, SLV2PortID id); @@ -118,7 +118,7 @@ slv2_port_get_minimum_value(SLV2Plugin* plugin, * Only valid for ports with a data type of lv2:float. */ float -slv2_port_get_maximum_value(SLV2Plugin* plugin, +slv2_port_get_maximum_value(SLV2Plugin plugin, SLV2PortID id); diff --git a/slv2/query.h b/slv2/query.h deleted file mode 100644 index ea78735..0000000 --- a/slv2/query.h +++ /dev/null @@ -1,130 +0,0 @@ -/* SLV2 - * Copyright (C) 2007 Dave Robillard - * - * 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) - * any later version. - * - * This library is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#ifndef __SLV2_QUERY_H__ -#define __SLV2_QUERY_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -#include -#include "plugin.h" -#include "types.h" - - -// FIXME: much of this should not be exposed - - -/** \defgroup query SPARQL query helpers - * - * This part is in progress, incomplete, a random mishmash of crap that - * evolved along with my understanding of this rasqal library. Nothing - * to see here, move long now. Nothing to see here. - * - * Eventually this will contain functions that make it convenient for host - * authors to query plugins in ways libslv2 doesn't nicely wrap (eg. for - * extensions not (yet) supported by libslv2). - * - * @{ - */ - -/** Return a header for a SPARQL query on the given plugin. - * - * The returned header defines the namespace prefixes used in the standard - * (rdf: rdfs: doap: lv2:), plugin: as the plugin's URI, and data: as the - * URL of the plugin's RDF (Turtle) data file. - * - * Example query to get a plugin's doap:name using this header: - * - * - * SELECT DISTINCT ?value FROM data: WHERE { - * plugin: doap:name ?value - * } - * - * - * \return an unsigned (UTF-8) string which must be free()'d. - */ -char* -slv2_query_header(const SLV2Plugin* p); - - -/** Return a language filter for the given variable. - * - * If the environment variable $LANG is not set, returns NULL. - * - * \arg variable SPARQL variable, including "?" or "$" (eg "?value"). - * - * This needs to be put inside the WHERE block, after the triples. - * - * eg. FILTER( LANG(?value) = "en" || LANG(?value) = "" ) - */ -char* -slv2_query_lang_filter(const char* variable); - - -rasqal_query_results* -slv2_plugin_query(SLV2Plugin* plugin, - const char* sparql_str); - -SLV2Strings -slv2_plugin_simple_query(SLV2Plugin* plugin, - const char* sparql_str, - const char* variable); - -unsigned -slv2_plugin_query_count(SLV2Plugin* plugin, - const char* sparql_str); - -#if 0 -/** Run a SPARQL query on a plugin's data file and return variable matches. - * - * Header from slv2query_header will be prepended to passed query string (so - * the default prefixes will be already defined, you don't need to add them - * yourself). - * - * Returned is a list of all matches for the query variable \a var_name. - */ -SLV2Strings -slv2_query_get_results(const SLV2Plugin* p, - const char* query_string, - const char* var_name); - -/** Run a SPARQL query on a plugin's data file and just count the matches. - * - * Header from slv2query_header will be prepended to passed query string (so - * the default prefixes will be already defined, you don't need to add them - * yourself). - * - * Returned is the total of all variable matches resulting from the query. - */ -size_t -slv2_query_count_results(const SLV2Plugin* p, - const char* query_string); -#endif - - -/** @} */ - - -#ifdef __cplusplus -} -#endif - -#endif /* __SLV2_QUERY_H__ */ - diff --git a/slv2/slv2.h b/slv2/slv2.h index 07e9201..539ea47 100644 --- a/slv2/slv2.h +++ b/slv2/slv2.h @@ -23,8 +23,6 @@ extern "C" { #endif -#include - #include #include #include @@ -33,7 +31,6 @@ extern "C" { #include #include - #ifdef __cplusplus } #endif diff --git a/slv2/stringlist.h b/slv2/stringlist.h index 4abb383..7414659 100644 --- a/slv2/stringlist.h +++ b/slv2/stringlist.h @@ -21,9 +21,6 @@ #include -typedef void* SLV2Strings; - - #ifdef __cplusplus extern "C" { #endif @@ -38,6 +35,9 @@ extern "C" { */ +typedef void* SLV2Strings; + + /** Allocate a new, empty SLV2Strings */ SLV2Strings @@ -47,21 +47,21 @@ slv2_strings_new(); /** Get the number of elements in a string list. */ unsigned -slv2_strings_size(const SLV2Strings list); +slv2_strings_size(SLV2Strings list); /** Get a string from a string list at the given index. * * @return the element at @a index, or NULL if index is out of range. */ -char* -slv2_strings_get_at(const SLV2Strings list, unsigned index); +const char* +slv2_strings_get_at(SLV2Strings list, unsigned index); /** Return whether @a list contains @a uri. */ bool -slv2_strings_contains(const SLV2Strings list, const char* uri); +slv2_strings_contains(SLV2Strings list, const char* uri); /** Free a string list. */ diff --git a/slv2/types.h b/slv2/types.h index dd7480c..03c84e7 100644 --- a/slv2/types.h +++ b/slv2/types.h @@ -19,7 +19,6 @@ #ifndef __SLV2_TYPES_H__ #define __SLV2_TYPES_H__ -#include #include #include diff --git a/slv2/util.h b/slv2/util.h index eb8dea7..aa08dbf 100644 --- a/slv2/util.h +++ b/slv2/util.h @@ -19,13 +19,7 @@ #ifndef __SLV2_UTIL_H__ #define __SLV2_UTIL_H__ -#define _XOPEN_SOURCE 500 -#include #include -#include -#include -#include -#include #ifdef __cplusplus extern "C" { @@ -41,7 +35,7 @@ extern "C" { /** Convert a full URI (eg file://foo/bar/baz.ttl) to a local path (e.g. /foo/bar/baz.ttl). * * Return value is shared and must not be deleted by caller. - * @return @uri converted to a path, or NULL on failure (URI is not local). + * @return @a uri converted to a path, or NULL on failure (URI is not local). */ const char* slv2_uri_to_path(const char* uri); diff --git a/src/library.c b/src/library.c index 591218d..45f298c 100644 --- a/src/library.c +++ b/src/library.c @@ -17,9 +17,9 @@ */ #include "config.h" +#include #include - raptor_uri* slv2_ontology_uri = NULL; diff --git a/src/plugin.c b/src/plugin.c index 6571326..8918fa3 100644 --- a/src/plugin.c +++ b/src/plugin.c @@ -24,14 +24,13 @@ #include #include #include -#include #include #include #include "private_types.h" -SLV2Plugin* -slv2_plugin_duplicate(const SLV2Plugin* p) +SLV2Plugin +slv2_plugin_duplicate(SLV2Plugin p) { assert(p); struct _Plugin* result = malloc(sizeof(struct _Plugin)); @@ -47,7 +46,7 @@ slv2_plugin_duplicate(const SLV2Plugin* p) const char* -slv2_plugin_get_uri(const SLV2Plugin* p) +slv2_plugin_get_uri(SLV2Plugin p) { assert(p); return p->plugin_uri; @@ -55,7 +54,7 @@ slv2_plugin_get_uri(const SLV2Plugin* p) SLV2Strings -slv2_plugin_get_data_uris(const SLV2Plugin* p) +slv2_plugin_get_data_uris(SLV2Plugin p) { assert(p); return p->data_uris; @@ -63,7 +62,7 @@ slv2_plugin_get_data_uris(const SLV2Plugin* p) const char* -slv2_plugin_get_library_uri(const SLV2Plugin* p) +slv2_plugin_get_library_uri(SLV2Plugin p) { assert(p); return p->lib_uri; @@ -71,7 +70,7 @@ slv2_plugin_get_library_uri(const SLV2Plugin* p) bool -slv2_plugin_verify(const SLV2Plugin* plugin) +slv2_plugin_verify(SLV2Plugin plugin) { // FIXME: finish this (properly) @@ -96,7 +95,7 @@ slv2_plugin_verify(const SLV2Plugin* plugin) char* -slv2_plugin_get_name(const SLV2Plugin* plugin) +slv2_plugin_get_name(SLV2Plugin plugin) { char* result = NULL; SLV2Strings prop = slv2_plugin_get_value(plugin, "doap:name"); @@ -113,25 +112,11 @@ slv2_plugin_get_name(const SLV2Plugin* plugin) SLV2Strings -slv2_plugin_get_value(const SLV2Plugin* p, - const char* predicate) +slv2_plugin_get_value(SLV2Plugin p, + const char* predicate) { assert(predicate); - /* - char* header = slv2_query_header(p); - char* lang_filter = slv2_query_lang_filter("?value"); - - char* query_string = slv2_strjoin( - header, - "SELECT DISTINCT ?value WHERE { \n", - "plugin: ", property, " ?value . \n", - ((lang_filter != NULL) ? lang_filter : ""), - "}", 0); - - free(header); - free(lang_filter);*/ - char* query = slv2_strjoin( "SELECT DISTINCT ?value WHERE {\n" "plugin: ", predicate, " ?value .\n" @@ -146,21 +131,21 @@ slv2_plugin_get_value(const SLV2Plugin* p, SLV2Strings -slv2_plugin_get_properties(const SLV2Plugin* p) +slv2_plugin_get_properties(SLV2Plugin p) { return slv2_plugin_get_value(p, "lv2:pluginProperty"); } SLV2Strings -slv2_plugin_get_hints(const SLV2Plugin* p) +slv2_plugin_get_hints(SLV2Plugin p) { return slv2_plugin_get_value(p, "lv2:pluginHint"); } uint32_t -slv2_plugin_get_num_ports(const SLV2Plugin* p) +slv2_plugin_get_num_ports(SLV2Plugin p) { const char* const query = "SELECT DISTINCT ?port\n" @@ -171,7 +156,7 @@ slv2_plugin_get_num_ports(const SLV2Plugin* p) bool -slv2_plugin_has_latency(const SLV2Plugin* p) +slv2_plugin_has_latency(SLV2Plugin p) { const char* const query = "SELECT DISTINCT ?port WHERE {\n" @@ -190,7 +175,7 @@ slv2_plugin_has_latency(const SLV2Plugin* p) uint32_t -slv2_plugin_get_latency_port(const SLV2Plugin* p) +slv2_plugin_get_latency_port(SLV2Plugin p) { const char* const query = "SELECT DISTINCT ?value WHERE {\n" @@ -212,7 +197,7 @@ slv2_plugin_get_latency_port(const SLV2Plugin* p) SLV2Strings -slv2_plugin_get_supported_features(const SLV2Plugin* p) +slv2_plugin_get_supported_features(SLV2Plugin p) { const char* const query = "SELECT DISTINCT ?feature WHERE {\n" @@ -228,7 +213,7 @@ slv2_plugin_get_supported_features(const SLV2Plugin* p) SLV2Strings -slv2_plugin_get_optional_features(const SLV2Plugin* p) +slv2_plugin_get_optional_features(SLV2Plugin p) { const char* const query = "SELECT DISTINCT ?feature WHERE {\n" @@ -242,7 +227,7 @@ slv2_plugin_get_optional_features(const SLV2Plugin* p) SLV2Strings -slv2_plugin_get_required_features(const SLV2Plugin* p) +slv2_plugin_get_required_features(SLV2Plugin p) { const char* const query = "SELECT DISTINCT ?feature WHERE {\n" diff --git a/src/plugininstance.c b/src/plugininstance.c index 13a659a..906bfb8 100644 --- a/src/plugininstance.c +++ b/src/plugininstance.c @@ -28,8 +28,8 @@ #include "private_types.h" -SLV2Instance* -slv2_plugin_instantiate(const SLV2Plugin* plugin, +SLV2Instance +slv2_plugin_instantiate(SLV2Plugin plugin, uint32_t sample_rate, const LV2_Host_Feature** host_features) { @@ -114,7 +114,7 @@ slv2_plugin_instantiate(const SLV2Plugin* plugin, void -slv2_instance_free(SLV2Instance* instance) +slv2_instance_free(SLV2Instance instance) { struct _Instance* i = (struct _Instance*)instance; i->lv2_descriptor->cleanup(i->lv2_handle); diff --git a/src/pluginlist.c b/src/pluginlist.c index d6c1665..a6a2a97 100644 --- a/src/pluginlist.c +++ b/src/pluginlist.c @@ -114,7 +114,7 @@ slv2_plugins_load_bundle(SLV2Plugins list, /* Get all plugins explicitly mentioned in the manifest (discovery pass 1) */ char* query_string = - "PREFIX : \n\n" + "PREFIX : \n\n" "SELECT DISTINCT ?plugin_uri FROM <>\n" "WHERE { ?plugin_uri a :Plugin }\n"; @@ -179,7 +179,7 @@ slv2_plugins_load_bundle(SLV2Plugins list, const char* binary = (const char*)rasqal_literal_as_string( rasqal_query_results_get_binding_value(results, 2)); - SLV2Plugin* plugin = slv2_plugins_get_by_uri(list, subject); + SLV2Plugin plugin = slv2_plugins_get_by_uri(list, subject); if (plugin && data_uri && !slv2_strings_contains(plugin->data_uris, data_uri)) raptor_sequence_push(plugin->data_uris, strdup(data_uri)); @@ -269,7 +269,7 @@ slv2_plugins_size(const SLV2Plugins list) } -SLV2Plugin* +SLV2Plugin slv2_plugins_get_by_uri(const SLV2Plugins list, const char* uri) { if (list->num_plugins > 0) { @@ -284,7 +284,7 @@ slv2_plugins_get_by_uri(const SLV2Plugins list, const char* uri) } -SLV2Plugin* +SLV2Plugin slv2_plugins_get_at(const SLV2Plugins list, unsigned index) { if (list->num_plugins == 0) diff --git a/src/port.c b/src/port.c index c6d0c10..8a298d7 100644 --- a/src/port.c +++ b/src/port.c @@ -19,11 +19,11 @@ #define _XOPEN_SOURCE 500 #include #include +#include #include #include #include #include -#include #include @@ -50,8 +50,8 @@ slv2_port_by_symbol(const char* symbol) SLV2PortClass -slv2_port_get_class(SLV2Plugin* p, - SLV2PortID id) +slv2_port_get_class(SLV2Plugin p, + SLV2PortID id) { SLV2Strings class = slv2_port_get_value(p, id, "rdf:type"); @@ -61,7 +61,7 @@ slv2_port_get_class(SLV2Plugin* p, enum { UNKNOWN, AUDIO, CONTROL, MIDI } type = UNKNOWN; for (unsigned i=0; i < slv2_strings_size(class); ++i) { - char* value = slv2_strings_get_at(class, i); + const char* value = slv2_strings_get_at(class, i); if (!strcmp(value, "http://lv2plug.in/ontology#InputPort")) io = 0; else if (!strcmp(value, "http://lv2plug.in/ontology#OutputPort")) @@ -97,7 +97,7 @@ slv2_port_get_class(SLV2Plugin* p, SLV2Strings -slv2_port_get_value(SLV2Plugin* p, +slv2_port_get_value(SLV2Plugin p, SLV2PortID id, const char* property) { @@ -136,8 +136,8 @@ slv2_port_get_value(SLV2Plugin* p, char* -slv2_port_get_symbol(SLV2Plugin* p, - SLV2PortID id) +slv2_port_get_symbol(SLV2Plugin p, + SLV2PortID id) { char* result = NULL; @@ -154,8 +154,8 @@ slv2_port_get_symbol(SLV2Plugin* p, char* -slv2_port_get_name(SLV2Plugin* p, - SLV2PortID id) +slv2_port_get_name(SLV2Plugin p, + SLV2PortID id) { char* result = NULL; @@ -172,8 +172,8 @@ slv2_port_get_name(SLV2Plugin* p, float -slv2_port_get_default_value(SLV2Plugin* p, - SLV2PortID id) +slv2_port_get_default_value(SLV2Plugin p, + SLV2PortID id) { // FIXME: do casting properly in the SPARQL query @@ -192,8 +192,8 @@ slv2_port_get_default_value(SLV2Plugin* p, float -slv2_port_get_minimum_value(SLV2Plugin* p, - SLV2PortID id) +slv2_port_get_minimum_value(SLV2Plugin p, + SLV2PortID id) { // FIXME: do casting properly in the SPARQL query @@ -212,8 +212,8 @@ slv2_port_get_minimum_value(SLV2Plugin* p, float -slv2_port_get_maximum_value(SLV2Plugin* p, - SLV2PortID id) +slv2_port_get_maximum_value(SLV2Plugin p, + SLV2PortID id) { // FIXME: do casting properly in the SPARQL query @@ -232,16 +232,16 @@ slv2_port_get_maximum_value(SLV2Plugin* p, SLV2Strings -slv2_port_get_properties(const SLV2Plugin* p, - SLV2PortID id) +slv2_port_get_properties(SLV2Plugin p, + SLV2PortID id) { return slv2_port_get_value(p, id, "lv2:portProperty"); } SLV2Strings -slv2_port_get_hints(const SLV2Plugin* p, - SLV2PortID id) +slv2_port_get_hints(SLV2Plugin p, + SLV2PortID id) { return slv2_port_get_value(p, id, "lv2:portHint"); } diff --git a/src/private_types.h b/src/private_types.h index 0d755f8..027d68d 100644 --- a/src/private_types.h +++ b/src/private_types.h @@ -29,6 +29,11 @@ extern "C" { #include +/** The URI of the lv2.ttl file. + */ +extern raptor_uri* slv2_ontology_uri; + + /** Record of an installed/available plugin. * * A simple reference to a plugin somewhere on the system. This just holds diff --git a/src/query.c b/src/query.c index 617b1df..b671ac8 100644 --- a/src/query.c +++ b/src/query.c @@ -17,10 +17,11 @@ */ #define _XOPEN_SOURCE 500 +#include #include #include +#include #include -#include #include #include #include @@ -28,7 +29,7 @@ char* -slv2_query_header(const SLV2Plugin* p) +slv2_query_header(SLV2Plugin p) { const char* const plugin_uri = slv2_plugin_get_uri(p); //SLV2Strings files = slv2_plugin_get_data_uris(p); @@ -109,7 +110,7 @@ slv2_query_count_bindings(rasqal_query_results* results) rasqal_query_results* -slv2_plugin_query(SLV2Plugin* plugin, +slv2_plugin_query(SLV2Plugin plugin, const char* sparql_str) { raptor_uri* base_uri = raptor_new_uri((unsigned char*)slv2_plugin_get_uri(plugin)); @@ -156,7 +157,7 @@ slv2_plugin_query(SLV2Plugin* plugin, /** Query a single variable */ SLV2Strings -slv2_plugin_simple_query(SLV2Plugin* plugin, +slv2_plugin_simple_query(SLV2Plugin plugin, const char* sparql_str, const char* variable) { @@ -174,7 +175,7 @@ slv2_plugin_simple_query(SLV2Plugin* plugin, * in the number of results (ie slv2_plugin_num_ports). */ unsigned -slv2_plugin_query_count(SLV2Plugin* plugin, +slv2_plugin_query_count(SLV2Plugin plugin, const char* sparql_str) { rasqal_query_results* results = slv2_plugin_query(plugin, sparql_str); @@ -185,10 +186,9 @@ slv2_plugin_query_count(SLV2Plugin* plugin, } -// FIXME: stupid interface size_t -slv2_query_count_results(const SLV2Plugin* p, - const char* query) +slv2_query_count_results(SLV2Plugin p, + const char* query) { char* header = slv2_query_header(p); char* query_str = slv2_strjoin(header, query, NULL); @@ -222,27 +222,3 @@ slv2_query_count_results(const SLV2Plugin* p, return count; } - -/* -size_t -slv2_query_get_num_results(rasqal_query_results* results, const char* var_name) -{ - size_t result = 0; - - while (!rasqal_query_results_finished(results)) { - if (!strcmp((const char*)rasqal_query_results_get_binding_name(results, 0), var_name)) { - ++result; - } - rasqal_query_results_next(results); - } - - return result; -} -*/ - -void -slv2_strings_free(SLV2Strings list) -{ - raptor_free_sequence(list); -} - diff --git a/src/stringlist.c b/src/stringlist.c index bdb173e..930454f 100644 --- a/src/stringlist.c +++ b/src/stringlist.c @@ -30,25 +30,32 @@ slv2_strings_new() } +void +slv2_strings_free(SLV2Strings list) +{ + raptor_free_sequence(list); +} + + unsigned -slv2_strings_size(const SLV2Strings list) +slv2_strings_size(SLV2Strings list) { return raptor_sequence_size(list); } -char* -slv2_strings_get_at(const SLV2Strings list, unsigned index) +const char* +slv2_strings_get_at(SLV2Strings list, unsigned index) { if (index > INT_MAX) return NULL; else - return (char*)raptor_sequence_get_at(list, (int)index); + return (const char*)raptor_sequence_get_at(list, (int)index); } bool -slv2_strings_contains(const SLV2Strings list, const char* uri) +slv2_strings_contains(SLV2Strings list, const char* uri) { for (unsigned i=0; i < slv2_strings_size(list); ++i) if (!strcmp(slv2_strings_get_at(list, i), uri)) diff --git a/utils/lv2_inspect.c b/utils/lv2_inspect.c index 077aefe..31dd2f9 100644 --- a/utils/lv2_inspect.c +++ b/utils/lv2_inspect.c @@ -22,7 +22,7 @@ void -print_port(SLV2Plugin* p, uint32_t index) +print_port(SLV2Plugin p, uint32_t index) { SLV2PortID id = slv2_port_by_index(index); @@ -76,7 +76,7 @@ print_port(SLV2Plugin* p, uint32_t index) void -print_plugin(SLV2Plugin* p) +print_plugin(SLV2Plugin p) { char* str = NULL; @@ -130,7 +130,7 @@ main(int argc, char** argv) SLV2Plugins plugins = slv2_plugins_new(); slv2_plugins_load_all(plugins); - SLV2Plugin* p = slv2_plugins_get_by_uri(plugins, argv[1]); + SLV2Plugin p = slv2_plugins_get_by_uri(plugins, argv[1]); if (!p) { fprintf(stderr, "Plugin not found.\n"); diff --git a/utils/lv2_list.c b/utils/lv2_list.c index a1966fd..c8e430d 100644 --- a/utils/lv2_list.c +++ b/utils/lv2_list.c @@ -24,7 +24,7 @@ void list_plugins(SLV2Plugins list) { for (unsigned i=0; i < slv2_plugins_size(list); ++i) { - const SLV2Plugin* const p = slv2_plugins_get_at(list, i); + SLV2Plugin p = slv2_plugins_get_at(list, i); printf("%s\n", slv2_plugin_get_uri(p)); } } -- cgit v1.2.1