Patrick Venture | 91ac8d3 | 2018-11-01 17:03:22 -0700 | [diff] [blame] | 1 | #include "config.h" |
| 2 | |
| 3 | #include "group.hpp" |
Patrick Williams | 158b2c1 | 2022-03-17 05:57:44 -0500 | [diff] [blame] | 4 | #include "ledlayout.hpp" |
George Liu | def5f5a | 2020-04-10 11:23:52 +0800 | [diff] [blame] | 5 | #ifdef LED_USE_JSON |
George Liu | 616a071 | 2021-02-18 10:50:24 +0800 | [diff] [blame] | 6 | #include "json-parser.hpp" |
George Liu | def5f5a | 2020-04-10 11:23:52 +0800 | [diff] [blame] | 7 | #else |
Patrick Venture | 91ac8d3 | 2018-11-01 17:03:22 -0700 | [diff] [blame] | 8 | #include "led-gen.hpp" |
George Liu | def5f5a | 2020-04-10 11:23:52 +0800 | [diff] [blame] | 9 | #endif |
Alexander Hansen | c0f7a8b | 2024-08-23 19:44:22 +0200 | [diff] [blame] | 10 | #include "config-validator.hpp" |
Vishwanatha Subbanna | 4c8c72b | 2016-11-29 23:02:06 +0530 | [diff] [blame] | 11 | #include "manager.hpp" |
George Liu | 2098aa6 | 2020-05-09 11:26:35 +0800 | [diff] [blame] | 12 | #include "serialize.hpp" |
George Liu | 1c737af | 2020-10-16 09:07:02 +0800 | [diff] [blame] | 13 | #include "utils.hpp" |
George Liu | c777bef | 2020-11-23 17:04:21 +0800 | [diff] [blame] | 14 | #ifdef USE_LAMP_TEST |
Patrick Williams | 953315d | 2022-03-16 14:30:39 -0500 | [diff] [blame] | 15 | #include "lamptest/lamptest.hpp" |
George Liu | c777bef | 2020-11-23 17:04:21 +0800 | [diff] [blame] | 16 | #endif |
| 17 | |
Patrick Williams | 7217c03 | 2022-03-16 16:26:09 -0500 | [diff] [blame] | 18 | #include <CLI/CLI.hpp> |
George Liu | c777bef | 2020-11-23 17:04:21 +0800 | [diff] [blame] | 19 | #include <sdeventplus/event.hpp> |
Patrick Venture | 91ac8d3 | 2018-11-01 17:03:22 -0700 | [diff] [blame] | 20 | |
George Liu | c5e0f31 | 2021-12-27 15:54:31 +0800 | [diff] [blame] | 21 | #include <algorithm> |
Patrick Venture | 91ac8d3 | 2018-11-01 17:03:22 -0700 | [diff] [blame] | 22 | #include <iostream> |
George Liu | 5467185 | 2023-10-30 09:09:39 +0800 | [diff] [blame] | 23 | #include <memory> |
Vishwanatha Subbanna | b21fda7 | 2016-10-17 17:46:37 +0530 | [diff] [blame] | 24 | |
Patrick Williams | 7217c03 | 2022-03-16 16:26:09 -0500 | [diff] [blame] | 25 | int main(int argc, char** argv) |
Vishwanatha Subbanna | b21fda7 | 2016-10-17 17:46:37 +0530 | [diff] [blame] | 26 | { |
Patrick Williams | 7217c03 | 2022-03-16 16:26:09 -0500 | [diff] [blame] | 27 | 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 Liu | c777bef | 2020-11-23 17:04:21 +0800 | [diff] [blame] | 36 | // Get a default event loop |
| 37 | auto event = sdeventplus::Event::get_default(); |
| 38 | |
Vishwanatha Subbanna | 4c8c72b | 2016-11-29 23:02:06 +0530 | [diff] [blame] | 39 | /** @brief Dbus constructs used by LED Group manager */ |
George Liu | 1c737af | 2020-10-16 09:07:02 +0800 | [diff] [blame] | 40 | auto& bus = phosphor::led::utils::DBusHandler::getBus(); |
Vishwanatha Subbanna | 4c8c72b | 2016-11-29 23:02:06 +0530 | [diff] [blame] | 41 | |
George Liu | def5f5a | 2020-04-10 11:23:52 +0800 | [diff] [blame] | 42 | #ifdef LED_USE_JSON |
Patrick Williams | 7217c03 | 2022-03-16 16:26:09 -0500 | [diff] [blame] | 43 | auto systemLedMap = getSystemLedMap(configFile); |
George Liu | def5f5a | 2020-04-10 11:23:52 +0800 | [diff] [blame] | 44 | #endif |
| 45 | |
Alexander Hansen | 638d148 | 2024-08-21 17:39:57 +0200 | [diff] [blame] | 46 | phosphor::led::validateConfigV1(systemLedMap); |
| 47 | |
Vishwanatha Subbanna | 11ca8f9 | 2017-02-27 19:33:45 +0530 | [diff] [blame] | 48 | /** @brief Group manager object */ |
Potin Lai | f1ed479 | 2023-07-13 18:45:14 +0800 | [diff] [blame] | 49 | phosphor::led::Manager manager(bus, systemLedMap, event); |
Vishwanatha Subbanna | 11ca8f9 | 2017-02-27 19:33:45 +0530 | [diff] [blame] | 50 | |
Vishwanatha Subbanna | 4c8c72b | 2016-11-29 23:02:06 +0530 | [diff] [blame] | 51 | /** @brief sd_bus object manager */ |
George Liu | 5d92f42 | 2023-07-19 09:18:24 +0800 | [diff] [blame] | 52 | sdbusplus::server::manager_t objManager(bus, |
| 53 | "/xyz/openbmc_project/led/groups"); |
Vishwanatha Subbanna | 4c8c72b | 2016-11-29 23:02:06 +0530 | [diff] [blame] | 54 | |
| 55 | /** @brief vector of led groups */ |
| 56 | std::vector<std::unique_ptr<phosphor::led::Group>> groups; |
| 57 | |
George Liu | 5467185 | 2023-10-30 09:09:39 +0800 | [diff] [blame] | 58 | std::shared_ptr<phosphor::led::Serialize> serializePtr = nullptr; |
| 59 | #ifdef PERSISTENT_LED_ASSERTED |
George Liu | 2098aa6 | 2020-05-09 11:26:35 +0800 | [diff] [blame] | 60 | /** @brief store and re-store Group */ |
George Liu | 5467185 | 2023-10-30 09:09:39 +0800 | [diff] [blame] | 61 | serializePtr = |
| 62 | std::make_shared<phosphor::led::Serialize>(SAVED_GROUPS_FILE); |
| 63 | #endif |
George Liu | 2098aa6 | 2020-05-09 11:26:35 +0800 | [diff] [blame] | 64 | |
George Liu | c777bef | 2020-11-23 17:04:21 +0800 | [diff] [blame] | 65 | #ifdef USE_LAMP_TEST |
| 66 | phosphor::led::LampTest lampTest(event, manager); |
| 67 | |
Manojkiran Eda | 94e894c | 2024-06-17 11:44:39 +0530 | [diff] [blame] | 68 | // Clear leds triggered by lamp test in previous boot |
George Liu | 16181d1 | 2024-08-22 20:05:20 +0800 | [diff] [blame] | 69 | phosphor::led::LampTest::clearLamps(); |
Sunny Srivastava | e3515c7 | 2022-10-15 12:45:40 -0500 | [diff] [blame] | 70 | |
George Liu | c777bef | 2020-11-23 17:04:21 +0800 | [diff] [blame] | 71 | groups.emplace_back(std::make_unique<phosphor::led::Group>( |
George Liu | 5467185 | 2023-10-30 09:09:39 +0800 | [diff] [blame] | 72 | bus, LAMP_TEST_OBJECT, manager, serializePtr, |
George Liu | 226059b | 2024-08-22 16:01:44 +0800 | [diff] [blame] | 73 | [&lampTest](auto&& arg1, auto&& arg2) { |
| 74 | return lampTest.requestHandler(std::forward<decltype(arg1)>(arg1), |
| 75 | std::forward<decltype(arg2)>(arg2)); |
| 76 | })); |
George Liu | b615162 | 2020-11-23 18:16:18 +0800 | [diff] [blame] | 77 | |
| 78 | // Register a lamp test method in the manager class, and call this method |
| 79 | // when the lamp test is started |
George Liu | 226059b | 2024-08-22 16:01:44 +0800 | [diff] [blame] | 80 | manager.setLampTestCallBack([&lampTest](auto&& arg1, auto&& arg2) { |
| 81 | return lampTest.processLEDUpdates(std::forward<decltype(arg1)>(arg1), |
| 82 | std::forward<decltype(arg2)>(arg2)); |
| 83 | }); |
George Liu | c777bef | 2020-11-23 17:04:21 +0800 | [diff] [blame] | 84 | #endif |
| 85 | |
Vishwanatha Subbanna | 4c8c72b | 2016-11-29 23:02:06 +0530 | [diff] [blame] | 86 | /** Now create so many dbus objects as there are groups */ |
Patrick Williams | 158b2c1 | 2022-03-17 05:57:44 -0500 | [diff] [blame] | 87 | std::ranges::transform(systemLedMap, std::back_inserter(groups), |
George Liu | 5467185 | 2023-10-30 09:09:39 +0800 | [diff] [blame] | 88 | [&bus, &manager, serializePtr](auto& grp) { |
Patrick Williams | 543ac9f | 2024-08-16 15:19:59 -0400 | [diff] [blame] | 89 | return std::make_unique<phosphor::led::Group>( |
| 90 | bus, grp.first, manager, serializePtr); |
| 91 | }); |
Vishwanatha Subbanna | 4c8c72b | 2016-11-29 23:02:06 +0530 | [diff] [blame] | 92 | |
George Liu | c777bef | 2020-11-23 17:04:21 +0800 | [diff] [blame] | 93 | // Attach the bus to sd_event to service user requests |
| 94 | bus.attach_event(event.get(), SD_EVENT_PRIORITY_NORMAL); |
| 95 | |
Vishwanatha Subbanna | 4c8c72b | 2016-11-29 23:02:06 +0530 | [diff] [blame] | 96 | /** @brief Claim the bus */ |
George Liu | 2525521 | 2023-07-18 10:14:03 +0800 | [diff] [blame] | 97 | bus.request_name("xyz.openbmc_project.LED.GroupManager"); |
George Liu | c777bef | 2020-11-23 17:04:21 +0800 | [diff] [blame] | 98 | event.loop(); |
Vishwanatha Subbanna | 4c8c72b | 2016-11-29 23:02:06 +0530 | [diff] [blame] | 99 | |
Vishwanatha Subbanna | b21fda7 | 2016-10-17 17:46:37 +0530 | [diff] [blame] | 100 | return 0; |
| 101 | } |