Mercurial > hg > svcore
comparison plugin/PluginScan.cpp @ 1246:75aefcc9f07d piper
Use plugin scan results to inform the list requests issued to Piper servers
author | Chris Cannam |
---|---|
date | Thu, 03 Nov 2016 14:14:09 +0000 |
parents | 0492e54ccd56 |
children | 8f076d02569a |
comparison
equal
deleted
inserted
replaced
1245:0492e54ccd56 | 1246:75aefcc9f07d |
---|---|
13 */ | 13 */ |
14 | 14 |
15 #include "PluginScan.h" | 15 #include "PluginScan.h" |
16 | 16 |
17 #include "base/Debug.h" | 17 #include "base/Debug.h" |
18 #include "base/Preferences.h" | |
18 #include "base/HelperExecPath.h" | 19 #include "base/HelperExecPath.h" |
19 | 20 |
20 #include "checker/knownplugins.h" | 21 #include "checker/knownplugins.h" |
21 | 22 |
22 #include <QMutex> | 23 #include <QMutex> |
45 if (!m_instance) m_instance = new PluginScan(); | 46 if (!m_instance) m_instance = new PluginScan(); |
46 mutex.unlock(); | 47 mutex.unlock(); |
47 return m_instance; | 48 return m_instance; |
48 } | 49 } |
49 | 50 |
50 PluginScan::PluginScan() : m_kp(0), m_succeeded(false), m_logger(new Logger) { | 51 PluginScan::PluginScan() : m_succeeded(false), m_logger(new Logger) { |
51 } | 52 } |
52 | 53 |
53 PluginScan::~PluginScan() { | 54 PluginScan::~PluginScan() { |
55 QMutexLocker locker(&m_mutex); | |
54 clear(); | 56 clear(); |
55 delete m_logger; | 57 delete m_logger; |
56 } | 58 } |
57 | 59 |
58 void | 60 void |
59 PluginScan::scan() | 61 PluginScan::scan() |
60 { | 62 { |
61 QStringList helperPaths = | 63 QMutexLocker locker(&m_mutex); |
62 HelperExecPath::getHelperExecutables("plugin-checker-helper"); | 64 |
65 bool inProcess = Preferences::getInstance()->getRunPluginsInProcess(); | |
66 | |
67 HelperExecPath hep(inProcess ? | |
68 HelperExecPath::NativeArchitectureOnly : | |
69 HelperExecPath::AllInstalled); | |
70 | |
71 QString helperName("plugin-checker-helper"); | |
72 auto helpers = hep.getHelperExecutables(helperName); | |
63 | 73 |
64 clear(); | 74 clear(); |
65 | 75 |
66 for (auto p: helperPaths) { | 76 for (auto p: helpers) { |
77 cerr << "NOTE: PluginScan: Found helper: " << p.executable << endl; | |
78 } | |
79 | |
80 if (helpers.empty()) { | |
81 cerr << "NOTE: No plugin checker helpers found in installation;" | |
82 << " found none of the following:" << endl; | |
83 for (auto d: hep.getHelperCandidatePaths(helperName)) { | |
84 cerr << "NOTE: " << d << endl; | |
85 } | |
86 } | |
87 | |
88 for (auto p: helpers) { | |
67 try { | 89 try { |
68 KnownPlugins *kp = new KnownPlugins(p.toStdString(), m_logger); | 90 KnownPlugins *kp = new KnownPlugins |
69 m_kp.push_back(kp); | 91 (p.executable.toStdString(), m_logger); |
92 if (m_kp.find(p.tag) != m_kp.end()) { | |
93 cerr << "WARNING: PluginScan::scan: Duplicate tag " << p.tag | |
94 << " for helpers" << endl; | |
95 continue; | |
96 } | |
97 m_kp[p.tag] = kp; | |
70 m_succeeded = true; | 98 m_succeeded = true; |
71 } catch (const std::exception &e) { | 99 } catch (const std::exception &e) { |
72 cerr << "ERROR: PluginScan::scan: " << e.what() | 100 cerr << "ERROR: PluginScan::scan: " << e.what() |
73 << " (with helper path = " << p << ")" << endl; | 101 << " (with helper path = " << p.executable << ")" << endl; |
74 } | 102 } |
75 } | 103 } |
104 } | |
105 | |
106 bool | |
107 PluginScan::scanSucceeded() const | |
108 { | |
109 QMutexLocker locker(&m_mutex); | |
110 return m_succeeded; | |
76 } | 111 } |
77 | 112 |
78 void | 113 void |
79 PluginScan::clear() | 114 PluginScan::clear() |
80 { | 115 { |
81 for (auto &p: m_kp) delete p; | 116 for (auto &p: m_kp) { |
117 delete p.second; | |
118 } | |
82 m_kp.clear(); | 119 m_kp.clear(); |
83 m_succeeded = false; | 120 m_succeeded = false; |
84 } | 121 } |
85 | 122 |
86 QStringList | 123 QList<PluginScan::Candidate> |
87 PluginScan::getCandidateLibrariesFor(PluginType type) const | 124 PluginScan::getCandidateLibrariesFor(PluginType type) const |
88 { | 125 { |
126 QMutexLocker locker(&m_mutex); | |
127 | |
89 KnownPlugins::PluginType kpt; | 128 KnownPlugins::PluginType kpt; |
90 switch (type) { | 129 switch (type) { |
91 case VampPlugin: kpt = KnownPlugins::VampPlugin; break; | 130 case VampPlugin: kpt = KnownPlugins::VampPlugin; break; |
92 case LADSPAPlugin: kpt = KnownPlugins::LADSPAPlugin; break; | 131 case LADSPAPlugin: kpt = KnownPlugins::LADSPAPlugin; break; |
93 case DSSIPlugin: kpt = KnownPlugins::DSSIPlugin; break; | 132 case DSSIPlugin: kpt = KnownPlugins::DSSIPlugin; break; |
94 default: throw std::logic_error("Inconsistency in plugin type enums"); | 133 default: throw std::logic_error("Inconsistency in plugin type enums"); |
95 } | 134 } |
96 | 135 |
97 QStringList candidates; | 136 QList<Candidate> candidates; |
98 | 137 |
99 for (auto kp: m_kp) { | 138 for (auto rec: m_kp) { |
100 | 139 |
140 KnownPlugins *kp = rec.second; | |
141 | |
101 auto c = kp->getCandidateLibrariesFor(kpt); | 142 auto c = kp->getCandidateLibrariesFor(kpt); |
102 | 143 |
103 std::cerr << "PluginScan: helper \"" << kp->getHelperExecutableName() | 144 std::cerr << "PluginScan: helper \"" << kp->getHelperExecutableName() |
104 << "\" likes " << c.size() << " libraries of type " | 145 << "\" likes " << c.size() << " libraries of type " |
105 << kp->getTagFor(kpt) << std::endl; | 146 << kp->getTagFor(kpt) << std::endl; |
106 | 147 |
107 for (auto s: c) candidates.push_back(s.c_str()); | 148 for (auto s: c) { |
149 candidates.push_back({ s.c_str(), rec.first }); | |
150 } | |
108 | 151 |
109 if (type != VampPlugin) { | 152 if (type != VampPlugin) { |
110 // We are only interested in querying multiple helpers | 153 // We are only interested in querying multiple helpers |
111 // when dealing with Vamp plugins, for which we can use | 154 // when dealing with Vamp plugins, for which we can use |
112 // external servers and so in some cases can support | 155 // external servers and so in some cases can support |
122 } | 165 } |
123 | 166 |
124 QString | 167 QString |
125 PluginScan::getStartupFailureReport() const | 168 PluginScan::getStartupFailureReport() const |
126 { | 169 { |
170 QMutexLocker locker(&m_mutex); | |
171 | |
127 if (!m_succeeded) { | 172 if (!m_succeeded) { |
128 return QObject::tr("<b>Failed to scan for plugins</b>" | 173 return QObject::tr("<b>Failed to scan for plugins</b>" |
129 "<p>Failed to scan for plugins at startup. Possibly " | 174 "<p>Failed to scan for plugins at startup. Possibly " |
130 "the plugin checker helper program was not correctly " | 175 "the plugin checker helper program was not correctly " |
131 "installed alongside %1?</p>") | 176 "installed alongside %1?</p>") |
137 "(internal error?)</p>"); | 182 "(internal error?)</p>"); |
138 } | 183 } |
139 | 184 |
140 QString report; | 185 QString report; |
141 for (auto kp: m_kp) { | 186 for (auto kp: m_kp) { |
142 report += QString::fromStdString(kp->getFailureReport()); | 187 report += QString::fromStdString(kp.second->getFailureReport()); |
143 } | 188 } |
144 if (report == "") { | 189 if (report == "") { |
145 return report; | 190 return report; |
146 } | 191 } |
147 | 192 |