DevMgr:newDevAttSpecInd: take ref & not sh_ptr to DASpec

Because NewDevAttSpecInd should be the function that creates the
persistent sh_ptr state within DevMgr.
This commit is contained in:
2025-09-28 11:14:55 -04:00
parent 7ab6e7b2c3
commit 27e707a22d
2 changed files with 13 additions and 11 deletions
+12 -10
View File
@@ -96,31 +96,33 @@ public:
};
void DeviceManager::newDeviceAttachmentSpecInd(
std::shared_ptr<DeviceAttachmentSpec> spec,
const DeviceAttachmentSpec &spec,
Callback<newDeviceAttachmentSpecIndCbFn> callback)
{
// First, add the spec to deviceAttachmentSpecs if it's not already there
bool specExists = false;
std::shared_ptr<DeviceAttachmentSpec> specPtr = nullptr;
for (const auto& existingSpec : deviceAttachmentSpecs)
{
if (*existingSpec == *spec)
if (*existingSpec == spec)
{
specExists = true;
specPtr = existingSpec;
break;
}
}
if (!specExists)
{
deviceAttachmentSpecs.push_back(
std::make_shared<DeviceAttachmentSpec>(*spec));
specPtr = std::make_shared<DeviceAttachmentSpec>(spec);
deviceAttachmentSpecs.push_back(specPtr);
}
bool deviceExists = false;
std::shared_ptr<Device> device = nullptr;
for (const auto& existingDevice : devices)
{
if (existingDevice->deviceIdentifier != spec->deviceIdentifier)
if (existingDevice->deviceIdentifier != spec.deviceIdentifier)
{ continue; }
device = existingDevice;
@@ -131,7 +133,7 @@ void DeviceManager::newDeviceAttachmentSpecInd(
// If device doesn't exist, create a new one and add it
if (!device)
{
device = std::make_shared<Device>(spec->deviceIdentifier);
device = std::make_shared<Device>(spec.deviceIdentifier);
devices.push_back(device);
}
@@ -140,7 +142,7 @@ void DeviceManager::newDeviceAttachmentSpecInd(
std::shared_ptr<DeviceRole> existingDeviceRole = nullptr;
for (const auto& role : attachedDeviceRoles)
{
if (*role->deviceAttachmentSpec == *spec)
if (*role->deviceAttachmentSpec == spec)
{
deviceRoleExists = true;
existingDeviceRole = role;
@@ -160,14 +162,14 @@ void DeviceManager::newDeviceAttachmentSpecInd(
}
// Already attached, callback with success
callback.callbackFn(true, existingDeviceRole, spec);
callback.callbackFn(true, existingDeviceRole, specPtr);
return;
}
// Create async continuation
const auto& caller = ComponentThread::getSelf();
auto continuation = std::make_shared<NewDeviceAttachmentSpecInd>(
spec, device, caller, callback);
specPtr, device, caller, callback);
mrntt::mrntt.thread->getIoService().post(
std::bind(
@@ -373,7 +375,7 @@ public:
for (const auto& spec : DeviceManager::deviceAttachmentSpecs)
{
DeviceManager::getInstance().newDeviceAttachmentSpecInd(
spec,
*spec,
{context, std::bind(
&AttachAllSenseDevicesFromSpecsReq::attachAllSenseDevicesFromSpecsReq2,
context.get(), context,
@@ -45,7 +45,7 @@ public:
std::shared_ptr<DeviceAttachmentSpec> deviceSpec)>
newDeviceAttachmentSpecIndCbFn;
void newDeviceAttachmentSpecInd(
std::shared_ptr<DeviceAttachmentSpec> spec,
const DeviceAttachmentSpec &spec,
Callback<newDeviceAttachmentSpecIndCbFn> callback);
// Device attachment/detachment methods moved from SenseApiManager