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:
@@ -72,7 +72,8 @@ std::optional<std::shared_ptr<Device>> DeviceManager::getDevice(
|
||||
|
||||
// GetOrCreateDeviceReq nested class implementation
|
||||
class DeviceManager::GetOrCreateDeviceReq
|
||||
: public smo::AsynchronousContinuation<livoxProto1_getOrCreateDeviceReqCbFn>
|
||||
: public smo::NonPostedAsynchronousContinuation<
|
||||
livoxProto1_getOrCreateDeviceReqCbFn>
|
||||
{
|
||||
public:
|
||||
DeviceManager& deviceManager;
|
||||
@@ -84,14 +85,14 @@ public:
|
||||
DeviceManager& mgr,
|
||||
std::shared_ptr<Device> device,
|
||||
livoxProto1_getOrCreateDeviceReqCbFn cb)
|
||||
: smo::AsynchronousContinuation<
|
||||
: smo::NonPostedAsynchronousContinuation<
|
||||
livoxProto1_getOrCreateDeviceReqCbFn>(std::move(cb)),
|
||||
deviceManager(mgr), pendingDevice(device)
|
||||
{}
|
||||
|
||||
// Public accessor for the original callback
|
||||
void callOriginalCallback(bool success, std::shared_ptr<Device> device)
|
||||
{ originalCbFn(success, device); }
|
||||
{ callOriginalCb(success, device); }
|
||||
|
||||
void callOriginalCallbackWithFailure()
|
||||
{ callOriginalCallback(false, nullptr); }
|
||||
@@ -176,7 +177,8 @@ void DeviceManager::getOrCreateDeviceReq(
|
||||
}
|
||||
|
||||
class DeviceManager::DestroyDeviceReq
|
||||
: public smo::AsynchronousContinuation<livoxProto1_destroyDeviceReqCbFn>
|
||||
: public smo::NonPostedAsynchronousContinuation<
|
||||
livoxProto1_destroyDeviceReqCbFn>
|
||||
{
|
||||
public:
|
||||
DeviceManager& deviceManager;
|
||||
@@ -187,14 +189,14 @@ public:
|
||||
DeviceManager& mgr,
|
||||
std::shared_ptr<Device> device,
|
||||
livoxProto1_destroyDeviceReqCbFn cb)
|
||||
: smo::AsynchronousContinuation<
|
||||
: smo::NonPostedAsynchronousContinuation<
|
||||
livoxProto1_destroyDeviceReqCbFn>(std::move(cb)),
|
||||
deviceManager(mgr), pendingDevice(device)
|
||||
{}
|
||||
|
||||
// Public accessor for the original callback
|
||||
void callOriginalCallback(bool success)
|
||||
{ originalCbFn(success); }
|
||||
{ callOriginalCb(success); }
|
||||
|
||||
void callOriginalCallbackWithFailure()
|
||||
{ callOriginalCallback(false); }
|
||||
|
||||
@@ -120,7 +120,7 @@ Device::~Device()
|
||||
* This class manages the overall device connection process including handshake and heartbeat setup
|
||||
*/
|
||||
class Device::ConnectReq
|
||||
: public smo::AsynchronousContinuation<Device::connectReqCbFn>
|
||||
: public smo::NonPostedAsynchronousContinuation<Device::connectReqCbFn>
|
||||
{
|
||||
private:
|
||||
Device& device;
|
||||
@@ -128,7 +128,7 @@ private:
|
||||
|
||||
public:
|
||||
ConnectReq(Device& dev, Device::connectReqCbFn cb)
|
||||
: smo::AsynchronousContinuation<Device::connectReqCbFn>(
|
||||
: smo::NonPostedAsynchronousContinuation<Device::connectReqCbFn>(
|
||||
std::move(cb)), device(dev)
|
||||
{}
|
||||
|
||||
@@ -148,7 +148,7 @@ public:
|
||||
// Store the handshake FD for heartbeats
|
||||
context->device.heartbeatFd = fd;
|
||||
context->device.startHeartbeat();
|
||||
context->originalCbFn(true);
|
||||
context->callOriginalCb(true);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -177,7 +177,7 @@ public:
|
||||
// Store the handshake FD for heartbeats
|
||||
context->device.heartbeatFd = fd;
|
||||
context->device.startHeartbeat();
|
||||
context->originalCbFn(true);
|
||||
context->callOriginalCb(true);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -208,7 +208,7 @@ public:
|
||||
{
|
||||
if (error)
|
||||
{
|
||||
context->originalCbFn(false);
|
||||
context->callOriginalCb(false);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -234,12 +234,12 @@ public:
|
||||
context->device.discoveredDevice.ipAddr = ipAddr;
|
||||
context->device.heartbeatFd = fd;
|
||||
context->device.startHeartbeat();
|
||||
context->originalCbFn(true);
|
||||
context->callOriginalCb(true);
|
||||
return;
|
||||
}
|
||||
|
||||
// All connection attempts failed
|
||||
context->originalCbFn(false);
|
||||
context->callOriginalCb(false);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -261,7 +261,8 @@ void Device::connectReq(Device::connectReqCbFn callback)
|
||||
}
|
||||
|
||||
class Device::ConnectToKnownDeviceReq
|
||||
: public smo::AsynchronousContinuation<Device::connectToKnownDeviceReqCbFn>
|
||||
: public smo::NonPostedAsynchronousContinuation<
|
||||
Device::connectToKnownDeviceReqCbFn>
|
||||
{
|
||||
public:
|
||||
Device& device;
|
||||
@@ -269,13 +270,13 @@ public:
|
||||
std::shared_ptr<livoxProto1::comms::DiscoveredDevice> deviceInfo;
|
||||
|
||||
ConnectToKnownDeviceReq(Device& dev, Device::connectToKnownDeviceReqCbFn cb)
|
||||
: smo::AsynchronousContinuation<Device::connectToKnownDeviceReqCbFn>(
|
||||
std::move(cb)), device(dev)
|
||||
: smo::NonPostedAsynchronousContinuation<
|
||||
Device::connectToKnownDeviceReqCbFn>(std::move(cb)), device(dev)
|
||||
{}
|
||||
|
||||
// Public accessor for the original callback
|
||||
void callOriginalCallback(bool success, const std::string& ipAddr, int fd)
|
||||
{ originalCbFn(success, ipAddr, fd); }
|
||||
{ callOriginalCb(success, ipAddr, fd); }
|
||||
|
||||
// Wrapper for failure cases
|
||||
void callOriginalCallbackWithFailure()
|
||||
@@ -363,7 +364,7 @@ void Device::connectToKnownDeviceReq(
|
||||
}
|
||||
|
||||
class Device::ConnectByDeviceIdentifierReq
|
||||
: public smo::AsynchronousContinuation<
|
||||
: public smo::NonPostedAsynchronousContinuation<
|
||||
Device::connectByDeviceIdentifierReqCbFn>
|
||||
{
|
||||
public:
|
||||
@@ -372,13 +373,14 @@ public:
|
||||
|
||||
ConnectByDeviceIdentifierReq(
|
||||
Device& dev, Device::connectByDeviceIdentifierReqCbFn cb)
|
||||
: smo::AsynchronousContinuation<Device::connectByDeviceIdentifierReqCbFn>(
|
||||
std::move(cb)), device(dev)
|
||||
: smo::NonPostedAsynchronousContinuation<
|
||||
Device::connectByDeviceIdentifierReqCbFn>(
|
||||
std::move(cb)), device(dev)
|
||||
{}
|
||||
|
||||
// Public accessor for the original callback
|
||||
void callOriginalCallback(bool success, const std::string& ipAddr, int fd)
|
||||
{ originalCbFn(success, ipAddr, fd); }
|
||||
{ callOriginalCb(success, ipAddr, fd); }
|
||||
|
||||
// Wrapper for failure cases
|
||||
void callOriginalCallbackWithFailure()
|
||||
@@ -445,7 +447,8 @@ void Device::connectByDeviceIdentifierReq(
|
||||
}
|
||||
|
||||
class Device::ExecuteHandshakeReq
|
||||
: public smo::AsynchronousContinuation<Device::executeHandshakeReqCbFn>
|
||||
: public smo::NonPostedAsynchronousContinuation<
|
||||
Device::executeHandshakeReqCbFn>
|
||||
{
|
||||
public:
|
||||
friend void Device::executeHandshakeReq(
|
||||
@@ -482,7 +485,7 @@ public:
|
||||
ExecuteHandshakeReq(
|
||||
Device& dev, const std::string& deviceIP,
|
||||
Device::executeHandshakeReqCbFn cb)
|
||||
: smo::AsynchronousContinuation<Device::executeHandshakeReqCbFn>(
|
||||
: smo::NonPostedAsynchronousContinuation<Device::executeHandshakeReqCbFn>(
|
||||
std::move(cb)),
|
||||
device(dev), deviceIP(deviceIP),
|
||||
handshakeFdDesc(device.componentThread->getIoService()),
|
||||
@@ -497,7 +500,7 @@ public:
|
||||
|
||||
// Public accessor for the original callback
|
||||
void callOriginalCallback(bool success, int fd)
|
||||
{ originalCbFn(success, fd); }
|
||||
{ callOriginalCb(success, fd); }
|
||||
|
||||
void callOriginalCallbackWithFailure()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user