blob: 1ff869b4dfe94511c6e08220eb7b71c938acca51 [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>
9
10namespace phosphor
11{
12
13namespace led
14{
15
16/** @class Manager
17 * @brief Manages group of LEDs and applies action on the elements of group
18 */
19
20class Manager
21{
22private:
23
24 /** @brief Define possible actions on a given LED.
25 * For the BLINK operation, follow 50-50 duty cycle
26 */
27 enum Action
28 {
29 OFF,
30 ON,
31 BLINK,
32 };
33
34 /** @brief Dbus constructs used by LED manager */
35 sdbusplus::bus::bus iv_bus;
36
37public:
38 Manager() = delete;
39 ~Manager() = default;
40 Manager(const Manager&) = delete;
41 Manager& operator=(const Manager&) = delete;
42 Manager(Manager&&) = default;
43 Manager& operator=(Manager&&) = default;
44
45 /** @brief Constructs LED manager
46 *
47 * @param[in] busName - The Dbus name to own
48 * @param[in] objPath - The Dbus path that hosts LED manager
49 * @param[in] intfName - The Dbus interface
50 */
51 Manager(const char* busName, const char* objPath, const char* intfName);
52
53 /** @brief Name of the LED and it's proposed action.
54 * This structure is supplied as configuration at build time
55 */
56 struct LedAction
57 {
58 std::string name;
59 Action action;
60
61 // Needed for inserting elements into sets
62 bool operator<(const LedAction& right) const
63 {
64 if (name == right.name)
65 {
66 return action < right.action;
67 }
68 return name < right.name;
69 }
70
71 // Needed for set union / intersect
72 bool operator==(const LedAction& right) const
73 {
74 // Only if name and action are same, consider equal
75 if (name == right.name &&
76 action == right.action)
77 {
78 return true;
79 }
80 return false;
81 }
82 };
83
84 /** @brief static global map constructed at compile time */
85 static const std::map<std::string,
86 std::set<LedAction>> cv_LedMap;
87
88 /** @brief sd_bus object manager */
89 sdbusplus::server::manager::manager objManager;
90
91 /** @brief Individual objects */
92 std::vector<sdbusplus::server::interface::interface> intfContainer;
93
94 void run();
95};
96
97} // namespace led
98
99} // namespace phosphor