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'; << '\n';
} }
device::DeviceManager::getInstance().attachAllUnattachedDevicesFromReq( device::DeviceManager::getInstance().attachAllUnattachedDevicesFromReq(
std::make_shared<std::vector<device::DeviceAttachmentSpec>>(),
{context, std::bind( {context, std::bind(
&InitializeReq::initializeReq2, &InitializeReq::initializeReq2,
context.get(), context, context.get(), context,
+22 -9
View File
@@ -490,11 +490,12 @@ class DeviceManager::AttachAllUnattachedDevicesFromReq
public: public:
AttachAllUnattachedDevicesFromReq( AttachAllUnattachedDevicesFromReq(
const unsigned int totalNSpecs, const unsigned int totalNSpecs,
const std::shared_ptr<std::vector<DeviceAttachmentSpec>>& specs,
const std::shared_ptr<ComponentThread>& caller, const std::shared_ptr<ComponentThread>& caller,
Callback<attachAllUnattachedDevicesFromReqCbFn> cb) Callback<attachAllUnattachedDevicesFromReqCbFn> cb)
: PostedAsynchronousContinuation<attachAllUnattachedDevicesFromReqCbFn>( : PostedAsynchronousContinuation<attachAllUnattachedDevicesFromReqCbFn>(
caller, cb), caller, cb),
loop(totalNSpecs) loop(totalNSpecs), specs(specs)
{} {}
public: public:
@@ -503,10 +504,10 @@ public:
context context
) )
{ {
for (const auto& spec : DeviceManager::deviceAttachmentSpecs) for (const auto& spec : *specs)
{ {
DeviceManager::getInstance().newDeviceAttachmentSpecInd( DeviceManager::getInstance().newDeviceAttachmentSpecInd(
*spec, spec,
{context, std::bind( {context, std::bind(
&AttachAllUnattachedDevicesFromReq::attachAllUnattachedDevicesFromReq2, &AttachAllUnattachedDevicesFromReq::attachAllUnattachedDevicesFromReq2,
context.get(), context, context.get(), context,
@@ -518,7 +519,7 @@ public:
// Callback methods for the attachment sequence // Callback methods for the attachment sequence
void attachAllUnattachedDevicesFromReq2( void attachAllUnattachedDevicesFromReq2(
std::shared_ptr<AttachAllUnattachedDevicesFromReq> context, 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 std::shared_ptr<DeviceAttachmentSpec> spec
) )
{ {
@@ -547,13 +548,15 @@ public:
public: public:
AsynchronousLoop loop; AsynchronousLoop loop;
std::shared_ptr<std::vector<DeviceAttachmentSpec>> specs;
}; };
void DeviceManager::attachAllUnattachedDevicesFromReq( void DeviceManager::attachAllUnattachedDevicesFromReq(
const std::shared_ptr<std::vector<DeviceAttachmentSpec>> &specs,
Callback<attachAllUnattachedDevicesFromReqCbFn> cb Callback<attachAllUnattachedDevicesFromReqCbFn> cb
) )
{ {
if (DeviceManager::getInstance().deviceAttachmentSpecs.size() == 0) if (specs->size() == 0)
{ {
AsynchronousLoop tmp(0); AsynchronousLoop tmp(0);
cb.callbackFn(tmp); cb.callbackFn(tmp);
@@ -562,8 +565,7 @@ void DeviceManager::attachAllUnattachedDevicesFromReq(
const auto& caller = ComponentThread::getSelf(); const auto& caller = ComponentThread::getSelf();
auto request = std::make_shared<AttachAllUnattachedDevicesFromReq>( auto request = std::make_shared<AttachAllUnattachedDevicesFromReq>(
DeviceManager::getInstance().deviceAttachmentSpecs.size(), specs->size(), specs, caller, std::move(cb));
caller, std::move(cb));
mrntt::mrntt.thread->getIoService().post( mrntt::mrntt.thread->getIoService().post(
std::bind( std::bind(
@@ -572,10 +574,18 @@ void DeviceManager::attachAllUnattachedDevicesFromReq(
} }
class DeviceManager::DetachAllAttachedDeviceRoles class DeviceManager::DetachAllAttachedDeviceRoles
: public AttachAllUnattachedDevicesFromReq : public PostedAsynchronousContinuation<
detachAllAttachedDeviceRolesCbFn>
{ {
public: 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( void detachAllAttachedDeviceRoles1_posted(
[[maybe_unused]] std::shared_ptr<DetachAllAttachedDeviceRoles> context [[maybe_unused]] std::shared_ptr<DetachAllAttachedDeviceRoles> context
@@ -619,6 +629,9 @@ public:
context->callOriginalCb(loop); context->callOriginalCb(loop);
} }
public:
AsynchronousLoop loop;
}; };
void DeviceManager::detachAllAttachedDeviceRoles( void DeviceManager::detachAllAttachedDeviceRoles(
@@ -71,6 +71,7 @@ public:
detachAllAttachedDeviceRolesCbFn; detachAllAttachedDeviceRolesCbFn;
void attachAllUnattachedDevicesFromReq( void attachAllUnattachedDevicesFromReq(
const std::shared_ptr<std::vector<DeviceAttachmentSpec>> &specs,
Callback<attachAllUnattachedDevicesFromReqCbFn> cb); Callback<attachAllUnattachedDevicesFromReqCbFn> cb);
void detachAllAttachedDeviceRoles( void detachAllAttachedDeviceRoles(
Callback<detachAllAttachedDeviceRolesCbFn> cb); Callback<detachAllAttachedDeviceRolesCbFn> cb);