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