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" |
Adriana Kobylak | 8bc2ab4 | 2020-07-15 09:16:27 -0500 | [diff] [blame] | 6 | #elif defined MMC_LAYOUT |
| 7 | #include "mmc/item_updater_mmc.hpp" |
Lei YU | 322f3f4 | 2019-02-21 16:10:41 +0800 | [diff] [blame] | 8 | #else |
| 9 | #include "static/item_updater_static.hpp" |
Lei YU | f3ce433 | 2019-02-21 14:09:49 +0800 | [diff] [blame] | 10 | #endif |
Gunnar Mills | f6ed589 | 2018-09-07 17:08:02 -0500 | [diff] [blame] | 11 | |
| 12 | #include <phosphor-logging/log.hpp> |
Adriana Kobylak | 2d8fa22 | 2017-03-15 12:34:32 -0500 | [diff] [blame] | 13 | #include <sdbusplus/bus.hpp> |
| 14 | #include <sdbusplus/server/manager.hpp> |
Brad Bishop | 0283f7c | 2020-11-09 10:09:26 -0500 | [diff] [blame] | 15 | #include <sdeventplus/event.hpp> |
Brad Bishop | 8facccf | 2020-11-04 09:44:58 -0500 | [diff] [blame] | 16 | |
Gunnar Mills | 6bd6d7b | 2017-09-18 09:22:36 -0500 | [diff] [blame] | 17 | #include <system_error> |
Adriana Kobylak | 2d8fa22 | 2017-03-15 12:34:32 -0500 | [diff] [blame] | 18 | |
Brad Bishop | 1ee9095 | 2020-11-09 11:57:32 -0500 | [diff] [blame^] | 19 | namespace openpower |
| 20 | { |
| 21 | namespace software |
| 22 | { |
| 23 | namespace updater |
| 24 | { |
| 25 | void initializeService(sdbusplus::bus::bus& bus) |
| 26 | { |
| 27 | sdbusplus::server::manager::manager objManager(bus, SOFTWARE_OBJPATH); |
| 28 | #ifdef UBIFS_LAYOUT |
| 29 | static ItemUpdaterUbi updater(bus, SOFTWARE_OBJPATH); |
| 30 | static Watch watch( |
| 31 | bus.get_event(), |
| 32 | std::bind(std::mem_fn(&ItemUpdater::updateFunctionalAssociation), |
| 33 | &updater, std::placeholders::_1)); |
| 34 | #elif defined MMC_LAYOUT |
| 35 | static ItemUpdaterMMC updater(bus, SOFTWARE_OBJPATH); |
| 36 | #else |
| 37 | static ItemUpdaterStatic updater(bus, SOFTWARE_OBJPATH); |
| 38 | #endif |
| 39 | bus.request_name(BUSNAME_UPDATER); |
| 40 | } |
| 41 | } // namespace updater |
| 42 | } // namespace software |
| 43 | } // namespace openpower |
| 44 | |
Brad Bishop | c8f2250 | 2020-11-06 14:42:09 -0500 | [diff] [blame] | 45 | int main(int, char*[]) |
Adriana Kobylak | 2d8fa22 | 2017-03-15 12:34:32 -0500 | [diff] [blame] | 46 | { |
Gunnar Mills | 6bd6d7b | 2017-09-18 09:22:36 -0500 | [diff] [blame] | 47 | using namespace openpower::software::updater; |
| 48 | using namespace phosphor::logging; |
Adriana Kobylak | 2d8fa22 | 2017-03-15 12:34:32 -0500 | [diff] [blame] | 49 | auto bus = sdbusplus::bus::new_default(); |
Brad Bishop | 0283f7c | 2020-11-09 10:09:26 -0500 | [diff] [blame] | 50 | auto loop = sdeventplus::Event::get_default(); |
Gunnar Mills | 6bd6d7b | 2017-09-18 09:22:36 -0500 | [diff] [blame] | 51 | |
Brad Bishop | 1ee9095 | 2020-11-09 11:57:32 -0500 | [diff] [blame^] | 52 | bus.attach_event(loop.get(), SD_EVENT_PRIORITY_NORMAL); |
Adriana Kobylak | 2d8fa22 | 2017-03-15 12:34:32 -0500 | [diff] [blame] | 53 | |
Brad Bishop | 1ee9095 | 2020-11-09 11:57:32 -0500 | [diff] [blame^] | 54 | initializeService(bus); |
Adriana Kobylak | 2d8fa22 | 2017-03-15 12:34:32 -0500 | [diff] [blame] | 55 | |
Gunnar Mills | 6bd6d7b | 2017-09-18 09:22:36 -0500 | [diff] [blame] | 56 | try |
Adriana Kobylak | 2d8fa22 | 2017-03-15 12:34:32 -0500 | [diff] [blame] | 57 | { |
Brad Bishop | 0283f7c | 2020-11-09 10:09:26 -0500 | [diff] [blame] | 58 | auto rc = loop.loop(); |
Gunnar Mills | 6bd6d7b | 2017-09-18 09:22:36 -0500 | [diff] [blame] | 59 | if (rc < 0) |
| 60 | { |
| 61 | log<level::ERR>("Error occurred during the sd_event_loop", |
| 62 | entry("RC=%d", rc)); |
| 63 | return -1; |
| 64 | } |
Adriana Kobylak | 2d8fa22 | 2017-03-15 12:34:32 -0500 | [diff] [blame] | 65 | } |
Gunnar Mills | 6bd6d7b | 2017-09-18 09:22:36 -0500 | [diff] [blame] | 66 | catch (const std::system_error& e) |
| 67 | { |
| 68 | log<level::ERR>(e.what()); |
| 69 | return -1; |
| 70 | } |
| 71 | |
Adriana Kobylak | 2d8fa22 | 2017-03-15 12:34:32 -0500 | [diff] [blame] | 72 | return 0; |
| 73 | } |