]> Creatis software - cpPlugins.git/blobdiff - lib/cpPlugins/OS/DLLManager.cxx
yet another refactoring
[cpPlugins.git] / lib / cpPlugins / OS / DLLManager.cxx
diff --git a/lib/cpPlugins/OS/DLLManager.cxx b/lib/cpPlugins/OS/DLLManager.cxx
new file mode 100644 (file)
index 0000000..ba13b36
--- /dev/null
@@ -0,0 +1,50 @@
+#include <cpPlugins/OS/DLLManager.h>
+#ifdef cpExtensions_OS_Windows
+#else // cpExtensions_OS_Windows
+#  include <dlfcn.h>
+#endif // cpExtensions_OS_Windows
+
+// -------------------------------------------------------------------------
+void* cpPlugins::OS::DLLManager::
+Open( const std::string& filename )
+{
+  void* hnd = NULL;
+#ifdef cpExtensions_OS_Windows
+#else // cpExtensions_OS_Windows
+  hnd = dlopen( filename.c_str( ), RTLD_NOW | RTLD_GLOBAL );
+  char* error = dlerror( );
+  if( error != NULL )
+    throw std::runtime_error( error );
+#endif // cpExtensions_OS_Windows
+  return( hnd );
+}
+
+// -------------------------------------------------------------------------
+void cpPlugins::OS::DLLManager::
+Close( void* hnd )
+{
+#ifdef cpExtensions_OS_Windows
+#else // cpExtensions_OS_Windows
+  /* TODO: why this clashes with VTK? -> Unregistering of factories.
+     dlclose( hnd );
+     dlerror( );
+  */
+#endif // cpExtensions_OS_Windows
+}
+
+// -------------------------------------------------------------------------
+void* cpPlugins::OS::DLLManager::
+Sym( void* hnd, const std::string& symbol )
+{
+  void* sym = NULL;
+#ifdef cpExtensions_OS_Windows
+#else // cpExtensions_OS_Windows
+  sym = dlsym( hnd, symbol.c_str( ) );
+  char* error = dlerror( );
+  if( error != NULL )
+    throw std::runtime_error( error );
+#endif // cpExtensions_OS_Windows
+  return( sym );
+}
+
+// eof - $RCSfile$