]> Creatis software - cpPlugins.git/blobdiff - lib/third_party/Pluma/PluginManager.cpp
More on graph editor
[cpPlugins.git] / lib / third_party / Pluma / PluginManager.cpp
index 9579da2f2fe4ff59f408e2757adb9e5b5aea03a3..6cfe12e1a1c86178f81848349190bbdf1461ca47 100644 (file)
@@ -22,7 +22,6 @@
 //\r
 ////////////////////////////////////////////////////////////\r
 \r
-\r
 ////////////////////////////////////////////////////////////\r
 // Headers\r
 ////////////////////////////////////////////////////////////\r
@@ -30,6 +29,7 @@
 #include <Pluma/DLibrary.hpp>\r
 #include <Pluma/Dir.hpp>\r
 #include <cstdio>\r
+#include <stdexcept>\r
 \r
 namespace pluma{\r
 \r
@@ -56,16 +56,26 @@ bool PluginManager::load(const std::string& path){
     registerFunction = reinterpret_cast<fnRegisterPlugin*>(lib->getSymbol("connect"));\r
 \r
     if(!registerFunction){\r
-        fprintf(stderr, "Failed to initialize plugin \"%s\": connect function not found\n", plugName.c_str());\r
+      //fprintf(stderr, "Failed to initialize plugin \"%s\": connect function not found\n", plugName.c_str());\r
         delete lib;\r
+        throw std::runtime_error(\r
+          std::string( "Failed to initialize plugin \"" ) +\r
+          plugName +\r
+          std::string( "\": connect function not found" )\r
+          );\r
         return false;\r
     }\r
     // try to initialize plugin:\r
     if (!registerFunction(host)){\r
         // plugin decided to fail\r
-        fprintf(stderr, "Self registry failed on plugin \"%s\".\n", plugName.c_str());\r
+      // fprintf(stderr, "Self registry failed on plugin \"%s\".\n", plugName.c_str());\r
         host.cancelAddictions();\r
         delete lib;\r
+        throw std::runtime_error(\r
+          std::string( "Self registry failed on plugin \"" ) +\r
+          plugName +\r
+          std::string( "\"" )\r
+          );\r
         return false;\r
     }\r
     // Store the library if addictions are confirmed\r
@@ -73,8 +83,13 @@ bool PluginManager::load(const std::string& path){
         libraries[plugName] = lib;\r
     else{\r
         // otherwise nothing was registered\r
-        fprintf(stderr, "Nothing registered by plugin \"%s\".\n", plugName.c_str());\r
+      // fprintf(stderr, "Nothing registered by plugin \"%s\".\n", plugName.c_str());\r
         delete lib;\r
+        throw std::runtime_error(\r
+          std::string( "Nothing registered by plugin \"" ) +\r
+          plugName +\r
+          std::string( "\"." )\r
+          );\r
         return false;\r
     }\r
     return true;\r
@@ -90,18 +105,24 @@ bool PluginManager::load(const std::string& folder, const std::string& pluginNam
     return load(folder + '/' + pluginName);\r
 }\r
 \r
-\r
 ////////////////////////////////////////////////////////////\r
-int PluginManager::loadFromFolder(const std::string& folder, bool recursive){\r
-    std::list<std::string> files;\r
+  std::list< std::string > PluginManager::loadFromFolder(const std::string& folder, bool recursive){\r
+    std::list<std::string> files, loaded_files;\r
     dir::listFiles(files, folder, PLUMA_LIB_EXTENSION, recursive);\r
     // try to load every library\r
-    int res = 0;\r
     std::list<std::string>::const_iterator it;\r
     for (it = files.begin() ; it != files.end() ; ++it){\r
-        if ( load(*it) ) ++res;\r
+      // *** LFV ***\r
+      try\r
+      {\r
+        if ( load(*it) ) loaded_files.push_back( *it );\r
+      }\r
+      catch( ... )\r
+      {\r
+      } // yrt\r
+      // *** LFV ***\r
     }\r
-    return res;\r
+    return loaded_files;\r
 }\r
 \r
 \r
@@ -166,7 +187,8 @@ void PluginManager::registerType(const std::string& type, unsigned int version,
 ////////////////////////////////////////////////////////////\r
 bool PluginManager::addProvider(Provider* provider){\r
     if (provider == NULL){\r
-        fprintf(stderr, "Trying to add null provider\n");\r
+      // fprintf(stderr, "Trying to add null provider\n");\r
+      throw std::runtime_error( "Trying to add null provider." );\r
         return false;\r
     }\r
     return host.registerProvider(provider);\r