Fixed automatic loading of plugins

This commit is contained in:
Robert Osfield
2010-02-10 16:23:27 +00:00
parent 4e44073e6b
commit f3ee7fa6ba
2 changed files with 73 additions and 59 deletions

View File

@@ -102,6 +102,9 @@ class OSGDB_EXPORT DeprecatedDotOsgWrapperManager : public osg::Referenced
bool writeObject(const osg::Object& obj,Output& fw); bool writeObject(const osg::Object& obj,Output& fw);
typedef std::list<std::string> FileNames;
bool getLibraryFileNamesToTry(const std::string& name, FileNames& fileNames);
private: private:
virtual ~DeprecatedDotOsgWrapperManager() {} virtual ~DeprecatedDotOsgWrapperManager() {}

View File

@@ -192,6 +192,22 @@ osg::Object* DeprecatedDotOsgWrapperManager::readObjectOfType(const osg::Object&
return readObjectOfType(concrete_wrapper(&compObj), fr); return readObjectOfType(concrete_wrapper(&compObj), fr);
} }
bool DeprecatedDotOsgWrapperManager::getLibraryFileNamesToTry(const std::string& name, FileNames& fileNames)
{
FileNames::size_type sizeBefore = fileNames.size();
std::string libraryName = osgDB::Registry::instance()->createLibraryNameForNodeKit(name);
if (!libraryName.empty()) fileNames.push_back(libraryName);
libraryName = osgDB::Registry::instance()->createLibraryNameForExtension(std::string("deprecated_")+name);
if (!libraryName.empty()) fileNames.push_back(libraryName);
libraryName = osgDB::Registry::instance()->createLibraryNameForExtension(name);
if (!libraryName.empty()) fileNames.push_back(libraryName);
return fileNames.size() != sizeBefore;
}
osg::Object* DeprecatedDotOsgWrapperManager::readObjectOfType(const basic_type_wrapper &btw,Input& fr) osg::Object* DeprecatedDotOsgWrapperManager::readObjectOfType(const basic_type_wrapper &btw,Input& fr)
{ {
const char *str = fr[0].getStr(); const char *str = fr[0].getStr();
@@ -226,17 +242,16 @@ osg::Object* DeprecatedDotOsgWrapperManager::readObjectOfType(const basic_type_w
// if we can recognize the objects. // if we can recognize the objects.
std::string libraryName = std::string(token,0,posDoubleColon); std::string libraryName = std::string(token,0,posDoubleColon);
// first try the standard nodekit library. FileNames fileNames;
std::string nodeKitLibraryName = osgDB::Registry::instance()->createLibraryNameForNodeKit(libraryName); if (getLibraryFileNamesToTry(libraryName, fileNames))
if (osgDB::Registry::instance()->loadLibrary(nodeKitLibraryName)==osgDB::Registry::LOADED) return readObjectOfType(btw,fr); {
for(FileNames::iterator itr = fileNames.begin();
// otherwise try the osgdb_ plugin library. itr != fileNames.end();
std::string pluginLibraryName = osgDB::Registry::instance()->createLibraryNameForExtension(std::string("deprecated_")+libraryName); ++itr)
if (osgDB::Registry::instance()->loadLibrary(pluginLibraryName)==osgDB::Registry::LOADED) return readObjectOfType(btw,fr); {
if (osgDB::Registry::instance()->loadLibrary(*itr)==osgDB::Registry::LOADED) return readObjectOfType(btw,fr);
// otherwise try the osgdb_ plugin library. }
pluginLibraryName = osgDB::Registry::instance()->createLibraryNameForExtension(libraryName); }
if (osgDB::Registry::instance()->loadLibrary(pluginLibraryName)==osgDB::Registry::LOADED) return readObjectOfType(btw,fr);
} }
} }
else if (fr[1].isOpenBracket()) else if (fr[1].isOpenBracket())
@@ -292,16 +307,14 @@ osg::Object* DeprecatedDotOsgWrapperManager::readObjectOfType(const basic_type_w
// if we can recognize the objects. // if we can recognize the objects.
std::string libraryName = std::string(token,0,posDoubleColon); std::string libraryName = std::string(token,0,posDoubleColon);
// first try the standard nodekit library. FileNames fileNames;
std::string nodeKitLibraryName = osgDB::Registry::instance()->createLibraryNameForNodeKit(libraryName); if (getLibraryFileNamesToTry(libraryName, fileNames))
if (osgDB::Registry::instance()->loadLibrary(nodeKitLibraryName)==osgDB::Registry::LOADED)
{ {
mitr = _objectWrapperMap.find(*aitr); for(FileNames::iterator itr = fileNames.begin();
if (mitr==_objectWrapperMap.end()) itr != fileNames.end() && mitr==_objectWrapperMap.end();
++itr)
{ {
// otherwise try the osgdb_ plugin library. if (osgDB::Registry::instance()->loadLibrary(*itr)==osgDB::Registry::LOADED)
std::string pluginLibraryName = osgDB::Registry::instance()->createLibraryNameForExtension(libraryName);
if (osgDB::Registry::instance()->loadLibrary(pluginLibraryName)==osgDB::Registry::LOADED)
{ {
mitr = _objectWrapperMap.find(*aitr); mitr = _objectWrapperMap.find(*aitr);
} }
@@ -352,13 +365,16 @@ osg::Object* DeprecatedDotOsgWrapperManager::readObject(DotOsgWrapperMap& dowMap
std::string libraryName = std::string(token,0,posDoubleColon); std::string libraryName = std::string(token,0,posDoubleColon);
// first try the standard nodekit library. FileNames fileNames;
std::string nodeKitLibraryName = osgDB::Registry::instance()->createLibraryNameForNodeKit(libraryName); if (getLibraryFileNamesToTry(libraryName, fileNames))
if (osgDB::Registry::instance()->loadLibrary(nodeKitLibraryName)==osgDB::Registry::LOADED) return readObject(dowMap,fr); {
for(FileNames::iterator itr = fileNames.begin();
// otherwise try the osgdb_ plugin library. itr != fileNames.end();
std::string pluginLibraryName = osgDB::Registry::instance()->createLibraryNameForExtension(libraryName); ++itr)
if (osgDB::Registry::instance()->loadLibrary(pluginLibraryName)==osgDB::Registry::LOADED) return readObject(dowMap,fr); {
if (osgDB::Registry::instance()->loadLibrary(*itr)==osgDB::Registry::LOADED) return readObject(dowMap,fr);
}
}
} }
} }
else if (fr[1].isOpenBracket()) else if (fr[1].isOpenBracket())
@@ -412,23 +428,19 @@ osg::Object* DeprecatedDotOsgWrapperManager::readObject(DotOsgWrapperMap& dowMap
std::string libraryName = std::string(token,0,posDoubleColon); std::string libraryName = std::string(token,0,posDoubleColon);
// first try the standard nodekit library. FileNames fileNames;
std::string nodeKitLibraryName = osgDB::Registry::instance()->createLibraryNameForNodeKit(libraryName); if (getLibraryFileNamesToTry(libraryName, fileNames))
if (osgDB::Registry::instance()->loadLibrary(nodeKitLibraryName)==osgDB::Registry::LOADED)
{ {
mitr = _objectWrapperMap.find(*aitr); for(FileNames::iterator itr = fileNames.begin();
} itr != fileNames.end() && mitr==_objectWrapperMap.end();
++itr)
if (mitr==_objectWrapperMap.end())
{
// otherwise try the osgdb_ plugin library.
std::string pluginLibraryName = osgDB::Registry::instance()->createLibraryNameForExtension(libraryName);
if (osgDB::Registry::instance()->loadLibrary(pluginLibraryName)==osgDB::Registry::LOADED)
{ {
mitr = _objectWrapperMap.find(*aitr); if (osgDB::Registry::instance()->loadLibrary(*itr)==osgDB::Registry::LOADED)
{
mitr = _objectWrapperMap.find(*aitr);
}
} }
} }
} }
} }
@@ -641,13 +653,16 @@ bool DeprecatedDotOsgWrapperManager::writeObject(const osg::Object& obj,Output&
if (itr==_classNameWrapperMap.end()) if (itr==_classNameWrapperMap.end())
{ {
// first try the standard nodekit library. FileNames fileNames;
std::string nodeKitLibraryName = osgDB::Registry::instance()->createLibraryNameForNodeKit(libraryName); if (getLibraryFileNamesToTry(libraryName, fileNames))
if (osgDB::Registry::instance()->loadLibrary(nodeKitLibraryName)==osgDB::Registry::LOADED) return writeObject(obj,fw); {
for(FileNames::iterator itr = fileNames.begin();
// otherwise try the osgdb_ plugin library. itr != fileNames.end();
std::string pluginLibraryName = osgDB::Registry::instance()->createLibraryNameForExtension(libraryName); ++itr)
if (osgDB::Registry::instance()->loadLibrary(pluginLibraryName)==osgDB::Registry::LOADED) return writeObject(obj,fw); {
if (osgDB::Registry::instance()->loadLibrary(*itr)==osgDB::Registry::LOADED) return writeObject(obj,fw);
}
}
// otherwise try simple class name // otherwise try simple class name
if (itr == _classNameWrapperMap.end()) if (itr == _classNameWrapperMap.end())
@@ -711,23 +726,19 @@ bool DeprecatedDotOsgWrapperManager::writeObject(const osg::Object& obj,Output&
std::string libraryName = std::string(token,0,posDoubleColon); std::string libraryName = std::string(token,0,posDoubleColon);
// first try the standard nodekit library. FileNames fileNames;
std::string nodeKitLibraryName = osgDB::Registry::instance()->createLibraryNameForNodeKit(libraryName); if (getLibraryFileNamesToTry(libraryName, fileNames))
if (osgDB::Registry::instance()->loadLibrary(nodeKitLibraryName)==osgDB::Registry::LOADED)
{ {
mitr = _objectWrapperMap.find(*aitr); for(FileNames::iterator itr = fileNames.begin();
} itr != fileNames.end() && mitr==_objectWrapperMap.end();
++itr)
if (mitr==_objectWrapperMap.end())
{
// otherwise try the osgdb_ plugin library.
std::string pluginLibraryName = osgDB::Registry::instance()->createLibraryNameForExtension(libraryName);
if (osgDB::Registry::instance()->loadLibrary(pluginLibraryName)==osgDB::Registry::LOADED)
{ {
mitr = _objectWrapperMap.find(*aitr); if (osgDB::Registry::instance()->loadLibrary(*itr)==osgDB::Registry::LOADED)
{
mitr = _objectWrapperMap.find(*aitr);
}
} }
} }
} }
} }
if (mitr!=_objectWrapperMap.end()) if (mitr!=_objectWrapperMap.end())