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