X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=lib%2FcpPlugins%2FInterface.cxx;h=53b7b118174179807139737986a54f5e9a1ed93b;hb=3143943a5befc9b72fb4fec14969b43cedd32c14;hp=6c6e0f8f66812db1e601fb2287359c32d78cd6bf;hpb=b67cad9ff3c38b4e99ac48a4852e9e94cb879c6a;p=cpPlugins.git diff --git a/lib/cpPlugins/Interface.cxx b/lib/cpPlugins/Interface.cxx index 6c6e0f8..53b7b11 100644 --- a/lib/cpPlugins/Interface.cxx +++ b/lib/cpPlugins/Interface.cxx @@ -6,6 +6,7 @@ # include #endif // cpPlugins_SYS_WINDOWS #include +#include // ------------------------------------------------------------------------- cpPlugins::Interface:: @@ -28,6 +29,26 @@ GetFilters( ) return( this->m_Filters ); } +// ------------------------------------------------------------------------- +void cpPlugins::Interface:: +GuessAccesiblePlugins( ) +{ + // Load environment configuration + char* path = std::getenv( "cpPlugins_PATHS" ); + if( path != NULL ) + { + std::vector< std::string > tokens; + cpPlugins::TokenizeString( tokens, path, "#" ); + for( auto tIt = tokens.begin( ); tIt != tokens.end( ); ++tIt ) + try { this->LoadPluginDir( *tIt ); } catch( ... ) { } + + } // fi + + // Load local path + auto lpath = cpPlugins::CanonicalPath( "." ); + try { this->LoadPluginDir( lpath ); } catch( ... ) { } +} + // ------------------------------------------------------------------------- bool cpPlugins::Interface:: LoadConfiguration( const std::string& filename ) @@ -39,18 +60,7 @@ LoadConfiguration( const std::string& filename ) this->UnloadAll( ); std::string line; while( std::getline( in, line ) ) - { - try - { - this->LoadPluginFile( line ); - } - catch( ... ) - { - // Do nothing - - } // yrt - - } // elihw + try { this->LoadPluginFile( line ); } catch( ... ) { } return( true ); } @@ -80,6 +90,14 @@ LoadPluginFile( const std::string& filename ) filename + std::string( "\" does not exist." ) ); + + // Check if it was already loaded + if( + this->m_DynLibraries.find( canonical_fn ) != this->m_DynLibraries.end( ) + ) + return; + + // Ok, try to load the library void* hnd = Self::_DLOpen( canonical_fn ); if( hnd == NULL ) throw std::runtime_error( @@ -136,21 +154,36 @@ LoadPluginFile( const std::string& filename ) } // ------------------------------------------------------------------------- -void cpPlugins::Interface:: +unsigned int cpPlugins::Interface:: LoadPluginDir( const std::string& dirname ) { -#error ACA VOY - DIR *dir; - struct dirent *ent; - if( (dir = opendir ( dirname.c_str( ) ) ) != NULL) + DIR* dir; + struct dirent* ent; + unsigned int count = 0; + if( ( dir = opendir( dirname.c_str( ) ) ) != NULL ) { - while ((ent = readdir (dir)) != NULL) { - printf ("%s\n", ent->d_name); - } - closedir (dir); - } else { - std::cerr << "error" << std::endl; + while( ( ent = readdir( dir ) ) != NULL ) + { + try + { + this->LoadPluginFile( + dirname + + std::string( "/" ) + + ent->d_name + ); + count++; + } + catch( ... ) { } + + } // elihw + closedir( dir ); } + else + throw std::runtime_error( + std::string( "cpPlugins::Interface: Could not load directory " ) + + std::string( "\"" ) + dirname + std::string( "\"" ) + ); + return( count ); } // -------------------------------------------------------------------------