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:
2025-09-17 16:32:20 -04:00
parent 33c006b178
commit 816a047920
9 changed files with 145 additions and 169 deletions
+21 -18
View File
@@ -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()
{