psu-ng: Process all Supported Configuration sets

The chassis may have more than one Supported Configuration interface,
such as supporting 2 power supplies of a certain type or 4 power
supplies of another. Therefore need to loop through the subtree results
to process each. Create a new helper function to initialize the system
properties to avoid duplicate code with the interfaces added callback.
To account for the multiple configurations, a subsequent commit would
convert the existing sys_properties member into a vector of
sys_properties to store each configuration.

Also remove removing the interfaces added match, because with multiple
configuration interfaces, it is not known how many interfaces the system
supports, and the interfaces added signal gets trigger for each one.

Tested: Verified the maxPowerSupplies value was as expected on
        Rainier 2U and adding a second Supported Configuration interface
        it was processed (overwrote the first value).

Change-Id: Ie9eed6d7acdaa9ed92e2da2be978b4bed37eab2b
Signed-off-by: Adriana Kobylak <anoo@us.ibm.com>
diff --git a/phosphor-power-supply/psu_manager.cpp b/phosphor-power-supply/psu_manager.cpp
index ffab79a..fa1294a 100644
--- a/phosphor-power-supply/psu_manager.cpp
+++ b/phosphor-power-supply/psu_manager.cpp
@@ -88,33 +88,47 @@
     }
 }
 
+void PSUManager::populateSysProperties(const util::DbusPropertyMap& properties)
+{
+    try
+    {
+        auto propIt = properties.find(maxCountProp);
+        if (propIt != properties.end())
+        {
+            const uint64_t* count = std::get_if<uint64_t>(&(propIt->second));
+            if (count != nullptr)
+            {
+                sysProperties.maxPowerSupplies = *count;
+            }
+        }
+    }
+    catch (std::exception& e)
+    {
+    }
+}
+
 void PSUManager::getSystemProperties()
 {
 
-    uint64_t maxCount;
     try
     {
         util::DbusSubtree subtree =
             util::getSubTree(bus, INVENTORY_OBJ_PATH, supportedConfIntf, 0);
-        auto objectIt = subtree.cbegin();
-        if (objectIt == subtree.cend())
+        if (subtree.empty())
         {
             throw std::runtime_error("Supported Configuration Not Found");
         }
-        std::string objPath = objectIt->first;
-        auto serviceIt = objectIt->second.cbegin();
-        if (serviceIt != objectIt->second.cend())
-        {
-            std::string service = serviceIt->first;
-            if (!service.empty())
-            {
-                util::getProperty<uint64_t>(supportedConfIntf, maxCountProp,
-                                            objPath, service, bus, maxCount);
-                sysProperties.maxPowerSupplies = maxCount;
 
-                // Don't need the match anymore
-                entityManagerIfacesAddedMatch.reset();
+        for (const auto& [objPath, services] : subtree)
+        {
+            std::string service = services.begin()->first;
+            if (objPath.empty() || service.empty())
+            {
+                continue;
             }
+            auto properties = util::getAllProperties(
+                bus, objPath, supportedConfIntf, service);
+            populateSysProperties(properties);
         }
     }
     catch (std::exception& e)
@@ -129,7 +143,7 @@
     try
     {
         sdbusplus::message::object_path objPath;
-        std::map<std::string, std::map<std::string, std::variant<uint64_t>>>
+        std::map<std::string, std::map<std::string, util::DbusVariant>>
             interfaces;
         msg.read(objPath, interfaces);
 
@@ -139,14 +153,7 @@
             return;
         }
 
-        auto itProp = itIntf->second.find(maxCountProp);
-        if (itProp != itIntf->second.cend())
-        {
-            sysProperties.maxPowerSupplies = std::get<0>(itProp->second);
-
-            // Don't need the match anymore
-            entityManagerIfacesAddedMatch.reset();
-        }
+        populateSysProperties(itIntf->second);
     }
     catch (std::exception& e)
     {
diff --git a/phosphor-power-supply/psu_manager.hpp b/phosphor-power-supply/psu_manager.hpp
index f651a28..0f93279 100644
--- a/phosphor-power-supply/psu_manager.hpp
+++ b/phosphor-power-supply/psu_manager.hpp
@@ -208,6 +208,13 @@
     }
 
     /**
+     * @brief Helper function to populate the system properties
+     *
+     * @param[in] properties - A map of property names and values
+     */
+    void populateSysProperties(const util::DbusPropertyMap& properties);
+
+    /**
      * @brief The system properties.
      */
     sys_properties sysProperties;