]> Creatis software - cpPlugins.git/blobdiff - lib/third_party/Pluma/DLibrary.cpp
Parameters are now part of the pipeline update process
[cpPlugins.git] / lib / third_party / Pluma / DLibrary.cpp
index 9b617dbf1dd7ac5a88a13152de88a0275e5d9bcc..923d825272c3538052e47e6e3c03d93169fb457d 100644 (file)
@@ -29,6 +29,7 @@
 #include <Pluma/DLibrary.hpp>\r
 #include <cstdio>\r
 #include <string>\r
+#include <stdexcept>\r
 \r
 \r
 namespace pluma{\r
@@ -36,7 +37,8 @@ namespace pluma{
 ////////////////////////////////////////////////////////////\r
 DLibrary* DLibrary::load(const std::string& path){\r
     if ( path.empty() ){\r
-        fprintf(stderr, "Failed to load library: Empty path\n");\r
+      // fprintf(stderr, "Failed to load library: Empty path\n");\r
+      throw std::runtime_error( "Failed to load library: Empty path." );\r
         return NULL;\r
     }\r
     void* handle = NULL;\r
@@ -45,16 +47,23 @@ DLibrary* DLibrary::load(const std::string& path){
     #ifdef PLUMA_SYS_WINDOWS\r
         handle = ::LoadLibraryA(path.c_str());\r
         if (!handle){\r
-            fprintf(stderr, "Failed to load library \"%s\".\n", path.c_str());\r
-            return NULL;\r
+          //fprintf(stderr, "Failed to load library \"%s\".\n", path.c_str());\r
+          throw std::runtime_error(\r
+            std::string( "Failed to load library \"" ) +\r
+            path +\r
+            std::string( "\"." );\r
+            );\r
+          return NULL;\r
         }\r
     #else\r
         handle = ::dlopen(path.c_str(), RTLD_NOW);\r
         if (!handle){\r
             const char* errorString = ::dlerror();\r
-            fprintf(stderr, "Failed to load library \"%s\".", path.c_str());\r
-            if(errorString) fprintf(stderr, " OS returned error: \"%s\".", errorString);\r
-            fprintf(stderr, "\n");\r
+            std::string error_text = "Failed to load library \"";\r
+            // fprintf(stderr, "Failed to load library \"%s\".", path.c_str());\r
+            if(errorString) error_text += std::string( errorString ); // fprintf(stderr, " OS returned error: \"%s\".", errorString);\r
+            // fprintf(stderr, "\n");\r
+            throw std::runtime_error( error_text + std::string( "\"." ) );\r
             return NULL;\r
         }\r
     #endif\r
@@ -78,7 +87,8 @@ DLibrary::~DLibrary(){
 ////////////////////////////////////////////////////////////\r
 void* DLibrary::getSymbol(const std::string& symbol){\r
     if (!handle){\r
-        fprintf(stderr, "Cannot inspect library symbols, library isn't loaded.\n");\r
+      //fprintf(stderr, "Cannot inspect library symbols, library isn't loaded.\n");\r
+      throw std::runtime_error( "Cannot inspect library symbols, library isn't loaded." );\r
         return NULL;\r
     }\r
     void* res;\r
@@ -88,8 +98,13 @@ void* DLibrary::getSymbol(const std::string& symbol){
         res = (void*)(::dlsym(handle, symbol.c_str()));\r
     #endif\r
     if (!res){\r
-        fprintf(stderr, "Library symbol \"%s\" not found.\n", symbol.c_str());\r
-        return NULL;\r
+      // fprintf(stderr, "Library symbol \"%s\" not found.\n", symbol.c_str());\r
+      throw std::runtime_error(\r
+        std::string( "Library symbol \"" ) +\r
+        symbol +\r
+        std::string( "\" not found." )\r
+        );\r
+      return NULL;\r
     }\r
     return res;\r
 }\r