From Michael Gronager, with updates from Robert Osfield, to add support
for Registry::closeAllLibrary and forced Registry destruction via Registry::instance(true).
This commit is contained in:
parent
1025643170
commit
0cbe10d399
@ -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<ReaderWriter> > ReaderWriterList;
|
||||
typedef std::vector< osg::ref_ptr<ReaderWriter> > ReaderWriterList;
|
||||
|
||||
protected:
|
||||
protected:
|
||||
|
||||
virtual ~Registry();
|
||||
|
||||
|
@ -41,12 +41,14 @@ DynamicLibrary::DynamicLibrary(const std::string& name,HANDLE handle)
|
||||
{
|
||||
_name = name;
|
||||
_handle = handle;
|
||||
osg::notify(osg::INFO)<<"Opened DynamicLibrary "<<_name<<std::endl;
|
||||
}
|
||||
|
||||
DynamicLibrary::~DynamicLibrary()
|
||||
{
|
||||
if (_handle)
|
||||
{
|
||||
osg::notify(osg::INFO)<<"Closing DynamicLibrary "<<_name<<std::endl;
|
||||
#if defined(WIN32) && !defined(__CYGWIN__)
|
||||
FreeLibrary((HMODULE)_handle);
|
||||
#elif defined(__DARWIN_OSX__)
|
||||
|
@ -116,10 +116,15 @@ void PrintFilePathList(std::ostream& stream,const FilePathList& filepath)
|
||||
}
|
||||
}
|
||||
|
||||
Registry* Registry::instance()
|
||||
Registry* Registry::instance(bool erase)
|
||||
{
|
||||
static ref_ptr<Registry> 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("<<wrapper->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("<<rw->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)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user