comparison plugin/FeatureExtractionPluginFactory.cpp @ 1140:c7f1300dbf64

Debug outputs
author Chris Cannam
date Tue, 03 Nov 2015 11:34:44 +0000
parents a1cd5abcb38b
children ea636412f9fe 0f90a357cb2a
comparison
equal deleted inserted replaced
1139:205250c5d2a2 1140:c7f1300dbf64
117 std::vector<QString> path = getPluginPath(); 117 std::vector<QString> path = getPluginPath();
118 118
119 for (std::vector<QString>::iterator i = path.begin(); i != path.end(); ++i) { 119 for (std::vector<QString>::iterator i = path.begin(); i != path.end(); ++i) {
120 120
121 #ifdef DEBUG_PLUGIN_SCAN_AND_INSTANTIATE 121 #ifdef DEBUG_PLUGIN_SCAN_AND_INSTANTIATE
122 SVDEBUG << "FeatureExtractionPluginFactory::getPluginIdentifiers: scanning directory " << i-<< endl; 122 cerr << "FeatureExtractionPluginFactory::getPluginIdentifiers: scanning directory " << *i << endl;
123 #endif 123 #endif
124 124
125 QDir pluginDir(*i, PLUGIN_GLOB, 125 QDir pluginDir(*i, PLUGIN_GLOB,
126 QDir::Name | QDir::IgnoreCase, 126 QDir::Name | QDir::IgnoreCase,
127 QDir::Files | QDir::Readable); 127 QDir::Files | QDir::Readable);
129 for (unsigned int j = 0; j < pluginDir.count(); ++j) { 129 for (unsigned int j = 0; j < pluginDir.count(); ++j) {
130 130
131 QString soname = pluginDir.filePath(pluginDir[j]); 131 QString soname = pluginDir.filePath(pluginDir[j]);
132 132
133 #ifdef DEBUG_PLUGIN_SCAN_AND_INSTANTIATE 133 #ifdef DEBUG_PLUGIN_SCAN_AND_INSTANTIATE
134 SVDEBUG << "FeatureExtractionPluginFactory::getPluginIdentifiers: trying potential library " << soname << endl; 134 cerr << "FeatureExtractionPluginFactory::getPluginIdentifiers: trying potential library " << soname << endl;
135 #endif 135 #endif
136 136
137 void *libraryHandle = DLOPEN(soname, RTLD_LAZY | RTLD_LOCAL); 137 void *libraryHandle = DLOPEN(soname, RTLD_LAZY | RTLD_LOCAL);
138 138
139 if (!libraryHandle) { 139 if (!libraryHandle) {
140 cerr << "WARNING: FeatureExtractionPluginFactory::getPluginIdentifiers: Failed to load library " << soname << ": " << DLERROR() << endl; 140 cerr << "WARNING: FeatureExtractionPluginFactory::getPluginIdentifiers: Failed to load library " << soname << ": " << DLERROR() << endl;
141 continue; 141 continue;
142 } 142 }
143 143
144 #ifdef DEBUG_PLUGIN_SCAN_AND_INSTANTIATE 144 #ifdef DEBUG_PLUGIN_SCAN_AND_INSTANTIATE
145 SVDEBUG << "FeatureExtractionPluginFactory::getPluginIdentifiers: It's a library all right, checking for descriptor" << endl; 145 cerr << "FeatureExtractionPluginFactory::getPluginIdentifiers: It's a library all right, checking for descriptor" << endl;
146 #endif 146 #endif
147 147
148 VampGetPluginDescriptorFunction fn = (VampGetPluginDescriptorFunction) 148 VampGetPluginDescriptorFunction fn = (VampGetPluginDescriptorFunction)
149 DLSYM(libraryHandle, "vampGetPluginDescriptor"); 149 DLSYM(libraryHandle, "vampGetPluginDescriptor");
150 150
155 } 155 }
156 continue; 156 continue;
157 } 157 }
158 158
159 #ifdef DEBUG_PLUGIN_SCAN_AND_INSTANTIATE 159 #ifdef DEBUG_PLUGIN_SCAN_AND_INSTANTIATE
160 SVDEBUG << "FeatureExtractionPluginFactory::getPluginIdentifiers: Vamp descriptor found" << endl; 160 cerr << "FeatureExtractionPluginFactory::getPluginIdentifiers: Vamp descriptor found" << endl;
161 #endif 161 #endif
162 162
163 const VampPluginDescriptor *descriptor = 0; 163 const VampPluginDescriptor *descriptor = 0;
164 int index = 0; 164 int index = 0;
165 165
173 << soname 173 << soname
174 << " returns the same plugin identifier \"" 174 << " returns the same plugin identifier \""
175 << descriptor->identifier << "\" at indices " 175 << descriptor->identifier << "\" at indices "
176 << known[descriptor->identifier] << " and " 176 << known[descriptor->identifier] << " and "
177 << index << endl; 177 << index << endl;
178 SVDEBUG << "FeatureExtractionPluginFactory::getPluginIdentifiers: Avoiding this library (obsolete API?)" << endl; 178 cerr << "FeatureExtractionPluginFactory::getPluginIdentifiers: Avoiding this library (obsolete API?)" << endl;
179 ok = false; 179 ok = false;
180 break; 180 break;
181 } else { 181 } else {
182 known[descriptor->identifier] = index; 182 known[descriptor->identifier] = index;
183 } 183 }
193 193
194 QString id = PluginIdentifier::createIdentifier 194 QString id = PluginIdentifier::createIdentifier
195 ("vamp", soname, descriptor->identifier); 195 ("vamp", soname, descriptor->identifier);
196 rv.push_back(id); 196 rv.push_back(id);
197 #ifdef DEBUG_PLUGIN_SCAN_AND_INSTANTIATE 197 #ifdef DEBUG_PLUGIN_SCAN_AND_INSTANTIATE
198 SVDEBUG << "FeatureExtractionPluginFactory::getPluginIdentifiers: Found plugin id " << id << " at index " << index << endl; 198 cerr << "FeatureExtractionPluginFactory::getPluginIdentifiers: Found plugin id " << id << " at index " << index << endl;
199 #endif 199 #endif
200 ++index; 200 ++index;
201 } 201 }
202 } 202 }
203 203
216 FeatureExtractionPluginFactory::findPluginFile(QString soname, QString inDir) 216 FeatureExtractionPluginFactory::findPluginFile(QString soname, QString inDir)
217 { 217 {
218 QString file = ""; 218 QString file = "";
219 219
220 #ifdef DEBUG_PLUGIN_SCAN_AND_INSTANTIATE 220 #ifdef DEBUG_PLUGIN_SCAN_AND_INSTANTIATE
221 SVDEBUG << "FeatureExtractionPluginFactory::findPluginFile(\"" 221 cerr << "FeatureExtractionPluginFactory::findPluginFile(\""
222 << soname << "\", \"" << inDir << "\")" 222 << soname << "\", \"" << inDir << "\")"
223 << endl; 223 << endl;
224 #endif 224 #endif
225 225
226 if (inDir != "") { 226 if (inDir != "") {
233 file = dir.filePath(QFileInfo(soname).fileName()); 233 file = dir.filePath(QFileInfo(soname).fileName());
234 234
235 if (QFileInfo(file).exists() && QFileInfo(file).isFile()) { 235 if (QFileInfo(file).exists() && QFileInfo(file).isFile()) {
236 236
237 #ifdef DEBUG_PLUGIN_SCAN_AND_INSTANTIATE 237 #ifdef DEBUG_PLUGIN_SCAN_AND_INSTANTIATE
238 SVDEBUG << "FeatureExtractionPluginFactory::findPluginFile: " 238 cerr << "FeatureExtractionPluginFactory::findPluginFile: "
239 << "found trivially at " << file << endl; 239 << "found trivially at " << file << endl;
240 #endif 240 #endif
241 241
242 return file; 242 return file;
243 } 243 }
245 for (unsigned int j = 0; j < dir.count(); ++j) { 245 for (unsigned int j = 0; j < dir.count(); ++j) {
246 file = dir.filePath(dir[j]); 246 file = dir.filePath(dir[j]);
247 if (QFileInfo(file).baseName() == QFileInfo(soname).baseName()) { 247 if (QFileInfo(file).baseName() == QFileInfo(soname).baseName()) {
248 248
249 #ifdef DEBUG_PLUGIN_SCAN_AND_INSTANTIATE 249 #ifdef DEBUG_PLUGIN_SCAN_AND_INSTANTIATE
250 SVDEBUG << "FeatureExtractionPluginFactory::findPluginFile: " 250 cerr << "FeatureExtractionPluginFactory::findPluginFile: "
251 << "found \"" << soname << "\" at " << file << endl; 251 << "found \"" << soname << "\" at " << file << endl;
252 #endif 252 #endif
253 253
254 return file; 254 return file;
255 } 255 }
256 } 256 }
257 257
258 #ifdef DEBUG_PLUGIN_SCAN_AND_INSTANTIATE 258 #ifdef DEBUG_PLUGIN_SCAN_AND_INSTANTIATE
259 SVDEBUG << "FeatureExtractionPluginFactory::findPluginFile (with dir): " 259 cerr << "FeatureExtractionPluginFactory::findPluginFile (with dir): "
260 << "not found" << endl; 260 << "not found" << endl;
261 #endif 261 #endif
262 262
263 return ""; 263 return "";
264 264
266 266
267 QFileInfo fi(soname); 267 QFileInfo fi(soname);
268 268
269 if (fi.isAbsolute() && fi.exists() && fi.isFile()) { 269 if (fi.isAbsolute() && fi.exists() && fi.isFile()) {
270 #ifdef DEBUG_PLUGIN_SCAN_AND_INSTANTIATE 270 #ifdef DEBUG_PLUGIN_SCAN_AND_INSTANTIATE
271 SVDEBUG << "FeatureExtractionPluginFactory::findPluginFile: " 271 cerr << "FeatureExtractionPluginFactory::findPluginFile: "
272 << "found trivially at " << soname << endl; 272 << "found trivially at " << soname << endl;
273 #endif 273 #endif
274 return soname; 274 return soname;
275 } 275 }
276 276
287 if (file != "") return file; 287 if (file != "") return file;
288 } 288 }
289 } 289 }
290 290
291 #ifdef DEBUG_PLUGIN_SCAN_AND_INSTANTIATE 291 #ifdef DEBUG_PLUGIN_SCAN_AND_INSTANTIATE
292 SVDEBUG << "FeatureExtractionPluginFactory::findPluginFile: " 292 cerr << "FeatureExtractionPluginFactory::findPluginFile: "
293 << "not found" << endl; 293 << "not found" << endl;
294 #endif 294 #endif
295 295
296 return ""; 296 return "";
297 } 297 }
310 int index = 0; 310 int index = 0;
311 311
312 QString type, soname, label; 312 QString type, soname, label;
313 PluginIdentifier::parseIdentifier(identifier, type, soname, label); 313 PluginIdentifier::parseIdentifier(identifier, type, soname, label);
314 if (type != "vamp") { 314 if (type != "vamp") {
315 SVDEBUG << "FeatureExtractionPluginFactory::instantiatePlugin: Wrong factory for plugin type " << type << endl; 315 cerr << "FeatureExtractionPluginFactory::instantiatePlugin: Wrong factory for plugin type " << type << endl;
316 return 0; 316 return 0;
317 } 317 }
318 318
319 QString found = findPluginFile(soname); 319 QString found = findPluginFile(soname);
320 320
322 cerr << "FeatureExtractionPluginFactory::instantiatePlugin: Failed to find library file " << soname << endl; 322 cerr << "FeatureExtractionPluginFactory::instantiatePlugin: Failed to find library file " << soname << endl;
323 return 0; 323 return 0;
324 } else if (found != soname) { 324 } else if (found != soname) {
325 325
326 #ifdef DEBUG_PLUGIN_SCAN_AND_INSTANTIATE 326 #ifdef DEBUG_PLUGIN_SCAN_AND_INSTANTIATE
327 SVDEBUG << "FeatureExtractionPluginFactory::instantiatePlugin: Given library name was " << soname << ", found at " << found << endl; 327 cerr << "FeatureExtractionPluginFactory::instantiatePlugin: Given library name was " << soname << ", found at " << found << endl;
328 cerr << soname << " -> " << found << endl; 328 cerr << soname << " -> " << found << endl;
329 #endif 329 #endif
330 330
331 } 331 }
332 332
341 341
342 VampGetPluginDescriptorFunction fn = (VampGetPluginDescriptorFunction) 342 VampGetPluginDescriptorFunction fn = (VampGetPluginDescriptorFunction)
343 DLSYM(libraryHandle, "vampGetPluginDescriptor"); 343 DLSYM(libraryHandle, "vampGetPluginDescriptor");
344 344
345 if (!fn) { 345 if (!fn) {
346 SVDEBUG << "FeatureExtractionPluginFactory::instantiatePlugin: No descriptor function in " << soname << endl; 346 cerr << "FeatureExtractionPluginFactory::instantiatePlugin: No descriptor function in " << soname << endl;
347 goto done; 347 goto done;
348 } 348 }
349 349
350 while ((descriptor = fn(VAMP_API_VERSION, index))) { 350 while ((descriptor = fn(VAMP_API_VERSION, index))) {
351 if (label == descriptor->identifier) break; 351 if (label == descriptor->identifier) break;