Mercurial > hg > piper-cpp
comparison json/VampJson.h @ 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 | a5ba837bca28 |
children | 7bfc07576830 |
comparison
equal
deleted
inserted
replaced
71:6c908ee3ad3b | 72:16acd7d24b1a |
---|---|
1035 | 1035 |
1036 static void | 1036 static void |
1037 markRPC(json11::Json::object &jo) { | 1037 markRPC(json11::Json::object &jo) { |
1038 jo["jsonrpc"] = "2.0"; | 1038 jo["jsonrpc"] = "2.0"; |
1039 } | 1039 } |
1040 | |
1041 static void | |
1042 addId(json11::Json::object &jo, const json11::Json &id) { | |
1043 if (!id.is_null()) { | |
1044 jo["id"] = id; | |
1045 } | |
1046 } | |
1040 | 1047 |
1041 public: | 1048 public: |
1042 | 1049 |
1043 static json11::Json | 1050 static json11::Json |
1044 fromRpcRequest_List() { | 1051 fromRpcRequest_List() { |
1049 jo["method"] = "list"; | 1056 jo["method"] = "list"; |
1050 return json11::Json(jo); | 1057 return json11::Json(jo); |
1051 } | 1058 } |
1052 | 1059 |
1053 static json11::Json | 1060 static json11::Json |
1054 fromRpcResponse_List(const Vamp::HostExt::ListResponse &resp) { | 1061 fromRpcResponse_List(const Vamp::HostExt::ListResponse &resp, |
1062 const json11::Json &id) { | |
1055 | 1063 |
1056 json11::Json::object jo; | 1064 json11::Json::object jo; |
1057 markRPC(jo); | 1065 markRPC(jo); |
1058 | 1066 |
1059 json11::Json::array arr; | 1067 json11::Json::array arr; |
1063 json11::Json::object po; | 1071 json11::Json::object po; |
1064 po["available"] = arr; | 1072 po["available"] = arr; |
1065 | 1073 |
1066 jo["method"] = "list"; | 1074 jo["method"] = "list"; |
1067 jo["result"] = po; | 1075 jo["result"] = po; |
1076 addId(jo, id); | |
1068 return json11::Json(jo); | 1077 return json11::Json(jo); |
1069 } | 1078 } |
1070 | 1079 |
1071 static json11::Json | 1080 static json11::Json |
1072 fromRpcRequest_Load(const Vamp::HostExt::LoadRequest &req) { | 1081 fromRpcRequest_Load(const Vamp::HostExt::LoadRequest &req) { |
1079 return json11::Json(jo); | 1088 return json11::Json(jo); |
1080 } | 1089 } |
1081 | 1090 |
1082 static json11::Json | 1091 static json11::Json |
1083 fromRpcResponse_Load(const Vamp::HostExt::LoadResponse &resp, | 1092 fromRpcResponse_Load(const Vamp::HostExt::LoadResponse &resp, |
1084 const PluginHandleMapper &pmapper) { | 1093 const PluginHandleMapper &pmapper, |
1094 const json11::Json &id) { | |
1085 | 1095 |
1086 if (resp.plugin) { | 1096 if (resp.plugin) { |
1087 | 1097 |
1088 json11::Json::object jo; | 1098 json11::Json::object jo; |
1089 markRPC(jo); | 1099 markRPC(jo); |
1090 | 1100 |
1091 jo["method"] = "load"; | 1101 jo["method"] = "load"; |
1092 jo["result"] = fromLoadResponse(resp, pmapper); | 1102 jo["result"] = fromLoadResponse(resp, pmapper); |
1103 addId(jo, id); | |
1093 return json11::Json(jo); | 1104 return json11::Json(jo); |
1094 | 1105 |
1095 } else { | 1106 } else { |
1096 return fromError("Failed to load plugin", RRType::Load); | 1107 return fromError("Failed to load plugin", RRType::Load, id); |
1097 } | 1108 } |
1098 } | 1109 } |
1099 | 1110 |
1100 static json11::Json | 1111 static json11::Json |
1101 fromRpcRequest_Configure(const Vamp::HostExt::ConfigurationRequest &req, | 1112 fromRpcRequest_Configure(const Vamp::HostExt::ConfigurationRequest &req, |
1109 return json11::Json(jo); | 1120 return json11::Json(jo); |
1110 } | 1121 } |
1111 | 1122 |
1112 static json11::Json | 1123 static json11::Json |
1113 fromRpcResponse_Configure(const Vamp::HostExt::ConfigurationResponse &resp, | 1124 fromRpcResponse_Configure(const Vamp::HostExt::ConfigurationResponse &resp, |
1114 const PluginHandleMapper &pmapper) { | 1125 const PluginHandleMapper &pmapper, |
1126 const json11::Json &id) { | |
1115 | 1127 |
1116 if (!resp.outputs.empty()) { | 1128 if (!resp.outputs.empty()) { |
1117 | 1129 |
1118 json11::Json::object jo; | 1130 json11::Json::object jo; |
1119 markRPC(jo); | 1131 markRPC(jo); |
1120 | 1132 |
1121 jo["method"] = "configure"; | 1133 jo["method"] = "configure"; |
1122 jo["result"] = fromConfigurationResponse(resp, pmapper); | 1134 jo["result"] = fromConfigurationResponse(resp, pmapper); |
1135 addId(jo, id); | |
1123 return json11::Json(jo); | 1136 return json11::Json(jo); |
1124 | 1137 |
1125 } else { | 1138 } else { |
1126 return fromError("Failed to configure plugin", RRType::Configure); | 1139 return fromError("Failed to configure plugin", RRType::Configure, id); |
1127 } | 1140 } |
1128 } | 1141 } |
1129 | 1142 |
1130 static json11::Json | 1143 static json11::Json |
1131 fromRpcRequest_Process(const Vamp::HostExt::ProcessRequest &req, | 1144 fromRpcRequest_Process(const Vamp::HostExt::ProcessRequest &req, |
1132 const PluginHandleMapper &pmapper, | 1145 const PluginHandleMapper &pmapper, |
1133 BufferSerialisation serialisation) { | 1146 BufferSerialisation serialisation) { |
1134 | 1147 |
1135 json11::Json::object jo; | 1148 json11::Json::object jo; |
1136 markRPC(jo); | 1149 markRPC(jo); |
1137 | 1150 |
1138 jo["method"] = "process"; | 1151 jo["method"] = "process"; |
1140 return json11::Json(jo); | 1153 return json11::Json(jo); |
1141 } | 1154 } |
1142 | 1155 |
1143 static json11::Json | 1156 static json11::Json |
1144 fromRpcResponse_Process(const Vamp::HostExt::ProcessResponse &resp, | 1157 fromRpcResponse_Process(const Vamp::HostExt::ProcessResponse &resp, |
1145 const PluginHandleMapper &pmapper, | 1158 const PluginHandleMapper &pmapper, |
1146 BufferSerialisation serialisation) { | 1159 BufferSerialisation serialisation, |
1160 const json11::Json &id) { | |
1147 | 1161 |
1148 json11::Json::object jo; | 1162 json11::Json::object jo; |
1149 markRPC(jo); | 1163 markRPC(jo); |
1150 | 1164 |
1151 json11::Json::object po; | 1165 json11::Json::object po; |
1153 po["features"] = fromFeatureSet(resp.features, | 1167 po["features"] = fromFeatureSet(resp.features, |
1154 *pmapper.pluginToOutputIdMapper(resp.plugin), | 1168 *pmapper.pluginToOutputIdMapper(resp.plugin), |
1155 serialisation); | 1169 serialisation); |
1156 jo["method"] = "process"; | 1170 jo["method"] = "process"; |
1157 jo["result"] = po; | 1171 jo["result"] = po; |
1172 addId(jo, id); | |
1158 return json11::Json(jo); | 1173 return json11::Json(jo); |
1159 } | 1174 } |
1160 | 1175 |
1161 static json11::Json | 1176 static json11::Json |
1162 fromRpcRequest_Finish(const Vamp::HostExt::FinishRequest &req, | 1177 fromRpcRequest_Finish(const Vamp::HostExt::FinishRequest &req, |
1173 return json11::Json(jo); | 1188 return json11::Json(jo); |
1174 } | 1189 } |
1175 | 1190 |
1176 static json11::Json | 1191 static json11::Json |
1177 fromRpcResponse_Finish(const Vamp::HostExt::ProcessResponse &resp, | 1192 fromRpcResponse_Finish(const Vamp::HostExt::ProcessResponse &resp, |
1178 const PluginHandleMapper &pmapper, | 1193 const PluginHandleMapper &pmapper, |
1179 BufferSerialisation serialisation) { | 1194 BufferSerialisation serialisation, |
1195 const json11::Json &id) { | |
1180 | 1196 |
1181 json11::Json::object jo; | 1197 json11::Json::object jo; |
1182 markRPC(jo); | 1198 markRPC(jo); |
1183 | 1199 |
1184 json11::Json::object po; | 1200 json11::Json::object po; |
1186 po["features"] = fromFeatureSet(resp.features, | 1202 po["features"] = fromFeatureSet(resp.features, |
1187 *pmapper.pluginToOutputIdMapper(resp.plugin), | 1203 *pmapper.pluginToOutputIdMapper(resp.plugin), |
1188 serialisation); | 1204 serialisation); |
1189 jo["method"] = "finish"; | 1205 jo["method"] = "finish"; |
1190 jo["result"] = po; | 1206 jo["result"] = po; |
1191 return json11::Json(jo); | 1207 addId(jo, id); |
1192 } | 1208 return json11::Json(jo); |
1193 | 1209 } |
1194 static json11::Json | 1210 |
1195 fromError(std::string errorText, RRType responseType) { | 1211 static json11::Json |
1212 fromError(std::string errorText, | |
1213 RRType responseType, | |
1214 const json11::Json &id) { | |
1196 | 1215 |
1197 json11::Json::object jo; | 1216 json11::Json::object jo; |
1198 markRPC(jo); | 1217 markRPC(jo); |
1199 | 1218 |
1200 std::string type; | 1219 std::string type; |
1211 eo["message"] = | 1230 eo["message"] = |
1212 std::string("error in ") + type + " request: " + errorText; | 1231 std::string("error in ") + type + " request: " + errorText; |
1213 | 1232 |
1214 jo["method"] = type; | 1233 jo["method"] = type; |
1215 jo["error"] = eo; | 1234 jo["error"] = eo; |
1216 | 1235 addId(jo, id); |
1217 return json11::Json(jo); | 1236 return json11::Json(jo); |
1218 } | 1237 } |
1219 | 1238 |
1220 static RRType | 1239 static RRType |
1221 getRequestResponseType(json11::Json j, std::string &err) { | 1240 getRequestResponseType(json11::Json j, std::string &err) { |