c@75
|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
c@75
|
2
|
c@75
|
3 /*
|
c@75
|
4 Piper C++
|
c@75
|
5
|
c@75
|
6 Centre for Digital Music, Queen Mary, University of London.
|
c@75
|
7 Copyright 2015-2016 QMUL.
|
c@75
|
8
|
c@75
|
9 Permission is hereby granted, free of charge, to any person
|
c@75
|
10 obtaining a copy of this software and associated documentation
|
c@75
|
11 files (the "Software"), to deal in the Software without
|
c@75
|
12 restriction, including without limitation the rights to use, copy,
|
c@75
|
13 modify, merge, publish, distribute, sublicense, and/or sell copies
|
c@75
|
14 of the Software, and to permit persons to whom the Software is
|
c@75
|
15 furnished to do so, subject to the following conditions:
|
c@75
|
16
|
c@75
|
17 The above copyright notice and this permission notice shall be
|
c@75
|
18 included in all copies or substantial portions of the Software.
|
c@75
|
19
|
c@75
|
20 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
c@75
|
21 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
c@75
|
22 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
c@75
|
23 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
|
c@75
|
24 ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
|
c@75
|
25 CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
c@75
|
26 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
c@75
|
27
|
c@75
|
28 Except as contained in this notice, the names of the Centre for
|
c@75
|
29 Digital Music; Queen Mary, University of London; and Chris Cannam
|
c@75
|
30 shall not be used in advertising or otherwise to promote the sale,
|
c@75
|
31 use or other dealings in this Software without prior written
|
c@75
|
32 authorization.
|
c@75
|
33 */
|
c@75
|
34
|
c@75
|
35 #include "piper.capnp.h"
|
c@75
|
36
|
c@75
|
37 #include <capnp/message.h>
|
c@75
|
38
|
c@75
|
39 #include <vamp-hostsdk/Plugin.h>
|
c@75
|
40 #include <vamp-hostsdk/PluginLoader.h>
|
c@97
|
41
|
c@97
|
42 #include "vamp-support/PluginStaticData.h"
|
c@97
|
43 #include "vamp-support/PluginConfiguration.h"
|
c@97
|
44 #include "vamp-support/RequestResponse.h"
|
c@75
|
45
|
c@75
|
46 #include "vamp-support/PluginHandleMapper.h"
|
c@75
|
47 #include "vamp-support/PluginOutputIdMapper.h"
|
c@75
|
48 #include "vamp-support/RequestResponseType.h"
|
c@75
|
49
|
c@97
|
50 namespace piper_vamp
|
c@75
|
51 {
|
c@75
|
52
|
c@75
|
53 /**
|
c@75
|
54 * Convert the structures laid out in the Vamp SDK classes into Cap'n
|
c@75
|
55 * Proto structures (and back again).
|
c@75
|
56 *
|
c@75
|
57 * At least some of this will be necessary for any implementation
|
c@75
|
58 * using Cap'n Proto that uses the C++ Vamp SDK to provide its
|
c@75
|
59 * reference structures. An implementation could alternatively use the
|
c@75
|
60 * Cap'n Proto structures directly, and interact with Vamp plugins
|
c@75
|
61 * using the Vamp C API, without using the C++ Vamp SDK classes at
|
c@75
|
62 * all. That would avoid a lot of copying (in Cap'n Proto style).
|
c@75
|
63 */
|
c@75
|
64 class VampnProto
|
c@75
|
65 {
|
c@75
|
66 public:
|
c@75
|
67 typedef ::capnp::MallocMessageBuilder MsgBuilder;
|
c@75
|
68
|
c@75
|
69 template <typename T, typename B>
|
c@75
|
70 static void buildBasicDescriptor(B &basic, const T &t) {
|
c@75
|
71 basic.setIdentifier(t.identifier);
|
c@75
|
72 basic.setName(t.name);
|
c@75
|
73 basic.setDescription(t.description);
|
c@75
|
74 }
|
c@75
|
75
|
c@75
|
76 template <typename T, typename B>
|
c@75
|
77 static void readBasicDescriptor(T &t, const B &basic) {
|
c@75
|
78 t.identifier = basic.getIdentifier();
|
c@75
|
79 t.name = basic.getName();
|
c@75
|
80 t.description = basic.getDescription();
|
c@75
|
81 }
|
c@75
|
82
|
c@75
|
83 template <typename T, typename M>
|
c@75
|
84 static void buildValueExtents(M &m, const T &t) {
|
c@75
|
85 m.setMinValue(t.minValue);
|
c@75
|
86 m.setMaxValue(t.maxValue);
|
c@75
|
87 }
|
c@75
|
88
|
c@75
|
89 template <typename T, typename M>
|
c@75
|
90 static void readValueExtents(T &t, const M &m) {
|
c@75
|
91 t.minValue = m.getMinValue();
|
c@75
|
92 t.maxValue = m.getMaxValue();
|
c@75
|
93 }
|
c@75
|
94
|
c@97
|
95 static void buildRealTime(piper::RealTime::Builder &b,
|
c@97
|
96 const Vamp::RealTime &t) {
|
c@75
|
97 b.setSec(t.sec);
|
c@75
|
98 b.setNsec(t.nsec);
|
c@75
|
99 }
|
c@75
|
100
|
c@97
|
101 static void readRealTime(Vamp::RealTime &t,
|
c@97
|
102 const piper::RealTime::Reader &r) {
|
c@75
|
103 t.sec = r.getSec();
|
c@75
|
104 t.nsec = r.getNsec();
|
c@75
|
105 }
|
c@75
|
106
|
c@97
|
107 static piper::SampleType
|
c@75
|
108 fromSampleType(Vamp::Plugin::OutputDescriptor::SampleType t) {
|
c@75
|
109 switch (t) {
|
c@75
|
110 case Vamp::Plugin::OutputDescriptor::OneSamplePerStep:
|
c@97
|
111 return piper::SampleType::ONE_SAMPLE_PER_STEP;
|
c@75
|
112 case Vamp::Plugin::OutputDescriptor::FixedSampleRate:
|
c@97
|
113 return piper::SampleType::FIXED_SAMPLE_RATE;
|
c@75
|
114 case Vamp::Plugin::OutputDescriptor::VariableSampleRate:
|
c@97
|
115 return piper::SampleType::VARIABLE_SAMPLE_RATE;
|
c@75
|
116 }
|
c@75
|
117 throw std::logic_error("unexpected Vamp SampleType enum value");
|
c@75
|
118 }
|
c@75
|
119
|
c@75
|
120 static Vamp::Plugin::OutputDescriptor::SampleType
|
c@97
|
121 toSampleType(piper::SampleType t) {
|
c@75
|
122 switch (t) {
|
c@97
|
123 case piper::SampleType::ONE_SAMPLE_PER_STEP:
|
c@75
|
124 return Vamp::Plugin::OutputDescriptor::OneSamplePerStep;
|
c@97
|
125 case piper::SampleType::FIXED_SAMPLE_RATE:
|
c@75
|
126 return Vamp::Plugin::OutputDescriptor::FixedSampleRate;
|
c@97
|
127 case piper::SampleType::VARIABLE_SAMPLE_RATE:
|
c@75
|
128 return Vamp::Plugin::OutputDescriptor::VariableSampleRate;
|
c@75
|
129 }
|
c@75
|
130 throw std::logic_error("unexpected Capnp SampleType enum value");
|
c@75
|
131 }
|
c@75
|
132
|
c@75
|
133 static void
|
c@97
|
134 buildConfiguredOutputDescriptor(piper::ConfiguredOutputDescriptor::Builder &b,
|
c@75
|
135 const Vamp::Plugin::OutputDescriptor &od) {
|
c@75
|
136
|
c@75
|
137 b.setUnit(od.unit);
|
c@75
|
138 b.setSampleType(fromSampleType(od.sampleType));
|
c@75
|
139 b.setSampleRate(od.sampleRate);
|
c@75
|
140 b.setHasDuration(od.hasDuration);
|
c@75
|
141
|
c@75
|
142 b.setHasFixedBinCount(od.hasFixedBinCount);
|
c@75
|
143 if (od.hasFixedBinCount) {
|
c@102
|
144 b.setBinCount(int(od.binCount));
|
c@75
|
145 if (od.binNames.size() > 0) {
|
c@102
|
146 auto binNames = b.initBinNames(unsigned(od.binNames.size()));
|
c@102
|
147 for (int i = 0; i < int(od.binNames.size()); ++i) {
|
c@75
|
148 binNames.set(i, od.binNames[i]);
|
c@75
|
149 }
|
c@75
|
150 }
|
c@75
|
151 }
|
c@75
|
152
|
c@75
|
153 b.setHasKnownExtents(od.hasKnownExtents);
|
c@75
|
154 if (od.hasKnownExtents) {
|
c@75
|
155 buildValueExtents(b, od);
|
c@75
|
156 }
|
c@75
|
157
|
c@75
|
158 b.setIsQuantized(od.isQuantized);
|
c@75
|
159 if (od.isQuantized) {
|
c@75
|
160 b.setQuantizeStep(od.quantizeStep);
|
c@75
|
161 }
|
c@75
|
162 }
|
c@75
|
163
|
c@75
|
164 static void
|
c@97
|
165 buildOutputDescriptor(piper::OutputDescriptor::Builder &b,
|
c@75
|
166 const Vamp::Plugin::OutputDescriptor &od) {
|
c@75
|
167
|
c@75
|
168 auto basic = b.initBasic();
|
c@75
|
169 buildBasicDescriptor(basic, od);
|
c@75
|
170
|
c@75
|
171 auto configured = b.initConfigured();
|
c@75
|
172 buildConfiguredOutputDescriptor(configured, od);
|
c@75
|
173 }
|
c@75
|
174
|
c@75
|
175 static void
|
c@75
|
176 readConfiguredOutputDescriptor(Vamp::Plugin::OutputDescriptor &od,
|
c@97
|
177 const piper::ConfiguredOutputDescriptor::Reader &r) {
|
c@75
|
178
|
c@75
|
179 od.unit = r.getUnit();
|
c@75
|
180
|
c@75
|
181 od.sampleType = toSampleType(r.getSampleType());
|
c@75
|
182 od.sampleRate = r.getSampleRate();
|
c@75
|
183 od.hasDuration = r.getHasDuration();
|
c@75
|
184
|
c@75
|
185 od.hasFixedBinCount = r.getHasFixedBinCount();
|
c@75
|
186 if (od.hasFixedBinCount) {
|
c@75
|
187 od.binCount = r.getBinCount();
|
c@75
|
188 od.binNames.clear();
|
c@75
|
189 auto nn = r.getBinNames();
|
c@75
|
190 for (const auto &n: nn) {
|
c@75
|
191 od.binNames.push_back(n);
|
c@75
|
192 }
|
c@75
|
193 }
|
c@75
|
194
|
c@75
|
195 od.hasKnownExtents = r.getHasKnownExtents();
|
c@75
|
196 if (od.hasKnownExtents) {
|
c@75
|
197 readValueExtents(od, r);
|
c@75
|
198 }
|
c@75
|
199
|
c@75
|
200 od.isQuantized = r.getIsQuantized();
|
c@75
|
201 if (od.isQuantized) {
|
c@75
|
202 od.quantizeStep = r.getQuantizeStep();
|
c@75
|
203 }
|
c@75
|
204 }
|
c@75
|
205
|
c@75
|
206 static void
|
c@75
|
207 readOutputDescriptor(Vamp::Plugin::OutputDescriptor &od,
|
c@97
|
208 const piper::OutputDescriptor::Reader &r) {
|
c@75
|
209
|
c@75
|
210 readBasicDescriptor(od, r.getBasic());
|
c@75
|
211 readConfiguredOutputDescriptor(od, r.getConfigured());
|
c@75
|
212 }
|
c@75
|
213
|
c@75
|
214 static void
|
c@97
|
215 buildParameterDescriptor(piper::ParameterDescriptor::Builder &b,
|
c@75
|
216 const Vamp::Plugin::ParameterDescriptor &pd) {
|
c@75
|
217
|
c@75
|
218 auto basic = b.initBasic();
|
c@75
|
219 buildBasicDescriptor(basic, pd);
|
c@75
|
220
|
c@75
|
221 b.setUnit(pd.unit);
|
c@75
|
222
|
c@75
|
223 buildValueExtents(b, pd);
|
c@75
|
224
|
c@75
|
225 b.setDefaultValue(pd.defaultValue);
|
c@75
|
226
|
c@75
|
227 b.setIsQuantized(pd.isQuantized);
|
c@75
|
228 if (pd.isQuantized) {
|
c@75
|
229 b.setQuantizeStep(pd.quantizeStep);
|
c@75
|
230 }
|
c@75
|
231
|
c@75
|
232 if (pd.valueNames.size() > 0) {
|
c@102
|
233 auto valueNames = b.initValueNames(unsigned(pd.valueNames.size()));
|
c@102
|
234 for (int i = 0; i < int(pd.valueNames.size()); ++i) {
|
c@75
|
235 valueNames.set(i, pd.valueNames[i]);
|
c@75
|
236 }
|
c@75
|
237 }
|
c@75
|
238 }
|
c@75
|
239
|
c@75
|
240 static void
|
c@75
|
241 readParameterDescriptor(Vamp::Plugin::ParameterDescriptor &pd,
|
c@97
|
242 const piper::ParameterDescriptor::Reader &r) {
|
c@75
|
243
|
c@75
|
244 readBasicDescriptor(pd, r.getBasic());
|
c@75
|
245
|
c@75
|
246 pd.unit = r.getUnit();
|
c@75
|
247
|
c@75
|
248 readValueExtents(pd, r);
|
c@75
|
249
|
c@75
|
250 pd.defaultValue = r.getDefaultValue();
|
c@75
|
251
|
c@75
|
252 pd.isQuantized = r.getIsQuantized();
|
c@75
|
253 if (pd.isQuantized) {
|
c@75
|
254 pd.quantizeStep = r.getQuantizeStep();
|
c@75
|
255 }
|
c@75
|
256
|
c@75
|
257 pd.valueNames.clear();
|
c@75
|
258 auto nn = r.getValueNames();
|
c@75
|
259 for (const auto &n: nn) {
|
c@75
|
260 pd.valueNames.push_back(n);
|
c@75
|
261 }
|
c@75
|
262 }
|
c@75
|
263
|
c@75
|
264 static void
|
c@97
|
265 buildFeature(piper::Feature::Builder &b,
|
c@75
|
266 const Vamp::Plugin::Feature &f) {
|
c@75
|
267
|
c@75
|
268 b.setHasTimestamp(f.hasTimestamp);
|
c@75
|
269 if (f.hasTimestamp) {
|
c@75
|
270 auto timestamp = b.initTimestamp();
|
c@75
|
271 buildRealTime(timestamp, f.timestamp);
|
c@75
|
272 }
|
c@75
|
273
|
c@75
|
274 b.setHasDuration(f.hasDuration);
|
c@75
|
275 if (f.hasDuration) {
|
c@75
|
276 auto duration = b.initDuration();
|
c@75
|
277 buildRealTime(duration, f.duration);
|
c@75
|
278 }
|
c@75
|
279
|
c@75
|
280 b.setLabel(f.label);
|
c@75
|
281
|
c@75
|
282 if (f.values.size() > 0) {
|
c@102
|
283 auto values = b.initFeatureValues(unsigned(f.values.size()));
|
c@102
|
284 for (int i = 0; i < int(f.values.size()); ++i) {
|
c@75
|
285 values.set(i, f.values[i]);
|
c@75
|
286 }
|
c@75
|
287 }
|
c@75
|
288 }
|
c@75
|
289
|
c@75
|
290 static void
|
c@75
|
291 readFeature(Vamp::Plugin::Feature &f,
|
c@97
|
292 const piper::Feature::Reader &r) {
|
c@75
|
293
|
c@75
|
294 f.hasTimestamp = r.getHasTimestamp();
|
c@75
|
295 if (f.hasTimestamp) {
|
c@75
|
296 readRealTime(f.timestamp, r.getTimestamp());
|
c@75
|
297 }
|
c@75
|
298
|
c@75
|
299 f.hasDuration = r.getHasDuration();
|
c@75
|
300 if (f.hasDuration) {
|
c@75
|
301 readRealTime(f.duration, r.getDuration());
|
c@75
|
302 }
|
c@75
|
303
|
c@75
|
304 f.label = r.getLabel();
|
c@75
|
305
|
c@75
|
306 f.values.clear();
|
c@75
|
307 auto vv = r.getFeatureValues();
|
c@75
|
308 for (auto v: vv) {
|
c@75
|
309 f.values.push_back(v);
|
c@75
|
310 }
|
c@75
|
311 }
|
c@75
|
312
|
c@75
|
313 static void
|
c@97
|
314 buildFeatureSet(piper::FeatureSet::Builder &b,
|
c@75
|
315 const Vamp::Plugin::FeatureSet &fs,
|
c@75
|
316 const PluginOutputIdMapper &omapper) {
|
c@75
|
317
|
c@102
|
318 auto featureset = b.initFeaturePairs(unsigned(fs.size()));
|
c@75
|
319 int ix = 0;
|
c@75
|
320 for (const auto &fsi : fs) {
|
c@75
|
321 auto fspair = featureset[ix];
|
c@75
|
322 fspair.setOutput(omapper.indexToId(fsi.first));
|
c@102
|
323 auto featurelist = fspair.initFeatures(unsigned(fsi.second.size()));
|
c@102
|
324 for (int j = 0; j < int(fsi.second.size()); ++j) {
|
c@75
|
325 auto feature = featurelist[j];
|
c@75
|
326 buildFeature(feature, fsi.second[j]);
|
c@75
|
327 }
|
c@75
|
328 ++ix;
|
c@75
|
329 }
|
c@75
|
330 }
|
c@75
|
331
|
c@75
|
332 static void
|
c@75
|
333 readFeatureSet(Vamp::Plugin::FeatureSet &fs,
|
c@97
|
334 const piper::FeatureSet::Reader &r,
|
c@75
|
335 const PluginOutputIdMapper &omapper) {
|
c@75
|
336
|
c@75
|
337 fs.clear();
|
c@75
|
338 auto pp = r.getFeaturePairs();
|
c@75
|
339 for (const auto &p: pp) {
|
c@75
|
340 Vamp::Plugin::FeatureList vfl;
|
c@75
|
341 auto ff = p.getFeatures();
|
c@75
|
342 for (const auto &f: ff) {
|
c@75
|
343 Vamp::Plugin::Feature vf;
|
c@75
|
344 readFeature(vf, f);
|
c@75
|
345 vfl.push_back(vf);
|
c@75
|
346 }
|
c@75
|
347 fs[omapper.idToIndex(p.getOutput())] = vfl;
|
c@75
|
348 }
|
c@75
|
349 }
|
c@75
|
350
|
c@97
|
351 static piper::InputDomain
|
c@75
|
352 fromInputDomain(Vamp::Plugin::InputDomain d) {
|
c@75
|
353 switch(d) {
|
c@75
|
354 case Vamp::Plugin::TimeDomain:
|
c@97
|
355 return piper::InputDomain::TIME_DOMAIN;
|
c@75
|
356 case Vamp::Plugin::FrequencyDomain:
|
c@97
|
357 return piper::InputDomain::FREQUENCY_DOMAIN;
|
c@75
|
358 default:
|
c@75
|
359 throw std::logic_error("unexpected Vamp InputDomain enum value");
|
c@75
|
360 }
|
c@75
|
361 }
|
c@75
|
362
|
c@75
|
363 static Vamp::Plugin::InputDomain
|
c@97
|
364 toInputDomain(piper::InputDomain d) {
|
c@75
|
365 switch(d) {
|
c@97
|
366 case piper::InputDomain::TIME_DOMAIN:
|
c@75
|
367 return Vamp::Plugin::TimeDomain;
|
c@97
|
368 case piper::InputDomain::FREQUENCY_DOMAIN:
|
c@75
|
369 return Vamp::Plugin::FrequencyDomain;
|
c@75
|
370 default:
|
c@75
|
371 throw std::logic_error("unexpected Capnp InputDomain enum value");
|
c@75
|
372 }
|
c@75
|
373 }
|
c@75
|
374
|
c@75
|
375 static void
|
c@97
|
376 buildExtractorStaticData(piper::ExtractorStaticData::Builder &b,
|
c@97
|
377 const PluginStaticData &d) {
|
c@75
|
378
|
c@75
|
379 b.setKey(d.pluginKey);
|
c@75
|
380
|
c@75
|
381 auto basic = b.initBasic();
|
c@75
|
382 buildBasicDescriptor(basic, d.basic);
|
c@75
|
383
|
c@75
|
384 b.setMaker(d.maker);
|
cannam@216
|
385 b.setRights(d.copyright);
|
c@75
|
386 b.setVersion(d.pluginVersion);
|
c@75
|
387
|
c@102
|
388 auto clist = b.initCategory(unsigned(d.category.size()));
|
c@102
|
389 for (int i = 0; i < int(d.category.size()); ++i) {
|
c@75
|
390 clist.set(i, d.category[i]);
|
c@75
|
391 }
|
c@75
|
392
|
c@102
|
393 b.setMinChannelCount(int(d.minChannelCount));
|
c@102
|
394 b.setMaxChannelCount(int(d.maxChannelCount));
|
c@75
|
395
|
c@75
|
396 const auto &vparams = d.parameters;
|
c@102
|
397 auto plist = b.initParameters(unsigned(vparams.size()));
|
c@102
|
398 for (int i = 0; i < int(vparams.size()); ++i) {
|
c@75
|
399 auto pd = plist[i];
|
c@75
|
400 buildParameterDescriptor(pd, vparams[i]);
|
c@75
|
401 }
|
c@75
|
402
|
c@75
|
403 const auto &vprogs = d.programs;
|
c@102
|
404 auto pglist = b.initPrograms(unsigned(vprogs.size()));
|
c@102
|
405 for (int i = 0; i < int(vprogs.size()); ++i) {
|
c@75
|
406 pglist.set(i, vprogs[i]);
|
c@75
|
407 }
|
c@75
|
408
|
c@75
|
409 b.setInputDomain(fromInputDomain(d.inputDomain));
|
c@75
|
410
|
c@75
|
411 const auto &vouts = d.basicOutputInfo;
|
c@102
|
412 auto olist = b.initBasicOutputInfo(unsigned(vouts.size()));
|
c@102
|
413 for (int i = 0; i < int(vouts.size()); ++i) {
|
c@75
|
414 auto od = olist[i];
|
c@75
|
415 buildBasicDescriptor(od, vouts[i]);
|
c@75
|
416 }
|
c@75
|
417 }
|
c@75
|
418
|
c@75
|
419 static void
|
c@97
|
420 readExtractorStaticData(PluginStaticData &d,
|
c@97
|
421 const piper::ExtractorStaticData::Reader &r) {
|
c@75
|
422
|
c@75
|
423 d.pluginKey = r.getKey();
|
c@75
|
424
|
c@75
|
425 readBasicDescriptor(d.basic, r.getBasic());
|
c@75
|
426
|
c@75
|
427 d.maker = r.getMaker();
|
cannam@216
|
428 d.copyright = r.getRights();
|
c@75
|
429 d.pluginVersion = r.getVersion();
|
c@75
|
430
|
c@75
|
431 d.category.clear();
|
c@75
|
432 auto cc = r.getCategory();
|
c@75
|
433 for (auto c: cc) {
|
c@75
|
434 d.category.push_back(c);
|
c@75
|
435 }
|
c@75
|
436
|
c@75
|
437 d.minChannelCount = r.getMinChannelCount();
|
c@75
|
438 d.maxChannelCount = r.getMaxChannelCount();
|
c@75
|
439
|
c@75
|
440 d.parameters.clear();
|
c@75
|
441 auto pp = r.getParameters();
|
c@75
|
442 for (auto p: pp) {
|
c@75
|
443 Vamp::Plugin::ParameterDescriptor pd;
|
c@75
|
444 readParameterDescriptor(pd, p);
|
c@75
|
445 d.parameters.push_back(pd);
|
c@75
|
446 }
|
c@75
|
447
|
c@75
|
448 d.programs.clear();
|
c@75
|
449 auto prp = r.getPrograms();
|
c@75
|
450 for (auto p: prp) {
|
c@75
|
451 d.programs.push_back(p);
|
c@75
|
452 }
|
c@75
|
453
|
c@75
|
454 d.inputDomain = toInputDomain(r.getInputDomain());
|
c@75
|
455
|
c@75
|
456 d.basicOutputInfo.clear();
|
c@75
|
457 auto oo = r.getBasicOutputInfo();
|
c@75
|
458 for (auto o: oo) {
|
c@97
|
459 PluginStaticData::Basic b;
|
c@75
|
460 readBasicDescriptor(b, o);
|
c@75
|
461 d.basicOutputInfo.push_back(b);
|
c@75
|
462 }
|
c@75
|
463 }
|
c@75
|
464
|
c@75
|
465 static void
|
c@97
|
466 buildConfiguration(piper::Configuration::Builder &b,
|
c@97
|
467 const PluginConfiguration &c) {
|
c@75
|
468
|
c@75
|
469 const auto &vparams = c.parameterValues;
|
c@102
|
470 auto params = b.initParameterValues(unsigned(vparams.size()));
|
c@75
|
471 int i = 0;
|
c@75
|
472 for (const auto &pp : vparams) {
|
c@75
|
473 auto param = params[i++];
|
c@75
|
474 param.setParameter(pp.first);
|
c@75
|
475 param.setValue(pp.second);
|
c@75
|
476 }
|
c@75
|
477
|
c@75
|
478 b.setCurrentProgram(c.currentProgram);
|
c@75
|
479 b.setChannelCount(c.channelCount);
|
cannam@185
|
480
|
cannam@185
|
481 auto framing = b.initFraming();
|
cannam@185
|
482 framing.setStepSize(c.framing.stepSize);
|
cannam@185
|
483 framing.setBlockSize(c.framing.blockSize);
|
c@75
|
484 }
|
c@75
|
485
|
c@75
|
486 static void
|
c@97
|
487 readConfiguration(PluginConfiguration &c,
|
c@97
|
488 const piper::Configuration::Reader &r) {
|
c@75
|
489
|
c@75
|
490 auto pp = r.getParameterValues();
|
c@75
|
491 for (const auto &p: pp) {
|
c@75
|
492 c.parameterValues[p.getParameter()] = p.getValue();
|
c@75
|
493 }
|
c@75
|
494
|
c@75
|
495 c.currentProgram = r.getCurrentProgram();
|
c@75
|
496 c.channelCount = r.getChannelCount();
|
cannam@185
|
497 c.framing.stepSize = r.getFraming().getStepSize();
|
cannam@185
|
498 c.framing.blockSize = r.getFraming().getBlockSize();
|
c@75
|
499 }
|
c@127
|
500
|
c@127
|
501 static void
|
c@127
|
502 buildListRequest(piper::ListRequest::Builder &r,
|
c@127
|
503 const ListRequest &resp) {
|
c@75
|
504
|
c@127
|
505 auto p = r.initFrom(unsigned(resp.from.size()));
|
c@127
|
506 for (int i = 0; i < int(resp.from.size()); ++i) {
|
c@127
|
507 p.set(i, resp.from[i]);
|
c@127
|
508 }
|
c@127
|
509 }
|
c@127
|
510
|
c@127
|
511 static void
|
c@127
|
512 readListRequest(ListRequest &lr,
|
c@127
|
513 const piper::ListRequest::Reader &r) {
|
c@127
|
514
|
c@127
|
515 lr.from.clear();
|
c@127
|
516 for (auto f: r.getFrom()) {
|
c@127
|
517 lr.from.push_back(f);
|
c@127
|
518 }
|
c@127
|
519 }
|
c@127
|
520
|
c@127
|
521 static void
|
c@127
|
522 buildListResponse(piper::ListResponse::Builder &r,
|
c@127
|
523 const ListResponse &resp) {
|
c@127
|
524
|
c@127
|
525 auto p = r.initAvailable(unsigned(resp.available.size()));
|
c@127
|
526 for (int i = 0; i < int(resp.available.size()); ++i) {
|
c@127
|
527 auto pd = p[i];
|
c@127
|
528 buildExtractorStaticData(pd, resp.available[i]);
|
c@127
|
529 }
|
c@127
|
530 }
|
c@127
|
531
|
c@75
|
532 static void
|
c@97
|
533 readListResponse(ListResponse &lr,
|
c@97
|
534 const piper::ListResponse::Reader &r) {
|
c@95
|
535
|
c@95
|
536 lr.available.clear();
|
c@95
|
537 auto pp = r.getAvailable();
|
c@95
|
538 for (const auto &p: pp) {
|
c@97
|
539 PluginStaticData psd;
|
c@95
|
540 readExtractorStaticData(psd, p);
|
c@95
|
541 lr.available.push_back(psd);
|
c@95
|
542 }
|
c@95
|
543 }
|
c@95
|
544
|
c@95
|
545 static void
|
c@97
|
546 buildLoadRequest(piper::LoadRequest::Builder &r,
|
c@97
|
547 const LoadRequest &req) {
|
c@75
|
548
|
c@75
|
549 r.setKey(req.pluginKey);
|
c@75
|
550 r.setInputSampleRate(req.inputSampleRate);
|
c@75
|
551
|
c@97
|
552 std::vector<piper::AdapterFlag> flags;
|
c@75
|
553 if (req.adapterFlags & Vamp::HostExt::PluginLoader::ADAPT_INPUT_DOMAIN) {
|
c@97
|
554 flags.push_back(piper::AdapterFlag::ADAPT_INPUT_DOMAIN);
|
c@75
|
555 }
|
c@75
|
556 if (req.adapterFlags & Vamp::HostExt::PluginLoader::ADAPT_CHANNEL_COUNT) {
|
c@97
|
557 flags.push_back(piper::AdapterFlag::ADAPT_CHANNEL_COUNT);
|
c@75
|
558 }
|
c@75
|
559 if (req.adapterFlags & Vamp::HostExt::PluginLoader::ADAPT_BUFFER_SIZE) {
|
c@97
|
560 flags.push_back(piper::AdapterFlag::ADAPT_BUFFER_SIZE);
|
c@75
|
561 }
|
c@75
|
562
|
c@102
|
563 auto f = r.initAdapterFlags(unsigned(flags.size()));
|
c@102
|
564 for (int i = 0; i < int(flags.size()); ++i) {
|
c@75
|
565 f.set(i, flags[i]);
|
c@75
|
566 }
|
c@75
|
567 }
|
c@75
|
568
|
c@75
|
569 static void
|
c@97
|
570 readLoadRequest(LoadRequest &req,
|
c@97
|
571 const piper::LoadRequest::Reader &r) {
|
c@75
|
572
|
c@75
|
573 req.pluginKey = r.getKey();
|
c@75
|
574 req.inputSampleRate = r.getInputSampleRate();
|
c@75
|
575
|
c@75
|
576 int flags = 0;
|
c@75
|
577 auto aa = r.getAdapterFlags();
|
c@75
|
578 for (auto a: aa) {
|
c@97
|
579 if (a == piper::AdapterFlag::ADAPT_INPUT_DOMAIN) {
|
c@75
|
580 flags |= Vamp::HostExt::PluginLoader::ADAPT_INPUT_DOMAIN;
|
c@75
|
581 }
|
c@97
|
582 if (a == piper::AdapterFlag::ADAPT_CHANNEL_COUNT) {
|
c@75
|
583 flags |= Vamp::HostExt::PluginLoader::ADAPT_CHANNEL_COUNT;
|
c@75
|
584 }
|
c@97
|
585 if (a == piper::AdapterFlag::ADAPT_BUFFER_SIZE) {
|
c@75
|
586 flags |= Vamp::HostExt::PluginLoader::ADAPT_BUFFER_SIZE;
|
c@75
|
587 }
|
c@75
|
588 }
|
c@75
|
589 req.adapterFlags = flags;
|
c@75
|
590 }
|
c@75
|
591
|
c@75
|
592 static void
|
c@97
|
593 buildLoadResponse(piper::LoadResponse::Builder &b,
|
c@97
|
594 const LoadResponse &resp,
|
c@75
|
595 const PluginHandleMapper &pmapper) {
|
c@75
|
596
|
c@75
|
597 b.setHandle(pmapper.pluginToHandle(resp.plugin));
|
c@75
|
598 auto sd = b.initStaticData();
|
c@75
|
599 buildExtractorStaticData(sd, resp.staticData);
|
c@75
|
600 auto conf = b.initDefaultConfiguration();
|
c@75
|
601 buildConfiguration(conf, resp.defaultConfiguration);
|
c@75
|
602 }
|
c@75
|
603
|
c@75
|
604 static void
|
c@97
|
605 readLoadResponse(LoadResponse &resp,
|
c@97
|
606 const piper::LoadResponse::Reader &r,
|
c@75
|
607 const PluginHandleMapper &pmapper) {
|
c@75
|
608
|
c@75
|
609 resp.plugin = pmapper.handleToPlugin(r.getHandle());
|
c@75
|
610 readExtractorStaticData(resp.staticData, r.getStaticData());
|
c@75
|
611 readConfiguration(resp.defaultConfiguration,
|
c@80
|
612 r.getDefaultConfiguration());
|
c@75
|
613 }
|
c@75
|
614
|
c@75
|
615 static void
|
c@97
|
616 buildConfigurationRequest(piper::ConfigurationRequest::Builder &b,
|
c@97
|
617 const ConfigurationRequest &cr,
|
c@75
|
618 const PluginHandleMapper &pmapper) {
|
c@75
|
619
|
c@75
|
620 b.setHandle(pmapper.pluginToHandle(cr.plugin));
|
c@75
|
621 auto c = b.initConfiguration();
|
c@75
|
622 buildConfiguration(c, cr.configuration);
|
c@75
|
623 }
|
c@75
|
624
|
c@75
|
625 static void
|
c@97
|
626 readConfigurationRequest(ConfigurationRequest &cr,
|
c@97
|
627 const piper::ConfigurationRequest::Reader &r,
|
c@75
|
628 const PluginHandleMapper &pmapper) {
|
c@75
|
629
|
c@75
|
630 auto h = r.getHandle();
|
c@75
|
631 cr.plugin = pmapper.handleToPlugin(h);
|
c@75
|
632 auto c = r.getConfiguration();
|
c@75
|
633 readConfiguration(cr.configuration, c);
|
c@75
|
634 }
|
c@75
|
635
|
c@75
|
636 static void
|
c@97
|
637 buildConfigurationResponse(piper::ConfigurationResponse::Builder &b,
|
c@97
|
638 const ConfigurationResponse &cr,
|
c@75
|
639 const PluginHandleMapper &pmapper) {
|
c@75
|
640
|
c@75
|
641 b.setHandle(pmapper.pluginToHandle(cr.plugin));
|
c@102
|
642 auto olist = b.initOutputs(unsigned(cr.outputs.size()));
|
c@102
|
643 for (int i = 0; i < int(cr.outputs.size()); ++i) {
|
c@75
|
644 auto od = olist[i];
|
c@75
|
645 buildOutputDescriptor(od, cr.outputs[i]);
|
c@75
|
646 }
|
cannam@185
|
647 auto framing = b.initFraming();
|
cannam@185
|
648 framing.setStepSize(cr.framing.stepSize);
|
cannam@185
|
649 framing.setBlockSize(cr.framing.blockSize);
|
c@75
|
650 }
|
c@75
|
651
|
c@75
|
652 static void
|
c@97
|
653 readConfigurationResponse(ConfigurationResponse &cr,
|
c@97
|
654 const piper::ConfigurationResponse::Reader &r,
|
c@75
|
655 const PluginHandleMapper &pmapper) {
|
c@75
|
656
|
c@75
|
657 cr.plugin = pmapper.handleToPlugin(r.getHandle());
|
c@75
|
658 cr.outputs.clear();
|
c@75
|
659 auto oo = r.getOutputs();
|
c@75
|
660 for (const auto &o: oo) {
|
c@75
|
661 Vamp::Plugin::OutputDescriptor desc;
|
c@75
|
662 readOutputDescriptor(desc, o);
|
c@75
|
663 cr.outputs.push_back(desc);
|
c@75
|
664 }
|
cannam@185
|
665 cr.framing.stepSize = r.getFraming().getStepSize();
|
cannam@185
|
666 cr.framing.blockSize = r.getFraming().getBlockSize();
|
c@75
|
667 }
|
c@75
|
668
|
c@75
|
669 static void
|
c@97
|
670 buildProcessInput(piper::ProcessInput::Builder &b,
|
c@75
|
671 Vamp::RealTime timestamp,
|
c@75
|
672 const std::vector<std::vector<float> > &buffers) {
|
c@75
|
673
|
c@75
|
674 auto t = b.initTimestamp();
|
c@75
|
675 buildRealTime(t, timestamp);
|
c@102
|
676 auto vv = b.initInputBuffers(unsigned(buffers.size()));
|
c@102
|
677 for (int ch = 0; ch < int(buffers.size()); ++ch) {
|
c@75
|
678 const int n = int(buffers[ch].size());
|
c@75
|
679 vv.init(ch, n);
|
c@75
|
680 auto v = vv[ch];
|
c@75
|
681 for (int i = 0; i < n; ++i) {
|
c@75
|
682 v.set(i, buffers[ch][i]);
|
c@75
|
683 }
|
c@75
|
684 }
|
c@75
|
685 }
|
c@75
|
686
|
c@75
|
687 static void
|
c@75
|
688 readProcessInput(Vamp::RealTime ×tamp,
|
c@75
|
689 std::vector<std::vector<float> > &buffers,
|
c@97
|
690 const piper::ProcessInput::Reader &b) {
|
c@75
|
691
|
c@75
|
692 readRealTime(timestamp, b.getTimestamp());
|
c@75
|
693 buffers.clear();
|
c@75
|
694 auto vv = b.getInputBuffers();
|
c@75
|
695 for (const auto &v: vv) {
|
c@75
|
696 std::vector<float> buf;
|
c@75
|
697 for (auto x: v) {
|
c@75
|
698 buf.push_back(x);
|
c@75
|
699 }
|
c@75
|
700 buffers.push_back(buf);
|
c@75
|
701 }
|
c@75
|
702 }
|
c@75
|
703
|
c@75
|
704 static void
|
c@97
|
705 buildProcessRequest(piper::ProcessRequest::Builder &b,
|
c@97
|
706 const ProcessRequest &pr,
|
c@75
|
707 const PluginHandleMapper &pmapper) {
|
c@75
|
708
|
c@75
|
709 b.setHandle(pmapper.pluginToHandle(pr.plugin));
|
c@75
|
710 auto input = b.initProcessInput();
|
c@75
|
711 buildProcessInput(input, pr.timestamp, pr.inputBuffers);
|
c@75
|
712 }
|
c@75
|
713
|
c@75
|
714 static void
|
c@97
|
715 readProcessRequest(ProcessRequest &pr,
|
c@97
|
716 const piper::ProcessRequest::Reader &r,
|
c@75
|
717 const PluginHandleMapper &pmapper) {
|
c@75
|
718
|
c@75
|
719 auto h = r.getHandle();
|
c@75
|
720 pr.plugin = pmapper.handleToPlugin(h);
|
c@75
|
721 readProcessInput(pr.timestamp, pr.inputBuffers, r.getProcessInput());
|
c@75
|
722 }
|
c@75
|
723
|
c@75
|
724 static void
|
c@97
|
725 buildProcessResponse(piper::ProcessResponse::Builder &b,
|
c@97
|
726 const ProcessResponse &pr,
|
c@75
|
727 const PluginHandleMapper &pmapper) {
|
c@75
|
728
|
c@75
|
729 b.setHandle(pmapper.pluginToHandle(pr.plugin));
|
c@75
|
730 auto f = b.initFeatures();
|
c@75
|
731 buildFeatureSet(f, pr.features,
|
c@75
|
732 *pmapper.pluginToOutputIdMapper(pr.plugin));
|
c@75
|
733 }
|
c@75
|
734
|
c@75
|
735 static void
|
c@97
|
736 readProcessResponse(ProcessResponse &pr,
|
c@97
|
737 const piper::ProcessResponse::Reader &r,
|
c@75
|
738 const PluginHandleMapper &pmapper) {
|
c@75
|
739
|
c@75
|
740 auto h = r.getHandle();
|
c@75
|
741 pr.plugin = pmapper.handleToPlugin(h);
|
c@75
|
742 readFeatureSet(pr.features, r.getFeatures(),
|
c@75
|
743 *pmapper.handleToOutputIdMapper(r.getHandle()));
|
c@75
|
744 }
|
c@75
|
745
|
c@75
|
746 static void
|
c@97
|
747 buildFinishResponse(piper::FinishResponse::Builder &b,
|
c@97
|
748 const FinishResponse &pr,
|
c@75
|
749 const PluginHandleMapper &pmapper) {
|
c@75
|
750
|
c@75
|
751 b.setHandle(pmapper.pluginToHandle(pr.plugin));
|
c@75
|
752 auto f = b.initFeatures();
|
c@75
|
753 buildFeatureSet(f, pr.features,
|
c@75
|
754 *pmapper.pluginToOutputIdMapper(pr.plugin));
|
c@75
|
755 }
|
c@75
|
756
|
c@75
|
757 static void
|
c@97
|
758 readFinishResponse(FinishResponse &pr,
|
c@97
|
759 const piper::FinishResponse::Reader &r,
|
c@75
|
760 const PluginHandleMapper &pmapper) {
|
c@75
|
761
|
c@75
|
762 auto h = r.getHandle();
|
c@75
|
763 pr.plugin = pmapper.handleToPlugin(h);
|
c@75
|
764 readFeatureSet(pr.features, r.getFeatures(),
|
c@75
|
765 *pmapper.handleToOutputIdMapper(r.getHandle()));
|
c@75
|
766 }
|
c@75
|
767
|
c@75
|
768 static void
|
c@127
|
769 buildRpcRequest_List(piper::RpcRequest::Builder &b,
|
c@127
|
770 const ListRequest &req) {
|
c@127
|
771 auto r = b.getRequest().initList();
|
c@127
|
772 buildListRequest(r, req);
|
c@75
|
773 }
|
c@75
|
774
|
c@75
|
775 static void
|
c@97
|
776 buildRpcResponse_List(piper::RpcResponse::Builder &b,
|
c@97
|
777 const ListResponse &resp) {
|
c@75
|
778
|
c@75
|
779 auto r = b.getResponse().initList();
|
c@127
|
780 buildListResponse(r, resp);
|
c@75
|
781 }
|
c@75
|
782
|
c@75
|
783 static void
|
c@97
|
784 buildRpcRequest_Load(piper::RpcRequest::Builder &b,
|
c@97
|
785 const LoadRequest &req) {
|
c@75
|
786 auto u = b.getRequest().initLoad();
|
c@75
|
787 buildLoadRequest(u, req);
|
c@75
|
788 }
|
c@75
|
789
|
c@75
|
790 static void
|
c@97
|
791 buildRpcResponse_Load(piper::RpcResponse::Builder &b,
|
c@97
|
792 const LoadResponse &resp,
|
c@80
|
793 const PluginHandleMapper &pmapper) {
|
c@75
|
794
|
c@75
|
795 if (resp.plugin) {
|
c@75
|
796 auto u = b.getResponse().initLoad();
|
c@75
|
797 buildLoadResponse(u, resp, pmapper);
|
c@75
|
798 } else {
|
c@75
|
799 buildRpcResponse_Error(b, "Failed to load plugin", RRType::Load);
|
c@75
|
800 }
|
c@75
|
801 }
|
c@75
|
802
|
c@75
|
803 static void
|
c@97
|
804 buildRpcRequest_Configure(piper::RpcRequest::Builder &b,
|
c@97
|
805 const ConfigurationRequest &cr,
|
c@80
|
806 const PluginHandleMapper &pmapper) {
|
c@75
|
807 auto u = b.getRequest().initConfigure();
|
c@75
|
808 buildConfigurationRequest(u, cr, pmapper);
|
c@75
|
809 }
|
c@75
|
810
|
c@75
|
811 static void
|
c@97
|
812 buildRpcResponse_Configure(piper::RpcResponse::Builder &b,
|
c@97
|
813 const ConfigurationResponse &cr,
|
c@80
|
814 const PluginHandleMapper &pmapper) {
|
c@75
|
815
|
c@75
|
816 if (!cr.outputs.empty()) {
|
c@75
|
817 auto u = b.getResponse().initConfigure();
|
c@75
|
818 buildConfigurationResponse(u, cr, pmapper);
|
c@75
|
819 } else {
|
c@75
|
820 buildRpcResponse_Error(b, "Failed to configure plugin",
|
c@75
|
821 RRType::Configure);
|
c@75
|
822 }
|
c@75
|
823 }
|
c@75
|
824
|
c@75
|
825 static void
|
c@97
|
826 buildRpcRequest_Process(piper::RpcRequest::Builder &b,
|
c@97
|
827 const ProcessRequest &pr,
|
c@80
|
828 const PluginHandleMapper &pmapper) {
|
c@75
|
829 auto u = b.getRequest().initProcess();
|
c@75
|
830 buildProcessRequest(u, pr, pmapper);
|
c@75
|
831 }
|
c@75
|
832
|
c@75
|
833 static void
|
c@97
|
834 buildRpcResponse_Process(piper::RpcResponse::Builder &b,
|
c@97
|
835 const ProcessResponse &pr,
|
c@80
|
836 const PluginHandleMapper &pmapper) {
|
c@75
|
837
|
c@75
|
838 auto u = b.getResponse().initProcess();
|
c@75
|
839 buildProcessResponse(u, pr, pmapper);
|
c@75
|
840 }
|
c@75
|
841
|
c@75
|
842 static void
|
c@97
|
843 buildRpcRequest_Finish(piper::RpcRequest::Builder &b,
|
c@97
|
844 const FinishRequest &req,
|
c@80
|
845 const PluginHandleMapper &pmapper) {
|
c@75
|
846
|
c@75
|
847 auto u = b.getRequest().initFinish();
|
c@75
|
848 u.setHandle(pmapper.pluginToHandle(req.plugin));
|
c@75
|
849 }
|
c@75
|
850
|
c@75
|
851 static void
|
c@97
|
852 buildRpcResponse_Finish(piper::RpcResponse::Builder &b,
|
c@97
|
853 const FinishResponse &pr,
|
c@80
|
854 const PluginHandleMapper &pmapper) {
|
c@75
|
855
|
c@75
|
856 auto u = b.getResponse().initFinish();
|
c@75
|
857 buildFinishResponse(u, pr, pmapper);
|
c@75
|
858 }
|
c@75
|
859
|
c@75
|
860 static void
|
c@97
|
861 buildRpcResponse_Error(piper::RpcResponse::Builder &b,
|
c@80
|
862 const std::string &errorText,
|
c@80
|
863 RRType responseType)
|
c@75
|
864 {
|
c@75
|
865 std::string type;
|
c@75
|
866
|
c@75
|
867 auto e = b.getResponse().initError();
|
c@75
|
868
|
c@75
|
869 if (responseType == RRType::List) {
|
c@75
|
870 type = "list";
|
c@75
|
871 } else if (responseType == RRType::Load) {
|
c@75
|
872 type = "load";
|
c@75
|
873 } else if (responseType == RRType::Configure) {
|
c@75
|
874 type = "configure";
|
c@75
|
875 } else if (responseType == RRType::Process) {
|
c@75
|
876 type = "process";
|
c@75
|
877 } else if (responseType == RRType::Finish) {
|
c@75
|
878 type = "finish";
|
c@75
|
879 } else {
|
c@75
|
880 type = "invalid";
|
c@75
|
881 }
|
c@75
|
882
|
c@75
|
883 e.setCode(0);
|
cannam@158
|
884
|
cannam@158
|
885 if (responseType == RRType::NotValid) {
|
cannam@158
|
886 e.setMessage(errorText);
|
cannam@158
|
887 } else {
|
cannam@158
|
888 e.setMessage
|
cannam@158
|
889 (std::string("error in ") + type + " request: " + errorText);
|
cannam@158
|
890 }
|
c@75
|
891 }
|
c@75
|
892
|
c@75
|
893 static void
|
c@97
|
894 buildRpcResponse_Exception(piper::RpcResponse::Builder &b,
|
c@80
|
895 const std::exception &e,
|
c@80
|
896 RRType responseType)
|
c@75
|
897 {
|
c@75
|
898 return buildRpcResponse_Error(b, e.what(), responseType);
|
c@75
|
899 }
|
c@75
|
900
|
c@75
|
901 static RRType
|
c@97
|
902 getRequestResponseType(const piper::RpcRequest::Reader &r) {
|
c@75
|
903 switch (r.getRequest().which()) {
|
c@97
|
904 case piper::RpcRequest::Request::Which::LIST:
|
c@75
|
905 return RRType::List;
|
c@97
|
906 case piper::RpcRequest::Request::Which::LOAD:
|
c@75
|
907 return RRType::Load;
|
c@97
|
908 case piper::RpcRequest::Request::Which::CONFIGURE:
|
c@75
|
909 return RRType::Configure;
|
c@97
|
910 case piper::RpcRequest::Request::Which::PROCESS:
|
c@75
|
911 return RRType::Process;
|
c@97
|
912 case piper::RpcRequest::Request::Which::FINISH:
|
c@75
|
913 return RRType::Finish;
|
c@75
|
914 }
|
c@75
|
915 return RRType::NotValid;
|
c@75
|
916 }
|
c@75
|
917
|
c@75
|
918 static RRType
|
c@97
|
919 getRequestResponseType(const piper::RpcResponse::Reader &r) {
|
c@75
|
920 switch (r.getResponse().which()) {
|
c@97
|
921 case piper::RpcResponse::Response::Which::ERROR:
|
cannam@170
|
922 return RRType::NotValid;
|
c@97
|
923 case piper::RpcResponse::Response::Which::LIST:
|
c@75
|
924 return RRType::List;
|
c@97
|
925 case piper::RpcResponse::Response::Which::LOAD:
|
c@75
|
926 return RRType::Load;
|
c@97
|
927 case piper::RpcResponse::Response::Which::CONFIGURE:
|
c@75
|
928 return RRType::Configure;
|
c@97
|
929 case piper::RpcResponse::Response::Which::PROCESS:
|
c@75
|
930 return RRType::Process;
|
c@97
|
931 case piper::RpcResponse::Response::Which::FINISH:
|
c@75
|
932 return RRType::Finish;
|
c@75
|
933 }
|
c@75
|
934 return RRType::NotValid;
|
c@75
|
935 }
|
c@75
|
936
|
c@75
|
937 static void
|
c@75
|
938 readRpcResponse_Error(int &code,
|
c@75
|
939 std::string &message,
|
c@97
|
940 const piper::RpcResponse::Reader &r) {
|
c@75
|
941 if (getRequestResponseType(r) != RRType::NotValid) {
|
c@75
|
942 throw std::logic_error("not an error response");
|
c@75
|
943 }
|
c@75
|
944 code = r.getResponse().getError().getCode();
|
c@75
|
945 message = r.getResponse().getError().getMessage();
|
c@75
|
946 }
|
c@75
|
947
|
c@75
|
948 static void
|
c@127
|
949 readRpcRequest_List(ListRequest &req,
|
c@127
|
950 const piper::RpcRequest::Reader &r) {
|
c@75
|
951 if (getRequestResponseType(r) != RRType::List) {
|
c@75
|
952 throw std::logic_error("not a list request");
|
c@75
|
953 }
|
c@127
|
954 readListRequest(req, r.getRequest().getList());
|
c@75
|
955 }
|
c@75
|
956
|
c@75
|
957 static void
|
c@97
|
958 readRpcResponse_List(ListResponse &resp,
|
c@97
|
959 const piper::RpcResponse::Reader &r) {
|
c@75
|
960 if (getRequestResponseType(r) != RRType::List) {
|
c@75
|
961 throw std::logic_error("not a list response");
|
c@75
|
962 }
|
c@95
|
963 readListResponse(resp, r.getResponse().getList());
|
c@75
|
964 }
|
c@75
|
965
|
c@75
|
966 static void
|
c@97
|
967 readRpcRequest_Load(LoadRequest &req,
|
c@97
|
968 const piper::RpcRequest::Reader &r) {
|
c@75
|
969 if (getRequestResponseType(r) != RRType::Load) {
|
c@75
|
970 throw std::logic_error("not a load request");
|
c@75
|
971 }
|
c@75
|
972 readLoadRequest(req, r.getRequest().getLoad());
|
c@75
|
973 }
|
c@75
|
974
|
c@75
|
975 static void
|
c@97
|
976 readRpcResponse_Load(LoadResponse &resp,
|
c@97
|
977 const piper::RpcResponse::Reader &r,
|
c@75
|
978 const PluginHandleMapper &pmapper) {
|
c@75
|
979 if (getRequestResponseType(r) != RRType::Load) {
|
c@75
|
980 throw std::logic_error("not a load response");
|
c@75
|
981 }
|
c@75
|
982 resp = {};
|
c@75
|
983 readLoadResponse(resp, r.getResponse().getLoad(), pmapper);
|
c@75
|
984 }
|
c@75
|
985
|
c@75
|
986 static void
|
c@97
|
987 readRpcRequest_Configure(ConfigurationRequest &req,
|
c@97
|
988 const piper::RpcRequest::Reader &r,
|
c@80
|
989 const PluginHandleMapper &pmapper) {
|
c@75
|
990 if (getRequestResponseType(r) != RRType::Configure) {
|
c@75
|
991 throw std::logic_error("not a configuration request");
|
c@75
|
992 }
|
c@75
|
993 readConfigurationRequest(req, r.getRequest().getConfigure(), pmapper);
|
c@75
|
994 }
|
c@75
|
995
|
c@75
|
996 static void
|
c@97
|
997 readRpcResponse_Configure(ConfigurationResponse &resp,
|
c@97
|
998 const piper::RpcResponse::Reader &r,
|
c@80
|
999 const PluginHandleMapper &pmapper) {
|
c@75
|
1000 if (getRequestResponseType(r) != RRType::Configure) {
|
c@75
|
1001 throw std::logic_error("not a configuration response");
|
c@75
|
1002 }
|
c@75
|
1003 resp = {};
|
c@75
|
1004 readConfigurationResponse(resp,
|
c@75
|
1005 r.getResponse().getConfigure(),
|
c@75
|
1006 pmapper);
|
c@75
|
1007 }
|
c@75
|
1008
|
c@75
|
1009 static void
|
c@97
|
1010 readRpcRequest_Process(ProcessRequest &req,
|
c@97
|
1011 const piper::RpcRequest::Reader &r,
|
c@80
|
1012 const PluginHandleMapper &pmapper) {
|
c@75
|
1013 if (getRequestResponseType(r) != RRType::Process) {
|
c@75
|
1014 throw std::logic_error("not a process request");
|
c@75
|
1015 }
|
c@75
|
1016 readProcessRequest(req, r.getRequest().getProcess(), pmapper);
|
c@75
|
1017 }
|
c@75
|
1018
|
c@75
|
1019 static void
|
c@97
|
1020 readRpcResponse_Process(ProcessResponse &resp,
|
c@97
|
1021 const piper::RpcResponse::Reader &r,
|
c@80
|
1022 const PluginHandleMapper &pmapper) {
|
c@75
|
1023 if (getRequestResponseType(r) != RRType::Process) {
|
c@75
|
1024 throw std::logic_error("not a process response");
|
c@75
|
1025 }
|
c@75
|
1026 resp = {};
|
c@75
|
1027 readProcessResponse(resp, r.getResponse().getProcess(), pmapper);
|
c@75
|
1028 }
|
c@75
|
1029
|
c@75
|
1030 static void
|
c@97
|
1031 readRpcRequest_Finish(FinishRequest &req,
|
c@97
|
1032 const piper::RpcRequest::Reader &r,
|
c@80
|
1033 const PluginHandleMapper &pmapper) {
|
c@75
|
1034 if (getRequestResponseType(r) != RRType::Finish) {
|
c@75
|
1035 throw std::logic_error("not a finish request");
|
c@75
|
1036 }
|
c@75
|
1037 req.plugin = pmapper.handleToPlugin
|
c@75
|
1038 (r.getRequest().getFinish().getHandle());
|
c@75
|
1039 }
|
c@75
|
1040
|
c@75
|
1041 static void
|
c@97
|
1042 readRpcResponse_Finish(FinishResponse &resp,
|
c@97
|
1043 const piper::RpcResponse::Reader &r,
|
c@80
|
1044 const PluginHandleMapper &pmapper) {
|
c@75
|
1045 if (getRequestResponseType(r) != RRType::Finish) {
|
c@75
|
1046 throw std::logic_error("not a finish response");
|
c@75
|
1047 }
|
c@75
|
1048 resp = {};
|
c@75
|
1049 readFinishResponse(resp, r.getResponse().getFinish(), pmapper);
|
c@75
|
1050 }
|
c@75
|
1051 };
|
c@75
|
1052
|
c@75
|
1053 }
|
c@75
|
1054
|
c@75
|
1055
|