Add support to send host bound commands for OpenPower machines

Ipmid launches a D-Bus service that would enable REST users to
send commands to Host. This commit puts the support for using
that service to send commands that are applicable to OpenPower
implementations only.

Change-Id: I68dcb3e742145b85a719fa3045367402aa1ed19b
Signed-off-by: Vishwanatha Subbanna <vishwa@linux.vnet.ibm.com>
diff --git a/oemhandler.cpp b/oemhandler.cpp
index 91bf2b7..aba86e3 100644
--- a/oemhandler.cpp
+++ b/oemhandler.cpp
@@ -1,10 +1,15 @@
 #include "oemhandler.hpp"
+#include "config.h"
 #include <host-ipmid/ipmid-api.h>
+#include <host-ipmid/ipmid-host-cmd.hpp>
 #include <fstream>
 #include <stdio.h>
 #include <string.h>
-#include <systemd/sd-bus.h>
 #include <endian.h>
+#include <functional>
+#include <systemd/sd-bus.h>
+#include <sdbusplus/bus.hpp>
+#include <host-interface.hpp>
 
 void register_netfn_oem_partial_esel() __attribute__((constructor));
 
@@ -136,6 +141,14 @@
     return ipmi_rc;
 }
 
+namespace {
+// Storage to keep the object alive during process life
+std::unique_ptr<open_power::host::command::Host> opHost
+        __attribute__((init_priority(101)));
+std::unique_ptr<sdbusplus::server::manager::manager> objManager
+        __attribute__((init_priority(101)));
+}
+
 void register_netfn_oem_partial_esel()
 {
     printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_OEM, IPMI_CMD_PESEL);
@@ -146,5 +159,19 @@
     ipmi_register_callback(NETFUN_OEM, IPMI_CMD_PREP_FW_UPDATE, NULL, ipmi_ibm_oem_prep_fw_update,
                            SYSTEM_INTERFACE);
 
+    // Create new object on the bus
+    auto objPath = std::string{CONTROL_HOST_OBJ_MGR} + '/' + HOST_NAME + '0';
+
+    // Add sdbusplus ObjectManager.
+    auto& sdbusPlusHandler = ipmid_get_sdbus_plus_handler();
+    objManager = std::make_unique<sdbusplus::server::manager::manager>(
+                    *sdbusPlusHandler,
+                    CONTROL_HOST_OBJ_MGR);
+
+    opHost = std::make_unique<open_power::host::command::Host>(
+                        *sdbusPlusHandler, objPath.c_str());
+
+    // Service for this is provided by phosphor layer systemcmdintf
+    // and this will be as part of that.
     return;
 }