17a7a29ecSShawn McCarney /** 27a7a29ecSShawn McCarney * Copyright © 2019 IBM Corporation 37a7a29ecSShawn McCarney * 47a7a29ecSShawn McCarney * Licensed under the Apache License, Version 2.0 (the "License"); 57a7a29ecSShawn McCarney * you may not use this file except in compliance with the License. 67a7a29ecSShawn McCarney * You may obtain a copy of the License at 77a7a29ecSShawn McCarney * 87a7a29ecSShawn McCarney * http://www.apache.org/licenses/LICENSE-2.0 97a7a29ecSShawn McCarney * 107a7a29ecSShawn McCarney * Unless required by applicable law or agreed to in writing, software 117a7a29ecSShawn McCarney * distributed under the License is distributed on an "AS IS" BASIS, 127a7a29ecSShawn McCarney * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 137a7a29ecSShawn McCarney * See the License for the specific language governing permissions and 147a7a29ecSShawn McCarney * limitations under the License. 157a7a29ecSShawn McCarney */ 167a7a29ecSShawn McCarney #pragma once 177a7a29ecSShawn McCarney 187a7a29ecSShawn McCarney #include "action_environment.hpp" 197a7a29ecSShawn McCarney 20*8a3db36aSShawn McCarney #include <string> 21*8a3db36aSShawn McCarney 22ea7385b8SShawn McCarney namespace phosphor::power::regulators 237a7a29ecSShawn McCarney { 247a7a29ecSShawn McCarney 257a7a29ecSShawn McCarney /** 267a7a29ecSShawn McCarney * @class Action 277a7a29ecSShawn McCarney * 287a7a29ecSShawn McCarney * Action to execute. 297a7a29ecSShawn McCarney * 307a7a29ecSShawn McCarney * All regulator actions are derived from this abstract base class. 317a7a29ecSShawn McCarney * 327a7a29ecSShawn McCarney * Actions are executed to perform regulator operations, such as configuring a 337a7a29ecSShawn McCarney * regulator or reading sensor values. 347a7a29ecSShawn McCarney */ 357a7a29ecSShawn McCarney class Action 367a7a29ecSShawn McCarney { 377a7a29ecSShawn McCarney public: 387a7a29ecSShawn McCarney // Specify which compiler-generated methods we want 397a7a29ecSShawn McCarney Action() = default; 407a7a29ecSShawn McCarney Action(const Action&) = delete; 417a7a29ecSShawn McCarney Action(Action&&) = delete; 427a7a29ecSShawn McCarney Action& operator=(const Action&) = delete; 437a7a29ecSShawn McCarney Action& operator=(Action&&) = delete; 447a7a29ecSShawn McCarney virtual ~Action() = default; 457a7a29ecSShawn McCarney 467a7a29ecSShawn McCarney /** 477a7a29ecSShawn McCarney * Executes this action. 487a7a29ecSShawn McCarney * 497a7a29ecSShawn McCarney * Throws an exception if an error occurs and the action cannot be 507a7a29ecSShawn McCarney * successfully executed. 517a7a29ecSShawn McCarney * 527a7a29ecSShawn McCarney * @param environment Action execution environment. 537a7a29ecSShawn McCarney * @return A boolean value whose meaning is defined by the action type. For 547a7a29ecSShawn McCarney * example, CompareByteAction returns true if the actual register 557a7a29ecSShawn McCarney * value matches the expected value. The return value does NOT 567a7a29ecSShawn McCarney * indicate if the action was successfully executed. 577a7a29ecSShawn McCarney */ 587a7a29ecSShawn McCarney virtual bool execute(ActionEnvironment& environment) = 0; 59*8a3db36aSShawn McCarney 60*8a3db36aSShawn McCarney /** 61*8a3db36aSShawn McCarney * Returns a string description of this action. 62*8a3db36aSShawn McCarney * 63*8a3db36aSShawn McCarney * The description should include the action name, properties, and property 64*8a3db36aSShawn McCarney * values. 65*8a3db36aSShawn McCarney * 66*8a3db36aSShawn McCarney * The description is used in journal entries and error logs. 67*8a3db36aSShawn McCarney * 68*8a3db36aSShawn McCarney * @return description of action 69*8a3db36aSShawn McCarney */ 70*8a3db36aSShawn McCarney virtual std::string toString() const = 0; 717a7a29ecSShawn McCarney }; 727a7a29ecSShawn McCarney 73ea7385b8SShawn McCarney } // namespace phosphor::power::regulators 74