diff options
Diffstat (limited to 'src/serialisation')
-rw-r--r-- | src/serialisation/Parser.cpp | 209 | ||||
-rw-r--r-- | src/serialisation/Parser.hpp | 26 | ||||
-rw-r--r-- | src/serialisation/Serialiser.cpp | 176 | ||||
-rw-r--r-- | src/serialisation/Serialiser.hpp | 21 | ||||
-rw-r--r-- | src/serialisation/wscript | 2 |
5 files changed, 218 insertions, 216 deletions
diff --git a/src/serialisation/Parser.cpp b/src/serialisation/Parser.cpp index df97fb78..f1ba2ed2 100644 --- a/src/serialisation/Parser.cpp +++ b/src/serialisation/Parser.cpp @@ -22,8 +22,7 @@ #include <glibmm/fileutils.h> #include <glibmm/convert.h> #include "raul/log.hpp" -#include "redlandmm/Model.hpp" -#include "redlandmm/Node.hpp" +#include "sord/sordmm.hpp" #include "raul/TableImpl.hpp" #include "raul/Atom.hpp" #include "raul/AtomRDF.hpp" @@ -33,6 +32,9 @@ #include "Parser.hpp" #include "names.hpp" +#include "serd/serd.h" +#include "sord/sordmm.hpp" + #define LOG(s) s << "[Parser] " #define NS_INGEN "http://drobilla.net/ns/ingen#" @@ -44,9 +46,9 @@ using namespace std; using namespace Raul; using namespace Ingen::Shared; -static const Redland::Node nil; +static const Sord::Node nil; -typedef set<Redland::Node> RDFNodes; +typedef set<Sord::Node> RDFNodes; namespace Ingen { namespace Serialisation { @@ -55,16 +57,26 @@ namespace Serialisation { static Glib::ustring relative_uri(Glib::ustring base, const Glib::ustring uri, bool leading_slash) { - raptor_uri* base_uri = raptor_new_uri((const unsigned char*)base.c_str()); - raptor_uri* full_uri = raptor_new_uri((const unsigned char*)uri.c_str()); + if (uri == base) { + return leading_slash ? "/" : ""; + } + + SerdURI base_uri; + serd_uri_parse((const uint8_t*)base.c_str(), &base_uri); - Glib::ustring ret((const char*)raptor_uri_to_relative_uri_string(base_uri, full_uri)); + SerdURI normal_base_uri; + SerdNode normal_base_uri_node = serd_node_new_uri_from_string( + (const uint8_t*)".", &base_uri, &normal_base_uri); - raptor_free_uri(base_uri); - raptor_free_uri(full_uri); + Glib::ustring normal_base_str((const char*)normal_base_uri_node.buf); - if (leading_slash && ret[0] != '/') - ret = Glib::ustring("/") + ret; + Glib::ustring ret = uri; + if (uri.length() >= normal_base_str.length() + && uri.substr(0, normal_base_str.length()) == normal_base_str) { + ret = uri.substr(normal_base_str.length()); + if (leading_slash && ret[0] != '/') + ret = Glib::ustring("/") + ret; + } return ret; } @@ -84,22 +96,21 @@ Parser::find_patches( Ingen::Shared::World* world, const Glib::ustring& manifest_uri) { - //Redland::Model model(*world->rdf_world(), manifest_uri, manifest_uri); - Redland::Model model(*world->rdf_world(), manifest_uri); + Sord::Model model(*world->rdf_world(), manifest_uri); model.load_file(manifest_uri); - Redland::Resource rdf_type(*world->rdf_world(), NS_RDF "type"); - Redland::Resource rdfs_seeAlso(*world->rdf_world(), NS_RDFS "seeAlso"); - Redland::Resource ingen_Patch(*world->rdf_world(), NS_INGEN "Patch"); + Sord::Resource rdf_type(*world->rdf_world(), NS_RDF "type"); + Sord::Resource rdfs_seeAlso(*world->rdf_world(), NS_RDFS "seeAlso"); + Sord::Resource ingen_Patch(*world->rdf_world(), NS_INGEN "Patch"); RDFNodes patches; - for (Redland::Iter i = model.find(nil, rdf_type, ingen_Patch); !i.end(); ++i) { + for (Sord::Iter i = model.find(nil, rdf_type, ingen_Patch); !i.end(); ++i) { patches.insert(i.get_subject()); } std::list<PatchRecord> records; for (RDFNodes::const_iterator i = patches.begin(); i != patches.end(); ++i) { - Redland::Iter f = model.find(*i, rdfs_seeAlso, nil); + Sord::Iter f = model.find(*i, rdfs_seeAlso, nil); if (f.end()) { LOG(error) << "Patch has no rdfs:seeAlso" << endl; continue; @@ -127,7 +138,11 @@ Parser::parse_document( { normalise_uri(document_uri); - assert(document_uri[document_uri.length() - 1] == '/'); + if (document_uri.substr(document_uri.length() - 4) != ".ttl") { + if (document_uri[document_uri.length() - 1] != '/') { + document_uri.append("/"); + } + } const std::string filename(Glib::filename_from_uri(document_uri)); const size_t ext = filename.find(INGEN_BUNDLE_EXT); @@ -139,7 +154,7 @@ Parser::parse_document( document_uri += basename + INGEN_PATCH_FILE_EXT; } - Redland::Model model(*world->rdf_world(), document_uri); + Sord::Model model(*world->rdf_world(), document_uri); model.load_file(document_uri); LOG(info) << "Parsing " << document_uri << endl; @@ -175,7 +190,7 @@ Parser::parse_string( boost::optional<Raul::Symbol> symbol, boost::optional<GraphObject::Properties> data) { - Redland::Model model(*world->rdf_world(), base_uri); + Sord::Model model(*world->rdf_world(), base_uri); model.load_string(str.c_str(), str.length(), base_uri); LOG(info) << "Parsing " << (data_path ? data_path->str() : "*") << " from string"; @@ -184,7 +199,7 @@ Parser::parse_string( info << endl; bool ret = parse(world, target, model, base_uri, data_path, parent, symbol, data); - Redland::Resource subject(*world->rdf_world(), base_uri); + Sord::Resource subject(*world->rdf_world(), base_uri); parse_connections(world, target, model, subject, parent ? *parent : "/"); return ret; @@ -203,20 +218,20 @@ Parser::parse_update( boost::optional<GraphObject::Properties> data) { #if 0 - Redland::Model model(*world->rdf_world(), str.c_str(), str.length(), base_uri); + Sord::Model model(*world->rdf_world(), str.c_str(), str.length(), base_uri); // Delete anything explicitly declared to not exist Glib::ustring query_str = Glib::ustring("SELECT DISTINCT ?o WHERE { ?o a owl:Nothing }"); - Redland::Query query(*world->rdf_world(), query_str); - SharedPtr<Redland::QueryResults> results(query.run(*world->rdf_world(), model, base_uri)); + Sord::Query query(*world->rdf_world(), query_str); + SharedPtr<Sord::QueryResults> results(query.run(*world->rdf_world(), model, base_uri)); for (; !results->finished(); results->next()) { - const Redland::Node& object = results->get("o"); + const Sord::Node& object = results->get("o"); target->del(object.to_string()); } // Properties - query = Redland::Query(*world->rdf_world(), + query = Sord::Query(*world->rdf_world(), "SELECT DISTINCT ?s ?p ?o WHERE {\n" "?s ?p ?o .\n" "}"); @@ -226,7 +241,7 @@ Parser::parse_update( Glib::Mutex::Lock lock(world->rdf_world()->mutex()); string obj_uri(results->get("s").to_string()); const string key(results->get("p").to_string()); - const Redland::Node& val_node(results->get("o")); + const Sord::Node& val_node(results->get("o")); const Atom a(AtomRDF::node_to_atom(model, val_node)); if (obj_uri.find(":") == string::npos) obj_uri = Path(obj_uri).str(); @@ -237,11 +252,11 @@ Parser::parse_update( // Connections - Redland::Resource subject(*world->rdf_world(), base_uri); + Sord::Resource subject(*world->rdf_world(), base_uri); parse_connections(world, target, model, subject, "/"); // Port values - query = Redland::Query(*world->rdf_world(), + query = Sord::Query(*world->rdf_world(), "SELECT DISTINCT ?path ?value WHERE {\n" "?path ingen:value ?value .\n" "}"); @@ -249,8 +264,8 @@ Parser::parse_update( results = query.run(*world->rdf_world(), model, base_uri); for (; !results->finished(); results->next()) { Glib::Mutex::Lock lock(world->rdf_world()->mutex()); - const string obj_path = results->get("path").to_string(); - const Redland::Node& val_node = results->get("value"); + const string obj_path = results->get("path").to_string(); + const Sord::Node& val_node = results->get("value"); const Atom a(AtomRDF::node_to_atom(model, val_node)); target->set_property(obj_path, world->uris()->ingen_value, a); } @@ -265,30 +280,30 @@ boost::optional<Path> Parser::parse( Ingen::Shared::World* world, Ingen::Shared::CommonInterface* target, - Redland::Model& model, + Sord::Model& model, Glib::ustring document_uri, boost::optional<Raul::Path> data_path, boost::optional<Raul::Path> parent, boost::optional<Raul::Symbol> symbol, boost::optional<GraphObject::Properties> data) { - const Redland::Node::Type res = Redland::Node::RESOURCE; + const Sord::Node::Type res = Sord::Node::RESOURCE; - const Redland::Resource rdf_type(*world->rdf_world(), NS_RDF "type"); + const Sord::Resource rdf_type(*world->rdf_world(), NS_RDF "type"); - const Redland::Node patch_class (*world->rdf_world(), res, NS_INGEN "Patch"); - const Redland::Node node_class (*world->rdf_world(), res, NS_INGEN "Node"); - const Redland::Node internal_class (*world->rdf_world(), res, NS_INGEN "Internal"); - const Redland::Node ladspa_class (*world->rdf_world(), res, NS_INGEN "LADSPAPlugin"); - const Redland::Node in_port_class (*world->rdf_world(), res, NS_LV2 "InputPort"); - const Redland::Node out_port_class (*world->rdf_world(), res, NS_LV2 "OutputPort"); - const Redland::Node lv2_class (*world->rdf_world(), res, NS_LV2 "Plugin"); + const Sord::Node patch_class (*world->rdf_world(), res, NS_INGEN "Patch"); + const Sord::Node node_class (*world->rdf_world(), res, NS_INGEN "Node"); + const Sord::Node internal_class (*world->rdf_world(), res, NS_INGEN "Internal"); + const Sord::Node ladspa_class (*world->rdf_world(), res, NS_INGEN "LADSPAPlugin"); + const Sord::Node in_port_class (*world->rdf_world(), res, NS_LV2 "InputPort"); + const Sord::Node out_port_class (*world->rdf_world(), res, NS_LV2 "OutputPort"); + const Sord::Node lv2_class (*world->rdf_world(), res, NS_LV2 "Plugin"); - Redland::Node subject; + Sord::Node subject = nil; if (data_path && data_path->is_root()) { subject = model.base_uri(); } else if (data_path) { - subject = Redland::Node(*world->rdf_world(), res, data_path->chop_start("/")); + subject = Sord::Node(*world->rdf_world(), res, data_path->chop_start("/")); } else { subject = nil; } @@ -297,9 +312,9 @@ Parser::parse( boost::optional<Path> ret; boost::optional<Path> root_path; - for (Redland::Iter i = model.find(subject, rdf_type, nil); !i.end(); ++i) { - const Redland::Node& subject = i.get_subject(); - const Redland::Node& rdf_class = i.get_object(); + for (Sord::Iter i = model.find(subject, rdf_type, nil); !i.end(); ++i) { + const Sord::Node& subject = i.get_subject(); + const Sord::Node& rdf_class = i.get_object(); if (!data_path) path_str = relative_uri(document_uri, subject.to_c_string(), true); @@ -367,19 +382,19 @@ boost::optional<Path> Parser::parse_patch( Ingen::Shared::World* world, Ingen::Shared::CommonInterface* target, - Redland::Model& model, - const Redland::Node& subject_node, + Sord::Model& model, + const Sord::Node& subject_node, boost::optional<Raul::Path> parent, boost::optional<Raul::Symbol> a_symbol, boost::optional<GraphObject::Properties> data) { const LV2URIMap& uris = *world->uris().get(); - Redland::Resource ingen_polyphony(*world->rdf_world(), NS_INGEN "polyphony"); - Redland::Resource lv2_port(*world->rdf_world(), NS_LV2 "port"); - Redland::Resource lv2_symbol(*world->rdf_world(), NS_LV2 "symbol"); + Sord::Resource ingen_polyphony(*world->rdf_world(), NS_INGEN "polyphony"); + Sord::Resource lv2_port(*world->rdf_world(), NS_LV2 "port"); + Sord::Resource lv2_symbol(*world->rdf_world(), NS_LV2 "symbol"); - const Redland::Node& patch = subject_node; + const Sord::Node& patch = subject_node; uint32_t patch_poly = 0; @@ -392,9 +407,9 @@ Parser::parse_patch( /* Load polyphony from file if necessary */ if (patch_poly == 0) { - Redland::Iter i = model.find(subject_node, ingen_polyphony, nil); + Sord::Iter i = model.find(subject_node, ingen_polyphony, nil); if (!i.end()) { - const Redland::Node& poly_node = i.get_object(); + const Sord::Node& poly_node = i.get_object(); if (poly_node.is_int()) patch_poly = poly_node.to_int(); else @@ -432,12 +447,12 @@ Parser::parse_patch( props.insert(make_pair(uris.ingen_polyphony, Raul::Atom(int32_t(patch_poly)))); target->put(patch_path, props); - Redland::Resource rdf_type(*world->rdf_world(), NS_RDF "type"); - Redland::Resource ingen_Patch(*world->rdf_world(), NS_INGEN "Patch"); - Redland::Resource ingen_node(*world->rdf_world(), NS_INGEN "node"); + Sord::Resource rdf_type(*world->rdf_world(), NS_RDF "type"); + Sord::Resource ingen_Patch(*world->rdf_world(), NS_INGEN "Patch"); + Sord::Resource ingen_node(*world->rdf_world(), NS_INGEN "node"); typedef multimap<Raul::URI, Raul::Atom> Properties; - typedef map<string, Redland::Node> Resources; + typedef map<string, Sord::Node> Resources; typedef map<string, Properties> Objects; typedef map<string, string> Types; @@ -447,16 +462,16 @@ Parser::parse_patch( Types types; /* For each node in this patch */ - typedef map<Redland::Node, Properties> Nodes; + typedef map<Sord::Node, Properties> Nodes; Nodes nodes; - for (Redland::Iter n = model.find(subject_node, ingen_node, nil); !n.end(); ++n) { - Redland::Node node = n.get_object(); + for (Sord::Iter n = model.find(subject_node, ingen_node, nil); !n.end(); ++n) { + Sord::Node node = n.get_object(); /* Get all node properties */ Properties node_properties; - for (Redland::Iter np = model.find(node, nil, nil); !np.end(); ++np) { - const Redland::Node& predicate = np.get_predicate(); - const Redland::Node& object = np.get_object(); + for (Sord::Iter np = model.find(node, nil, nil); !np.end(); ++np) { + const Sord::Node& predicate = np.get_predicate(); + const Sord::Node& object = np.get_object(); if (!skip_property(predicate)) { node_properties.insert( make_pair(predicate.to_string(), @@ -470,14 +485,14 @@ Parser::parse_patch( target->put(node_path, node_properties); /* For each port on this node */ - for (Redland::Iter p = model.find(node, lv2_port, nil); !p.end(); ++p) { - Redland::Node port = p.get_object(); + for (Sord::Iter p = model.find(node, lv2_port, nil); !p.end(); ++p) { + Sord::Node port = p.get_object(); /* Get all port properties */ Properties port_properties; - for (Redland::Iter pp = model.find(port, nil, nil); !pp.end(); ++pp) { - const Redland::Node& predicate = pp.get_predicate(); - const Redland::Node& object = pp.get_object(); + for (Sord::Iter pp = model.find(port, nil, nil); !pp.end(); ++pp) { + const Sord::Node& predicate = pp.get_predicate(); + const Sord::Node& object = pp.get_object(); if (!skip_property(predicate)) { port_properties.insert( make_pair(predicate.to_string(), @@ -499,14 +514,14 @@ Parser::parse_patch( } /* For each port on this patch */ - for (Redland::Iter p = model.find(patch, lv2_port, nil); !p.end(); ++p) { - Redland::Node port = p.get_object(); + for (Sord::Iter p = model.find(patch, lv2_port, nil); !p.end(); ++p) { + Sord::Node port = p.get_object(); /* Get all port properties */ Properties port_properties; - for (Redland::Iter pp = model.find(port, nil, nil); !pp.end(); ++pp) { - const Redland::Node& predicate = pp.get_predicate(); - const Redland::Node& object = pp.get_object(); + for (Sord::Iter pp = model.find(port, nil, nil); !pp.end(); ++pp) { + const Sord::Node& predicate = pp.get_predicate(); + const Sord::Node& object = pp.get_object(); if (!skip_property(predicate)) { port_properties.insert( make_pair(predicate.to_string(), @@ -533,7 +548,7 @@ Parser::parse_patch( target->set_property(patch_path, uris.ingen_enabled, (bool)true); #if 0 /* Enable */ - query = Redland::Query(*world->rdf_world(), Glib::ustring( + query = Sord::Query(*world->rdf_world(), Glib::ustring( "SELECT DISTINCT ?enabled WHERE {\n") + subject + " ingen:enabled ?enabled .\n" "}"); @@ -541,7 +556,7 @@ Parser::parse_patch( results = query.run(*world->rdf_world(), model, base_uri); for (; !results->finished(); results->next()) { Glib::Mutex::Lock lock(world->rdf_world()->mutex()); - const Redland::Node& enabled_node = results->get("enabled"); + const Sord::Node& enabled_node = results->get("enabled"); if (enabled_node.is_bool() && enabled_node) { target->set_property(patch_path, uris.ingen_enabled, (bool)true); break; @@ -559,24 +574,24 @@ boost::optional<Path> Parser::parse_node( Ingen::Shared::World* world, Ingen::Shared::CommonInterface* target, - Redland::Model& model, - const Redland::Node& subject, + Sord::Model& model, + const Sord::Node& subject, const Raul::Path& path, boost::optional<GraphObject::Properties> data) { const LV2URIMap& uris = *world->uris().get(); - Redland::Resource rdf_instanceOf(*world->rdf_world(), NS_RDF "instanceOf"); + Sord::Resource rdf_instanceOf(*world->rdf_world(), NS_RDF "instanceOf"); /* Get plugin */ - Redland::Iter i = model.find(subject, rdf_instanceOf, nil); + Sord::Iter i = model.find(subject, rdf_instanceOf, nil); if (i.end()) { LOG(error) << "Node missing mandatory rdf:instanceOf property" << endl; return boost::optional<Path>(); } - const Redland::Node& plugin_node = i.get_object(); - if (plugin_node.type() != Redland::Node::RESOURCE) { + const Sord::Node& plugin_node = i.get_object(); + if (plugin_node.type() != Sord::Node::RESOURCE) { LOG(error) << "Node's rdf:instanceOf property is not a resource" << endl; return boost::optional<Path>(); } @@ -597,24 +612,24 @@ bool Parser::parse_connections( Ingen::Shared::World* world, Ingen::Shared::CommonInterface* target, - Redland::Model& model, - const Redland::Node& subject, + Sord::Model& model, + const Sord::Node& subject, const Raul::Path& parent) { - Redland::Resource ingen_connection(*world->rdf_world(), NS_INGEN "connection"); - Redland::Resource ingen_source(*world->rdf_world(), NS_INGEN "source"); - Redland::Resource ingen_destination(*world->rdf_world(), NS_INGEN "destination"); + Sord::Resource ingen_connection(*world->rdf_world(), NS_INGEN "connection"); + Sord::Resource ingen_source(*world->rdf_world(), NS_INGEN "source"); + Sord::Resource ingen_destination(*world->rdf_world(), NS_INGEN "destination"); const Glib::ustring& base_uri = model.base_uri().to_string(); RDFNodes connections; - for (Redland::Iter i = model.find(subject, ingen_connection, nil); !i.end(); ++i) { + for (Sord::Iter i = model.find(subject, ingen_connection, nil); !i.end(); ++i) { connections.insert(i.get_object()); } for (RDFNodes::const_iterator i = connections.begin(); i != connections.end(); ++i) { - Redland::Iter s = model.find(*i, ingen_source, nil); - Redland::Iter d = model.find(*i, ingen_destination, nil); + Sord::Iter s = model.find(*i, ingen_source, nil); + Sord::Iter d = model.find(*i, ingen_destination, nil); if (s.end()) { LOG(error) << "Connection has no source" << endl; @@ -648,15 +663,15 @@ bool Parser::parse_properties( Ingen::Shared::World* world, Ingen::Shared::CommonInterface* target, - Redland::Model& model, - const Redland::Node& subject, + Sord::Model& model, + const Sord::Node& subject, const Raul::URI& uri, boost::optional<GraphObject::Properties> data) { Resource::Properties properties; - for (Redland::Iter i = model.find(subject, nil, nil); !i.end(); ++i) { - const Redland::Node& key = i.get_predicate(); - const Redland::Node& val = i.get_object(); + for (Sord::Iter i = model.find(subject, nil, nil); !i.end(); ++i) { + const Sord::Node& key = i.get_predicate(); + const Sord::Node& val = i.get_object(); if (!skip_property(key)) { properties.insert(make_pair(key.to_string(), AtomRDF::node_to_atom(model, val))); @@ -674,7 +689,7 @@ Parser::parse_properties( bool -Parser::skip_property(const Redland::Node& predicate) +Parser::skip_property(const Sord::Node& predicate) { return (predicate.to_string() == "http://drobilla.net/ns/ingen#node" || predicate.to_string() == "http://lv2plug.in/ns/lv2core#port"); diff --git a/src/serialisation/Parser.hpp b/src/serialisation/Parser.hpp index ed354905..06f42f14 100644 --- a/src/serialisation/Parser.hpp +++ b/src/serialisation/Parser.hpp @@ -24,8 +24,8 @@ #include <boost/optional.hpp> #include "interface/GraphObject.hpp" -namespace Raul { class Path; } -namespace Redland { class World; class Model; class Node; } +namespace Raul { class Path; } +namespace Sord { class World; class Model; class Node; } namespace Ingen { namespace Shared { class CommonInterface; } } namespace Ingen { @@ -86,7 +86,7 @@ private: boost::optional<Raul::Path> parse( Ingen::Shared::World* world, Shared::CommonInterface* target, - Redland::Model& model, + Sord::Model& model, Glib::ustring document_uri, boost::optional<Raul::Path> data_path=boost::optional<Raul::Path>(), boost::optional<Raul::Path> parent=boost::optional<Raul::Path>(), @@ -96,8 +96,8 @@ private: boost::optional<Raul::Path> parse_patch( Ingen::Shared::World* world, Ingen::Shared::CommonInterface* target, - Redland::Model& model, - const Redland::Node& subject, + Sord::Model& model, + const Sord::Node& subject, boost::optional<Raul::Path> parent=boost::optional<Raul::Path>(), boost::optional<Raul::Symbol> symbol=boost::optional<Raul::Symbol>(), boost::optional<Properties> data=boost::optional<Properties>()); @@ -105,27 +105,27 @@ private: boost::optional<Raul::Path> parse_node( Ingen::Shared::World* world, Ingen::Shared::CommonInterface* target, - Redland::Model& model, - const Redland::Node& subject, + Sord::Model& model, + const Sord::Node& subject, const Raul::Path& path, boost::optional<Properties> data=boost::optional<Properties>()); bool parse_properties( Ingen::Shared::World* world, Ingen::Shared::CommonInterface* target, - Redland::Model& model, - const Redland::Node& subject, + Sord::Model& model, + const Sord::Node& subject, const Raul::URI& uri, - boost::optional<Properties> data=boost::optional<Properties>()); + boost::optional<Properties> data = boost::optional<Properties>()); bool parse_connections( Ingen::Shared::World* world, Ingen::Shared::CommonInterface* target, - Redland::Model& model, - const Redland::Node& subject, + Sord::Model& model, + const Sord::Node& subject, const Raul::Path& patch); - bool skip_property(const Redland::Node& predicate); + bool skip_property(const Sord::Node& predicate); }; diff --git a/src/serialisation/Serialiser.cpp b/src/serialisation/Serialiser.cpp index 99e8bdc4..4c6e3f12 100644 --- a/src/serialisation/Serialiser.cpp +++ b/src/serialisation/Serialiser.cpp @@ -36,9 +36,7 @@ #include "raul/AtomRDF.hpp" #include "raul/Path.hpp" #include "raul/TableImpl.hpp" -#include "redlandmm/Model.hpp" -#include "redlandmm/Node.hpp" -#include "redlandmm/World.hpp" +#include "sord/sordmm.hpp" #include "module/World.hpp" #include "interface/EngineInterface.hpp" #include "interface/Plugin.hpp" @@ -55,7 +53,7 @@ using namespace std; using namespace Raul; -using namespace Redland; +using namespace Sord; using namespace Ingen; using namespace Ingen::Shared; @@ -110,23 +108,23 @@ Serialiser::write_manifest(const std::string& bundle_uri, SharedPtr<Patch> patch = PtrCast<Patch>(i->object); if (patch) { const std::string filename = uri_to_symbol(i->uri) + INGEN_PATCH_FILE_EXT; - const Redland::Resource subject(_model->world(), filename); + const Sord::Resource subject(_model->world(), filename); _model->add_statement( subject, - Redland::Curie(_model->world(), "rdf:type"), - Redland::Resource(_model->world(), "ingen:Patch")); + Sord::Curie(_model->world(), "rdf:type"), + Sord::Curie(_model->world(), "ingen:Patch")); _model->add_statement( subject, - Redland::Curie(_model->world(), "rdf:type"), - Redland::Resource(_model->world(), "lv2:Plugin")); + Sord::Curie(_model->world(), "rdf:type"), + Sord::Curie(_model->world(), "lv2:Plugin")); _model->add_statement( subject, - Redland::Curie(_model->world(), "rdfs:seeAlso"), - Redland::Resource(_model->world(), filename)); + Sord::Curie(_model->world(), "rdfs:seeAlso"), + Sord::Resource(_model->world(), filename)); _model->add_statement( subject, - Redland::Curie(_model->world(), "lv2:binary"), - Redland::Resource(_model->world(), + Sord::Curie(_model->world(), "lv2:binary"), + Sord::Resource(_model->world(), Glib::Module::build_path("", "ingen_lv2"))); symlink(Glib::Module::build_path(INGEN_MODULE_DIR, "ingen_lv2").c_str(), Glib::Module::build_path(bundle_path, "ingen_lv2").c_str()); @@ -166,7 +164,7 @@ Serialiser::to_string(SharedPtr<GraphObject> object, start_to_string(object->path(), base_uri); serialise(object); - Redland::Resource base_rdf_node(_model->world(), base_uri); + Sord::Resource base_rdf_node(_model->world(), base_uri); for (GraphObject::Properties::const_iterator v = extra_rdf.begin(); v != extra_rdf.end(); ++v) { if (v->first.find(":") != string::npos) { _model->add_statement( @@ -196,7 +194,7 @@ Serialiser::start_to_filename(const string& filename) _base_uri = "file://" + filename; else _base_uri = filename; - _model = new Redland::Model(*_world.rdf_world(), _base_uri); + _model = new Sord::Model(*_world.rdf_world(), _base_uri); _mode = TO_FILE; } @@ -218,7 +216,7 @@ Serialiser::start_to_string(const Raul::Path& root, const string& base_uri) _root_path = root; _base_uri = base_uri; - _model = new Redland::Model(*_world.rdf_world(), base_uri); + _model = new Sord::Model(*_world.rdf_world(), base_uri); _mode = TO_STRING; } @@ -233,9 +231,9 @@ Serialiser::finish() { string ret = ""; if (_mode == TO_FILE) { - _model->serialise_to_file(_base_uri, "turtle"); + _model->write_to_file(_base_uri, "turtle"); } else { - char* c_str = _model->serialise_to_string("turtle"); + char* c_str = _model->write_to_string("turtle"); if (c_str != NULL) { ret = c_str; free(c_str); @@ -249,31 +247,21 @@ Serialiser::finish() } -Redland::Node +Sord::Node Serialiser::instance_rdf_node(const Path& path) { assert(_model); assert(path.is_child_of(_root_path)); - - if (path == _root_path) - return Redland::Resource(_model->world(), _base_uri); - else - return Redland::Resource(_model->world(), - path.substr(_root_path.base().length())); + return Sord::Resource(_model->world(), path.chop_scheme().substr(1)); } -Redland::Node +Sord::Node Serialiser::class_rdf_node(const Path& path) { assert(_model); assert(path.is_child_of(_root_path)); - - if (path == _root_path) - return Redland::Resource(_model->world(), _base_uri); - else - return Redland::Resource(_model->world(), - string(META_PREFIX) + path.relative_to_base(_root_path).chop_start("/")); + return Sord::Resource(_model->world(), path.chop_scheme().substr(1)); } @@ -286,10 +274,10 @@ Serialiser::serialise(SharedPtr<GraphObject> object) throw (std::logic_error) SharedPtr<Shared::Patch> patch = PtrCast<Shared::Patch>(object); if (patch) { if (patch->path() == _root_path) { - const Redland::Resource patch_id(_model->world(), _base_uri); + const Sord::Resource patch_id(_model->world(), ""); serialise_patch(patch, patch_id); } else { - const Redland::Resource patch_id(_model->world(), + const Sord::Resource patch_id(_model->world(), string(META_PREFIX) + patch->path().chop_start("/")); serialise_patch(patch, patch_id); serialise_node(patch, patch_id, instance_rdf_node(patch->path())); @@ -299,7 +287,7 @@ Serialiser::serialise(SharedPtr<GraphObject> object) throw (std::logic_error) SharedPtr<Shared::Node> node = PtrCast<Shared::Node>(object); if (node) { - const Redland::Resource plugin_id(_model->world(), node->plugin()->uri().str()); + const Sord::Resource plugin_id(_model->world(), node->plugin()->uri().str()); serialise_node(node, plugin_id, instance_rdf_node(node->path())); return; } @@ -316,19 +304,19 @@ Serialiser::serialise(SharedPtr<GraphObject> object) throw (std::logic_error) void -Serialiser::serialise_patch(SharedPtr<Shared::Patch> patch, const Redland::Node& patch_id) +Serialiser::serialise_patch(SharedPtr<Shared::Patch> patch, const Sord::Node& patch_id) { assert(_model); _model->add_statement( patch_id, - Redland::Curie(_model->world(), "rdf:type"), - Redland::Resource(_model->world(), "ingen:Patch")); + Sord::Curie(_model->world(), "rdf:type"), + Sord::Curie(_model->world(), "ingen:Patch")); _model->add_statement( patch_id, - Redland::Curie(_model->world(), "rdf:type"), - Redland::Resource(_model->world(), "lv2:Plugin")); + Sord::Curie(_model->world(), "rdf:type"), + Sord::Curie(_model->world(), "lv2:Plugin")); const LV2URIMap& uris = *_world.uris().get(); @@ -343,7 +331,7 @@ Serialiser::serialise_patch(SharedPtr<Shared::Patch> patch, const Redland::Node& _model->add_statement( patch_id, AtomRDF::atom_to_node(*_model, uris.lv2_symbol.c_str()), - Redland::Literal(_model->world(), symbol)); + Sord::Literal(_model->world(), symbol)); } else { symbol = s->second.get_string(); } @@ -353,7 +341,7 @@ Serialiser::serialise_patch(SharedPtr<Shared::Patch> patch, const Redland::Node& _model->add_statement( patch_id, AtomRDF::atom_to_node(*_model, uris.doap_name), - Redland::Literal(_model->world(), symbol)); + Sord::Literal(_model->world(), symbol)); serialise_properties(patch_id, NULL, patch->meta().properties()); @@ -366,21 +354,21 @@ Serialiser::serialise_patch(SharedPtr<Shared::Patch> patch, const Redland::Node& SharedPtr<Shared::Patch> subpatch = PtrCast<Shared::Patch>(n->second); SharedPtr<Shared::Node> node = PtrCast<Shared::Node>(n->second); if (subpatch) { - const Redland::Resource class_id(_model->world(), + const Sord::Resource class_id(_model->world(), string(META_PREFIX) + subpatch->path().chop_start("/")); - const Redland::Node node_id(instance_rdf_node(n->second->path())); + const Sord::Node node_id(instance_rdf_node(n->second->path())); _model->add_statement( patch_id, - Redland::Curie(_model->world(), "ingen:node"), + Sord::Curie(_model->world(), "ingen:node"), node_id); serialise_patch(subpatch, class_id); serialise_node(subpatch, class_id, node_id); } else if (node) { - const Redland::Resource class_id(_model->world(), node->plugin()->uri().str()); - const Redland::Node node_id(instance_rdf_node(n->second->path())); + const Sord::Resource class_id(_model->world(), node->plugin()->uri().str()); + const Sord::Node node_id(instance_rdf_node(n->second->path())); _model->add_statement( patch_id, - Redland::Curie(_model->world(), "ingen:node"), + Sord::Curie(_model->world(), "ingen:node"), node_id); serialise_node(node, class_id, node_id); } @@ -390,7 +378,7 @@ Serialiser::serialise_patch(SharedPtr<Shared::Patch> patch, const Redland::Node& for (uint32_t i=0; i < patch->num_ports(); ++i) { Port* p = patch->port(i); - const Redland::Node port_id = root + const Sord::Node port_id = root ? instance_rdf_node(p->path()) : class_rdf_node(p->path()); @@ -400,7 +388,7 @@ Serialiser::serialise_patch(SharedPtr<Shared::Patch> patch, const Redland::Node& _model->add_statement( patch_id, - Redland::Resource(_model->world(), "http://lv2plug.in/ns/lv2core#port"), + Sord::Resource(_model->world(), "http://lv2plug.in/ns/lv2core#port"), port_id); serialise_port_meta(p, port_id); if (root) @@ -419,41 +407,41 @@ Serialiser::serialise_plugin(const Shared::Plugin& plugin) { assert(_model); - const Redland::Node plugin_id = Redland::Resource(_model->world(), plugin.uri().str()); + const Sord::Node plugin_id = Sord::Resource(_model->world(), plugin.uri().str()); _model->add_statement( plugin_id, - Redland::Curie(_model->world(), "rdf:type"), - Redland::Resource(_model->world(), plugin.type_uri().str())); + Sord::Curie(_model->world(), "rdf:type"), + Sord::Resource(_model->world(), plugin.type_uri().str())); } void Serialiser::serialise_node(SharedPtr<Shared::Node> node, - const Redland::Node& class_id, const Redland::Node& node_id) + const Sord::Node& class_id, const Sord::Node& node_id) { _model->add_statement( node_id, - Redland::Curie(_model->world(), "rdf:type"), - Redland::Resource(_model->world(), "ingen:Node")); + Sord::Curie(_model->world(), "rdf:type"), + Sord::Curie(_model->world(), "ingen:Node")); _model->add_statement( node_id, - Redland::Curie(_model->world(), "rdf:instanceOf"), + Sord::Curie(_model->world(), "rdf:instanceOf"), class_id); _model->add_statement( node_id, - Redland::Curie(_model->world(), "lv2:symbol"), - Redland::Literal(_model->world(), node->path().symbol())); + Sord::Curie(_model->world(), "lv2:symbol"), + Sord::Literal(_model->world(), node->path().symbol())); serialise_properties(node_id, &node->meta(), node->properties()); for (uint32_t i=0; i < node->num_ports(); ++i) { Port* p = node->port(i); - const Redland::Node port_id = instance_rdf_node(p->path()); + const Sord::Node port_id = instance_rdf_node(p->path()); serialise_port(p, port_id); _model->add_statement( node_id, - Redland::Curie(_model->world(), "lv2:port"), + Sord::Curie(_model->world(), "lv2:port"), port_id); } } @@ -461,36 +449,36 @@ Serialiser::serialise_node(SharedPtr<Shared::Node> node, /** Serialise a port on a Node */ void -Serialiser::serialise_port(const Port* port, const Redland::Node& port_id) +Serialiser::serialise_port(const Port* port, const Sord::Node& port_id) { if (port->is_input()) _model->add_statement( port_id, - Redland::Curie(_model->world(), "rdf:type"), - Redland::Resource(_model->world(), "lv2:InputPort")); + Sord::Curie(_model->world(), "rdf:type"), + Sord::Curie(_model->world(), "lv2:InputPort")); else _model->add_statement( port_id, - Redland::Curie(_model->world(), "rdf:type"), - Redland::Resource(_model->world(), "lv2:OutputPort")); + Sord::Curie(_model->world(), "rdf:type"), + Sord::Curie(_model->world(), "lv2:OutputPort")); for (Port::PortTypes::const_iterator i = port->types().begin(); i != port->types().end(); ++i) _model->add_statement( port_id, - Redland::Curie(_model->world(), "rdf:type"), - Redland::Resource(_model->world(), i->uri().str())); + Sord::Curie(_model->world(), "rdf:type"), + Sord::Resource(_model->world(), i->uri().str())); if (dynamic_cast<Patch*>(port->graph_parent())) _model->add_statement( port_id, - Redland::Curie(_model->world(), "rdf:instanceOf"), + Sord::Curie(_model->world(), "rdf:instanceOf"), class_rdf_node(port->path())); _model->add_statement( port_id, - Redland::Curie(_model->world(), "lv2:symbol"), - Redland::Literal(_model->world(), port->path().symbol())); + Sord::Curie(_model->world(), "lv2:symbol"), + Sord::Literal(_model->world(), port->path().symbol())); serialise_properties(port_id, &port->meta(), port->properties()); } @@ -498,42 +486,42 @@ Serialiser::serialise_port(const Port* port, const Redland::Node& port_id) /** Serialise a port on a Patch */ void -Serialiser::serialise_port_meta(const Port* port, const Redland::Node& port_id) +Serialiser::serialise_port_meta(const Port* port, const Sord::Node& port_id) { if (port->is_input()) _model->add_statement( port_id, - Redland::Curie(_model->world(), "rdf:type"), - Redland::Resource(_model->world(), "lv2:InputPort")); + Sord::Curie(_model->world(), "rdf:type"), + Sord::Curie(_model->world(), "lv2:InputPort")); else _model->add_statement( port_id, - Redland::Curie(_model->world(), "rdf:type"), - Redland::Resource(_model->world(), "lv2:OutputPort")); + Sord::Curie(_model->world(), "rdf:type"), + Sord::Curie(_model->world(), "lv2:OutputPort")); for (Port::PortTypes::const_iterator i = port->types().begin(); i != port->types().end(); ++i) _model->add_statement( port_id, - Redland::Curie(_model->world(), "rdf:type"), - Redland::Resource(_model->world(), i->uri().str())); + Sord::Curie(_model->world(), "rdf:type"), + Sord::Resource(_model->world(), i->uri().str())); _model->add_statement( port_id, - Redland::Curie(_model->world(), "lv2:index"), + Sord::Curie(_model->world(), "lv2:index"), AtomRDF::atom_to_node(*_model, Atom((int)port->index()))); _model->add_statement( port_id, - Redland::Curie(_model->world(), "lv2:symbol"), - Redland::Literal(_model->world(), port->path().symbol())); + Sord::Curie(_model->world(), "lv2:symbol"), + Sord::Literal(_model->world(), port->path().symbol())); if (!port->get_property("http://lv2plug.in/ns/lv2core#default").is_valid()) { if (port->is_input()) { if (port->value().is_valid()) { _model->add_statement( port_id, - Redland::Curie(_model->world(), "lv2:default"), + Sord::Curie(_model->world(), "lv2:default"), AtomRDF::atom_to_node(*_model, Atom(port->value()))); } else if (port->is_a(PortType::CONTROL)) { LOG(warn) << "Port " << port->path() << " has no lv2:default" << endl; @@ -553,48 +541,48 @@ Serialiser::serialise_connection(SharedPtr<GraphObject> parent, throw std::logic_error("serialise_connection called without serialization in progress"); bool top = (parent->path() == _root_path); - const Redland::Node src_node = top + const Sord::Node src_node = top ? instance_rdf_node(connection->src_port_path()) : class_rdf_node(connection->src_port_path()); - const Redland::Node dst_node = top + const Sord::Node dst_node = top ? instance_rdf_node(connection->dst_port_path()) : class_rdf_node(connection->dst_port_path()); - const Redland::Node connection_node = Redland::Node::blank_id(*_world.rdf_world()); + const Sord::Node connection_node = Sord::Node::blank_id(*_world.rdf_world()); _model->add_statement( connection_node, - Redland::Curie(_model->world(), "ingen:source"), + Sord::Curie(_model->world(), "ingen:source"), src_node); _model->add_statement( connection_node, - Redland::Curie(_model->world(), "ingen:destination"), + Sord::Curie(_model->world(), "ingen:destination"), dst_node); if (parent) { - const Redland::Node parent_node = class_rdf_node(parent->path()); + const Sord::Node parent_node = class_rdf_node(parent->path()); _model->add_statement( parent_node, - Redland::Curie(_model->world(), "ingen:connection"), + Sord::Curie(_model->world(), "ingen:connection"), connection_node); } else { _model->add_statement( connection_node, - Redland::Curie(_model->world(), "rdf:type"), - Redland::Resource(_model->world(), "ingen:Connection")); + Sord::Curie(_model->world(), "rdf:type"), + Sord::Curie(_model->world(), "ingen:Connection")); } } void Serialiser::serialise_properties( - Redland::Node subject, + Sord::Node subject, const Shared::Resource* meta, const GraphObject::Properties& properties) { for (GraphObject::Properties::const_iterator v = properties.begin(); v != properties.end(); ++v) { if (v->second.is_valid()) { if (!meta || !meta->has_property(v->first.str(), v->second)) { - const Redland::Resource key(_model->world(), v->first.str()); - const Redland::Node value(AtomRDF::atom_to_node(*_model, v->second)); + const Sord::Resource key(_model->world(), v->first.str()); + const Sord::Node value(AtomRDF::atom_to_node(*_model, v->second)); if (value.is_valid()) { _model->add_statement(subject, key, value); } else { diff --git a/src/serialisation/Serialiser.hpp b/src/serialisation/Serialiser.hpp index ccc51d20..58fd6fc6 100644 --- a/src/serialisation/Serialiser.hpp +++ b/src/serialisation/Serialiser.hpp @@ -25,8 +25,7 @@ #include <cassert> #include "raul/SharedPtr.hpp" #include "raul/Path.hpp" -#include "redlandmm/World.hpp" -#include "redlandmm/Model.hpp" +#include "sord/sordmm.hpp" #include "interface/GraphObject.hpp" #include "shared/Store.hpp" @@ -93,27 +92,27 @@ private: void setup_prefixes(); - void serialise_patch(SharedPtr<Shared::Patch> p, const Redland::Node& id); + void serialise_patch(SharedPtr<Shared::Patch> p, const Sord::Node& id); void serialise_node(SharedPtr<Shared::Node> n, - const Redland::Node& class_id, const Redland::Node& id); - void serialise_port(const Shared::Port* p, const Redland::Node& id); - void serialise_port_meta(const Shared::Port* p, const Redland::Node& id); + const Sord::Node& class_id, const Sord::Node& id); + void serialise_port(const Shared::Port* p, const Sord::Node& id); + void serialise_port_meta(const Shared::Port* p, const Sord::Node& id); - void serialise_meta_properties(Redland::Node subject, const Properties& properties); + void serialise_meta_properties(Sord::Node subject, const Properties& properties); void serialise_properties( - Redland::Node subject, + Sord::Node subject, const Shared::Resource* meta, const Properties& properties); - Redland::Node instance_rdf_node(const Raul::Path& path); - Redland::Node class_rdf_node(const Raul::Path& path); + Sord::Node instance_rdf_node(const Raul::Path& path); + Sord::Node class_rdf_node(const Raul::Path& path); Raul::Path _root_path; SharedPtr<Shared::Store> _store; Mode _mode; std::string _base_uri; Shared::World& _world; - Redland::Model* _model; + Sord::Model* _model; }; diff --git a/src/serialisation/wscript b/src/serialisation/wscript index 4d2fe690..4e38bed5 100644 --- a/src/serialisation/wscript +++ b/src/serialisation/wscript @@ -17,5 +17,5 @@ def build(bld): obj.target = 'ingen_serialisation' obj.install_path = '${LIBDIR}' obj.use = 'libingen_shared' - autowaf.use_lib(bld, obj, 'GLIBMM LV2CORE SLV2 RAUL REDLANDMM') + autowaf.use_lib(bld, obj, 'GLIBMM LV2CORE SLV2 RAUL SORD') |