summaryrefslogtreecommitdiff
path: root/redfish-core/lib/led.hpp
diff options
context:
space:
mode:
authorJonathan Doman <jonathan.doman@intel.com>2021-06-11 19:36:17 +0300
committerKrzysztof Grobelny <krzysztof.grobelny@intel.com>2021-12-28 15:23:02 +0300
commit1e1e598df6d1d9530dde6e92d8f74f8143f60e50 (patch)
treeb71aee4a4c50c79332e14d6e74094693888855a6 /redfish-core/lib/led.hpp
parent168e20c1306e3e689907ba43e14ea679e2328611 (diff)
downloadbmcweb-1e1e598df6d1d9530dde6e92d8f74f8143f60e50.tar.xz
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 <jonathan.doman@intel.com> Signed-off-by: Krzysztof Grobelny <krzysztof.grobelny@intel.com>
Diffstat (limited to 'redfish-core/lib/led.hpp')
-rw-r--r--redfish-core/lib/led.hpp180
1 files changed, 82 insertions, 98 deletions
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 <app.hpp>
+#include <sdbusplus/asio/property.hpp>
namespace redfish
{
@@ -35,61 +36,57 @@ inline void
getIndicatorLedState(const std::shared_ptr<bmcweb::AsyncResp>& 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<bool>(
+ *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<bool>(&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<bool>(&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<bool>(
+ *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<bmcweb::AsyncResp>& 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<bool>(
+ *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<bool>(&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<bool>(&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<bool>(
+ *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;
+ });
+ });
}
/**