1 #include "config.h"
2 
3 #include "chassis_state_manager.hpp"
4 
5 #include <getopt.h>
6 
7 #include <sdbusplus/bus.hpp>
8 
9 #include <cstdlib>
10 #include <exception>
11 #include <iostream>
12 
13 int main(int argc, char** argv)
14 {
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 
33     auto bus = sdbusplus::bus::new_default();
34 
35     auto chassisBusName =
36         std::string{CHASSIS_BUSNAME} + std::to_string(chassisId);
37     auto objPathInst = std::string{CHASSIS_OBJPATH} + std::to_string(chassisId);
38 
39     // Add sdbusplus ObjectManager.
40     sdbusplus::server::manager::manager objManager(bus, objPathInst.c_str());
41     phosphor::state::manager::Chassis manager(bus, objPathInst.c_str(),
42                                               chassisId);
43 
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     }
50 
51     bus.request_name(chassisBusName.c_str());
52     manager.startPOHCounter();
53     return 0;
54 }
55