George Liu | d6a1bae | 2022-06-20 13:47:31 +0800 | [diff] [blame] | 1 | #include "config.h" |
Matt Spinler | fb35a32 | 2018-11-26 14:30:30 -0600 | [diff] [blame] | 2 | |
George Liu | d6a1bae | 2022-06-20 13:47:31 +0800 | [diff] [blame] | 3 | #include "button_handler.hpp" |
Matt Spinler | 69f9351 | 2018-11-26 14:55:58 -0600 | [diff] [blame] | 4 | |
George Liu | 9fb1597 | 2022-06-20 14:54:38 +0800 | [diff] [blame] | 5 | #include <phosphor-logging/lg2.hpp> |
Matt Spinler | 963c65f | 2018-11-26 14:46:41 -0600 | [diff] [blame] | 6 | #include <xyz/openbmc_project/State/Chassis/server.hpp> |
| 7 | #include <xyz/openbmc_project/State/Host/server.hpp> |
Matt Spinler | fb35a32 | 2018-11-26 14:30:30 -0600 | [diff] [blame] | 8 | namespace phosphor |
| 9 | { |
| 10 | namespace button |
| 11 | { |
Matt Spinler | 963c65f | 2018-11-26 14:46:41 -0600 | [diff] [blame] | 12 | |
| 13 | namespace sdbusRule = sdbusplus::bus::match::rules; |
| 14 | using namespace sdbusplus::xyz::openbmc_project::State::server; |
Matt Spinler | 963c65f | 2018-11-26 14:46:41 -0600 | [diff] [blame] | 15 | |
Matt Spinler | 963c65f | 2018-11-26 14:46:41 -0600 | [diff] [blame] | 16 | constexpr auto chassisIface = "xyz.openbmc_project.State.Chassis"; |
| 17 | constexpr auto hostIface = "xyz.openbmc_project.State.Host"; |
| 18 | constexpr auto powerButtonIface = "xyz.openbmc_project.Chassis.Buttons.Power"; |
Matt Spinler | 69f9351 | 2018-11-26 14:55:58 -0600 | [diff] [blame] | 19 | constexpr auto idButtonIface = "xyz.openbmc_project.Chassis.Buttons.ID"; |
Matt Spinler | 06a5bdd | 2018-11-26 14:50:48 -0600 | [diff] [blame] | 20 | constexpr auto resetButtonIface = "xyz.openbmc_project.Chassis.Buttons.Reset"; |
Matt Spinler | 69f9351 | 2018-11-26 14:55:58 -0600 | [diff] [blame] | 21 | constexpr auto ledGroupIface = "xyz.openbmc_project.Led.Group"; |
Naveen Moses | 3bd1cfc | 2022-02-14 18:04:20 +0530 | [diff] [blame] | 22 | constexpr auto ledGroupBasePath = "/xyz/openbmc_project/led/groups/"; |
| 23 | constexpr auto hostSelectorIface = |
| 24 | "xyz.openbmc_project.Chassis.Buttons.HostSelector"; |
| 25 | constexpr auto debugHostSelectorIface = |
Naveen Moses | a6d4e65 | 2022-04-13 19:27:25 +0530 | [diff] [blame] | 26 | "xyz.openbmc_project.Chassis.Buttons.Button"; |
Naveen Moses | 3bd1cfc | 2022-02-14 18:04:20 +0530 | [diff] [blame] | 27 | |
| 28 | constexpr auto propertyIface = "org.freedesktop.DBus.Properties"; |
| 29 | constexpr auto mapperIface = "xyz.openbmc_project.ObjectMapper"; |
Matt Spinler | 963c65f | 2018-11-26 14:46:41 -0600 | [diff] [blame] | 30 | |
| 31 | constexpr auto mapperObjPath = "/xyz/openbmc_project/object_mapper"; |
| 32 | constexpr auto mapperService = "xyz.openbmc_project.ObjectMapper"; |
Naveen Moses | 3bd1cfc | 2022-02-14 18:04:20 +0530 | [diff] [blame] | 33 | constexpr auto BMC_POSITION = 0; |
Matt Spinler | 963c65f | 2018-11-26 14:46:41 -0600 | [diff] [blame] | 34 | |
Patrick Williams | 9a529a6 | 2022-07-22 19:26:54 -0500 | [diff] [blame] | 35 | Handler::Handler(sdbusplus::bus_t& bus) : bus(bus) |
Matt Spinler | fb35a32 | 2018-11-26 14:30:30 -0600 | [diff] [blame] | 36 | { |
Matt Spinler | 963c65f | 2018-11-26 14:46:41 -0600 | [diff] [blame] | 37 | try |
| 38 | { |
| 39 | if (!getService(POWER_DBUS_OBJECT_NAME, powerButtonIface).empty()) |
| 40 | { |
George Liu | 9fb1597 | 2022-06-20 14:54:38 +0800 | [diff] [blame] | 41 | lg2::info("Starting power button handler"); |
Matt Spinler | 963c65f | 2018-11-26 14:46:41 -0600 | [diff] [blame] | 42 | powerButtonReleased = std::make_unique<sdbusplus::bus::match_t>( |
| 43 | bus, |
| 44 | sdbusRule::type::signal() + sdbusRule::member("Released") + |
| 45 | sdbusRule::path(POWER_DBUS_OBJECT_NAME) + |
| 46 | sdbusRule::interface(powerButtonIface), |
Naveen Moses | ab8dac5 | 2022-07-15 19:32:27 +0530 | [diff] [blame] | 47 | std::bind(std::mem_fn(&Handler::powerReleased), this, |
Matt Spinler | 963c65f | 2018-11-26 14:46:41 -0600 | [diff] [blame] | 48 | std::placeholders::_1)); |
Matt Spinler | 963c65f | 2018-11-26 14:46:41 -0600 | [diff] [blame] | 49 | } |
| 50 | } |
Patrick Williams | 9a529a6 | 2022-07-22 19:26:54 -0500 | [diff] [blame] | 51 | catch (const sdbusplus::exception_t& e) |
Matt Spinler | 963c65f | 2018-11-26 14:46:41 -0600 | [diff] [blame] | 52 | { |
| 53 | // The button wasn't implemented |
| 54 | } |
Matt Spinler | 06a5bdd | 2018-11-26 14:50:48 -0600 | [diff] [blame] | 55 | |
| 56 | try |
| 57 | { |
Matt Spinler | 69f9351 | 2018-11-26 14:55:58 -0600 | [diff] [blame] | 58 | if (!getService(ID_DBUS_OBJECT_NAME, idButtonIface).empty()) |
| 59 | { |
George Liu | 9fb1597 | 2022-06-20 14:54:38 +0800 | [diff] [blame] | 60 | lg2::info("Registering ID button handler"); |
Matt Spinler | 69f9351 | 2018-11-26 14:55:58 -0600 | [diff] [blame] | 61 | idButtonReleased = std::make_unique<sdbusplus::bus::match_t>( |
| 62 | bus, |
| 63 | sdbusRule::type::signal() + sdbusRule::member("Released") + |
| 64 | sdbusRule::path(ID_DBUS_OBJECT_NAME) + |
| 65 | sdbusRule::interface(idButtonIface), |
Naveen Moses | ab8dac5 | 2022-07-15 19:32:27 +0530 | [diff] [blame] | 66 | std::bind(std::mem_fn(&Handler::idReleased), this, |
Matt Spinler | 69f9351 | 2018-11-26 14:55:58 -0600 | [diff] [blame] | 67 | std::placeholders::_1)); |
| 68 | } |
| 69 | } |
Patrick Williams | 9a529a6 | 2022-07-22 19:26:54 -0500 | [diff] [blame] | 70 | catch (const sdbusplus::exception_t& e) |
Matt Spinler | 69f9351 | 2018-11-26 14:55:58 -0600 | [diff] [blame] | 71 | { |
| 72 | // The button wasn't implemented |
| 73 | } |
| 74 | |
| 75 | try |
| 76 | { |
Matt Spinler | 06a5bdd | 2018-11-26 14:50:48 -0600 | [diff] [blame] | 77 | if (!getService(RESET_DBUS_OBJECT_NAME, resetButtonIface).empty()) |
| 78 | { |
George Liu | 9fb1597 | 2022-06-20 14:54:38 +0800 | [diff] [blame] | 79 | lg2::info("Registering reset button handler"); |
Matt Spinler | 06a5bdd | 2018-11-26 14:50:48 -0600 | [diff] [blame] | 80 | resetButtonReleased = std::make_unique<sdbusplus::bus::match_t>( |
| 81 | bus, |
| 82 | sdbusRule::type::signal() + sdbusRule::member("Released") + |
| 83 | sdbusRule::path(RESET_DBUS_OBJECT_NAME) + |
| 84 | sdbusRule::interface(resetButtonIface), |
Naveen Moses | ab8dac5 | 2022-07-15 19:32:27 +0530 | [diff] [blame] | 85 | std::bind(std::mem_fn(&Handler::resetReleased), this, |
Matt Spinler | 06a5bdd | 2018-11-26 14:50:48 -0600 | [diff] [blame] | 86 | std::placeholders::_1)); |
| 87 | } |
| 88 | } |
Patrick Williams | 9a529a6 | 2022-07-22 19:26:54 -0500 | [diff] [blame] | 89 | catch (const sdbusplus::exception_t& e) |
Matt Spinler | 06a5bdd | 2018-11-26 14:50:48 -0600 | [diff] [blame] | 90 | { |
| 91 | // The button wasn't implemented |
| 92 | } |
Naveen Moses | a6d4e65 | 2022-04-13 19:27:25 +0530 | [diff] [blame] | 93 | try |
| 94 | { |
| 95 | if (!getService(DBG_HS_DBUS_OBJECT_NAME, debugHostSelectorIface) |
| 96 | .empty()) |
| 97 | { |
| 98 | lg2::info("Registering debug host selector button handler"); |
| 99 | debugHSButtonReleased = std::make_unique<sdbusplus::bus::match_t>( |
| 100 | bus, |
| 101 | sdbusRule::type::signal() + sdbusRule::member("Released") + |
| 102 | sdbusRule::path(DBG_HS_DBUS_OBJECT_NAME) + |
| 103 | sdbusRule::interface(debugHostSelectorIface), |
| 104 | std::bind(std::mem_fn(&Handler::debugHostSelectorReleased), |
| 105 | this, std::placeholders::_1)); |
| 106 | } |
| 107 | } |
Patrick Williams | e3b4e11 | 2022-11-26 09:41:58 -0600 | [diff] [blame] | 108 | catch (const sdbusplus::exception_t& e) |
Naveen Moses | a6d4e65 | 2022-04-13 19:27:25 +0530 | [diff] [blame] | 109 | { |
| 110 | // The button wasn't implemented |
| 111 | } |
Matt Spinler | 963c65f | 2018-11-26 14:46:41 -0600 | [diff] [blame] | 112 | } |
Naveen Moses | 3bd1cfc | 2022-02-14 18:04:20 +0530 | [diff] [blame] | 113 | bool Handler::isMultiHost() |
| 114 | { |
| 115 | // return true in case host selector object is available |
| 116 | return (!getService(HS_DBUS_OBJECT_NAME, hostSelectorIface).empty()); |
| 117 | } |
Matt Spinler | 963c65f | 2018-11-26 14:46:41 -0600 | [diff] [blame] | 118 | std::string Handler::getService(const std::string& path, |
| 119 | const std::string& interface) const |
| 120 | { |
| 121 | auto method = bus.new_method_call(mapperService, mapperObjPath, mapperIface, |
| 122 | "GetObject"); |
| 123 | method.append(path, std::vector{interface}); |
Thang Q. Nguyen | 4250785 | 2022-08-12 09:11:35 +0700 | [diff] [blame] | 124 | try |
| 125 | { |
| 126 | auto result = bus.call(method); |
| 127 | std::map<std::string, std::vector<std::string>> objectData; |
| 128 | result.read(objectData); |
| 129 | return objectData.begin()->first; |
| 130 | } |
Patrick Williams | e3b4e11 | 2022-11-26 09:41:58 -0600 | [diff] [blame] | 131 | catch (const sdbusplus::exception_t& e) |
Thang Q. Nguyen | 4250785 | 2022-08-12 09:11:35 +0700 | [diff] [blame] | 132 | { |
| 133 | return std::string(); |
| 134 | } |
Matt Spinler | 963c65f | 2018-11-26 14:46:41 -0600 | [diff] [blame] | 135 | } |
Naveen Moses | 3bd1cfc | 2022-02-14 18:04:20 +0530 | [diff] [blame] | 136 | size_t Handler::getHostSelectorValue() |
Matt Spinler | 963c65f | 2018-11-26 14:46:41 -0600 | [diff] [blame] | 137 | { |
Naveen Moses | 3bd1cfc | 2022-02-14 18:04:20 +0530 | [diff] [blame] | 138 | auto HSService = getService(HS_DBUS_OBJECT_NAME, hostSelectorIface); |
| 139 | |
| 140 | if (HSService.empty()) |
| 141 | { |
Naveen Moses | a6d4e65 | 2022-04-13 19:27:25 +0530 | [diff] [blame] | 142 | lg2::info("Host selector dbus object not available"); |
Naveen Moses | 3bd1cfc | 2022-02-14 18:04:20 +0530 | [diff] [blame] | 143 | throw std::invalid_argument("Host selector dbus object not available"); |
| 144 | } |
| 145 | |
| 146 | try |
| 147 | { |
| 148 | auto method = bus.new_method_call( |
| 149 | HSService.c_str(), HS_DBUS_OBJECT_NAME, propertyIface, "Get"); |
| 150 | method.append(hostSelectorIface, "Position"); |
| 151 | auto result = bus.call(method); |
| 152 | |
| 153 | std::variant<size_t> HSPositionVariant; |
| 154 | result.read(HSPositionVariant); |
| 155 | |
| 156 | auto position = std::get<size_t>(HSPositionVariant); |
| 157 | return position; |
| 158 | } |
Patrick Williams | 9a529a6 | 2022-07-22 19:26:54 -0500 | [diff] [blame] | 159 | catch (const sdbusplus::exception_t& e) |
Naveen Moses | 3bd1cfc | 2022-02-14 18:04:20 +0530 | [diff] [blame] | 160 | { |
Naveen Moses | a6d4e65 | 2022-04-13 19:27:25 +0530 | [diff] [blame] | 161 | lg2::error("Error reading host selector position: {ERROR}", "ERROR", e); |
Naveen Moses | 3bd1cfc | 2022-02-14 18:04:20 +0530 | [diff] [blame] | 162 | throw; |
| 163 | } |
| 164 | } |
| 165 | bool Handler::poweredOn(size_t hostNumber) const |
| 166 | { |
Potin Lai | c0fee46 | 2022-12-23 14:19:23 +0800 | [diff] [blame] | 167 | auto hostObjectName = HOST_STATE_OBJECT_NAME + std::to_string(hostNumber); |
| 168 | auto service = getService(hostObjectName.c_str(), hostIface); |
| 169 | auto method = bus.new_method_call(service.c_str(), hostObjectName.c_str(), |
| 170 | propertyIface, "Get"); |
| 171 | method.append(hostIface, "CurrentHostState"); |
Matt Spinler | 963c65f | 2018-11-26 14:46:41 -0600 | [diff] [blame] | 172 | auto result = bus.call(method); |
| 173 | |
Patrick Williams | 5ed4cc0 | 2020-05-13 17:52:15 -0500 | [diff] [blame] | 174 | std::variant<std::string> state; |
Matt Spinler | 963c65f | 2018-11-26 14:46:41 -0600 | [diff] [blame] | 175 | result.read(state); |
| 176 | |
Potin Lai | c0fee46 | 2022-12-23 14:19:23 +0800 | [diff] [blame] | 177 | return Host::HostState::Off != |
| 178 | Host::convertHostStateFromString(std::get<std::string>(state)); |
Matt Spinler | 963c65f | 2018-11-26 14:46:41 -0600 | [diff] [blame] | 179 | } |
| 180 | |
DelphineCCChiu | 395c764 | 2023-04-19 10:46:47 +0800 | [diff] [blame^] | 181 | void Handler::handlePowerEvent(PowerEvent powerEventType, |
| 182 | std::chrono::microseconds duration) |
Matt Spinler | 963c65f | 2018-11-26 14:46:41 -0600 | [diff] [blame] | 183 | { |
Naveen Moses | 3bd1cfc | 2022-02-14 18:04:20 +0530 | [diff] [blame] | 184 | std::string objPathName; |
| 185 | std::string dbusIfaceName; |
| 186 | std::string transitionName; |
| 187 | std::variant<Host::Transition, Chassis::Transition> transition; |
DelphineCCChiu | 395c764 | 2023-04-19 10:46:47 +0800 | [diff] [blame^] | 188 | uint64_t durationMs = |
| 189 | std::chrono::duration_cast<std::chrono::milliseconds>(duration).count(); |
Matt Spinler | 963c65f | 2018-11-26 14:46:41 -0600 | [diff] [blame] | 190 | |
Naveen Moses | 3bd1cfc | 2022-02-14 18:04:20 +0530 | [diff] [blame] | 191 | size_t hostNumber = 0; |
| 192 | auto isMultiHostSystem = isMultiHost(); |
| 193 | if (isMultiHostSystem) |
Matt Spinler | 963c65f | 2018-11-26 14:46:41 -0600 | [diff] [blame] | 194 | { |
Naveen Moses | 3bd1cfc | 2022-02-14 18:04:20 +0530 | [diff] [blame] | 195 | hostNumber = getHostSelectorValue(); |
Naveen Moses | a6d4e65 | 2022-04-13 19:27:25 +0530 | [diff] [blame] | 196 | lg2::info("Multi-host system detected : {POSITION}", "POSITION", |
George Liu | 9fb1597 | 2022-06-20 14:54:38 +0800 | [diff] [blame] | 197 | hostNumber); |
Naveen Moses | 3bd1cfc | 2022-02-14 18:04:20 +0530 | [diff] [blame] | 198 | } |
| 199 | |
| 200 | std::string hostNumStr = std::to_string(hostNumber); |
| 201 | |
| 202 | // ignore power and reset button events if BMC is selected. |
| 203 | if (isMultiHostSystem && (hostNumber == BMC_POSITION) && |
DelphineCCChiu | 395c764 | 2023-04-19 10:46:47 +0800 | [diff] [blame^] | 204 | (powerEventType != PowerEvent::powerReleased) && |
| 205 | (durationMs <= LONG_PRESS_TIME_MS)) |
Naveen Moses | 3bd1cfc | 2022-02-14 18:04:20 +0530 | [diff] [blame] | 206 | { |
George Liu | 9fb1597 | 2022-06-20 14:54:38 +0800 | [diff] [blame] | 207 | lg2::info( |
Naveen Moses | a6d4e65 | 2022-04-13 19:27:25 +0530 | [diff] [blame] | 208 | "handlePowerEvent : BMC selected on multi-host system. ignoring power and reset button events..."); |
Naveen Moses | 3bd1cfc | 2022-02-14 18:04:20 +0530 | [diff] [blame] | 209 | return; |
| 210 | } |
| 211 | |
| 212 | switch (powerEventType) |
| 213 | { |
Naveen Moses | ab8dac5 | 2022-07-15 19:32:27 +0530 | [diff] [blame] | 214 | case PowerEvent::powerReleased: |
George Liu | 5b98f4d | 2022-06-20 13:31:14 +0800 | [diff] [blame] | 215 | { |
DelphineCCChiu | 395c764 | 2023-04-19 10:46:47 +0800 | [diff] [blame^] | 216 | if (durationMs <= LONG_PRESS_TIME_MS) |
Naveen Moses | 3bd1cfc | 2022-02-14 18:04:20 +0530 | [diff] [blame] | 217 | { |
DelphineCCChiu | 395c764 | 2023-04-19 10:46:47 +0800 | [diff] [blame^] | 218 | objPathName = HOST_STATE_OBJECT_NAME + hostNumStr; |
| 219 | dbusIfaceName = hostIface; |
| 220 | transitionName = "RequestedHostTransition"; |
| 221 | |
| 222 | transition = Host::Transition::On; |
| 223 | |
| 224 | if (poweredOn(hostNumber)) |
| 225 | { |
| 226 | transition = Host::Transition::Off; |
| 227 | } |
| 228 | lg2::info("handlePowerEvent : Handle power button press "); |
| 229 | |
| 230 | break; |
Naveen Moses | 3bd1cfc | 2022-02-14 18:04:20 +0530 | [diff] [blame] | 231 | } |
DelphineCCChiu | 395c764 | 2023-04-19 10:46:47 +0800 | [diff] [blame^] | 232 | else |
Naveen Moses | 3bd1cfc | 2022-02-14 18:04:20 +0530 | [diff] [blame] | 233 | { |
DelphineCCChiu | 395c764 | 2023-04-19 10:46:47 +0800 | [diff] [blame^] | 234 | dbusIfaceName = chassisIface; |
| 235 | transitionName = "RequestedPowerTransition"; |
| 236 | objPathName = CHASSIS_STATE_OBJECT_NAME + hostNumStr; |
| 237 | transition = Chassis::Transition::Off; |
| 238 | |
| 239 | /* multi host system : |
| 240 | hosts (1 to N) - host shutdown |
| 241 | bmc (0) - sled cycle |
| 242 | single host system : |
| 243 | host(0) - host shutdown |
| 244 | */ |
| 245 | if (isMultiHostSystem && (hostNumber == BMC_POSITION)) |
| 246 | { |
Naveen Moses | 3bd1cfc | 2022-02-14 18:04:20 +0530 | [diff] [blame] | 247 | #if CHASSIS_SYSTEM_RESET_ENABLED |
DelphineCCChiu | 395c764 | 2023-04-19 10:46:47 +0800 | [diff] [blame^] | 248 | objPathName = CHASSISSYSTEM_STATE_OBJECT_NAME + hostNumStr; |
| 249 | transition = Chassis::Transition::PowerCycle; |
Naveen Moses | 3bd1cfc | 2022-02-14 18:04:20 +0530 | [diff] [blame] | 250 | #else |
DelphineCCChiu | 395c764 | 2023-04-19 10:46:47 +0800 | [diff] [blame^] | 251 | return; |
Naveen Moses | 3bd1cfc | 2022-02-14 18:04:20 +0530 | [diff] [blame] | 252 | #endif |
DelphineCCChiu | 395c764 | 2023-04-19 10:46:47 +0800 | [diff] [blame^] | 253 | } |
| 254 | else if (!poweredOn(hostNumber)) |
| 255 | { |
| 256 | lg2::info( |
| 257 | "Power is off so ignoring long power button press"); |
| 258 | return; |
| 259 | } |
| 260 | lg2::info("handlePowerEvent : handle long power button press"); |
| 261 | break; |
Naveen Moses | 3bd1cfc | 2022-02-14 18:04:20 +0530 | [diff] [blame] | 262 | } |
Matt Spinler | 963c65f | 2018-11-26 14:46:41 -0600 | [diff] [blame] | 263 | } |
Naveen Moses | ab8dac5 | 2022-07-15 19:32:27 +0530 | [diff] [blame] | 264 | case PowerEvent::resetReleased: |
George Liu | 5b98f4d | 2022-06-20 13:31:14 +0800 | [diff] [blame] | 265 | { |
Naveen Moses | 3bd1cfc | 2022-02-14 18:04:20 +0530 | [diff] [blame] | 266 | objPathName = HOST_STATE_OBJECT_NAME + hostNumStr; |
| 267 | dbusIfaceName = hostIface; |
| 268 | transitionName = "RequestedHostTransition"; |
Matt Spinler | 963c65f | 2018-11-26 14:46:41 -0600 | [diff] [blame] | 269 | |
Naveen Moses | 3bd1cfc | 2022-02-14 18:04:20 +0530 | [diff] [blame] | 270 | if (!poweredOn(hostNumber)) |
| 271 | { |
George Liu | 9fb1597 | 2022-06-20 14:54:38 +0800 | [diff] [blame] | 272 | lg2::info("Power is off so ignoring reset button press"); |
Naveen Moses | 3bd1cfc | 2022-02-14 18:04:20 +0530 | [diff] [blame] | 273 | return; |
| 274 | } |
Matt Spinler | 963c65f | 2018-11-26 14:46:41 -0600 | [diff] [blame] | 275 | |
George Liu | 9fb1597 | 2022-06-20 14:54:38 +0800 | [diff] [blame] | 276 | lg2::info("Handling reset button press"); |
Naveen Moses | 3bd1cfc | 2022-02-14 18:04:20 +0530 | [diff] [blame] | 277 | transition = Host::Transition::Reboot; |
| 278 | break; |
| 279 | } |
George Liu | 5b98f4d | 2022-06-20 13:31:14 +0800 | [diff] [blame] | 280 | default: |
| 281 | { |
George Liu | 9fb1597 | 2022-06-20 14:54:38 +0800 | [diff] [blame] | 282 | lg2::error("{EVENT} is invalid power event. skipping...", "EVENT", |
| 283 | static_cast<std::underlying_type_t<PowerEvent>>( |
| 284 | powerEventType)); |
Naveen Moses | 3bd1cfc | 2022-02-14 18:04:20 +0530 | [diff] [blame] | 285 | |
| 286 | return; |
| 287 | } |
| 288 | } |
| 289 | auto service = getService(objPathName.c_str(), dbusIfaceName); |
| 290 | auto method = bus.new_method_call(service.c_str(), objPathName.c_str(), |
| 291 | propertyIface, "Set"); |
| 292 | method.append(dbusIfaceName, transitionName, transition); |
| 293 | bus.call(method); |
| 294 | } |
DelphineCCChiu | 395c764 | 2023-04-19 10:46:47 +0800 | [diff] [blame^] | 295 | void Handler::powerReleased(sdbusplus::message_t& msg) |
Naveen Moses | 3bd1cfc | 2022-02-14 18:04:20 +0530 | [diff] [blame] | 296 | { |
| 297 | try |
| 298 | { |
DelphineCCChiu | 395c764 | 2023-04-19 10:46:47 +0800 | [diff] [blame^] | 299 | uint64_t time; |
| 300 | msg.read(time); |
| 301 | |
| 302 | handlePowerEvent(PowerEvent::powerReleased, |
| 303 | std::chrono::microseconds(time)); |
Matt Spinler | 963c65f | 2018-11-26 14:46:41 -0600 | [diff] [blame] | 304 | } |
Patrick Williams | 9a529a6 | 2022-07-22 19:26:54 -0500 | [diff] [blame] | 305 | catch (const sdbusplus::exception_t& e) |
Matt Spinler | 963c65f | 2018-11-26 14:46:41 -0600 | [diff] [blame] | 306 | { |
George Liu | 9fb1597 | 2022-06-20 14:54:38 +0800 | [diff] [blame] | 307 | lg2::error("Failed power state change on a power button press: {ERROR}", |
| 308 | "ERROR", e); |
Matt Spinler | 963c65f | 2018-11-26 14:46:41 -0600 | [diff] [blame] | 309 | } |
| 310 | } |
Matt Spinler | 06a5bdd | 2018-11-26 14:50:48 -0600 | [diff] [blame] | 311 | |
Patrick Williams | 9a529a6 | 2022-07-22 19:26:54 -0500 | [diff] [blame] | 312 | void Handler::resetReleased(sdbusplus::message_t& /* msg */) |
Matt Spinler | 06a5bdd | 2018-11-26 14:50:48 -0600 | [diff] [blame] | 313 | { |
| 314 | try |
| 315 | { |
DelphineCCChiu | 395c764 | 2023-04-19 10:46:47 +0800 | [diff] [blame^] | 316 | // No need to calculate duration, set to 0. |
| 317 | handlePowerEvent(PowerEvent::resetReleased, |
| 318 | std::chrono::microseconds(0)); |
Matt Spinler | 06a5bdd | 2018-11-26 14:50:48 -0600 | [diff] [blame] | 319 | } |
Patrick Williams | 9a529a6 | 2022-07-22 19:26:54 -0500 | [diff] [blame] | 320 | catch (const sdbusplus::exception_t& e) |
Matt Spinler | 06a5bdd | 2018-11-26 14:50:48 -0600 | [diff] [blame] | 321 | { |
George Liu | 9fb1597 | 2022-06-20 14:54:38 +0800 | [diff] [blame] | 322 | lg2::error("Failed power state change on a reset button press: {ERROR}", |
| 323 | "ERROR", e); |
Matt Spinler | 06a5bdd | 2018-11-26 14:50:48 -0600 | [diff] [blame] | 324 | } |
| 325 | } |
Matt Spinler | 69f9351 | 2018-11-26 14:55:58 -0600 | [diff] [blame] | 326 | |
Patrick Williams | 9a529a6 | 2022-07-22 19:26:54 -0500 | [diff] [blame] | 327 | void Handler::idReleased(sdbusplus::message_t& /* msg */) |
Matt Spinler | 69f9351 | 2018-11-26 14:55:58 -0600 | [diff] [blame] | 328 | { |
| 329 | std::string groupPath{ledGroupBasePath}; |
| 330 | groupPath += ID_LED_GROUP; |
| 331 | |
| 332 | auto service = getService(groupPath, ledGroupIface); |
| 333 | |
| 334 | if (service.empty()) |
| 335 | { |
George Liu | 9fb1597 | 2022-06-20 14:54:38 +0800 | [diff] [blame] | 336 | lg2::info("No found {GROUP} during ID button press:", "GROUP", |
| 337 | groupPath); |
Matt Spinler | 69f9351 | 2018-11-26 14:55:58 -0600 | [diff] [blame] | 338 | return; |
| 339 | } |
| 340 | |
| 341 | try |
| 342 | { |
| 343 | auto method = bus.new_method_call(service.c_str(), groupPath.c_str(), |
| 344 | propertyIface, "Get"); |
| 345 | method.append(ledGroupIface, "Asserted"); |
| 346 | auto result = bus.call(method); |
| 347 | |
Patrick Williams | 5ed4cc0 | 2020-05-13 17:52:15 -0500 | [diff] [blame] | 348 | std::variant<bool> state; |
Matt Spinler | 69f9351 | 2018-11-26 14:55:58 -0600 | [diff] [blame] | 349 | result.read(state); |
| 350 | |
Patrick Williams | 51f5e8b | 2020-05-13 11:33:44 -0500 | [diff] [blame] | 351 | state = !std::get<bool>(state); |
Matt Spinler | 69f9351 | 2018-11-26 14:55:58 -0600 | [diff] [blame] | 352 | |
George Liu | 9fb1597 | 2022-06-20 14:54:38 +0800 | [diff] [blame] | 353 | lg2::info( |
| 354 | "Changing ID LED group state on ID LED press, GROUP = {GROUP}, STATE = {STATE}", |
| 355 | "GROUP", groupPath, "STATE", std::get<bool>(state)); |
Matt Spinler | 69f9351 | 2018-11-26 14:55:58 -0600 | [diff] [blame] | 356 | |
| 357 | method = bus.new_method_call(service.c_str(), groupPath.c_str(), |
| 358 | propertyIface, "Set"); |
| 359 | |
| 360 | method.append(ledGroupIface, "Asserted", state); |
| 361 | result = bus.call(method); |
| 362 | } |
Patrick Williams | 9a529a6 | 2022-07-22 19:26:54 -0500 | [diff] [blame] | 363 | catch (const sdbusplus::exception_t& e) |
Matt Spinler | 69f9351 | 2018-11-26 14:55:58 -0600 | [diff] [blame] | 364 | { |
George Liu | 9fb1597 | 2022-06-20 14:54:38 +0800 | [diff] [blame] | 365 | lg2::error("Error toggling ID LED group on ID button press: {ERROR}", |
| 366 | "ERROR", e); |
Matt Spinler | 69f9351 | 2018-11-26 14:55:58 -0600 | [diff] [blame] | 367 | } |
| 368 | } |
Naveen Moses | a6d4e65 | 2022-04-13 19:27:25 +0530 | [diff] [blame] | 369 | |
| 370 | void Handler::increaseHostSelectorPosition() |
| 371 | { |
| 372 | try |
| 373 | { |
| 374 | auto HSService = getService(HS_DBUS_OBJECT_NAME, hostSelectorIface); |
| 375 | |
| 376 | if (HSService.empty()) |
| 377 | { |
| 378 | lg2::error("Host selector service not available"); |
| 379 | return; |
| 380 | } |
| 381 | |
| 382 | auto method = |
| 383 | bus.new_method_call(HSService.c_str(), HS_DBUS_OBJECT_NAME, |
| 384 | phosphor::button::propertyIface, "GetAll"); |
| 385 | method.append(phosphor::button::hostSelectorIface); |
| 386 | auto result = bus.call(method); |
| 387 | std::unordered_map<std::string, std::variant<size_t>> properties; |
| 388 | result.read(properties); |
| 389 | |
| 390 | auto maxPosition = std::get<size_t>(properties.at("MaxPosition")); |
| 391 | auto position = std::get<size_t>(properties.at("Position")); |
| 392 | |
| 393 | std::variant<size_t> HSPositionVariant = |
| 394 | (position < maxPosition) ? (position + 1) : 0; |
| 395 | |
| 396 | method = bus.new_method_call(HSService.c_str(), HS_DBUS_OBJECT_NAME, |
| 397 | phosphor::button::propertyIface, "Set"); |
| 398 | method.append(phosphor::button::hostSelectorIface, "Position"); |
| 399 | |
| 400 | method.append(HSPositionVariant); |
| 401 | result = bus.call(method); |
| 402 | } |
Patrick Williams | e3b4e11 | 2022-11-26 09:41:58 -0600 | [diff] [blame] | 403 | catch (const sdbusplus::exception_t& e) |
Naveen Moses | a6d4e65 | 2022-04-13 19:27:25 +0530 | [diff] [blame] | 404 | { |
| 405 | lg2::error("Error modifying host selector position : {ERROR}", "ERROR", |
| 406 | e); |
| 407 | } |
| 408 | } |
| 409 | |
Patrick Williams | e3b4e11 | 2022-11-26 09:41:58 -0600 | [diff] [blame] | 410 | void Handler::debugHostSelectorReleased(sdbusplus::message_t& /* msg */) |
Naveen Moses | a6d4e65 | 2022-04-13 19:27:25 +0530 | [diff] [blame] | 411 | { |
| 412 | try |
| 413 | { |
| 414 | increaseHostSelectorPosition(); |
| 415 | } |
Patrick Williams | e3b4e11 | 2022-11-26 09:41:58 -0600 | [diff] [blame] | 416 | catch (const sdbusplus::exception_t& e) |
Naveen Moses | a6d4e65 | 2022-04-13 19:27:25 +0530 | [diff] [blame] | 417 | { |
| 418 | lg2::error( |
| 419 | "Failed power process debug host selector button press : {ERROR}", |
| 420 | "ERROR", e); |
| 421 | } |
| 422 | } |
| 423 | |
Matt Spinler | fb35a32 | 2018-11-26 14:30:30 -0600 | [diff] [blame] | 424 | } // namespace button |
| 425 | } // namespace phosphor |