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 | |
Matthew Barth | bbc7c58 | 2020-02-03 15:55:15 -0600 | [diff] [blame^] | 19 | #include "utility.hpp" |
| 20 | |
Matthew Barth | 29e9e38 | 2020-01-23 13:40:49 -0600 | [diff] [blame] | 21 | #include <sdbusplus/bus.hpp> |
| 22 | |
Matthew Barth | f2bcf1f | 2020-01-29 14:42:47 -0600 | [diff] [blame] | 23 | #include <chrono> |
| 24 | |
Matthew Barth | 29e9e38 | 2020-01-23 13:40:49 -0600 | [diff] [blame] | 25 | namespace phosphor |
| 26 | { |
| 27 | namespace power |
| 28 | { |
| 29 | namespace regulators |
| 30 | { |
| 31 | |
Matthew Barth | f2bcf1f | 2020-01-29 14:42:47 -0600 | [diff] [blame] | 32 | Manager::Manager(sdbusplus::bus::bus& bus, const sdeventplus::Event& event) : |
Matthew Barth | bbc7c58 | 2020-02-03 15:55:15 -0600 | [diff] [blame^] | 33 | ManagerObject(bus, objPath, true), bus(bus), eventLoop(event), fileName("") |
Matthew Barth | 29e9e38 | 2020-01-23 13:40:49 -0600 | [diff] [blame] | 34 | { |
Matthew Barth | bbc7c58 | 2020-02-03 15:55:15 -0600 | [diff] [blame^] | 35 | // Attempt to get the filename property from dbus |
| 36 | setFileName(getFileNameDbus()); |
| 37 | |
| 38 | // TODO Subscribe to interfacesAdded signal for filename property |
| 39 | // Callback should set fileName and call parse json function |
| 40 | |
| 41 | if (!fileName.empty()) |
| 42 | { |
| 43 | // TODO Load & parse JSON configuration data file |
| 44 | } |
Matthew Barth | 29e9e38 | 2020-01-23 13:40:49 -0600 | [diff] [blame] | 45 | |
| 46 | // Obtain dbus service name |
| 47 | bus.request_name(busName); |
| 48 | } |
| 49 | |
| 50 | void Manager::configure() |
| 51 | { |
| 52 | // TODO Configuration errors that should halt poweron, |
| 53 | // throw InternalFailure exception (or similar) to |
| 54 | // fail the call(busctl) to this method |
| 55 | } |
| 56 | |
| 57 | void Manager::monitor(bool enable) |
| 58 | { |
| 59 | if (enable) |
| 60 | { |
Matthew Barth | f2bcf1f | 2020-01-29 14:42:47 -0600 | [diff] [blame] | 61 | Timer timer(eventLoop, std::bind(&Manager::timerExpired, this)); |
| 62 | // Set timer as a repeating 1sec timer |
| 63 | timer.restart(std::chrono::milliseconds(1000)); |
| 64 | timers.emplace_back(std::move(timer)); |
Matthew Barth | 29e9e38 | 2020-01-23 13:40:49 -0600 | [diff] [blame] | 65 | } |
| 66 | else |
| 67 | { |
Matthew Barth | f2bcf1f | 2020-01-29 14:42:47 -0600 | [diff] [blame] | 68 | // Delete all timers to disable monitoring |
| 69 | timers.clear(); |
Matthew Barth | 29e9e38 | 2020-01-23 13:40:49 -0600 | [diff] [blame] | 70 | } |
| 71 | } |
| 72 | |
Matthew Barth | f2bcf1f | 2020-01-29 14:42:47 -0600 | [diff] [blame] | 73 | void Manager::timerExpired() |
| 74 | { |
| 75 | // TODO Analyze, refresh sensor status, and |
| 76 | // collect/update telemetry for each regulator |
| 77 | } |
| 78 | |
Matthew Barth | 7cbc553 | 2020-01-29 15:13:13 -0600 | [diff] [blame] | 79 | void Manager::sighupHandler(sdeventplus::source::Signal& /*sigSrc*/, |
| 80 | const struct signalfd_siginfo* /*sigInfo*/) |
| 81 | { |
| 82 | // TODO Reload and process the configuration data |
| 83 | } |
| 84 | |
Matthew Barth | bbc7c58 | 2020-02-03 15:55:15 -0600 | [diff] [blame^] | 85 | const std::string Manager::getFileNameDbus() |
| 86 | { |
| 87 | std::string fileName = ""; |
| 88 | using namespace phosphor::power::util; |
| 89 | |
| 90 | try |
| 91 | { |
| 92 | // Do not log an error when service or property are not found |
| 93 | auto service = getService(sysDbusPath, sysDbusIntf, bus, false); |
| 94 | if (!service.empty()) |
| 95 | { |
| 96 | getProperty(sysDbusIntf, sysDbusProp, sysDbusPath, service, bus, |
| 97 | fileName); |
| 98 | } |
| 99 | } |
| 100 | catch (const sdbusplus::exception::SdBusError&) |
| 101 | { |
| 102 | // File name property not available on dbus |
| 103 | fileName = ""; |
| 104 | } |
| 105 | |
| 106 | return fileName; |
| 107 | } |
| 108 | |
Matthew Barth | 29e9e38 | 2020-01-23 13:40:49 -0600 | [diff] [blame] | 109 | } // namespace regulators |
| 110 | } // namespace power |
| 111 | } // namespace phosphor |