Patrick Venture | 91ac8d3 | 2018-11-01 17:03:22 -0700 | [diff] [blame] | 1 | #include "config.h" |
| 2 | |
| 3 | #include "group.hpp" |
George Liu | def5f5a | 2020-04-10 11:23:52 +0800 | [diff] [blame] | 4 | #ifdef LED_USE_JSON |
George Liu | 616a071 | 2021-02-18 10:50:24 +0800 | [diff] [blame] | 5 | #include "json-parser.hpp" |
George Liu | def5f5a | 2020-04-10 11:23:52 +0800 | [diff] [blame] | 6 | #else |
Patrick Venture | 91ac8d3 | 2018-11-01 17:03:22 -0700 | [diff] [blame] | 7 | #include "led-gen.hpp" |
George Liu | def5f5a | 2020-04-10 11:23:52 +0800 | [diff] [blame] | 8 | #endif |
Vishwanatha Subbanna | ed49073 | 2016-12-20 15:59:29 +0530 | [diff] [blame] | 9 | #include "ledlayout.hpp" |
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 |
| 14 | #include "lamptest.hpp" |
| 15 | #endif |
| 16 | |
| 17 | #include <sdeventplus/event.hpp> |
Patrick Venture | 91ac8d3 | 2018-11-01 17:03:22 -0700 | [diff] [blame] | 18 | |
| 19 | #include <iostream> |
Vishwanatha Subbanna | b21fda7 | 2016-10-17 17:46:37 +0530 | [diff] [blame] | 20 | |
| 21 | int main(void) |
| 22 | { |
George Liu | c777bef | 2020-11-23 17:04:21 +0800 | [diff] [blame] | 23 | // Get a default event loop |
| 24 | auto event = sdeventplus::Event::get_default(); |
| 25 | |
Vishwanatha Subbanna | 4c8c72b | 2016-11-29 23:02:06 +0530 | [diff] [blame] | 26 | /** @brief Dbus constructs used by LED Group manager */ |
George Liu | 1c737af | 2020-10-16 09:07:02 +0800 | [diff] [blame] | 27 | auto& bus = phosphor::led::utils::DBusHandler::getBus(); |
Vishwanatha Subbanna | 4c8c72b | 2016-11-29 23:02:06 +0530 | [diff] [blame] | 28 | |
George Liu | def5f5a | 2020-04-10 11:23:52 +0800 | [diff] [blame] | 29 | #ifdef LED_USE_JSON |
George Liu | 616a071 | 2021-02-18 10:50:24 +0800 | [diff] [blame] | 30 | auto systemLedMap = getSystemLedMap(); |
George Liu | def5f5a | 2020-04-10 11:23:52 +0800 | [diff] [blame] | 31 | #endif |
| 32 | |
Vishwanatha Subbanna | 11ca8f9 | 2017-02-27 19:33:45 +0530 | [diff] [blame] | 33 | /** @brief Group manager object */ |
| 34 | phosphor::led::Manager manager(bus, systemLedMap); |
| 35 | |
Vishwanatha Subbanna | 4c8c72b | 2016-11-29 23:02:06 +0530 | [diff] [blame] | 36 | /** @brief sd_bus object manager */ |
| 37 | sdbusplus::server::manager::manager objManager(bus, OBJPATH); |
| 38 | |
| 39 | /** @brief vector of led groups */ |
| 40 | std::vector<std::unique_ptr<phosphor::led::Group>> groups; |
| 41 | |
George Liu | 2098aa6 | 2020-05-09 11:26:35 +0800 | [diff] [blame] | 42 | /** @brief store and re-store Group */ |
| 43 | phosphor::led::Serialize serialize(SAVED_GROUPS_FILE); |
| 44 | |
George Liu | c777bef | 2020-11-23 17:04:21 +0800 | [diff] [blame] | 45 | #ifdef USE_LAMP_TEST |
| 46 | phosphor::led::LampTest lampTest(event, manager); |
| 47 | |
| 48 | groups.emplace_back(std::make_unique<phosphor::led::Group>( |
| 49 | bus, LAMP_TEST_OBJECT, manager, serialize, |
| 50 | std::bind(std::mem_fn(&phosphor::led::LampTest::requestHandler), |
George Liu | 87fd11c | 2020-11-23 16:40:14 +0800 | [diff] [blame] | 51 | &lampTest, std::placeholders::_1, std::placeholders::_2))); |
George Liu | b615162 | 2020-11-23 18:16:18 +0800 | [diff] [blame] | 52 | |
| 53 | // Register a lamp test method in the manager class, and call this method |
| 54 | // when the lamp test is started |
| 55 | manager.setLampTestCallBack( |
| 56 | std::bind(std::mem_fn(&phosphor::led::LampTest::processLEDUpdates), |
| 57 | &lampTest, std::placeholders::_1, std::placeholders::_2)); |
George Liu | c777bef | 2020-11-23 17:04:21 +0800 | [diff] [blame] | 58 | #endif |
| 59 | |
Vishwanatha Subbanna | 4c8c72b | 2016-11-29 23:02:06 +0530 | [diff] [blame] | 60 | /** Now create so many dbus objects as there are groups */ |
Patrick Venture | 91ac8d3 | 2018-11-01 17:03:22 -0700 | [diff] [blame] | 61 | for (auto& grp : systemLedMap) |
Vishwanatha Subbanna | 4c8c72b | 2016-11-29 23:02:06 +0530 | [diff] [blame] | 62 | { |
George Liu | 2098aa6 | 2020-05-09 11:26:35 +0800 | [diff] [blame] | 63 | groups.emplace_back(std::make_unique<phosphor::led::Group>( |
| 64 | bus, grp.first, manager, serialize)); |
Vishwanatha Subbanna | 4c8c72b | 2016-11-29 23:02:06 +0530 | [diff] [blame] | 65 | } |
| 66 | |
George Liu | c777bef | 2020-11-23 17:04:21 +0800 | [diff] [blame] | 67 | // Attach the bus to sd_event to service user requests |
| 68 | bus.attach_event(event.get(), SD_EVENT_PRIORITY_NORMAL); |
| 69 | |
Vishwanatha Subbanna | 4c8c72b | 2016-11-29 23:02:06 +0530 | [diff] [blame] | 70 | /** @brief Claim the bus */ |
| 71 | bus.request_name(BUSNAME); |
George Liu | c777bef | 2020-11-23 17:04:21 +0800 | [diff] [blame] | 72 | event.loop(); |
Vishwanatha Subbanna | 4c8c72b | 2016-11-29 23:02:06 +0530 | [diff] [blame] | 73 | |
Vishwanatha Subbanna | b21fda7 | 2016-10-17 17:46:37 +0530 | [diff] [blame] | 74 | return 0; |
| 75 | } |