comparison plugin/LADSPAPluginFactory.cpp @ 686:b4a8d8221eaf debug-output

Remove most toStdString calls (no longer needed, with debug header)
author Chris Cannam
date Thu, 12 May 2011 17:31:24 +0100
parents 115f60df1e4d
children 06f13a3b9e9e
comparison
equal deleted inserted replaced
685:99222d4bfc78 686:b4a8d8221eaf
348 348
349 m_instances.insert(instance); 349 m_instances.insert(instance);
350 350
351 #ifdef DEBUG_LADSPA_PLUGIN_FACTORY 351 #ifdef DEBUG_LADSPA_PLUGIN_FACTORY
352 std::cerr << "LADSPAPluginFactory::instantiatePlugin(" 352 std::cerr << "LADSPAPluginFactory::instantiatePlugin("
353 << identifier.toStdString() << ": now have " << m_instances.size() << " instances" << std::endl; 353 << identifier << ": now have " << m_instances.size() << " instances" << std::endl;
354 #endif 354 #endif
355 355
356 return instance; 356 return instance;
357 } 357 }
358 358
382 ii != m_instances.end(); ++ii) { 382 ii != m_instances.end(); ++ii) {
383 QString itype, isoname, ilabel; 383 QString itype, isoname, ilabel;
384 PluginIdentifier::parseIdentifier((*ii)->getPluginIdentifier(), itype, isoname, ilabel); 384 PluginIdentifier::parseIdentifier((*ii)->getPluginIdentifier(), itype, isoname, ilabel);
385 if (isoname == soname) { 385 if (isoname == soname) {
386 #ifdef DEBUG_LADSPA_PLUGIN_FACTORY 386 #ifdef DEBUG_LADSPA_PLUGIN_FACTORY
387 std::cerr << "LADSPAPluginFactory::releasePlugin: dll " << soname.toStdString() << " is still in use for plugin " << ilabel.toStdString() << std::endl; 387 std::cerr << "LADSPAPluginFactory::releasePlugin: dll " << soname << " is still in use for plugin " << ilabel << std::endl;
388 #endif 388 #endif
389 stillInUse = true; 389 stillInUse = true;
390 break; 390 break;
391 } 391 }
392 } 392 }
393 393
394 if (!stillInUse) { 394 if (!stillInUse) {
395 if (soname != PluginIdentifier::BUILTIN_PLUGIN_SONAME) { 395 if (soname != PluginIdentifier::BUILTIN_PLUGIN_SONAME) {
396 #ifdef DEBUG_LADSPA_PLUGIN_FACTORY 396 #ifdef DEBUG_LADSPA_PLUGIN_FACTORY
397 std::cerr << "LADSPAPluginFactory::releasePlugin: dll " << soname.toStdString() << " no longer in use, unloading" << std::endl; 397 std::cerr << "LADSPAPluginFactory::releasePlugin: dll " << soname << " no longer in use, unloading" << std::endl;
398 #endif 398 #endif
399 unloadLibrary(soname); 399 unloadLibrary(soname);
400 } 400 }
401 } 401 }
402 402
403 #ifdef DEBUG_LADSPA_PLUGIN_FACTORY 403 #ifdef DEBUG_LADSPA_PLUGIN_FACTORY
404 std::cerr << "LADSPAPluginFactory::releasePlugin(" 404 std::cerr << "LADSPAPluginFactory::releasePlugin("
405 << identifier.toStdString() << ": now have " << m_instances.size() << " instances" << std::endl; 405 << identifier << ": now have " << m_instances.size() << " instances" << std::endl;
406 #endif 406 #endif
407 } 407 }
408 408
409 const LADSPA_Descriptor * 409 const LADSPA_Descriptor *
410 LADSPAPluginFactory::getLADSPADescriptor(QString identifier) 410 LADSPAPluginFactory::getLADSPADescriptor(QString identifier)
413 PluginIdentifier::parseIdentifier(identifier, type, soname, label); 413 PluginIdentifier::parseIdentifier(identifier, type, soname, label);
414 414
415 if (m_libraryHandles.find(soname) == m_libraryHandles.end()) { 415 if (m_libraryHandles.find(soname) == m_libraryHandles.end()) {
416 loadLibrary(soname); 416 loadLibrary(soname);
417 if (m_libraryHandles.find(soname) == m_libraryHandles.end()) { 417 if (m_libraryHandles.find(soname) == m_libraryHandles.end()) {
418 std::cerr << "WARNING: LADSPAPluginFactory::getLADSPADescriptor: loadLibrary failed for " << soname.toStdString() << std::endl; 418 std::cerr << "WARNING: LADSPAPluginFactory::getLADSPADescriptor: loadLibrary failed for " << soname << std::endl;
419 return 0; 419 return 0;
420 } 420 }
421 } 421 }
422 422
423 void *libraryHandle = m_libraryHandles[soname]; 423 void *libraryHandle = m_libraryHandles[soname];
424 424
425 LADSPA_Descriptor_Function fn = (LADSPA_Descriptor_Function) 425 LADSPA_Descriptor_Function fn = (LADSPA_Descriptor_Function)
426 DLSYM(libraryHandle, "ladspa_descriptor"); 426 DLSYM(libraryHandle, "ladspa_descriptor");
427 427
428 if (!fn) { 428 if (!fn) {
429 std::cerr << "WARNING: LADSPAPluginFactory::getLADSPADescriptor: No descriptor function in library " << soname.toStdString() << std::endl; 429 std::cerr << "WARNING: LADSPAPluginFactory::getLADSPADescriptor: No descriptor function in library " << soname << std::endl;
430 return 0; 430 return 0;
431 } 431 }
432 432
433 const LADSPA_Descriptor *descriptor = 0; 433 const LADSPA_Descriptor *descriptor = 0;
434 434
436 while ((descriptor = fn(index))) { 436 while ((descriptor = fn(index))) {
437 if (descriptor->Label == label) return descriptor; 437 if (descriptor->Label == label) return descriptor;
438 ++index; 438 ++index;
439 } 439 }
440 440
441 std::cerr << "WARNING: LADSPAPluginFactory::getLADSPADescriptor: No such plugin as " << label.toStdString() << " in library " << soname.toStdString() << std::endl; 441 std::cerr << "WARNING: LADSPAPluginFactory::getLADSPADescriptor: No such plugin as " << label << " in library " << soname << std::endl;
442 442
443 return 0; 443 return 0;
444 } 444 }
445 445
446 void 446 void
447 LADSPAPluginFactory::loadLibrary(QString soName) 447 LADSPAPluginFactory::loadLibrary(QString soName)
448 { 448 {
449 void *libraryHandle = DLOPEN(soName, RTLD_NOW); 449 void *libraryHandle = DLOPEN(soName, RTLD_NOW);
450 if (libraryHandle) { 450 if (libraryHandle) {
451 m_libraryHandles[soName] = libraryHandle; 451 m_libraryHandles[soName] = libraryHandle;
452 std::cerr << "LADSPAPluginFactory::loadLibrary: Loaded library \"" << soName.toStdString() << "\"" << std::endl; 452 std::cerr << "LADSPAPluginFactory::loadLibrary: Loaded library \"" << soName << "\"" << std::endl;
453 return; 453 return;
454 } 454 }
455 455
456 if (QFileInfo(soName).exists()) { 456 if (QFileInfo(soName).exists()) {
457 DLERROR(); 457 DLERROR();
458 std::cerr << "LADSPAPluginFactory::loadLibrary: Library \"" << soName.toStdString() << "\" exists, but failed to load it" << std::endl; 458 std::cerr << "LADSPAPluginFactory::loadLibrary: Library \"" << soName << "\" exists, but failed to load it" << std::endl;
459 return; 459 return;
460 } 460 }
461 461
462 std::vector<QString> pathList = getPluginPath(); 462 std::vector<QString> pathList = getPluginPath();
463 463
466 466
467 for (std::vector<QString>::iterator i = pathList.begin(); 467 for (std::vector<QString>::iterator i = pathList.begin();
468 i != pathList.end(); ++i) { 468 i != pathList.end(); ++i) {
469 469
470 #ifdef DEBUG_LADSPA_PLUGIN_FACTORY 470 #ifdef DEBUG_LADSPA_PLUGIN_FACTORY
471 std::cerr << "Looking at: " << (*i).toStdString() << std::endl; 471 std::cerr << "Looking at: " << (*i) << std::endl;
472 #endif 472 #endif
473 473
474 QDir dir(*i, PLUGIN_GLOB, 474 QDir dir(*i, PLUGIN_GLOB,
475 QDir::Name | QDir::IgnoreCase, 475 QDir::Name | QDir::IgnoreCase,
476 QDir::Files | QDir::Readable); 476 QDir::Files | QDir::Readable);
477 477
478 if (QFileInfo(dir.filePath(fileName)).exists()) { 478 if (QFileInfo(dir.filePath(fileName)).exists()) {
479 #ifdef DEBUG_LADSPA_PLUGIN_FACTORY 479 #ifdef DEBUG_LADSPA_PLUGIN_FACTORY
480 std::cerr << "Loading: " << fileName.toStdString() << std::endl; 480 std::cerr << "Loading: " << fileName << std::endl;
481 #endif 481 #endif
482 libraryHandle = DLOPEN(dir.filePath(fileName), RTLD_NOW); 482 libraryHandle = DLOPEN(dir.filePath(fileName), RTLD_NOW);
483 if (libraryHandle) { 483 if (libraryHandle) {
484 m_libraryHandles[soName] = libraryHandle; 484 m_libraryHandles[soName] = libraryHandle;
485 return; 485 return;
488 488
489 for (unsigned int j = 0; j < dir.count(); ++j) { 489 for (unsigned int j = 0; j < dir.count(); ++j) {
490 QString file = dir.filePath(dir[j]); 490 QString file = dir.filePath(dir[j]);
491 if (QFileInfo(file).baseName() == base) { 491 if (QFileInfo(file).baseName() == base) {
492 #ifdef DEBUG_LADSPA_PLUGIN_FACTORY 492 #ifdef DEBUG_LADSPA_PLUGIN_FACTORY
493 std::cerr << "Loading: " << file.toStdString() << std::endl; 493 std::cerr << "Loading: " << file << std::endl;
494 #endif 494 #endif
495 libraryHandle = DLOPEN(file, RTLD_NOW); 495 libraryHandle = DLOPEN(file, RTLD_NOW);
496 if (libraryHandle) { 496 if (libraryHandle) {
497 m_libraryHandles[soName] = libraryHandle; 497 m_libraryHandles[soName] = libraryHandle;
498 return; 498 return;
499 } 499 }
500 } 500 }
501 } 501 }
502 } 502 }
503 503
504 std::cerr << "LADSPAPluginFactory::loadLibrary: Failed to locate plugin library \"" << soName.toStdString() << "\"" << std::endl; 504 std::cerr << "LADSPAPluginFactory::loadLibrary: Failed to locate plugin library \"" << soName << "\"" << std::endl;
505 } 505 }
506 506
507 void 507 void
508 LADSPAPluginFactory::unloadLibrary(QString soName) 508 LADSPAPluginFactory::unloadLibrary(QString soName)
509 { 509 {
510 LibraryHandleMap::iterator li = m_libraryHandles.find(soName); 510 LibraryHandleMap::iterator li = m_libraryHandles.find(soName);
511 if (li != m_libraryHandles.end()) { 511 if (li != m_libraryHandles.end()) {
512 // std::cerr << "unloading " << soname.toStdString() << std::endl; 512 // std::cerr << "unloading " << soname << std::endl;
513 DLCLOSE(m_libraryHandles[soName]); 513 DLCLOSE(m_libraryHandles[soName]);
514 m_libraryHandles.erase(li); 514 m_libraryHandles.erase(li);
515 } 515 }
516 } 516 }
517 517
682 { 682 {
683 void *libraryHandle = DLOPEN(soname, RTLD_LAZY); 683 void *libraryHandle = DLOPEN(soname, RTLD_LAZY);
684 684
685 if (!libraryHandle) { 685 if (!libraryHandle) {
686 std::cerr << "WARNING: LADSPAPluginFactory::discoverPlugins: couldn't load plugin library " 686 std::cerr << "WARNING: LADSPAPluginFactory::discoverPlugins: couldn't load plugin library "
687 << soname.toStdString() << " - " << DLERROR() << std::endl; 687 << soname << " - " << DLERROR() << std::endl;
688 return; 688 return;
689 } 689 }
690 690
691 LADSPA_Descriptor_Function fn = (LADSPA_Descriptor_Function) 691 LADSPA_Descriptor_Function fn = (LADSPA_Descriptor_Function)
692 DLSYM(libraryHandle, "ladspa_descriptor"); 692 DLSYM(libraryHandle, "ladspa_descriptor");
693 693
694 if (!fn) { 694 if (!fn) {
695 std::cerr << "WARNING: LADSPAPluginFactory::discoverPlugins: No descriptor function in " << soname.toStdString() << std::endl; 695 std::cerr << "WARNING: LADSPAPluginFactory::discoverPlugins: No descriptor function in " << soname << std::endl;
696 return; 696 return;
697 } 697 }
698 698
699 const LADSPA_Descriptor *descriptor = 0; 699 const LADSPA_Descriptor *descriptor = 0;
700 700
720 char *def_uri = 0; 720 char *def_uri = 0;
721 lrdf_defaults *defs = 0; 721 lrdf_defaults *defs = 0;
722 722
723 if (m_lrdfTaxonomy[descriptor->UniqueID] != "") { 723 if (m_lrdfTaxonomy[descriptor->UniqueID] != "") {
724 m_taxonomy[identifier] = m_lrdfTaxonomy[descriptor->UniqueID]; 724 m_taxonomy[identifier] = m_lrdfTaxonomy[descriptor->UniqueID];
725 // std::cerr << "set id \"" << identifier.toStdString() << "\" to cat \"" << m_taxonomy[identifier].toStdString() << "\" from LRDF" << std::endl; 725 // std::cerr << "set id \"" << identifier << "\" to cat \"" << m_taxonomy[identifier] << "\" from LRDF" << std::endl;
726 // std::cout << identifier.toStdString() << "::" << m_taxonomy[identifier].toStdString() << std::endl; 726 // std::cout << identifier << "::" << m_taxonomy[identifier] << std::endl;
727 } 727 }
728 728
729 QString category = m_taxonomy[identifier]; 729 QString category = m_taxonomy[identifier];
730 730
731 if (category == "" && descriptor->Name != 0) { 731 if (category == "" && descriptor->Name != 0) {
816 if (pluginPath[i].contains("/lib/")) { 816 if (pluginPath[i].contains("/lib/")) {
817 QString p(pluginPath[i]); 817 QString p(pluginPath[i]);
818 path.push_back(p); 818 path.push_back(p);
819 p.replace("/lib/", "/share/"); 819 p.replace("/lib/", "/share/");
820 path.push_back(p); 820 path.push_back(p);
821 // std::cerr << "LADSPAPluginFactory::generateFallbackCategories: path element " << p.toStdString() << std::endl; 821 // std::cerr << "LADSPAPluginFactory::generateFallbackCategories: path element " << p << std::endl;
822 } 822 }
823 path.push_back(pluginPath[i]); 823 path.push_back(pluginPath[i]);
824 // std::cerr << "LADSPAPluginFactory::generateFallbackCategories: path element " << pluginPath[i].toStdString() << std::endl; 824 // std::cerr << "LADSPAPluginFactory::generateFallbackCategories: path element " << pluginPath[i] << std::endl;
825 } 825 }
826 826
827 for (size_t i = 0; i < path.size(); ++i) { 827 for (size_t i = 0; i < path.size(); ++i) {
828 828
829 QDir dir(path[i], "*.cat"); 829 QDir dir(path[i], "*.cat");
830 830
831 // std::cerr << "LADSPAPluginFactory::generateFallbackCategories: directory " << path[i].toStdString() << " has " << dir.count() << " .cat files" << std::endl; 831 // std::cerr << "LADSPAPluginFactory::generateFallbackCategories: directory " << path[i] << " has " << dir.count() << " .cat files" << std::endl;
832 for (unsigned int j = 0; j < dir.count(); ++j) { 832 for (unsigned int j = 0; j < dir.count(); ++j) {
833 833
834 QFile file(path[i] + "/" + dir[j]); 834 QFile file(path[i] + "/" + dir[j]);
835 835
836 // std::cerr << "LADSPAPluginFactory::generateFallbackCategories: about to open " << (path[i].toStdString() + "/" + dir[j].toStdString()) << std::endl; 836 // std::cerr << "LADSPAPluginFactory::generateFallbackCategories: about to open " << (path[i].toStdString() + "/" + dir[j].toStdString()) << std::endl;
840 QTextStream stream(&file); 840 QTextStream stream(&file);
841 QString line; 841 QString line;
842 842
843 while (!stream.atEnd()) { 843 while (!stream.atEnd()) {
844 line = stream.readLine(); 844 line = stream.readLine();
845 // std::cerr << "line is: \"" << line.toStdString() << "\"" << std::endl; 845 // std::cerr << "line is: \"" << line << "\"" << std::endl;
846 QString id = PluginIdentifier::canonicalise 846 QString id = PluginIdentifier::canonicalise
847 (line.section("::", 0, 0)); 847 (line.section("::", 0, 0));
848 QString cat = line.section("::", 1, 1); 848 QString cat = line.section("::", 1, 1);
849 m_taxonomy[id] = cat; 849 m_taxonomy[id] = cat;
850 // std::cerr << "set id \"" << id.toStdString() << "\" to cat \"" << cat.toStdString() << "\"" << std::endl; 850 // std::cerr << "set id \"" << id << "\" to cat \"" << cat << "\"" << std::endl;
851 } 851 }
852 } 852 }
853 } 853 }
854 } 854 }
855 } 855 }