Gunnar Mills | f6ed589 | 2018-09-07 17:08:02 -0500 | [diff] [blame] | 1 | #include "config.h" |
| 2 | |
Lei YU | f3ce433 | 2019-02-21 14:09:49 +0800 | [diff] [blame] | 3 | #ifdef UBIFS_LAYOUT |
| 4 | #include "ubi/item_updater_ubi.hpp" |
Lei YU | da6ab6c | 2019-02-22 14:21:22 +0800 | [diff] [blame] | 5 | #include "ubi/watch.hpp" |
Lei YU | 322f3f4 | 2019-02-21 16:10:41 +0800 | [diff] [blame] | 6 | #else |
| 7 | #include "static/item_updater_static.hpp" |
Lei YU | f3ce433 | 2019-02-21 14:09:49 +0800 | [diff] [blame] | 8 | #endif |
Gunnar Mills | f6ed589 | 2018-09-07 17:08:02 -0500 | [diff] [blame] | 9 | |
| 10 | #include <phosphor-logging/log.hpp> |
Adriana Kobylak | 2d8fa22 | 2017-03-15 12:34:32 -0500 | [diff] [blame] | 11 | #include <sdbusplus/bus.hpp> |
| 12 | #include <sdbusplus/server/manager.hpp> |
Gunnar Mills | 6bd6d7b | 2017-09-18 09:22:36 -0500 | [diff] [blame] | 13 | #include <system_error> |
Adriana Kobylak | 2d8fa22 | 2017-03-15 12:34:32 -0500 | [diff] [blame] | 14 | |
| 15 | int main(int argc, char* argv[]) |
| 16 | { |
Gunnar Mills | 6bd6d7b | 2017-09-18 09:22:36 -0500 | [diff] [blame] | 17 | using namespace openpower::software::updater; |
| 18 | using namespace phosphor::logging; |
Adriana Kobylak | 2d8fa22 | 2017-03-15 12:34:32 -0500 | [diff] [blame] | 19 | auto bus = sdbusplus::bus::new_default(); |
| 20 | |
Gunnar Mills | 6bd6d7b | 2017-09-18 09:22:36 -0500 | [diff] [blame] | 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 | |
Adriana Kobylak | 2d8fa22 | 2017-03-15 12:34:32 -0500 | [diff] [blame] | 30 | // Add sdbusplus ObjectManager. |
| 31 | sdbusplus::server::manager::manager objManager(bus, SOFTWARE_OBJPATH); |
| 32 | |
Lei YU | f3ce433 | 2019-02-21 14:09:49 +0800 | [diff] [blame] | 33 | #ifdef UBIFS_LAYOUT |
| 34 | ItemUpdaterUbi updater(bus, SOFTWARE_OBJPATH); |
Lei YU | 322f3f4 | 2019-02-21 16:10:41 +0800 | [diff] [blame] | 35 | #else |
| 36 | ItemUpdaterStatic updater(bus, SOFTWARE_OBJPATH); |
Lei YU | f3ce433 | 2019-02-21 14:09:49 +0800 | [diff] [blame] | 37 | #endif |
Adriana Kobylak | 2d8fa22 | 2017-03-15 12:34:32 -0500 | [diff] [blame] | 38 | |
| 39 | bus.request_name(BUSNAME_UPDATER); |
Gunnar Mills | 6bd6d7b | 2017-09-18 09:22:36 -0500 | [diff] [blame] | 40 | try |
Adriana Kobylak | 2d8fa22 | 2017-03-15 12:34:32 -0500 | [diff] [blame] | 41 | { |
Lei YU | da6ab6c | 2019-02-22 14:21:22 +0800 | [diff] [blame] | 42 | #ifdef UBIFS_LAYOUT |
Gunnar Mills | 6bd6d7b | 2017-09-18 09:22:36 -0500 | [diff] [blame] | 43 | openpower::software::updater::Watch watch( |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 44 | loop, |
| 45 | std::bind(std::mem_fn(&ItemUpdater::updateFunctionalAssociation), |
| 46 | &updater, std::placeholders::_1)); |
Lei YU | da6ab6c | 2019-02-22 14:21:22 +0800 | [diff] [blame] | 47 | #endif |
Gunnar Mills | 6bd6d7b | 2017-09-18 09:22:36 -0500 | [diff] [blame] | 48 | 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 Kobylak | 2d8fa22 | 2017-03-15 12:34:32 -0500 | [diff] [blame] | 56 | } |
Gunnar Mills | 6bd6d7b | 2017-09-18 09:22:36 -0500 | [diff] [blame] | 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 | |
Adriana Kobylak | 2d8fa22 | 2017-03-15 12:34:32 -0500 | [diff] [blame] | 65 | return 0; |
| 66 | } |