From 081352a14c7c4f73113d9a491280e327eec14c83 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sat, 21 Apr 2007 01:23:59 +0000 Subject: Changed "categories" to "plugin classes" to better match RDF. Renamed files to match API. git-svn-id: http://svn.drobilla.net/lad/slv2@466 a436a847-0d15-0410-975c-d299462d15a1 --- slv2/Makefile.am | 8 +- slv2/categories.h | 80 ------------- slv2/category.h | 70 ------------ slv2/plugin.h | 8 +- slv2/pluginclass.h | 70 ++++++++++++ slv2/pluginclasses.h | 80 +++++++++++++ slv2/pluginlist.h | 95 ---------------- slv2/plugins.h | 95 ++++++++++++++++ slv2/port.h | 2 +- slv2/slv2.h | 6 +- slv2/stringlist.h | 84 -------------- slv2/strings.h | 84 ++++++++++++++ slv2/types.h | 4 +- slv2/world.h | 33 +++++- src/Makefile.am | 8 +- src/categories.c | 90 --------------- src/category.c | 57 ---------- src/plugin.c | 33 ++++-- src/pluginclass.c | 57 ++++++++++ src/pluginclasses.c | 90 +++++++++++++++ src/pluginlist.c | 314 --------------------------------------------------- src/plugins.c | 314 +++++++++++++++++++++++++++++++++++++++++++++++++++ src/private_types.h | 26 ++--- src/query.c | 2 +- src/stringlist.c | 65 ----------- src/strings.c | 65 +++++++++++ src/world.c | 39 ++++--- utils/lv2_inspect.c | 2 +- 28 files changed, 963 insertions(+), 918 deletions(-) delete mode 100644 slv2/categories.h delete mode 100644 slv2/category.h create mode 100644 slv2/pluginclass.h create mode 100644 slv2/pluginclasses.h delete mode 100644 slv2/pluginlist.h create mode 100644 slv2/plugins.h delete mode 100644 slv2/stringlist.h create mode 100644 slv2/strings.h delete mode 100644 src/categories.c delete mode 100644 src/category.c create mode 100644 src/pluginclass.c create mode 100644 src/pluginclasses.c delete mode 100644 src/pluginlist.c create mode 100644 src/plugins.c delete mode 100644 src/stringlist.c create mode 100644 src/strings.c diff --git a/slv2/Makefile.am b/slv2/Makefile.am index 8e1b827..05fc432 100644 --- a/slv2/Makefile.am +++ b/slv2/Makefile.am @@ -5,12 +5,12 @@ slv2include_HEADERS = \ types.h \ slv2.h \ world.h \ - category.h \ - categories.h \ + pluginclass.h \ + pluginclasses.h \ plugin.h \ port.h \ - pluginlist.h \ + plugins.h \ plugininstance.h \ - stringlist.h \ + strings.h \ util.h diff --git a/slv2/categories.h b/slv2/categories.h deleted file mode 100644 index 44b9aee..0000000 --- a/slv2/categories.h +++ /dev/null @@ -1,80 +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_CATEGORIES_H__ -#define __SLV2_CATEGORIES_H__ - -#include - -#ifdef __cplusplus -extern "C" { -#endif - - -typedef void* SLV2Categories; - - -/** \defgroup categories Categories - * - * @{ - */ - -/** Get the number of plugins in the list. - */ -unsigned -slv2_categories_size(SLV2Categories list); - - -/** Get a category from the list by URI. - * - * Return value is shared (stored in \a list) and must not be freed or - * modified by the caller in any way. - * - * Time = O(log2(n)) - * - * \return NULL if plugin with \a url not found in \a list. - */ -SLV2Category -slv2_categories_get_by_uri(SLV2Categories list, - const char* uri); - - -/** Get a plugin from the list by index. - * - * \a index has no significance other than as an index into this list. - * Any \a index not less than slv2_categories_get_length(list) will return NULL, - * so all categories in a list can be enumerated by repeated calls - * to this function starting with \a index = 0. - * - * Time = O(1) - * - * \return NULL if \a index out of range. - */ -SLV2Category -slv2_categories_get_at(SLV2Categories list, - unsigned index); - - -/** @} */ - -#ifdef __cplusplus -} -#endif - -#endif /* __SLV2_CATEGORIES_H__ */ - diff --git a/slv2/category.h b/slv2/category.h deleted file mode 100644 index 1d0159f..0000000 --- a/slv2/category.h +++ /dev/null @@ -1,70 +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_CATEGORY_H__ -#define __SLV2_CATEGORY_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -#include - -/** \addtogroup data - * @{ - */ - - -/** Get the URI of this category. - * - * Returned value is owned by \a category and must not be freed by caller. - * - * Time = O(1) - */ -const char* slv2_category_get_uri(SLV2Category category); - - -/** Get the label of this category, ie "Oscillators". - * - * Returned value is owned by \a category and must not be freed by caller. - * - * Time = O(1) - */ -const char* slv2_category_get_label(SLV2Category category); - -#if 0 -/** Get the path of this category, ie "Plugins/Generators/Oscillators". - * - * SLV2 automatically generates an ideal category heirarchy given the plugins - * present. The last fragment of the path is the category's label, - * as returned by slv2_category_get_label. - * - * Returned value is owned by \a category and must not be freed by caller. - * - * Time = O(1) - */ -const char* slv2_category_get_path(SLV2Category category); -#endif - -/** @} */ - -#ifdef __cplusplus -} -#endif - -#endif /* __SLV2_CATEGORY_H__ */ diff --git a/slv2/plugin.h b/slv2/plugin.h index 4db5130..c8f4be0 100644 --- a/slv2/plugin.h +++ b/slv2/plugin.h @@ -27,7 +27,7 @@ extern "C" { #include #include #include -#include +#include /** \defgroup data Plugin data access * @@ -134,10 +134,10 @@ char* slv2_plugin_get_name(SLV2Plugin plugin); -/** Get the category this plugin belongs to. +/** Get the class this plugin belongs to (ie Filters). */ -SLV2Category -slv2_plugin_get_category(SLV2Plugin plugin); +SLV2PluginClass +slv2_plugin_get_class(SLV2Plugin plugin); /** Get a value associated with the plugin in a plugin's data files. diff --git a/slv2/pluginclass.h b/slv2/pluginclass.h new file mode 100644 index 0000000..1124bd8 --- /dev/null +++ b/slv2/pluginclass.h @@ -0,0 +1,70 @@ +/* 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_PLUGIN_CLASS_H__ +#define __SLV2_PLUGIN_CLASS_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +/** \addtogroup data + * @{ + */ + + +/** Get the URI of this plugin class. + * + * Returned value is owned by \a plugin_class and must not be freed by caller. + * + * Time = O(1) + */ +const char* slv2_plugin_class_get_uri(SLV2PluginClass plugin_class); + + +/** Get the label of this plugin_class, ie "Oscillators". + * + * Returned value is owned by \a plugin_class and must not be freed by caller. + * + * Time = O(1) + */ +const char* slv2_plugin_class_get_label(SLV2PluginClass plugin_class); + +#if 0 +/** Get the path of this plugin_class, ie "Plugins/Generators/Oscillators". + * + * SLV2 automatically generates an ideal plugin_class heirarchy given the plugins + * present. The last fragment of the path is the plugin_class's label, + * as returned by slv2_plugin_class_get_label. + * + * Returned value is owned by \a plugin_class and must not be freed by caller. + * + * Time = O(1) + */ +const char* slv2_plugin_class_get_path(SLV2PluginClass plugin_class); +#endif + +/** @} */ + +#ifdef __cplusplus +} +#endif + +#endif /* __SLV2_PLUGIN_CLASS_H__ */ diff --git a/slv2/pluginclasses.h b/slv2/pluginclasses.h new file mode 100644 index 0000000..39177b8 --- /dev/null +++ b/slv2/pluginclasses.h @@ -0,0 +1,80 @@ +/* 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_PLUGIN_CLASSES_H__ +#define __SLV2_PLUGIN_CLASSES_H__ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + + +typedef void* SLV2PluginClasses; + + +/** \defgroup plugin_classes Plugin classes (categories) + * + * @{ + */ + +/** Get the number of plugins in the list. + */ +unsigned +slv2_plugin_classes_size(SLV2PluginClasses list); + + +/** Get a plugin class from the list by URI. + * + * Return value is shared (stored in \a list) and must not be freed or + * modified by the caller in any way. + * + * Time = O(log2(n)) + * + * \return NULL if plugin with \a url not found in \a list. + */ +SLV2PluginClass +slv2_plugin_classes_get_by_uri(SLV2PluginClasses list, + const char* uri); + + +/** Get a plugin from the list by index. + * + * \a index has no significance other than as an index into this list. + * Any \a index not less than slv2_plugin_classes_get_length(list) will return NULL, + * so all plugin_classes in a list can be enumerated by repeated calls + * to this function starting with \a index = 0. + * + * Time = O(1) + * + * \return NULL if \a index out of range. + */ +SLV2PluginClass +slv2_plugin_classes_get_at(SLV2PluginClasses list, + unsigned index); + + +/** @} */ + +#ifdef __cplusplus +} +#endif + +#endif /* __SLV2_PLUGIN_CLASSES_H__ */ + diff --git a/slv2/pluginlist.h b/slv2/pluginlist.h deleted file mode 100644 index a2978e1..0000000 --- a/slv2/pluginlist.h +++ /dev/null @@ -1,95 +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_PLUGINLIST_H__ -#define __SLV2_PLUGINLIST_H__ - -#include - -#ifdef __cplusplus -extern "C" { -#endif - - -typedef void* SLV2Plugins; - - -/** \defgroup plugins Plugin lists - * - * These functions work with lists of plugins which come from an - * SLV2World. These lists contain only a weak reference to an LV2 plugin - * in the Model. - * - * @{ - */ - - -/** Free a plugin list. - * - * Freeing a plugin list does not destroy the plugins it contains (plugins - * are owned by the world). \a list is invalid after this call. - */ -void -slv2_plugins_free(SLV2World world, - SLV2Plugins list); - - -/** Get the number of plugins in the list. - */ -unsigned -slv2_plugins_size(SLV2Plugins list); - - -/** Get a plugin from the list by URI. - * - * Return value is shared (stored in \a list) and must not be freed or - * modified by the caller in any way. - * - * Time = O(log2(n)) - * - * \return NULL if plugin with \a url not found in \a list. - */ -SLV2Plugin -slv2_plugins_get_by_uri(SLV2Plugins list, - const char* uri); - - -/** Get a plugin from the list by index. - * - * \a index has no significance other than as an index into this list. - * Any \a index not less than slv2_list_get_length(list) will return NULL, - * so all plugins in a list can be enumerated by repeated calls - * to this function starting with \a index = 0. - * - * Time = O(1) - * - * \return NULL if \a index out of range. - */ -SLV2Plugin -slv2_plugins_get_at(SLV2Plugins list, - unsigned index); - - -/** @} */ - -#ifdef __cplusplus -} -#endif - -#endif /* __SLV2_PLUGINLIST_H__ */ - diff --git a/slv2/plugins.h b/slv2/plugins.h new file mode 100644 index 0000000..7b9a5a3 --- /dev/null +++ b/slv2/plugins.h @@ -0,0 +1,95 @@ +/* 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_PLUGINS_H__ +#define __SLV2_PLUGINS_H__ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + + +typedef void* SLV2Plugins; + + +/** \defgroup plugins Plugin lists + * + * These functions work with lists of plugins which come from an + * SLV2World. These lists contain only a weak reference to an LV2 plugin + * in the Model. + * + * @{ + */ + + +/** Free a plugin list. + * + * Freeing a plugin list does not destroy the plugins it contains (plugins + * are owned by the world). \a list is invalid after this call. + */ +void +slv2_plugins_free(SLV2World world, + SLV2Plugins list); + + +/** Get the number of plugins in the list. + */ +unsigned +slv2_plugins_size(SLV2Plugins list); + + +/** Get a plugin from the list by URI. + * + * Return value is shared (stored in \a list) and must not be freed or + * modified by the caller in any way. + * + * Time = O(log2(n)) + * + * \return NULL if plugin with \a url not found in \a list. + */ +SLV2Plugin +slv2_plugins_get_by_uri(SLV2Plugins list, + const char* uri); + + +/** Get a plugin from the list by index. + * + * \a index has no significance other than as an index into this list. + * Any \a index not less than slv2_list_get_length(list) will return NULL, + * so all plugins in a list can be enumerated by repeated calls + * to this function starting with \a index = 0. + * + * Time = O(1) + * + * \return NULL if \a index out of range. + */ +SLV2Plugin +slv2_plugins_get_at(SLV2Plugins list, + unsigned index); + + +/** @} */ + +#ifdef __cplusplus +} +#endif + +#endif /* __SLV2_PLUGINS_H__ */ + diff --git a/slv2/port.h b/slv2/port.h index d415f84..165c1f1 100644 --- a/slv2/port.h +++ b/slv2/port.h @@ -26,7 +26,7 @@ extern "C" { #include #include #include -#include +#include /** \addtogroup data * @{ diff --git a/slv2/slv2.h b/slv2/slv2.h index a052e56..2d89e4e 100644 --- a/slv2/slv2.h +++ b/slv2/slv2.h @@ -25,12 +25,12 @@ extern "C" { #include #include -#include +#include #include #include -#include +#include #include -#include +#include #ifdef __cplusplus diff --git a/slv2/stringlist.h b/slv2/stringlist.h deleted file mode 100644 index eb613d6..0000000 --- a/slv2/stringlist.h +++ /dev/null @@ -1,84 +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_STRINGLIST_H__ -#define __SLV2_STRINGLIST_H__ - -#include - -#ifdef __cplusplus -extern "C" { -#endif - - -/** \defgroup strings Collections of strings - * - * SLV2Strings is an ordered collection of strings which is fast for random - * access by index (i.e. a fancy array). - * - * @{ - */ - - -typedef void* SLV2Strings; - - -/** Allocate a new, empty SLV2Strings - */ -SLV2Strings -slv2_strings_new(); - - -/** Get the number of elements in a string list. - */ -unsigned -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. - * - * Time = O(1) - */ -const char* -slv2_strings_get_at(SLV2Strings list, unsigned index); - - -/** Return whether \a list contains \a string. - * - * Time = O(n) - */ -bool -slv2_strings_contains(SLV2Strings list, const char* string); - - -/** Free a string list. - */ -void -slv2_strings_free(SLV2Strings); - - -/** @} */ - -#ifdef __cplusplus -} -#endif - -#endif /* __SLV2_STRINGLIST_H__ */ - diff --git a/slv2/strings.h b/slv2/strings.h new file mode 100644 index 0000000..5a16025 --- /dev/null +++ b/slv2/strings.h @@ -0,0 +1,84 @@ +/* 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_STRINGS_H__ +#define __SLV2_STRINGS_H__ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + + +/** \defgroup strings Collections of strings + * + * SLV2Strings is an ordered collection of strings which is fast for random + * access by index (i.e. a fancy array). + * + * @{ + */ + + +typedef void* SLV2Strings; + + +/** Allocate a new, empty SLV2Strings + */ +SLV2Strings +slv2_strings_new(); + + +/** Get the number of elements in a string list. + */ +unsigned +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. + * + * Time = O(1) + */ +const char* +slv2_strings_get_at(SLV2Strings list, unsigned index); + + +/** Return whether \a list contains \a string. + * + * Time = O(n) + */ +bool +slv2_strings_contains(SLV2Strings list, const char* string); + + +/** Free a string list. + */ +void +slv2_strings_free(SLV2Strings); + + +/** @} */ + +#ifdef __cplusplus +} +#endif + +#endif /* __SLV2_STRINGS_H__ */ + diff --git a/slv2/types.h b/slv2/types.h index f595dd1..42f2e59 100644 --- a/slv2/types.h +++ b/slv2/types.h @@ -56,8 +56,8 @@ typedef struct _Plugin* SLV2Plugin; typedef struct _World* SLV2World; -/** A plugin category. Opaque, but valid to compare to NULL. */ -typedef struct _Category* SLV2Category; +/** A plugin class. Opaque, but valid to compare to NULL. */ +typedef struct _PluginClass* SLV2PluginClass; #ifdef __cplusplus diff --git a/slv2/world.h b/slv2/world.h index 64f0fc2..59b0adc 100644 --- a/slv2/world.h +++ b/slv2/world.h @@ -19,7 +19,8 @@ #ifndef __SLV2_WORLD_H__ #define __SLV2_WORLD_H__ -#include +#include +#include #ifdef __cplusplus extern "C" { @@ -102,6 +103,16 @@ slv2_world_load_bundle(SLV2World world, const char* bundle_uri); +/** Return a list of all found plugin classes. + * + * Returned list is owned by world and must not be freed by the caller. + * + * Time = O(1) + */ +SLV2PluginClasses +slv2_world_get_plugin_classes(SLV2World world); + + /** Return a list of all found plugins. * * The returned list contains just enough references to query @@ -110,8 +121,8 @@ slv2_world_load_bundle(SLV2World world, * a query (at which time the data is cached with the SLV2Plugin so future * queries are very fast). * - * Returned plugins contain a reference to this world, world must not be - * destroyed until plugins are finished with. + * Returned list must be freed by user with slv2_plugins_free. The contained + * plugins are owned by \a world and must not be freed by caller. * * Time = O(1) */ @@ -125,8 +136,8 @@ slv2_world_get_all_plugins(SLV2World world); * \a include (a pointer to a function which takes an SLV2Plugin and returns * a bool) will be in the returned list. * - * Returned plugins contain a reference to this world, world must not be - * destroyed until plugins are finished with. + * Returned list must be freed by user with slv2_plugins_free. The contained + * plugins are owned by \a world and must not be freed by caller. * * Time = O(n * Time(include)) */ @@ -135,6 +146,18 @@ slv2_world_get_plugins_by_filter(SLV2World world, bool (*include)(SLV2Plugin)); +/** Return a list of found plugins in a given class. + * + * Returned list must be freed by user with slv2_plugins_free. The contained + * plugins are owned by \a world and must not be freed by caller. + * + * Time = O(n) + */ +SLV2Plugins +slv2_world_get_plugins_by_class(SLV2World world, + SLV2PluginClass plugin_class); + + #if 0 /** Get plugins filtered by a user-defined SPARQL query. * diff --git a/src/Makefile.am b/src/Makefile.am index cc5a774..11f7aa8 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -7,12 +7,12 @@ libslv2_la_LIBADD = @REDLAND_LIBS@ libslv2_la_SOURCES = \ private_types.h \ world.c \ - category.c \ - categories.c \ + pluginclass.c \ + pluginclasses.c \ plugin.c \ query.c \ port.c \ - pluginlist.c \ + plugins.c \ plugininstance.c \ - stringlist.c \ + strings.c \ util.c diff --git a/src/categories.c b/src/categories.c deleted file mode 100644 index 133e7ee..0000000 --- a/src/categories.c +++ /dev/null @@ -1,90 +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. - */ - -#define _XOPEN_SOURCE 500 - -#include -#include -#include -#include -#include -#include "private_types.h" - - -SLV2Categories -slv2_categories_new() -{ - return raptor_new_sequence((void (*)(void*))&slv2_category_free, NULL); -} - - -void -slv2_categories_free(SLV2Categories list) -{ - //if (list != world->categories) - raptor_free_sequence(list); -} - - -unsigned -slv2_categories_size(SLV2Categories list) -{ - return raptor_sequence_size(list); -} - - -SLV2Category -slv2_categories_get_by_uri(SLV2Categories list, const char* uri) -{ - // good old fashioned binary search - - int lower = 0; - int upper = raptor_sequence_size(list) - 1; - int i; - - if (upper == 0) - return NULL; - - while (upper >= lower) { - i = lower + ((upper - lower) / 2); - - SLV2Category p = raptor_sequence_get_at(list, i); - - int cmp = strcmp(slv2_category_get_uri(p), uri); - - if (cmp == 0) - return p; - else if (cmp > 0) - upper = i - 1; - else - lower = i + 1; - } - - return NULL; -} - - -SLV2Category -slv2_categories_get_at(SLV2Categories list, unsigned index) -{ - if (index > INT_MAX) - return NULL; - else - return (SLV2Category)raptor_sequence_get_at(list, (int)index); -} - diff --git a/src/category.c b/src/category.c deleted file mode 100644 index 5eae2af..0000000 --- a/src/category.c +++ /dev/null @@ -1,57 +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. - */ - -#define _XOPEN_SOURCE 500 - -#include -#include -#include -#include "private_types.h" - - -SLV2Category -slv2_category_new(const char* uri, const char* label) -{ - SLV2Category category = (SLV2Category)malloc(sizeof(struct _Category)); - category->uri = strdup(uri); - category->label = strdup(label); - return category; -} - - -void -slv2_category_free(SLV2Category category) -{ - free(category->uri); - free(category->label); - free(category); -} - - -const char* -slv2_category_get_uri(SLV2Category category) -{ - return category->uri; -} - - -const char* -slv2_category_get_label(SLV2Category category) -{ - return category->label; -} diff --git a/src/plugin.c b/src/plugin.c index 7fe8e1d..6216ab7 100644 --- a/src/plugin.c +++ b/src/plugin.c @@ -25,7 +25,7 @@ #include #include #include -#include +#include #include "private_types.h" @@ -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->category = NULL; + plugin->plugin_class = NULL; plugin->data_uris = slv2_strings_new(); plugin->ports = raptor_new_sequence((void (*)(void*))&slv2_port_free, NULL); plugin->storage = NULL; @@ -146,7 +146,7 @@ slv2_plugin_load(SLV2Plugin p) librdf_free_uri(data_uri); } - // Load category + // Load plugin_class const unsigned char* query = (const unsigned char*) "SELECT DISTINCT ?class WHERE { <> a ?class }"; @@ -160,16 +160,20 @@ slv2_plugin_load(SLV2Plugin p) librdf_uri* class_uri = librdf_node_get_uri(class_node); const char* class_uri_str = (const char*)librdf_uri_as_string(class_uri); - SLV2Category category = slv2_categories_get_by_uri(p->world->categories, class_uri_str); + SLV2PluginClass plugin_class = slv2_plugin_classes_get_by_uri( + p->world->plugin_classes, class_uri_str); - if (category) { - p->category = category; + if (plugin_class) { + p->plugin_class = plugin_class; break; } librdf_query_results_next(results); } + if (p->plugin_class == NULL) + fprintf(stderr, "Warning: Unclassy plugin: %s\n", slv2_plugin_get_uri(p)); + // Load ports query = (const unsigned char*) "PREFIX : \n" @@ -242,13 +246,13 @@ slv2_plugin_get_library_uri(SLV2Plugin p) } -SLV2Category -slv2_plugin_get_category(SLV2Plugin p) +SLV2PluginClass +slv2_plugin_get_plugin_class(SLV2Plugin p) { - if (!p->category) + if (!p->plugin_class) slv2_plugin_load(p); - return p->category; + return p->plugin_class; } @@ -325,6 +329,15 @@ slv2_plugin_get_name(SLV2Plugin plugin) } +/** Get the class this plugin belongs to (ie Filters). + */ +SLV2PluginClass +slv2_plugin_get_class(SLV2Plugin plugin) +{ + return plugin->plugin_class; +} + + SLV2Strings slv2_plugin_get_value(SLV2Plugin p, const char* predicate) diff --git a/src/pluginclass.c b/src/pluginclass.c new file mode 100644 index 0000000..3669b9b --- /dev/null +++ b/src/pluginclass.c @@ -0,0 +1,57 @@ +/* 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. + */ + +#define _XOPEN_SOURCE 500 + +#include +#include +#include +#include "private_types.h" + + +SLV2PluginClass +slv2_plugin_class_new(const char* uri, const char* label) +{ + SLV2PluginClass plugin_class = (SLV2PluginClass)malloc(sizeof(struct _PluginClass)); + plugin_class->uri = strdup(uri); + plugin_class->label = strdup(label); + return plugin_class; +} + + +void +slv2_plugin_class_free(SLV2PluginClass plugin_class) +{ + free(plugin_class->uri); + free(plugin_class->label); + free(plugin_class); +} + + +const char* +slv2_plugin_class_get_uri(SLV2PluginClass plugin_class) +{ + return plugin_class->uri; +} + + +const char* +slv2_plugin_class_get_label(SLV2PluginClass plugin_class) +{ + return plugin_class->label; +} diff --git a/src/pluginclasses.c b/src/pluginclasses.c new file mode 100644 index 0000000..919201e --- /dev/null +++ b/src/pluginclasses.c @@ -0,0 +1,90 @@ +/* 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. + */ + +#define _XOPEN_SOURCE 500 + +#include +#include +#include +#include +#include +#include "private_types.h" + + +SLV2PluginClasses +slv2_plugin_classes_new() +{ + return raptor_new_sequence((void (*)(void*))&slv2_plugin_class_free, NULL); +} + + +void +slv2_plugin_classes_free(SLV2PluginClasses list) +{ + //if (list != world->plugin_classes) + raptor_free_sequence(list); +} + + +unsigned +slv2_plugin_classes_size(SLV2PluginClasses list) +{ + return raptor_sequence_size(list); +} + + +SLV2PluginClass +slv2_plugin_classes_get_by_uri(SLV2PluginClasses list, const char* uri) +{ + // good old fashioned binary search + + int lower = 0; + int upper = raptor_sequence_size(list) - 1; + int i; + + if (upper == 0) + return NULL; + + while (upper >= lower) { + i = lower + ((upper - lower) / 2); + + SLV2PluginClass p = raptor_sequence_get_at(list, i); + + int cmp = strcmp(slv2_plugin_class_get_uri(p), uri); + + if (cmp == 0) + return p; + else if (cmp > 0) + upper = i - 1; + else + lower = i + 1; + } + + return NULL; +} + + +SLV2PluginClass +slv2_plugin_classes_get_at(SLV2PluginClasses list, unsigned index) +{ + if (index > INT_MAX) + return NULL; + else + return (SLV2PluginClass)raptor_sequence_get_at(list, (int)index); +} + diff --git a/src/pluginlist.c b/src/pluginlist.c deleted file mode 100644 index da003a5..0000000 --- a/src/pluginlist.c +++ /dev/null @@ -1,314 +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. - */ - -#define _XOPEN_SOURCE 500 -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "private_types.h" - - -SLV2Plugins -slv2_plugins_new() -{ - //return raptor_new_sequence((void (*)(void*))&slv2_plugin_free, NULL); - return raptor_new_sequence(NULL, NULL); -} - - -void -slv2_plugins_free(SLV2World world, SLV2Plugins list) -{ - if (list != world->plugins) - raptor_free_sequence(list); -} - -#if 0 -void -slv2_plugins_filter(SLV2Plugins dest, SLV2Plugins source, bool (*include)(SLV2Plugin)) -{ - assert(dest); - - for (int i=0; i < raptor_sequence_size(source); ++i) { - SLV2Plugin p = raptor_sequence_get_at(source, i); - if (include(p)) - raptor_sequence_push(dest, slv2_plugin_duplicate(p)); - } -} - - -void -slv2_plugins_load_all(SLV2Plugins list) -{ - /* FIXME: this is much slower than it should be in many ways.. */ - - assert(list); - - char* slv2_path = getenv("LV2_PATH"); - - SLV2Plugins load_list = slv2_plugins_new(); - - if (slv2_path) { - slv2_plugins_load_path(load_list, slv2_path); - } else { - const char* const home = getenv("HOME"); - const char* const suffix = "/.lv2:/usr/local/lib/lv2:usr/lib/lv2"; - slv2_path = slv2_strjoin(home, suffix, NULL); - - fprintf(stderr, "$LV2_PATH is unset. Using default path %s\n", slv2_path); - - /* pass 1: find all plugins */ - slv2_plugins_load_path(load_list, slv2_path); - - /* pass 2: find all data files for plugins */ - slv2_plugins_load_path(load_list, slv2_path); - - free(slv2_path); - } - - /* insert only valid plugins into list */ - slv2_plugins_filter(list, load_list, slv2_plugin_verify); - slv2_plugins_free(load_list); -} - - -/* This is the parser for manifest.ttl - * This is called twice on each bundle in the discovery process, which is (much) less - * efficient than it could be.... */ -void -slv2_plugins_load_bundle(SLV2Plugins list, - const char* bundle_base_url) -{ - assert(list); - - unsigned char* manifest_url = malloc( - (strlen((char*)bundle_base_url) + strlen("manifest.ttl") + 2) * sizeof(unsigned char)); - memcpy(manifest_url, bundle_base_url, strlen((char*)bundle_base_url)+1 * sizeof(unsigned char)); - if (bundle_base_url[strlen(bundle_base_url)-1] == '/') - strcat((char*)manifest_url, "manifest.ttl"); - else - strcat((char*)manifest_url, "/manifest.ttl"); - - librdf_query_results *results; - librdf_uri *base_uri = librdf_new_uri(slv2_rdf_world, manifest_url); - - /* Get all plugins explicitly mentioned in the manifest (discovery pass 1) */ - char* query_string = - "PREFIX : \n\n" - "SELECT DISTINCT ?plugin_uri FROM <>\n" - "WHERE { ?plugin_uri a :Plugin }\n"; - - librdf_query *rq = librdf_new_query(slv2_rdf_world, "sparql", NULL, - (unsigned char*)query_string, base_uri); - - - - //printf("%s\n\n", query_string); - - results = librdf_query_execute(rq, model->model); - - while (!librdf_query_results_finished(results)) { - - librdf_node* literal = librdf_query_results_get_binding_value(results, 0); - assert(literal); - - if (!slv2_plugins_get_by_uri(list, (const char*)librdf_node_get_literal_value(literal))) { - /* Create a new plugin */ - struct _Plugin* new_plugin = slv2_plugin_new(); - new_plugin->plugin_uri = strdup((const char*)librdf_node_get_literal_value(literal)); - new_plugin->bundle_url = strdup(bundle_base_url); - raptor_sequence_push(new_plugin->data_uris, strdup((const char*)manifest_url)); - - raptor_sequence_push(list, new_plugin); - - } - - librdf_query_results_next(results); - } - - if (results) - librdf_free_query_results(results); - - librdf_free_query(rq); - - /* Get all data files linked to plugins (discovery pass 2) */ - query_string = - "PREFIX rdfs: \n" - "PREFIX : \n\n" - "SELECT DISTINCT ?subject ?data_uri ?binary FROM <>\n" - "WHERE { ?subject rdfs:seeAlso ?data_uri\n" - "OPTIONAL { ?subject :binary ?binary } }\n"; - - rq = librdf_new_query(slv2_rdf_world, "sparql", NULL, - (unsigned char*)query_string, base_uri); - - //printf("%s\n\n", query_string); - - results = librdf_query_execute(rq, slv2_model); - - while (!librdf_query_results_finished(results)) { - - const char* subject = (const char*)librdf_node_get_literal_value( - librdf_query_results_get_binding_value(results, 0)); - - const char* data_uri = (const char*)librdf_node_get_literal_value( - librdf_query_results_get_binding_value(results, 1)); - - const char* binary = (const char*)librdf_node_get_literal_value( - librdf_query_results_get_binding_value(results, 2)); - - 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)); - - if (plugin && binary && !plugin->lib_uri) - ((struct _Plugin*)plugin)->lib_uri = strdup(binary); - - librdf_query_results_next(results); - - } - - if (results) - librdf_free_query_results(results); - - librdf_free_query(rq); - - librdf_free_uri(base_uri); - free(manifest_url); -} - - -/* Add all the plugins found in dir to list. - * (Private helper function, not exposed in public API) - */ -void -slv2_plugins_load_dir(SLV2Plugins list, const char* dir) -{ - assert(list); - - DIR* pdir = opendir(dir); - if (!pdir) - return; - - struct dirent* pfile; - while ((pfile = readdir(pdir))) { - if (!strcmp(pfile->d_name, ".") || !strcmp(pfile->d_name, "..")) - continue; - - char* bundle_path = slv2_strjoin(dir, "/", pfile->d_name, NULL); - char* bundle_url = slv2_strjoin("file://", dir, "/", pfile->d_name, NULL); - DIR* bundle_dir = opendir(bundle_path); - - if (bundle_dir != NULL) { - closedir(bundle_dir); - - slv2_plugins_load_bundle(list, bundle_url); - //printf("Loaded bundle %s\n", bundle_url); - } - - free(bundle_path); - free(bundle_url); - } - - closedir(pdir); -} - - -void -slv2_plugins_load_path(SLV2Plugins list, - const char* lv2_path) -{ - assert(list); - - 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_plugins_load_dir(list, dir); - - *delim = 'X'; - dir = delim + 1; - } - - //char* slv2_path = strdup(slv2 - - free(path); -} -#endif - -unsigned -slv2_plugins_size(SLV2Plugins list) -{ - return raptor_sequence_size(list); -} - - -SLV2Plugin -slv2_plugins_get_by_uri(SLV2Plugins list, const char* uri) -{ - // good old fashioned binary search - - int lower = 0; - int upper = raptor_sequence_size(list) - 1; - int i; - - if (upper == 0) - return NULL; - - while (upper >= lower) { - i = lower + ((upper - lower) / 2); - - SLV2Plugin p = raptor_sequence_get_at(list, i); - - int cmp = strcmp(slv2_plugin_get_uri(p), uri); - - if (cmp == 0) - return p; - else if (cmp > 0) - upper = i - 1; - else - lower = i + 1; - } - - return NULL; -} - - -SLV2Plugin -slv2_plugins_get_at(SLV2Plugins list, unsigned index) -{ - if (index > INT_MAX) - return NULL; - else - return (SLV2Plugin)raptor_sequence_get_at(list, (int)index); -} - diff --git a/src/plugins.c b/src/plugins.c new file mode 100644 index 0000000..9d62398 --- /dev/null +++ b/src/plugins.c @@ -0,0 +1,314 @@ +/* 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. + */ + +#define _XOPEN_SOURCE 500 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "private_types.h" + + +SLV2Plugins +slv2_plugins_new() +{ + //return raptor_new_sequence((void (*)(void*))&slv2_plugin_free, NULL); + return raptor_new_sequence(NULL, NULL); +} + + +void +slv2_plugins_free(SLV2World world, SLV2Plugins list) +{ + if (list != world->plugins) + raptor_free_sequence(list); +} + +#if 0 +void +slv2_plugins_filter(SLV2Plugins dest, SLV2Plugins source, bool (*include)(SLV2Plugin)) +{ + assert(dest); + + for (int i=0; i < raptor_sequence_size(source); ++i) { + SLV2Plugin p = raptor_sequence_get_at(source, i); + if (include(p)) + raptor_sequence_push(dest, slv2_plugin_duplicate(p)); + } +} + + +void +slv2_plugins_load_all(SLV2Plugins list) +{ + /* FIXME: this is much slower than it should be in many ways.. */ + + assert(list); + + char* slv2_path = getenv("LV2_PATH"); + + SLV2Plugins load_list = slv2_plugins_new(); + + if (slv2_path) { + slv2_plugins_load_path(load_list, slv2_path); + } else { + const char* const home = getenv("HOME"); + const char* const suffix = "/.lv2:/usr/local/lib/lv2:usr/lib/lv2"; + slv2_path = slv2_strjoin(home, suffix, NULL); + + fprintf(stderr, "$LV2_PATH is unset. Using default path %s\n", slv2_path); + + /* pass 1: find all plugins */ + slv2_plugins_load_path(load_list, slv2_path); + + /* pass 2: find all data files for plugins */ + slv2_plugins_load_path(load_list, slv2_path); + + free(slv2_path); + } + + /* insert only valid plugins into list */ + slv2_plugins_filter(list, load_list, slv2_plugin_verify); + slv2_plugins_free(load_list); +} + + +/* This is the parser for manifest.ttl + * This is called twice on each bundle in the discovery process, which is (much) less + * efficient than it could be.... */ +void +slv2_plugins_load_bundle(SLV2Plugins list, + const char* bundle_base_url) +{ + assert(list); + + unsigned char* manifest_url = malloc( + (strlen((char*)bundle_base_url) + strlen("manifest.ttl") + 2) * sizeof(unsigned char)); + memcpy(manifest_url, bundle_base_url, strlen((char*)bundle_base_url)+1 * sizeof(unsigned char)); + if (bundle_base_url[strlen(bundle_base_url)-1] == '/') + strcat((char*)manifest_url, "manifest.ttl"); + else + strcat((char*)manifest_url, "/manifest.ttl"); + + librdf_query_results *results; + librdf_uri *base_uri = librdf_new_uri(slv2_rdf_world, manifest_url); + + /* Get all plugins explicitly mentioned in the manifest (discovery pass 1) */ + char* query_string = + "PREFIX : \n\n" + "SELECT DISTINCT ?plugin_uri FROM <>\n" + "WHERE { ?plugin_uri a :Plugin }\n"; + + librdf_query *rq = librdf_new_query(slv2_rdf_world, "sparql", NULL, + (unsigned char*)query_string, base_uri); + + + + //printf("%s\n\n", query_string); + + results = librdf_query_execute(rq, model->model); + + while (!librdf_query_results_finished(results)) { + + librdf_node* literal = librdf_query_results_get_binding_value(results, 0); + assert(literal); + + if (!slv2_plugins_get_by_uri(list, (const char*)librdf_node_get_literal_value(literal))) { + /* Create a new plugin */ + struct _Plugin* new_plugin = slv2_plugin_new(); + new_plugin->plugin_uri = strdup((const char*)librdf_node_get_literal_value(literal)); + new_plugin->bundle_url = strdup(bundle_base_url); + raptor_sequence_push(new_plugin->data_uris, strdup((const char*)manifest_url)); + + raptor_sequence_push(list, new_plugin); + + } + + librdf_query_results_next(results); + } + + if (results) + librdf_free_query_results(results); + + librdf_free_query(rq); + + /* Get all data files linked to plugins (discovery pass 2) */ + query_string = + "PREFIX rdfs: \n" + "PREFIX : \n\n" + "SELECT DISTINCT ?subject ?data_uri ?binary FROM <>\n" + "WHERE { ?subject rdfs:seeAlso ?data_uri\n" + "OPTIONAL { ?subject :binary ?binary } }\n"; + + rq = librdf_new_query(slv2_rdf_world, "sparql", NULL, + (unsigned char*)query_string, base_uri); + + //printf("%s\n\n", query_string); + + results = librdf_query_execute(rq, slv2_model); + + while (!librdf_query_results_finished(results)) { + + const char* subject = (const char*)librdf_node_get_literal_value( + librdf_query_results_get_binding_value(results, 0)); + + const char* data_uri = (const char*)librdf_node_get_literal_value( + librdf_query_results_get_binding_value(results, 1)); + + const char* binary = (const char*)librdf_node_get_literal_value( + librdf_query_results_get_binding_value(results, 2)); + + 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)); + + if (plugin && binary && !plugin->lib_uri) + ((struct _Plugin*)plugin)->lib_uri = strdup(binary); + + librdf_query_results_next(results); + + } + + if (results) + librdf_free_query_results(results); + + librdf_free_query(rq); + + librdf_free_uri(base_uri); + free(manifest_url); +} + + +/* Add all the plugins found in dir to list. + * (Private helper function, not exposed in public API) + */ +void +slv2_plugins_load_dir(SLV2Plugins list, const char* dir) +{ + assert(list); + + DIR* pdir = opendir(dir); + if (!pdir) + return; + + struct dirent* pfile; + while ((pfile = readdir(pdir))) { + if (!strcmp(pfile->d_name, ".") || !strcmp(pfile->d_name, "..")) + continue; + + char* bundle_path = slv2_strjoin(dir, "/", pfile->d_name, NULL); + char* bundle_url = slv2_strjoin("file://", dir, "/", pfile->d_name, NULL); + DIR* bundle_dir = opendir(bundle_path); + + if (bundle_dir != NULL) { + closedir(bundle_dir); + + slv2_plugins_load_bundle(list, bundle_url); + //printf("Loaded bundle %s\n", bundle_url); + } + + free(bundle_path); + free(bundle_url); + } + + closedir(pdir); +} + + +void +slv2_plugins_load_path(SLV2Plugins list, + const char* lv2_path) +{ + assert(list); + + 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_plugins_load_dir(list, dir); + + *delim = 'X'; + dir = delim + 1; + } + + //char* slv2_path = strdup(slv2 + + free(path); +} +#endif + +unsigned +slv2_plugins_size(SLV2Plugins list) +{ + return raptor_sequence_size(list); +} + + +SLV2Plugin +slv2_plugins_get_by_uri(SLV2Plugins list, const char* uri) +{ + // good old fashioned binary search + + int lower = 0; + int upper = raptor_sequence_size(list) - 1; + int i; + + if (upper == 0) + return NULL; + + while (upper >= lower) { + i = lower + ((upper - lower) / 2); + + SLV2Plugin p = raptor_sequence_get_at(list, i); + + int cmp = strcmp(slv2_plugin_get_uri(p), uri); + + if (cmp == 0) + return p; + else if (cmp > 0) + upper = i - 1; + else + lower = i + 1; + } + + return NULL; +} + + +SLV2Plugin +slv2_plugins_get_at(SLV2Plugins list, unsigned index) +{ + if (index > INT_MAX) + return NULL; + else + return (SLV2Plugin)raptor_sequence_get_at(list, (int)index); +} + diff --git a/src/private_types.h b/src/private_types.h index ff4580c..a0337ac 100644 --- a/src/private_types.h +++ b/src/private_types.h @@ -27,7 +27,7 @@ extern "C" { #include #include #include -#include +#include /** Reference to a port on some plugin. @@ -54,7 +54,7 @@ struct _Plugin { librdf_uri* plugin_uri; // char* bundle_url; // Bundle directory plugin was loaded from char* binary_uri; // lv2:binary - SLV2Category category; + SLV2PluginClass plugin_class; raptor_sequence* data_uris; // rdfs::seeAlso raptor_sequence* ports; librdf_storage* storage; @@ -80,26 +80,26 @@ struct _InstanceImpl { }; -struct _Category { +struct _PluginClass { char* uri; char* label; }; -SLV2Category slv2_category_new(const char* uri, const char* label); -void slv2_category_free(SLV2Category category); +SLV2PluginClass slv2_plugin_class_new(const char* uri, const char* label); +void slv2_plugin_class_free(SLV2PluginClass class); -SLV2Categories slv2_categories_new(); -void slv2_categories_free(); +SLV2PluginClasses slv2_plugin_classes_new(); +void slv2_plugin_classes_free(); /** Model of LV2 (RDF) data loaded from bundles. */ struct _World { - librdf_world* world; - librdf_storage* storage; - librdf_model* model; - librdf_parser* parser; - SLV2Categories categories; - SLV2Plugins plugins; + librdf_world* world; + librdf_storage* storage; + librdf_model* model; + librdf_parser* parser; + SLV2PluginClasses plugin_classes; + SLV2Plugins plugins; }; /** Load all bundles found in \a search_path. diff --git a/src/query.c b/src/query.c index 56a7412..a4d8e16 100644 --- a/src/query.c +++ b/src/query.c @@ -23,7 +23,7 @@ #include #include #include -#include +#include #include "private_types.h" diff --git a/src/stringlist.c b/src/stringlist.c deleted file mode 100644 index 2233e7e..0000000 --- a/src/stringlist.c +++ /dev/null @@ -1,65 +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. - */ - -#include -#include -#include -#include -#include - - -SLV2Strings -slv2_strings_new() -{ - return raptor_new_sequence(&free, NULL); -} - - -void -slv2_strings_free(SLV2Strings list) -{ - raptor_free_sequence(list); -} - - -unsigned -slv2_strings_size(SLV2Strings list) -{ - return raptor_sequence_size(list); -} - - -const char* -slv2_strings_get_at(SLV2Strings list, unsigned index) -{ - if (index > INT_MAX) - return NULL; - else - return (const char*)raptor_sequence_get_at(list, (int)index); -} - - -bool -slv2_strings_contains(SLV2Strings list, const char* str) -{ - for (unsigned i=0; i < slv2_strings_size(list); ++i) - if (!strcmp(slv2_strings_get_at(list, i), str)) - return true; - - return false; -} diff --git a/src/strings.c b/src/strings.c new file mode 100644 index 0000000..39da54f --- /dev/null +++ b/src/strings.c @@ -0,0 +1,65 @@ +/* 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. + */ + +#include +#include +#include +#include +#include + + +SLV2Strings +slv2_strings_new() +{ + return raptor_new_sequence(&free, NULL); +} + + +void +slv2_strings_free(SLV2Strings list) +{ + raptor_free_sequence(list); +} + + +unsigned +slv2_strings_size(SLV2Strings list) +{ + return raptor_sequence_size(list); +} + + +const char* +slv2_strings_get_at(SLV2Strings list, unsigned index) +{ + if (index > INT_MAX) + return NULL; + else + return (const char*)raptor_sequence_get_at(list, (int)index); +} + + +bool +slv2_strings_contains(SLV2Strings list, const char* str) +{ + for (unsigned i=0; i < slv2_strings_size(list); ++i) + if (!strcmp(slv2_strings_get_at(list, i), str)) + return true; + + return false; +} diff --git a/src/world.c b/src/world.c index c8735ea..d4d47b2 100644 --- a/src/world.c +++ b/src/world.c @@ -44,7 +44,7 @@ slv2_world_new() world->parser = librdf_new_parser(world->world, "turtle", NULL, NULL); - world->categories = slv2_categories_new(); + world->plugin_classes = slv2_plugin_classes_new(); world->plugins = slv2_plugins_new(); @@ -60,8 +60,8 @@ slv2_world_free(SLV2World world) raptor_free_sequence(world->plugins); world->plugins = NULL; - slv2_categories_free(world->categories); - world->categories = NULL; + slv2_plugin_classes_free(world->plugin_classes); + world->plugin_classes = NULL; librdf_free_parser(world->parser); world->parser = NULL; @@ -164,17 +164,18 @@ slv2_plugin_compare_by_uri(const void* a, const void* b) void -slv2_world_load_categories(SLV2World world) +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 categories) + // then the ontology (ie classes which aren't LV2 plugin_classes) unsigned char* query_string = (unsigned char*) "PREFIX : \n" "PREFIX rdfs: \n" - "SELECT DISTINCT ?category ?label\n" - "WHERE { ?category a rdfs:Class; rdfs:label ?label }\n" - "ORDER BY ?category\n"; + "SELECT DISTINCT ?class ?label WHERE {\n" + //" ?plugin a :Plugin; a ?class .\n" + " ?class a rdfs:Class; rdfs:label ?label\n" + "} ORDER BY ?class\n"; librdf_query* q = librdf_new_query(world->world, "sparql", NULL, query_string, NULL); @@ -182,16 +183,17 @@ slv2_world_load_categories(SLV2World world) librdf_query_results* results = librdf_query_execute(q, world->model); while (!librdf_query_results_finished(results)) { - librdf_node* category_node = librdf_query_results_get_binding_value(results, 0); - librdf_uri* category_uri = librdf_node_get_uri(category_node); + librdf_node* class_node = librdf_query_results_get_binding_value(results, 0); + librdf_uri* class_uri = librdf_node_get_uri(class_node); librdf_node* label_node = librdf_query_results_get_binding_value(results, 1); const char* label = (const char*)librdf_node_get_literal_value(label_node); - //printf("CATEGORY: %s (%s)\n", librdf_uri_as_string(category_uri), label); - SLV2Category category = slv2_category_new( - (const char*)librdf_uri_as_string(category_uri), + //printf("CLASS: %s (%s)\n", librdf_uri_as_string(class_uri), label); + + SLV2PluginClass plugin_class = slv2_plugin_class_new( + (const char*)librdf_uri_as_string(class_uri), label); - raptor_sequence_push(world->categories, category); + raptor_sequence_push(world->plugin_classes, plugin_class); librdf_query_results_next(results); } @@ -228,7 +230,7 @@ slv2_world_load_all(SLV2World world) /* 3. Query out things to cache */ - slv2_world_load_categories(world); + slv2_world_load_plugin_classes(world); // Find all plugins and associated data files unsigned char* query_string = (unsigned char*) @@ -307,6 +309,13 @@ slv2_world_serialize(const char* filename) #endif +SLV2PluginClasses +slv2_world_get_plugin_classes(SLV2World world) +{ + return world->plugin_classes; +} + + SLV2Plugins slv2_world_get_all_plugins(SLV2World world) { diff --git a/utils/lv2_inspect.c b/utils/lv2_inspect.c index 75b6fac..f1e1881 100644 --- a/utils/lv2_inspect.c +++ b/utils/lv2_inspect.c @@ -97,7 +97,7 @@ print_plugin(SLV2Plugin p) printf("\tName: %s\n\n", str); free(str); - const char* class_label = slv2_category_get_label(slv2_plugin_get_category(p)); + const char* class_label = slv2_plugin_class_get_label(slv2_plugin_get_class(p)); printf("\tClass: %s\n\n", class_label); if (slv2_plugin_has_latency(p)) -- cgit v1.2.1