Jayashree Dhanapal | b677984 | 2022-10-07 13:34:16 +0530 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include "physical.hpp" |
| 4 | |
Jayashree Dhanapal | b677984 | 2022-10-07 13:34:16 +0530 | [diff] [blame] | 5 | #include <phosphor-logging/lg2.hpp> |
| 6 | #include <sdbusplus/bus.hpp> |
| 7 | #include <sdbusplus/server/interface.hpp> |
| 8 | #include <sdbusplus/vtable.hpp> |
| 9 | |
| 10 | #include <unordered_map> |
| 11 | |
| 12 | static constexpr auto busName = "xyz.openbmc_project.LED.Controller"; |
| 13 | static constexpr auto ledPath = "/xyz/openbmc_project/led"; |
| 14 | static constexpr auto physParent = "/xyz/openbmc_project/led/physical"; |
Jayashree Dhanapal | b677984 | 2022-10-07 13:34:16 +0530 | [diff] [blame] | 15 | static constexpr auto internalInterface = |
| 16 | "xyz.openbmc_project.Led.Sysfs.Internal"; |
| 17 | static constexpr auto ledAddMethod = "AddLED"; |
| 18 | |
| 19 | namespace phosphor |
| 20 | { |
| 21 | namespace led |
| 22 | { |
| 23 | namespace sysfs |
| 24 | { |
| 25 | namespace interface |
| 26 | { |
| 27 | |
| 28 | class InternalInterface |
| 29 | { |
| 30 | public: |
| 31 | InternalInterface() = delete; |
| 32 | InternalInterface(const InternalInterface&) = delete; |
| 33 | InternalInterface& operator=(const InternalInterface&) = delete; |
| 34 | InternalInterface(InternalInterface&&) = delete; |
| 35 | InternalInterface& operator=(InternalInterface&&) = delete; |
| 36 | virtual ~InternalInterface() = default; |
| 37 | |
| 38 | /** |
| 39 | * @brief Construct a class to put object onto bus at a dbus path. |
| 40 | * |
| 41 | * @param[in] bus - D-Bus object. |
| 42 | * @param[in] path - D-Bus Path. |
| 43 | */ |
| 44 | |
| 45 | InternalInterface(sdbusplus::bus_t& bus, const char* path); |
| 46 | |
| 47 | /** |
| 48 | * @brief Implementation for the AddLed method to add |
| 49 | * the LED name to dbus path. |
| 50 | * |
| 51 | * @param[in] name - LED name to add. |
| 52 | */ |
| 53 | |
| 54 | void addLED(const std::string& name); |
| 55 | |
| 56 | /** |
| 57 | * @brief Implementation for the RemoveLed method to remove |
| 58 | * the LED name to dbus path. |
| 59 | * |
| 60 | * @param[in] name - LED name to remove. |
| 61 | */ |
| 62 | |
| 63 | void removeLED(const std::string& name); |
| 64 | |
Alexander Hansen | 673b981 | 2024-08-01 15:21:34 +0200 | [diff] [blame] | 65 | /** @brief Generates LED DBus name from LED description |
| 66 | * |
| 67 | * @param[in] name - LED description |
| 68 | * @return - DBus LED name |
| 69 | */ |
| 70 | |
| 71 | static std::string getDbusName(const LedDescr& ledDescr); |
| 72 | |
Jayashree Dhanapal | b677984 | 2022-10-07 13:34:16 +0530 | [diff] [blame] | 73 | private: |
| 74 | /** |
| 75 | * @brief Unordered map to declare the sysfs LEDs |
| 76 | */ |
| 77 | |
| 78 | std::unordered_map<std::string, std::unique_ptr<phosphor::led::Physical>> |
| 79 | leds; |
| 80 | |
| 81 | /** |
Jayashree Dhanapal | b677984 | 2022-10-07 13:34:16 +0530 | [diff] [blame] | 82 | * @brief sdbusplus D-Bus connection. |
| 83 | */ |
| 84 | |
| 85 | sdbusplus::bus_t& bus; |
| 86 | |
| 87 | /** |
| 88 | * @brief Systemd bus callback for the AddLed method. |
| 89 | */ |
| 90 | |
| 91 | static int addLedConfigure(sd_bus_message* msg, void* context, |
| 92 | sd_bus_error* error); |
| 93 | |
| 94 | /** |
| 95 | * @brief Systemd bus callback for the RemoveLed method. |
| 96 | */ |
| 97 | |
| 98 | static int removeLedConfigure(sd_bus_message* msg, void* context, |
| 99 | sd_bus_error* error); |
| 100 | |
| 101 | /** |
| 102 | * @brief Systemd vtable structure that contains all the |
| 103 | * methods, signals, and properties of this interface with their |
| 104 | * respective systemd attributes |
| 105 | */ |
| 106 | |
| 107 | static const std::array<sdbusplus::vtable::vtable_t, 4> vtable; |
| 108 | |
| 109 | /** |
| 110 | * @brief Support for the dbus based instance of this interface. |
| 111 | */ |
| 112 | |
| 113 | sdbusplus::server::interface_t serverInterface; |
| 114 | |
| 115 | /** |
| 116 | * @brief Implementation to create a dbus path for LED. |
| 117 | * |
| 118 | * @param[in] name - LED name. |
| 119 | */ |
| 120 | |
| 121 | void createLEDPath(const std::string& ledName); |
Jayashree Dhanapal | b677984 | 2022-10-07 13:34:16 +0530 | [diff] [blame] | 122 | }; |
| 123 | |
| 124 | } // namespace interface |
| 125 | } // namespace sysfs |
| 126 | } // namespace led |
| 127 | } // namespace phosphor |