Chris@1178: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ Chris@1178: Chris@1178: /* Chris@1178: Sonic Visualiser Chris@1178: An audio file viewer and annotation editor. Chris@1178: Centre for Digital Music, Queen Mary, University of London. Chris@1178: Chris@1178: This program is free software; you can redistribute it and/or Chris@1178: modify it under the terms of the GNU General Public License as Chris@1178: published by the Free Software Foundation; either version 2 of the Chris@1178: License, or (at your option) any later version. See the file Chris@1178: COPYING included with this distribution for more information. Chris@1178: */ Chris@1178: Chris@1178: #include "PluginScan.h" Chris@1178: Chris@1178: #include "base/Debug.h" Chris@1178: Chris@1180: #include "checker/knownplugins.h" Chris@1180: Chris@1178: #include Chris@1178: Chris@1178: using std::string; Chris@1178: Chris@1180: class PluginScan::Logger : public PluginCandidates::LogCallback Chris@1180: { Chris@1180: protected: Chris@1180: void log(std::string message) { Chris@1180: SVDEBUG << "PluginScan: " << message; Chris@1180: } Chris@1180: }; Chris@1180: Chris@1180: PluginScan *PluginScan::getInstance() Chris@1180: { Chris@1178: static QMutex mutex; Chris@1178: static PluginScan *m_instance = 0; Chris@1178: mutex.lock(); Chris@1178: if (!m_instance) m_instance = new PluginScan(); Chris@1178: mutex.unlock(); Chris@1178: return m_instance; Chris@1178: } Chris@1178: Chris@1180: PluginScan::PluginScan() : m_kp(0), m_succeeded(false), m_logger(new Logger) { Chris@1178: } Chris@1178: Chris@1178: PluginScan::~PluginScan() { Chris@1178: delete m_kp; Chris@1180: delete m_logger; Chris@1178: } Chris@1178: Chris@1178: void Chris@1178: PluginScan::scan() Chris@1178: { Chris@1178: delete m_kp; Chris@1179: m_succeeded = false; Chris@1179: try { Chris@1180: m_kp = new KnownPlugins("./helper", m_logger); //!!! Chris@1179: m_succeeded = true; Chris@1179: } catch (const std::exception &e) { Chris@1179: cerr << "ERROR: PluginScan::scan: " << e.what() << endl; Chris@1179: m_kp = 0; Chris@1179: } Chris@1179: } Chris@1179: Chris@1179: QStringList Chris@1180: PluginScan::getCandidateLibrariesFor(PluginType type) const Chris@1179: { Chris@1180: KnownPlugins::PluginType kpt; Chris@1180: switch (type) { Chris@1180: case VampPlugin: kpt = KnownPlugins::VampPlugin; break; Chris@1180: case LADSPAPlugin: kpt = KnownPlugins::LADSPAPlugin; break; Chris@1180: case DSSIPlugin: kpt = KnownPlugins::DSSIPlugin; break; Chris@1180: default: throw std::logic_error("Inconsistency in plugin type enums"); Chris@1180: } Chris@1180: Chris@1179: QStringList candidates; Chris@1179: if (!m_kp) return candidates; Chris@1180: auto c = m_kp->getCandidateLibrariesFor(kpt); Chris@1179: for (auto s: c) candidates.push_back(s.c_str()); Chris@1179: return candidates; Chris@1178: } Chris@1178: Chris@1178: QString Chris@1178: PluginScan::getStartupFailureReport() const Chris@1178: { Chris@1179: if (!m_succeeded) { Chris@1179: return QObject::tr("Failed to scan for plugins" Chris@1179: "

Failed to scan for plugins at startup " Chris@1179: "(application installation problem?)

"); Chris@1179: } Chris@1179: if (!m_kp) { Chris@1179: return QObject::tr("Did not scan for plugins" Chris@1179: "

Apparently no scan for plugins was attempted " Chris@1179: "(internal error?)

"); Chris@1179: } Chris@1179: Chris@1178: string report = m_kp->getFailureReport(); Chris@1179: if (report == "") { Chris@1179: return QString(report.c_str()); Chris@1179: } Chris@1179: Chris@1179: return QObject::tr("Failed to load plugins" Chris@1179: "

Failed to load one or more plugin libraries:

") Chris@1179: + QString(report.c_str()); Chris@1178: } Chris@1178: