LivoxProto1: port to sscl::co framework
Code now actually looks a lot cleaner, tbh.
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
#include <boostAsioLinkageFix.h>
|
||||
#include <stdexcept>
|
||||
#include <spinscale/cps/callback.h>
|
||||
#include <boost/asio/posix/stream_descriptor.hpp>
|
||||
#include "livoxProto1.h"
|
||||
#include "device.h"
|
||||
@@ -10,14 +9,13 @@
|
||||
|
||||
extern "C" {
|
||||
|
||||
void livoxProto1_getOrCreateDeviceReq(
|
||||
sscl::co::ViralNonPostingInvoker<LivoxProto1GetOrCreateDeviceResult>
|
||||
livoxProto1_getOrCreateDeviceCReq(
|
||||
const std::string& deviceIdentifier,
|
||||
const std::shared_ptr<sscl::ComponentThread>& componentThread,
|
||||
int commandTimeoutMs, int retryDelayMs,
|
||||
const std::string& smoIp, uint8_t smoSubnetNbits,
|
||||
uint16_t dataPort, uint16_t cmdPort, uint16_t imuPort,
|
||||
sscl::cps::Callback<livoxProto1_getOrCreateDeviceReqCbFn> callback
|
||||
)
|
||||
uint16_t dataPort, uint16_t cmdPort, uint16_t imuPort)
|
||||
{
|
||||
// Get the global DeviceManager instance
|
||||
auto& protoState = livoxProto1::getProtoState();
|
||||
@@ -28,19 +26,16 @@ void livoxProto1_getOrCreateDeviceReq(
|
||||
"livoxProto1_main first");
|
||||
}
|
||||
|
||||
// Delegate to DeviceManager
|
||||
protoState.deviceManager->getOrCreateDeviceReq(
|
||||
// Delegate to the DeviceManager to create the device
|
||||
co_return co_await protoState.deviceManager->getOrCreateDeviceCReq(
|
||||
deviceIdentifier, componentThread,
|
||||
commandTimeoutMs, retryDelayMs,
|
||||
smoIp, smoSubnetNbits,
|
||||
dataPort, cmdPort, imuPort,
|
||||
callback);
|
||||
dataPort, cmdPort, imuPort);
|
||||
}
|
||||
|
||||
void livoxProto1_destroyDeviceReq(
|
||||
std::shared_ptr<livoxProto1::Device> device,
|
||||
sscl::cps::Callback<livoxProto1_destroyDeviceReqCbFn> callback
|
||||
)
|
||||
sscl::co::ViralNonPostingInvoker<bool> livoxProto1_destroyDeviceCReq(
|
||||
std::shared_ptr<livoxProto1::Device> device)
|
||||
{
|
||||
auto& protoState = livoxProto1::getProtoState();
|
||||
if (!protoState.deviceManager)
|
||||
@@ -49,8 +44,7 @@ void livoxProto1_destroyDeviceReq(
|
||||
+ ": DeviceManager not initialized");
|
||||
}
|
||||
|
||||
protoState.deviceManager->destroyDeviceReq(
|
||||
device, callback);
|
||||
co_return co_await protoState.deviceManager->destroyDeviceCReq(device);
|
||||
}
|
||||
|
||||
void livoxProto1_main(
|
||||
@@ -65,10 +59,8 @@ void livoxProto1_exit(void)
|
||||
livoxProto1::exit();
|
||||
}
|
||||
|
||||
void livoxProto1_device_enablePcloudDataReq(
|
||||
std::shared_ptr<livoxProto1::Device> device,
|
||||
sscl::cps::Callback<livoxProto1_device_enablePcloudDataReqCbFn> callback
|
||||
)
|
||||
sscl::co::ViralNonPostingInvoker<bool> livoxProto1_device_enablePcloudDataCReq(
|
||||
std::shared_ptr<livoxProto1::Device> device)
|
||||
{
|
||||
if (!device)
|
||||
{
|
||||
@@ -76,13 +68,11 @@ void livoxProto1_device_enablePcloudDataReq(
|
||||
+ ": Device pointer is null");
|
||||
}
|
||||
|
||||
device->enablePcloudDataReq(callback);
|
||||
co_return co_await device->enablePcloudDataCReq();
|
||||
}
|
||||
|
||||
void livoxProto1_device_disablePcloudDataReq(
|
||||
std::shared_ptr<livoxProto1::Device> device,
|
||||
sscl::cps::Callback<livoxProto1_device_disablePcloudDataReqCbFn> callback
|
||||
)
|
||||
sscl::co::ViralNonPostingInvoker<bool> livoxProto1_device_disablePcloudDataCReq(
|
||||
std::shared_ptr<livoxProto1::Device> device)
|
||||
{
|
||||
if (!device)
|
||||
{
|
||||
@@ -90,13 +80,12 @@ void livoxProto1_device_disablePcloudDataReq(
|
||||
+ ": Device pointer is null");
|
||||
}
|
||||
|
||||
device->disablePcloudDataReq(callback);
|
||||
co_return co_await device->disablePcloudDataCReq();
|
||||
}
|
||||
|
||||
void livoxProto1_device_getReturnModeReq(
|
||||
std::shared_ptr<livoxProto1::Device> device,
|
||||
sscl::cps::Callback<livoxProto1_device_getReturnModeReqCbFn> callback
|
||||
)
|
||||
sscl::co::ViralNonPostingInvoker<LivoxProto1GetReturnModeResult>
|
||||
livoxProto1_device_getReturnModeCReq(
|
||||
std::shared_ptr<livoxProto1::Device> device)
|
||||
{
|
||||
if (!device)
|
||||
{
|
||||
@@ -104,7 +93,12 @@ void livoxProto1_device_getReturnModeReq(
|
||||
+ ": Device pointer is null");
|
||||
}
|
||||
|
||||
device->getReturnModeReq(callback);
|
||||
livoxProto1::Device::GetReturnModeResult deviceResult =
|
||||
co_await device->getReturnModeCReq();
|
||||
LivoxProto1GetReturnModeResult result;
|
||||
result.success = deviceResult.success;
|
||||
result.returnMode = deviceResult.returnMode;
|
||||
co_return result;
|
||||
}
|
||||
|
||||
std::shared_ptr<boost::asio::posix::stream_descriptor>
|
||||
|
||||
Reference in New Issue
Block a user