blob: e2b579397f54cafd5db8aaaa8e312398839eb0fc [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>
Gunnar Mills6bd6d7b2017-09-18 09:22:36 -050015#include <system_error>
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050016
17int main(int argc, char* argv[])
18{
Gunnar Mills6bd6d7b2017-09-18 09:22:36 -050019 using namespace openpower::software::updater;
20 using namespace phosphor::logging;
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050021 auto bus = sdbusplus::bus::new_default();
22
Gunnar Mills6bd6d7b2017-09-18 09:22:36 -050023 sd_event* loop = nullptr;
24 auto rc = sd_event_default(&loop);
25 if (rc < 0)
26 {
27 log<level::ERR>("Error occurred during the sd_event_default",
28 entry("RC=%d", rc));
29 return -1;
30 }
31
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050032 // Add sdbusplus ObjectManager.
33 sdbusplus::server::manager::manager objManager(bus, SOFTWARE_OBJPATH);
34
Lei YUf3ce4332019-02-21 14:09:49 +080035#ifdef UBIFS_LAYOUT
36 ItemUpdaterUbi updater(bus, SOFTWARE_OBJPATH);
Adriana Kobylak8bc2ab42020-07-15 09:16:27 -050037#elif defined MMC_LAYOUT
38 ItemUpdaterMMC updater(bus, SOFTWARE_OBJPATH);
Lei YU322f3f42019-02-21 16:10:41 +080039#else
40 ItemUpdaterStatic updater(bus, SOFTWARE_OBJPATH);
Lei YUf3ce4332019-02-21 14:09:49 +080041#endif
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050042
43 bus.request_name(BUSNAME_UPDATER);
Gunnar Mills6bd6d7b2017-09-18 09:22:36 -050044 try
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050045 {
Lei YUda6ab6c2019-02-22 14:21:22 +080046#ifdef UBIFS_LAYOUT
Gunnar Mills6bd6d7b2017-09-18 09:22:36 -050047 openpower::software::updater::Watch watch(
Adriana Kobylak70dcb632018-02-27 15:46:52 -060048 loop,
49 std::bind(std::mem_fn(&ItemUpdater::updateFunctionalAssociation),
50 &updater, std::placeholders::_1));
Lei YUda6ab6c2019-02-22 14:21:22 +080051#endif
Gunnar Mills6bd6d7b2017-09-18 09:22:36 -050052 bus.attach_event(loop, SD_EVENT_PRIORITY_NORMAL);
Lei YU1db9adf2019-03-05 16:02:31 +080053 rc = sd_event_loop(loop);
Gunnar Mills6bd6d7b2017-09-18 09:22:36 -050054 if (rc < 0)
55 {
56 log<level::ERR>("Error occurred during the sd_event_loop",
57 entry("RC=%d", rc));
58 return -1;
59 }
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050060 }
Gunnar Mills6bd6d7b2017-09-18 09:22:36 -050061 catch (const std::system_error& e)
62 {
63 log<level::ERR>(e.what());
64 return -1;
65 }
66
67 sd_event_unref(loop);
68
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050069 return 0;
70}