used sdbusplus::unpackPropertiesNoThrow part 5

used sdbusplus::unpackPropertiesNoThrow in chassis.hpp and sensors.hpp,
also replaced all usages of "GetAll" with
sdbusplus::asio::getAllProperties

    bmcweb size: 2701720 -> 2697624 (-4096)
compressed size: 1131481 -> 1129725 (-1756)

Tested:
  Performed get on:
  - /redfish/v1/Chassis/chassis
  - /redfish/v1/Chassis/chassis/Thermal

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

Change-Id: I76377710cd037f7c54cb0639c011b64c73a719ab
Signed-off-by: Krzysztof Grobelny <krzysztof.grobelny@intel.com>
diff --git a/redfish-core/lib/chassis.hpp b/redfish-core/lib/chassis.hpp
index d6f9321..11ef6c4 100644
--- a/redfish-core/lib/chassis.hpp
+++ b/redfish-core/lib/chassis.hpp
@@ -24,7 +24,9 @@
 #include <query.hpp>
 #include <registries/privilege_registry.hpp>
 #include <sdbusplus/asio/property.hpp>
+#include <sdbusplus/unpack_properties.hpp>
 #include <utils/collection.hpp>
+#include <utils/dbus_utils.hpp>
 
 namespace redfish
 {
@@ -336,45 +338,58 @@
                 }
             }
 
-            crow::connections::systemBus->async_method_call(
+            sdbusplus::asio::getAllProperties(
+                *crow::connections::systemBus, connectionName, path,
+                "xyz.openbmc_project.Inventory.Decorator.Asset",
                 [asyncResp, chassisId(std::string(chassisId))](
                     const boost::system::error_code /*ec2*/,
                     const dbus::utility::DBusPropertiesMap& propertiesList) {
-                for (const std::pair<std::string,
-                                     dbus::utility::DbusVariantType>& property :
-                     propertiesList)
+                const std::string* partNumber = nullptr;
+                const std::string* serialNumber = nullptr;
+                const std::string* manufacturer = nullptr;
+                const std::string* model = nullptr;
+                const std::string* sparePartNumber = nullptr;
+
+                const bool success = sdbusplus::unpackPropertiesNoThrow(
+                    dbus_utils::UnpackErrorPrinter(), propertiesList,
+                    "PartNumber", partNumber, "SerialNumber", serialNumber,
+                    "Manufacturer", manufacturer, "Model", model,
+                    "SparePartNumber", sparePartNumber);
+
+                if (!success)
                 {
-                    // Store DBus properties that are also
-                    // Redfish properties with same name and a
-                    // string value
-                    const std::string& propertyName = property.first;
-                    if ((propertyName == "PartNumber") ||
-                        (propertyName == "SerialNumber") ||
-                        (propertyName == "Manufacturer") ||
-                        (propertyName == "Model") ||
-                        (propertyName == "SparePartNumber"))
-                    {
-                        const std::string* value =
-                            std::get_if<std::string>(&property.second);
-                        if (value == nullptr)
-                        {
-                            BMCWEB_LOG_ERROR << "Null value returned for "
-                                             << propertyName;
-                            messages::internalError(asyncResp->res);
-                            return;
-                        }
-                        // SparePartNumber is optional on D-Bus
-                        // so skip if it is empty
-                        if (propertyName == "SparePartNumber")
-                        {
-                            if (value->empty())
-                            {
-                                continue;
-                            }
-                        }
-                        asyncResp->res.jsonValue[propertyName] = *value;
-                    }
+                    messages::internalError(asyncResp->res);
+                    return;
                 }
+
+                if (partNumber != nullptr)
+                {
+                    asyncResp->res.jsonValue["PartNumber"] = *partNumber;
+                }
+
+                if (serialNumber != nullptr)
+                {
+                    asyncResp->res.jsonValue["SerialNumber"] = *serialNumber;
+                }
+
+                if (manufacturer != nullptr)
+                {
+                    asyncResp->res.jsonValue["Manufacturer"] = *manufacturer;
+                }
+
+                if (model != nullptr)
+                {
+                    asyncResp->res.jsonValue["Model"] = *model;
+                }
+
+                // SparePartNumber is optional on D-Bus
+                // so skip if it is empty
+                if (sparePartNumber != nullptr && !sparePartNumber->empty())
+                {
+                    asyncResp->res.jsonValue["SparePartNumber"] =
+                        *sparePartNumber;
+                }
+
                 asyncResp->res.jsonValue["Name"] = chassisId;
                 asyncResp->res.jsonValue["Id"] = chassisId;
 #ifdef BMCWEB_ALLOW_DEPRECATED_POWER_THERMAL
@@ -408,9 +423,7 @@
                 asyncResp->res.jsonValue["Links"]["ManagedBy"] =
                     std::move(managedBy);
                 getChassisState(asyncResp);
-                },
-                connectionName, path, "org.freedesktop.DBus.Properties",
-                "GetAll", "xyz.openbmc_project.Inventory.Decorator.Asset");
+                });
 
             for (const auto& interface : interfaces2)
             {
diff --git a/redfish-core/lib/sensors.hpp b/redfish-core/lib/sensors.hpp
index aa48e0d..2b1a3c8 100644
--- a/redfish-core/lib/sensors.hpp
+++ b/redfish-core/lib/sensors.hpp
@@ -24,6 +24,8 @@
 #include <query.hpp>
 #include <registries/privilege_registry.hpp>
 #include <sdbusplus/asio/property.hpp>
+#include <sdbusplus/unpack_properties.hpp>
+#include <utils/dbus_utils.hpp>
 #include <utils/json_utils.hpp>
 #include <utils/query_param.hpp>
 
@@ -1122,22 +1124,36 @@
                 {
                     return;
                 }
-                crow::connections::systemBus->async_method_call(
+                sdbusplus::asio::getAllProperties(
+                    *crow::connections::systemBus, owner, path,
+                    "xyz.openbmc_project.Control.FanRedundancy",
                     [path, sensorsAsyncResp](
                         const boost::system::error_code& err,
-                        const std::map<std::string,
-                                       dbus::utility::DbusVariantType>& ret) {
+                        const dbus::utility::DBusPropertiesMap& ret) {
                     if (err)
                     {
                         return; // don't have to have this
                                 // interface
                     }
-                    auto findFailures = ret.find("AllowedFailures");
-                    auto findCollection = ret.find("Collection");
-                    auto findStatus = ret.find("Status");
 
-                    if (findFailures == ret.end() ||
-                        findCollection == ret.end() || findStatus == ret.end())
+                    const uint8_t* allowedFailures = nullptr;
+                    const std::vector<std::string>* collection = nullptr;
+                    const std::string* status = nullptr;
+
+                    const bool success = sdbusplus::unpackPropertiesNoThrow(
+                        dbus_utils::UnpackErrorPrinter(), ret,
+                        "AllowedFailures", allowedFailures, "Collection",
+                        collection, "Status", status);
+
+                    if (!success)
+                    {
+                        messages::internalError(
+                            sensorsAsyncResp->asyncResp->res);
+                        return;
+                    }
+
+                    if (allowedFailures == nullptr || collection == nullptr ||
+                        status == nullptr)
                     {
                         BMCWEB_LOG_ERROR << "Invalid redundancy interface";
                         messages::internalError(
@@ -1145,24 +1161,6 @@
                         return;
                     }
 
-                    const uint8_t* allowedFailures =
-                        std::get_if<uint8_t>(&(findFailures->second));
-                    const std::vector<std::string>* collection =
-                        std::get_if<std::vector<std::string>>(
-                            &(findCollection->second));
-                    const std::string* status =
-                        std::get_if<std::string>(&(findStatus->second));
-
-                    if (allowedFailures == nullptr || collection == nullptr ||
-                        status == nullptr)
-                    {
-
-                        BMCWEB_LOG_ERROR
-                            << "Invalid redundancy interface types";
-                        messages::internalError(
-                            sensorsAsyncResp->asyncResp->res);
-                        return;
-                    }
                     sdbusplus::message::object_path objectPath(path);
                     std::string name = objectPath.filename();
                     if (name.empty())
@@ -1247,9 +1245,7 @@
                     redundancy["Status"]["State"] = "Enabled";
 
                     jResp.push_back(std::move(redundancy));
-                    },
-                    owner, path, "org.freedesktop.DBus.Properties", "GetAll",
-                    "xyz.openbmc_project.Control.FanRedundancy");
+                    });
                 });
         }
         },