DevMgr: attachAllUnattachedDevsFrom: now takes sh_ptr<vector<Spec>>

This method now accepts a sh_ptr<vector<DeviceAttachmentSpec>> to
tell it specifically which specs to attempt to attach.

This enables us to implement different frontends that supply it
with collections of devices from different sources (GUI, cmdline,
previously failed-to-attach/hot-removed devices, etc).

SMO temporarily initializes none of the devices from the cmdline
during this commit as we transition to implementing the cmdline
collection frontend.
This commit is contained in:
2025-09-28 12:39:45 -04:00
parent 2c60248127
commit b43ffcb677
3 changed files with 24 additions and 9 deletions
+1
View File
@@ -79,6 +79,7 @@ public:
<< '\n';
}
device::DeviceManager::getInstance().attachAllUnattachedDevicesFromReq(
std::make_shared<std::vector<device::DeviceAttachmentSpec>>(),
{context, std::bind(
&InitializeReq::initializeReq2,
context.get(), context,
+22 -9
View File
@@ -490,11 +490,12 @@ class DeviceManager::AttachAllUnattachedDevicesFromReq
public:
AttachAllUnattachedDevicesFromReq(
const unsigned int totalNSpecs,
const std::shared_ptr<std::vector<DeviceAttachmentSpec>>& specs,
const std::shared_ptr<ComponentThread>& caller,
Callback<attachAllUnattachedDevicesFromReqCbFn> cb)
: PostedAsynchronousContinuation<attachAllUnattachedDevicesFromReqCbFn>(
caller, cb),
loop(totalNSpecs)
loop(totalNSpecs), specs(specs)
{}
public:
@@ -503,10 +504,10 @@ public:
context
)
{
for (const auto& spec : DeviceManager::deviceAttachmentSpecs)
for (const auto& spec : *specs)
{
DeviceManager::getInstance().newDeviceAttachmentSpecInd(
*spec,
spec,
{context, std::bind(
&AttachAllUnattachedDevicesFromReq::attachAllUnattachedDevicesFromReq2,
context.get(), context,
@@ -518,7 +519,7 @@ public:
// Callback methods for the attachment sequence
void attachAllUnattachedDevicesFromReq2(
std::shared_ptr<AttachAllUnattachedDevicesFromReq> context,
bool success, std::shared_ptr<DeviceRole> deviceRole,
bool success, [[maybe_unused]] std::shared_ptr<DeviceRole> deviceRole,
std::shared_ptr<DeviceAttachmentSpec> spec
)
{
@@ -547,13 +548,15 @@ public:
public:
AsynchronousLoop loop;
std::shared_ptr<std::vector<DeviceAttachmentSpec>> specs;
};
void DeviceManager::attachAllUnattachedDevicesFromReq(
const std::shared_ptr<std::vector<DeviceAttachmentSpec>> &specs,
Callback<attachAllUnattachedDevicesFromReqCbFn> cb
)
{
if (DeviceManager::getInstance().deviceAttachmentSpecs.size() == 0)
if (specs->size() == 0)
{
AsynchronousLoop tmp(0);
cb.callbackFn(tmp);
@@ -562,8 +565,7 @@ void DeviceManager::attachAllUnattachedDevicesFromReq(
const auto& caller = ComponentThread::getSelf();
auto request = std::make_shared<AttachAllUnattachedDevicesFromReq>(
DeviceManager::getInstance().deviceAttachmentSpecs.size(),
caller, std::move(cb));
specs->size(), specs, caller, std::move(cb));
mrntt::mrntt.thread->getIoService().post(
std::bind(
@@ -572,10 +574,18 @@ void DeviceManager::attachAllUnattachedDevicesFromReq(
}
class DeviceManager::DetachAllAttachedDeviceRoles
: public AttachAllUnattachedDevicesFromReq
: public PostedAsynchronousContinuation<
detachAllAttachedDeviceRolesCbFn>
{
public:
using AttachAllUnattachedDevicesFromReq::AttachAllUnattachedDevicesFromReq;
DetachAllAttachedDeviceRoles(
const unsigned int totalNSpecs,
const std::shared_ptr<ComponentThread>& caller,
Callback<detachAllAttachedDeviceRolesCbFn> cb)
: PostedAsynchronousContinuation<detachAllAttachedDeviceRolesCbFn>(
caller, cb),
loop(totalNSpecs)
{}
void detachAllAttachedDeviceRoles1_posted(
[[maybe_unused]] std::shared_ptr<DetachAllAttachedDeviceRoles> context
@@ -619,6 +629,9 @@ public:
context->callOriginalCb(loop);
}
public:
AsynchronousLoop loop;
};
void DeviceManager::detachAllAttachedDeviceRoles(
@@ -71,6 +71,7 @@ public:
detachAllAttachedDeviceRolesCbFn;
void attachAllUnattachedDevicesFromReq(
const std::shared_ptr<std::vector<DeviceAttachmentSpec>> &specs,
Callback<attachAllUnattachedDevicesFromReqCbFn> cb);
void detachAllAttachedDeviceRoles(
Callback<detachAllAttachedDeviceRolesCbFn> cb);