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