From b9de87b822a4fd61ffd4f0c899f7b8f81955c3f1 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Thu, 26 Apr 2012 23:30:35 +0000 Subject: Implement delta via atoms. git-svn-id: http://svn.drobilla.net/lad/trunk/ingen@4278 a436a847-0d15-0410-975c-d299462d15a1 --- ingen/shared/AtomReader.hpp | 3 ++ src/shared/AtomReader.cpp | 71 +++++++++++++++++++++++++++++++++------------ 2 files changed, 56 insertions(+), 18 deletions(-) diff --git a/ingen/shared/AtomReader.hpp b/ingen/shared/AtomReader.hpp index aa77a38f..7cbacd29 100644 --- a/ingen/shared/AtomReader.hpp +++ b/ingen/shared/AtomReader.hpp @@ -41,6 +41,9 @@ public: void write(const LV2_Atom* msg); private: + void get_props(const LV2_Atom_Object* obj, + Ingen::Resource::Properties& props); + LV2URIMap& _map; URIs& _uris; Forge& _forge; diff --git a/src/shared/AtomReader.cpp b/src/shared/AtomReader.cpp index f7c5d7e4..343bb23e 100644 --- a/src/shared/AtomReader.cpp +++ b/src/shared/AtomReader.cpp @@ -31,6 +31,25 @@ AtomReader::AtomReader(LV2URIMap& map, URIs& uris, Forge& forge, Interface& ifac { } +void +AtomReader::get_props(const LV2_Atom_Object* obj, + Ingen::Resource::Properties& props) +{ + LV2_ATOM_OBJECT_FOREACH(obj, p) { + 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)); + } +} + void AtomReader::write(const LV2_Atom* msg) { @@ -59,32 +78,48 @@ AtomReader::write(const LV2_Atom* msg) if (!body) { Raul::warn << "Put message has no body" << std::endl; return; + } else if (!subject_uri) { + Raul::warn << "Put message has no subject" << std::endl; + return; } Ingen::Resource::Properties props; - LV2_ATOM_OBJECT_FOREACH(body, p) { - 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)); + get_props(body, props); + + _iface.set_response_id(obj->body.id); + _iface.put(subject_uri, props); + } else if (obj->body.otype == _uris.patch_Patch) { + if (!subject_uri) { + Raul::warn << "Put message has no subject" << std::endl; + return; } - 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; + const LV2_Atom_Object* remove = NULL; + lv2_atom_object_get(obj, (LV2_URID)_uris.patch_remove, &remove, 0); + if (!remove) { + Raul::warn << "Patch message has no remove" << std::endl; + return; } + const LV2_Atom_Object* add = NULL; + lv2_atom_object_get(obj, (LV2_URID)_uris.patch_add, &add, 0); + if (!add) { + Raul::warn << "Patch message has no add" << std::endl; + return; + } + + Ingen::Resource::Properties add_props; + get_props(remove, add_props); + + Ingen::Resource::Properties remove_props; + get_props(remove, remove_props); + + _iface.delta(subject_uri, remove_props, add_props); + } else { - Raul::warn << "Unknown object type " << obj->body.otype << std::endl; + Raul::warn << "Unknown object type <" + << _map.unmap_uri(obj->body.otype) + << ">" << std::endl; } } -- cgit v1.2.1