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