chassis-state-manager: Add multi-chassis support

Add multi-chassis management support, each chassis bus separates by
giving a unique chassis id.

Current code only support single chassis, and alway assume bus name is
"xyz.openbmc_project.State.Chassis".

This patch allow user to launch chassis-state-manager with a chassis id,
and chassis id is added into service bus name for identification.

Because there are many places hardcode with bus name
"xyz.openbmc_project.State.Chassis", if chassis id is 0,
chassis-state-manager will request both
"xyz.openbmc_project.State.Chassis" and
"xyz.openbmc_project.State.Chassis0" bus name to meet backwards
compatibility.

Tested on Bletchley:
root@bletchley:~# busctl tree xyz.openbmc_project.State.Chassis
`-/xyz
  `-/xyz/openbmc_project
    `-/xyz/openbmc_project/state
      `-/xyz/openbmc_project/state/chassis0
root@bletchley:~# busctl tree xyz.openbmc_project.State.Chassis0
`-/xyz
  `-/xyz/openbmc_project
    `-/xyz/openbmc_project/state
      `-/xyz/openbmc_project/state/chassis0
root@bletchley:~# busctl tree xyz.openbmc_project.State.Chassis1
`-/xyz
  `-/xyz/openbmc_project
    `-/xyz/openbmc_project/state
      `-/xyz/openbmc_project/state/chassis1
......

patch dependencies:
https://gerrit.openbmc-project.xyz/c/openbmc/phosphor-state-manager/+/51465

Signed-off-by: Potin Lai <potin.lai@quantatw.com>
Change-Id: I2ce3e9ab2c95a2688143f4e3775da164a5c33c19
diff --git a/host_check.cpp b/host_check.cpp
index a4f8e0d..c3bf068 100644
--- a/host_check.cpp
+++ b/host_check.cpp
@@ -39,7 +39,7 @@
 constexpr auto PROPERTY_INTERFACE = "org.freedesktop.DBus.Properties";
 
 constexpr auto CHASSIS_STATE_SVC = "xyz.openbmc_project.State.Chassis";
-constexpr auto CHASSIS_STATE_PATH = "/xyz/openbmc_project/state/chassis0";
+constexpr auto CHASSIS_STATE_PATH = "/xyz/openbmc_project/state/chassis";
 constexpr auto CHASSIS_STATE_INTF = "xyz.openbmc_project.State.Chassis";
 constexpr auto CHASSIS_STATE_POWER_PROP = "CurrentPowerState";
 
@@ -124,11 +124,20 @@
 }
 
 // Helper function to check if chassis power is on
-bool isChassiPowerOn(sdbusplus::bus::bus& bus)
+bool isChassiPowerOn(sdbusplus::bus::bus& bus, size_t id)
 {
+    auto svcname = std::string{CHASSIS_STATE_SVC};
+    auto objpath = std::string{CHASSIS_STATE_PATH};
+
+    if (id != 0)
+    {
+        svcname += std::to_string(id);
+        objpath += std::to_string(id);
+    }
+
     try
     {
-        auto method = bus.new_method_call(CHASSIS_STATE_SVC, CHASSIS_STATE_PATH,
+        auto method = bus.new_method_call(svcname.c_str(), objpath.c_str(),
                                           PROPERTY_INTERFACE, "Get");
         method.append(CHASSIS_STATE_INTF, CHASSIS_STATE_POWER_PROP);
 
@@ -147,21 +156,20 @@
     {
         error("Error reading Chassis Power State, error: {ERROR}, "
               "service: {SERVICE} path: {PATH}",
-              "ERROR", e, "SERVICE", CHASSIS_STATE_SVC, "PATH",
-              CHASSIS_STATE_PATH);
+              "ERROR", e, "SERVICE", svcname.c_str(), "PATH", objpath.c_str());
         throw;
     }
     return false;
 }
 
-bool isHostRunning()
+bool isHostRunning(size_t id)
 {
     info("Check if host is running");
 
     auto bus = sdbusplus::bus::new_default();
 
     // No need to check if chassis power is not on
-    if (!isChassiPowerOn(bus))
+    if (!isChassiPowerOn(bus, id))
     {
         info("Chassis power not on, exit");
         return false;