dbushelper: avoid new bus connections
The dbushelper required a new bus connection, for what was often a
single dbus access. Switch the helper class to take a reference to
a bus instead so that the same bus connections can be reused.
Fixes openbmc/phosphor-pid-control#44
Tested: Significant decrease in the number of dbus connections
observed.
```
:1.510 8025 swampd root :1.510 phosphor-pid-control.service - -
:1.511 8025 swampd root :1.511 phosphor-pid-control.service - -
:1.512 8025 swampd root :1.512 phosphor-pid-control.service - -
xyz.openbmc_project.Hwmon.external 8025 swampd root :1.511 phosphor-pid-control.service - -
xyz.openbmc_project.State.FanCtrl 8025 swampd root :1.510 phosphor-pid-control.service
```
Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
Change-Id: Ifbbfe10cbd533aa95e35db2800dfb9e83e37a5e0
diff --git a/sensors/builder.cpp b/sensors/builder.cpp
index e71e9ce..166977b 100644
--- a/sensors/builder.cpp
+++ b/sensors/builder.cpp
@@ -82,17 +82,15 @@
{
ri = DbusPassive::createDbusPassive(
passiveListeningBus, info->type, name,
- std::make_unique<DbusHelper>(
- sdbusplus::bus::new_system()),
- info, redundancy);
+ std::make_unique<DbusHelper>(passiveListeningBus), info,
+ redundancy);
}
else
{
ri = DbusPassive::createDbusPassive(
passiveListeningBus, info->type, name,
- std::make_unique<DbusHelper>(
- sdbusplus::bus::new_system()),
- info, nullptr);
+ std::make_unique<DbusHelper>(passiveListeningBus), info,
+ nullptr);
}
if (ri == nullptr)
{
@@ -134,15 +132,13 @@
{
wi = DbusWritePercent::createDbusWrite(
info->writePath, info->min, info->max,
- std::make_unique<DbusHelper>(
- sdbusplus::bus::new_system()));
+ std::make_unique<DbusHelper>(passiveListeningBus));
}
else
{
wi = DbusWrite::createDbusWrite(
info->writePath, info->min, info->max,
- std::make_unique<DbusHelper>(
- sdbusplus::bus::new_system()));
+ std::make_unique<DbusHelper>(passiveListeningBus));
}
if (wi == nullptr)