blob: 0b060dc6dd3dc0953a75c1d86f15323cd2f197f3 [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
5#include "json-config.hpp"
6#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"
Patrick Venture91ac8d32018-11-01 17:03:22 -070012
13#include <iostream>
Vishwanatha Subbannab21fda72016-10-17 17:46:37 +053014
15int main(void)
16{
Vishwanatha Subbanna4c8c72b2016-11-29 23:02:06 +053017 /** @brief Dbus constructs used by LED Group manager */
18 sdbusplus::bus::bus bus = sdbusplus::bus::new_default();
19
George Liudef5f5a2020-04-10 11:23:52 +080020#ifdef LED_USE_JSON
21 auto systemLedMap = loadJsonConfig(LED_JSON_FILE);
22#endif
23
Vishwanatha Subbanna11ca8f92017-02-27 19:33:45 +053024 /** @brief Group manager object */
25 phosphor::led::Manager manager(bus, systemLedMap);
26
Vishwanatha Subbanna4c8c72b2016-11-29 23:02:06 +053027 /** @brief sd_bus object manager */
28 sdbusplus::server::manager::manager objManager(bus, OBJPATH);
29
30 /** @brief vector of led groups */
31 std::vector<std::unique_ptr<phosphor::led::Group>> groups;
32
George Liu2098aa62020-05-09 11:26:35 +080033 /** @brief store and re-store Group */
34 phosphor::led::Serialize serialize(SAVED_GROUPS_FILE);
35
Vishwanatha Subbanna4c8c72b2016-11-29 23:02:06 +053036 /** Now create so many dbus objects as there are groups */
Patrick Venture91ac8d32018-11-01 17:03:22 -070037 for (auto& grp : systemLedMap)
Vishwanatha Subbanna4c8c72b2016-11-29 23:02:06 +053038 {
George Liu2098aa62020-05-09 11:26:35 +080039 groups.emplace_back(std::make_unique<phosphor::led::Group>(
40 bus, grp.first, manager, serialize));
Vishwanatha Subbanna4c8c72b2016-11-29 23:02:06 +053041 }
42
43 /** @brief Claim the bus */
44 bus.request_name(BUSNAME);
45
46 /** @brief Wait for client requests */
Patrick Venture91ac8d32018-11-01 17:03:22 -070047 while (true)
Vishwanatha Subbanna4c8c72b2016-11-29 23:02:06 +053048 {
49 /** @brief process dbus calls / signals discarding unhandled */
50 bus.process_discard();
51 bus.wait();
52 }
Vishwanatha Subbannab21fda72016-10-17 17:46:37 +053053 return 0;
54}