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