From b43ffcb6773824e313bfa5d7e2edbfde55b14901 Mon Sep 17 00:00:00 2001 From: Hayodea Hekol Date: Sun, 28 Sep 2025 12:39:45 -0400 Subject: [PATCH] DevMgr: attachAllUnattachedDevsFrom: now takes sh_ptr> This method now accepts a sh_ptr> 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. --- smocore/body/body.cpp | 1 + smocore/deviceManager/deviceManager.cpp | 31 +++++++++++++------ smocore/include/deviceManager/deviceManager.h | 1 + 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/smocore/body/body.cpp b/smocore/body/body.cpp index fd255d3..ca2745b 100644 --- a/smocore/body/body.cpp +++ b/smocore/body/body.cpp @@ -79,6 +79,7 @@ public: << '\n'; } device::DeviceManager::getInstance().attachAllUnattachedDevicesFromReq( + std::make_shared>(), {context, std::bind( &InitializeReq::initializeReq2, context.get(), context, diff --git a/smocore/deviceManager/deviceManager.cpp b/smocore/deviceManager/deviceManager.cpp index 93b6d41..7f20629 100644 --- a/smocore/deviceManager/deviceManager.cpp +++ b/smocore/deviceManager/deviceManager.cpp @@ -490,11 +490,12 @@ class DeviceManager::AttachAllUnattachedDevicesFromReq public: AttachAllUnattachedDevicesFromReq( const unsigned int totalNSpecs, + const std::shared_ptr>& specs, const std::shared_ptr& caller, Callback cb) : PostedAsynchronousContinuation( 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 context, - bool success, std::shared_ptr deviceRole, + bool success, [[maybe_unused]] std::shared_ptr deviceRole, std::shared_ptr spec ) { @@ -547,13 +548,15 @@ public: public: AsynchronousLoop loop; + std::shared_ptr> specs; }; void DeviceManager::attachAllUnattachedDevicesFromReq( + const std::shared_ptr> &specs, Callback 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( - 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& caller, + Callback cb) + : PostedAsynchronousContinuation( + caller, cb), + loop(totalNSpecs) + {} void detachAllAttachedDeviceRoles1_posted( [[maybe_unused]] std::shared_ptr context @@ -619,6 +629,9 @@ public: context->callOriginalCb(loop); } + +public: + AsynchronousLoop loop; }; void DeviceManager::detachAllAttachedDeviceRoles( diff --git a/smocore/include/deviceManager/deviceManager.h b/smocore/include/deviceManager/deviceManager.h index 6cc275e..14eb939 100644 --- a/smocore/include/deviceManager/deviceManager.h +++ b/smocore/include/deviceManager/deviceManager.h @@ -71,6 +71,7 @@ public: detachAllAttachedDeviceRolesCbFn; void attachAllUnattachedDevicesFromReq( + const std::shared_ptr> &specs, Callback cb); void detachAllAttachedDeviceRoles( Callback cb);