osg::SharedObjectHandler Class Reference

#include <OSGSharedObjectHandler.h>

List of all members.

Public Types

typedef std::map< std::string,
SharedObjectP
SharedObjectMap
typedef SharedObjectMap::iterator SharedObjectMapIt
typedef
SharedObjectMap::const_iterator 
SharedObjectMapConstIt
typedef std::vector< std::string > NameStore
typedef std::vector
< std::string >::iterator 
NameStoreIt
typedef std::vector
< std::string >
::const_iterator 
NameStoreConstIt

Public Member Functions

SharedObjectP getSharedObject (const Char8 *szName)
SharedObjectP getOSGSharedObject (const Char8 *szName)
SharedObjectP findSharedObject (const Char8 *szName) const
void removeSharedObject (const Char8 *szName)
void removeSharedObject (SharedObjectP pObject)
void registerLoadedObject (const Char8 *szName)
void dump (void)

Static Public Member Functions

static SharedObjectHandlerP the (void)

Protected Member Functions

 SharedObjectHandler (void)
virtual ~SharedObjectHandler (void)
bool initialize (void)
void terminate (void)

Protected Attributes

SharedObjectMap _mSharedObjects
NameStore _vLoadedNames

Static Protected Attributes

static SharedObjectHandlerP _the = NULL

Private Member Functions

 SharedObjectHandler (const SharedObjectHandler &source)
void operator= (const SharedObjectHandler &source)

Friends

bool osgInit (Int32 argc, Char8 **argv, UInt16 major, UInt16 minor, UInt16 release, bool debug, bool dll, bool mt)
bool osgExit (void)


Detailed Description

Definition at line 248 of file OSGSharedObjectHandler.h.


Member Typedef Documentation

Definition at line 264 of file OSGSharedObjectHandler.h.

typedef SharedObjectMap::iterator osg::SharedObjectHandler::SharedObjectMapIt

Definition at line 266 of file OSGSharedObjectHandler.h.

typedef SharedObjectMap::const_iterator osg::SharedObjectHandler::SharedObjectMapConstIt

Definition at line 268 of file OSGSharedObjectHandler.h.

typedef std::vector<std::string> osg::SharedObjectHandler::NameStore

Definition at line 271 of file OSGSharedObjectHandler.h.

typedef std::vector<std::string>::iterator osg::SharedObjectHandler::NameStoreIt

Definition at line 272 of file OSGSharedObjectHandler.h.

typedef std::vector<std::string>::const_iterator osg::SharedObjectHandler::NameStoreConstIt

Definition at line 273 of file OSGSharedObjectHandler.h.


Constructor & Destructor Documentation

osg::SharedObjectHandler::SharedObjectHandler ( const SharedObjectHandler source  )  [private]

SharedObjectHandler::SharedObjectHandler ( void   )  [protected]

Definition at line 328 of file OSGSharedObjectHandler.cpp.

References FINFO.

00328                                              :
00329     _mSharedObjects(),
00330     _vLoadedNames  ()
00331 {
00332     FINFO(("create SharedObjectHandler\n"));
00333 }

SharedObjectHandler::~SharedObjectHandler ( void   )  [protected, virtual]

Definition at line 335 of file OSGSharedObjectHandler.cpp.

References FINFO.

00336 {
00337     FINFO(("destroy SharedObjectHandler\n"));
00338 }


Member Function Documentation

void osg::SharedObjectHandler::operator= ( const SharedObjectHandler source  )  [private]

bool SharedObjectHandler::initialize ( void   )  [protected]

Definition at line 492 of file OSGSharedObjectHandler.cpp.

References _mSharedObjects, _vLoadedNames, osg::MemoryObject::addRef(), FINFO, and getSharedObject().

Referenced by osg::osgInit().

00493 {
00494     SharedObjectP pAppHandle = getSharedObject(NULL);
00495 
00496     for(UInt32 i = 0; i < _vLoadedNames.size(); ++i)
00497     {
00498         FINFO(("Preloaded %s %p\n", _vLoadedNames[i].c_str(), pAppHandle));
00499 
00500         _mSharedObjects[_vLoadedNames[i]] = pAppHandle;
00501         pAppHandle->addRef();
00502     }
00503 
00504     _vLoadedNames.clear();
00505 
00506     return true;
00507 }

void SharedObjectHandler::terminate ( void   )  [protected]

Definition at line 340 of file OSGSharedObjectHandler.cpp.

References _mSharedObjects, _the, dump(), and FINFO.

Referenced by osg::osgExit().

00341 {
00342     FINFO(("terminate SharedObjectHandler\n"));
00343 
00344     this->dump();
00345 
00346     SharedObjectMapIt soIt  = _mSharedObjects.begin();
00347     SharedObjectMapIt soEnd = _mSharedObjects.end  ();
00348 
00349     while(soIt != soEnd)
00350     {
00351         soIt->second->close();
00352 
00353         soIt->second->subRef();
00354 
00355         ++soIt;
00356     }
00357 
00358     _the = NULL;
00359     delete this;
00360 }

SharedObjectHandlerP SharedObjectHandler::the ( void   )  [static]

Definition at line 304 of file OSGSharedObjectHandler.cpp.

References _the.

Referenced by osg::osgExit(), and osg::osgInit().

00305 {
00306     if(_the == NULL)
00307     {
00308         _the = new SharedObjectHandler;
00309     }
00310 
00311     return _the;
00312 }

SharedObjectP SharedObjectHandler::getSharedObject ( const Char8 szName  ) 

Definition at line 368 of file OSGSharedObjectHandler.cpp.

References _mSharedObjects, _vLoadedNames, osg::MemoryObject::addRef(), findSharedObject(), FINFO, osg::SharedObject::getName(), osg::GlobalSystemState, osg::SharedObject::open(), and osg::Running.

Referenced by getOSGSharedObject(), initialize(), and osg::osgInit().

00370 {
00371     SharedObjectP returnValue = NULL;
00372 
00373     returnValue = findSharedObject(szName);
00374 
00375     if(returnValue == NULL)
00376     {
00377         returnValue = new SharedObject(szName);
00378 
00379         returnValue->open  ();
00380         returnValue->addRef();
00381 
00382         _mSharedObjects[returnValue->getName()] = returnValue;
00383 
00384         if(GlobalSystemState == Running)
00385         {
00386 //            FactoryController::the()->initializePendingElements();
00387         }
00388     }
00389 
00390 #if 0
00391     for(UInt32 i = 0; i < _vLoadedNames.size(); ++i)
00392     {
00393         FINFO(("Pulled in %s\n", _vLoadedNames[i].c_str()));
00394     }
00395 #endif
00396 
00397     _vLoadedNames.clear();
00398 
00399     return returnValue;
00400 }

SharedObjectP SharedObjectHandler::getOSGSharedObject ( const Char8 szName  ) 

Definition at line 402 of file OSGSharedObjectHandler.cpp.

References getSharedObject().

Referenced by osg::osgInit().

00404 {
00405     SharedObjectP returnValue = NULL;
00406 
00407     std::string tmpString; 
00408 
00409 #ifndef WIN32    
00410     tmpString.append("lib");
00411     tmpString.append(szName);
00412     tmpString.append(".so");
00413 #else
00414     tmpString.append(szName);
00415     tmpString.append(".dll");
00416 #endif
00417 
00418     returnValue = getSharedObject(tmpString.c_str());
00419 
00420     return returnValue;
00421 }

SharedObjectP SharedObjectHandler::findSharedObject ( const Char8 szName  )  const

Definition at line 423 of file OSGSharedObjectHandler.cpp.

References _mSharedObjects, and osg::SharedObject::_szApplicationObjectName.

Referenced by getSharedObject().

00425 {
00426     SharedObjectMapConstIt  mapIt;
00427     SharedObjectP           returnValue  = NULL;
00428     std::string             szSearchName;
00429 
00430     if(szName != NULL)
00431     {
00432         szSearchName.assign(szName);
00433     }
00434     else
00435     {
00436         szSearchName.assign(SharedObject::_szApplicationObjectName);
00437     }
00438 
00439     mapIt = _mSharedObjects.find(szSearchName);
00440 
00441     if(mapIt != _mSharedObjects.end())
00442     {
00443         returnValue = mapIt->second;
00444     }
00445     
00446     return returnValue;
00447 }

void SharedObjectHandler::removeSharedObject ( const Char8 szName  ) 

Definition at line 449 of file OSGSharedObjectHandler.cpp.

References _mSharedObjects, and osg::SharedObject::_szApplicationObjectName.

Referenced by removeSharedObject().

00450 {
00451     SharedObjectMapIt  mapIt;
00452     std::string        szSearchName;
00453 
00454     if(szName != NULL)
00455     {
00456         szSearchName.assign(szName);
00457     }
00458     else
00459     {
00460         szSearchName.assign(SharedObject::_szApplicationObjectName);
00461     }
00462 
00463     mapIt = _mSharedObjects.find(szSearchName);
00464 
00465     _mSharedObjects.erase(mapIt);
00466 }

void SharedObjectHandler::removeSharedObject ( SharedObjectP  pObject  ) 

Definition at line 468 of file OSGSharedObjectHandler.cpp.

References osg::SharedObject::getCName(), and removeSharedObject().

00469 {
00470     if(pObject != NULL)
00471     {
00472         removeSharedObject(pObject->getCName());
00473     }
00474 }

void SharedObjectHandler::registerLoadedObject ( const Char8 szName  ) 

Definition at line 476 of file OSGSharedObjectHandler.cpp.

References _vLoadedNames.

00477 {
00478     std::string tmpString;
00479 
00480 #ifndef WIN32    
00481     tmpString.append("lib");
00482     tmpString.append(szName);
00483     tmpString.append(".so");
00484 #else
00485     tmpString.append(szName);
00486     tmpString.append(".dll");
00487 #endif
00488 
00489     _vLoadedNames.push_back(tmpString);
00490 }

void SharedObjectHandler::dump ( void   ) 

Definition at line 509 of file OSGSharedObjectHandler.cpp.

References _mSharedObjects, and FINFO.

Referenced by osg::osgInit(), and terminate().

00510 {
00511     SharedObjectMapIt soIt  = _mSharedObjects.begin();
00512     SharedObjectMapIt soEnd = _mSharedObjects.end  ();
00513 
00514     while(soIt != soEnd)
00515     {
00516         FINFO(("SO : %s | %p\n", soIt->first.c_str(), soIt->second));
00517 
00518         soIt->second->dump();
00519         ++soIt;
00520     }
00521 }


Friends And Related Function Documentation

bool osgInit ( Int32  argc,
Char8 **  argv,
UInt16  major,
UInt16  minor,
UInt16  release,
bool  debug,
bool  dll,
bool  mt 
) [friend]

Definition at line 303 of file OSGBaseFunctions.cpp.

00306 {
00307     CompileConfig prog(major, minor, release, debug, dll, mt),
00308     lib(OSG_MAJOR_VERSION, OSG_MINOR_VERSION, 
00309                       OSG_RELEASE_VERSION,
00310 #ifdef _DEBUG  
00311     true,
00312 #else
00313     false,
00314 #endif
00315 #ifdef _DLL  
00316     true,
00317 #else
00318     false,
00319 #endif
00320 #ifdef _MT  
00321     true
00322 #else
00323     false
00324 #endif
00325     );
00326     
00327     if(lib.compare(prog))
00328     {
00329         exit(1);
00330     }
00331 
00332     // without it floats could be written as "1,456" ...
00333     setlocale(LC_NUMERIC, "English");
00334     
00335     UInt32 i;
00336     bool   returnValue = true;
00337 
00338     returnValue = SharedObjectHandler::the()->initialize();
00339 
00340     if(osgPreloadSharedObject != NULL)
00341     {
00342         for(UInt32 i = 0; i < osgPreloadSharedObject->size(); ++i)
00343         {
00344             SharedObjectHandler::the()->getOSGSharedObject(
00345                 (*osgPreloadSharedObject)[i].c_str());
00346         }
00347     }
00348 
00349 #ifdef WIN32
00350     std::string pathSep(";");
00351 #else
00352     std::string pathSep(":");
00353 #endif
00354 
00355     char *szEnvLibs = getenv("OSG_LOAD_LIBS");
00356 
00357     if(szEnvLibs != NULL)
00358     {
00359         std::string tmpString(szEnvLibs);
00360         string_token_iterator libIt(tmpString, pathSep.c_str());
00361 
00362         string_token_iterator libEnd;
00363 
00364         while(libIt != libEnd)
00365         {
00366             SharedObjectHandler::the()->getOSGSharedObject(
00367                 (*libIt).c_str());
00368 
00369             ++libIt;
00370         }
00371     }
00372 
00373     const char *szEnvPlugins       = getenv("OSG_PLUGIN_PATH");
00374     const char *szEnvPluginPattern = getenv("OSG_PLUGIN_PATTERN");
00375 
00376     if(szEnvPlugins != NULL)
00377     {
00378         if(szEnvPluginPattern == NULL)
00379         {
00380             szEnvPluginPattern = PluginPattern;
00381         }
00382 
00383         FINFO(("Get Plugins %s from %s\n", 
00384                szEnvPluginPattern,
00385                szEnvPlugins));
00386 
00387         std::vector<Char8 *> *pPlugins = 
00388             Directory::getEntries(szEnvPlugins, szEnvPluginPattern);
00389 
00390         if(pPlugins != NULL)
00391         {
00392             std::string szPluginName;
00393 
00394             for(UInt32 i = 0; i < pPlugins->size(); ++i)
00395             {
00396                 if((*pPlugins)[i][0] == '.')
00397                 {
00398                     if((*pPlugins)[i][1] == '\0')
00399                     {
00400                         continue;
00401                     }
00402                     else if((*pPlugins)[i][1] == '.' &&
00403                             (*pPlugins)[i][2] == '\0')
00404                     {
00405                         continue;
00406                     }
00407                 }
00408 
00409                 szPluginName.assign(szEnvPlugins);
00410                 szPluginName += '/';
00411                 szPluginName += (*pPlugins)[i];
00412 
00413                 FINFO(("Loading plugin %s\n", 
00414                        szPluginName.c_str()));
00415 
00416                 SharedObjectHandler::the()->getSharedObject(
00417                     szPluginName.c_str());
00418             }
00419         }
00420 
00421         delete pPlugins;
00422     }
00423 
00424     SharedObjectHandler::the()->dump();
00425 
00426     if(returnValue == false)
00427         return returnValue;
00428 
00429     if(osgPreMPInitFunctions != NULL)
00430     {
00431         for(i = 0; i < osgPreMPInitFunctions->size(); i++)
00432         {
00433             returnValue &= (*osgPreMPInitFunctions)[i]();
00434             
00435             if(returnValue == false)
00436                 break;         
00437         }
00438     
00439         osgPreMPInitFunctions->clear();
00440     }
00441         
00442     if(returnValue == false)
00443         return returnValue;
00444 
00445     returnValue &= ThreadManager::initialize();
00446 
00447     if(returnValue == false)
00448         return returnValue;
00449 
00450     if(osgInitFunctions != NULL)
00451     {
00452         for(i = 0; i < osgInitFunctions->size(); i++)
00453         {
00454             returnValue &= (*osgInitFunctions)[i]();
00455             
00456             if(returnValue == false)
00457                 break;         
00458         }
00459 
00460         osgInitFunctions->clear();
00461     }
00462     
00463     if(returnValue == false)
00464         return returnValue;
00465 
00466 #ifdef OSG_GV_BETA
00467     returnValue &= FactoryController::the()->initialize();
00468 #endif
00469 
00470     GlobalSystemState = Running;
00471 
00472     atexit(osgExitWrapper);
00473     
00474     return returnValue;
00475 }

bool osgExit ( void   )  [friend]

Definition at line 480 of file OSGBaseFunctions.cpp.

00481 {
00482     bool returnValue = true;
00483 
00484     if(GlobalSystemState != Running)
00485         return true;
00486         
00487     GlobalSystemState = Shutdown;
00488 
00489 #ifdef OSG_GV_BETA
00490     returnValue &= FactoryController::the()->terminate();
00491 #endif
00492     SharedObjectHandler::the()->terminate();
00493     
00494     if(osgSystemExitFunctions != NULL)
00495     {
00496         for(Int32 i = osgSystemExitFunctions->size() - 1; i >= 0; i--)
00497         {
00498             returnValue &= (*osgSystemExitFunctions)[i]();
00499             
00500             if(returnValue == false)
00501                 break;         
00502         }
00503     }
00504 
00505     returnValue &= ThreadManager::terminate();
00506 
00507     if(osgPostMPExitFunctions != NULL)
00508     {
00509         for(Int32 i = osgPostMPExitFunctions->size() - 1; i >= 0; i--)
00510         {
00511             returnValue &= (*osgPostMPExitFunctions)[i]();
00512             
00513             if(returnValue == false)
00514                 break;         
00515         }
00516     }
00517 
00518     return returnValue;
00519 }


Member Data Documentation

SharedObjectHandlerP SharedObjectHandler::_the = NULL [static, protected]

Definition at line 336 of file OSGSharedObjectHandler.h.

Referenced by terminate(), and the().

Definition at line 348 of file OSGSharedObjectHandler.h.

Referenced by getSharedObject(), initialize(), and registerLoadedObject().


The documentation for this class was generated from the following files:

Generated on Mon Mar 17 11:10:50 2008 for OpenSG by  doxygen 1.5.5