entity-manager: create class EMDBusInterface
class EMDBusInterface is created to remove global var 'inventory'.
The one instance of this class is a member of class EntityManager and
has the same lifetime. Since the EntityManager class instance is created
at the start of the main function, the 'inventory' member should always
be in scope from the perspective of the rest of the code, as before.
The class was created with a small amount of changes.
It does not aim to be a good abstraction for entity-manager's dbus
interface, the primary goal is to get rid of the global variable and
avoid passing it through a bunch of functions.
Tested: On Tyan S8030
```
Jul 01 09:59:26 s8030-bmc-30303035c0c1 entity-manager[4204]: Inventory Added: Supermicro PWS 920P SQ 0
Jul 01 09:59:26 s8030-bmc-30303035c0c1 entity-manager[4204]: Inventory Added: Supermicro PWS 920P SQ 1
Jul 01 09:59:26 s8030-bmc-30303035c0c1 entity-manager[4204]: Inventory Added: chassis
Jul 01 09:59:26 s8030-bmc-30303035c0c1 entity-manager[4204]: Inventory Added: MBX 1.57 Chassis
```
busctl tree output as before
Change-Id: I5f682311358836f88fe861d778210cf38efe08fa
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 5a6955d..e4cd71a 100644
--- a/src/entity_manager/entity_manager.cpp
+++ b/src/entity_manager/entity_manager.cpp
@@ -124,17 +124,17 @@
boardPath += boardName;
std::shared_ptr<sdbusplus::asio::dbus_interface> inventoryIface =
- dbus_interface::createInterface(
- objServer, boardPath, "xyz.openbmc_project.Inventory.Item",
- boardName);
+ dbus_interface.createInterface(objServer, boardPath,
+ "xyz.openbmc_project.Inventory.Item",
+ boardName);
std::shared_ptr<sdbusplus::asio::dbus_interface> boardIface =
- dbus_interface::createInterface(
+ dbus_interface.createInterface(
objServer, boardPath,
"xyz.openbmc_project.Inventory.Item." + boardType,
boardNameOrig);
- dbus_interface::createAddObjectMethod(
+ dbus_interface.createAddObjectMethod(
io, jsonPointerPath, boardPath, systemConfiguration, objServer,
boardNameOrig);
@@ -148,8 +148,8 @@
if (propValue.type() == nlohmann::json::value_t::object)
{
std::shared_ptr<sdbusplus::asio::dbus_interface> iface =
- dbus_interface::createInterface(objServer, boardPath,
- propName, boardNameOrig);
+ dbus_interface.createInterface(objServer, boardPath,
+ propName, boardNameOrig);
dbus_interface::populateInterfaceFromJson(
io, systemConfiguration, jsonPointerPath + propName, iface,
@@ -211,7 +211,7 @@
if (itemType == "BMC")
{
std::shared_ptr<sdbusplus::asio::dbus_interface> bmcIface =
- dbus_interface::createInterface(
+ dbus_interface.createInterface(
objServer, ifacePath,
"xyz.openbmc_project.Inventory.Item.Bmc",
boardNameOrig);
@@ -222,7 +222,7 @@
else if (itemType == "System")
{
std::shared_ptr<sdbusplus::asio::dbus_interface> systemIface =
- dbus_interface::createInterface(
+ dbus_interface.createInterface(
objServer, ifacePath,
"xyz.openbmc_project.Inventory.Item.System",
boardNameOrig);
@@ -244,7 +244,7 @@
ifaceName.append(itemType).append(".").append(name);
std::shared_ptr<sdbusplus::asio::dbus_interface>
- objectIface = dbus_interface::createInterface(
+ objectIface = dbus_interface.createInterface(
objServer, ifacePath, ifaceName, boardNameOrig);
dbus_interface::populateInterfaceFromJson(
@@ -288,7 +288,7 @@
ifaceName.append(std::to_string(index));
std::shared_ptr<sdbusplus::asio::dbus_interface>
- objectIface = dbus_interface::createInterface(
+ objectIface = dbus_interface.createInterface(
objServer, ifacePath, ifaceName, boardNameOrig);
dbus_interface::populateInterfaceFromJson(
@@ -302,7 +302,7 @@
}
std::shared_ptr<sdbusplus::asio::dbus_interface> itemIface =
- dbus_interface::createInterface(
+ dbus_interface.createInterface(
objServer, ifacePath,
"xyz.openbmc_project.Configuration." + itemType,
boardNameOrig);
@@ -326,7 +326,7 @@
continue;
}
- auto ifacePtr = dbus_interface::createInterface(
+ auto ifacePtr = dbus_interface.createInterface(
objServer, assocPath, "xyz.openbmc_project.Association.Definitions",
findBoard->second);
@@ -422,7 +422,7 @@
return;
}
- auto& ifaces = dbus_interface::getDeviceInterfaces(device);
+ auto& ifaces = dbus_interface.getDeviceInterfaces(device);
for (auto& iface : ifaces)
{
auto sharedPtr = iface.lock();