Add lampTest class for LED

- Add the framework of the lamp test class.

- For the lamp test path in led group, Initiate lamp test when the
  Asserted property is true, Stop the lamp test when the Asserted
  property is false or the timer expires.

Tested:
- stat lamp test:
  busctl set-property xyz.openbmc_project.LED.GroupManager
  /xyz/openbmc_project/led/groups/lamp_test
  xyz.openbmc_project.Led.Group  Asserted b true

- stop lamp test:
  busctl set-property xyz.openbmc_project.LED.GroupManager
  /xyz/openbmc_project/led/groups/lamp_test
  xyz.openbmc_project.Led.Group  Asserted b false

Signed-off-by: George Liu <liuxiwei@inspur.com>
Change-Id: I7e6fe0ffc4679288ab90050742d2680051e61905
diff --git a/led-main.cpp b/led-main.cpp
index 8dcfff6..7857e91 100644
--- a/led-main.cpp
+++ b/led-main.cpp
@@ -10,11 +10,19 @@
 #include "manager.hpp"
 #include "serialize.hpp"
 #include "utils.hpp"
+#ifdef USE_LAMP_TEST
+#include "lamptest.hpp"
+#endif
+
+#include <sdeventplus/event.hpp>
 
 #include <iostream>
 
 int main(void)
 {
+    // Get a default event loop
+    auto event = sdeventplus::Event::get_default();
+
     /** @brief Dbus constructs used by LED Group manager */
     auto& bus = phosphor::led::utils::DBusHandler::getBus();
 
@@ -34,6 +42,15 @@
     /** @brief store and re-store Group */
     phosphor::led::Serialize serialize(SAVED_GROUPS_FILE);
 
+#ifdef USE_LAMP_TEST
+    phosphor::led::LampTest lampTest(event, manager);
+
+    groups.emplace_back(std::make_unique<phosphor::led::Group>(
+        bus, LAMP_TEST_OBJECT, manager, serialize,
+        std::bind(std::mem_fn(&phosphor::led::LampTest::requestHandler),
+                  &lampTest, std::placeholders::_1)));
+#endif
+
     /** Now create so many dbus objects as there are groups */
     for (auto& grp : systemLedMap)
     {
@@ -41,15 +58,12 @@
             bus, grp.first, manager, serialize));
     }
 
+    // Attach the bus to sd_event to service user requests
+    bus.attach_event(event.get(), SD_EVENT_PRIORITY_NORMAL);
+
     /** @brief Claim the bus */
     bus.request_name(BUSNAME);
+    event.loop();
 
-    /** @brief Wait for client requests */
-    while (true)
-    {
-        /** @brief process dbus calls / signals discarding unhandled */
-        bus.process_discard();
-        bus.wait();
-    }
     return 0;
 }