blob: 074660d715fe6a1a97684e4b56bdd353926d5d61 [file] [log] [blame]
Matt Spinlerafb39132017-08-14 13:53:07 -05001/**
2 * Copyright © 2017 IBM Corporation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16#include <chrono>
17#include <iostream>
Matt Spinler56d90a82017-08-14 14:05:11 -050018#include <phosphor-logging/log.hpp>
Matt Spinlerafb39132017-08-14 13:53:07 -050019#include "argument.hpp"
Matt Spinler56d90a82017-08-14 14:05:11 -050020#include "pgood_monitor.hpp"
Matt Spinlerb2d72512017-08-22 09:07:01 -050021#include "ucd90160.hpp"
Matt Spinlerafb39132017-08-14 13:53:07 -050022
23using namespace witherspoon::power;
Matt Spinler56d90a82017-08-14 14:05:11 -050024using namespace phosphor::logging;
Matt Spinlerafb39132017-08-14 13:53:07 -050025
26int main(int argc, char** argv)
27{
28 ArgumentParser args{argc, argv};
29 auto action = args["action"];
30
31 if (action != "pgood-monitor")
32 {
33 std::cerr << "Invalid action\n";
34 args.usage(argv);
35 exit(EXIT_FAILURE);
36 }
37
38 auto i = strtoul(args["interval"].c_str(), nullptr, 10);
39 if (i == 0)
40 {
41 std::cerr << "Invalid interval value\n";
42 exit(EXIT_FAILURE);
43 }
44
45 std::chrono::seconds interval{i};
46
Matt Spinler56d90a82017-08-14 14:05:11 -050047 sd_event* e = nullptr;
48 auto r = sd_event_default(&e);
49 if (r < 0)
50 {
51 log<level::ERR>("sd_event_default() failed",
52 entry("ERROR=%s", strerror(-r)));
53 exit(EXIT_FAILURE);
54 }
55
56 event::Event event{e};
57 auto bus = sdbusplus::bus::new_default();
58 bus.attach_event(event.get(), SD_EVENT_PRIORITY_NORMAL);
59
Matt Spinlerb2d72512017-08-22 09:07:01 -050060 auto device = std::make_unique<UCD90160>(0);
61
62 PGOODMonitor monitor{std::move(device), bus, event, interval};
Matt Spinler56d90a82017-08-14 14:05:11 -050063
64 return monitor.run();
Matt Spinlerafb39132017-08-14 13:53:07 -050065}