blob: 7dc5136c42683007749a9eed10f351af6309ee8c [file] [log] [blame]
Bob King8e4cb642020-04-24 13:18:53 +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 <sstream>
22#include <string>
23
24namespace phosphor::power::regulators
25{
26
27/**
28 * @class CompareVPDAction
29 *
30 * Compares a VPD (Vital Product Data) keyword value to an expected value.
31 *
32 * Implements the compare_vpd action in the JSON config file.
33 */
34class CompareVPDAction : public Action
35{
36 public:
37 // Specify which compiler-generated methods we want
38 CompareVPDAction() = delete;
39 CompareVPDAction(const CompareVPDAction&) = delete;
40 CompareVPDAction(CompareVPDAction&&) = delete;
41 CompareVPDAction& operator=(const CompareVPDAction&) = delete;
42 CompareVPDAction& operator=(CompareVPDAction&&) = delete;
43 virtual ~CompareVPDAction() = default;
44
45 /**
46 * Constructor.
47 *
48 * @param fru Field-Replaceable Unit (FRU). Specify the D-Bus inventory path
49 * of the FRU.
50 * @param keyword VPD keyword. Specify one of the following: "CCIN",
51 * "Manufacturer", "Model", "PartNumber".
52 * @param value Expected value
53 */
54 explicit CompareVPDAction(const std::string& fru,
55 const std::string& keyword,
56 const std::string& value) :
57 fru{fru},
58 keyword{keyword}, value{value}
59 {
60 }
61
62 /**
63 * Executes this action.
64 *
65 * TODO: Not implemented yet
66 *
67 * @param environment Action execution environment.
68 * @return true
69 */
70 virtual bool execute(ActionEnvironment& /* environment */) override
71 {
72 // TODO: Not implemented yet
73 return true;
74 }
75
76 /**
77 * Returns the Field-Replaceable Unit (FRU).
78 *
79 * @return FRU
80 */
81 const std::string& getFRU() const
82 {
83 return fru;
84 }
85
86 /**
87 * Returns the VPD keyword.
88 *
89 * @return keyword
90 */
91 const std::string& getKeyword() const
92 {
93 return keyword;
94 }
95
96 /**
97 * Returns the expected value.
98 *
99 * @return value
100 */
101 const std::string& getValue() const
102 {
103 return value;
104 }
105
106 /**
107 * Returns a string description of this action.
108 *
109 * @return description of action
110 */
111 virtual std::string toString() const override
112 {
113 std::ostringstream ss;
114 ss << "compare_vpd: { ";
115 ss << "fru: " << fru << ", ";
116 ss << "keyword: " << keyword << ", ";
117 ss << "value: " << value << " }";
118
119 return ss.str();
120 }
121
122 private:
123 /**
124 * Field-Replaceable Unit (FRU) that contains the VPD.
125 */
126 const std::string fru{};
127
128 /**
129 * VPD keyword.
130 */
131 const std::string keyword{};
132
133 /**
134 * Expected value.
135 */
136 const std::string value{};
137};
138
139} // namespace phosphor::power::regulators