blob: eac4fd4c7a127732f8f3bb3a52e2b6d99260bf3a [file] [log] [blame]
Andrew Geisslera90a31a2016-12-13 16:16:28 -06001#include "config.h"
Andrew Geisslere426b582020-05-28 12:40:55 -05002
Andrew Geisslera90a31a2016-12-13 16:16:28 -06003#include "chassis_state_manager.hpp"
4
Potin Lai70f36d82022-03-15 10:25:39 +08005#include <getopt.h>
6
Andrew Geisslere426b582020-05-28 12:40:55 -05007#include <sdbusplus/bus.hpp>
8
9#include <cstdlib>
10#include <exception>
11#include <iostream>
12
Potin Lai70f36d82022-03-15 10:25:39 +080013int main(int argc, char** argv)
Andrew Geisslera90a31a2016-12-13 16:16:28 -060014{
Potin Lai70f36d82022-03-15 10:25:39 +080015 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 Geisslera90a31a2016-12-13 16:16:28 -060033 auto bus = sdbusplus::bus::new_default();
34
Potin Lai70f36d82022-03-15 10:25:39 +080035 auto chassisBusName =
36 std::string{CHASSIS_BUSNAME} + std::to_string(chassisId);
37 auto objPathInst = std::string{CHASSIS_OBJPATH} + std::to_string(chassisId);
Andrew Geisslera90a31a2016-12-13 16:16:28 -060038
39 // Add sdbusplus ObjectManager.
40 sdbusplus::server::manager::manager objManager(bus, objPathInst.c_str());
Potin Lai70f36d82022-03-15 10:25:39 +080041 phosphor::state::manager::Chassis manager(bus, objPathInst.c_str(),
42 chassisId);
Andrew Geisslera90a31a2016-12-13 16:16:28 -060043
Potin Lai70f36d82022-03-15 10:25:39 +080044 // 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 Geisslera90a31a2016-12-13 16:16:28 -060050
Potin Lai70f36d82022-03-15 10:25:39 +080051 bus.request_name(chassisBusName.c_str());
Nagaraju Goruganticb781fe2018-04-06 13:41:01 -050052 manager.startPOHCounter();
Andrew Geisslera90a31a2016-12-13 16:16:28 -060053 return 0;
54}