diff options
Diffstat (limited to 'src/libs')
-rw-r--r-- | src/libs/engine/ObjectSender.hpp | 2 | ||||
-rw-r--r-- | src/libs/gui/PatchCanvas.cpp | 6 | ||||
-rw-r--r-- | src/libs/gui/UploadPatchWindow.cpp | 2 | ||||
-rw-r--r-- | src/libs/serialisation/Serialiser.cpp | 94 | ||||
-rw-r--r-- | src/libs/serialisation/Serialiser.hpp | 15 |
5 files changed, 56 insertions, 63 deletions
diff --git a/src/libs/engine/ObjectSender.hpp b/src/libs/engine/ObjectSender.hpp index 7176dcaa..9b6eb000 100644 --- a/src/libs/engine/ObjectSender.hpp +++ b/src/libs/engine/ObjectSender.hpp @@ -38,7 +38,7 @@ class PluginImpl; * (protocol), this is used from the engine to easily send proper Objects * with these messages (which is done in a few different parts of the code). * - * Basically a serializer, except to calls on ClientInterface rather than + * Basically a serialiser, except to calls on ClientInterface rather than * eg a byte stream. */ class ObjectSender { diff --git a/src/libs/gui/PatchCanvas.cpp b/src/libs/gui/PatchCanvas.cpp index 3f0e2716..74000b79 100644 --- a/src/libs/gui/PatchCanvas.cpp +++ b/src/libs/gui/PatchCanvas.cpp @@ -465,11 +465,11 @@ PatchCanvas::copy_selection() for (list<boost::shared_ptr<Item> >::iterator m = _selected_items.begin(); m != _selected_items.end(); ++m) { boost::shared_ptr<NodeModule> module = boost::dynamic_pointer_cast<NodeModule>(*m); if (module) { - serialiser.serialize(module->node()); + serialiser.serialise(module->node()); } else { boost::shared_ptr<PatchPortModule> port_module = boost::dynamic_pointer_cast<PatchPortModule>(*m); if (port_module) - serialiser.serialize(port_module->port()); + serialiser.serialise(port_module->port()); } } @@ -477,7 +477,7 @@ PatchCanvas::copy_selection() c != _selected_connections.end(); ++c) { boost::shared_ptr<Connection> connection = boost::dynamic_pointer_cast<Connection>(*c); if (connection) - serialiser.serialize_connection(connection->model()); + serialiser.serialise_connection(connection->model()); } string result = serialiser.finish(); diff --git a/src/libs/gui/UploadPatchWindow.cpp b/src/libs/gui/UploadPatchWindow.cpp index 57045a91..959bb1ae 100644 --- a/src/libs/gui/UploadPatchWindow.cpp +++ b/src/libs/gui/UploadPatchWindow.cpp @@ -251,7 +251,7 @@ UploadPatchWindow::upload_clicked() Serialiser s(*App::instance().world()->rdf_world); s.start_to_string(); - s.serialize(_patch); + s.serialise(_patch); const string str = s.finish(); istringstream stream(str); diff --git a/src/libs/serialisation/Serialiser.cpp b/src/libs/serialisation/Serialiser.cpp index b21b7c6d..f0008b64 100644 --- a/src/libs/serialisation/Serialiser.cpp +++ b/src/libs/serialisation/Serialiser.cpp @@ -62,7 +62,7 @@ Serialiser::to_file(SharedPtr<GraphObject> object, const string& filename) { _root_object = object; start_to_filename(filename); - serialize(object); + serialise(object); finish(); } @@ -72,7 +72,7 @@ Serialiser::to_string(SharedPtr<GraphObject> object) { _root_object = object; start_to_string(); - serialize(object); + serialise(object); return finish(); } @@ -97,7 +97,7 @@ Serialiser::start_to_filename(const string& filename) * This must be called before any serializing methods. * * The results of the serialization will be returned by the finish() method after - * the desired objects have been serialized. + * the desired objects have been serialised. */ void Serialiser::start_to_string() @@ -121,9 +121,9 @@ Serialiser::finish() string ret = ""; if (_mode == TO_FILE) - _model->serialize_to_file(_base_uri); + _model->serialise_to_file(_base_uri); else - ret = _model->serialize_to_string(); + ret = _model->serialise_to_string(); _base_uri = ""; _node_map.clear(); @@ -214,31 +214,31 @@ Serialiser::find_file(const string& filename, const string& additional_path) #endif void -Serialiser::serialize(SharedPtr<GraphObject> object) throw (std::logic_error) +Serialiser::serialise(SharedPtr<GraphObject> object) throw (std::logic_error) { if (!_model) - throw std::logic_error("serialize called without serialization in progress"); + throw std::logic_error("serialise called without serialization in progress"); SharedPtr<Shared::Patch> patch = PtrCast<Shared::Patch>(object); if (patch) { - serialize_patch(patch); + serialise_patch(patch); return; } SharedPtr<Shared::Node> node = PtrCast<Shared::Node>(object); if (node) { - serialize_node(node, path_to_node_id(node->path())); + serialise_node(node, path_to_node_id(node->path())); return; } SharedPtr<Shared::Port> port = PtrCast<Shared::Port>(object); if (port) { - serialize_port(port.get(), path_to_node_id(port->path())); + serialise_port(port.get(), path_to_node_id(port->path())); return; } cerr << "[Serialiser] WARNING: Unsupported object type, " - << object->path() << " not serialized." << endl; + << object->path() << " not serialised." << endl; } @@ -256,7 +256,7 @@ Serialiser::patch_path_to_rdf_id(const Path& path) void -Serialiser::serialize_patch(SharedPtr<Shared::Patch> patch) +Serialiser::serialise_patch(SharedPtr<Shared::Patch> patch) { assert(_model); @@ -283,26 +283,18 @@ Serialiser::serialize_patch(SharedPtr<Shared::Patch> patch) "ingen:enabled", Atom(patch->enabled())); - for (GraphObject::Variables::const_iterator m = patch->variables().begin(); - m != patch->variables().end(); ++m) { - if (m->first.find(":") != string::npos) { - _model->add_statement( - patch_id, - m->first.c_str(), - m->second); - } - } + serialise_variables(patch_id, patch->variables()); for (GraphObject::const_iterator n = patch->children_begin(); n != patch->children_end(); ++n) { SharedPtr<Shared::Patch> patch = PtrCast<Shared::Patch>(n->second); SharedPtr<Shared::Node> node = PtrCast<Shared::Node>(n->second); if (patch) { _model->add_statement(patch_id, "ingen:node", patch_path_to_rdf_id(patch->path())); - serialize_patch(patch); + serialise_patch(patch); } else if (node) { const RDF::Node node_id = path_to_node_id(n->second->path()); _model->add_statement(patch_id, "ingen:node", node_id); - serialize_node(node, node_id); + serialise_node(node, node_id); } } @@ -310,18 +302,18 @@ Serialiser::serialize_patch(SharedPtr<Shared::Patch> patch) Port* p = patch->port(i); const RDF::Node port_id = path_to_node_id(p->path()); _model->add_statement(patch_id, "ingen:port", port_id); - serialize_port(p, port_id); + serialise_port(p, port_id); } for (Shared::Patch::Connections::const_iterator c = patch->connections().begin(); c != patch->connections().end(); ++c) { - serialize_connection(*c); + serialise_connection(*c); } } void -Serialiser::serialize_plugin(SharedPtr<Shared::Plugin> plugin) +Serialiser::serialise_plugin(SharedPtr<Shared::Plugin> plugin) { assert(_model); @@ -335,7 +327,7 @@ Serialiser::serialize_plugin(SharedPtr<Shared::Plugin> plugin) void -Serialiser::serialize_node(SharedPtr<Shared::Node> node, const RDF::Node& node_id) +Serialiser::serialise_node(SharedPtr<Shared::Node> node, const RDF::Node& node_id) { const RDF::Node plugin_id = RDF::Node(_model->world(), RDF::Node::RESOURCE, node->plugin()->uri()); @@ -360,33 +352,26 @@ Serialiser::serialize_node(SharedPtr<Shared::Node> node, const RDF::Node& node_i "ingen:polyphonic", node->polyphonic()); - //serialize_plugin(node->plugin()); + //serialise_plugin(node->plugin()); for (uint32_t i=0; i < node->num_ports(); ++i) { Port* p = node->port(i); assert(p); const RDF::Node port_id = path_to_node_id(p->path()); - serialize_port(p, port_id); + serialise_port(p, port_id); _model->add_statement(node_id, "ingen:port", port_id); } - for (GraphObject::Variables::const_iterator m = node->variables().begin(); - m != node->variables().end(); ++m) { - if (m->first.find(":") != string::npos) { - _model->add_statement( - node_id, - m->first, - m->second); - } - } + serialise_variables(node_id, node->variables()); } + /** Writes a port subject with various information only if there are some * predicate/object pairs to go with it (eg if the port has variable, or a value, or..). * Audio output ports with no variable will not be written, for example. */ void -Serialiser::serialize_port(const Port* port, const RDF::Node& port_id) +Serialiser::serialise_port(const Port* port, const RDF::Node& port_id) { if (port->is_input()) _model->add_statement(port_id, "rdf:type", @@ -403,31 +388,36 @@ Serialiser::serialize_port(const Port* port, const RDF::Node& port_id) if (port->type() == DataType::CONTROL && port->is_input()) _model->add_statement(port_id, "ingen:value", port->value()); - if (port->variables().size() > 0) { - for (GraphObject::Variables::const_iterator m = port->variables().begin(); - m != port->variables().end(); ++m) { - if (m->first.find(":") != string::npos) { - _model->add_statement( - port_id, - m->first, - m->second); - } - } - } + serialise_variables(port_id, port->variables()); } void -Serialiser::serialize_connection(SharedPtr<Connection> connection) throw (std::logic_error) +Serialiser::serialise_connection(SharedPtr<Connection> connection) throw (std::logic_error) { if (!_model) - throw std::logic_error("serialize_connection called without serialization in progress"); + throw std::logic_error("serialise_connection called without serialization in progress"); const RDF::Node src_node = path_to_node_id(connection->src_port_path()); const RDF::Node dst_node = path_to_node_id(connection->dst_port_path()); _model->add_statement(dst_node, "ingen:connectedTo", src_node); } + + +void +Serialiser::serialise_variables(RDF::Node subject, const GraphObject::Variables& variables) +{ + for (GraphObject::Variables::const_iterator v = variables.begin(); v != variables.end(); ++v) { + if (v->first.find(":") != string::npos) { + RDF::Node var_id = _world.blank_id(); + _model->add_statement(subject, "ingen:variable", var_id); + _model->add_statement(var_id, "ingen:value", v->second); + } else { + cerr << "Warning: not serialising variable with key '" << v->first << "'" << endl; + } + } +} } // namespace Serialisation diff --git a/src/libs/serialisation/Serialiser.hpp b/src/libs/serialisation/Serialiser.hpp index fb1df5d0..041bbb69 100644 --- a/src/libs/serialisation/Serialiser.hpp +++ b/src/libs/serialisation/Serialiser.hpp @@ -28,6 +28,7 @@ #include <raul/Atom.hpp> #include <raul/RDFWorld.hpp> #include <raul/RDFModel.hpp> +#include "interface/GraphObject.hpp" using namespace Raul; using namespace Ingen::Shared; @@ -59,8 +60,8 @@ public: string to_string(SharedPtr<GraphObject> object); void start_to_string(); - void serialize(SharedPtr<GraphObject> object) throw (std::logic_error); - void serialize_connection(SharedPtr<Shared::Connection> c) throw (std::logic_error); + void serialise(SharedPtr<GraphObject> object) throw (std::logic_error); + void serialise_connection(SharedPtr<Shared::Connection> c) throw (std::logic_error); string finish(); private: @@ -70,11 +71,13 @@ private: void setup_prefixes(); - void serialize_plugin(SharedPtr<Shared::Plugin> p); + void serialise_plugin(SharedPtr<Shared::Plugin> p); - void serialize_patch(SharedPtr<Shared::Patch> p); - void serialize_node(SharedPtr<Shared::Node> n, const Raul::RDF::Node& id); - void serialize_port(const Shared::Port* p, const Raul::RDF::Node& id); + void serialise_patch(SharedPtr<Shared::Patch> p); + void serialise_node(SharedPtr<Shared::Node> n, const Raul::RDF::Node& id); + void serialise_port(const Shared::Port* p, const Raul::RDF::Node& id); + + void serialise_variables(RDF::Node subject, const GraphObject::Variables& variables); Raul::RDF::Node path_to_node_id(const Path& path); Raul::RDF::Node patch_path_to_rdf_id(const Path& path); |