dso.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "dso.h"
00020
00021 #include "debug.h"
00022 #include "log.h"
00023
00024 #ifdef WIN32
00025 # define EQ_DL_ERROR getErrorString( GetLastError( ))
00026 #else
00027 # include <dlfcn.h>
00028 # define EQ_DL_ERROR dlerror()
00029 #endif
00030
00031 namespace eq
00032 {
00033 namespace base
00034 {
00035
00036 bool DSO::open( const std::string& fileName )
00037 {
00038 if( _dso )
00039 {
00040 EQWARN << "DSO already open, close it first" << std::endl;
00041 return false;
00042 }
00043
00044 if( fileName.empty( ))
00045 {
00046 #ifdef WIN32
00047 _dso = GetModuleHandle( "Equalizer.dll" );
00048 EQASSERT( _dso );
00049 #else
00050 _dso = RTLD_DEFAULT;
00051 #endif
00052 }
00053 else
00054 {
00055 #ifdef WIN32
00056 _dso = LoadLibrary( fileName.c_str() );
00057 #else
00058 _dso = dlopen( fileName.c_str(), RTLD_LAZY | RTLD_LOCAL );
00059 #endif
00060 if( !_dso )
00061 {
00062 EQWARN << "Can't open library: " << EQ_DL_ERROR << std::endl;
00063 return false;
00064 }
00065 }
00066
00067 return true;
00068 }
00069
00070 void DSO::close()
00071 {
00072 if( !_dso )
00073 return;
00074
00075 #ifdef WIN32
00076 if( _dso != GetModuleHandle( 0 ))
00077 FreeLibrary( _dso ) ;
00078 #else
00079 if( _dso != RTLD_DEFAULT )
00080 dlclose ( _dso );
00081 #endif
00082
00083 _dso = 0;
00084 }
00085
00086 void* DSO::getFunctionPointer( const std::string& name )
00087 {
00088 #ifdef WIN32
00089 return GetProcAddress( _dso, name.c_str() );
00090 #else
00091 return dlsym( _dso, name.c_str() );
00092 #endif
00093 }
00094
00095 }
00096 }