Mercurial > hg > svcore
comparison plugin/PluginScan.cpp @ 1206:659372323b45 tony-2.0-integration
Merge latest SV 3.0 branch code
author | Chris Cannam |
---|---|
date | Fri, 19 Aug 2016 15:58:57 +0100 |
parents | 2f628dc9a0b0 |
children | c0cec4659784 |
comparison
equal
deleted
inserted
replaced
1136:e94719f941ba | 1206:659372323b45 |
---|---|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ | |
2 | |
3 /* | |
4 Sonic Visualiser | |
5 An audio file viewer and annotation editor. | |
6 Centre for Digital Music, Queen Mary, University of London. | |
7 | |
8 This program is free software; you can redistribute it and/or | |
9 modify it under the terms of the GNU General Public License as | |
10 published by the Free Software Foundation; either version 2 of the | |
11 License, or (at your option) any later version. See the file | |
12 COPYING included with this distribution for more information. | |
13 */ | |
14 | |
15 #include "PluginScan.h" | |
16 | |
17 #include "base/Debug.h" | |
18 | |
19 #include "checker/knownplugins.h" | |
20 | |
21 #include <QMutex> | |
22 #include <QCoreApplication> | |
23 | |
24 using std::string; | |
25 | |
26 class PluginScan::Logger : public PluginCandidates::LogCallback | |
27 { | |
28 protected: | |
29 void log(std::string message) { | |
30 SVDEBUG << "PluginScan: " << message; | |
31 } | |
32 }; | |
33 | |
34 PluginScan *PluginScan::getInstance() | |
35 { | |
36 static QMutex mutex; | |
37 static PluginScan *m_instance = 0; | |
38 mutex.lock(); | |
39 if (!m_instance) m_instance = new PluginScan(); | |
40 mutex.unlock(); | |
41 return m_instance; | |
42 } | |
43 | |
44 PluginScan::PluginScan() : m_kp(0), m_succeeded(false), m_logger(new Logger) { | |
45 } | |
46 | |
47 PluginScan::~PluginScan() { | |
48 delete m_kp; | |
49 delete m_logger; | |
50 } | |
51 | |
52 void | |
53 PluginScan::scan(QString helperExecutablePath) | |
54 { | |
55 delete m_kp; | |
56 m_succeeded = false; | |
57 try { | |
58 m_kp = new KnownPlugins(helperExecutablePath.toStdString(), m_logger); | |
59 m_succeeded = true; | |
60 } catch (const std::exception &e) { | |
61 cerr << "ERROR: PluginScan::scan: " << e.what() << endl; | |
62 m_kp = 0; | |
63 } | |
64 } | |
65 | |
66 QStringList | |
67 PluginScan::getCandidateLibrariesFor(PluginType type) const | |
68 { | |
69 KnownPlugins::PluginType kpt; | |
70 switch (type) { | |
71 case VampPlugin: kpt = KnownPlugins::VampPlugin; break; | |
72 case LADSPAPlugin: kpt = KnownPlugins::LADSPAPlugin; break; | |
73 case DSSIPlugin: kpt = KnownPlugins::DSSIPlugin; break; | |
74 default: throw std::logic_error("Inconsistency in plugin type enums"); | |
75 } | |
76 | |
77 QStringList candidates; | |
78 if (!m_kp) return candidates; | |
79 auto c = m_kp->getCandidateLibrariesFor(kpt); | |
80 for (auto s: c) candidates.push_back(s.c_str()); | |
81 return candidates; | |
82 } | |
83 | |
84 QString | |
85 PluginScan::getStartupFailureReport() const | |
86 { | |
87 if (!m_succeeded) { | |
88 return QObject::tr("<b>Failed to scan for plugins</b>" | |
89 "<p>Failed to scan for plugins at startup. Possibly " | |
90 "the plugin checker helper program was not correctly " | |
91 "installed alongside %1?</p>") | |
92 .arg(QCoreApplication::applicationName()); | |
93 } | |
94 if (!m_kp) { | |
95 return QObject::tr("<b>Did not scan for plugins</b>" | |
96 "<p>Apparently no scan for plugins was attempted " | |
97 "(internal error?)</p>"); | |
98 } | |
99 | |
100 string report = m_kp->getFailureReport(); | |
101 if (report == "") { | |
102 return QString(report.c_str()); | |
103 } | |
104 | |
105 return QObject::tr("<b>Failed to load plugins</b>" | |
106 "<p>Failed to load one or more plugin libraries:</p>") | |
107 + QString(report.c_str()) | |
108 + QObject::tr("<p>These plugins may be incompatible with the system, " | |
109 "and will be ignored during this run of %1.</p>") | |
110 .arg(QCoreApplication::applicationName()); | |
111 } | |
112 |