Lei YU | 2f9c0cc | 2017-01-20 14:02:03 +0800 | [diff] [blame] | 1 | #include <sdbusplus/bus.hpp> |
| 2 | |
| 3 | #include "config.h" |
Lei YU | 9623282 | 2017-01-20 14:05:46 +0800 | [diff] [blame] | 4 | #include "bmc_epoch.hpp" |
Lei YU | af5abc5 | 2017-03-07 17:49:17 +0800 | [diff] [blame] | 5 | #include "host_epoch.hpp" |
Lei YU | 415b964 | 2017-02-09 11:37:26 +0800 | [diff] [blame] | 6 | #include "manager.hpp" |
Lei YU | 2f9c0cc | 2017-01-20 14:02:03 +0800 | [diff] [blame] | 7 | |
| 8 | int main() |
| 9 | { |
| 10 | auto bus = sdbusplus::bus::new_default(); |
Lei YU | 7b21879 | 2017-02-09 12:10:13 +0800 | [diff] [blame] | 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 | |
Gunnar Mills | 7f25c53 | 2017-10-25 20:45:28 -0500 | [diff] [blame^] | 18 | // acquire a reference to the default event loop |
Lei YU | 7b21879 | 2017-02-09 12:10:13 +0800 | [diff] [blame] | 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 YU | 415b964 | 2017-02-09 11:37:26 +0800 | [diff] [blame] | 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); |
Lei YU | 9623282 | 2017-01-20 14:05:46 +0800 | [diff] [blame] | 31 | phosphor::time::BmcEpoch bmc(bus, OBJPATH_BMC); |
Lei YU | af5abc5 | 2017-03-07 17:49:17 +0800 | [diff] [blame] | 32 | phosphor::time::HostEpoch host(bus,OBJPATH_HOST); |
Lei YU | 2f9c0cc | 2017-01-20 14:02:03 +0800 | [diff] [blame] | 33 | |
Lei YU | 415b964 | 2017-02-09 11:37:26 +0800 | [diff] [blame] | 34 | manager.addListener(&bmc); |
| 35 | manager.addListener(&host); |
Lei YU | 7b21879 | 2017-02-09 12:10:13 +0800 | [diff] [blame] | 36 | bmc.setBmcTimeChangeListener(&host); |
Lei YU | 415b964 | 2017-02-09 11:37:26 +0800 | [diff] [blame] | 37 | |
Lei YU | 2f9c0cc | 2017-01-20 14:02:03 +0800 | [diff] [blame] | 38 | bus.request_name(BUSNAME); |
| 39 | |
Lei YU | 7b21879 | 2017-02-09 12:10:13 +0800 | [diff] [blame] | 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 | |
Lei YU | 2f9c0cc | 2017-01-20 14:02:03 +0800 | [diff] [blame] | 45 | return 0; |
| 46 | } |