Add BMC state transition of reboot

This commit should support the transition to
reboot a BMC using systemd.  Later commits will
handle the remaining transition monitoring for
updating the current state.

Change-Id: I1fb14b8775de4d2cbc522aa3405c8917291bf3cc
Signed-off-by: Josh D. King <jdking@us.ibm.com>
diff --git a/bmc_state_manager.cpp b/bmc_state_manager.cpp
index c739ae0..12a04a4 100644
--- a/bmc_state_manager.cpp
+++ b/bmc_state_manager.cpp
@@ -1,4 +1,5 @@
 #include <iostream>
+#include <string>
 #include <log.hpp>
 #include "bmc_state_manager.hpp"
 
@@ -14,6 +15,12 @@
 
 using namespace phosphor::logging;
 
+/* Map a transition to it's systemd target */
+const std::map<server::BMC::Transition, const char*> SYSTEMD_TABLE =
+{
+        {server::BMC::Transition::Reboot, "reboot.target"}
+};
+
 constexpr auto SYSTEMD_SERVICE   = "org.freedesktop.systemd1";
 constexpr auto SYSTEMD_OBJ_PATH  = "/org/freedesktop/systemd1";
 constexpr auto SYSTEMD_INTERFACE = "org.freedesktop.systemd1.Manager";
@@ -29,22 +36,35 @@
     return;
 }
 
+void BMC::executeTransition(const Transition tranReq)
+{
+    //Check to make sure it can be found
+    auto iter = SYSTEMD_TABLE.find(tranReq);
+    if (iter == SYSTEMD_TABLE.end()) return;
+
+    const auto& sysdUnit = iter->second;
+
+    auto method = this->bus.new_method_call(SYSTEMD_SERVICE,
+                                            SYSTEMD_OBJ_PATH,
+                                            SYSTEMD_INTERFACE,
+                                            "StartUnit");
+
+    method.append(sysdUnit, "replace");
+
+    this->bus.call(method);
+
+    return;
+}
+
 BMC::Transition BMC::requestedBMCTransition(Transition value)
 {
     log<level::INFO>(
             "Setting the RequestedBMCTransition field",
             entry("REQUESTED_BMC_TRANSITION=0x%s",
                   convertForMessage(value).c_str()));
-    return server::BMC::requestedBMCTransition(value);
-}
 
-BMC::BMCState BMC::currentBMCState(BMCState value)
-{
-    log<level::INFO>(
-            "Setting the BMCState field",
-            entry("CURRENT_BMC_STATE=0x%s",
-                  convertForMessage(value).c_str()));
-    return server::BMC::currentBMCState(value);
+    executeTransition(value);
+    return server::BMC::requestedBMCTransition(value);
 }
 
 
diff --git a/bmc_state_manager.hpp b/bmc_state_manager.hpp
index be88ba8..1ddef53 100644
--- a/bmc_state_manager.hpp
+++ b/bmc_state_manager.hpp
@@ -21,6 +21,10 @@
     public:
         /** @brief Constructs BMC State Manager
          *
+         *  @note This constructor passes 'true' to the base class in order to
+         *  defer dbus object registration until we can run
+         *  subscribeToSystemdSignals() and set our properties
+         *
          * @param[in] bus       - The Dbus bus object
          * @param[in] busName   - The Dbus name to own
          * @param[in] objPath   - The Dbus object path
@@ -38,8 +42,6 @@
         /** @brief Set value of BMCTransition **/
         Transition requestedBMCTransition(Transition value) override;
 
-        /** @breif Set value of CurrentBMCState **/
-        BMCState currentBMCState(BMCState value) override;
 
     private:
         /**
@@ -47,10 +49,15 @@
          **/
         void subscribeToSystemdSignals();
 
+        /** @brief Execute the transition request
+         *
+         *  @param[in] tranReq   - Transition requested
+         */
+        void executeTransition(Transition tranReq);
+
         /** @brief Persistent sdbusplus DBus bus connection. **/
         sdbusplus::bus::bus& bus;
 
-
 };
 
 } // namespace manager