Async: add sh_ptr<ContinuationChainLink> to Callback<>
This change enables us to finally implement the tracing of continuations backward from the point of acquisition for deadlock debugging.
This commit is contained in:
@@ -16,6 +16,7 @@
|
||||
#include <boost/asio.hpp>
|
||||
#include <opts.h>
|
||||
#include <asynchronousContinuation.h>
|
||||
#include <callback.h>
|
||||
#include "device.h"
|
||||
#include "protocol.h"
|
||||
#include "core.h"
|
||||
@@ -127,7 +128,7 @@ private:
|
||||
std::unique_ptr<boost::asio::deadline_timer> retryTimer;
|
||||
|
||||
public:
|
||||
ConnectReq(Device& dev, Device::connectReqCbFn cb)
|
||||
ConnectReq(Device& dev, smo::Callback<Device::connectReqCbFn> cb)
|
||||
: smo::NonPostedAsynchronousContinuation<Device::connectReqCbFn>(
|
||||
std::move(cb)), device(dev)
|
||||
{}
|
||||
@@ -160,9 +161,9 @@ public:
|
||||
|
||||
// Try direct connect by device identifier
|
||||
context->device.connectByDeviceIdentifierReq(
|
||||
std::bind(&ConnectReq::connectReq2, context.get(), context,
|
||||
{context, std::bind(&ConnectReq::connectReq2, context.get(), context,
|
||||
std::placeholders::_1, std::placeholders::_2,
|
||||
std::placeholders::_3));
|
||||
std::placeholders::_3)});
|
||||
}
|
||||
|
||||
void connectReq2(
|
||||
@@ -219,9 +220,9 @@ public:
|
||||
}
|
||||
|
||||
context->device.connectToKnownDeviceReq(
|
||||
std::bind(&ConnectReq::connectReq4, context.get(), context,
|
||||
{context, std::bind(&ConnectReq::connectReq4, context.get(), context,
|
||||
std::placeholders::_1, std::placeholders::_2,
|
||||
std::placeholders::_3));
|
||||
std::placeholders::_3)});
|
||||
}
|
||||
|
||||
void connectReq4(
|
||||
@@ -243,7 +244,7 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
void Device::connectReq(Device::connectReqCbFn callback)
|
||||
void Device::connectReq(smo::Callback<Device::connectReqCbFn> callback)
|
||||
{
|
||||
// Create the connection request object to hold state and callbacks
|
||||
auto request = std::make_shared<ConnectReq>(*this, std::move(callback));
|
||||
@@ -254,10 +255,10 @@ void Device::connectReq(Device::connectReqCbFn callback)
|
||||
}
|
||||
|
||||
connectToKnownDeviceReq(
|
||||
std::bind(
|
||||
{request, std::bind(
|
||||
&ConnectReq::connectReq1, request.get(), request,
|
||||
std::placeholders::_1, std::placeholders::_2,
|
||||
std::placeholders::_3));
|
||||
std::placeholders::_3)});
|
||||
}
|
||||
|
||||
class Device::ConnectToKnownDeviceReq
|
||||
@@ -269,7 +270,7 @@ public:
|
||||
std::string deviceIP;
|
||||
std::shared_ptr<livoxProto1::comms::DiscoveredDevice> deviceInfo;
|
||||
|
||||
ConnectToKnownDeviceReq(Device& dev, Device::connectToKnownDeviceReqCbFn cb)
|
||||
ConnectToKnownDeviceReq(Device& dev, smo::Callback<Device::connectToKnownDeviceReqCbFn> cb)
|
||||
: smo::NonPostedAsynchronousContinuation<
|
||||
Device::connectToKnownDeviceReqCbFn>(std::move(cb)), device(dev)
|
||||
{}
|
||||
@@ -297,7 +298,7 @@ public:
|
||||
* broadcastListener.
|
||||
*/
|
||||
void Device::connectToKnownDeviceReq(
|
||||
Device::connectToKnownDeviceReqCbFn callback
|
||||
smo::Callback<Device::connectToKnownDeviceReqCbFn> callback
|
||||
)
|
||||
{
|
||||
// Create the connection request object to hold state and callbacks
|
||||
@@ -357,10 +358,10 @@ void Device::connectToKnownDeviceReq(
|
||||
// Execute handshake with the known device using async method
|
||||
request->device.executeHandshakeReq(
|
||||
request->deviceIP,
|
||||
std::bind(
|
||||
{request, std::bind(
|
||||
&ConnectToKnownDeviceReq::connectToKnownDeviceReq1,
|
||||
request.get(), request,
|
||||
std::placeholders::_1, std::placeholders::_2));
|
||||
std::placeholders::_1, std::placeholders::_2)});
|
||||
}
|
||||
|
||||
class Device::ConnectByDeviceIdentifierReq
|
||||
@@ -372,7 +373,7 @@ public:
|
||||
std::string deviceIP;
|
||||
|
||||
ConnectByDeviceIdentifierReq(
|
||||
Device& dev, Device::connectByDeviceIdentifierReqCbFn cb)
|
||||
Device& dev, smo::Callback<Device::connectByDeviceIdentifierReqCbFn> cb)
|
||||
: smo::NonPostedAsynchronousContinuation<
|
||||
Device::connectByDeviceIdentifierReqCbFn>(
|
||||
std::move(cb)), device(dev)
|
||||
@@ -398,7 +399,7 @@ public:
|
||||
};
|
||||
|
||||
void Device::connectByDeviceIdentifierReq(
|
||||
Device::connectByDeviceIdentifierReqCbFn callback
|
||||
smo::Callback<Device::connectByDeviceIdentifierReqCbFn> callback
|
||||
)
|
||||
{
|
||||
/** EXPLANATION:
|
||||
@@ -415,7 +416,7 @@ void Device::connectByDeviceIdentifierReq(
|
||||
// Check if smoIp is provided - required for heuristic construction
|
||||
if (smoIp.empty())
|
||||
{
|
||||
callback(false, "", -1);
|
||||
callback.callbackFn(false, "", -1);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -440,10 +441,10 @@ void Device::connectByDeviceIdentifierReq(
|
||||
// Execute handshake using async method
|
||||
request->device.executeHandshakeReq(
|
||||
request->deviceIP,
|
||||
std::bind(
|
||||
{request, std::bind(
|
||||
&ConnectByDeviceIdentifierReq::connectByDeviceIdentifierReq1,
|
||||
request.get(), request,
|
||||
std::placeholders::_1, std::placeholders::_2));
|
||||
std::placeholders::_1, std::placeholders::_2)});
|
||||
}
|
||||
|
||||
class Device::ExecuteHandshakeReq
|
||||
@@ -452,7 +453,8 @@ class Device::ExecuteHandshakeReq
|
||||
{
|
||||
public:
|
||||
friend void Device::executeHandshakeReq(
|
||||
const std::string& deviceIP, Device::executeHandshakeReqCbFn callback);
|
||||
const std::string& deviceIP,
|
||||
smo::Callback<Device::executeHandshakeReqCbFn> callback);
|
||||
|
||||
enum class SocketState
|
||||
{
|
||||
@@ -484,7 +486,7 @@ public:
|
||||
public:
|
||||
ExecuteHandshakeReq(
|
||||
Device& dev, const std::string& deviceIP,
|
||||
Device::executeHandshakeReqCbFn cb)
|
||||
smo::Callback<Device::executeHandshakeReqCbFn> cb)
|
||||
: smo::NonPostedAsynchronousContinuation<Device::executeHandshakeReqCbFn>(
|
||||
std::move(cb)),
|
||||
device(dev), deviceIP(deviceIP),
|
||||
@@ -650,7 +652,8 @@ private:
|
||||
*/
|
||||
handshakeFdDesc.async_wait(
|
||||
boost::asio::posix::stream_descriptor::wait_read,
|
||||
std::bind(&ExecuteHandshakeReq::executeHandshakeReq1_2, this,
|
||||
std::bind(
|
||||
&ExecuteHandshakeReq::executeHandshakeReq1_2, this,
|
||||
request,
|
||||
std::placeholders::_1));
|
||||
}
|
||||
@@ -830,7 +833,8 @@ private:
|
||||
};
|
||||
|
||||
void Device::executeHandshakeReq(
|
||||
const std::string& deviceIP, Device::executeHandshakeReqCbFn callback
|
||||
const std::string& deviceIP,
|
||||
smo::Callback<Device::executeHandshakeReqCbFn> callback
|
||||
)
|
||||
{
|
||||
// Create the handshake request object to hold state and callbacks
|
||||
@@ -866,7 +870,7 @@ void Device::executeHandshakeReq(
|
||||
}
|
||||
}
|
||||
|
||||
void Device::disconnectReq(Device::disconnectReqCbFn callback)
|
||||
void Device::disconnectReq(smo::Callback<Device::disconnectReqCbFn> callback)
|
||||
{
|
||||
// Stop heartbeat first
|
||||
heartbeatActive.store(false);
|
||||
@@ -875,7 +879,7 @@ void Device::disconnectReq(Device::disconnectReqCbFn callback)
|
||||
{
|
||||
std::cout << __func__ << ": No heartbeat socket available, skipping "
|
||||
"disconnect message" << std::endl;
|
||||
callback(true);
|
||||
callback.callbackFn(true);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -911,7 +915,7 @@ void Device::disconnectReq(Device::disconnectReqCbFn callback)
|
||||
// Close the heartbeat socket
|
||||
close(heartbeatFd);
|
||||
heartbeatFd = -1;
|
||||
callback(true);
|
||||
callback.callbackFn(true);
|
||||
}
|
||||
|
||||
std::string Device::generateClientDeviceIpFromSerialNumber(
|
||||
|
||||
Reference in New Issue
Block a user