blob: 3c612089d160226fe455f5c4befccbd30588782b [file] [log] [blame]
Shawn McCarney1e5f9932019-10-31 12:03:27 -05001/**
2 * Copyright © 2019 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 <string>
22
23namespace phosphor
24{
25namespace power
26{
27namespace regulators
28{
29
30/**
31 * @class SetDeviceAction
32 *
33 * Sets the device that will be used by subsequent actions.
34 *
35 * Implements the set_device action in the JSON config file.
36 */
37class SetDeviceAction : public Action
38{
39 public:
40 // Specify which compiler-generated methods we want
41 SetDeviceAction() = delete;
42 SetDeviceAction(const SetDeviceAction&) = delete;
43 SetDeviceAction(SetDeviceAction&&) = delete;
44 SetDeviceAction& operator=(const SetDeviceAction&) = delete;
45 SetDeviceAction& operator=(SetDeviceAction&&) = delete;
46 virtual ~SetDeviceAction() = default;
47
48 /**
49 * Constructor.
50 *
51 * @param deviceID device ID
52 */
53 explicit SetDeviceAction(const std::string& deviceID) : deviceID{deviceID}
54 {
55 }
56
57 /**
58 * Executes this action.
59 *
60 * Sets the current device ID in the ActionEnvironment. This causes
61 * subsequent actions to use that device.
62 *
63 * @param environment Action execution environment.
64 * @return true
65 */
66 virtual bool execute(ActionEnvironment& environment) override
67 {
68 environment.setDeviceID(deviceID);
69 return true;
70 }
71
72 /**
73 * Returns the device ID.
74 *
75 * @return device ID
76 */
77 const std::string& getDeviceID() const
78 {
79 return deviceID;
80 }
81
82 private:
83 /**
84 * Device ID.
85 */
86 const std::string deviceID{};
87};
88
89} // namespace regulators
90} // namespace power
91} // namespace phosphor