From bee242f29045b82e50a4f112ac17f7e14344df78 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Thu, 26 Jul 2007 19:16:52 +0000 Subject: Use PathTable for engine side objects. Re-implement renaming and destroying more cleanly (not to mention workingly). git-svn-id: http://svn.drobilla.net/lad/ingen@638 a436a847-0d15-0410-975c-d299462d15a1 --- src/libs/engine/events/AddNodeEvent.cpp | 5 +-- src/libs/engine/events/AddPortEvent.cpp | 5 +-- src/libs/engine/events/ClearPatchEvent.cpp | 3 ++ src/libs/engine/events/CreatePatchEvent.cpp | 5 +-- src/libs/engine/events/DestroyEvent.cpp | 26 ++++++++------ src/libs/engine/events/DestroyEvent.hpp | 28 +++++++-------- src/libs/engine/events/RenameEvent.cpp | 45 +++++++++++++------------ src/libs/engine/events/RenameEvent.hpp | 15 +++++---- src/libs/engine/events/RequestMetadataEvent.cpp | 2 +- src/libs/engine/events/RequestObjectEvent.cpp | 2 +- src/libs/engine/events/SetMetadataEvent.cpp | 2 +- 11 files changed, 76 insertions(+), 62 deletions(-) (limited to 'src/libs/engine/events') diff --git a/src/libs/engine/events/AddNodeEvent.cpp b/src/libs/engine/events/AddNodeEvent.cpp index fd95e838..f1aa3aed 100644 --- a/src/libs/engine/events/AddNodeEvent.cpp +++ b/src/libs/engine/events/AddNodeEvent.cpp @@ -71,7 +71,7 @@ AddNodeEvent::AddNodeEvent(Engine& engine, SharedPtr responde void AddNodeEvent::pre_process() { - if (_engine.object_store()->find(_path) != NULL) { + if (_engine.object_store()->find_object(_path) != NULL) { _node_already_exists = true; QueuedEvent::pre_process(); return; @@ -95,7 +95,8 @@ AddNodeEvent::pre_process() // This can be done here because the audio thread doesn't touch the // node tree - just the process order array _patch->add_node(new Raul::ListNode(_node)); - _node->add_to_store(_engine.object_store()); + //_node->add_to_store(_engine.object_store()); + _engine.object_store()->add(_node); // FIXME: not really necessary to build process order since it's not connected, // just append to the list diff --git a/src/libs/engine/events/AddPortEvent.cpp b/src/libs/engine/events/AddPortEvent.cpp index c4e7a26c..6288a03f 100644 --- a/src/libs/engine/events/AddPortEvent.cpp +++ b/src/libs/engine/events/AddPortEvent.cpp @@ -75,7 +75,7 @@ AddPortEvent::AddPortEvent(Engine& engine, void AddPortEvent::pre_process() { - if (_engine.object_store()->find(_path) != NULL) { + if (_engine.object_store()->find_object(_path) != NULL) { QueuedEvent::pre_process(); return; } @@ -109,7 +109,8 @@ AddPortEvent::pre_process() _ports_array->at(_patch->num_ports()-1) = _patch_port; - _patch_port->add_to_store(_engine.object_store()); + //_patch_port->add_to_store(_engine.object_store()); + _engine.object_store()->add(_patch_port); if (!_patch->parent()) { if (_type == "ingen:audio") diff --git a/src/libs/engine/events/ClearPatchEvent.cpp b/src/libs/engine/events/ClearPatchEvent.cpp index 8ac8c23d..0269aaa7 100644 --- a/src/libs/engine/events/ClearPatchEvent.cpp +++ b/src/libs/engine/events/ClearPatchEvent.cpp @@ -43,6 +43,8 @@ ClearPatchEvent::ClearPatchEvent(Engine& engine, SharedPtr re void ClearPatchEvent::pre_process() { + cerr << "FIXME: CLEAR PATCH\n"; +#if 0 _patch = _engine.object_store()->find_patch(_patch_path); if (_patch != NULL) { @@ -52,6 +54,7 @@ ClearPatchEvent::pre_process() for (Raul::List::const_iterator i = _patch->nodes().begin(); i != _patch->nodes().end(); ++i) (*i)->remove_from_store(); } +#endif QueuedEvent::pre_process(); } diff --git a/src/libs/engine/events/CreatePatchEvent.cpp b/src/libs/engine/events/CreatePatchEvent.cpp index 866420d7..24339320 100644 --- a/src/libs/engine/events/CreatePatchEvent.cpp +++ b/src/libs/engine/events/CreatePatchEvent.cpp @@ -46,7 +46,7 @@ CreatePatchEvent::CreatePatchEvent(Engine& engine, SharedPtr void CreatePatchEvent::pre_process() { - if (_path == "/" || _engine.object_store()->find(_path) != NULL) { + if (_path == "/" || _engine.object_store()->find_object(_path) != NULL) { _error = OBJECT_EXISTS; QueuedEvent::pre_process(); return; @@ -81,7 +81,8 @@ CreatePatchEvent::pre_process() _patch->activate(); // Insert into ObjectStore - _patch->add_to_store(_engine.object_store()); + //_patch->add_to_store(_engine.object_store()); + _engine.object_store()->add(_patch); QueuedEvent::pre_process(); } diff --git a/src/libs/engine/events/DestroyEvent.cpp b/src/libs/engine/events/DestroyEvent.cpp index dde2e86b..91b12af0 100644 --- a/src/libs/engine/events/DestroyEvent.cpp +++ b/src/libs/engine/events/DestroyEvent.cpp @@ -40,13 +40,13 @@ namespace Ingen { DestroyEvent::DestroyEvent(Engine& engine, SharedPtr responder, FrameTime time, QueuedEventSource* source, const string& path, bool block) : QueuedEvent(engine, responder, time, source, source), _path(path), + _store_iterator(engine.object_store()->objects().end()), _object(NULL), _node(NULL), _port(NULL), _driver_port(NULL), _patch_node_listnode(NULL), _patch_port_listnode(NULL), - _store_treenode(NULL), _ports_array(NULL), _process_order(NULL), _disconnect_node_event(NULL), @@ -55,10 +55,11 @@ DestroyEvent::DestroyEvent(Engine& engine, SharedPtr responde assert(_source); } - +#if 0 DestroyEvent::DestroyEvent(Engine& engine, SharedPtr responder, FrameTime time, QueuedEventSource* source, Node* node, bool block) : QueuedEvent(engine, responder, block, source), _path(node->path()), + _store_iterator(engine.object_store()->objects().end()) _object(node), _node(node), _port(NULL), @@ -72,7 +73,7 @@ DestroyEvent::DestroyEvent(Engine& engine, SharedPtr responde _disconnect_port_event(NULL) { } - +#endif DestroyEvent::~DestroyEvent() { @@ -84,16 +85,20 @@ DestroyEvent::~DestroyEvent() void DestroyEvent::pre_process() { - if (_object == NULL) { - _object = _engine.object_store()->find(_path); + //if (_object == NULL) { + _store_iterator = _engine.object_store()->find(_path); + //_object = _engine.object_store()->find_object(_path); - if (_object) { + if (_store_iterator != _engine.object_store()->objects().end()) { _node = dynamic_cast(_object); if (!_node) _port = dynamic_cast(_object); } - } + //} + + if (_store_iterator != _engine.object_store()->objects().end()) + _engine.object_store()->remove(_store_iterator); if (_node != NULL && _path != "/") { assert(_node->parent_patch()); @@ -101,11 +106,12 @@ DestroyEvent::pre_process() if (_patch_node_listnode) { assert(_patch_node_listnode->elem() == _node); - _node->remove_from_store(); - _disconnect_node_event = new DisconnectNodeEvent(_engine, _node); _disconnect_node_event->pre_process(); + //_node->remove_from_store(); + _engine.object_store()->remove(_store_iterator); + if (_node->parent_patch()->enabled()) { // FIXME: is this called multiple times? _process_order = _node->parent_patch()->build_process_order(); @@ -128,7 +134,7 @@ DestroyEvent::pre_process() if (_patch_port_listnode) { assert(_patch_port_listnode->elem() == _port); - _port->remove_from_store(); + //_port->remove_from_store(); _disconnect_port_event = new DisconnectPortEvent(_engine, _port); _disconnect_port_event->pre_process(); diff --git a/src/libs/engine/events/DestroyEvent.hpp b/src/libs/engine/events/DestroyEvent.hpp index 6495258e..0a855951 100644 --- a/src/libs/engine/events/DestroyEvent.hpp +++ b/src/libs/engine/events/DestroyEvent.hpp @@ -21,7 +21,7 @@ #include #include #include "QueuedEvent.hpp" - +#include "ObjectStore.hpp" using std::string; @@ -51,7 +51,7 @@ class DestroyEvent : public QueuedEvent { public: DestroyEvent(Engine& engine, SharedPtr responder, FrameTime timestamp, QueuedEventSource* source, const string& path, bool block = true); - DestroyEvent(Engine& engine, SharedPtr responder, FrameTime timestamp, QueuedEventSource* source, Node* node, bool block = true); + //DestroyEvent(Engine& engine, SharedPtr responder, FrameTime timestamp, QueuedEventSource* source, Node* node, bool block = true); ~DestroyEvent(); void pre_process(); @@ -59,18 +59,18 @@ public: void post_process(); private: - Path _path; - GraphObject* _object; - Node* _node; ///< Same as _object if it is a Node, otherwise NULL - Port* _port; ///< Same as _object if it is a Port, otherwise NULL - DriverPort* _driver_port; - Raul::ListNode* _patch_node_listnode; - Raul::ListNode* _patch_port_listnode; - TreeNode* _store_treenode; - Raul::Array* _ports_array; ///< New (external) ports array for Patch - Raul::Array* _process_order; ///< Patch's new process order - DisconnectNodeEvent* _disconnect_node_event; - DisconnectPortEvent* _disconnect_port_event; + Path _path; + ObjectStore::Objects::iterator _store_iterator; + GraphObject* _object; + Node* _node; ///< Same as _object if it is a Node, otherwise NULL + Port* _port; ///< Same as _object if it is a Port, otherwise NULL + DriverPort* _driver_port; + Raul::ListNode* _patch_node_listnode; + Raul::ListNode* _patch_port_listnode; + Raul::Array* _ports_array; ///< New (external) ports array for Patch + Raul::Array* _process_order; ///< Patch's new process order + DisconnectNodeEvent* _disconnect_node_event; + DisconnectPortEvent* _disconnect_port_event; }; diff --git a/src/libs/engine/events/RenameEvent.cpp b/src/libs/engine/events/RenameEvent.cpp index 0a2b0239..a7dc4874 100644 --- a/src/libs/engine/events/RenameEvent.cpp +++ b/src/libs/engine/events/RenameEvent.cpp @@ -25,6 +25,8 @@ #include #include "ObjectStore.hpp" +using namespace std; + namespace Ingen { @@ -34,7 +36,7 @@ RenameEvent::RenameEvent(Engine& engine, SharedPtr responder, _name(name), _new_path(_old_path.parent().base() + name), _parent_patch(NULL), - _store_treenode(NULL), + _store_iterator(engine.object_store()->objects().end()), _error(NO_ERROR) { /* @@ -59,34 +61,33 @@ RenameEvent::pre_process() return; } - if (_engine.object_store()->find(_new_path)) { - _error = OBJECT_EXISTS; - QueuedEvent::pre_process(); - return; - } - - TreeNode* obj = _engine.object_store()->remove(_old_path); - - if (obj == NULL) { + _store_iterator = _engine.object_store()->find(_old_path); + if (_store_iterator == _engine.object_store()->objects().end()) { _error = OBJECT_NOT_FOUND; QueuedEvent::pre_process(); return; } - // Renaming only works for Nodes and Patches (which are Nodes) - /*if (obj->as_node() == NULL) { - _error = OBJECT_NOT_RENAMABLE; - QueuedEvent::pre_process(); - return; - }*/ + Table removed = _engine.object_store()->remove(_store_iterator); + assert(removed.size() > 0); - if (obj != NULL) { - obj->node()->set_path(_new_path); - obj->key(_new_path); - _engine.object_store()->add(obj); - assert(obj->node()->path() == _new_path); + for (Table::iterator i = removed.begin(); i != removed.end(); ++i) { + const Path& child_old_path = i->first; + assert(Path::descendant_comparator(_old_path, child_old_path)); + + Path child_new_path; + if (child_old_path == _old_path) + child_new_path = _new_path; + else + child_new_path = _new_path.base() + child_old_path.substr(_old_path.length()+1); + + cerr << "Renamed " << child_old_path << " -> " << child_new_path << endl; + i->second->set_path(child_new_path); + i->first = child_new_path; } - + + _engine.object_store()->add(removed); + QueuedEvent::pre_process(); } diff --git a/src/libs/engine/events/RenameEvent.hpp b/src/libs/engine/events/RenameEvent.hpp index f50efcc7..52a3050e 100644 --- a/src/libs/engine/events/RenameEvent.hpp +++ b/src/libs/engine/events/RenameEvent.hpp @@ -19,8 +19,9 @@ #define RENAMEEVENT_H #include -#include "QueuedEvent.hpp" #include +#include "QueuedEvent.hpp" +#include "ObjectStore.hpp" using std::string; @@ -54,12 +55,12 @@ public: private: enum ErrorType { NO_ERROR, OBJECT_NOT_FOUND, OBJECT_EXISTS, OBJECT_NOT_RENAMABLE, INVALID_NAME }; - Path _old_path; - string _name; - Path _new_path; - Patch* _parent_patch; - TreeNode* _store_treenode; - ErrorType _error; + Path _old_path; + string _name; + Path _new_path; + Patch* _parent_patch; + ObjectStore::Objects::iterator _store_iterator; + ErrorType _error; }; diff --git a/src/libs/engine/events/RequestMetadataEvent.cpp b/src/libs/engine/events/RequestMetadataEvent.cpp index b9696c4a..9540d738 100644 --- a/src/libs/engine/events/RequestMetadataEvent.cpp +++ b/src/libs/engine/events/RequestMetadataEvent.cpp @@ -44,7 +44,7 @@ RequestMetadataEvent::pre_process() _client = _engine.broadcaster()->client(_responder->client_uri()); if (_client) { - _object = _engine.object_store()->find(_path); + _object = _engine.object_store()->find_object(_path); if (_object == NULL) { QueuedEvent::pre_process(); return; diff --git a/src/libs/engine/events/RequestObjectEvent.cpp b/src/libs/engine/events/RequestObjectEvent.cpp index 8efe37b7..745b10c1 100644 --- a/src/libs/engine/events/RequestObjectEvent.cpp +++ b/src/libs/engine/events/RequestObjectEvent.cpp @@ -44,7 +44,7 @@ void RequestObjectEvent::pre_process() { _client = _engine.broadcaster()->client(_responder->client_uri()); - _object = _engine.object_store()->find(_path); + _object = _engine.object_store()->find_object(_path); QueuedEvent::pre_process(); } diff --git a/src/libs/engine/events/SetMetadataEvent.cpp b/src/libs/engine/events/SetMetadataEvent.cpp index caa1b449..4a93bed6 100644 --- a/src/libs/engine/events/SetMetadataEvent.cpp +++ b/src/libs/engine/events/SetMetadataEvent.cpp @@ -41,7 +41,7 @@ SetMetadataEvent::SetMetadataEvent(Engine& engine, SharedPtr void SetMetadataEvent::pre_process() { - _object = _engine.object_store()->find(_path); + _object = _engine.object_store()->find_object(_path); if (_object == NULL) { QueuedEvent::pre_process(); return; -- cgit v1.2.1