diff options
| author | Ed Tanous <ed.tanous@intel.com> | 2018-10-16 14:09:17 -0700 |
|---|---|---|
| committer | Jason M. Bills <jason.m.bills@linux.intel.com> | 2018-11-19 10:32:12 -0800 |
| commit | b1556427d980393a9c93f84faaccbd6376022f9a (patch) | |
| tree | c8d88a9486cb84a499f58ec205bc26ce727a17a9 /redfish-core/include | |
| parent | 976596bcd89c7087c4981400f76377345b74fd66 (diff) | |
| download | bmcweb-b1556427d980393a9c93f84faaccbd6376022f9a.tar.gz bmcweb-b1556427d980393a9c93f84faaccbd6376022f9a.zip | |
Move Redfish PECI to the new json interface
This change adds vector handling to the new json interface
and modifies the SendRawPECI Redfish command to utilize it.
Tested: Executed raw PECI commands with good and bad input
to check that it will work and error out correctly.
Change-Id: Ic1c837f5823d28555f727849156b4dabf1b8acef
Signed-off-by: Ed Tanous <ed.tanous@intel.com>
Signed-off-by: Jason M. Bills <jason.m.bills@linux.intel.com>
Diffstat (limited to 'redfish-core/include')
| -rw-r--r-- | redfish-core/include/utils/json_utils.hpp | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/redfish-core/include/utils/json_utils.hpp b/redfish-core/include/utils/json_utils.hpp index 778a905..1d969e0 100644 --- a/redfish-core/include/utils/json_utils.hpp +++ b/redfish-core/include/utils/json_utils.hpp @@ -55,6 +55,16 @@ struct is_optional<boost::optional<Type>> : std::true_type template <typename Type> constexpr bool is_optional_v = is_optional<Type>::value; +template <typename Type> struct is_vector : std::false_type +{ +}; + +template <typename Type> struct is_vector<std::vector<Type>> : std::true_type +{ +}; + +template <typename Type> constexpr bool is_vector_v = is_vector<Type>::value; + template <typename Type> void unpackValue(nlohmann::json& jsonValue, const std::string& key, crow::Response& res, Type& value) @@ -94,6 +104,21 @@ void unpackValue(nlohmann::json& jsonValue, const std::string& key, value.emplace(); unpackValue<typename Type::value_type>(jsonValue, key, res, *value); } + else if constexpr (is_vector_v<Type>) + { + if (!jsonValue.is_array()) + { + messages::propertyValueTypeError(res, res.jsonValue.dump(), key); + return; + } + + for (const auto& val : jsonValue.items()) + { + value.emplace_back(); + unpackValue<typename Type::value_type>(val.value(), key, res, + value.back()); + } + } else { using JsonType = std::add_const_t<std::add_pointer_t<Type>>; |

