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