EntityManager: Promote FoundDeviceT to a struct and rename

Using tuples is a readability headache. Use names provided by a struct
rather than opaque indices.

Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
Change-Id: Ifd5225ee28e0898d35193165ae379e6e7c6026da
diff --git a/include/EntityManager.hpp b/include/EntityManager.hpp
index 2b4565b..22a8042 100644
--- a/include/EntityManager.hpp
+++ b/include/EntityManager.hpp
@@ -30,8 +30,13 @@
 #include <optional>
 #include <string>
 
-// The string is the path to the object hosting the interface
-using FoundDeviceT = std::vector<std::tuple<DBusInterface, std::string>>;
+struct DBusDeviceDescriptor
+{
+    DBusInterface interface;
+    std::string path;
+};
+
+using FoundDevices = std::vector<DBusDeviceDescriptor>;
 
 struct CmpStr
 {
@@ -83,13 +88,13 @@
     PerformProbe(
         const std::vector<std::string>& probeCommand,
         std::shared_ptr<PerformScan>& scanPtr,
-        std::function<void(FoundDeviceT&, const MapperGetSubTreeResponse&)>&&
+        std::function<void(FoundDevices&, const MapperGetSubTreeResponse&)>&&
             callback);
     virtual ~PerformProbe();
 
     std::vector<std::string> _probeCommand;
     std::shared_ptr<PerformScan> scan;
-    std::function<void(FoundDeviceT&, const MapperGetSubTreeResponse&)>
+    std::function<void(FoundDevices&, const MapperGetSubTreeResponse&)>
         _callback;
 };
 
diff --git a/src/PerformProbe.cpp b/src/PerformProbe.cpp
index 690ce15..d120b3c 100644
--- a/src/PerformProbe.cpp
+++ b/src/PerformProbe.cpp
@@ -24,9 +24,9 @@
 
 // probes dbus interface dictionary for a key with a value that matches a regex
 // When an interface passes a probe, also save its D-Bus path with it.
-bool probeDbus(const std::string& interface,
+bool probeDbus(const std::string& interfaceName,
                const std::map<std::string, nlohmann::json>& matches,
-               FoundDeviceT& devices, const std::shared_ptr<PerformScan>& scan,
+               FoundDevices& devices, const std::shared_ptr<PerformScan>& scan,
                bool& foundProbe)
 {
     bool foundMatch = false;
@@ -34,7 +34,7 @@
 
     for (const auto& [path, interfaces] : scan->dbusProbeObjects)
     {
-        auto it = interfaces.find(interface);
+        auto it = interfaces.find(interfaceName);
         if (it == interfaces.end())
         {
             continue;
@@ -43,13 +43,12 @@
         foundProbe = true;
 
         bool deviceMatches = true;
-        const boost::container::flat_map<std::string, DBusValueVariant>&
-            properties = it->second;
+        const DBusInterface& interface = it->second;
 
         for (const auto& [matchProp, matchJSON] : matches)
         {
-            auto deviceValue = properties.find(matchProp);
-            if (deviceValue != properties.end())
+            auto deviceValue = interface.find(matchProp);
+            if (deviceValue != interface.end())
             {
                 deviceMatches =
                     deviceMatches && matchProbe(matchJSON, deviceValue->second);
@@ -66,9 +65,13 @@
             if constexpr (debug)
             {
                 std::cerr << "probeDBus: Found probe match on " << path << " "
-                          << interface << "\n";
+                          << interfaceName << "\n";
             }
-            devices.emplace_back(properties, path);
+            // Use emplace back when clang implements
+            // http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p0960r3.html
+            //
+            // https://en.cppreference.com/w/cpp/compiler_support/20
+            devices.push_back({interface, path});
             foundMatch = true;
         }
     }
@@ -78,7 +81,7 @@
 // default probe entry point, iterates a list looking for specific types to
 // call specific probe functions
 bool probe(const std::vector<std::string>& probeCommand,
-           const std::shared_ptr<PerformScan>& scan, FoundDeviceT& foundDevs)
+           const std::shared_ptr<PerformScan>& scan, FoundDevices& foundDevs)
 {
     const static std::regex command(R"(\((.*)\))");
     std::smatch match;
@@ -196,9 +199,13 @@
     // probe passed, but empty device
     if (ret && foundDevs.size() == 0)
     {
-        foundDevs.emplace_back(
-            boost::container::flat_map<std::string, DBusValueVariant>{},
-            std::string{});
+        // Use emplace back when clang implements
+        // http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p0960r3.html
+        //
+        // https://en.cppreference.com/w/cpp/compiler_support/20
+        foundDevs.push_back(
+            {boost::container::flat_map<std::string, DBusValueVariant>{},
+             std::string{}});
     }
     if (matchOne && ret)
     {
@@ -214,14 +221,14 @@
 PerformProbe::PerformProbe(
     const std::vector<std::string>& probeCommand,
     std::shared_ptr<PerformScan>& scanPtr,
-    std::function<void(FoundDeviceT&, const MapperGetSubTreeResponse&)>&&
+    std::function<void(FoundDevices&, const MapperGetSubTreeResponse&)>&&
         callback) :
     _probeCommand(probeCommand),
     scan(scanPtr), _callback(std::move(callback))
 {}
 PerformProbe::~PerformProbe()
 {
-    FoundDeviceT foundDevs;
+    FoundDevices foundDevs;
     if (probe(_probeCommand, scan, foundDevs))
     {
         _callback(foundDevs, scan->dbusProbeObjects);
diff --git a/src/PerformScan.cpp b/src/PerformScan.cpp
index befd210..ab1bd4b 100644
--- a/src/PerformScan.cpp
+++ b/src/PerformScan.cpp
@@ -293,7 +293,7 @@
         auto probePointer = std::make_shared<PerformProbe>(
             probeCommand, thisRef,
             [&, recordPtr,
-             probeName](FoundDeviceT& foundDevices,
+             probeName](FoundDevices& foundDevices,
                         const MapperGetSubTreeResponse& allInterfaces) {
                 _passed = true;
                 std::set<nlohmann::json> usedNames;
@@ -310,7 +310,7 @@
                      itr != foundDevices.end();)
                 {
                     std::string recordName =
-                        getRecordName(std::get<0>(*itr), probeName);
+                        getRecordName(itr->interface, probeName);
 
                     auto fromLastJson = lastJson.find(recordName);
                     if (fromLastJson != lastJson.end())
@@ -377,8 +377,8 @@
                 for (auto& foundDeviceAndPath : foundDevices)
                 {
                     const DBusInterface& foundDevice =
-                        std::get<0>(foundDeviceAndPath);
-                    const std::string& path = std::get<1>(foundDeviceAndPath);
+                        foundDeviceAndPath.interface;
+                    const std::string& path = foundDeviceAndPath.path;
 
                     // Need all interfaces on this path so that template
                     // substitutions can be done with any of the contained