annotate plugin/PluginScan.cpp @ 1245:0492e54ccd56 piper

Logging; use only first ("native") helper for non-Vamp plugins
author Chris Cannam
date Tue, 01 Nov 2016 16:02:15 +0000
parents c6bdf247016a
children 75aefcc9f07d
rev   line source
Chris@1178 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@1178 2
Chris@1178 3 /*
Chris@1178 4 Sonic Visualiser
Chris@1178 5 An audio file viewer and annotation editor.
Chris@1178 6 Centre for Digital Music, Queen Mary, University of London.
Chris@1178 7
Chris@1178 8 This program is free software; you can redistribute it and/or
Chris@1178 9 modify it under the terms of the GNU General Public License as
Chris@1178 10 published by the Free Software Foundation; either version 2 of the
Chris@1178 11 License, or (at your option) any later version. See the file
Chris@1178 12 COPYING included with this distribution for more information.
Chris@1178 13 */
Chris@1178 14
Chris@1178 15 #include "PluginScan.h"
Chris@1178 16
Chris@1178 17 #include "base/Debug.h"
Chris@1241 18 #include "base/HelperExecPath.h"
Chris@1178 19
Chris@1180 20 #include "checker/knownplugins.h"
Chris@1180 21
Chris@1178 22 #include <QMutex>
Chris@1181 23 #include <QCoreApplication>
Chris@1178 24
Chris@1178 25 using std::string;
Chris@1178 26
cannam@1231 27 //#define DEBUG_PLUGIN_SCAN 1
cannam@1231 28
Chris@1180 29 class PluginScan::Logger : public PluginCandidates::LogCallback
Chris@1180 30 {
Chris@1180 31 protected:
Chris@1180 32 void log(std::string message) {
cannam@1231 33 #ifdef DEBUG_PLUGIN_SCAN
cannam@1231 34 cerr << "PluginScan: " << message;
cannam@1231 35 #endif
Chris@1180 36 SVDEBUG << "PluginScan: " << message;
Chris@1180 37 }
Chris@1180 38 };
Chris@1180 39
Chris@1180 40 PluginScan *PluginScan::getInstance()
Chris@1180 41 {
Chris@1178 42 static QMutex mutex;
Chris@1178 43 static PluginScan *m_instance = 0;
Chris@1178 44 mutex.lock();
Chris@1178 45 if (!m_instance) m_instance = new PluginScan();
Chris@1178 46 mutex.unlock();
Chris@1178 47 return m_instance;
Chris@1178 48 }
Chris@1178 49
Chris@1180 50 PluginScan::PluginScan() : m_kp(0), m_succeeded(false), m_logger(new Logger) {
Chris@1178 51 }
Chris@1178 52
Chris@1178 53 PluginScan::~PluginScan() {
Chris@1241 54 clear();
Chris@1180 55 delete m_logger;
Chris@1178 56 }
Chris@1178 57
Chris@1178 58 void
Chris@1241 59 PluginScan::scan()
Chris@1178 60 {
Chris@1241 61 QStringList helperPaths =
Chris@1241 62 HelperExecPath::getHelperExecutables("plugin-checker-helper");
Chris@1241 63
Chris@1241 64 clear();
Chris@1241 65
Chris@1241 66 for (auto p: helperPaths) {
Chris@1241 67 try {
Chris@1241 68 KnownPlugins *kp = new KnownPlugins(p.toStdString(), m_logger);
Chris@1241 69 m_kp.push_back(kp);
Chris@1241 70 m_succeeded = true;
Chris@1241 71 } catch (const std::exception &e) {
Chris@1241 72 cerr << "ERROR: PluginScan::scan: " << e.what()
Chris@1241 73 << " (with helper path = " << p << ")" << endl;
Chris@1241 74 }
Chris@1241 75 }
Chris@1241 76 }
Chris@1241 77
Chris@1241 78 void
Chris@1241 79 PluginScan::clear()
Chris@1241 80 {
Chris@1241 81 for (auto &p: m_kp) delete p;
Chris@1241 82 m_kp.clear();
Chris@1179 83 m_succeeded = false;
Chris@1179 84 }
Chris@1179 85
Chris@1179 86 QStringList
Chris@1180 87 PluginScan::getCandidateLibrariesFor(PluginType type) const
Chris@1179 88 {
Chris@1180 89 KnownPlugins::PluginType kpt;
Chris@1180 90 switch (type) {
Chris@1180 91 case VampPlugin: kpt = KnownPlugins::VampPlugin; break;
Chris@1180 92 case LADSPAPlugin: kpt = KnownPlugins::LADSPAPlugin; break;
Chris@1180 93 case DSSIPlugin: kpt = KnownPlugins::DSSIPlugin; break;
Chris@1180 94 default: throw std::logic_error("Inconsistency in plugin type enums");
Chris@1180 95 }
Chris@1180 96
Chris@1179 97 QStringList candidates;
Chris@1245 98
Chris@1241 99 for (auto kp: m_kp) {
Chris@1245 100
Chris@1241 101 auto c = kp->getCandidateLibrariesFor(kpt);
Chris@1245 102
Chris@1245 103 std::cerr << "PluginScan: helper \"" << kp->getHelperExecutableName()
Chris@1245 104 << "\" likes " << c.size() << " libraries of type "
Chris@1245 105 << kp->getTagFor(kpt) << std::endl;
Chris@1245 106
Chris@1241 107 for (auto s: c) candidates.push_back(s.c_str());
Chris@1245 108
Chris@1245 109 if (type != VampPlugin) {
Chris@1245 110 // We are only interested in querying multiple helpers
Chris@1245 111 // when dealing with Vamp plugins, for which we can use
Chris@1245 112 // external servers and so in some cases can support
Chris@1245 113 // additional architectures. Other plugin formats are
Chris@1245 114 // loaded directly and so must match the host, which is
Chris@1245 115 // what the first helper is supposed to handle -- so
Chris@1245 116 // break after the first one if not querying Vamp
Chris@1245 117 break;
Chris@1245 118 }
Chris@1241 119 }
Chris@1245 120
Chris@1179 121 return candidates;
Chris@1178 122 }
Chris@1178 123
Chris@1178 124 QString
Chris@1178 125 PluginScan::getStartupFailureReport() const
Chris@1178 126 {
Chris@1179 127 if (!m_succeeded) {
Chris@1179 128 return QObject::tr("<b>Failed to scan for plugins</b>"
Chris@1181 129 "<p>Failed to scan for plugins at startup. Possibly "
Chris@1181 130 "the plugin checker helper program was not correctly "
Chris@1181 131 "installed alongside %1?</p>")
Chris@1181 132 .arg(QCoreApplication::applicationName());
Chris@1179 133 }
Chris@1241 134 if (m_kp.empty()) {
Chris@1179 135 return QObject::tr("<b>Did not scan for plugins</b>"
Chris@1179 136 "<p>Apparently no scan for plugins was attempted "
Chris@1179 137 "(internal error?)</p>");
Chris@1179 138 }
Chris@1179 139
Chris@1241 140 QString report;
Chris@1241 141 for (auto kp: m_kp) {
Chris@1241 142 report += QString::fromStdString(kp->getFailureReport());
Chris@1241 143 }
Chris@1179 144 if (report == "") {
Chris@1241 145 return report;
Chris@1179 146 }
Chris@1179 147
Chris@1179 148 return QObject::tr("<b>Failed to load plugins</b>"
Chris@1179 149 "<p>Failed to load one or more plugin libraries:</p>")
Chris@1241 150 + report
Chris@1181 151 + QObject::tr("<p>These plugins may be incompatible with the system, "
Chris@1181 152 "and will be ignored during this run of %1.</p>")
Chris@1181 153 .arg(QCoreApplication::applicationName());
Chris@1178 154 }
Chris@1178 155