blob: 1798dc0883229b270f8bfa04b9e30d9937d39215 [file] [log] [blame]
Lei YU2f9c0cc2017-01-20 14:02:03 +08001#include <sdbusplus/bus.hpp>
2
3#include "config.h"
Lei YU96232822017-01-20 14:05:46 +08004#include "bmc_epoch.hpp"
Lei YUaf5abc52017-03-07 17:49:17 +08005#include "host_epoch.hpp"
Lei YU415b9642017-02-09 11:37:26 +08006#include "manager.hpp"
Lei YU2f9c0cc2017-01-20 14:02:03 +08007
8int main()
9{
10 auto bus = sdbusplus::bus::new_default();
Lei YU7b218792017-02-09 12:10:13 +080011 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);
Lei YU415b9642017-02-09 11:37:26 +080025
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);
Lei YU96232822017-01-20 14:05:46 +080031 phosphor::time::BmcEpoch bmc(bus, OBJPATH_BMC);
Lei YUaf5abc52017-03-07 17:49:17 +080032 phosphor::time::HostEpoch host(bus,OBJPATH_HOST);
Lei YU2f9c0cc2017-01-20 14:02:03 +080033
Lei YU415b9642017-02-09 11:37:26 +080034 manager.addListener(&bmc);
35 manager.addListener(&host);
Lei YU7b218792017-02-09 12:10:13 +080036 bmc.setBmcTimeChangeListener(&host);
Lei YU415b9642017-02-09 11:37:26 +080037
Lei YU2f9c0cc2017-01-20 14:02:03 +080038 bus.request_name(BUSNAME);
39
Lei YU7b218792017-02-09 12:10:13 +080040 // Start event loop for all sd-bus events and timer event
41 sd_event_loop(bus.get_event());
42
43 bus.detach_event();
44
Lei YU2f9c0cc2017-01-20 14:02:03 +080045 return 0;
46}