blob: 186e06bf17faa04f38109b403a132e30bff9f8a9 [file] [log] [blame]
Andrew Geissler36529022016-11-29 15:23:54 -06001#include "config.h"
Andrew Geisslere426b582020-05-28 12:40:55 -05002
Andrew Geissler36529022016-11-29 15:23:54 -06003#include "host_state_manager.hpp"
4
Allen.Wang79b45002022-02-10 17:59:20 +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 <experimental/filesystem>
12#include <iostream>
13
Allen.Wang79b45002022-02-10 17:59:20 +080014int main(int argc, char** argv)
Andrew Geissler36529022016-11-29 15:23:54 -060015{
Allen.Wang79b45002022-02-10 17:59:20 +080016 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 Subhashchandran3f475242017-07-12 00:44:27 -050036 namespace fs = std::experimental::filesystem;
37
Andrew Geissler36529022016-11-29 15:23:54 -060038 auto bus = sdbusplus::bus::new_default();
39
Allen.Wang79b45002022-02-10 17:59:20 +080040 auto hostBusName = std::string{HOST_BUSNAME} + std::to_string(hostId);
41 auto objPathInst = std::string{HOST_OBJPATH} + std::to_string(hostId);
Andrew Geissler1cb8b702016-12-13 13:33:06 -060042
Andrew Geissler36529022016-11-29 15:23:54 -060043 // Add sdbusplus ObjectManager.
Andrew Geissler1cb8b702016-12-13 13:33:06 -060044 sdbusplus::server::manager::manager objManager(bus, objPathInst.c_str());
Andrew Geissler36529022016-11-29 15:23:54 -060045
Allen.Wang79b45002022-02-10 17:59:20 +080046 phosphor::state::manager::Host manager(bus, objPathInst.c_str(), hostId);
Andrew Geisslera90a31a2016-12-13 16:16:28 -060047
Dhruvaraj Subhashchandran3f475242017-07-12 00:44:27 -050048 auto dir = fs::path(HOST_STATE_PERSIST_PATH).parent_path();
49 fs::create_directories(dir);
50
Allen.Wang79b45002022-02-10 17:59:20 +080051 // 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 Geissler36529022016-11-29 15:23:54 -060059
Andrew Geissler58a18012018-01-19 19:36:05 -080060 while (true)
Andrew Geissler36529022016-11-29 15:23:54 -060061 {
62 bus.process_discard();
63 bus.wait();
64 }
65 return 0;
66}