James Feist | 1c8fba9 | 2019-12-20 15:12:07 -0800 | [diff] [blame] | 1 | /* |
| 2 | // Copyright (c) 2019 Intel Corporation |
| 3 | // |
| 4 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | // you may not use this file except in compliance with the License. |
| 6 | // You may obtain a copy of the License at |
| 7 | // |
| 8 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | // |
| 10 | // Unless required by applicable law or agreed to in writing, software |
| 11 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | // See the License for the specific language governing permissions and |
| 14 | // limitations under the License. |
| 15 | */ |
| 16 | #pragma once |
| 17 | |
| 18 | #include "async_resp.hpp" |
| 19 | #include "dbus_utility.hpp" |
| 20 | #include "redfish_util.hpp" |
| 21 | |
| 22 | #include <variant> |
| 23 | |
| 24 | namespace redfish |
| 25 | { |
| 26 | /** |
| 27 | * @brief Retrieves identify led group properties over dbus |
| 28 | * |
| 29 | * @param[in] aResp Shared pointer for generating response message. |
| 30 | * |
| 31 | * @return None. |
| 32 | */ |
Gunnar Mills | 9f8bfa7 | 2020-09-28 13:45:19 -0500 | [diff] [blame^] | 33 | // TODO (Gunnar): Remove IndicatorLED after enough time has passed |
Ed Tanous | b5a7693 | 2020-09-29 16:16:58 -0700 | [diff] [blame] | 34 | inline void getIndicatorLedState(const std::shared_ptr<AsyncResp>& aResp) |
James Feist | 1c8fba9 | 2019-12-20 15:12:07 -0800 | [diff] [blame] | 35 | { |
| 36 | BMCWEB_LOG_DEBUG << "Get led groups"; |
| 37 | crow::connections::systemBus->async_method_call( |
| 38 | [aResp](const boost::system::error_code ec, |
| 39 | const std::variant<bool> asserted) { |
| 40 | // Some systems may not have enclosure_identify_blink object so |
| 41 | // proceed to get enclosure_identify state. |
| 42 | if (!ec) |
| 43 | { |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 44 | const bool* blinking = std::get_if<bool>(&asserted); |
James Feist | 1c8fba9 | 2019-12-20 15:12:07 -0800 | [diff] [blame] | 45 | if (!blinking) |
| 46 | { |
| 47 | BMCWEB_LOG_DEBUG << "Get identity blinking LED failed"; |
| 48 | messages::internalError(aResp->res); |
| 49 | return; |
| 50 | } |
| 51 | // Blinking ON, no need to check enclosure_identify assert. |
| 52 | if (*blinking) |
| 53 | { |
| 54 | aResp->res.jsonValue["IndicatorLED"] = "Blinking"; |
| 55 | return; |
| 56 | } |
| 57 | } |
| 58 | crow::connections::systemBus->async_method_call( |
Ed Tanous | 23a21a1 | 2020-07-25 04:45:05 +0000 | [diff] [blame] | 59 | [aResp](const boost::system::error_code ec2, |
| 60 | const std::variant<bool> asserted2) { |
| 61 | if (!ec2) |
James Feist | 1c8fba9 | 2019-12-20 15:12:07 -0800 | [diff] [blame] | 62 | { |
Ed Tanous | 23a21a1 | 2020-07-25 04:45:05 +0000 | [diff] [blame] | 63 | const bool* ledOn = std::get_if<bool>(&asserted2); |
James Feist | 1c8fba9 | 2019-12-20 15:12:07 -0800 | [diff] [blame] | 64 | if (!ledOn) |
| 65 | { |
| 66 | BMCWEB_LOG_DEBUG |
| 67 | << "Get enclosure identity led failed"; |
| 68 | messages::internalError(aResp->res); |
| 69 | return; |
| 70 | } |
| 71 | |
| 72 | if (*ledOn) |
| 73 | { |
| 74 | aResp->res.jsonValue["IndicatorLED"] = "Lit"; |
| 75 | } |
| 76 | else |
| 77 | { |
| 78 | aResp->res.jsonValue["IndicatorLED"] = "Off"; |
| 79 | } |
| 80 | } |
| 81 | return; |
| 82 | }, |
| 83 | "xyz.openbmc_project.LED.GroupManager", |
| 84 | "/xyz/openbmc_project/led/groups/enclosure_identify", |
| 85 | "org.freedesktop.DBus.Properties", "Get", |
| 86 | "xyz.openbmc_project.Led.Group", "Asserted"); |
| 87 | }, |
| 88 | "xyz.openbmc_project.LED.GroupManager", |
| 89 | "/xyz/openbmc_project/led/groups/enclosure_identify_blink", |
| 90 | "org.freedesktop.DBus.Properties", "Get", |
| 91 | "xyz.openbmc_project.Led.Group", "Asserted"); |
| 92 | } |
| 93 | |
| 94 | /** |
| 95 | * @brief Sets identify led group properties |
| 96 | * |
| 97 | * @param[in] aResp Shared pointer for generating response message. |
| 98 | * @param[in] ledState LED state passed from request |
| 99 | * |
| 100 | * @return None. |
| 101 | */ |
Gunnar Mills | 9f8bfa7 | 2020-09-28 13:45:19 -0500 | [diff] [blame^] | 102 | // TODO (Gunnar): Remove IndicatorLED after enough time has passed |
Ed Tanous | b5a7693 | 2020-09-29 16:16:58 -0700 | [diff] [blame] | 103 | inline void setIndicatorLedState(const std::shared_ptr<AsyncResp>& aResp, |
Ed Tanous | 23a21a1 | 2020-07-25 04:45:05 +0000 | [diff] [blame] | 104 | const std::string& ledState) |
James Feist | 1c8fba9 | 2019-12-20 15:12:07 -0800 | [diff] [blame] | 105 | { |
| 106 | BMCWEB_LOG_DEBUG << "Set led groups"; |
| 107 | bool ledOn = false; |
| 108 | bool ledBlinkng = false; |
| 109 | |
| 110 | if (ledState == "Lit") |
| 111 | { |
| 112 | ledOn = true; |
| 113 | } |
| 114 | else if (ledState == "Blinking") |
| 115 | { |
| 116 | ledBlinkng = true; |
| 117 | } |
| 118 | else if (ledState != "Off") |
| 119 | { |
| 120 | messages::propertyValueNotInList(aResp->res, ledState, "IndicatorLED"); |
| 121 | return; |
| 122 | } |
| 123 | |
| 124 | crow::connections::systemBus->async_method_call( |
Ed Tanous | cb13a39 | 2020-07-25 19:02:03 +0000 | [diff] [blame] | 125 | [aResp, ledOn, ledBlinkng](const boost::system::error_code ec) mutable { |
James Feist | 1c8fba9 | 2019-12-20 15:12:07 -0800 | [diff] [blame] | 126 | if (ec) |
| 127 | { |
| 128 | // Some systems may not have enclosure_identify_blink object so |
| 129 | // Lets set enclosure_identify state to true if Blinking is |
| 130 | // true. |
| 131 | if (ledBlinkng) |
| 132 | { |
| 133 | ledOn = true; |
| 134 | } |
| 135 | } |
| 136 | crow::connections::systemBus->async_method_call( |
Ed Tanous | cb13a39 | 2020-07-25 19:02:03 +0000 | [diff] [blame] | 137 | [aResp](const boost::system::error_code ec2) { |
Ed Tanous | 23a21a1 | 2020-07-25 04:45:05 +0000 | [diff] [blame] | 138 | if (ec2) |
James Feist | 1c8fba9 | 2019-12-20 15:12:07 -0800 | [diff] [blame] | 139 | { |
Ed Tanous | 23a21a1 | 2020-07-25 04:45:05 +0000 | [diff] [blame] | 140 | BMCWEB_LOG_DEBUG << "DBUS response error " << ec2; |
James Feist | 1c8fba9 | 2019-12-20 15:12:07 -0800 | [diff] [blame] | 141 | messages::internalError(aResp->res); |
| 142 | return; |
| 143 | } |
| 144 | }, |
| 145 | "xyz.openbmc_project.LED.GroupManager", |
| 146 | "/xyz/openbmc_project/led/groups/enclosure_identify", |
| 147 | "org.freedesktop.DBus.Properties", "Set", |
| 148 | "xyz.openbmc_project.Led.Group", "Asserted", |
| 149 | std::variant<bool>(ledOn)); |
| 150 | }, |
| 151 | "xyz.openbmc_project.LED.GroupManager", |
| 152 | "/xyz/openbmc_project/led/groups/enclosure_identify_blink", |
| 153 | "org.freedesktop.DBus.Properties", "Set", |
| 154 | "xyz.openbmc_project.Led.Group", "Asserted", |
| 155 | std::variant<bool>(ledBlinkng)); |
| 156 | } |
Gunnar Mills | 9f8bfa7 | 2020-09-28 13:45:19 -0500 | [diff] [blame^] | 157 | |
| 158 | /** |
| 159 | * @brief Retrieves identify led group properties over dbus |
| 160 | * |
| 161 | * @param[in] aResp Shared pointer for generating response message. |
| 162 | * |
| 163 | * @return None. |
| 164 | */ |
| 165 | inline void getLocationIndicatorActive(const std::shared_ptr<AsyncResp>& aResp) |
| 166 | { |
| 167 | BMCWEB_LOG_DEBUG << "Get LocationIndicatorActive"; |
| 168 | crow::connections::systemBus->async_method_call( |
| 169 | [aResp](const boost::system::error_code ec, |
| 170 | const std::variant<bool> asserted) { |
| 171 | // Some systems may not have enclosure_identify_blink object so |
| 172 | // proceed to get enclosure_identify state. |
| 173 | if (!ec) |
| 174 | { |
| 175 | const bool* blinking = std::get_if<bool>(&asserted); |
| 176 | if (!blinking) |
| 177 | { |
| 178 | BMCWEB_LOG_DEBUG << "Get identity blinking LED failed"; |
| 179 | messages::internalError(aResp->res); |
| 180 | return; |
| 181 | } |
| 182 | // Blinking ON, no need to check enclosure_identify assert. |
| 183 | if (*blinking) |
| 184 | { |
| 185 | aResp->res.jsonValue["LocationIndicatorActive"] = true; |
| 186 | return; |
| 187 | } |
| 188 | } |
| 189 | crow::connections::systemBus->async_method_call( |
| 190 | [aResp](const boost::system::error_code ec2, |
| 191 | const std::variant<bool> asserted2) { |
| 192 | if (!ec2) |
| 193 | { |
| 194 | const bool* ledOn = std::get_if<bool>(&asserted2); |
| 195 | if (!ledOn) |
| 196 | { |
| 197 | BMCWEB_LOG_DEBUG |
| 198 | << "Get enclosure identity led failed"; |
| 199 | messages::internalError(aResp->res); |
| 200 | return; |
| 201 | } |
| 202 | |
| 203 | if (*ledOn) |
| 204 | { |
| 205 | aResp->res.jsonValue["LocationIndicatorActive"] = |
| 206 | true; |
| 207 | } |
| 208 | else |
| 209 | { |
| 210 | aResp->res.jsonValue["LocationIndicatorActive"] = |
| 211 | false; |
| 212 | } |
| 213 | } |
| 214 | return; |
| 215 | }, |
| 216 | "xyz.openbmc_project.LED.GroupManager", |
| 217 | "/xyz/openbmc_project/led/groups/enclosure_identify", |
| 218 | "org.freedesktop.DBus.Properties", "Get", |
| 219 | "xyz.openbmc_project.Led.Group", "Asserted"); |
| 220 | }, |
| 221 | "xyz.openbmc_project.LED.GroupManager", |
| 222 | "/xyz/openbmc_project/led/groups/enclosure_identify_blink", |
| 223 | "org.freedesktop.DBus.Properties", "Get", |
| 224 | "xyz.openbmc_project.Led.Group", "Asserted"); |
| 225 | } |
| 226 | |
| 227 | /** |
| 228 | * @brief Sets identify led group properties |
| 229 | * |
| 230 | * @param[in] aResp Shared pointer for generating response message. |
| 231 | * @param[in] ledState LED state passed from request |
| 232 | * |
| 233 | * @return None. |
| 234 | */ |
| 235 | inline void setLocationIndicatorActive(const std::shared_ptr<AsyncResp>& aResp, |
| 236 | const bool ledState) |
| 237 | { |
| 238 | BMCWEB_LOG_DEBUG << "Set LocationIndicatorActive"; |
| 239 | |
| 240 | crow::connections::systemBus->async_method_call( |
| 241 | [aResp, ledState](const boost::system::error_code ec) mutable { |
| 242 | if (ec) |
| 243 | { |
| 244 | // Some systems may not have enclosure_identify_blink object so |
| 245 | // lets set enclosure_identify state also if |
| 246 | // enclosure_identify_blink failed |
| 247 | crow::connections::systemBus->async_method_call( |
| 248 | [aResp](const boost::system::error_code ec2) { |
| 249 | if (ec2) |
| 250 | { |
| 251 | BMCWEB_LOG_DEBUG << "DBUS response error " << ec2; |
| 252 | messages::internalError(aResp->res); |
| 253 | return; |
| 254 | } |
| 255 | }, |
| 256 | "xyz.openbmc_project.LED.GroupManager", |
| 257 | "/xyz/openbmc_project/led/groups/enclosure_identify", |
| 258 | "org.freedesktop.DBus.Properties", "Set", |
| 259 | "xyz.openbmc_project.Led.Group", "Asserted", |
| 260 | std::variant<bool>(ledState)); |
| 261 | } |
| 262 | }, |
| 263 | "xyz.openbmc_project.LED.GroupManager", |
| 264 | "/xyz/openbmc_project/led/groups/enclosure_identify_blink", |
| 265 | "org.freedesktop.DBus.Properties", "Set", |
| 266 | "xyz.openbmc_project.Led.Group", "Asserted", |
| 267 | std::variant<bool>(ledState)); |
| 268 | } |
Ed Tanous | 23a21a1 | 2020-07-25 04:45:05 +0000 | [diff] [blame] | 269 | } // namespace redfish |