Shawn McCarney | 8109502 | 2020-07-16 14:22:26 -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 | */ |
| 16 | #pragma once |
| 17 | |
Shawn McCarney | 8279a11 | 2021-04-27 16:51:30 -0500 | [diff] [blame] | 18 | #include "dbus_sensors.hpp" |
Shawn McCarney | 8109502 | 2020-07-16 14:22:26 -0500 | [diff] [blame] | 19 | #include "error_logging.hpp" |
| 20 | #include "journal.hpp" |
Shawn McCarney | d58858c | 2020-11-04 18:28:01 -0600 | [diff] [blame] | 21 | #include "presence_service.hpp" |
Shawn McCarney | 8279a11 | 2021-04-27 16:51:30 -0500 | [diff] [blame] | 22 | #include "sensors.hpp" |
Shawn McCarney | 4e0402c | 2021-02-05 00:08:33 -0600 | [diff] [blame] | 23 | #include "vpd.hpp" |
Shawn McCarney | 8109502 | 2020-07-16 14:22:26 -0500 | [diff] [blame] | 24 | |
| 25 | #include <sdbusplus/bus.hpp> |
| 26 | |
| 27 | namespace phosphor::power::regulators |
| 28 | { |
| 29 | |
| 30 | /** |
| 31 | * @class Services |
| 32 | * |
| 33 | * Abstract base class that provides an interface to system services like error |
| 34 | * logging and the journal. |
| 35 | * |
| 36 | * This interface is a container for a set of system services. It can be passed |
| 37 | * as a single parameter to the rest of the application. |
| 38 | */ |
| 39 | class Services |
| 40 | { |
| 41 | public: |
| 42 | // Specify which compiler-generated methods we want |
| 43 | Services() = default; |
| 44 | Services(const Services&) = delete; |
| 45 | Services(Services&&) = delete; |
| 46 | Services& operator=(const Services&) = delete; |
| 47 | Services& operator=(Services&&) = delete; |
| 48 | virtual ~Services() = default; |
| 49 | |
| 50 | /** |
| 51 | * Returns the D-Bus bus object. |
| 52 | * |
| 53 | * @return D-Bus bus |
| 54 | */ |
Patrick Williams | 7354ce6 | 2022-07-22 19:26:56 -0500 | [diff] [blame] | 55 | virtual sdbusplus::bus_t& getBus() = 0; |
Shawn McCarney | 8109502 | 2020-07-16 14:22:26 -0500 | [diff] [blame] | 56 | |
| 57 | /** |
| 58 | * Returns the error logging interface. |
| 59 | * |
| 60 | * @return error logging interface |
| 61 | */ |
| 62 | virtual ErrorLogging& getErrorLogging() = 0; |
| 63 | |
| 64 | /** |
| 65 | * Returns the journal interface. |
| 66 | * |
| 67 | * @return journal interface |
| 68 | */ |
| 69 | virtual Journal& getJournal() = 0; |
Shawn McCarney | d58858c | 2020-11-04 18:28:01 -0600 | [diff] [blame] | 70 | |
| 71 | /** |
| 72 | * Returns the interface to hardware presence data. |
| 73 | * |
| 74 | * @return hardware presence interface |
| 75 | */ |
| 76 | virtual PresenceService& getPresenceService() = 0; |
Shawn McCarney | 4e0402c | 2021-02-05 00:08:33 -0600 | [diff] [blame] | 77 | |
| 78 | /** |
Shawn McCarney | 8279a11 | 2021-04-27 16:51:30 -0500 | [diff] [blame] | 79 | * Returns the sensors interface. |
| 80 | * |
| 81 | * @return sensors interface |
| 82 | */ |
| 83 | virtual Sensors& getSensors() = 0; |
| 84 | |
| 85 | /** |
Shawn McCarney | 4e0402c | 2021-02-05 00:08:33 -0600 | [diff] [blame] | 86 | * Returns the interface to hardware VPD (Vital Product Data). |
| 87 | * |
| 88 | * @return hardware VPD interface |
| 89 | */ |
| 90 | virtual VPD& getVPD() = 0; |
Shawn McCarney | 8109502 | 2020-07-16 14:22:26 -0500 | [diff] [blame] | 91 | }; |
| 92 | |
| 93 | /** |
| 94 | * @class BMCServices |
| 95 | * |
| 96 | * Implementation of the Services interface using standard BMC system services. |
| 97 | */ |
| 98 | class BMCServices : public Services |
| 99 | { |
| 100 | public: |
| 101 | // Specify which compiler-generated methods we want |
| 102 | BMCServices() = delete; |
| 103 | BMCServices(const BMCServices&) = delete; |
| 104 | BMCServices(BMCServices&&) = delete; |
| 105 | BMCServices& operator=(const BMCServices&) = delete; |
| 106 | BMCServices& operator=(BMCServices&&) = delete; |
| 107 | virtual ~BMCServices() = default; |
| 108 | |
| 109 | /** |
| 110 | * Constructor. |
| 111 | * |
| 112 | * @param bus D-Bus bus object |
| 113 | */ |
Patrick Williams | 7354ce6 | 2022-07-22 19:26:56 -0500 | [diff] [blame] | 114 | explicit BMCServices(sdbusplus::bus_t& bus) : |
Patrick Williams | 48781ae | 2023-05-10 07:50:50 -0500 | [diff] [blame^] | 115 | bus{bus}, errorLogging{bus}, presenceService{bus}, sensors{bus}, |
| 116 | vpd{bus} |
Adriana Kobylak | 0c9a33d | 2021-09-13 18:05:09 +0000 | [diff] [blame] | 117 | {} |
Shawn McCarney | 8109502 | 2020-07-16 14:22:26 -0500 | [diff] [blame] | 118 | |
| 119 | /** @copydoc Services::getBus() */ |
Patrick Williams | 7354ce6 | 2022-07-22 19:26:56 -0500 | [diff] [blame] | 120 | virtual sdbusplus::bus_t& getBus() override |
Shawn McCarney | 8109502 | 2020-07-16 14:22:26 -0500 | [diff] [blame] | 121 | { |
| 122 | return bus; |
| 123 | } |
| 124 | |
| 125 | /** @copydoc Services::getErrorLogging() */ |
| 126 | virtual ErrorLogging& getErrorLogging() override |
| 127 | { |
| 128 | return errorLogging; |
| 129 | } |
| 130 | |
| 131 | /** @copydoc Services::getJournal() */ |
| 132 | virtual Journal& getJournal() override |
| 133 | { |
| 134 | return journal; |
| 135 | } |
| 136 | |
Shawn McCarney | d58858c | 2020-11-04 18:28:01 -0600 | [diff] [blame] | 137 | /** @copydoc Services::getPresenceService() */ |
| 138 | virtual PresenceService& getPresenceService() override |
| 139 | { |
| 140 | return presenceService; |
| 141 | } |
| 142 | |
Shawn McCarney | 8279a11 | 2021-04-27 16:51:30 -0500 | [diff] [blame] | 143 | /** @copydoc Services::getSensors() */ |
| 144 | virtual Sensors& getSensors() override |
| 145 | { |
| 146 | return sensors; |
| 147 | } |
| 148 | |
Shawn McCarney | 4e0402c | 2021-02-05 00:08:33 -0600 | [diff] [blame] | 149 | /** @copydoc Services::getVPD() */ |
| 150 | virtual VPD& getVPD() override |
| 151 | { |
| 152 | return vpd; |
| 153 | } |
| 154 | |
Shawn McCarney | 8109502 | 2020-07-16 14:22:26 -0500 | [diff] [blame] | 155 | private: |
| 156 | /** |
| 157 | * D-Bus bus object. |
| 158 | */ |
Patrick Williams | 7354ce6 | 2022-07-22 19:26:56 -0500 | [diff] [blame] | 159 | sdbusplus::bus_t& bus; |
Shawn McCarney | 8109502 | 2020-07-16 14:22:26 -0500 | [diff] [blame] | 160 | |
| 161 | /** |
| 162 | * Implementation of the ErrorLogging interface using D-Bus method calls. |
| 163 | */ |
| 164 | DBusErrorLogging errorLogging; |
| 165 | |
| 166 | /** |
| 167 | * Implementation of the Journal interface that writes to the systemd |
| 168 | * journal. |
| 169 | */ |
| 170 | SystemdJournal journal{}; |
Shawn McCarney | d58858c | 2020-11-04 18:28:01 -0600 | [diff] [blame] | 171 | |
| 172 | /** |
| 173 | * Implementation of the PresenceService interface using D-Bus method calls. |
| 174 | */ |
| 175 | DBusPresenceService presenceService; |
Shawn McCarney | 4e0402c | 2021-02-05 00:08:33 -0600 | [diff] [blame] | 176 | |
| 177 | /** |
Shawn McCarney | 8279a11 | 2021-04-27 16:51:30 -0500 | [diff] [blame] | 178 | * Implementation of the Sensors interface using D-Bus. |
| 179 | */ |
| 180 | DBusSensors sensors; |
| 181 | |
| 182 | /** |
Shawn McCarney | 4e0402c | 2021-02-05 00:08:33 -0600 | [diff] [blame] | 183 | * Implementation of the VPD interface using D-Bus method calls. |
| 184 | */ |
| 185 | DBusVPD vpd; |
Shawn McCarney | 8109502 | 2020-07-16 14:22:26 -0500 | [diff] [blame] | 186 | }; |
| 187 | |
| 188 | } // namespace phosphor::power::regulators |