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 /** 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 78 private: 79 /** 80 * Device ID. 81 */ 82 const std::string deviceID{}; 83 }; 84 85 } // namespace phosphor::power::regulators 86