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