X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;ds=sidebyside;f=lib%2FcpPlugins%2FInterface.cxx;h=259288243d5a309e803115bddb6e50a98645b210;hb=f533290f40279617e54e19086dde7c0ba9b07f5b;hp=0ee1faf9911aea516acf2fbe49c3d57a7c744930;hpb=e29096b7c37e89da4cda28bde9102cdb9ff159ea;p=cpPlugins.git diff --git a/lib/cpPlugins/Interface.cxx b/lib/cpPlugins/Interface.cxx index 0ee1faf..2592882 100644 --- a/lib/cpPlugins/Interface.cxx +++ b/lib/cpPlugins/Interface.cxx @@ -1,6 +1,7 @@ #include #ifdef cpPlugins_SYS_WINDOWS +# include #else // cpPlugins_SYS_WINDOWS # include #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