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_environment.hpp"
19 
20 #include <string>
21 
22 namespace phosphor::power::regulators
23 {
24 
25 /**
26  * @class Action
27  *
28  * Action to execute.
29  *
30  * All regulator actions are derived from this abstract base class.
31  *
32  * Actions are executed to perform regulator operations, such as configuring a
33  * regulator or reading sensor values.
34  */
35 class Action
36 {
37   public:
38     // Specify which compiler-generated methods we want
39     Action() = default;
40     Action(const Action&) = delete;
41     Action(Action&&) = delete;
42     Action& operator=(const Action&) = delete;
43     Action& operator=(Action&&) = delete;
44     virtual ~Action() = default;
45 
46     /**
47      * Executes this action.
48      *
49      * Throws an exception if an error occurs and the action cannot be
50      * successfully executed.
51      *
52      * @param environment Action execution environment.
53      * @return A boolean value whose meaning is defined by the action type.  For
54      *         example, CompareByteAction returns true if the actual register
55      *         value matches the expected value.  The return value does NOT
56      *         indicate if the action was successfully executed.
57      */
58     virtual bool execute(ActionEnvironment& environment) = 0;
59 
60     /**
61      * Returns a string description of this action.
62      *
63      * The description should include the action name, properties, and property
64      * values.
65      *
66      * The description is used in journal entries and error logs.
67      *
68      * @return description of action
69      */
70     virtual std::string toString() const = 0;
71 };
72 
73 } // namespace phosphor::power::regulators
74