From 41f28207814f5715d38792e7d26e3074beac9bce Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Thu, 27 Dec 2012 01:45:52 +0100 Subject: [PATCH] allow to clear the global Asset registration (#154) --- src/proc/asset/db.hpp | 68 +++++++++++-------- src/proc/assetmanager.cpp | 7 ++ src/proc/assetmanager.hpp | 10 ++- .../mobject/session/sess-manager-impl.cpp | 2 +- 4 files changed, 58 insertions(+), 29 deletions(-) diff --git a/src/proc/asset/db.hpp b/src/proc/asset/db.hpp index bfe99a029..8605a0f59 100644 --- a/src/proc/asset/db.hpp +++ b/src/proc/asset/db.hpp @@ -93,18 +93,19 @@ namespace asset { { IdHashtable table; - DB () : table() { } - ~DB () {clear();} + DB() + : table() + { } + + ~DB() + { + clear(); + } friend class lib::singleton::StaticCreate; public: - template - void put (ID hash, P& ptr) { table[hash] = static_pointer_cast (ptr); } - void put (ID hash, PAsset& ptr) { table[hash] = ptr; } - bool del (ID hash) { return table.erase (hash); } - template P get (ID hash) const @@ -112,6 +113,25 @@ namespace asset { return dynamic_pointer_cast (find (hash)); } + template + void + put (ID hash, P& ptr) + { + table[hash] = static_pointer_cast (ptr); + } + + void + put (ID hash, PAsset& ptr) + { + table[hash] = ptr; + } + + bool + del (ID hash) + { + return table.erase (hash); + } + /** removes all registered assets and does something similar * to Asset::unlink() on each to break cyclic dependencies * (we can't use the real unlink()-function, because this @@ -120,28 +140,21 @@ namespace asset { * could result in segfaults. This doesn't seem to be * a problem, though, because we register and process * \e all assets and the net effect is just breaking - * any cyclic dependencies) + * any cyclic dependencies) + * @note EX_FREE */ void - clear () throw() - { - try - { - IdHashtable::iterator i = table.begin(); - IdHashtable::iterator e = table.end(); - for ( ; i!=e ; ++i ) - i->second->dependants.clear(); - - table.clear(); - } - catch (lumiera::Error& EX) - { - WARN (progress, "Problems while clearing Asset registry: %s", EX.what()); - } - catch (...) - { - ERROR (progress, "Serious trouble while clearing Asset registry."); - } } + clear () + try + { + IdHashtable::iterator i = table.begin(); + IdHashtable::iterator e = table.end(); + for ( ; i!=e ; ++i ) + i->second->dependants.clear(); + + table.clear(); + } + ERROR_LOG_AND_IGNORE (progress, "cleaning the Asset registry") /** intended for diagnostics */ @@ -154,6 +167,7 @@ namespace asset { output.push_back (i->second); } + private: const PAsset & find (size_t hash) const diff --git a/src/proc/assetmanager.cpp b/src/proc/assetmanager.cpp index 1b4fdb4e3..ad34e5794 100644 --- a/src/proc/assetmanager.cpp +++ b/src/proc/assetmanager.cpp @@ -210,6 +210,13 @@ namespace asset { } + void + AssetManager::clear() + { + INFO (progress, "Clearing the Asset registry..."); + registry.clear(); + } + list AssetManager::listContent() const diff --git a/src/proc/assetmanager.hpp b/src/proc/assetmanager.hpp index 2dc983f23..4ed24eb5b 100644 --- a/src/proc/assetmanager.hpp +++ b/src/proc/assetmanager.hpp @@ -94,10 +94,18 @@ namespace asset { /** @return true if the given id is registered with the given Category */ bool known (IDA id, const Category& cat) ; - /**remove the given asset from the internal DB. + /** remove the given asset from the internal DB. * together with all its dependents */ void remove (IDA id) ; + /** deregister and evict all known Assets. + * @note the actual object instances are managed by reference count, + * i.e. typically the Assets will be kept alive by MObjects from the sesison + * @warning unsure if this design is sane. Asset subsystem needs a rework ////////////////////////////TICKET #691 + * @todo verify this actually works, especially with session shutdown ////////////////////////////TICKET #154 + */ + void clear() ; + /** extract a sorted list of all registered Assets */ list listContent() const; diff --git a/src/proc/mobject/session/sess-manager-impl.cpp b/src/proc/mobject/session/sess-manager-impl.cpp index f467e523e..496244c57 100644 --- a/src/proc/mobject/session/sess-manager-impl.cpp +++ b/src/proc/mobject/session/sess-manager-impl.cpp @@ -175,7 +175,7 @@ namespace session { void deconfigure() { - TODO ("reset the assets registered with AssetManager"); + AssetManager::instance().clear(); /////////////////////////////////////////////////////////////////// TICKET #154 }