Bob King | 07301ea | 2020-04-21 17:22:23 +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 | 07301ea | 2020-04-21 17:22:23 +0800 | [diff] [blame] | 21 | #include <string> |
| 22 | |
| 23 | namespace phosphor::power::regulators |
| 24 | { |
| 25 | |
| 26 | /** |
| 27 | * @class ComparePresenceAction |
| 28 | * |
| 29 | * Compares a hardware component's presence to an expected value. |
| 30 | * |
| 31 | * Implements the compare_presence action in the JSON config file. |
| 32 | */ |
| 33 | class ComparePresenceAction : public Action |
| 34 | { |
| 35 | public: |
| 36 | // Specify which compiler-generated methods we want |
| 37 | ComparePresenceAction() = delete; |
| 38 | ComparePresenceAction(const ComparePresenceAction&) = delete; |
| 39 | ComparePresenceAction(ComparePresenceAction&&) = delete; |
| 40 | ComparePresenceAction& operator=(const ComparePresenceAction&) = delete; |
| 41 | ComparePresenceAction& operator=(ComparePresenceAction&&) = delete; |
| 42 | virtual ~ComparePresenceAction() = default; |
| 43 | |
| 44 | /** |
| 45 | * Constructor. |
| 46 | * |
Shawn McCarney | 45907cc | 2021-02-05 17:33:11 -0600 | [diff] [blame] | 47 | * @param fru Field-Replaceable Unit (FRU). Specify the D-Bus inventory path |
| 48 | * of the FRU. |
Bob King | 07301ea | 2020-04-21 17:22:23 +0800 | [diff] [blame] | 49 | * @param value Expected presence value |
| 50 | */ |
| 51 | explicit ComparePresenceAction(const std::string& fru, bool value) : |
| 52 | fru{fru}, value{value} |
Adriana Kobylak | 0c9a33d | 2021-09-13 18:05:09 +0000 | [diff] [blame] | 53 | {} |
Bob King | 07301ea | 2020-04-21 17:22:23 +0800 | [diff] [blame] | 54 | |
| 55 | /** |
| 56 | * Executes this action. |
| 57 | * |
Shawn McCarney | 45907cc | 2021-02-05 17:33:11 -0600 | [diff] [blame] | 58 | * Compares the actual presence value to the expected value. |
| 59 | * |
| 60 | * Throws an exception if an error occurs. |
| 61 | * |
| 62 | * @param environment action execution environment |
| 63 | * @return true if the actual presence value equals the expected value, |
| 64 | * otherwise returns false |
Bob King | 07301ea | 2020-04-21 17:22:23 +0800 | [diff] [blame] | 65 | */ |
Bob King | 49e90d3 | 2020-11-11 13:55:25 +0800 | [diff] [blame] | 66 | virtual bool execute(ActionEnvironment& environment) override; |
Bob King | 07301ea | 2020-04-21 17:22:23 +0800 | [diff] [blame] | 67 | |
| 68 | /** |
| 69 | * Returns the Field-Replaceable Unit (FRU). |
| 70 | * |
| 71 | * @return FRU |
| 72 | */ |
| 73 | const std::string& getFRU() const |
| 74 | { |
| 75 | return fru; |
| 76 | } |
| 77 | |
| 78 | /** |
| 79 | * Returns the expected presence value. |
| 80 | * |
| 81 | * @return value |
| 82 | */ |
| 83 | bool getValue() const |
| 84 | { |
| 85 | return value; |
| 86 | } |
| 87 | |
| 88 | /** |
| 89 | * Returns a string description of this action. |
| 90 | * |
| 91 | * @return description of action |
| 92 | */ |
Bob King | 49e90d3 | 2020-11-11 13:55:25 +0800 | [diff] [blame] | 93 | virtual std::string toString() const override; |
Bob King | 07301ea | 2020-04-21 17:22:23 +0800 | [diff] [blame] | 94 | |
| 95 | private: |
| 96 | /** |
| 97 | * Field-Replaceable Unit (FRU) for this action. |
| 98 | * |
Shawn McCarney | 45907cc | 2021-02-05 17:33:11 -0600 | [diff] [blame] | 99 | * The D-Bus inventory path of the FRU. |
Bob King | 07301ea | 2020-04-21 17:22:23 +0800 | [diff] [blame] | 100 | */ |
| 101 | const std::string fru{}; |
| 102 | |
| 103 | /** |
| 104 | * Expected presence value. |
| 105 | */ |
| 106 | const bool value{}; |
| 107 | }; |
| 108 | |
| 109 | } // namespace phosphor::power::regulators |