Async: new hierachy; manages reply posting and unlocking
Async: Use new [Non]PostedAsyncCont and callOriginalCb This new hierarchy of classes gives us a central mechanism for managing both reply-posting and lockSpec unlocking. * callOriginalCb: Now uses a modern C++ variadic template design enabling it to handle both direct calling and std::bind() re-binding of an arbitrary number of arguments from the caller. This enables us to mostly eliminate the repeated, bespoke definitions of callOriginalCb littered throughout the codebase. We've also propagated these changes throughout the codebase in this patch.
This commit is contained in:
@@ -262,30 +262,18 @@ void SenseApiManager::finalizeAllSenseApiLibs(void)
|
||||
}
|
||||
|
||||
class SenseApiManager::AttachSenseDeviceReq
|
||||
: public TargetedAsynchronousContinuation<attachSenseDeviceReqCbFn>
|
||||
: public PostedAsynchronousContinuation<attachSenseDeviceReqCbFn>
|
||||
{
|
||||
public:
|
||||
AttachSenseDeviceReq(
|
||||
const std::shared_ptr<device::DeviceAttachmentSpec>& spec,
|
||||
const std::shared_ptr<ComponentThread> &caller,
|
||||
attachSenseDeviceReqCbFn cb)
|
||||
: TargetedAsynchronousContinuation<attachSenseDeviceReqCbFn>(
|
||||
: PostedAsynchronousContinuation<attachSenseDeviceReqCbFn>(
|
||||
caller, cb),
|
||||
spec(spec)
|
||||
{}
|
||||
|
||||
void callOriginalCb(
|
||||
bool success, std::shared_ptr<device::DeviceAttachmentSpec> deviceSpec
|
||||
)
|
||||
{
|
||||
if (originalCbFn)
|
||||
{
|
||||
caller->getIoService().post(
|
||||
std::bind(
|
||||
originalCbFn, success, deviceSpec));
|
||||
}
|
||||
}
|
||||
|
||||
public:
|
||||
void attachSenseDeviceReq1_posted(
|
||||
[[maybe_unused]] std::shared_ptr<AttachSenseDeviceReq> context
|
||||
@@ -448,7 +436,7 @@ void SenseApiManager::detachSenseDeviceReq(
|
||||
}
|
||||
|
||||
class SenseApiManager::AttachAllSenseDevicesFromSpecsReq
|
||||
: public TargetedAsynchronousContinuation<
|
||||
: public PostedAsynchronousContinuation<
|
||||
attachAllSenseDevicesFromSpecsReqCbFn>
|
||||
{
|
||||
public:
|
||||
@@ -456,21 +444,11 @@ public:
|
||||
const unsigned int totalNSpecs,
|
||||
const std::shared_ptr<ComponentThread>& caller,
|
||||
attachAllSenseDevicesFromSpecsReqCbFn cb)
|
||||
: TargetedAsynchronousContinuation<attachAllSenseDevicesFromSpecsReqCbFn>(
|
||||
: PostedAsynchronousContinuation<attachAllSenseDevicesFromSpecsReqCbFn>(
|
||||
caller, cb),
|
||||
loop(totalNSpecs)
|
||||
{}
|
||||
|
||||
void callOriginalCallback()
|
||||
{
|
||||
if (originalCbFn)
|
||||
{
|
||||
caller->getIoService().post(
|
||||
std::bind(
|
||||
originalCbFn, loop));
|
||||
}
|
||||
}
|
||||
|
||||
public:
|
||||
void attachAllSenseDevicesFromSpecsReq1_posted(
|
||||
[[maybe_unused]] std::shared_ptr<AttachAllSenseDevicesFromSpecsReq> context
|
||||
@@ -513,7 +491,7 @@ public:
|
||||
<< context->loop.nFailed.load() << " devices failed\n";
|
||||
}
|
||||
|
||||
context->callOriginalCallback();
|
||||
context->callOriginalCb(loop);
|
||||
}
|
||||
|
||||
public:
|
||||
@@ -588,7 +566,7 @@ public:
|
||||
<< context->loop.nFailed.load() << " devices failed\n";
|
||||
}
|
||||
|
||||
context->callOriginalCallback();
|
||||
context->callOriginalCb(loop);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user