Alexander Hansen | 4e1142d | 2025-07-25 17:07:27 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: Apache-2.0 |
| 2 | // SPDX-FileCopyrightText: Copyright 2018 Intel Corporation |
James Feist | 3cb5fec | 2018-01-23 14:41:51 -0800 | [diff] [blame] | 3 | |
Brad Bishop | e45d8c7 | 2022-05-25 15:12:53 -0400 | [diff] [blame] | 4 | #include "entity_manager.hpp" |
James Feist | 1df06a4 | 2019-04-11 14:23:04 -0700 | [diff] [blame] | 5 | |
Christopher Meis | fc9e7fd | 2025-04-03 13:13:35 +0200 | [diff] [blame] | 6 | #include "../utils.hpp" |
| 7 | #include "../variant_visitors.hpp" |
Christopher Meis | bdaa6b2 | 2025-04-02 10:49:02 +0200 | [diff] [blame] | 8 | #include "configuration.hpp" |
Christopher Meis | 12bea9b | 2025-04-03 10:14:42 +0200 | [diff] [blame] | 9 | #include "dbus_interface.hpp" |
Alexander Hansen | f57a259 | 2025-06-27 15:07:07 +0200 | [diff] [blame] | 10 | #include "log_device_inventory.hpp" |
Brad Bishop | e45d8c7 | 2022-05-25 15:12:53 -0400 | [diff] [blame] | 11 | #include "overlay.hpp" |
Christopher Meis | 26fbbd5 | 2025-03-26 14:55:06 +0100 | [diff] [blame] | 12 | #include "perform_scan.hpp" |
Alexander Hansen | 6080318 | 2025-06-27 14:41:28 +0200 | [diff] [blame] | 13 | #include "phosphor-logging/lg2.hpp" |
Benjamin Fair | ca2eb04 | 2022-09-13 06:40:42 +0000 | [diff] [blame] | 14 | #include "topology.hpp" |
Christopher Meis | 59ef1e7 | 2025-04-16 08:53:25 +0200 | [diff] [blame] | 15 | #include "utils.hpp" |
James Feist | 481c5d5 | 2019-08-13 14:40:40 -0700 | [diff] [blame] | 16 | |
James Feist | 11be667 | 2018-04-06 14:05:32 -0700 | [diff] [blame] | 17 | #include <boost/algorithm/string/case_conv.hpp> |
James Feist | f5125b0 | 2019-06-06 11:27:43 -0700 | [diff] [blame] | 18 | #include <boost/algorithm/string/classification.hpp> |
James Feist | 3cb5fec | 2018-01-23 14:41:51 -0800 | [diff] [blame] | 19 | #include <boost/algorithm/string/predicate.hpp> |
| 20 | #include <boost/algorithm/string/replace.hpp> |
James Feist | f5125b0 | 2019-06-06 11:27:43 -0700 | [diff] [blame] | 21 | #include <boost/algorithm/string/split.hpp> |
James Feist | 02d2b93 | 2020-02-06 16:28:48 -0800 | [diff] [blame] | 22 | #include <boost/asio/io_context.hpp> |
Ed Tanous | 49a888c | 2023-03-06 13:44:51 -0800 | [diff] [blame] | 23 | #include <boost/asio/post.hpp> |
James Feist | b1728ca | 2020-04-30 15:40:55 -0700 | [diff] [blame] | 24 | #include <boost/asio/steady_timer.hpp> |
James Feist | 3cb5fec | 2018-01-23 14:41:51 -0800 | [diff] [blame] | 25 | #include <boost/container/flat_map.hpp> |
| 26 | #include <boost/container/flat_set.hpp> |
James Feist | f5125b0 | 2019-06-06 11:27:43 -0700 | [diff] [blame] | 27 | #include <boost/range/iterator_range.hpp> |
James Feist | 8c505da | 2020-05-28 10:06:33 -0700 | [diff] [blame] | 28 | #include <nlohmann/json.hpp> |
| 29 | #include <sdbusplus/asio/connection.hpp> |
| 30 | #include <sdbusplus/asio/object_server.hpp> |
| 31 | |
James Feist | 637b3ef | 2019-04-15 16:35:30 -0700 | [diff] [blame] | 32 | #include <filesystem> |
James Feist | a465ccc | 2019-02-08 12:51:01 -0800 | [diff] [blame] | 33 | #include <fstream> |
Andrew Jeffery | e35d0ac | 2022-03-24 15:53:13 +1030 | [diff] [blame] | 34 | #include <functional> |
James Feist | a465ccc | 2019-02-08 12:51:01 -0800 | [diff] [blame] | 35 | #include <iostream> |
Andrew Jeffery | 666583b | 2021-12-01 15:50:12 +1030 | [diff] [blame] | 36 | #include <map> |
James Feist | a465ccc | 2019-02-08 12:51:01 -0800 | [diff] [blame] | 37 | #include <regex> |
James Feist | 1df06a4 | 2019-04-11 14:23:04 -0700 | [diff] [blame] | 38 | constexpr const char* tempConfigDir = "/tmp/configuration/"; |
| 39 | constexpr const char* lastConfiguration = "/tmp/configuration/last.json"; |
James Feist | f1b1414 | 2019-04-10 15:22:09 -0700 | [diff] [blame] | 40 | |
Adrian Ambrożewicz | c789fca | 2020-05-14 15:50:05 +0200 | [diff] [blame] | 41 | static constexpr std::array<const char*, 6> settableInterfaces = { |
| 42 | "FanProfile", "Pid", "Pid.Zone", "Stepwise", "Thresholds", "Polling"}; |
James Feist | 3cb5fec | 2018-01-23 14:41:51 -0800 | [diff] [blame] | 43 | |
Ed Tanous | 07d467b | 2021-02-23 14:48:37 -0800 | [diff] [blame] | 44 | const std::regex illegalDbusPathRegex("[^A-Za-z0-9_.]"); |
| 45 | const std::regex illegalDbusMemberRegex("[^A-Za-z0-9_]"); |
James Feist | 1b2e224 | 2018-01-30 13:45:19 -0800 | [diff] [blame] | 46 | |
James Feist | a465ccc | 2019-02-08 12:51:01 -0800 | [diff] [blame] | 47 | sdbusplus::asio::PropertyPermission getPermission(const std::string& interface) |
James Feist | c6248a5 | 2018-08-14 10:09:45 -0700 | [diff] [blame] | 48 | { |
| 49 | return std::find(settableInterfaces.begin(), settableInterfaces.end(), |
| 50 | interface) != settableInterfaces.end() |
| 51 | ? sdbusplus::asio::PropertyPermission::readWrite |
| 52 | : sdbusplus::asio::PropertyPermission::readOnly; |
| 53 | } |
| 54 | |
Christopher Meis | cf6a75b | 2025-06-03 07:53:50 +0200 | [diff] [blame] | 55 | EntityManager::EntityManager( |
Alexander Hansen | a555acf | 2025-06-27 11:59:10 +0200 | [diff] [blame] | 56 | std::shared_ptr<sdbusplus::asio::connection>& systemBus, |
| 57 | boost::asio::io_context& io) : |
Christopher Meis | cf6a75b | 2025-06-03 07:53:50 +0200 | [diff] [blame] | 58 | systemBus(systemBus), |
| 59 | objServer(sdbusplus::asio::object_server(systemBus, /*skipManager=*/true)), |
| 60 | lastJson(nlohmann::json::object()), |
Alexander Hansen | b1340da | 2025-06-27 14:29:13 +0200 | [diff] [blame] | 61 | systemConfiguration(nlohmann::json::object()), io(io), |
Alexander Hansen | e164627 | 2025-07-25 11:47:17 +0200 | [diff] [blame] | 62 | powerStatus(*systemBus), propertiesChangedTimer(io) |
Christopher Meis | cf6a75b | 2025-06-03 07:53:50 +0200 | [diff] [blame] | 63 | { |
| 64 | // All other objects that EntityManager currently support are under the |
| 65 | // inventory subtree. |
| 66 | // See the discussion at |
| 67 | // https://discord.com/channels/775381525260664832/1018929092009144380 |
| 68 | objServer.add_manager("/xyz/openbmc_project/inventory"); |
James Feist | 75fdeeb | 2018-02-20 14:26:16 -0800 | [diff] [blame] | 69 | |
Christopher Meis | cf6a75b | 2025-06-03 07:53:50 +0200 | [diff] [blame] | 70 | entityIface = objServer.add_interface("/xyz/openbmc_project/EntityManager", |
| 71 | "xyz.openbmc_project.EntityManager"); |
| 72 | entityIface->register_method("ReScan", [this]() { |
| 73 | propertiesChangedCallback(); |
| 74 | }); |
| 75 | dbus_interface::tryIfaceInitialize(entityIface); |
Christopher Meis | f725257 | 2025-06-11 13:22:05 +0200 | [diff] [blame] | 76 | |
| 77 | initFilters(configuration.probeInterfaces); |
Christopher Meis | cf6a75b | 2025-06-03 07:53:50 +0200 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | void EntityManager::postToDbus(const nlohmann::json& newConfiguration) |
James Feist | 1b2e224 | 2018-01-30 13:45:19 -0800 | [diff] [blame] | 81 | { |
Matt Spinler | 6eb6097 | 2023-08-14 16:36:20 -0500 | [diff] [blame] | 82 | std::map<std::string, std::string> newBoards; // path -> name |
Benjamin Fair | ca2eb04 | 2022-09-13 06:40:42 +0000 | [diff] [blame] | 83 | |
James Feist | 97a63f1 | 2018-05-17 13:50:57 -0700 | [diff] [blame] | 84 | // iterate through boards |
Patrick Williams | 2594d36 | 2022-09-28 06:46:24 -0500 | [diff] [blame] | 85 | for (const auto& [boardId, boardConfig] : newConfiguration.items()) |
James Feist | 1b2e224 | 2018-01-30 13:45:19 -0800 | [diff] [blame] | 86 | { |
Alexander Hansen | 4fcd946 | 2025-07-30 17:44:44 +0200 | [diff] [blame] | 87 | postBoardToDBus(boardId, boardConfig, newBoards); |
James Feist | 1b2e224 | 2018-01-30 13:45:19 -0800 | [diff] [blame] | 88 | } |
Benjamin Fair | ca2eb04 | 2022-09-13 06:40:42 +0000 | [diff] [blame] | 89 | |
Matt Spinler | 6eb6097 | 2023-08-14 16:36:20 -0500 | [diff] [blame] | 90 | for (const auto& [assocPath, assocPropValue] : |
| 91 | topology.getAssocs(newBoards)) |
Benjamin Fair | ca2eb04 | 2022-09-13 06:40:42 +0000 | [diff] [blame] | 92 | { |
Matt Spinler | 6eb6097 | 2023-08-14 16:36:20 -0500 | [diff] [blame] | 93 | auto findBoard = newBoards.find(assocPath); |
| 94 | if (findBoard == newBoards.end()) |
| 95 | { |
| 96 | continue; |
| 97 | } |
Benjamin Fair | ca2eb04 | 2022-09-13 06:40:42 +0000 | [diff] [blame] | 98 | |
Alexander Hansen | 57604ed | 2025-06-27 13:22:28 +0200 | [diff] [blame] | 99 | auto ifacePtr = dbus_interface.createInterface( |
Matt Spinler | 6eb6097 | 2023-08-14 16:36:20 -0500 | [diff] [blame] | 100 | objServer, assocPath, "xyz.openbmc_project.Association.Definitions", |
| 101 | findBoard->second); |
| 102 | |
| 103 | ifacePtr->register_property("Associations", assocPropValue); |
Christopher Meis | 12bea9b | 2025-04-03 10:14:42 +0200 | [diff] [blame] | 104 | dbus_interface::tryIfaceInitialize(ifacePtr); |
Benjamin Fair | ca2eb04 | 2022-09-13 06:40:42 +0000 | [diff] [blame] | 105 | } |
James Feist | 1b2e224 | 2018-01-30 13:45:19 -0800 | [diff] [blame] | 106 | } |
| 107 | |
Alexander Hansen | 4fcd946 | 2025-07-30 17:44:44 +0200 | [diff] [blame] | 108 | void EntityManager::postBoardToDBus( |
| 109 | const std::string& boardId, const nlohmann::json& boardConfig, |
| 110 | std::map<std::string, std::string>& newBoards) |
| 111 | { |
| 112 | std::string boardName = boardConfig["Name"]; |
| 113 | std::string boardNameOrig = boardConfig["Name"]; |
| 114 | std::string jsonPointerPath = "/" + boardId; |
| 115 | // loop through newConfiguration, but use values from system |
| 116 | // configuration to be able to modify via dbus later |
| 117 | auto boardValues = systemConfiguration[boardId]; |
| 118 | auto findBoardType = boardValues.find("Type"); |
| 119 | std::string boardType; |
| 120 | if (findBoardType != boardValues.end() && |
| 121 | findBoardType->type() == nlohmann::json::value_t::string) |
| 122 | { |
| 123 | boardType = findBoardType->get<std::string>(); |
| 124 | std::regex_replace(boardType.begin(), boardType.begin(), |
| 125 | boardType.end(), illegalDbusMemberRegex, "_"); |
| 126 | } |
| 127 | else |
| 128 | { |
| 129 | std::cerr << "Unable to find type for " << boardName |
| 130 | << " reverting to Chassis.\n"; |
| 131 | boardType = "Chassis"; |
| 132 | } |
| 133 | std::string boardtypeLower = boost::algorithm::to_lower_copy(boardType); |
| 134 | |
| 135 | std::regex_replace(boardName.begin(), boardName.begin(), boardName.end(), |
| 136 | illegalDbusMemberRegex, "_"); |
| 137 | std::string boardPath = "/xyz/openbmc_project/inventory/system/"; |
| 138 | boardPath += boardtypeLower; |
| 139 | boardPath += "/"; |
| 140 | boardPath += boardName; |
| 141 | |
| 142 | std::shared_ptr<sdbusplus::asio::dbus_interface> inventoryIface = |
| 143 | dbus_interface.createInterface(objServer, boardPath, |
| 144 | "xyz.openbmc_project.Inventory.Item", |
| 145 | boardName); |
| 146 | |
| 147 | std::shared_ptr<sdbusplus::asio::dbus_interface> boardIface = |
| 148 | dbus_interface.createInterface( |
| 149 | objServer, boardPath, |
| 150 | "xyz.openbmc_project.Inventory.Item." + boardType, boardNameOrig); |
| 151 | |
| 152 | dbus_interface.createAddObjectMethod( |
| 153 | io, jsonPointerPath, boardPath, systemConfiguration, objServer, |
| 154 | boardNameOrig); |
| 155 | |
| 156 | dbus_interface::populateInterfaceFromJson( |
| 157 | io, systemConfiguration, jsonPointerPath, boardIface, boardValues, |
| 158 | objServer); |
| 159 | jsonPointerPath += "/"; |
| 160 | // iterate through board properties |
| 161 | for (const auto& [propName, propValue] : boardValues.items()) |
| 162 | { |
| 163 | if (propValue.type() == nlohmann::json::value_t::object) |
| 164 | { |
| 165 | std::shared_ptr<sdbusplus::asio::dbus_interface> iface = |
| 166 | dbus_interface.createInterface(objServer, boardPath, propName, |
| 167 | boardNameOrig); |
| 168 | |
| 169 | dbus_interface::populateInterfaceFromJson( |
| 170 | io, systemConfiguration, jsonPointerPath + propName, iface, |
| 171 | propValue, objServer); |
| 172 | } |
| 173 | } |
| 174 | |
Alexander Hansen | 4fa4012 | 2025-07-30 18:26:35 +0200 | [diff] [blame] | 175 | nlohmann::json::iterator exposes = boardValues.find("Exposes"); |
Alexander Hansen | 4fcd946 | 2025-07-30 17:44:44 +0200 | [diff] [blame] | 176 | if (exposes == boardValues.end()) |
| 177 | { |
| 178 | return; |
| 179 | } |
| 180 | // iterate through exposes |
| 181 | jsonPointerPath += "Exposes/"; |
| 182 | |
| 183 | // store the board level pointer so we can modify it on the way down |
| 184 | std::string jsonPointerPathBoard = jsonPointerPath; |
| 185 | size_t exposesIndex = -1; |
Alexander Hansen | 4fa4012 | 2025-07-30 18:26:35 +0200 | [diff] [blame] | 186 | for (nlohmann::json& item : *exposes) |
Alexander Hansen | 4fcd946 | 2025-07-30 17:44:44 +0200 | [diff] [blame] | 187 | { |
Alexander Hansen | 4fa4012 | 2025-07-30 18:26:35 +0200 | [diff] [blame] | 188 | postExposesRecordsToDBus(item, exposesIndex, boardNameOrig, |
| 189 | jsonPointerPath, jsonPointerPathBoard, |
| 190 | boardPath, boardType); |
| 191 | } |
Alexander Hansen | 4fcd946 | 2025-07-30 17:44:44 +0200 | [diff] [blame] | 192 | |
Alexander Hansen | 4fa4012 | 2025-07-30 18:26:35 +0200 | [diff] [blame] | 193 | newBoards.emplace(boardPath, boardNameOrig); |
| 194 | } |
| 195 | |
| 196 | void EntityManager::postExposesRecordsToDBus( |
| 197 | nlohmann::json& item, size_t& exposesIndex, |
| 198 | const std::string& boardNameOrig, std::string jsonPointerPath, |
| 199 | const std::string& jsonPointerPathBoard, const std::string& boardPath, |
| 200 | const std::string& boardType) |
| 201 | { |
| 202 | exposesIndex++; |
| 203 | jsonPointerPath = jsonPointerPathBoard; |
| 204 | jsonPointerPath += std::to_string(exposesIndex); |
| 205 | |
| 206 | auto findName = item.find("Name"); |
| 207 | if (findName == item.end()) |
| 208 | { |
| 209 | std::cerr << "cannot find name in field " << item << "\n"; |
| 210 | return; |
| 211 | } |
| 212 | auto findStatus = item.find("Status"); |
| 213 | // if status is not found it is assumed to be status = 'okay' |
| 214 | if (findStatus != item.end()) |
| 215 | { |
| 216 | if (*findStatus == "disabled") |
Alexander Hansen | 4fcd946 | 2025-07-30 17:44:44 +0200 | [diff] [blame] | 217 | { |
Alexander Hansen | 4fa4012 | 2025-07-30 18:26:35 +0200 | [diff] [blame] | 218 | return; |
Alexander Hansen | 4fcd946 | 2025-07-30 17:44:44 +0200 | [diff] [blame] | 219 | } |
Alexander Hansen | 4fa4012 | 2025-07-30 18:26:35 +0200 | [diff] [blame] | 220 | } |
| 221 | auto findType = item.find("Type"); |
| 222 | std::string itemType; |
| 223 | if (findType != item.end()) |
| 224 | { |
| 225 | itemType = findType->get<std::string>(); |
| 226 | std::regex_replace(itemType.begin(), itemType.begin(), itemType.end(), |
| 227 | illegalDbusPathRegex, "_"); |
| 228 | } |
| 229 | else |
| 230 | { |
| 231 | itemType = "unknown"; |
| 232 | } |
| 233 | std::string itemName = findName->get<std::string>(); |
| 234 | std::regex_replace(itemName.begin(), itemName.begin(), itemName.end(), |
| 235 | illegalDbusMemberRegex, "_"); |
| 236 | std::string ifacePath = boardPath; |
| 237 | ifacePath += "/"; |
| 238 | ifacePath += itemName; |
| 239 | |
| 240 | if (itemType == "BMC") |
| 241 | { |
| 242 | std::shared_ptr<sdbusplus::asio::dbus_interface> bmcIface = |
| 243 | dbus_interface.createInterface( |
| 244 | objServer, ifacePath, "xyz.openbmc_project.Inventory.Item.Bmc", |
| 245 | boardNameOrig); |
| 246 | dbus_interface::populateInterfaceFromJson( |
| 247 | io, systemConfiguration, jsonPointerPath, bmcIface, item, objServer, |
| 248 | getPermission(itemType)); |
| 249 | } |
| 250 | else if (itemType == "System") |
| 251 | { |
| 252 | std::shared_ptr<sdbusplus::asio::dbus_interface> systemIface = |
| 253 | dbus_interface.createInterface( |
| 254 | objServer, ifacePath, |
| 255 | "xyz.openbmc_project.Inventory.Item.System", boardNameOrig); |
| 256 | dbus_interface::populateInterfaceFromJson( |
| 257 | io, systemConfiguration, jsonPointerPath, systemIface, item, |
| 258 | objServer, getPermission(itemType)); |
| 259 | } |
| 260 | |
| 261 | for (const auto& [name, config] : item.items()) |
| 262 | { |
| 263 | jsonPointerPath = jsonPointerPathBoard; |
| 264 | jsonPointerPath.append(std::to_string(exposesIndex)) |
| 265 | .append("/") |
| 266 | .append(name); |
| 267 | if (config.type() == nlohmann::json::value_t::object) |
Alexander Hansen | 4fcd946 | 2025-07-30 17:44:44 +0200 | [diff] [blame] | 268 | { |
Alexander Hansen | 4fa4012 | 2025-07-30 18:26:35 +0200 | [diff] [blame] | 269 | std::string ifaceName = "xyz.openbmc_project.Configuration."; |
| 270 | ifaceName.append(itemType).append(".").append(name); |
| 271 | |
| 272 | std::shared_ptr<sdbusplus::asio::dbus_interface> objectIface = |
| 273 | dbus_interface.createInterface(objServer, ifacePath, ifaceName, |
| 274 | boardNameOrig); |
| 275 | |
| 276 | dbus_interface::populateInterfaceFromJson( |
| 277 | io, systemConfiguration, jsonPointerPath, objectIface, config, |
| 278 | objServer, getPermission(name)); |
| 279 | } |
| 280 | else if (config.type() == nlohmann::json::value_t::array) |
| 281 | { |
| 282 | size_t index = 0; |
| 283 | if (config.empty()) |
Alexander Hansen | 4fcd946 | 2025-07-30 17:44:44 +0200 | [diff] [blame] | 284 | { |
| 285 | continue; |
| 286 | } |
Alexander Hansen | 4fa4012 | 2025-07-30 18:26:35 +0200 | [diff] [blame] | 287 | bool isLegal = true; |
| 288 | auto type = config[0].type(); |
| 289 | if (type != nlohmann::json::value_t::object) |
| 290 | { |
| 291 | continue; |
| 292 | } |
Alexander Hansen | 4fcd946 | 2025-07-30 17:44:44 +0200 | [diff] [blame] | 293 | |
Alexander Hansen | 4fa4012 | 2025-07-30 18:26:35 +0200 | [diff] [blame] | 294 | // verify legal json |
| 295 | for (const auto& arrayItem : config) |
| 296 | { |
| 297 | if (arrayItem.type() != type) |
| 298 | { |
| 299 | isLegal = false; |
| 300 | break; |
| 301 | } |
| 302 | } |
| 303 | if (!isLegal) |
| 304 | { |
| 305 | std::cerr << "dbus format error" << config << "\n"; |
| 306 | break; |
| 307 | } |
Alexander Hansen | 4fcd946 | 2025-07-30 17:44:44 +0200 | [diff] [blame] | 308 | |
Alexander Hansen | 4fa4012 | 2025-07-30 18:26:35 +0200 | [diff] [blame] | 309 | for (auto& arrayItem : config) |
Alexander Hansen | 4fcd946 | 2025-07-30 17:44:44 +0200 | [diff] [blame] | 310 | { |
| 311 | std::string ifaceName = "xyz.openbmc_project.Configuration."; |
| 312 | ifaceName.append(itemType).append(".").append(name); |
Alexander Hansen | 4fa4012 | 2025-07-30 18:26:35 +0200 | [diff] [blame] | 313 | ifaceName.append(std::to_string(index)); |
Alexander Hansen | 4fcd946 | 2025-07-30 17:44:44 +0200 | [diff] [blame] | 314 | |
| 315 | std::shared_ptr<sdbusplus::asio::dbus_interface> objectIface = |
| 316 | dbus_interface.createInterface(objServer, ifacePath, |
| 317 | ifaceName, boardNameOrig); |
| 318 | |
| 319 | dbus_interface::populateInterfaceFromJson( |
Alexander Hansen | 4fa4012 | 2025-07-30 18:26:35 +0200 | [diff] [blame] | 320 | io, systemConfiguration, |
| 321 | jsonPointerPath + "/" + std::to_string(index), objectIface, |
| 322 | arrayItem, objServer, getPermission(name)); |
| 323 | index++; |
Alexander Hansen | 4fcd946 | 2025-07-30 17:44:44 +0200 | [diff] [blame] | 324 | } |
| 325 | } |
Alexander Hansen | 4fcd946 | 2025-07-30 17:44:44 +0200 | [diff] [blame] | 326 | } |
| 327 | |
Alexander Hansen | 4fa4012 | 2025-07-30 18:26:35 +0200 | [diff] [blame] | 328 | std::shared_ptr<sdbusplus::asio::dbus_interface> itemIface = |
| 329 | dbus_interface.createInterface( |
| 330 | objServer, ifacePath, |
| 331 | "xyz.openbmc_project.Configuration." + itemType, boardNameOrig); |
| 332 | |
| 333 | dbus_interface::populateInterfaceFromJson( |
| 334 | io, systemConfiguration, jsonPointerPath, itemIface, item, objServer, |
| 335 | getPermission(itemType)); |
| 336 | |
| 337 | topology.addBoard(boardPath, boardType, boardNameOrig, item); |
Alexander Hansen | 4fcd946 | 2025-07-30 17:44:44 +0200 | [diff] [blame] | 338 | } |
| 339 | |
Andrew Jeffery | 5519293 | 2022-03-24 12:29:27 +1030 | [diff] [blame] | 340 | static bool deviceRequiresPowerOn(const nlohmann::json& entity) |
| 341 | { |
| 342 | auto powerState = entity.find("PowerState"); |
Andrew Jeffery | b620944 | 2022-03-24 12:36:20 +1030 | [diff] [blame] | 343 | if (powerState == entity.end()) |
Andrew Jeffery | 5519293 | 2022-03-24 12:29:27 +1030 | [diff] [blame] | 344 | { |
Andrew Jeffery | b620944 | 2022-03-24 12:36:20 +1030 | [diff] [blame] | 345 | return false; |
Andrew Jeffery | 5519293 | 2022-03-24 12:29:27 +1030 | [diff] [blame] | 346 | } |
| 347 | |
Ed Tanous | 3013fb4 | 2022-07-09 08:27:06 -0700 | [diff] [blame] | 348 | const auto* ptr = powerState->get_ptr<const std::string*>(); |
| 349 | if (ptr == nullptr) |
Andrew Jeffery | b620944 | 2022-03-24 12:36:20 +1030 | [diff] [blame] | 350 | { |
| 351 | return false; |
| 352 | } |
| 353 | |
| 354 | return *ptr == "On" || *ptr == "BiosPost"; |
Andrew Jeffery | 5519293 | 2022-03-24 12:29:27 +1030 | [diff] [blame] | 355 | } |
| 356 | |
Andrew Jeffery | 89ec352 | 2022-03-24 13:30:41 +1030 | [diff] [blame] | 357 | static void pruneDevice(const nlohmann::json& systemConfiguration, |
| 358 | const bool powerOff, const bool scannedPowerOff, |
| 359 | const std::string& name, const nlohmann::json& device) |
| 360 | { |
| 361 | if (systemConfiguration.contains(name)) |
| 362 | { |
| 363 | return; |
| 364 | } |
| 365 | |
Andrew Jeffery | 4db38bc | 2022-03-24 13:42:41 +1030 | [diff] [blame] | 366 | if (deviceRequiresPowerOn(device) && (powerOff || scannedPowerOff)) |
Andrew Jeffery | 89ec352 | 2022-03-24 13:30:41 +1030 | [diff] [blame] | 367 | { |
Andrew Jeffery | 89ec352 | 2022-03-24 13:30:41 +1030 | [diff] [blame] | 368 | return; |
| 369 | } |
| 370 | |
| 371 | logDeviceRemoved(device); |
| 372 | } |
| 373 | |
Alexander Hansen | 95ab18f | 2025-06-27 13:58:10 +0200 | [diff] [blame] | 374 | void EntityManager::startRemovedTimer(boost::asio::steady_timer& timer, |
| 375 | nlohmann::json& systemConfiguration) |
James Feist | 1df06a4 | 2019-04-11 14:23:04 -0700 | [diff] [blame] | 376 | { |
James Feist | fb00f39 | 2019-06-25 14:16:48 -0700 | [diff] [blame] | 377 | if (systemConfiguration.empty() || lastJson.empty()) |
| 378 | { |
| 379 | return; // not ready yet |
| 380 | } |
James Feist | 1df06a4 | 2019-04-11 14:23:04 -0700 | [diff] [blame] | 381 | if (scannedPowerOn) |
| 382 | { |
| 383 | return; |
| 384 | } |
| 385 | |
Alexander Hansen | 0ab32b3 | 2025-06-27 14:50:33 +0200 | [diff] [blame] | 386 | if (!powerStatus.isPowerOn() && scannedPowerOff) |
James Feist | 1df06a4 | 2019-04-11 14:23:04 -0700 | [diff] [blame] | 387 | { |
| 388 | return; |
| 389 | } |
| 390 | |
James Feist | b1728ca | 2020-04-30 15:40:55 -0700 | [diff] [blame] | 391 | timer.expires_after(std::chrono::seconds(10)); |
Andrew Jeffery | 27a1cfb | 2022-03-24 12:31:53 +1030 | [diff] [blame] | 392 | timer.async_wait( |
Alexander Hansen | 95ab18f | 2025-06-27 13:58:10 +0200 | [diff] [blame] | 393 | [&systemConfiguration, this](const boost::system::error_code& ec) { |
Patrick Williams | b707743 | 2024-08-16 15:22:21 -0400 | [diff] [blame] | 394 | if (ec == boost::asio::error::operation_aborted) |
| 395 | { |
| 396 | return; |
| 397 | } |
Andrew Jeffery | 27a1cfb | 2022-03-24 12:31:53 +1030 | [diff] [blame] | 398 | |
Alexander Hansen | 0ab32b3 | 2025-06-27 14:50:33 +0200 | [diff] [blame] | 399 | bool powerOff = !powerStatus.isPowerOn(); |
Patrick Williams | b707743 | 2024-08-16 15:22:21 -0400 | [diff] [blame] | 400 | for (const auto& [name, device] : lastJson.items()) |
| 401 | { |
| 402 | pruneDevice(systemConfiguration, powerOff, scannedPowerOff, |
| 403 | name, device); |
| 404 | } |
Andrew Jeffery | 89ec352 | 2022-03-24 13:30:41 +1030 | [diff] [blame] | 405 | |
Patrick Williams | b707743 | 2024-08-16 15:22:21 -0400 | [diff] [blame] | 406 | scannedPowerOff = true; |
| 407 | if (!powerOff) |
| 408 | { |
| 409 | scannedPowerOn = true; |
| 410 | } |
| 411 | }); |
James Feist | 1df06a4 | 2019-04-11 14:23:04 -0700 | [diff] [blame] | 412 | } |
| 413 | |
Christopher Meis | cf6a75b | 2025-06-03 07:53:50 +0200 | [diff] [blame] | 414 | void EntityManager::pruneConfiguration(bool powerOff, const std::string& name, |
| 415 | const nlohmann::json& device) |
Andrew Jeffery | 0d0c146 | 2022-03-24 15:26:39 +1030 | [diff] [blame] | 416 | { |
| 417 | if (powerOff && deviceRequiresPowerOn(device)) |
| 418 | { |
| 419 | // power not on yet, don't know if it's there or not |
| 420 | return; |
| 421 | } |
| 422 | |
Alexander Hansen | 57604ed | 2025-06-27 13:22:28 +0200 | [diff] [blame] | 423 | auto& ifaces = dbus_interface.getDeviceInterfaces(device); |
Andrew Jeffery | 0d0c146 | 2022-03-24 15:26:39 +1030 | [diff] [blame] | 424 | for (auto& iface : ifaces) |
| 425 | { |
| 426 | auto sharedPtr = iface.lock(); |
| 427 | if (!!sharedPtr) |
| 428 | { |
| 429 | objServer.remove_interface(sharedPtr); |
| 430 | } |
| 431 | } |
| 432 | |
| 433 | ifaces.clear(); |
| 434 | systemConfiguration.erase(name); |
Matt Spinler | 6eb6097 | 2023-08-14 16:36:20 -0500 | [diff] [blame] | 435 | topology.remove(device["Name"].get<std::string>()); |
Andrew Jeffery | 0d0c146 | 2022-03-24 15:26:39 +1030 | [diff] [blame] | 436 | logDeviceRemoved(device); |
| 437 | } |
| 438 | |
Christopher Meis | cf6a75b | 2025-06-03 07:53:50 +0200 | [diff] [blame] | 439 | void EntityManager::publishNewConfiguration( |
Andrew Jeffery | e35d0ac | 2022-03-24 15:53:13 +1030 | [diff] [blame] | 440 | const size_t& instance, const size_t count, |
Christopher Meis | cf6a75b | 2025-06-03 07:53:50 +0200 | [diff] [blame] | 441 | boost::asio::steady_timer& timer, // Gerrit discussion: |
Andrew Jeffery | e35d0ac | 2022-03-24 15:53:13 +1030 | [diff] [blame] | 442 | // https://gerrit.openbmc-project.xyz/c/openbmc/entity-manager/+/52316/6 |
| 443 | // |
| 444 | // Discord discussion: |
| 445 | // https://discord.com/channels/775381525260664832/867820390406422538/958048437729910854 |
| 446 | // |
| 447 | // NOLINTNEXTLINE(performance-unnecessary-value-param) |
Christopher Meis | cf6a75b | 2025-06-03 07:53:50 +0200 | [diff] [blame] | 448 | const nlohmann::json newConfiguration) |
Andrew Jeffery | e35d0ac | 2022-03-24 15:53:13 +1030 | [diff] [blame] | 449 | { |
Alexander Hansen | a555acf | 2025-06-27 11:59:10 +0200 | [diff] [blame] | 450 | loadOverlays(newConfiguration, io); |
Andrew Jeffery | e35d0ac | 2022-03-24 15:53:13 +1030 | [diff] [blame] | 451 | |
Christopher Meis | cf6a75b | 2025-06-03 07:53:50 +0200 | [diff] [blame] | 452 | boost::asio::post(io, [this]() { |
Christopher Meis | f725257 | 2025-06-11 13:22:05 +0200 | [diff] [blame] | 453 | if (!writeJsonFiles(systemConfiguration)) |
Andrew Jeffery | e35d0ac | 2022-03-24 15:53:13 +1030 | [diff] [blame] | 454 | { |
| 455 | std::cerr << "Error writing json files\n"; |
| 456 | } |
| 457 | }); |
| 458 | |
Christopher Meis | cf6a75b | 2025-06-03 07:53:50 +0200 | [diff] [blame] | 459 | boost::asio::post(io, [this, &instance, count, &timer, newConfiguration]() { |
| 460 | postToDbus(newConfiguration); |
Andrew Jeffery | e35d0ac | 2022-03-24 15:53:13 +1030 | [diff] [blame] | 461 | if (count == instance) |
| 462 | { |
Alexander Hansen | 95ab18f | 2025-06-27 13:58:10 +0200 | [diff] [blame] | 463 | startRemovedTimer(timer, systemConfiguration); |
Andrew Jeffery | e35d0ac | 2022-03-24 15:53:13 +1030 | [diff] [blame] | 464 | } |
| 465 | }); |
| 466 | } |
| 467 | |
James Feist | 8f2710a | 2018-05-09 17:18:55 -0700 | [diff] [blame] | 468 | // main properties changed entry |
Christopher Meis | cf6a75b | 2025-06-03 07:53:50 +0200 | [diff] [blame] | 469 | void EntityManager::propertiesChangedCallback() |
James Feist | 8f2710a | 2018-05-09 17:18:55 -0700 | [diff] [blame] | 470 | { |
Alexander Hansen | fc1b1e2 | 2025-06-27 14:34:11 +0200 | [diff] [blame] | 471 | propertiesChangedInstance++; |
| 472 | size_t count = propertiesChangedInstance; |
James Feist | 1df06a4 | 2019-04-11 14:23:04 -0700 | [diff] [blame] | 473 | |
Alexander Hansen | b1340da | 2025-06-27 14:29:13 +0200 | [diff] [blame] | 474 | propertiesChangedTimer.expires_after(std::chrono::milliseconds(500)); |
James Feist | 8f2710a | 2018-05-09 17:18:55 -0700 | [diff] [blame] | 475 | |
| 476 | // setup an async wait as we normally get flooded with new requests |
Alexander Hansen | b1340da | 2025-06-27 14:29:13 +0200 | [diff] [blame] | 477 | propertiesChangedTimer.async_wait( |
| 478 | [this, count](const boost::system::error_code& ec) { |
| 479 | if (ec == boost::asio::error::operation_aborted) |
| 480 | { |
| 481 | // we were cancelled |
| 482 | return; |
| 483 | } |
| 484 | if (ec) |
| 485 | { |
| 486 | std::cerr << "async wait error " << ec << "\n"; |
| 487 | return; |
| 488 | } |
James Feist | 8f2710a | 2018-05-09 17:18:55 -0700 | [diff] [blame] | 489 | |
Alexander Hansen | b1340da | 2025-06-27 14:29:13 +0200 | [diff] [blame] | 490 | if (propertiesChangedInProgress) |
| 491 | { |
| 492 | propertiesChangedCallback(); |
| 493 | return; |
| 494 | } |
| 495 | propertiesChangedInProgress = true; |
James Feist | 2539ccd | 2020-05-01 16:15:08 -0700 | [diff] [blame] | 496 | |
Alexander Hansen | b1340da | 2025-06-27 14:29:13 +0200 | [diff] [blame] | 497 | nlohmann::json oldConfiguration = systemConfiguration; |
| 498 | auto missingConfigurations = std::make_shared<nlohmann::json>(); |
| 499 | *missingConfigurations = systemConfiguration; |
James Feist | 899e17f | 2019-09-13 11:46:29 -0700 | [diff] [blame] | 500 | |
Alexander Hansen | b1340da | 2025-06-27 14:29:13 +0200 | [diff] [blame] | 501 | auto perfScan = std::make_shared<scan::PerformScan>( |
Christopher Meis | f725257 | 2025-06-11 13:22:05 +0200 | [diff] [blame] | 502 | *this, *missingConfigurations, configuration.configurations, io, |
Alexander Hansen | b1340da | 2025-06-27 14:29:13 +0200 | [diff] [blame] | 503 | [this, count, oldConfiguration, missingConfigurations]() { |
| 504 | // this is something that since ac has been applied to the |
| 505 | // bmc we saw, and we no longer see it |
Alexander Hansen | 0ab32b3 | 2025-06-27 14:50:33 +0200 | [diff] [blame] | 506 | bool powerOff = !powerStatus.isPowerOn(); |
Alexander Hansen | b1340da | 2025-06-27 14:29:13 +0200 | [diff] [blame] | 507 | for (const auto& [name, device] : |
| 508 | missingConfigurations->items()) |
| 509 | { |
| 510 | pruneConfiguration(powerOff, name, device); |
| 511 | } |
Alexander Hansen | b1340da | 2025-06-27 14:29:13 +0200 | [diff] [blame] | 512 | nlohmann::json newConfiguration = systemConfiguration; |
| 513 | |
Christopher Meis | f725257 | 2025-06-11 13:22:05 +0200 | [diff] [blame] | 514 | deriveNewConfiguration(oldConfiguration, newConfiguration); |
Alexander Hansen | b1340da | 2025-06-27 14:29:13 +0200 | [diff] [blame] | 515 | |
| 516 | for (const auto& [_, device] : newConfiguration.items()) |
| 517 | { |
| 518 | logDeviceAdded(device); |
| 519 | } |
| 520 | |
| 521 | propertiesChangedInProgress = false; |
| 522 | |
| 523 | boost::asio::post(io, [this, newConfiguration, count] { |
| 524 | publishNewConfiguration( |
Alexander Hansen | fc1b1e2 | 2025-06-27 14:34:11 +0200 | [diff] [blame] | 525 | std::ref(propertiesChangedInstance), count, |
Alexander Hansen | b1340da | 2025-06-27 14:29:13 +0200 | [diff] [blame] | 526 | std::ref(propertiesChangedTimer), newConfiguration); |
| 527 | }); |
Christopher Meis | cf6a75b | 2025-06-03 07:53:50 +0200 | [diff] [blame] | 528 | }); |
Alexander Hansen | b1340da | 2025-06-27 14:29:13 +0200 | [diff] [blame] | 529 | perfScan->run(); |
| 530 | }); |
James Feist | 75fdeeb | 2018-02-20 14:26:16 -0800 | [diff] [blame] | 531 | } |
| 532 | |
Matt Spinler | 8d1ac3a | 2023-02-02 09:48:04 -0600 | [diff] [blame] | 533 | // Check if InterfacesAdded payload contains an iface that needs probing. |
Patrick Williams | b707743 | 2024-08-16 15:22:21 -0400 | [diff] [blame] | 534 | static bool iaContainsProbeInterface( |
Christopher Meis | f725257 | 2025-06-11 13:22:05 +0200 | [diff] [blame] | 535 | sdbusplus::message_t& msg, |
| 536 | const std::unordered_set<std::string>& probeInterfaces) |
Matt Spinler | 8d1ac3a | 2023-02-02 09:48:04 -0600 | [diff] [blame] | 537 | { |
| 538 | sdbusplus::message::object_path path; |
| 539 | DBusObject interfaces; |
| 540 | std::set<std::string> interfaceSet; |
| 541 | std::set<std::string> intersect; |
| 542 | |
| 543 | msg.read(path, interfaces); |
| 544 | |
| 545 | std::for_each(interfaces.begin(), interfaces.end(), |
| 546 | [&interfaceSet](const auto& iface) { |
Patrick Williams | b707743 | 2024-08-16 15:22:21 -0400 | [diff] [blame] | 547 | interfaceSet.insert(iface.first); |
| 548 | }); |
Matt Spinler | 8d1ac3a | 2023-02-02 09:48:04 -0600 | [diff] [blame] | 549 | |
| 550 | std::set_intersection(interfaceSet.begin(), interfaceSet.end(), |
| 551 | probeInterfaces.begin(), probeInterfaces.end(), |
| 552 | std::inserter(intersect, intersect.end())); |
| 553 | return !intersect.empty(); |
| 554 | } |
| 555 | |
| 556 | // Check if InterfacesRemoved payload contains an iface that needs probing. |
Patrick Williams | b707743 | 2024-08-16 15:22:21 -0400 | [diff] [blame] | 557 | static bool irContainsProbeInterface( |
Christopher Meis | f725257 | 2025-06-11 13:22:05 +0200 | [diff] [blame] | 558 | sdbusplus::message_t& msg, |
| 559 | const std::unordered_set<std::string>& probeInterfaces) |
Matt Spinler | 8d1ac3a | 2023-02-02 09:48:04 -0600 | [diff] [blame] | 560 | { |
| 561 | sdbusplus::message::object_path path; |
| 562 | std::set<std::string> interfaces; |
| 563 | std::set<std::string> intersect; |
| 564 | |
| 565 | msg.read(path, interfaces); |
| 566 | |
| 567 | std::set_intersection(interfaces.begin(), interfaces.end(), |
| 568 | probeInterfaces.begin(), probeInterfaces.end(), |
| 569 | std::inserter(intersect, intersect.end())); |
| 570 | return !intersect.empty(); |
| 571 | } |
| 572 | |
Alexander Hansen | ad28e40 | 2025-06-25 12:38:20 +0200 | [diff] [blame] | 573 | void EntityManager::handleCurrentConfigurationJson() |
| 574 | { |
| 575 | if (em_utils::fwVersionIsSame()) |
| 576 | { |
Christopher Meis | f725257 | 2025-06-11 13:22:05 +0200 | [diff] [blame] | 577 | if (std::filesystem::is_regular_file(currentConfiguration)) |
Alexander Hansen | ad28e40 | 2025-06-25 12:38:20 +0200 | [diff] [blame] | 578 | { |
| 579 | // this file could just be deleted, but it's nice for debug |
| 580 | std::filesystem::create_directory(tempConfigDir); |
| 581 | std::filesystem::remove(lastConfiguration); |
Christopher Meis | f725257 | 2025-06-11 13:22:05 +0200 | [diff] [blame] | 582 | std::filesystem::copy(currentConfiguration, lastConfiguration); |
| 583 | std::filesystem::remove(currentConfiguration); |
Alexander Hansen | ad28e40 | 2025-06-25 12:38:20 +0200 | [diff] [blame] | 584 | |
| 585 | std::ifstream jsonStream(lastConfiguration); |
| 586 | if (jsonStream.good()) |
| 587 | { |
| 588 | auto data = nlohmann::json::parse(jsonStream, nullptr, false); |
| 589 | if (data.is_discarded()) |
| 590 | { |
| 591 | std::cerr |
| 592 | << "syntax error in " << lastConfiguration << "\n"; |
| 593 | } |
| 594 | else |
| 595 | { |
| 596 | lastJson = std::move(data); |
| 597 | } |
| 598 | } |
| 599 | else |
| 600 | { |
| 601 | std::cerr << "unable to open " << lastConfiguration << "\n"; |
| 602 | } |
| 603 | } |
| 604 | } |
| 605 | else |
| 606 | { |
| 607 | // not an error, just logging at this level to make it in the journal |
| 608 | std::cerr << "Clearing previous configuration\n"; |
Christopher Meis | f725257 | 2025-06-11 13:22:05 +0200 | [diff] [blame] | 609 | std::filesystem::remove(currentConfiguration); |
Alexander Hansen | ad28e40 | 2025-06-25 12:38:20 +0200 | [diff] [blame] | 610 | } |
| 611 | } |
| 612 | |
Christopher Meis | cf6a75b | 2025-06-03 07:53:50 +0200 | [diff] [blame] | 613 | void EntityManager::registerCallback(const std::string& path) |
James Feist | 75fdeeb | 2018-02-20 14:26:16 -0800 | [diff] [blame] | 614 | { |
Christopher Meis | cf6a75b | 2025-06-03 07:53:50 +0200 | [diff] [blame] | 615 | if (dbusMatches.contains(path)) |
| 616 | { |
| 617 | return; |
| 618 | } |
Nan Zhou | a331567 | 2022-09-20 19:48:14 +0000 | [diff] [blame] | 619 | |
Alexander Hansen | 6080318 | 2025-06-27 14:41:28 +0200 | [diff] [blame] | 620 | lg2::debug("creating PropertiesChanged match on {PATH}", "PATH", path); |
| 621 | |
Christopher Meis | cf6a75b | 2025-06-03 07:53:50 +0200 | [diff] [blame] | 622 | std::function<void(sdbusplus::message_t & message)> eventHandler = |
| 623 | [&](sdbusplus::message_t&) { propertiesChangedCallback(); }; |
James Feist | fd1264a | 2018-05-03 12:10:00 -0700 | [diff] [blame] | 624 | |
Christopher Meis | cf6a75b | 2025-06-03 07:53:50 +0200 | [diff] [blame] | 625 | sdbusplus::bus::match_t match( |
| 626 | static_cast<sdbusplus::bus_t&>(*systemBus), |
| 627 | "type='signal',member='PropertiesChanged',path='" + path + "'", |
| 628 | eventHandler); |
| 629 | dbusMatches.emplace(path, std::move(match)); |
| 630 | } |
James Feist | fd1264a | 2018-05-03 12:10:00 -0700 | [diff] [blame] | 631 | |
Christopher Meis | cf6a75b | 2025-06-03 07:53:50 +0200 | [diff] [blame] | 632 | // We need a poke from DBus for static providers that create all their |
| 633 | // objects prior to claiming a well-known name, and thus don't emit any |
| 634 | // org.freedesktop.DBus.Properties signals. Similarly if a process exits |
| 635 | // for any reason, expected or otherwise, we'll need a poke to remove |
| 636 | // entities from DBus. |
Christopher Meis | f725257 | 2025-06-11 13:22:05 +0200 | [diff] [blame] | 637 | void EntityManager::initFilters( |
| 638 | const std::unordered_set<std::string>& probeInterfaces) |
Christopher Meis | cf6a75b | 2025-06-03 07:53:50 +0200 | [diff] [blame] | 639 | { |
Alexander Hansen | 0f7bd78 | 2025-06-27 13:39:53 +0200 | [diff] [blame] | 640 | nameOwnerChangedMatch = std::make_unique<sdbusplus::bus::match_t>( |
Patrick Williams | 2af3922 | 2022-07-22 19:26:56 -0500 | [diff] [blame] | 641 | static_cast<sdbusplus::bus_t&>(*systemBus), |
Brad Bishop | c76af0f | 2020-12-04 13:50:23 -0500 | [diff] [blame] | 642 | sdbusplus::bus::match::rules::nameOwnerChanged(), |
Christopher Meis | cf6a75b | 2025-06-03 07:53:50 +0200 | [diff] [blame] | 643 | [this](sdbusplus::message_t& m) { |
Patrick Williams | b707743 | 2024-08-16 15:22:21 -0400 | [diff] [blame] | 644 | auto [name, oldOwner, |
| 645 | newOwner] = m.unpack<std::string, std::string, std::string>(); |
Patrick Williams | 7b8786f | 2022-10-10 10:23:37 -0500 | [diff] [blame] | 646 | |
Patrick Williams | b707743 | 2024-08-16 15:22:21 -0400 | [diff] [blame] | 647 | if (name.starts_with(':')) |
| 648 | { |
| 649 | // We should do nothing with unique-name connections. |
| 650 | return; |
| 651 | } |
Patrick Williams | 7b8786f | 2022-10-10 10:23:37 -0500 | [diff] [blame] | 652 | |
Christopher Meis | cf6a75b | 2025-06-03 07:53:50 +0200 | [diff] [blame] | 653 | propertiesChangedCallback(); |
Patrick Williams | b707743 | 2024-08-16 15:22:21 -0400 | [diff] [blame] | 654 | }); |
Christopher Meis | cf6a75b | 2025-06-03 07:53:50 +0200 | [diff] [blame] | 655 | |
Brad Bishop | 10a8c5f | 2020-12-07 21:40:07 -0500 | [diff] [blame] | 656 | // We also need a poke from DBus when new interfaces are created or |
| 657 | // destroyed. |
Alexander Hansen | 0f7bd78 | 2025-06-27 13:39:53 +0200 | [diff] [blame] | 658 | interfacesAddedMatch = std::make_unique<sdbusplus::bus::match_t>( |
Patrick Williams | 2af3922 | 2022-07-22 19:26:56 -0500 | [diff] [blame] | 659 | static_cast<sdbusplus::bus_t&>(*systemBus), |
Brad Bishop | 10a8c5f | 2020-12-07 21:40:07 -0500 | [diff] [blame] | 660 | sdbusplus::bus::match::rules::interfacesAdded(), |
Christopher Meis | cf6a75b | 2025-06-03 07:53:50 +0200 | [diff] [blame] | 661 | [this, probeInterfaces](sdbusplus::message_t& msg) { |
Patrick Williams | b707743 | 2024-08-16 15:22:21 -0400 | [diff] [blame] | 662 | if (iaContainsProbeInterface(msg, probeInterfaces)) |
| 663 | { |
Christopher Meis | cf6a75b | 2025-06-03 07:53:50 +0200 | [diff] [blame] | 664 | propertiesChangedCallback(); |
Patrick Williams | b707743 | 2024-08-16 15:22:21 -0400 | [diff] [blame] | 665 | } |
| 666 | }); |
Christopher Meis | cf6a75b | 2025-06-03 07:53:50 +0200 | [diff] [blame] | 667 | |
Alexander Hansen | 0f7bd78 | 2025-06-27 13:39:53 +0200 | [diff] [blame] | 668 | interfacesRemovedMatch = std::make_unique<sdbusplus::bus::match_t>( |
Patrick Williams | 2af3922 | 2022-07-22 19:26:56 -0500 | [diff] [blame] | 669 | static_cast<sdbusplus::bus_t&>(*systemBus), |
Brad Bishop | 10a8c5f | 2020-12-07 21:40:07 -0500 | [diff] [blame] | 670 | sdbusplus::bus::match::rules::interfacesRemoved(), |
Christopher Meis | cf6a75b | 2025-06-03 07:53:50 +0200 | [diff] [blame] | 671 | [this, probeInterfaces](sdbusplus::message_t& msg) { |
Patrick Williams | b707743 | 2024-08-16 15:22:21 -0400 | [diff] [blame] | 672 | if (irContainsProbeInterface(msg, probeInterfaces)) |
| 673 | { |
Christopher Meis | cf6a75b | 2025-06-03 07:53:50 +0200 | [diff] [blame] | 674 | propertiesChangedCallback(); |
Patrick Williams | b707743 | 2024-08-16 15:22:21 -0400 | [diff] [blame] | 675 | } |
| 676 | }); |
Christopher Meis | cf6a75b | 2025-06-03 07:53:50 +0200 | [diff] [blame] | 677 | } |