summaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorMatt Spinler <spinler@us.ibm.com>2019-01-30 15:33:21 -0600
committerMatt Spinler <spinler@us.ibm.com>2019-01-31 08:28:08 -0600
commitfe7e97d3108aa98b6bead4101694098b09adbafb (patch)
treee3f3fa0a3f372d1d7a4d8b5d81d12dfd4fc72b5e /include
parent715748a15d6244384561128cf25a4732524a1575 (diff)
downloadbmcweb-fe7e97d3108aa98b6bead4101694098b09adbafb.tar.gz
bmcweb-fe7e97d3108aa98b6bead4101694098b09adbafb.zip
REST: GET: Use convertDBusToJSON
Use new_method_call() + async_send() to get back an sd_bus_message from the org.freedesktop.DBus.Properties.GetAll call in the GET handler, and then use convertDBusToJSON to extract any possible property type instead of having to use a variant with all possible property types defined ahead of time. Tested: Did a get on several different paths, including one in /org/open_power/ that had a signature of a(tx) that previously didn't return anything. Resolves openbmc/bmcweb#34 Change-Id: I40309664fa969741c4af9a60b9059c60bf6f35f4 Signed-off-by: Matt Spinler <spinler@us.ibm.com>
Diffstat (limited to 'include')
-rw-r--r--include/openbmc_dbus_rest.hpp64
1 files changed, 33 insertions, 31 deletions
diff --git a/include/openbmc_dbus_rest.hpp b/include/openbmc_dbus_rest.hpp
index 907febb..9503191 100644
--- a/include/openbmc_dbus_rest.hpp
+++ b/include/openbmc_dbus_rest.hpp
@@ -1609,12 +1609,15 @@ void handleGet(crow::Response &res, std::string &objectPath,
for (const std::string &interface : interfaceNames)
{
- crow::connections::systemBus->async_method_call(
- [&res, response, propertyName](
- const boost::system::error_code ec,
- const std::vector<std::pair<
- std::string, dbus::utility::DbusVariantType>>
- &properties) {
+ sdbusplus::message::message m =
+ crow::connections::systemBus->new_method_call(
+ connection.first.c_str(), path->c_str(),
+ "org.freedesktop.DBus.Properties", "GetAll");
+ m.append(interface);
+ crow::connections::systemBus->async_send(
+ m, [&res, response,
+ propertyName](const boost::system::error_code ec,
+ sdbusplus::message::message &msg) {
if (ec)
{
BMCWEB_LOG_ERROR << "Bad dbus request error: "
@@ -1622,30 +1625,31 @@ void handleGet(crow::Response &res, std::string &objectPath,
}
else
{
- for (const std::pair<
- std::string,
- dbus::utility::DbusVariantType>
- &property : properties)
+ nlohmann::json properties;
+ int r =
+ convertDBusToJSON("a{sv}", msg, properties);
+ if (r < 0)
{
- // if property name is empty, or matches our
- // search query, add it to the response json
-
- if (propertyName->empty())
- {
- sdbusplus::message::variant_ns::visit(
- [&response, &property](auto &&val) {
- (*response)[property.first] =
- val;
- },
- property.second);
- }
- else if (property.first == *propertyName)
+ BMCWEB_LOG_ERROR
+ << "convertDBusToJSON failed";
+ }
+ else
+ {
+ for (auto &prop : properties.items())
{
- sdbusplus::message::variant_ns::visit(
- [&response](auto &&val) {
- (*response) = val;
- },
- property.second);
+ // if property name is empty, or matches
+ // our search query, add it to the
+ // response json
+
+ if (propertyName->empty())
+ {
+ (*response)[prop.key()] =
+ std::move(prop.value());
+ }
+ else if (prop.key() == *propertyName)
+ {
+ *response = std::move(prop.value());
+ }
}
}
}
@@ -1666,9 +1670,7 @@ void handleGet(crow::Response &res, std::string &objectPath,
}
res.end();
}
- },
- connection.first, *path,
- "org.freedesktop.DBus.Properties", "GetAll", interface);
+ });
}
}
},
OpenPOWER on IntegriCloud