blob: 9e32216d67d44edf024e4f22e9a506b6e3d11711 [file] [log] [blame]
Vishwanatha Subbanna4c8c72b2016-11-29 23:02:06 +05301#pragma once
2
3#include <map>
4#include <set>
5namespace phosphor
6{
7namespace led
8{
9
10/** @class Manager
11 * @brief Manages group of LEDs and applies action on the elements of group
12 */
13class Manager
14{
15 public:
16 /** @brief Define possible actions on a given LED.
17 * For the BLINK operation, follow 50-50 duty cycle
18 */
19 enum Action
20 {
21 Off,
22 On,
23 Blink,
24 };
25
26 /** @brief Only need the default Manager */
27 Manager() = default;
28 ~Manager() = default;
29 Manager(const Manager&) = delete;
30 Manager& operator=(const Manager&) = delete;
31 Manager(Manager&&) = delete;
32 Manager& operator=(Manager&&) = delete;
33
34 /** @brief Name of the LED and it's proposed action.
35 * This structure is supplied as configuration at build time
36 */
37 struct LedAction
38 {
39 std::string name;
40 Action action;
41
42 // Needed for inserting elements into sets
43 bool operator<(const LedAction& right) const
44 {
45 if (name == right.name)
46 {
47 return action < right.action;
48 }
49 return name < right.name;
50 }
51 };
52
53 /** @brief For finding intersection */
54 static bool ledComp(const LedAction& left, const LedAction& right)
55 {
56 return left.name < right.name;
57 }
58
59 using group = std::set<LedAction>;
60
61 /** @brief static global map constructed at compile time */
62 static const std::map<std::string, group> ledMap;
63
64 /** @brief Given a group name, applies the action on the group
65 *
66 * @param[in] path - dbus path of group
67 * @param[in] assert - Could be true or false
68 * @return - Success or exception thrown
69 */
70 bool setGroupState(const std::string& path, bool assert);
71
72 private:
73 /** @brief Pointers to groups that are in asserted state */
74 std::set<const group*> assertedGroups;
75
76 /** @brief Contains the LEDs that are in asserted state */
77 group currentState;
78
79 /** @brief Finds the set of LEDs to operate on and executes action
80 *
81 * @return: None
82 */
83 void driveLEDs();
84};
85
86} // namespace led
87} // namespace phosphor