blob: c003d22d57d7dd46fd809a15589c94f127faf00e [file] [log] [blame]
James Feist1c8fba92019-12-20 15:12:07 -08001/*
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
24namespace 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 Mills9f8bfa72020-09-28 13:45:19 -050033// TODO (Gunnar): Remove IndicatorLED after enough time has passed
Ed Tanousb5a76932020-09-29 16:16:58 -070034inline void getIndicatorLedState(const std::shared_ptr<AsyncResp>& aResp)
James Feist1c8fba92019-12-20 15:12:07 -080035{
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 Mills1214b7e2020-06-04 10:11:30 -050044 const bool* blinking = std::get_if<bool>(&asserted);
James Feist1c8fba92019-12-20 15:12:07 -080045 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 Tanous23a21a12020-07-25 04:45:05 +000059 [aResp](const boost::system::error_code ec2,
60 const std::variant<bool> asserted2) {
61 if (!ec2)
James Feist1c8fba92019-12-20 15:12:07 -080062 {
Ed Tanous23a21a12020-07-25 04:45:05 +000063 const bool* ledOn = std::get_if<bool>(&asserted2);
James Feist1c8fba92019-12-20 15:12:07 -080064 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 Mills9f8bfa72020-09-28 13:45:19 -0500102// TODO (Gunnar): Remove IndicatorLED after enough time has passed
Ed Tanousb5a76932020-09-29 16:16:58 -0700103inline void setIndicatorLedState(const std::shared_ptr<AsyncResp>& aResp,
Ed Tanous23a21a12020-07-25 04:45:05 +0000104 const std::string& ledState)
James Feist1c8fba92019-12-20 15:12:07 -0800105{
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 Tanouscb13a392020-07-25 19:02:03 +0000125 [aResp, ledOn, ledBlinkng](const boost::system::error_code ec) mutable {
James Feist1c8fba92019-12-20 15:12:07 -0800126 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 Tanouscb13a392020-07-25 19:02:03 +0000137 [aResp](const boost::system::error_code ec2) {
Ed Tanous23a21a12020-07-25 04:45:05 +0000138 if (ec2)
James Feist1c8fba92019-12-20 15:12:07 -0800139 {
Ed Tanous23a21a12020-07-25 04:45:05 +0000140 BMCWEB_LOG_DEBUG << "DBUS response error " << ec2;
James Feist1c8fba92019-12-20 15:12:07 -0800141 messages::internalError(aResp->res);
142 return;
143 }
Jayaprakash Mutyala1d40ef62021-02-26 13:06:03 +0000144 messages::success(aResp->res);
James Feist1c8fba92019-12-20 15:12:07 -0800145 },
146 "xyz.openbmc_project.LED.GroupManager",
147 "/xyz/openbmc_project/led/groups/enclosure_identify",
148 "org.freedesktop.DBus.Properties", "Set",
149 "xyz.openbmc_project.Led.Group", "Asserted",
150 std::variant<bool>(ledOn));
151 },
152 "xyz.openbmc_project.LED.GroupManager",
153 "/xyz/openbmc_project/led/groups/enclosure_identify_blink",
154 "org.freedesktop.DBus.Properties", "Set",
155 "xyz.openbmc_project.Led.Group", "Asserted",
156 std::variant<bool>(ledBlinkng));
157}
Gunnar Mills9f8bfa72020-09-28 13:45:19 -0500158
159/**
160 * @brief Retrieves identify led group properties over dbus
161 *
162 * @param[in] aResp Shared pointer for generating response message.
163 *
164 * @return None.
165 */
166inline void getLocationIndicatorActive(const std::shared_ptr<AsyncResp>& aResp)
167{
168 BMCWEB_LOG_DEBUG << "Get LocationIndicatorActive";
169 crow::connections::systemBus->async_method_call(
170 [aResp](const boost::system::error_code ec,
171 const std::variant<bool> asserted) {
172 // Some systems may not have enclosure_identify_blink object so
173 // proceed to get enclosure_identify state.
174 if (!ec)
175 {
176 const bool* blinking = std::get_if<bool>(&asserted);
177 if (!blinking)
178 {
179 BMCWEB_LOG_DEBUG << "Get identity blinking LED failed";
180 messages::internalError(aResp->res);
181 return;
182 }
183 // Blinking ON, no need to check enclosure_identify assert.
184 if (*blinking)
185 {
186 aResp->res.jsonValue["LocationIndicatorActive"] = true;
187 return;
188 }
189 }
190 crow::connections::systemBus->async_method_call(
191 [aResp](const boost::system::error_code ec2,
192 const std::variant<bool> asserted2) {
193 if (!ec2)
194 {
195 const bool* ledOn = std::get_if<bool>(&asserted2);
196 if (!ledOn)
197 {
198 BMCWEB_LOG_DEBUG
199 << "Get enclosure identity led failed";
200 messages::internalError(aResp->res);
201 return;
202 }
203
204 if (*ledOn)
205 {
206 aResp->res.jsonValue["LocationIndicatorActive"] =
207 true;
208 }
209 else
210 {
211 aResp->res.jsonValue["LocationIndicatorActive"] =
212 false;
213 }
214 }
215 return;
216 },
217 "xyz.openbmc_project.LED.GroupManager",
218 "/xyz/openbmc_project/led/groups/enclosure_identify",
219 "org.freedesktop.DBus.Properties", "Get",
220 "xyz.openbmc_project.Led.Group", "Asserted");
221 },
222 "xyz.openbmc_project.LED.GroupManager",
223 "/xyz/openbmc_project/led/groups/enclosure_identify_blink",
224 "org.freedesktop.DBus.Properties", "Get",
225 "xyz.openbmc_project.Led.Group", "Asserted");
226}
227
228/**
229 * @brief Sets identify led group properties
230 *
231 * @param[in] aResp Shared pointer for generating response message.
232 * @param[in] ledState LED state passed from request
233 *
234 * @return None.
235 */
236inline void setLocationIndicatorActive(const std::shared_ptr<AsyncResp>& aResp,
237 const bool ledState)
238{
239 BMCWEB_LOG_DEBUG << "Set LocationIndicatorActive";
240
241 crow::connections::systemBus->async_method_call(
242 [aResp, ledState](const boost::system::error_code ec) mutable {
243 if (ec)
244 {
245 // Some systems may not have enclosure_identify_blink object so
246 // lets set enclosure_identify state also if
247 // enclosure_identify_blink failed
248 crow::connections::systemBus->async_method_call(
249 [aResp](const boost::system::error_code ec2) {
250 if (ec2)
251 {
252 BMCWEB_LOG_DEBUG << "DBUS response error " << ec2;
253 messages::internalError(aResp->res);
254 return;
255 }
256 },
257 "xyz.openbmc_project.LED.GroupManager",
258 "/xyz/openbmc_project/led/groups/enclosure_identify",
259 "org.freedesktop.DBus.Properties", "Set",
260 "xyz.openbmc_project.Led.Group", "Asserted",
261 std::variant<bool>(ledState));
262 }
263 },
264 "xyz.openbmc_project.LED.GroupManager",
265 "/xyz/openbmc_project/led/groups/enclosure_identify_blink",
266 "org.freedesktop.DBus.Properties", "Set",
267 "xyz.openbmc_project.Led.Group", "Asserted",
268 std::variant<bool>(ledState));
269}
Ed Tanous23a21a12020-07-25 04:45:05 +0000270} // namespace redfish