summaryrefslogtreecommitdiffstats
path: root/cooling-type/main.cpp
blob: cddbe3172848ffe6ca403bb1ef104c68eec0d3f5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include <iostream>
#include <memory> //make_unique
#include <sdbusplus/bus.hpp>
#include <phosphor-logging/log.hpp>
#include "argument.hpp"
#include "cooling_type.hpp"

using namespace phosphor::cooling::type;
using namespace phosphor::logging;

// Utility function to find the device string for a given pin name.
std::string findGpio(std::string pinName)
{
    std::string path = "/dev/null";
    //TODO
    return path;
}

int main(int argc, char* argv[])
{
    auto rc = -1;
    auto options = ArgumentParser(argc, argv);

    auto objpath = (options)["path"];
    if (argc < 2)
    {
        std::cerr << std::endl << "Too few arguments" << std::endl;
        log<level::ERR>("Too few arguments");
        options.usage(argv);
    }
    else if (objpath == ArgumentParser::empty_string)
    {
        log<level::ERR>("Bus path argument required");
    }
    else
    {
        auto bus = sdbusplus::bus::new_default();
        CoolingType coolingType(bus);

        auto gpiopin = (options)["gpio"];
        if (gpiopin != ArgumentParser::empty_string)
        {
            try
            {
                auto gpiopath = findGpio(gpiopin);
                coolingType.setupGpio(gpiopath);
            }
            catch (std::exception& err)
            {
                rc = -1;
                log<phosphor::logging::level::ERR>(err.what());
            }
        }

        auto air = (options)["air"];
        if (air != ArgumentParser::empty_string)
        {
            coolingType.setAirCooled();
        }

        auto water = (options)["water"];
        if (water != ArgumentParser::empty_string)
        {
            coolingType.setWaterCooled();
        }

        coolingType.updateInventory(objpath);

        rc = 0;
    }

    return rc;
}

// vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
OpenPOWER on IntegriCloud