blob: 0fd1c9b1102bfbbf25dedd2b997d21c66d4055ce [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 }
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 Mills9f8bfa72020-09-28 13:45:19 -0500157
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 */
165inline 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 */
235inline 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 Tanous23a21a12020-07-25 04:45:05 +0000269} // namespace redfish