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