diff --git a/smocore/deviceManager/deviceManager.cpp b/smocore/deviceManager/deviceManager.cpp index 1968588..eef7dac 100644 --- a/smocore/deviceManager/deviceManager.cpp +++ b/smocore/deviceManager/deviceManager.cpp @@ -96,31 +96,33 @@ public: }; void DeviceManager::newDeviceAttachmentSpecInd( - std::shared_ptr spec, + const DeviceAttachmentSpec &spec, Callback callback) { // First, add the spec to deviceAttachmentSpecs if it's not already there bool specExists = false; + std::shared_ptr 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(*spec)); + specPtr = std::make_shared(spec); + deviceAttachmentSpecs.push_back(specPtr); } bool deviceExists = false; std::shared_ptr 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(spec->deviceIdentifier); + device = std::make_shared(spec.deviceIdentifier); devices.push_back(device); } @@ -140,7 +142,7 @@ void DeviceManager::newDeviceAttachmentSpecInd( std::shared_ptr 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( - 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, diff --git a/smocore/include/deviceManager/deviceManager.h b/smocore/include/deviceManager/deviceManager.h index b37a8f2..cd095d6 100644 --- a/smocore/include/deviceManager/deviceManager.h +++ b/smocore/include/deviceManager/deviceManager.h @@ -45,7 +45,7 @@ public: std::shared_ptr deviceSpec)> newDeviceAttachmentSpecIndCbFn; void newDeviceAttachmentSpecInd( - std::shared_ptr spec, + const DeviceAttachmentSpec &spec, Callback callback); // Device attachment/detachment methods moved from SenseApiManager