Add support for tracking system power state

Change-Id: Ie0f27f696082ff3ee60c955992f3c2e55f4b5e57
Signed-off-by: Brandon Wyman <bjwyman@gmail.com>
diff --git a/power-supply/power_supply.hpp b/power-supply/power_supply.hpp
index 496218f..317c20b 100644
--- a/power-supply/power_supply.hpp
+++ b/power-supply/power_supply.hpp
@@ -2,6 +2,7 @@
 #include <sdbusplus/bus/match.hpp>
 #include "device.hpp"
 #include "pmbus.hpp"
+#include "timer.hpp"
 
 namespace witherspoon
 {
@@ -34,11 +35,15 @@
          * @param[in] objpath - the path to monitor
          * @param[in] invpath - the inventory path to use
          * @param[in] bus - D-Bus bus object
+         * @param[in] e - event object
+         * @param[in] t - time to allow power supply to assert PG#
          */
         PowerSupply(const std::string& name, size_t inst,
                     const std::string& objpath,
                     const std::string& invpath,
-                    sdbusplus::bus::bus& bus);
+                    sdbusplus::bus::bus& bus,
+                    event::Event& e,
+                    std::chrono::seconds& t);
 
         /**
          * Power supply specific function to analyze for faults/errors.
@@ -66,14 +71,6 @@
         std::string monitorPath;
 
         /**
-         * The D-Bus path to use for this power supply's inventory status.
-         */
-        std::string inventoryPath;
-
-        /** @brief Connection for sdbusplus bus */
-        sdbusplus::bus::bus& bus;
-
-        /**
          * @brief Pointer to the PMBus interface
          *
          * Used to read out of or write to the /sysfs tree(s) containing files
@@ -83,13 +80,45 @@
         witherspoon::pmbus::PMBus pmbusIntf;
 
         /**
-         * @brief True if the power supply is present.
+         * @brief D-Bus path to use for this power supply's inventory status.
          */
+        std::string inventoryPath;
+
+        /** @brief Connection for sdbusplus bus */
+        sdbusplus::bus::bus& bus;
+
+        /** @brief True if the power supply is present. */
         bool present = false;
 
-        /** @brief Used to subscribe to dbus pcap propety changes **/
+        /** @brief Used to subscribe to D-Bus property changes to Present **/
         std::unique_ptr<sdbusplus::bus::match_t> presentMatch;
 
+        /** @brief True if the power is on. */
+        bool powerOn = false;
+
+        /** @brief The sd_event structure used by the power on timer. */
+        event::Event& event;
+
+        /**
+         * @brief Interval to setting powerOn to true.
+         *
+         * The amount of time to wait from power state on to setting the
+         * internal powerOn state to true. The amount of time the power supply
+         * is allowed to delay setting DGood/PG#.
+         */
+        std::chrono::seconds powerOnInterval;
+
+        /**
+         * @brief Timer used to delay setting the internal powerOn state.
+         *
+         * The timer used to do the callback after the power state has been on
+         * long enough.
+         */
+        Timer powerOnTimer;
+
+        /** @brief Used to subscribe to D-Bus power on state changes **/
+        std::unique_ptr<sdbusplus::bus::match_t> powerOnMatch;
+
         /**
          * @brief Has a PMBus read failure already been logged?
          */
@@ -128,6 +157,22 @@
          * objects present member variable to reflect current status.
          */
         void updatePresence();
+
+        /**
+         * @brief Updates the poweredOn status by querying D-Bus
+         *
+         * The D-Bus property for the sytem power state will be read to
+         * determine if the system is powered on or not.
+         */
+        void updatePowerState();
+
+        /** @brief Callback for power state property changes
+         * Process changes to the powered on stat property for the system.
+         *
+         * @param[in] msg - Data associated with the power state signal
+         */
+        void powerStateChanged(sdbusplus::message::message& msg);
+
 };
 
 }