X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=lib%2Fthird_party%2FPluma%2FPluginManager.cpp;h=6cfe12e1a1c86178f81848349190bbdf1461ca47;hb=c06908465eb6da50572779f423d1e2c9e03b68dd;hp=9579da2f2fe4ff59f408e2757adb9e5b5aea03a3;hpb=351f2e4ce6e3b11e77ba27998d41ff4310b806ad;p=cpPlugins.git diff --git a/lib/third_party/Pluma/PluginManager.cpp b/lib/third_party/Pluma/PluginManager.cpp index 9579da2..6cfe12e 100644 --- a/lib/third_party/Pluma/PluginManager.cpp +++ b/lib/third_party/Pluma/PluginManager.cpp @@ -22,7 +22,6 @@ // //////////////////////////////////////////////////////////// - //////////////////////////////////////////////////////////// // Headers //////////////////////////////////////////////////////////// @@ -30,6 +29,7 @@ #include #include #include +#include namespace pluma{ @@ -56,16 +56,26 @@ bool PluginManager::load(const std::string& path){ registerFunction = reinterpret_cast(lib->getSymbol("connect")); if(!registerFunction){ - fprintf(stderr, "Failed to initialize plugin \"%s\": connect function not found\n", plugName.c_str()); + //fprintf(stderr, "Failed to initialize plugin \"%s\": connect function not found\n", plugName.c_str()); delete lib; + throw std::runtime_error( + std::string( "Failed to initialize plugin \"" ) + + plugName + + std::string( "\": connect function not found" ) + ); return false; } // try to initialize plugin: if (!registerFunction(host)){ // plugin decided to fail - fprintf(stderr, "Self registry failed on plugin \"%s\".\n", plugName.c_str()); + // fprintf(stderr, "Self registry failed on plugin \"%s\".\n", plugName.c_str()); host.cancelAddictions(); delete lib; + throw std::runtime_error( + std::string( "Self registry failed on plugin \"" ) + + plugName + + std::string( "\"" ) + ); return false; } // Store the library if addictions are confirmed @@ -73,8 +83,13 @@ bool PluginManager::load(const std::string& path){ libraries[plugName] = lib; else{ // otherwise nothing was registered - fprintf(stderr, "Nothing registered by plugin \"%s\".\n", plugName.c_str()); + // fprintf(stderr, "Nothing registered by plugin \"%s\".\n", plugName.c_str()); delete lib; + throw std::runtime_error( + std::string( "Nothing registered by plugin \"" ) + + plugName + + std::string( "\"." ) + ); return false; } return true; @@ -90,18 +105,24 @@ bool PluginManager::load(const std::string& folder, const std::string& pluginNam return load(folder + '/' + pluginName); } - //////////////////////////////////////////////////////////// -int PluginManager::loadFromFolder(const std::string& folder, bool recursive){ - std::list files; + std::list< std::string > PluginManager::loadFromFolder(const std::string& folder, bool recursive){ + std::list files, loaded_files; dir::listFiles(files, folder, PLUMA_LIB_EXTENSION, recursive); // try to load every library - int res = 0; std::list::const_iterator it; for (it = files.begin() ; it != files.end() ; ++it){ - if ( load(*it) ) ++res; + // *** LFV *** + try + { + if ( load(*it) ) loaded_files.push_back( *it ); + } + catch( ... ) + { + } // yrt + // *** LFV *** } - return res; + return loaded_files; } @@ -166,7 +187,8 @@ void PluginManager::registerType(const std::string& type, unsigned int version, //////////////////////////////////////////////////////////// bool PluginManager::addProvider(Provider* provider){ if (provider == NULL){ - fprintf(stderr, "Trying to add null provider\n"); + // fprintf(stderr, "Trying to add null provider\n"); + throw std::runtime_error( "Trying to add null provider." ); return false; } return host.registerProvider(provider);