DevMgr:removeDASpec: Make serialized; acquire DevMgr qutex
This commit is contained in:
@@ -170,26 +170,48 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
class DeviceManager::RemoveDeviceAttachmentSpecReq
|
class DeviceManager::RemoveDeviceAttachmentSpecReq
|
||||||
: public PostedAsynchronousContinuation<removeDeviceAttachmentSpecReqCbFn>
|
: public SerializedAsynchronousContinuation<removeDeviceAttachmentSpecReqCbFn>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
RemoveDeviceAttachmentSpecReq(
|
RemoveDeviceAttachmentSpecReq(
|
||||||
const std::shared_ptr<DeviceAttachmentSpec> &s,
|
const DeviceAttachmentSpec &spec,
|
||||||
const std::shared_ptr<ComponentThread> &caller,
|
const std::shared_ptr<ComponentThread> &caller,
|
||||||
Callback<removeDeviceAttachmentSpecReqCbFn> cb)
|
Callback<removeDeviceAttachmentSpecReqCbFn> cb,
|
||||||
: PostedAsynchronousContinuation<removeDeviceAttachmentSpecReqCbFn>(
|
std::vector<std::reference_wrapper<Qutex>> requiredLocks)
|
||||||
caller, cb),
|
: SerializedAsynchronousContinuation<removeDeviceAttachmentSpecReqCbFn>(
|
||||||
spec(s)
|
caller, cb, requiredLocks),
|
||||||
|
spec(spec)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
public:
|
||||||
|
DeviceAttachmentSpec spec;
|
||||||
|
std::shared_ptr<DeviceAttachmentSpec> specPtr;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void removeDeviceAttachmentSpecReq1_posted(
|
void removeDeviceAttachmentSpecReq1_posted(
|
||||||
[[maybe_unused]] std::shared_ptr<RemoveDeviceAttachmentSpecReq> context
|
[[maybe_unused]] std::shared_ptr<RemoveDeviceAttachmentSpecReq> context
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
|
// Find the shared_ptr to the spec in the collection
|
||||||
|
for (const auto& existingSpec : DeviceManager::deviceAttachmentSpecs)
|
||||||
|
{
|
||||||
|
if (*existingSpec == spec)
|
||||||
|
{
|
||||||
|
specPtr = existingSpec;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!specPtr)
|
||||||
|
{
|
||||||
|
// Spec not found, callback with failure and return
|
||||||
|
callOriginalCb(false, nullptr);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Call detachSenseDeviceReq first - only clean up metadata if this succeeds
|
// Call detachSenseDeviceReq first - only clean up metadata if this succeeds
|
||||||
DeviceManager::getInstance().detachSenseDeviceReq(
|
DeviceManager::getInstance().detachSenseDeviceReq(
|
||||||
spec,
|
specPtr,
|
||||||
{context, std::bind(
|
{context, std::bind(
|
||||||
&RemoveDeviceAttachmentSpecReq::removeDeviceAttachmentSpecReq2,
|
&RemoveDeviceAttachmentSpecReq::removeDeviceAttachmentSpecReq2,
|
||||||
context.get(), context,
|
context.get(), context,
|
||||||
@@ -213,14 +235,14 @@ public:
|
|||||||
try {
|
try {
|
||||||
// Find the DeviceRole in attachedDeviceRoles
|
// Find the DeviceRole in attachedDeviceRoles
|
||||||
auto deviceRoleIt = std::find_if(
|
auto deviceRoleIt = std::find_if(
|
||||||
attachedDeviceRoles.begin(),
|
DeviceManager::attachedDeviceRoles.begin(),
|
||||||
attachedDeviceRoles.end(),
|
DeviceManager::attachedDeviceRoles.end(),
|
||||||
[&spec = spec](const std::shared_ptr<DeviceRole> &role) {
|
[&specPtr = specPtr](const std::shared_ptr<DeviceRole> &role) {
|
||||||
return *role->deviceAttachmentSpec == *spec;
|
return *role->deviceAttachmentSpec == *specPtr;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
if (deviceRoleIt == attachedDeviceRoles.end())
|
if (deviceRoleIt == DeviceManager::attachedDeviceRoles.end())
|
||||||
{
|
{
|
||||||
// DeviceRole not found, callback with failure
|
// DeviceRole not found, callback with failure
|
||||||
callOriginalCb(false, deviceSpec);
|
callOriginalCb(false, deviceSpec);
|
||||||
@@ -231,7 +253,7 @@ public:
|
|||||||
auto& device = deviceRole->parentDevice;
|
auto& device = deviceRole->parentDevice;
|
||||||
|
|
||||||
// Remove DeviceRole from DeviceManager's collection
|
// Remove DeviceRole from DeviceManager's collection
|
||||||
attachedDeviceRoles.erase(deviceRoleIt);
|
DeviceManager::attachedDeviceRoles.erase(deviceRoleIt);
|
||||||
|
|
||||||
// Remove DeviceRole from Device's collection
|
// Remove DeviceRole from Device's collection
|
||||||
auto deviceRoleIt2 = std::find(
|
auto deviceRoleIt2 = std::find(
|
||||||
@@ -245,14 +267,18 @@ public:
|
|||||||
|
|
||||||
// Remove DeviceAttachmentSpec from deviceAttachmentSpecs collection
|
// Remove DeviceAttachmentSpec from deviceAttachmentSpecs collection
|
||||||
auto specIt = std::find_if(
|
auto specIt = std::find_if(
|
||||||
deviceAttachmentSpecs.begin(),
|
DeviceManager::deviceAttachmentSpecs.begin(),
|
||||||
deviceAttachmentSpecs.end(),
|
DeviceManager::deviceAttachmentSpecs.end(),
|
||||||
[&spec = spec](const std::shared_ptr<DeviceAttachmentSpec> &existingSpec) {
|
[&specPtr = specPtr](
|
||||||
return *existingSpec == *spec;
|
const std::shared_ptr<DeviceAttachmentSpec> &existingSpec)
|
||||||
});
|
{
|
||||||
if (specIt != deviceAttachmentSpecs.end())
|
return *existingSpec == *specPtr;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
if (specIt != DeviceManager::deviceAttachmentSpecs.end())
|
||||||
{
|
{
|
||||||
deviceAttachmentSpecs.erase(specIt);
|
DeviceManager::deviceAttachmentSpecs.erase(specIt);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Callback with success
|
// Callback with success
|
||||||
@@ -262,9 +288,6 @@ public:
|
|||||||
callOriginalCb(false, deviceSpec);
|
callOriginalCb(false, deviceSpec);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
|
||||||
std::shared_ptr<DeviceAttachmentSpec> spec;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
void DeviceManager::newDeviceAttachmentSpecInd(
|
void DeviceManager::newDeviceAttachmentSpecInd(
|
||||||
@@ -290,33 +313,19 @@ void DeviceManager::removeDeviceAttachmentSpecReq(
|
|||||||
const DeviceAttachmentSpec &spec,
|
const DeviceAttachmentSpec &spec,
|
||||||
Callback<removeDeviceAttachmentSpecReqCbFn> callback)
|
Callback<removeDeviceAttachmentSpecReqCbFn> callback)
|
||||||
{
|
{
|
||||||
// Find the shared_ptr to the spec in the collection
|
|
||||||
std::shared_ptr<DeviceAttachmentSpec> specPtr = nullptr;
|
|
||||||
for (const auto& existingSpec : deviceAttachmentSpecs)
|
|
||||||
{
|
|
||||||
if (*existingSpec == spec)
|
|
||||||
{
|
|
||||||
specPtr = existingSpec;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!specPtr)
|
|
||||||
{
|
|
||||||
// Spec not found, callback with failure
|
|
||||||
callback.callbackFn(false, nullptr);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create async continuation
|
|
||||||
const auto& caller = ComponentThread::getSelf();
|
const auto& caller = ComponentThread::getSelf();
|
||||||
auto continuation = std::make_shared<RemoveDeviceAttachmentSpecReq>(
|
|
||||||
specPtr, caller, callback);
|
|
||||||
|
|
||||||
mrntt::mrntt.thread->getIoService().post(
|
auto request = std::make_shared<RemoveDeviceAttachmentSpecReq>(
|
||||||
|
spec, caller, callback,
|
||||||
|
LockSet<removeDeviceAttachmentSpecReqCbFn>::Set{
|
||||||
|
std::ref(DeviceManager::getInstance().qutex)
|
||||||
|
});
|
||||||
|
|
||||||
|
RemoveDeviceAttachmentSpecReq::LockerAndInvoker lockvoker(
|
||||||
|
*request, mrntt::mrntt.thread,
|
||||||
std::bind(
|
std::bind(
|
||||||
&RemoveDeviceAttachmentSpecReq::removeDeviceAttachmentSpecReq1_posted,
|
&RemoveDeviceAttachmentSpecReq::removeDeviceAttachmentSpecReq1_posted,
|
||||||
continuation.get(), continuation));
|
request.get(), request));
|
||||||
}
|
}
|
||||||
|
|
||||||
class DeviceManager::AttachSenseDeviceReq
|
class DeviceManager::AttachSenseDeviceReq
|
||||||
|
|||||||
Reference in New Issue
Block a user