Mercurial > hg > piper-cpp
changeset 55:38780f15ac8d
Make RequestResponse types more consistent by adding plugin to ConfigurationResponse and introducing a FinishRequest
author | Chris Cannam <c.cannam@qmul.ac.uk> |
---|---|
date | Mon, 19 Sep 2016 13:35:56 +0100 |
parents | 524a6d5ee813 |
children | 815e94fedc1c |
files | Makefile bits/RequestOrResponse.h capnproto/VampnProto.h capnproto/vamp.capnp json/VampJson.h utilities/json-cli.cpp utilities/json-to-capnp.cpp utilities/vampipe-convert.cpp utilities/vampipe-server.cpp |
diffstat | 9 files changed, 64 insertions(+), 42 deletions(-) [+] |
line wrap: on
line diff
--- a/Makefile Fri Sep 16 16:34:00 2016 +0100 +++ b/Makefile Mon Sep 19 13:35:56 2016 +0100 @@ -1,5 +1,5 @@ -CXXFLAGS := -Wall -Werror -g -std=c++11 +CXXFLAGS := -Wall -Werror -g3 -std=c++11 INCFLAGS := -Ivamp-plugin-sdk -Ijson -I/usr/local/include -Icapnproto -I. LDFLAGS := vamp-plugin-sdk/libvamp-hostsdk.a -L/usr/local/lib -lcapnp -lkj -ldl
--- a/bits/RequestOrResponse.h Fri Sep 16 16:34:00 2016 +0100 +++ b/bits/RequestOrResponse.h Mon Sep 19 13:35:56 2016 +0100 @@ -55,8 +55,7 @@ RequestOrResponse() : // nothing by default direction(Request), type(RRType::NotValid), - success(false), - finishPlugin(0) { } + success(false) { } Direction direction; RRType type; @@ -70,7 +69,7 @@ Vamp::HostExt::ConfigurationResponse configurationResponse; Vamp::HostExt::ProcessRequest processRequest; Vamp::HostExt::ProcessResponse processResponse; - Vamp::Plugin *finishPlugin; + Vamp::HostExt::FinishRequest finishRequest; Vamp::HostExt::ProcessResponse finishResponse; };
--- a/capnproto/VampnProto.h Fri Sep 16 16:34:00 2016 +0100 +++ b/capnproto/VampnProto.h Mon Sep 19 13:35:56 2016 +0100 @@ -572,8 +572,10 @@ static void buildConfigurationResponse(ConfigurationResponse::Builder &b, - const Vamp::HostExt::ConfigurationResponse &cr) { + const Vamp::HostExt::ConfigurationResponse &cr, + const PluginHandleMapper &pmapper) { + b.setPluginHandle(pmapper.pluginToHandle(cr.plugin)); auto olist = b.initOutputs(cr.outputs.size()); for (size_t i = 0; i < cr.outputs.size(); ++i) { auto od = olist[i]; @@ -583,8 +585,10 @@ static void readConfigurationResponse(Vamp::HostExt::ConfigurationResponse &cr, - const ConfigurationResponse::Reader &r) { + const ConfigurationResponse::Reader &r, + const PluginHandleMapper &pmapper) { + cr.plugin = pmapper.handleToPlugin(r.getPluginHandle()); cr.outputs.clear(); auto oo = r.getOutputs(); for (const auto &o: oo) { @@ -717,11 +721,12 @@ static void buildVampResponse_Configure(VampResponse::Builder &b, - const Vamp::HostExt::ConfigurationResponse &cr) { + const Vamp::HostExt::ConfigurationResponse &cr, + const PluginHandleMapper &pmapper) { b.setSuccess(!cr.outputs.empty()); b.setErrorText(""); auto u = b.getResponse().initConfigure(); - buildConfigurationResponse(u, cr); + buildConfigurationResponse(u, cr, pmapper); } static void @@ -744,11 +749,11 @@ static void buildVampRequest_Finish(VampRequest::Builder &b, - Vamp::Plugin *p, + const Vamp::HostExt::FinishRequest &req, const PluginHandleMapper &pmapper) { auto u = b.getRequest().initFinish(); - u.setPluginHandle(pmapper.pluginToHandle(p)); + u.setPluginHandle(pmapper.pluginToHandle(req.plugin)); } static void @@ -889,13 +894,16 @@ static void readVampResponse_Configure(Vamp::HostExt::ConfigurationResponse &resp, - const VampResponse::Reader &r) { + const VampResponse::Reader &r, + const PluginHandleMapper &pmapper) { if (getRequestResponseType(r) != RRType::Configure) { throw std::logic_error("not a configuration response"); } resp = {}; if (r.getSuccess()) { - readConfigurationResponse(resp, r.getResponse().getConfigure()); + readConfigurationResponse(resp, + r.getResponse().getConfigure(), + pmapper); } } @@ -923,13 +931,13 @@ } static void - readVampRequest_Finish(Vamp::Plugin *&finishPlugin, + readVampRequest_Finish(Vamp::HostExt::FinishRequest &req, const VampRequest::Reader &r, const PluginHandleMapper &pmapper) { if (getRequestResponseType(r) != RRType::Finish) { throw std::logic_error("not a finish request"); } - finishPlugin = pmapper.handleToPlugin + req.plugin = pmapper.handleToPlugin (r.getRequest().getFinish().getPluginHandle()); }
--- a/capnproto/vamp.capnp Fri Sep 16 16:34:00 2016 +0100 +++ b/capnproto/vamp.capnp Mon Sep 19 13:35:56 2016 +0100 @@ -136,8 +136,8 @@ } struct ConfigurationResponse { -#!!! now the only response type not to have the pluginHandle, so maybe it should, just for completeness - outputs @0 :List(OutputDescriptor); + pluginHandle @0 :Int32; + outputs @1 :List(OutputDescriptor); } struct ProcessRequest {
--- a/json/VampJson.h Fri Sep 16 16:34:00 2016 +0100 +++ b/json/VampJson.h Mon Sep 19 13:35:56 2016 +0100 @@ -804,9 +804,12 @@ } static json11::Json - fromConfigurationResponse(const Vamp::HostExt::ConfigurationResponse &cr) { + fromConfigurationResponse(const Vamp::HostExt::ConfigurationResponse &cr, + const PluginHandleMapper &pmapper) { json11::Json::object jo; + + jo["pluginHandle"] = pmapper.pluginToHandle(cr.plugin); json11::Json::array outs; for (auto &d: cr.outputs) { @@ -818,10 +821,13 @@ } static Vamp::HostExt::ConfigurationResponse - toConfigurationResponse(json11::Json j) { + toConfigurationResponse(json11::Json j, + const PluginHandleMapper &pmapper) { Vamp::HostExt::ConfigurationResponse cr; + cr.plugin = pmapper.handleToPlugin(j["pluginHandle"].int_value()); + if (!j["outputList"].is_array()) { throw Failure("array expected for output list"); } @@ -971,13 +977,14 @@ } static json11::Json - fromVampResponse_Configure(const Vamp::HostExt::ConfigurationResponse &resp) { + fromVampResponse_Configure(const Vamp::HostExt::ConfigurationResponse &resp, + const PluginHandleMapper &pmapper) { json11::Json::object jo; jo["type"] = "configure"; jo["success"] = (!resp.outputs.empty()); jo["errorText"] = ""; - jo["content"] = fromConfigurationResponse(resp); + jo["content"] = fromConfigurationResponse(resp, pmapper); return json11::Json(jo); } @@ -1011,13 +1018,13 @@ } static json11::Json - fromVampRequest_Finish(Vamp::Plugin *p, + fromVampRequest_Finish(const Vamp::HostExt::FinishRequest &req, const PluginHandleMapper &pmapper) { json11::Json::object jo; jo["type"] = "finish"; json11::Json::object fo; - fo["pluginHandle"] = pmapper.pluginToHandle(p); + fo["pluginHandle"] = pmapper.pluginToHandle(req.plugin); jo["content"] = fo; return json11::Json(jo); } @@ -1149,11 +1156,11 @@ } static Vamp::HostExt::ConfigurationResponse - toVampResponse_Configure(json11::Json j) { + toVampResponse_Configure(json11::Json j, const PluginHandleMapper &pmapper) { Vamp::HostExt::ConfigurationResponse resp; if (successful(j)) { - resp = toConfigurationResponse(j["content"]); + resp = toConfigurationResponse(j["content"], pmapper); } return resp; } @@ -1183,11 +1190,14 @@ return resp; } - static Vamp::Plugin * + static Vamp::HostExt::FinishRequest toVampRequest_Finish(json11::Json j, const PluginHandleMapper &pmapper) { checkTypeField(j, "finish"); - return pmapper.handleToPlugin(j["content"]["pluginHandle"].int_value()); + Vamp::HostExt::FinishRequest req; + req.plugin = pmapper.handleToPlugin + (j["content"]["pluginHandle"].int_value()); + return req; } static Vamp::HostExt::ProcessResponse
--- a/utilities/json-cli.cpp Fri Sep 16 16:34:00 2016 +0100 +++ b/utilities/json-cli.cpp Mon Sep 19 13:35:56 2016 +0100 @@ -1,3 +1,6 @@ + +//!!! This program was an early test -- it should still compile but +//!!! it's incomplete. Remove it and use the server program instead. #include "VampJson.h" #include "bits/CountingPluginHandleMapper.h" @@ -105,7 +108,7 @@ cerr << "Configured and initialised plugin " << handle << endl; - return VampJson::fromConfigurationResponse(response); + return VampJson::fromConfigurationResponse(response, mapper); } Json
--- a/utilities/json-to-capnp.cpp Fri Sep 16 16:34:00 2016 +0100 +++ b/utilities/json-to-capnp.cpp Mon Sep 19 13:35:56 2016 +0100 @@ -55,8 +55,9 @@ } else if (type == "configurationresponse") { auto resp = message.initRoot<ConfigurationResponse>(); + PreservingPluginHandleMapper mapper; VampnProto::buildConfigurationResponse - (resp, VampJson::toConfigurationResponse(payload)); + (resp, VampJson::toConfigurationResponse(payload, mapper), mapper); } else if (type == "feature") { auto f = message.initRoot<Feature>();
--- a/utilities/vampipe-convert.cpp Fri Sep 16 16:34:00 2016 +0100 +++ b/utilities/vampipe-convert.cpp Mon Sep 19 13:35:56 2016 +0100 @@ -113,7 +113,7 @@ rr.processRequest = VampJson::toVampRequest_Process(j, mapper, serialisation); break; case RRType::Finish: - rr.finishPlugin = VampJson::toVampRequest_Finish(j, mapper); + rr.finishRequest = VampJson::toVampRequest_Finish(j, mapper); break; case RRType::NotValid: break; @@ -148,7 +148,7 @@ (rr.processRequest, mapper, serialisation); break; case RRType::Finish: - j = VampJson::fromVampRequest_Finish(rr.finishPlugin, mapper); + j = VampJson::fromVampRequest_Finish(rr.finishRequest, mapper); break; case RRType::NotValid: break; @@ -186,7 +186,7 @@ rr.loadResponse = VampJson::toVampResponse_Load(j, mapper); break; case RRType::Configure: - rr.configurationResponse = VampJson::toVampResponse_Configure(j); + rr.configurationResponse = VampJson::toVampResponse_Configure(j, mapper); break; case RRType::Process: rr.processResponse = VampJson::toVampResponse_Process(j, mapper, serialisation); @@ -226,7 +226,8 @@ j = VampJson::fromVampResponse_Load(rr.loadResponse, mapper); break; case RRType::Configure: - j = VampJson::fromVampResponse_Configure(rr.configurationResponse); + j = VampJson::fromVampResponse_Configure(rr.configurationResponse, + mapper); break; case RRType::Process: j = VampJson::fromVampResponse_Process @@ -271,7 +272,7 @@ VampnProto::readVampRequest_Process(rr.processRequest, reader, mapper); break; case RRType::Finish: - VampnProto::readVampRequest_Finish(rr.finishPlugin, reader, mapper); + VampnProto::readVampRequest_Finish(rr.finishRequest, reader, mapper); break; case RRType::NotValid: break; @@ -302,7 +303,7 @@ VampnProto::buildVampRequest_Process(builder, rr.processRequest, mapper); break; case RRType::Finish: - VampnProto::buildVampRequest_Finish(builder, rr.finishPlugin, mapper); + VampnProto::buildVampRequest_Finish(builder, rr.finishRequest, mapper); break; case RRType::NotValid: break; @@ -334,7 +335,7 @@ break; case RRType::Configure: VampnProto::readVampResponse_Configure(rr.configurationResponse, - reader); + reader, mapper); break; case RRType::Process: VampnProto::readVampResponse_Process(rr.processResponse, reader, mapper); @@ -370,7 +371,7 @@ VampnProto::buildVampResponse_Load(builder, rr.loadResponse, mapper); break; case RRType::Configure: - VampnProto::buildVampResponse_Configure(builder, rr.configurationResponse); + VampnProto::buildVampResponse_Configure(builder, rr.configurationResponse, mapper); break; case RRType::Process: VampnProto::buildVampResponse_Process(builder, rr.processResponse, mapper);
--- a/utilities/vampipe-server.cpp Fri Sep 16 16:34:00 2016 +0100 +++ b/utilities/vampipe-server.cpp Mon Sep 19 13:35:56 2016 +0100 @@ -65,7 +65,7 @@ VampnProto::readVampRequest_Process(rr.processRequest, reader, mapper); break; case RRType::Finish: - VampnProto::readVampRequest_Finish(rr.finishPlugin, reader, mapper); + VampnProto::readVampRequest_Finish(rr.finishRequest, reader, mapper); break; case RRType::NotValid: break; @@ -95,7 +95,7 @@ VampnProto::buildVampResponse_Load(builder, rr.loadResponse, mapper); break; case RRType::Configure: - VampnProto::buildVampResponse_Configure(builder, rr.configurationResponse); + VampnProto::buildVampResponse_Configure(builder, rr.configurationResponse, mapper); break; case RRType::Process: VampnProto::buildVampResponse_Process(builder, rr.processResponse, mapper); @@ -196,9 +196,9 @@ case RRType::Finish: { - response.finishResponse.plugin = request.finishPlugin; + response.finishResponse.plugin = request.finishRequest.plugin; response.finishResponse.features = - request.finishPlugin->getRemainingFeatures(); + request.finishRequest.plugin->getRemainingFeatures(); // We do not delete the plugin here -- we need it in the // mapper when converting the features. It gets deleted by the @@ -249,9 +249,9 @@ cerr << "vampipe-server: response written" << endl; if (request.type == RRType::Finish) { - auto h = mapper.pluginToHandle(request.finishPlugin); + auto h = mapper.pluginToHandle(request.finishRequest.plugin); mapper.removePlugin(h); - delete request.finishPlugin; + delete request.finishRequest.plugin; } } catch (std::exception &e) {