comparison plugin/PiperVampPluginFactory.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 604b0b2a58e1
children 8f076d02569a
comparison
equal deleted inserted replaced
1245:0492e54ccd56 1246:75aefcc9f07d
48 48
49 PiperVampPluginFactory::PiperVampPluginFactory() 49 PiperVampPluginFactory::PiperVampPluginFactory()
50 { 50 {
51 QString serverName = "piper-vamp-simple-server"; 51 QString serverName = "piper-vamp-simple-server";
52 52
53 m_servers = HelperExecPath::getHelperExecutables(serverName); 53 HelperExecPath hep(HelperExecPath::AllInstalled);
54 54 m_servers = hep.getHelperExecutables(serverName);
55
56 for (auto n: m_servers) {
57 cerr << "NOTE: PiperVampPluginFactory: Found server: "
58 << n.executable << endl;
59 }
60
55 if (m_servers.empty()) { 61 if (m_servers.empty()) {
56 cerr << "NOTE: No Piper Vamp servers found in installation;" 62 cerr << "NOTE: No Piper Vamp servers found in installation;"
57 << " found none of the following:" << endl; 63 << " found none of the following:" << endl;
58 for (auto d: HelperExecPath::getHelperCandidatePaths(serverName)) { 64 for (auto d: hep.getHelperCandidatePaths(serverName)) {
59 cerr << "NOTE: " << d << endl; 65 cerr << "NOTE: " << d << endl;
60 } 66 }
61 }
62 }
63
64 QStringList
65 PiperVampPluginFactory::getServerSuffixes()
66 {
67 if (sizeof(void *) == 8) {
68 return { "-64", "", "-32" };
69 } else {
70 return { "", "-32" };
71 } 67 }
72 } 68 }
73 69
74 vector<QString> 70 vector<QString>
75 PiperVampPluginFactory::getPluginIdentifiers(QString &errorMessage) 71 PiperVampPluginFactory::getPluginIdentifiers(QString &errorMessage)
147 void 143 void
148 PiperVampPluginFactory::populate(QString &errorMessage) 144 PiperVampPluginFactory::populate(QString &errorMessage)
149 { 145 {
150 QString someError; 146 QString someError;
151 147
152 for (QString s: m_servers) { 148 for (auto s: m_servers) {
153 149
154 populateFrom(s, someError); 150 populateFrom(s, someError);
155 151
156 if (someError != "" && errorMessage == "") { 152 if (someError != "" && errorMessage == "") {
157 errorMessage = someError; 153 errorMessage = someError;
158 } 154 }
159 } 155 }
160 } 156 }
161 157
162 void 158 void
163 PiperVampPluginFactory::populateFrom(QString server, QString &errorMessage) 159 PiperVampPluginFactory::populateFrom(const HelperExecPath::HelperExec &server,
164 { 160 QString &errorMessage)
165 piper_vamp::client::ProcessQtTransport transport(server.toStdString(), 161 {
166 "capnp"); 162 QString tag = server.tag;
163 string executable = server.executable.toStdString();
164
165 PluginScan *scan = PluginScan::getInstance();
166 auto candidateLibraries =
167 scan->getCandidateLibrariesFor(PluginScan::VampPlugin);
168
169 vector<string> from;
170 for (const auto &c: candidateLibraries) {
171 if (c.helperTag == tag) {
172 string soname = QFileInfo(c.libraryPath).baseName().toStdString();
173 cerr << "INFO: For tag \"" << tag << "\" giving library " << soname << endl;
174 from.push_back(soname);
175 }
176 }
177
178 if (from.empty()) {
179 cerr << "PiperVampPluginFactory: No candidate libraries for tag \""
180 << tag << "\"";
181 if (scan->scanSucceeded()) {
182 // we have to assume that they all failed to load (i.e. we
183 // exclude them all) rather than sending an empty list
184 // (which would mean no exclusions)
185 cerr << ", skipping" << endl;
186 return;
187 } else {
188 cerr << ", but it seems the scan failed, so bumbling on anyway" << endl;
189 }
190 }
191
192 piper_vamp::client::ProcessQtTransport transport(executable, "capnp");
167 if (!transport.isOK()) { 193 if (!transport.isOK()) {
168 errorMessage = QObject::tr("Could not start external plugin host"); 194 errorMessage = QObject::tr("Could not start external plugin host");
169 return; 195 return;
170 } 196 }
171 197
182 errorMessage = QObject::tr("External plugin host invocation failed: %1") 208 errorMessage = QObject::tr("External plugin host invocation failed: %1")
183 .arg(e.what()); 209 .arg(e.what());
184 return; 210 return;
185 } 211 }
186 212
187 cerr << "PiperVampPluginFactory: server \"" << server << "\" lists " 213 cerr << "PiperVampPluginFactory: server \"" << executable << "\" lists "
188 << lr.available.size() << " plugin(s)" << endl; 214 << lr.available.size() << " plugin(s)" << endl;
189 215
190 for (const auto &pd: lr.available) { 216 for (const auto &pd: lr.available) {
191 217
192 QString identifier = 218 QString identifier =
196 // have it already, from a higher-priority server 222 // have it already, from a higher-priority server
197 // (e.g. 64-bit instead of 32-bit) 223 // (e.g. 64-bit instead of 32-bit)
198 continue; 224 continue;
199 } 225 }
200 226
201 m_origins[identifier] = server; 227 m_origins[identifier] = server.executable;
202 228
203 m_pluginData[identifier] = pd; 229 m_pluginData[identifier] = pd;
204 230
205 QStringList catlist; 231 QStringList catlist;
206 for (const auto &cs: pd.category) { 232 for (const auto &cs: pd.category) {