Andrew Geissler | a90a31a | 2016-12-13 16:16:28 -0600 | [diff] [blame] | 1 | #include "config.h" |
Andrew Geissler | e426b58 | 2020-05-28 12:40:55 -0500 | [diff] [blame] | 2 | |
Andrew Geissler | a90a31a | 2016-12-13 16:16:28 -0600 | [diff] [blame] | 3 | #include "chassis_state_manager.hpp" |
| 4 | |
Potin Lai | 70f36d8 | 2022-03-15 10:25:39 +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 <iostream> |
| 12 | |
Potin Lai | 70f36d8 | 2022-03-15 10:25:39 +0800 | [diff] [blame] | 13 | int main(int argc, char** argv) |
Andrew Geissler | a90a31a | 2016-12-13 16:16:28 -0600 | [diff] [blame] | 14 | { |
Potin Lai | 70f36d8 | 2022-03-15 10:25:39 +0800 | [diff] [blame] | 15 | size_t chassisId = 0; |
| 16 | int arg; |
| 17 | int optIndex = 0; |
| 18 | static struct option longOpts[] = {{"chassis", required_argument, 0, 'c'}, |
| 19 | {0, 0, 0, 0}}; |
| 20 | |
| 21 | while ((arg = getopt_long(argc, argv, "c:", longOpts, &optIndex)) != -1) |
| 22 | { |
| 23 | switch (arg) |
| 24 | { |
| 25 | case 'c': |
| 26 | chassisId = std::stoul(optarg); |
| 27 | break; |
| 28 | default: |
| 29 | break; |
| 30 | } |
| 31 | } |
| 32 | |
Andrew Geissler | a90a31a | 2016-12-13 16:16:28 -0600 | [diff] [blame] | 33 | auto bus = sdbusplus::bus::new_default(); |
| 34 | |
Potin Lai | 70f36d8 | 2022-03-15 10:25:39 +0800 | [diff] [blame] | 35 | auto chassisBusName = |
| 36 | std::string{CHASSIS_BUSNAME} + std::to_string(chassisId); |
| 37 | auto objPathInst = std::string{CHASSIS_OBJPATH} + std::to_string(chassisId); |
Andrew Geissler | a90a31a | 2016-12-13 16:16:28 -0600 | [diff] [blame] | 38 | |
| 39 | // Add sdbusplus ObjectManager. |
| 40 | sdbusplus::server::manager::manager objManager(bus, objPathInst.c_str()); |
Potin Lai | 70f36d8 | 2022-03-15 10:25:39 +0800 | [diff] [blame] | 41 | phosphor::state::manager::Chassis manager(bus, objPathInst.c_str(), |
| 42 | chassisId); |
Andrew Geissler | a90a31a | 2016-12-13 16:16:28 -0600 | [diff] [blame] | 43 | |
Potin Lai | 70f36d8 | 2022-03-15 10:25:39 +0800 | [diff] [blame] | 44 | // For backwards compatibility, request a busname without chassis id if |
| 45 | // input id is 0. |
| 46 | if (chassisId == 0) |
| 47 | { |
| 48 | bus.request_name(CHASSIS_BUSNAME); |
| 49 | } |
Andrew Geissler | a90a31a | 2016-12-13 16:16:28 -0600 | [diff] [blame] | 50 | |
Potin Lai | 70f36d8 | 2022-03-15 10:25:39 +0800 | [diff] [blame] | 51 | bus.request_name(chassisBusName.c_str()); |
Nagaraju Goruganti | cb781fe | 2018-04-06 13:41:01 -0500 | [diff] [blame] | 52 | manager.startPOHCounter(); |
Andrew Geissler | a90a31a | 2016-12-13 16:16:28 -0600 | [diff] [blame] | 53 | return 0; |
| 54 | } |