comparison plugin/PluginScan.cpp @ 1241:c6bdf247016a 3.0-integration

Support multiple plugin checker helpers, as for multiple piper servers
author Chris Cannam
date Tue, 01 Nov 2016 14:06:47 +0000
parents c0cec4659784
children 0492e54ccd56
comparison
equal deleted inserted replaced
1240:42a4b058f8ba 1241:c6bdf247016a
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/HelperExecPath.h"
18 19
19 #include "checker/knownplugins.h" 20 #include "checker/knownplugins.h"
20 21
21 #include <QMutex> 22 #include <QMutex>
22 #include <QCoreApplication> 23 #include <QCoreApplication>
48 49
49 PluginScan::PluginScan() : m_kp(0), m_succeeded(false), m_logger(new Logger) { 50 PluginScan::PluginScan() : m_kp(0), m_succeeded(false), m_logger(new Logger) {
50 } 51 }
51 52
52 PluginScan::~PluginScan() { 53 PluginScan::~PluginScan() {
53 delete m_kp; 54 clear();
54 delete m_logger; 55 delete m_logger;
55 } 56 }
56 57
57 void 58 void
58 PluginScan::scan(QString helperExecutablePath) 59 PluginScan::scan()
59 { 60 {
60 delete m_kp; 61 QStringList helperPaths =
62 HelperExecPath::getHelperExecutables("plugin-checker-helper");
63
64 clear();
65
66 for (auto p: helperPaths) {
67 try {
68 KnownPlugins *kp = new KnownPlugins(p.toStdString(), m_logger);
69 m_kp.push_back(kp);
70 m_succeeded = true;
71 } catch (const std::exception &e) {
72 cerr << "ERROR: PluginScan::scan: " << e.what()
73 << " (with helper path = " << p << ")" << endl;
74 }
75 }
76 }
77
78 void
79 PluginScan::clear()
80 {
81 for (auto &p: m_kp) delete p;
82 m_kp.clear();
61 m_succeeded = false; 83 m_succeeded = false;
62 try {
63 m_kp = new KnownPlugins(helperExecutablePath.toStdString(), m_logger);
64 m_succeeded = true;
65 } catch (const std::exception &e) {
66 cerr << "ERROR: PluginScan::scan: " << e.what() << endl;
67 m_kp = 0;
68 }
69 } 84 }
70 85
71 QStringList 86 QStringList
72 PluginScan::getCandidateLibrariesFor(PluginType type) const 87 PluginScan::getCandidateLibrariesFor(PluginType type) const
73 { 88 {
78 case DSSIPlugin: kpt = KnownPlugins::DSSIPlugin; break; 93 case DSSIPlugin: kpt = KnownPlugins::DSSIPlugin; break;
79 default: throw std::logic_error("Inconsistency in plugin type enums"); 94 default: throw std::logic_error("Inconsistency in plugin type enums");
80 } 95 }
81 96
82 QStringList candidates; 97 QStringList candidates;
83 if (!m_kp) return candidates; 98 for (auto kp: m_kp) {
84 auto c = m_kp->getCandidateLibrariesFor(kpt); 99 auto c = kp->getCandidateLibrariesFor(kpt);
85 for (auto s: c) candidates.push_back(s.c_str()); 100 for (auto s: c) candidates.push_back(s.c_str());
101 }
86 return candidates; 102 return candidates;
87 } 103 }
88 104
89 QString 105 QString
90 PluginScan::getStartupFailureReport() const 106 PluginScan::getStartupFailureReport() const
94 "<p>Failed to scan for plugins at startup. Possibly " 110 "<p>Failed to scan for plugins at startup. Possibly "
95 "the plugin checker helper program was not correctly " 111 "the plugin checker helper program was not correctly "
96 "installed alongside %1?</p>") 112 "installed alongside %1?</p>")
97 .arg(QCoreApplication::applicationName()); 113 .arg(QCoreApplication::applicationName());
98 } 114 }
99 if (!m_kp) { 115 if (m_kp.empty()) {
100 return QObject::tr("<b>Did not scan for plugins</b>" 116 return QObject::tr("<b>Did not scan for plugins</b>"
101 "<p>Apparently no scan for plugins was attempted " 117 "<p>Apparently no scan for plugins was attempted "
102 "(internal error?)</p>"); 118 "(internal error?)</p>");
103 } 119 }
104 120
105 string report = m_kp->getFailureReport(); 121 QString report;
122 for (auto kp: m_kp) {
123 report += QString::fromStdString(kp->getFailureReport());
124 }
106 if (report == "") { 125 if (report == "") {
107 return QString(report.c_str()); 126 return report;
108 } 127 }
109 128
110 return QObject::tr("<b>Failed to load plugins</b>" 129 return QObject::tr("<b>Failed to load plugins</b>"
111 "<p>Failed to load one or more plugin libraries:</p>") 130 "<p>Failed to load one or more plugin libraries:</p>")
112 + QString(report.c_str()) 131 + report
113 + QObject::tr("<p>These plugins may be incompatible with the system, " 132 + QObject::tr("<p>These plugins may be incompatible with the system, "
114 "and will be ignored during this run of %1.</p>") 133 "and will be ignored during this run of %1.</p>")
115 .arg(QCoreApplication::applicationName()); 134 .arg(QCoreApplication::applicationName());
116 } 135 }
117 136