blob: f671d5dc7c5aa6425a21fc5f4be9c7fcdee9ff78 [file] [log] [blame]
Patrick Venture91ac8d32018-11-01 17:03:22 -07001#include "config.h"
2
3#include "group.hpp"
Patrick Williams158b2c12022-03-17 05:57:44 -05004#include "ledlayout.hpp"
George Liudef5f5a2020-04-10 11:23:52 +08005#ifdef LED_USE_JSON
George Liu616a0712021-02-18 10:50:24 +08006#include "json-parser.hpp"
George Liudef5f5a2020-04-10 11:23:52 +08007#else
Patrick Venture91ac8d32018-11-01 17:03:22 -07008#include "led-gen.hpp"
George Liudef5f5a2020-04-10 11:23:52 +08009#endif
Alexander Hansenc0f7a8b2024-08-23 19:44:22 +020010#include "config-validator.hpp"
Vishwanatha Subbanna4c8c72b2016-11-29 23:02:06 +053011#include "manager.hpp"
George Liu2098aa62020-05-09 11:26:35 +080012#include "serialize.hpp"
George Liu1c737af2020-10-16 09:07:02 +080013#include "utils.hpp"
George Liuc777bef2020-11-23 17:04:21 +080014#ifdef USE_LAMP_TEST
Patrick Williams953315d2022-03-16 14:30:39 -050015#include "lamptest/lamptest.hpp"
George Liuc777bef2020-11-23 17:04:21 +080016#endif
17
Patrick Williams7217c032022-03-16 16:26:09 -050018#include <CLI/CLI.hpp>
George Liuc777bef2020-11-23 17:04:21 +080019#include <sdeventplus/event.hpp>
Patrick Venture91ac8d32018-11-01 17:03:22 -070020
George Liuc5e0f312021-12-27 15:54:31 +080021#include <algorithm>
Patrick Venture91ac8d32018-11-01 17:03:22 -070022#include <iostream>
George Liu54671852023-10-30 09:09:39 +080023#include <memory>
Vishwanatha Subbannab21fda72016-10-17 17:46:37 +053024
Patrick Williams7217c032022-03-16 16:26:09 -050025int main(int argc, char** argv)
Vishwanatha Subbannab21fda72016-10-17 17:46:37 +053026{
Patrick Williams7217c032022-03-16 16:26:09 -050027 CLI::App app("phosphor-led-manager");
28
29#ifdef LED_USE_JSON
30 std::string configFile{};
31 app.add_option("-c,--config", configFile, "Path to JSON config");
32#endif
33
34 CLI11_PARSE(app, argc, argv);
35
George Liuc777bef2020-11-23 17:04:21 +080036 // Get a default event loop
37 auto event = sdeventplus::Event::get_default();
38
Vishwanatha Subbanna4c8c72b2016-11-29 23:02:06 +053039 /** @brief Dbus constructs used by LED Group manager */
George Liu1c737af2020-10-16 09:07:02 +080040 auto& bus = phosphor::led::utils::DBusHandler::getBus();
Vishwanatha Subbanna4c8c72b2016-11-29 23:02:06 +053041
George Liudef5f5a2020-04-10 11:23:52 +080042#ifdef LED_USE_JSON
Patrick Williams7217c032022-03-16 16:26:09 -050043 auto systemLedMap = getSystemLedMap(configFile);
George Liudef5f5a2020-04-10 11:23:52 +080044#endif
45
Alexander Hansen638d1482024-08-21 17:39:57 +020046 phosphor::led::validateConfigV1(systemLedMap);
47
Vishwanatha Subbanna11ca8f92017-02-27 19:33:45 +053048 /** @brief Group manager object */
Potin Laif1ed4792023-07-13 18:45:14 +080049 phosphor::led::Manager manager(bus, systemLedMap, event);
Vishwanatha Subbanna11ca8f92017-02-27 19:33:45 +053050
Vishwanatha Subbanna4c8c72b2016-11-29 23:02:06 +053051 /** @brief sd_bus object manager */
George Liu5d92f422023-07-19 09:18:24 +080052 sdbusplus::server::manager_t objManager(bus,
53 "/xyz/openbmc_project/led/groups");
Vishwanatha Subbanna4c8c72b2016-11-29 23:02:06 +053054
55 /** @brief vector of led groups */
56 std::vector<std::unique_ptr<phosphor::led::Group>> groups;
57
George Liu54671852023-10-30 09:09:39 +080058 std::shared_ptr<phosphor::led::Serialize> serializePtr = nullptr;
59#ifdef PERSISTENT_LED_ASSERTED
George Liu2098aa62020-05-09 11:26:35 +080060 /** @brief store and re-store Group */
George Liu54671852023-10-30 09:09:39 +080061 serializePtr =
62 std::make_shared<phosphor::led::Serialize>(SAVED_GROUPS_FILE);
63#endif
George Liu2098aa62020-05-09 11:26:35 +080064
George Liuc777bef2020-11-23 17:04:21 +080065#ifdef USE_LAMP_TEST
66 phosphor::led::LampTest lampTest(event, manager);
67
Manojkiran Eda94e894c2024-06-17 11:44:39 +053068 // Clear leds triggered by lamp test in previous boot
George Liu16181d12024-08-22 20:05:20 +080069 phosphor::led::LampTest::clearLamps();
Sunny Srivastavae3515c72022-10-15 12:45:40 -050070
George Liuc777bef2020-11-23 17:04:21 +080071 groups.emplace_back(std::make_unique<phosphor::led::Group>(
George Liu54671852023-10-30 09:09:39 +080072 bus, LAMP_TEST_OBJECT, manager, serializePtr,
George Liu226059b2024-08-22 16:01:44 +080073 [&lampTest](auto&& arg1, auto&& arg2) {
74 return lampTest.requestHandler(std::forward<decltype(arg1)>(arg1),
75 std::forward<decltype(arg2)>(arg2));
76 }));
George Liub6151622020-11-23 18:16:18 +080077
78 // Register a lamp test method in the manager class, and call this method
79 // when the lamp test is started
George Liu226059b2024-08-22 16:01:44 +080080 manager.setLampTestCallBack([&lampTest](auto&& arg1, auto&& arg2) {
81 return lampTest.processLEDUpdates(std::forward<decltype(arg1)>(arg1),
82 std::forward<decltype(arg2)>(arg2));
83 });
George Liuc777bef2020-11-23 17:04:21 +080084#endif
85
Vishwanatha Subbanna4c8c72b2016-11-29 23:02:06 +053086 /** Now create so many dbus objects as there are groups */
Patrick Williams158b2c12022-03-17 05:57:44 -050087 std::ranges::transform(systemLedMap, std::back_inserter(groups),
George Liu54671852023-10-30 09:09:39 +080088 [&bus, &manager, serializePtr](auto& grp) {
Patrick Williams543ac9f2024-08-16 15:19:59 -040089 return std::make_unique<phosphor::led::Group>(
90 bus, grp.first, manager, serializePtr);
91 });
Vishwanatha Subbanna4c8c72b2016-11-29 23:02:06 +053092
George Liuc777bef2020-11-23 17:04:21 +080093 // Attach the bus to sd_event to service user requests
94 bus.attach_event(event.get(), SD_EVENT_PRIORITY_NORMAL);
95
Vishwanatha Subbanna4c8c72b2016-11-29 23:02:06 +053096 /** @brief Claim the bus */
George Liu25255212023-07-18 10:14:03 +080097 bus.request_name("xyz.openbmc_project.LED.GroupManager");
George Liuc777bef2020-11-23 17:04:21 +080098 event.loop();
Vishwanatha Subbanna4c8c72b2016-11-29 23:02:06 +053099
Vishwanatha Subbannab21fda72016-10-17 17:46:37 +0530100 return 0;
101}