Update softoff to support new host control interface

The new host control design requires applications use its
new dbus interfaces to interact with the host.  This commit
moves the softoff application over to this new interface.

Change-Id: I3c6830a59d72df1f112ee7a63a08bfca53375bf7
Signed-off-by: Andrew Geissler <andrewg@us.ibm.com>
diff --git a/softoff/softoff.hpp b/softoff/softoff.hpp
index f0e992c..43bc303 100644
--- a/softoff/softoff.hpp
+++ b/softoff/softoff.hpp
@@ -2,14 +2,20 @@
 
 #include <sdbusplus/bus.hpp>
 #include <sdbusplus/server/object.hpp>
+#include <functional>
+#include <xyz/openbmc_project/Control/Host/server.hpp>
 #include <xyz/openbmc_project/Ipmi/Internal/SoftPowerOff/server.hpp>
 #include "timer.hpp"
+#include "config.h"
 namespace phosphor
 {
 namespace ipmi
 {
 
 namespace Base = sdbusplus::xyz::openbmc_project::Ipmi::Internal::server;
+using namespace sdbusplus::xyz::openbmc_project::Control::server;
+
+namespace sdbusRule = sdbusplus::bus::match::rules;
 
 /** @class SoftPowerOff
  *  @brief Responsible for coordinating Host SoftPowerOff operation
@@ -30,17 +36,27 @@
             sdbusplus::server::object::object<
                 Base::SoftPowerOff>(bus, objPath, false),
                 bus(bus),
-                timer(event)
+                timer(event),
+                hostControlSignal(
+                        bus,
+                        sdbusRule::type::signal() +
+                        sdbusRule::member("CommandComplete") +
+                        sdbusRule::path("/xyz/openbmc_project/control/host0") +
+                        sdbusRule::interface(CONTROL_HOST_BUSNAME) +
+                        sdbusRule::argN(0,convertForMessage(
+                                Host::Command::SoftOff)),
+                        std::bind(std::mem_fn(&SoftPowerOff::hostControlEvent),
+                                  this, std::placeholders::_1))
         {
             // Need to announce since we may get the response
-            // very quickly on SMS_ATN
+            // very quickly on host shutdown command
             emit_object_added();
 
-            // The whole purpose of this application is to send SMS_ATTN
-            // and watch for the soft power off to go through. We need the
-            // interface added signal emitted before we send SMS_ATN just to
-            // attend to lightning fast response from host
-            sendSMSAttn();
+            // The whole purpose of this application is to send a host shutdown
+            // command and watch for the soft power off to go through. We need
+            // the interface added signal emitted before we send the shutdown
+            // command just to attend to lightning fast response from host
+            sendHostShutDownCmd();
         }
 
         /** @brief Tells if the objective of this application is completed */
@@ -94,21 +110,36 @@
          */
         bool completed = false;
 
-        /** @brief Sends SMS_ATN to host to initiate soft power off process.
+        /** @brief Subscribe to host control signals
          *
-         *  After sending the SMS_ATN, starts a timer for 30
-         *  seconds and expects a initial response from the host.
-         *  After receiving the initial response, starts another
-         *  timer for 30 minutes to let host do a clean shutdown of
-         *  partitions. When the second response is received from the
-         *  host, it indicates that BMC can do a power off.
+         *  Protocol is to send the host power off request to the host
+         *  control interface and then wait for a signal indicating pass/fail
+         **/
+        sdbusplus::bus::match_t hostControlSignal;
+
+        /** @brief Sends host control command to tell host to shut down
+         *
+         *  After sending the command, wait for a signal indicating the status
+         *  of the command.
+         *
+         *  After receiving the initial response, start a timer for 30 minutes
+         *  to let host do a clean shutdown of partitions. When the response is
+         *  received from the host, it indicates that BMC can do a power off.
          *  If BMC fails to get any response, then a hard power off would
          *  be forced.
          *
          *  @return - Does not return anything. Error will result in exception
          *            being thrown
          */
-        void sendSMSAttn();
+        void sendHostShutDownCmd();
+
+        /** @brief Callback function on host control signals
+         *
+         * @param[in]  msg       - Data associated with subscribed signal
+         *
+         */
+        void hostControlEvent(sdbusplus::message::message& msg);
+
 };
 } // namespace ipmi
 } // namespace phosphor