blob: 8dcfff68de884fca54011ae085c1ef8b67e78b3e [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"
Patrick Venture91ac8d32018-11-01 17:03:22 -070013
14#include <iostream>
Vishwanatha Subbannab21fda72016-10-17 17:46:37 +053015
16int main(void)
17{
Vishwanatha Subbanna4c8c72b2016-11-29 23:02:06 +053018 /** @brief Dbus constructs used by LED Group manager */
George Liu1c737af2020-10-16 09:07:02 +080019 auto& bus = phosphor::led::utils::DBusHandler::getBus();
Vishwanatha Subbanna4c8c72b2016-11-29 23:02:06 +053020
George Liudef5f5a2020-04-10 11:23:52 +080021#ifdef LED_USE_JSON
George Liu616a0712021-02-18 10:50:24 +080022 auto systemLedMap = getSystemLedMap();
George Liudef5f5a2020-04-10 11:23:52 +080023#endif
24
Vishwanatha Subbanna11ca8f92017-02-27 19:33:45 +053025 /** @brief Group manager object */
26 phosphor::led::Manager manager(bus, systemLedMap);
27
Vishwanatha Subbanna4c8c72b2016-11-29 23:02:06 +053028 /** @brief sd_bus object manager */
29 sdbusplus::server::manager::manager objManager(bus, OBJPATH);
30
31 /** @brief vector of led groups */
32 std::vector<std::unique_ptr<phosphor::led::Group>> groups;
33
George Liu2098aa62020-05-09 11:26:35 +080034 /** @brief store and re-store Group */
35 phosphor::led::Serialize serialize(SAVED_GROUPS_FILE);
36
Vishwanatha Subbanna4c8c72b2016-11-29 23:02:06 +053037 /** Now create so many dbus objects as there are groups */
Patrick Venture91ac8d32018-11-01 17:03:22 -070038 for (auto& grp : systemLedMap)
Vishwanatha Subbanna4c8c72b2016-11-29 23:02:06 +053039 {
George Liu2098aa62020-05-09 11:26:35 +080040 groups.emplace_back(std::make_unique<phosphor::led::Group>(
41 bus, grp.first, manager, serialize));
Vishwanatha Subbanna4c8c72b2016-11-29 23:02:06 +053042 }
43
44 /** @brief Claim the bus */
45 bus.request_name(BUSNAME);
46
47 /** @brief Wait for client requests */
Patrick Venture91ac8d32018-11-01 17:03:22 -070048 while (true)
Vishwanatha Subbanna4c8c72b2016-11-29 23:02:06 +053049 {
50 /** @brief process dbus calls / signals discarding unhandled */
51 bus.process_discard();
52 bus.wait();
53 }
Vishwanatha Subbannab21fda72016-10-17 17:46:37 +053054 return 0;
55}