Shawn McCarney | 4e0402c | 2021-02-05 00:08:33 -0600 | [diff] [blame] | 1 | /** |
| 2 | * Copyright © 2021 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 <sdbusplus/bus.hpp> |
| 19 | |
Matt Spinler | aacc2aa | 2021-05-25 09:31:35 -0600 | [diff] [blame] | 20 | #include <cstdint> |
Shawn McCarney | 4e0402c | 2021-02-05 00:08:33 -0600 | [diff] [blame] | 21 | #include <map> |
| 22 | #include <string> |
Matt Spinler | aacc2aa | 2021-05-25 09:31:35 -0600 | [diff] [blame] | 23 | #include <vector> |
Shawn McCarney | 4e0402c | 2021-02-05 00:08:33 -0600 | [diff] [blame] | 24 | |
| 25 | namespace phosphor::power::regulators |
| 26 | { |
| 27 | |
| 28 | /** |
| 29 | * @class VPD |
| 30 | * |
| 31 | * Abstract base class that provides an interface to hardware VPD (Vital Product |
| 32 | * Data). |
| 33 | * |
| 34 | * The interface is used to obtain VPD keyword values. |
| 35 | */ |
| 36 | class VPD |
| 37 | { |
| 38 | public: |
| 39 | // Specify which compiler-generated methods we want |
| 40 | VPD() = default; |
| 41 | VPD(const VPD&) = delete; |
| 42 | VPD(VPD&&) = delete; |
| 43 | VPD& operator=(const VPD&) = delete; |
| 44 | VPD& operator=(VPD&&) = delete; |
| 45 | virtual ~VPD() = default; |
| 46 | |
| 47 | /** |
| 48 | * Clears any cached hardware VPD values. |
| 49 | */ |
| 50 | virtual void clearCache(void) = 0; |
| 51 | |
| 52 | /** |
| 53 | * Returns the value of the specified VPD keyword for the specified |
| 54 | * inventory path. |
| 55 | * |
| 56 | * May return a cached value if one is available to improve performance. |
| 57 | * |
| 58 | * Throws an exception if an error occurs while obtaining the VPD |
| 59 | * value. |
| 60 | * |
| 61 | * @param inventoryPath D-Bus inventory path of the hardware |
| 62 | * @param keyword VPD keyword |
| 63 | * @return VPD keyword value |
| 64 | */ |
Matt Spinler | aacc2aa | 2021-05-25 09:31:35 -0600 | [diff] [blame] | 65 | virtual std::vector<uint8_t> getValue(const std::string& inventoryPath, |
| 66 | const std::string& keyword) = 0; |
Shawn McCarney | 4e0402c | 2021-02-05 00:08:33 -0600 | [diff] [blame] | 67 | }; |
| 68 | |
| 69 | /** |
| 70 | * @class DBusVPD |
| 71 | * |
| 72 | * Implementation of the VPD interface using D-Bus method calls. |
| 73 | */ |
| 74 | class DBusVPD : public VPD |
| 75 | { |
| 76 | public: |
| 77 | // Specify which compiler-generated methods we want |
| 78 | DBusVPD() = delete; |
| 79 | DBusVPD(const DBusVPD&) = delete; |
| 80 | DBusVPD(DBusVPD&&) = delete; |
| 81 | DBusVPD& operator=(const DBusVPD&) = delete; |
| 82 | DBusVPD& operator=(DBusVPD&&) = delete; |
| 83 | virtual ~DBusVPD() = default; |
| 84 | |
| 85 | /** |
| 86 | * Constructor. |
| 87 | * |
| 88 | * @param bus D-Bus bus object |
| 89 | */ |
| 90 | explicit DBusVPD(sdbusplus::bus::bus& bus) : bus{bus} |
Adriana Kobylak | 0c9a33d | 2021-09-13 18:05:09 +0000 | [diff] [blame] | 91 | {} |
Shawn McCarney | 4e0402c | 2021-02-05 00:08:33 -0600 | [diff] [blame] | 92 | |
| 93 | /** @copydoc VPD::clearCache() */ |
| 94 | virtual void clearCache(void) override |
| 95 | { |
| 96 | cache.clear(); |
| 97 | } |
| 98 | |
| 99 | /** @copydoc VPD::getValue() */ |
Matt Spinler | aacc2aa | 2021-05-25 09:31:35 -0600 | [diff] [blame] | 100 | virtual std::vector<uint8_t> getValue(const std::string& inventoryPath, |
| 101 | const std::string& keyword) override; |
Shawn McCarney | 4e0402c | 2021-02-05 00:08:33 -0600 | [diff] [blame] | 102 | |
| 103 | private: |
| 104 | /** |
| 105 | * Type alias for map from keyword names to values. |
| 106 | */ |
Matt Spinler | aacc2aa | 2021-05-25 09:31:35 -0600 | [diff] [blame] | 107 | using KeywordMap = std::map<std::string, std::vector<uint8_t>>; |
Shawn McCarney | 4e0402c | 2021-02-05 00:08:33 -0600 | [diff] [blame] | 108 | |
| 109 | /** |
| 110 | * D-Bus bus object. |
| 111 | */ |
| 112 | sdbusplus::bus::bus& bus; |
| 113 | |
| 114 | /** |
| 115 | * Cached VPD keyword values. |
| 116 | * |
| 117 | * Map from inventory paths to VPD keywords. |
| 118 | */ |
| 119 | std::map<std::string, KeywordMap> cache{}; |
| 120 | }; |
| 121 | |
| 122 | } // namespace phosphor::power::regulators |