xref: /openbmc/phosphor-time-manager/main.cpp (revision 7b218796)
1 #include <sdbusplus/bus.hpp>
2 
3 #include "config.h"
4 #include "bmc_epoch.hpp"
5 #include "host_epoch.hpp"
6 #include "manager.hpp"
7 
8 int main()
9 {
10     auto bus = sdbusplus::bus::new_default();
11     sd_event* event = nullptr;
12 
13     auto eventDeleter = [](sd_event* e) {
14         e = sd_event_unref(e);
15     };
16     using SdEvent = std::unique_ptr<sd_event, decltype(eventDeleter)>;
17 
18     // acquire a referece to the default event loop
19     sd_event_default(&event);
20     SdEvent sdEvent {event, eventDeleter};
21     event = nullptr;
22 
23     // attach bus to this event loop
24     bus.attach_event(sdEvent.get(), SD_EVENT_PRIORITY_NORMAL);
25 
26     // Add sdbusplus ObjectManager
27     sdbusplus::server::manager::manager bmcEpochObjManager(bus, OBJPATH_BMC);
28     sdbusplus::server::manager::manager hostEpochObjManager(bus, OBJPATH_HOST);
29 
30     phosphor::time::Manager manager(bus);
31     phosphor::time::BmcEpoch bmc(bus, OBJPATH_BMC);
32     phosphor::time::HostEpoch host(bus,OBJPATH_HOST);
33 
34     manager.addListener(&bmc);
35     manager.addListener(&host);
36     bmc.setBmcTimeChangeListener(&host);
37 
38     bus.request_name(BUSNAME);
39 
40     // Start event loop for all sd-bus events and timer event
41     sd_event_loop(bus.get_event());
42 
43     bus.detach_event();
44 
45     return 0;
46 }
47