X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=lib%2FcpPlugins%2FInterface.cxx;h=58e468d29e114cc2b802a22fab6cb1b8f90d07f2;hb=b5691a406e0f87d9f051cdd5877a4dfb299764a5;hp=6c6e0f8f66812db1e601fb2287359c32d78cd6bf;hpb=b67cad9ff3c38b4e99ac48a4852e9e94cb879c6a;p=cpPlugins.git diff --git a/lib/cpPlugins/Interface.cxx b/lib/cpPlugins/Interface.cxx index 6c6e0f8..58e468d 100644 --- a/lib/cpPlugins/Interface.cxx +++ b/lib/cpPlugins/Interface.cxx @@ -80,6 +80,12 @@ 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 +142,34 @@ 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( ent->d_name ); + count++; + } + catch( ... ) + { + // Ignore errors + } // yrt + } // elihw + closedir( dir ); } + else + throw std::runtime_error( + std::string( "cpPlugins::Interface: Could not load directory " ) + + std::string( "\"" ) + dirname + std::string( "\"" ) + ); + return( count ); } // -------------------------------------------------------------------------