diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/AtomReader.cpp | 6 | ||||
-rw-r--r-- | src/AtomWriter.cpp | 6 | ||||
-rw-r--r-- | src/Configuration.cpp | 1 | ||||
-rw-r--r-- | src/client/ClientStore.cpp | 4 | ||||
-rw-r--r-- | src/ingen/ingen.cpp | 18 | ||||
-rw-r--r-- | src/server/Broadcaster.hpp | 6 | ||||
-rw-r--r-- | src/server/EventWriter.cpp | 6 | ||||
-rw-r--r-- | src/server/EventWriter.hpp | 4 | ||||
-rw-r--r-- | src/server/events/Copy.cpp | 122 | ||||
-rw-r--r-- | src/server/events/Copy.hpp | 31 |
10 files changed, 130 insertions, 74 deletions
diff --git a/src/AtomReader.cpp b/src/AtomReader.cpp index c9f2f3ac..c7ef6e74 100644 --- a/src/AtomReader.cpp +++ b/src/AtomReader.cpp @@ -288,8 +288,8 @@ AtomReader::write(const LV2_Atom* msg) return false; } - boost::optional<Raul::Path> subject_path(atom_to_path(subject)); - if (!subject_path) { + boost::optional<Raul::URI> subject_uri(atom_to_uri(subject)); + if (!subject_uri) { _log.warn("Copy message has non-path subject\n"); return false; } @@ -300,7 +300,7 @@ AtomReader::write(const LV2_Atom* msg) return false; } - _iface.copy(*subject_path, *dest_uri); + _iface.copy(*subject_uri, *dest_uri); } else if (obj->body.otype == _uris.patch_Move) { if (!subject) { _log.warn("Move message has no subject\n"); diff --git a/src/AtomWriter.cpp b/src/AtomWriter.cpp index 0063f24e..d650535c 100644 --- a/src/AtomWriter.cpp +++ b/src/AtomWriter.cpp @@ -168,13 +168,13 @@ AtomWriter::delta(const Raul::URI& uri, } void -AtomWriter::copy(const Raul::Path& old_path, - const Raul::URI& new_uri) +AtomWriter::copy(const Raul::URI& old_uri, + const Raul::URI& new_uri) { LV2_Atom_Forge_Frame msg; forge_request(&msg, _uris.patch_Copy); lv2_atom_forge_key(&_forge, _uris.patch_subject); - forge_uri(Node::path_to_uri(old_path)); + forge_uri(old_uri); lv2_atom_forge_key(&_forge, _uris.patch_destination); forge_uri(new_uri); lv2_atom_forge_pop(&_forge, &msg); diff --git a/src/Configuration.cpp b/src/Configuration.cpp index bf464428..70b76b20 100644 --- a/src/Configuration.cpp +++ b/src/Configuration.cpp @@ -59,6 +59,7 @@ Configuration::Configuration(Forge& forge) add("jackServer", "jack-server", 's', "JACK server name", GLOBAL, forge.String, forge.alloc("")); add("uuid", "uuid", 'u', "JACK session UUID", SESSION, forge.String, Atom()); add("load", "load", 'l', "Load graph", SESSION, forge.String, Atom()); + add("serverLoad", "server-load", 'i', "Load graph (server side)", SESSION, forge.String, Atom()); add("save", "save", 'o', "Save graph", SESSION, forge.String, Atom()); add("execute", "execute", 'x', "File of commands to execute", SESSION, forge.String, Atom()); add("path", "path", 'L', "Target path for loaded graph", SESSION, forge.String, Atom()); diff --git a/src/client/ClientStore.cpp b/src/client/ClientStore.cpp index 58a46228..31ef4d47 100644 --- a/src/client/ClientStore.cpp +++ b/src/client/ClientStore.cpp @@ -208,8 +208,8 @@ ClientStore::del(const Raul::URI& uri) } void -ClientStore::copy(const Raul::Path& old_path, - const Raul::URI& new_uri) +ClientStore::copy(const Raul::URI& old_uri, + const Raul::URI& new_uri) { _log.error("Client store copy unsupported\n"); } diff --git a/src/ingen/ingen.cpp b/src/ingen/ingen.cpp index 164eded5..b5605197 100644 --- a/src/ingen/ingen.cpp +++ b/src/ingen/ingen.cpp @@ -181,6 +181,20 @@ main(int argc, char** argv) std::lock_guard<std::mutex> lock(world->rdf_mutex()); world->parser()->parse_file( world, engine_interface.get(), graph, parent, symbol); + } else if (conf.option("server-load").is_valid()) { + const char* path = conf.option("server-load").ptr<char>(); + if (serd_uri_string_has_scheme((const uint8_t*)path)) { + std::cout << "Loading " << path << " (server side)" << std::endl; + engine_interface->copy(Raul::URI(path), Node::root_graph_uri()); + } else { + SerdNode uri = serd_node_new_file_uri( + (const uint8_t*)path, NULL, NULL, true); + std::cout << "Loading " << (const char*)uri.buf + << " (server side)" << std::endl; + engine_interface->copy(Raul::URI((const char*)uri.buf), + Node::root_graph_uri()); + serd_node_free(&uri); + } } // Save the currently loaded graph @@ -188,12 +202,12 @@ main(int argc, char** argv) const char* path = conf.option("save").ptr<char>(); if (serd_uri_string_has_scheme((const uint8_t*)path)) { std::cout << "Saving to " << path << std::endl; - engine_interface->copy(Raul::Path("/"), Raul::URI(path)); + engine_interface->copy(Node::root_graph_uri(), Raul::URI(path)); } else { SerdNode uri = serd_node_new_file_uri( (const uint8_t*)path, NULL, NULL, true); std::cout << "Saving to " << (const char*)uri.buf << std::endl; - engine_interface->copy(Raul::Path("/"), + engine_interface->copy(Node::root_graph_uri(), Raul::URI((const char*)uri.buf)); serd_node_free(&uri); } diff --git a/src/server/Broadcaster.hpp b/src/server/Broadcaster.hpp index aa07c26d..f7952a31 100644 --- a/src/server/Broadcaster.hpp +++ b/src/server/Broadcaster.hpp @@ -111,9 +111,9 @@ public: BROADCAST(delta, uri, remove, add); } - void copy(const Raul::Path& old_path, - const Raul::URI& new_uri) { - BROADCAST(copy, old_path, new_uri); + void copy(const Raul::URI& old_uri, + const Raul::URI& new_uri) { + BROADCAST(copy, old_uri, new_uri); } void move(const Raul::Path& old_path, diff --git a/src/server/EventWriter.cpp b/src/server/EventWriter.cpp index 1fb5aa2c..1ec5e1a7 100644 --- a/src/server/EventWriter.cpp +++ b/src/server/EventWriter.cpp @@ -69,12 +69,12 @@ EventWriter::delta(const Raul::URI& uri, } void -EventWriter::copy(const Raul::Path& old_path, - const Raul::URI& new_uri) +EventWriter::copy(const Raul::URI& old_uri, + const Raul::URI& new_uri) { _engine.enqueue_event( new Events::Copy(_engine, _respondee, _request_id, now(), - old_path, new_uri)); + old_uri, new_uri)); } void diff --git a/src/server/EventWriter.hpp b/src/server/EventWriter.hpp index efb48d59..15a144ef 100644 --- a/src/server/EventWriter.hpp +++ b/src/server/EventWriter.hpp @@ -64,8 +64,8 @@ public: const Resource::Properties& remove, const Resource::Properties& add); - virtual void copy(const Raul::Path& old_path, - const Raul::URI& new_uri); + virtual void copy(const Raul::URI& old_uri, + const Raul::URI& new_uri); virtual void move(const Raul::Path& old_path, const Raul::Path& new_path); diff --git a/src/server/events/Copy.cpp b/src/server/events/Copy.cpp index 4e89bb88..e0438c9d 100644 --- a/src/server/events/Copy.cpp +++ b/src/server/events/Copy.cpp @@ -14,6 +14,7 @@ along with Ingen. If not, see <http://www.gnu.org/licenses/>. */ +#include "ingen/Parser.hpp" #include "ingen/Serialiser.hpp" #include "ingen/Store.hpp" #include "raul/Path.hpp" @@ -31,14 +32,14 @@ namespace Ingen { namespace Server { namespace Events { -Copy::Copy(Engine& engine, - SPtr<Interface> client, - int32_t id, - SampleCount timestamp, - const Raul::Path& old_path, - const Raul::URI& new_uri) +Copy::Copy(Engine& engine, + SPtr<Interface> client, + int32_t id, + SampleCount timestamp, + const Raul::URI& old_uri, + const Raul::URI& new_uri) : Event(engine, client, id, timestamp) - , _old_path(old_path) + , _old_uri(old_uri) , _new_uri(new_uri) , _old_block(NULL) , _parent(NULL) @@ -49,36 +50,46 @@ Copy::Copy(Engine& engine, bool Copy::pre_process() { - if (_old_path.empty() || _new_uri == Node::root_graph_uri()) { - return Event::pre_process_done(Status::BAD_REQUEST); - } - std::unique_lock<std::mutex> lock(_engine.store()->mutex()); - // Find the old node - const Store::iterator i = _engine.store()->find(_old_path); - if (i == _engine.store()->end()) { - return Event::pre_process_done(Status::NOT_FOUND, _old_path); + if (Node::uri_is_path(_old_uri)) { + // Old URI is a path within the engine + const Raul::Path old_path = Node::uri_to_path(_old_uri); + + // Find the old node + const Store::iterator i = _engine.store()->find(old_path); + if (i == _engine.store()->end()) { + return Event::pre_process_done(Status::NOT_FOUND, old_path); + } + + // Ensure it is a block (ports are not supported for now) + if (!(_old_block = dynamic_ptr_cast<BlockImpl>(i->second))) { + return Event::pre_process_done(Status::BAD_OBJECT_TYPE, old_path); + } + + if (Node::uri_is_path(_new_uri)) { + // Copy to path within the engine + return engine_to_engine(); + } else if (_new_uri.scheme() == "file") { + // Copy to filesystem path (i.e. save) + return engine_to_filesystem(); + } else { + return Event::pre_process_done(Status::BAD_REQUEST); + } + } else if (_old_uri.scheme() == "file") { + if (Node::uri_is_path(_new_uri)) { + filesystem_to_engine(); + } else { + // Ingen is not your file manager + return Event::pre_process_done(Status::BAD_REQUEST); + } } - // Ensure it is a block (ports are not supported for now) - if (!(_old_block = dynamic_ptr_cast<BlockImpl>(i->second))) { - return Event::pre_process_done(Status::BAD_OBJECT_TYPE, _old_path); - } - - if (Node::uri_is_path(_new_uri)) { - // Copy to path within the engine - return copy_to_engine(); - } else if (_new_uri.scheme() == "file") { - // Copy to filesystem path (i.e. save) - return copy_to_filesystem(); - } else { - return Event::pre_process_done(Status::BAD_REQUEST); - } + return Event::pre_process_done(Status::BAD_URI); } bool -Copy::copy_to_engine() +Copy::engine_to_engine() { // Only support a single source for now const Raul::Path new_path = Node::uri_to_path(_new_uri); @@ -121,29 +132,32 @@ Copy::copy_to_engine() return Event::pre_process_done(Status::SUCCESS); } +static bool +ends_with(const std::string& str, const std::string& end) +{ + if (str.length() >= end.length()) { + return !str.compare(str.length() - end.length(), end.length(), end); + } + return false; +} + bool -Copy::copy_to_filesystem() +Copy::engine_to_filesystem() { // Ensure source is a graph SPtr<GraphImpl> graph = dynamic_ptr_cast<GraphImpl>(_old_block); if (!graph) { - return Event::pre_process_done(Status::BAD_OBJECT_TYPE, _old_path); + return Event::pre_process_done(Status::BAD_OBJECT_TYPE, _old_uri); } - // Parse filename from target URI - const uint8_t* uri = (const uint8_t*)_new_uri.c_str(); - uint8_t* path = serd_file_uri_parse(uri, NULL); - const std::string filename = (const char*)path; - free(path); - if (!_engine.world()->serialiser()) { return Event::pre_process_done(Status::INTERNAL_ERROR); } std::lock_guard<std::mutex> lock(_engine.world()->rdf_mutex()); - if (filename.find(".ingen") != std::string::npos) { - _engine.world()->serialiser()->write_bundle(graph, _new_uri/*filename*/); + if (ends_with(_new_uri, ".ingen") || ends_with(_new_uri, ".ingen/")) { + _engine.world()->serialiser()->write_bundle(graph, _new_uri); } else { _engine.world()->serialiser()->start_to_file(graph->path(), _new_uri); _engine.world()->serialiser()->serialise(graph); @@ -153,6 +167,32 @@ Copy::copy_to_filesystem() return Event::pre_process_done(Status::SUCCESS); } +bool +Copy::filesystem_to_engine() +{ + if (!_engine.world()->parser()) { + return Event::pre_process_done(Status::INTERNAL_ERROR); + } + + std::lock_guard<std::mutex> lock(_engine.world()->rdf_mutex()); + + // Old URI is a filesystem path and new URI is a path within the engine + const std::string src_path = _old_uri.substr(strlen("file://")); + const Raul::Path dst_path = Node::uri_to_path(_new_uri); + boost::optional<Raul::Path> dst_parent; + boost::optional<Raul::Symbol> dst_symbol; + if (!dst_path.is_root()) { + dst_parent = dst_path.parent(); + dst_symbol = Raul::Symbol(dst_path.symbol()); + } + + _engine.world()->parser()->parse_file( + _engine.world(), _engine.world()->interface().get(), src_path, + dst_parent, dst_symbol); + + return Event::pre_process_done(Status::SUCCESS); +} + void Copy::execute(ProcessContext& context) { @@ -167,7 +207,7 @@ Copy::post_process() { Broadcaster::Transfer t(*_engine.broadcaster()); if (respond() == Status::SUCCESS) { - _engine.broadcaster()->copy(_old_path, _new_uri); + _engine.broadcaster()->copy(_old_uri, _new_uri); } } diff --git a/src/server/events/Copy.hpp b/src/server/events/Copy.hpp index e40bfa3b..dfcbd3b2 100644 --- a/src/server/events/Copy.hpp +++ b/src/server/events/Copy.hpp @@ -47,27 +47,28 @@ namespace Events { class Copy : public Event { public: - Copy(Engine& engine, - SPtr<Interface> client, - int32_t id, - SampleCount timestamp, - const Raul::Path& old_path, - const Raul::URI& new_uri); + Copy(Engine& engine, + SPtr<Interface> client, + int32_t id, + SampleCount timestamp, + const Raul::URI& old_uri, + const Raul::URI& new_uri); bool pre_process(); void execute(ProcessContext& context); void post_process(); private: - bool copy_to_engine(); - bool copy_to_filesystem(); - - const Raul::Path _old_path; - const Raul::URI _new_uri; - SPtr<BlockImpl> _old_block; - GraphImpl* _parent; - BlockImpl* _block; - CompiledGraph* _compiled_graph; + bool engine_to_engine(); + bool engine_to_filesystem(); + bool filesystem_to_engine(); + + const Raul::URI _old_uri; + const Raul::URI _new_uri; + SPtr<BlockImpl> _old_block; + GraphImpl* _parent; + BlockImpl* _block; + CompiledGraph* _compiled_graph; }; } // namespace Events |