1 #include "argument.hpp"
2 #include "cooling_type.hpp"
3 #include "sdbusplus.hpp"
4 
5 #include <fmt/format.h>
6 
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     auto options = ArgumentParser(argc, argv);
21 
22     auto objpath = (options)["path"];
23     if (argc < 2)
24     {
25         std::cerr << std::endl << "Too few arguments" << std::endl;
26         log<level::ERR>("Too few arguments");
27         options.usage(argv);
28     }
29     else if (objpath == ArgumentParser::empty_string)
30     {
31         log<level::ERR>("Bus path argument required");
32     }
33     else
34     {
35         auto bus = sdbusplus::bus::new_default();
36         CoolingType coolingType(bus);
37 
38         try
39         {
40             auto air = (options)["air"];
41             if (air != ArgumentParser::empty_string)
42             {
43                 coolingType.setAirCooled();
44             }
45 
46             auto water = (options)["water"];
47             if (water != ArgumentParser::empty_string)
48             {
49                 coolingType.setWaterCooled();
50             }
51 
52             auto gpiopath = (options)["dev"];
53             if (gpiopath != ArgumentParser::empty_string)
54             {
55                 auto keycode = (options)["event"];
56                 if (keycode != ArgumentParser::empty_string)
57                 {
58                     auto gpiocode = std::stoul(keycode);
59                     coolingType.readGpio(gpiopath, gpiocode);
60                 }
61                 else
62                 {
63                     log<level::ERR>("--event=<keycode> argument required\n");
64                     return rc;
65                 }
66             }
67 
68             coolingType.updateInventory(objpath);
69             rc = 0;
70         }
71         catch (DBusMethodError& dme)
72         {
73             log<level::ERR>(
74                 fmt::format("Uncaught DBus method failure exception "
75                             "Busname: {} "
76                             "Path: {} "
77                             "Interface: {} "
78                             "Method: {}",
79                             dme.busName, dme.path, dme.interface, dme.method)
80                     .c_str());
81         }
82         catch (std::exception& err)
83         {
84             log<phosphor::logging::level::ERR>(err.what());
85         }
86     }
87 
88     return rc;
89 }
90 
91 // vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
92