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