blob: 1a75f8c52431df6e2e08bcaa7360d0c178559882 [file] [log] [blame]
Vishwanatha Subbanna4c8c72b2016-11-29 23:02:06 +05301#pragma once
2
3#include <map>
4#include <set>
Vishwanatha Subbanna11ca8f92017-02-27 19:33:45 +05305#include <sdbusplus/bus.hpp>
Vishwanatha Subbannaed490732016-12-20 15:59:29 +05306#include "ledlayout.hpp"
Vishwanatha Subbanna4c8c72b2016-11-29 23:02:06 +05307namespace phosphor
8{
9namespace led
10{
11
Vishwanatha Subbanna11ca8f92017-02-27 19:33:45 +053012/** @brief Physical LED dbus constructs */
13constexpr auto PHY_LED_PATH = "/xyz/openbmc_project/led/physical/";
14constexpr auto PHY_LED_IFACE = "xyz.openbmc_project.Led.Physical";
15constexpr auto DBUS_PROPERTY_IFACE = "org.freedesktop.DBus.Properties";
16
Vishwanatha Subbanna4c8c72b2016-11-29 23:02:06 +053017/** @class Manager
18 * @brief Manages group of LEDs and applies action on the elements of group
19 */
20class Manager
21{
22 public:
Vishwanatha Subbanna4c8c72b2016-11-29 23:02:06 +053023 /** @brief Only need the default Manager */
Vishwanatha Subbannaed490732016-12-20 15:59:29 +053024 Manager() = delete;
Vishwanatha Subbanna4c8c72b2016-11-29 23:02:06 +053025 ~Manager() = default;
26 Manager(const Manager&) = delete;
27 Manager& operator=(const Manager&) = delete;
28 Manager(Manager&&) = delete;
29 Manager& operator=(Manager&&) = delete;
30
Vishwanatha Subbanna4c8c72b2016-11-29 23:02:06 +053031 /** @brief For finding intersection */
Vishwanatha Subbannaed490732016-12-20 15:59:29 +053032 static bool ledComp(const phosphor::led::Layout::LedAction& left,
33 const phosphor::led::Layout::LedAction& right)
Vishwanatha Subbanna4c8c72b2016-11-29 23:02:06 +053034 {
35 return left.name < right.name;
36 }
37
Vishwanatha Subbannaed490732016-12-20 15:59:29 +053038 using group = std::set<phosphor::led::Layout::LedAction>;
Vishwanatha Subbanna11ca8f92017-02-27 19:33:45 +053039 using LedLayout = std::map<std::string, group>;
Vishwanatha Subbanna4c8c72b2016-11-29 23:02:06 +053040
41 /** @brief static global map constructed at compile time */
Vishwanatha Subbanna11ca8f92017-02-27 19:33:45 +053042 const LedLayout& ledMap;
Vishwanatha Subbannaed490732016-12-20 15:59:29 +053043
Vishwanatha Subbanna11ca8f92017-02-27 19:33:45 +053044 /** @brief Refer the user supplied LED layout and sdbusplus handler
Vishwanatha Subbannaed490732016-12-20 15:59:29 +053045 *
Vishwanatha Subbanna11ca8f92017-02-27 19:33:45 +053046 * @param [in] bus - sdbusplus handler
47 * @param [in] LedLayout - LEDs group layout
Vishwanatha Subbannaed490732016-12-20 15:59:29 +053048 */
Vishwanatha Subbanna11ca8f92017-02-27 19:33:45 +053049 Manager(sdbusplus::bus::bus& bus,
50 const LedLayout& ledLayout)
51 : ledMap(ledLayout),
52 bus(bus)
Vishwanatha Subbannaed490732016-12-20 15:59:29 +053053 {
54 // Nothing here
55 }
Vishwanatha Subbanna4c8c72b2016-11-29 23:02:06 +053056
57 /** @brief Given a group name, applies the action on the group
58 *
Vishwanatha Subbannaed490732016-12-20 15:59:29 +053059 * @param[in] path - dbus path of group
60 * @param[in] assert - Could be true or false
61 * @param[in] ledsAssert - LEDs that are to be asserted newly
62 * @param[in] ledsDeAssert - LEDs that are to be Deasserted
63 * @param[in] ledsUpdate - LEDs that need a transition between
64 * different types of asserted states.
65 *
66 * @return - Success or exception thrown
Vishwanatha Subbanna4c8c72b2016-11-29 23:02:06 +053067 */
Vishwanatha Subbannaed490732016-12-20 15:59:29 +053068 bool setGroupState(const std::string& path, bool assert,
69 group& ledsAssert, group& ledsDeAssert,
70 group& ledsUpdate);
71
72 /** @brief Finds the set of LEDs to operate on and executes action
73 *
74 * @param[in] ledsAssert - LEDs that are to be asserted newly
75 * @param[in] ledsDeAssert - LEDs that are to be Deasserted
76 * @param[in] ledsUpdate - LEDs that need a transition between
77 * different types of asserted states.
78 *
79 * @return: None
80 */
81 void driveLEDs(group& ledsAssert, group& ledsDeAssert,
82 group& ledsUpdate);
Vishwanatha Subbanna4c8c72b2016-11-29 23:02:06 +053083
84 private:
Vishwanatha Subbanna11ca8f92017-02-27 19:33:45 +053085 /** @brief sdbusplus handler */
86 sdbusplus::bus::bus& bus;
87
Vishwanatha Subbannadcc3f382017-03-24 20:15:02 +053088 /** Map of physical LED path to service name */
89 std::map<std::string, std::string> phyLeds {};
90
Vishwanatha Subbanna4c8c72b2016-11-29 23:02:06 +053091 /** @brief Pointers to groups that are in asserted state */
92 std::set<const group*> assertedGroups;
93
94 /** @brief Contains the LEDs that are in asserted state */
95 group currentState;
96
Vishwanatha Subbanna11ca8f92017-02-27 19:33:45 +053097 /** @brief Returns action string based on enum
98 *
99 * @param[in] action - Action enum
100 *
101 * @return string equivalent of the passed in enumeration
102 */
Vishwanatha Subbanna4fa92482017-03-10 14:39:20 +0530103 static std::string getPhysicalAction(Layout::Action action);
Vishwanatha Subbanna11ca8f92017-02-27 19:33:45 +0530104
105 /** @brief Chooses appropriate action to be triggered on physical LED
106 * and calls into function that applies the actual action.
107 *
108 * @param[in] objPath - dbus object path
109 * @param[in] action - Intended action to be triggered
110 * @param[in] dutyOn - Duty Cycle ON percentage
111 */
112 void drivePhysicalLED(const std::string& objPath,
113 Layout::Action action,
114 uint8_t dutyOn);
115
116 /** @brief Makes a dbus call to a passed in service name.
117 * This is now the physical LED controller
118 *
119 * @param[in] service - dbus service name
120 * @param[in] objPath - dbus object path
121 * @param[in] property - property to be written to
122 * @param[in] value - Value to write
123 */
124 template <typename T>
125 void drivePhysicalLED(const std::string& service,
126 const std::string& objPath,
127 const std::string& property,
128 const T& value)
129 {
130 sdbusplus::message::variant<T> data = value;
131
132 auto method = bus.new_method_call(service.c_str(), objPath.c_str(),
133 DBUS_PROPERTY_IFACE, "Set");
134 method.append(PHY_LED_IFACE);
135 method.append(property);
136 method.append(data);
137
138 // There will be exceptions going forward and hence don't need a
139 // response
140 bus.call_noreply(method);
141 return;
142 }
143
Vishwanatha Subbannadcc3f382017-03-24 20:15:02 +0530144 /** @brief Populates map of Physical LED paths to service name */
145 void populateObjectMap();
Vishwanatha Subbanna4c8c72b2016-11-29 23:02:06 +0530146};
147
148} // namespace led
149} // namespace phosphor