From 18b70d11dadd487dbeceacd9f955be6c42da2cbb Mon Sep 17 00:00:00 2001 From: Deepak Kodihalli Date: Fri, 21 Jul 2017 13:36:33 -0500 Subject: power_policy: switch to new settings API Change-Id: I5a54c32fe13f7f0314f0d6a902193b16ca4556fd Signed-off-by: Deepak Kodihalli --- chassishandler.cpp | 80 ++++++++++++++++++++++++++---------------------------- 1 file changed, 39 insertions(+), 41 deletions(-) (limited to 'chassishandler.cpp') diff --git a/chassishandler.cpp b/chassishandler.cpp index 6c8b8e0..1a69cdb 100644 --- a/chassishandler.cpp +++ b/chassishandler.cpp @@ -29,6 +29,7 @@ #include #include #include +#include #include "config.h" @@ -120,13 +121,15 @@ namespace internal constexpr auto bootModeIntf = "xyz.openbmc_project.Control.Boot.Mode"; constexpr auto bootSourceIntf = "xyz.openbmc_project.Control.Boot.Source"; +constexpr auto powerRestoreIntf = + "xyz.openbmc_project.Control.Power.RestorePolicy"; sdbusplus::bus::bus dbus(ipmid_get_sd_bus_connection()); namespace cache { settings::Objects objects(dbus, - {bootModeIntf, bootSourceIntf}); + {bootModeIntf, bootSourceIntf, powerRestoreIntf}); } // namespace cache } // namespace internal @@ -858,33 +861,21 @@ int initiate_state_transition(State::Host::Transition transition) return rc; } -struct hostPowerPolicyTypeMap_t +namespace power_policy { - uint8_t policyNum; - char policyName[19]; -}; - -hostPowerPolicyTypeMap_t g_hostPowerPolicyTypeMap_t[] = { - {0x00, "LEAVE_OFF"}, - {0x01, "RESTORE_LAST_STATE"}, - {0x02, "ALWAYS_POWER_ON"}, - {0x03, "UNKNOWN"} -}; +using namespace sdbusplus::xyz::openbmc_project::Control::Power::server; +using IpmiValue = uint8_t; +using DbusValue = RestorePolicy::Policy; -uint8_t get_host_power_policy(char *p) +std::map dbusToIpmi = { + {RestorePolicy::Policy::AlwaysOff, 0x00}, + {RestorePolicy::Policy::Restore, 0x01}, + {RestorePolicy::Policy::AlwaysOn, 0x02} +}; - hostPowerPolicyTypeMap_t *s = g_hostPowerPolicyTypeMap_t; - - while (s->policyNum != 0x03) { - if (!strcmp(s->policyName,p)) - break; - s++; - } - - return s->policyNum; -} +} // namespace power_policy //---------------------------------------------------------------------- // Get Chassis Status commands @@ -906,11 +897,32 @@ ipmi_ret_t ipmi_get_chassis_status(ipmi_netfn_t netfn, ipmi_cmd_t cmd, ipmi_ret_t rc = IPMI_CC_OK; ipmi_get_chassis_status_t chassis_status{}; - char *p = NULL; uint8_t s = 0; - // Get the system bus where most system services are provided. - bus = ipmid_get_sd_bus_connection(); + using namespace chassis::internal; + using namespace chassis::internal::cache; + using namespace power_policy; + + const auto& powerRestoreSetting = objects.map.at(powerRestoreIntf); + auto method = + dbus.new_method_call( + objects.service(powerRestoreSetting, powerRestoreIntf).c_str(), + powerRestoreSetting.c_str(), + PROP_INTF, + "Get"); + method.append(powerRestoreIntf, "PowerRestorePolicy"); + auto resp = dbus.call(method); + if (resp.is_method_error()) + { + log("Error in PowerRestorePolicy Get"); + report(); + *data_len = 0; + return IPMI_CC_UNSPECIFIED_ERROR; + } + sdbusplus::message::variant result; + resp.read(result); + auto powerRestore = + RestorePolicy::convertPolicyFromString(result.get()); *data_len = 4; @@ -939,21 +951,7 @@ ipmi_ret_t ipmi_get_chassis_status(ipmi_netfn_t netfn, ipmi_cmd_t cmd, printf("pgood is 0x%02x\n", pgood); - // Get Power Policy - r = dbus_get_property("power_policy",&p); - - if (r < 0) { - fprintf(stderr, "Dbus get property(power_policy) failed for get_sys_boot_options.\n"); - rc = IPMI_CC_UNSPECIFIED_ERROR; - } else { - s = get_host_power_policy(p); - } - - if (p) - { - free(p); - p = NULL; - } + s = dbusToIpmi.at(powerRestore); // Current Power State // [7] reserved -- cgit v1.2.1