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