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/utility.cpp b/utility.cpp
index bd84249..680b89e 100644
--- a/utility.cpp
+++ b/utility.cpp
@@ -15,6 +15,8 @@
  */
 #include "utility.hpp"
 
+#include "types.hpp"
+
 #include <fstream>
 
 namespace phosphor
@@ -103,6 +105,24 @@
     return type;
 }
 
+bool isPoweredOn(sdbusplus::bus::bus& bus)
+{
+    // When state = 1, system is powered on
+    int32_t state = 0;
+
+    try
+    {
+        auto service = util::getService(POWER_OBJ_PATH, POWER_IFACE, bus);
+        getProperty<int32_t>(POWER_IFACE, "state", POWER_OBJ_PATH, service, bus,
+                             state);
+    }
+    catch (std::exception& e)
+    {
+        log<level::INFO>("Failed to get power state. Assuming it is off.");
+    }
+    return state != 0;
+}
+
 } // namespace util
 } // namespace power
 } // namespace phosphor