comparison json/VampJson.h @ 13:1d13354ddc44

Build & read config request/response etc
author Chris Cannam <c.cannam@qmul.ac.uk>
date Tue, 17 May 2016 16:18:24 +0100
parents 828930f9a65d
children 913fc1d3710a
comparison
equal deleted inserted replaced
12:828930f9a65d 13:1d13354ddc44
699 resp.defaultConfiguration = toPluginConfiguration(j["defaultConfiguration"]); 699 resp.defaultConfiguration = toPluginConfiguration(j["defaultConfiguration"]);
700 return resp; 700 return resp;
701 } 701 }
702 702
703 static json11::Json 703 static json11::Json
704 fromConfigurationRequest(const Vamp::HostExt::ConfigurationRequest &cr,
705 PluginHandleMapper &mapper) {
706
707 json11::Json::object jo;
708
709 jo["pluginHandle"] = mapper.pluginToHandle(cr.plugin);
710 jo["configuration"] = fromPluginConfiguration(cr.configuration);
711
712 return json11::Json(jo);
713 }
714
715 static Vamp::HostExt::ConfigurationRequest
716 toConfigurationRequest(json11::Json j,
717 PluginHandleMapper &mapper) {
718
719 std::string err;
720
721 if (!j.has_shape({
722 { "pluginHandle", json11::Json::NUMBER },
723 { "configuration", json11::Json::OBJECT } }, err)) {
724 throw Failure("malformed configuration request: " + err);
725 }
726
727 Vamp::HostExt::ConfigurationRequest cr;
728 cr.plugin = mapper.handleToPlugin(j["pluginHandle"].int_value());
729 cr.configuration = toPluginConfiguration(j["configuration"]);
730 return cr;
731 }
732
733 static json11::Json
704 fromConfigurationResponse(const Vamp::HostExt::ConfigurationResponse &cr) { 734 fromConfigurationResponse(const Vamp::HostExt::ConfigurationResponse &cr) {
705 735
706 json11::Json::object jout; 736 json11::Json::object jo;
707 737
708 json11::Json::array outs; 738 json11::Json::array outs;
709 for (auto &d: cr.outputs) { 739 for (auto &d: cr.outputs) {
710 outs.push_back(fromOutputDescriptor(d)); 740 outs.push_back(fromOutputDescriptor(d));
711 } 741 }
712 jout["outputList"] = outs; 742 jo["outputList"] = outs;
713 743
714 return json11::Json(jout); 744 return json11::Json(jo);
715 } 745 }
716 746
717 static Vamp::HostExt::ConfigurationResponse toConfigurationResponse(json11::Json j) { 747 static Vamp::HostExt::ConfigurationResponse
718 748 toConfigurationResponse(json11::Json j) {
749
719 Vamp::HostExt::ConfigurationResponse cr; 750 Vamp::HostExt::ConfigurationResponse cr;
720 751
721 if (!j["outputList"].is_array()) { 752 if (!j["outputList"].is_array()) {
722 throw Failure("array expected for output list"); 753 throw Failure("array expected for output list");
723 } 754 }