blob: 10af42da9bf343aa6ecb37113d91a7fba54ca05b [file] [log] [blame]
Vishwanatha Subbanna4c8c72b2016-11-29 23:02:06 +05301#pragma once
2
3#include <map>
4#include <set>
Vishwanatha Subbannaed490732016-12-20 15:59:29 +05305#include "ledlayout.hpp"
Vishwanatha Subbanna4c8c72b2016-11-29 23:02:06 +05306namespace phosphor
7{
8namespace led
9{
10
11/** @class Manager
12 * @brief Manages group of LEDs and applies action on the elements of group
13 */
14class Manager
15{
16 public:
Vishwanatha Subbanna4c8c72b2016-11-29 23:02:06 +053017 /** @brief Only need the default Manager */
Vishwanatha Subbannaed490732016-12-20 15:59:29 +053018 Manager() = delete;
Vishwanatha Subbanna4c8c72b2016-11-29 23:02:06 +053019 ~Manager() = default;
20 Manager(const Manager&) = delete;
21 Manager& operator=(const Manager&) = delete;
22 Manager(Manager&&) = delete;
23 Manager& operator=(Manager&&) = delete;
24
Vishwanatha Subbanna4c8c72b2016-11-29 23:02:06 +053025 /** @brief For finding intersection */
Vishwanatha Subbannaed490732016-12-20 15:59:29 +053026 static bool ledComp(const phosphor::led::Layout::LedAction& left,
27 const phosphor::led::Layout::LedAction& right)
Vishwanatha Subbanna4c8c72b2016-11-29 23:02:06 +053028 {
29 return left.name < right.name;
30 }
31
Vishwanatha Subbannaed490732016-12-20 15:59:29 +053032 using group = std::set<phosphor::led::Layout::LedAction>;
Vishwanatha Subbanna4c8c72b2016-11-29 23:02:06 +053033
34 /** @brief static global map constructed at compile time */
Vishwanatha Subbannaed490732016-12-20 15:59:29 +053035 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 Subbanna4c8c72b2016-11-29 23:02:06 +053046
47 /** @brief Given a group name, applies the action on the group
48 *
Vishwanatha Subbannaed490732016-12-20 15:59:29 +053049 * @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 Subbanna4c8c72b2016-11-29 23:02:06 +053057 */
Vishwanatha Subbannaed490732016-12-20 15:59:29 +053058 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 Subbanna4c8c72b2016-11-29 23:02:06 +053073
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 Subbanna4c8c72b2016-11-29 23:02:06 +053081};
82
83} // namespace led
84} // namespace phosphor