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:
@@ -96,31 +96,33 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
void DeviceManager::newDeviceAttachmentSpecInd(
|
void DeviceManager::newDeviceAttachmentSpecInd(
|
||||||
std::shared_ptr<DeviceAttachmentSpec> spec,
|
const DeviceAttachmentSpec &spec,
|
||||||
Callback<newDeviceAttachmentSpecIndCbFn> callback)
|
Callback<newDeviceAttachmentSpecIndCbFn> callback)
|
||||||
{
|
{
|
||||||
// First, add the spec to deviceAttachmentSpecs if it's not already there
|
// First, add the spec to deviceAttachmentSpecs if it's not already there
|
||||||
bool specExists = false;
|
bool specExists = false;
|
||||||
|
std::shared_ptr<DeviceAttachmentSpec> specPtr = nullptr;
|
||||||
for (const auto& existingSpec : deviceAttachmentSpecs)
|
for (const auto& existingSpec : deviceAttachmentSpecs)
|
||||||
{
|
{
|
||||||
if (*existingSpec == *spec)
|
if (*existingSpec == spec)
|
||||||
{
|
{
|
||||||
specExists = true;
|
specExists = true;
|
||||||
|
specPtr = existingSpec;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!specExists)
|
if (!specExists)
|
||||||
{
|
{
|
||||||
deviceAttachmentSpecs.push_back(
|
specPtr = std::make_shared<DeviceAttachmentSpec>(spec);
|
||||||
std::make_shared<DeviceAttachmentSpec>(*spec));
|
deviceAttachmentSpecs.push_back(specPtr);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool deviceExists = false;
|
bool deviceExists = false;
|
||||||
std::shared_ptr<Device> device = nullptr;
|
std::shared_ptr<Device> device = nullptr;
|
||||||
for (const auto& existingDevice : devices)
|
for (const auto& existingDevice : devices)
|
||||||
{
|
{
|
||||||
if (existingDevice->deviceIdentifier != spec->deviceIdentifier)
|
if (existingDevice->deviceIdentifier != spec.deviceIdentifier)
|
||||||
{ continue; }
|
{ continue; }
|
||||||
|
|
||||||
device = existingDevice;
|
device = existingDevice;
|
||||||
@@ -131,7 +133,7 @@ void DeviceManager::newDeviceAttachmentSpecInd(
|
|||||||
// If device doesn't exist, create a new one and add it
|
// If device doesn't exist, create a new one and add it
|
||||||
if (!device)
|
if (!device)
|
||||||
{
|
{
|
||||||
device = std::make_shared<Device>(spec->deviceIdentifier);
|
device = std::make_shared<Device>(spec.deviceIdentifier);
|
||||||
devices.push_back(device);
|
devices.push_back(device);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -140,7 +142,7 @@ void DeviceManager::newDeviceAttachmentSpecInd(
|
|||||||
std::shared_ptr<DeviceRole> existingDeviceRole = nullptr;
|
std::shared_ptr<DeviceRole> existingDeviceRole = nullptr;
|
||||||
for (const auto& role : attachedDeviceRoles)
|
for (const auto& role : attachedDeviceRoles)
|
||||||
{
|
{
|
||||||
if (*role->deviceAttachmentSpec == *spec)
|
if (*role->deviceAttachmentSpec == spec)
|
||||||
{
|
{
|
||||||
deviceRoleExists = true;
|
deviceRoleExists = true;
|
||||||
existingDeviceRole = role;
|
existingDeviceRole = role;
|
||||||
@@ -160,14 +162,14 @@ void DeviceManager::newDeviceAttachmentSpecInd(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Already attached, callback with success
|
// Already attached, callback with success
|
||||||
callback.callbackFn(true, existingDeviceRole, spec);
|
callback.callbackFn(true, existingDeviceRole, specPtr);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create async continuation
|
// Create async continuation
|
||||||
const auto& caller = ComponentThread::getSelf();
|
const auto& caller = ComponentThread::getSelf();
|
||||||
auto continuation = std::make_shared<NewDeviceAttachmentSpecInd>(
|
auto continuation = std::make_shared<NewDeviceAttachmentSpecInd>(
|
||||||
spec, device, caller, callback);
|
specPtr, device, caller, callback);
|
||||||
|
|
||||||
mrntt::mrntt.thread->getIoService().post(
|
mrntt::mrntt.thread->getIoService().post(
|
||||||
std::bind(
|
std::bind(
|
||||||
@@ -373,7 +375,7 @@ public:
|
|||||||
for (const auto& spec : DeviceManager::deviceAttachmentSpecs)
|
for (const auto& spec : DeviceManager::deviceAttachmentSpecs)
|
||||||
{
|
{
|
||||||
DeviceManager::getInstance().newDeviceAttachmentSpecInd(
|
DeviceManager::getInstance().newDeviceAttachmentSpecInd(
|
||||||
spec,
|
*spec,
|
||||||
{context, std::bind(
|
{context, std::bind(
|
||||||
&AttachAllSenseDevicesFromSpecsReq::attachAllSenseDevicesFromSpecsReq2,
|
&AttachAllSenseDevicesFromSpecsReq::attachAllSenseDevicesFromSpecsReq2,
|
||||||
context.get(), context,
|
context.get(), context,
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ public:
|
|||||||
std::shared_ptr<DeviceAttachmentSpec> deviceSpec)>
|
std::shared_ptr<DeviceAttachmentSpec> deviceSpec)>
|
||||||
newDeviceAttachmentSpecIndCbFn;
|
newDeviceAttachmentSpecIndCbFn;
|
||||||
void newDeviceAttachmentSpecInd(
|
void newDeviceAttachmentSpecInd(
|
||||||
std::shared_ptr<DeviceAttachmentSpec> spec,
|
const DeviceAttachmentSpec &spec,
|
||||||
Callback<newDeviceAttachmentSpecIndCbFn> callback);
|
Callback<newDeviceAttachmentSpecIndCbFn> callback);
|
||||||
|
|
||||||
// Device attachment/detachment methods moved from SenseApiManager
|
// Device attachment/detachment methods moved from SenseApiManager
|
||||||
|
|||||||
Reference in New Issue
Block a user