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.
This commit is contained in:
2025-09-28 23:15:22 -04:00
parent 93103aa8d4
commit bd52e49ba3
2 changed files with 34 additions and 0 deletions
+32
View File
@@ -584,6 +584,38 @@ void DeviceManager::attachAllUnattachedDevicesFromCmdlineReq(
attachAllUnattachedDevicesFromReq(specs, std::move(cb));
}
void DeviceManager::attachAllUnattachedDevicesFromKnownListReq(
Callback<attachAllUnattachedDevicesFromReqCbFn> cb
)
{
// Create a vector to hold unattached device specs
auto unattachedSpecs = std::make_shared<std::vector<DeviceAttachmentSpec>>();
// 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>