Create a new Dbus interface for LED

A new Dbus API method is created in the phosphor-led-sysfs repository
under xyz.openbmc_project.Led.Sysfs.Internal interface name to add or
remove the LED, which will be coming from each udev LED event to
create the LED dbus path.

xyz.openbmc_project.Led.Sysfs.Internal interface
.AddLED                                method
.RemoveLED                             method

This Dbus API method is added to support the multihost physical
LEDs design.
https://gerrit.openbmc.org/c/openbmc/docs/+/55230

Also support a executable for LED DBUS API method

Added a new executable for LED DBUS API method to communicate
between udev and application.

Executable will call Dbus API method to pass LED name as argument from
udev, after the primary service started.

Tested : Tested the dbus method is invoked for each LED udev event
in Facebook YosemiteV2 platform.

Signed-off-by: Jayashree Dhanapal <jayashree-d@hcl.com>
Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
Change-Id: I3fa6c3caa130b2b71ebc9fe8d69541c029f516ab
Signed-off-by: Alexander Hansen <alexander.hansen@9elements.com>
diff --git a/interfaces/internal_interface.hpp b/interfaces/internal_interface.hpp
new file mode 100644
index 0000000..25d530d
--- /dev/null
+++ b/interfaces/internal_interface.hpp
@@ -0,0 +1,152 @@
+#pragma once
+
+#include "physical.hpp"
+
+#include <boost/algorithm/string.hpp>
+#include <phosphor-logging/lg2.hpp>
+#include <sdbusplus/bus.hpp>
+#include <sdbusplus/server/interface.hpp>
+#include <sdbusplus/vtable.hpp>
+
+#include <unordered_map>
+
+static constexpr auto busName = "xyz.openbmc_project.LED.Controller";
+static constexpr auto ledPath = "/xyz/openbmc_project/led";
+static constexpr auto physParent = "/xyz/openbmc_project/led/physical";
+static constexpr auto devParent = "/sys/class/leds/";
+static constexpr auto internalInterface =
+    "xyz.openbmc_project.Led.Sysfs.Internal";
+static constexpr auto ledAddMethod = "AddLED";
+
+namespace phosphor
+{
+namespace led
+{
+namespace sysfs
+{
+namespace interface
+{
+
+class InternalInterface
+{
+  public:
+    InternalInterface() = delete;
+    InternalInterface(const InternalInterface&) = delete;
+    InternalInterface& operator=(const InternalInterface&) = delete;
+    InternalInterface(InternalInterface&&) = delete;
+    InternalInterface& operator=(InternalInterface&&) = delete;
+    virtual ~InternalInterface() = default;
+
+    /**
+     *  @brief Construct a class to put object onto bus at a dbus path.
+     *
+     *  @param[in] bus  - D-Bus object.
+     *  @param[in] path - D-Bus Path.
+     */
+
+    InternalInterface(sdbusplus::bus_t& bus, const char* path);
+
+    /**
+     *  @brief Implementation for the AddLed method to add
+     *  the LED name to dbus path.
+     *
+     *  @param[in] name - LED name to add.
+     */
+
+    void addLED(const std::string& name);
+
+    /**
+     *  @brief Implementation for the RemoveLed method to remove
+     *  the LED name to dbus path.
+     *
+     *  @param[in] name - LED name to remove.
+     */
+
+    void removeLED(const std::string& name);
+
+  private:
+    /**
+     *  @brief  Unordered map to declare the sysfs LEDs
+     */
+
+    std::unordered_map<std::string, std::unique_ptr<phosphor::led::Physical>>
+        leds;
+
+    /**
+     *  @brief Structure to define the LED sysfs name
+     */
+
+    struct LedDescr
+    {
+        std::string devicename;
+        std::string color;
+        std::string function;
+    };
+
+    /**
+     *  @brief sdbusplus D-Bus connection.
+     */
+
+    sdbusplus::bus_t& bus;
+
+    /**
+     *  @brief Systemd bus callback for the AddLed method.
+     */
+
+    static int addLedConfigure(sd_bus_message* msg, void* context,
+                               sd_bus_error* error);
+
+    /**
+     *  @brief Systemd bus callback for the RemoveLed method.
+     */
+
+    static int removeLedConfigure(sd_bus_message* msg, void* context,
+                                  sd_bus_error* error);
+
+    /**
+     *  @brief Systemd vtable structure that contains all the
+     *  methods, signals, and properties of this interface with their
+     *  respective systemd attributes
+     */
+
+    static const std::array<sdbusplus::vtable::vtable_t, 4> vtable;
+
+    /**
+     *  @brief Support for the dbus based instance of this interface.
+     */
+
+    sdbusplus::server::interface_t serverInterface;
+
+    /**
+     *   @brief Implementation to create a dbus path for LED.
+     *
+     *   @param[in] name - LED name.
+     */
+
+    void createLEDPath(const std::string& ledName);
+
+    /** @brief Parse LED name in sysfs
+     *
+     *  Parse sysfs LED name in format "devicename:colour:function"
+     *  or "devicename:colour" or "devicename" and sets corresponding
+     *  fields in LedDescr struct.
+     *
+     *  @param[in] name      - LED name in sysfs
+     *  @param[out] ledDescr - LED description
+     */
+
+    static void getLedDescr(const std::string& name, LedDescr& ledDescr);
+
+    /** @brief Generates LED DBus name from LED description
+     *
+     *  @param[in] name      - LED description
+     *  @return              - DBus LED name
+     */
+
+    static std::string getDbusName(const LedDescr& ledDescr);
+};
+
+} // namespace interface
+} // namespace sysfs
+} // namespace led
+} // namespace phosphor