blob: 43e1b5c39d678de833b34b735b27f71a6bae95a1 [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 */
33void getIndicatorLedState(std::shared_ptr<AsyncResp> aResp)
34{
35 BMCWEB_LOG_DEBUG << "Get led groups";
36 crow::connections::systemBus->async_method_call(
37 [aResp](const boost::system::error_code ec,
38 const std::variant<bool> asserted) {
39 // Some systems may not have enclosure_identify_blink object so
40 // proceed to get enclosure_identify state.
41 if (!ec)
42 {
43 const bool *blinking = std::get_if<bool>(&asserted);
44 if (!blinking)
45 {
46 BMCWEB_LOG_DEBUG << "Get identity blinking LED failed";
47 messages::internalError(aResp->res);
48 return;
49 }
50 // Blinking ON, no need to check enclosure_identify assert.
51 if (*blinking)
52 {
53 aResp->res.jsonValue["IndicatorLED"] = "Blinking";
54 return;
55 }
56 }
57 crow::connections::systemBus->async_method_call(
58 [aResp](const boost::system::error_code ec,
59 const std::variant<bool> asserted) {
60 if (!ec)
61 {
62 const bool *ledOn = std::get_if<bool>(&asserted);
63 if (!ledOn)
64 {
65 BMCWEB_LOG_DEBUG
66 << "Get enclosure identity led failed";
67 messages::internalError(aResp->res);
68 return;
69 }
70
71 if (*ledOn)
72 {
73 aResp->res.jsonValue["IndicatorLED"] = "Lit";
74 }
75 else
76 {
77 aResp->res.jsonValue["IndicatorLED"] = "Off";
78 }
79 }
80 return;
81 },
82 "xyz.openbmc_project.LED.GroupManager",
83 "/xyz/openbmc_project/led/groups/enclosure_identify",
84 "org.freedesktop.DBus.Properties", "Get",
85 "xyz.openbmc_project.Led.Group", "Asserted");
86 },
87 "xyz.openbmc_project.LED.GroupManager",
88 "/xyz/openbmc_project/led/groups/enclosure_identify_blink",
89 "org.freedesktop.DBus.Properties", "Get",
90 "xyz.openbmc_project.Led.Group", "Asserted");
91}
92
93/**
94 * @brief Sets identify led group properties
95 *
96 * @param[in] aResp Shared pointer for generating response message.
97 * @param[in] ledState LED state passed from request
98 *
99 * @return None.
100 */
101void setIndicatorLedState(std::shared_ptr<AsyncResp> aResp,
102 const std::string &ledState)
103{
104 BMCWEB_LOG_DEBUG << "Set led groups";
105 bool ledOn = false;
106 bool ledBlinkng = false;
107
108 if (ledState == "Lit")
109 {
110 ledOn = true;
111 }
112 else if (ledState == "Blinking")
113 {
114 ledBlinkng = true;
115 }
116 else if (ledState != "Off")
117 {
118 messages::propertyValueNotInList(aResp->res, ledState, "IndicatorLED");
119 return;
120 }
121
122 crow::connections::systemBus->async_method_call(
123 [aResp, ledOn, ledBlinkng](const boost::system::error_code ec,
124 const std::variant<bool> asserted) mutable {
125 if (ec)
126 {
127 // Some systems may not have enclosure_identify_blink object so
128 // Lets set enclosure_identify state to true if Blinking is
129 // true.
130 if (ledBlinkng)
131 {
132 ledOn = true;
133 }
134 }
135 crow::connections::systemBus->async_method_call(
136 [aResp](const boost::system::error_code ec,
137 const std::variant<bool> asserted) {
138 if (ec)
139 {
140 BMCWEB_LOG_DEBUG << "DBUS response error " << ec;
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}
157} // namespace redfish