Refactor getAssociationEndPoints method

Since the getAssociationEndPoints method has been implemented in
dbus_utility and this commit is to integrate all the places where the
endpoints attribute is obtained, and use the method in dbus_utility
uniformly.

Tested:
1. Redfish Validator Passed
2. For all the endpoints we changed, we got the same result as before

Signed-off-by: George Liu <liuxiwei@inspur.com>
Change-Id: I91a5e80de5bc3b5712c2d5b81f2f8b982d1c884e
diff --git a/redfish-core/include/utils/sw_utils.hpp b/redfish-core/include/utils/sw_utils.hpp
index 1f5eed3..90048dd 100644
--- a/redfish-core/include/utils/sw_utils.hpp
+++ b/redfish-core/include/utils/sw_utils.hpp
@@ -353,12 +353,10 @@
     getSwUpdatableStatus(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
                          const std::shared_ptr<std::string>& swId)
 {
-    sdbusplus::asio::getProperty<std::vector<std::string>>(
-        *crow::connections::systemBus, "xyz.openbmc_project.ObjectMapper",
+    dbus::utility::getAssociationEndPoints(
         "/xyz/openbmc_project/software/updateable",
-        "xyz.openbmc_project.Association", "endpoints",
         [asyncResp, swId](const boost::system::error_code& ec,
-                          const std::vector<std::string>& objPaths) {
+                          const dbus::utility::MapperEndPoints& objPaths) {
         if (ec)
         {
             BMCWEB_LOG_DEBUG << " error_code = " << ec
diff --git a/redfish-core/lib/chassis.hpp b/redfish-core/lib/chassis.hpp
index 4701af4..dd77195 100644
--- a/redfish-core/lib/chassis.hpp
+++ b/redfish-core/lib/chassis.hpp
@@ -250,12 +250,10 @@
 
             auto health = std::make_shared<HealthPopulate>(asyncResp);
 
-            sdbusplus::asio::getProperty<std::vector<std::string>>(
-                *crow::connections::systemBus,
-                "xyz.openbmc_project.ObjectMapper", path + "/all_sensors",
-                "xyz.openbmc_project.Association", "endpoints",
+            dbus::utility::getAssociationEndPoints(
+                path + "/all_sensors",
                 [health](const boost::system::error_code& ec2,
-                         const std::vector<std::string>& resp) {
+                         const dbus::utility::MapperEndPoints& resp) {
                 if (ec2)
                 {
                     return; // no sensors = no failures
@@ -290,12 +288,11 @@
                 crow::utility::urlFromPieces("redfish", "v1", "Systems",
                                              "system", "PCIeDevices");
 
-            sdbusplus::asio::getProperty<std::vector<std::string>>(
-                *crow::connections::systemBus,
-                "xyz.openbmc_project.ObjectMapper", path + "/drive",
-                "xyz.openbmc_project.Association", "endpoints",
-                [asyncResp, chassisId](const boost::system::error_code& ec3,
-                                       const std::vector<std::string>& resp) {
+            dbus::utility::getAssociationEndPoints(
+                path + "/drive",
+                [asyncResp,
+                 chassisId](const boost::system::error_code& ec3,
+                            const dbus::utility::MapperEndPoints& resp) {
                 if (ec3 || resp.empty())
                 {
                     return; // no drives = no failures
diff --git a/redfish-core/lib/pcie_slots.hpp b/redfish-core/lib/pcie_slots.hpp
index 42c8bb1..2b9ef2b 100644
--- a/redfish-core/lib/pcie_slots.hpp
+++ b/redfish-core/lib/pcie_slots.hpp
@@ -151,7 +151,7 @@
     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
     const std::string& chassisID, const std::string& pcieSlotPath,
     const std::string& connectionName, const boost::system::error_code& ec,
-    const std::variant<std::vector<std::string>>& endpoints)
+    const dbus::utility::MapperEndPoints& pcieSlotChassis)
 {
     if (ec)
     {
@@ -165,24 +165,14 @@
         return;
     }
 
-    const std::vector<std::string>* pcieSlotChassis =
-        std::get_if<std::vector<std::string>>(&(endpoints));
-
-    if (pcieSlotChassis == nullptr)
-    {
-        BMCWEB_LOG_ERROR << "Error getting PCIe Slot association!";
-        messages::internalError(asyncResp->res);
-        return;
-    }
-
-    if (pcieSlotChassis->size() != 1)
+    if (pcieSlotChassis.size() != 1)
     {
         BMCWEB_LOG_ERROR << "PCIe Slot association error! ";
         messages::internalError(asyncResp->res);
         return;
     }
 
-    sdbusplus::message::object_path path((*pcieSlotChassis)[0]);
+    sdbusplus::message::object_path path(pcieSlotChassis[0]);
     std::string chassisName = path.filename();
     if (chassisName != chassisID)
     {
@@ -239,17 +229,14 @@
 
             // The association of this PCIeSlot is used to determine whether
             // it belongs to this ChassisID
-            crow::connections::systemBus->async_method_call(
+            dbus::utility::getAssociationEndPoints(
+                std::string{pcieSlotAssociationPath},
                 [asyncResp, chassisID, pcieSlotPath, connectionName](
                     const boost::system::error_code& ec2,
-                    const std::variant<std::vector<std::string>>& endpoints) {
+                    const dbus::utility::MapperEndPoints& endpoints) {
                 onMapperAssociationDone(asyncResp, chassisID, pcieSlotPath,
                                         connectionName, ec2, endpoints);
-                },
-                "xyz.openbmc_project.ObjectMapper",
-                std::string{pcieSlotAssociationPath},
-                "org.freedesktop.DBus.Properties", "Get",
-                "xyz.openbmc_project.Association", "endpoints");
+                });
         }
     }
 }
diff --git a/redfish-core/lib/sensors.hpp b/redfish-core/lib/sensors.hpp
index 8189bdb..ef3354d 100644
--- a/redfish-core/lib/sensors.hpp
+++ b/redfish-core/lib/sensors.hpp
@@ -564,13 +564,12 @@
 
         // Get the list of all sensors for this Chassis element
         std::string sensorPath = *chassisPath + "/all_sensors";
-        sdbusplus::asio::getProperty<std::vector<std::string>>(
-            *crow::connections::systemBus, "xyz.openbmc_project.ObjectMapper",
-            sensorPath, "xyz.openbmc_project.Association", "endpoints",
+        dbus::utility::getAssociationEndPoints(
+            sensorPath,
             [asyncResp, chassisSubNode, sensorTypes,
              callback{std::forward<const Callback>(callback)}](
                 const boost::system::error_code& e,
-                const std::vector<std::string>& nodeSensorList) {
+                const dbus::utility::MapperEndPoints& nodeSensorList) {
             if (e)
             {
                 if (e.value() != EBADR)
@@ -983,27 +982,22 @@
         {
             return; // don't have to have this interface
         }
-        for (const std::pair<
-                 std::string,
-                 std::vector<std::pair<std::string, std::vector<std::string>>>>&
+        for (const std::pair<std::string, dbus::utility::MapperServiceMap>&
                  pathPair : resp)
         {
             const std::string& path = pathPair.first;
-            const std::vector<std::pair<std::string, std::vector<std::string>>>&
-                objDict = pathPair.second;
+            const dbus::utility::MapperServiceMap& objDict = pathPair.second;
             if (objDict.empty())
             {
                 continue; // this should be impossible
             }
 
             const std::string& owner = objDict.begin()->first;
-            sdbusplus::asio::getProperty<std::vector<std::string>>(
-                *crow::connections::systemBus,
-                "xyz.openbmc_project.ObjectMapper", path + "/chassis",
-                "xyz.openbmc_project.Association", "endpoints",
-                [path, owner,
-                 sensorsAsyncResp](const boost::system::error_code& e,
-                                   const std::vector<std::string>& endpoints) {
+            dbus::utility::getAssociationEndPoints(
+                path + "/chassis",
+                [path, owner, sensorsAsyncResp](
+                    const boost::system::error_code& e,
+                    const dbus::utility::MapperEndPoints& endpoints) {
                 if (e)
                 {
                     return; // if they don't have an association we
diff --git a/redfish-core/lib/storage.hpp b/redfish-core/lib/storage.hpp
index 5f3ccd3..0388ccd 100644
--- a/redfish-core/lib/storage.hpp
+++ b/redfish-core/lib/storage.hpp
@@ -702,12 +702,11 @@
             asyncResp->res.jsonValue["Name"] = "Drive Collection";
 
             // Association lambda
-            sdbusplus::asio::getProperty<std::vector<std::string>>(
-                *crow::connections::systemBus,
-                "xyz.openbmc_project.ObjectMapper", path + "/drive",
-                "xyz.openbmc_project.Association", "endpoints",
-                [asyncResp, chassisId](const boost::system::error_code& ec3,
-                                       const std::vector<std::string>& resp) {
+            dbus::utility::getAssociationEndPoints(
+                path + "/drive",
+                [asyncResp,
+                 chassisId](const boost::system::error_code& ec3,
+                            const dbus::utility::MapperEndPoints& resp) {
                 if (ec3)
                 {
                     BMCWEB_LOG_ERROR << "Error in chassis Drive association ";
@@ -867,13 +866,11 @@
                 continue;
             }
 
-            sdbusplus::asio::getProperty<std::vector<std::string>>(
-                *crow::connections::systemBus,
-                "xyz.openbmc_project.ObjectMapper", path + "/drive",
-                "xyz.openbmc_project.Association", "endpoints",
+            dbus::utility::getAssociationEndPoints(
+                path + "/drive",
                 [asyncResp, chassisId,
                  driveName](const boost::system::error_code& ec3,
-                            const std::vector<std::string>& resp) {
+                            const dbus::utility::MapperEndPoints& resp) {
                 if (ec3)
                 {
                     return; // no drives = no failures