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);