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      */
491e5f993dSShawn McCarney     explicit SetDeviceAction(const std::string& deviceID) : deviceID{deviceID}
501e5f993dSShawn McCarney     {
511e5f993dSShawn McCarney     }
521e5f993dSShawn McCarney 
531e5f993dSShawn McCarney     /**
541e5f993dSShawn McCarney      * Executes this action.
551e5f993dSShawn McCarney      *
561e5f993dSShawn McCarney      * Sets the current device ID in the ActionEnvironment.  This causes
571e5f993dSShawn McCarney      * subsequent actions to use that device.
581e5f993dSShawn McCarney      *
591e5f993dSShawn McCarney      * @param environment Action execution environment.
601e5f993dSShawn McCarney      * @return true
611e5f993dSShawn McCarney      */
621e5f993dSShawn McCarney     virtual bool execute(ActionEnvironment& environment) override
631e5f993dSShawn McCarney     {
641e5f993dSShawn McCarney         environment.setDeviceID(deviceID);
651e5f993dSShawn McCarney         return true;
661e5f993dSShawn McCarney     }
671e5f993dSShawn McCarney 
681e5f993dSShawn McCarney     /**
691e5f993dSShawn McCarney      * Returns the device ID.
701e5f993dSShawn McCarney      *
711e5f993dSShawn McCarney      * @return device ID
721e5f993dSShawn McCarney      */
731e5f993dSShawn McCarney     const std::string& getDeviceID() const
741e5f993dSShawn McCarney     {
751e5f993dSShawn McCarney         return deviceID;
761e5f993dSShawn McCarney     }
771e5f993dSShawn McCarney 
78*8a3db36aSShawn McCarney     /**
79*8a3db36aSShawn McCarney      * Returns a string description of this action.
80*8a3db36aSShawn McCarney      *
81*8a3db36aSShawn McCarney      * @return description of action
82*8a3db36aSShawn McCarney      */
83*8a3db36aSShawn McCarney     virtual std::string toString() const override
84*8a3db36aSShawn McCarney     {
85*8a3db36aSShawn McCarney         return "set_device: " + deviceID;
86*8a3db36aSShawn McCarney     }
87*8a3db36aSShawn McCarney 
881e5f993dSShawn McCarney   private:
891e5f993dSShawn McCarney     /**
901e5f993dSShawn McCarney      * Device ID.
911e5f993dSShawn McCarney      */
921e5f993dSShawn McCarney     const std::string deviceID{};
931e5f993dSShawn McCarney };
941e5f993dSShawn McCarney 
95ea7385b8SShawn McCarney } // namespace phosphor::power::regulators
96