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 "action.hpp" 19 #include "action_environment.hpp" 20 #include "phase_fault.hpp" 21 22 #include <string> 23 24 namespace phosphor::power::regulators 25 { 26 27 /** 28 * @class LogPhaseFaultAction 29 * 30 * Logs a redundant phase fault error for a voltage regulator. 31 * 32 * Implements the log_phase_fault action in the JSON config file. 33 */ 34 class LogPhaseFaultAction : public Action 35 { 36 public: 37 // Specify which compiler-generated methods we want 38 LogPhaseFaultAction() = delete; 39 LogPhaseFaultAction(const LogPhaseFaultAction&) = delete; 40 LogPhaseFaultAction(LogPhaseFaultAction&&) = delete; 41 LogPhaseFaultAction& operator=(const LogPhaseFaultAction&) = delete; 42 LogPhaseFaultAction& operator=(LogPhaseFaultAction&&) = delete; 43 virtual ~LogPhaseFaultAction() = default; 44 45 /** 46 * Constructor. 47 * 48 * @param type phase fault type 49 */ LogPhaseFaultAction(PhaseFaultType type)50 explicit LogPhaseFaultAction(PhaseFaultType type) : type{type} {} 51 52 /** 53 * Executes this action. 54 * 55 * Adds the phase fault to the set that have been detected. 56 * 57 * @param environment action execution environment 58 * @return true 59 */ execute(ActionEnvironment & environment)60 virtual bool execute(ActionEnvironment& environment) override 61 { 62 environment.addPhaseFault(type); 63 return true; 64 } 65 66 /** 67 * Returns the phase fault type. 68 * 69 * @return phase fault type 70 */ getType() const71 PhaseFaultType getType() const 72 { 73 return type; 74 } 75 76 /** 77 * Returns a string description of this action. 78 * 79 * @return description of action 80 */ toString() const81 virtual std::string toString() const override 82 { 83 return "log_phase_fault: { type: " + regulators::toString(type) + " }"; 84 } 85 86 private: 87 /** 88 * Phase fault type. 89 */ 90 const PhaseFaultType type; 91 }; 92 93 } // namespace phosphor::power::regulators 94