diff 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
line wrap: on
line diff
--- a/json/VampJson.h	Fri Sep 16 15:10:57 2016 +0100
+++ b/json/VampJson.h	Fri Sep 16 16:20:05 2016 +0100
@@ -1001,9 +1001,12 @@
         jo["type"] = "process";
         jo["success"] = true;
         jo["errorText"] = "";
-        jo["content"] = fromFeatureSet(resp.features,
-                                       pmapper.pluginToOutputIdMapper(resp.plugin),
-                                       serialisation);
+        json11::Json::object po;
+        po["pluginHandle"] = pmapper.pluginToHandle(resp.plugin);
+        po["features"] = fromFeatureSet(resp.features,
+                                        pmapper.pluginToOutputIdMapper(resp.plugin),
+                                        serialisation);
+        jo["content"] = po;
         return json11::Json(jo);
     }
     
@@ -1028,14 +1031,17 @@
         jo["type"] = "finish";
         jo["success"] = true;
         jo["errorText"] = "";
-        jo["content"] = fromFeatureSet(resp.features,
-                                       pmapper.pluginToOutputIdMapper(resp.plugin),
-                                       serialisation);
+        json11::Json::object po;
+        po["pluginHandle"] = pmapper.pluginToHandle(resp.plugin);
+        po["features"] = fromFeatureSet(resp.features,
+                                        pmapper.pluginToOutputIdMapper(resp.plugin),
+                                        serialisation);
+        jo["content"] = po;
         return json11::Json(jo);
     }
 
     static json11::Json
-    fromException(const std::exception &e, RRType responseType) {
+    fromError(std::string errorText, RRType responseType) {
 
         json11::Json::object jo;
         std::string type;
@@ -1049,10 +1055,15 @@
 
         jo["type"] = type;
         jo["success"] = false;
-        jo["errorText"] = std::string("exception caught: ") +
-            type + " request: " + e.what();
+        jo["errorText"] = std::string("error in ") + type + " request: " + errorText;
         return json11::Json(jo);
     }
+
+    static json11::Json
+    fromException(const std::exception &e, RRType responseType) {
+
+        return fromError(e.what(), responseType);
+    }
     
 private: // go private briefly for a couple of helper functions
     
@@ -1163,10 +1174,11 @@
         Vamp::HostExt::ProcessResponse resp;
         if (successful(j)) {
             auto jc = j["content"];
-            resp.features = toFeatureSet
-                (jc["features"],
-                 pmapper.handleToOutputIdMapper(jc["pluginHandle"].int_value()),
-                 serialisation);
+            auto h = jc["pluginHandle"].int_value();
+            resp.plugin = pmapper.handleToPlugin(h);
+            resp.features = toFeatureSet(jc["features"],
+                                         pmapper.handleToOutputIdMapper(h),
+                                         serialisation);
         }
         return resp;
     }
@@ -1186,10 +1198,11 @@
         Vamp::HostExt::ProcessResponse resp;
         if (successful(j)) {
             auto jc = j["content"];
-            resp.features = toFeatureSet
-                (jc["features"],
-                 pmapper.handleToOutputIdMapper(jc["pluginHandle"].int_value()),
-                 serialisation);
+            auto h = jc["pluginHandle"].int_value();
+            resp.plugin = pmapper.handleToPlugin(h);
+            resp.features = toFeatureSet(jc["features"],
+                                         pmapper.handleToOutputIdMapper(h),
+                                         serialisation);
         }
         return resp;
     }