blob: e54239a898708a559e34e774a60e731836a9ac34 [file] [log] [blame]
Gunnar Millsf6ed5892018-09-07 17:08:02 -05001#include "config.h"
2
Lei YUf3ce4332019-02-21 14:09:49 +08003#ifdef UBIFS_LAYOUT
4#include "ubi/item_updater_ubi.hpp"
Lei YUda6ab6c2019-02-22 14:21:22 +08005#include "ubi/watch.hpp"
Lei YUf3ce4332019-02-21 14:09:49 +08006#endif
Gunnar Millsf6ed5892018-09-07 17:08:02 -05007
8#include <phosphor-logging/log.hpp>
Adriana Kobylak2d8fa222017-03-15 12:34:32 -05009#include <sdbusplus/bus.hpp>
10#include <sdbusplus/server/manager.hpp>
Gunnar Mills6bd6d7b2017-09-18 09:22:36 -050011#include <system_error>
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050012
13int main(int argc, char* argv[])
14{
Gunnar Mills6bd6d7b2017-09-18 09:22:36 -050015 using namespace openpower::software::updater;
16 using namespace phosphor::logging;
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050017 auto bus = sdbusplus::bus::new_default();
18
Gunnar Mills6bd6d7b2017-09-18 09:22:36 -050019 sd_event* loop = nullptr;
20 auto rc = sd_event_default(&loop);
21 if (rc < 0)
22 {
23 log<level::ERR>("Error occurred during the sd_event_default",
24 entry("RC=%d", rc));
25 return -1;
26 }
27
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050028 // Add sdbusplus ObjectManager.
29 sdbusplus::server::manager::manager objManager(bus, SOFTWARE_OBJPATH);
30
Lei YUf3ce4332019-02-21 14:09:49 +080031#ifdef UBIFS_LAYOUT
32 ItemUpdaterUbi updater(bus, SOFTWARE_OBJPATH);
33#endif
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050034
35 bus.request_name(BUSNAME_UPDATER);
Gunnar Mills6bd6d7b2017-09-18 09:22:36 -050036 try
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050037 {
Lei YUda6ab6c2019-02-22 14:21:22 +080038#ifdef UBIFS_LAYOUT
Gunnar Mills6bd6d7b2017-09-18 09:22:36 -050039 openpower::software::updater::Watch watch(
Adriana Kobylak70dcb632018-02-27 15:46:52 -060040 loop,
41 std::bind(std::mem_fn(&ItemUpdater::updateFunctionalAssociation),
42 &updater, std::placeholders::_1));
Lei YUda6ab6c2019-02-22 14:21:22 +080043#endif
Gunnar Mills6bd6d7b2017-09-18 09:22:36 -050044 bus.attach_event(loop, SD_EVENT_PRIORITY_NORMAL);
45 auto rc = sd_event_loop(loop);
46 if (rc < 0)
47 {
48 log<level::ERR>("Error occurred during the sd_event_loop",
49 entry("RC=%d", rc));
50 return -1;
51 }
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050052 }
Gunnar Mills6bd6d7b2017-09-18 09:22:36 -050053 catch (const std::system_error& e)
54 {
55 log<level::ERR>(e.what());
56 return -1;
57 }
58
59 sd_event_unref(loop);
60
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050061 return 0;
62}