Mercurial > hg > piper-cpp
comparison vamp-json/VampJson.h @ 127:5b113c87b6e6
Add and implement the "from" param for list request. The simple-server implementation is not yet correct.
author | Chris Cannam <c.cannam@qmul.ac.uk> |
---|---|
date | Wed, 02 Nov 2016 14:27:42 +0000 |
parents | 2380d5865355 |
children | 615fc5a47509 |
comparison
equal
deleted
inserted
replaced
126:2004ec2b653e | 127:5b113c87b6e6 |
---|---|
800 | 800 |
801 return Vamp::HostExt::PluginLoader::AdapterFlags(flags); | 801 return Vamp::HostExt::PluginLoader::AdapterFlags(flags); |
802 } | 802 } |
803 | 803 |
804 static json11::Json | 804 static json11::Json |
805 fromListRequest(const ListRequest &req) { | |
806 json11::Json::object jo; | |
807 json11::Json::array arr; | |
808 for (const auto &f: req.from) { | |
809 arr.push_back(f); | |
810 } | |
811 jo["from"] = arr; | |
812 return json11::Json(jo); | |
813 } | |
814 | |
815 static ListRequest | |
816 toListRequest(json11::Json j, std::string &err) { | |
817 | |
818 ListRequest req; | |
819 if (!j["from"].is_null() && | |
820 !j["from"].is_array()) { | |
821 err = "array expected for from field"; | |
822 return {}; | |
823 } | |
824 for (const auto &a: j["from"].array_items()) { | |
825 if (!a.is_string()) { | |
826 err = "string expected for element in from array"; | |
827 return {}; | |
828 } | |
829 req.from.push_back(a.string_value()); | |
830 } | |
831 return req; | |
832 } | |
833 | |
834 static json11::Json | |
835 fromListResponse(const ListResponse &resp) { | |
836 | |
837 json11::Json::array arr; | |
838 for (const auto &a: resp.available) { | |
839 arr.push_back(fromPluginStaticData(a)); | |
840 } | |
841 json11::Json::object jo; | |
842 jo["available"] = arr; | |
843 | |
844 return json11::Json(jo); | |
845 } | |
846 | |
847 static ListResponse | |
848 toListResponse(json11::Json j, std::string &err) { | |
849 | |
850 ListResponse resp; | |
851 for (const auto &a: j["result"]["available"].array_items()) { | |
852 resp.available.push_back(toPluginStaticData(a, err)); | |
853 if (failed(err)) return {}; | |
854 } | |
855 return resp; | |
856 } | |
857 | |
858 static json11::Json | |
805 fromLoadRequest(const LoadRequest &req) { | 859 fromLoadRequest(const LoadRequest &req) { |
806 | 860 |
807 json11::Json::object jo; | 861 json11::Json::object jo; |
808 jo["key"] = req.pluginKey; | 862 jo["key"] = req.pluginKey; |
809 jo["inputSampleRate"] = req.inputSampleRate; | 863 jo["inputSampleRate"] = req.inputSampleRate; |
1049 } | 1103 } |
1050 | 1104 |
1051 public: | 1105 public: |
1052 | 1106 |
1053 static json11::Json | 1107 static json11::Json |
1054 fromRpcRequest_List(const json11::Json &id) { | 1108 fromRpcRequest_List(const ListRequest &req, |
1109 const json11::Json &id) { | |
1055 | 1110 |
1056 json11::Json::object jo; | 1111 json11::Json::object jo; |
1057 markRPC(jo); | 1112 markRPC(jo); |
1058 | 1113 |
1059 jo["method"] = "list"; | 1114 jo["method"] = "list"; |
1115 jo["params"] = fromListRequest(req); | |
1060 addId(jo, id); | 1116 addId(jo, id); |
1061 return json11::Json(jo); | 1117 return json11::Json(jo); |
1062 } | 1118 } |
1063 | 1119 |
1064 static json11::Json | 1120 static json11::Json |
1066 const json11::Json &id) { | 1122 const json11::Json &id) { |
1067 | 1123 |
1068 json11::Json::object jo; | 1124 json11::Json::object jo; |
1069 markRPC(jo); | 1125 markRPC(jo); |
1070 | 1126 |
1071 json11::Json::array arr; | |
1072 for (const auto &a: resp.available) { | |
1073 arr.push_back(fromPluginStaticData(a)); | |
1074 } | |
1075 json11::Json::object po; | |
1076 po["available"] = arr; | |
1077 | |
1078 jo["method"] = "list"; | 1127 jo["method"] = "list"; |
1079 jo["result"] = po; | 1128 jo["result"] = fromListResponse(resp); |
1080 addId(jo, id); | 1129 addId(jo, id); |
1081 return json11::Json(jo); | 1130 return json11::Json(jo); |
1082 } | 1131 } |
1083 | 1132 |
1084 static json11::Json | 1133 static json11::Json |
1268 err = "unknown or unexpected request/response type \"" + type + "\""; | 1317 err = "unknown or unexpected request/response type \"" + type + "\""; |
1269 return RRType::NotValid; | 1318 return RRType::NotValid; |
1270 } | 1319 } |
1271 } | 1320 } |
1272 | 1321 |
1273 static void | 1322 static ListRequest |
1274 toRpcRequest_List(json11::Json j, std::string &err) { | 1323 toRpcRequest_List(json11::Json j, std::string &err) { |
1324 | |
1275 checkTypeField(j, "list", err); | 1325 checkTypeField(j, "list", err); |
1326 if (failed(err)) return {}; | |
1327 return toListRequest(j["params"], err); | |
1276 } | 1328 } |
1277 | 1329 |
1278 static ListResponse | 1330 static ListResponse |
1279 toRpcResponse_List(json11::Json j, std::string &err) { | 1331 toRpcResponse_List(json11::Json j, std::string &err) { |
1280 | 1332 |
1281 ListResponse resp; | 1333 ListResponse resp; |
1282 if (successful(j, err) && !failed(err)) { | 1334 if (successful(j, err) && !failed(err)) { |
1283 for (const auto &a: j["result"]["available"].array_items()) { | 1335 resp = toListResponse(j["result"], err); |
1284 resp.available.push_back(toPluginStaticData(a, err)); | 1336 } |
1285 if (failed(err)) return {}; | |
1286 } | |
1287 } | |
1288 | |
1289 return resp; | 1337 return resp; |
1290 } | 1338 } |
1291 | 1339 |
1292 static LoadRequest | 1340 static LoadRequest |
1293 toRpcRequest_Load(json11::Json j, std::string &err) { | 1341 toRpcRequest_Load(json11::Json j, std::string &err) { |