summaryrefslogtreecommitdiffstats
path: root/src/shared
diff options
context:
space:
mode:
Diffstat (limited to 'src/shared')
-rw-r--r--src/shared/AtomReader.cpp32
-rw-r--r--src/shared/AtomWriter.cpp87
-rw-r--r--src/shared/URIs.cpp9
3 files changed, 106 insertions, 22 deletions
diff --git a/src/shared/AtomReader.cpp b/src/shared/AtomReader.cpp
index 009aace6..618c8833 100644
--- a/src/shared/AtomReader.cpp
+++ b/src/shared/AtomReader.cpp
@@ -45,37 +45,49 @@ AtomReader::write(const LV2_Atom* msg)
const LV2_Atom* subject = NULL;
lv2_object_get(obj, (LV2_URID)_uris.patch_subject, &subject, NULL);
- const char* subject_uri = subject ? (const char*)LV2_ATOM_BODY(subject) : NULL;
+ const char* subject_uri = NULL;
+ if (subject && subject->type == _uris.atom_URI) {
+ subject_uri = (const char*)LV2_ATOM_BODY(subject);
+ } else if (subject && subject->type == _uris.atom_URID) {
+ subject_uri = _map.unmap_uri(((LV2_Atom_URID*)subject)->body);
+ }
+
if (obj->body.otype == _uris.patch_Get) {
- Raul::warn << "ATOM GET " << subject_uri << std::endl;
- _iface.set_response_id(1);
+ _iface.set_response_id(obj->body.id);
_iface.get(subject_uri);
} else if (obj->body.otype == _uris.patch_Put) {
- Raul::warn << "PUT" << std::endl;
const LV2_Atom_Object* body = NULL;
lv2_object_get(obj, (LV2_URID)_uris.patch_body, &body, 0);
if (!body) {
- Raul::warn << "NO BODY" << std::endl;
+ Raul::warn << "Put message has no body" << std::endl;
return;
}
Ingen::Resource::Properties props;
LV2_OBJECT_FOREACH(body, i) {
LV2_Atom_Property_Body* p = lv2_object_iter_get(i);
- props.insert(std::make_pair(_map.unmap_uri(p->key),
- _forge.alloc(p->value.size,
- p->value.type,
- LV2_ATOM_BODY(&p->value))));
+ Raul::Atom val;
+ if (p->value.type == _uris.atom_URID) {
+ const LV2_Atom_URID* urid = (const LV2_Atom_URID*)&p->value;
+ val = _forge.alloc_uri(_map.unmap_uri(urid->body));
+ } else {
+ val = _forge.alloc(p->value.size,
+ p->value.type,
+ LV2_ATOM_BODY(&p->value));
+ }
+
+ props.insert(std::make_pair(_map.unmap_uri(p->key), val));
}
if (subject_uri) {
+ _iface.set_response_id(obj->body.id);
_iface.put(subject_uri, props);
} else {
Raul::warn << "Put message has no subject, ignored" << std::endl;
}
} else {
- Raul::warn << "HANDLE MESSAGE TYPE " << obj->body.otype << std::endl;
+ Raul::warn << "Unknown object type " << obj->body.otype << std::endl;
}
}
diff --git a/src/shared/AtomWriter.cpp b/src/shared/AtomWriter.cpp
index 81a9d9ba..eef9a795 100644
--- a/src/shared/AtomWriter.cpp
+++ b/src/shared/AtomWriter.cpp
@@ -82,6 +82,31 @@ AtomWriter::bundle_end()
}
void
+AtomWriter::forge_uri(const Raul::URI& uri)
+{
+ if (serd_uri_string_has_scheme((const uint8_t*)uri.c_str())) {
+ lv2_atom_forge_urid(&_forge, _map.map_uri(uri.c_str()));
+ } else {
+ lv2_atom_forge_uri(&_forge, uri.c_str(), uri.length());
+ }
+}
+
+void
+AtomWriter::forge_properties(const Resource::Properties& properties)
+{
+ for (Resource::Properties::const_iterator i = properties.begin();
+ i != properties.end(); ++i) {
+ lv2_atom_forge_property_head(&_forge, _map.map_uri(i->first.c_str()), 0);
+ if (i->second.type() == _forge.URI) {
+ forge_uri(i->second.get_uri());
+ } else {
+ lv2_atom_forge_atom(&_forge, i->second.size(), i->second.type());
+ lv2_atom_forge_write(&_forge, i->second.get_body(), i->second.size());
+ }
+ }
+}
+
+void
AtomWriter::put(const Raul::URI& uri,
const Resource::Properties& properties,
Resource::Graph ctx)
@@ -89,20 +114,14 @@ AtomWriter::put(const Raul::URI& uri,
LV2_Atom_Forge_Frame msg;
lv2_atom_forge_blank(&_forge, &msg, next_id(), _uris.patch_Put);
lv2_atom_forge_property_head(&_forge, _uris.patch_subject, 0);
- lv2_atom_forge_uri(&_forge, uri.c_str(), uri.length());
+ forge_uri(uri);
lv2_atom_forge_property_head(&_forge, _uris.patch_body, 0);
LV2_Atom_Forge_Frame body;
lv2_atom_forge_blank(&_forge, &body, 0, 0);
-
- for (Resource::Properties::const_iterator i = properties.begin();
- i != properties.end(); ++i) {
- lv2_atom_forge_property_head(&_forge, _map.map_uri(i->first.c_str()), 0);
- lv2_atom_forge_atom(&_forge, i->second.size(), i->second.type());
- lv2_atom_forge_write(&_forge, i->second.get_body(), i->second.size());
- }
-
+ forge_properties(properties);
lv2_atom_forge_pop(&_forge, &body);
+
lv2_atom_forge_pop(&_forge, &msg);
finish_msg();
}
@@ -112,17 +131,46 @@ AtomWriter::delta(const Raul::URI& uri,
const Resource::Properties& remove,
const Resource::Properties& add)
{
+ LV2_Atom_Forge_Frame msg;
+ lv2_atom_forge_blank(&_forge, &msg, next_id(), _uris.patch_Patch);
+ lv2_atom_forge_property_head(&_forge, _uris.patch_subject, 0);
+ forge_uri(uri);
+
+ lv2_atom_forge_property_head(&_forge, _uris.patch_remove, 0);
+ LV2_Atom_Forge_Frame remove_obj;
+ lv2_atom_forge_blank(&_forge, &remove_obj, 0, 0);
+ forge_properties(remove);
+ lv2_atom_forge_pop(&_forge, &remove_obj);
+
+ lv2_atom_forge_property_head(&_forge, _uris.patch_add, 0);
+ LV2_Atom_Forge_Frame add_obj;
+ lv2_atom_forge_blank(&_forge, &add_obj, 0, 0);
+ forge_properties(add);
+ lv2_atom_forge_pop(&_forge, &add_obj);
+
+ lv2_atom_forge_pop(&_forge, &msg);
+ finish_msg();
}
void
AtomWriter::move(const Raul::Path& old_path,
const Raul::Path& new_path)
{
+ LV2_Atom_Forge_Frame msg;
+ lv2_atom_forge_blank(&_forge, &msg, next_id(), _uris.patch_Move);
+ lv2_atom_forge_property_head(&_forge, _uris.patch_subject, 0);
+ forge_uri(old_path);
+ lv2_atom_forge_property_head(&_forge, _uris.patch_destination, 0);
+ forge_uri(new_path);
}
void
AtomWriter::del(const Raul::URI& uri)
{
+ LV2_Atom_Forge_Frame msg;
+ lv2_atom_forge_blank(&_forge, &msg, next_id(), _uris.patch_Delete);
+ lv2_atom_forge_property_head(&_forge, _uris.patch_subject, 0);
+ forge_uri(uri);
}
void
@@ -136,9 +184,9 @@ AtomWriter::connect(const Raul::Path& src,
LV2_Atom_Forge_Frame body;
lv2_atom_forge_blank(&_forge, &body, 0, _uris.ingen_Connection);
lv2_atom_forge_property_head(&_forge, _uris.ingen_source, 0);
- lv2_atom_forge_string(&_forge, src.c_str(), src.length());
+ forge_uri(src);
lv2_atom_forge_property_head(&_forge, _uris.ingen_destination, 0);
- lv2_atom_forge_string(&_forge, dst.c_str(), dst.length());
+ forge_uri(dst);
lv2_atom_forge_pop(&_forge, &body);
lv2_atom_forge_pop(&_forge, &msg);
@@ -163,6 +211,21 @@ AtomWriter::set_property(const Raul::URI& subject,
const Raul::URI& predicate,
const Raul::Atom& value)
{
+ LV2_Atom_Forge_Frame msg;
+ lv2_atom_forge_blank(&_forge, &msg, next_id(), _uris.patch_Set);
+ lv2_atom_forge_property_head(&_forge, _uris.patch_subject, 0);
+ forge_uri(subject);
+ lv2_atom_forge_property_head(&_forge, _uris.patch_body, 0);
+
+ LV2_Atom_Forge_Frame body;
+ lv2_atom_forge_blank(&_forge, &body, 0, 0);
+ lv2_atom_forge_property_head(&_forge, _map.map_uri(predicate.c_str()), 0);
+ lv2_atom_forge_atom(&_forge, value.size(), value.type());
+ lv2_atom_forge_write(&_forge, value.get_body(), value.size());
+ lv2_atom_forge_pop(&_forge, &body);
+
+ lv2_atom_forge_pop(&_forge, &msg);
+ finish_msg();
}
void
@@ -176,7 +239,7 @@ AtomWriter::get(const Raul::URI& uri)
LV2_Atom_Forge_Frame msg;
lv2_atom_forge_blank(&_forge, &msg, next_id(), _uris.patch_Get);
lv2_atom_forge_property_head(&_forge, _uris.patch_subject, 0);
- lv2_atom_forge_uri(&_forge, uri.c_str(), uri.length());
+ forge_uri(uri);
lv2_atom_forge_pop(&_forge, &msg);
finish_msg();
}
diff --git a/src/shared/URIs.cpp b/src/shared/URIs.cpp
index 07cd8ab1..45cd7592 100644
--- a/src/shared/URIs.cpp
+++ b/src/shared/URIs.cpp
@@ -59,6 +59,8 @@ URIs::URIs(Ingen::Forge& f, LV2URIMap* map)
, atom_Sequence (forge, map, LV2_ATOM__Sequence)
, atom_Sound (forge, map, LV2_ATOM__Sound)
, atom_String (forge, map, LV2_ATOM__String)
+ , atom_URI (forge, map, LV2_ATOM__URI)
+ , atom_URID (forge, map, LV2_ATOM__URID)
, atom_ValuePort (forge, map, LV2_ATOM__ValuePort)
, atom_Vector (forge, map, LV2_ATOM__Vector)
, atom_bufferType (forge, map, LV2_ATOM__bufferType)
@@ -114,10 +116,17 @@ URIs::URIs(Ingen::Forge& f, LV2URIMap* map)
, midi_NoteOn (forge, map, LV2_MIDI__NoteOn)
, midi_controllerNumber (forge, map, LV2_MIDI__controllerNumber)
, midi_noteNumber (forge, map, LV2_MIDI__noteNumber)
+ , patch_Delete (forge, map, LV2_PATCH__Delete)
, patch_Get (forge, map, LV2_PATCH__Get)
+ , patch_Move (forge, map, LV2_PATCH__Move)
+ , patch_Patch (forge, map, LV2_PATCH__Patch)
, patch_Put (forge, map, LV2_PATCH__Put)
, patch_Response (forge, map, LV2_PATCH__Response)
+ , patch_Set (forge, map, LV2_PATCH__Set)
+ , patch_add (forge, map, LV2_PATCH__add)
, patch_body (forge, map, LV2_PATCH__body)
+ , patch_destination (forge, map, LV2_PATCH__destination)
+ , patch_remove (forge, map, LV2_PATCH__remove)
, patch_request (forge, map, LV2_PATCH__request)
, patch_subject (forge, map, LV2_PATCH__subject)
, rdf_instanceOf (forge, map, NS_RDF "instanceOf")