Jim Wright | 10eb00f | 2021-07-21 12:10:38 -0500 | [diff] [blame] | 1 | /** |
| 2 | * Copyright © 2021 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 | |
Jim Wright | 539b608 | 2021-08-02 14:50:23 -0500 | [diff] [blame] | 17 | #include "power_control.hpp" |
| 18 | |
| 19 | #include "types.hpp" |
| 20 | |
Jim Wright | 22318a3 | 2021-08-27 15:56:09 -0500 | [diff] [blame] | 21 | #include <fmt/format.h> |
| 22 | |
Jim Wright | 539b608 | 2021-08-02 14:50:23 -0500 | [diff] [blame] | 23 | #include <phosphor-logging/log.hpp> |
| 24 | #include <sdbusplus/bus.hpp> |
| 25 | #include <sdeventplus/event.hpp> |
| 26 | #include <sdeventplus/utility/timer.hpp> |
| 27 | |
| 28 | #include <chrono> |
| 29 | #include <exception> |
| 30 | |
| 31 | using namespace phosphor::logging; |
| 32 | |
| 33 | namespace phosphor::power::sequencer |
Jim Wright | 10eb00f | 2021-07-21 12:10:38 -0500 | [diff] [blame] | 34 | { |
Jim Wright | 539b608 | 2021-08-02 14:50:23 -0500 | [diff] [blame] | 35 | |
| 36 | PowerControl::PowerControl(sdbusplus::bus::bus& bus, |
| 37 | const sdeventplus::Event& event) : |
Jim Wright | 22318a3 | 2021-08-27 15:56:09 -0500 | [diff] [blame] | 38 | PowerObject{bus, POWER_OBJ_PATH, true}, |
| 39 | bus{bus}, timer{event, std::bind(&PowerControl::pollPgood, this), |
| 40 | pollInterval} |
Jim Wright | 539b608 | 2021-08-02 14:50:23 -0500 | [diff] [blame] | 41 | { |
| 42 | // Obtain dbus service name |
| 43 | bus.request_name(POWER_IFACE); |
Jim Wright | 10eb00f | 2021-07-21 12:10:38 -0500 | [diff] [blame] | 44 | } |
Jim Wright | 539b608 | 2021-08-02 14:50:23 -0500 | [diff] [blame] | 45 | |
Jim Wright | 22318a3 | 2021-08-27 15:56:09 -0500 | [diff] [blame] | 46 | int PowerControl::getPgood() const |
| 47 | { |
| 48 | return pgood; |
| 49 | } |
| 50 | |
| 51 | int PowerControl::getPgoodTimeout() const |
| 52 | { |
| 53 | return timeout.count(); |
| 54 | } |
| 55 | |
| 56 | int PowerControl::getState() const |
| 57 | { |
| 58 | return state; |
| 59 | } |
| 60 | |
Jim Wright | 539b608 | 2021-08-02 14:50:23 -0500 | [diff] [blame] | 61 | void PowerControl::pollPgood() |
Adriana Kobylak | 0c9a33d | 2021-09-13 18:05:09 +0000 | [diff] [blame] | 62 | {} |
Jim Wright | 539b608 | 2021-08-02 14:50:23 -0500 | [diff] [blame] | 63 | |
Jim Wright | 22318a3 | 2021-08-27 15:56:09 -0500 | [diff] [blame] | 64 | void PowerControl::setPgoodTimeout(int t) |
| 65 | { |
| 66 | if (timeout.count() != t) |
| 67 | { |
| 68 | timeout = std::chrono::seconds(t); |
| 69 | emitPropertyChangedSignal("pgood_timeout"); |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | void PowerControl::setState(int s) |
| 74 | { |
| 75 | if (state == s) |
| 76 | { |
| 77 | log<level::INFO>( |
| 78 | fmt::format("Power already at requested state: {}", state).c_str()); |
| 79 | return; |
| 80 | } |
| 81 | |
| 82 | log<level::INFO>(fmt::format("setState: {}", s).c_str()); |
| 83 | state = s; |
| 84 | emitPropertyChangedSignal("state"); |
| 85 | } |
| 86 | |
Jim Wright | 539b608 | 2021-08-02 14:50:23 -0500 | [diff] [blame] | 87 | } // namespace phosphor::power::sequencer |