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>
diff --git a/redfish-core/lib/processor.hpp b/redfish-core/lib/processor.hpp
index df0d0bb..b33f912 100644
--- a/redfish-core/lib/processor.hpp
+++ b/redfish-core/lib/processor.hpp
@@ -15,12 +15,15 @@
 */
 #pragma once
 
+#include "dbus_singleton.hpp"
+#include "error_messages.hpp"
 #include "health.hpp"
 
 #include <app.hpp>
 #include <boost/container/flat_map.hpp>
 #include <dbus_utility.hpp>
 #include <registries/privilege_registry.hpp>
+#include <sdbusplus/asio/property.hpp>
 #include <sdbusplus/message/native_types.hpp>
 #include <sdbusplus/utility/dedup_variant.hpp>
 #include <utils/collection.hpp>
@@ -59,28 +62,19 @@
                              const std::string& objPath)
 {
     BMCWEB_LOG_DEBUG << "Get Processor UUID";
-    crow::connections::systemBus->async_method_call(
-        [objPath, aResp{std::move(aResp)}](
-            const boost::system::error_code ec,
-            const dbus::utility::DbusVariantType& property) {
+    sdbusplus::asio::getProperty<std::string>(
+        *crow::connections::systemBus, service, objPath,
+        "xyz.openbmc_project.Common.UUID", "UUID",
+        [objPath, aResp{std::move(aResp)}](const boost::system::error_code ec,
+                                           const std::string& property) {
             if (ec)
             {
                 BMCWEB_LOG_DEBUG << "DBUS response error";
                 messages::internalError(aResp->res);
                 return;
             }
-            const std::string* value = std::get_if<std::string>(&property);
-            if (value == nullptr)
-            {
-                BMCWEB_LOG_DEBUG << "Null value returned "
-                                    "for UUID";
-                messages::internalError(aResp->res);
-                return;
-            }
-            aResp->res.jsonValue["UUID"] = *value;
-        },
-        service, objPath, "org.freedesktop.DBus.Properties", "Get",
-        "xyz.openbmc_project.Common.UUID", "UUID");
+            aResp->res.jsonValue["UUID"] = property;
+        });
 }
 
 inline void
@@ -595,10 +589,15 @@
                     // Once we found the current applied config, queue another
                     // request to read the base freq core ids out of that
                     // config.
-                    crow::connections::systemBus->async_method_call(
-                        [aResp](
-                            const boost::system::error_code ec,
-                            const dbus::utility::DbusVariantType& property) {
+                    sdbusplus::asio::getProperty<
+                        BaseSpeedPrioritySettingsProperty>(
+                        *crow::connections::systemBus, service, dbusPath,
+                        "xyz.openbmc_project.Inventory.Item.Cpu."
+                        "OperatingConfig",
+                        "BaseSpeedPrioritySettings",
+                        [aResp](const boost::system::error_code ec,
+                                const BaseSpeedPrioritySettingsProperty&
+                                    baseSpeedList) {
                             if (ec)
                             {
                                 BMCWEB_LOG_WARNING
@@ -606,18 +605,9 @@
                                 messages::internalError(aResp->res);
                                 return;
                             }
-                            auto baseSpeedList =
-                                std::get_if<BaseSpeedPrioritySettingsProperty>(
-                                    &property);
-                            if (baseSpeedList != nullptr)
-                            {
-                                highSpeedCoreIdsHandler(aResp, *baseSpeedList);
-                            }
-                        },
-                        service, dbusPath, "org.freedesktop.DBus.Properties",
-                        "Get",
-                        "xyz.openbmc_project.Inventory.Item.Cpu.OperatingConfig",
-                        "BaseSpeedPrioritySettings");
+
+                            highSpeedCoreIdsHandler(aResp, baseSpeedList);
+                        });
                 }
                 else if (dbusPropName == "BaseSpeedPriorityEnabled")
                 {
@@ -647,10 +637,11 @@
                                const std::string& objPath)
 {
     BMCWEB_LOG_DEBUG << "Get Cpu Location Data";
-    crow::connections::systemBus->async_method_call(
-        [objPath, aResp{std::move(aResp)}](
-            const boost::system::error_code ec,
-            const dbus::utility::DbusVariantType& property) {
+    sdbusplus::asio::getProperty<std::string>(
+        *crow::connections::systemBus, service, objPath,
+        "xyz.openbmc_project.Inventory.Decorator.LocationCode", "LocationCode",
+        [objPath, aResp{std::move(aResp)}](const boost::system::error_code ec,
+                                           const std::string& property) {
             if (ec)
             {
                 BMCWEB_LOG_DEBUG << "DBUS response error";
@@ -658,21 +649,9 @@
                 return;
             }
 
-            const std::string* value = std::get_if<std::string>(&property);
-
-            if (value == nullptr)
-            {
-                // illegal value
-                BMCWEB_LOG_DEBUG << "Location code value error";
-                messages::internalError(aResp->res);
-                return;
-            }
-
             aResp->res.jsonValue["Location"]["PartLocation"]["ServiceLabel"] =
-                *value;
-        },
-        service, objPath, "org.freedesktop.DBus.Properties", "Get",
-        "xyz.openbmc_project.Inventory.Decorator.LocationCode", "LocationCode");
+                property;
+        });
 }
 
 /**
@@ -688,23 +667,20 @@
                            const std::string& objectPath)
 {
     BMCWEB_LOG_DEBUG << "Get CPU UniqueIdentifier";
-    crow::connections::systemBus->async_method_call(
-        [aResp](boost::system::error_code ec,
-                const dbus::utility::DbusVariantType& property) {
-            const std::string* id = std::get_if<std::string>(&property);
-            if (ec || id == nullptr)
+    sdbusplus::asio::getProperty<std::string>(
+        *crow::connections::systemBus, service, objectPath,
+        "xyz.openbmc_project.Inventory.Decorator.UniqueIdentifier",
+        "UniqueIdentifier",
+        [aResp](boost::system::error_code ec, const std::string& id) {
+            if (ec)
             {
                 BMCWEB_LOG_ERROR << "Failed to read cpu unique id: " << ec;
                 messages::internalError(aResp->res);
                 return;
             }
             aResp->res
-                .jsonValue["ProcessorId"]["ProtectedIdentificationNumber"] =
-                *id;
-        },
-        service, objectPath, "org.freedesktop.DBus.Properties", "Get",
-        "xyz.openbmc_project.Inventory.Decorator.UniqueIdentifier",
-        "UniqueIdentifier");
+                .jsonValue["ProcessorId"]["ProtectedIdentificationNumber"] = id;
+        });
 }
 
 /**