Shawn McCarney | e0c6a2d | 2020-05-01 11:37:08 -0500 | [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 | */ |
Matthew Barth | 29e9e38 | 2020-01-23 13:40:49 -0600 | [diff] [blame] | 16 | #pragma once |
| 17 | |
Shawn McCarney | b464c8b | 2020-07-16 17:51:38 -0500 | [diff] [blame] | 18 | #include "services.hpp" |
Shawn McCarney | e0c6a2d | 2020-05-01 11:37:08 -0500 | [diff] [blame] | 19 | #include "system.hpp" |
| 20 | |
Matthew Barth | 29e9e38 | 2020-01-23 13:40:49 -0600 | [diff] [blame] | 21 | #include <interfaces/manager_interface.hpp> |
| 22 | #include <sdbusplus/bus.hpp> |
Matthew Barth | 250d0a9 | 2020-02-28 13:04:24 -0600 | [diff] [blame] | 23 | #include <sdbusplus/bus/match.hpp> |
Matthew Barth | 29e9e38 | 2020-01-23 13:40:49 -0600 | [diff] [blame] | 24 | #include <sdbusplus/server/object.hpp> |
Matthew Barth | f2bcf1f | 2020-01-29 14:42:47 -0600 | [diff] [blame] | 25 | #include <sdeventplus/event.hpp> |
Matthew Barth | 7cbc553 | 2020-01-29 15:13:13 -0600 | [diff] [blame] | 26 | #include <sdeventplus/source/signal.hpp> |
Matthew Barth | f2bcf1f | 2020-01-29 14:42:47 -0600 | [diff] [blame] | 27 | #include <sdeventplus/utility/timer.hpp> |
Matthew Barth | 29e9e38 | 2020-01-23 13:40:49 -0600 | [diff] [blame] | 28 | |
Shawn McCarney | e0c6a2d | 2020-05-01 11:37:08 -0500 | [diff] [blame] | 29 | #include <filesystem> |
| 30 | #include <memory> |
| 31 | #include <string> |
| 32 | #include <vector> |
Matthew Barth | bbc7c58 | 2020-02-03 15:55:15 -0600 | [diff] [blame] | 33 | |
Matthew Barth | 29e9e38 | 2020-01-23 13:40:49 -0600 | [diff] [blame] | 34 | namespace phosphor::power::regulators |
| 35 | { |
| 36 | |
Matthew Barth | f2bcf1f | 2020-01-29 14:42:47 -0600 | [diff] [blame] | 37 | using Timer = sdeventplus::utility::Timer<sdeventplus::ClockId::Monotonic>; |
| 38 | |
Matthew Barth | 29e9e38 | 2020-01-23 13:40:49 -0600 | [diff] [blame] | 39 | using ManagerObject = sdbusplus::server::object::object< |
| 40 | phosphor::power::regulators::interface::ManagerInterface>; |
| 41 | |
| 42 | class Manager : public ManagerObject |
| 43 | { |
| 44 | public: |
| 45 | Manager() = delete; |
| 46 | Manager(const Manager&) = delete; |
| 47 | Manager(Manager&&) = delete; |
| 48 | Manager& operator=(const Manager&) = delete; |
| 49 | Manager& operator=(Manager&&) = delete; |
| 50 | ~Manager() = default; |
| 51 | |
| 52 | /** |
| 53 | * Constructor |
| 54 | * Creates a manager over the regulators. |
| 55 | * |
Shawn McCarney | b464c8b | 2020-07-16 17:51:38 -0500 | [diff] [blame] | 56 | * @param bus the D-Bus bus |
Shawn McCarney | e0c6a2d | 2020-05-01 11:37:08 -0500 | [diff] [blame] | 57 | * @param event the sdevent event |
Matthew Barth | 29e9e38 | 2020-01-23 13:40:49 -0600 | [diff] [blame] | 58 | */ |
Matthew Barth | f2bcf1f | 2020-01-29 14:42:47 -0600 | [diff] [blame] | 59 | Manager(sdbusplus::bus::bus& bus, const sdeventplus::Event& event); |
Matthew Barth | 29e9e38 | 2020-01-23 13:40:49 -0600 | [diff] [blame] | 60 | |
| 61 | /** |
Shawn McCarney | e0c6a2d | 2020-05-01 11:37:08 -0500 | [diff] [blame] | 62 | * Overridden manager object's configure method |
Matthew Barth | 29e9e38 | 2020-01-23 13:40:49 -0600 | [diff] [blame] | 63 | */ |
| 64 | void configure() override; |
| 65 | |
| 66 | /** |
Shawn McCarney | 589c181 | 2021-01-14 12:13:26 -0600 | [diff] [blame^] | 67 | * Callback function to handle interfacesAdded D-Bus signals |
| 68 | * |
| 69 | * @param msg Expanded sdbusplus message data |
| 70 | */ |
| 71 | void interfacesAddedHandler(sdbusplus::message::message& msg); |
| 72 | |
| 73 | /** |
Shawn McCarney | e0c6a2d | 2020-05-01 11:37:08 -0500 | [diff] [blame] | 74 | * Overridden manager object's monitor method |
Matthew Barth | 29e9e38 | 2020-01-23 13:40:49 -0600 | [diff] [blame] | 75 | * |
Shawn McCarney | e0c6a2d | 2020-05-01 11:37:08 -0500 | [diff] [blame] | 76 | * @param enable Enable or disable regulator monitoring |
Matthew Barth | 29e9e38 | 2020-01-23 13:40:49 -0600 | [diff] [blame] | 77 | */ |
| 78 | void monitor(bool enable) override; |
| 79 | |
Matthew Barth | f2bcf1f | 2020-01-29 14:42:47 -0600 | [diff] [blame] | 80 | /** |
Shawn McCarney | e0c6a2d | 2020-05-01 11:37:08 -0500 | [diff] [blame] | 81 | * Callback function to handle receiving a HUP signal |
Matthew Barth | 7cbc553 | 2020-01-29 15:13:13 -0600 | [diff] [blame] | 82 | * to reload the configuration data. |
| 83 | * |
Shawn McCarney | e0c6a2d | 2020-05-01 11:37:08 -0500 | [diff] [blame] | 84 | * @param sigSrc sd_event_source signal wrapper |
| 85 | * @param sigInfo signal info on signal fd |
Matthew Barth | 7cbc553 | 2020-01-29 15:13:13 -0600 | [diff] [blame] | 86 | */ |
| 87 | void sighupHandler(sdeventplus::source::Signal& sigSrc, |
| 88 | const struct signalfd_siginfo* sigInfo); |
| 89 | |
Matthew Barth | 250d0a9 | 2020-02-28 13:04:24 -0600 | [diff] [blame] | 90 | /** |
Shawn McCarney | 589c181 | 2021-01-14 12:13:26 -0600 | [diff] [blame^] | 91 | * Timer expired callback function |
Matthew Barth | 250d0a9 | 2020-02-28 13:04:24 -0600 | [diff] [blame] | 92 | */ |
Shawn McCarney | 589c181 | 2021-01-14 12:13:26 -0600 | [diff] [blame^] | 93 | void timerExpired(); |
Matthew Barth | 250d0a9 | 2020-02-28 13:04:24 -0600 | [diff] [blame] | 94 | |
Matthew Barth | 29e9e38 | 2020-01-23 13:40:49 -0600 | [diff] [blame] | 95 | private: |
| 96 | /** |
Shawn McCarney | 589c181 | 2021-01-14 12:13:26 -0600 | [diff] [blame^] | 97 | * Finds the list of compatible system types using D-Bus methods. |
Matthew Barth | bbc7c58 | 2020-02-03 15:55:15 -0600 | [diff] [blame] | 98 | * |
Shawn McCarney | 589c181 | 2021-01-14 12:13:26 -0600 | [diff] [blame^] | 99 | * This list is used to find the correct JSON configuration file for the |
| 100 | * current system. |
Matthew Barth | bbc7c58 | 2020-02-03 15:55:15 -0600 | [diff] [blame] | 101 | * |
Shawn McCarney | 589c181 | 2021-01-14 12:13:26 -0600 | [diff] [blame^] | 102 | * Note that some systems do not support the D-Bus compatible interface. |
| 103 | * |
| 104 | * If a list of compatible system types is found, it is stored in the |
| 105 | * compatibleSystemTypes data member. |
Matthew Barth | bbc7c58 | 2020-02-03 15:55:15 -0600 | [diff] [blame] | 106 | */ |
Shawn McCarney | 589c181 | 2021-01-14 12:13:26 -0600 | [diff] [blame^] | 107 | void findCompatibleSystemTypes(); |
Shawn McCarney | e0c6a2d | 2020-05-01 11:37:08 -0500 | [diff] [blame] | 108 | |
| 109 | /** |
| 110 | * Finds the JSON configuration file. |
| 111 | * |
Shawn McCarney | 589c181 | 2021-01-14 12:13:26 -0600 | [diff] [blame^] | 112 | * Looks for a configuration file based on the list of compatable system |
| 113 | * types. If no file is found, looks for a file with the default name. |
Shawn McCarney | e0c6a2d | 2020-05-01 11:37:08 -0500 | [diff] [blame] | 114 | * |
Shawn McCarney | 589c181 | 2021-01-14 12:13:26 -0600 | [diff] [blame^] | 115 | * Looks for the file in the test directory and standard directory. |
Shawn McCarney | e0c6a2d | 2020-05-01 11:37:08 -0500 | [diff] [blame] | 116 | * |
Shawn McCarney | 589c181 | 2021-01-14 12:13:26 -0600 | [diff] [blame^] | 117 | * Throws an exception if an operating system error occurs while checking |
| 118 | * for the existance of a file. |
Shawn McCarney | e0c6a2d | 2020-05-01 11:37:08 -0500 | [diff] [blame] | 119 | * |
Shawn McCarney | 589c181 | 2021-01-14 12:13:26 -0600 | [diff] [blame^] | 120 | * @return absolute path to config file, or an empty path if none found |
Shawn McCarney | e0c6a2d | 2020-05-01 11:37:08 -0500 | [diff] [blame] | 121 | */ |
| 122 | std::filesystem::path findConfigFile(); |
| 123 | |
| 124 | /** |
| 125 | * Loads the JSON configuration file. |
| 126 | * |
Shawn McCarney | 589c181 | 2021-01-14 12:13:26 -0600 | [diff] [blame^] | 127 | * Looks for the config file using findConfigFile(). |
Shawn McCarney | e0c6a2d | 2020-05-01 11:37:08 -0500 | [diff] [blame] | 128 | * |
| 129 | * If the config file is found, it is parsed and the resulting information |
Shawn McCarney | 589c181 | 2021-01-14 12:13:26 -0600 | [diff] [blame^] | 130 | * is stored in the system data member. If parsing fails, an error is |
| 131 | * logged. |
Shawn McCarney | e0c6a2d | 2020-05-01 11:37:08 -0500 | [diff] [blame] | 132 | */ |
| 133 | void loadConfigFile(); |
| 134 | |
| 135 | /** |
Shawn McCarney | b464c8b | 2020-07-16 17:51:38 -0500 | [diff] [blame] | 136 | * The D-Bus bus |
Shawn McCarney | e0c6a2d | 2020-05-01 11:37:08 -0500 | [diff] [blame] | 137 | */ |
| 138 | sdbusplus::bus::bus& bus; |
| 139 | |
| 140 | /** |
| 141 | * Event to loop on |
| 142 | */ |
| 143 | sdeventplus::Event eventLoop; |
| 144 | |
| 145 | /** |
Shawn McCarney | b464c8b | 2020-07-16 17:51:38 -0500 | [diff] [blame] | 146 | * System services like error logging and the journal. |
| 147 | */ |
| 148 | BMCServices services; |
| 149 | |
| 150 | /** |
Shawn McCarney | e0c6a2d | 2020-05-01 11:37:08 -0500 | [diff] [blame] | 151 | * List of event timers |
| 152 | */ |
| 153 | std::vector<Timer> timers{}; |
| 154 | |
| 155 | /** |
| 156 | * List of dbus signal matches |
| 157 | */ |
| 158 | std::vector<std::unique_ptr<sdbusplus::bus::match::match>> signals{}; |
| 159 | |
| 160 | /** |
Shawn McCarney | 589c181 | 2021-01-14 12:13:26 -0600 | [diff] [blame^] | 161 | * List of compatible system types for the current system. |
| 162 | * |
| 163 | * Used to find the JSON configuration file. |
Shawn McCarney | e0c6a2d | 2020-05-01 11:37:08 -0500 | [diff] [blame] | 164 | */ |
Shawn McCarney | 589c181 | 2021-01-14 12:13:26 -0600 | [diff] [blame^] | 165 | std::vector<std::string> compatibleSystemTypes{}; |
Shawn McCarney | e0c6a2d | 2020-05-01 11:37:08 -0500 | [diff] [blame] | 166 | |
| 167 | /** |
| 168 | * Computer system being controlled and monitored by the BMC. |
| 169 | * |
| 170 | * Contains the information loaded from the JSON configuration file. |
| 171 | * Contains nullptr if the configuration file has not been loaded. |
| 172 | */ |
| 173 | std::unique_ptr<System> system{}; |
Matthew Barth | 29e9e38 | 2020-01-23 13:40:49 -0600 | [diff] [blame] | 174 | }; |
| 175 | |
| 176 | } // namespace phosphor::power::regulators |