blob: 7009cf6657ffc71bd8681cb1ba3b446db37f6878 [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}
Adriana Kobylak0c9a33d2021-09-13 18:05:09 +000050 {}
Shawn McCarney1e5f9932019-10-31 12:03:27 -050051
52 /**
53 * Executes this action.
54 *
55 * Sets the current device ID in the ActionEnvironment. This causes
56 * subsequent actions to use that device.
57 *
58 * @param environment Action execution environment.
59 * @return true
60 */
61 virtual bool execute(ActionEnvironment& environment) override
62 {
63 environment.setDeviceID(deviceID);
64 return true;
65 }
66
67 /**
68 * Returns the device ID.
69 *
70 * @return device ID
71 */
72 const std::string& getDeviceID() const
73 {
74 return deviceID;
75 }
76
Shawn McCarney8a3db362020-02-05 16:24:16 -060077 /**
78 * Returns a string description of this action.
79 *
80 * @return description of action
81 */
82 virtual std::string toString() const override
83 {
84 return "set_device: " + deviceID;
85 }
86
Shawn McCarney1e5f9932019-10-31 12:03:27 -050087 private:
88 /**
89 * Device ID.
90 */
91 const std::string deviceID{};
92};
93
Shawn McCarneyea7385b2019-11-07 12:19:32 -060094} // namespace phosphor::power::regulators