1 #include "argument.hpp" 2 #include "cooling_type.hpp" 3 #include "sdbusplus.hpp" 4 5 #include <phosphor-logging/log.hpp> 6 #include <sdbusplus/bus.hpp> 7 8 #include <iostream> 9 #include <memory> 10 11 using namespace phosphor::cooling::type; 12 using namespace phosphor::fan::util; 13 using namespace phosphor::logging; 14 15 int main(int argc, char* argv[]) 16 { 17 auto rc = 1; 18 auto options = ArgumentParser(argc, argv); 19 20 auto objpath = (options)["path"]; 21 if (argc < 2) 22 { 23 std::cerr << std::endl << "Too few arguments" << std::endl; 24 log<level::ERR>("Too few arguments"); 25 options.usage(argv); 26 } 27 else if (objpath == ArgumentParser::empty_string) 28 { 29 log<level::ERR>("Bus path argument required"); 30 } 31 else 32 { 33 auto bus = sdbusplus::bus::new_default(); 34 CoolingType coolingType(bus); 35 36 try 37 { 38 auto air = (options)["air"]; 39 if (air != ArgumentParser::empty_string) 40 { 41 coolingType.setAirCooled(); 42 } 43 44 auto water = (options)["water"]; 45 if (water != ArgumentParser::empty_string) 46 { 47 coolingType.setWaterCooled(); 48 } 49 50 auto gpiopath = (options)["dev"]; 51 if (gpiopath != ArgumentParser::empty_string) 52 { 53 auto keycode = (options)["event"]; 54 if (keycode != ArgumentParser::empty_string) 55 { 56 auto gpiocode = std::stoul(keycode); 57 coolingType.readGpio(gpiopath, gpiocode); 58 } 59 else 60 { 61 log<level::ERR>("--event=<keycode> argument required\n"); 62 return rc; 63 } 64 } 65 66 coolingType.updateInventory(objpath); 67 rc = 0; 68 } 69 catch (DBusMethodError& dme) 70 { 71 log<level::ERR>("Uncaught DBus method failure exception", 72 entry("BUSNAME=%s", dme.busName.c_str()), 73 entry("PATH=%s", dme.path.c_str()), 74 entry("INTERFACE=%s", dme.interface.c_str()), 75 entry("METHOD=%s", dme.method.c_str())); 76 } 77 catch (std::exception& err) 78 { 79 log<phosphor::logging::level::ERR>(err.what()); 80 } 81 } 82 83 return rc; 84 } 85 86 // vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 87