]> Creatis software - cpPlugins.git/blob - lib/cpPlugins/OS/DLLManager.cxx
yet another refactoring
[cpPlugins.git] / lib / cpPlugins / OS / DLLManager.cxx
1 #include <cpPlugins/OS/DLLManager.h>
2 #ifdef cpExtensions_OS_Windows
3 #else // cpExtensions_OS_Windows
4 #  include <dlfcn.h>
5 #endif // cpExtensions_OS_Windows
6
7 // -------------------------------------------------------------------------
8 void* cpPlugins::OS::DLLManager::
9 Open( const std::string& filename )
10 {
11   void* hnd = NULL;
12 #ifdef cpExtensions_OS_Windows
13 #else // cpExtensions_OS_Windows
14   hnd = dlopen( filename.c_str( ), RTLD_NOW | RTLD_GLOBAL );
15   char* error = dlerror( );
16   if( error != NULL )
17     throw std::runtime_error( error );
18 #endif // cpExtensions_OS_Windows
19   return( hnd );
20 }
21
22 // -------------------------------------------------------------------------
23 void cpPlugins::OS::DLLManager::
24 Close( void* hnd )
25 {
26 #ifdef cpExtensions_OS_Windows
27 #else // cpExtensions_OS_Windows
28   /* TODO: why this clashes with VTK? -> Unregistering of factories.
29      dlclose( hnd );
30      dlerror( );
31   */
32 #endif // cpExtensions_OS_Windows
33 }
34
35 // -------------------------------------------------------------------------
36 void* cpPlugins::OS::DLLManager::
37 Sym( void* hnd, const std::string& symbol )
38 {
39   void* sym = NULL;
40 #ifdef cpExtensions_OS_Windows
41 #else // cpExtensions_OS_Windows
42   sym = dlsym( hnd, symbol.c_str( ) );
43   char* error = dlerror( );
44   if( error != NULL )
45     throw std::runtime_error( error );
46 #endif // cpExtensions_OS_Windows
47   return( sym );
48 }
49
50 // eof - $RCSfile$