diff options
| -rw-r--r-- | redfish-core/lib/chassis.hpp | 46 |
1 files changed, 45 insertions, 1 deletions
diff --git a/redfish-core/lib/chassis.hpp b/redfish-core/lib/chassis.hpp index d24e641..f78789a 100644 --- a/redfish-core/lib/chassis.hpp +++ b/redfish-core/lib/chassis.hpp @@ -24,6 +24,50 @@ namespace redfish { /** + * @brief Retrieves chassis state properties over dbus + * + * @param[in] aResp - Shared pointer for completing asynchronous calls. + * + * @return None. + */ +void getChassisState(std::shared_ptr<AsyncResp> aResp) +{ + crow::connections::systemBus->async_method_call( + [aResp{std::move(aResp)}]( + const boost::system::error_code ec, + const std::variant<std::string> &chassisState) { + if (ec) + { + BMCWEB_LOG_DEBUG << "DBUS response error " << ec; + messages::internalError(aResp->res); + return; + } + + const std::string *s = std::get_if<std::string>(&chassisState); + BMCWEB_LOG_DEBUG << "Chassis state: " << *s; + if (s != nullptr) + { + // Verify Chassis State + if (*s == "xyz.openbmc_project.State.Chassis.PowerState.On") + { + aResp->res.jsonValue["PowerState"] = "On"; + aResp->res.jsonValue["Status"]["State"] = "Enabled"; + } + else if (*s == + "xyz.openbmc_project.State.Chassis.PowerState.Off") + { + aResp->res.jsonValue["PowerState"] = "Off"; + aResp->res.jsonValue["Status"]["State"] = "StandbyOffline"; + } + } + }, + "xyz.openbmc_project.State.Chassis", + "/xyz/openbmc_project/state/chassis0", + "org.freedesktop.DBus.Properties", "Get", + "xyz.openbmc_project.State.Chassis", "CurrentPowerState"); +} + +/** * DBus types primitives for several generic DBus interfaces * TODO(Pawel) consider move this to separate file into boost::dbus */ @@ -241,7 +285,6 @@ class Chassis : public Node "/redfish/v1/$metadata#Chassis.Chassis"; res.jsonValue["Name"] = "Chassis Collection"; res.jsonValue["ChassisType"] = "RackMount"; - res.jsonValue["PowerState"] = "On"; auto asyncResp = std::make_shared<AsyncResp>(res); crow::connections::systemBus->async_method_call( @@ -330,6 +373,7 @@ class Chassis : public Node {{"@odata.id", "/redfish/v1/Systems/system"}}}; asyncResp->res.jsonValue["Links"]["ManagedBy"] = { {{"@odata.id", "/redfish/v1/Managers/bmc"}}}; + getChassisState(asyncResp); }, connectionName, path, "org.freedesktop.DBus.Properties", "GetAll", |

