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 | f3ce433 | 2019-02-21 14:09:49 +0800 | [diff] [blame] | 6 | #endif |
Gunnar Mills | f6ed589 | 2018-09-07 17:08:02 -0500 | [diff] [blame] | 7 | |
| 8 | #include <phosphor-logging/log.hpp> |
Adriana Kobylak | 2d8fa22 | 2017-03-15 12:34:32 -0500 | [diff] [blame] | 9 | #include <sdbusplus/bus.hpp> |
| 10 | #include <sdbusplus/server/manager.hpp> |
Gunnar Mills | 6bd6d7b | 2017-09-18 09:22:36 -0500 | [diff] [blame] | 11 | #include <system_error> |
Adriana Kobylak | 2d8fa22 | 2017-03-15 12:34:32 -0500 | [diff] [blame] | 12 | |
| 13 | int main(int argc, char* argv[]) |
| 14 | { |
Gunnar Mills | 6bd6d7b | 2017-09-18 09:22:36 -0500 | [diff] [blame] | 15 | using namespace openpower::software::updater; |
| 16 | using namespace phosphor::logging; |
Adriana Kobylak | 2d8fa22 | 2017-03-15 12:34:32 -0500 | [diff] [blame] | 17 | auto bus = sdbusplus::bus::new_default(); |
| 18 | |
Gunnar Mills | 6bd6d7b | 2017-09-18 09:22:36 -0500 | [diff] [blame] | 19 | sd_event* loop = nullptr; |
| 20 | auto rc = sd_event_default(&loop); |
| 21 | if (rc < 0) |
| 22 | { |
| 23 | log<level::ERR>("Error occurred during the sd_event_default", |
| 24 | entry("RC=%d", rc)); |
| 25 | return -1; |
| 26 | } |
| 27 | |
Adriana Kobylak | 2d8fa22 | 2017-03-15 12:34:32 -0500 | [diff] [blame] | 28 | // Add sdbusplus ObjectManager. |
| 29 | sdbusplus::server::manager::manager objManager(bus, SOFTWARE_OBJPATH); |
| 30 | |
Lei YU | f3ce433 | 2019-02-21 14:09:49 +0800 | [diff] [blame] | 31 | #ifdef UBIFS_LAYOUT |
| 32 | ItemUpdaterUbi updater(bus, SOFTWARE_OBJPATH); |
| 33 | #endif |
Adriana Kobylak | 2d8fa22 | 2017-03-15 12:34:32 -0500 | [diff] [blame] | 34 | |
| 35 | bus.request_name(BUSNAME_UPDATER); |
Gunnar Mills | 6bd6d7b | 2017-09-18 09:22:36 -0500 | [diff] [blame] | 36 | try |
Adriana Kobylak | 2d8fa22 | 2017-03-15 12:34:32 -0500 | [diff] [blame] | 37 | { |
Lei YU | da6ab6c | 2019-02-22 14:21:22 +0800 | [diff] [blame] | 38 | #ifdef UBIFS_LAYOUT |
Gunnar Mills | 6bd6d7b | 2017-09-18 09:22:36 -0500 | [diff] [blame] | 39 | openpower::software::updater::Watch watch( |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 40 | loop, |
| 41 | std::bind(std::mem_fn(&ItemUpdater::updateFunctionalAssociation), |
| 42 | &updater, std::placeholders::_1)); |
Lei YU | da6ab6c | 2019-02-22 14:21:22 +0800 | [diff] [blame] | 43 | #endif |
Gunnar Mills | 6bd6d7b | 2017-09-18 09:22:36 -0500 | [diff] [blame] | 44 | bus.attach_event(loop, SD_EVENT_PRIORITY_NORMAL); |
| 45 | auto rc = sd_event_loop(loop); |
| 46 | if (rc < 0) |
| 47 | { |
| 48 | log<level::ERR>("Error occurred during the sd_event_loop", |
| 49 | entry("RC=%d", rc)); |
| 50 | return -1; |
| 51 | } |
Adriana Kobylak | 2d8fa22 | 2017-03-15 12:34:32 -0500 | [diff] [blame] | 52 | } |
Gunnar Mills | 6bd6d7b | 2017-09-18 09:22:36 -0500 | [diff] [blame] | 53 | catch (const std::system_error& e) |
| 54 | { |
| 55 | log<level::ERR>(e.what()); |
| 56 | return -1; |
| 57 | } |
| 58 | |
| 59 | sd_event_unref(loop); |
| 60 | |
Adriana Kobylak | 2d8fa22 | 2017-03-15 12:34:32 -0500 | [diff] [blame] | 61 | return 0; |
| 62 | } |