entity-manager: extract postConfigurationRecord

Extract function postConfigurationRecord from function
postExposesRecordsToDBus.

The newly created function handles the creation of nested dbus
interfaces from object and array properties in exposes records.

What's been changed:
- Extract function with return type bool
- Bool gets mapped as false, true -> break, continue to keep the
  original control flow.
- All parameters are passed as references

Tested: on Tyan S8030

```
root@s8030-bmc-30303035c0c1:~# busctl tree xyz.openbmc_project.EntityManager
`- /xyz
  `- /xyz/openbmc_project
    |- /xyz/openbmc_project/EntityManager
    `- /xyz/openbmc_project/inventory
      `- /xyz/openbmc_project/inventory/system
        |- /xyz/openbmc_project/inventory/system/board
        | `- /xyz/openbmc_project/inventory/system/board/Tyan_S8030_Baseboard
        |   |- /xyz/openbmc_project/inventory/system/board/Tyan_S8030_Baseboard/CPU0_Power_Consumption
        |   |- /xyz/openbmc_project/inventory/system/board/Tyan_S8030_Baseboard/CPU0_Temp
        |   |- /xyz/openbmc_project/inventory/system/board/Tyan_S8030_Baseboard/GARBO_SENSOR
        |   |- /xyz/openbmc_project/inventory/system/board/Tyan_S8030_Baseboard/HostSPIFlash
        |   |- /xyz/openbmc_project/inventory/system/board/Tyan_S8030_Baseboard/P0_VDD_18_RUN
        |   |- /xyz/openbmc_project/inventory/system/board/Tyan_S8030_Baseboard/P0_VDD_CORE_RUN
        |   |- /xyz/openbmc_project/inventory/system/board/Tyan_S8030_Baseboard/P0_VDD_MEM_ABCD
        |   |- /xyz/openbmc_project/inventory/system/board/Tyan_S8030_Baseboard/P0_VDD_MEM_EFGH
        |   |- /xyz/openbmc_project/inventory/system/board/Tyan_S8030_Baseboard/P0_VDD_SOC_RUN
        |   |- /xyz/openbmc_project/inventory/system/board/Tyan_S8030_Baseboard/VBAT_33
        |   |- /xyz/openbmc_project/inventory/system/board/Tyan_S8030_Baseboard/VDD_12_RUN
        |   |- /xyz/openbmc_project/inventory/system/board/Tyan_S8030_Baseboard/VDD_33_DUAL
        |   |- /xyz/openbmc_project/inventory/system/board/Tyan_S8030_Baseboard/VDD_33_RUN
        |   |- /xyz/openbmc_project/inventory/system/board/Tyan_S8030_Baseboard/VDD_5_DUAL
        |   |- /xyz/openbmc_project/inventory/system/board/Tyan_S8030_Baseboard/VDD_5_RUN
        |   `- /xyz/openbmc_project/inventory/system/board/Tyan_S8030_Baseboard/X550
        |- /xyz/openbmc_project/inventory/system/chassis
        | `- /xyz/openbmc_project/inventory/system/chassis/MBX_1_57_Chassis
        |   |- /xyz/openbmc_project/inventory/system/chassis/MBX_1_57_Chassis/Fan_Control
        |   |- /xyz/openbmc_project/inventory/system/chassis/MBX_1_57_Chassis/NIC_1_Ignore
        |   |- /xyz/openbmc_project/inventory/system/chassis/MBX_1_57_Chassis/NIC_2_Ignore
        |   |- /xyz/openbmc_project/inventory/system/chassis/MBX_1_57_Chassis/NIC_FRU_1
        |   |- /xyz/openbmc_project/inventory/system/chassis/MBX_1_57_Chassis/NIC_FRU_2
        |   |- /xyz/openbmc_project/inventory/system/chassis/MBX_1_57_Chassis/SYS_FAN_1
        |   |- /xyz/openbmc_project/inventory/system/chassis/MBX_1_57_Chassis/SYS_FAN_2
        |   |- /xyz/openbmc_project/inventory/system/chassis/MBX_1_57_Chassis/SYS_FAN_3
        |   |- /xyz/openbmc_project/inventory/system/chassis/MBX_1_57_Chassis/Temperature_Control
        |   `- /xyz/openbmc_project/inventory/system/chassis/MBX_1_57_Chassis/Zone0
        `- /xyz/openbmc_project/inventory/system/powersupply
          |- /xyz/openbmc_project/inventory/system/powersupply/Supermicro_PWS_920P_SQ_0
          | |- /xyz/openbmc_project/inventory/system/powersupply/Supermicro_PWS_920P_SQ_0/PSU0
          | |- /xyz/openbmc_project/inventory/system/powersupply/Supermicro_PWS_920P_SQ_0/PSU0_ADDR
          | `- /xyz/openbmc_project/inventory/system/powersupply/Supermicro_PWS_920P_SQ_0/PSU0_FRU
          `- /xyz/openbmc_project/inventory/system/powersupply/Supermicro_PWS_920P_SQ_1
            |- /xyz/openbmc_project/inventory/system/powersupply/Supermicro_PWS_920P_SQ_1/PSU1
            |- /xyz/openbmc_project/inventory/system/powersupply/Supermicro_PWS_920P_SQ_1/PSU1_ADDR
            `- /xyz/openbmc_project/inventory/system/powersupply/Supermicro_PWS_920P_SQ_1/PSU1_FRU
```

Checking individual record

```
root@s8030-bmc-30303035c0c1:~# busctl introspect xyz.openbmc_project.EntityManager /xyz/openbmc_project/inventory/system/board/Tyan_S8030_Baseboard/VBAT_33
NAME                                              TYPE      SIGNATURE RESULT/VALUE     FLAGS
...
xyz.openbmc_project.Configuration.ADC             interface -         -                -
.Index                                            property  t         10               emits-change
.Name                                             property  s         "VBAT_33"        emits-change
.PowerState                                       property  s         "Always"         emits-change
.ScaleFactor                                      property  d         0.3333           emits-change
.Type                                             property  s         "ADC"            emits-change
xyz.openbmc_project.Configuration.ADC.Thresholds0 interface -         -                -
.Delete                                           method    -         -                -
.Direction                                        property  s         "greater than"   emits-change
.Name                                             property  s         "upper critical" emits-change
.Severity                                         property  d         1                emits-change
.Value                                            property  d         3.507            emits-change
xyz.openbmc_project.Configuration.ADC.Thresholds1 interface -         -                -
.Delete                                           method    -         -                -
.Direction                                        property  s         "less than"      emits-change
.Name                                             property  s         "lower critical" emits-change
.Severity                                         property  d         1                emits-change
.Value                                            property  d         2.688            emits-change
```

Another record with nested object

```
root@s8030-bmc-30303035c0c1:~# busctl introspect xyz.openbmc_project.EntityManager /xyz/openbmc_project/inventory/system/board/Tyan_S8030_Baseboard/HostSPIFlash
NAME                                                    TYPE      SIGNATURE RESULT/VALUE                       FLAGS
...
xyz.openbmc_project.Configuration.SPIFlash              interface -         -                                  -
.Name                                                   property  s         "HostSPIFlash"                     emits-change
.SPIControllerIndex                                     property  t         1                                  emits-change
.SPIDeviceIndex                                         property  t         0                                  emits-change
.Type                                                   property  s         "SPIFlash"                         emits-change
xyz.openbmc_project.Configuration.SPIFlash.FirmwareInfo interface -         -                                  -
.CompatibleHardware                                     property  s         "com.tyan.Hardware.S8030.SPI.Host" emits-change
.VendorIANA                                             property  t         6653                               emits-change
xyz.openbmc_project.Configuration.SPIFlash.MuxOutputs0  interface -         -                                  -
.Name                                                   property  s         "BMC_SPI_SEL"                      emits-change
.Polarity                                               property  s         "High"                             emits-change
```

Change-Id: I1d9ace86b62ed5131c3405d13c5034f4d7770ec7
Signed-off-by: Alexander Hansen <alexander.hansen@9elements.com>
diff --git a/src/entity_manager/entity_manager.cpp b/src/entity_manager/entity_manager.cpp
index d3edf62..d66695f 100644
--- a/src/entity_manager/entity_manager.cpp
+++ b/src/entity_manager/entity_manager.cpp
@@ -259,64 +259,11 @@
         jsonPointerPath.append(std::to_string(exposesIndex))
             .append("/")
             .append(name);
-        if (config.type() == nlohmann::json::value_t::object)
+
+        if (!postConfigurationRecord(name, config, boardNameOrig, itemType,
+                                     jsonPointerPath, ifacePath))
         {
-            std::string ifaceName = "xyz.openbmc_project.Configuration.";
-            ifaceName.append(itemType).append(".").append(name);
-
-            std::shared_ptr<sdbusplus::asio::dbus_interface> objectIface =
-                dbus_interface.createInterface(objServer, ifacePath, ifaceName,
-                                               boardNameOrig);
-
-            dbus_interface::populateInterfaceFromJson(
-                io, systemConfiguration, jsonPointerPath, objectIface, config,
-                objServer, getPermission(name));
-        }
-        else if (config.type() == nlohmann::json::value_t::array)
-        {
-            size_t index = 0;
-            if (config.empty())
-            {
-                continue;
-            }
-            bool isLegal = true;
-            auto type = config[0].type();
-            if (type != nlohmann::json::value_t::object)
-            {
-                continue;
-            }
-
-            // verify legal json
-            for (const auto& arrayItem : config)
-            {
-                if (arrayItem.type() != type)
-                {
-                    isLegal = false;
-                    break;
-                }
-            }
-            if (!isLegal)
-            {
-                std::cerr << "dbus format error" << config << "\n";
-                break;
-            }
-
-            for (auto& arrayItem : config)
-            {
-                std::string ifaceName = "xyz.openbmc_project.Configuration.";
-                ifaceName.append(itemType).append(".").append(name);
-                ifaceName.append(std::to_string(index));
-
-                std::shared_ptr<sdbusplus::asio::dbus_interface> objectIface =
-                    dbus_interface.createInterface(objServer, ifacePath,
-                                                   ifaceName, boardNameOrig);
-
-                dbus_interface::populateInterfaceFromJson(
-                    io, systemConfiguration,
-                    jsonPointerPath + "/" + std::to_string(index), objectIface,
-                    arrayItem, objServer, getPermission(name));
-                index++;
-            }
+            break;
         }
     }
 
@@ -332,6 +279,74 @@
     topology.addBoard(boardPath, boardType, boardNameOrig, item);
 }
 
+bool EntityManager::postConfigurationRecord(
+    const std::string& name, nlohmann::json& config,
+    const std::string& boardNameOrig, const std::string& itemType,
+    const std::string& jsonPointerPath, const std::string& ifacePath)
+{
+    if (config.type() == nlohmann::json::value_t::object)
+    {
+        std::string ifaceName = "xyz.openbmc_project.Configuration.";
+        ifaceName.append(itemType).append(".").append(name);
+
+        std::shared_ptr<sdbusplus::asio::dbus_interface> objectIface =
+            dbus_interface.createInterface(objServer, ifacePath, ifaceName,
+                                           boardNameOrig);
+
+        dbus_interface::populateInterfaceFromJson(
+            io, systemConfiguration, jsonPointerPath, objectIface, config,
+            objServer, getPermission(name));
+    }
+    else if (config.type() == nlohmann::json::value_t::array)
+    {
+        size_t index = 0;
+        if (config.empty())
+        {
+            return true;
+        }
+        bool isLegal = true;
+        auto type = config[0].type();
+        if (type != nlohmann::json::value_t::object)
+        {
+            return true;
+        }
+
+        // verify legal json
+        for (const auto& arrayItem : config)
+        {
+            if (arrayItem.type() != type)
+            {
+                isLegal = false;
+                break;
+            }
+        }
+        if (!isLegal)
+        {
+            std::cerr << "dbus format error" << config << "\n";
+            return false;
+        }
+
+        for (auto& arrayItem : config)
+        {
+            std::string ifaceName = "xyz.openbmc_project.Configuration.";
+            ifaceName.append(itemType).append(".").append(name);
+            ifaceName.append(std::to_string(index));
+
+            std::shared_ptr<sdbusplus::asio::dbus_interface> objectIface =
+                dbus_interface.createInterface(objServer, ifacePath, ifaceName,
+                                               boardNameOrig);
+
+            dbus_interface::populateInterfaceFromJson(
+                io, systemConfiguration,
+                jsonPointerPath + "/" + std::to_string(index), objectIface,
+                arrayItem, objServer, getPermission(name));
+            index++;
+        }
+    }
+
+    return true;
+}
+
 static bool deviceRequiresPowerOn(const nlohmann::json& entity)
 {
     auto powerState = entity.find("PowerState");
diff --git a/src/entity_manager/entity_manager.hpp b/src/entity_manager/entity_manager.hpp
index 9a5a451..33efb31 100644
--- a/src/entity_manager/entity_manager.hpp
+++ b/src/entity_manager/entity_manager.hpp
@@ -60,6 +60,12 @@
         const std::string& jsonPointerPathBoard, const std::string& boardPath,
         const std::string& boardType);
 
+    // @returns false on error
+    bool postConfigurationRecord(
+        const std::string& name, nlohmann::json& config,
+        const std::string& boardNameOrig, const std::string& itemType,
+        const std::string& jsonPointerPath, const std::string& ifacePath);
+
     void pruneConfiguration(bool powerOff, const std::string& name,
                             const nlohmann::json& device);