host-state-manager: Add multi-host support

Add support management multiple host state with multi process.
Each process obtain a d-bus object for corresponding host.

TESTED : Built the openbmc image for Facebook Bletchley hardware.
Verified Host State buses/objects created successfully

root@bletchley:~# busctl tree xyz.openbmc_project.State.Host1
└─/xyz
  └─/xyz/openbmc_project
    └─/xyz/openbmc_project/state
      └─/xyz/openbmc_project/state/host1
root@bletchley:~# busctl tree xyz.openbmc_project.State.Host2
└─/xyz
  └─/xyz/openbmc_project
    └─/xyz/openbmc_project/state
      └─/xyz/openbmc_project/state/host2
...

Built with host id 0 :
expose both Host and Host0 name to keep backwards compatibility.
'busctl |grep xyz.openbmc_project.State.Host'
...
xyz.openbmc_project.State.Host   8398 phosphor-host-s root  :1.212  xyz.openbmc_project.State.Host@0.service
xyz.openbmc_project.State.Host0  8398 phosphor-host-s root  :1.212  xyz.openbmc_project.State.Host@0.service
...

Signed-off-by: Allen.Wang <Allen_Wang@quantatw.com>
Change-Id: Ie18007122a5df9e33f387e691eaa9979ce18ed0e
diff --git a/host_state_manager_main.cpp b/host_state_manager_main.cpp
index 865987c..186e06b 100644
--- a/host_state_manager_main.cpp
+++ b/host_state_manager_main.cpp
@@ -2,6 +2,8 @@
 
 #include "host_state_manager.hpp"
 
+#include <getopt.h>
+
 #include <sdbusplus/bus.hpp>
 
 #include <cstdlib>
@@ -9,24 +11,51 @@
 #include <experimental/filesystem>
 #include <iostream>
 
-int main()
+int main(int argc, char** argv)
 {
+    size_t hostId = 0;
+
+    int arg;
+    int optIndex = 0;
+
+    static struct option longOpts[] = {{"host", required_argument, 0, 'h'},
+                                       {0, 0, 0, 0}};
+
+    while ((arg = getopt_long(argc, argv, "h:", longOpts, &optIndex)) != -1)
+    {
+        switch (arg)
+        {
+            case 'h':
+                hostId = std::stoul(optarg);
+                break;
+            default:
+                break;
+        }
+    }
+
     namespace fs = std::experimental::filesystem;
 
     auto bus = sdbusplus::bus::new_default();
 
-    // For now, we only have one instance of the host
-    auto objPathInst = std::string{HOST_OBJPATH} + '0';
+    auto hostBusName = std::string{HOST_BUSNAME} + std::to_string(hostId);
+    auto objPathInst = std::string{HOST_OBJPATH} + std::to_string(hostId);
 
     // Add sdbusplus ObjectManager.
     sdbusplus::server::manager::manager objManager(bus, objPathInst.c_str());
 
-    phosphor::state::manager::Host manager(bus, objPathInst.c_str());
+    phosphor::state::manager::Host manager(bus, objPathInst.c_str(), hostId);
 
     auto dir = fs::path(HOST_STATE_PERSIST_PATH).parent_path();
     fs::create_directories(dir);
 
-    bus.request_name(HOST_BUSNAME);
+    // For backwards compatibility, request a busname without host id if
+    // input id is 0.
+    if (hostId == 0)
+    {
+        bus.request_name(HOST_BUSNAME);
+    }
+
+    bus.request_name(hostBusName.c_str());
 
     while (true)
     {