summaryrefslogtreecommitdiffstats
path: root/main.cpp
blob: 8344b38909f168d488f9b26d925d1a287e76d654 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include "config.h"

#include "bmc_epoch.hpp"
#include "host_epoch.hpp"
#include "manager.hpp"

#include <sdbusplus/bus.hpp>

int main()
{
    auto bus = sdbusplus::bus::new_default();
    sd_event* event = nullptr;

    auto eventDeleter = [](sd_event* e) { e = sd_event_unref(e); };
    using SdEvent = std::unique_ptr<sd_event, decltype(eventDeleter)>;

    // acquire a reference to the default event loop
    sd_event_default(&event);
    SdEvent sdEvent{event, eventDeleter};
    event = nullptr;

    // attach bus to this event loop
    bus.attach_event(sdEvent.get(), SD_EVENT_PRIORITY_NORMAL);

    // Add sdbusplus ObjectManager
    sdbusplus::server::manager::manager bmcEpochObjManager(bus, OBJPATH_BMC);
    sdbusplus::server::manager::manager hostEpochObjManager(bus, OBJPATH_HOST);

    phosphor::time::Manager manager(bus);
    phosphor::time::BmcEpoch bmc(bus, OBJPATH_BMC);
    phosphor::time::HostEpoch host(bus, OBJPATH_HOST);

    manager.addListener(&bmc);
    manager.addListener(&host);
    bmc.setBmcTimeChangeListener(&host);

    bus.request_name(BUSNAME);

    // Start event loop for all sd-bus events and timer event
    sd_event_loop(bus.get_event());

    bus.detach_event();

    return 0;
}
OpenPOWER on IntegriCloud