blob: 9ba705bca8521651dc2dc7d0f5c8b671bdfaaacf [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 YU322f3f42019-02-21 16:10:41 +08006#else
7#include "static/item_updater_static.hpp"
Lei YUf3ce4332019-02-21 14:09:49 +08008#endif
Gunnar Millsf6ed5892018-09-07 17:08:02 -05009
10#include <phosphor-logging/log.hpp>
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050011#include <sdbusplus/bus.hpp>
12#include <sdbusplus/server/manager.hpp>
Gunnar Mills6bd6d7b2017-09-18 09:22:36 -050013#include <system_error>
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050014
15int main(int argc, char* argv[])
16{
Gunnar Mills6bd6d7b2017-09-18 09:22:36 -050017 using namespace openpower::software::updater;
18 using namespace phosphor::logging;
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050019 auto bus = sdbusplus::bus::new_default();
20
Gunnar Mills6bd6d7b2017-09-18 09:22:36 -050021 sd_event* loop = nullptr;
22 auto rc = sd_event_default(&loop);
23 if (rc < 0)
24 {
25 log<level::ERR>("Error occurred during the sd_event_default",
26 entry("RC=%d", rc));
27 return -1;
28 }
29
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050030 // Add sdbusplus ObjectManager.
31 sdbusplus::server::manager::manager objManager(bus, SOFTWARE_OBJPATH);
32
Lei YUf3ce4332019-02-21 14:09:49 +080033#ifdef UBIFS_LAYOUT
34 ItemUpdaterUbi updater(bus, SOFTWARE_OBJPATH);
Lei YU322f3f42019-02-21 16:10:41 +080035#else
36 ItemUpdaterStatic updater(bus, SOFTWARE_OBJPATH);
Lei YUf3ce4332019-02-21 14:09:49 +080037#endif
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050038
39 bus.request_name(BUSNAME_UPDATER);
Gunnar Mills6bd6d7b2017-09-18 09:22:36 -050040 try
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050041 {
Lei YUda6ab6c2019-02-22 14:21:22 +080042#ifdef UBIFS_LAYOUT
Gunnar Mills6bd6d7b2017-09-18 09:22:36 -050043 openpower::software::updater::Watch watch(
Adriana Kobylak70dcb632018-02-27 15:46:52 -060044 loop,
45 std::bind(std::mem_fn(&ItemUpdater::updateFunctionalAssociation),
46 &updater, std::placeholders::_1));
Lei YUda6ab6c2019-02-22 14:21:22 +080047#endif
Gunnar Mills6bd6d7b2017-09-18 09:22:36 -050048 bus.attach_event(loop, SD_EVENT_PRIORITY_NORMAL);
49 auto rc = sd_event_loop(loop);
50 if (rc < 0)
51 {
52 log<level::ERR>("Error occurred during the sd_event_loop",
53 entry("RC=%d", rc));
54 return -1;
55 }
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050056 }
Gunnar Mills6bd6d7b2017-09-18 09:22:36 -050057 catch (const std::system_error& e)
58 {
59 log<level::ERR>(e.what());
60 return -1;
61 }
62
63 sd_event_unref(loop);
64
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050065 return 0;
66}