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 
17 #include "if_action.hpp"
18 
19 #include "action_utils.hpp"
20 
21 namespace phosphor::power::regulators
22 {
23 
24 bool IfAction::execute(ActionEnvironment& environment)
25 {
26     bool returnValue{true};
27 
28     // Execute condition action and check whether it returned true
29     if (conditionAction->execute(environment) == true)
30     {
31         // Condition was true; execute actions in "then" clause
32         returnValue = action_utils::execute(thenActions, environment);
33     }
34     else
35     {
36         // Condition was false; check if optional "else" clause was specified
37         if (elseActions.size() > 0)
38         {
39             // Execute actions in "else" clause
40             returnValue = action_utils::execute(elseActions, environment);
41         }
42         else
43         {
44             // No "else" clause specified; return value is false in this case
45             returnValue = false;
46         }
47     }
48 
49     return returnValue;
50 }
51 
52 } // namespace phosphor::power::regulators
53