annotate plugin/PluginScan.cpp @ 1242:c401e738793f piper

Merge from branch 3.0-integration
author Chris Cannam
date Tue, 01 Nov 2016 14:08:57 +0000
parents c6bdf247016a
children 0492e54ccd56
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@1241 98 for (auto kp: m_kp) {
Chris@1241 99 auto c = kp->getCandidateLibrariesFor(kpt);
Chris@1241 100 for (auto s: c) candidates.push_back(s.c_str());
Chris@1241 101 }
Chris@1179 102 return candidates;
Chris@1178 103 }
Chris@1178 104
Chris@1178 105 QString
Chris@1178 106 PluginScan::getStartupFailureReport() const
Chris@1178 107 {
Chris@1179 108 if (!m_succeeded) {
Chris@1179 109 return QObject::tr("<b>Failed to scan for plugins</b>"
Chris@1181 110 "<p>Failed to scan for plugins at startup. Possibly "
Chris@1181 111 "the plugin checker helper program was not correctly "
Chris@1181 112 "installed alongside %1?</p>")
Chris@1181 113 .arg(QCoreApplication::applicationName());
Chris@1179 114 }
Chris@1241 115 if (m_kp.empty()) {
Chris@1179 116 return QObject::tr("<b>Did not scan for plugins</b>"
Chris@1179 117 "<p>Apparently no scan for plugins was attempted "
Chris@1179 118 "(internal error?)</p>");
Chris@1179 119 }
Chris@1179 120
Chris@1241 121 QString report;
Chris@1241 122 for (auto kp: m_kp) {
Chris@1241 123 report += QString::fromStdString(kp->getFailureReport());
Chris@1241 124 }
Chris@1179 125 if (report == "") {
Chris@1241 126 return report;
Chris@1179 127 }
Chris@1179 128
Chris@1179 129 return QObject::tr("<b>Failed to load plugins</b>"
Chris@1179 130 "<p>Failed to load one or more plugin libraries:</p>")
Chris@1241 131 + report
Chris@1181 132 + QObject::tr("<p>These plugins may be incompatible with the system, "
Chris@1181 133 "and will be ignored during this run of %1.</p>")
Chris@1181 134 .arg(QCoreApplication::applicationName());
Chris@1178 135 }
Chris@1178 136