util::dbus: Make common the hostRunningState code

Move the code for getting the host running state from attention handler
specific code to common utility code.

Signed-off-by: Ben Tyner <ben.tyner@ibm.com>
Change-Id: I457662cc13aa4dc89b321f238cd060e7e7486d1b
diff --git a/attn/attn_dbus.cpp b/attn/attn_dbus.cpp
index a82e5ce..a9af4c6 100644
--- a/attn/attn_dbus.cpp
+++ b/attn/attn_dbus.cpp
@@ -1,7 +1,6 @@
 #include <attn_common.hpp>
 #include <attn_dbus.hpp>
 #include <attn_logging.hpp>
-#include <xyz/openbmc_project/State/Boot/Progress/server.hpp>
 
 #include <string>
 #include <vector>
@@ -224,66 +223,4 @@
     return fd; // file descriptor or -1
 }
 
-/** @brief Get the running state of the host */
-HostRunningState hostRunningState()
-{
-    HostRunningState host = HostRunningState::Unknown;
-
-    // dbus specifics
-    constexpr auto path      = "/xyz/openbmc_project/state/host0";
-    constexpr auto interface = "xyz.openbmc_project.State.Boot.Progress";
-    constexpr auto extended  = "org.freedesktop.DBus.Properties";
-    constexpr auto function  = "Get";
-
-    sdbusplus::message::message method;
-
-    if (0 == dbusMethod(path, interface, function, method, extended))
-    {
-        try
-        {
-            // additional dbus call parameters
-            method.append(interface, "BootProgress");
-
-            // using system dbus
-            auto bus      = sdbusplus::bus::new_system();
-            auto response = bus.call(method);
-
-            // reply will be a variant
-            std::variant<std::string, bool, std::vector<uint8_t>,
-                         std::vector<std::string>>
-                reply;
-
-            // parse dbus response into reply
-            response.read(reply);
-
-            // get boot progress (string) and convert to boot stage
-            std::string bootProgress(std::get<std::string>(reply));
-
-            using BootProgress = sdbusplus::xyz::openbmc_project::State::Boot::
-                server::Progress::ProgressStages;
-
-            BootProgress stage = sdbusplus::xyz::openbmc_project::State::Boot::
-                server::Progress::convertProgressStagesFromString(bootProgress);
-
-            if ((stage == BootProgress::SystemInitComplete) ||
-                (stage == BootProgress::OSStart) ||
-                (stage == BootProgress::OSRunning))
-            {
-                host = HostRunningState::Started;
-            }
-            else
-            {
-                host = HostRunningState::NotStarted;
-            }
-        }
-        catch (const sdbusplus::exception::SdBusError& e)
-        {
-            trace<level::ERROR>("hostRunningState exception");
-            std::string traceMsg = std::string(e.what(), maxTraceLen);
-            trace<level::ERROR>(traceMsg.c_str());
-        }
-    }
-
-    return host;
-}
 } // namespace attn
diff --git a/attn/attn_dbus.hpp b/attn/attn_dbus.hpp
index 088bf59..59291a7 100644
--- a/attn/attn_dbus.hpp
+++ b/attn/attn_dbus.hpp
@@ -8,13 +8,6 @@
 namespace attn
 {
 
-enum class HostRunningState
-{
-    Unknown,
-    NotStarted,
-    Started
-};
-
 /**
  * Create a dbus method
  *
@@ -72,14 +65,4 @@
  */
 int getPel(const uint32_t i_pelId);
 
-/**
- * Get the host running state
- *
- * Use host boot progress to determine if a host has been started. If host
- * boot progress can not be determined then host state will be unknown.
- *
- * @return HostType == "Unknown", "Started or "NotStarted"
- */
-HostRunningState hostRunningState();
-
 } // namespace attn
diff --git a/attn/attn_handler.cpp b/attn/attn_handler.cpp
index c1a4b48..85172ea 100644
--- a/attn/attn_handler.cpp
+++ b/attn/attn_handler.cpp
@@ -14,6 +14,7 @@
 #include <attn/bp_handler.hpp>
 #include <attn/ti_handler.hpp>
 #include <attn/vital_handler.hpp>
+#include <util/dbus.hpp>
 
 #include <algorithm>
 #include <iomanip>
@@ -271,13 +272,17 @@
                 {
                     trace<level::INFO>("TI info data ptr is invalid");
 
-                    HostRunningState runningState = hostRunningState();
-                    std::string stateString       = "host state unknown";
+                    util::dbus::HostRunningState runningState =
+                        util::dbus::hostRunningState();
 
-                    if ((HostRunningState::Started == runningState) ||
-                        (HostRunningState::Unknown == runningState))
+                    std::string stateString = "host state unknown";
+
+                    if ((util::dbus::HostRunningState::Started ==
+                         runningState) ||
+                        (util::dbus::HostRunningState::Unknown == runningState))
                     {
-                        if (HostRunningState::Started == runningState)
+                        if (util::dbus::HostRunningState::Started ==
+                            runningState)
                         {
                             stateString = "host started";
                         }