entity-manager: attach DBus matches to EM class
Attach nameOwnerChangedMatch, interfacesAddedMatch,
interfacesRemovedMatch to the EntityManager instance.
They are added as unique_ptr to preserve the original control flow and
initialization point.
Since EntityManager instance goes out of scope only at the end of the
main function, their lifetime should be similar to their previous static
lifetime duration, from the perspective of the rest of the code.
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: Icc9bad2cc0cd3e9001f38cd94cff87b65b4b6b5d
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 e4cd71a..3dc2f80 100644
--- a/src/entity_manager/entity_manager.cpp
+++ b/src/entity_manager/entity_manager.cpp
@@ -650,7 +650,7 @@
// entities from DBus.
void EntityManager::initFilters(const std::set<std::string>& probeInterfaces)
{
- static sdbusplus::bus::match_t nameOwnerChangedMatch(
+ nameOwnerChangedMatch = std::make_unique<sdbusplus::bus::match_t>(
static_cast<sdbusplus::bus_t&>(*systemBus),
sdbusplus::bus::match::rules::nameOwnerChanged(),
[this](sdbusplus::message_t& m) {
@@ -668,7 +668,7 @@
// We also need a poke from DBus when new interfaces are created or
// destroyed.
- static sdbusplus::bus::match_t interfacesAddedMatch(
+ interfacesAddedMatch = std::make_unique<sdbusplus::bus::match_t>(
static_cast<sdbusplus::bus_t&>(*systemBus),
sdbusplus::bus::match::rules::interfacesAdded(),
[this, probeInterfaces](sdbusplus::message_t& msg) {
@@ -678,7 +678,7 @@
}
});
- static sdbusplus::bus::match_t interfacesRemovedMatch(
+ interfacesRemovedMatch = std::make_unique<sdbusplus::bus::match_t>(
static_cast<sdbusplus::bus_t&>(*systemBus),
sdbusplus::bus::match::rules::interfacesRemoved(),
[this, probeInterfaces](sdbusplus::message_t& msg) {