blob: 69ee015c31284efe26435c51370a85a8c4dc24de [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"
Adriana Kobylak8bc2ab42020-07-15 09:16:27 -05006#elif defined MMC_LAYOUT
7#include "mmc/item_updater_mmc.hpp"
Lei YU322f3f42019-02-21 16:10:41 +08008#else
9#include "static/item_updater_static.hpp"
Lei YUf3ce4332019-02-21 14:09:49 +080010#endif
Gunnar Millsf6ed5892018-09-07 17:08:02 -050011
12#include <phosphor-logging/log.hpp>
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050013#include <sdbusplus/bus.hpp>
14#include <sdbusplus/server/manager.hpp>
Brad Bishop8facccf2020-11-04 09:44:58 -050015
Gunnar Mills6bd6d7b2017-09-18 09:22:36 -050016#include <system_error>
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050017
Brad Bishopc8f22502020-11-06 14:42:09 -050018int main(int, char*[])
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050019{
Gunnar Mills6bd6d7b2017-09-18 09:22:36 -050020 using namespace openpower::software::updater;
21 using namespace phosphor::logging;
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050022 auto bus = sdbusplus::bus::new_default();
23
Gunnar Mills6bd6d7b2017-09-18 09:22:36 -050024 sd_event* loop = nullptr;
25 auto rc = sd_event_default(&loop);
26 if (rc < 0)
27 {
28 log<level::ERR>("Error occurred during the sd_event_default",
29 entry("RC=%d", rc));
30 return -1;
31 }
32
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050033 // Add sdbusplus ObjectManager.
34 sdbusplus::server::manager::manager objManager(bus, SOFTWARE_OBJPATH);
35
Lei YUf3ce4332019-02-21 14:09:49 +080036#ifdef UBIFS_LAYOUT
37 ItemUpdaterUbi updater(bus, SOFTWARE_OBJPATH);
Adriana Kobylak8bc2ab42020-07-15 09:16:27 -050038#elif defined MMC_LAYOUT
39 ItemUpdaterMMC updater(bus, SOFTWARE_OBJPATH);
Lei YU322f3f42019-02-21 16:10:41 +080040#else
41 ItemUpdaterStatic updater(bus, SOFTWARE_OBJPATH);
Lei YUf3ce4332019-02-21 14:09:49 +080042#endif
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050043
44 bus.request_name(BUSNAME_UPDATER);
Gunnar Mills6bd6d7b2017-09-18 09:22:36 -050045 try
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050046 {
Lei YUda6ab6c2019-02-22 14:21:22 +080047#ifdef UBIFS_LAYOUT
Gunnar Mills6bd6d7b2017-09-18 09:22:36 -050048 openpower::software::updater::Watch watch(
Adriana Kobylak70dcb632018-02-27 15:46:52 -060049 loop,
50 std::bind(std::mem_fn(&ItemUpdater::updateFunctionalAssociation),
51 &updater, std::placeholders::_1));
Lei YUda6ab6c2019-02-22 14:21:22 +080052#endif
Gunnar Mills6bd6d7b2017-09-18 09:22:36 -050053 bus.attach_event(loop, SD_EVENT_PRIORITY_NORMAL);
Lei YU1db9adf2019-03-05 16:02:31 +080054 rc = sd_event_loop(loop);
Gunnar Mills6bd6d7b2017-09-18 09:22:36 -050055 if (rc < 0)
56 {
57 log<level::ERR>("Error occurred during the sd_event_loop",
58 entry("RC=%d", rc));
59 return -1;
60 }
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050061 }
Gunnar Mills6bd6d7b2017-09-18 09:22:36 -050062 catch (const std::system_error& e)
63 {
64 log<level::ERR>(e.what());
65 return -1;
66 }
67
68 sd_event_unref(loop);
69
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050070 return 0;
71}