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