xref: /openbmc/phosphor-bmc-code-mgmt/bmc/sync_manager_main.cpp (revision cab87e9cdeeb3e166d6d577511f6be4dc7721aca)
1*cab87e9cSJagpal Singh Gill #include "config.h"
2*cab87e9cSJagpal Singh Gill 
3*cab87e9cSJagpal Singh Gill #include "sync_manager.hpp"
4*cab87e9cSJagpal Singh Gill #include "sync_watch.hpp"
5*cab87e9cSJagpal Singh Gill 
6*cab87e9cSJagpal Singh Gill #include <systemd/sd-event.h>
7*cab87e9cSJagpal Singh Gill 
8*cab87e9cSJagpal Singh Gill #include <phosphor-logging/lg2.hpp>
9*cab87e9cSJagpal Singh Gill #include <sdbusplus/bus.hpp>
10*cab87e9cSJagpal Singh Gill #include <sdbusplus/server/manager.hpp>
11*cab87e9cSJagpal Singh Gill 
12*cab87e9cSJagpal Singh Gill #include <exception>
13*cab87e9cSJagpal Singh Gill 
main()14*cab87e9cSJagpal Singh Gill int main()
15*cab87e9cSJagpal Singh Gill {
16*cab87e9cSJagpal Singh Gill     auto bus = sdbusplus::bus::new_default();
17*cab87e9cSJagpal Singh Gill 
18*cab87e9cSJagpal Singh Gill     sd_event* loop = nullptr;
19*cab87e9cSJagpal Singh Gill     sd_event_default(&loop);
20*cab87e9cSJagpal Singh Gill 
21*cab87e9cSJagpal Singh Gill     sdbusplus::server::manager_t objManager(bus, SOFTWARE_OBJPATH);
22*cab87e9cSJagpal Singh Gill 
23*cab87e9cSJagpal Singh Gill     try
24*cab87e9cSJagpal Singh Gill     {
25*cab87e9cSJagpal Singh Gill         using namespace phosphor::software::manager;
26*cab87e9cSJagpal Singh Gill         auto syncCallback = std::bind(
27*cab87e9cSJagpal Singh Gill             &Sync::processEntry, std::placeholders::_1, std::placeholders::_2);
28*cab87e9cSJagpal Singh Gill         phosphor::software::manager::SyncWatch watch(*loop, syncCallback);
29*cab87e9cSJagpal Singh Gill         bus.attach_event(loop, SD_EVENT_PRIORITY_NORMAL);
30*cab87e9cSJagpal Singh Gill         sd_event_loop(loop);
31*cab87e9cSJagpal Singh Gill     }
32*cab87e9cSJagpal Singh Gill     catch (const std::exception& e)
33*cab87e9cSJagpal Singh Gill     {
34*cab87e9cSJagpal Singh Gill         lg2::error("Error in event loop: {ERROR}", "ERROR", e);
35*cab87e9cSJagpal Singh Gill         sd_event_unref(loop);
36*cab87e9cSJagpal Singh Gill         return -1;
37*cab87e9cSJagpal Singh Gill     }
38*cab87e9cSJagpal Singh Gill 
39*cab87e9cSJagpal Singh Gill     sd_event_unref(loop);
40*cab87e9cSJagpal Singh Gill 
41*cab87e9cSJagpal Singh Gill     return 0;
42*cab87e9cSJagpal Singh Gill }
43