blob: 32306bdfa0eb4d511f500aaa0438793370178b7a [file] [log] [blame]
Vishwanatha Subbannab21fda72016-10-17 17:46:37 +05301#pragma once
2
3#include <map>
4#include <set>
5#include <vector>
6#include <sdbusplus/bus.hpp>
7#include <sdbusplus/server/interface.hpp>
8#include <sdbusplus/server/manager.hpp>
Vishwanatha Subbannab21fda72016-10-17 17:46:37 +05309namespace phosphor
10{
Vishwanatha Subbannab21fda72016-10-17 17:46:37 +053011namespace led
12{
13
Vishwanatha Subbannabb8fe0b2016-11-12 18:29:38 +053014/** @class Group
Vishwanatha Subbannab21fda72016-10-17 17:46:37 +053015 * @brief Manages group of LEDs and applies action on the elements of group
16 */
17
Vishwanatha Subbannabb8fe0b2016-11-12 18:29:38 +053018class Group
Vishwanatha Subbannab21fda72016-10-17 17:46:37 +053019{
Vishwanatha Subbannabb8fe0b2016-11-12 18:29:38 +053020 public:
21 /** @brief Define possible actions on a given LED.
22 * For the BLINK operation, follow 50-50 duty cycle
23 */
24 enum Action
Vishwanatha Subbannab21fda72016-10-17 17:46:37 +053025 {
Vishwanatha Subbannabb8fe0b2016-11-12 18:29:38 +053026 OFF,
27 ON,
28 BLINK,
29 };
30
31 Group() = delete;
32 ~Group() = default;
33 Group(const Group&) = delete;
34 Group& operator=(const Group&) = delete;
35 Group(Group&&) = delete;
36 Group& operator=(Group&&) = delete;
37
38 /** @brief Constructs LED manager
39 *
40 * @param[in] busName - The Dbus name to own
41 * @param[in] objPath - The Dbus path that hosts LED manager
42 * @param[in] intfName - The Dbus interface
43 */
44 Group(const char* busName, const char* objPath, const char* intfName);
45
46 /** @brief Name of the LED and it's proposed action.
47 * This structure is supplied as configuration at build time
48 */
49 struct LedAction
50 {
51 std::string name;
52 Action action;
53
54 // Needed for inserting elements into sets
55 bool operator<(const LedAction& right) const
Vishwanatha Subbannab21fda72016-10-17 17:46:37 +053056 {
Vishwanatha Subbannabb8fe0b2016-11-12 18:29:38 +053057 if (name == right.name)
58 {
59 return action < right.action;
60 }
61 return name < right.name;
Vishwanatha Subbannab21fda72016-10-17 17:46:37 +053062 }
Vishwanatha Subbannabb8fe0b2016-11-12 18:29:38 +053063 };
64
65 /** @brief For finding intersection */
66 static bool ledComp(const LedAction& left, const LedAction& right)
67 {
68 return left.name < right.name;
Vishwanatha Subbannab21fda72016-10-17 17:46:37 +053069 }
70
Vishwanatha Subbannabb8fe0b2016-11-12 18:29:38 +053071 using group = std::set<LedAction>;
Vishwanatha Subbannab21fda72016-10-17 17:46:37 +053072
Vishwanatha Subbannabb8fe0b2016-11-12 18:29:38 +053073 /** @brief static global map constructed at compile time */
74 static const std::map<std::string, group> ledMap;
Vishwanatha Subbannab21fda72016-10-17 17:46:37 +053075
Vishwanatha Subbannabb8fe0b2016-11-12 18:29:38 +053076 /** @brief Dbus constructs used by LED manager */
77 sdbusplus::bus::bus bus;
Vishwanatha Subbannab21fda72016-10-17 17:46:37 +053078
Vishwanatha Subbannabb8fe0b2016-11-12 18:29:38 +053079 /** @brief sd_bus object manager */
80 sdbusplus::server::manager::manager objManager;
Vishwanatha Subbannab21fda72016-10-17 17:46:37 +053081
Vishwanatha Subbannabb8fe0b2016-11-12 18:29:38 +053082 /** @brief Individual objects */
83 std::vector<sdbusplus::server::interface::interface> intfContainer;
84
85 /** @brief Pointers to groups that are in asserted state */
86 static std::set<const group*> assertedGroups;
87
88 /** @brief Contains the LEDs that are in asserted state */
89 static group currentState;
90
91 /** @brief Waits on the client request and processes them */
92 void run();
93
94 /** @brief Given a group name, tells if its in asserted state or not.
95 *
96 * @param[in] name - Group name
97 * @return - Whether in asserted state or not
98 */
99 bool getGroupState(const std::string& name);
100
101 /** @brief Given a group name, applies the action on the group
102 *
103 * @param[in] name - Group name
104 * @param[in] assert - Could be 0 or 1
105 * @return - Success or exception thrown
106 */
107 int setGroupState(const std::string& name, bool assert);
108
109 private:
110 /** @brief Finds the set of LEDs to operate on and executes action
111 *
112 * @return: Returns '0' for now.
113 */
114 int driveLEDs();
Vishwanatha Subbannab21fda72016-10-17 17:46:37 +0530115};
116
117} // namespace led
118
119} // namespace phosphor