1 #include "config.h"
2 
3 #include "host_state_manager.hpp"
4 
5 #include <getopt.h>
6 
7 #include <sdbusplus/bus.hpp>
8 
9 #include <cstdlib>
10 #include <exception>
11 #include <filesystem>
12 #include <iostream>
13 
14 int main(int argc, char** argv)
15 {
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 
36     namespace fs = std::filesystem;
37 
38     auto bus = sdbusplus::bus::new_default();
39 
40     auto hostBusName = std::string{HOST_BUSNAME} + std::to_string(hostId);
41     auto objPathInst = std::string{HOST_OBJPATH} + std::to_string(hostId);
42 
43     // Add sdbusplus ObjectManager.
44     sdbusplus::server::manager::manager objManager(bus, objPathInst.c_str());
45 
46     phosphor::state::manager::Host manager(bus, objPathInst.c_str(), hostId);
47 
48     auto dir = fs::path(HOST_STATE_PERSIST_PATH).parent_path();
49     fs::create_directories(dir);
50 
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());
59 
60     while (true)
61     {
62         bus.process_discard();
63         bus.wait();
64     }
65     return 0;
66 }
67