diff options
author | Jonathan Doman <jonathan.doman@intel.com> | 2021-06-11 19:36:17 +0300 |
---|---|---|
committer | Krzysztof Grobelny <krzysztof.grobelny@intel.com> | 2021-12-28 15:23:02 +0300 |
commit | 1e1e598df6d1d9530dde6e92d8f74f8143f60e50 (patch) | |
tree | b71aee4a4c50c79332e14d6e74094693888855a6 /redfish-core/lib/metric_report.hpp | |
parent | 168e20c1306e3e689907ba43e14ea679e2328611 (diff) | |
download | bmcweb-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/metric_report.hpp')
-rw-r--r-- | redfish-core/lib/metric_report.hpp | 32 |
1 files changed, 11 insertions, 21 deletions
diff --git a/redfish-core/lib/metric_report.hpp b/redfish-core/lib/metric_report.hpp index c36f719a56..b7ebb9902e 100644 --- a/redfish-core/lib/metric_report.hpp +++ b/redfish-core/lib/metric_report.hpp @@ -6,6 +6,7 @@ #include <app.hpp> #include <dbus_utility.hpp> #include <registries/privilege_registry.hpp> +#include <sdbusplus/asio/property.hpp> namespace redfish { @@ -35,7 +36,7 @@ inline nlohmann::json toMetricValues(const Readings& readings) } inline bool fillReport(nlohmann::json& json, const std::string& id, - const dbus::utility::DbusVariantType& var) + const TimestampReadings& timestampReadings) { json["@odata.type"] = "#MetricReport.v1_3_0.MetricReport"; json["@odata.id"] = telemetry::metricReportUri + std::string("/") + id; @@ -44,15 +45,7 @@ inline bool fillReport(nlohmann::json& json, const std::string& id, json["MetricReportDefinition"]["@odata.id"] = telemetry::metricReportDefinitionUri + std::string("/") + id; - const TimestampReadings* timestampReadings = - std::get_if<TimestampReadings>(&var); - if (!timestampReadings) - { - BMCWEB_LOG_ERROR << "Property type mismatch or property is missing"; - return false; - } - - const auto& [timestamp, readings] = *timestampReadings; + const auto& [timestamp, readings] = timestampReadings; json["Timestamp"] = crow::utility::getDateTimeUint(timestamp); json["MetricValues"] = toMetricValues(readings); return true; @@ -105,10 +98,13 @@ inline void requestRoutesMetricReport(App& app) return; } - crow::connections::systemBus->async_method_call( + sdbusplus::asio::getProperty< + telemetry::TimestampReadings>( + *crow::connections::systemBus, telemetry::service, + reportPath, telemetry::reportInterface, "Readings", [asyncResp, id](const boost::system::error_code ec, - const dbus::utility::DbusVariantType& ret) { + const telemetry::TimestampReadings& ret) { if (ec) { BMCWEB_LOG_ERROR @@ -117,15 +113,9 @@ inline void requestRoutesMetricReport(App& app) return; } - if (!telemetry::fillReport( - asyncResp->res.jsonValue, id, ret)) - { - messages::internalError(asyncResp->res); - } - }, - telemetry::service, reportPath, - "org.freedesktop.DBus.Properties", "Get", - telemetry::reportInterface, "Readings"); + telemetry::fillReport(asyncResp->res.jsonValue, + id, ret); + }); }, telemetry::service, reportPath, telemetry::reportInterface, "Update"); |