entity-manager: create class PowerStatusMonitor
Removing following global variables
```
// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
static bool powerStatusOn = false;
// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
static std::unique_ptr<sdbusplus::bus::match_t> powerMatch = nullptr;
```
and placing them in a new class PowerStatusMonitor.
class PowerStatusMonitor is a member of class EntityManager and
inherits its lifetime. So there should be no issue with the lifetime
compared to the global variable.
Tested: Inspection only.
Change-Id: Ibdd9eb3adb6655d88c90c2da8435912887ff547c
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 ff9a5d5..d55105c 100644
--- a/src/entity_manager/entity_manager.cpp
+++ b/src/entity_manager/entity_manager.cpp
@@ -385,7 +385,7 @@
return;
}
- if (!em_utils::isPowerOn() && scannedPowerOff)
+ if (!powerStatus.isPowerOn() && scannedPowerOff)
{
return;
}
@@ -398,7 +398,7 @@
return;
}
- bool powerOff = !em_utils::isPowerOn();
+ bool powerOff = !powerStatus.isPowerOn();
for (const auto& [name, device] : lastJson.items())
{
pruneDevice(systemConfiguration, powerOff, scannedPowerOff,
@@ -505,7 +505,7 @@
[this, count, oldConfiguration, missingConfigurations]() {
// this is something that since ac has been applied to the
// bmc we saw, and we no longer see it
- bool powerOff = !em_utils::isPowerOn();
+ bool powerOff = !powerStatus.isPowerOn();
for (const auto& [name, device] :
missingConfigurations->items())
{
@@ -693,7 +693,7 @@
// some boards only show up after power is on, we want to not say they are
// removed until the same state happens
- em_utils::setupPowerMatch(em.systemBus);
+ em.powerStatus.setupPowerMatch(em.systemBus);
io.run();