Matt Spinler | 7084927 | 2017-08-22 09:14:40 -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 <phosphor-logging/log.hpp> |
Matt Spinler | 45a054a | 2017-08-22 15:07:07 -0500 | [diff] [blame] | 17 | #include "config.h" |
Matt Spinler | 7084927 | 2017-08-22 09:14:40 -0500 | [diff] [blame] | 18 | #include "runtime_monitor.hpp" |
| 19 | #include "utility.hpp" |
| 20 | |
| 21 | namespace witherspoon |
| 22 | { |
| 23 | namespace power |
| 24 | { |
| 25 | |
| 26 | using namespace phosphor::logging; |
| 27 | |
| 28 | int RuntimeMonitor::run() |
| 29 | { |
Matt Spinler | 45a054a | 2017-08-22 15:07:07 -0500 | [diff] [blame] | 30 | #ifdef UCD90160_DEVICE_ACCESS |
Matt Spinler | 7084927 | 2017-08-22 09:14:40 -0500 | [diff] [blame] | 31 | return DeviceMonitor::run(); |
Matt Spinler | 45a054a | 2017-08-22 15:07:07 -0500 | [diff] [blame] | 32 | #else |
| 33 | return EXIT_SUCCESS; |
| 34 | #endif |
Matt Spinler | 7084927 | 2017-08-22 09:14:40 -0500 | [diff] [blame] | 35 | } |
| 36 | |
| 37 | void RuntimeMonitor::onPowerLost(sdbusplus::message::message& msg) |
| 38 | { |
| 39 | log<level::INFO>("PGOOD failure detected. Checking for faults."); |
| 40 | |
| 41 | try |
| 42 | { |
| 43 | timer.stop(); |
| 44 | |
Matt Spinler | 45a054a | 2017-08-22 15:07:07 -0500 | [diff] [blame] | 45 | #ifdef UCD90160_DEVICE_ACCESS |
Matt Spinler | 7084927 | 2017-08-22 09:14:40 -0500 | [diff] [blame] | 46 | device->onFailure(); |
Matt Spinler | 45a054a | 2017-08-22 15:07:07 -0500 | [diff] [blame] | 47 | #endif |
Matt Spinler | 7084927 | 2017-08-22 09:14:40 -0500 | [diff] [blame] | 48 | //Note: This application only runs when the system has |
| 49 | //power, so it will be killed by systemd sometime shortly |
| 50 | //after this power off is issued. |
| 51 | |
| 52 | util::powerOff(bus); |
| 53 | } |
| 54 | catch (std::exception& e) |
| 55 | { |
| 56 | //No need to crash |
| 57 | log<level::ERR>(e.what()); |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | } |
| 62 | } |