comparison plugin/PiperVampPluginFactory.cpp @ 1227:5d886b7b4029 piper

Error reporting for Piper server startup
author Chris Cannam
date Fri, 21 Oct 2016 16:24:30 +0100
parents ba16388b937d
children fac1666e429b
comparison
equal deleted inserted replaced
1226:91ff08313375 1227:5d886b7b4029
30 30
31 #include <QDir> 31 #include <QDir>
32 #include <QFile> 32 #include <QFile>
33 #include <QFileInfo> 33 #include <QFileInfo>
34 #include <QTextStream> 34 #include <QTextStream>
35 #include <QCoreApplication>
35 36
36 #include <iostream> 37 #include <iostream>
37 38
38 #include "base/Profiler.h" 39 #include "base/Profiler.h"
39 40
43 using namespace std; 44 using namespace std;
44 45
45 //#define DEBUG_PLUGIN_SCAN_AND_INSTANTIATE 1 46 //#define DEBUG_PLUGIN_SCAN_AND_INSTANTIATE 1
46 47
47 PiperVampPluginFactory::PiperVampPluginFactory() : 48 PiperVampPluginFactory::PiperVampPluginFactory() :
48 m_serverName("piper-cpp/bin/piper-vamp-server") //!!! 49 // No server unless we find one - don't run arbitrary stuff from the path:
50 m_serverName()
49 { 51 {
52 // Server must exist either in the same directory as this one or
53 // (preferably) a subdirectory called "piper-bin".
54 //!!! todo: merge this with plugin scan checker thingy used in main.cpp?
55 QString myDir = QCoreApplication::applicationDirPath();
56 QString name = "piper-vamp-server";
57 QString path = myDir + "/piper-bin/" + name;
58 QString suffix = "";
59 #ifdef _WIN32
60 suffix = ".exe";
61 #endif
62 if (!QFile(path + suffix).exists()) {
63 cerr << "NOTE: Piper Vamp server not found at " << (path + suffix)
64 << ", trying in my own directory" << endl;
65 path = myDir + "/" + name;
66 }
67 if (!QFile(path + suffix).exists()) {
68 cerr << "NOTE: Piper Vamp server not found at " << (path + suffix)
69 << endl;
70 } else {
71 m_serverName = (path + suffix).toStdString();
72 }
50 } 73 }
51 74
52 vector<QString> 75 vector<QString>
53 PiperVampPluginFactory::getPluginIdentifiers() 76 PiperVampPluginFactory::getPluginIdentifiers(QString &errorMessage)
54 { 77 {
55 Profiler profiler("PiperVampPluginFactory::getPluginIdentifiers"); 78 Profiler profiler("PiperVampPluginFactory::getPluginIdentifiers");
56 79
57 QMutexLocker locker(&m_mutex); 80 QMutexLocker locker(&m_mutex);
58 81
82 if (m_serverName == "") {
83 errorMessage = QObject::tr("External plugin host executable does not appear to be installed");
84 return {};
85 }
86
59 if (m_pluginData.empty()) { 87 if (m_pluginData.empty()) {
60 populate(); 88 populate(errorMessage);
61 } 89 }
62 90
63 vector<QString> rv; 91 vector<QString> rv;
64 92
65 for (const auto &d: m_pluginData) { 93 for (const auto &d: m_pluginData) {
109 return {}; 137 return {};
110 } 138 }
111 } 139 }
112 140
113 void 141 void
114 PiperVampPluginFactory::populate() 142 PiperVampPluginFactory::populate(QString &errorMessage)
115 { 143 {
144 if (m_serverName == "") return;
145
116 piper_vamp::client::ProcessQtTransport transport(m_serverName); 146 piper_vamp::client::ProcessQtTransport transport(m_serverName);
147 if (!transport.isOK()) {
148 errorMessage = QObject::tr("Could not start external plugin host");
149 return;
150 }
151
117 piper_vamp::client::CapnpRRClient client(&transport); 152 piper_vamp::client::CapnpRRClient client(&transport);
118 piper_vamp::ListResponse lr = client.listPluginData(); 153 piper_vamp::ListResponse lr = client.listPluginData();
119 154
120 for (const auto &pd: lr.available) { 155 for (const auto &pd: lr.available) {
121 156