Mercurial > hg > piper-cpp
comparison json/VampJson.h @ 52:e90fd30990eb
Error handling, and pass plugin handles through
author | Chris Cannam <c.cannam@qmul.ac.uk> |
---|---|
date | Fri, 16 Sep 2016 16:20:05 +0100 |
parents | f4244a2d55ac |
children | 38780f15ac8d |
comparison
equal
deleted
inserted
replaced
51:f4244a2d55ac | 52:e90fd30990eb |
---|---|
999 | 999 |
1000 json11::Json::object jo; | 1000 json11::Json::object jo; |
1001 jo["type"] = "process"; | 1001 jo["type"] = "process"; |
1002 jo["success"] = true; | 1002 jo["success"] = true; |
1003 jo["errorText"] = ""; | 1003 jo["errorText"] = ""; |
1004 jo["content"] = fromFeatureSet(resp.features, | 1004 json11::Json::object po; |
1005 pmapper.pluginToOutputIdMapper(resp.plugin), | 1005 po["pluginHandle"] = pmapper.pluginToHandle(resp.plugin); |
1006 serialisation); | 1006 po["features"] = fromFeatureSet(resp.features, |
1007 pmapper.pluginToOutputIdMapper(resp.plugin), | |
1008 serialisation); | |
1009 jo["content"] = po; | |
1007 return json11::Json(jo); | 1010 return json11::Json(jo); |
1008 } | 1011 } |
1009 | 1012 |
1010 static json11::Json | 1013 static json11::Json |
1011 fromVampRequest_Finish(Vamp::Plugin *p, | 1014 fromVampRequest_Finish(Vamp::Plugin *p, |
1026 | 1029 |
1027 json11::Json::object jo; | 1030 json11::Json::object jo; |
1028 jo["type"] = "finish"; | 1031 jo["type"] = "finish"; |
1029 jo["success"] = true; | 1032 jo["success"] = true; |
1030 jo["errorText"] = ""; | 1033 jo["errorText"] = ""; |
1031 jo["content"] = fromFeatureSet(resp.features, | 1034 json11::Json::object po; |
1032 pmapper.pluginToOutputIdMapper(resp.plugin), | 1035 po["pluginHandle"] = pmapper.pluginToHandle(resp.plugin); |
1033 serialisation); | 1036 po["features"] = fromFeatureSet(resp.features, |
1034 return json11::Json(jo); | 1037 pmapper.pluginToOutputIdMapper(resp.plugin), |
1035 } | 1038 serialisation); |
1036 | 1039 jo["content"] = po; |
1037 static json11::Json | 1040 return json11::Json(jo); |
1038 fromException(const std::exception &e, RRType responseType) { | 1041 } |
1042 | |
1043 static json11::Json | |
1044 fromError(std::string errorText, RRType responseType) { | |
1039 | 1045 |
1040 json11::Json::object jo; | 1046 json11::Json::object jo; |
1041 std::string type; | 1047 std::string type; |
1042 | 1048 |
1043 if (responseType == RRType::List) type = "list"; | 1049 if (responseType == RRType::List) type = "list"; |
1047 else if (responseType == RRType::Finish) type = "finish"; | 1053 else if (responseType == RRType::Finish) type = "finish"; |
1048 else type = "invalid"; | 1054 else type = "invalid"; |
1049 | 1055 |
1050 jo["type"] = type; | 1056 jo["type"] = type; |
1051 jo["success"] = false; | 1057 jo["success"] = false; |
1052 jo["errorText"] = std::string("exception caught: ") + | 1058 jo["errorText"] = std::string("error in ") + type + " request: " + errorText; |
1053 type + " request: " + e.what(); | 1059 return json11::Json(jo); |
1054 return json11::Json(jo); | 1060 } |
1061 | |
1062 static json11::Json | |
1063 fromException(const std::exception &e, RRType responseType) { | |
1064 | |
1065 return fromError(e.what(), responseType); | |
1055 } | 1066 } |
1056 | 1067 |
1057 private: // go private briefly for a couple of helper functions | 1068 private: // go private briefly for a couple of helper functions |
1058 | 1069 |
1059 static void | 1070 static void |
1161 BufferSerialisation &serialisation) { | 1172 BufferSerialisation &serialisation) { |
1162 | 1173 |
1163 Vamp::HostExt::ProcessResponse resp; | 1174 Vamp::HostExt::ProcessResponse resp; |
1164 if (successful(j)) { | 1175 if (successful(j)) { |
1165 auto jc = j["content"]; | 1176 auto jc = j["content"]; |
1166 resp.features = toFeatureSet | 1177 auto h = jc["pluginHandle"].int_value(); |
1167 (jc["features"], | 1178 resp.plugin = pmapper.handleToPlugin(h); |
1168 pmapper.handleToOutputIdMapper(jc["pluginHandle"].int_value()), | 1179 resp.features = toFeatureSet(jc["features"], |
1169 serialisation); | 1180 pmapper.handleToOutputIdMapper(h), |
1181 serialisation); | |
1170 } | 1182 } |
1171 return resp; | 1183 return resp; |
1172 } | 1184 } |
1173 | 1185 |
1174 static Vamp::Plugin * | 1186 static Vamp::Plugin * |
1184 BufferSerialisation &serialisation) { | 1196 BufferSerialisation &serialisation) { |
1185 | 1197 |
1186 Vamp::HostExt::ProcessResponse resp; | 1198 Vamp::HostExt::ProcessResponse resp; |
1187 if (successful(j)) { | 1199 if (successful(j)) { |
1188 auto jc = j["content"]; | 1200 auto jc = j["content"]; |
1189 resp.features = toFeatureSet | 1201 auto h = jc["pluginHandle"].int_value(); |
1190 (jc["features"], | 1202 resp.plugin = pmapper.handleToPlugin(h); |
1191 pmapper.handleToOutputIdMapper(jc["pluginHandle"].int_value()), | 1203 resp.features = toFeatureSet(jc["features"], |
1192 serialisation); | 1204 pmapper.handleToOutputIdMapper(h), |
1205 serialisation); | |
1193 } | 1206 } |
1194 return resp; | 1207 return resp; |
1195 } | 1208 } |
1196 }; | 1209 }; |
1197 | 1210 |