blob: 7857e917b0196498b1e07815ff2f091b6d0fe4c3 [file] [log] [blame]
Patrick Venture91ac8d32018-11-01 17:03:22 -07001#include "config.h"
2
3#include "group.hpp"
George Liudef5f5a2020-04-10 11:23:52 +08004#ifdef LED_USE_JSON
George Liu616a0712021-02-18 10:50:24 +08005#include "json-parser.hpp"
George Liudef5f5a2020-04-10 11:23:52 +08006#else
Patrick Venture91ac8d32018-11-01 17:03:22 -07007#include "led-gen.hpp"
George Liudef5f5a2020-04-10 11:23:52 +08008#endif
Vishwanatha Subbannaed490732016-12-20 15:59:29 +05309#include "ledlayout.hpp"
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
14#include "lamptest.hpp"
15#endif
16
17#include <sdeventplus/event.hpp>
Patrick Venture91ac8d32018-11-01 17:03:22 -070018
19#include <iostream>
Vishwanatha Subbannab21fda72016-10-17 17:46:37 +053020
21int main(void)
22{
George Liuc777bef2020-11-23 17:04:21 +080023 // Get a default event loop
24 auto event = sdeventplus::Event::get_default();
25
Vishwanatha Subbanna4c8c72b2016-11-29 23:02:06 +053026 /** @brief Dbus constructs used by LED Group manager */
George Liu1c737af2020-10-16 09:07:02 +080027 auto& bus = phosphor::led::utils::DBusHandler::getBus();
Vishwanatha Subbanna4c8c72b2016-11-29 23:02:06 +053028
George Liudef5f5a2020-04-10 11:23:52 +080029#ifdef LED_USE_JSON
George Liu616a0712021-02-18 10:50:24 +080030 auto systemLedMap = getSystemLedMap();
George Liudef5f5a2020-04-10 11:23:52 +080031#endif
32
Vishwanatha Subbanna11ca8f92017-02-27 19:33:45 +053033 /** @brief Group manager object */
34 phosphor::led::Manager manager(bus, systemLedMap);
35
Vishwanatha Subbanna4c8c72b2016-11-29 23:02:06 +053036 /** @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 Liu2098aa62020-05-09 11:26:35 +080042 /** @brief store and re-store Group */
43 phosphor::led::Serialize serialize(SAVED_GROUPS_FILE);
44
George Liuc777bef2020-11-23 17:04:21 +080045#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),
51 &lampTest, std::placeholders::_1)));
52#endif
53
Vishwanatha Subbanna4c8c72b2016-11-29 23:02:06 +053054 /** Now create so many dbus objects as there are groups */
Patrick Venture91ac8d32018-11-01 17:03:22 -070055 for (auto& grp : systemLedMap)
Vishwanatha Subbanna4c8c72b2016-11-29 23:02:06 +053056 {
George Liu2098aa62020-05-09 11:26:35 +080057 groups.emplace_back(std::make_unique<phosphor::led::Group>(
58 bus, grp.first, manager, serialize));
Vishwanatha Subbanna4c8c72b2016-11-29 23:02:06 +053059 }
60
George Liuc777bef2020-11-23 17:04:21 +080061 // Attach the bus to sd_event to service user requests
62 bus.attach_event(event.get(), SD_EVENT_PRIORITY_NORMAL);
63
Vishwanatha Subbanna4c8c72b2016-11-29 23:02:06 +053064 /** @brief Claim the bus */
65 bus.request_name(BUSNAME);
George Liuc777bef2020-11-23 17:04:21 +080066 event.loop();
Vishwanatha Subbanna4c8c72b2016-11-29 23:02:06 +053067
Vishwanatha Subbannab21fda72016-10-17 17:46:37 +053068 return 0;
69}