Host state power on and off support

This supports the basic systemd transitions to power on and
off a host.  Future commits will handle monitoring for the
state transition to finish and updating the current state.

Change-Id: I1ada1f4e7bd2844db49e63aaaf5b64c88b4af127
Signed-off-by: Andrew Geissler <andrewg@us.ibm.com>
diff --git a/host_state_manager.cpp b/host_state_manager.cpp
index 1b3c556..640ea94 100644
--- a/host_state_manager.cpp
+++ b/host_state_manager.cpp
@@ -1,4 +1,6 @@
 #include <iostream>
+#include <map>
+#include <string>
 #include <systemd/sd-bus.h>
 #include "host_state_manager.hpp"
 
@@ -12,15 +14,30 @@
 // When you see server:: you know we're referencing our base class
 namespace server = sdbusplus::xyz::openbmc_project::State::server;
 
+/* Map a transition to it's systemd target */
+const std::map<server::Host::Transition,std::string> SYSTEMD_TARGET_TABLE =
+{
+        {server::Host::Transition::Off,"obmc-chassis-stop@0.target"},
+        {server::Host::Transition::On,"obmc-chassis-start@0.target"}
+};
+
+constexpr auto SYSTEMD_SERVICE   = "org.freedesktop.systemd1";
+constexpr auto SYSTEMD_OBJ_PATH  = "/org/freedesktop/systemd1";
+constexpr auto SYSTEMD_INTERFACE = "org.freedesktop.systemd1.Manager";
+
+constexpr auto SYSTEM_SERVICE   = "org.openbmc.managers.System";
+constexpr auto SYSTEM_OBJ_PATH  = "/org/openbmc/managers/System";
+constexpr auto SYSTEM_INTERFACE = SYSTEM_SERVICE;
+
 // TODO - Will be rewritten once sdbusplus client bindings are in place
 //        and persistent storage design is in place
 void Host::determineInitialState()
 {
     std::string sysState;
 
-    auto method = this->bus.new_method_call("org.openbmc.managers.System",
-                                            "/org/openbmc/managers/System",
-                                            "org.openbmc.managers.System",
+    auto method = this->bus.new_method_call(SYSTEM_SERVICE,
+                                            SYSTEM_OBJ_PATH,
+                                            SYSTEM_INTERFACE,
                                             "getSystemState");
 
     auto reply = this->bus.call(method);
@@ -45,17 +62,37 @@
     return;
 }
 
+void Host::executeTransition(Transition tranReq)
+{
+    auto sysdUnit = SYSTEMD_TARGET_TABLE.find(tranReq)->second;
+
+    auto method = this->bus.new_method_call(SYSTEMD_SERVICE,
+                                            SYSTEMD_OBJ_PATH,
+                                            SYSTEMD_INTERFACE,
+                                            "StartUnit");
+
+    method.append(sysdUnit);
+    method.append("replace");
+
+    this->bus.call(method);
+
+    return;
+}
+
 Host::Transition Host::requestedHostTransition(Transition value)
 {
-    std::cout << "Someone is setting the RequestedHostTransition field" <<
-        std::endl;
+    std::cout << "Someone is setting the RequestedHostTransition field"
+              << std::endl;
+    executeTransition(value);
+    std::cout << "Transition executed with success" << std::endl;
+
     return server::Host::requestedHostTransition(value);
 }
 
 Host::HostState Host::currentHostState(HostState value)
 {
-    std::cout << "Someone is being bad and trying to set the HostState field" <<
-            std::endl;
+    std::cout << "Someone is being bad and trying to set the HostState field"
+              << std::endl;
 
     return server::Host::currentHostState();
 }