xref: /openbmc/phosphor-power/phosphor-regulators/src/configuration.cpp (revision 3976500fc98dce0ea50f13da96310c60a98bf689)
1*3976500fSShawn McCarney /**
2*3976500fSShawn McCarney  * Copyright © 2020 IBM Corporation
3*3976500fSShawn McCarney  *
4*3976500fSShawn McCarney  * Licensed under the Apache License, Version 2.0 (the "License");
5*3976500fSShawn McCarney  * you may not use this file except in compliance with the License.
6*3976500fSShawn McCarney  * You may obtain a copy of the License at
7*3976500fSShawn McCarney  *
8*3976500fSShawn McCarney  *     http://www.apache.org/licenses/LICENSE-2.0
9*3976500fSShawn McCarney  *
10*3976500fSShawn McCarney  * Unless required by applicable law or agreed to in writing, software
11*3976500fSShawn McCarney  * distributed under the License is distributed on an "AS IS" BASIS,
12*3976500fSShawn McCarney  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*3976500fSShawn McCarney  * See the License for the specific language governing permissions and
14*3976500fSShawn McCarney  * limitations under the License.
15*3976500fSShawn McCarney  */
16*3976500fSShawn McCarney 
17*3976500fSShawn McCarney #include "configuration.hpp"
18*3976500fSShawn McCarney 
19*3976500fSShawn McCarney #include "action_environment.hpp"
20*3976500fSShawn McCarney #include "action_utils.hpp"
21*3976500fSShawn McCarney #include "chassis.hpp"
22*3976500fSShawn McCarney #include "device.hpp"
23*3976500fSShawn McCarney #include "exception_utils.hpp"
24*3976500fSShawn McCarney #include "journal.hpp"
25*3976500fSShawn McCarney #include "rail.hpp"
26*3976500fSShawn McCarney #include "system.hpp"
27*3976500fSShawn McCarney 
28*3976500fSShawn McCarney #include <exception>
29*3976500fSShawn McCarney 
30*3976500fSShawn McCarney namespace phosphor::power::regulators
31*3976500fSShawn McCarney {
32*3976500fSShawn McCarney 
33*3976500fSShawn McCarney void Configuration::execute(System& system, Chassis& chassis, Device& device)
34*3976500fSShawn McCarney {
35*3976500fSShawn McCarney     execute(system, chassis, device, device.getID());
36*3976500fSShawn McCarney }
37*3976500fSShawn McCarney 
38*3976500fSShawn McCarney void Configuration::execute(System& system, Chassis& chassis, Device& device,
39*3976500fSShawn McCarney                             Rail& rail)
40*3976500fSShawn McCarney {
41*3976500fSShawn McCarney     execute(system, chassis, device, rail.getID());
42*3976500fSShawn McCarney }
43*3976500fSShawn McCarney 
44*3976500fSShawn McCarney void Configuration::execute(System& system, Chassis& /*chassis*/,
45*3976500fSShawn McCarney                             Device& device, const std::string& deviceOrRailID)
46*3976500fSShawn McCarney {
47*3976500fSShawn McCarney     try
48*3976500fSShawn McCarney     {
49*3976500fSShawn McCarney         // Log debug message in journal
50*3976500fSShawn McCarney         std::string message{"Configuring " + deviceOrRailID};
51*3976500fSShawn McCarney         if (volts.has_value())
52*3976500fSShawn McCarney         {
53*3976500fSShawn McCarney             message += ": volts=" + std::to_string(volts.value());
54*3976500fSShawn McCarney         }
55*3976500fSShawn McCarney         journal::logDebug(message);
56*3976500fSShawn McCarney 
57*3976500fSShawn McCarney         // Create ActionEnvironment
58*3976500fSShawn McCarney         ActionEnvironment environment{system.getIDMap(), device.getID()};
59*3976500fSShawn McCarney         if (volts.has_value())
60*3976500fSShawn McCarney         {
61*3976500fSShawn McCarney             environment.setVolts(volts.value());
62*3976500fSShawn McCarney         }
63*3976500fSShawn McCarney 
64*3976500fSShawn McCarney         // Execute the actions
65*3976500fSShawn McCarney         action_utils::execute(actions, environment);
66*3976500fSShawn McCarney     }
67*3976500fSShawn McCarney     catch (const std::exception& e)
68*3976500fSShawn McCarney     {
69*3976500fSShawn McCarney         // Log error messages in journal
70*3976500fSShawn McCarney         exception_utils::log(e);
71*3976500fSShawn McCarney         journal::logErr("Unable to configure " + deviceOrRailID);
72*3976500fSShawn McCarney 
73*3976500fSShawn McCarney         // TODO: Create error log entry
74*3976500fSShawn McCarney     }
75*3976500fSShawn McCarney }
76*3976500fSShawn McCarney 
77*3976500fSShawn McCarney } // namespace phosphor::power::regulators
78