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