sensor:monitor: Use a single PowerState object

Now that both monitor classes need to know about power state, change
them to keep a shared_ptr to a PowerState object and then pass the
object into their constructors.

Signed-off-by: Matt Spinler <spinler@us.ibm.com>
Change-Id: Ia83217e8af51204bbb3fc6e8e3f2eac5912b5913
diff --git a/sensor-monitor/threshold_alarm_logger.cpp b/sensor-monitor/threshold_alarm_logger.cpp
index 50ccf5e..78dbc55 100644
--- a/sensor-monitor/threshold_alarm_logger.cpp
+++ b/sensor-monitor/threshold_alarm_logger.cpp
@@ -82,12 +82,11 @@
             {false,
              ErrorData{"PerfLossLowClear", Entry::Level::Informational}}}}}}};
 
-ThresholdAlarmLogger::ThresholdAlarmLogger(sdbusplus::bus::bus& bus,
-                                           sdeventplus::Event& event) :
+ThresholdAlarmLogger::ThresholdAlarmLogger(
+    sdbusplus::bus::bus& bus, sdeventplus::Event& event,
+    std::shared_ptr<PowerState> powerState) :
     bus(bus),
-    event(event), _powerState(std::make_unique<PGoodState>(
-                      bus, std::bind(&ThresholdAlarmLogger::powerStateChanged,
-                                     this, std::placeholders::_1))),
+    event(event), _powerState(std::move(powerState)),
     warningMatch(bus,
                  "type='signal',member='PropertiesChanged',"
                  "path_namespace='/xyz/openbmc_project/sensors',"
@@ -110,6 +109,10 @@
                   std::bind(&ThresholdAlarmLogger::propertiesChanged, this,
                             std::placeholders::_1))
 {
+    _powerState->addCallback("thresholdMon",
+                             std::bind(&ThresholdAlarmLogger::powerStateChanged,
+                                       this, std::placeholders::_1));
+
     // check for any currently asserted threshold alarms
     std::for_each(
         thresholdData.begin(), thresholdData.end(),