blob: ba7ee44b379ad0640aeab4164f796409bd2022f2 [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
Vishwanatha Subbanna4c8c72b2016-11-29 23:02:06 +053010#include "manager.hpp"
George Liu2098aa62020-05-09 11:26:35 +080011#include "serialize.hpp"
George Liu1c737af2020-10-16 09:07:02 +080012#include "utils.hpp"
George Liuc777bef2020-11-23 17:04:21 +080013#ifdef USE_LAMP_TEST
Patrick Williams953315d2022-03-16 14:30:39 -050014#include "lamptest/lamptest.hpp"
George Liuc777bef2020-11-23 17:04:21 +080015#endif
16
Patrick Williams7217c032022-03-16 16:26:09 -050017#include <CLI/CLI.hpp>
George Liuc777bef2020-11-23 17:04:21 +080018#include <sdeventplus/event.hpp>
Patrick Venture91ac8d32018-11-01 17:03:22 -070019
George Liuc5e0f312021-12-27 15:54:31 +080020#include <algorithm>
Patrick Venture91ac8d32018-11-01 17:03:22 -070021#include <iostream>
George Liu54671852023-10-30 09:09:39 +080022#include <memory>
Vishwanatha Subbannab21fda72016-10-17 17:46:37 +053023
Patrick Williams7217c032022-03-16 16:26:09 -050024int main(int argc, char** argv)
Vishwanatha Subbannab21fda72016-10-17 17:46:37 +053025{
Patrick Williams7217c032022-03-16 16:26:09 -050026 CLI::App app("phosphor-led-manager");
27
28#ifdef LED_USE_JSON
29 std::string configFile{};
30 app.add_option("-c,--config", configFile, "Path to JSON config");
31#endif
32
33 CLI11_PARSE(app, argc, argv);
34
George Liuc777bef2020-11-23 17:04:21 +080035 // Get a default event loop
36 auto event = sdeventplus::Event::get_default();
37
Vishwanatha Subbanna4c8c72b2016-11-29 23:02:06 +053038 /** @brief Dbus constructs used by LED Group manager */
George Liu1c737af2020-10-16 09:07:02 +080039 auto& bus = phosphor::led::utils::DBusHandler::getBus();
Vishwanatha Subbanna4c8c72b2016-11-29 23:02:06 +053040
George Liudef5f5a2020-04-10 11:23:52 +080041#ifdef LED_USE_JSON
Patrick Williams7217c032022-03-16 16:26:09 -050042 auto systemLedMap = getSystemLedMap(configFile);
George Liudef5f5a2020-04-10 11:23:52 +080043#endif
44
Vishwanatha Subbanna11ca8f92017-02-27 19:33:45 +053045 /** @brief Group manager object */
Potin Laif1ed4792023-07-13 18:45:14 +080046 phosphor::led::Manager manager(bus, systemLedMap, event);
Vishwanatha Subbanna11ca8f92017-02-27 19:33:45 +053047
Vishwanatha Subbanna4c8c72b2016-11-29 23:02:06 +053048 /** @brief sd_bus object manager */
George Liu5d92f422023-07-19 09:18:24 +080049 sdbusplus::server::manager_t objManager(bus,
50 "/xyz/openbmc_project/led/groups");
Vishwanatha Subbanna4c8c72b2016-11-29 23:02:06 +053051
52 /** @brief vector of led groups */
53 std::vector<std::unique_ptr<phosphor::led::Group>> groups;
54
George Liu54671852023-10-30 09:09:39 +080055 std::shared_ptr<phosphor::led::Serialize> serializePtr = nullptr;
56#ifdef PERSISTENT_LED_ASSERTED
George Liu2098aa62020-05-09 11:26:35 +080057 /** @brief store and re-store Group */
George Liu54671852023-10-30 09:09:39 +080058 serializePtr =
59 std::make_shared<phosphor::led::Serialize>(SAVED_GROUPS_FILE);
60#endif
George Liu2098aa62020-05-09 11:26:35 +080061
George Liuc777bef2020-11-23 17:04:21 +080062#ifdef USE_LAMP_TEST
63 phosphor::led::LampTest lampTest(event, manager);
64
Sunny Srivastavae3515c72022-10-15 12:45:40 -050065 // Clear leds triggerred by lamp test in previous boot
66 lampTest.clearLamps();
67
George Liuc777bef2020-11-23 17:04:21 +080068 groups.emplace_back(std::make_unique<phosphor::led::Group>(
George Liu54671852023-10-30 09:09:39 +080069 bus, LAMP_TEST_OBJECT, manager, serializePtr,
George Liuc777bef2020-11-23 17:04:21 +080070 std::bind(std::mem_fn(&phosphor::led::LampTest::requestHandler),
George Liu87fd11c2020-11-23 16:40:14 +080071 &lampTest, std::placeholders::_1, std::placeholders::_2)));
George Liub6151622020-11-23 18:16:18 +080072
73 // Register a lamp test method in the manager class, and call this method
74 // when the lamp test is started
75 manager.setLampTestCallBack(
76 std::bind(std::mem_fn(&phosphor::led::LampTest::processLEDUpdates),
77 &lampTest, std::placeholders::_1, std::placeholders::_2));
George Liuc777bef2020-11-23 17:04:21 +080078#endif
79
Vishwanatha Subbanna4c8c72b2016-11-29 23:02:06 +053080 /** Now create so many dbus objects as there are groups */
Patrick Williams158b2c12022-03-17 05:57:44 -050081 std::ranges::transform(systemLedMap, std::back_inserter(groups),
George Liu54671852023-10-30 09:09:39 +080082 [&bus, &manager, serializePtr](auto& grp) {
Patrick Williams857da382023-05-10 07:50:20 -050083 return std::make_unique<phosphor::led::Group>(bus, grp.first, manager,
George Liu54671852023-10-30 09:09:39 +080084 serializePtr);
Patrick Williams857da382023-05-10 07:50:20 -050085 });
Vishwanatha Subbanna4c8c72b2016-11-29 23:02:06 +053086
George Liuc777bef2020-11-23 17:04:21 +080087 // Attach the bus to sd_event to service user requests
88 bus.attach_event(event.get(), SD_EVENT_PRIORITY_NORMAL);
89
Vishwanatha Subbanna4c8c72b2016-11-29 23:02:06 +053090 /** @brief Claim the bus */
George Liu25255212023-07-18 10:14:03 +080091 bus.request_name("xyz.openbmc_project.LED.GroupManager");
George Liuc777bef2020-11-23 17:04:21 +080092 event.loop();
Vishwanatha Subbanna4c8c72b2016-11-29 23:02:06 +053093
Vishwanatha Subbannab21fda72016-10-17 17:46:37 +053094 return 0;
95}