From 0cbe10d3991041eabe763ef997f556daec7cb7b0 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Sat, 13 Dec 2003 16:36:29 +0000 Subject: [PATCH] From Michael Gronager, with updates from Robert Osfield, to add support for Registry::closeAllLibrary and forced Registry destruction via Registry::instance(true). --- include/osgDB/Registry | 8 +++++--- src/osgDB/DynamicLibrary.cpp | 2 ++ src/osgDB/Registry.cpp | 18 ++++++++++++------ 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/include/osgDB/Registry b/include/osgDB/Registry index 21b092966..1fe5d411a 100644 --- a/include/osgDB/Registry +++ b/include/osgDB/Registry @@ -67,7 +67,7 @@ class OSGDB_EXPORT Registry : public osg::Referenced { public: - static Registry* instance(); + static Registry* instance(bool erase = false); /** read the command line arguments.*/ void readCommandLine(osg::ArgumentParser& commandLine); @@ -98,6 +98,8 @@ class OSGDB_EXPORT Registry : public osg::Referenced bool loadLibrary(const std::string& fileName); /** close the attached library with specified name.*/ bool closeLibrary(const std::string& fileName); + /** close all libraries.*/ + void closeAllLibraries(); /** get a reader writer which handles specified extension.*/ ReaderWriter* getReaderWriterForExtension(const std::string& ext); @@ -206,9 +208,9 @@ class OSGDB_EXPORT Registry : public osg::Referenced /** get the attached library with specified name.*/ DynamicLibrary* getLibrary(const std::string& fileName); - typedef std::vector< osg::ref_ptr > ReaderWriterList; + typedef std::vector< osg::ref_ptr > ReaderWriterList; - protected: + protected: virtual ~Registry(); diff --git a/src/osgDB/DynamicLibrary.cpp b/src/osgDB/DynamicLibrary.cpp index 818164816..bf4c0a6aa 100644 --- a/src/osgDB/DynamicLibrary.cpp +++ b/src/osgDB/DynamicLibrary.cpp @@ -41,12 +41,14 @@ DynamicLibrary::DynamicLibrary(const std::string& name,HANDLE handle) { _name = name; _handle = handle; + osg::notify(osg::INFO)<<"Opened DynamicLibrary "<<_name< s_nodeFactory = new Registry; - return s_nodeFactory.get(); + if (erase) + { + s_nodeFactory->closeAllLibraries(); + s_nodeFactory = 0; + } + return s_nodeFactory.get(); // will return NULL on erase } @@ -192,6 +197,7 @@ Registry::Registry() Registry::~Registry() { + closeAllLibraries(); } #ifndef WIN32 @@ -354,8 +360,6 @@ void Registry::addDotOsgWrapper(DotOsgWrapper* wrapper) { if (wrapper==0L) return; - if (_openingLibrary) notify(INFO) << "Opening Library : "<< std::endl; - //notify(INFO) << "osg::Registry::addDotOsgWrapper("<getName()<<")"<< std::endl; const DotOsgWrapper::Associates& assoc = wrapper->getAssociates(); @@ -442,8 +446,6 @@ void Registry::addReaderWriter(ReaderWriter* rw) { if (rw==0L) return; - // if (_openingLibrary) notify(INFO) << "Opening Library : "<< std::endl; - // notify(INFO) << "osg::Registry::addReaderWriter("<className()<<")"<< std::endl; _rwList.push_back(rw); @@ -563,6 +565,10 @@ bool Registry::closeLibrary(const std::string& fileName) return false; } +void Registry::closeAllLibraries() +{ + _dlList.clear(); +} Registry::DynamicLibraryList::iterator Registry::getLibraryItr(const std::string& fileName) {