annotate plugin/PluginScan.cpp @ 1219:794b64e62e58 msvc2015_64

Tidy and re-fix for Linux
author Chris Cannam
date Wed, 19 Oct 2016 09:11:51 +0100
parents 2f628dc9a0b0
children c0cec4659784
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@1178 18
Chris@1180 19 #include "checker/knownplugins.h"
Chris@1180 20
Chris@1178 21 #include <QMutex>
Chris@1181 22 #include <QCoreApplication>
Chris@1178 23
Chris@1178 24 using std::string;
Chris@1178 25
Chris@1180 26 class PluginScan::Logger : public PluginCandidates::LogCallback
Chris@1180 27 {
Chris@1180 28 protected:
Chris@1180 29 void log(std::string message) {
Chris@1180 30 SVDEBUG << "PluginScan: " << message;
Chris@1180 31 }
Chris@1180 32 };
Chris@1180 33
Chris@1180 34 PluginScan *PluginScan::getInstance()
Chris@1180 35 {
Chris@1178 36 static QMutex mutex;
Chris@1178 37 static PluginScan *m_instance = 0;
Chris@1178 38 mutex.lock();
Chris@1178 39 if (!m_instance) m_instance = new PluginScan();
Chris@1178 40 mutex.unlock();
Chris@1178 41 return m_instance;
Chris@1178 42 }
Chris@1178 43
Chris@1180 44 PluginScan::PluginScan() : m_kp(0), m_succeeded(false), m_logger(new Logger) {
Chris@1178 45 }
Chris@1178 46
Chris@1178 47 PluginScan::~PluginScan() {
Chris@1178 48 delete m_kp;
Chris@1180 49 delete m_logger;
Chris@1178 50 }
Chris@1178 51
Chris@1178 52 void
Chris@1181 53 PluginScan::scan(QString helperExecutablePath)
Chris@1178 54 {
Chris@1178 55 delete m_kp;
Chris@1179 56 m_succeeded = false;
Chris@1179 57 try {
Chris@1181 58 m_kp = new KnownPlugins(helperExecutablePath.toStdString(), m_logger);
Chris@1179 59 m_succeeded = true;
Chris@1179 60 } catch (const std::exception &e) {
Chris@1179 61 cerr << "ERROR: PluginScan::scan: " << e.what() << endl;
Chris@1179 62 m_kp = 0;
Chris@1179 63 }
Chris@1179 64 }
Chris@1179 65
Chris@1179 66 QStringList
Chris@1180 67 PluginScan::getCandidateLibrariesFor(PluginType type) const
Chris@1179 68 {
Chris@1180 69 KnownPlugins::PluginType kpt;
Chris@1180 70 switch (type) {
Chris@1180 71 case VampPlugin: kpt = KnownPlugins::VampPlugin; break;
Chris@1180 72 case LADSPAPlugin: kpt = KnownPlugins::LADSPAPlugin; break;
Chris@1180 73 case DSSIPlugin: kpt = KnownPlugins::DSSIPlugin; break;
Chris@1180 74 default: throw std::logic_error("Inconsistency in plugin type enums");
Chris@1180 75 }
Chris@1180 76
Chris@1179 77 QStringList candidates;
Chris@1179 78 if (!m_kp) return candidates;
Chris@1180 79 auto c = m_kp->getCandidateLibrariesFor(kpt);
Chris@1179 80 for (auto s: c) candidates.push_back(s.c_str());
Chris@1179 81 return candidates;
Chris@1178 82 }
Chris@1178 83
Chris@1178 84 QString
Chris@1178 85 PluginScan::getStartupFailureReport() const
Chris@1178 86 {
Chris@1179 87 if (!m_succeeded) {
Chris@1179 88 return QObject::tr("<b>Failed to scan for plugins</b>"
Chris@1181 89 "<p>Failed to scan for plugins at startup. Possibly "
Chris@1181 90 "the plugin checker helper program was not correctly "
Chris@1181 91 "installed alongside %1?</p>")
Chris@1181 92 .arg(QCoreApplication::applicationName());
Chris@1179 93 }
Chris@1179 94 if (!m_kp) {
Chris@1179 95 return QObject::tr("<b>Did not scan for plugins</b>"
Chris@1179 96 "<p>Apparently no scan for plugins was attempted "
Chris@1179 97 "(internal error?)</p>");
Chris@1179 98 }
Chris@1179 99
Chris@1178 100 string report = m_kp->getFailureReport();
Chris@1179 101 if (report == "") {
Chris@1179 102 return QString(report.c_str());
Chris@1179 103 }
Chris@1179 104
Chris@1179 105 return QObject::tr("<b>Failed to load plugins</b>"
Chris@1179 106 "<p>Failed to load one or more plugin libraries:</p>")
Chris@1181 107 + QString(report.c_str())
Chris@1181 108 + QObject::tr("<p>These plugins may be incompatible with the system, "
Chris@1181 109 "and will be ignored during this run of %1.</p>")
Chris@1181 110 .arg(QCoreApplication::applicationName());
Chris@1178 111 }
Chris@1178 112