Vishwanatha Subbanna | b21fda7 | 2016-10-17 17:46:37 +0530 | [diff] [blame] | 1 | #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 Subbanna | b21fda7 | 2016-10-17 17:46:37 +0530 | [diff] [blame] | 9 | namespace phosphor |
| 10 | { |
Vishwanatha Subbanna | b21fda7 | 2016-10-17 17:46:37 +0530 | [diff] [blame] | 11 | namespace led |
| 12 | { |
| 13 | |
Vishwanatha Subbanna | bb8fe0b | 2016-11-12 18:29:38 +0530 | [diff] [blame^] | 14 | /** @class Group |
Vishwanatha Subbanna | b21fda7 | 2016-10-17 17:46:37 +0530 | [diff] [blame] | 15 | * @brief Manages group of LEDs and applies action on the elements of group |
| 16 | */ |
| 17 | |
Vishwanatha Subbanna | bb8fe0b | 2016-11-12 18:29:38 +0530 | [diff] [blame^] | 18 | class Group |
Vishwanatha Subbanna | b21fda7 | 2016-10-17 17:46:37 +0530 | [diff] [blame] | 19 | { |
Vishwanatha Subbanna | bb8fe0b | 2016-11-12 18:29:38 +0530 | [diff] [blame^] | 20 | 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 Subbanna | b21fda7 | 2016-10-17 17:46:37 +0530 | [diff] [blame] | 25 | { |
Vishwanatha Subbanna | bb8fe0b | 2016-11-12 18:29:38 +0530 | [diff] [blame^] | 26 | 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 Subbanna | b21fda7 | 2016-10-17 17:46:37 +0530 | [diff] [blame] | 56 | { |
Vishwanatha Subbanna | bb8fe0b | 2016-11-12 18:29:38 +0530 | [diff] [blame^] | 57 | if (name == right.name) |
| 58 | { |
| 59 | return action < right.action; |
| 60 | } |
| 61 | return name < right.name; |
Vishwanatha Subbanna | b21fda7 | 2016-10-17 17:46:37 +0530 | [diff] [blame] | 62 | } |
Vishwanatha Subbanna | bb8fe0b | 2016-11-12 18:29:38 +0530 | [diff] [blame^] | 63 | }; |
| 64 | |
| 65 | /** @brief For finding intersection */ |
| 66 | static bool ledComp(const LedAction& left, const LedAction& right) |
| 67 | { |
| 68 | return left.name < right.name; |
Vishwanatha Subbanna | b21fda7 | 2016-10-17 17:46:37 +0530 | [diff] [blame] | 69 | } |
| 70 | |
Vishwanatha Subbanna | bb8fe0b | 2016-11-12 18:29:38 +0530 | [diff] [blame^] | 71 | using group = std::set<LedAction>; |
Vishwanatha Subbanna | b21fda7 | 2016-10-17 17:46:37 +0530 | [diff] [blame] | 72 | |
Vishwanatha Subbanna | bb8fe0b | 2016-11-12 18:29:38 +0530 | [diff] [blame^] | 73 | /** @brief static global map constructed at compile time */ |
| 74 | static const std::map<std::string, group> ledMap; |
Vishwanatha Subbanna | b21fda7 | 2016-10-17 17:46:37 +0530 | [diff] [blame] | 75 | |
Vishwanatha Subbanna | bb8fe0b | 2016-11-12 18:29:38 +0530 | [diff] [blame^] | 76 | /** @brief Dbus constructs used by LED manager */ |
| 77 | sdbusplus::bus::bus bus; |
Vishwanatha Subbanna | b21fda7 | 2016-10-17 17:46:37 +0530 | [diff] [blame] | 78 | |
Vishwanatha Subbanna | bb8fe0b | 2016-11-12 18:29:38 +0530 | [diff] [blame^] | 79 | /** @brief sd_bus object manager */ |
| 80 | sdbusplus::server::manager::manager objManager; |
Vishwanatha Subbanna | b21fda7 | 2016-10-17 17:46:37 +0530 | [diff] [blame] | 81 | |
Vishwanatha Subbanna | bb8fe0b | 2016-11-12 18:29:38 +0530 | [diff] [blame^] | 82 | /** @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 Subbanna | b21fda7 | 2016-10-17 17:46:37 +0530 | [diff] [blame] | 115 | }; |
| 116 | |
| 117 | } // namespace led |
| 118 | |
| 119 | } // namespace phosphor |