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