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