blob: 0933505ae015dedf48fa333f9c11907522b29e3b [file] [log] [blame]
Adriana Kobylak2d8fa222017-03-15 12:34:32 -05001#include <sdbusplus/bus.hpp>
2#include <sdbusplus/server/manager.hpp>
Gunnar Mills6bd6d7b2017-09-18 09:22:36 -05003#include <system_error>
Adriana Kobylak2d8fa222017-03-15 12:34:32 -05004#include "config.h"
5#include "item_updater.hpp"
Gunnar Mills6bd6d7b2017-09-18 09:22:36 -05006#include <phosphor-logging/log.hpp>
7#include "watch.hpp"
Adriana Kobylak2d8fa222017-03-15 12:34:32 -05008
9int main(int argc, char* argv[])
10{
Gunnar Mills6bd6d7b2017-09-18 09:22:36 -050011 using namespace openpower::software::updater;
12 using namespace phosphor::logging;
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050013 auto bus = sdbusplus::bus::new_default();
14
Gunnar Mills6bd6d7b2017-09-18 09:22:36 -050015 sd_event* loop = nullptr;
16 auto rc = sd_event_default(&loop);
17 if (rc < 0)
18 {
19 log<level::ERR>("Error occurred during the sd_event_default",
20 entry("RC=%d", rc));
21 return -1;
22 }
23
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050024 // Add sdbusplus ObjectManager.
25 sdbusplus::server::manager::manager objManager(bus, SOFTWARE_OBJPATH);
26
Gunnar Mills6bd6d7b2017-09-18 09:22:36 -050027 ItemUpdater updater(bus, SOFTWARE_OBJPATH);
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050028
29 bus.request_name(BUSNAME_UPDATER);
Gunnar Mills6bd6d7b2017-09-18 09:22:36 -050030 try
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050031 {
Gunnar Mills6bd6d7b2017-09-18 09:22:36 -050032 openpower::software::updater::Watch watch(
33 loop,
34 std::bind(std::mem_fn(
35 &ItemUpdater::updateFunctionalAssociation),
36 &updater,
37 std::placeholders::_1));
38 bus.attach_event(loop, SD_EVENT_PRIORITY_NORMAL);
39 auto rc = sd_event_loop(loop);
40 if (rc < 0)
41 {
42 log<level::ERR>("Error occurred during the sd_event_loop",
43 entry("RC=%d", rc));
44 return -1;
45 }
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050046 }
Gunnar Mills6bd6d7b2017-09-18 09:22:36 -050047 catch (const std::system_error& e)
48 {
49 log<level::ERR>(e.what());
50 return -1;
51 }
52
53 sd_event_unref(loop);
54
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050055 return 0;
56}