| Alexander Hansen | 4e1142d | 2025-07-25 17:07:27 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: Apache-2.0 | 
|  | 2 | // SPDX-FileCopyrightText: Copyright 2018 Intel Corporation | 
|  | 3 |  | 
| Christopher Meis | 26fbbd5 | 2025-03-26 14:55:06 +0100 | [diff] [blame] | 4 | #include "perform_scan.hpp" | 
|  | 5 |  | 
| Christopher Meis | 26fbbd5 | 2025-03-26 14:55:06 +0100 | [diff] [blame] | 6 | #include "perform_probe.hpp" | 
| Christopher Meis | 59ef1e7 | 2025-04-16 08:53:25 +0200 | [diff] [blame] | 7 | #include "utils.hpp" | 
| Andrew Jeffery | 47af65a | 2021-12-01 14:16:31 +1030 | [diff] [blame] | 8 |  | 
| Andrew Jeffery | 47af65a | 2021-12-01 14:16:31 +1030 | [diff] [blame] | 9 | #include <boost/asio/steady_timer.hpp> | 
|  | 10 | #include <boost/container/flat_map.hpp> | 
|  | 11 | #include <boost/container/flat_set.hpp> | 
| Alexander Hansen | c3db2c3 | 2024-08-20 15:01:38 +0200 | [diff] [blame] | 12 | #include <phosphor-logging/lg2.hpp> | 
| Andrew Jeffery | 47af65a | 2021-12-01 14:16:31 +1030 | [diff] [blame] | 13 |  | 
|  | 14 | #include <charconv> | 
|  | 15 |  | 
| Andrew Jeffery | 47af65a | 2021-12-01 14:16:31 +1030 | [diff] [blame] | 16 | using GetSubTreeType = std::vector< | 
|  | 17 | std::pair<std::string, | 
|  | 18 | std::vector<std::pair<std::string, std::vector<std::string>>>>>; | 
|  | 19 |  | 
|  | 20 | constexpr const int32_t maxMapperDepth = 0; | 
|  | 21 |  | 
| Andrew Jeffery | d9b6784 | 2022-04-05 16:44:20 +0930 | [diff] [blame] | 22 | struct DBusInterfaceInstance | 
|  | 23 | { | 
|  | 24 | std::string busName; | 
|  | 25 | std::string path; | 
|  | 26 | std::string interface; | 
|  | 27 | }; | 
|  | 28 |  | 
| Patrick Williams | 5a80703 | 2025-03-03 11:20:39 -0500 | [diff] [blame] | 29 | void getInterfaces( | 
|  | 30 | const DBusInterfaceInstance& instance, | 
| Christopher Meis | 26fbbd5 | 2025-03-26 14:55:06 +0100 | [diff] [blame] | 31 | const std::vector<std::shared_ptr<probe::PerformProbe>>& probeVector, | 
| Alexander Hansen | a555acf | 2025-06-27 11:59:10 +0200 | [diff] [blame] | 32 | const std::shared_ptr<scan::PerformScan>& scan, boost::asio::io_context& io, | 
|  | 33 | size_t retries = 5) | 
| Andrew Jeffery | 47af65a | 2021-12-01 14:16:31 +1030 | [diff] [blame] | 34 | { | 
| Ed Tanous | 3013fb4 | 2022-07-09 08:27:06 -0700 | [diff] [blame] | 35 | if (retries == 0U) | 
| Andrew Jeffery | 47af65a | 2021-12-01 14:16:31 +1030 | [diff] [blame] | 36 | { | 
| Alexander Hansen | 8feb045 | 2025-09-15 14:29:20 +0200 | [diff] [blame] | 37 | lg2::error("retries exhausted on {BUSNAME} {PATH} {INTF}", "BUSNAME", | 
|  | 38 | instance.busName, "PATH", instance.path, "INTF", | 
|  | 39 | instance.interface); | 
| Andrew Jeffery | 47af65a | 2021-12-01 14:16:31 +1030 | [diff] [blame] | 40 | return; | 
|  | 41 | } | 
|  | 42 |  | 
| Christopher Meis | cf6a75b | 2025-06-03 07:53:50 +0200 | [diff] [blame] | 43 | scan->_em.systemBus->async_method_call( | 
| Alexander Hansen | a555acf | 2025-06-27 11:59:10 +0200 | [diff] [blame] | 44 | [instance, scan, probeVector, retries, | 
|  | 45 | &io](boost::system::error_code& errc, const DBusInterface& resp) { | 
| Patrick Williams | b707743 | 2024-08-16 15:22:21 -0400 | [diff] [blame] | 46 | if (errc) | 
|  | 47 | { | 
| Alexander Hansen | 8feb045 | 2025-09-15 14:29:20 +0200 | [diff] [blame] | 48 | lg2::error("error calling getall on {BUSNAME} {PATH} {INTF}", | 
|  | 49 | "BUSNAME", instance.busName, "PATH", instance.path, | 
|  | 50 | "INTF", instance.interface); | 
| Andrew Jeffery | 47af65a | 2021-12-01 14:16:31 +1030 | [diff] [blame] | 51 |  | 
| Patrick Williams | b707743 | 2024-08-16 15:22:21 -0400 | [diff] [blame] | 52 | auto timer = std::make_shared<boost::asio::steady_timer>(io); | 
|  | 53 | timer->expires_after(std::chrono::seconds(2)); | 
| Andrew Jeffery | 47af65a | 2021-12-01 14:16:31 +1030 | [diff] [blame] | 54 |  | 
| Alexander Hansen | a555acf | 2025-06-27 11:59:10 +0200 | [diff] [blame] | 55 | timer->async_wait([timer, instance, scan, probeVector, retries, | 
|  | 56 | &io](const boost::system::error_code&) { | 
|  | 57 | getInterfaces(instance, probeVector, scan, io, retries - 1); | 
| Patrick Williams | b707743 | 2024-08-16 15:22:21 -0400 | [diff] [blame] | 58 | }); | 
|  | 59 | return; | 
|  | 60 | } | 
| Andrew Jeffery | 47af65a | 2021-12-01 14:16:31 +1030 | [diff] [blame] | 61 |  | 
| Patrick Williams | b707743 | 2024-08-16 15:22:21 -0400 | [diff] [blame] | 62 | scan->dbusProbeObjects[instance.path][instance.interface] = resp; | 
|  | 63 | }, | 
| Andrew Jeffery | d9b6784 | 2022-04-05 16:44:20 +0930 | [diff] [blame] | 64 | instance.busName, instance.path, "org.freedesktop.DBus.Properties", | 
|  | 65 | "GetAll", instance.interface); | 
| Andrew Jeffery | 47af65a | 2021-12-01 14:16:31 +1030 | [diff] [blame] | 66 | } | 
|  | 67 |  | 
| Patrick Williams | 5a80703 | 2025-03-03 11:20:39 -0500 | [diff] [blame] | 68 | static void processDbusObjects( | 
| Christopher Meis | 26fbbd5 | 2025-03-26 14:55:06 +0100 | [diff] [blame] | 69 | std::vector<std::shared_ptr<probe::PerformProbe>>& probeVector, | 
|  | 70 | const std::shared_ptr<scan::PerformScan>& scan, | 
| Alexander Hansen | a555acf | 2025-06-27 11:59:10 +0200 | [diff] [blame] | 71 | const GetSubTreeType& interfaceSubtree, boost::asio::io_context& io) | 
| Andrew Jeffery | 8d2761e | 2022-04-05 16:26:28 +0930 | [diff] [blame] | 72 | { | 
| Andrew Jeffery | 8d2761e | 2022-04-05 16:26:28 +0930 | [diff] [blame] | 73 | for (const auto& [path, object] : interfaceSubtree) | 
|  | 74 | { | 
| Andrew Jeffery | 4732183 | 2022-04-05 16:30:29 +0930 | [diff] [blame] | 75 | // Get a PropertiesChanged callback for all interfaces on this path. | 
| Christopher Meis | cf6a75b | 2025-06-03 07:53:50 +0200 | [diff] [blame] | 76 | scan->_em.registerCallback(path); | 
| Andrew Jeffery | 4732183 | 2022-04-05 16:30:29 +0930 | [diff] [blame] | 77 |  | 
| Andrew Jeffery | 8d2761e | 2022-04-05 16:26:28 +0930 | [diff] [blame] | 78 | for (const auto& [busname, ifaces] : object) | 
|  | 79 | { | 
|  | 80 | for (const std::string& iface : ifaces) | 
|  | 81 | { | 
|  | 82 | // The 3 default org.freedeskstop interfaces (Peer, | 
|  | 83 | // Introspectable, and Properties) are returned by | 
|  | 84 | // the mapper but don't have properties, so don't bother | 
|  | 85 | // with the GetAll call to save some cycles. | 
| George Liu | 164af2f | 2025-08-21 17:16:31 +0800 | [diff] [blame] | 86 | if (!iface.starts_with("org.freedesktop")) | 
| Andrew Jeffery | 8d2761e | 2022-04-05 16:26:28 +0930 | [diff] [blame] | 87 | { | 
| Alexander Hansen | a555acf | 2025-06-27 11:59:10 +0200 | [diff] [blame] | 88 | getInterfaces({busname, path, iface}, probeVector, scan, | 
|  | 89 | io); | 
| Andrew Jeffery | 8d2761e | 2022-04-05 16:26:28 +0930 | [diff] [blame] | 90 | } | 
|  | 91 | } | 
|  | 92 | } | 
| Andrew Jeffery | 8d2761e | 2022-04-05 16:26:28 +0930 | [diff] [blame] | 93 | } | 
|  | 94 | } | 
|  | 95 |  | 
| Andrew Jeffery | 47af65a | 2021-12-01 14:16:31 +1030 | [diff] [blame] | 96 | // Populates scan->dbusProbeObjects with all interfaces and properties | 
|  | 97 | // for the paths that own the interfaces passed in. | 
| Christopher Meis | 26fbbd5 | 2025-03-26 14:55:06 +0100 | [diff] [blame] | 98 | void findDbusObjects( | 
|  | 99 | std::vector<std::shared_ptr<probe::PerformProbe>>&& probeVector, | 
|  | 100 | boost::container::flat_set<std::string>&& interfaces, | 
| Alexander Hansen | a555acf | 2025-06-27 11:59:10 +0200 | [diff] [blame] | 101 | const std::shared_ptr<scan::PerformScan>& scan, boost::asio::io_context& io, | 
|  | 102 | size_t retries = 5) | 
| Andrew Jeffery | 47af65a | 2021-12-01 14:16:31 +1030 | [diff] [blame] | 103 | { | 
|  | 104 | // Filter out interfaces already obtained. | 
|  | 105 | for (const auto& [path, probeInterfaces] : scan->dbusProbeObjects) | 
|  | 106 | { | 
|  | 107 | for (const auto& [interface, _] : probeInterfaces) | 
|  | 108 | { | 
|  | 109 | interfaces.erase(interface); | 
|  | 110 | } | 
|  | 111 | } | 
|  | 112 | if (interfaces.empty()) | 
|  | 113 | { | 
|  | 114 | return; | 
|  | 115 | } | 
|  | 116 |  | 
|  | 117 | // find all connections in the mapper that expose a specific type | 
| Christopher Meis | cf6a75b | 2025-06-03 07:53:50 +0200 | [diff] [blame] | 118 | scan->_em.systemBus->async_method_call( | 
| Alexander Hansen | a555acf | 2025-06-27 11:59:10 +0200 | [diff] [blame] | 119 | [interfaces, probeVector{std::move(probeVector)}, scan, retries, | 
|  | 120 | &io](boost::system::error_code& ec, | 
|  | 121 | const GetSubTreeType& interfaceSubtree) mutable { | 
| Patrick Williams | b707743 | 2024-08-16 15:22:21 -0400 | [diff] [blame] | 122 | if (ec) | 
| Andrew Jeffery | 47af65a | 2021-12-01 14:16:31 +1030 | [diff] [blame] | 123 | { | 
| Patrick Williams | b707743 | 2024-08-16 15:22:21 -0400 | [diff] [blame] | 124 | if (ec.value() == ENOENT) | 
|  | 125 | { | 
|  | 126 | return; // wasn't found by mapper | 
|  | 127 | } | 
| Alexander Hansen | 8feb045 | 2025-09-15 14:29:20 +0200 | [diff] [blame] | 128 | lg2::error("Error communicating to mapper."); | 
| Andrew Jeffery | 47af65a | 2021-12-01 14:16:31 +1030 | [diff] [blame] | 129 |  | 
| Patrick Williams | b707743 | 2024-08-16 15:22:21 -0400 | [diff] [blame] | 130 | if (retries == 0U) | 
|  | 131 | { | 
|  | 132 | // if we can't communicate to the mapper something is very | 
|  | 133 | // wrong | 
|  | 134 | std::exit(EXIT_FAILURE); | 
|  | 135 | } | 
|  | 136 |  | 
|  | 137 | auto timer = std::make_shared<boost::asio::steady_timer>(io); | 
|  | 138 | timer->expires_after(std::chrono::seconds(10)); | 
|  | 139 |  | 
|  | 140 | timer->async_wait( | 
|  | 141 | [timer, interfaces{std::move(interfaces)}, scan, | 
| Alexander Hansen | a555acf | 2025-06-27 11:59:10 +0200 | [diff] [blame] | 142 | probeVector{std::move(probeVector)}, retries, | 
|  | 143 | &io](const boost::system::error_code&) mutable { | 
| Patrick Williams | b707743 | 2024-08-16 15:22:21 -0400 | [diff] [blame] | 144 | findDbusObjects(std::move(probeVector), | 
| Alexander Hansen | a555acf | 2025-06-27 11:59:10 +0200 | [diff] [blame] | 145 | std::move(interfaces), scan, io, | 
| Patrick Williams | b707743 | 2024-08-16 15:22:21 -0400 | [diff] [blame] | 146 | retries - 1); | 
|  | 147 | }); | 
|  | 148 | return; | 
| Andrew Jeffery | 47af65a | 2021-12-01 14:16:31 +1030 | [diff] [blame] | 149 | } | 
|  | 150 |  | 
| Alexander Hansen | a555acf | 2025-06-27 11:59:10 +0200 | [diff] [blame] | 151 | processDbusObjects(probeVector, scan, interfaceSubtree, io); | 
| Patrick Williams | b707743 | 2024-08-16 15:22:21 -0400 | [diff] [blame] | 152 | }, | 
| Andrew Jeffery | 47af65a | 2021-12-01 14:16:31 +1030 | [diff] [blame] | 153 | "xyz.openbmc_project.ObjectMapper", | 
|  | 154 | "/xyz/openbmc_project/object_mapper", | 
|  | 155 | "xyz.openbmc_project.ObjectMapper", "GetSubTree", "/", maxMapperDepth, | 
|  | 156 | interfaces); | 
| Andrew Jeffery | 47af65a | 2021-12-01 14:16:31 +1030 | [diff] [blame] | 157 | } | 
|  | 158 |  | 
| Andrew Jeffery | 09a09a6 | 2022-04-12 22:49:57 +0930 | [diff] [blame] | 159 | static std::string getRecordName(const DBusInterface& probe, | 
|  | 160 | const std::string& probeName) | 
| Andrew Jeffery | 47af65a | 2021-12-01 14:16:31 +1030 | [diff] [blame] | 161 | { | 
|  | 162 | if (probe.empty()) | 
|  | 163 | { | 
|  | 164 | return probeName; | 
|  | 165 | } | 
|  | 166 |  | 
| Andrew Jeffery | 928c5b2 | 2022-04-05 16:57:51 +0930 | [diff] [blame] | 167 | // use an array so alphabetical order from the flat_map is maintained | 
| Andrew Jeffery | 47af65a | 2021-12-01 14:16:31 +1030 | [diff] [blame] | 168 | auto device = nlohmann::json::array(); | 
| Ed Tanous | 3013fb4 | 2022-07-09 08:27:06 -0700 | [diff] [blame] | 169 | for (const auto& devPair : probe) | 
| Andrew Jeffery | 47af65a | 2021-12-01 14:16:31 +1030 | [diff] [blame] | 170 | { | 
|  | 171 | device.push_back(devPair.first); | 
|  | 172 | std::visit([&device](auto&& v) { device.push_back(v); }, | 
|  | 173 | devPair.second); | 
|  | 174 | } | 
| Andrew Jeffery | 8650187 | 2022-04-05 16:58:22 +0930 | [diff] [blame] | 175 |  | 
| Andrew Jeffery | 928c5b2 | 2022-04-05 16:57:51 +0930 | [diff] [blame] | 176 | // hashes are hard to distinguish, use the non-hashed version if we want | 
|  | 177 | // debug | 
| Alexander Hansen | c3db2c3 | 2024-08-20 15:01:38 +0200 | [diff] [blame] | 178 | // return probeName + device.dump(); | 
| Andrew Jeffery | 1ae4ed6 | 2022-04-05 16:55:43 +0930 | [diff] [blame] | 179 |  | 
| Andrew Jeffery | 8650187 | 2022-04-05 16:58:22 +0930 | [diff] [blame] | 180 | return std::to_string(std::hash<std::string>{}(probeName + device.dump())); | 
| Andrew Jeffery | 47af65a | 2021-12-01 14:16:31 +1030 | [diff] [blame] | 181 | } | 
|  | 182 |  | 
| Alexander Hansen | a555acf | 2025-06-27 11:59:10 +0200 | [diff] [blame] | 183 | scan::PerformScan::PerformScan( | 
|  | 184 | EntityManager& em, nlohmann::json& missingConfigurations, | 
| Christopher Meis | f725257 | 2025-06-11 13:22:05 +0200 | [diff] [blame] | 185 | std::vector<nlohmann::json>& configurations, boost::asio::io_context& io, | 
| Alexander Hansen | a555acf | 2025-06-27 11:59:10 +0200 | [diff] [blame] | 186 | std::function<void()>&& callback) : | 
| Christopher Meis | cf6a75b | 2025-06-03 07:53:50 +0200 | [diff] [blame] | 187 | _em(em), _missingConfigurations(missingConfigurations), | 
| Alexander Hansen | a555acf | 2025-06-27 11:59:10 +0200 | [diff] [blame] | 188 | _configurations(configurations), _callback(std::move(callback)), io(io) | 
| Andrew Jeffery | 47af65a | 2021-12-01 14:16:31 +1030 | [diff] [blame] | 189 | {} | 
| Andrew Jeffery | db45148 | 2022-04-13 16:53:22 +0930 | [diff] [blame] | 190 |  | 
| Andrew Jeffery | 7a7faed | 2022-04-13 17:24:56 +0930 | [diff] [blame] | 191 | static void pruneRecordExposes(nlohmann::json& record) | 
| Andrew Jeffery | db45148 | 2022-04-13 16:53:22 +0930 | [diff] [blame] | 192 | { | 
| Andrew Jeffery | 7a7faed | 2022-04-13 17:24:56 +0930 | [diff] [blame] | 193 | auto findExposes = record.find("Exposes"); | 
| Andrew Jeffery | 5f05145 | 2022-04-13 17:11:37 +0930 | [diff] [blame] | 194 | if (findExposes == record.end()) | 
| Andrew Jeffery | db45148 | 2022-04-13 16:53:22 +0930 | [diff] [blame] | 195 | { | 
| Andrew Jeffery | 5f05145 | 2022-04-13 17:11:37 +0930 | [diff] [blame] | 196 | return; | 
| Andrew Jeffery | db45148 | 2022-04-13 16:53:22 +0930 | [diff] [blame] | 197 | } | 
| Andrew Jeffery | 5f05145 | 2022-04-13 17:11:37 +0930 | [diff] [blame] | 198 |  | 
|  | 199 | auto copy = nlohmann::json::array(); | 
|  | 200 | for (auto& expose : *findExposes) | 
|  | 201 | { | 
| Andrew Jeffery | 742a7eb | 2022-04-13 17:14:46 +0930 | [diff] [blame] | 202 | if (!expose.is_null()) | 
| Andrew Jeffery | 5f05145 | 2022-04-13 17:11:37 +0930 | [diff] [blame] | 203 | { | 
| Andrew Jeffery | 742a7eb | 2022-04-13 17:14:46 +0930 | [diff] [blame] | 204 | copy.emplace_back(expose); | 
| Andrew Jeffery | 5f05145 | 2022-04-13 17:11:37 +0930 | [diff] [blame] | 205 | } | 
| Andrew Jeffery | 5f05145 | 2022-04-13 17:11:37 +0930 | [diff] [blame] | 206 | } | 
|  | 207 | *findExposes = copy; | 
| Andrew Jeffery | db45148 | 2022-04-13 16:53:22 +0930 | [diff] [blame] | 208 | } | 
|  | 209 |  | 
| Patrick Williams | b707743 | 2024-08-16 15:22:21 -0400 | [diff] [blame] | 210 | static void recordDiscoveredIdentifiers( | 
|  | 211 | std::set<nlohmann::json>& usedNames, std::list<size_t>& indexes, | 
|  | 212 | const std::string& probeName, const nlohmann::json& record) | 
| Andrew Jeffery | 6addc02 | 2022-04-13 18:08:58 +0930 | [diff] [blame] | 213 | { | 
|  | 214 | size_t indexIdx = probeName.find('$'); | 
| Andrew Jeffery | ba41b62 | 2022-04-13 18:13:28 +0930 | [diff] [blame] | 215 | if (indexIdx == std::string::npos) | 
| Andrew Jeffery | 6addc02 | 2022-04-13 18:08:58 +0930 | [diff] [blame] | 216 | { | 
|  | 217 | return; | 
|  | 218 | } | 
|  | 219 |  | 
| Andrew Jeffery | c0da0cc | 2022-04-13 18:15:09 +0930 | [diff] [blame] | 220 | auto nameIt = record.find("Name"); | 
|  | 221 | if (nameIt == record.end()) | 
| Andrew Jeffery | 6addc02 | 2022-04-13 18:08:58 +0930 | [diff] [blame] | 222 | { | 
| Alexander Hansen | 8feb045 | 2025-09-15 14:29:20 +0200 | [diff] [blame] | 223 | lg2::error("Last JSON Illegal"); | 
| Andrew Jeffery | 6addc02 | 2022-04-13 18:08:58 +0930 | [diff] [blame] | 224 | return; | 
|  | 225 | } | 
|  | 226 |  | 
|  | 227 | int index = 0; | 
|  | 228 | auto str = nameIt->get<std::string>().substr(indexIdx); | 
| Ed Tanous | 3013fb4 | 2022-07-09 08:27:06 -0700 | [diff] [blame] | 229 | // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) | 
|  | 230 | const char* endPtr = str.data() + str.size(); | 
|  | 231 | auto [p, ec] = std::from_chars(str.data(), endPtr, index); | 
| Andrew Jeffery | 6addc02 | 2022-04-13 18:08:58 +0930 | [diff] [blame] | 232 | if (ec != std::errc()) | 
|  | 233 | { | 
|  | 234 | return; // non-numeric replacement | 
|  | 235 | } | 
|  | 236 |  | 
|  | 237 | usedNames.insert(nameIt.value()); | 
|  | 238 |  | 
|  | 239 | auto usedIt = std::find(indexes.begin(), indexes.end(), index); | 
|  | 240 | if (usedIt != indexes.end()) | 
|  | 241 | { | 
|  | 242 | indexes.erase(usedIt); | 
|  | 243 | } | 
|  | 244 | } | 
|  | 245 |  | 
| Andrew Jeffery | 6890ae2 | 2022-04-14 15:33:01 +0930 | [diff] [blame] | 246 | static bool extractExposeActionRecordNames(std::vector<std::string>& matches, | 
|  | 247 | nlohmann::json::iterator& keyPair) | 
|  | 248 | { | 
| Andrew Jeffery | a244984 | 2022-04-14 15:35:51 +0930 | [diff] [blame] | 249 | if (keyPair.value().is_string()) | 
| Andrew Jeffery | 6890ae2 | 2022-04-14 15:33:01 +0930 | [diff] [blame] | 250 | { | 
|  | 251 | matches.emplace_back(keyPair.value()); | 
| Andrew Jeffery | ba3c50c | 2022-04-14 15:34:38 +0930 | [diff] [blame] | 252 | return true; | 
| Andrew Jeffery | 6890ae2 | 2022-04-14 15:33:01 +0930 | [diff] [blame] | 253 | } | 
| Andrew Jeffery | ba3c50c | 2022-04-14 15:34:38 +0930 | [diff] [blame] | 254 |  | 
| Andrew Jeffery | a244984 | 2022-04-14 15:35:51 +0930 | [diff] [blame] | 255 | if (keyPair.value().is_array()) | 
| Andrew Jeffery | 6890ae2 | 2022-04-14 15:33:01 +0930 | [diff] [blame] | 256 | { | 
|  | 257 | for (const auto& value : keyPair.value()) | 
|  | 258 | { | 
| Andrew Jeffery | a244984 | 2022-04-14 15:35:51 +0930 | [diff] [blame] | 259 | if (!value.is_string()) | 
| Andrew Jeffery | 6890ae2 | 2022-04-14 15:33:01 +0930 | [diff] [blame] | 260 | { | 
| Alexander Hansen | 8feb045 | 2025-09-15 14:29:20 +0200 | [diff] [blame] | 261 | lg2::error("Value is invalid type {VALUE}", "VALUE", value); | 
| Andrew Jeffery | 6890ae2 | 2022-04-14 15:33:01 +0930 | [diff] [blame] | 262 | break; | 
|  | 263 | } | 
|  | 264 | matches.emplace_back(value); | 
|  | 265 | } | 
| Andrew Jeffery | 6890ae2 | 2022-04-14 15:33:01 +0930 | [diff] [blame] | 266 |  | 
| Andrew Jeffery | ba3c50c | 2022-04-14 15:34:38 +0930 | [diff] [blame] | 267 | return true; | 
| Andrew Jeffery | 6890ae2 | 2022-04-14 15:33:01 +0930 | [diff] [blame] | 268 | } | 
|  | 269 |  | 
| Alexander Hansen | 8feb045 | 2025-09-15 14:29:20 +0200 | [diff] [blame] | 270 | lg2::error("Value is invalid type {KEY}", "KEY", keyPair.key()); | 
| Andrew Jeffery | ba3c50c | 2022-04-14 15:34:38 +0930 | [diff] [blame] | 271 |  | 
|  | 272 | return false; | 
| Andrew Jeffery | 6890ae2 | 2022-04-14 15:33:01 +0930 | [diff] [blame] | 273 | } | 
|  | 274 |  | 
| Patrick Williams | b707743 | 2024-08-16 15:22:21 -0400 | [diff] [blame] | 275 | static std::optional<std::vector<std::string>::iterator> findExposeActionRecord( | 
|  | 276 | std::vector<std::string>& matches, const nlohmann::json& record) | 
| Andrew Jeffery | 6de53fb | 2022-04-14 15:45:38 +0930 | [diff] [blame] | 277 | { | 
| Andrew Jeffery | 1a02da8 | 2022-04-14 20:39:06 +0930 | [diff] [blame] | 278 | const auto& name = (record)["Name"].get_ref<const std::string&>(); | 
|  | 279 | auto compare = [&name](const std::string& s) { return s == name; }; | 
|  | 280 | auto matchIt = std::find_if(matches.begin(), matches.end(), compare); | 
| Andrew Jeffery | 6de53fb | 2022-04-14 15:45:38 +0930 | [diff] [blame] | 281 |  | 
|  | 282 | if (matchIt == matches.end()) | 
|  | 283 | { | 
|  | 284 | return std::nullopt; | 
|  | 285 | } | 
|  | 286 |  | 
|  | 287 | return matchIt; | 
|  | 288 | } | 
|  | 289 |  | 
| Andrew Jeffery | cf11bd3 | 2022-04-14 18:34:31 +0930 | [diff] [blame] | 290 | static void applyBindExposeAction(nlohmann::json& exposedObject, | 
|  | 291 | nlohmann::json& expose, | 
|  | 292 | const std::string& propertyName) | 
|  | 293 | { | 
| George Liu | 164af2f | 2025-08-21 17:16:31 +0800 | [diff] [blame] | 294 | if (propertyName.starts_with("Bind")) | 
| Andrew Jeffery | cf11bd3 | 2022-04-14 18:34:31 +0930 | [diff] [blame] | 295 | { | 
|  | 296 | std::string bind = propertyName.substr(sizeof("Bind") - 1); | 
|  | 297 | exposedObject["Status"] = "okay"; | 
|  | 298 | expose[bind] = exposedObject; | 
|  | 299 | } | 
|  | 300 | } | 
|  | 301 |  | 
|  | 302 | static void applyDisableExposeAction(nlohmann::json& exposedObject, | 
|  | 303 | const std::string& propertyName) | 
|  | 304 | { | 
|  | 305 | if (propertyName == "DisableNode") | 
|  | 306 | { | 
|  | 307 | exposedObject["Status"] = "disabled"; | 
|  | 308 | } | 
|  | 309 | } | 
|  | 310 |  | 
| Patrick Williams | b707743 | 2024-08-16 15:22:21 -0400 | [diff] [blame] | 311 | static void applyConfigExposeActions( | 
|  | 312 | std::vector<std::string>& matches, nlohmann::json& expose, | 
|  | 313 | const std::string& propertyName, nlohmann::json& configExposes) | 
| Andrew Jeffery | 5468f8e | 2022-04-14 21:08:31 +0930 | [diff] [blame] | 314 | { | 
| Andrew Jeffery | da45e5e | 2022-04-14 21:12:02 +0930 | [diff] [blame] | 315 | for (auto& exposedObject : configExposes) | 
| Andrew Jeffery | 5468f8e | 2022-04-14 21:08:31 +0930 | [diff] [blame] | 316 | { | 
|  | 317 | auto match = findExposeActionRecord(matches, exposedObject); | 
| Andrew Jeffery | 060ac9c | 2022-04-14 21:11:18 +0930 | [diff] [blame] | 318 | if (match) | 
| Andrew Jeffery | 5468f8e | 2022-04-14 21:08:31 +0930 | [diff] [blame] | 319 | { | 
| Andrew Jeffery | 060ac9c | 2022-04-14 21:11:18 +0930 | [diff] [blame] | 320 | matches.erase(*match); | 
|  | 321 | applyBindExposeAction(exposedObject, expose, propertyName); | 
|  | 322 | applyDisableExposeAction(exposedObject, propertyName); | 
| Andrew Jeffery | 5468f8e | 2022-04-14 21:08:31 +0930 | [diff] [blame] | 323 | } | 
| Andrew Jeffery | 5468f8e | 2022-04-14 21:08:31 +0930 | [diff] [blame] | 324 | } | 
|  | 325 | } | 
|  | 326 |  | 
| Patrick Williams | b707743 | 2024-08-16 15:22:21 -0400 | [diff] [blame] | 327 | static void applyExposeActions( | 
|  | 328 | nlohmann::json& systemConfiguration, const std::string& recordName, | 
|  | 329 | nlohmann::json& expose, nlohmann::json::iterator& keyPair) | 
| Andrew Jeffery | b48779d | 2022-04-14 21:40:31 +0930 | [diff] [blame] | 330 | { | 
| George Liu | 164af2f | 2025-08-21 17:16:31 +0800 | [diff] [blame] | 331 | bool isBind = keyPair.key().starts_with("Bind"); | 
| Andrew Jeffery | b48779d | 2022-04-14 21:40:31 +0930 | [diff] [blame] | 332 | bool isDisable = keyPair.key() == "DisableNode"; | 
|  | 333 | bool isExposeAction = isBind || isDisable; | 
|  | 334 |  | 
|  | 335 | if (!isExposeAction) | 
|  | 336 | { | 
|  | 337 | return; | 
|  | 338 | } | 
|  | 339 |  | 
|  | 340 | std::vector<std::string> matches; | 
|  | 341 |  | 
|  | 342 | if (!extractExposeActionRecordNames(matches, keyPair)) | 
|  | 343 | { | 
|  | 344 | return; | 
|  | 345 | } | 
|  | 346 |  | 
| Patrick Williams | 2594d36 | 2022-09-28 06:46:24 -0500 | [diff] [blame] | 347 | for (const auto& [configId, config] : systemConfiguration.items()) | 
| Andrew Jeffery | b48779d | 2022-04-14 21:40:31 +0930 | [diff] [blame] | 348 | { | 
|  | 349 | // don't disable ourselves | 
|  | 350 | if (isDisable && configId == recordName) | 
|  | 351 | { | 
|  | 352 | continue; | 
|  | 353 | } | 
|  | 354 |  | 
|  | 355 | auto configListFind = config.find("Exposes"); | 
|  | 356 | if (configListFind == config.end()) | 
|  | 357 | { | 
|  | 358 | continue; | 
|  | 359 | } | 
|  | 360 |  | 
|  | 361 | if (!configListFind->is_array()) | 
|  | 362 | { | 
|  | 363 | continue; | 
|  | 364 | } | 
|  | 365 |  | 
|  | 366 | applyConfigExposeActions(matches, expose, keyPair.key(), | 
|  | 367 | *configListFind); | 
|  | 368 | } | 
|  | 369 |  | 
|  | 370 | if (!matches.empty()) | 
|  | 371 | { | 
| Alexander Hansen | 8feb045 | 2025-09-15 14:29:20 +0200 | [diff] [blame] | 372 | lg2::error( | 
|  | 373 | "configuration file dependency error, could not find {KEY} {VALUE}", | 
|  | 374 | "KEY", keyPair.key(), "VALUE", keyPair.value()); | 
| Andrew Jeffery | b48779d | 2022-04-14 21:40:31 +0930 | [diff] [blame] | 375 | } | 
|  | 376 | } | 
|  | 377 |  | 
| Patrick Williams | b707743 | 2024-08-16 15:22:21 -0400 | [diff] [blame] | 378 | static std::string generateDeviceName( | 
|  | 379 | const std::set<nlohmann::json>& usedNames, const DBusObject& dbusObject, | 
|  | 380 | size_t foundDeviceIdx, const std::string& nameTemplate, | 
|  | 381 | std::optional<std::string>& replaceStr) | 
| Andrew Jeffery | dabee98 | 2022-04-19 13:27:24 +0930 | [diff] [blame] | 382 | { | 
|  | 383 | nlohmann::json copyForName = {{"Name", nameTemplate}}; | 
|  | 384 | nlohmann::json::iterator copyIt = copyForName.begin(); | 
| Christopher Meis | 59ef1e7 | 2025-04-16 08:53:25 +0200 | [diff] [blame] | 385 | std::optional<std::string> replaceVal = em_utils::templateCharReplace( | 
|  | 386 | copyIt, dbusObject, foundDeviceIdx, replaceStr); | 
| Andrew Jeffery | dabee98 | 2022-04-19 13:27:24 +0930 | [diff] [blame] | 387 |  | 
|  | 388 | if (!replaceStr && replaceVal) | 
|  | 389 | { | 
| Patrick Williams | 6459993 | 2025-05-14 07:24:20 -0400 | [diff] [blame] | 390 | if (usedNames.contains(copyIt.value())) | 
| Andrew Jeffery | dabee98 | 2022-04-19 13:27:24 +0930 | [diff] [blame] | 391 | { | 
|  | 392 | replaceStr = replaceVal; | 
|  | 393 | copyForName = {{"Name", nameTemplate}}; | 
|  | 394 | copyIt = copyForName.begin(); | 
| Christopher Meis | 59ef1e7 | 2025-04-16 08:53:25 +0200 | [diff] [blame] | 395 | em_utils::templateCharReplace(copyIt, dbusObject, foundDeviceIdx, | 
|  | 396 | replaceStr); | 
| Andrew Jeffery | dabee98 | 2022-04-19 13:27:24 +0930 | [diff] [blame] | 397 | } | 
|  | 398 | } | 
|  | 399 |  | 
|  | 400 | if (replaceStr) | 
|  | 401 | { | 
| Alexander Hansen | 8feb045 | 2025-09-15 14:29:20 +0200 | [diff] [blame] | 402 | lg2::error( | 
|  | 403 | "Duplicates found, replacing {STR} with found device index. Consider fixing template to not have duplicates", | 
|  | 404 | "STR", *replaceStr); | 
| Andrew Jeffery | dabee98 | 2022-04-19 13:27:24 +0930 | [diff] [blame] | 405 | } | 
|  | 406 |  | 
|  | 407 | return copyIt.value(); | 
|  | 408 | } | 
|  | 409 |  | 
| Christopher Meis | 26fbbd5 | 2025-03-26 14:55:06 +0100 | [diff] [blame] | 410 | void scan::PerformScan::updateSystemConfiguration( | 
|  | 411 | const nlohmann::json& recordRef, const std::string& probeName, | 
|  | 412 | FoundDevices& foundDevices) | 
| Andrew Jeffery | ae6c1a4 | 2022-04-19 15:44:42 +0930 | [diff] [blame] | 413 | { | 
|  | 414 | _passed = true; | 
|  | 415 | passedProbes.push_back(probeName); | 
|  | 416 |  | 
|  | 417 | std::set<nlohmann::json> usedNames; | 
|  | 418 | std::list<size_t> indexes(foundDevices.size()); | 
|  | 419 | std::iota(indexes.begin(), indexes.end(), 1); | 
|  | 420 |  | 
|  | 421 | // copy over persisted configurations and make sure we remove | 
|  | 422 | // indexes that are already used | 
|  | 423 | for (auto itr = foundDevices.begin(); itr != foundDevices.end();) | 
|  | 424 | { | 
|  | 425 | std::string recordName = getRecordName(itr->interface, probeName); | 
|  | 426 |  | 
| Christopher Meis | cf6a75b | 2025-06-03 07:53:50 +0200 | [diff] [blame] | 427 | auto record = _em.systemConfiguration.find(recordName); | 
|  | 428 | if (record == _em.systemConfiguration.end()) | 
| Andrew Jeffery | ae6c1a4 | 2022-04-19 15:44:42 +0930 | [diff] [blame] | 429 | { | 
| Christopher Meis | cf6a75b | 2025-06-03 07:53:50 +0200 | [diff] [blame] | 430 | record = _em.lastJson.find(recordName); | 
|  | 431 | if (record == _em.lastJson.end()) | 
| Zhikui Ren | 1f77d9c | 2022-08-29 16:02:37 -0700 | [diff] [blame] | 432 | { | 
|  | 433 | itr++; | 
|  | 434 | continue; | 
|  | 435 | } | 
|  | 436 |  | 
|  | 437 | pruneRecordExposes(*record); | 
|  | 438 |  | 
| Christopher Meis | cf6a75b | 2025-06-03 07:53:50 +0200 | [diff] [blame] | 439 | _em.systemConfiguration[recordName] = *record; | 
| Andrew Jeffery | ae6c1a4 | 2022-04-19 15:44:42 +0930 | [diff] [blame] | 440 | } | 
| Andrew Jeffery | ae6c1a4 | 2022-04-19 15:44:42 +0930 | [diff] [blame] | 441 | _missingConfigurations.erase(recordName); | 
|  | 442 |  | 
|  | 443 | // We've processed the device, remove it and advance the | 
|  | 444 | // iterator | 
|  | 445 | itr = foundDevices.erase(itr); | 
| JinFuLin | 8f05a3a | 2022-11-21 15:33:24 +0800 | [diff] [blame] | 446 | recordDiscoveredIdentifiers(usedNames, indexes, probeName, *record); | 
| Andrew Jeffery | ae6c1a4 | 2022-04-19 15:44:42 +0930 | [diff] [blame] | 447 | } | 
|  | 448 |  | 
|  | 449 | std::optional<std::string> replaceStr; | 
|  | 450 |  | 
|  | 451 | DBusObject emptyObject; | 
|  | 452 | DBusInterface emptyInterface; | 
|  | 453 | emptyObject.emplace(std::string{}, emptyInterface); | 
|  | 454 |  | 
|  | 455 | for (const auto& [foundDevice, path] : foundDevices) | 
|  | 456 | { | 
|  | 457 | // Need all interfaces on this path so that template | 
|  | 458 | // substitutions can be done with any of the contained | 
|  | 459 | // properties.  If the probe that passed didn't use an | 
|  | 460 | // interface, such as if it was just TRUE, then | 
|  | 461 | // templateCharReplace will just get passed in an empty | 
|  | 462 | // map. | 
| Andrew Jeffery | af9b46b | 2022-04-21 12:34:43 +0930 | [diff] [blame] | 463 | auto objectIt = dbusProbeObjects.find(path); | 
|  | 464 | const DBusObject& dbusObject = (objectIt == dbusProbeObjects.end()) | 
|  | 465 | ? emptyObject | 
|  | 466 | : objectIt->second; | 
| Andrew Jeffery | ae6c1a4 | 2022-04-19 15:44:42 +0930 | [diff] [blame] | 467 |  | 
|  | 468 | nlohmann::json record = recordRef; | 
|  | 469 | std::string recordName = getRecordName(foundDevice, probeName); | 
|  | 470 | size_t foundDeviceIdx = indexes.front(); | 
|  | 471 | indexes.pop_front(); | 
|  | 472 |  | 
|  | 473 | // check name first so we have no duplicate names | 
|  | 474 | auto getName = record.find("Name"); | 
|  | 475 | if (getName == record.end()) | 
|  | 476 | { | 
| Alexander Hansen | 8feb045 | 2025-09-15 14:29:20 +0200 | [diff] [blame] | 477 | lg2::error("Record Missing Name! {JSON}", "JSON", record.dump()); | 
| Andrew Jeffery | ae6c1a4 | 2022-04-19 15:44:42 +0930 | [diff] [blame] | 478 | continue; // this should be impossible at this level | 
|  | 479 | } | 
|  | 480 |  | 
|  | 481 | std::string deviceName = generateDeviceName( | 
|  | 482 | usedNames, dbusObject, foundDeviceIdx, getName.value(), replaceStr); | 
|  | 483 | getName.value() = deviceName; | 
|  | 484 | usedNames.insert(deviceName); | 
|  | 485 |  | 
|  | 486 | for (auto keyPair = record.begin(); keyPair != record.end(); keyPair++) | 
|  | 487 | { | 
|  | 488 | if (keyPair.key() != "Name") | 
|  | 489 | { | 
| Christopher Meis | 59ef1e7 | 2025-04-16 08:53:25 +0200 | [diff] [blame] | 490 | em_utils::templateCharReplace(keyPair, dbusObject, | 
|  | 491 | foundDeviceIdx, replaceStr); | 
| Andrew Jeffery | ae6c1a4 | 2022-04-19 15:44:42 +0930 | [diff] [blame] | 492 | } | 
|  | 493 | } | 
|  | 494 |  | 
|  | 495 | // insert into configuration temporarily to be able to | 
|  | 496 | // reference ourselves | 
|  | 497 |  | 
| Christopher Meis | cf6a75b | 2025-06-03 07:53:50 +0200 | [diff] [blame] | 498 | _em.systemConfiguration[recordName] = record; | 
| Andrew Jeffery | ae6c1a4 | 2022-04-19 15:44:42 +0930 | [diff] [blame] | 499 |  | 
|  | 500 | auto findExpose = record.find("Exposes"); | 
|  | 501 | if (findExpose == record.end()) | 
|  | 502 | { | 
|  | 503 | continue; | 
|  | 504 | } | 
|  | 505 |  | 
|  | 506 | for (auto& expose : *findExpose) | 
|  | 507 | { | 
|  | 508 | for (auto keyPair = expose.begin(); keyPair != expose.end(); | 
|  | 509 | keyPair++) | 
|  | 510 | { | 
| Christopher Meis | 59ef1e7 | 2025-04-16 08:53:25 +0200 | [diff] [blame] | 511 | em_utils::templateCharReplace(keyPair, dbusObject, | 
|  | 512 | foundDeviceIdx, replaceStr); | 
| Andrew Jeffery | ae6c1a4 | 2022-04-19 15:44:42 +0930 | [diff] [blame] | 513 |  | 
| Christopher Meis | cf6a75b | 2025-06-03 07:53:50 +0200 | [diff] [blame] | 514 | applyExposeActions(_em.systemConfiguration, recordName, expose, | 
| Andrew Jeffery | ae6c1a4 | 2022-04-19 15:44:42 +0930 | [diff] [blame] | 515 | keyPair); | 
|  | 516 | } | 
|  | 517 | } | 
|  | 518 |  | 
|  | 519 | // overwrite ourselves with cleaned up version | 
| Christopher Meis | cf6a75b | 2025-06-03 07:53:50 +0200 | [diff] [blame] | 520 | _em.systemConfiguration[recordName] = record; | 
| Andrew Jeffery | ae6c1a4 | 2022-04-19 15:44:42 +0930 | [diff] [blame] | 521 | _missingConfigurations.erase(recordName); | 
|  | 522 | } | 
|  | 523 | } | 
|  | 524 |  | 
| Christopher Meis | 26fbbd5 | 2025-03-26 14:55:06 +0100 | [diff] [blame] | 525 | void scan::PerformScan::run() | 
| Andrew Jeffery | 47af65a | 2021-12-01 14:16:31 +1030 | [diff] [blame] | 526 | { | 
|  | 527 | boost::container::flat_set<std::string> dbusProbeInterfaces; | 
| Christopher Meis | 26fbbd5 | 2025-03-26 14:55:06 +0100 | [diff] [blame] | 528 | std::vector<std::shared_ptr<probe::PerformProbe>> dbusProbePointers; | 
| Andrew Jeffery | 47af65a | 2021-12-01 14:16:31 +1030 | [diff] [blame] | 529 |  | 
|  | 530 | for (auto it = _configurations.begin(); it != _configurations.end();) | 
|  | 531 | { | 
| Andrew Jeffery | 47af65a | 2021-12-01 14:16:31 +1030 | [diff] [blame] | 532 | // check for poorly formatted fields, probe must be an array | 
| Andrew Jeffery | 3883487 | 2022-04-19 15:15:57 +0930 | [diff] [blame] | 533 | auto findProbe = it->find("Probe"); | 
| Andrew Jeffery | 47af65a | 2021-12-01 14:16:31 +1030 | [diff] [blame] | 534 | if (findProbe == it->end()) | 
|  | 535 | { | 
| Alexander Hansen | 8feb045 | 2025-09-15 14:29:20 +0200 | [diff] [blame] | 536 | lg2::error("configuration file missing probe:\n {JSON}", "JSON", | 
|  | 537 | *it); | 
| Andrew Jeffery | 47af65a | 2021-12-01 14:16:31 +1030 | [diff] [blame] | 538 | it = _configurations.erase(it); | 
|  | 539 | continue; | 
|  | 540 | } | 
| Andrew Jeffery | 47af65a | 2021-12-01 14:16:31 +1030 | [diff] [blame] | 541 |  | 
| Andrew Jeffery | 3883487 | 2022-04-19 15:15:57 +0930 | [diff] [blame] | 542 | auto findName = it->find("Name"); | 
| Andrew Jeffery | 47af65a | 2021-12-01 14:16:31 +1030 | [diff] [blame] | 543 | if (findName == it->end()) | 
|  | 544 | { | 
| Alexander Hansen | 8feb045 | 2025-09-15 14:29:20 +0200 | [diff] [blame] | 545 | lg2::error("configuration file missing name:\n {JSON}", "JSON", | 
|  | 546 | *it); | 
| Andrew Jeffery | 47af65a | 2021-12-01 14:16:31 +1030 | [diff] [blame] | 547 | it = _configurations.erase(it); | 
|  | 548 | continue; | 
|  | 549 | } | 
|  | 550 | std::string probeName = *findName; | 
|  | 551 |  | 
|  | 552 | if (std::find(passedProbes.begin(), passedProbes.end(), probeName) != | 
|  | 553 | passedProbes.end()) | 
|  | 554 | { | 
|  | 555 | it = _configurations.erase(it); | 
|  | 556 | continue; | 
|  | 557 | } | 
| Andrew Jeffery | 3883487 | 2022-04-19 15:15:57 +0930 | [diff] [blame] | 558 |  | 
| Andrew Jeffery | 98f3d53 | 2022-04-19 15:29:22 +0930 | [diff] [blame] | 559 | nlohmann::json& recordRef = *it; | 
| Andrew Jeffery | 3883487 | 2022-04-19 15:15:57 +0930 | [diff] [blame] | 560 | nlohmann::json probeCommand; | 
|  | 561 | if ((*findProbe).type() != nlohmann::json::value_t::array) | 
|  | 562 | { | 
|  | 563 | probeCommand = nlohmann::json::array(); | 
|  | 564 | probeCommand.push_back(*findProbe); | 
|  | 565 | } | 
|  | 566 | else | 
|  | 567 | { | 
|  | 568 | probeCommand = *findProbe; | 
|  | 569 | } | 
| Andrew Jeffery | 47af65a | 2021-12-01 14:16:31 +1030 | [diff] [blame] | 570 |  | 
|  | 571 | // store reference to this to children to makes sure we don't get | 
|  | 572 | // destroyed too early | 
|  | 573 | auto thisRef = shared_from_this(); | 
| Christopher Meis | 26fbbd5 | 2025-03-26 14:55:06 +0100 | [diff] [blame] | 574 | auto probePointer = std::make_shared<probe::PerformProbe>( | 
| Andrew Jeffery | ea4ff02 | 2022-04-21 12:31:40 +0930 | [diff] [blame] | 575 | recordRef, probeCommand, probeName, thisRef); | 
| Andrew Jeffery | 47af65a | 2021-12-01 14:16:31 +1030 | [diff] [blame] | 576 |  | 
|  | 577 | // parse out dbus probes by discarding other probe types, store in a | 
|  | 578 | // map | 
|  | 579 | for (const nlohmann::json& probeJson : probeCommand) | 
|  | 580 | { | 
|  | 581 | const std::string* probe = probeJson.get_ptr<const std::string*>(); | 
|  | 582 | if (probe == nullptr) | 
|  | 583 | { | 
| Alexander Hansen | 8feb045 | 2025-09-15 14:29:20 +0200 | [diff] [blame] | 584 | lg2::error("Probe statement wasn't a string, can't parse"); | 
| Andrew Jeffery | 47af65a | 2021-12-01 14:16:31 +1030 | [diff] [blame] | 585 | continue; | 
|  | 586 | } | 
| Christopher Meis | 26fbbd5 | 2025-03-26 14:55:06 +0100 | [diff] [blame] | 587 | if (probe::findProbeType(*probe)) | 
| Andrew Jeffery | 47af65a | 2021-12-01 14:16:31 +1030 | [diff] [blame] | 588 | { | 
|  | 589 | continue; | 
|  | 590 | } | 
|  | 591 | // syntax requires probe before first open brace | 
|  | 592 | auto findStart = probe->find('('); | 
|  | 593 | std::string interface = probe->substr(0, findStart); | 
|  | 594 | dbusProbeInterfaces.emplace(interface); | 
|  | 595 | dbusProbePointers.emplace_back(probePointer); | 
|  | 596 | } | 
|  | 597 | it++; | 
|  | 598 | } | 
|  | 599 |  | 
|  | 600 | // probe vector stores a shared_ptr to each PerformProbe that cares | 
|  | 601 | // about a dbus interface | 
|  | 602 | findDbusObjects(std::move(dbusProbePointers), | 
| Alexander Hansen | a555acf | 2025-06-27 11:59:10 +0200 | [diff] [blame] | 603 | std::move(dbusProbeInterfaces), shared_from_this(), io); | 
| Andrew Jeffery | 47af65a | 2021-12-01 14:16:31 +1030 | [diff] [blame] | 604 | } | 
|  | 605 |  | 
| Christopher Meis | 26fbbd5 | 2025-03-26 14:55:06 +0100 | [diff] [blame] | 606 | scan::PerformScan::~PerformScan() | 
| Andrew Jeffery | 47af65a | 2021-12-01 14:16:31 +1030 | [diff] [blame] | 607 | { | 
|  | 608 | if (_passed) | 
|  | 609 | { | 
|  | 610 | auto nextScan = std::make_shared<PerformScan>( | 
| Alexander Hansen | a555acf | 2025-06-27 11:59:10 +0200 | [diff] [blame] | 611 | _em, _missingConfigurations, _configurations, io, | 
|  | 612 | std::move(_callback)); | 
| Andrew Jeffery | 47af65a | 2021-12-01 14:16:31 +1030 | [diff] [blame] | 613 | nextScan->passedProbes = std::move(passedProbes); | 
|  | 614 | nextScan->dbusProbeObjects = std::move(dbusProbeObjects); | 
|  | 615 | nextScan->run(); | 
| Andrew Jeffery | 47af65a | 2021-12-01 14:16:31 +1030 | [diff] [blame] | 616 | } | 
|  | 617 | else | 
|  | 618 | { | 
|  | 619 | _callback(); | 
| Andrew Jeffery | 47af65a | 2021-12-01 14:16:31 +1030 | [diff] [blame] | 620 | } | 
|  | 621 | } |