Andrew Geissler | 3652902 | 2016-11-29 15:23:54 -0600 | [diff] [blame] | 1 | #include "config.h" |
Andrew Geissler | e426b58 | 2020-05-28 12:40:55 -0500 | [diff] [blame] | 2 | |
Andrew Geissler | 3652902 | 2016-11-29 15:23:54 -0600 | [diff] [blame] | 3 | #include "host_state_manager.hpp" |
| 4 | |
Allen.Wang | 79b4500 | 2022-02-10 17:59:20 +0800 | [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 | |
| 9 | #include <cstdlib> |
| 10 | #include <exception> |
| 11 | #include <experimental/filesystem> |
| 12 | #include <iostream> |
| 13 | |
Allen.Wang | 79b4500 | 2022-02-10 17:59:20 +0800 | [diff] [blame] | 14 | int main(int argc, char** argv) |
Andrew Geissler | 3652902 | 2016-11-29 15:23:54 -0600 | [diff] [blame] | 15 | { |
Allen.Wang | 79b4500 | 2022-02-10 17:59:20 +0800 | [diff] [blame] | 16 | size_t hostId = 0; |
| 17 | |
| 18 | int arg; |
| 19 | int optIndex = 0; |
| 20 | |
| 21 | static struct option longOpts[] = {{"host", required_argument, 0, 'h'}, |
| 22 | {0, 0, 0, 0}}; |
| 23 | |
| 24 | while ((arg = getopt_long(argc, argv, "h:", longOpts, &optIndex)) != -1) |
| 25 | { |
| 26 | switch (arg) |
| 27 | { |
| 28 | case 'h': |
| 29 | hostId = std::stoul(optarg); |
| 30 | break; |
| 31 | default: |
| 32 | break; |
| 33 | } |
| 34 | } |
| 35 | |
Dhruvaraj Subhashchandran | 3f47524 | 2017-07-12 00:44:27 -0500 | [diff] [blame] | 36 | namespace fs = std::experimental::filesystem; |
| 37 | |
Andrew Geissler | 3652902 | 2016-11-29 15:23:54 -0600 | [diff] [blame] | 38 | auto bus = sdbusplus::bus::new_default(); |
| 39 | |
Allen.Wang | 79b4500 | 2022-02-10 17:59:20 +0800 | [diff] [blame] | 40 | auto hostBusName = std::string{HOST_BUSNAME} + std::to_string(hostId); |
| 41 | auto objPathInst = std::string{HOST_OBJPATH} + std::to_string(hostId); |
Andrew Geissler | 1cb8b70 | 2016-12-13 13:33:06 -0600 | [diff] [blame] | 42 | |
Andrew Geissler | 3652902 | 2016-11-29 15:23:54 -0600 | [diff] [blame] | 43 | // Add sdbusplus ObjectManager. |
Andrew Geissler | 1cb8b70 | 2016-12-13 13:33:06 -0600 | [diff] [blame] | 44 | sdbusplus::server::manager::manager objManager(bus, objPathInst.c_str()); |
Andrew Geissler | 3652902 | 2016-11-29 15:23:54 -0600 | [diff] [blame] | 45 | |
Allen.Wang | 79b4500 | 2022-02-10 17:59:20 +0800 | [diff] [blame] | 46 | phosphor::state::manager::Host manager(bus, objPathInst.c_str(), hostId); |
Andrew Geissler | a90a31a | 2016-12-13 16:16:28 -0600 | [diff] [blame] | 47 | |
Dhruvaraj Subhashchandran | 3f47524 | 2017-07-12 00:44:27 -0500 | [diff] [blame] | 48 | auto dir = fs::path(HOST_STATE_PERSIST_PATH).parent_path(); |
| 49 | fs::create_directories(dir); |
| 50 | |
Allen.Wang | 79b4500 | 2022-02-10 17:59:20 +0800 | [diff] [blame] | 51 | // For backwards compatibility, request a busname without host id if |
| 52 | // input id is 0. |
| 53 | if (hostId == 0) |
| 54 | { |
| 55 | bus.request_name(HOST_BUSNAME); |
| 56 | } |
| 57 | |
| 58 | bus.request_name(hostBusName.c_str()); |
Andrew Geissler | 3652902 | 2016-11-29 15:23:54 -0600 | [diff] [blame] | 59 | |
Andrew Geissler | 58a1801 | 2018-01-19 19:36:05 -0800 | [diff] [blame] | 60 | while (true) |
Andrew Geissler | 3652902 | 2016-11-29 15:23:54 -0600 | [diff] [blame] | 61 | { |
| 62 | bus.process_discard(); |
| 63 | bus.wait(); |
| 64 | } |
| 65 | return 0; |
| 66 | } |