Andrew Geissler | e426b58 | 2020-05-28 12:40:55 -0500 | [diff] [blame] | 1 | #include "config.h" |
| 2 | |
| 3 | #include "scheduled_host_transition.hpp" |
| 4 | |
Patrick Williams | 211d972 | 2022-04-07 21:24:33 -0500 | [diff] [blame^] | 5 | #include <getopt.h> |
| 6 | |
Andrew Geissler | e426b58 | 2020-05-28 12:40:55 -0500 | [diff] [blame] | 7 | #include <sdbusplus/bus.hpp> |
| 8 | |
Carol Wang | 71230ef | 2020-02-18 17:39:49 +0800 | [diff] [blame] | 9 | #include <cstdlib> |
Carol Wang | 71230ef | 2020-02-18 17:39:49 +0800 | [diff] [blame] | 10 | #include <exception> |
Carol Wang | 1dbbef4 | 2020-03-09 11:51:23 +0800 | [diff] [blame] | 11 | #include <filesystem> |
Carol Wang | 71230ef | 2020-02-18 17:39:49 +0800 | [diff] [blame] | 12 | |
Patrick Williams | 211d972 | 2022-04-07 21:24:33 -0500 | [diff] [blame^] | 13 | int main(int argc, char** argv) |
Carol Wang | 71230ef | 2020-02-18 17:39:49 +0800 | [diff] [blame] | 14 | { |
Patrick Williams | 211d972 | 2022-04-07 21:24:33 -0500 | [diff] [blame^] | 15 | size_t hostId = 0; |
| 16 | |
| 17 | int arg; |
| 18 | int optIndex = 0; |
| 19 | |
| 20 | static struct option longOpts[] = {{"host", required_argument, 0, 'h'}, |
| 21 | {0, 0, 0, 0}}; |
| 22 | |
| 23 | while ((arg = getopt_long(argc, argv, "h:", longOpts, &optIndex)) != -1) |
| 24 | { |
| 25 | switch (arg) |
| 26 | { |
| 27 | case 'h': |
| 28 | hostId = std::stoul(optarg); |
| 29 | break; |
| 30 | default: |
| 31 | break; |
| 32 | } |
| 33 | } |
| 34 | |
Carol Wang | 1dbbef4 | 2020-03-09 11:51:23 +0800 | [diff] [blame] | 35 | namespace fs = std::filesystem; |
| 36 | |
Carol Wang | 6a5db3d | 2020-02-21 10:12:01 +0800 | [diff] [blame] | 37 | // Get a default event loop |
| 38 | auto event = sdeventplus::Event::get_default(); |
| 39 | |
| 40 | // Get a handle to system dbus |
Carol Wang | 71230ef | 2020-02-18 17:39:49 +0800 | [diff] [blame] | 41 | auto bus = sdbusplus::bus::new_default(); |
| 42 | |
| 43 | // For now, we only have one instance of the host |
Patrick Williams | 211d972 | 2022-04-07 21:24:33 -0500 | [diff] [blame^] | 44 | auto objPathInst = std::string{HOST_OBJPATH} + std::to_string(hostId); |
Carol Wang | 71230ef | 2020-02-18 17:39:49 +0800 | [diff] [blame] | 45 | |
Carol Wang | 1dbbef4 | 2020-03-09 11:51:23 +0800 | [diff] [blame] | 46 | // Check SCHEDULED_HOST_TRANSITION_PERSIST_PATH |
| 47 | auto dir = fs::path(SCHEDULED_HOST_TRANSITION_PERSIST_PATH).parent_path(); |
| 48 | if (!fs::exists(dir)) |
| 49 | { |
| 50 | fs::create_directories(dir); |
| 51 | } |
| 52 | |
Carol Wang | 71230ef | 2020-02-18 17:39:49 +0800 | [diff] [blame] | 53 | // Add sdbusplus ObjectManager. |
| 54 | sdbusplus::server::manager::manager objManager(bus, objPathInst.c_str()); |
| 55 | |
| 56 | phosphor::state::manager::ScheduledHostTransition manager( |
Patrick Williams | 211d972 | 2022-04-07 21:24:33 -0500 | [diff] [blame^] | 57 | bus, objPathInst.c_str(), hostId, event); |
Carol Wang | 71230ef | 2020-02-18 17:39:49 +0800 | [diff] [blame] | 58 | |
Patrick Williams | 211d972 | 2022-04-07 21:24:33 -0500 | [diff] [blame^] | 59 | bus.request_name((std::string{SCHEDULED_HOST_TRANSITION_BUSNAME} + |
| 60 | std::to_string(hostId)) |
| 61 | .c_str()); |
Carol Wang | 71230ef | 2020-02-18 17:39:49 +0800 | [diff] [blame] | 62 | |
Carol Wang | 6a5db3d | 2020-02-21 10:12:01 +0800 | [diff] [blame] | 63 | // Attach the bus to sd_event to service user requests |
| 64 | bus.attach_event(event.get(), SD_EVENT_PRIORITY_NORMAL); |
| 65 | event.loop(); |
| 66 | |
Carol Wang | 71230ef | 2020-02-18 17:39:49 +0800 | [diff] [blame] | 67 | return 0; |
| 68 | } |