blob: b16c98f4456ec04f2102c97db1dbbc8a3d47a642 [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
Bob King07301ea2020-04-21 17:22:23 +080021#include <string>
22
23namespace phosphor::power::regulators
24{
25
26/**
27 * @class ComparePresenceAction
28 *
29 * Compares a hardware component's presence to an expected value.
30 *
31 * Implements the compare_presence action in the JSON config file.
32 */
33class ComparePresenceAction : public Action
34{
35 public:
36 // Specify which compiler-generated methods we want
37 ComparePresenceAction() = delete;
38 ComparePresenceAction(const ComparePresenceAction&) = delete;
39 ComparePresenceAction(ComparePresenceAction&&) = delete;
40 ComparePresenceAction& operator=(const ComparePresenceAction&) = delete;
41 ComparePresenceAction& operator=(ComparePresenceAction&&) = delete;
42 virtual ~ComparePresenceAction() = default;
43
44 /**
45 * Constructor.
46 *
47 * @param fru Field-Replaceable Unit (FRU)
48 * @param value Expected presence value
49 */
50 explicit ComparePresenceAction(const std::string& fru, bool value) :
51 fru{fru}, value{value}
52 {
53 }
54
55 /**
56 * Executes this action.
57 *
Bob King07301ea2020-04-21 17:22:23 +080058 * @param environment Action execution environment.
59 * @return true
60 */
Bob King49e90d32020-11-11 13:55:25 +080061 virtual bool execute(ActionEnvironment& environment) override;
Bob King07301ea2020-04-21 17:22:23 +080062
63 /**
64 * Returns the Field-Replaceable Unit (FRU).
65 *
66 * @return FRU
67 */
68 const std::string& getFRU() const
69 {
70 return fru;
71 }
72
73 /**
74 * Returns the expected presence value.
75 *
76 * @return value
77 */
78 bool getValue() const
79 {
80 return value;
81 }
82
83 /**
84 * Returns a string description of this action.
85 *
86 * @return description of action
87 */
Bob King49e90d32020-11-11 13:55:25 +080088 virtual std::string toString() const override;
Bob King07301ea2020-04-21 17:22:23 +080089
90 private:
91 /**
92 * Field-Replaceable Unit (FRU) for this action.
93 *
94 * Specify the D-Bus inventory path of the FRU.
95 */
96 const std::string fru{};
97
98 /**
99 * Expected presence value.
100 */
101 const bool value{};
102};
103
104} // namespace phosphor::power::regulators