1 /** 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 23 namespace phosphor::power::regulators 24 { 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 */ 33 class 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 * 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 77 /** 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 87 private: 88 /** 89 * Device ID. 90 */ 91 const std::string deviceID{}; 92 }; 93 94 } // namespace phosphor::power::regulators 95