Andrew Geissler | a80a3af | 2019-02-04 14:01:49 -0600 | [diff] [blame] | 1 | #include "associations.hpp" |
Andrew Geissler | 3b025e6 | 2019-02-01 10:33:54 -0600 | [diff] [blame] | 2 | #include "processing.hpp" |
Matt Spinler | dd94586 | 2018-09-07 12:41:05 -0500 | [diff] [blame] | 3 | #include "src/argument.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 | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 8 | #include <boost/algorithm/string/predicate.hpp> |
Ed Tanous | 21c6059 | 2020-08-17 23:43:46 -0700 | [diff] [blame] | 9 | #include <boost/asio/io_context.hpp> |
| 10 | #include <boost/asio/signal_set.hpp> |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 11 | #include <boost/container/flat_map.hpp> |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 12 | #include <sdbusplus/asio/connection.hpp> |
| 13 | #include <sdbusplus/asio/object_server.hpp> |
Konstantin Aladyshev | b15df6b | 2022-01-11 14:50:55 +0300 | [diff] [blame] | 14 | #include <xyz/openbmc_project/Common/error.hpp> |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 15 | |
Brad Bishop | 2352088 | 2022-05-26 21:39:53 -0400 | [diff] [blame] | 16 | #include <atomic> |
| 17 | #include <chrono> |
Brad Bishop | ea11946 | 2022-05-31 20:32:04 -0400 | [diff] [blame] | 18 | #include <exception> |
Brad Bishop | 2352088 | 2022-05-26 21:39:53 -0400 | [diff] [blame] | 19 | #include <iomanip> |
| 20 | #include <iostream> |
Brad Bishop | 1f62380 | 2022-05-31 18:22:10 -0400 | [diff] [blame] | 21 | #include <utility> |
Brad Bishop | 2352088 | 2022-05-26 21:39:53 -0400 | [diff] [blame] | 22 | |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame] | 23 | AssociationMaps associationMaps; |
Matt Spinler | 937a232 | 2019-01-23 13:54:22 -0600 | [diff] [blame] | 24 | |
Brad Bishop | f944a45 | 2022-05-05 15:06:46 -0400 | [diff] [blame] | 25 | static AllowDenyList serviceAllowList; |
Matt Spinler | dd94586 | 2018-09-07 12:41:05 -0500 | [diff] [blame] | 26 | |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 27 | void updateOwners(sdbusplus::asio::connection* conn, |
| 28 | boost::container::flat_map<std::string, std::string>& owners, |
| 29 | const std::string& newObject) |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 30 | { |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 31 | if (boost::starts_with(newObject, ":")) |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 32 | { |
| 33 | return; |
| 34 | } |
| 35 | conn->async_method_call( |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 36 | [&, newObject](const boost::system::error_code ec, |
| 37 | const std::string& nameOwner) { |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 38 | if (ec) |
| 39 | { |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 40 | std::cerr << "Error getting owner of " << newObject << " : " |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 41 | << ec << "\n"; |
| 42 | return; |
| 43 | } |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 44 | owners[nameOwner] = newObject; |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 45 | }, |
| 46 | "org.freedesktop.DBus", "/", "org.freedesktop.DBus", "GetNameOwner", |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 47 | newObject); |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 48 | } |
| 49 | |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 50 | void sendIntrospectionCompleteSignal(sdbusplus::asio::connection* systemBus, |
| 51 | const std::string& processName) |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 52 | { |
| 53 | // TODO(ed) This signal doesn't get exposed properly in the |
| 54 | // introspect right now. Find out how to register signals in |
| 55 | // sdbusplus |
Patrick Williams | cc8070b | 2022-07-22 19:26:55 -0500 | [diff] [blame^] | 56 | sdbusplus::message_t m = systemBus->new_signal( |
Brad Bishop | a02cd54 | 2021-10-12 19:12:42 -0400 | [diff] [blame] | 57 | "/xyz/openbmc_project/object_mapper", |
| 58 | "xyz.openbmc_project.ObjectMapper.Private", "IntrospectionComplete"); |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 59 | m.append(processName); |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 60 | m.signal_send(); |
| 61 | } |
| 62 | |
| 63 | struct InProgressIntrospect |
| 64 | { |
Brad Bishop | 1f62380 | 2022-05-31 18:22:10 -0400 | [diff] [blame] | 65 | InProgressIntrospect() = delete; |
| 66 | InProgressIntrospect(const InProgressIntrospect&) = delete; |
| 67 | InProgressIntrospect(InProgressIntrospect&&) = delete; |
| 68 | InProgressIntrospect& operator=(const InProgressIntrospect&) = delete; |
| 69 | InProgressIntrospect& operator=(InProgressIntrospect&&) = delete; |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 70 | InProgressIntrospect( |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 71 | sdbusplus::asio::connection* systemBus, boost::asio::io_context& io, |
| 72 | const std::string& processName, 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 | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 76 | globalStartTime |
Matt Spinler | aecabe8 | 2018-09-19 13:25:42 -0500 | [diff] [blame] | 77 | #endif |
| 78 | ) : |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 79 | systemBus(systemBus), |
| 80 | io(io), processName(processName), 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 | 1f62380 | 2022-05-31 18:22:10 -0400 | [diff] [blame] | 83 | globalStartTime(std::move(globalStartTime)), |
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 | |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 133 | void doAssociations(sdbusplus::asio::connection* systemBus, |
| 134 | InterfaceMapType& interfaceMap, |
| 135 | sdbusplus::asio::object_server& objectServer, |
| 136 | const std::string& processName, const std::string& path, |
| 137 | int timeoutRetries = 0) |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 138 | { |
Adrian Ambrożewicz | bb40bd3 | 2021-02-12 13:36:26 +0100 | [diff] [blame] | 139 | constexpr int maxTimeoutRetries = 3; |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 140 | systemBus->async_method_call( |
| 141 | [&objectServer, path, processName, &interfaceMap, systemBus, |
Adrian Ambrożewicz | bb40bd3 | 2021-02-12 13:36:26 +0100 | [diff] [blame] | 142 | timeoutRetries]( |
Matt Spinler | 937a232 | 2019-01-23 13:54:22 -0600 | [diff] [blame] | 143 | const boost::system::error_code ec, |
Patrick Williams | 2bb2d6b | 2020-05-13 17:59:02 -0500 | [diff] [blame] | 144 | const std::variant<std::vector<Association>>& variantAssociations) { |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 145 | if (ec) |
| 146 | { |
Adrian Ambrożewicz | bb40bd3 | 2021-02-12 13:36:26 +0100 | [diff] [blame] | 147 | if (ec.value() == boost::system::errc::timed_out && |
| 148 | timeoutRetries < maxTimeoutRetries) |
| 149 | { |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 150 | doAssociations(systemBus, interfaceMap, objectServer, |
| 151 | processName, path, timeoutRetries + 1); |
Adrian Ambrożewicz | bb40bd3 | 2021-02-12 13:36:26 +0100 | [diff] [blame] | 152 | return; |
| 153 | } |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 154 | std::cerr << "Error getting associations from " << path << "\n"; |
| 155 | } |
| 156 | std::vector<Association> associations = |
Patrick Williams | b05bc12 | 2020-05-13 12:21:00 -0500 | [diff] [blame] | 157 | std::get<std::vector<Association>>(variantAssociations); |
Andrew Geissler | 4511b33 | 2019-02-21 15:40:40 -0600 | [diff] [blame] | 158 | associationChanged(objectServer, associations, path, processName, |
Matt Spinler | e0b0e3a | 2019-04-08 10:39:23 -0500 | [diff] [blame] | 159 | interfaceMap, associationMaps); |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 160 | }, |
| 161 | processName, path, "org.freedesktop.DBus.Properties", "Get", |
John Wang | d0cf942 | 2019-09-17 16:01:34 +0800 | [diff] [blame] | 162 | assocDefsInterface, assocDefsProperty); |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 163 | } |
| 164 | |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 165 | void doIntrospect(sdbusplus::asio::connection* systemBus, |
Brad Bishop | 1f62380 | 2022-05-31 18:22:10 -0400 | [diff] [blame] | 166 | const std::shared_ptr<InProgressIntrospect>& transaction, |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 167 | InterfaceMapType& interfaceMap, |
| 168 | sdbusplus::asio::object_server& objectServer, |
Brad Bishop | 1f62380 | 2022-05-31 18:22:10 -0400 | [diff] [blame] | 169 | const std::string& path, int timeoutRetries = 0) |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 170 | { |
Vernon Mauery | c52be0d | 2020-01-14 11:14:25 -0800 | [diff] [blame] | 171 | constexpr int maxTimeoutRetries = 3; |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 172 | systemBus->async_method_call( |
| 173 | [&interfaceMap, &objectServer, transaction, path, systemBus, |
Vernon Mauery | c52be0d | 2020-01-14 11:14:25 -0800 | [diff] [blame] | 174 | timeoutRetries](const boost::system::error_code ec, |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 175 | const std::string& introspectXml) { |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 176 | if (ec) |
| 177 | { |
Vernon Mauery | c52be0d | 2020-01-14 11:14:25 -0800 | [diff] [blame] | 178 | if (ec.value() == boost::system::errc::timed_out && |
| 179 | timeoutRetries < maxTimeoutRetries) |
| 180 | { |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 181 | doIntrospect(systemBus, transaction, interfaceMap, |
| 182 | objectServer, path, timeoutRetries + 1); |
Vernon Mauery | c52be0d | 2020-01-14 11:14:25 -0800 | [diff] [blame] | 183 | return; |
| 184 | } |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 185 | std::cerr << "Introspect call failed with error: " << ec << ", " |
| 186 | << ec.message() |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 187 | << " on process: " << transaction->processName |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 188 | << " path: " << path << "\n"; |
| 189 | return; |
| 190 | } |
| 191 | |
| 192 | tinyxml2::XMLDocument doc; |
| 193 | |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 194 | tinyxml2::XMLError e = doc.Parse(introspectXml.c_str()); |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 195 | if (e != tinyxml2::XMLError::XML_SUCCESS) |
| 196 | { |
| 197 | std::cerr << "XML parsing failed\n"; |
| 198 | return; |
| 199 | } |
| 200 | |
| 201 | tinyxml2::XMLNode* pRoot = doc.FirstChildElement("node"); |
| 202 | if (pRoot == nullptr) |
| 203 | { |
| 204 | std::cerr << "XML document did not contain any data\n"; |
| 205 | return; |
| 206 | } |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 207 | auto& thisPathMap = interfaceMap[path]; |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 208 | tinyxml2::XMLElement* pElement = |
| 209 | pRoot->FirstChildElement("interface"); |
| 210 | while (pElement != nullptr) |
| 211 | { |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 212 | const char* ifaceName = pElement->Attribute("name"); |
| 213 | if (ifaceName == nullptr) |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 214 | { |
| 215 | continue; |
| 216 | } |
| 217 | |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 218 | thisPathMap[transaction->processName].emplace(ifaceName); |
Ed Tanous | d4dd96a | 2018-11-12 11:37:44 -0800 | [diff] [blame] | 219 | |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 220 | if (std::strcmp(ifaceName, assocDefsInterface) == 0) |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 221 | { |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 222 | doAssociations(systemBus, interfaceMap, objectServer, |
| 223 | transaction->processName, path); |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 224 | } |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 225 | |
| 226 | pElement = pElement->NextSiblingElement("interface"); |
| 227 | } |
| 228 | |
Matt Spinler | 11401e2 | 2019-04-08 13:13:25 -0500 | [diff] [blame] | 229 | // Check if this new path has a pending association that can |
| 230 | // now be completed. |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 231 | checkIfPendingAssociation(path, interfaceMap, |
Matt Spinler | 11401e2 | 2019-04-08 13:13:25 -0500 | [diff] [blame] | 232 | transaction->assocMaps, objectServer); |
| 233 | |
Ed Tanous | 50232cd | 2018-11-12 11:34:43 -0800 | [diff] [blame] | 234 | pElement = pRoot->FirstChildElement("node"); |
| 235 | while (pElement != nullptr) |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 236 | { |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 237 | const char* childPath = pElement->Attribute("name"); |
| 238 | if (childPath != nullptr) |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 239 | { |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 240 | std::string parentPath(path); |
| 241 | if (parentPath == "/") |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 242 | { |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 243 | parentPath.clear(); |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 244 | } |
Ed Tanous | 50232cd | 2018-11-12 11:34:43 -0800 | [diff] [blame] | 245 | |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 246 | doIntrospect(systemBus, transaction, interfaceMap, |
| 247 | objectServer, parentPath + "/" + childPath); |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 248 | } |
Ed Tanous | 50232cd | 2018-11-12 11:34:43 -0800 | [diff] [blame] | 249 | pElement = pElement->NextSiblingElement("node"); |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 250 | } |
| 251 | }, |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 252 | transaction->processName, path, "org.freedesktop.DBus.Introspectable", |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 253 | "Introspect"); |
| 254 | } |
| 255 | |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 256 | void startNewIntrospect( |
| 257 | sdbusplus::asio::connection* systemBus, boost::asio::io_context& io, |
| 258 | InterfaceMapType& interfaceMap, const std::string& processName, |
Matt Spinler | 11401e2 | 2019-04-08 13:13:25 -0500 | [diff] [blame] | 259 | AssociationMaps& assocMaps, |
Brad Bishop | d6aa552 | 2022-05-31 19:23:48 -0400 | [diff] [blame] | 260 | #ifdef MAPPER_ENABLE_DEBUG |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 261 | std::shared_ptr<std::chrono::time_point<std::chrono::steady_clock>> |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 262 | globalStartTime, |
Matt Spinler | aecabe8 | 2018-09-19 13:25:42 -0500 | [diff] [blame] | 263 | #endif |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 264 | sdbusplus::asio::object_server& objectServer) |
| 265 | { |
Brad Bishop | d554232 | 2022-06-02 19:56:23 -0400 | [diff] [blame] | 266 | if (needToIntrospect(processName, serviceAllowList)) |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 267 | { |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 268 | std::shared_ptr<InProgressIntrospect> transaction = |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 269 | std::make_shared<InProgressIntrospect>(systemBus, io, processName, |
Matt Spinler | 11401e2 | 2019-04-08 13:13:25 -0500 | [diff] [blame] | 270 | assocMaps |
Brad Bishop | d6aa552 | 2022-05-31 19:23:48 -0400 | [diff] [blame] | 271 | #ifdef MAPPER_ENABLE_DEBUG |
Matt Spinler | aecabe8 | 2018-09-19 13:25:42 -0500 | [diff] [blame] | 272 | , |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 273 | globalStartTime |
Matt Spinler | aecabe8 | 2018-09-19 13:25:42 -0500 | [diff] [blame] | 274 | #endif |
| 275 | ); |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 276 | |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 277 | doIntrospect(systemBus, transaction, interfaceMap, objectServer, "/"); |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 278 | } |
| 279 | } |
| 280 | |
| 281 | // TODO(ed) replace with std::set_intersection once c++17 is available |
| 282 | template <class InputIt1, class InputIt2> |
| 283 | bool intersect(InputIt1 first1, InputIt1 last1, InputIt2 first2, InputIt2 last2) |
| 284 | { |
| 285 | while (first1 != last1 && first2 != last2) |
| 286 | { |
| 287 | if (*first1 < *first2) |
| 288 | { |
| 289 | ++first1; |
| 290 | continue; |
| 291 | } |
| 292 | if (*first2 < *first1) |
| 293 | { |
| 294 | ++first2; |
| 295 | continue; |
| 296 | } |
| 297 | return true; |
| 298 | } |
| 299 | return false; |
| 300 | } |
| 301 | |
| 302 | void doListNames( |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 303 | boost::asio::io_context& io, InterfaceMapType& interfaceMap, |
| 304 | sdbusplus::asio::connection* systemBus, |
| 305 | boost::container::flat_map<std::string, std::string>& nameOwners, |
Matt Spinler | 11401e2 | 2019-04-08 13:13:25 -0500 | [diff] [blame] | 306 | AssociationMaps& assocMaps, sdbusplus::asio::object_server& objectServer) |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 307 | { |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 308 | systemBus->async_method_call( |
| 309 | [&io, &interfaceMap, &nameOwners, &objectServer, systemBus, |
Matt Spinler | 11401e2 | 2019-04-08 13:13:25 -0500 | [diff] [blame] | 310 | &assocMaps](const boost::system::error_code ec, |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 311 | std::vector<std::string> processNames) { |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 312 | if (ec) |
| 313 | { |
| 314 | std::cerr << "Error getting names: " << ec << "\n"; |
| 315 | std::exit(EXIT_FAILURE); |
| 316 | return; |
| 317 | } |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 318 | // Try to make startup consistent |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 319 | std::sort(processNames.begin(), processNames.end()); |
Brad Bishop | d6aa552 | 2022-05-31 19:23:48 -0400 | [diff] [blame] | 320 | #ifdef MAPPER_ENABLE_DEBUG |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 321 | std::shared_ptr<std::chrono::time_point<std::chrono::steady_clock>> |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 322 | globalStartTime = std::make_shared< |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 323 | std::chrono::time_point<std::chrono::steady_clock>>( |
| 324 | std::chrono::steady_clock::now()); |
Matt Spinler | aecabe8 | 2018-09-19 13:25:42 -0500 | [diff] [blame] | 325 | #endif |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 326 | for (const std::string& processName : processNames) |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 327 | { |
Brad Bishop | d554232 | 2022-06-02 19:56:23 -0400 | [diff] [blame] | 328 | if (needToIntrospect(processName, serviceAllowList)) |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 329 | { |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 330 | startNewIntrospect(systemBus, io, interfaceMap, processName, |
| 331 | assocMaps, |
Brad Bishop | d6aa552 | 2022-05-31 19:23:48 -0400 | [diff] [blame] | 332 | #ifdef MAPPER_ENABLE_DEBUG |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 333 | globalStartTime, |
Matt Spinler | aecabe8 | 2018-09-19 13:25:42 -0500 | [diff] [blame] | 334 | #endif |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 335 | objectServer); |
| 336 | updateOwners(systemBus, nameOwners, processName); |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 337 | } |
| 338 | } |
| 339 | }, |
| 340 | "org.freedesktop.DBus", "/org/freedesktop/DBus", "org.freedesktop.DBus", |
| 341 | "ListNames"); |
| 342 | } |
| 343 | |
Matt Spinler | dd94586 | 2018-09-07 12:41:05 -0500 | [diff] [blame] | 344 | void splitArgs(const std::string& stringArgs, |
| 345 | boost::container::flat_set<std::string>& listArgs) |
| 346 | { |
| 347 | std::istringstream args; |
| 348 | std::string arg; |
| 349 | |
| 350 | args.str(stringArgs); |
| 351 | |
| 352 | while (!args.eof()) |
| 353 | { |
| 354 | args >> arg; |
| 355 | if (!arg.empty()) |
| 356 | { |
| 357 | listArgs.insert(arg); |
| 358 | } |
| 359 | } |
| 360 | } |
| 361 | |
Ed Tanous | 964681c | 2022-07-08 12:47:24 -0700 | [diff] [blame] | 362 | void addObjectMapResult(std::vector<InterfaceMapType::value_type>& objectMap, |
| 363 | const std::string& objectPath, |
| 364 | const ConnectionNames::value_type& interfaceMap) |
Matt Spinler | 9f0958e | 2018-09-11 08:26:10 -0500 | [diff] [blame] | 365 | { |
| 366 | // Adds an object path/service name/interface list entry to |
Matt Spinler | 47c0975 | 2018-11-29 14:54:13 -0600 | [diff] [blame] | 367 | // the results of GetSubTree and GetAncestors. |
Matt Spinler | 9f0958e | 2018-09-11 08:26:10 -0500 | [diff] [blame] | 368 | // If an entry for the object path already exists, just add the |
| 369 | // service name and interfaces to that entry, otherwise create |
| 370 | // a new entry. |
| 371 | auto entry = std::find_if( |
Matt Spinler | 47c0975 | 2018-11-29 14:54:13 -0600 | [diff] [blame] | 372 | objectMap.begin(), objectMap.end(), |
Matt Spinler | 9f0958e | 2018-09-11 08:26:10 -0500 | [diff] [blame] | 373 | [&objectPath](const auto& i) { return objectPath == i.first; }); |
| 374 | |
Matt Spinler | 47c0975 | 2018-11-29 14:54:13 -0600 | [diff] [blame] | 375 | if (entry != objectMap.end()) |
Matt Spinler | 9f0958e | 2018-09-11 08:26:10 -0500 | [diff] [blame] | 376 | { |
| 377 | entry->second.emplace(interfaceMap); |
| 378 | } |
| 379 | else |
| 380 | { |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 381 | InterfaceMapType::value_type object; |
Matt Spinler | 9f0958e | 2018-09-11 08:26:10 -0500 | [diff] [blame] | 382 | object.first = objectPath; |
| 383 | object.second.emplace(interfaceMap); |
Matt Spinler | 47c0975 | 2018-11-29 14:54:13 -0600 | [diff] [blame] | 384 | objectMap.push_back(object); |
Matt Spinler | 9f0958e | 2018-09-11 08:26:10 -0500 | [diff] [blame] | 385 | } |
| 386 | } |
| 387 | |
Matt Spinler | a82779f | 2019-01-09 12:39:42 -0600 | [diff] [blame] | 388 | // Remove parents of the passed in path that: |
| 389 | // 1) Only have the 3 default interfaces on them |
| 390 | // - Means D-Bus created these, not application code, |
| 391 | // with the Properties, Introspectable, and Peer ifaces |
| 392 | // 2) Have no other child for this owner |
| 393 | void removeUnneededParents(const std::string& objectPath, |
| 394 | const std::string& owner, |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 395 | InterfaceMapType& interfaceMap) |
Matt Spinler | a82779f | 2019-01-09 12:39:42 -0600 | [diff] [blame] | 396 | { |
| 397 | auto parent = objectPath; |
| 398 | |
| 399 | while (true) |
| 400 | { |
| 401 | auto pos = parent.find_last_of('/'); |
| 402 | if ((pos == std::string::npos) || (pos == 0)) |
| 403 | { |
| 404 | break; |
| 405 | } |
| 406 | parent = parent.substr(0, pos); |
| 407 | |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 408 | auto parentIt = interfaceMap.find(parent); |
| 409 | if (parentIt == interfaceMap.end()) |
Matt Spinler | a82779f | 2019-01-09 12:39:42 -0600 | [diff] [blame] | 410 | { |
| 411 | break; |
| 412 | } |
| 413 | |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 414 | auto ifacesIt = parentIt->second.find(owner); |
| 415 | if (ifacesIt == parentIt->second.end()) |
Matt Spinler | a82779f | 2019-01-09 12:39:42 -0600 | [diff] [blame] | 416 | { |
| 417 | break; |
| 418 | } |
| 419 | |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 420 | if (ifacesIt->second.size() != 3) |
Matt Spinler | a82779f | 2019-01-09 12:39:42 -0600 | [diff] [blame] | 421 | { |
| 422 | break; |
| 423 | } |
| 424 | |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 425 | auto childPath = parent + '/'; |
Matt Spinler | a82779f | 2019-01-09 12:39:42 -0600 | [diff] [blame] | 426 | |
| 427 | // Remove this parent if there isn't a remaining child on this owner |
| 428 | auto child = std::find_if( |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 429 | interfaceMap.begin(), interfaceMap.end(), |
| 430 | [&owner, &childPath](const auto& entry) { |
| 431 | return boost::starts_with(entry.first, childPath) && |
Matt Spinler | a82779f | 2019-01-09 12:39:42 -0600 | [diff] [blame] | 432 | (entry.second.find(owner) != entry.second.end()); |
| 433 | }); |
| 434 | |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 435 | if (child == interfaceMap.end()) |
Matt Spinler | a82779f | 2019-01-09 12:39:42 -0600 | [diff] [blame] | 436 | { |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 437 | parentIt->second.erase(ifacesIt); |
| 438 | if (parentIt->second.empty()) |
Matt Spinler | a82779f | 2019-01-09 12:39:42 -0600 | [diff] [blame] | 439 | { |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 440 | interfaceMap.erase(parentIt); |
Matt Spinler | a82779f | 2019-01-09 12:39:42 -0600 | [diff] [blame] | 441 | } |
| 442 | } |
| 443 | else |
| 444 | { |
| 445 | break; |
| 446 | } |
| 447 | } |
| 448 | } |
| 449 | |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 450 | std::vector<InterfaceMapType::value_type> |
| 451 | getAncestors(const InterfaceMapType& interfaceMap, std::string reqPath, |
Ed Tanous | 0a13c76 | 2021-09-28 13:29:25 -0700 | [diff] [blame] | 452 | std::vector<std::string>& interfaces) |
| 453 | { |
| 454 | // Interfaces need to be sorted for intersect to function |
| 455 | std::sort(interfaces.begin(), interfaces.end()); |
| 456 | |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 457 | if (boost::ends_with(reqPath, "/")) |
Ed Tanous | 0a13c76 | 2021-09-28 13:29:25 -0700 | [diff] [blame] | 458 | { |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 459 | reqPath.pop_back(); |
Ed Tanous | 0a13c76 | 2021-09-28 13:29:25 -0700 | [diff] [blame] | 460 | } |
Brad Bishop | 1f62380 | 2022-05-31 18:22:10 -0400 | [diff] [blame] | 461 | if (!reqPath.empty() && interfaceMap.find(reqPath) == interfaceMap.end()) |
Ed Tanous | 0a13c76 | 2021-09-28 13:29:25 -0700 | [diff] [blame] | 462 | { |
Konstantin Aladyshev | b15df6b | 2022-01-11 14:50:55 +0300 | [diff] [blame] | 463 | throw sdbusplus::xyz::openbmc_project::Common::Error:: |
| 464 | ResourceNotFound(); |
Ed Tanous | 0a13c76 | 2021-09-28 13:29:25 -0700 | [diff] [blame] | 465 | } |
| 466 | |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 467 | std::vector<InterfaceMapType::value_type> ret; |
Brad Bishop | 1f62380 | 2022-05-31 18:22:10 -0400 | [diff] [blame] | 468 | for (const auto& objectPath : interfaceMap) |
Ed Tanous | 0a13c76 | 2021-09-28 13:29:25 -0700 | [diff] [blame] | 469 | { |
Brad Bishop | 1f62380 | 2022-05-31 18:22:10 -0400 | [diff] [blame] | 470 | const auto& thisPath = objectPath.first; |
Brandon Kim | 82720f0 | 2022-07-08 09:57:22 -0700 | [diff] [blame] | 471 | |
| 472 | if (reqPath == thisPath) |
| 473 | { |
| 474 | continue; |
| 475 | } |
| 476 | |
| 477 | if (boost::starts_with(reqPath, thisPath)) |
Ed Tanous | 0a13c76 | 2021-09-28 13:29:25 -0700 | [diff] [blame] | 478 | { |
| 479 | if (interfaces.empty()) |
| 480 | { |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 481 | ret.emplace_back(objectPath); |
Ed Tanous | 0a13c76 | 2021-09-28 13:29:25 -0700 | [diff] [blame] | 482 | } |
| 483 | else |
| 484 | { |
Brad Bishop | 1f62380 | 2022-05-31 18:22:10 -0400 | [diff] [blame] | 485 | for (const auto& interfaceMap : objectPath.second) |
Ed Tanous | 0a13c76 | 2021-09-28 13:29:25 -0700 | [diff] [blame] | 486 | { |
Ed Tanous | 0a13c76 | 2021-09-28 13:29:25 -0700 | [diff] [blame] | 487 | if (intersect(interfaces.begin(), interfaces.end(), |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 488 | interfaceMap.second.begin(), |
| 489 | interfaceMap.second.end())) |
Ed Tanous | 0a13c76 | 2021-09-28 13:29:25 -0700 | [diff] [blame] | 490 | { |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 491 | addObjectMapResult(ret, thisPath, interfaceMap); |
Ed Tanous | 0a13c76 | 2021-09-28 13:29:25 -0700 | [diff] [blame] | 492 | } |
| 493 | } |
| 494 | } |
| 495 | } |
| 496 | } |
| 497 | |
| 498 | return ret; |
| 499 | } |
| 500 | |
Ed Tanous | 964681c | 2022-07-08 12:47:24 -0700 | [diff] [blame] | 501 | ConnectionNames getObject(const InterfaceMapType& interfaceMap, |
| 502 | const std::string& path, |
| 503 | std::vector<std::string>& interfaces) |
Ed Tanous | 0a13c76 | 2021-09-28 13:29:25 -0700 | [diff] [blame] | 504 | { |
Ed Tanous | 964681c | 2022-07-08 12:47:24 -0700 | [diff] [blame] | 505 | ConnectionNames results; |
Ed Tanous | 0a13c76 | 2021-09-28 13:29:25 -0700 | [diff] [blame] | 506 | |
| 507 | // Interfaces need to be sorted for intersect to function |
| 508 | std::sort(interfaces.begin(), interfaces.end()); |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 509 | auto pathRef = interfaceMap.find(path); |
| 510 | if (pathRef == interfaceMap.end()) |
Ed Tanous | 0a13c76 | 2021-09-28 13:29:25 -0700 | [diff] [blame] | 511 | { |
Konstantin Aladyshev | b15df6b | 2022-01-11 14:50:55 +0300 | [diff] [blame] | 512 | throw sdbusplus::xyz::openbmc_project::Common::Error:: |
| 513 | ResourceNotFound(); |
Ed Tanous | 0a13c76 | 2021-09-28 13:29:25 -0700 | [diff] [blame] | 514 | } |
| 515 | if (interfaces.empty()) |
| 516 | { |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 517 | return pathRef->second; |
Ed Tanous | 0a13c76 | 2021-09-28 13:29:25 -0700 | [diff] [blame] | 518 | } |
Brad Bishop | 1f62380 | 2022-05-31 18:22:10 -0400 | [diff] [blame] | 519 | for (const auto& interfaceMap : pathRef->second) |
Ed Tanous | 0a13c76 | 2021-09-28 13:29:25 -0700 | [diff] [blame] | 520 | { |
| 521 | if (intersect(interfaces.begin(), interfaces.end(), |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 522 | interfaceMap.second.begin(), interfaceMap.second.end())) |
Ed Tanous | 0a13c76 | 2021-09-28 13:29:25 -0700 | [diff] [blame] | 523 | { |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 524 | results.emplace(interfaceMap.first, interfaceMap.second); |
Ed Tanous | 0a13c76 | 2021-09-28 13:29:25 -0700 | [diff] [blame] | 525 | } |
| 526 | } |
| 527 | |
| 528 | if (results.empty()) |
| 529 | { |
Konstantin Aladyshev | b15df6b | 2022-01-11 14:50:55 +0300 | [diff] [blame] | 530 | throw sdbusplus::xyz::openbmc_project::Common::Error:: |
| 531 | ResourceNotFound(); |
Ed Tanous | 0a13c76 | 2021-09-28 13:29:25 -0700 | [diff] [blame] | 532 | } |
| 533 | |
| 534 | return results; |
| 535 | } |
| 536 | |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 537 | std::vector<InterfaceMapType::value_type> |
| 538 | getSubTree(const InterfaceMapType& interfaceMap, std::string reqPath, |
Ed Tanous | 0a13c76 | 2021-09-28 13:29:25 -0700 | [diff] [blame] | 539 | int32_t depth, std::vector<std::string>& interfaces) |
| 540 | { |
| 541 | if (depth <= 0) |
| 542 | { |
| 543 | depth = std::numeric_limits<int32_t>::max(); |
| 544 | } |
| 545 | // Interfaces need to be sorted for intersect to function |
| 546 | std::sort(interfaces.begin(), interfaces.end()); |
Ed Tanous | 0a13c76 | 2021-09-28 13:29:25 -0700 | [diff] [blame] | 547 | |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 548 | if (boost::ends_with(reqPath, "/")) |
Ed Tanous | 0a13c76 | 2021-09-28 13:29:25 -0700 | [diff] [blame] | 549 | { |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 550 | reqPath.pop_back(); |
Ed Tanous | 0a13c76 | 2021-09-28 13:29:25 -0700 | [diff] [blame] | 551 | } |
Brad Bishop | 1f62380 | 2022-05-31 18:22:10 -0400 | [diff] [blame] | 552 | if (!reqPath.empty() && interfaceMap.find(reqPath) == interfaceMap.end()) |
Ed Tanous | 0a13c76 | 2021-09-28 13:29:25 -0700 | [diff] [blame] | 553 | { |
Konstantin Aladyshev | b15df6b | 2022-01-11 14:50:55 +0300 | [diff] [blame] | 554 | throw sdbusplus::xyz::openbmc_project::Common::Error:: |
| 555 | ResourceNotFound(); |
Ed Tanous | 0a13c76 | 2021-09-28 13:29:25 -0700 | [diff] [blame] | 556 | } |
| 557 | |
Brandon Kim | 82720f0 | 2022-07-08 09:57:22 -0700 | [diff] [blame] | 558 | std::vector<InterfaceMapType::value_type> ret; |
Brad Bishop | 1f62380 | 2022-05-31 18:22:10 -0400 | [diff] [blame] | 559 | for (const auto& objectPath : interfaceMap) |
Ed Tanous | 0a13c76 | 2021-09-28 13:29:25 -0700 | [diff] [blame] | 560 | { |
Brad Bishop | 1f62380 | 2022-05-31 18:22:10 -0400 | [diff] [blame] | 561 | const auto& thisPath = objectPath.first; |
Ed Tanous | 0a13c76 | 2021-09-28 13:29:25 -0700 | [diff] [blame] | 562 | |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 563 | if (thisPath == reqPath) |
Ed Tanous | 0a13c76 | 2021-09-28 13:29:25 -0700 | [diff] [blame] | 564 | { |
| 565 | continue; |
| 566 | } |
| 567 | |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 568 | if (boost::starts_with(thisPath, reqPath)) |
Ed Tanous | 0a13c76 | 2021-09-28 13:29:25 -0700 | [diff] [blame] | 569 | { |
| 570 | // count the number of slashes past the search term |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 571 | int32_t thisDepth = std::count(thisPath.begin() + reqPath.size(), |
| 572 | thisPath.end(), '/'); |
| 573 | if (thisDepth <= depth) |
Ed Tanous | 0a13c76 | 2021-09-28 13:29:25 -0700 | [diff] [blame] | 574 | { |
Brad Bishop | 1f62380 | 2022-05-31 18:22:10 -0400 | [diff] [blame] | 575 | for (const auto& interfaceMap : objectPath.second) |
Ed Tanous | 0a13c76 | 2021-09-28 13:29:25 -0700 | [diff] [blame] | 576 | { |
| 577 | if (intersect(interfaces.begin(), interfaces.end(), |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 578 | interfaceMap.second.begin(), |
| 579 | interfaceMap.second.end()) || |
Ed Tanous | 0a13c76 | 2021-09-28 13:29:25 -0700 | [diff] [blame] | 580 | interfaces.empty()) |
| 581 | { |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 582 | addObjectMapResult(ret, thisPath, interfaceMap); |
Ed Tanous | 0a13c76 | 2021-09-28 13:29:25 -0700 | [diff] [blame] | 583 | } |
| 584 | } |
| 585 | } |
| 586 | } |
| 587 | } |
| 588 | |
| 589 | return ret; |
| 590 | } |
| 591 | |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 592 | std::vector<std::string> getSubTreePaths(const InterfaceMapType& interfaceMap, |
| 593 | std::string reqPath, int32_t depth, |
| 594 | std::vector<std::string>& interfaces) |
Ed Tanous | 0a13c76 | 2021-09-28 13:29:25 -0700 | [diff] [blame] | 595 | { |
| 596 | if (depth <= 0) |
| 597 | { |
| 598 | depth = std::numeric_limits<int32_t>::max(); |
| 599 | } |
| 600 | // Interfaces need to be sorted for intersect to function |
| 601 | std::sort(interfaces.begin(), interfaces.end()); |
Ed Tanous | 0a13c76 | 2021-09-28 13:29:25 -0700 | [diff] [blame] | 602 | |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 603 | if (boost::ends_with(reqPath, "/")) |
Ed Tanous | 0a13c76 | 2021-09-28 13:29:25 -0700 | [diff] [blame] | 604 | { |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 605 | reqPath.pop_back(); |
Ed Tanous | 0a13c76 | 2021-09-28 13:29:25 -0700 | [diff] [blame] | 606 | } |
Brad Bishop | 1f62380 | 2022-05-31 18:22:10 -0400 | [diff] [blame] | 607 | if (!reqPath.empty() && interfaceMap.find(reqPath) == interfaceMap.end()) |
Ed Tanous | 0a13c76 | 2021-09-28 13:29:25 -0700 | [diff] [blame] | 608 | { |
Konstantin Aladyshev | b15df6b | 2022-01-11 14:50:55 +0300 | [diff] [blame] | 609 | throw sdbusplus::xyz::openbmc_project::Common::Error:: |
| 610 | ResourceNotFound(); |
Ed Tanous | 0a13c76 | 2021-09-28 13:29:25 -0700 | [diff] [blame] | 611 | } |
| 612 | |
Brandon Kim | 82720f0 | 2022-07-08 09:57:22 -0700 | [diff] [blame] | 613 | std::vector<std::string> ret; |
Brad Bishop | 1f62380 | 2022-05-31 18:22:10 -0400 | [diff] [blame] | 614 | for (const auto& objectPath : interfaceMap) |
Ed Tanous | 0a13c76 | 2021-09-28 13:29:25 -0700 | [diff] [blame] | 615 | { |
Brad Bishop | 1f62380 | 2022-05-31 18:22:10 -0400 | [diff] [blame] | 616 | const auto& thisPath = objectPath.first; |
Ed Tanous | 0a13c76 | 2021-09-28 13:29:25 -0700 | [diff] [blame] | 617 | |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 618 | if (thisPath == reqPath) |
Ed Tanous | 0a13c76 | 2021-09-28 13:29:25 -0700 | [diff] [blame] | 619 | { |
| 620 | continue; |
| 621 | } |
| 622 | |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 623 | if (boost::starts_with(thisPath, reqPath)) |
Ed Tanous | 0a13c76 | 2021-09-28 13:29:25 -0700 | [diff] [blame] | 624 | { |
| 625 | // count the number of slashes past the search term |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 626 | int thisDepth = std::count(thisPath.begin() + reqPath.size(), |
| 627 | thisPath.end(), '/'); |
| 628 | if (thisDepth <= depth) |
Ed Tanous | 0a13c76 | 2021-09-28 13:29:25 -0700 | [diff] [blame] | 629 | { |
| 630 | bool add = interfaces.empty(); |
Brad Bishop | 1f62380 | 2022-05-31 18:22:10 -0400 | [diff] [blame] | 631 | for (const auto& interfaceMap : objectPath.second) |
Ed Tanous | 0a13c76 | 2021-09-28 13:29:25 -0700 | [diff] [blame] | 632 | { |
| 633 | if (intersect(interfaces.begin(), interfaces.end(), |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 634 | interfaceMap.second.begin(), |
| 635 | interfaceMap.second.end())) |
Ed Tanous | 0a13c76 | 2021-09-28 13:29:25 -0700 | [diff] [blame] | 636 | { |
| 637 | add = true; |
| 638 | break; |
| 639 | } |
| 640 | } |
| 641 | if (add) |
| 642 | { |
| 643 | // TODO(ed) this is a copy |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 644 | ret.emplace_back(thisPath); |
Ed Tanous | 0a13c76 | 2021-09-28 13:29:25 -0700 | [diff] [blame] | 645 | } |
| 646 | } |
| 647 | } |
| 648 | } |
| 649 | |
| 650 | return ret; |
| 651 | } |
| 652 | |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 653 | int main(int argc, char** argv) |
| 654 | { |
Matt Spinler | dd94586 | 2018-09-07 12:41:05 -0500 | [diff] [blame] | 655 | auto options = ArgumentParser(argc, argv); |
Ed Tanous | 21c6059 | 2020-08-17 23:43:46 -0700 | [diff] [blame] | 656 | boost::asio::io_context io; |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 657 | std::shared_ptr<sdbusplus::asio::connection> systemBus = |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 658 | std::make_shared<sdbusplus::asio::connection>(io); |
| 659 | |
Brad Bishop | f944a45 | 2022-05-05 15:06:46 -0400 | [diff] [blame] | 660 | splitArgs(options["service-namespaces"], serviceAllowList); |
Matt Spinler | dd94586 | 2018-09-07 12:41:05 -0500 | [diff] [blame] | 661 | |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 662 | sdbusplus::asio::object_server server(systemBus); |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 663 | |
| 664 | // Construct a signal set registered for process termination. |
| 665 | boost::asio::signal_set signals(io, SIGINT, SIGTERM); |
Brad Bishop | 2d41d6a | 2021-08-03 08:14:45 -0400 | [diff] [blame] | 666 | signals.async_wait( |
| 667 | [&io](const boost::system::error_code&, int) { io.stop(); }); |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 668 | |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 669 | InterfaceMapType interfaceMap; |
| 670 | boost::container::flat_map<std::string, std::string> nameOwners; |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 671 | |
Patrick Williams | cc8070b | 2022-07-22 19:26:55 -0500 | [diff] [blame^] | 672 | std::function<void(sdbusplus::message_t & message)> nameChangeHandler = |
| 673 | [&interfaceMap, &io, &nameOwners, &server, |
| 674 | systemBus](sdbusplus::message_t& message) { |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 675 | std::string name; // well-known |
| 676 | std::string oldOwner; // unique-name |
| 677 | std::string newOwner; // unique-name |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 678 | |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 679 | message.read(name, oldOwner, newOwner); |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 680 | |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 681 | if (!oldOwner.empty()) |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 682 | { |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 683 | processNameChangeDelete(nameOwners, name, oldOwner, |
| 684 | interfaceMap, associationMaps, server); |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 685 | } |
| 686 | |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 687 | if (!newOwner.empty()) |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 688 | { |
Brad Bishop | d6aa552 | 2022-05-31 19:23:48 -0400 | [diff] [blame] | 689 | #ifdef MAPPER_ENABLE_DEBUG |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 690 | auto transaction = std::make_shared< |
| 691 | std::chrono::time_point<std::chrono::steady_clock>>( |
| 692 | std::chrono::steady_clock::now()); |
Matt Spinler | aecabe8 | 2018-09-19 13:25:42 -0500 | [diff] [blame] | 693 | #endif |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 694 | // New daemon added |
Brad Bishop | d554232 | 2022-06-02 19:56:23 -0400 | [diff] [blame] | 695 | if (needToIntrospect(name, serviceAllowList)) |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 696 | { |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 697 | nameOwners[newOwner] = name; |
| 698 | startNewIntrospect(systemBus.get(), io, interfaceMap, name, |
| 699 | associationMaps, |
Brad Bishop | d6aa552 | 2022-05-31 19:23:48 -0400 | [diff] [blame] | 700 | #ifdef MAPPER_ENABLE_DEBUG |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 701 | transaction, |
Matt Spinler | aecabe8 | 2018-09-19 13:25:42 -0500 | [diff] [blame] | 702 | #endif |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 703 | server); |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 704 | } |
| 705 | } |
| 706 | }; |
| 707 | |
Patrick Williams | cc8070b | 2022-07-22 19:26:55 -0500 | [diff] [blame^] | 708 | sdbusplus::bus::match_t nameOwnerChanged( |
| 709 | static_cast<sdbusplus::bus_t&>(*systemBus), |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 710 | sdbusplus::bus::match::rules::nameOwnerChanged(), nameChangeHandler); |
| 711 | |
Patrick Williams | cc8070b | 2022-07-22 19:26:55 -0500 | [diff] [blame^] | 712 | std::function<void(sdbusplus::message_t & message)> interfacesAddedHandler = |
| 713 | [&interfaceMap, &nameOwners, &server](sdbusplus::message_t& message) { |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 714 | sdbusplus::message::object_path objPath; |
| 715 | InterfacesAdded interfacesAdded; |
| 716 | message.read(objPath, interfacesAdded); |
| 717 | std::string wellKnown; |
| 718 | if (!getWellKnown(nameOwners, message.get_sender(), wellKnown)) |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 719 | { |
| 720 | return; // only introspect well-known |
| 721 | } |
Brad Bishop | d554232 | 2022-06-02 19:56:23 -0400 | [diff] [blame] | 722 | if (needToIntrospect(wellKnown, serviceAllowList)) |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 723 | { |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 724 | processInterfaceAdded(interfaceMap, objPath, interfacesAdded, |
| 725 | wellKnown, associationMaps, server); |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 726 | } |
| 727 | }; |
| 728 | |
Patrick Williams | cc8070b | 2022-07-22 19:26:55 -0500 | [diff] [blame^] | 729 | sdbusplus::bus::match_t interfacesAdded( |
| 730 | static_cast<sdbusplus::bus_t&>(*systemBus), |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 731 | sdbusplus::bus::match::rules::interfacesAdded(), |
| 732 | interfacesAddedHandler); |
| 733 | |
Patrick Williams | cc8070b | 2022-07-22 19:26:55 -0500 | [diff] [blame^] | 734 | std::function<void(sdbusplus::message_t & message)> |
| 735 | interfacesRemovedHandler = [&interfaceMap, &nameOwners, |
| 736 | &server](sdbusplus::message_t& message) { |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 737 | sdbusplus::message::object_path objPath; |
| 738 | std::vector<std::string> interfacesRemoved; |
| 739 | message.read(objPath, interfacesRemoved); |
| 740 | auto connectionMap = interfaceMap.find(objPath.str); |
| 741 | if (connectionMap == interfaceMap.end()) |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 742 | { |
| 743 | return; |
| 744 | } |
| 745 | |
| 746 | std::string sender; |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 747 | if (!getWellKnown(nameOwners, message.get_sender(), sender)) |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 748 | { |
| 749 | return; |
| 750 | } |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 751 | for (const std::string& interface : interfacesRemoved) |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 752 | { |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 753 | auto interfaceSet = connectionMap->second.find(sender); |
| 754 | if (interfaceSet == connectionMap->second.end()) |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 755 | { |
| 756 | continue; |
| 757 | } |
| 758 | |
John Wang | d0cf942 | 2019-09-17 16:01:34 +0800 | [diff] [blame] | 759 | if (interface == assocDefsInterface) |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 760 | { |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 761 | removeAssociation(objPath.str, sender, server, |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame] | 762 | associationMaps); |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 763 | } |
| 764 | |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 765 | interfaceSet->second.erase(interface); |
Matt Spinler | 9c3d285 | 2019-04-08 15:57:19 -0500 | [diff] [blame] | 766 | |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 767 | if (interfaceSet->second.empty()) |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 768 | { |
Matt Spinler | 9c3d285 | 2019-04-08 15:57:19 -0500 | [diff] [blame] | 769 | // If this was the last interface on this connection, |
| 770 | // erase the connection |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 771 | connectionMap->second.erase(interfaceSet); |
Matt Spinler | 9c3d285 | 2019-04-08 15:57:19 -0500 | [diff] [blame] | 772 | |
| 773 | // Instead of checking if every single path is the endpoint |
| 774 | // of an association that needs to be moved to pending, |
| 775 | // only check when the only remaining owner of this path is |
| 776 | // ourself, which would be because we still own the |
| 777 | // association path. |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 778 | if ((connectionMap->second.size() == 1) && |
| 779 | (connectionMap->second.begin()->first == |
Brad Bishop | a02cd54 | 2021-10-12 19:12:42 -0400 | [diff] [blame] | 780 | "xyz.openbmc_project.ObjectMapper")) |
Matt Spinler | 9c3d285 | 2019-04-08 15:57:19 -0500 | [diff] [blame] | 781 | { |
| 782 | // Remove the 2 association D-Bus paths and move the |
| 783 | // association to pending. |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 784 | moveAssociationToPending(objPath.str, associationMaps, |
Matt Spinler | 9c3d285 | 2019-04-08 15:57:19 -0500 | [diff] [blame] | 785 | server); |
| 786 | } |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 787 | } |
| 788 | } |
| 789 | // If this was the last connection on this object path, |
| 790 | // erase the object path |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 791 | if (connectionMap->second.empty()) |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 792 | { |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 793 | interfaceMap.erase(connectionMap); |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 794 | } |
Matt Spinler | a82779f | 2019-01-09 12:39:42 -0600 | [diff] [blame] | 795 | |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 796 | removeUnneededParents(objPath.str, sender, interfaceMap); |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 797 | }; |
| 798 | |
Patrick Williams | cc8070b | 2022-07-22 19:26:55 -0500 | [diff] [blame^] | 799 | sdbusplus::bus::match_t interfacesRemoved( |
| 800 | static_cast<sdbusplus::bus_t&>(*systemBus), |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 801 | sdbusplus::bus::match::rules::interfacesRemoved(), |
| 802 | interfacesRemovedHandler); |
| 803 | |
Patrick Williams | cc8070b | 2022-07-22 19:26:55 -0500 | [diff] [blame^] | 804 | std::function<void(sdbusplus::message_t & message)> |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 805 | associationChangedHandler = [&server, &nameOwners, &interfaceMap]( |
Patrick Williams | cc8070b | 2022-07-22 19:26:55 -0500 | [diff] [blame^] | 806 | sdbusplus::message_t& message) { |
Matt Spinler | 8f876a5 | 2019-04-15 13:22:50 -0500 | [diff] [blame] | 807 | std::string objectName; |
Patrick Williams | 2bb2d6b | 2020-05-13 17:59:02 -0500 | [diff] [blame] | 808 | boost::container::flat_map<std::string, |
| 809 | std::variant<std::vector<Association>>> |
Matt Spinler | 8f876a5 | 2019-04-15 13:22:50 -0500 | [diff] [blame] | 810 | values; |
| 811 | message.read(objectName, values); |
John Wang | d0cf942 | 2019-09-17 16:01:34 +0800 | [diff] [blame] | 812 | auto prop = values.find(assocDefsProperty); |
Matt Spinler | 8f876a5 | 2019-04-15 13:22:50 -0500 | [diff] [blame] | 813 | if (prop != values.end()) |
| 814 | { |
| 815 | std::vector<Association> associations = |
Patrick Williams | b05bc12 | 2020-05-13 12:21:00 -0500 | [diff] [blame] | 816 | std::get<std::vector<Association>>(prop->second); |
Matt Spinler | 8f876a5 | 2019-04-15 13:22:50 -0500 | [diff] [blame] | 817 | |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 818 | std::string wellKnown; |
| 819 | if (!getWellKnown(nameOwners, message.get_sender(), wellKnown)) |
Matt Spinler | 8f876a5 | 2019-04-15 13:22:50 -0500 | [diff] [blame] | 820 | { |
| 821 | return; |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 822 | } |
Matt Spinler | 8f876a5 | 2019-04-15 13:22:50 -0500 | [diff] [blame] | 823 | associationChanged(server, associations, message.get_path(), |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 824 | wellKnown, interfaceMap, associationMaps); |
Matt Spinler | 8f876a5 | 2019-04-15 13:22:50 -0500 | [diff] [blame] | 825 | } |
| 826 | }; |
Patrick Williams | cc8070b | 2022-07-22 19:26:55 -0500 | [diff] [blame^] | 827 | sdbusplus::bus::match_t assocChangedMatch( |
| 828 | static_cast<sdbusplus::bus_t&>(*systemBus), |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 829 | sdbusplus::bus::match::rules::interface( |
| 830 | "org.freedesktop.DBus.Properties") + |
| 831 | sdbusplus::bus::match::rules::member("PropertiesChanged") + |
Matt Spinler | 8f876a5 | 2019-04-15 13:22:50 -0500 | [diff] [blame] | 832 | sdbusplus::bus::match::rules::argN(0, assocDefsInterface), |
| 833 | associationChangedHandler); |
| 834 | |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 835 | std::shared_ptr<sdbusplus::asio::dbus_interface> iface = |
Brad Bishop | a02cd54 | 2021-10-12 19:12:42 -0400 | [diff] [blame] | 836 | server.add_interface("/xyz/openbmc_project/object_mapper", |
| 837 | "xyz.openbmc_project.ObjectMapper"); |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 838 | |
| 839 | iface->register_method( |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 840 | "GetAncestors", [&interfaceMap](std::string& reqPath, |
| 841 | std::vector<std::string>& interfaces) { |
| 842 | return getAncestors(interfaceMap, reqPath, interfaces); |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 843 | }); |
| 844 | |
| 845 | iface->register_method( |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 846 | "GetObject", [&interfaceMap](const std::string& path, |
| 847 | std::vector<std::string>& interfaces) { |
| 848 | return getObject(interfaceMap, path, interfaces); |
| 849 | }); |
| 850 | |
| 851 | iface->register_method( |
| 852 | "GetSubTree", [&interfaceMap](std::string& reqPath, int32_t depth, |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 853 | std::vector<std::string>& interfaces) { |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 854 | return getSubTree(interfaceMap, reqPath, depth, interfaces); |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 855 | }); |
| 856 | |
| 857 | iface->register_method( |
| 858 | "GetSubTreePaths", |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 859 | [&interfaceMap](std::string& reqPath, int32_t depth, |
| 860 | std::vector<std::string>& interfaces) { |
| 861 | return getSubTreePaths(interfaceMap, reqPath, depth, interfaces); |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 862 | }); |
| 863 | |
| 864 | iface->initialize(); |
| 865 | |
| 866 | io.post([&]() { |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 867 | doListNames(io, interfaceMap, systemBus.get(), nameOwners, |
Matt Spinler | 11401e2 | 2019-04-08 13:13:25 -0500 | [diff] [blame] | 868 | associationMaps, server); |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 869 | }); |
| 870 | |
Brad Bishop | a098a37 | 2022-05-05 15:19:04 -0400 | [diff] [blame] | 871 | systemBus->request_name("xyz.openbmc_project.ObjectMapper"); |
Vishwanatha Subbanna | 64354ef | 2020-08-21 03:35:26 -0500 | [diff] [blame] | 872 | |
Ed Tanous | 6052063 | 2018-06-11 17:46:52 -0700 | [diff] [blame] | 873 | io.run(); |
| 874 | } |