blob: 8344b38909f168d488f9b26d925d1a287e76d654 [file] [log] [blame]
Lei YU2f9c0cc2017-01-20 14:02:03 +08001#include "config.h"
Gunnar Millsab4cc6a2018-09-14 14:42:39 -05002
Lei YU96232822017-01-20 14:05:46 +08003#include "bmc_epoch.hpp"
Lei YUaf5abc52017-03-07 17:49:17 +08004#include "host_epoch.hpp"
Lei YU415b9642017-02-09 11:37:26 +08005#include "manager.hpp"
Lei YU2f9c0cc2017-01-20 14:02:03 +08006
Gunnar Millsab4cc6a2018-09-14 14:42:39 -05007#include <sdbusplus/bus.hpp>
8
Lei YU2f9c0cc2017-01-20 14:02:03 +08009int main()
10{
11 auto bus = sdbusplus::bus::new_default();
Lei YU7b218792017-02-09 12:10:13 +080012 sd_event* event = nullptr;
13
Gunnar Millsab4cc6a2018-09-14 14:42:39 -050014 auto eventDeleter = [](sd_event* e) { e = sd_event_unref(e); };
Lei YU7b218792017-02-09 12:10:13 +080015 using SdEvent = std::unique_ptr<sd_event, decltype(eventDeleter)>;
16
Gunnar Mills7f25c532017-10-25 20:45:28 -050017 // acquire a reference to the default event loop
Lei YU7b218792017-02-09 12:10:13 +080018 sd_event_default(&event);
Gunnar Millsab4cc6a2018-09-14 14:42:39 -050019 SdEvent sdEvent{event, eventDeleter};
Lei YU7b218792017-02-09 12:10:13 +080020 event = nullptr;
21
22 // attach bus to this event loop
23 bus.attach_event(sdEvent.get(), SD_EVENT_PRIORITY_NORMAL);
Lei YU415b9642017-02-09 11:37:26 +080024
25 // Add sdbusplus ObjectManager
26 sdbusplus::server::manager::manager bmcEpochObjManager(bus, OBJPATH_BMC);
27 sdbusplus::server::manager::manager hostEpochObjManager(bus, OBJPATH_HOST);
28
29 phosphor::time::Manager manager(bus);
Lei YU96232822017-01-20 14:05:46 +080030 phosphor::time::BmcEpoch bmc(bus, OBJPATH_BMC);
Gunnar Millsab4cc6a2018-09-14 14:42:39 -050031 phosphor::time::HostEpoch host(bus, OBJPATH_HOST);
Lei YU2f9c0cc2017-01-20 14:02:03 +080032
Lei YU415b9642017-02-09 11:37:26 +080033 manager.addListener(&bmc);
34 manager.addListener(&host);
Lei YU7b218792017-02-09 12:10:13 +080035 bmc.setBmcTimeChangeListener(&host);
Lei YU415b9642017-02-09 11:37:26 +080036
Lei YU2f9c0cc2017-01-20 14:02:03 +080037 bus.request_name(BUSNAME);
38
Lei YU7b218792017-02-09 12:10:13 +080039 // Start event loop for all sd-bus events and timer event
40 sd_event_loop(bus.get_event());
41
42 bus.detach_event();
43
Lei YU2f9c0cc2017-01-20 14:02:03 +080044 return 0;
45}