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