Mercurial > hg > piper-cpp
changeset 72:16acd7d24b1a
Ensure id is passed through in adapter (still pending for server/converter)
author | Chris Cannam <c.cannam@qmul.ac.uk> |
---|---|
date | Fri, 07 Oct 2016 16:43:18 +0100 |
parents | 6c908ee3ad3b |
children | 7bfc07576830 |
files | json/VampJson.h |
diffstat | 1 files changed, 32 insertions(+), 13 deletions(-) [+] |
line wrap: on
line diff
--- a/json/VampJson.h Fri Oct 07 14:27:11 2016 +0100 +++ b/json/VampJson.h Fri Oct 07 16:43:18 2016 +0100 @@ -1037,6 +1037,13 @@ markRPC(json11::Json::object &jo) { jo["jsonrpc"] = "2.0"; } + + static void + addId(json11::Json::object &jo, const json11::Json &id) { + if (!id.is_null()) { + jo["id"] = id; + } + } public: @@ -1051,7 +1058,8 @@ } static json11::Json - fromRpcResponse_List(const Vamp::HostExt::ListResponse &resp) { + fromRpcResponse_List(const Vamp::HostExt::ListResponse &resp, + const json11::Json &id) { json11::Json::object jo; markRPC(jo); @@ -1065,6 +1073,7 @@ jo["method"] = "list"; jo["result"] = po; + addId(jo, id); return json11::Json(jo); } @@ -1081,7 +1090,8 @@ static json11::Json fromRpcResponse_Load(const Vamp::HostExt::LoadResponse &resp, - const PluginHandleMapper &pmapper) { + const PluginHandleMapper &pmapper, + const json11::Json &id) { if (resp.plugin) { @@ -1090,10 +1100,11 @@ jo["method"] = "load"; jo["result"] = fromLoadResponse(resp, pmapper); + addId(jo, id); return json11::Json(jo); } else { - return fromError("Failed to load plugin", RRType::Load); + return fromError("Failed to load plugin", RRType::Load, id); } } @@ -1111,7 +1122,8 @@ static json11::Json fromRpcResponse_Configure(const Vamp::HostExt::ConfigurationResponse &resp, - const PluginHandleMapper &pmapper) { + const PluginHandleMapper &pmapper, + const json11::Json &id) { if (!resp.outputs.empty()) { @@ -1120,17 +1132,18 @@ jo["method"] = "configure"; jo["result"] = fromConfigurationResponse(resp, pmapper); + addId(jo, id); return json11::Json(jo); } else { - return fromError("Failed to configure plugin", RRType::Configure); + return fromError("Failed to configure plugin", RRType::Configure, id); } } static json11::Json fromRpcRequest_Process(const Vamp::HostExt::ProcessRequest &req, - const PluginHandleMapper &pmapper, - BufferSerialisation serialisation) { + const PluginHandleMapper &pmapper, + BufferSerialisation serialisation) { json11::Json::object jo; markRPC(jo); @@ -1142,8 +1155,9 @@ static json11::Json fromRpcResponse_Process(const Vamp::HostExt::ProcessResponse &resp, - const PluginHandleMapper &pmapper, - BufferSerialisation serialisation) { + const PluginHandleMapper &pmapper, + BufferSerialisation serialisation, + const json11::Json &id) { json11::Json::object jo; markRPC(jo); @@ -1155,6 +1169,7 @@ serialisation); jo["method"] = "process"; jo["result"] = po; + addId(jo, id); return json11::Json(jo); } @@ -1175,8 +1190,9 @@ static json11::Json fromRpcResponse_Finish(const Vamp::HostExt::ProcessResponse &resp, - const PluginHandleMapper &pmapper, - BufferSerialisation serialisation) { + const PluginHandleMapper &pmapper, + BufferSerialisation serialisation, + const json11::Json &id) { json11::Json::object jo; markRPC(jo); @@ -1188,11 +1204,14 @@ serialisation); jo["method"] = "finish"; jo["result"] = po; + addId(jo, id); return json11::Json(jo); } static json11::Json - fromError(std::string errorText, RRType responseType) { + fromError(std::string errorText, + RRType responseType, + const json11::Json &id) { json11::Json::object jo; markRPC(jo); @@ -1213,7 +1232,7 @@ jo["method"] = type; jo["error"] = eo; - + addId(jo, id); return json11::Json(jo); }