Bob King | 8e4cb64 | 2020-04-24 13:18:53 +0800 | [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 "action.hpp" |
| 19 | #include "action_environment.hpp" |
| 20 | |
Matt Spinler | aacc2aa | 2021-05-25 09:31:35 -0600 | [diff] [blame] | 21 | #include <cstdint> |
Bob King | 8e4cb64 | 2020-04-24 13:18:53 +0800 | [diff] [blame] | 22 | #include <string> |
Matt Spinler | aacc2aa | 2021-05-25 09:31:35 -0600 | [diff] [blame] | 23 | #include <vector> |
Bob King | 8e4cb64 | 2020-04-24 13:18:53 +0800 | [diff] [blame] | 24 | |
| 25 | namespace phosphor::power::regulators |
| 26 | { |
| 27 | |
| 28 | /** |
| 29 | * @class CompareVPDAction |
| 30 | * |
| 31 | * Compares a VPD (Vital Product Data) keyword value to an expected value. |
| 32 | * |
| 33 | * Implements the compare_vpd action in the JSON config file. |
| 34 | */ |
| 35 | class CompareVPDAction : public Action |
| 36 | { |
| 37 | public: |
| 38 | // Specify which compiler-generated methods we want |
| 39 | CompareVPDAction() = delete; |
| 40 | CompareVPDAction(const CompareVPDAction&) = delete; |
| 41 | CompareVPDAction(CompareVPDAction&&) = delete; |
| 42 | CompareVPDAction& operator=(const CompareVPDAction&) = delete; |
| 43 | CompareVPDAction& operator=(CompareVPDAction&&) = delete; |
| 44 | virtual ~CompareVPDAction() = default; |
| 45 | |
| 46 | /** |
| 47 | * Constructor. |
| 48 | * |
| 49 | * @param fru Field-Replaceable Unit (FRU). Specify the D-Bus inventory path |
| 50 | * of the FRU. |
| 51 | * @param keyword VPD keyword. Specify one of the following: "CCIN", |
| 52 | * "Manufacturer", "Model", "PartNumber". |
| 53 | * @param value Expected value |
| 54 | */ |
| 55 | explicit CompareVPDAction(const std::string& fru, |
| 56 | const std::string& keyword, |
Matt Spinler | aacc2aa | 2021-05-25 09:31:35 -0600 | [diff] [blame] | 57 | const std::vector<uint8_t>& value) : |
Bob King | 8e4cb64 | 2020-04-24 13:18:53 +0800 | [diff] [blame] | 58 | fru{fru}, |
| 59 | keyword{keyword}, value{value} |
Adriana Kobylak | 0c9a33d | 2021-09-13 18:05:09 +0000 | [diff] [blame] | 60 | {} |
Bob King | 8e4cb64 | 2020-04-24 13:18:53 +0800 | [diff] [blame] | 61 | |
| 62 | /** |
| 63 | * Executes this action. |
| 64 | * |
Shawn McCarney | 45907cc | 2021-02-05 17:33:11 -0600 | [diff] [blame] | 65 | * Compares the actual VPD keyword value to the expected value. |
Bob King | 8e4cb64 | 2020-04-24 13:18:53 +0800 | [diff] [blame] | 66 | * |
Shawn McCarney | 45907cc | 2021-02-05 17:33:11 -0600 | [diff] [blame] | 67 | * Throws an exception if an error occurs. |
| 68 | * |
| 69 | * @param environment action execution environment |
| 70 | * @return true if the keyword value equals the expected value, otherwise |
| 71 | * returns false |
Bob King | 8e4cb64 | 2020-04-24 13:18:53 +0800 | [diff] [blame] | 72 | */ |
Shawn McCarney | 45907cc | 2021-02-05 17:33:11 -0600 | [diff] [blame] | 73 | virtual bool execute(ActionEnvironment& environment) override; |
Bob King | 8e4cb64 | 2020-04-24 13:18:53 +0800 | [diff] [blame] | 74 | |
| 75 | /** |
| 76 | * Returns the Field-Replaceable Unit (FRU). |
| 77 | * |
| 78 | * @return FRU |
| 79 | */ |
| 80 | const std::string& getFRU() const |
| 81 | { |
| 82 | return fru; |
| 83 | } |
| 84 | |
| 85 | /** |
| 86 | * Returns the VPD keyword. |
| 87 | * |
| 88 | * @return keyword |
| 89 | */ |
| 90 | const std::string& getKeyword() const |
| 91 | { |
| 92 | return keyword; |
| 93 | } |
| 94 | |
| 95 | /** |
| 96 | * Returns the expected value. |
| 97 | * |
| 98 | * @return value |
| 99 | */ |
Matt Spinler | aacc2aa | 2021-05-25 09:31:35 -0600 | [diff] [blame] | 100 | const std::vector<uint8_t>& getValue() const |
Bob King | 8e4cb64 | 2020-04-24 13:18:53 +0800 | [diff] [blame] | 101 | { |
| 102 | return value; |
| 103 | } |
| 104 | |
| 105 | /** |
| 106 | * Returns a string description of this action. |
| 107 | * |
| 108 | * @return description of action |
| 109 | */ |
Shawn McCarney | 45907cc | 2021-02-05 17:33:11 -0600 | [diff] [blame] | 110 | virtual std::string toString() const override; |
Bob King | 8e4cb64 | 2020-04-24 13:18:53 +0800 | [diff] [blame] | 111 | |
| 112 | private: |
| 113 | /** |
Shawn McCarney | 45907cc | 2021-02-05 17:33:11 -0600 | [diff] [blame] | 114 | * Field-Replaceable Unit (FRU) for this action. |
| 115 | * |
| 116 | * The D-Bus inventory path of the FRU. |
Bob King | 8e4cb64 | 2020-04-24 13:18:53 +0800 | [diff] [blame] | 117 | */ |
| 118 | const std::string fru{}; |
| 119 | |
| 120 | /** |
| 121 | * VPD keyword. |
| 122 | */ |
| 123 | const std::string keyword{}; |
| 124 | |
| 125 | /** |
| 126 | * Expected value. |
| 127 | */ |
Matt Spinler | aacc2aa | 2021-05-25 09:31:35 -0600 | [diff] [blame] | 128 | const std::vector<uint8_t> value{}; |
Bob King | 8e4cb64 | 2020-04-24 13:18:53 +0800 | [diff] [blame] | 129 | }; |
| 130 | |
| 131 | } // namespace phosphor::power::regulators |