blob: b2c7880cedf93b7e12fad03119483f52cd83125b [file] [log] [blame]
Bob King07301ea2020-04-21 17:22:23 +08001/**
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
21#include <ios>
22#include <sstream>
23#include <string>
24
25namespace phosphor::power::regulators
26{
27
28/**
29 * @class ComparePresenceAction
30 *
31 * Compares a hardware component's presence to an expected value.
32 *
33 * Implements the compare_presence action in the JSON config file.
34 */
35class ComparePresenceAction : public Action
36{
37 public:
38 // Specify which compiler-generated methods we want
39 ComparePresenceAction() = delete;
40 ComparePresenceAction(const ComparePresenceAction&) = delete;
41 ComparePresenceAction(ComparePresenceAction&&) = delete;
42 ComparePresenceAction& operator=(const ComparePresenceAction&) = delete;
43 ComparePresenceAction& operator=(ComparePresenceAction&&) = delete;
44 virtual ~ComparePresenceAction() = default;
45
46 /**
47 * Constructor.
48 *
49 * @param fru Field-Replaceable Unit (FRU)
50 * @param value Expected presence value
51 */
52 explicit ComparePresenceAction(const std::string& fru, bool value) :
53 fru{fru}, value{value}
54 {
55 }
56
57 /**
58 * Executes this action.
59 *
60 * TODO: Not implemented yet
61 *
62 * @param environment Action execution environment.
63 * @return true
64 */
65 virtual bool execute(ActionEnvironment& /* environment */) override
66 {
67 // TODO: Not implemented yet
68 return true;
69 }
70
71 /**
72 * Returns the Field-Replaceable Unit (FRU).
73 *
74 * @return FRU
75 */
76 const std::string& getFRU() const
77 {
78 return fru;
79 }
80
81 /**
82 * Returns the expected presence value.
83 *
84 * @return value
85 */
86 bool getValue() const
87 {
88 return value;
89 }
90
91 /**
92 * Returns a string description of this action.
93 *
94 * @return description of action
95 */
96 virtual std::string toString() const override
97 {
98 std::ostringstream ss;
99 ss << "compare_presence: { ";
100
101 ss << "fru: " << fru << ", ";
102
103 ss << "value: " << std::boolalpha << value << " }";
104
105 return ss.str();
106 }
107
108 private:
109 /**
110 * Field-Replaceable Unit (FRU) for this action.
111 *
112 * Specify the D-Bus inventory path of the FRU.
113 */
114 const std::string fru{};
115
116 /**
117 * Expected presence value.
118 */
119 const bool value{};
120};
121
122} // namespace phosphor::power::regulators