used sdbusplus::unpackPropertiesNoThrow part 7

used sdbusplus::unpackPropertiesNoThrow in cable.hpp,
metric_report_definition.hpp, telemetry_service.hpp and trigger.hpp,
also replaced all usages of "GetAll" with
sdbusplus::asio::getAllProperties

    bmcweb size: 2697624 -> 2693528 (-4096)
compressed size: 1129037 -> 1129322 (+285)

Tested:
  Performed get on one of the:
  - /redfish/v1/Cables
  - /redfish/v1/TelemetryService/MetricReportDefinitions
  - /redfish/v1/TelemetryService/Triggers
    (trigger was added using Dbus API)

  Get result before and after the change was in same format.

Change-Id: I24f001b4f52d8eb5f529b08de278a611f8fa22b2
Signed-off-by: Krzysztof Grobelny <krzysztof.grobelny@intel.com>
diff --git a/redfish-core/lib/cable.hpp b/redfish-core/lib/cable.hpp
index e553682..0b8cd0f 100644
--- a/redfish-core/lib/cable.hpp
+++ b/redfish-core/lib/cable.hpp
@@ -1,6 +1,9 @@
 #pragma once
 #include <dbus_utility.hpp>
 #include <query.hpp>
+#include <sdbusplus/asio/property.hpp>
+#include <sdbusplus/unpack_properties.hpp>
+#include <utils/dbus_utils.hpp>
 #include <utils/json_utils.hpp>
 
 namespace redfish
@@ -23,40 +26,37 @@
         return;
     }
 
-    for (const auto& [propKey, propVariant] : properties)
+    const std::string* cableTypeDescription = nullptr;
+    const double* length = nullptr;
+
+    const bool success = sdbusplus::unpackPropertiesNoThrow(
+        dbus_utils::UnpackErrorPrinter(), properties, "CableTypeDescription",
+        cableTypeDescription, "Length", length);
+
+    if (!success)
     {
-        if (propKey == "CableTypeDescription")
-        {
-            const std::string* cableTypeDescription =
-                std::get_if<std::string>(&propVariant);
-            if (cableTypeDescription == nullptr)
-            {
-                messages::internalError(resp);
-                return;
-            }
-            resp.jsonValue["CableType"] = *cableTypeDescription;
-        }
-        else if (propKey == "Length")
-        {
-            const double* cableLength = std::get_if<double>(&propVariant);
-            if (cableLength == nullptr)
-            {
-                messages::internalError(resp);
-                return;
-            }
+        messages::internalError(resp);
+        return;
+    }
 
-            if (!std::isfinite(*cableLength))
+    if (cableTypeDescription != nullptr)
+    {
+        resp.jsonValue["CableType"] = *cableTypeDescription;
+    }
+
+    if (length != nullptr)
+    {
+        if (!std::isfinite(*length))
+        {
+            if (std::isnan(*length))
             {
-                if (std::isnan(*cableLength))
-                {
-                    continue;
-                }
-                messages::internalError(resp);
                 return;
             }
-
-            resp.jsonValue["LengthMeters"] = *cableLength;
+            messages::internalError(resp);
+            return;
         }
+
+        resp.jsonValue["LengthMeters"] = *length;
     }
 }
 
@@ -83,14 +83,14 @@
                 continue;
             }
 
-            crow::connections::systemBus->async_method_call(
+            sdbusplus::asio::getAllProperties(
+                *crow::connections::systemBus, service, cableObjectPath,
+                interface,
                 [asyncResp](
                     const boost::system::error_code ec,
                     const dbus::utility::DBusPropertiesMap& properties) {
                 fillCableProperties(asyncResp->res, ec, properties);
-                },
-                service, cableObjectPath, "org.freedesktop.DBus.Properties",
-                "GetAll", interface);
+                });
         }
     }
 }
diff --git a/redfish-core/lib/metric_report_definition.hpp b/redfish-core/lib/metric_report_definition.hpp
index 88333fc..37e9031 100644
--- a/redfish-core/lib/metric_report_definition.hpp
+++ b/redfish-core/lib/metric_report_definition.hpp
@@ -9,6 +9,9 @@
 #include <dbus_utility.hpp>
 #include <query.hpp>
 #include <registries/privilege_registry.hpp>
+#include <sdbusplus/asio/property.hpp>
+#include <sdbusplus/unpack_properties.hpp>
+#include <utils/dbus_utils.hpp>
 
 #include <map>
 #include <tuple>
@@ -49,66 +52,61 @@
 
     const bool* emitsReadingsUpdate = nullptr;
     const bool* logToMetricReportsCollection = nullptr;
-    const ReadingParameters* readingParams = nullptr;
+    const ReadingParameters* readingParameters = nullptr;
     const std::string* reportingType = nullptr;
     const uint64_t* interval = nullptr;
-    for (const auto& [key, var] : ret)
+
+    const bool success = sdbusplus::unpackPropertiesNoThrow(
+        dbus_utils::UnpackErrorPrinter(), ret, "EmitsReadingsUpdate",
+        emitsReadingsUpdate, "LogToMetricReportsCollection",
+        logToMetricReportsCollection, "ReadingParameters", readingParameters,
+        "ReportingType", reportingType, "Interval", interval);
+
+    if (!success)
     {
-        if (key == "EmitsReadingsUpdate")
-        {
-            emitsReadingsUpdate = std::get_if<bool>(&var);
-        }
-        else if (key == "LogToMetricReportsCollection")
-        {
-            logToMetricReportsCollection = std::get_if<bool>(&var);
-        }
-        else if (key == "ReadingParameters")
-        {
-            readingParams = std::get_if<ReadingParameters>(&var);
-        }
-        else if (key == "ReportingType")
-        {
-            reportingType = std::get_if<std::string>(&var);
-        }
-        else if (key == "Interval")
-        {
-            interval = std::get_if<uint64_t>(&var);
-        }
-    }
-    if (emitsReadingsUpdate == nullptr ||
-        logToMetricReportsCollection == nullptr || readingParams == nullptr ||
-        reportingType == nullptr || interval == nullptr)
-    {
-        BMCWEB_LOG_ERROR << "Property type mismatch or property is missing";
         messages::internalError(asyncResp->res);
         return;
     }
 
     std::vector<std::string> redfishReportActions;
     redfishReportActions.reserve(2);
-    if (*emitsReadingsUpdate)
+    if (emitsReadingsUpdate != nullptr && *emitsReadingsUpdate)
     {
         redfishReportActions.emplace_back("RedfishEvent");
     }
-    if (*logToMetricReportsCollection)
+
+    if (logToMetricReportsCollection != nullptr &&
+        *logToMetricReportsCollection)
     {
         redfishReportActions.emplace_back("LogToMetricReportsCollection");
     }
 
     nlohmann::json metrics = nlohmann::json::array();
-    for (const auto& [sensorPath, operationType, metricId, metadata] :
-         *readingParams)
+    if (readingParameters != nullptr)
     {
-        metrics.push_back({
-            {"MetricId", metricId},
-            {"MetricProperties", {metadata}},
-        });
+        for (const auto& [sensorPath, operationType, metricId, metadata] :
+             *readingParameters)
+        {
+            metrics.push_back({
+                {"MetricId", metricId},
+                {"MetricProperties", {metadata}},
+            });
+        }
     }
+
+    if (reportingType != nullptr)
+    {
+        asyncResp->res.jsonValue["MetricReportDefinitionType"] = *reportingType;
+    }
+
+    if (interval != nullptr)
+    {
+        asyncResp->res.jsonValue["Schedule"]["RecurrenceInterval"] =
+            time_utils::toDurationString(std::chrono::milliseconds(*interval));
+    }
+
     asyncResp->res.jsonValue["Metrics"] = metrics;
-    asyncResp->res.jsonValue["MetricReportDefinitionType"] = *reportingType;
     asyncResp->res.jsonValue["ReportActions"] = redfishReportActions;
-    asyncResp->res.jsonValue["Schedule"]["RecurrenceInterval"] =
-        time_utils::toDurationString(std::chrono::milliseconds(*interval));
 }
 
 struct AddReportArgs
@@ -433,7 +431,9 @@
             return;
         }
 
-        crow::connections::systemBus->async_method_call(
+        sdbusplus::asio::getAllProperties(
+            *crow::connections::systemBus, telemetry::service,
+            telemetry::getDbusReportPath(id), telemetry::reportInterface,
             [asyncResp,
              id](const boost::system::error_code ec,
                  const std::vector<std::pair<
@@ -453,10 +453,7 @@
             }
 
             telemetry::fillReportDefinition(asyncResp, id, ret);
-            },
-            telemetry::service, telemetry::getDbusReportPath(id),
-            "org.freedesktop.DBus.Properties", "GetAll",
-            telemetry::reportInterface);
+            });
         });
     BMCWEB_ROUTE(app,
                  "/redfish/v1/TelemetryService/MetricReportDefinitions/<str>/")
diff --git a/redfish-core/lib/telemetry_service.hpp b/redfish-core/lib/telemetry_service.hpp
index 72a1e1d..afedbc6 100644
--- a/redfish-core/lib/telemetry_service.hpp
+++ b/redfish-core/lib/telemetry_service.hpp
@@ -6,6 +6,9 @@
 #include <dbus_utility.hpp>
 #include <query.hpp>
 #include <registries/privilege_registry.hpp>
+#include <sdbusplus/asio/property.hpp>
+#include <sdbusplus/unpack_properties.hpp>
+#include <utils/dbus_utils.hpp>
 
 namespace redfish
 {
@@ -31,7 +34,10 @@
     asyncResp->res.jsonValue["Triggers"]["@odata.id"] =
         "/redfish/v1/TelemetryService/Triggers";
 
-    crow::connections::systemBus->async_method_call(
+    sdbusplus::asio::getAllProperties(
+        *crow::connections::systemBus, telemetry::service,
+        "/xyz/openbmc_project/Telemetry/Reports",
+        "xyz.openbmc_project.Telemetry.ReportManager",
         [asyncResp](const boost::system::error_code ec,
                     const dbus::utility::DBusPropertiesMap& ret) {
         if (ec == boost::system::errc::host_unreachable)
@@ -50,32 +56,29 @@
 
         const size_t* maxReports = nullptr;
         const uint64_t* minInterval = nullptr;
-        for (const auto& [key, var] : ret)
+
+        const bool success = sdbusplus::unpackPropertiesNoThrow(
+            dbus_utils::UnpackErrorPrinter(), ret, "MaxReports", maxReports,
+            "MinInterval", minInterval);
+
+        if (!success)
         {
-            if (key == "MaxReports")
-            {
-                maxReports = std::get_if<size_t>(&var);
-            }
-            else if (key == "MinInterval")
-            {
-                minInterval = std::get_if<uint64_t>(&var);
-            }
-        }
-        if (maxReports == nullptr || minInterval == nullptr)
-        {
-            BMCWEB_LOG_ERROR << "Property type mismatch or property is missing";
             messages::internalError(asyncResp->res);
             return;
         }
 
-        asyncResp->res.jsonValue["MaxReports"] = *maxReports;
-        asyncResp->res.jsonValue["MinCollectionInterval"] =
-            time_utils::toDurationString(
-                std::chrono::milliseconds(static_cast<time_t>(*minInterval)));
-        },
-        telemetry::service, "/xyz/openbmc_project/Telemetry/Reports",
-        "org.freedesktop.DBus.Properties", "GetAll",
-        "xyz.openbmc_project.Telemetry.ReportManager");
+        if (maxReports != nullptr)
+        {
+            asyncResp->res.jsonValue["MaxReports"] = *maxReports;
+        }
+
+        if (minInterval != nullptr)
+        {
+            asyncResp->res.jsonValue["MinCollectionInterval"] =
+                time_utils::toDurationString(std::chrono::milliseconds(
+                    static_cast<time_t>(*minInterval)));
+        }
+        });
 }
 
 inline void requestRoutesTelemetryService(App& app)
diff --git a/redfish-core/lib/trigger.hpp b/redfish-core/lib/trigger.hpp
index 920a8c3..5e2f050 100644
--- a/redfish-core/lib/trigger.hpp
+++ b/redfish-core/lib/trigger.hpp
@@ -6,6 +6,9 @@
 #include <app.hpp>
 #include <query.hpp>
 #include <registries/privilege_registry.hpp>
+#include <sdbusplus/asio/property.hpp>
+#include <sdbusplus/unpack_properties.hpp>
+#include <utils/dbus_utils.hpp>
 
 #include <tuple>
 #include <variant>
@@ -188,107 +191,99 @@
     const bool* discrete = nullptr;
     const TriggerSensorsParams* sensors = nullptr;
     const std::vector<sdbusplus::message::object_path>* reports = nullptr;
-    const std::vector<std::string>* actions = nullptr;
+    const std::vector<std::string>* triggerActions = nullptr;
     const TriggerThresholdParamsExt* thresholds = nullptr;
 
-    for (const auto& [key, var] : properties)
-    {
-        if (key == "Name")
-        {
-            name = std::get_if<std::string>(&var);
-        }
-        else if (key == "Discrete")
-        {
-            discrete = std::get_if<bool>(&var);
-        }
-        else if (key == "Sensors")
-        {
-            sensors = std::get_if<TriggerSensorsParams>(&var);
-        }
-        else if (key == "Reports")
-        {
-            reports =
-                std::get_if<std::vector<sdbusplus::message::object_path>>(&var);
-        }
-        else if (key == "TriggerActions")
-        {
-            actions = std::get_if<std::vector<std::string>>(&var);
-        }
-        else if (key == "Thresholds")
-        {
-            thresholds = std::get_if<TriggerThresholdParamsExt>(&var);
-        }
-    }
+    const bool success = sdbusplus::unpackPropertiesNoThrow(
+        dbus_utils::UnpackErrorPrinter(), properties, "Name", name, "Discrete",
+        discrete, "Sensors", sensors, "Reports", reports, "TriggerActions",
+        triggerActions, "Thresholds", thresholds);
 
-    if (name == nullptr || discrete == nullptr || sensors == nullptr ||
-        reports == nullptr || actions == nullptr || thresholds == nullptr)
+    if (!success)
     {
-        BMCWEB_LOG_ERROR
-            << "Property type mismatch or property is missing in Trigger: "
-            << id;
         return false;
     }
 
-    std::optional<std::vector<std::string>> triggerActions =
-        getTriggerActions(*actions);
-    if (!triggerActions)
+    if (triggerActions != nullptr)
     {
-        BMCWEB_LOG_ERROR << "Property TriggerActions is invalid in Trigger: "
-                         << id;
-        return false;
-    }
-
-    std::optional<nlohmann::json> linkedReports =
-        getMetricReportDefinitions(*reports);
-    if (!linkedReports)
-    {
-        BMCWEB_LOG_ERROR << "Property Reports is invalid in Trigger: " << id;
-        return false;
-    }
-
-    if (*discrete)
-    {
-        std::optional<nlohmann::json::array_t> discreteTriggers =
-            getDiscreteTriggers(*thresholds);
-
-        if (!discreteTriggers)
+        std::optional<std::vector<std::string>> redfishTriggerActions =
+            getTriggerActions(*triggerActions);
+        if (!redfishTriggerActions)
         {
-            BMCWEB_LOG_ERROR << "Property Thresholds is invalid for discrete "
-                                "triggers in Trigger: "
+            BMCWEB_LOG_ERROR
+                << "Property TriggerActions is invalid in Trigger: " << id;
+            return false;
+        }
+        json["TriggerActions"] = *triggerActions;
+    }
+
+    if (reports != nullptr)
+    {
+        std::optional<nlohmann::json> linkedReports =
+            getMetricReportDefinitions(*reports);
+        if (!linkedReports)
+        {
+            BMCWEB_LOG_ERROR << "Property Reports is invalid in Trigger: "
                              << id;
             return false;
         }
-
-        json["DiscreteTriggers"] = *discreteTriggers;
-        json["DiscreteTriggerCondition"] =
-            discreteTriggers->empty() ? "Changed" : "Specified";
-        json["MetricType"] = "Discrete";
+        json["Links"]["MetricReportDefinitions"] = *linkedReports;
     }
-    else
+
+    if (discrete != nullptr)
     {
-        std::optional<nlohmann::json> numericThresholds =
-            getNumericThresholds(*thresholds);
-
-        if (!numericThresholds)
+        if (*discrete)
         {
-            BMCWEB_LOG_ERROR << "Property Thresholds is invalid for numeric "
-                                "thresholds in Trigger: "
-                             << id;
-            return false;
-        }
+            std::optional<nlohmann::json::array_t> discreteTriggers =
+                getDiscreteTriggers(*thresholds);
 
-        json["NumericThresholds"] = *numericThresholds;
-        json["MetricType"] = "Numeric";
+            if (!discreteTriggers)
+            {
+                BMCWEB_LOG_ERROR
+                    << "Property Thresholds is invalid for discrete "
+                       "triggers in Trigger: "
+                    << id;
+                return false;
+            }
+
+            json["DiscreteTriggers"] = *discreteTriggers;
+            json["DiscreteTriggerCondition"] =
+                discreteTriggers->empty() ? "Changed" : "Specified";
+            json["MetricType"] = "Discrete";
+        }
+        else
+        {
+            std::optional<nlohmann::json> numericThresholds =
+                getNumericThresholds(*thresholds);
+
+            if (!numericThresholds)
+            {
+                BMCWEB_LOG_ERROR
+                    << "Property Thresholds is invalid for numeric "
+                       "thresholds in Trigger: "
+                    << id;
+                return false;
+            }
+
+            json["NumericThresholds"] = *numericThresholds;
+            json["MetricType"] = "Numeric";
+        }
+    }
+
+    if (name != nullptr)
+    {
+        json["Name"] = *name;
+    }
+
+    if (sensors != nullptr)
+    {
+        json["MetricProperties"] = getMetricProperties(*sensors);
     }
 
     json["@odata.type"] = "#Triggers.v1_2_0.Triggers";
     json["@odata.id"] = crow::utility::urlFromPieces(
         "redfish", "v1", "TelemetryService", "Triggers", id);
     json["Id"] = id;
-    json["Name"] = *name;
-    json["TriggerActions"] = *triggerActions;
-    json["MetricProperties"] = getMetricProperties(*sensors);
-    json["Links"]["MetricReportDefinitions"] = *linkedReports;
 
     return true;
 }
@@ -329,7 +324,9 @@
         {
             return;
         }
-        crow::connections::systemBus->async_method_call(
+        sdbusplus::asio::getAllProperties(
+            *crow::connections::systemBus, telemetry::service,
+            telemetry::getDbusTriggerPath(id), telemetry::triggerInterface,
             [asyncResp,
              id](const boost::system::error_code ec,
                  const std::vector<std::pair<
@@ -351,10 +348,7 @@
             {
                 messages::internalError(asyncResp->res);
             }
-            },
-            telemetry::service, telemetry::getDbusTriggerPath(id),
-            "org.freedesktop.DBus.Properties", "GetAll",
-            telemetry::triggerInterface);
+            });
         });
 
     BMCWEB_ROUTE(app, "/redfish/v1/TelemetryService/Triggers/<str>/")