Mercurial > hg > vamp-plugin-load-checker
comparison src/plugincandidates.cpp @ 19:c80c55cabfcd
Untabify
author | Chris Cannam |
---|---|
date | Tue, 01 Nov 2016 15:16:08 +0000 |
parents | 8643d4d1cb14 |
children | 386de1be6226 |
comparison
equal
deleted
inserted
replaced
18:7eff522b23ae | 19:c80c55cabfcd |
---|---|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ | 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ |
2 /* | 2 /* |
3 Copyright (c) 2016 Queen Mary, University of London | 3 Copyright (c) 2016 Queen Mary, University of London |
4 | 4 |
5 Permission is hereby granted, free of charge, to any person | 5 Permission is hereby granted, free of charge, to any person |
6 obtaining a copy of this software and associated documentation | 6 obtaining a copy of this software and associated documentation |
7 files (the "Software"), to deal in the Software without | 7 files (the "Software"), to deal in the Software without |
8 restriction, including without limitation the rights to use, copy, | 8 restriction, including without limitation the rights to use, copy, |
9 modify, merge, publish, distribute, sublicense, and/or sell copies | 9 modify, merge, publish, distribute, sublicense, and/or sell copies |
10 of the Software, and to permit persons to whom the Software is | 10 of the Software, and to permit persons to whom the Software is |
11 furnished to do so, subject to the following conditions: | 11 furnished to do so, subject to the following conditions: |
12 | 12 |
13 The above copyright notice and this permission notice shall be | 13 The above copyright notice and this permission notice shall be |
14 included in all copies or substantial portions of the Software. | 14 included in all copies or substantial portions of the Software. |
15 | 15 |
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | 16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
17 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | 17 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
18 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | 18 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
19 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY | 19 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY |
20 CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF | 20 CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF |
21 CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | 21 CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION |
22 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | 22 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
23 | 23 |
24 Except as contained in this notice, the names of the Centre for | 24 Except as contained in this notice, the names of the Centre for |
25 Digital Music and Queen Mary, University of London shall not be | 25 Digital Music and Queen Mary, University of London shall not be |
26 used in advertising or otherwise to promote the sale, use or other | 26 used in advertising or otherwise to promote the sale, use or other |
27 dealings in this Software without prior written authorization. | 27 dealings in this Software without prior written authorization. |
28 */ | 28 */ |
29 | 29 |
30 #include "plugincandidates.h" | 30 #include "plugincandidates.h" |
31 | 31 |
32 #include <set> | 32 #include <set> |
87 for (string dirname: path) { | 87 for (string dirname: path) { |
88 | 88 |
89 log("scanning directory " + dirname + "\n"); | 89 log("scanning directory " + dirname + "\n"); |
90 | 90 |
91 QDir dir(dirname.c_str(), PLUGIN_GLOB, | 91 QDir dir(dirname.c_str(), PLUGIN_GLOB, |
92 QDir::Name | QDir::IgnoreCase, | 92 QDir::Name | QDir::IgnoreCase, |
93 QDir::Files | QDir::Readable); | 93 QDir::Files | QDir::Readable); |
94 | 94 |
95 for (unsigned int i = 0; i < dir.count(); ++i) { | 95 for (unsigned int i = 0; i < dir.count(); ++i) { |
96 QString soname = dir.filePath(dir[i]); | 96 QString soname = dir.filePath(dir[i]); |
97 // NB this means the library names passed to the helper | 97 // NB this means the library names passed to the helper |
98 // are UTF-8 encoded | 98 // are UTF-8 encoded |
99 candidates.push_back(soname.toStdString()); | 99 candidates.push_back(soname.toStdString()); |
100 } | 100 } |
103 return candidates; | 103 return candidates; |
104 } | 104 } |
105 | 105 |
106 void | 106 void |
107 PluginCandidates::scan(string tag, | 107 PluginCandidates::scan(string tag, |
108 vector<string> pluginPath, | 108 vector<string> pluginPath, |
109 string descriptorSymbolName) | 109 string descriptorSymbolName) |
110 { | 110 { |
111 vector<string> libraries = getLibrariesInPath(pluginPath); | 111 vector<string> libraries = getLibrariesInPath(pluginPath); |
112 vector<string> remaining = libraries; | 112 vector<string> remaining = libraries; |
113 | 113 |
114 int runlimit = 20; | 114 int runlimit = 20; |
115 int runcount = 0; | 115 int runcount = 0; |
116 | 116 |
117 vector<string> result; | 117 vector<string> result; |
118 | 118 |
119 while (result.size() < libraries.size() && runcount < runlimit) { | 119 while (result.size() < libraries.size() && runcount < runlimit) { |
120 vector<string> output = runHelper(remaining, descriptorSymbolName); | 120 vector<string> output = runHelper(remaining, descriptorSymbolName); |
121 result.insert(result.end(), output.begin(), output.end()); | 121 result.insert(result.end(), output.begin(), output.end()); |
122 int shortfall = int(remaining.size()) - int(output.size()); | 122 int shortfall = int(remaining.size()) - int(output.size()); |
123 if (shortfall > 0) { | 123 if (shortfall > 0) { |
124 // Helper bailed out for some reason presumably associated | 124 // Helper bailed out for some reason presumably associated |
125 // with the plugin following the last one it reported | 125 // with the plugin following the last one it reported |
126 // on. Add a failure entry for that one and continue with | 126 // on. Add a failure entry for that one and continue with |
127 // the following ones. | 127 // the following ones. |
128 string failed = *(remaining.rbegin() + shortfall - 1); | 128 string failed = *(remaining.rbegin() + shortfall - 1); |
129 log("helper output ended before result for plugin " + failed + "\n"); | 129 log("helper output ended before result for plugin " + failed + "\n"); |
130 result.push_back("FAILURE|" + failed + "|Plugin load check failed or timed out"); | 130 result.push_back("FAILURE|" + failed + "|Plugin load check failed or timed out"); |
131 remaining = vector<string> | 131 remaining = vector<string> |
132 (remaining.rbegin(), remaining.rbegin() + shortfall - 1); | 132 (remaining.rbegin(), remaining.rbegin() + shortfall - 1); |
133 } | 133 } |
134 ++runcount; | 134 ++runcount; |
135 } | 135 } |
136 | 136 |
137 recordResult(tag, result); | 137 recordResult(tag, result); |
138 } | 138 } |
139 | 139 |
160 } else { | 160 } else { |
161 std::cerr << "Helper process " << m_helper | 161 std::cerr << "Helper process " << m_helper |
162 << " failed on startup with error code " | 162 << " failed on startup with error code " |
163 << err << std::endl; | 163 << err << std::endl; |
164 } | 164 } |
165 throw runtime_error("plugin load helper failed to start"); | 165 throw runtime_error("plugin load helper failed to start"); |
166 } | 166 } |
167 for (auto &lib: libraries) { | 167 for (auto &lib: libraries) { |
168 process.write(lib.c_str(), lib.size()); | 168 process.write(lib.c_str(), lib.size()); |
169 process.write("\n", 1); | 169 process.write("\n", 1); |
170 } | 170 } |
171 | 171 |
172 QTime t; | 172 QTime t; |
173 t.start(); | 173 t.start(); |
174 int timeout = 3000; // ms | 174 int timeout = 3000; // ms |
175 | 175 |
176 const int buflen = 4096; | 176 const int buflen = 4096; |
177 bool done = false; | 177 bool done = false; |
178 | 178 |
179 while (!done) { | 179 while (!done) { |
180 char buf[buflen]; | 180 char buf[buflen]; |
181 qint64 linelen = process.readLine(buf, buflen); | 181 qint64 linelen = process.readLine(buf, buflen); |
182 if (linelen > 0) { | 182 if (linelen > 0) { |
183 output.push_back(buf); | 183 output.push_back(buf); |
184 done = (output.size() == libraries.size()); | 184 done = (output.size() == libraries.size()); |
185 } else if (linelen < 0) { | 185 } else if (linelen < 0) { |
186 // error case | 186 // error case |
187 log("received error code while reading from helper\n"); | 187 log("received error code while reading from helper\n"); |
188 done = true; | 188 done = true; |
189 } else { | 189 } else { |
190 // no error, but no line read (could just be between | 190 // no error, but no line read (could just be between |
191 // lines, or could be eof) | 191 // lines, or could be eof) |
192 done = (process.state() == QProcess::NotRunning); | 192 done = (process.state() == QProcess::NotRunning); |
193 if (!done) { | 193 if (!done) { |
194 if (t.elapsed() > timeout) { | 194 if (t.elapsed() > timeout) { |