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