summaryrefslogtreecommitdiffstats
path: root/cooling-type/main.cpp
blob: 3aa7d2805a87d3f41c1548b2b80491ba66789f60 (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
76
77
78
79
80
81
82
83
84
85
#include <iostream>
#include <memory>
#include <sdbusplus/bus.hpp>
#include <phosphor-logging/log.hpp>
#include "argument.hpp"
#include "cooling_type.hpp"
#include "sdbusplus.hpp"

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

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);

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

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

            auto gpiopath = (options)["dev"];
            if (gpiopath != ArgumentParser::empty_string)
            {
                auto keycode = (options)["event"];
                if (keycode != ArgumentParser::empty_string)
                {
                    auto gpiocode = std::stoul(keycode);
                    coolingType.readGpio(gpiopath, gpiocode);
                }
                else
                {
                    log<level::ERR>("--event=<keycode> argument required\n");
                    return rc;
                }
            }

            coolingType.updateInventory(objpath);
            rc = 0;
        }
        catch (DBusMethodError& dme)
        {
            log<level::ERR>("Uncaught DBus method failure exception",
                    entry("BUSNAME=%s", dme.busName.c_str()),
                    entry("PATH=%s", dme.path.c_str()),
                    entry("INTERFACE=%s", dme.interface.c_str()),
                    entry("METHOD=%s", dme.method.c_str()));
        }
        catch (std::exception& err)
        {
            log<phosphor::logging::level::ERR>(err.what());
        }

    }

    return rc;
}

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