Andrew Geissler | a80a3af | 2019-02-04 14:01:49 -0600 | [diff] [blame] | 1 | #include "associations.hpp" |
Willy Tu | aba14d3 | 2023-01-31 14:19:59 -0800 | [diff] [blame] | 2 | #include "handler.hpp" |
Andrew Geissler | 3b025e6 | 2019-02-01 10:33:54 -0600 | [diff] [blame] | 3 | #include "processing.hpp" |
Matt Spinler | 35396c1 | 2019-04-05 11:46:57 -0500 | [diff] [blame] | 4 | #include "types.hpp" |
Matt Spinler | dd94586 | 2018-09-07 12:41:05 -0500 | [diff] [blame] | 5 | |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 6 | #include <tinyxml2.h> |
| 7 | |
Ed Tanous | 21c6059 | 2020-08-17 23:43:46 -0700 | [diff] [blame] | 8 | #include <boost/asio/io_context.hpp> |
| 9 | #include <boost/asio/signal_set.hpp> |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 10 | #include <boost/container/flat_map.hpp> |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 11 | #include <sdbusplus/asio/connection.hpp> |
| 12 | #include <sdbusplus/asio/object_server.hpp> |
Konstantin Aladyshev | b15df6b | 2022-01-11 14:50:55 +0300 | [diff] [blame] | 13 | #include <xyz/openbmc_project/Common/error.hpp> |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 14 | |
Brad Bishop | 2352088 | 2022-05-26 21:39:53 -0400 | [diff] [blame] | 15 | #include <atomic> |
| 16 | #include <chrono> |
Brad Bishop | ea11946 | 2022-05-31 20:32:04 -0400 | [diff] [blame] | 17 | #include <exception> |
Brad Bishop | 2352088 | 2022-05-26 21:39:53 -0400 | [diff] [blame] | 18 | #include <iomanip> |
| 19 | #include <iostream> |
Brandon Kim | f6ebfc7 | 2022-07-07 12:53:44 -0700 | [diff] [blame] | 20 | #include <string> |
| 21 | #include <string_view> |
Brad Bishop | 1f62380 | 2022-05-31 18:22:10 -0400 | [diff] [blame] | 22 | #include <utility> |
Brad Bishop | 2352088 | 2022-05-26 21:39:53 -0400 | [diff] [blame] | 23 | |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame] | 24 | AssociationMaps associationMaps; |
Matt Spinler | 937a232 | 2019-01-23 13:54:22 -0600 | [diff] [blame] | 25 | |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 26 | void updateOwners(sdbusplus::asio::connection* conn, |
| 27 | boost::container::flat_map<std::string, std::string>& owners, |
| 28 | const std::string& newObject) |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 29 | { |
Brad Bishop | 86d2880 | 2022-07-11 15:49:31 -0400 | [diff] [blame] | 30 | if (newObject.starts_with(":")) |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 31 | { |
| 32 | return; |
| 33 | } |
| 34 | conn->async_method_call( |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 35 | [&, newObject](const boost::system::error_code ec, |
| 36 | const std::string& nameOwner) { |
Patrick Williams | 9052ebd | 2024-08-16 15:22:16 -0400 | [diff] [blame] | 37 | if (ec) |
| 38 | { |
| 39 | std::cerr << "Error getting owner of " << newObject << " : " |
| 40 | << ec << "\n"; |
| 41 | return; |
| 42 | } |
| 43 | owners[nameOwner] = newObject; |
| 44 | }, |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 45 | "org.freedesktop.DBus", "/", "org.freedesktop.DBus", "GetNameOwner", |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 46 | newObject); |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 47 | } |
| 48 | |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 49 | void sendIntrospectionCompleteSignal(sdbusplus::asio::connection* systemBus, |
| 50 | const std::string& processName) |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 51 | { |
| 52 | // TODO(ed) This signal doesn't get exposed properly in the |
| 53 | // introspect right now. Find out how to register signals in |
| 54 | // sdbusplus |
Patrick Williams | cc8070b | 2022-07-22 19:26:55 -0500 | [diff] [blame] | 55 | sdbusplus::message_t m = systemBus->new_signal( |
Brad Bishop | a02cd54 | 2021-10-12 19:12:42 -0400 | [diff] [blame] | 56 | "/xyz/openbmc_project/object_mapper", |
| 57 | "xyz.openbmc_project.ObjectMapper.Private", "IntrospectionComplete"); |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 58 | m.append(processName); |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 59 | m.signal_send(); |
| 60 | } |
| 61 | |
| 62 | struct InProgressIntrospect |
| 63 | { |
Brad Bishop | 1f62380 | 2022-05-31 18:22:10 -0400 | [diff] [blame] | 64 | InProgressIntrospect() = delete; |
| 65 | InProgressIntrospect(const InProgressIntrospect&) = delete; |
| 66 | InProgressIntrospect(InProgressIntrospect&&) = delete; |
| 67 | InProgressIntrospect& operator=(const InProgressIntrospect&) = delete; |
| 68 | InProgressIntrospect& operator=(InProgressIntrospect&&) = delete; |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 69 | InProgressIntrospect( |
Brad Bishop | 11c0cc3 | 2025-07-08 16:04:25 -0400 | [diff] [blame] | 70 | sdbusplus::asio::connection* systemBusConnection, |
| 71 | boost::asio::io_context& ioContext, |
| 72 | const std::string& introspectProcessName, AssociationMaps& am |
Brad Bishop | d6aa552 | 2022-05-31 19:23:48 -0400 | [diff] [blame] | 73 | #ifdef MAPPER_ENABLE_DEBUG |
Matt Spinler | aecabe8 | 2018-09-19 13:25:42 -0500 | [diff] [blame] | 74 | , |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 75 | std::shared_ptr<std::chrono::time_point<std::chrono::steady_clock>> |
Brad Bishop | 11c0cc3 | 2025-07-08 16:04:25 -0400 | [diff] [blame] | 76 | globalIntrospectStartTime |
Matt Spinler | aecabe8 | 2018-09-19 13:25:42 -0500 | [diff] [blame] | 77 | #endif |
| 78 | ) : |
Brad Bishop | 11c0cc3 | 2025-07-08 16:04:25 -0400 | [diff] [blame] | 79 | systemBus(systemBusConnection), io(ioContext), |
| 80 | processName(introspectProcessName), assocMaps(am) |
Brad Bishop | d6aa552 | 2022-05-31 19:23:48 -0400 | [diff] [blame] | 81 | #ifdef MAPPER_ENABLE_DEBUG |
Matt Spinler | aecabe8 | 2018-09-19 13:25:42 -0500 | [diff] [blame] | 82 | , |
Brad Bishop | 11c0cc3 | 2025-07-08 16:04:25 -0400 | [diff] [blame] | 83 | globalStartTime(std::move(globalIntrospectStartTime)), |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 84 | processStartTime(std::chrono::steady_clock::now()) |
Matt Spinler | aecabe8 | 2018-09-19 13:25:42 -0500 | [diff] [blame] | 85 | #endif |
Brad Bishop | 2352088 | 2022-05-26 21:39:53 -0400 | [diff] [blame] | 86 | {} |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 87 | ~InProgressIntrospect() |
| 88 | { |
Brad Bishop | ea11946 | 2022-05-31 20:32:04 -0400 | [diff] [blame] | 89 | try |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 90 | { |
Brad Bishop | ea11946 | 2022-05-31 20:32:04 -0400 | [diff] [blame] | 91 | sendIntrospectionCompleteSignal(systemBus, processName); |
Brad Bishop | d6aa552 | 2022-05-31 19:23:48 -0400 | [diff] [blame] | 92 | #ifdef MAPPER_ENABLE_DEBUG |
Brad Bishop | ea11946 | 2022-05-31 20:32:04 -0400 | [diff] [blame] | 93 | std::chrono::duration<float> diff = |
| 94 | std::chrono::steady_clock::now() - processStartTime; |
| 95 | std::cout << std::setw(50) << processName << " scan took " |
| 96 | << diff.count() << " seconds\n"; |
| 97 | |
| 98 | // If we're the last outstanding caller globally, calculate the |
| 99 | // time it took |
| 100 | if (globalStartTime != nullptr && globalStartTime.use_count() == 1) |
| 101 | { |
| 102 | diff = std::chrono::steady_clock::now() - *globalStartTime; |
| 103 | std::cout << "Total scan took " << diff.count() |
| 104 | << " seconds to complete\n"; |
| 105 | } |
Matt Spinler | aecabe8 | 2018-09-19 13:25:42 -0500 | [diff] [blame] | 106 | #endif |
Brad Bishop | ea11946 | 2022-05-31 20:32:04 -0400 | [diff] [blame] | 107 | } |
| 108 | catch (const std::exception& e) |
| 109 | { |
| 110 | std::cerr |
| 111 | << "Terminating, unhandled exception while introspecting: " |
| 112 | << e.what() << "\n"; |
| 113 | std::terminate(); |
| 114 | } |
| 115 | catch (...) |
| 116 | { |
| 117 | std::cerr |
| 118 | << "Terminating, unhandled exception while introspecting\n"; |
| 119 | std::terminate(); |
| 120 | } |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 121 | } |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 122 | sdbusplus::asio::connection* systemBus; |
Ed Tanous | 21c6059 | 2020-08-17 23:43:46 -0700 | [diff] [blame] | 123 | boost::asio::io_context& io; |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 124 | std::string processName; |
Matt Spinler | 11401e2 | 2019-04-08 13:13:25 -0500 | [diff] [blame] | 125 | AssociationMaps& assocMaps; |
Brad Bishop | d6aa552 | 2022-05-31 19:23:48 -0400 | [diff] [blame] | 126 | #ifdef MAPPER_ENABLE_DEBUG |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 127 | std::shared_ptr<std::chrono::time_point<std::chrono::steady_clock>> |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 128 | globalStartTime; |
| 129 | std::chrono::time_point<std::chrono::steady_clock> processStartTime; |
Matt Spinler | aecabe8 | 2018-09-19 13:25:42 -0500 | [diff] [blame] | 130 | #endif |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 131 | }; |
| 132 | |
Kallas, Pawel | 5b4357d | 2022-10-12 15:36:37 +0200 | [diff] [blame] | 133 | void doAssociations(boost::asio::io_context& io, |
| 134 | sdbusplus::asio::connection* systemBus, |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 135 | InterfaceMapType& interfaceMap, |
| 136 | sdbusplus::asio::object_server& objectServer, |
| 137 | const std::string& processName, const std::string& path, |
| 138 | int timeoutRetries = 0) |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 139 | { |
Adrian Ambrożewicz | bb40bd3 | 2021-02-12 13:36:26 +0100 | [diff] [blame] | 140 | constexpr int maxTimeoutRetries = 3; |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 141 | systemBus->async_method_call( |
Kallas, Pawel | 5b4357d | 2022-10-12 15:36:37 +0200 | [diff] [blame] | 142 | [&io, &objectServer, path, processName, &interfaceMap, systemBus, |
Adrian Ambrożewicz | bb40bd3 | 2021-02-12 13:36:26 +0100 | [diff] [blame] | 143 | timeoutRetries]( |
Matt Spinler | 937a232 | 2019-01-23 13:54:22 -0600 | [diff] [blame] | 144 | const boost::system::error_code ec, |
Patrick Williams | 2bb2d6b | 2020-05-13 17:59:02 -0500 | [diff] [blame] | 145 | const std::variant<std::vector<Association>>& variantAssociations) { |
Patrick Williams | 9052ebd | 2024-08-16 15:22:16 -0400 | [diff] [blame] | 146 | if (ec) |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 147 | { |
Patrick Williams | 9052ebd | 2024-08-16 15:22:16 -0400 | [diff] [blame] | 148 | if (ec.value() == boost::system::errc::timed_out && |
| 149 | timeoutRetries < maxTimeoutRetries) |
| 150 | { |
| 151 | doAssociations(io, systemBus, interfaceMap, objectServer, |
| 152 | processName, path, timeoutRetries + 1); |
| 153 | return; |
| 154 | } |
| 155 | std::cerr << "Error getting associations from " << path << "\n"; |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 156 | } |
Patrick Williams | 9052ebd | 2024-08-16 15:22:16 -0400 | [diff] [blame] | 157 | std::vector<Association> associations = |
| 158 | std::get<std::vector<Association>>(variantAssociations); |
| 159 | associationChanged(io, objectServer, associations, path, |
| 160 | processName, interfaceMap, associationMaps); |
| 161 | }, |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 162 | processName, path, "org.freedesktop.DBus.Properties", "Get", |
John Wang | d0cf942 | 2019-09-17 16:01:34 +0800 | [diff] [blame] | 163 | assocDefsInterface, assocDefsProperty); |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 164 | } |
| 165 | |
Kallas, Pawel | 5b4357d | 2022-10-12 15:36:37 +0200 | [diff] [blame] | 166 | void doIntrospect(boost::asio::io_context& io, |
| 167 | sdbusplus::asio::connection* systemBus, |
Brad Bishop | 1f62380 | 2022-05-31 18:22:10 -0400 | [diff] [blame] | 168 | const std::shared_ptr<InProgressIntrospect>& transaction, |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 169 | InterfaceMapType& interfaceMap, |
| 170 | sdbusplus::asio::object_server& objectServer, |
Brad Bishop | 1f62380 | 2022-05-31 18:22:10 -0400 | [diff] [blame] | 171 | const std::string& path, int timeoutRetries = 0) |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 172 | { |
Vernon Mauery | c52be0d | 2020-01-14 11:14:25 -0800 | [diff] [blame] | 173 | constexpr int maxTimeoutRetries = 3; |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 174 | systemBus->async_method_call( |
Kallas, Pawel | 5b4357d | 2022-10-12 15:36:37 +0200 | [diff] [blame] | 175 | [&io, &interfaceMap, &objectServer, transaction, path, systemBus, |
Vernon Mauery | c52be0d | 2020-01-14 11:14:25 -0800 | [diff] [blame] | 176 | timeoutRetries](const boost::system::error_code ec, |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 177 | const std::string& introspectXml) { |
Patrick Williams | 9052ebd | 2024-08-16 15:22:16 -0400 | [diff] [blame] | 178 | if (ec) |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 179 | { |
Patrick Williams | 9052ebd | 2024-08-16 15:22:16 -0400 | [diff] [blame] | 180 | if (ec.value() == boost::system::errc::timed_out && |
| 181 | timeoutRetries < maxTimeoutRetries) |
| 182 | { |
| 183 | doIntrospect(io, systemBus, transaction, interfaceMap, |
| 184 | objectServer, path, timeoutRetries + 1); |
| 185 | return; |
| 186 | } |
| 187 | std::cerr << "Introspect call failed with error: " << ec << ", " |
| 188 | << ec.message() |
| 189 | << " on process: " << transaction->processName |
| 190 | << " path: " << path << "\n"; |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 191 | return; |
| 192 | } |
| 193 | |
Patrick Williams | 9052ebd | 2024-08-16 15:22:16 -0400 | [diff] [blame] | 194 | tinyxml2::XMLDocument doc; |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 195 | |
Patrick Williams | 9052ebd | 2024-08-16 15:22:16 -0400 | [diff] [blame] | 196 | tinyxml2::XMLError e = doc.Parse(introspectXml.c_str()); |
| 197 | if (e != tinyxml2::XMLError::XML_SUCCESS) |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 198 | { |
Patrick Williams | 9052ebd | 2024-08-16 15:22:16 -0400 | [diff] [blame] | 199 | std::cerr << "XML parsing failed\n"; |
| 200 | return; |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 201 | } |
| 202 | |
Patrick Williams | 9052ebd | 2024-08-16 15:22:16 -0400 | [diff] [blame] | 203 | tinyxml2::XMLNode* pRoot = doc.FirstChildElement("node"); |
| 204 | if (pRoot == nullptr) |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 205 | { |
Patrick Williams | 9052ebd | 2024-08-16 15:22:16 -0400 | [diff] [blame] | 206 | std::cerr << "XML document did not contain any data\n"; |
| 207 | return; |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 208 | } |
Patrick Williams | 9052ebd | 2024-08-16 15:22:16 -0400 | [diff] [blame] | 209 | auto& thisPathMap = interfaceMap[path]; |
| 210 | tinyxml2::XMLElement* pElement = |
| 211 | pRoot->FirstChildElement("interface"); |
| 212 | while (pElement != nullptr) |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 213 | { |
Patrick Williams | 9052ebd | 2024-08-16 15:22:16 -0400 | [diff] [blame] | 214 | const char* ifaceName = pElement->Attribute("name"); |
| 215 | if (ifaceName == nullptr) |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 216 | { |
Patrick Williams | 9052ebd | 2024-08-16 15:22:16 -0400 | [diff] [blame] | 217 | continue; |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 218 | } |
| 219 | |
Patrick Williams | 9052ebd | 2024-08-16 15:22:16 -0400 | [diff] [blame] | 220 | thisPathMap[transaction->processName].emplace(ifaceName); |
| 221 | |
| 222 | if (std::strcmp(ifaceName, assocDefsInterface) == 0) |
| 223 | { |
| 224 | doAssociations(io, systemBus, interfaceMap, objectServer, |
| 225 | transaction->processName, path); |
| 226 | } |
| 227 | |
| 228 | pElement = pElement->NextSiblingElement("interface"); |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 229 | } |
Patrick Williams | 9052ebd | 2024-08-16 15:22:16 -0400 | [diff] [blame] | 230 | |
| 231 | // Check if this new path has a pending association that can |
| 232 | // now be completed. |
| 233 | checkIfPendingAssociation(io, path, interfaceMap, |
| 234 | transaction->assocMaps, objectServer); |
| 235 | |
| 236 | pElement = pRoot->FirstChildElement("node"); |
| 237 | while (pElement != nullptr) |
| 238 | { |
| 239 | const char* childPath = pElement->Attribute("name"); |
| 240 | if (childPath != nullptr) |
| 241 | { |
| 242 | std::string parentPath(path); |
| 243 | if (parentPath == "/") |
| 244 | { |
| 245 | parentPath.clear(); |
| 246 | } |
| 247 | |
| 248 | doIntrospect(io, systemBus, transaction, interfaceMap, |
| 249 | objectServer, parentPath + "/" + childPath); |
| 250 | } |
| 251 | pElement = pElement->NextSiblingElement("node"); |
| 252 | } |
| 253 | }, |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 254 | transaction->processName, path, "org.freedesktop.DBus.Introspectable", |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 255 | "Introspect"); |
| 256 | } |
| 257 | |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 258 | void startNewIntrospect( |
| 259 | sdbusplus::asio::connection* systemBus, boost::asio::io_context& io, |
| 260 | InterfaceMapType& interfaceMap, const std::string& processName, |
Matt Spinler | 11401e2 | 2019-04-08 13:13:25 -0500 | [diff] [blame] | 261 | AssociationMaps& assocMaps, |
Brad Bishop | d6aa552 | 2022-05-31 19:23:48 -0400 | [diff] [blame] | 262 | #ifdef MAPPER_ENABLE_DEBUG |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 263 | std::shared_ptr<std::chrono::time_point<std::chrono::steady_clock>> |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 264 | globalStartTime, |
Matt Spinler | aecabe8 | 2018-09-19 13:25:42 -0500 | [diff] [blame] | 265 | #endif |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 266 | sdbusplus::asio::object_server& objectServer) |
| 267 | { |
Brad Bishop | 1e94e60 | 2022-06-02 19:47:53 -0400 | [diff] [blame] | 268 | if (needToIntrospect(processName)) |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 269 | { |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 270 | std::shared_ptr<InProgressIntrospect> transaction = |
Patrick Williams | 9052ebd | 2024-08-16 15:22:16 -0400 | [diff] [blame] | 271 | std::make_shared<InProgressIntrospect>( |
| 272 | systemBus, io, processName, assocMaps |
Brad Bishop | d6aa552 | 2022-05-31 19:23:48 -0400 | [diff] [blame] | 273 | #ifdef MAPPER_ENABLE_DEBUG |
Patrick Williams | 9052ebd | 2024-08-16 15:22:16 -0400 | [diff] [blame] | 274 | , |
| 275 | globalStartTime |
Matt Spinler | aecabe8 | 2018-09-19 13:25:42 -0500 | [diff] [blame] | 276 | #endif |
| 277 | ); |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 278 | |
Kallas, Pawel | 5b4357d | 2022-10-12 15:36:37 +0200 | [diff] [blame] | 279 | doIntrospect(io, systemBus, transaction, interfaceMap, objectServer, |
| 280 | "/"); |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 281 | } |
| 282 | } |
| 283 | |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 284 | void doListNames( |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 285 | boost::asio::io_context& io, InterfaceMapType& interfaceMap, |
| 286 | sdbusplus::asio::connection* systemBus, |
| 287 | boost::container::flat_map<std::string, std::string>& nameOwners, |
Matt Spinler | 11401e2 | 2019-04-08 13:13:25 -0500 | [diff] [blame] | 288 | AssociationMaps& assocMaps, sdbusplus::asio::object_server& objectServer) |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 289 | { |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 290 | systemBus->async_method_call( |
| 291 | [&io, &interfaceMap, &nameOwners, &objectServer, systemBus, |
Matt Spinler | 11401e2 | 2019-04-08 13:13:25 -0500 | [diff] [blame] | 292 | &assocMaps](const boost::system::error_code ec, |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 293 | std::vector<std::string> processNames) { |
Patrick Williams | 9052ebd | 2024-08-16 15:22:16 -0400 | [diff] [blame] | 294 | if (ec) |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 295 | { |
Patrick Williams | 9052ebd | 2024-08-16 15:22:16 -0400 | [diff] [blame] | 296 | std::cerr << "Error getting names: " << ec << "\n"; |
| 297 | std::exit(EXIT_FAILURE); |
| 298 | return; |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 299 | } |
Patrick Williams | 9052ebd | 2024-08-16 15:22:16 -0400 | [diff] [blame] | 300 | // Try to make startup consistent |
| 301 | std::sort(processNames.begin(), processNames.end()); |
| 302 | #ifdef MAPPER_ENABLE_DEBUG |
| 303 | std::shared_ptr<std::chrono::time_point<std::chrono::steady_clock>> |
| 304 | globalStartTime = std::make_shared< |
| 305 | std::chrono::time_point<std::chrono::steady_clock>>( |
| 306 | std::chrono::steady_clock::now()); |
| 307 | #endif |
| 308 | for (const std::string& processName : processNames) |
| 309 | { |
| 310 | if (needToIntrospect(processName)) |
| 311 | { |
| 312 | startNewIntrospect(systemBus, io, interfaceMap, processName, |
| 313 | assocMaps, |
| 314 | #ifdef MAPPER_ENABLE_DEBUG |
| 315 | globalStartTime, |
| 316 | #endif |
| 317 | objectServer); |
| 318 | updateOwners(systemBus, nameOwners, processName); |
| 319 | } |
| 320 | } |
| 321 | }, |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 322 | "org.freedesktop.DBus", "/org/freedesktop/DBus", "org.freedesktop.DBus", |
| 323 | "ListNames"); |
| 324 | } |
| 325 | |
Matt Spinler | a82779f | 2019-01-09 12:39:42 -0600 | [diff] [blame] | 326 | // Remove parents of the passed in path that: |
| 327 | // 1) Only have the 3 default interfaces on them |
| 328 | // - Means D-Bus created these, not application code, |
| 329 | // with the Properties, Introspectable, and Peer ifaces |
| 330 | // 2) Have no other child for this owner |
| 331 | void removeUnneededParents(const std::string& objectPath, |
| 332 | const std::string& owner, |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 333 | InterfaceMapType& interfaceMap) |
Matt Spinler | a82779f | 2019-01-09 12:39:42 -0600 | [diff] [blame] | 334 | { |
| 335 | auto parent = objectPath; |
| 336 | |
| 337 | while (true) |
| 338 | { |
| 339 | auto pos = parent.find_last_of('/'); |
| 340 | if ((pos == std::string::npos) || (pos == 0)) |
| 341 | { |
| 342 | break; |
| 343 | } |
| 344 | parent = parent.substr(0, pos); |
| 345 | |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 346 | auto parentIt = interfaceMap.find(parent); |
| 347 | if (parentIt == interfaceMap.end()) |
Matt Spinler | a82779f | 2019-01-09 12:39:42 -0600 | [diff] [blame] | 348 | { |
| 349 | break; |
| 350 | } |
| 351 | |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 352 | auto ifacesIt = parentIt->second.find(owner); |
| 353 | if (ifacesIt == parentIt->second.end()) |
Matt Spinler | a82779f | 2019-01-09 12:39:42 -0600 | [diff] [blame] | 354 | { |
| 355 | break; |
| 356 | } |
| 357 | |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 358 | if (ifacesIt->second.size() != 3) |
Matt Spinler | a82779f | 2019-01-09 12:39:42 -0600 | [diff] [blame] | 359 | { |
| 360 | break; |
| 361 | } |
| 362 | |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 363 | auto childPath = parent + '/'; |
Matt Spinler | a82779f | 2019-01-09 12:39:42 -0600 | [diff] [blame] | 364 | |
| 365 | // Remove this parent if there isn't a remaining child on this owner |
Patrick Williams | 9052ebd | 2024-08-16 15:22:16 -0400 | [diff] [blame] | 366 | auto child = std::find_if( |
| 367 | interfaceMap.begin(), interfaceMap.end(), |
| 368 | [&owner, &childPath](const auto& entry) { |
| 369 | return entry.first.starts_with(childPath) && |
| 370 | (entry.second.find(owner) != entry.second.end()); |
| 371 | }); |
Matt Spinler | a82779f | 2019-01-09 12:39:42 -0600 | [diff] [blame] | 372 | |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 373 | if (child == interfaceMap.end()) |
Matt Spinler | a82779f | 2019-01-09 12:39:42 -0600 | [diff] [blame] | 374 | { |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 375 | parentIt->second.erase(ifacesIt); |
| 376 | if (parentIt->second.empty()) |
Matt Spinler | a82779f | 2019-01-09 12:39:42 -0600 | [diff] [blame] | 377 | { |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 378 | interfaceMap.erase(parentIt); |
Matt Spinler | a82779f | 2019-01-09 12:39:42 -0600 | [diff] [blame] | 379 | } |
| 380 | } |
| 381 | else |
| 382 | { |
| 383 | break; |
| 384 | } |
| 385 | } |
| 386 | } |
| 387 | |
Brad Bishop | 1e94e60 | 2022-06-02 19:47:53 -0400 | [diff] [blame] | 388 | int main() |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 389 | { |
Ed Tanous | 21c6059 | 2020-08-17 23:43:46 -0700 | [diff] [blame] | 390 | boost::asio::io_context io; |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 391 | std::shared_ptr<sdbusplus::asio::connection> systemBus = |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 392 | std::make_shared<sdbusplus::asio::connection>(io); |
| 393 | |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 394 | sdbusplus::asio::object_server server(systemBus); |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 395 | |
| 396 | // Construct a signal set registered for process termination. |
| 397 | boost::asio::signal_set signals(io, SIGINT, SIGTERM); |
Patrick Williams | 9052ebd | 2024-08-16 15:22:16 -0400 | [diff] [blame] | 398 | signals.async_wait([&io](const boost::system::error_code&, int) { |
| 399 | io.stop(); |
| 400 | }); |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 401 | |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 402 | InterfaceMapType interfaceMap; |
| 403 | boost::container::flat_map<std::string, std::string> nameOwners; |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 404 | |
William A. Kennington III | 60ffc24 | 2022-12-02 19:36:01 -0800 | [diff] [blame] | 405 | auto nameChangeHandler = [&interfaceMap, &io, &nameOwners, &server, |
| 406 | systemBus](sdbusplus::message_t& message) { |
| 407 | std::string name; // well-known |
| 408 | std::string oldOwner; // unique-name |
| 409 | std::string newOwner; // unique-name |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 410 | |
William A. Kennington III | 60ffc24 | 2022-12-02 19:36:01 -0800 | [diff] [blame] | 411 | message.read(name, oldOwner, newOwner); |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 412 | |
William A. Kennington III | 60ffc24 | 2022-12-02 19:36:01 -0800 | [diff] [blame] | 413 | if (name.starts_with(':')) |
| 414 | { |
| 415 | // We should do nothing with unique-name connections. |
| 416 | return; |
| 417 | } |
Patrick Williams | 4824820 | 2022-10-10 10:26:47 -0500 | [diff] [blame] | 418 | |
William A. Kennington III | 60ffc24 | 2022-12-02 19:36:01 -0800 | [diff] [blame] | 419 | if (!oldOwner.empty()) |
| 420 | { |
| 421 | processNameChangeDelete(io, nameOwners, name, oldOwner, |
| 422 | interfaceMap, associationMaps, server); |
| 423 | } |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 424 | |
William A. Kennington III | 60ffc24 | 2022-12-02 19:36:01 -0800 | [diff] [blame] | 425 | if (!newOwner.empty()) |
| 426 | { |
Brad Bishop | d6aa552 | 2022-05-31 19:23:48 -0400 | [diff] [blame] | 427 | #ifdef MAPPER_ENABLE_DEBUG |
William A. Kennington III | 60ffc24 | 2022-12-02 19:36:01 -0800 | [diff] [blame] | 428 | auto transaction = std::make_shared< |
| 429 | std::chrono::time_point<std::chrono::steady_clock>>( |
| 430 | std::chrono::steady_clock::now()); |
Matt Spinler | aecabe8 | 2018-09-19 13:25:42 -0500 | [diff] [blame] | 431 | #endif |
William A. Kennington III | 60ffc24 | 2022-12-02 19:36:01 -0800 | [diff] [blame] | 432 | // New daemon added |
| 433 | if (needToIntrospect(name)) |
| 434 | { |
| 435 | nameOwners[newOwner] = name; |
| 436 | startNewIntrospect(systemBus.get(), io, interfaceMap, name, |
| 437 | associationMaps, |
Brad Bishop | d6aa552 | 2022-05-31 19:23:48 -0400 | [diff] [blame] | 438 | #ifdef MAPPER_ENABLE_DEBUG |
William A. Kennington III | 60ffc24 | 2022-12-02 19:36:01 -0800 | [diff] [blame] | 439 | transaction, |
Matt Spinler | aecabe8 | 2018-09-19 13:25:42 -0500 | [diff] [blame] | 440 | #endif |
William A. Kennington III | 60ffc24 | 2022-12-02 19:36:01 -0800 | [diff] [blame] | 441 | server); |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 442 | } |
William A. Kennington III | 60ffc24 | 2022-12-02 19:36:01 -0800 | [diff] [blame] | 443 | } |
| 444 | }; |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 445 | |
Patrick Williams | cc8070b | 2022-07-22 19:26:55 -0500 | [diff] [blame] | 446 | sdbusplus::bus::match_t nameOwnerChanged( |
| 447 | static_cast<sdbusplus::bus_t&>(*systemBus), |
William A. Kennington III | 60ffc24 | 2022-12-02 19:36:01 -0800 | [diff] [blame] | 448 | sdbusplus::bus::match::rules::nameOwnerChanged(), |
| 449 | std::move(nameChangeHandler)); |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 450 | |
William A. Kennington III | 60ffc24 | 2022-12-02 19:36:01 -0800 | [diff] [blame] | 451 | auto interfacesAddedHandler = [&io, &interfaceMap, &nameOwners, |
| 452 | &server](sdbusplus::message_t& message) { |
| 453 | sdbusplus::message::object_path objPath; |
| 454 | InterfacesAdded interfacesAdded; |
| 455 | message.read(objPath, interfacesAdded); |
| 456 | std::string wellKnown; |
| 457 | if (!getWellKnown(nameOwners, message.get_sender(), wellKnown)) |
| 458 | { |
| 459 | return; // only introspect well-known |
| 460 | } |
| 461 | if (needToIntrospect(wellKnown)) |
| 462 | { |
| 463 | processInterfaceAdded(io, interfaceMap, objPath, interfacesAdded, |
| 464 | wellKnown, associationMaps, server); |
| 465 | } |
| 466 | }; |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 467 | |
Patrick Williams | cc8070b | 2022-07-22 19:26:55 -0500 | [diff] [blame] | 468 | sdbusplus::bus::match_t interfacesAdded( |
| 469 | static_cast<sdbusplus::bus_t&>(*systemBus), |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 470 | sdbusplus::bus::match::rules::interfacesAdded(), |
William A. Kennington III | 60ffc24 | 2022-12-02 19:36:01 -0800 | [diff] [blame] | 471 | std::move(interfacesAddedHandler)); |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 472 | |
William A. Kennington III | 60ffc24 | 2022-12-02 19:36:01 -0800 | [diff] [blame] | 473 | auto interfacesRemovedHandler = [&io, &interfaceMap, &nameOwners, |
| 474 | &server](sdbusplus::message_t& message) { |
| 475 | sdbusplus::message::object_path objPath; |
| 476 | std::vector<std::string> interfacesRemoved; |
| 477 | message.read(objPath, interfacesRemoved); |
| 478 | auto connectionMap = interfaceMap.find(objPath.str); |
| 479 | if (connectionMap == interfaceMap.end()) |
| 480 | { |
| 481 | return; |
| 482 | } |
| 483 | |
| 484 | std::string sender; |
| 485 | if (!getWellKnown(nameOwners, message.get_sender(), sender)) |
| 486 | { |
| 487 | return; |
| 488 | } |
| 489 | for (const std::string& interface : interfacesRemoved) |
| 490 | { |
| 491 | auto interfaceSet = connectionMap->second.find(sender); |
| 492 | if (interfaceSet == connectionMap->second.end()) |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 493 | { |
William A. Kennington III | 60ffc24 | 2022-12-02 19:36:01 -0800 | [diff] [blame] | 494 | continue; |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 495 | } |
| 496 | |
William A. Kennington III | 60ffc24 | 2022-12-02 19:36:01 -0800 | [diff] [blame] | 497 | if (interface == assocDefsInterface) |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 498 | { |
William A. Kennington III | 60ffc24 | 2022-12-02 19:36:01 -0800 | [diff] [blame] | 499 | removeAssociation(io, objPath.str, sender, server, |
| 500 | associationMaps); |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 501 | } |
William A. Kennington III | 60ffc24 | 2022-12-02 19:36:01 -0800 | [diff] [blame] | 502 | |
| 503 | interfaceSet->second.erase(interface); |
| 504 | |
| 505 | if (interfaceSet->second.empty()) |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 506 | { |
William A. Kennington III | 60ffc24 | 2022-12-02 19:36:01 -0800 | [diff] [blame] | 507 | // If this was the last interface on this connection, |
| 508 | // erase the connection |
| 509 | connectionMap->second.erase(interfaceSet); |
| 510 | |
| 511 | // Instead of checking if every single path is the endpoint |
| 512 | // of an association that needs to be moved to pending, |
| 513 | // only check when the only remaining owner of this path is |
| 514 | // ourself, which would be because we still own the |
| 515 | // association path. |
| 516 | if ((connectionMap->second.size() == 1) && |
| 517 | (connectionMap->second.begin()->first == |
| 518 | "xyz.openbmc_project.ObjectMapper")) |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 519 | { |
William A. Kennington III | 60ffc24 | 2022-12-02 19:36:01 -0800 | [diff] [blame] | 520 | // Remove the 2 association D-Bus paths and move the |
| 521 | // association to pending. |
| 522 | moveAssociationToPending(io, objPath.str, associationMaps, |
| 523 | server); |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 524 | } |
| 525 | } |
William A. Kennington III | 60ffc24 | 2022-12-02 19:36:01 -0800 | [diff] [blame] | 526 | } |
| 527 | // If this was the last connection on this object path, |
| 528 | // erase the object path |
| 529 | if (connectionMap->second.empty()) |
| 530 | { |
| 531 | interfaceMap.erase(connectionMap); |
| 532 | } |
Matt Spinler | a82779f | 2019-01-09 12:39:42 -0600 | [diff] [blame] | 533 | |
William A. Kennington III | 60ffc24 | 2022-12-02 19:36:01 -0800 | [diff] [blame] | 534 | removeUnneededParents(objPath.str, sender, interfaceMap); |
| 535 | }; |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 536 | |
Patrick Williams | cc8070b | 2022-07-22 19:26:55 -0500 | [diff] [blame] | 537 | sdbusplus::bus::match_t interfacesRemoved( |
| 538 | static_cast<sdbusplus::bus_t&>(*systemBus), |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 539 | sdbusplus::bus::match::rules::interfacesRemoved(), |
William A. Kennington III | 60ffc24 | 2022-12-02 19:36:01 -0800 | [diff] [blame] | 540 | std::move(interfacesRemovedHandler)); |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 541 | |
William A. Kennington III | 60ffc24 | 2022-12-02 19:36:01 -0800 | [diff] [blame] | 542 | auto associationChangedHandler = [&io, &server, &nameOwners, &interfaceMap]( |
| 543 | sdbusplus::message_t& message) { |
| 544 | std::string objectName; |
| 545 | boost::container::flat_map<std::string, |
| 546 | std::variant<std::vector<Association>>> |
| 547 | values; |
| 548 | message.read(objectName, values); |
| 549 | auto prop = values.find(assocDefsProperty); |
| 550 | if (prop != values.end()) |
| 551 | { |
| 552 | std::vector<Association> associations = |
| 553 | std::get<std::vector<Association>>(prop->second); |
| 554 | |
| 555 | std::string wellKnown; |
| 556 | if (!getWellKnown(nameOwners, message.get_sender(), wellKnown)) |
Matt Spinler | 8f876a5 | 2019-04-15 13:22:50 -0500 | [diff] [blame] | 557 | { |
William A. Kennington III | 60ffc24 | 2022-12-02 19:36:01 -0800 | [diff] [blame] | 558 | return; |
Matt Spinler | 8f876a5 | 2019-04-15 13:22:50 -0500 | [diff] [blame] | 559 | } |
William A. Kennington III | 60ffc24 | 2022-12-02 19:36:01 -0800 | [diff] [blame] | 560 | associationChanged(io, server, associations, message.get_path(), |
| 561 | wellKnown, interfaceMap, associationMaps); |
| 562 | } |
| 563 | }; |
Patrick Williams | cc8070b | 2022-07-22 19:26:55 -0500 | [diff] [blame] | 564 | sdbusplus::bus::match_t assocChangedMatch( |
| 565 | static_cast<sdbusplus::bus_t&>(*systemBus), |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 566 | sdbusplus::bus::match::rules::interface( |
| 567 | "org.freedesktop.DBus.Properties") + |
| 568 | sdbusplus::bus::match::rules::member("PropertiesChanged") + |
Matt Spinler | 8f876a5 | 2019-04-15 13:22:50 -0500 | [diff] [blame] | 569 | sdbusplus::bus::match::rules::argN(0, assocDefsInterface), |
William A. Kennington III | 60ffc24 | 2022-12-02 19:36:01 -0800 | [diff] [blame] | 570 | std::move(associationChangedHandler)); |
Matt Spinler | 8f876a5 | 2019-04-15 13:22:50 -0500 | [diff] [blame] | 571 | |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 572 | std::shared_ptr<sdbusplus::asio::dbus_interface> iface = |
Brad Bishop | a02cd54 | 2021-10-12 19:12:42 -0400 | [diff] [blame] | 573 | server.add_interface("/xyz/openbmc_project/object_mapper", |
| 574 | "xyz.openbmc_project.ObjectMapper"); |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 575 | |
| 576 | iface->register_method( |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 577 | "GetAncestors", [&interfaceMap](std::string& reqPath, |
| 578 | std::vector<std::string>& interfaces) { |
Patrick Williams | 9052ebd | 2024-08-16 15:22:16 -0400 | [diff] [blame] | 579 | return getAncestors(interfaceMap, reqPath, interfaces); |
| 580 | }); |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 581 | |
| 582 | iface->register_method( |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 583 | "GetObject", [&interfaceMap](const std::string& path, |
| 584 | std::vector<std::string>& interfaces) { |
Patrick Williams | 9052ebd | 2024-08-16 15:22:16 -0400 | [diff] [blame] | 585 | return getObject(interfaceMap, path, interfaces); |
| 586 | }); |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 587 | |
| 588 | iface->register_method( |
| 589 | "GetSubTree", [&interfaceMap](std::string& reqPath, int32_t depth, |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 590 | std::vector<std::string>& interfaces) { |
Patrick Williams | 9052ebd | 2024-08-16 15:22:16 -0400 | [diff] [blame] | 591 | return getSubTree(interfaceMap, reqPath, depth, interfaces); |
| 592 | }); |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 593 | |
| 594 | iface->register_method( |
| 595 | "GetSubTreePaths", |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 596 | [&interfaceMap](std::string& reqPath, int32_t depth, |
| 597 | std::vector<std::string>& interfaces) { |
Patrick Williams | 9052ebd | 2024-08-16 15:22:16 -0400 | [diff] [blame] | 598 | return getSubTreePaths(interfaceMap, reqPath, depth, interfaces); |
| 599 | }); |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 600 | |
Willy Tu | 58881d0 | 2022-10-02 20:46:45 +0000 | [diff] [blame] | 601 | iface->register_method( |
| 602 | "GetAssociatedSubTree", |
| 603 | [&interfaceMap](const sdbusplus::message::object_path& associationPath, |
| 604 | const sdbusplus::message::object_path& reqPath, |
| 605 | int32_t depth, std::vector<std::string>& interfaces) { |
Patrick Williams | 9052ebd | 2024-08-16 15:22:16 -0400 | [diff] [blame] | 606 | return getAssociatedSubTree(interfaceMap, associationMaps, |
| 607 | associationPath, reqPath, depth, |
| 608 | interfaces); |
| 609 | }); |
Willy Tu | 58881d0 | 2022-10-02 20:46:45 +0000 | [diff] [blame] | 610 | |
| 611 | iface->register_method( |
| 612 | "GetAssociatedSubTreePaths", |
| 613 | [&interfaceMap](const sdbusplus::message::object_path& associationPath, |
| 614 | const sdbusplus::message::object_path& reqPath, |
| 615 | int32_t depth, std::vector<std::string>& interfaces) { |
Patrick Williams | 9052ebd | 2024-08-16 15:22:16 -0400 | [diff] [blame] | 616 | return getAssociatedSubTreePaths(interfaceMap, associationMaps, |
| 617 | associationPath, reqPath, depth, |
| 618 | interfaces); |
| 619 | }); |
Willy Tu | 58881d0 | 2022-10-02 20:46:45 +0000 | [diff] [blame] | 620 | |
Lakshmi Yadlapati | c363323 | 2024-04-09 10:47:29 -0500 | [diff] [blame] | 621 | iface->register_method( |
| 622 | "GetAssociatedSubTreeById", |
| 623 | [&interfaceMap](const std::string& id, const std::string& objectPath, |
| 624 | std::vector<std::string>& subtreeInterfaces, |
| 625 | const std::string& association, |
| 626 | std::vector<std::string>& endpointInterfaces) { |
| 627 | return getAssociatedSubTreeById(interfaceMap, associationMaps, id, |
| 628 | objectPath, subtreeInterfaces, |
| 629 | association, endpointInterfaces); |
| 630 | }); |
| 631 | |
| 632 | iface->register_method( |
| 633 | "GetAssociatedSubTreePathsById", |
| 634 | [&interfaceMap](const std::string& id, const std::string& objectPath, |
| 635 | std::vector<std::string>& subtreeInterfaces, |
| 636 | const std::string& association, |
| 637 | std::vector<std::string>& endpointInterfaces) { |
| 638 | return getAssociatedSubTreePathsById( |
| 639 | interfaceMap, associationMaps, id, objectPath, |
| 640 | subtreeInterfaces, association, endpointInterfaces); |
| 641 | }); |
| 642 | |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 643 | iface->initialize(); |
| 644 | |
Ed Tanous | 41ad838 | 2025-02-13 17:00:14 -0800 | [diff] [blame] | 645 | boost::asio::post(io, [&]() { |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 646 | doListNames(io, interfaceMap, systemBus.get(), nameOwners, |
Matt Spinler | 11401e2 | 2019-04-08 13:13:25 -0500 | [diff] [blame] | 647 | associationMaps, server); |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 648 | }); |
| 649 | |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 650 | systemBus->request_name("xyz.openbmc_project.ObjectMapper"); |
Vishwanatha Subbanna | 64354ef | 2020-08-21 03:35:26 -0500 | [diff] [blame] | 651 | |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 652 | io.run(); |
| 653 | } |