1953315d2SPatrick Williams #include "config.h" 2953315d2SPatrick Williams 3953315d2SPatrick Williams #include "group.hpp" 4158b2c14SPatrick Williams #include "ledlayout.hpp" 5953315d2SPatrick Williams #ifdef LED_USE_JSON 6953315d2SPatrick Williams #include "json-parser.hpp" 7953315d2SPatrick Williams #else 8953315d2SPatrick Williams #include "led-gen.hpp" 9953315d2SPatrick Williams #endif 10953315d2SPatrick Williams #include "manager.hpp" 11953315d2SPatrick Williams #include "serialize.hpp" 12953315d2SPatrick Williams #include "utils.hpp" 13953315d2SPatrick Williams #ifdef USE_LAMP_TEST 14953315d2SPatrick Williams #include "lamptest/lamptest.hpp" 15953315d2SPatrick Williams #endif 16953315d2SPatrick Williams 177217c035SPatrick Williams #include <CLI/CLI.hpp> 18953315d2SPatrick Williams #include <sdeventplus/event.hpp> 19953315d2SPatrick Williams 20953315d2SPatrick Williams #include <algorithm> 21953315d2SPatrick Williams #include <iostream> 2254671853SGeorge Liu #include <memory> 23953315d2SPatrick Williams 247217c035SPatrick Williams int main(int argc, char** argv) 25953315d2SPatrick Williams { 267217c035SPatrick Williams CLI::App app("phosphor-led-manager"); 277217c035SPatrick Williams 287217c035SPatrick Williams #ifdef LED_USE_JSON 297217c035SPatrick Williams std::string configFile{}; 307217c035SPatrick Williams app.add_option("-c,--config", configFile, "Path to JSON config"); 317217c035SPatrick Williams #endif 327217c035SPatrick Williams 337217c035SPatrick Williams CLI11_PARSE(app, argc, argv); 347217c035SPatrick Williams 35953315d2SPatrick Williams // Get a default event loop 36953315d2SPatrick Williams auto event = sdeventplus::Event::get_default(); 37953315d2SPatrick Williams 38953315d2SPatrick Williams /** @brief Dbus constructs used by LED Group manager */ 39953315d2SPatrick Williams auto& bus = phosphor::led::utils::DBusHandler::getBus(); 40953315d2SPatrick Williams 41953315d2SPatrick Williams #ifdef LED_USE_JSON 427217c035SPatrick Williams auto systemLedMap = getSystemLedMap(configFile); 43953315d2SPatrick Williams #endif 44953315d2SPatrick Williams 45953315d2SPatrick Williams /** @brief Group manager object */ 46f1ed4796SPotin Lai phosphor::led::Manager manager(bus, systemLedMap, event); 47953315d2SPatrick Williams 48953315d2SPatrick Williams /** @brief sd_bus object manager */ 495d92f423SGeorge Liu sdbusplus::server::manager_t objManager(bus, 505d92f423SGeorge Liu "/xyz/openbmc_project/led/groups"); 51953315d2SPatrick Williams 52953315d2SPatrick Williams /** @brief vector of led groups */ 53953315d2SPatrick Williams std::vector<std::unique_ptr<phosphor::led::Group>> groups; 54953315d2SPatrick Williams 5554671853SGeorge Liu std::shared_ptr<phosphor::led::Serialize> serializePtr = nullptr; 5654671853SGeorge Liu #ifdef PERSISTENT_LED_ASSERTED 57953315d2SPatrick Williams /** @brief store and re-store Group */ 5854671853SGeorge Liu serializePtr = 5954671853SGeorge Liu std::make_shared<phosphor::led::Serialize>(SAVED_GROUPS_FILE); 6054671853SGeorge Liu #endif 61953315d2SPatrick Williams 62953315d2SPatrick Williams #ifdef USE_LAMP_TEST 63953315d2SPatrick Williams phosphor::led::LampTest lampTest(event, manager); 64953315d2SPatrick Williams 65*94e894cbSManojkiran Eda // Clear leds triggered by lamp test in previous boot 66e3515c71SSunny Srivastava lampTest.clearLamps(); 67e3515c71SSunny Srivastava 68953315d2SPatrick Williams groups.emplace_back(std::make_unique<phosphor::led::Group>( 6954671853SGeorge Liu bus, LAMP_TEST_OBJECT, manager, serializePtr, 70953315d2SPatrick Williams std::bind(std::mem_fn(&phosphor::led::LampTest::requestHandler), 71953315d2SPatrick Williams &lampTest, std::placeholders::_1, std::placeholders::_2))); 72953315d2SPatrick Williams 73953315d2SPatrick Williams // Register a lamp test method in the manager class, and call this method 74953315d2SPatrick Williams // when the lamp test is started 75953315d2SPatrick Williams manager.setLampTestCallBack( 76953315d2SPatrick Williams std::bind(std::mem_fn(&phosphor::led::LampTest::processLEDUpdates), 77953315d2SPatrick Williams &lampTest, std::placeholders::_1, std::placeholders::_2)); 78953315d2SPatrick Williams #endif 79953315d2SPatrick Williams 80953315d2SPatrick Williams /** Now create so many dbus objects as there are groups */ 81158b2c14SPatrick Williams std::ranges::transform(systemLedMap, std::back_inserter(groups), 8254671853SGeorge Liu [&bus, &manager, serializePtr](auto& grp) { 83857da383SPatrick Williams return std::make_unique<phosphor::led::Group>(bus, grp.first, manager, 8454671853SGeorge Liu serializePtr); 85953315d2SPatrick Williams }); 86953315d2SPatrick Williams 87953315d2SPatrick Williams // Attach the bus to sd_event to service user requests 88953315d2SPatrick Williams bus.attach_event(event.get(), SD_EVENT_PRIORITY_NORMAL); 89953315d2SPatrick Williams 90953315d2SPatrick Williams /** @brief Claim the bus */ 9125255212SGeorge Liu bus.request_name("xyz.openbmc_project.LED.GroupManager"); 92953315d2SPatrick Williams event.loop(); 93953315d2SPatrick Williams 94953315d2SPatrick Williams return 0; 95953315d2SPatrick Williams } 96