From bd52e49ba3e152e0026c79f490079957a89bdbab Mon Sep 17 00:00:00 2001 From: Hayodea Hekol Date: Sun, 28 Sep 2025 23:15:22 -0400 Subject: [PATCH] DevMgr: Add attachAllUnattachedDevicesFromKnownListReq This function is the backbone for the DeviceReattacher daemon. It assembles a list of all DA specs which are known to Mrntt, but which haven't been successfully attached as yet, and attempts to attach them. --- smocore/deviceManager/deviceManager.cpp | 32 +++++++++++++++++++ smocore/include/deviceManager/deviceManager.h | 2 ++ 2 files changed, 34 insertions(+) diff --git a/smocore/deviceManager/deviceManager.cpp b/smocore/deviceManager/deviceManager.cpp index b4100be..92c4530 100644 --- a/smocore/deviceManager/deviceManager.cpp +++ b/smocore/deviceManager/deviceManager.cpp @@ -584,6 +584,38 @@ void DeviceManager::attachAllUnattachedDevicesFromCmdlineReq( attachAllUnattachedDevicesFromReq(specs, std::move(cb)); } +void DeviceManager::attachAllUnattachedDevicesFromKnownListReq( + Callback cb + ) +{ + // Create a vector to hold unattached device specs + auto unattachedSpecs = std::make_shared>(); + + // Cycle through all DA specs in deviceAttachmentSpecs + for (const auto& spec : deviceAttachmentSpecs) + { + bool isAttached = false; + + // Cross reference with attachedDeviceRoles + for (const auto& role : attachedDeviceRoles) + { + if (*role->deviceAttachmentSpec == *spec) + { + isAttached = true; + break; + } + } + + // If spec doesn't appear in attachedDeviceRoles, add it to the vector + if (!isAttached) { + unattachedSpecs->push_back(*spec); + } + } + + // Pass the vector to the existing function + attachAllUnattachedDevicesFromReq(unattachedSpecs, std::move(cb)); +} + class DeviceManager::DetachAllAttachedDeviceRoles : public PostedAsynchronousContinuation< detachAllAttachedDeviceRolesCbFn> diff --git a/smocore/include/deviceManager/deviceManager.h b/smocore/include/deviceManager/deviceManager.h index ae80260..18f7db5 100644 --- a/smocore/include/deviceManager/deviceManager.h +++ b/smocore/include/deviceManager/deviceManager.h @@ -73,6 +73,8 @@ public: void attachAllUnattachedDevicesFromReq( const std::shared_ptr> &specs, Callback cb); + void attachAllUnattachedDevicesFromKnownListReq( + Callback cb); void attachAllUnattachedDevicesFromCmdlineReq( Callback cb); void detachAllAttachedDeviceRoles(