Vishwanatha Subbanna | 4c8c72b | 2016-11-29 23:02:06 +0530 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include <map> |
| 4 | #include <set> |
Vishwanatha Subbanna | ed49073 | 2016-12-20 15:59:29 +0530 | [diff] [blame^] | 5 | #include "ledlayout.hpp" |
Vishwanatha Subbanna | 4c8c72b | 2016-11-29 23:02:06 +0530 | [diff] [blame] | 6 | namespace phosphor |
| 7 | { |
| 8 | namespace led |
| 9 | { |
| 10 | |
| 11 | /** @class Manager |
| 12 | * @brief Manages group of LEDs and applies action on the elements of group |
| 13 | */ |
| 14 | class Manager |
| 15 | { |
| 16 | public: |
Vishwanatha Subbanna | 4c8c72b | 2016-11-29 23:02:06 +0530 | [diff] [blame] | 17 | /** @brief Only need the default Manager */ |
Vishwanatha Subbanna | ed49073 | 2016-12-20 15:59:29 +0530 | [diff] [blame^] | 18 | Manager() = delete; |
Vishwanatha Subbanna | 4c8c72b | 2016-11-29 23:02:06 +0530 | [diff] [blame] | 19 | ~Manager() = default; |
| 20 | Manager(const Manager&) = delete; |
| 21 | Manager& operator=(const Manager&) = delete; |
| 22 | Manager(Manager&&) = delete; |
| 23 | Manager& operator=(Manager&&) = delete; |
| 24 | |
Vishwanatha Subbanna | 4c8c72b | 2016-11-29 23:02:06 +0530 | [diff] [blame] | 25 | /** @brief For finding intersection */ |
Vishwanatha Subbanna | ed49073 | 2016-12-20 15:59:29 +0530 | [diff] [blame^] | 26 | static bool ledComp(const phosphor::led::Layout::LedAction& left, |
| 27 | const phosphor::led::Layout::LedAction& right) |
Vishwanatha Subbanna | 4c8c72b | 2016-11-29 23:02:06 +0530 | [diff] [blame] | 28 | { |
| 29 | return left.name < right.name; |
| 30 | } |
| 31 | |
Vishwanatha Subbanna | ed49073 | 2016-12-20 15:59:29 +0530 | [diff] [blame^] | 32 | using group = std::set<phosphor::led::Layout::LedAction>; |
Vishwanatha Subbanna | 4c8c72b | 2016-11-29 23:02:06 +0530 | [diff] [blame] | 33 | |
| 34 | /** @brief static global map constructed at compile time */ |
Vishwanatha Subbanna | ed49073 | 2016-12-20 15:59:29 +0530 | [diff] [blame^] | 35 | const std::map<std::string, group>& ledMap; |
| 36 | |
| 37 | /** @brief Refer the user supplied LED layout. |
| 38 | * |
| 39 | * @param [in] ledLayout - LEDs group layout |
| 40 | */ |
| 41 | explicit Manager(const std::map<std::string, Manager::group>& ledLayout) |
| 42 | : ledMap(ledLayout) |
| 43 | { |
| 44 | // Nothing here |
| 45 | } |
Vishwanatha Subbanna | 4c8c72b | 2016-11-29 23:02:06 +0530 | [diff] [blame] | 46 | |
| 47 | /** @brief Given a group name, applies the action on the group |
| 48 | * |
Vishwanatha Subbanna | ed49073 | 2016-12-20 15:59:29 +0530 | [diff] [blame^] | 49 | * @param[in] path - dbus path of group |
| 50 | * @param[in] assert - Could be true or false |
| 51 | * @param[in] ledsAssert - LEDs that are to be asserted newly |
| 52 | * @param[in] ledsDeAssert - LEDs that are to be Deasserted |
| 53 | * @param[in] ledsUpdate - LEDs that need a transition between |
| 54 | * different types of asserted states. |
| 55 | * |
| 56 | * @return - Success or exception thrown |
Vishwanatha Subbanna | 4c8c72b | 2016-11-29 23:02:06 +0530 | [diff] [blame] | 57 | */ |
Vishwanatha Subbanna | ed49073 | 2016-12-20 15:59:29 +0530 | [diff] [blame^] | 58 | bool setGroupState(const std::string& path, bool assert, |
| 59 | group& ledsAssert, group& ledsDeAssert, |
| 60 | group& ledsUpdate); |
| 61 | |
| 62 | /** @brief Finds the set of LEDs to operate on and executes action |
| 63 | * |
| 64 | * @param[in] ledsAssert - LEDs that are to be asserted newly |
| 65 | * @param[in] ledsDeAssert - LEDs that are to be Deasserted |
| 66 | * @param[in] ledsUpdate - LEDs that need a transition between |
| 67 | * different types of asserted states. |
| 68 | * |
| 69 | * @return: None |
| 70 | */ |
| 71 | void driveLEDs(group& ledsAssert, group& ledsDeAssert, |
| 72 | group& ledsUpdate); |
Vishwanatha Subbanna | 4c8c72b | 2016-11-29 23:02:06 +0530 | [diff] [blame] | 73 | |
| 74 | private: |
| 75 | /** @brief Pointers to groups that are in asserted state */ |
| 76 | std::set<const group*> assertedGroups; |
| 77 | |
| 78 | /** @brief Contains the LEDs that are in asserted state */ |
| 79 | group currentState; |
| 80 | |
Vishwanatha Subbanna | 4c8c72b | 2016-11-29 23:02:06 +0530 | [diff] [blame] | 81 | }; |
| 82 | |
| 83 | } // namespace led |
| 84 | } // namespace phosphor |