diff options
author | David Robillard <d@drobilla.net> | 2006-12-09 07:43:15 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2006-12-09 07:43:15 +0000 |
commit | d5e8ce8127784fc67953ab3b6247e911be697cc2 (patch) | |
tree | 41ed069b23a9cab56b4443cf699b26080a590ae5 /src/libs | |
parent | d2d755b0db3b4779d581c7a70841609257250c12 (diff) | |
download | ingen-d5e8ce8127784fc67953ab3b6247e911be697cc2.tar.gz ingen-d5e8ce8127784fc67953ab3b6247e911be697cc2.tar.bz2 ingen-d5e8ce8127784fc67953ab3b6247e911be697cc2.zip |
Preliminary patch loading (just loads nodes from RDF).
git-svn-id: http://svn.drobilla.net/lad/ingen@214 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'src/libs')
-rw-r--r-- | src/libs/client/Loader.cpp | 57 | ||||
-rw-r--r-- | src/libs/client/Loader.h | 48 | ||||
-rw-r--r-- | src/libs/client/Makefile.am | 8 | ||||
-rw-r--r-- | src/libs/client/PluginModel.h | 8 | ||||
-rw-r--r-- | src/libs/client/RDFQuery.cpp | 66 | ||||
-rw-r--r-- | src/libs/client/RDFQuery.h | 60 | ||||
-rw-r--r-- | src/libs/client/RDFWriter.cpp | 4 | ||||
-rw-r--r-- | src/libs/client/Serializer.cpp | 44 | ||||
-rw-r--r-- | src/libs/client/Serializer.h | 24 |
9 files changed, 282 insertions, 37 deletions
diff --git a/src/libs/client/Loader.cpp b/src/libs/client/Loader.cpp new file mode 100644 index 00000000..7816e88a --- /dev/null +++ b/src/libs/client/Loader.cpp @@ -0,0 +1,57 @@ +/* This file is part of Ingen. Copyright (C) 2006 Dave Robillard. + * + * Ingen 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. + * + * Ingen 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 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 <iostream> +#include "Loader.h" +#include "RDFQuery.h" +#include "ModelEngineInterface.h" + +namespace Ingen { +namespace Client { + + +Loader::Loader(SharedPtr<ModelEngineInterface> engine) + : _engine(engine) +{ +} + + +/** Load (create) all objects from an RDF into the engine. + * + * @param filename Filename to load objects from. + * @param parent Path of parent under which to load objects. + * @return whether or not load was successful. + */ +void +Loader::load(const Glib::ustring& filename, + const Path& parent) +{ + RDFQuery query(Glib::ustring("SELECT DISTINCT ?name ?plugin FROM <") + filename + "> WHERE {\n" + + "?patch ingen:node ?node .\n" + + "?node ingen:name ?name ;\n" + + " ingen:plugin ?plugin .\n" + + "}"); + + RDFQuery::Results nodes = query.run(filename); + + for (RDFQuery::Results::iterator i = nodes.begin(); i != nodes.end(); ++i) + _engine->create_node(parent.base() + (*i)["name"], (*i)["plugin"], false); +} + + +} // namespace Client +} // namespace Ingen + diff --git a/src/libs/client/Loader.h b/src/libs/client/Loader.h new file mode 100644 index 00000000..5fd31d52 --- /dev/null +++ b/src/libs/client/Loader.h @@ -0,0 +1,48 @@ +/* This file is part of Ingen. Copyright (C) 2006 Dave Robillard. + * + * Ingen 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. + * + * Ingen 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 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 LOADER_H +#define LOADER_H + +#include <glibmm/ustring.h> +#include "raul/SharedPtr.h" +#include "raul/Path.h" + +namespace Ingen { +namespace Client { + +class ModelEngineInterface; + + +/** Loads objects (patches, nodes, etc) into the engine from RDF. + */ +class Loader { +public: + Loader(SharedPtr<ModelEngineInterface> engine); + + void load(const Glib::ustring& filename, + const Path& parent); + +private: + //string _patch_search_path; + SharedPtr<ModelEngineInterface> _engine; +}; + + +} // namespace Client +} // namespace Ingen + +#endif // LOADER_H diff --git a/src/libs/client/Makefile.am b/src/libs/client/Makefile.am index cde46fbd..48811414 100644 --- a/src/libs/client/Makefile.am +++ b/src/libs/client/Makefile.am @@ -3,8 +3,8 @@ AM_CXXFLAGS = -I$(top_srcdir)/src/common if BUILD_CLIENT_LIB noinst_LTLIBRARIES = libingenclient.la -libingenclient_la_CXXFLAGS = -I$(top_srcdir)/src/common -DPKGDATADIR=\"$(pkgdatadir)\" @LXML2_CFLAGS@ @RAPTOR_CFLAGS@ @LSIGCPP_CFLAGS@ @RAUL_CFLAGS@ -libingenclient_la_LIBADD = @LXML2_LIBS@ @LOSC_LIBS@ @RAPTOR_LIBS@ @LSIGCPP_LIBS@ @RAUL_LIBS@ +libingenclient_la_CXXFLAGS = -I$(top_srcdir)/src/common -DPKGDATADIR=\"$(pkgdatadir)\" @LXML2_CFLAGS@ @RAPTOR_CFLAGS@ @LSIGCPP_CFLAGS@ @RAUL_CFLAGS@ @GLIBMM_CFLAGS@ +libingenclient_la_LIBADD = @LXML2_LIBS@ @LOSC_LIBS@ @RAPTOR_LIBS@ @LSIGCPP_LIBS@ @RAUL_LIBS@ @GLIBMM_LIBS@ libingenclient_la_SOURCES = \ OSCEngineSender.h \ @@ -30,8 +30,12 @@ libingenclient_la_SOURCES = \ PluginModel.h \ RDFWriter.h \ RDFWriter.cpp \ + RDFQuery.h \ + RDFQuery.cpp \ Serializer.h \ Serializer.cpp \ + Loader.h \ + Loader.cpp \ DeprecatedSerializer.h \ DeprecatedSerializer.cpp \ ConnectionModel.h \ diff --git a/src/libs/client/PluginModel.h b/src/libs/client/PluginModel.h index 76edc737..7af4f169 100644 --- a/src/libs/client/PluginModel.h +++ b/src/libs/client/PluginModel.h @@ -59,10 +59,10 @@ public: }*/ const char* const type_uri() const { - if (m_type == LV2) return "ingen:LV2"; - else if (m_type == LADSPA) return "ingen:LADSPA"; - else if (m_type == DSSI) return "ingen:DSSI"; - else if (m_type == Internal) return "ingen:Internal"; + if (m_type == LV2) return "ingen:LV2Plugin"; + else if (m_type == LADSPA) return "ingen:LADSPAPlugin"; + else if (m_type == DSSI) return "ingen:DSSIPlugin"; + else if (m_type == Internal) return "ingen:InternalPlugin"; else if (m_type == Patch) return "ingen:Patch"; else return ""; } diff --git a/src/libs/client/RDFQuery.cpp b/src/libs/client/RDFQuery.cpp new file mode 100644 index 00000000..8e08848a --- /dev/null +++ b/src/libs/client/RDFQuery.cpp @@ -0,0 +1,66 @@ +/* This file is part of Ingen. Copyright (C) 2006 Dave Robillard. + * + * Ingen 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. + * + * Ingen 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 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 <iostream> +#include <cassert> +#include <rasqal.h> +#include "RDFQuery.h" + +namespace Ingen { +namespace Client { + + +RDFQuery::Results +RDFQuery::run(const Glib::ustring filename) +{ + Results result; + + rasqal_init(); + + rasqal_query *rq = rasqal_new_query("sparql", NULL); + + rasqal_query_prepare(rq, (unsigned char*)_query.c_str(), NULL); + rasqal_query_results* results = rasqal_query_execute(rq); + assert(results); + + while (!rasqal_query_results_finished(results)) { + + Bindings bindings; + + for (int i=0; i < rasqal_query_results_get_bindings_count(results); i++) { + const unsigned char* rname = rasqal_query_results_get_binding_name(results, i); + rasqal_literal* rvalue = rasqal_query_results_get_binding_value(results, i); + + Glib::ustring name((const char*)rname); + Glib::ustring value((const char*)rasqal_literal_as_string(rvalue)); + + bindings.insert(std::make_pair(name, value)); + } + + result.push_back(bindings); + rasqal_query_results_next(results); + } + + rasqal_free_query_results(results); + rasqal_free_query(rq); + rasqal_finish(); + + return result; +} + + +} // namespace Client +} // namespace Ingen diff --git a/src/libs/client/RDFQuery.h b/src/libs/client/RDFQuery.h new file mode 100644 index 00000000..3e7a1521 --- /dev/null +++ b/src/libs/client/RDFQuery.h @@ -0,0 +1,60 @@ +/* This file is part of Ingen. Copyright (C) 2006 Dave Robillard. + * + * Ingen 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. + * + * Ingen 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 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 RDFQUERY_H +#define RDFQUERY_H + +#include <map> +#include <list> +#include <glibmm/ustring.h> + +namespace Ingen { +namespace Client { + + +/** Pretty wrapper for a SPARQL query. + * + * Automatically handles things like prepending prefixes, etc. Ingen specific. + */ +class RDFQuery { +public: + typedef std::map<Glib::ustring, Glib::ustring> Bindings; + typedef std::list<Bindings> Results; + + RDFQuery(Glib::ustring query) + { + const char* const _prefix_header = + "PREFIX ingen: <http://codeson.net/ns/ingen#>\n" + "PREFIX lv2: <http://lv2plug.in/ontology#>\n"; + + _query = _prefix_header + query; + } + + Results run(const Glib::ustring filename); + + Glib::ustring string() { return _query; } + +private: + + Glib::ustring _query; +}; + + +} // namespace Client +} // namespace Ingen + +#endif // RDFQUERY_H + diff --git a/src/libs/client/RDFWriter.cpp b/src/libs/client/RDFWriter.cpp index e1762ed2..649c8a1a 100644 --- a/src/libs/client/RDFWriter.cpp +++ b/src/libs/client/RDFWriter.cpp @@ -19,8 +19,8 @@ #define U(x) ((const unsigned char*)(x)) -static const char* const RDF_LANG = "rdfxml-abbrev"; -//static const char* const RDF_LANG = "turtle"; +//static const char* const RDF_LANG = "rdfxml-abbrev"; +static const char* const RDF_LANG = "turtle"; RDFWriter::RDFWriter() diff --git a/src/libs/client/Serializer.cpp b/src/libs/client/Serializer.cpp index 3984a49a..b8929546 100644 --- a/src/libs/client/Serializer.cpp +++ b/src/libs/client/Serializer.cpp @@ -47,18 +47,6 @@ namespace Ingen { namespace Client { -Serializer::Serializer(SharedPtr<ModelEngineInterface> engine) - : _patch_search_path(".") - , _engine(engine) -{ -} - - -Serializer::~Serializer() -{ -} - - /** Begin a serialization to a file. * * This must be called before any serializing methods. @@ -111,7 +99,7 @@ Serializer::path_to_node_id(const Path& path) return RdfId(RdfId::ANONYMOUS, ret); } - +#if 0 /** Searches for the filename passed in the path, returning the full * path of the file, or the empty string if not found. * @@ -160,7 +148,7 @@ Serializer::find_file(const string& filename, const string& additional_path) return ""; } - +#endif void Serializer::serialize(SharedPtr<ObjectModel> object) throw (std::logic_error) @@ -235,8 +223,18 @@ Serializer::serialize_patch(SharedPtr<PatchModel> patch, unsigned depth) for (ConnectionList::const_iterator c = patch->connections().begin(); c != patch->connections().end(); ++c) { serialize_connection(*c); } - - //_engine->set_metadata(patch->path(), "uri", uri); +} + + +void +Serializer::serialize_plugin(SharedPtr<PluginModel> plugin) +{ + const RdfId plugin_id = RdfId(RdfId::RESOURCE, plugin->uri()); + + _writer.write( + plugin_id, + NS_RDF("type"), + RdfId(RdfId::RESOURCE, plugin->type_uri())); } @@ -249,11 +247,25 @@ Serializer::serialize_node(SharedPtr<NodeModel> node, unsigned depth) ? RdfId(RdfId::RESOURCE, string("#") + node->path().substr(1)) : path_to_node_id(node->path()); // anonymous + const RdfId plugin_id = RdfId(RdfId::RESOURCE, node->plugin()->uri()); + _writer.write( node_id, NS_RDF("type"), NS_INGEN("Node")); + _writer.write( + node_id, + NS_INGEN("name"), + node->path().name()); + + _writer.write( + node_id, + NS_INGEN("plugin"), + plugin_id); + + //serialize_plugin(node->plugin()); + /*_writer.write(_serializer, node_uri_ref.c_str(), NS_INGEN("name"), diff --git a/src/libs/client/Serializer.h b/src/libs/client/Serializer.h index 5fe00199..8ae18313 100644 --- a/src/libs/client/Serializer.h +++ b/src/libs/client/Serializer.h @@ -14,8 +14,8 @@ * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -#ifndef PATCHLIBRARIAN_H -#define PATCHLIBRARIAN_H +#ifndef SERIALIZER_H +#define SERIALIZER_H #include <map> #include <utility> @@ -36,6 +36,7 @@ using boost::optional; namespace Ingen { namespace Client { +class PluginModel; class PatchModel; class NodeModel; class PortModel; @@ -49,20 +50,17 @@ class ModelEngineInterface; #define NS_INGEN(x) RdfId(RdfId::RESOURCE, "http://codeson.net/ns/ingen#" x) -/** Handles all patch saving and loading. +/** Serializes Ingen objects (patches, nodes, etc) to RDF. * * \ingroup IngenClient */ class Serializer { public: - Serializer(SharedPtr<ModelEngineInterface> engine); - ~Serializer(); - - void path(const string& path) { _patch_search_path = path; } - const string& path() { return _patch_search_path; } + //void path(const string& path) { _patch_search_path = path; } + //const string& path() { return _patch_search_path; } - string find_file(const string& filename, const string& additional_path = ""); + //string find_file(const string& filename, const string& additional_path = ""); bool load_patch(bool merge, const string& data_base_uri, @@ -81,19 +79,19 @@ public: private: + void serialize_plugin(SharedPtr<PluginModel> p); + void serialize_patch(SharedPtr<PatchModel> p, unsigned depth); void serialize_node(SharedPtr<NodeModel> n, unsigned depth); void serialize_port(SharedPtr<PortModel> p, unsigned depth); RdfId path_to_node_id(const Path& path); - RDFWriter _writer; - string _patch_search_path; - SharedPtr<ModelEngineInterface> _engine; + RDFWriter _writer; }; } // namespace Client } // namespace Ingen -#endif // PATCHLIBRARIAN_H +#endif // SERIALIZER_H |