blob: 85dc2b384ecabd6d803150c62470043e437ef8ac [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 Bishop0283f7c2020-11-09 10:09:26 -050015#include <sdeventplus/event.hpp>
Brad Bishop8facccf2020-11-04 09:44:58 -050016
Gunnar Mills6bd6d7b2017-09-18 09:22:36 -050017#include <system_error>
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050018
Brad Bishop1ee90952020-11-09 11:57:32 -050019namespace openpower
20{
21namespace software
22{
23namespace updater
24{
25void initializeService(sdbusplus::bus::bus& bus)
26{
27 sdbusplus::server::manager::manager objManager(bus, SOFTWARE_OBJPATH);
28#ifdef UBIFS_LAYOUT
29 static ItemUpdaterUbi updater(bus, SOFTWARE_OBJPATH);
30 static Watch watch(
31 bus.get_event(),
32 std::bind(std::mem_fn(&ItemUpdater::updateFunctionalAssociation),
33 &updater, std::placeholders::_1));
34#elif defined MMC_LAYOUT
35 static ItemUpdaterMMC updater(bus, SOFTWARE_OBJPATH);
36#else
37 static ItemUpdaterStatic updater(bus, SOFTWARE_OBJPATH);
38#endif
39 bus.request_name(BUSNAME_UPDATER);
40}
41} // namespace updater
42} // namespace software
43} // namespace openpower
44
Brad Bishopc8f22502020-11-06 14:42:09 -050045int main(int, char*[])
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050046{
Gunnar Mills6bd6d7b2017-09-18 09:22:36 -050047 using namespace openpower::software::updater;
48 using namespace phosphor::logging;
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050049 auto bus = sdbusplus::bus::new_default();
Brad Bishop0283f7c2020-11-09 10:09:26 -050050 auto loop = sdeventplus::Event::get_default();
Gunnar Mills6bd6d7b2017-09-18 09:22:36 -050051
Brad Bishop1ee90952020-11-09 11:57:32 -050052 bus.attach_event(loop.get(), SD_EVENT_PRIORITY_NORMAL);
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050053
Brad Bishop1ee90952020-11-09 11:57:32 -050054 initializeService(bus);
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050055
Gunnar Mills6bd6d7b2017-09-18 09:22:36 -050056 try
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050057 {
Brad Bishop0283f7c2020-11-09 10:09:26 -050058 auto rc = loop.loop();
Gunnar Mills6bd6d7b2017-09-18 09:22:36 -050059 if (rc < 0)
60 {
61 log<level::ERR>("Error occurred during the sd_event_loop",
62 entry("RC=%d", rc));
63 return -1;
64 }
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050065 }
Gunnar Mills6bd6d7b2017-09-18 09:22:36 -050066 catch (const std::system_error& e)
67 {
68 log<level::ERR>(e.what());
69 return -1;
70 }
71
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050072 return 0;
73}