comparison plugin/FeatureExtractionPluginFactory.cpp @ 1179:6b1af0f05f06 pluginscan

Make use of, and warn for, the plugin checker for all types of plugin. Haven't yet resolved the question of how to install and find it.
author Chris Cannam
date Thu, 14 Apr 2016 14:03:18 +0100
parents bf05d9259dbc
children 98664afd518b
comparison
equal deleted inserted replaced
1178:bf05d9259dbc 1179:6b1af0f05f06
19 #include <vamp-hostsdk/PluginHostAdapter.h> 19 #include <vamp-hostsdk/PluginHostAdapter.h>
20 #include <vamp-hostsdk/PluginWrapper.h> 20 #include <vamp-hostsdk/PluginWrapper.h>
21 21
22 #include "system/System.h" 22 #include "system/System.h"
23 23
24 #include "PluginScan.h"
25
24 #include <QDir> 26 #include <QDir>
25 #include <QFile> 27 #include <QFile>
26 #include <QFileInfo> 28 #include <QFileInfo>
27 #include <QTextStream> 29 #include <QTextStream>
28 30
109 111
110 return rv; 112 return rv;
111 } 113 }
112 114
113 vector<QString> 115 vector<QString>
114 FeatureExtractionPluginFactory::getPluginCandidateFiles()
115 {
116 vector<QString> path = getPluginPath();
117 vector<QString> candidates;
118
119 for (QString dirname : path) {
120
121 #ifdef DEBUG_PLUGIN_SCAN_AND_INSTANTIATE
122 cerr << "FeatureExtractionPluginFactory::getPluginCandidateFiles: scanning directory " << dirname << endl;
123 #endif
124
125 QDir pluginDir(dirname, PLUGIN_GLOB,
126 QDir::Name | QDir::IgnoreCase,
127 QDir::Files | QDir::Readable);
128
129 for (unsigned int j = 0; j < pluginDir.count(); ++j) {
130 QString soname = pluginDir.filePath(pluginDir[j]);
131 candidates.push_back(soname);
132 }
133 }
134
135 return candidates;
136 }
137
138 vector<QString>
139 FeatureExtractionPluginFactory::winnowPluginCandidates(vector<QString> candidates,
140 QString &warningMessage)
141 {
142 vector<QString> good, bad;
143 vector<PluginLoadStatus> badStatuses;
144
145 for (QString c: candidates) {
146
147 PluginLoadStatus status =
148 TestPluginLoadability(c, "vampGetPluginDescriptor");
149
150 if (status == PluginLoadOK) {
151 good.push_back(c);
152 } else if (status == UnknownPluginLoadStatus) {
153 cerr << "WARNING: Unknown load status for plugin candidate \""
154 << c << "\", continuing" << endl;
155 good.push_back(c);
156 } else {
157 bad.push_back(c);
158 badStatuses.push_back(status);
159 }
160 }
161
162 if (!bad.empty()) {
163 warningMessage =
164 QObject::tr("<b>Failed to load plugins</b>"
165 "<p>Failed to load one or more plugin libraries:</p>\n");
166 warningMessage += "<ul>";
167 for (int i = 0; in_range_for(bad, i); ++i) {
168 QString m;
169 if (badStatuses[i] == PluginLoadFailedToLoadLibrary) {
170 m = QObject::tr("Failed to load library");
171 } else if (badStatuses[i] == PluginLoadFailedToFindDescriptor) {
172 m = QObject::tr("Failed to query plugins from library after loading");
173 } else if (badStatuses[i] == PluginLoadFailedElsewhere) {
174 m = QObject::tr("Unknown failure");
175 } else {
176 m = QObject::tr("Success: internal error?");
177 }
178 warningMessage += QString("<li>%1 (%2)</li>\n")
179 .arg(bad[i])
180 .arg(m);
181 }
182 warningMessage += "</ul>";
183 }
184 return good;
185 }
186
187 vector<QString>
188 FeatureExtractionPluginFactory::getPluginIdentifiers() 116 FeatureExtractionPluginFactory::getPluginIdentifiers()
189 { 117 {
190 Profiler profiler("FeatureExtractionPluginFactory::getPluginIdentifiers"); 118 Profiler profiler("FeatureExtractionPluginFactory::getPluginIdentifiers");
191 119
192 vector<QString> rv; 120 vector<QString> rv;
193 vector<QString> candidates = winnowPluginCandidates(getPluginCandidateFiles(), 121
194 m_pluginScanError); 122 QStringList candidates =
123 PluginScan::getInstance()->getCandidateVampLibraries();
195 124
196 for (QString soname : candidates) { 125 for (QString soname : candidates) {
197 126
198 void *libraryHandle = DLOPEN(soname, RTLD_LAZY | RTLD_LOCAL); 127 void *libraryHandle = DLOPEN(soname, RTLD_LAZY | RTLD_LOCAL);
199 128