blob: 1f77e55f73cabbd16d229966cf7aa06a0679f022 [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 Spinlerafb39132017-08-14 13:53:07 -050021
22using namespace witherspoon::power;
Matt Spinler56d90a82017-08-14 14:05:11 -050023using namespace phosphor::logging;
Matt Spinlerafb39132017-08-14 13:53:07 -050024
25int main(int argc, char** argv)
26{
27 ArgumentParser args{argc, argv};
28 auto action = args["action"];
29
30 if (action != "pgood-monitor")
31 {
32 std::cerr << "Invalid action\n";
33 args.usage(argv);
34 exit(EXIT_FAILURE);
35 }
36
37 auto i = strtoul(args["interval"].c_str(), nullptr, 10);
38 if (i == 0)
39 {
40 std::cerr << "Invalid interval value\n";
41 exit(EXIT_FAILURE);
42 }
43
44 std::chrono::seconds interval{i};
45
Matt Spinler56d90a82017-08-14 14:05:11 -050046 sd_event* e = nullptr;
47 auto r = sd_event_default(&e);
48 if (r < 0)
49 {
50 log<level::ERR>("sd_event_default() failed",
51 entry("ERROR=%s", strerror(-r)));
52 exit(EXIT_FAILURE);
53 }
54
55 event::Event event{e};
56 auto bus = sdbusplus::bus::new_default();
57 bus.attach_event(event.get(), SD_EVENT_PRIORITY_NORMAL);
58
59 PGOODMonitor monitor{bus, event, interval};
60
61 return monitor.run();
Matt Spinlerafb39132017-08-14 13:53:07 -050062}