Shawn McCarney | 3976500 | 2020-04-09 18:03:26 -0500 | [diff] [blame] | 1 | /** |
| 2 | * Copyright © 2020 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 "configuration.hpp" |
| 18 | |
| 19 | #include "action_environment.hpp" |
| 20 | #include "action_utils.hpp" |
| 21 | #include "chassis.hpp" |
| 22 | #include "device.hpp" |
Shawn McCarney | 81a2f90 | 2021-03-23 21:41:34 -0500 | [diff] [blame] | 23 | #include "error_logging_utils.hpp" |
Shawn McCarney | 3976500 | 2020-04-09 18:03:26 -0500 | [diff] [blame] | 24 | #include "exception_utils.hpp" |
Shawn McCarney | 3976500 | 2020-04-09 18:03:26 -0500 | [diff] [blame] | 25 | #include "rail.hpp" |
| 26 | #include "system.hpp" |
| 27 | |
| 28 | #include <exception> |
| 29 | |
| 30 | namespace phosphor::power::regulators |
| 31 | { |
| 32 | |
Bob King | 23243f8 | 2020-07-29 10:38:57 +0800 | [diff] [blame] | 33 | void Configuration::execute(Services& services, System& system, |
| 34 | Chassis& chassis, Device& device) |
Shawn McCarney | 3976500 | 2020-04-09 18:03:26 -0500 | [diff] [blame] | 35 | { |
Bob King | 23243f8 | 2020-07-29 10:38:57 +0800 | [diff] [blame] | 36 | execute(services, system, chassis, device, device.getID()); |
Shawn McCarney | 3976500 | 2020-04-09 18:03:26 -0500 | [diff] [blame] | 37 | } |
| 38 | |
Bob King | 23243f8 | 2020-07-29 10:38:57 +0800 | [diff] [blame] | 39 | void Configuration::execute(Services& services, System& system, |
| 40 | Chassis& chassis, Device& device, Rail& rail) |
Shawn McCarney | 3976500 | 2020-04-09 18:03:26 -0500 | [diff] [blame] | 41 | { |
Bob King | 23243f8 | 2020-07-29 10:38:57 +0800 | [diff] [blame] | 42 | execute(services, system, chassis, device, rail.getID()); |
Shawn McCarney | 3976500 | 2020-04-09 18:03:26 -0500 | [diff] [blame] | 43 | } |
| 44 | |
Bob King | 5cfe510 | 2020-07-30 16:26:18 +0800 | [diff] [blame] | 45 | void Configuration::execute(Services& services, System& system, |
Bob King | 23243f8 | 2020-07-29 10:38:57 +0800 | [diff] [blame] | 46 | Chassis& /*chassis*/, Device& device, |
| 47 | const std::string& deviceOrRailID) |
Shawn McCarney | 3976500 | 2020-04-09 18:03:26 -0500 | [diff] [blame] | 48 | { |
| 49 | try |
| 50 | { |
| 51 | // Log debug message in journal |
| 52 | std::string message{"Configuring " + deviceOrRailID}; |
| 53 | if (volts.has_value()) |
| 54 | { |
| 55 | message += ": volts=" + std::to_string(volts.value()); |
| 56 | } |
Bob King | 5cfe510 | 2020-07-30 16:26:18 +0800 | [diff] [blame] | 57 | services.getJournal().logDebug(message); |
Shawn McCarney | 3976500 | 2020-04-09 18:03:26 -0500 | [diff] [blame] | 58 | |
| 59 | // Create ActionEnvironment |
Bob King | 73eacee | 2020-10-23 13:58:02 +0800 | [diff] [blame] | 60 | ActionEnvironment environment{system.getIDMap(), device.getID(), |
| 61 | services}; |
Shawn McCarney | 3976500 | 2020-04-09 18:03:26 -0500 | [diff] [blame] | 62 | if (volts.has_value()) |
| 63 | { |
| 64 | environment.setVolts(volts.value()); |
| 65 | } |
| 66 | |
| 67 | // Execute the actions |
| 68 | action_utils::execute(actions, environment); |
| 69 | } |
| 70 | catch (const std::exception& e) |
| 71 | { |
| 72 | // Log error messages in journal |
Bob King | 5cfe510 | 2020-07-30 16:26:18 +0800 | [diff] [blame] | 73 | services.getJournal().logError(exception_utils::getMessages(e)); |
| 74 | services.getJournal().logError("Unable to configure " + deviceOrRailID); |
Shawn McCarney | 3976500 | 2020-04-09 18:03:26 -0500 | [diff] [blame] | 75 | |
Shawn McCarney | 81a2f90 | 2021-03-23 21:41:34 -0500 | [diff] [blame] | 76 | // Create error log entry |
| 77 | error_logging_utils::logError(std::current_exception(), |
| 78 | Entry::Level::Warning, services); |
Shawn McCarney | 3976500 | 2020-04-09 18:03:26 -0500 | [diff] [blame] | 79 | } |
| 80 | } |
| 81 | |
| 82 | } // namespace phosphor::power::regulators |