entity-manager: not pass through io, objServer

Pass
`boost::asio::io_context& io`
and
`sdbusplus::asio::object_server& objServer`

into constructor for class EMDBusInterface.

Since these are just references, nothing exciting should happen here.
The change reduces the number of parameters and makes the code more
easily readable.

Tested: on Tyan S8030

clean log
```
Sep 22 16:00:47 s8030-bmc-30303035c0c1 systemd[1]: Started Entity Manager.
Sep 22 16:00:57 s8030-bmc-30303035c0c1 entity-manager[10392]: Inventory Added: Supermicro PWS 920P SQ 0
Sep 22 16:00:57 s8030-bmc-30303035c0c1 entity-manager[10392]: Inventory Added: Supermicro PWS 920P SQ 1
Sep 22 16:00:57 s8030-bmc-30303035c0c1 entity-manager[10392]: Inventory Added: Tyan S8030 Baseboard
Sep 22 16:00:57 s8030-bmc-30303035c0c1 entity-manager[10392]: Inventory Added: MBX 1.57 Chassis
```

and clean `busctl tree`
```
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/GenericContainPort
        |   |- /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
```

Change-Id: Id292bf86a72c9b6e707b2cec71b77c63ed5077a2
Signed-off-by: Alexander Hansen <alexander.hansen@9elements.com>
diff --git a/src/entity_manager/dbus_interface.cpp b/src/entity_manager/dbus_interface.cpp
index 3ae698c..b6fbc01 100644
--- a/src/entity_manager/dbus_interface.cpp
+++ b/src/entity_manager/dbus_interface.cpp
@@ -22,6 +22,11 @@
 const std::regex illegalDbusPathRegex("[^A-Za-z0-9_.]");
 const std::regex illegalDbusMemberRegex("[^A-Za-z0-9_]");
 
+EMDBusInterface::EMDBusInterface(boost::asio::io_context& io,
+                                 sdbusplus::asio::object_server& objServer) :
+    io(io), objServer(objServer)
+{}
+
 void tryIfaceInitialize(std::shared_ptr<sdbusplus::asio::dbus_interface>& iface)
 {
     try
@@ -38,9 +43,9 @@
 }
 
 std::shared_ptr<sdbusplus::asio::dbus_interface>
-    EMDBusInterface::createInterface(
-        sdbusplus::asio::object_server& objServer, const std::string& path,
-        const std::string& interface, const std::string& parent, bool checkNull)
+    EMDBusInterface::createInterface(const std::string& path,
+                                     const std::string& interface,
+                                     const std::string& parent, bool checkNull)
 {
     // on first add we have no reason to check for null before add, as there
     // won't be any. For dynamically added interfaces, we check for null so that
@@ -62,16 +67,15 @@
     return ptr;
 }
 
-void createDeleteObjectMethod(
+void EMDBusInterface::createDeleteObjectMethod(
     const std::string& jsonPointerPath,
     const std::shared_ptr<sdbusplus::asio::dbus_interface>& iface,
-    sdbusplus::asio::object_server& objServer,
-    nlohmann::json& systemConfiguration, boost::asio::io_context& io)
+    nlohmann::json& systemConfiguration)
 {
     std::weak_ptr<sdbusplus::asio::dbus_interface> interface = iface;
     iface->register_method(
-        "Delete", [&objServer, &systemConfiguration, interface,
-                   jsonPointerPath{std::string(jsonPointerPath)}, &io]() {
+        "Delete", [this, &systemConfiguration, interface,
+                   jsonPointerPath{std::string(jsonPointerPath)}]() {
             std::shared_ptr<sdbusplus::asio::dbus_interface> dbusInterface =
                 interface.lock();
             if (!dbusInterface)
@@ -85,7 +89,7 @@
 
             // todo(james): dig through sdbusplus to find out why we can't
             // delete it in a method call
-            boost::asio::post(io, [&objServer, dbusInterface]() mutable {
+            boost::asio::post(io, [dbusInterface, this]() mutable {
                 objServer.remove_interface(dbusInterface);
             });
 
@@ -196,12 +200,10 @@
 }
 
 // adds simple json types to interface's properties
-void populateInterfaceFromJson(
-    boost::asio::io_context& io, nlohmann::json& systemConfiguration,
-    const std::string& jsonPointerPath,
+void EMDBusInterface::populateInterfaceFromJson(
+    nlohmann::json& systemConfiguration, const std::string& jsonPointerPath,
     std::shared_ptr<sdbusplus::asio::dbus_interface>& iface,
-    nlohmann::json& dict, sdbusplus::asio::object_server& objServer,
-    sdbusplus::asio::PropertyPermission permission)
+    nlohmann::json& dict, sdbusplus::asio::PropertyPermission permission)
 {
     for (const auto& [key, value] : dict.items())
     {
@@ -232,25 +234,22 @@
     }
     if (permission == sdbusplus::asio::PropertyPermission::readWrite)
     {
-        createDeleteObjectMethod(jsonPointerPath, iface, objServer,
-                                 systemConfiguration, io);
+        createDeleteObjectMethod(jsonPointerPath, iface, systemConfiguration);
     }
     tryIfaceInitialize(iface);
 }
 
 void EMDBusInterface::createAddObjectMethod(
-    boost::asio::io_context& io, const std::string& jsonPointerPath,
-    const std::string& path, nlohmann::json& systemConfiguration,
-    sdbusplus::asio::object_server& objServer, const std::string& board)
+    const std::string& jsonPointerPath, const std::string& path,
+    nlohmann::json& systemConfiguration, const std::string& board)
 {
-    std::shared_ptr<sdbusplus::asio::dbus_interface> iface = createInterface(
-        objServer, path, "xyz.openbmc_project.AddObject", board);
+    std::shared_ptr<sdbusplus::asio::dbus_interface> iface =
+        createInterface(path, "xyz.openbmc_project.AddObject", board);
 
     iface->register_method(
         "AddObject",
-        [&systemConfiguration, &objServer,
-         jsonPointerPath{std::string(jsonPointerPath)}, path{std::string(path)},
-         board, &io,
+        [&systemConfiguration, jsonPointerPath{std::string(jsonPointerPath)},
+         path{std::string(path)}, board,
          this](const boost::container::flat_map<std::string, JsonVariantType>&
                    data) {
             nlohmann::json::json_pointer ptr(jsonPointerPath);
@@ -351,15 +350,15 @@
                                dbusName.end(), illegalDbusMemberRegex, "_");
 
             std::shared_ptr<sdbusplus::asio::dbus_interface> interface =
-                createInterface(objServer, path + "/" + dbusName,
+                createInterface(path + "/" + dbusName,
                                 "xyz.openbmc_project.Configuration." + *type,
                                 board, true);
             // permission is read-write, as since we just created it, must be
             // runtime modifiable
             populateInterfaceFromJson(
-                io, systemConfiguration,
+                systemConfiguration,
                 jsonPointerPath + "/Exposes/" + std::to_string(lastIndex),
-                interface, newData, objServer,
+                interface, newData,
                 sdbusplus::asio::PropertyPermission::readWrite);
         });
     tryIfaceInitialize(iface);
diff --git a/src/entity_manager/dbus_interface.hpp b/src/entity_manager/dbus_interface.hpp
index 84efec8..30423e6 100644
--- a/src/entity_manager/dbus_interface.hpp
+++ b/src/entity_manager/dbus_interface.hpp
@@ -16,20 +16,37 @@
 class EMDBusInterface
 {
   public:
+    EMDBusInterface(boost::asio::io_context& io,
+                    sdbusplus::asio::object_server& objServer);
+
     std::shared_ptr<sdbusplus::asio::dbus_interface> createInterface(
-        sdbusplus::asio::object_server& objServer, const std::string& path,
-        const std::string& interface, const std::string& parent,
-        bool checkNull = false);
+        const std::string& path, const std::string& interface,
+        const std::string& parent, bool checkNull = false);
 
     std::vector<std::weak_ptr<sdbusplus::asio::dbus_interface>>&
         getDeviceInterfaces(const nlohmann::json& device);
 
-    void createAddObjectMethod(
-        boost::asio::io_context& io, const std::string& jsonPointerPath,
-        const std::string& path, nlohmann::json& systemConfiguration,
-        sdbusplus::asio::object_server& objServer, const std::string& board);
+    void createAddObjectMethod(const std::string& jsonPointerPath,
+                               const std::string& path,
+                               nlohmann::json& systemConfiguration,
+                               const std::string& board);
+
+    void populateInterfaceFromJson(
+        nlohmann::json& systemConfiguration, const std::string& jsonPointerPath,
+        std::shared_ptr<sdbusplus::asio::dbus_interface>& iface,
+        nlohmann::json& dict,
+        sdbusplus::asio::PropertyPermission permission =
+            sdbusplus::asio::PropertyPermission::readOnly);
+
+    void createDeleteObjectMethod(
+        const std::string& jsonPointerPath,
+        const std::shared_ptr<sdbusplus::asio::dbus_interface>& iface,
+        nlohmann::json& systemConfiguration);
 
   private:
+    boost::asio::io_context& io;
+    sdbusplus::asio::object_server& objServer;
+
     boost::container::flat_map<
         std::string,
         std::vector<std::weak_ptr<sdbusplus::asio::dbus_interface>>>
@@ -138,18 +155,4 @@
     }
 }
 
-void createDeleteObjectMethod(
-    const std::string& jsonPointerPath,
-    const std::shared_ptr<sdbusplus::asio::dbus_interface>& iface,
-    sdbusplus::asio::object_server& objServer,
-    nlohmann::json& systemConfiguration, boost::asio::io_context& io);
-
-void populateInterfaceFromJson(
-    boost::asio::io_context& io, nlohmann::json& systemConfiguration,
-    const std::string& jsonPointerPath,
-    std::shared_ptr<sdbusplus::asio::dbus_interface>& iface,
-    nlohmann::json& dict, sdbusplus::asio::object_server& objServer,
-    sdbusplus::asio::PropertyPermission permission =
-        sdbusplus::asio::PropertyPermission::readOnly);
-
 } // namespace dbus_interface
diff --git a/src/entity_manager/entity_manager.cpp b/src/entity_manager/entity_manager.cpp
index e5e8b23..3835cc1 100644
--- a/src/entity_manager/entity_manager.cpp
+++ b/src/entity_manager/entity_manager.cpp
@@ -58,7 +58,8 @@
     objServer(sdbusplus::asio::object_server(systemBus, /*skipManager=*/true)),
     lastJson(nlohmann::json::object()),
     systemConfiguration(nlohmann::json::object()), io(io),
-    powerStatus(*systemBus), propertiesChangedTimer(io)
+    dbus_interface(io, objServer), powerStatus(*systemBus),
+    propertiesChangedTimer(io)
 {
     // All other objects that EntityManager currently support are under the
     // inventory subtree.
@@ -96,7 +97,7 @@
         }
 
         auto ifacePtr = dbus_interface.createInterface(
-            objServer, assocPath, "xyz.openbmc_project.Association.Definitions",
+            assocPath, "xyz.openbmc_project.Association.Definitions",
             findBoard->second);
 
         ifacePtr->register_property("Associations", assocPropValue);
@@ -134,22 +135,19 @@
         em_utils::buildInventorySystemPath(boardName, boardType);
 
     std::shared_ptr<sdbusplus::asio::dbus_interface> inventoryIface =
-        dbus_interface.createInterface(objServer, boardPath,
-                                       "xyz.openbmc_project.Inventory.Item",
-                                       boardName);
+        dbus_interface.createInterface(
+            boardPath, "xyz.openbmc_project.Inventory.Item", boardName);
 
     std::shared_ptr<sdbusplus::asio::dbus_interface> boardIface =
         dbus_interface.createInterface(
-            objServer, boardPath,
-            "xyz.openbmc_project.Inventory.Item." + boardType, boardNameOrig);
+            boardPath, "xyz.openbmc_project.Inventory.Item." + boardType,
+            boardNameOrig);
 
-    dbus_interface.createAddObjectMethod(
-        io, jsonPointerPath, boardPath, systemConfiguration, objServer,
-        boardNameOrig);
+    dbus_interface.createAddObjectMethod(jsonPointerPath, boardPath,
+                                         systemConfiguration, boardNameOrig);
 
-    dbus_interface::populateInterfaceFromJson(
-        io, systemConfiguration, jsonPointerPath, boardIface, boardValues,
-        objServer);
+    dbus_interface.populateInterfaceFromJson(
+        systemConfiguration, jsonPointerPath, boardIface, boardValues);
     jsonPointerPath += "/";
     // iterate through board properties
     for (const auto& [propName, propValue] : boardValues.items())
@@ -157,12 +155,12 @@
         if (propValue.type() == nlohmann::json::value_t::object)
         {
             std::shared_ptr<sdbusplus::asio::dbus_interface> iface =
-                dbus_interface.createInterface(objServer, boardPath, propName,
+                dbus_interface.createInterface(boardPath, propName,
                                                boardNameOrig);
 
-            dbus_interface::populateInterfaceFromJson(
-                io, systemConfiguration, jsonPointerPath + propName, iface,
-                propValue, objServer);
+            dbus_interface.populateInterfaceFromJson(
+                systemConfiguration, jsonPointerPath + propName, iface,
+                propValue);
         }
     }
 
@@ -235,21 +233,21 @@
     {
         std::shared_ptr<sdbusplus::asio::dbus_interface> bmcIface =
             dbus_interface.createInterface(
-                objServer, ifacePath, "xyz.openbmc_project.Inventory.Item.Bmc",
+                ifacePath, "xyz.openbmc_project.Inventory.Item.Bmc",
                 boardNameOrig);
-        dbus_interface::populateInterfaceFromJson(
-            io, systemConfiguration, jsonPointerPath, bmcIface, item, objServer,
+        dbus_interface.populateInterfaceFromJson(
+            systemConfiguration, jsonPointerPath, bmcIface, item,
             getPermission(itemType));
     }
     else if (itemType == "System")
     {
         std::shared_ptr<sdbusplus::asio::dbus_interface> systemIface =
             dbus_interface.createInterface(
-                objServer, ifacePath,
-                "xyz.openbmc_project.Inventory.Item.System", boardNameOrig);
-        dbus_interface::populateInterfaceFromJson(
-            io, systemConfiguration, jsonPointerPath, systemIface, item,
-            objServer, getPermission(itemType));
+                ifacePath, "xyz.openbmc_project.Inventory.Item.System",
+                boardNameOrig);
+        dbus_interface.populateInterfaceFromJson(
+            systemConfiguration, jsonPointerPath, systemIface, item,
+            getPermission(itemType));
     }
 
     for (const auto& [name, config] : item.items())
@@ -268,11 +266,11 @@
 
     std::shared_ptr<sdbusplus::asio::dbus_interface> itemIface =
         dbus_interface.createInterface(
-            objServer, ifacePath,
-            "xyz.openbmc_project.Configuration." + itemType, boardNameOrig);
+            ifacePath, "xyz.openbmc_project.Configuration." + itemType,
+            boardNameOrig);
 
-    dbus_interface::populateInterfaceFromJson(
-        io, systemConfiguration, jsonPointerPath, itemIface, item, objServer,
+    dbus_interface.populateInterfaceFromJson(
+        systemConfiguration, jsonPointerPath, itemIface, item,
         getPermission(itemType));
 
     topology.addBoard(boardPath, boardType, boardNameOrig, item);
@@ -289,12 +287,11 @@
         ifaceName.append(itemType).append(".").append(name);
 
         std::shared_ptr<sdbusplus::asio::dbus_interface> objectIface =
-            dbus_interface.createInterface(objServer, ifacePath, ifaceName,
-                                           boardNameOrig);
+            dbus_interface.createInterface(ifacePath, ifaceName, boardNameOrig);
 
-        dbus_interface::populateInterfaceFromJson(
-            io, systemConfiguration, jsonPointerPath, objectIface, config,
-            objServer, getPermission(name));
+        dbus_interface.populateInterfaceFromJson(
+            systemConfiguration, jsonPointerPath, objectIface, config,
+            getPermission(name));
     }
     else if (config.type() == nlohmann::json::value_t::array)
     {
@@ -332,13 +329,13 @@
             ifaceName.append(std::to_string(index));
 
             std::shared_ptr<sdbusplus::asio::dbus_interface> objectIface =
-                dbus_interface.createInterface(objServer, ifacePath, ifaceName,
+                dbus_interface.createInterface(ifacePath, ifaceName,
                                                boardNameOrig);
 
-            dbus_interface::populateInterfaceFromJson(
-                io, systemConfiguration,
+            dbus_interface.populateInterfaceFromJson(
+                systemConfiguration,
                 jsonPointerPath + "/" + std::to_string(index), objectIface,
-                arrayItem, objServer, getPermission(name));
+                arrayItem, getPermission(name));
             index++;
         }
     }