Vishwanatha Subbanna | 4c8c72b | 2016-11-29 23:02:06 +0530 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include <map> |
| 4 | #include <set> |
Vishwanatha Subbanna | 11ca8f9 | 2017-02-27 19:33:45 +0530 | [diff] [blame] | 5 | #include <sdbusplus/bus.hpp> |
Vishwanatha Subbanna | ed49073 | 2016-12-20 15:59:29 +0530 | [diff] [blame] | 6 | #include "ledlayout.hpp" |
Vishwanatha Subbanna | 4c8c72b | 2016-11-29 23:02:06 +0530 | [diff] [blame] | 7 | namespace phosphor |
| 8 | { |
| 9 | namespace led |
| 10 | { |
| 11 | |
Vishwanatha Subbanna | 11ca8f9 | 2017-02-27 19:33:45 +0530 | [diff] [blame] | 12 | /** @brief Physical LED dbus constructs */ |
| 13 | constexpr auto PHY_LED_PATH = "/xyz/openbmc_project/led/physical/"; |
| 14 | constexpr auto PHY_LED_IFACE = "xyz.openbmc_project.Led.Physical"; |
| 15 | constexpr auto DBUS_PROPERTY_IFACE = "org.freedesktop.DBus.Properties"; |
| 16 | |
Vishwanatha Subbanna | 4c8c72b | 2016-11-29 23:02:06 +0530 | [diff] [blame] | 17 | /** @class Manager |
| 18 | * @brief Manages group of LEDs and applies action on the elements of group |
| 19 | */ |
| 20 | class Manager |
| 21 | { |
| 22 | public: |
Vishwanatha Subbanna | 4c8c72b | 2016-11-29 23:02:06 +0530 | [diff] [blame] | 23 | /** @brief Only need the default Manager */ |
Vishwanatha Subbanna | ed49073 | 2016-12-20 15:59:29 +0530 | [diff] [blame] | 24 | Manager() = delete; |
Vishwanatha Subbanna | 4c8c72b | 2016-11-29 23:02:06 +0530 | [diff] [blame] | 25 | ~Manager() = default; |
| 26 | Manager(const Manager&) = delete; |
| 27 | Manager& operator=(const Manager&) = delete; |
| 28 | Manager(Manager&&) = delete; |
| 29 | Manager& operator=(Manager&&) = delete; |
| 30 | |
Vishwanatha Subbanna | 4c8c72b | 2016-11-29 23:02:06 +0530 | [diff] [blame] | 31 | /** @brief For finding intersection */ |
Vishwanatha Subbanna | ed49073 | 2016-12-20 15:59:29 +0530 | [diff] [blame] | 32 | static bool ledComp(const phosphor::led::Layout::LedAction& left, |
| 33 | const phosphor::led::Layout::LedAction& right) |
Vishwanatha Subbanna | 4c8c72b | 2016-11-29 23:02:06 +0530 | [diff] [blame] | 34 | { |
| 35 | return left.name < right.name; |
| 36 | } |
| 37 | |
Vishwanatha Subbanna | ed49073 | 2016-12-20 15:59:29 +0530 | [diff] [blame] | 38 | using group = std::set<phosphor::led::Layout::LedAction>; |
Vishwanatha Subbanna | 11ca8f9 | 2017-02-27 19:33:45 +0530 | [diff] [blame] | 39 | using LedLayout = std::map<std::string, group>; |
Vishwanatha Subbanna | 4c8c72b | 2016-11-29 23:02:06 +0530 | [diff] [blame] | 40 | |
| 41 | /** @brief static global map constructed at compile time */ |
Vishwanatha Subbanna | 11ca8f9 | 2017-02-27 19:33:45 +0530 | [diff] [blame] | 42 | const LedLayout& ledMap; |
Vishwanatha Subbanna | ed49073 | 2016-12-20 15:59:29 +0530 | [diff] [blame] | 43 | |
Vishwanatha Subbanna | 11ca8f9 | 2017-02-27 19:33:45 +0530 | [diff] [blame] | 44 | /** @brief Refer the user supplied LED layout and sdbusplus handler |
Vishwanatha Subbanna | ed49073 | 2016-12-20 15:59:29 +0530 | [diff] [blame] | 45 | * |
Vishwanatha Subbanna | 11ca8f9 | 2017-02-27 19:33:45 +0530 | [diff] [blame] | 46 | * @param [in] bus - sdbusplus handler |
| 47 | * @param [in] LedLayout - LEDs group layout |
Vishwanatha Subbanna | ed49073 | 2016-12-20 15:59:29 +0530 | [diff] [blame] | 48 | */ |
Vishwanatha Subbanna | 11ca8f9 | 2017-02-27 19:33:45 +0530 | [diff] [blame] | 49 | Manager(sdbusplus::bus::bus& bus, |
| 50 | const LedLayout& ledLayout) |
| 51 | : ledMap(ledLayout), |
| 52 | bus(bus) |
Vishwanatha Subbanna | ed49073 | 2016-12-20 15:59:29 +0530 | [diff] [blame] | 53 | { |
| 54 | // Nothing here |
| 55 | } |
Vishwanatha Subbanna | 4c8c72b | 2016-11-29 23:02:06 +0530 | [diff] [blame] | 56 | |
| 57 | /** @brief Given a group name, applies the action on the group |
| 58 | * |
Vishwanatha Subbanna | ed49073 | 2016-12-20 15:59:29 +0530 | [diff] [blame] | 59 | * @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 Subbanna | 4c8c72b | 2016-11-29 23:02:06 +0530 | [diff] [blame] | 67 | */ |
Vishwanatha Subbanna | ed49073 | 2016-12-20 15:59:29 +0530 | [diff] [blame] | 68 | 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 Subbanna | 4c8c72b | 2016-11-29 23:02:06 +0530 | [diff] [blame] | 83 | |
| 84 | private: |
Vishwanatha Subbanna | 11ca8f9 | 2017-02-27 19:33:45 +0530 | [diff] [blame] | 85 | /** @brief sdbusplus handler */ |
| 86 | sdbusplus::bus::bus& bus; |
| 87 | |
Vishwanatha Subbanna | 4c8c72b | 2016-11-29 23:02:06 +0530 | [diff] [blame] | 88 | /** @brief Pointers to groups that are in asserted state */ |
| 89 | std::set<const group*> assertedGroups; |
| 90 | |
| 91 | /** @brief Contains the LEDs that are in asserted state */ |
| 92 | group currentState; |
| 93 | |
Vishwanatha Subbanna | 11ca8f9 | 2017-02-27 19:33:45 +0530 | [diff] [blame] | 94 | /** @brief Returns action string based on enum |
| 95 | * |
| 96 | * @param[in] action - Action enum |
| 97 | * |
| 98 | * @return string equivalent of the passed in enumeration |
| 99 | */ |
Vishwanatha Subbanna | 4fa9248 | 2017-03-10 14:39:20 +0530 | [diff] [blame^] | 100 | static std::string getPhysicalAction(Layout::Action action); |
Vishwanatha Subbanna | 11ca8f9 | 2017-02-27 19:33:45 +0530 | [diff] [blame] | 101 | |
| 102 | /** @brief Chooses appropriate action to be triggered on physical LED |
| 103 | * and calls into function that applies the actual action. |
| 104 | * |
| 105 | * @param[in] objPath - dbus object path |
| 106 | * @param[in] action - Intended action to be triggered |
| 107 | * @param[in] dutyOn - Duty Cycle ON percentage |
| 108 | */ |
| 109 | void drivePhysicalLED(const std::string& objPath, |
| 110 | Layout::Action action, |
| 111 | uint8_t dutyOn); |
| 112 | |
| 113 | /** @brief Makes a dbus call to a passed in service name. |
| 114 | * This is now the physical LED controller |
| 115 | * |
| 116 | * @param[in] service - dbus service name |
| 117 | * @param[in] objPath - dbus object path |
| 118 | * @param[in] property - property to be written to |
| 119 | * @param[in] value - Value to write |
| 120 | */ |
| 121 | template <typename T> |
| 122 | void drivePhysicalLED(const std::string& service, |
| 123 | const std::string& objPath, |
| 124 | const std::string& property, |
| 125 | const T& value) |
| 126 | { |
| 127 | sdbusplus::message::variant<T> data = value; |
| 128 | |
| 129 | auto method = bus.new_method_call(service.c_str(), objPath.c_str(), |
| 130 | DBUS_PROPERTY_IFACE, "Set"); |
| 131 | method.append(PHY_LED_IFACE); |
| 132 | method.append(property); |
| 133 | method.append(data); |
| 134 | |
| 135 | // There will be exceptions going forward and hence don't need a |
| 136 | // response |
| 137 | bus.call_noreply(method); |
| 138 | return; |
| 139 | } |
| 140 | |
| 141 | /** @brief Finds the service name given a dbus object path and interface |
| 142 | * |
| 143 | * @param[in] objPath - dbus object path |
| 144 | * @param[in] interface - dbus interface |
| 145 | * |
| 146 | * @return: Service name or none |
| 147 | */ |
| 148 | std::string getServiceName(const std::string& objPath, |
| 149 | const std::string& interface) const; |
Vishwanatha Subbanna | 4c8c72b | 2016-11-29 23:02:06 +0530 | [diff] [blame] | 150 | }; |
| 151 | |
| 152 | } // namespace led |
| 153 | } // namespace phosphor |