X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;ds=sidebyside;f=lib%2FcpPlugins%2FInterface.cxx;h=58e468d29e114cc2b802a22fab6cb1b8f90d07f2;hb=7989665e222981539e3c354e9d50bf142e777a2c;hp=611143e09d66ca6e170a44adb4edd73bcbc05e4b;hpb=8d7780dd6a0a8f010d705e957e1eae793b7948cc;p=cpPlugins.git diff --git a/lib/cpPlugins/Interface.cxx b/lib/cpPlugins/Interface.cxx index 611143e..58e468d 100644 --- a/lib/cpPlugins/Interface.cxx +++ b/lib/cpPlugins/Interface.cxx @@ -5,6 +5,7 @@ #else // cpPlugins_SYS_WINDOWS # include #endif // cpPlugins_SYS_WINDOWS +#include // ------------------------------------------------------------------------- cpPlugins::Interface:: @@ -73,11 +74,23 @@ LoadPluginFile( const std::string& filename ) { // Open library with its canonical path name auto canonical_fn = cpPlugins::PathHelper::CanonicalPath( filename ); + if( canonical_fn == "" ) + throw std::runtime_error( + std::string( "cpPlugins::Interface: Library \"" ) + + 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( std::string( "cpPlugins::Interface: Could not load library \"" ) + - canonical_fn + + filename + std::string( "\"" ) ); @@ -128,6 +141,37 @@ LoadPluginFile( const std::string& filename ) Self::_DLClose( hnd ); } +// ------------------------------------------------------------------------- +unsigned int cpPlugins::Interface:: +LoadPluginDir( const std::string& dirname ) +{ + DIR* dir; + struct dirent* ent; + unsigned int count = 0; + if( ( dir = opendir( dirname.c_str( ) ) ) != NULL ) + { + 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 ); +} + // ------------------------------------------------------------------------- void cpPlugins::Interface:: UnloadAll( )