diff json/VampJson.h @ 10:c8451896c40e

Some conversions for plugin handles
author Chris Cannam <c.cannam@qmul.ac.uk>
date Tue, 17 May 2016 09:58:15 +0100
parents d8358afe3f2c
children 828930f9a65d
line wrap: on
line diff
--- a/json/VampJson.h	Mon May 16 15:46:22 2016 +0100
+++ b/json/VampJson.h	Tue May 17 09:58:15 2016 +0100
@@ -14,6 +14,10 @@
 #include <vamp-hostsdk/Plugin.h>
 #include <vamp-hostsdk/PluginLoader.h>
 
+#include "bits/PluginHandleMapper.h"
+
+namespace vampipe {
+
 /**
  * Convert the structures laid out in the Vamp SDK classes into JSON
  * (and back again) following the schema in the vamp-json-schema
@@ -663,7 +667,40 @@
         req.adapterFlags = toAdapterFlags(j["adapterFlags"]);
         return req;
     }
+
+    static json11::Json
+    fromLoadResponse(Vamp::HostExt::LoadResponse resp,
+                     PluginHandleMapper &mapper) {
+
+        json11::Json::object jo;
+        jo["pluginHandle"] = double(mapper.pluginToHandle(resp.plugin));
+        jo["staticData"] = fromPluginStaticData(resp.staticData);
+        jo["defaultConfiguration"] =
+            fromPluginConfiguration(resp.defaultConfiguration);
+        return json11::Json(jo);
+    }
+
+    static Vamp::HostExt::LoadResponse
+    toLoadResponse(json11::Json j,
+                   PluginHandleMapper &mapper) {
+
+        std::string err;
+
+        if (!j.has_shape({
+                    { "pluginHandle", json11::Json::NUMBER },
+                    { "staticData", json11::Json::OBJECT },
+                    { "defaultConfiguration", json11::Json::OBJECT } }, err)) {
+            throw VampJson::Failure("malformed load response: " + err);
+        }
+
+        Vamp::HostExt::LoadResponse resp;
+        resp.plugin = mapper.handleToPlugin(j["pluginHandle"].int_value());
+        resp.staticData = toPluginStaticData(j["staticData"]);
+        resp.defaultConfiguration = toPluginConfiguration(j["defaultConfiguration"]);
+        return resp;
+    }
 };
 
+}
 
 #endif