From 1e1e598df6d1d9530dde6e92d8f74f8143f60e50 Mon Sep 17 00:00:00 2001 From: Jonathan Doman Date: Fri, 11 Jun 2021 09:36:17 -0700 Subject: Using sdbusplus::asio::getProperty It simplifies a lot of code and after changing sdbusplus implementation slightly reduces binary size if used together with: https://gerrit.openbmc-project.xyz/c/openbmc/sdbusplus/+/49467 * Uncompressed size: 3033148 -> 3012164, -20984 B * gzip compressed size: 1220586 -> 1214625, -5961 B Tested: - Redfish validator output is the same before and after the change Change-Id: Ibe3227d3f4230de2363ba3d9396e51130c8240a5 Signed-off-by: Jonathan Doman Signed-off-by: Krzysztof Grobelny --- redfish-core/lib/led.hpp | 180 +++++++++++++++++++++-------------------------- 1 file changed, 82 insertions(+), 98 deletions(-) (limited to 'redfish-core/lib/led.hpp') diff --git a/redfish-core/lib/led.hpp b/redfish-core/lib/led.hpp index c4a7ed8805..6f5f5f121b 100644 --- a/redfish-core/lib/led.hpp +++ b/redfish-core/lib/led.hpp @@ -20,6 +20,7 @@ #include "redfish_util.hpp" #include +#include namespace redfish { @@ -35,61 +36,57 @@ inline void getIndicatorLedState(const std::shared_ptr& aResp) { BMCWEB_LOG_DEBUG << "Get led groups"; - crow::connections::systemBus->async_method_call( - [aResp](const boost::system::error_code ec, - const dbus::utility::DbusVariantType asserted) { + sdbusplus::asio::getProperty( + *crow::connections::systemBus, "xyz.openbmc_project.LED.GroupManager", + "/xyz/openbmc_project/led/groups/enclosure_identify_blink", + "xyz.openbmc_project.Led.Group", "Asserted", + [aResp](const boost::system::error_code ec, const bool blinking) { // Some systems may not have enclosure_identify_blink object so // proceed to get enclosure_identify state. - if (!ec) + if (ec == boost::system::errc::invalid_argument) { - const bool* blinking = std::get_if(&asserted); - if (!blinking) - { - BMCWEB_LOG_DEBUG << "Get identity blinking LED failed"; - messages::internalError(aResp->res); - return; - } - // Blinking ON, no need to check enclosure_identify assert. - if (*blinking) - { - aResp->res.jsonValue["IndicatorLED"] = "Blinking"; - return; - } + BMCWEB_LOG_DEBUG + << "Get identity blinking LED failed, missmatch in property type"; + messages::internalError(aResp->res); + return; } - crow::connections::systemBus->async_method_call( - [aResp](const boost::system::error_code ec2, - const dbus::utility::DbusVariantType asserted2) { - if (!ec2) - { - const bool* ledOn = std::get_if(&asserted2); - if (!ledOn) - { - BMCWEB_LOG_DEBUG - << "Get enclosure identity led failed"; - messages::internalError(aResp->res); - return; - } - if (*ledOn) - { - aResp->res.jsonValue["IndicatorLED"] = "Lit"; - } - else - { - aResp->res.jsonValue["IndicatorLED"] = "Off"; - } - } - return; - }, + // Blinking ON, no need to check enclosure_identify assert. + if (!ec && blinking) + { + aResp->res.jsonValue["IndicatorLED"] = "Blinking"; + return; + } + + sdbusplus::asio::getProperty( + *crow::connections::systemBus, "xyz.openbmc_project.LED.GroupManager", "/xyz/openbmc_project/led/groups/enclosure_identify", - "org.freedesktop.DBus.Properties", "Get", - "xyz.openbmc_project.Led.Group", "Asserted"); - }, - "xyz.openbmc_project.LED.GroupManager", - "/xyz/openbmc_project/led/groups/enclosure_identify_blink", - "org.freedesktop.DBus.Properties", "Get", - "xyz.openbmc_project.Led.Group", "Asserted"); + "xyz.openbmc_project.Led.Group", "Asserted", + [aResp](const boost::system::error_code ec2, const bool ledOn) { + if (ec2 == boost::system::errc::invalid_argument) + { + BMCWEB_LOG_DEBUG + << "Get enclosure identity led failed, missmatch in property type"; + messages::internalError(aResp->res); + return; + } + + if (ec2) + { + return; + } + + if (ledOn) + { + aResp->res.jsonValue["IndicatorLED"] = "Lit"; + } + else + { + aResp->res.jsonValue["IndicatorLED"] = "Off"; + } + }); + }); } /** @@ -169,63 +166,50 @@ inline void getLocationIndicatorActive(const std::shared_ptr& aResp) { BMCWEB_LOG_DEBUG << "Get LocationIndicatorActive"; - crow::connections::systemBus->async_method_call( - [aResp](const boost::system::error_code ec, - const dbus::utility::DbusVariantType asserted) { + sdbusplus::asio::getProperty( + *crow::connections::systemBus, "xyz.openbmc_project.LED.GroupManager", + "/xyz/openbmc_project/led/groups/enclosure_identify_blink", + "xyz.openbmc_project.Led.Group", "Asserted", + [aResp](const boost::system::error_code ec, const bool blinking) { // Some systems may not have enclosure_identify_blink object so // proceed to get enclosure_identify state. - if (!ec) + if (ec == boost::system::errc::invalid_argument) { - const bool* blinking = std::get_if(&asserted); - if (!blinking) - { - BMCWEB_LOG_DEBUG << "Get identity blinking LED failed"; - messages::internalError(aResp->res); - return; - } - // Blinking ON, no need to check enclosure_identify assert. - if (*blinking) - { - aResp->res.jsonValue["LocationIndicatorActive"] = true; - return; - } + BMCWEB_LOG_DEBUG + << "Get identity blinking LED failed, missmatch in property type"; + messages::internalError(aResp->res); + return; } - crow::connections::systemBus->async_method_call( - [aResp](const boost::system::error_code ec2, - const dbus::utility::DbusVariantType asserted2) { - if (!ec2) - { - const bool* ledOn = std::get_if(&asserted2); - if (!ledOn) - { - BMCWEB_LOG_DEBUG - << "Get enclosure identity led failed"; - messages::internalError(aResp->res); - return; - } - if (*ledOn) - { - aResp->res.jsonValue["LocationIndicatorActive"] = - true; - } - else - { - aResp->res.jsonValue["LocationIndicatorActive"] = - false; - } - } - return; - }, + // Blinking ON, no need to check enclosure_identify assert. + if (!ec && blinking) + { + aResp->res.jsonValue["LocationIndicatorActive"] = true; + return; + } + + sdbusplus::asio::getProperty( + *crow::connections::systemBus, "xyz.openbmc_project.LED.GroupManager", "/xyz/openbmc_project/led/groups/enclosure_identify", - "org.freedesktop.DBus.Properties", "Get", - "xyz.openbmc_project.Led.Group", "Asserted"); - }, - "xyz.openbmc_project.LED.GroupManager", - "/xyz/openbmc_project/led/groups/enclosure_identify_blink", - "org.freedesktop.DBus.Properties", "Get", - "xyz.openbmc_project.Led.Group", "Asserted"); + "xyz.openbmc_project.Led.Group", "Asserted", + [aResp](const boost::system::error_code ec2, const bool ledOn) { + if (ec2 == boost::system::errc::invalid_argument) + { + BMCWEB_LOG_DEBUG + << "Get enclosure identity led failed, missmatch in property type"; + messages::internalError(aResp->res); + return; + } + + if (ec2) + { + return; + } + + aResp->res.jsonValue["LocationIndicatorActive"] = ledOn; + }); + }); } /** -- cgit v1.2.3