11e5f993dSShawn McCarney /** 21e5f993dSShawn McCarney * Copyright © 2019 IBM Corporation 31e5f993dSShawn McCarney * 41e5f993dSShawn McCarney * Licensed under the Apache License, Version 2.0 (the "License"); 51e5f993dSShawn McCarney * you may not use this file except in compliance with the License. 61e5f993dSShawn McCarney * You may obtain a copy of the License at 71e5f993dSShawn McCarney * 81e5f993dSShawn McCarney * http://www.apache.org/licenses/LICENSE-2.0 91e5f993dSShawn McCarney * 101e5f993dSShawn McCarney * Unless required by applicable law or agreed to in writing, software 111e5f993dSShawn McCarney * distributed under the License is distributed on an "AS IS" BASIS, 121e5f993dSShawn McCarney * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 131e5f993dSShawn McCarney * See the License for the specific language governing permissions and 141e5f993dSShawn McCarney * limitations under the License. 151e5f993dSShawn McCarney */ 161e5f993dSShawn McCarney #pragma once 171e5f993dSShawn McCarney 181e5f993dSShawn McCarney #include "action.hpp" 191e5f993dSShawn McCarney #include "action_environment.hpp" 201e5f993dSShawn McCarney 211e5f993dSShawn McCarney #include <string> 221e5f993dSShawn McCarney 23ea7385b8SShawn McCarney namespace phosphor::power::regulators 241e5f993dSShawn McCarney { 251e5f993dSShawn McCarney 261e5f993dSShawn McCarney /** 271e5f993dSShawn McCarney * @class SetDeviceAction 281e5f993dSShawn McCarney * 291e5f993dSShawn McCarney * Sets the device that will be used by subsequent actions. 301e5f993dSShawn McCarney * 311e5f993dSShawn McCarney * Implements the set_device action in the JSON config file. 321e5f993dSShawn McCarney */ 331e5f993dSShawn McCarney class SetDeviceAction : public Action 341e5f993dSShawn McCarney { 351e5f993dSShawn McCarney public: 361e5f993dSShawn McCarney // Specify which compiler-generated methods we want 371e5f993dSShawn McCarney SetDeviceAction() = delete; 381e5f993dSShawn McCarney SetDeviceAction(const SetDeviceAction&) = delete; 391e5f993dSShawn McCarney SetDeviceAction(SetDeviceAction&&) = delete; 401e5f993dSShawn McCarney SetDeviceAction& operator=(const SetDeviceAction&) = delete; 411e5f993dSShawn McCarney SetDeviceAction& operator=(SetDeviceAction&&) = delete; 421e5f993dSShawn McCarney virtual ~SetDeviceAction() = default; 431e5f993dSShawn McCarney 441e5f993dSShawn McCarney /** 451e5f993dSShawn McCarney * Constructor. 461e5f993dSShawn McCarney * 471e5f993dSShawn McCarney * @param deviceID device ID 481e5f993dSShawn McCarney */ SetDeviceAction(const std::string & deviceID)491e5f993dSShawn McCarney explicit SetDeviceAction(const std::string& deviceID) : deviceID{deviceID} 50*0c9a33d6SAdriana Kobylak {} 511e5f993dSShawn McCarney 521e5f993dSShawn McCarney /** 531e5f993dSShawn McCarney * Executes this action. 541e5f993dSShawn McCarney * 551e5f993dSShawn McCarney * Sets the current device ID in the ActionEnvironment. This causes 561e5f993dSShawn McCarney * subsequent actions to use that device. 571e5f993dSShawn McCarney * 581e5f993dSShawn McCarney * @param environment Action execution environment. 591e5f993dSShawn McCarney * @return true 601e5f993dSShawn McCarney */ execute(ActionEnvironment & environment)611e5f993dSShawn McCarney virtual bool execute(ActionEnvironment& environment) override 621e5f993dSShawn McCarney { 631e5f993dSShawn McCarney environment.setDeviceID(deviceID); 641e5f993dSShawn McCarney return true; 651e5f993dSShawn McCarney } 661e5f993dSShawn McCarney 671e5f993dSShawn McCarney /** 681e5f993dSShawn McCarney * Returns the device ID. 691e5f993dSShawn McCarney * 701e5f993dSShawn McCarney * @return device ID 711e5f993dSShawn McCarney */ getDeviceID() const721e5f993dSShawn McCarney const std::string& getDeviceID() const 731e5f993dSShawn McCarney { 741e5f993dSShawn McCarney return deviceID; 751e5f993dSShawn McCarney } 761e5f993dSShawn McCarney 778a3db36aSShawn McCarney /** 788a3db36aSShawn McCarney * Returns a string description of this action. 798a3db36aSShawn McCarney * 808a3db36aSShawn McCarney * @return description of action 818a3db36aSShawn McCarney */ toString() const828a3db36aSShawn McCarney virtual std::string toString() const override 838a3db36aSShawn McCarney { 848a3db36aSShawn McCarney return "set_device: " + deviceID; 858a3db36aSShawn McCarney } 868a3db36aSShawn McCarney 871e5f993dSShawn McCarney private: 881e5f993dSShawn McCarney /** 891e5f993dSShawn McCarney * Device ID. 901e5f993dSShawn McCarney */ 911e5f993dSShawn McCarney const std::string deviceID{}; 921e5f993dSShawn McCarney }; 931e5f993dSShawn McCarney 94ea7385b8SShawn McCarney } // namespace phosphor::power::regulators 95