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