1 #include "config.h"
2 
3 #ifdef UBIFS_LAYOUT
4 #include "ubi/item_updater_ubi.hpp"
5 #include "ubi/watch.hpp"
6 #elif defined MMC_LAYOUT
7 #include "mmc/item_updater_mmc.hpp"
8 #else
9 #include "static/item_updater_static.hpp"
10 #endif
11 
12 #include <phosphor-logging/log.hpp>
13 #include <sdbusplus/bus.hpp>
14 #include <sdbusplus/server/manager.hpp>
15 #include <system_error>
16 
17 int main(int argc, char* argv[])
18 {
19     using namespace openpower::software::updater;
20     using namespace phosphor::logging;
21     auto bus = sdbusplus::bus::new_default();
22 
23     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 
32     // Add sdbusplus ObjectManager.
33     sdbusplus::server::manager::manager objManager(bus, SOFTWARE_OBJPATH);
34 
35 #ifdef UBIFS_LAYOUT
36     ItemUpdaterUbi updater(bus, SOFTWARE_OBJPATH);
37 #elif defined MMC_LAYOUT
38     ItemUpdaterMMC updater(bus, SOFTWARE_OBJPATH);
39 #else
40     ItemUpdaterStatic updater(bus, SOFTWARE_OBJPATH);
41 #endif
42 
43     bus.request_name(BUSNAME_UPDATER);
44     try
45     {
46 #ifdef UBIFS_LAYOUT
47         openpower::software::updater::Watch watch(
48             loop,
49             std::bind(std::mem_fn(&ItemUpdater::updateFunctionalAssociation),
50                       &updater, std::placeholders::_1));
51 #endif
52         bus.attach_event(loop, SD_EVENT_PRIORITY_NORMAL);
53         rc = sd_event_loop(loop);
54         if (rc < 0)
55         {
56             log<level::ERR>("Error occurred during the sd_event_loop",
57                             entry("RC=%d", rc));
58             return -1;
59         }
60     }
61     catch (const std::system_error& e)
62     {
63         log<level::ERR>(e.what());
64         return -1;
65     }
66 
67     sd_event_unref(loop);
68 
69     return 0;
70 }
71