Matthew Barth | 29e9e38 | 2020-01-23 13:40:49 -0600 | [diff] [blame] | 1 | /** |
| 2 | * Copyright © 2020 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 | |
| 17 | #include "manager.hpp" |
| 18 | |
| 19 | #include <sdbusplus/bus.hpp> |
| 20 | |
Matthew Barth | f2bcf1f | 2020-01-29 14:42:47 -0600 | [diff] [blame] | 21 | #include <chrono> |
| 22 | |
Matthew Barth | 29e9e38 | 2020-01-23 13:40:49 -0600 | [diff] [blame] | 23 | namespace phosphor |
| 24 | { |
| 25 | namespace power |
| 26 | { |
| 27 | namespace regulators |
| 28 | { |
| 29 | |
Matthew Barth | f2bcf1f | 2020-01-29 14:42:47 -0600 | [diff] [blame] | 30 | Manager::Manager(sdbusplus::bus::bus& bus, const sdeventplus::Event& event) : |
| 31 | ManagerObject(bus, objPath, true), bus(bus), eventLoop(event) |
Matthew Barth | 29e9e38 | 2020-01-23 13:40:49 -0600 | [diff] [blame] | 32 | { |
| 33 | // TODO get property (IM keyword) |
| 34 | // call parse json function |
| 35 | // TODO subscribe to interfacesadded (IM keyword) |
| 36 | // callback would call parse json function |
| 37 | |
| 38 | // Obtain dbus service name |
| 39 | bus.request_name(busName); |
| 40 | } |
| 41 | |
| 42 | void Manager::configure() |
| 43 | { |
| 44 | // TODO Configuration errors that should halt poweron, |
| 45 | // throw InternalFailure exception (or similar) to |
| 46 | // fail the call(busctl) to this method |
| 47 | } |
| 48 | |
| 49 | void Manager::monitor(bool enable) |
| 50 | { |
| 51 | if (enable) |
| 52 | { |
Matthew Barth | f2bcf1f | 2020-01-29 14:42:47 -0600 | [diff] [blame] | 53 | Timer timer(eventLoop, std::bind(&Manager::timerExpired, this)); |
| 54 | // Set timer as a repeating 1sec timer |
| 55 | timer.restart(std::chrono::milliseconds(1000)); |
| 56 | timers.emplace_back(std::move(timer)); |
Matthew Barth | 29e9e38 | 2020-01-23 13:40:49 -0600 | [diff] [blame] | 57 | } |
| 58 | else |
| 59 | { |
Matthew Barth | f2bcf1f | 2020-01-29 14:42:47 -0600 | [diff] [blame] | 60 | // Delete all timers to disable monitoring |
| 61 | timers.clear(); |
Matthew Barth | 29e9e38 | 2020-01-23 13:40:49 -0600 | [diff] [blame] | 62 | } |
| 63 | } |
| 64 | |
Matthew Barth | f2bcf1f | 2020-01-29 14:42:47 -0600 | [diff] [blame] | 65 | void Manager::timerExpired() |
| 66 | { |
| 67 | // TODO Analyze, refresh sensor status, and |
| 68 | // collect/update telemetry for each regulator |
| 69 | } |
| 70 | |
Matthew Barth | 7cbc553 | 2020-01-29 15:13:13 -0600 | [diff] [blame] | 71 | void Manager::sighupHandler(sdeventplus::source::Signal& /*sigSrc*/, |
| 72 | const struct signalfd_siginfo* /*sigInfo*/) |
| 73 | { |
| 74 | // TODO Reload and process the configuration data |
| 75 | } |
| 76 | |
Matthew Barth | 29e9e38 | 2020-01-23 13:40:49 -0600 | [diff] [blame] | 77 | } // namespace regulators |
| 78 | } // namespace power |
| 79 | } // namespace phosphor |