blob: c0690b435e355967b4e7e25660ea49cacd0e964c [file] [log] [blame]
Shawn McCarneyfa23f7d2021-08-26 15:31:47 -05001/**
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
24namespace 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 */
34class 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 */
50 explicit LogPhaseFaultAction(PhaseFaultType type) : type{type}
51 {
52 }
53
54 /**
55 * Executes this action.
56 *
57 * Adds the phase fault to the set that have been detected.
58 *
59 * @param environment action execution environment
60 * @return true
61 */
62 virtual bool execute(ActionEnvironment& environment) override
63 {
64 environment.addPhaseFault(type);
65 return true;
66 }
67
68 /**
69 * Returns the phase fault type.
70 *
71 * @return phase fault type
72 */
73 PhaseFaultType getType() const
74 {
75 return type;
76 }
77
78 /**
79 * Returns a string description of this action.
80 *
81 * @return description of action
82 */
83 virtual std::string toString() const override
84 {
85 return "log_phase_fault: { type: " + regulators::toString(type) + " }";
86 }
87
88 private:
89 /**
90 * Phase fault type.
91 */
92 const PhaseFaultType type;
93};
94
95} // namespace phosphor::power::regulators