From 2ad0daa288aca040153b7a4dd974109b9a4fc2fc Mon Sep 17 00:00:00 2001 From: David Robillard Date: Wed, 16 Feb 2011 21:43:16 +0000 Subject: Tidy up serialiser interface. git-svn-id: http://svn.drobilla.net/lad/trunk/ingen@2965 a436a847-0d15-0410-975c-d299462d15a1 --- src/engine/HTTPEngineReceiver.cpp | 10 ++++- src/gui/ThreadedLoader.cpp | 5 +-- src/serialisation/Serialiser.cpp | 95 +++++++++++++++++---------------------- src/serialisation/Serialiser.hpp | 25 ++++------- 4 files changed, 60 insertions(+), 75 deletions(-) (limited to 'src') diff --git a/src/engine/HTTPEngineReceiver.cpp b/src/engine/HTTPEngineReceiver.cpp index d2106c13..81481f02 100644 --- a/src/engine/HTTPEngineReceiver.cpp +++ b/src/engine/HTTPEngineReceiver.cpp @@ -99,9 +99,14 @@ HTTPEngineReceiver::deactivate_source() void -HTTPEngineReceiver::message_callback(SoupServer* server, SoupMessage* msg, const char* path_str, - GHashTable *query, SoupClientContext* client, void* data) +HTTPEngineReceiver::message_callback(SoupServer* server, + SoupMessage* msg, + const char* path_str, + GHashTable* query, + SoupClientContext* client, + void* data) { + #if 0 HTTPEngineReceiver* me = (HTTPEngineReceiver*)data; SharedPtr store = me->_engine.world()->store(); @@ -221,6 +226,7 @@ HTTPEngineReceiver::message_callback(SoupServer* server, SoupMessage* msg, const } else { soup_message_set_status(msg, SOUP_STATUS_NOT_IMPLEMENTED); } + #endif } diff --git a/src/gui/ThreadedLoader.cpp b/src/gui/ThreadedLoader.cpp index cd5e5ce6..10f1f8d6 100644 --- a/src/gui/ThreadedLoader.cpp +++ b/src/gui/ThreadedLoader.cpp @@ -137,11 +137,10 @@ void ThreadedLoader::save_patch_event(SharedPtr model, const string& filename) { if (App::instance().serialiser()) { - Serialiser::Record r(model, filename); if (filename.find(INGEN_BUNDLE_EXT) != string::npos) - App::instance().serialiser()->write_bundle(r); + App::instance().serialiser()->write_bundle(model, filename); else - App::instance().serialiser()->to_file(r); + App::instance().serialiser()->to_file(model, filename); } } diff --git a/src/serialisation/Serialiser.cpp b/src/serialisation/Serialiser.cpp index 1ffe07c8..fb25d437 100644 --- a/src/serialisation/Serialiser.cpp +++ b/src/serialisation/Serialiser.cpp @@ -78,11 +78,9 @@ Serialiser::Serialiser(Shared::World& world, SharedPtr store) } void -Serialiser::to_file(const Record& record) +Serialiser::to_file(SharedPtr object, + const std::string& filename) { - SharedPtr object = record.object; - const string& filename = record.uri; - _root_path = object->path(); start_to_filename(filename); serialise(object); @@ -93,61 +91,64 @@ static std::string uri_to_symbol(const std::string& uri) { - return Path::nameify(Glib::path_get_basename(Glib::filename_from_uri(uri))); + const std::string filename = Glib::filename_from_uri(uri); + return Path::nameify(Glib::path_get_basename( + filename.substr(0, filename.find_last_of('.')))); } void -Serialiser::write_manifest(const std::string& bundle_uri, - const Records& records) +Serialiser::write_manifest(const std::string& bundle_uri, + SharedPtr patch, + const std::string& patch_symbol) { - const string bundle_path(Glib::filename_from_uri(bundle_uri)); - const string filename(Glib::build_filename(bundle_path, "manifest.ttl")); - start_to_filename(filename); Sord::World& world = _model->world(); - for (Records::const_iterator i = records.begin(); i != records.end(); ++i) { - SharedPtr patch = PtrCast(i->object); - if (patch) { - const std::string filename = uri_to_symbol(i->uri) + INGEN_PATCH_FILE_EXT; - const Sord::URI subject(world, filename); - _model->add_statement(subject, - Sord::Curie(world, "rdf:type"), - Sord::Curie(world, "ingen:Patch")); - _model->add_statement(subject, - Sord::Curie(world, "rdf:type"), - Sord::Curie(world, "lv2:Plugin")); - _model->add_statement(subject, - Sord::Curie(world, "rdfs:seeAlso"), - Sord::URI(world, filename)); - _model->add_statement( - subject, - Sord::Curie(world, "lv2:binary"), - Sord::URI(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()); - } - } + + const string bundle_path(Glib::filename_from_uri(bundle_uri)); + const string manifest_path(Glib::build_filename(bundle_path, "manifest.ttl")); + const string binary_path(Glib::Module::build_path("", "ingen_lv2")); + + start_to_filename(manifest_path); + + const string filename(patch_symbol + INGEN_PATCH_FILE_EXT); + const Sord::URI subject(world, filename); + + _model->add_statement(subject, + Sord::Curie(world, "rdf:type"), + Sord::Curie(world, "ingen:Patch")); + _model->add_statement(subject, + Sord::Curie(world, "rdf:type"), + Sord::Curie(world, "lv2:Plugin")); + _model->add_statement(subject, + Sord::Curie(world, "rdfs:seeAlso"), + Sord::URI(world, filename)); + _model->add_statement(subject, + Sord::Curie(world, "lv2:binary"), + Sord::URI(world, binary_path)); + + symlink(Glib::Module::build_path(INGEN_MODULE_DIR, "ingen_lv2").c_str(), + Glib::Module::build_path(bundle_path, "ingen_lv2").c_str()); + finish(); } void -Serialiser::write_bundle(const Record& record) +Serialiser::write_bundle(SharedPtr object, + const std::string& uri) { - SharedPtr object = record.object; - string bundle_uri = record.uri; + string bundle_uri = uri; if (bundle_uri[bundle_uri.length()-1] != '/') bundle_uri.append("/"); g_mkdir_with_parents(Glib::filename_from_uri(bundle_uri).c_str(), 0744); - Records records; - - string symbol = uri_to_symbol(record.uri); + const string symbol = uri_to_symbol(uri); const string root_file = bundle_uri + symbol + INGEN_PATCH_FILE_EXT; + start_to_filename(root_file); serialise(object); finish(); - records.push_back(Record(object, bundle_uri + symbol + INGEN_PATCH_FILE_EXT)); - write_manifest(bundle_uri, records); + + write_manifest(bundle_uri, PtrCast(object), symbol); } string @@ -329,7 +330,7 @@ Serialiser::serialise_patch(SharedPtr patch, const Sord::Node& pa continue; SharedPtr subpatch = PtrCast(n->second); - SharedPtr node = PtrCast(n->second); + SharedPtr node = PtrCast(n->second); if (subpatch) { const Sord::URI class_id(world, string(META_PREFIX) + subpatch->path().chop_start("/")); @@ -373,18 +374,6 @@ Serialiser::serialise_patch(SharedPtr patch, const Sord::Node& pa } } -void -Serialiser::serialise_plugin(const Shared::Plugin& plugin) -{ - assert(_model); - - const Sord::Node plugin_id = Sord::URI(_model->world(), plugin.uri().str()); - - _model->add_statement(plugin_id, - Sord::Curie(_model->world(), "rdf:type"), - Sord::URI(_model->world(), plugin.type_uri().str())); -} - void Serialiser::serialise_node(SharedPtr node, const Sord::Node& class_id, diff --git a/src/serialisation/Serialiser.hpp b/src/serialisation/Serialiser.hpp index 7fc641f6..b1f7b5ef 100644 --- a/src/serialisation/Serialiser.hpp +++ b/src/serialisation/Serialiser.hpp @@ -57,23 +57,11 @@ public: typedef Shared::GraphObject::Properties Properties; - struct Record { - Record(SharedPtr o, const std::string& u) - : object(o), uri(u) - {} + void to_file(SharedPtr object, + const std::string& filename); - const SharedPtr object; - const std::string uri; - }; - - typedef std::list Records; - - void to_file(const Record& record); - - void write_bundle(const Record& record); - - void write_manifest(const std::string& bundle_uri, - const Records& records); + void write_bundle(SharedPtr object, + const std::string& filename); std::string to_string(SharedPtr object, const std::string& base_uri, @@ -81,7 +69,6 @@ public: void start_to_string(const Raul::Path& root, const std::string& base_uri); void serialise(SharedPtr object) throw (std::logic_error); - void serialise_plugin(const Shared::Plugin& p); void serialise_connection(SharedPtr parent, SharedPtr c) throw (std::logic_error); @@ -107,6 +94,10 @@ private: Sord::Node path_rdf_node(const Raul::Path& path); + void write_manifest(const std::string& bundle_uri, + SharedPtr patch, + const std::string& patch_symbol); + Raul::Path _root_path; SharedPtr _store; Mode _mode; -- cgit v1.2.1