blob: 8edc36c6945c835d3e5882c09698f993f6ba0a64 [file] [log] [blame]
Shawn McCarney39765002020-04-09 18:03:26 -05001/**
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"
24#include "journal.hpp"
25#include "rail.hpp"
26#include "system.hpp"
27
28#include <exception>
29
30namespace phosphor::power::regulators
31{
32
Bob King23243f82020-07-29 10:38:57 +080033void Configuration::execute(Services& services, System& system,
34 Chassis& chassis, Device& device)
Shawn McCarney39765002020-04-09 18:03:26 -050035{
Bob King23243f82020-07-29 10:38:57 +080036 execute(services, system, chassis, device, device.getID());
Shawn McCarney39765002020-04-09 18:03:26 -050037}
38
Bob King23243f82020-07-29 10:38:57 +080039void Configuration::execute(Services& services, System& system,
40 Chassis& chassis, Device& device, Rail& rail)
Shawn McCarney39765002020-04-09 18:03:26 -050041{
Bob King23243f82020-07-29 10:38:57 +080042 execute(services, system, chassis, device, rail.getID());
Shawn McCarney39765002020-04-09 18:03:26 -050043}
44
Bob King23243f82020-07-29 10:38:57 +080045void Configuration::execute(Services& /*services*/, System& system,
46 Chassis& /*chassis*/, Device& device,
47 const std::string& deviceOrRailID)
Shawn McCarney39765002020-04-09 18:03:26 -050048{
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 }
57 journal::logDebug(message);
58
59 // Create ActionEnvironment
60 ActionEnvironment environment{system.getIDMap(), device.getID()};
61 if (volts.has_value())
62 {
63 environment.setVolts(volts.value());
64 }
65
66 // Execute the actions
67 action_utils::execute(actions, environment);
68 }
69 catch (const std::exception& e)
70 {
71 // Log error messages in journal
72 exception_utils::log(e);
73 journal::logErr("Unable to configure " + deviceOrRailID);
74
75 // TODO: Create error log entry
76 }
77}
78
79} // namespace phosphor::power::regulators