-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathmanager.hpp
196 lines (166 loc) · 6.27 KB
/
manager.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
#pragma once
#include "ledlayout.hpp"
#include "utils.hpp"
#include <sdeventplus/event.hpp>
#include <sdeventplus/utility/timer.hpp>
#include <map>
#include <set>
#include <string>
namespace phosphor
{
namespace led
{
using namespace phosphor::led::utils;
static constexpr auto PHY_LED_PATH = "/xyz/openbmc_project/led/physical/";
static constexpr auto PHY_LED_IFACE = "xyz.openbmc_project.Led.Physical";
/** @class Manager
* @brief Manages group of LEDs and applies action on the elements of group
*/
class Manager
{
public:
/** @brief Only need the default Manager */
Manager() = delete;
~Manager() = default;
Manager(const Manager&) = delete;
Manager& operator=(const Manager&) = delete;
Manager(Manager&&) = delete;
Manager& operator=(Manager&&) = delete;
/** @brief Special comparator for finding set difference */
static bool ledComp(const phosphor::led::Layout::LedAction& left,
const phosphor::led::Layout::LedAction& right)
{
// Example :
// If FIRST_1 is {fan0, 1, 1} and FIRST_2 is {fan0, 2, 2},
// with default priority of Blink, this comparator would return
// false. But considering the priority, this comparator would need
// to return true so that we consider appropriate set and in
// this case its {fan0, 1, 1}
if (left.name == right.name)
{
if (left.action == right.action)
{
return false;
}
else
{
return true;
}
}
return left.name < right.name;
}
/** @brief Comparator for finding LEDs to be DeAsserted */
static bool ledLess(const phosphor::led::Layout::LedAction& left,
const phosphor::led::Layout::LedAction& right)
{
return left.name < right.name;
}
/** @brief Comparator for helping unique_copy */
static bool ledEqual(const phosphor::led::Layout::LedAction& left,
const phosphor::led::Layout::LedAction& right)
{
return left.name == right.name;
}
using group = std::set<phosphor::led::Layout::LedAction>;
using LedLayout = std::map<std::string, group>;
/** @brief static global map constructed at compile time */
const LedLayout& ledMap;
/** @brief Refer the user supplied LED layout and sdbusplus handler
*
* @param [in] bus - sdbusplus handler
* @param [in] LedLayout - LEDs group layout
* @param [in] Event - sd event handler
*/
Manager(
sdbusplus::bus_t& bus, const LedLayout& ledLayout,
const sdeventplus::Event& event = sdeventplus::Event::get_default()) :
ledMap(ledLayout),
bus(bus), timer(event, [this](auto&) { driveLedsHandler(); })
{
// Nothing here
}
/** @brief Given a group name, applies the action on the group
*
* @param[in] path - dbus path of group
* @param[in] assert - Could be true or false
* @param[in] ledsAssert - LEDs that are to be asserted new
* or to a different state
* @param[in] ledsDeAssert - LEDs that are to be Deasserted
*
* @return - Success or exception thrown
*/
bool setGroupState(const std::string& path, bool assert, group& ledsAssert,
group& ledsDeAssert);
/** @brief Finds the set of LEDs to operate on and executes action
*
* @param[in] ledsAssert - LEDs that are to be asserted newly
* or to a different state
* @param[in] ledsDeAssert - LEDs that are to be Deasserted
*
* @return: None
*/
void driveLEDs(group& ledsAssert, group& ledsDeAssert);
/** @brief Chooses appropriate action to be triggered on physical LED
* and calls into function that applies the actual action.
*
* @param[in] objPath - D-Bus object path
* @param[in] action - Intended action to be triggered
* @param[in] dutyOn - Duty Cycle ON percentage
* @param[in] period - Time taken for one blink cycle
*
* @return: - 0: success, -1: LED set failed
*/
int drivePhysicalLED(const std::string& objPath, Layout::Action action,
uint8_t dutyOn, const uint16_t period);
/** @brief Set lamp test callback when enabled lamp test.
*
* @param[in] callBack - Custom callback when enabled lamp test
*/
void setLampTestCallBack(
std::function<bool(group& ledsAssert, group& ledsDeAssert)> callBack);
/** @brief Check for asserted state by group path.
*
* @param[in] path - LED group path
*
* @return - Asserted state as a bool
*/
bool isAsserted(const std::string& path) const
{
return assertedGroups.contains(&ledMap.at(path));
}
private:
/** @brief sdbusplus handler */
sdbusplus::bus::bus& bus;
/** Map of physical LED path to service name */
std::map<std::string, std::string> phyLeds{};
/** DBusHandler class handles the D-Bus operations */
DBusHandler dBusHandler;
/** @brief Pointers to groups that are in asserted state */
std::set<const group*> assertedGroups;
/** @brief Contains the highest priority actions for all
* asserted LEDs.
*/
group currentState;
/** @brief Contains the set of all actions for asserted LEDs */
group combinedState;
/** @brief Custom callback when enabled lamp test */
std::function<bool(group& ledsAssert, group& ledsDeAssert)>
lampTestCallBack;
/** @brief Timer used for LEDs handler callback*/
sdeventplus::utility::Timer<sdeventplus::ClockId::Monotonic> timer;
/** @brief Contains the required set of assert LEDs action */
group reqLedsAssert;
/** @brief Contains the required set of deassert LEDs action */
group reqLedsDeAssert;
/** @brief LEDs handler callback */
void driveLedsHandler();
/** @brief Returns action string based on enum
*
* @param[in] action - Action enum
*
* @return string equivalent of the passed in enumeration
*/
static std::string getPhysicalAction(Layout::Action action);
};
} // namespace led
} // namespace phosphor