util::dbus: Make common the transition host support

Move transition host support from attention handler specific code to
common util code.

Signed-off-by: Ben Tyner <ben.tyner@ibm.com>
Change-Id: I7fb4970354aaeca65fcc074107f99262e504ac34
diff --git a/util/dbus.cpp b/util/dbus.cpp
index 7e8a234..968a44f 100644
--- a/util/dbus.cpp
+++ b/util/dbus.cpp
@@ -165,6 +165,38 @@
     return names;
 }
 
+/** @brief Transition the host state */
+void transitionHost(const HostState i_hostState)
+{
+    try
+    {
+        // We will be transitioning host by starting appropriate dbus target
+        std::string target = "obmc-host-quiesce@0.target"; // quiesce is default
+
+        // crash (mpipl) mode state requested
+        if (HostState::Crash == i_hostState)
+        {
+            target = "obmc-host-crash@0.target";
+        }
+
+        auto bus    = sdbusplus::bus::new_system();
+        auto method = bus.new_method_call(
+            "org.freedesktop.systemd1", "/org/freedesktop/systemd1",
+            "org.freedesktop.systemd1.Manager", "StartUnit");
+
+        method.append(target);    // target unit to start
+        method.append("replace"); // mode = replace conflicting queued jobs
+
+        bus.call_noreply(method); // start the service
+    }
+    catch (const sdbusplus::exception::SdBusError& e)
+    {
+        trace::err("util::dbus::transitionHost exception");
+        std::string traceMsg = std::string(e.what());
+        trace::err(traceMsg.c_str());
+    }
+}
+
 } // namespace dbus
 
 } // namespace util
diff --git a/util/dbus.hpp b/util/dbus.hpp
index 03fb5be..66a2ad4 100644
--- a/util/dbus.hpp
+++ b/util/dbus.hpp
@@ -64,6 +64,23 @@
  */
 std::vector<std::string> systemNames();
 
+/** @brief Host states for util::dbus host state operations */
+enum class HostState
+{
+    Quiesce,
+    Diagnostic,
+    Crash
+};
+
+/**
+ * @brief Transition the host state
+ *
+ * We will transition the host state by starting the appropriate dbus target.
+ *
+ * @param i_hostState the state to transition the host to
+ */
+void transitionHost(const HostState i_hostState);
+
 } // namespace dbus
 
 } // namespace util