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