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.hpp b/host_state_manager.hpp
index a27cbf5..c3394f0 100644
--- a/host_state_manager.hpp
+++ b/host_state_manager.hpp
@@ -51,8 +51,9 @@
      *
      * @param[in] bus       - The Dbus bus object
      * @param[in] objPath   - The Dbus object path
+     * @param[in] id        - The Host id
      */
-    Host(sdbusplus::bus::bus& bus, const char* objPath) :
+    Host(sdbusplus::bus::bus& bus, const char* objPath, size_t id) :
         HostInherit(bus, objPath, true), bus(bus),
         systemdSignalJobRemoved(
             bus,
@@ -68,11 +69,14 @@
                 sdbusRule::interface("org.freedesktop.systemd1.Manager"),
             std::bind(std::mem_fn(&Host::sysStateChangeJobNew), this,
                       std::placeholders::_1)),
-        settings(bus)
+        settings(bus), id(id)
     {
         // Enable systemd signals
         subscribeToSystemdSignals();
 
+        // create map of target name base on host id
+        createSystemdTargetMaps();
+
         // Will throw exception on fail
         determineInitialState();
 
@@ -135,6 +139,11 @@
      **/
     void determineInitialState();
 
+    /**
+     * create systemd target instance names and mapping table
+     **/
+    void createSystemdTargetMaps();
+
     /** @brief Execute the transition request
      *
      * This function assumes the state has been validated and the host
@@ -267,6 +276,24 @@
      */
     bool deserialize(const fs::path& path);
 
+    /**
+     * @brief Get target name of a HostState
+     *
+     * @param[in] state      -  The state of the host
+     *
+     * @return string - systemd target name of the state
+     */
+    const std::string& getTarget(HostState state);
+
+    /**
+     * @brief Get target name of a TransitionRequest
+     *
+     * @param[in] tranReq      -  Transition requested
+     *
+     * @return string - systemd target name of Requested transition
+     */
+    const std::string& getTarget(Transition tranReq);
+
     /** @brief Persistent sdbusplus DBus bus connection. */
     sdbusplus::bus::bus& bus;
 
@@ -278,6 +305,15 @@
 
     // Settings objects of interest
     settings::Objects settings;
+
+    /** @brief Host id. **/
+    const size_t id = 0;
+
+    /** @brief HostState to systemd target mapping table. **/
+    std::map<HostState, std::string> stateTargetTable;
+
+    /** @brief Requested Transition to systemd target mapping table. **/
+    std::map<Transition, std::string> transitionTargetTable;
 };
 
 } // namespace manager