Let PowerState class run multiple callbacks

Previously the PowerState class could only handle a single callback
function.  This commit changes that to allow other callback functions to
be added with a addCallback() method.  The callback functions are then
executed when the power state changes.

This also changes the use of the PowerState object in the fan presence
code to a shared_ptr instead of a unique_ptr, and adds a function to
return the PowerState object to use in the app, creating it if
necessary.  This allows multiple pieces of the code to add their own
callbacks to the same object.

Signed-off-by: Matt Spinler <spinler@us.ibm.com>
Change-Id: I35fc8ab94c4806f0c7fd2f1552c58131b8f30f23
diff --git a/presence/error_reporter.cpp b/presence/error_reporter.cpp
index f1dfaa9..72c7dae 100644
--- a/presence/error_reporter.cpp
+++ b/presence/error_reporter.cpp
@@ -15,6 +15,7 @@
  */
 #include "error_reporter.hpp"
 
+#include "get_power_state.hpp"
 #include "logging.hpp"
 #include "psensor.hpp"
 #include "utility.hpp"
@@ -46,14 +47,12 @@
     const std::vector<
         std::tuple<Fan, std::vector<std::unique_ptr<PresenceSensor>>>>& fans) :
     _bus(bus),
-    _event(sdeventplus::Event::get_default())
+    _event(sdeventplus::Event::get_default()),
+    _powerState(getPowerStateObject())
 {
-    // If different methods to check the power state are needed across the
-    // various platforms, the method/class to use could be read out of JSON
-    // or set with a compilation flag.
-    _powerState = std::make_unique<PGoodState>(
-        bus, std::bind(std::mem_fn(&ErrorReporter::powerStateChanged), this,
-                       std::placeholders::_1));
+    _powerState->addCallback("errorReporter",
+                             std::bind(&ErrorReporter::powerStateChanged, this,
+                                       std::placeholders::_1));
 
     for (const auto& fan : fans)
     {