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