1 #include "config.h" 2 3 #include "group.hpp" 4 #include "ledlayout.hpp" 5 #ifdef LED_USE_JSON 6 #include "json-parser.hpp" 7 #else 8 #include "led-gen.hpp" 9 #endif 10 #include "manager.hpp" 11 #include "serialize.hpp" 12 #include "utils.hpp" 13 #ifdef USE_LAMP_TEST 14 #include "lamptest/lamptest.hpp" 15 #endif 16 17 #include <CLI/CLI.hpp> 18 #include <sdeventplus/event.hpp> 19 20 #include <algorithm> 21 #include <iostream> 22 23 int main(int argc, char** argv) 24 { 25 CLI::App app("phosphor-led-manager"); 26 27 #ifdef LED_USE_JSON 28 std::string configFile{}; 29 app.add_option("-c,--config", configFile, "Path to JSON config"); 30 #endif 31 32 CLI11_PARSE(app, argc, argv); 33 34 // Get a default event loop 35 auto event = sdeventplus::Event::get_default(); 36 37 /** @brief Dbus constructs used by LED Group manager */ 38 auto& bus = phosphor::led::utils::DBusHandler::getBus(); 39 40 #ifdef LED_USE_JSON 41 auto systemLedMap = getSystemLedMap(configFile); 42 #endif 43 44 /** @brief Group manager object */ 45 phosphor::led::Manager manager(bus, systemLedMap); 46 47 /** @brief sd_bus object manager */ 48 sdbusplus::server::manager::manager objManager(bus, OBJPATH); 49 50 /** @brief vector of led groups */ 51 std::vector<std::unique_ptr<phosphor::led::Group>> groups; 52 53 /** @brief store and re-store Group */ 54 phosphor::led::Serialize serialize(SAVED_GROUPS_FILE); 55 56 #ifdef USE_LAMP_TEST 57 phosphor::led::LampTest lampTest(event, manager); 58 59 groups.emplace_back(std::make_unique<phosphor::led::Group>( 60 bus, LAMP_TEST_OBJECT, manager, serialize, 61 std::bind(std::mem_fn(&phosphor::led::LampTest::requestHandler), 62 &lampTest, std::placeholders::_1, std::placeholders::_2))); 63 64 // Register a lamp test method in the manager class, and call this method 65 // when the lamp test is started 66 manager.setLampTestCallBack( 67 std::bind(std::mem_fn(&phosphor::led::LampTest::processLEDUpdates), 68 &lampTest, std::placeholders::_1, std::placeholders::_2)); 69 #endif 70 71 /** Now create so many dbus objects as there are groups */ 72 std::ranges::transform(systemLedMap, std::back_inserter(groups), 73 [&bus, &manager, &serialize](auto& grp) { 74 return std::make_unique<phosphor::led::Group>( 75 bus, grp.first, manager, serialize); 76 }); 77 78 // Attach the bus to sd_event to service user requests 79 bus.attach_event(event.get(), SD_EVENT_PRIORITY_NORMAL); 80 81 /** @brief Claim the bus */ 82 bus.request_name(BUSNAME); 83 event.loop(); 84 85 return 0; 86 } 87