Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

osg::SharedObject Class Reference

#include <OSGSharedObjectHandler.h>

Inheritance diagram for osg::SharedObject:

osg::MemoryObject List of all members.

Public Types

enum  SharedObjectType { Invalid = 0x0000, Application = 0x0001, SharedLibrary = 0x0002 }

Public Member Functions

bool open (void)
AnonSymbolHandle getSymbol (const Char8 *szSymbolName)
bool isOpen (void)
bool reOpen (void)
const std::string & getName (void)
const Char8getCName (void)
void dump (void)
Reference Counting
*void addRef (void)
void subRef (void)
Int32 getRefCount (void)

Protected Member Functions

 SharedObject (const Char8 *szName)
virtual ~SharedObject (void)
bool close (void)

Protected Attributes

std::string _szName
SharedHandle _pHandle
SharedObjectType _type

Static Protected Attributes

static Char8 _szApplicationObjectName [] = "Application"

Private Types

typedef MemoryObject Inherited

Private Member Functions

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

Friends

class SharedObjectHandler

Detailed Description

Definition at line 97 of file OSGSharedObjectHandler.h.


Member Typedef Documentation

typedef MemoryObject osg::SharedObject::Inherited [private]
 

Definition at line 130 of file OSGSharedObjectHandler.h.


Member Enumeration Documentation

enum osg::SharedObject::SharedObjectType
 

Enumerator:
Invalid 
Application 
SharedLibrary 

Definition at line 109 of file OSGSharedObjectHandler.h.

00110     {
00111         Invalid       = 0x0000,
00112         Application   = 0x0001,
00113         SharedLibrary = 0x0002
00114     };


Constructor & Destructor Documentation

osg::SharedObject::SharedObject const SharedObject source  )  [private]
 

SharedObject::SharedObject const Char8 szName  )  [protected]
 

Definition at line 109 of file OSGSharedObjectHandler.cpp.

References _szApplicationObjectName, _szName, _type, Application, and FINFO.

00109                                               :
00110      Inherited(       ),
00111     _szName   (       ),
00112     _pHandle  (NULL   ),
00113     _type     (Invalid)
00114 {
00115     if(szName == NULL)
00116     {
00117         _szName.assign(_szApplicationObjectName);
00118 
00119         _type = Application;
00120     }
00121     else
00122     {
00123         _szName.assign(szName);
00124 
00125         _type = SharedLibrary;
00126     }    
00127     
00128     FINFO(("construct SharedObject %s\n", _szName.c_str()));
00129 }

SharedObject::~SharedObject void   )  [protected, virtual]
 

Definition at line 131 of file OSGSharedObjectHandler.cpp.

References _szName, and FINFO.

00132 {
00133     FINFO(("destroy SharedObject %s\n", _szName.c_str()));
00134 }


Member Function Documentation

void osg::SharedObject::operator= const SharedObject source  )  [private]
 

bool SharedObject::close void   )  [protected]
 

Definition at line 136 of file OSGSharedObjectHandler.cpp.

References _pHandle.

Referenced by reOpen().

00137 {
00138     bool returnValue = false;
00139 
00140     if(_pHandle != NULL)
00141     {
00142 #ifndef WIN32
00143         returnValue = (dlclose(_pHandle) == 0);
00144 #else
00145         returnValue = FreeLibrary(_pHandle);
00146 #endif
00147         _pHandle    = NULL;
00148     }
00149 
00150     return returnValue;
00151 }

bool SharedObject::open void   ) 
 

Definition at line 159 of file OSGSharedObjectHandler.cpp.

References _pHandle, _szName, _type, and FWARNING.

Referenced by osg::SharedObjectHandler::getSharedObject(), getSymbol(), and reOpen().

00160 {
00161     const Char8 *libName = NULL;
00162 
00163     if(_pHandle != NULL)
00164     {
00165         return true;
00166     }
00167 
00168     if(_type == SharedLibrary)
00169     {
00170         libName = _szName.c_str();
00171     }
00172     
00173 #ifndef WIN32
00174 #ifdef OSG_DLOPEN_LAZY
00175     _pHandle = dlopen(libName, RTLD_LAZY);
00176 #else
00177     _pHandle = dlopen(libName, RTLD_NOW);
00178 #endif
00179 
00180     if(_pHandle == NULL)
00181     {
00182         FWARNING(("Could not open shared object : %s\n", dlerror()));
00183     }
00184 #else
00185 
00186     if(libName == NULL)
00187     {
00188         Char8 szModuleName[1024];
00189 
00190         GetModuleFileName(NULL, szModuleName, 1024);
00191 
00192         _pHandle = LoadLibrary(szModuleName);
00193     }
00194     else
00195     {
00196         _pHandle = LoadLibrary(libName);
00197     }
00198 #endif
00199 
00200     return (_pHandle != NULL);
00201 }

AnonSymbolHandle SharedObject::getSymbol const Char8 szSymbolName  ) 
 

Definition at line 203 of file OSGSharedObjectHandler.cpp.

References _pHandle, FWARNING, isOpen(), and open().

00204 {
00205     AnonSymbolHandle returnValue = NULL;
00206 
00207     if(isOpen() == false)
00208     {
00209         if(open() == false)
00210         {
00211             return returnValue;
00212         }
00213     }
00214 
00215     if(_pHandle != NULL && szSymbolName != NULL)
00216     {
00217 #ifndef WIN32
00218         returnValue = dlsym(_pHandle, szSymbolName);
00219 #else
00220         returnValue = GetProcAddress(_pHandle, szSymbolName);
00221 #endif
00222     }
00223 
00224 #ifndef WIN32
00225     if(returnValue == NULL)
00226     {
00227         FWARNING(("could not get symbol %s : %s\n", szSymbolName, dlerror()));
00228     }
00229 #else
00230 #endif
00231 
00232     return returnValue;
00233 }

bool SharedObject::isOpen void   ) 
 

Definition at line 235 of file OSGSharedObjectHandler.cpp.

References _pHandle.

Referenced by getSymbol().

00236 {
00237     return _pHandle != NULL;
00238 }

bool SharedObject::reOpen void   ) 
 

Definition at line 240 of file OSGSharedObjectHandler.cpp.

References close(), and open().

00241 {
00242     close();
00243     
00244     return open();
00245 }

const std::string & SharedObject::getName void   ) 
 

Definition at line 247 of file OSGSharedObjectHandler.cpp.

References _szName.

Referenced by osg::SharedObjectHandler::getSharedObject().

00248 {
00249     return _szName;
00250 }

const Char8 * SharedObject::getCName void   ) 
 

Definition at line 252 of file OSGSharedObjectHandler.cpp.

References _szName.

Referenced by osg::SharedObjectHandler::removeSharedObject().

00253 {
00254     return _szName.c_str();
00255 }

void SharedObject::dump void   ) 
 

Definition at line 257 of file OSGSharedObjectHandler.cpp.

References _pHandle, _szName, and FINFO.

00258 {
00259     FINFO(("\tObject %s | %p\n", _szName.c_str(), _pHandle));
00260 }

void MemoryObject::addRef void   )  [inherited]
 

Definition at line 64 of file OSGMemoryObject.cpp.

References osg::MemoryObject::_refCount.

Referenced by osg::SharedObjectHandler::getSharedObject(), and osg::SharedObjectHandler::initialize().

00065 {
00066     _refCount++;
00067 }

void MemoryObject::subRef void   )  [inherited]
 

Definition at line 69 of file OSGMemoryObject.cpp.

References osg::MemoryObject::_refCount.

00070 {
00071     _refCount--;
00072 
00073     if(_refCount <= 0)
00074         delete this;
00075 }

Int32 MemoryObject::getRefCount void   )  [inherited]
 

Definition at line 77 of file OSGMemoryObject.cpp.

References osg::MemoryObject::_refCount.

00078 {
00079     return _refCount;
00080 }


Friends And Related Function Documentation

friend class SharedObjectHandler [friend]
 

Definition at line 136 of file OSGSharedObjectHandler.h.


Member Data Documentation

Char8 SharedObject::_szApplicationObjectName = "Application" [static, protected]
 

Definition at line 77 of file OSGSharedObjectHandler.cpp.

Referenced by osg::SharedObjectHandler::findSharedObject(), osg::SharedObjectHandler::removeSharedObject(), and SharedObject().

std::string osg::SharedObject::_szName [protected]
 

Definition at line 187 of file OSGSharedObjectHandler.h.

Referenced by dump(), getCName(), getName(), open(), SharedObject(), and ~SharedObject().

SharedHandle osg::SharedObject::_pHandle [protected]
 

Definition at line 188 of file OSGSharedObjectHandler.h.

Referenced by close(), dump(), getSymbol(), isOpen(), and open().

SharedObjectType osg::SharedObject::_type [protected]
 

Definition at line 190 of file OSGSharedObjectHandler.h.

Referenced by open(), and SharedObject().


The documentation for this class was generated from the following files:
Generated on Thu Aug 25 04:12:36 2005 for OpenSG by  doxygen 1.4.3