xref: /openbmc/phosphor-power/phosphor-regulators/src/configuration.cpp (revision 81a2f90b9c205068b0700a2bda35fb2b3d2ede00)
13976500fSShawn McCarney /**
23976500fSShawn McCarney  * Copyright © 2020 IBM Corporation
33976500fSShawn McCarney  *
43976500fSShawn McCarney  * Licensed under the Apache License, Version 2.0 (the "License");
53976500fSShawn McCarney  * you may not use this file except in compliance with the License.
63976500fSShawn McCarney  * You may obtain a copy of the License at
73976500fSShawn McCarney  *
83976500fSShawn McCarney  *     http://www.apache.org/licenses/LICENSE-2.0
93976500fSShawn McCarney  *
103976500fSShawn McCarney  * Unless required by applicable law or agreed to in writing, software
113976500fSShawn McCarney  * distributed under the License is distributed on an "AS IS" BASIS,
123976500fSShawn McCarney  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
133976500fSShawn McCarney  * See the License for the specific language governing permissions and
143976500fSShawn McCarney  * limitations under the License.
153976500fSShawn McCarney  */
163976500fSShawn McCarney 
173976500fSShawn McCarney #include "configuration.hpp"
183976500fSShawn McCarney 
193976500fSShawn McCarney #include "action_environment.hpp"
203976500fSShawn McCarney #include "action_utils.hpp"
213976500fSShawn McCarney #include "chassis.hpp"
223976500fSShawn McCarney #include "device.hpp"
23*81a2f90bSShawn McCarney #include "error_logging_utils.hpp"
243976500fSShawn McCarney #include "exception_utils.hpp"
253976500fSShawn McCarney #include "rail.hpp"
263976500fSShawn McCarney #include "system.hpp"
273976500fSShawn McCarney 
283976500fSShawn McCarney #include <exception>
293976500fSShawn McCarney 
303976500fSShawn McCarney namespace phosphor::power::regulators
313976500fSShawn McCarney {
323976500fSShawn McCarney 
execute(Services & services,System & system,Chassis & chassis,Device & device)3323243f84SBob King void Configuration::execute(Services& services, System& system,
3423243f84SBob King                             Chassis& chassis, Device& device)
353976500fSShawn McCarney {
3623243f84SBob King     execute(services, system, chassis, device, device.getID());
373976500fSShawn McCarney }
383976500fSShawn McCarney 
execute(Services & services,System & system,Chassis & chassis,Device & device,Rail & rail)3923243f84SBob King void Configuration::execute(Services& services, System& system,
4023243f84SBob King                             Chassis& chassis, Device& device, Rail& rail)
413976500fSShawn McCarney {
4223243f84SBob King     execute(services, system, chassis, device, rail.getID());
433976500fSShawn McCarney }
443976500fSShawn McCarney 
execute(Services & services,System & system,Chassis &,Device & device,const std::string & deviceOrRailID)455cfe5103SBob King void Configuration::execute(Services& services, System& system,
4623243f84SBob King                             Chassis& /*chassis*/, Device& device,
4723243f84SBob King                             const std::string& deviceOrRailID)
483976500fSShawn McCarney {
493976500fSShawn McCarney     try
503976500fSShawn McCarney     {
513976500fSShawn McCarney         // Log debug message in journal
523976500fSShawn McCarney         std::string message{"Configuring " + deviceOrRailID};
533976500fSShawn McCarney         if (volts.has_value())
543976500fSShawn McCarney         {
553976500fSShawn McCarney             message += ": volts=" + std::to_string(volts.value());
563976500fSShawn McCarney         }
575cfe5103SBob King         services.getJournal().logDebug(message);
583976500fSShawn McCarney 
593976500fSShawn McCarney         // Create ActionEnvironment
6073eaceebSBob King         ActionEnvironment environment{system.getIDMap(), device.getID(),
6173eaceebSBob King                                       services};
623976500fSShawn McCarney         if (volts.has_value())
633976500fSShawn McCarney         {
643976500fSShawn McCarney             environment.setVolts(volts.value());
653976500fSShawn McCarney         }
663976500fSShawn McCarney 
673976500fSShawn McCarney         // Execute the actions
683976500fSShawn McCarney         action_utils::execute(actions, environment);
693976500fSShawn McCarney     }
703976500fSShawn McCarney     catch (const std::exception& e)
713976500fSShawn McCarney     {
723976500fSShawn McCarney         // Log error messages in journal
735cfe5103SBob King         services.getJournal().logError(exception_utils::getMessages(e));
745cfe5103SBob King         services.getJournal().logError("Unable to configure " + deviceOrRailID);
753976500fSShawn McCarney 
76*81a2f90bSShawn McCarney         // Create error log entry
77*81a2f90bSShawn McCarney         error_logging_utils::logError(std::current_exception(),
78*81a2f90bSShawn McCarney                                       Entry::Level::Warning, services);
793976500fSShawn McCarney     }
803976500fSShawn McCarney }
813976500fSShawn McCarney 
823976500fSShawn McCarney } // namespace phosphor::power::regulators
83