summaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorMatt Spinler <spinler@us.ibm.com>2019-01-14 13:13:00 -0600
committerMatt Spinler <spinler@us.ibm.com>2019-01-21 14:01:04 -0600
commit89c1970b718ae26497d3f7c9ac5e596fa2fb3968 (patch)
tree79e22e902550ed0533d4939428750c4126b0c970 /include
parent75c6c67f82c1fce39e42bc3f374555a84fc44ab1 (diff)
downloadbmcweb-89c1970b718ae26497d3f7c9ac5e596fa2fb3968.tar.gz
bmcweb-89c1970b718ae26497d3f7c9ac5e596fa2fb3968.zip
REST: Add method return support for variants
Variants are in their own container. In order to get the type of the data contained in the variant, the peek API needs to be used. Resolves openbmc/bmcweb#24 Change-Id: I085064a8eabe2f57cfa0f1977fe7b9c19baa80e2 Signed-off-by: Matt Spinler <spinler@us.ibm.com>
Diffstat (limited to 'include')
-rw-r--r--include/openbmc_dbus_rest.hpp44
1 files changed, 43 insertions, 1 deletions
diff --git a/include/openbmc_dbus_rest.hpp b/include/openbmc_dbus_rest.hpp
index a5024be..9f282a6 100644
--- a/include/openbmc_dbus_rest.hpp
+++ b/include/openbmc_dbus_rest.hpp
@@ -995,6 +995,41 @@ int readStructFromMessage(const std::string &typeCode,
return 0;
}
+int readVariantFromMessage(sdbusplus::message::message &m, nlohmann::json &data)
+{
+ const char *containerType;
+ int r = sd_bus_message_peek_type(m.get(), NULL, &containerType);
+ if (r < 0)
+ {
+ BMCWEB_LOG_ERROR << "sd_bus_message_peek_type failed";
+ return r;
+ }
+
+ r = sd_bus_message_enter_container(m.get(), SD_BUS_TYPE_VARIANT,
+ containerType);
+ if (r < 0)
+ {
+ BMCWEB_LOG_ERROR << "sd_bus_message_enter_container failed with rc "
+ << r;
+ return r;
+ }
+
+ r = convertDBusToJSON(containerType, m, data);
+ if (r < 0)
+ {
+ return r;
+ }
+
+ r = sd_bus_message_exit_container(m.get());
+ if (r < 0)
+ {
+ BMCWEB_LOG_ERROR << "sd_bus_message_enter_container failed";
+ return r;
+ }
+
+ return 0;
+}
+
int convertDBusToJSON(const std::string &returnType,
sdbusplus::message::message &m, nlohmann::json &response)
{
@@ -1133,9 +1168,16 @@ int convertDBusToJSON(const std::string &returnType,
return r;
}
}
+ else if (boost::starts_with(typeCode, "v"))
+ {
+ r = readVariantFromMessage(m, thisElement);
+ if (r < 0)
+ {
+ return r;
+ }
+ }
else
{
- // TODO: add variant support
BMCWEB_LOG_ERROR << "Invalid D-Bus signature type " << typeCode;
return -2;
}
OpenPOWER on IntegriCloud