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