Refactor: Move isPoweredOn to utility

The check of power on will be used by other components, so move it to
utility.
There are several constexpr definitions are used by multiple components,
move them into types.hpp so that we do not have duplicated constexprs.

Signed-off-by: Lei YU <mine260309@gmail.com>
Change-Id: I42ad142d6e7ae8da9c0cf6d8f5cb21dee229eba2
diff --git a/power-supply/power_supply.cpp b/power-supply/power_supply.cpp
index 62067ef..981435f 100644
--- a/power-supply/power_supply.cpp
+++ b/power-supply/power_supply.cpp
@@ -21,6 +21,7 @@
 #include "gpio.hpp"
 #include "names_values.hpp"
 #include "pmbus.hpp"
+#include "types.hpp"
 #include "utility.hpp"
 
 #include <functional>
@@ -41,25 +42,6 @@
 using namespace sdbusplus::xyz::openbmc_project::Common::Device::Error;
 namespace version = sdbusplus::xyz::openbmc_project::Software::server;
 
-constexpr auto ASSOCIATION_IFACE = "xyz.openbmc_project.Association";
-constexpr auto LOGGING_IFACE = "xyz.openbmc_project.Logging.Entry";
-constexpr auto INVENTORY_IFACE = "xyz.openbmc_project.Inventory.Item";
-constexpr auto POWER_IFACE = "org.openbmc.control.Power";
-constexpr auto INVENTORY_MGR_IFACE = "xyz.openbmc_project.Inventory.Manager";
-constexpr auto ASSET_IFACE = "xyz.openbmc_project.Inventory.Decorator.Asset";
-constexpr auto VERSION_IFACE = "xyz.openbmc_project.Software.Version";
-
-constexpr auto ENDPOINTS_PROP = "endpoints";
-constexpr auto MESSAGE_PROP = "Message";
-constexpr auto RESOLVED_PROP = "Resolved";
-constexpr auto PRESENT_PROP = "Present";
-constexpr auto VERSION_PURPOSE_PROP = "Purpose";
-
-constexpr auto INVENTORY_OBJ_PATH = "/xyz/openbmc_project/inventory";
-constexpr auto POWER_OBJ_PATH = "/org/openbmc/control/power0";
-
-constexpr auto INPUT_HISTORY = "input_history";
-
 PowerSupply::PowerSupply(const std::string& name, size_t inst,
                          const std::string& objpath, const std::string& invpath,
                          sdbusplus::bus::bus& bus, const sdeventplus::Event& e,
@@ -261,31 +243,7 @@
 
 void PowerSupply::updatePowerState()
 {
-    // When state = 1, system is powered on
-    int32_t state = 0;
-
-    try
-    {
-        auto service = util::getService(POWER_OBJ_PATH, POWER_IFACE, bus);
-
-        // Use getProperty utility function to get power state.
-        util::getProperty<int32_t>(POWER_IFACE, "state", POWER_OBJ_PATH,
-                                   service, bus, state);
-
-        if (state)
-        {
-            powerOn = true;
-        }
-        else
-        {
-            powerOn = false;
-        }
-    }
-    catch (std::exception& e)
-    {
-        log<level::INFO>("Failed to get power state. Assuming it is off.");
-        powerOn = false;
-    }
+    powerOn = util::isPoweredOn(bus);
 }
 
 void PowerSupply::checkInputFault(const uint16_t statusWord)