Matt Spinler | afb3913 | 2017-08-14 13:53:07 -0500 | [diff] [blame] | 1 | /** |
| 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 Spinler | 56d90a8 | 2017-08-14 14:05:11 -0500 | [diff] [blame] | 18 | #include <phosphor-logging/log.hpp> |
Matt Spinler | afb3913 | 2017-08-14 13:53:07 -0500 | [diff] [blame] | 19 | #include "argument.hpp" |
Matt Spinler | 56d90a8 | 2017-08-14 14:05:11 -0500 | [diff] [blame] | 20 | #include "pgood_monitor.hpp" |
Matt Spinler | afb3913 | 2017-08-14 13:53:07 -0500 | [diff] [blame] | 21 | |
| 22 | using namespace witherspoon::power; |
Matt Spinler | 56d90a8 | 2017-08-14 14:05:11 -0500 | [diff] [blame] | 23 | using namespace phosphor::logging; |
Matt Spinler | afb3913 | 2017-08-14 13:53:07 -0500 | [diff] [blame] | 24 | |
| 25 | int 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 Spinler | 56d90a8 | 2017-08-14 14:05:11 -0500 | [diff] [blame] | 46 | 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 Spinler | afb3913 | 2017-08-14 13:53:07 -0500 | [diff] [blame] | 62 | } |