1 #include "cooling_type.hpp"
2 #include "sdbusplus.hpp"
3
4 #include <CLI/CLI.hpp>
5 #include <phosphor-logging/log.hpp>
6 #include <sdbusplus/bus.hpp>
7
8 #include <format>
9 #include <iostream>
10 #include <memory>
11
12 using namespace phosphor::cooling::type;
13 using namespace phosphor::fan::util;
14 using namespace phosphor::logging;
15
main(int argc,char * argv[])16 int main(int argc, char* argv[])
17 {
18 auto rc = 1;
19
20 CLI::App app{"Phosphor Cooling type"};
21 std::string objpath{};
22 bool air = false;
23 bool water = false;
24 std::string gpiopath{};
25 std::string keycode{};
26
27 app.add_option("-p,--path", objpath,
28 "object path under inventory to have CoolingType updated")
29 ->required();
30 app.add_flag("-a,--air", air,
31 "Force 'AirCooled' property to be set to true.");
32 app.add_flag("-w,--water", water,
33 "Force 'WaterCooled' property to be set to true.");
34 app.add_option(
35 "-d,--dev", gpiopath,
36 "Device to read for GPIO pin state to determine 'WaterCooled' (true) and 'AirCooled' (false)");
37 app.add_option("-e,--event", keycode, "Keycode for pin to read");
38 app.allow_extras();
39 try
40 {
41 app.parse(argc, argv);
42 }
43 catch (const CLI::Error& e)
44 {
45 return app.exit(e);
46 }
47
48 if (objpath.empty())
49 {
50 log<level::ERR>("Bus path argument required");
51 return rc;
52 }
53
54 auto bus = sdbusplus::bus::new_default();
55 CoolingType coolingType(bus);
56
57 try
58 {
59 if (air)
60 {
61 coolingType.setAirCooled();
62 }
63
64 if (water)
65 {
66 coolingType.setWaterCooled();
67 }
68
69 if (!gpiopath.empty())
70 {
71 if (keycode.empty())
72 {
73 log<level::ERR>("--event=<keycode> argument required\n");
74 return rc;
75 }
76 auto gpiocode = std::stoul(keycode);
77 coolingType.readGpio(gpiopath, gpiocode);
78 }
79
80 coolingType.updateInventory(objpath);
81 rc = 0;
82 }
83 catch (const DBusMethodError& dme)
84 {
85 log<level::ERR>(
86 std::format("Uncaught DBus method failure exception "
87 "Busname: {} "
88 "Path: {} "
89 "Interface: {} "
90 "Method: {}",
91 dme.busName, dme.path, dme.interface, dme.method)
92 .c_str());
93 }
94 catch (const std::exception& err)
95 {
96 log<phosphor::logging::level::ERR>(err.what());
97 }
98
99 return rc;
100 }
101
102 // vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
103