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