]> Creatis software - cpPlugins.git/blobdiff - lib/cpPlugins/Interface.cxx
...
[cpPlugins.git] / lib / cpPlugins / Interface.cxx
index 0ee1faf9911aea516acf2fbe49c3d57a7c744930..259288243d5a309e803115bddb6e50a98645b210 100644 (file)
@@ -1,6 +1,7 @@
 #include <cpPlugins/Interface.h>
 
 #ifdef cpPlugins_SYS_WINDOWS
+#  include <Windows.h>
 #else // cpPlugins_SYS_WINDOWS
 #  include <dlfcn.h>
 #endif // cpPlugins_SYS_WINDOWS
@@ -26,6 +27,45 @@ GetFilters( )
   return( this->m_Filters );
 }
 
+// -------------------------------------------------------------------------
+bool cpPlugins::Interface::
+LoadConfiguration( const std::string& filename )
+{
+  std::ifstream in( filename.c_str( ) );
+  if( !in )
+    return( false );
+
+  this->UnloadAll( );
+  std::string line;
+  while( std::getline( in, line ) )
+  {
+    try
+    {
+      this->LoadPluginFile( line );
+    }
+    catch( ... )
+    {
+      // Do nothing
+
+    } // yrt
+
+  } // elihw
+  return( true );
+}
+
+// -------------------------------------------------------------------------
+bool cpPlugins::Interface::
+SaveConfiguration( const std::string& filename ) const
+{
+  std::ofstream out( filename.c_str( ) );
+  if( !out )
+    return( false );
+  auto dIt = this->m_DynLibraries.begin( );
+  for( ; dIt != this->m_DynLibraries.end( ); ++dIt )
+    out << dIt->first << std::endl;
+  out.close( );
+}
+
 // -------------------------------------------------------------------------
 void cpPlugins::Interface::
 LoadPluginFile( const std::string& filename )
@@ -124,7 +164,7 @@ _DLOpen( const std::string& fname )
 {
   void* hnd = NULL;
 #ifdef cpPlugins_SYS_WINDOWS
-  // TODO:
+  hnd = ::LoadLibraryA( fname.c_str( ) );
 #else // cpPlugins_SYS_WINDOWS
   hnd = dlopen( fname.c_str( ), RTLD_NOW | RTLD_GLOBAL );
   dlerror( );
@@ -137,11 +177,15 @@ cpPlugins::Interface::
 TFilters cpPlugins::Interface::
 _DLGetFilters( void* hnd )
 {
+  typedef const TFilters ( *f_t )( );
+
   TFilters filters;
 #ifdef cpPlugins_SYS_WINDOWS
-  // TODO:
+  auto f = ( f_t )(
+    ::GetProcAddress( ( HMODULE )hnd, "cpPlugins_LoadedFilters" )
+    );
+  std::cout << f << std::endl;
 #else // cpPlugins_SYS_WINDOWS
-  typedef const TFilters ( *f_t )( );
   auto f = ( f_t ) dlsym( hnd, "cpPlugins_LoadedFilters" );
   const char* err = dlerror( );
   if( err != NULL )
@@ -154,8 +198,8 @@ _DLGetFilters( void* hnd )
       );
 
   } // fi
-  filters = f( );
 #endif // cpPlugins_SYS_WINDOWS
+  filters = f( );
   return( filters );
 }
 
@@ -187,7 +231,7 @@ void cpPlugins::Interface::
 _DLClose( void* hnd )
 {
 #ifdef cpPlugins_SYS_WINDOWS
-  // TODO:
+  ::FreeLibrary( ( HMODULE )hnd );
 #else // cpPlugins_SYS_WINDOWS
   dlclose( hnd );
 #endif // cpPlugins_SYS_WINDOWS