From 2c6db7e54c8124a7dd49d04fa949c3351676aee1 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sat, 21 May 2011 00:12:46 +0000 Subject: Fix patch loading. git-svn-id: http://svn.drobilla.net/lad/trunk/ingen@3304 a436a847-0d15-0410-975c-d299462d15a1 --- include/ingen/Resource.hpp | 11 +++++------ src/ingen/main.cpp | 7 ++++++- src/serialisation/Parser.cpp | 30 ++++++++++++++++++++++++++---- src/serialisation/Parser.hpp | 9 +++++---- src/server/ingen_lv2.cpp | 12 +++++++++--- 5 files changed, 51 insertions(+), 18 deletions(-) diff --git a/include/ingen/Resource.hpp b/include/ingen/Resource.hpp index 136c2df8..6404213c 100644 --- a/include/ingen/Resource.hpp +++ b/include/ingen/Resource.hpp @@ -25,7 +25,7 @@ #include "raul/URI.hpp" #include "raul/log.hpp" -#define NS_INGEN "http://drobilla.net/software/ingen#" +#define NS_INGEN "http://drobilla.net/ns/ingen#" namespace Ingen { @@ -42,21 +42,20 @@ public: switch (g) { default: case DEFAULT: - return "http://drobilla.net/software/ingen#defaultContext"; + return NS_INGEN "defaultContext"; case EXTERNAL: - return "http://drobilla.net/software/ingen#externalContext"; + return NS_INGEN "externalContext"; case INTERNAL: - return "http://drobilla.net/software/ingen#internalContext"; + return NS_INGEN "internalContext"; } } static Graph uri_to_graph(const char* uri) { - const size_t prefix_len = strlen("http://drobilla.net/software/ingen#"); if (strncmp(uri, NS_INGEN, sizeof(NS_INGEN) - 1)) { return DEFAULT; } - const char* suffix = uri + prefix_len; + const char* suffix = uri + sizeof(NS_INGEN) - 1; if (!strcmp(suffix, "defaultContext")) { return DEFAULT; } else if (!strcmp(suffix, "externalContext")) { diff --git a/src/ingen/main.cpp b/src/ingen/main.cpp index f93e333b..997fb66e 100644 --- a/src/ingen/main.cpp +++ b/src/ingen/main.cpp @@ -157,6 +157,10 @@ main(int argc, char** argv) world->set_engine(engine_interface); + if (world->local_engine()) { + world->local_engine()->activate(); + } + // Load a patch if (conf.option("load").is_valid() && engine_interface) { boost::optional parent; @@ -191,6 +195,7 @@ main(int argc, char** argv) } engine_interface->get("ingen:plugins"); + engine_interface->get("path:/"); world->parser()->parse_file( world, engine_interface.get(), uri, parent, symbol); } @@ -217,7 +222,7 @@ main(int argc, char** argv) signal(SIGINT, ingen_interrupt); signal(SIGTERM, ingen_interrupt); - // Activate the enginie + // Activate the engine world->local_engine()->activate(); // Run engine main loop until interrupt diff --git a/src/serialisation/Parser.cpp b/src/serialisation/Parser.cpp index 5197c175..198a520e 100644 --- a/src/serialisation/Parser.cpp +++ b/src/serialisation/Parser.cpp @@ -108,6 +108,7 @@ Parser::Parser(Ingen::Shared::World& world) Parser::PatchRecords Parser::find_patches(Ingen::Shared::World* world, + SerdEnv* env, const Glib::ustring& manifest_uri) { const Sord::URI ingen_Patch (*world->rdf_world(), NS_INGEN "Patch"); @@ -115,9 +116,7 @@ Parser::find_patches(Ingen::Shared::World* world, const Sord::URI rdfs_seeAlso(*world->rdf_world(), NS_RDFS "seeAlso"); Sord::Model model(*world->rdf_world(), manifest_uri); - SerdEnv* env = serd_env_new(NULL); model.load_file(env, SERD_TURTLE, manifest_uri); - serd_env_free(env); std::list records; for (Sord::Iter i = model.find(nil, rdf_type, ingen_Patch); !i.end(); ++i) { @@ -156,21 +155,35 @@ Parser::parse_file(Ingen::Shared::World* world, file_uri = Glib::ustring("file://") + file_uri; } + const bool is_bundle = (file_uri.substr(file_uri.length() - 4) != ".ttl"); + + if (is_bundle && file_uri[file_uri.length() - 1] != '/') { + file_uri.append("/"); + } + + SerdNode base_node = serd_node_from_string( + SERD_URI, (const uint8_t*)file_uri.c_str()); + SerdEnv* env = serd_env_new(&base_node); + if (file_uri.substr(file_uri.length() - 4) != ".ttl") { // Not a Turtle file, try to open it as a bundle if (file_uri[file_uri.length() - 1] != '/') { file_uri.append("/"); } - Parser::PatchRecords records = find_patches(world, file_uri + "manifest.ttl"); + Parser::PatchRecords records = find_patches(world, env, file_uri + "manifest.ttl"); if (!records.empty()) { file_uri = records.front().file_uri; } } + base_node = serd_node_from_string( + SERD_URI, (const uint8_t*)file_uri.c_str()); + serd_env_set_base_uri(env, &base_node); + // Load patch file into model Sord::Model model(*world->rdf_world(), file_uri); - SerdEnv* env = serd_env_new(NULL); model.load_file(env, SERD_TURTLE, file_uri); + serd_env_free(env); LOG(info) << "Parsing " << file_uri << endl; @@ -260,6 +273,7 @@ Parser::parse(Ingen::Shared::World* world, const Sord::Node& subject = i.get_subject(); const Sord::Node& rdf_class = i.get_object(); + assert(rdf_class.is_uri()); Subjects::iterator s = subjects.find(subject); if (s == subjects.end()) { std::set types; @@ -285,10 +299,18 @@ Parser::parse(Ingen::Shared::World* world, } else if (types.find(port_class) != types.end()) { parse_properties(world, target, model, subject, path, data); ret = path; + } else { + LOG(error) << "Subject has no known types" << endl; } if (!ret) { LOG(error) << "Failed to parse " << path << endl; + LOG(error) << "Types:" << endl; + for (std::set::const_iterator t = types.begin(); + t != types.end(); ++t) { + LOG(error) << " :: " << *t << endl; + assert((*t).is_uri()); + } return boost::optional(); } diff --git a/src/serialisation/Parser.hpp b/src/serialisation/Parser.hpp index b5e2db63..30c04bab 100644 --- a/src/serialisation/Parser.hpp +++ b/src/serialisation/Parser.hpp @@ -21,11 +21,11 @@ #include #include -#include - #include +#include #include "raul/Path.hpp" +#include "serd/serd.h" #include "ingen/GraphObject.hpp" @@ -74,8 +74,9 @@ public: typedef std::list PatchRecords; - virtual PatchRecords find_patches(Shared::World* world, - const Glib::ustring& manifest_uri); + virtual PatchRecords find_patches(Shared::World* world, + SerdEnv* env, + const Glib::ustring& manifest_uri); private: boost::optional parse( diff --git a/src/server/ingen_lv2.cpp b/src/server/ingen_lv2.cpp index aa3c1f56..9ef1aede 100644 --- a/src/server/ingen_lv2.cpp +++ b/src/server/ingen_lv2.cpp @@ -399,9 +399,15 @@ Lib::Lib() typedef Serialisation::Parser::PatchRecords Records; - Records records(world->parser()->find_patches( - world, Glib::filename_to_uri( - Shared::bundle_file_path("manifest.ttl")))); + const std::string manifest_path = Shared::bundle_file_path("manifest.ttl"); + const SerdNode base_node = serd_node_from_string( + SERD_URI, (const uint8_t*)manifest_path.c_str()); + + SerdEnv* env = serd_env_new(&base_node); + Records records( + world->parser()->find_patches(world, env, + Glib::filename_to_uri(manifest_path))); + serd_env_free(env); for (Records::iterator i = records.begin(); i != records.end(); ++i) { patches.push_back( -- cgit v1.2.1