diff plugin/FeatureExtractionPluginFactory.cpp @ 1148:9cdb4206aceb 3.0-integration

Check for plugin loadability before trying to load in the main process (POSIX only so far)
author Chris Cannam
date Mon, 11 Jan 2016 14:18:56 +0000
parents bff23ef9407e
children afed8be79032
line wrap: on
line diff
--- a/plugin/FeatureExtractionPluginFactory.cpp	Fri Jan 08 15:39:12 2016 +0000
+++ b/plugin/FeatureExtractionPluginFactory.cpp	Mon Jan 11 14:18:56 2016 +0000
@@ -136,13 +136,59 @@
 }
 
 vector<QString>
+FeatureExtractionPluginFactory::winnowPluginCandidates(vector<QString> candidates)
+{
+    vector<QString> good, bad;
+    vector<PluginLoadStatus> badStatuses;
+    
+    for (QString c: candidates) {
+
+        PluginLoadStatus status =
+            TestPluginLoadability(c, "vampGetPluginDescriptor");
+
+        if (status == PluginLoadOK) {
+            good.push_back(c);
+        } else if (status == UnknownPluginLoadStatus) {
+            cerr << "WARNING: Unknown load status for plugin candidate \""
+                 << c << "\", continuing" << endl;
+            good.push_back(c);
+        } else {
+            bad.push_back(c);
+            badStatuses.push_back(status);
+        }
+    }
+    
+    if (!bad.empty()) {
+        QString warningMessage = "<b>Failed to load plugins</b></p>Failed to load one or more plugin libraries:</p><ul>\n";
+        for (int i = 0; i < bad.size(); ++i) {
+            QString m;
+            if (badStatuses[i] == PluginLoadFailedToLoadLibrary) {
+                m = "Failed to load library";
+            } else if (badStatuses[i] == PluginLoadFailedToFindDescriptor) {
+                m = "Failed to query plugins from library after loading";
+            } else if (badStatuses[i] == PluginLoadFailedElsewhere) {
+                m = "Unknown failure";
+            } else {
+                m = "Success: internal error?";
+            }
+            warningMessage += QString("<li>%1 (%2)</li>\n")
+                .arg(bad[i])
+                .arg(m);
+        }
+        warningMessage += "</ul>";
+        cerr << warningMessage; //!!! for now!
+    }
+    return good;
+}
+
+vector<QString>
 FeatureExtractionPluginFactory::getPluginIdentifiers()
 {
     Profiler profiler("FeatureExtractionPluginFactory::getPluginIdentifiers");
 
     vector<QString> rv;
-    vector<QString> candidates = getPluginCandidateFiles();
-
+    vector<QString> candidates = winnowPluginCandidates(getPluginCandidateFiles());
+    
     for (QString soname : candidates) {
 
 #ifdef DEBUG_PLUGIN_SCAN_AND_INSTANTIATE