Cheng C Yang | 58b2b53 | 2019-05-31 00:19:45 +0800 | [diff] [blame] | 1 | /* |
| 2 | // Copyright (c) 2019 Intel 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 | |
Andrew Jeffery | e73bd0a | 2023-01-25 10:39:57 +1030 | [diff] [blame] | 17 | #include "PSUEvent.hpp" |
| 18 | |
| 19 | #include "SensorPaths.hpp" |
| 20 | |
Ed Tanous | 1f97863 | 2023-02-28 18:16:39 -0800 | [diff] [blame] | 21 | #include <boost/asio/io_context.hpp> |
James Feist | 8086aba | 2020-08-25 16:00:59 -0700 | [diff] [blame] | 22 | #include <boost/asio/read_until.hpp> |
Patrick Venture | 96e97db | 2019-10-31 13:44:38 -0700 | [diff] [blame] | 23 | #include <boost/container/flat_map.hpp> |
Patrick Williams | 0c42f40 | 2021-08-27 16:05:45 -0500 | [diff] [blame] | 24 | #include <phosphor-logging/lg2.hpp> |
Cheng C Yang | 58b2b53 | 2019-05-31 00:19:45 +0800 | [diff] [blame] | 25 | #include <sdbusplus/asio/connection.hpp> |
| 26 | #include <sdbusplus/asio/object_server.hpp> |
James Feist | 38fb598 | 2020-05-28 10:09:54 -0700 | [diff] [blame] | 27 | |
| 28 | #include <iostream> |
| 29 | #include <memory> |
Patrick Venture | 96e97db | 2019-10-31 13:44:38 -0700 | [diff] [blame] | 30 | #include <stdexcept> |
| 31 | #include <string> |
| 32 | #include <utility> |
| 33 | #include <variant> |
| 34 | #include <vector> |
Cheng C Yang | 58b2b53 | 2019-05-31 00:19:45 +0800 | [diff] [blame] | 35 | |
| 36 | PSUCombineEvent::PSUCombineEvent( |
Yong Li | 3046a02 | 2020-04-03 13:01:02 +0800 | [diff] [blame] | 37 | sdbusplus::asio::object_server& objectServer, |
| 38 | std::shared_ptr<sdbusplus::asio::connection>& conn, |
Ed Tanous | 1f97863 | 2023-02-28 18:16:39 -0800 | [diff] [blame] | 39 | boost::asio::io_context& io, const std::string& psuName, |
George Liu | 5b3542e | 2023-10-31 17:27:12 +0800 | [diff] [blame] | 40 | const PowerState& powerState, EventPathList& eventPathList, |
| 41 | GroupEventPathList& groupEventPathList, const std::string& combineEventName, |
| 42 | double pollRate) : |
Cheng C Yang | 58b2b53 | 2019-05-31 00:19:45 +0800 | [diff] [blame] | 43 | objServer(objectServer) |
| 44 | { |
Ed Tanous | 6cb732a | 2021-02-18 15:33:51 -0800 | [diff] [blame] | 45 | std::string psuNameEscaped = sensor_paths::escapePathForDbus(psuName); |
Cheng C Yang | 58b2b53 | 2019-05-31 00:19:45 +0800 | [diff] [blame] | 46 | eventInterface = objServer.add_interface( |
Ed Tanous | 6cb732a | 2021-02-18 15:33:51 -0800 | [diff] [blame] | 47 | "/xyz/openbmc_project/State/Decorator/" + psuNameEscaped + "_" + |
Cheng C Yang | 58b2b53 | 2019-05-31 00:19:45 +0800 | [diff] [blame] | 48 | combineEventName, |
| 49 | "xyz.openbmc_project.State.Decorator.OperationalStatus"); |
James Feist | b6c0b91 | 2019-07-09 12:21:44 -0700 | [diff] [blame] | 50 | eventInterface->register_property("functional", true); |
Cheng C Yang | 58b2b53 | 2019-05-31 00:19:45 +0800 | [diff] [blame] | 51 | |
| 52 | if (!eventInterface->initialize()) |
| 53 | { |
| 54 | std::cerr << "error initializing event interface\n"; |
| 55 | } |
| 56 | |
| 57 | std::shared_ptr<std::set<std::string>> combineEvent = |
| 58 | std::make_shared<std::set<std::string>>(); |
Zev Weiss | b85145c | 2022-08-12 18:21:02 -0700 | [diff] [blame] | 59 | for (const auto& [eventName, paths] : eventPathList) |
Cheng C Yang | 58b2b53 | 2019-05-31 00:19:45 +0800 | [diff] [blame] | 60 | { |
Yong Li | 591b1e4 | 2019-12-19 17:46:31 +0800 | [diff] [blame] | 61 | std::shared_ptr<std::set<std::string>> assert = |
| 62 | std::make_shared<std::set<std::string>>(); |
Cheng C Yang | 202a1ff | 2020-01-09 09:34:22 +0800 | [diff] [blame] | 63 | std::shared_ptr<bool> state = std::make_shared<bool>(false); |
Yong Li | 591b1e4 | 2019-12-19 17:46:31 +0800 | [diff] [blame] | 64 | |
Cheng C Yang | 58b2b53 | 2019-05-31 00:19:45 +0800 | [diff] [blame] | 65 | std::string eventPSUName = eventName + psuName; |
Zev Weiss | b85145c | 2022-08-12 18:21:02 -0700 | [diff] [blame] | 66 | for (const auto& path : paths) |
Cheng C Yang | 58b2b53 | 2019-05-31 00:19:45 +0800 | [diff] [blame] | 67 | { |
Yong Li | bf8b1da | 2020-04-15 16:32:50 +0800 | [diff] [blame] | 68 | auto p = std::make_shared<PSUSubEvent>( |
Konstantin Aladyshev | c7a1ae6 | 2021-04-30 08:50:43 +0000 | [diff] [blame] | 69 | eventInterface, path, conn, io, powerState, eventName, |
| 70 | eventName, assert, combineEvent, state, psuName, pollRate); |
Yong Li | bf8b1da | 2020-04-15 16:32:50 +0800 | [diff] [blame] | 71 | p->setupRead(); |
| 72 | |
| 73 | events[eventPSUName].emplace_back(p); |
Cheng C Yang | 58b2b53 | 2019-05-31 00:19:45 +0800 | [diff] [blame] | 74 | asserts.emplace_back(assert); |
| 75 | states.emplace_back(state); |
| 76 | } |
| 77 | } |
Cheng C Yang | 202a1ff | 2020-01-09 09:34:22 +0800 | [diff] [blame] | 78 | |
Zev Weiss | b85145c | 2022-08-12 18:21:02 -0700 | [diff] [blame] | 79 | for (const auto& [eventName, groupEvents] : groupEventPathList) |
Cheng C Yang | 202a1ff | 2020-01-09 09:34:22 +0800 | [diff] [blame] | 80 | { |
Zev Weiss | b85145c | 2022-08-12 18:21:02 -0700 | [diff] [blame] | 81 | for (const auto& [groupEventName, paths] : groupEvents) |
Cheng C Yang | 202a1ff | 2020-01-09 09:34:22 +0800 | [diff] [blame] | 82 | { |
| 83 | std::shared_ptr<std::set<std::string>> assert = |
| 84 | std::make_shared<std::set<std::string>>(); |
| 85 | std::shared_ptr<bool> state = std::make_shared<bool>(false); |
| 86 | |
Cheng C Yang | 202a1ff | 2020-01-09 09:34:22 +0800 | [diff] [blame] | 87 | std::string eventPSUName = groupEventName + psuName; |
Zev Weiss | b85145c | 2022-08-12 18:21:02 -0700 | [diff] [blame] | 88 | for (const auto& path : paths) |
Cheng C Yang | 202a1ff | 2020-01-09 09:34:22 +0800 | [diff] [blame] | 89 | { |
Yong Li | bf8b1da | 2020-04-15 16:32:50 +0800 | [diff] [blame] | 90 | auto p = std::make_shared<PSUSubEvent>( |
Konstantin Aladyshev | c7a1ae6 | 2021-04-30 08:50:43 +0000 | [diff] [blame] | 91 | eventInterface, path, conn, io, powerState, groupEventName, |
Zev Weiss | b85145c | 2022-08-12 18:21:02 -0700 | [diff] [blame] | 92 | eventName, assert, combineEvent, state, psuName, pollRate); |
Yong Li | bf8b1da | 2020-04-15 16:32:50 +0800 | [diff] [blame] | 93 | p->setupRead(); |
| 94 | events[eventPSUName].emplace_back(p); |
| 95 | |
Cheng C Yang | 202a1ff | 2020-01-09 09:34:22 +0800 | [diff] [blame] | 96 | asserts.emplace_back(assert); |
| 97 | states.emplace_back(state); |
| 98 | } |
| 99 | } |
| 100 | } |
Cheng C Yang | 58b2b53 | 2019-05-31 00:19:45 +0800 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | PSUCombineEvent::~PSUCombineEvent() |
| 104 | { |
Cheng C Yang | 202a1ff | 2020-01-09 09:34:22 +0800 | [diff] [blame] | 105 | // Clear unique_ptr first |
Zev Weiss | b85145c | 2022-08-12 18:21:02 -0700 | [diff] [blame] | 106 | for (auto& [psuName, subEvents] : events) |
Cheng C Yang | 202a1ff | 2020-01-09 09:34:22 +0800 | [diff] [blame] | 107 | { |
Zev Weiss | b85145c | 2022-08-12 18:21:02 -0700 | [diff] [blame] | 108 | for (auto& subEventPtr : subEvents) |
Cheng C Yang | 202a1ff | 2020-01-09 09:34:22 +0800 | [diff] [blame] | 109 | { |
| 110 | subEventPtr.reset(); |
| 111 | } |
| 112 | } |
Cheng C Yang | 58b2b53 | 2019-05-31 00:19:45 +0800 | [diff] [blame] | 113 | events.clear(); |
| 114 | objServer.remove_interface(eventInterface); |
| 115 | } |
| 116 | |
Cheng C Yang | 9b53a62 | 2019-08-27 22:13:58 +0800 | [diff] [blame] | 117 | static boost::container::flat_map<std::string, |
| 118 | std::pair<std::string, std::string>> |
| 119 | logID = { |
| 120 | {"PredictiveFailure", |
| 121 | {"OpenBMC.0.1.PowerSupplyFailurePredicted", |
| 122 | "OpenBMC.0.1.PowerSupplyPredictedFailureRecovered"}}, |
| 123 | {"Failure", |
| 124 | {"OpenBMC.0.1.PowerSupplyFailed", "OpenBMC.0.1.PowerSupplyRecovered"}}, |
| 125 | {"ACLost", |
Cheng C Yang | bb732ef | 2019-09-18 16:25:58 +0800 | [diff] [blame] | 126 | {"OpenBMC.0.1.PowerSupplyPowerLost", |
| 127 | "OpenBMC.0.1.PowerSupplyPowerRestored"}}, |
Cheng C Yang | 9b53a62 | 2019-08-27 22:13:58 +0800 | [diff] [blame] | 128 | {"FanFault", |
| 129 | {"OpenBMC.0.1.PowerSupplyFanFailed", |
| 130 | "OpenBMC.0.1.PowerSupplyFanRecovered"}}, |
jayaprakash Mutyala | d12f23e | 2019-12-03 23:03:52 +0000 | [diff] [blame] | 131 | {"ConfigureError", |
| 132 | {"OpenBMC.0.1.PowerSupplyConfigurationError", |
| 133 | "OpenBMC.0.1.PowerSupplyConfigurationErrorRecovered"}}}; |
Cheng C Yang | 5665db2 | 2019-07-12 00:57:30 +0800 | [diff] [blame] | 134 | |
Cheng C Yang | 58b2b53 | 2019-05-31 00:19:45 +0800 | [diff] [blame] | 135 | PSUSubEvent::PSUSubEvent( |
| 136 | std::shared_ptr<sdbusplus::asio::dbus_interface> eventInterface, |
Yong Li | 3046a02 | 2020-04-03 13:01:02 +0800 | [diff] [blame] | 137 | const std::string& path, std::shared_ptr<sdbusplus::asio::connection>& conn, |
Ed Tanous | 1f97863 | 2023-02-28 18:16:39 -0800 | [diff] [blame] | 138 | boost::asio::io_context& io, const PowerState& powerState, |
Konstantin Aladyshev | c7a1ae6 | 2021-04-30 08:50:43 +0000 | [diff] [blame] | 139 | const std::string& groupEventName, const std::string& eventName, |
Cheng C Yang | 58b2b53 | 2019-05-31 00:19:45 +0800 | [diff] [blame] | 140 | std::shared_ptr<std::set<std::string>> asserts, |
| 141 | std::shared_ptr<std::set<std::string>> combineEvent, |
Lei YU | 7170a23 | 2021-02-04 16:19:27 +0800 | [diff] [blame] | 142 | std::shared_ptr<bool> state, const std::string& psuName, double pollRate) : |
Ed Tanous | 2049bd2 | 2022-07-09 07:20:26 -0700 | [diff] [blame] | 143 | eventInterface(std::move(eventInterface)), |
| 144 | asserts(std::move(asserts)), combineEvent(std::move(combineEvent)), |
| 145 | assertState(std::move(state)), path(path), eventName(eventName), |
Ed Tanous | 16966b5 | 2021-09-15 15:06:59 -0700 | [diff] [blame] | 146 | readState(powerState), waitTimer(io), |
| 147 | |
| 148 | inputDev(io, path, boost::asio::random_access_file::read_only), |
| 149 | psuName(psuName), groupEventName(groupEventName), systemBus(conn) |
Cheng C Yang | 58b2b53 | 2019-05-31 00:19:45 +0800 | [diff] [blame] | 150 | { |
Ed Tanous | 16966b5 | 2021-09-15 15:06:59 -0700 | [diff] [blame] | 151 | buffer = std::make_shared<std::array<char, 128>>(); |
Lei YU | 7170a23 | 2021-02-04 16:19:27 +0800 | [diff] [blame] | 152 | if (pollRate > 0.0) |
| 153 | { |
| 154 | eventPollMs = static_cast<unsigned int>(pollRate * 1000); |
| 155 | } |
Ed Tanous | 99c4409 | 2022-01-14 09:59:09 -0800 | [diff] [blame] | 156 | |
Cheng C Yang | 5665db2 | 2019-07-12 00:57:30 +0800 | [diff] [blame] | 157 | auto found = logID.find(eventName); |
| 158 | if (found == logID.end()) |
| 159 | { |
Cheng C Yang | 9b53a62 | 2019-08-27 22:13:58 +0800 | [diff] [blame] | 160 | assertMessage.clear(); |
| 161 | deassertMessage.clear(); |
Cheng C Yang | 5665db2 | 2019-07-12 00:57:30 +0800 | [diff] [blame] | 162 | } |
| 163 | else |
| 164 | { |
Cheng C Yang | 9b53a62 | 2019-08-27 22:13:58 +0800 | [diff] [blame] | 165 | assertMessage = found->second.first; |
| 166 | deassertMessage = found->second.second; |
Cheng C Yang | 5665db2 | 2019-07-12 00:57:30 +0800 | [diff] [blame] | 167 | } |
| 168 | |
| 169 | auto fanPos = path.find("fan"); |
| 170 | if (fanPos != std::string::npos) |
| 171 | { |
| 172 | fanName = path.substr(fanPos); |
Ed Tanous | 8a57ec0 | 2020-10-09 12:46:52 -0700 | [diff] [blame] | 173 | auto fanNamePos = fanName.find('_'); |
Cheng C Yang | 9b53a62 | 2019-08-27 22:13:58 +0800 | [diff] [blame] | 174 | if (fanNamePos != std::string::npos) |
| 175 | { |
| 176 | fanName = fanName.substr(0, fanNamePos); |
| 177 | } |
Cheng C Yang | 5665db2 | 2019-07-12 00:57:30 +0800 | [diff] [blame] | 178 | } |
Cheng C Yang | 58b2b53 | 2019-05-31 00:19:45 +0800 | [diff] [blame] | 179 | } |
| 180 | |
Konstantin Aladyshev | c7a1ae6 | 2021-04-30 08:50:43 +0000 | [diff] [blame] | 181 | PSUSubEvent::~PSUSubEvent() |
| 182 | { |
| 183 | waitTimer.cancel(); |
| 184 | inputDev.close(); |
| 185 | } |
| 186 | |
Ed Tanous | 201a101 | 2024-04-03 18:07:28 -0700 | [diff] [blame] | 187 | void PSUSubEvent::setupRead() |
Cheng C Yang | 58b2b53 | 2019-05-31 00:19:45 +0800 | [diff] [blame] | 188 | { |
Konstantin Aladyshev | c7a1ae6 | 2021-04-30 08:50:43 +0000 | [diff] [blame] | 189 | if (!readingStateGood(readState)) |
| 190 | { |
| 191 | // Deassert the event |
| 192 | updateValue(0); |
| 193 | restartRead(); |
| 194 | return; |
| 195 | } |
Ed Tanous | 16966b5 | 2021-09-15 15:06:59 -0700 | [diff] [blame] | 196 | if (!buffer) |
| 197 | { |
| 198 | std::cerr << "Buffer was invalid?"; |
| 199 | return; |
| 200 | } |
Konstantin Aladyshev | c7a1ae6 | 2021-04-30 08:50:43 +0000 | [diff] [blame] | 201 | |
Yong Li | bf8b1da | 2020-04-15 16:32:50 +0800 | [diff] [blame] | 202 | std::weak_ptr<PSUSubEvent> weakRef = weak_from_this(); |
Ed Tanous | 16966b5 | 2021-09-15 15:06:59 -0700 | [diff] [blame] | 203 | inputDev.async_read_some_at( |
| 204 | 0, boost::asio::buffer(buffer->data(), buffer->size() - 1), |
| 205 | [weakRef, buffer{buffer}](const boost::system::error_code& ec, |
| 206 | std::size_t bytesTransferred) { |
Ed Tanous | bb67932 | 2022-05-16 16:10:00 -0700 | [diff] [blame] | 207 | std::shared_ptr<PSUSubEvent> self = weakRef.lock(); |
| 208 | if (self) |
| 209 | { |
Ed Tanous | 16966b5 | 2021-09-15 15:06:59 -0700 | [diff] [blame] | 210 | self->handleResponse(ec, bytesTransferred); |
Ed Tanous | bb67932 | 2022-05-16 16:10:00 -0700 | [diff] [blame] | 211 | } |
Patrick Williams | 597e842 | 2023-10-20 11:19:01 -0500 | [diff] [blame] | 212 | }); |
Cheng C Yang | 58b2b53 | 2019-05-31 00:19:45 +0800 | [diff] [blame] | 213 | } |
| 214 | |
Konstantin Aladyshev | c7a1ae6 | 2021-04-30 08:50:43 +0000 | [diff] [blame] | 215 | void PSUSubEvent::restartRead() |
Cheng C Yang | 58b2b53 | 2019-05-31 00:19:45 +0800 | [diff] [blame] | 216 | { |
Konstantin Aladyshev | c7a1ae6 | 2021-04-30 08:50:43 +0000 | [diff] [blame] | 217 | std::weak_ptr<PSUSubEvent> weakRef = weak_from_this(); |
Ed Tanous | 83db50c | 2023-03-01 10:20:24 -0800 | [diff] [blame] | 218 | waitTimer.expires_after(std::chrono::milliseconds(eventPollMs)); |
Konstantin Aladyshev | c7a1ae6 | 2021-04-30 08:50:43 +0000 | [diff] [blame] | 219 | waitTimer.async_wait([weakRef](const boost::system::error_code& ec) { |
| 220 | if (ec == boost::asio::error::operation_aborted) |
| 221 | { |
| 222 | return; |
| 223 | } |
| 224 | std::shared_ptr<PSUSubEvent> self = weakRef.lock(); |
| 225 | if (self) |
| 226 | { |
| 227 | self->setupRead(); |
| 228 | } |
| 229 | }); |
Cheng C Yang | 58b2b53 | 2019-05-31 00:19:45 +0800 | [diff] [blame] | 230 | } |
| 231 | |
Ed Tanous | 16966b5 | 2021-09-15 15:06:59 -0700 | [diff] [blame] | 232 | void PSUSubEvent::handleResponse(const boost::system::error_code& err, |
| 233 | size_t bytesTransferred) |
Cheng C Yang | 58b2b53 | 2019-05-31 00:19:45 +0800 | [diff] [blame] | 234 | { |
Ed Tanous | 16966b5 | 2021-09-15 15:06:59 -0700 | [diff] [blame] | 235 | if (err == boost::asio::error::operation_aborted) |
| 236 | { |
| 237 | return; |
| 238 | } |
| 239 | |
Yong Li | bf8b1da | 2020-04-15 16:32:50 +0800 | [diff] [blame] | 240 | if ((err == boost::system::errc::bad_file_descriptor) || |
| 241 | (err == boost::asio::error::misc_errors::not_found)) |
Cheng C Yang | 58b2b53 | 2019-05-31 00:19:45 +0800 | [diff] [blame] | 242 | { |
| 243 | return; |
| 244 | } |
Ed Tanous | 16966b5 | 2021-09-15 15:06:59 -0700 | [diff] [blame] | 245 | if (!buffer) |
| 246 | { |
| 247 | std::cerr << "Buffer was invalid?"; |
| 248 | return; |
| 249 | } |
| 250 | // null terminate the string so we don't walk off the end |
| 251 | std::array<char, 128>& bufferRef = *buffer; |
| 252 | bufferRef[bytesTransferred] = '\0'; |
| 253 | |
Cheng C Yang | 58b2b53 | 2019-05-31 00:19:45 +0800 | [diff] [blame] | 254 | if (!err) |
| 255 | { |
Cheng C Yang | 58b2b53 | 2019-05-31 00:19:45 +0800 | [diff] [blame] | 256 | try |
| 257 | { |
Ed Tanous | 16966b5 | 2021-09-15 15:06:59 -0700 | [diff] [blame] | 258 | int nvalue = std::stoi(bufferRef.data()); |
Josh Lehan | 833661a | 2020-03-04 17:35:41 -0800 | [diff] [blame] | 259 | updateValue(nvalue); |
Cheng C Yang | 58b2b53 | 2019-05-31 00:19:45 +0800 | [diff] [blame] | 260 | errCount = 0; |
| 261 | } |
| 262 | catch (const std::invalid_argument&) |
| 263 | { |
| 264 | errCount++; |
| 265 | } |
| 266 | } |
| 267 | else |
| 268 | { |
| 269 | errCount++; |
| 270 | } |
| 271 | if (errCount >= warnAfterErrorCount) |
| 272 | { |
| 273 | if (errCount == warnAfterErrorCount) |
| 274 | { |
| 275 | std::cerr << "Failure to read event at " << path << "\n"; |
| 276 | } |
| 277 | updateValue(0); |
| 278 | errCount++; |
| 279 | } |
Konstantin Aladyshev | c7a1ae6 | 2021-04-30 08:50:43 +0000 | [diff] [blame] | 280 | restartRead(); |
Cheng C Yang | 58b2b53 | 2019-05-31 00:19:45 +0800 | [diff] [blame] | 281 | } |
| 282 | |
| 283 | // Any of the sub events of one event is asserted, then the event will be |
| 284 | // asserted. Only if none of the sub events are asserted, the event will be |
| 285 | // deasserted. |
| 286 | void PSUSubEvent::updateValue(const int& newValue) |
| 287 | { |
Josh Lehan | 833661a | 2020-03-04 17:35:41 -0800 | [diff] [blame] | 288 | // Take no action if value already equal |
| 289 | // Same semantics as Sensor::updateValue(const double&) |
| 290 | if (newValue == value) |
| 291 | { |
| 292 | return; |
| 293 | } |
| 294 | |
Cheng C Yang | 58b2b53 | 2019-05-31 00:19:45 +0800 | [diff] [blame] | 295 | if (newValue == 0) |
| 296 | { |
Yong Li | 591b1e4 | 2019-12-19 17:46:31 +0800 | [diff] [blame] | 297 | // log deassert only after all asserts are gone |
Cheng C Yang | 58b2b53 | 2019-05-31 00:19:45 +0800 | [diff] [blame] | 298 | if (!(*asserts).empty()) |
| 299 | { |
Yong Li | 591b1e4 | 2019-12-19 17:46:31 +0800 | [diff] [blame] | 300 | auto found = (*asserts).find(path); |
| 301 | if (found == (*asserts).end()) |
| 302 | { |
| 303 | return; |
| 304 | } |
| 305 | (*asserts).erase(path); |
| 306 | |
Cheng C Yang | 58b2b53 | 2019-05-31 00:19:45 +0800 | [diff] [blame] | 307 | return; |
| 308 | } |
Ed Tanous | 2049bd2 | 2022-07-09 07:20:26 -0700 | [diff] [blame] | 309 | if (*assertState) |
Cheng C Yang | 58b2b53 | 2019-05-31 00:19:45 +0800 | [diff] [blame] | 310 | { |
| 311 | *assertState = false; |
Cheng C Yang | 202a1ff | 2020-01-09 09:34:22 +0800 | [diff] [blame] | 312 | auto foundCombine = (*combineEvent).find(groupEventName); |
Cheng C Yang | 9b53a62 | 2019-08-27 22:13:58 +0800 | [diff] [blame] | 313 | if (foundCombine == (*combineEvent).end()) |
Cheng C Yang | 58b2b53 | 2019-05-31 00:19:45 +0800 | [diff] [blame] | 314 | { |
| 315 | return; |
| 316 | } |
Cheng C Yang | 202a1ff | 2020-01-09 09:34:22 +0800 | [diff] [blame] | 317 | (*combineEvent).erase(groupEventName); |
Cheng C Yang | 9b53a62 | 2019-08-27 22:13:58 +0800 | [diff] [blame] | 318 | if (!deassertMessage.empty()) |
| 319 | { |
| 320 | // Fan Failed has two args |
Cheng C Yang | 9b53a62 | 2019-08-27 22:13:58 +0800 | [diff] [blame] | 321 | if (deassertMessage == "OpenBMC.0.1.PowerSupplyFanRecovered") |
| 322 | { |
Patrick Williams | 0c42f40 | 2021-08-27 16:05:45 -0500 | [diff] [blame] | 323 | lg2::info("{EVENT} deassert", "EVENT", eventName, |
| 324 | "REDFISH_MESSAGE_ID", deassertMessage, |
| 325 | "REDFISH_MESSAGE_ARGS", |
| 326 | (psuName + ',' + fanName)); |
Cheng C Yang | 9b53a62 | 2019-08-27 22:13:58 +0800 | [diff] [blame] | 327 | } |
| 328 | else |
| 329 | { |
Patrick Williams | 0c42f40 | 2021-08-27 16:05:45 -0500 | [diff] [blame] | 330 | lg2::info("{EVENT} deassert", "EVENT", eventName, |
| 331 | "REDFISH_MESSAGE_ID", deassertMessage, |
| 332 | "REDFISH_MESSAGE_ARGS", psuName); |
Cheng C Yang | 9b53a62 | 2019-08-27 22:13:58 +0800 | [diff] [blame] | 333 | } |
| 334 | } |
| 335 | |
Cheng C Yang | 58b2b53 | 2019-05-31 00:19:45 +0800 | [diff] [blame] | 336 | if ((*combineEvent).empty()) |
| 337 | { |
| 338 | eventInterface->set_property("functional", true); |
| 339 | } |
| 340 | } |
| 341 | } |
| 342 | else |
| 343 | { |
Paul Fertser | 3453354 | 2021-07-20 08:29:09 +0000 | [diff] [blame] | 344 | std::cerr << "PSUSubEvent asserted by " << path << "\n"; |
| 345 | |
Ed Tanous | 2049bd2 | 2022-07-09 07:20:26 -0700 | [diff] [blame] | 346 | if ((!*assertState) && ((*asserts).empty())) |
Cheng C Yang | 58b2b53 | 2019-05-31 00:19:45 +0800 | [diff] [blame] | 347 | { |
| 348 | *assertState = true; |
Cheng C Yang | 9b53a62 | 2019-08-27 22:13:58 +0800 | [diff] [blame] | 349 | if (!assertMessage.empty()) |
Cheng C Yang | 5665db2 | 2019-07-12 00:57:30 +0800 | [diff] [blame] | 350 | { |
| 351 | // Fan Failed has two args |
Cheng C Yang | 9b53a62 | 2019-08-27 22:13:58 +0800 | [diff] [blame] | 352 | if (assertMessage == "OpenBMC.0.1.PowerSupplyFanFailed") |
Cheng C Yang | 5665db2 | 2019-07-12 00:57:30 +0800 | [diff] [blame] | 353 | { |
Patrick Williams | 0c42f40 | 2021-08-27 16:05:45 -0500 | [diff] [blame] | 354 | lg2::warning("{EVENT} assert", "EVENT", eventName, |
| 355 | "REDFISH_MESSAGE_ID", assertMessage, |
| 356 | "REDFISH_MESSAGE_ARGS", |
| 357 | (psuName + ',' + fanName)); |
Cheng C Yang | 5665db2 | 2019-07-12 00:57:30 +0800 | [diff] [blame] | 358 | } |
| 359 | else |
| 360 | { |
Patrick Williams | 0c42f40 | 2021-08-27 16:05:45 -0500 | [diff] [blame] | 361 | lg2::warning("{EVENT} assert", "EVENT", eventName, |
| 362 | "REDFISH_MESSAGE_ID", assertMessage, |
| 363 | "REDFISH_MESSAGE_ARGS", psuName); |
Cheng C Yang | 5665db2 | 2019-07-12 00:57:30 +0800 | [diff] [blame] | 364 | } |
| 365 | } |
Cheng C Yang | 58b2b53 | 2019-05-31 00:19:45 +0800 | [diff] [blame] | 366 | if ((*combineEvent).empty()) |
| 367 | { |
| 368 | eventInterface->set_property("functional", false); |
| 369 | } |
Cheng C Yang | 202a1ff | 2020-01-09 09:34:22 +0800 | [diff] [blame] | 370 | (*combineEvent).emplace(groupEventName); |
Cheng C Yang | 58b2b53 | 2019-05-31 00:19:45 +0800 | [diff] [blame] | 371 | } |
Yong Li | 591b1e4 | 2019-12-19 17:46:31 +0800 | [diff] [blame] | 372 | (*asserts).emplace(path); |
Cheng C Yang | 58b2b53 | 2019-05-31 00:19:45 +0800 | [diff] [blame] | 373 | } |
| 374 | value = newValue; |
| 375 | } |