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 = |
| 26 | "xyz.openbmc_project.Chassis.Buttons.DebugHostSelector"; |
| 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 | |
Matt Spinler | fb35a32 | 2018-11-26 14:30:30 -0600 | [diff] [blame] | 35 | Handler::Handler(sdbusplus::bus::bus& bus) : bus(bus) |
| 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), |
| 47 | std::bind(std::mem_fn(&Handler::powerPressed), this, |
| 48 | std::placeholders::_1)); |
| 49 | |
| 50 | powerButtonLongPressReleased = |
| 51 | std::make_unique<sdbusplus::bus::match_t>( |
| 52 | bus, |
| 53 | sdbusRule::type::signal() + |
| 54 | sdbusRule::member("PressedLong") + |
| 55 | sdbusRule::path(POWER_DBUS_OBJECT_NAME) + |
| 56 | sdbusRule::interface(powerButtonIface), |
| 57 | std::bind(std::mem_fn(&Handler::longPowerPressed), this, |
| 58 | std::placeholders::_1)); |
| 59 | } |
| 60 | } |
Patrick Williams | 6d724ce | 2021-10-06 12:40:26 -0500 | [diff] [blame] | 61 | catch (const sdbusplus::exception::exception& e) |
Matt Spinler | 963c65f | 2018-11-26 14:46:41 -0600 | [diff] [blame] | 62 | { |
| 63 | // The button wasn't implemented |
| 64 | } |
Matt Spinler | 06a5bdd | 2018-11-26 14:50:48 -0600 | [diff] [blame] | 65 | |
| 66 | try |
| 67 | { |
Matt Spinler | 69f9351 | 2018-11-26 14:55:58 -0600 | [diff] [blame] | 68 | if (!getService(ID_DBUS_OBJECT_NAME, idButtonIface).empty()) |
| 69 | { |
George Liu | 9fb1597 | 2022-06-20 14:54:38 +0800 | [diff] [blame^] | 70 | lg2::info("Registering ID button handler"); |
Matt Spinler | 69f9351 | 2018-11-26 14:55:58 -0600 | [diff] [blame] | 71 | idButtonReleased = std::make_unique<sdbusplus::bus::match_t>( |
| 72 | bus, |
| 73 | sdbusRule::type::signal() + sdbusRule::member("Released") + |
| 74 | sdbusRule::path(ID_DBUS_OBJECT_NAME) + |
| 75 | sdbusRule::interface(idButtonIface), |
| 76 | std::bind(std::mem_fn(&Handler::idPressed), this, |
| 77 | std::placeholders::_1)); |
| 78 | } |
| 79 | } |
Patrick Williams | 6d724ce | 2021-10-06 12:40:26 -0500 | [diff] [blame] | 80 | catch (const sdbusplus::exception::exception& e) |
Matt Spinler | 69f9351 | 2018-11-26 14:55:58 -0600 | [diff] [blame] | 81 | { |
| 82 | // The button wasn't implemented |
| 83 | } |
| 84 | |
| 85 | try |
| 86 | { |
Matt Spinler | 06a5bdd | 2018-11-26 14:50:48 -0600 | [diff] [blame] | 87 | if (!getService(RESET_DBUS_OBJECT_NAME, resetButtonIface).empty()) |
| 88 | { |
George Liu | 9fb1597 | 2022-06-20 14:54:38 +0800 | [diff] [blame^] | 89 | lg2::info("Registering reset button handler"); |
Matt Spinler | 06a5bdd | 2018-11-26 14:50:48 -0600 | [diff] [blame] | 90 | resetButtonReleased = std::make_unique<sdbusplus::bus::match_t>( |
| 91 | bus, |
| 92 | sdbusRule::type::signal() + sdbusRule::member("Released") + |
| 93 | sdbusRule::path(RESET_DBUS_OBJECT_NAME) + |
| 94 | sdbusRule::interface(resetButtonIface), |
| 95 | std::bind(std::mem_fn(&Handler::resetPressed), this, |
| 96 | std::placeholders::_1)); |
| 97 | } |
| 98 | } |
Patrick Williams | 6d724ce | 2021-10-06 12:40:26 -0500 | [diff] [blame] | 99 | catch (const sdbusplus::exception::exception& e) |
Matt Spinler | 06a5bdd | 2018-11-26 14:50:48 -0600 | [diff] [blame] | 100 | { |
| 101 | // The button wasn't implemented |
| 102 | } |
Matt Spinler | 963c65f | 2018-11-26 14:46:41 -0600 | [diff] [blame] | 103 | } |
Naveen Moses | 3bd1cfc | 2022-02-14 18:04:20 +0530 | [diff] [blame] | 104 | bool Handler::isMultiHost() |
| 105 | { |
| 106 | // return true in case host selector object is available |
| 107 | return (!getService(HS_DBUS_OBJECT_NAME, hostSelectorIface).empty()); |
| 108 | } |
Matt Spinler | 963c65f | 2018-11-26 14:46:41 -0600 | [diff] [blame] | 109 | std::string Handler::getService(const std::string& path, |
| 110 | const std::string& interface) const |
| 111 | { |
| 112 | auto method = bus.new_method_call(mapperService, mapperObjPath, mapperIface, |
| 113 | "GetObject"); |
| 114 | method.append(path, std::vector{interface}); |
| 115 | auto result = bus.call(method); |
| 116 | |
| 117 | std::map<std::string, std::vector<std::string>> objectData; |
| 118 | result.read(objectData); |
| 119 | |
| 120 | return objectData.begin()->first; |
| 121 | } |
Naveen Moses | 3bd1cfc | 2022-02-14 18:04:20 +0530 | [diff] [blame] | 122 | size_t Handler::getHostSelectorValue() |
Matt Spinler | 963c65f | 2018-11-26 14:46:41 -0600 | [diff] [blame] | 123 | { |
Naveen Moses | 3bd1cfc | 2022-02-14 18:04:20 +0530 | [diff] [blame] | 124 | auto HSService = getService(HS_DBUS_OBJECT_NAME, hostSelectorIface); |
| 125 | |
| 126 | if (HSService.empty()) |
| 127 | { |
George Liu | 9fb1597 | 2022-06-20 14:54:38 +0800 | [diff] [blame^] | 128 | lg2::info("Host Selector dbus object not available"); |
Naveen Moses | 3bd1cfc | 2022-02-14 18:04:20 +0530 | [diff] [blame] | 129 | throw std::invalid_argument("Host selector dbus object not available"); |
| 130 | } |
| 131 | |
| 132 | try |
| 133 | { |
| 134 | auto method = bus.new_method_call( |
| 135 | HSService.c_str(), HS_DBUS_OBJECT_NAME, propertyIface, "Get"); |
| 136 | method.append(hostSelectorIface, "Position"); |
| 137 | auto result = bus.call(method); |
| 138 | |
| 139 | std::variant<size_t> HSPositionVariant; |
| 140 | result.read(HSPositionVariant); |
| 141 | |
| 142 | auto position = std::get<size_t>(HSPositionVariant); |
| 143 | return position; |
| 144 | } |
| 145 | catch (const sdbusplus::exception::exception& e) |
| 146 | { |
George Liu | 9fb1597 | 2022-06-20 14:54:38 +0800 | [diff] [blame^] | 147 | lg2::error("Error reading Host selector Position: {ERROR}", "ERROR", e); |
Naveen Moses | 3bd1cfc | 2022-02-14 18:04:20 +0530 | [diff] [blame] | 148 | throw; |
| 149 | } |
| 150 | } |
| 151 | bool Handler::poweredOn(size_t hostNumber) const |
| 152 | { |
| 153 | auto chassisObjectName = |
| 154 | CHASSIS_STATE_OBJECT_NAME + std::to_string(hostNumber); |
| 155 | auto service = getService(chassisObjectName.c_str(), chassisIface); |
Matt Spinler | 963c65f | 2018-11-26 14:46:41 -0600 | [diff] [blame] | 156 | auto method = bus.new_method_call( |
Naveen Moses | 3bd1cfc | 2022-02-14 18:04:20 +0530 | [diff] [blame] | 157 | service.c_str(), chassisObjectName.c_str(), propertyIface, "Get"); |
Matt Spinler | 963c65f | 2018-11-26 14:46:41 -0600 | [diff] [blame] | 158 | method.append(chassisIface, "CurrentPowerState"); |
| 159 | auto result = bus.call(method); |
| 160 | |
Patrick Williams | 5ed4cc0 | 2020-05-13 17:52:15 -0500 | [diff] [blame] | 161 | std::variant<std::string> state; |
Matt Spinler | 963c65f | 2018-11-26 14:46:41 -0600 | [diff] [blame] | 162 | result.read(state); |
| 163 | |
| 164 | return Chassis::PowerState::On == |
Patrick Williams | 51f5e8b | 2020-05-13 11:33:44 -0500 | [diff] [blame] | 165 | Chassis::convertPowerStateFromString(std::get<std::string>(state)); |
Matt Spinler | 963c65f | 2018-11-26 14:46:41 -0600 | [diff] [blame] | 166 | } |
| 167 | |
Naveen Moses | 3bd1cfc | 2022-02-14 18:04:20 +0530 | [diff] [blame] | 168 | void Handler::handlePowerEvent(PowerEvent powerEventType) |
Matt Spinler | 963c65f | 2018-11-26 14:46:41 -0600 | [diff] [blame] | 169 | { |
Naveen Moses | 3bd1cfc | 2022-02-14 18:04:20 +0530 | [diff] [blame] | 170 | std::string objPathName; |
| 171 | std::string dbusIfaceName; |
| 172 | std::string transitionName; |
| 173 | std::variant<Host::Transition, Chassis::Transition> transition; |
Matt Spinler | 963c65f | 2018-11-26 14:46:41 -0600 | [diff] [blame] | 174 | |
Naveen Moses | 3bd1cfc | 2022-02-14 18:04:20 +0530 | [diff] [blame] | 175 | size_t hostNumber = 0; |
| 176 | auto isMultiHostSystem = isMultiHost(); |
| 177 | if (isMultiHostSystem) |
Matt Spinler | 963c65f | 2018-11-26 14:46:41 -0600 | [diff] [blame] | 178 | { |
Naveen Moses | 3bd1cfc | 2022-02-14 18:04:20 +0530 | [diff] [blame] | 179 | hostNumber = getHostSelectorValue(); |
George Liu | 9fb1597 | 2022-06-20 14:54:38 +0800 | [diff] [blame^] | 180 | lg2::info("Multi host system detected : {POSITION}", "POSITION", |
| 181 | hostNumber); |
Naveen Moses | 3bd1cfc | 2022-02-14 18:04:20 +0530 | [diff] [blame] | 182 | } |
| 183 | |
| 184 | std::string hostNumStr = std::to_string(hostNumber); |
| 185 | |
| 186 | // ignore power and reset button events if BMC is selected. |
| 187 | if (isMultiHostSystem && (hostNumber == BMC_POSITION) && |
| 188 | (powerEventType != PowerEvent::longPowerPressed)) |
| 189 | { |
George Liu | 9fb1597 | 2022-06-20 14:54:38 +0800 | [diff] [blame^] | 190 | lg2::info( |
| 191 | "handlePowerEvent : BMC selected on multihost system. ignoring power and reset button events..."); |
Naveen Moses | 3bd1cfc | 2022-02-14 18:04:20 +0530 | [diff] [blame] | 192 | return; |
| 193 | } |
| 194 | |
| 195 | switch (powerEventType) |
| 196 | { |
George Liu | 5b98f4d | 2022-06-20 13:31:14 +0800 | [diff] [blame] | 197 | case PowerEvent::powerPressed: |
| 198 | { |
Naveen Moses | 3bd1cfc | 2022-02-14 18:04:20 +0530 | [diff] [blame] | 199 | objPathName = HOST_STATE_OBJECT_NAME + hostNumStr; |
| 200 | dbusIfaceName = hostIface; |
| 201 | transitionName = "RequestedHostTransition"; |
| 202 | |
| 203 | transition = Host::Transition::On; |
| 204 | |
| 205 | if (poweredOn(hostNumber)) |
| 206 | { |
| 207 | transition = Host::Transition::Off; |
| 208 | } |
George Liu | 9fb1597 | 2022-06-20 14:54:38 +0800 | [diff] [blame^] | 209 | lg2::info("handlePowerEvent : handle power button press "); |
Naveen Moses | 3bd1cfc | 2022-02-14 18:04:20 +0530 | [diff] [blame] | 210 | |
| 211 | break; |
| 212 | } |
George Liu | 5b98f4d | 2022-06-20 13:31:14 +0800 | [diff] [blame] | 213 | case PowerEvent::longPowerPressed: |
| 214 | { |
Naveen Moses | 3bd1cfc | 2022-02-14 18:04:20 +0530 | [diff] [blame] | 215 | dbusIfaceName = chassisIface; |
| 216 | transitionName = "RequestedPowerTransition"; |
| 217 | objPathName = CHASSIS_STATE_OBJECT_NAME + hostNumStr; |
| 218 | transition = Chassis::Transition::Off; |
| 219 | |
| 220 | /* multi host system : |
| 221 | hosts (1 to N) - host shutdown |
| 222 | bmc (0) - sled cycle |
| 223 | single host system : |
| 224 | host(0) - host shutdown |
| 225 | */ |
| 226 | if (isMultiHostSystem && (hostNumber == BMC_POSITION)) |
| 227 | { |
| 228 | #if CHASSIS_SYSTEM_RESET_ENABLED |
| 229 | objPathName = CHASSISSYSTEM_STATE_OBJECT_NAME + hostNumStr; |
| 230 | transition = Chassis::Transition::PowerCycle; |
| 231 | #else |
| 232 | return; |
| 233 | #endif |
| 234 | } |
| 235 | else if (!poweredOn(hostNumber)) |
| 236 | { |
George Liu | 9fb1597 | 2022-06-20 14:54:38 +0800 | [diff] [blame^] | 237 | lg2::info("Power is off so ignoring long power button press"); |
Naveen Moses | 3bd1cfc | 2022-02-14 18:04:20 +0530 | [diff] [blame] | 238 | return; |
| 239 | } |
George Liu | 9fb1597 | 2022-06-20 14:54:38 +0800 | [diff] [blame^] | 240 | lg2::info("handlePowerEvent : handle long power button press"); |
Naveen Moses | 3bd1cfc | 2022-02-14 18:04:20 +0530 | [diff] [blame] | 241 | |
| 242 | break; |
Matt Spinler | 963c65f | 2018-11-26 14:46:41 -0600 | [diff] [blame] | 243 | } |
| 244 | |
George Liu | 5b98f4d | 2022-06-20 13:31:14 +0800 | [diff] [blame] | 245 | case PowerEvent::resetPressed: |
| 246 | { |
Naveen Moses | 3bd1cfc | 2022-02-14 18:04:20 +0530 | [diff] [blame] | 247 | objPathName = HOST_STATE_OBJECT_NAME + hostNumStr; |
| 248 | dbusIfaceName = hostIface; |
| 249 | transitionName = "RequestedHostTransition"; |
Matt Spinler | 963c65f | 2018-11-26 14:46:41 -0600 | [diff] [blame] | 250 | |
Naveen Moses | 3bd1cfc | 2022-02-14 18:04:20 +0530 | [diff] [blame] | 251 | if (!poweredOn(hostNumber)) |
| 252 | { |
George Liu | 9fb1597 | 2022-06-20 14:54:38 +0800 | [diff] [blame^] | 253 | lg2::info("Power is off so ignoring reset button press"); |
Naveen Moses | 3bd1cfc | 2022-02-14 18:04:20 +0530 | [diff] [blame] | 254 | return; |
| 255 | } |
Matt Spinler | 963c65f | 2018-11-26 14:46:41 -0600 | [diff] [blame] | 256 | |
George Liu | 9fb1597 | 2022-06-20 14:54:38 +0800 | [diff] [blame^] | 257 | lg2::info("Handling reset button press"); |
Naveen Moses | 3bd1cfc | 2022-02-14 18:04:20 +0530 | [diff] [blame] | 258 | transition = Host::Transition::Reboot; |
| 259 | break; |
| 260 | } |
George Liu | 5b98f4d | 2022-06-20 13:31:14 +0800 | [diff] [blame] | 261 | default: |
| 262 | { |
George Liu | 9fb1597 | 2022-06-20 14:54:38 +0800 | [diff] [blame^] | 263 | lg2::error("{EVENT} is invalid power event. skipping...", "EVENT", |
| 264 | static_cast<std::underlying_type_t<PowerEvent>>( |
| 265 | powerEventType)); |
Naveen Moses | 3bd1cfc | 2022-02-14 18:04:20 +0530 | [diff] [blame] | 266 | |
| 267 | return; |
| 268 | } |
| 269 | } |
| 270 | auto service = getService(objPathName.c_str(), dbusIfaceName); |
| 271 | auto method = bus.new_method_call(service.c_str(), objPathName.c_str(), |
| 272 | propertyIface, "Set"); |
| 273 | method.append(dbusIfaceName, transitionName, transition); |
| 274 | bus.call(method); |
| 275 | } |
George Liu | 94afa4b | 2022-06-20 13:36:43 +0800 | [diff] [blame] | 276 | void Handler::powerPressed(sdbusplus::message::message& /* msg */) |
Naveen Moses | 3bd1cfc | 2022-02-14 18:04:20 +0530 | [diff] [blame] | 277 | { |
| 278 | try |
| 279 | { |
| 280 | handlePowerEvent(PowerEvent::powerPressed); |
Matt Spinler | 963c65f | 2018-11-26 14:46:41 -0600 | [diff] [blame] | 281 | } |
Patrick Williams | 6d724ce | 2021-10-06 12:40:26 -0500 | [diff] [blame] | 282 | catch (const sdbusplus::exception::exception& e) |
Matt Spinler | 963c65f | 2018-11-26 14:46:41 -0600 | [diff] [blame] | 283 | { |
George Liu | 9fb1597 | 2022-06-20 14:54:38 +0800 | [diff] [blame^] | 284 | lg2::error("Failed power state change on a power button press: {ERROR}", |
| 285 | "ERROR", e); |
Matt Spinler | 963c65f | 2018-11-26 14:46:41 -0600 | [diff] [blame] | 286 | } |
| 287 | } |
George Liu | 94afa4b | 2022-06-20 13:36:43 +0800 | [diff] [blame] | 288 | void Handler::longPowerPressed(sdbusplus::message::message& /* msg */) |
Matt Spinler | 963c65f | 2018-11-26 14:46:41 -0600 | [diff] [blame] | 289 | { |
| 290 | try |
| 291 | { |
Naveen Moses | 3bd1cfc | 2022-02-14 18:04:20 +0530 | [diff] [blame] | 292 | handlePowerEvent(PowerEvent::longPowerPressed); |
Matt Spinler | 963c65f | 2018-11-26 14:46:41 -0600 | [diff] [blame] | 293 | } |
Patrick Williams | 6d724ce | 2021-10-06 12:40:26 -0500 | [diff] [blame] | 294 | catch (const sdbusplus::exception::exception& e) |
Matt Spinler | 963c65f | 2018-11-26 14:46:41 -0600 | [diff] [blame] | 295 | { |
George Liu | 9fb1597 | 2022-06-20 14:54:38 +0800 | [diff] [blame^] | 296 | lg2::error("Failed powering off on long power button press: {ERROR}", |
| 297 | "ERROR", e); |
Matt Spinler | 963c65f | 2018-11-26 14:46:41 -0600 | [diff] [blame] | 298 | } |
Matt Spinler | fb35a32 | 2018-11-26 14:30:30 -0600 | [diff] [blame] | 299 | } |
Matt Spinler | 06a5bdd | 2018-11-26 14:50:48 -0600 | [diff] [blame] | 300 | |
George Liu | 94afa4b | 2022-06-20 13:36:43 +0800 | [diff] [blame] | 301 | void Handler::resetPressed(sdbusplus::message::message& /* msg */) |
Matt Spinler | 06a5bdd | 2018-11-26 14:50:48 -0600 | [diff] [blame] | 302 | { |
| 303 | try |
| 304 | { |
Naveen Moses | 3bd1cfc | 2022-02-14 18:04:20 +0530 | [diff] [blame] | 305 | handlePowerEvent(PowerEvent::resetPressed); |
Matt Spinler | 06a5bdd | 2018-11-26 14:50:48 -0600 | [diff] [blame] | 306 | } |
Patrick Williams | 6d724ce | 2021-10-06 12:40:26 -0500 | [diff] [blame] | 307 | catch (const sdbusplus::exception::exception& e) |
Matt Spinler | 06a5bdd | 2018-11-26 14:50:48 -0600 | [diff] [blame] | 308 | { |
George Liu | 9fb1597 | 2022-06-20 14:54:38 +0800 | [diff] [blame^] | 309 | lg2::error("Failed power state change on a reset button press: {ERROR}", |
| 310 | "ERROR", e); |
Matt Spinler | 06a5bdd | 2018-11-26 14:50:48 -0600 | [diff] [blame] | 311 | } |
| 312 | } |
Matt Spinler | 69f9351 | 2018-11-26 14:55:58 -0600 | [diff] [blame] | 313 | |
George Liu | 94afa4b | 2022-06-20 13:36:43 +0800 | [diff] [blame] | 314 | void Handler::idPressed(sdbusplus::message::message& /* msg */) |
Matt Spinler | 69f9351 | 2018-11-26 14:55:58 -0600 | [diff] [blame] | 315 | { |
| 316 | std::string groupPath{ledGroupBasePath}; |
| 317 | groupPath += ID_LED_GROUP; |
| 318 | |
| 319 | auto service = getService(groupPath, ledGroupIface); |
| 320 | |
| 321 | if (service.empty()) |
| 322 | { |
George Liu | 9fb1597 | 2022-06-20 14:54:38 +0800 | [diff] [blame^] | 323 | lg2::info("No found {GROUP} during ID button press:", "GROUP", |
| 324 | groupPath); |
Matt Spinler | 69f9351 | 2018-11-26 14:55:58 -0600 | [diff] [blame] | 325 | return; |
| 326 | } |
| 327 | |
| 328 | try |
| 329 | { |
| 330 | auto method = bus.new_method_call(service.c_str(), groupPath.c_str(), |
| 331 | propertyIface, "Get"); |
| 332 | method.append(ledGroupIface, "Asserted"); |
| 333 | auto result = bus.call(method); |
| 334 | |
Patrick Williams | 5ed4cc0 | 2020-05-13 17:52:15 -0500 | [diff] [blame] | 335 | std::variant<bool> state; |
Matt Spinler | 69f9351 | 2018-11-26 14:55:58 -0600 | [diff] [blame] | 336 | result.read(state); |
| 337 | |
Patrick Williams | 51f5e8b | 2020-05-13 11:33:44 -0500 | [diff] [blame] | 338 | state = !std::get<bool>(state); |
Matt Spinler | 69f9351 | 2018-11-26 14:55:58 -0600 | [diff] [blame] | 339 | |
George Liu | 9fb1597 | 2022-06-20 14:54:38 +0800 | [diff] [blame^] | 340 | lg2::info( |
| 341 | "Changing ID LED group state on ID LED press, GROUP = {GROUP}, STATE = {STATE}", |
| 342 | "GROUP", groupPath, "STATE", std::get<bool>(state)); |
Matt Spinler | 69f9351 | 2018-11-26 14:55:58 -0600 | [diff] [blame] | 343 | |
| 344 | method = bus.new_method_call(service.c_str(), groupPath.c_str(), |
| 345 | propertyIface, "Set"); |
| 346 | |
| 347 | method.append(ledGroupIface, "Asserted", state); |
| 348 | result = bus.call(method); |
| 349 | } |
Patrick Williams | 6d724ce | 2021-10-06 12:40:26 -0500 | [diff] [blame] | 350 | catch (const sdbusplus::exception::exception& e) |
Matt Spinler | 69f9351 | 2018-11-26 14:55:58 -0600 | [diff] [blame] | 351 | { |
George Liu | 9fb1597 | 2022-06-20 14:54:38 +0800 | [diff] [blame^] | 352 | lg2::error("Error toggling ID LED group on ID button press: {ERROR}", |
| 353 | "ERROR", e); |
Matt Spinler | 69f9351 | 2018-11-26 14:55:58 -0600 | [diff] [blame] | 354 | } |
| 355 | } |
Matt Spinler | fb35a32 | 2018-11-26 14:30:30 -0600 | [diff] [blame] | 356 | } // namespace button |
| 357 | } // namespace phosphor |