blob: 5618c4c69ab64798e0d7681a0e424b8101cc9299 [file] [log] [blame]
Patrick Venture91ac8d32018-11-01 17:03:22 -07001#include "config.h"
2
Alexander Hansenc0f7a8b2024-08-23 19:44:22 +02003#include "config-validator.hpp"
Alexander Hansen89caaaf2025-01-30 11:17:50 +01004#include "group.hpp"
5#include "json-parser.hpp"
Alexander Hansenb3c7d372026-01-07 12:35:58 +01006#include "lamptest/lamptest.hpp"
Alexander Hansen89caaaf2025-01-30 11:17:50 +01007#include "ledlayout.hpp"
Vishwanatha Subbanna4c8c72b2016-11-29 23:02:06 +05308#include "manager.hpp"
George Liu2098aa62020-05-09 11:26:35 +08009#include "serialize.hpp"
George Liu1c737af2020-10-16 09:07:02 +080010#include "utils.hpp"
George Liuc777bef2020-11-23 17:04:21 +080011
Patrick Williams7217c032022-03-16 16:26:09 -050012#include <CLI/CLI.hpp>
George Liuc777bef2020-11-23 17:04:21 +080013#include <sdeventplus/event.hpp>
Patrick Venture91ac8d32018-11-01 17:03:22 -070014
George Liuc5e0f312021-12-27 15:54:31 +080015#include <algorithm>
Patrick Venture91ac8d32018-11-01 17:03:22 -070016#include <iostream>
George Liu54671852023-10-30 09:09:39 +080017#include <memory>
Vishwanatha Subbannab21fda72016-10-17 17:46:37 +053018
Patrick Williams7217c032022-03-16 16:26:09 -050019int main(int argc, char** argv)
Vishwanatha Subbannab21fda72016-10-17 17:46:37 +053020{
Patrick Williams7217c032022-03-16 16:26:09 -050021 CLI::App app("phosphor-led-manager");
22
Patrick Williams7217c032022-03-16 16:26:09 -050023 std::string configFile{};
24 app.add_option("-c,--config", configFile, "Path to JSON config");
Patrick Williams7217c032022-03-16 16:26:09 -050025
26 CLI11_PARSE(app, argc, argv);
27
George Liuc777bef2020-11-23 17:04:21 +080028 // Get a default event loop
29 auto event = sdeventplus::Event::get_default();
30
Vishwanatha Subbanna4c8c72b2016-11-29 23:02:06 +053031 /** @brief Dbus constructs used by LED Group manager */
George Liu1c737af2020-10-16 09:07:02 +080032 auto& bus = phosphor::led::utils::DBusHandler::getBus();
Vishwanatha Subbanna4c8c72b2016-11-29 23:02:06 +053033
Patrick Williams7217c032022-03-16 16:26:09 -050034 auto systemLedMap = getSystemLedMap(configFile);
George Liudef5f5a2020-04-10 11:23:52 +080035
Alexander Hansen638d1482024-08-21 17:39:57 +020036 phosphor::led::validateConfigV1(systemLedMap);
37
Vishwanatha Subbanna11ca8f92017-02-27 19:33:45 +053038 /** @brief Group manager object */
Potin Laif1ed4792023-07-13 18:45:14 +080039 phosphor::led::Manager manager(bus, systemLedMap, event);
Vishwanatha Subbanna11ca8f92017-02-27 19:33:45 +053040
Vishwanatha Subbanna4c8c72b2016-11-29 23:02:06 +053041 /** @brief sd_bus object manager */
George Liu5d92f422023-07-19 09:18:24 +080042 sdbusplus::server::manager_t objManager(bus,
43 "/xyz/openbmc_project/led/groups");
Vishwanatha Subbanna4c8c72b2016-11-29 23:02:06 +053044
45 /** @brief vector of led groups */
46 std::vector<std::unique_ptr<phosphor::led::Group>> groups;
47
George Liu54671852023-10-30 09:09:39 +080048 std::shared_ptr<phosphor::led::Serialize> serializePtr = nullptr;
Alexander Hansen68e204c2026-01-07 12:55:45 +010049 if constexpr (PERSISTENT_LED_ASSERTED)
50 {
51 /** @brief store and re-store Group */
52 serializePtr =
53 std::make_shared<phosphor::led::Serialize>(SAVED_GROUPS_FILE);
54 }
George Liu2098aa62020-05-09 11:26:35 +080055
Alexander Hansen68e204c2026-01-07 12:55:45 +010056 std::unique_ptr<phosphor::led::LampTest> lampTest;
George Liuc777bef2020-11-23 17:04:21 +080057
Alexander Hansen68e204c2026-01-07 12:55:45 +010058 if constexpr (USE_LAMP_TEST)
59 {
60 lampTest = std::make_unique<phosphor::led::LampTest>(event, manager);
Sunny Srivastavae3515c72022-10-15 12:45:40 -050061
Alexander Hansen68e204c2026-01-07 12:55:45 +010062 // Clear leds triggered by lamp test in previous boot
63 lampTest->clearLamps();
George Liub6151622020-11-23 18:16:18 +080064
Alexander Hansen68e204c2026-01-07 12:55:45 +010065 groups.emplace_back(std::make_unique<phosphor::led::Group>(
66 bus, LAMP_TEST_OBJECT, manager, serializePtr,
67 [&lampTest](auto&& arg1, auto&& arg2) {
68 return lampTest->requestHandler(
69 std::forward<decltype(arg1)>(arg1),
70 std::forward<decltype(arg2)>(arg2));
71 }));
72
73 // Register a lamp test method in the manager class, and call this
74 // method when the lamp test is started
75 manager.setLampTestCallBack([&lampTest](auto&& arg1, auto&& arg2) {
76 return lampTest->processLEDUpdates(
77 std::forward<decltype(arg1)>(arg1),
78 std::forward<decltype(arg2)>(arg2));
79 });
80 }
George Liuc777bef2020-11-23 17:04:21 +080081
Vishwanatha Subbanna4c8c72b2016-11-29 23:02:06 +053082 /** Now create so many dbus objects as there are groups */
Patrick Williams158b2c12022-03-17 05:57:44 -050083 std::ranges::transform(systemLedMap, std::back_inserter(groups),
George Liu54671852023-10-30 09:09:39 +080084 [&bus, &manager, serializePtr](auto& grp) {
Patrick Williams543ac9f2024-08-16 15:19:59 -040085 return std::make_unique<phosphor::led::Group>(
86 bus, grp.first, manager, serializePtr);
87 });
Vishwanatha Subbanna4c8c72b2016-11-29 23:02:06 +053088
George Liuc777bef2020-11-23 17:04:21 +080089 // Attach the bus to sd_event to service user requests
90 bus.attach_event(event.get(), SD_EVENT_PRIORITY_NORMAL);
91
Vishwanatha Subbanna4c8c72b2016-11-29 23:02:06 +053092 /** @brief Claim the bus */
George Liu25255212023-07-18 10:14:03 +080093 bus.request_name("xyz.openbmc_project.LED.GroupManager");
George Liuc777bef2020-11-23 17:04:21 +080094 event.loop();
Vishwanatha Subbanna4c8c72b2016-11-29 23:02:06 +053095
Vishwanatha Subbannab21fda72016-10-17 17:46:37 +053096 return 0;
97}