summaryrefslogtreecommitdiffstats
path: root/src/engine/events/SetMetadata.cpp
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2009-10-19 04:07:02 +0000
committerDavid Robillard <d@drobilla.net>2009-10-19 04:07:02 +0000
commita0108c19c4704316a02c85676af349acdda29d72 (patch)
treec971fe3fa385bd3abfb3d450f7f2b4e1a718ed60 /src/engine/events/SetMetadata.cpp
parent78ebb57ba3268da3560aa596dfe14c515f617890 (diff)
downloadingen-a0108c19c4704316a02c85676af349acdda29d72.tar.gz
ingen-a0108c19c4704316a02c85676af349acdda29d72.tar.bz2
ingen-a0108c19c4704316a02c85676af349acdda29d72.zip
Fix set/PUT with multiple properties of the same predicate.
Actually set port value when PUT of ingen:value occurs (fix ticket #410). git-svn-id: http://svn.drobilla.net/lad/trunk/ingen@2198 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'src/engine/events/SetMetadata.cpp')
-rw-r--r--src/engine/events/SetMetadata.cpp42
1 files changed, 37 insertions, 5 deletions
diff --git a/src/engine/events/SetMetadata.cpp b/src/engine/events/SetMetadata.cpp
index e991bcf5..3d62781d 100644
--- a/src/engine/events/SetMetadata.cpp
+++ b/src/engine/events/SetMetadata.cpp
@@ -31,6 +31,7 @@
#include "QueuedEventSource.hpp"
#include "Responder.hpp"
#include "SetMetadata.hpp"
+#include "SetPortValue.hpp"
using namespace std;
using namespace Raul;
@@ -47,6 +48,7 @@ SetMetadata::SetMetadata(
SharedPtr<Responder> responder,
SampleCount timestamp,
QueuedEventSource* source,
+ bool replace,
bool meta,
const URI& subject,
const Properties& properties)
@@ -58,12 +60,20 @@ SetMetadata::SetMetadata(
, _object(NULL)
, _patch(NULL)
, _compiled_patch(NULL)
+ , _replace(replace)
, _is_meta(meta)
, _success(false)
{
}
+SetMetadata::~SetMetadata()
+{
+ for (SetEvents::iterator i = _set_events.begin(); i != _set_events.end(); ++i)
+ delete *i;
+}
+
+
void
SetMetadata::pre_process()
{
@@ -112,16 +122,23 @@ SetMetadata::pre_process()
_types.reserve(_properties.size());
+ GraphObjectImpl* obj = dynamic_cast<GraphObjectImpl*>(_object);
+
+ // If we're replacing (i.e. this is a PUT, not a POST), first remove all properties
+ // with keys we will later set. This must be done first so a PUT with several properties
+ // of the same predicate (e.g. rdf:type) retains the multiple values. Only previously
+ // existing properties should be replaced
+ if (_replace)
+ for (Properties::iterator p = _properties.begin(); p != _properties.end(); ++p)
+ obj->properties().erase(p->first);
+
for (Properties::iterator p = _properties.begin(); p != _properties.end(); ++p) {
const Raul::URI& key = p->first;
const Raul::Atom& value = p->second;
- GraphObjectImpl* obj = dynamic_cast<GraphObjectImpl*>(_object);
SpecialType op = NONE;
if (obj) {
- if (_is_meta)
- obj->meta().set_property(key, value);
- else
- obj->set_property(key, value);
+ Resource& resource = _is_meta ? obj->meta() : *obj;
+ resource.add_property(key, value);
_patch = dynamic_cast<PatchImpl*>(_object);
@@ -150,6 +167,15 @@ SetMetadata::pre_process()
_error = BAD_TYPE;
}
}
+ } else if (key.str() == "ingen:value") {
+ PortImpl* port = dynamic_cast<PortImpl*>(_object);
+ if (port) {
+ SetPortValue* ev = new SetPortValue(_engine, _responder, _time, port, value);
+ ev->pre_process();
+ _set_events.push_back(ev);
+ } else {
+ cerr << "WARNING: Set value for non-port " << _object->uri() << endl;
+ }
}
}
@@ -179,6 +205,9 @@ SetMetadata::execute(ProcessContext& context)
return;
}
+ for (SetEvents::iterator i = _set_events.begin(); i != _set_events.end(); ++i)
+ (*i)->execute(context);
+
std::vector<SpecialType>::const_iterator t = _types.begin();
for (Properties::iterator p = _properties.begin(); p != _properties.end(); ++p, ++t) {
const Raul::Atom& value = p->second;
@@ -219,6 +248,9 @@ SetMetadata::execute(ProcessContext& context)
void
SetMetadata::post_process()
{
+ for (SetEvents::iterator i = _set_events.begin(); i != _set_events.end(); ++i)
+ (*i)->post_process();
+
switch (_error) {
case NO_ERROR:
_responder->respond_ok();