comparison plugin/PiperVampPluginFactory.cpp @ 1559:c55de1488b93

Check server minimum version
author Chris Cannam
date Thu, 01 Nov 2018 14:06:38 +0000
parents c014839f49c7
children 2b532ff7f22e
comparison
equal deleted inserted replaced
1558:73b3dd65e0b3 1559:c55de1488b93
56 56
57 PiperVampPluginFactory::PiperVampPluginFactory() : 57 PiperVampPluginFactory::PiperVampPluginFactory() :
58 m_logger(new Logger) 58 m_logger(new Logger)
59 { 59 {
60 QString serverName = "piper-vamp-simple-server"; 60 QString serverName = "piper-vamp-simple-server";
61 float minimumVersion = 2.0;
61 62
62 HelperExecPath hep(HelperExecPath::AllInstalled); 63 HelperExecPath hep(HelperExecPath::AllInstalled);
63 m_servers = hep.getHelperExecutables(serverName); 64
64 65 auto servers = hep.getHelperExecutables(serverName);
65 for (auto n: m_servers) { 66
67 for (auto n: servers) {
66 SVDEBUG << "NOTE: PiperVampPluginFactory: Found server: " 68 SVDEBUG << "NOTE: PiperVampPluginFactory: Found server: "
67 << n.executable << endl; 69 << n.executable << endl;
70 if (serverMeetsMinimumVersion(n, minimumVersion)) {
71 m_servers.push_back(n);
72 } else {
73 SVCERR << "WARNING: PiperVampPluginFactory: Server at "
74 << n.executable
75 << " does not meet minimum version requirement (version >= "
76 << minimumVersion << ")" << endl;
77 }
68 } 78 }
69 79
70 if (m_servers.empty()) { 80 if (m_servers.empty()) {
71 SVDEBUG << "NOTE: No Piper Vamp servers found in installation;" 81 SVDEBUG << "NOTE: No Piper Vamp servers found in installation;"
72 << " found none of the following:" << endl; 82 << " the following paths are either absent or fail "
83 << "minimum-version check:" << endl;
73 for (auto d: hep.getHelperCandidatePaths(serverName)) { 84 for (auto d: hep.getHelperCandidatePaths(serverName)) {
74 SVDEBUG << "NOTE: " << d << endl; 85 SVDEBUG << "NOTE: " << d << endl;
75 } 86 }
76 } 87 }
77 } 88 }
78 89
79 PiperVampPluginFactory::~PiperVampPluginFactory() 90 PiperVampPluginFactory::~PiperVampPluginFactory()
80 { 91 {
81 delete m_logger; 92 delete m_logger;
93 }
94
95 bool
96 PiperVampPluginFactory::serverMeetsMinimumVersion(const HelperExecPath::HelperExec &server,
97 float minimumVersion)
98 {
99 QProcess process;
100 QString executable = server.executable;
101 process.setReadChannel(QProcess::StandardOutput);
102 process.setProcessChannelMode(QProcess::ForwardedErrorChannel);
103 process.start(executable, { "--version" });
104
105 if (!process.waitForStarted()) {
106 QProcess::ProcessError err = process.error();
107 if (err == QProcess::FailedToStart) {
108 SVCERR << "WARNING: Unable to start server " << executable
109 << " for version check" << endl;
110 } else if (err == QProcess::Crashed) {
111 SVCERR << "WARNING: Server " << executable
112 << " crashed on version check" << endl;
113 } else {
114 SVCERR << "WARNING: Server " << executable
115 << " failed on version check with error code "
116 << err << endl;
117 }
118 return false;
119 }
120 process.waitForFinished();
121
122 QByteArray output = process.readAllStandardOutput();
123 while (output.endsWith('\n') || output.endsWith('\r')) {
124 output.chop(1);
125 }
126
127 QString outputString(output);
128 bool ok = false;
129 float version = outputString.toFloat(&ok);
130 if (!ok) {
131 SVCERR << "WARNING: Failed to convert server version response \""
132 << outputString << "\" into one- or two-part version number"
133 << endl;
134 }
135
136 SVDEBUG << "Server " << executable << " reports version number "
137 << version << endl;
138
139 float eps = 1e-6;
140 return (version >= minimumVersion ||
141 fabsf(version - minimumVersion) < eps); // arf
82 } 142 }
83 143
84 vector<QString> 144 vector<QString>
85 PiperVampPluginFactory::getPluginIdentifiers(QString &errorMessage) 145 PiperVampPluginFactory::getPluginIdentifiers(QString &errorMessage)
86 { 146 {