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