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 |
Vishwanatha Subbanna | 4c8c72b | 2016-11-29 23:02:06 +0530 | [diff] [blame] | 10 | #include "manager.hpp" |
George Liu | 2098aa6 | 2020-05-09 11:26:35 +0800 | [diff] [blame] | 11 | #include "serialize.hpp" |
George Liu | 1c737af | 2020-10-16 09:07:02 +0800 | [diff] [blame] | 12 | #include "utils.hpp" |
George Liu | c777bef | 2020-11-23 17:04:21 +0800 | [diff] [blame] | 13 | #ifdef USE_LAMP_TEST |
Patrick Williams | 953315d | 2022-03-16 14:30:39 -0500 | [diff] [blame] | 14 | #include "lamptest/lamptest.hpp" |
George Liu | c777bef | 2020-11-23 17:04:21 +0800 | [diff] [blame] | 15 | #endif |
| 16 | |
Patrick Williams | 7217c03 | 2022-03-16 16:26:09 -0500 | [diff] [blame] | 17 | #include <CLI/CLI.hpp> |
George Liu | c777bef | 2020-11-23 17:04:21 +0800 | [diff] [blame] | 18 | #include <sdeventplus/event.hpp> |
Patrick Venture | 91ac8d3 | 2018-11-01 17:03:22 -0700 | [diff] [blame] | 19 | |
George Liu | c5e0f31 | 2021-12-27 15:54:31 +0800 | [diff] [blame] | 20 | #include <algorithm> |
Patrick Venture | 91ac8d3 | 2018-11-01 17:03:22 -0700 | [diff] [blame] | 21 | #include <iostream> |
Vishwanatha Subbanna | b21fda7 | 2016-10-17 17:46:37 +0530 | [diff] [blame] | 22 | |
Patrick Williams | 7217c03 | 2022-03-16 16:26:09 -0500 | [diff] [blame] | 23 | int main(int argc, char** argv) |
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 | 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 | |
George Liu | c777bef | 2020-11-23 17:04:21 +0800 | [diff] [blame] | 34 | // Get a default event loop |
| 35 | auto event = sdeventplus::Event::get_default(); |
| 36 | |
Vishwanatha Subbanna | 4c8c72b | 2016-11-29 23:02:06 +0530 | [diff] [blame] | 37 | /** @brief Dbus constructs used by LED Group manager */ |
George Liu | 1c737af | 2020-10-16 09:07:02 +0800 | [diff] [blame] | 38 | auto& bus = phosphor::led::utils::DBusHandler::getBus(); |
Vishwanatha Subbanna | 4c8c72b | 2016-11-29 23:02:06 +0530 | [diff] [blame] | 39 | |
George Liu | def5f5a | 2020-04-10 11:23:52 +0800 | [diff] [blame] | 40 | #ifdef LED_USE_JSON |
Patrick Williams | 7217c03 | 2022-03-16 16:26:09 -0500 | [diff] [blame] | 41 | auto systemLedMap = getSystemLedMap(configFile); |
George Liu | def5f5a | 2020-04-10 11:23:52 +0800 | [diff] [blame] | 42 | #endif |
| 43 | |
Vishwanatha Subbanna | 11ca8f9 | 2017-02-27 19:33:45 +0530 | [diff] [blame] | 44 | /** @brief Group manager object */ |
| 45 | phosphor::led::Manager manager(bus, systemLedMap); |
| 46 | |
Vishwanatha Subbanna | 4c8c72b | 2016-11-29 23:02:06 +0530 | [diff] [blame] | 47 | /** @brief sd_bus object manager */ |
George Liu | 5d92f42 | 2023-07-19 09:18:24 +0800 | [diff] [blame^] | 48 | sdbusplus::server::manager_t objManager(bus, |
| 49 | "/xyz/openbmc_project/led/groups"); |
Vishwanatha Subbanna | 4c8c72b | 2016-11-29 23:02:06 +0530 | [diff] [blame] | 50 | |
| 51 | /** @brief vector of led groups */ |
| 52 | std::vector<std::unique_ptr<phosphor::led::Group>> groups; |
| 53 | |
George Liu | 2098aa6 | 2020-05-09 11:26:35 +0800 | [diff] [blame] | 54 | /** @brief store and re-store Group */ |
| 55 | phosphor::led::Serialize serialize(SAVED_GROUPS_FILE); |
| 56 | |
George Liu | c777bef | 2020-11-23 17:04:21 +0800 | [diff] [blame] | 57 | #ifdef USE_LAMP_TEST |
| 58 | phosphor::led::LampTest lampTest(event, manager); |
| 59 | |
| 60 | groups.emplace_back(std::make_unique<phosphor::led::Group>( |
| 61 | bus, LAMP_TEST_OBJECT, manager, serialize, |
| 62 | std::bind(std::mem_fn(&phosphor::led::LampTest::requestHandler), |
George Liu | 87fd11c | 2020-11-23 16:40:14 +0800 | [diff] [blame] | 63 | &lampTest, std::placeholders::_1, std::placeholders::_2))); |
George Liu | b615162 | 2020-11-23 18:16:18 +0800 | [diff] [blame] | 64 | |
| 65 | // Register a lamp test method in the manager class, and call this method |
| 66 | // when the lamp test is started |
| 67 | manager.setLampTestCallBack( |
| 68 | std::bind(std::mem_fn(&phosphor::led::LampTest::processLEDUpdates), |
| 69 | &lampTest, std::placeholders::_1, std::placeholders::_2)); |
George Liu | c777bef | 2020-11-23 17:04:21 +0800 | [diff] [blame] | 70 | #endif |
| 71 | |
Vishwanatha Subbanna | 4c8c72b | 2016-11-29 23:02:06 +0530 | [diff] [blame] | 72 | /** Now create so many dbus objects as there are groups */ |
Patrick Williams | 158b2c1 | 2022-03-17 05:57:44 -0500 | [diff] [blame] | 73 | std::ranges::transform(systemLedMap, std::back_inserter(groups), |
| 74 | [&bus, &manager, &serialize](auto& grp) { |
Patrick Williams | 857da38 | 2023-05-10 07:50:20 -0500 | [diff] [blame] | 75 | return std::make_unique<phosphor::led::Group>(bus, grp.first, manager, |
| 76 | serialize); |
| 77 | }); |
Vishwanatha Subbanna | 4c8c72b | 2016-11-29 23:02:06 +0530 | [diff] [blame] | 78 | |
George Liu | c777bef | 2020-11-23 17:04:21 +0800 | [diff] [blame] | 79 | // Attach the bus to sd_event to service user requests |
| 80 | bus.attach_event(event.get(), SD_EVENT_PRIORITY_NORMAL); |
| 81 | |
Vishwanatha Subbanna | 4c8c72b | 2016-11-29 23:02:06 +0530 | [diff] [blame] | 82 | /** @brief Claim the bus */ |
George Liu | 2525521 | 2023-07-18 10:14:03 +0800 | [diff] [blame] | 83 | bus.request_name("xyz.openbmc_project.LED.GroupManager"); |
George Liu | c777bef | 2020-11-23 17:04:21 +0800 | [diff] [blame] | 84 | event.loop(); |
Vishwanatha Subbanna | 4c8c72b | 2016-11-29 23:02:06 +0530 | [diff] [blame] | 85 | |
Vishwanatha Subbanna | b21fda7 | 2016-10-17 17:46:37 +0530 | [diff] [blame] | 86 | return 0; |
| 87 | } |