summaryrefslogtreecommitdiffstats
path: root/src/serialisation
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2008-11-30 19:56:36 +0000
committerDavid Robillard <d@drobilla.net>2008-11-30 19:56:36 +0000
commit684a8fd8fd54a391662e72b1113ddbda14e66612 (patch)
treec1f8896711e45e4102f1968fde465199e7373fd1 /src/serialisation
parent56a392e69a378f28d25b6b66feb62e36125da20c (diff)
downloadingen-684a8fd8fd54a391662e72b1113ddbda14e66612.tar.gz
ingen-684a8fd8fd54a391662e72b1113ddbda14e66612.tar.bz2
ingen-684a8fd8fd54a391662e72b1113ddbda14e66612.zip
Some support for bundle saving.
git-svn-id: http://svn.drobilla.net/lad/trunk/ingen@1831 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'src/serialisation')
-rw-r--r--src/serialisation/Serialiser.cpp68
-rw-r--r--src/serialisation/Serialiser.hpp18
2 files changed, 84 insertions, 2 deletions
diff --git a/src/serialisation/Serialiser.cpp b/src/serialisation/Serialiser.cpp
index baf8a475..0bb7b57d 100644
--- a/src/serialisation/Serialiser.cpp
+++ b/src/serialisation/Serialiser.cpp
@@ -27,6 +27,9 @@
#include <string>
#include <utility> // pair, make_pair
#include <vector>
+#include <glib.h>
+#include <glib/gstdio.h>
+#include <glibmm/convert.h>
#include "raul/Atom.hpp"
#include "raul/AtomRDF.hpp"
#include "raul/Path.hpp"
@@ -62,8 +65,11 @@ Serialiser::Serialiser(Shared::World& world, SharedPtr<Shared::Store> store)
void
-Serialiser::to_file(SharedPtr<GraphObject> object, const string& filename)
+Serialiser::to_file(const Record& record)
{
+ SharedPtr<GraphObject> object = record.object;
+ const string& filename = record.uri;
+
_root_path = object->path();
start_to_filename(filename);
serialise(object);
@@ -71,6 +77,66 @@ Serialiser::to_file(SharedPtr<GraphObject> object, const string& filename)
}
+static
+std::string
+uri_to_symbol(const std::string& uri)
+{
+ string symbol = uri;
+ symbol = symbol.substr(symbol.find_last_of("/") + 1);
+ symbol = symbol.substr(0, symbol.find("."));
+ symbol = Path::nameify(symbol);
+ return symbol;
+}
+
+
+void
+Serialiser::write_manifest(const std::string& bundle_uri,
+ const Records& records)
+{
+
+ cout << "WRITE MANIFEST BUNDLE URI: " << bundle_uri << endl;
+ const string filename = Glib::filename_from_uri(bundle_uri) + "manifest.ttl";
+ cout << "FILENAME: " << filename << endl;
+ start_to_filename(filename);
+ _model->set_base_uri(bundle_uri);
+ for (Records::const_iterator i = records.begin(); i != records.end(); ++i) {
+ SharedPtr<Patch> patch = PtrCast<Patch>(i->object);
+ if (patch) {
+ const Redland::Node subject(_model->world(), Redland::Node::RESOURCE,
+ uri_to_symbol(i->uri));
+ _model->add_statement(subject, "rdf:type",
+ Redland::Node(_model->world(), Redland::Node::RESOURCE, "ingen:Patch"));
+ _model->add_statement(subject, "rdf:type",
+ Redland::Node(_model->world(), Redland::Node::RESOURCE, "lv2:Plugin"));
+ _model->add_statement(subject, "rdfs:seeAlso",
+ Redland::Node(_model->world(), Redland::Node::RESOURCE, i->uri));
+ }
+ }
+ finish();
+}
+
+
+void
+Serialiser::write_bundle(const Record& record)
+{
+ SharedPtr<GraphObject> object = record.object;
+ string bundle_uri = record.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 root_file = bundle_uri + symbol + ".ingen.ttl";
+ start_to_filename(root_file);
+ serialise(object);
+ finish();
+ records.push_back(Record(object, bundle_uri + symbol + ".ingen.ttl"));
+ write_manifest(bundle_uri, records);
+}
+
string
Serialiser::to_string(SharedPtr<GraphObject> object,
diff --git a/src/serialisation/Serialiser.hpp b/src/serialisation/Serialiser.hpp
index 4d33d771..6151bae2 100644
--- a/src/serialisation/Serialiser.hpp
+++ b/src/serialisation/Serialiser.hpp
@@ -58,7 +58,23 @@ class Serialiser
public:
Serialiser(Shared::World& world, SharedPtr<Shared::Store> store);
- void to_file(SharedPtr<GraphObject> object, const std::string& filename);
+ struct Record {
+ Record(SharedPtr<GraphObject> o, const std::string& u)
+ : object(o), uri(u)
+ {}
+
+ const SharedPtr<GraphObject> object;
+ const std::string uri;
+ };
+
+ typedef std::list<Record> Records;
+
+ void to_file(const Record& record);
+
+ void write_bundle(const Record& record);
+
+ void write_manifest(const std::string& bundle_uri,
+ const Records& records);
std::string to_string(SharedPtr<GraphObject> object,
const std::string& base_uri,