Lei YU | 2f9c0cc | 2017-01-20 14:02:03 +0800 | [diff] [blame] | 1 | #include "config.h" |
Gunnar Mills | ab4cc6a | 2018-09-14 14:42:39 -0500 | [diff] [blame] | 2 | |
Lei YU | 9623282 | 2017-01-20 14:05:46 +0800 | [diff] [blame] | 3 | #include "bmc_epoch.hpp" |
Lei YU | af5abc5 | 2017-03-07 17:49:17 +0800 | [diff] [blame] | 4 | #include "host_epoch.hpp" |
Lei YU | 415b964 | 2017-02-09 11:37:26 +0800 | [diff] [blame] | 5 | #include "manager.hpp" |
Lei YU | 2f9c0cc | 2017-01-20 14:02:03 +0800 | [diff] [blame] | 6 | |
Gunnar Mills | ab4cc6a | 2018-09-14 14:42:39 -0500 | [diff] [blame] | 7 | #include <sdbusplus/bus.hpp> |
| 8 | |
Lei YU | 2f9c0cc | 2017-01-20 14:02:03 +0800 | [diff] [blame] | 9 | int main() |
| 10 | { |
| 11 | auto bus = sdbusplus::bus::new_default(); |
Lei YU | 7b21879 | 2017-02-09 12:10:13 +0800 | [diff] [blame] | 12 | sd_event* event = nullptr; |
| 13 | |
Gunnar Mills | ab4cc6a | 2018-09-14 14:42:39 -0500 | [diff] [blame] | 14 | auto eventDeleter = [](sd_event* e) { e = sd_event_unref(e); }; |
Lei YU | 7b21879 | 2017-02-09 12:10:13 +0800 | [diff] [blame] | 15 | using SdEvent = std::unique_ptr<sd_event, decltype(eventDeleter)>; |
| 16 | |
Gunnar Mills | 7f25c53 | 2017-10-25 20:45:28 -0500 | [diff] [blame] | 17 | // acquire a reference to the default event loop |
Lei YU | 7b21879 | 2017-02-09 12:10:13 +0800 | [diff] [blame] | 18 | sd_event_default(&event); |
Gunnar Mills | ab4cc6a | 2018-09-14 14:42:39 -0500 | [diff] [blame] | 19 | SdEvent sdEvent{event, eventDeleter}; |
Lei YU | 7b21879 | 2017-02-09 12:10:13 +0800 | [diff] [blame] | 20 | event = nullptr; |
| 21 | |
| 22 | // attach bus to this event loop |
| 23 | bus.attach_event(sdEvent.get(), SD_EVENT_PRIORITY_NORMAL); |
Lei YU | 415b964 | 2017-02-09 11:37:26 +0800 | [diff] [blame] | 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); |
Lei YU | 9623282 | 2017-01-20 14:05:46 +0800 | [diff] [blame] | 30 | phosphor::time::BmcEpoch bmc(bus, OBJPATH_BMC); |
Gunnar Mills | ab4cc6a | 2018-09-14 14:42:39 -0500 | [diff] [blame] | 31 | phosphor::time::HostEpoch host(bus, OBJPATH_HOST); |
Lei YU | 2f9c0cc | 2017-01-20 14:02:03 +0800 | [diff] [blame] | 32 | |
Lei YU | 415b964 | 2017-02-09 11:37:26 +0800 | [diff] [blame] | 33 | manager.addListener(&bmc); |
| 34 | manager.addListener(&host); |
Lei YU | 7b21879 | 2017-02-09 12:10:13 +0800 | [diff] [blame] | 35 | bmc.setBmcTimeChangeListener(&host); |
Lei YU | 415b964 | 2017-02-09 11:37:26 +0800 | [diff] [blame] | 36 | |
Lei YU | 2f9c0cc | 2017-01-20 14:02:03 +0800 | [diff] [blame] | 37 | bus.request_name(BUSNAME); |
| 38 | |
Lei YU | 7b21879 | 2017-02-09 12:10:13 +0800 | [diff] [blame] | 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 | |
Lei YU | 2f9c0cc | 2017-01-20 14:02:03 +0800 | [diff] [blame] | 44 | return 0; |
| 45 | } |