1953315d2SPatrick Williams #include "config.h" 2953315d2SPatrick Williams 3953315d2SPatrick Williams #include "group.hpp" 4953315d2SPatrick Williams #ifdef LED_USE_JSON 5953315d2SPatrick Williams #include "json-parser.hpp" 6953315d2SPatrick Williams #else 7953315d2SPatrick Williams #include "led-gen.hpp" 8953315d2SPatrick Williams #endif 9953315d2SPatrick Williams #include "ledlayout.hpp" 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 17*7217c035SPatrick Williams #include <CLI/CLI.hpp> 18953315d2SPatrick Williams #include <sdeventplus/event.hpp> 19953315d2SPatrick Williams 20953315d2SPatrick Williams #include <algorithm> 21953315d2SPatrick Williams #include <iostream> 22953315d2SPatrick Williams 23*7217c035SPatrick Williams int main(int argc, char** argv) 24953315d2SPatrick Williams { 25*7217c035SPatrick Williams CLI::App app("phosphor-led-manager"); 26*7217c035SPatrick Williams 27*7217c035SPatrick Williams #ifdef LED_USE_JSON 28*7217c035SPatrick Williams std::string configFile{}; 29*7217c035SPatrick Williams app.add_option("-c,--config", configFile, "Path to JSON config"); 30*7217c035SPatrick Williams #endif 31*7217c035SPatrick Williams 32*7217c035SPatrick Williams CLI11_PARSE(app, argc, argv); 33*7217c035SPatrick Williams 34953315d2SPatrick Williams // Get a default event loop 35953315d2SPatrick Williams auto event = sdeventplus::Event::get_default(); 36953315d2SPatrick Williams 37953315d2SPatrick Williams /** @brief Dbus constructs used by LED Group manager */ 38953315d2SPatrick Williams auto& bus = phosphor::led::utils::DBusHandler::getBus(); 39953315d2SPatrick Williams 40953315d2SPatrick Williams #ifdef LED_USE_JSON 41*7217c035SPatrick Williams auto systemLedMap = getSystemLedMap(configFile); 42953315d2SPatrick Williams #endif 43953315d2SPatrick Williams 44953315d2SPatrick Williams /** @brief Group manager object */ 45953315d2SPatrick Williams phosphor::led::Manager manager(bus, systemLedMap); 46953315d2SPatrick Williams 47953315d2SPatrick Williams /** @brief sd_bus object manager */ 48953315d2SPatrick Williams sdbusplus::server::manager::manager objManager(bus, OBJPATH); 49953315d2SPatrick Williams 50953315d2SPatrick Williams /** @brief vector of led groups */ 51953315d2SPatrick Williams std::vector<std::unique_ptr<phosphor::led::Group>> groups; 52953315d2SPatrick Williams 53953315d2SPatrick Williams /** @brief store and re-store Group */ 54953315d2SPatrick Williams phosphor::led::Serialize serialize(SAVED_GROUPS_FILE); 55953315d2SPatrick Williams 56953315d2SPatrick Williams #ifdef USE_LAMP_TEST 57953315d2SPatrick Williams phosphor::led::LampTest lampTest(event, manager); 58953315d2SPatrick Williams 59953315d2SPatrick Williams groups.emplace_back(std::make_unique<phosphor::led::Group>( 60953315d2SPatrick Williams bus, LAMP_TEST_OBJECT, manager, serialize, 61953315d2SPatrick Williams std::bind(std::mem_fn(&phosphor::led::LampTest::requestHandler), 62953315d2SPatrick Williams &lampTest, std::placeholders::_1, std::placeholders::_2))); 63953315d2SPatrick Williams 64953315d2SPatrick Williams // Register a lamp test method in the manager class, and call this method 65953315d2SPatrick Williams // when the lamp test is started 66953315d2SPatrick Williams manager.setLampTestCallBack( 67953315d2SPatrick Williams std::bind(std::mem_fn(&phosphor::led::LampTest::processLEDUpdates), 68953315d2SPatrick Williams &lampTest, std::placeholders::_1, std::placeholders::_2)); 69953315d2SPatrick Williams #endif 70953315d2SPatrick Williams 71953315d2SPatrick Williams /** Now create so many dbus objects as there are groups */ 72953315d2SPatrick Williams std::ranges::transform( 73953315d2SPatrick Williams systemLedMap, std::back_inserter(groups), 74953315d2SPatrick Williams [&bus, &manager, &serialize]( 75953315d2SPatrick Williams const std::pair<std::string, 76953315d2SPatrick Williams std::set<phosphor::led::Layout::LedAction>>& grp) { 77953315d2SPatrick Williams return std::make_unique<phosphor::led::Group>(bus, grp.first, 78953315d2SPatrick Williams manager, serialize); 79953315d2SPatrick Williams }); 80953315d2SPatrick Williams 81953315d2SPatrick Williams // Attach the bus to sd_event to service user requests 82953315d2SPatrick Williams bus.attach_event(event.get(), SD_EVENT_PRIORITY_NORMAL); 83953315d2SPatrick Williams 84953315d2SPatrick Williams /** @brief Claim the bus */ 85953315d2SPatrick Williams bus.request_name(BUSNAME); 86953315d2SPatrick Williams event.loop(); 87953315d2SPatrick Williams 88953315d2SPatrick Williams return 0; 89953315d2SPatrick Williams } 90