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