Andrew Geissler | e426b58 | 2020-05-28 12:40:55 -0500 | [diff] [blame] | 1 | #include "config.h" |
| 2 | |
| 3 | #include "scheduled_host_transition.hpp" |
| 4 | |
| 5 | #include <sdbusplus/bus.hpp> |
| 6 | |
Carol Wang | 71230ef | 2020-02-18 17:39:49 +0800 | [diff] [blame] | 7 | #include <cstdlib> |
Carol Wang | 71230ef | 2020-02-18 17:39:49 +0800 | [diff] [blame] | 8 | #include <exception> |
Carol Wang | 1dbbef4 | 2020-03-09 11:51:23 +0800 | [diff] [blame] | 9 | #include <filesystem> |
Carol Wang | 71230ef | 2020-02-18 17:39:49 +0800 | [diff] [blame] | 10 | |
| 11 | int main() |
| 12 | { |
Carol Wang | 1dbbef4 | 2020-03-09 11:51:23 +0800 | [diff] [blame] | 13 | namespace fs = std::filesystem; |
| 14 | |
Carol Wang | 6a5db3d | 2020-02-21 10:12:01 +0800 | [diff] [blame] | 15 | // Get a default event loop |
| 16 | auto event = sdeventplus::Event::get_default(); |
| 17 | |
| 18 | // Get a handle to system dbus |
Carol Wang | 71230ef | 2020-02-18 17:39:49 +0800 | [diff] [blame] | 19 | auto bus = sdbusplus::bus::new_default(); |
| 20 | |
| 21 | // For now, we only have one instance of the host |
| 22 | auto objPathInst = std::string{HOST_OBJPATH} + '0'; |
| 23 | |
Carol Wang | 1dbbef4 | 2020-03-09 11:51:23 +0800 | [diff] [blame] | 24 | // Check SCHEDULED_HOST_TRANSITION_PERSIST_PATH |
| 25 | auto dir = fs::path(SCHEDULED_HOST_TRANSITION_PERSIST_PATH).parent_path(); |
| 26 | if (!fs::exists(dir)) |
| 27 | { |
| 28 | fs::create_directories(dir); |
| 29 | } |
| 30 | |
Carol Wang | 71230ef | 2020-02-18 17:39:49 +0800 | [diff] [blame] | 31 | // Add sdbusplus ObjectManager. |
| 32 | sdbusplus::server::manager::manager objManager(bus, objPathInst.c_str()); |
| 33 | |
| 34 | phosphor::state::manager::ScheduledHostTransition manager( |
Carol Wang | 6a5db3d | 2020-02-21 10:12:01 +0800 | [diff] [blame] | 35 | bus, objPathInst.c_str(), event); |
Carol Wang | 71230ef | 2020-02-18 17:39:49 +0800 | [diff] [blame] | 36 | |
| 37 | bus.request_name(SCHEDULED_HOST_TRANSITION_BUSNAME); |
| 38 | |
Carol Wang | 6a5db3d | 2020-02-21 10:12:01 +0800 | [diff] [blame] | 39 | // Attach the bus to sd_event to service user requests |
| 40 | bus.attach_event(event.get(), SD_EVENT_PRIORITY_NORMAL); |
| 41 | event.loop(); |
| 42 | |
Carol Wang | 71230ef | 2020-02-18 17:39:49 +0800 | [diff] [blame] | 43 | return 0; |
| 44 | } |