From a95e08e48c2d1f68693609627c6d6f52c6982264 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Wed, 13 May 2009 06:14:40 +0000 Subject: Generic simple query system for both objects and plugins. git-svn-id: http://svn.drobilla.net/lad/trunk/ingen@1997 a436a847-0d15-0410-975c-d299462d15a1 --- src/engine/events/RequestMetadataEvent.cpp | 43 +++++++++++++++++------------- 1 file changed, 25 insertions(+), 18 deletions(-) (limited to 'src/engine/events/RequestMetadataEvent.cpp') diff --git a/src/engine/events/RequestMetadataEvent.cpp b/src/engine/events/RequestMetadataEvent.cpp index cf8a127a..14cbcfb3 100644 --- a/src/engine/events/RequestMetadataEvent.cpp +++ b/src/engine/events/RequestMetadataEvent.cpp @@ -23,6 +23,7 @@ #include "EngineStore.hpp" #include "ClientBroadcaster.hpp" #include "PortImpl.hpp" +#include "PluginImpl.hpp" #include "AudioBuffer.hpp" using namespace std; @@ -36,15 +37,16 @@ using namespace Shared; RequestMetadataEvent::RequestMetadataEvent(Engine& engine, SharedPtr responder, SampleCount timestamp, - bool property, - const Path& node_path, + bool is_property, + const URI& subject, const URI& key) : QueuedEvent(engine, responder, timestamp) + , _error(NO_ERROR) , _special_type(NONE) - , _path(node_path) - , _property(property) + , _uri(subject) , _key(key) - , _object(NULL) + , _resource(0) + , _is_property(is_property) { } @@ -52,9 +54,14 @@ RequestMetadataEvent::RequestMetadataEvent(Engine& engine, void RequestMetadataEvent::pre_process() { + const bool is_object = (_uri.scheme() == Path::scheme && Path::is_valid(_uri.str())); if (_responder->client()) { - _object = _engine.engine_store()->find_object(_path); - if (_object == NULL) { + if (is_object) + _resource = _engine.engine_store()->find_object(Path(_uri.str())); + else + _resource = _engine.node_factory()->plugin(_uri); + + if (!_resource) { QueuedEvent::pre_process(); return; } @@ -62,10 +69,10 @@ RequestMetadataEvent::pre_process() if (_key.str() == "ingen:value") _special_type = PORT_VALUE; - else if (_property) - _value = _object->get_property(_key); + else if (!is_object || _is_property) + _value = _resource->get_property(_key); else - _value = _object->get_variable(_key); + _value = dynamic_cast(_resource)->get_variable(_key); QueuedEvent::pre_process(); } @@ -76,12 +83,12 @@ RequestMetadataEvent::execute(ProcessContext& context) { QueuedEvent::execute(context); if (_special_type == PORT_VALUE) { - PortImpl* port = dynamic_cast(_object); + PortImpl* port = dynamic_cast(_resource); if (port) { if (port->type() == DataType::CONTROL || port->type() == DataType::AUDIO) _value = ((AudioBuffer*)port->buffer(0))->value_at(0); // TODO: offset } else { - _object = 0; + _resource = 0; } } } @@ -92,19 +99,19 @@ RequestMetadataEvent::post_process() { if (_responder->client()) { if (_special_type == PORT_VALUE) { - if (_object) { + if (_resource) { _responder->respond_ok(); - _responder->client()->set_port_value(_path, _value); + _responder->client()->set_port_value(_uri.str(), _value); } else { - const string msg = "Get value for non-port " + _path.str(); + const string msg = "Get value for non-port " + _uri.str(); _responder->respond_error(msg); } - } else if (!_object) { - const string msg = "Unable to find variable subject " + _path.str(); + } else if (!_resource) { + const string msg = "Unable to find subject " + _uri.str(); _responder->respond_error(msg); } else { _responder->respond_ok(); - _responder->client()->set_variable(_path, _key, _value); + _responder->client()->set_variable(_uri, _key, _value); } } else { _responder->respond_error("Unknown client"); -- cgit v1.2.1