livoxProto1: Implement async getOrCreateDeviceReq+destroyDeviceReq

These are now both fully asynchronous. They also work fully
and both connect and disconnect to/from the Avia just fine,
in all tested scenarios.
This commit is contained in:
2025-09-09 12:07:49 -04:00
parent 48121ec84c
commit 20cdf64afb
9 changed files with 1041 additions and 269 deletions
+26 -9
View File
@@ -5,8 +5,11 @@
#include <string>
#include <memory>
#include <cstdint>
#include <optional>
#include <user/senseApiDesc.h>
#include "device.h"
#include "broadcastListener.h"
#include "livoxProto1.h"
namespace livoxProto1 {
@@ -18,30 +21,43 @@ public:
static void deviceGoneAwayInd(const comms::DiscoveredDevice &device);
std::shared_ptr<Device> getOrCreateDevice(
void getOrCreateDeviceReq(
const std::string &deviceIdentifier,
const std::shared_ptr<smo::ComponentThread>& componentThread,
int handshakeTimeoutMs, int retryDelayMs,
const std::string& smoIp, uint8_t smoSubnetNbits,
uint16_t dataPort, uint16_t cmdPort, uint16_t imuPort);
uint16_t dataPort, uint16_t cmdPort, uint16_t imuPort,
livoxProto1_getOrCreateDeviceReqCbFn callback);
std::shared_ptr<Device> getDevice(const std::string &deviceIdentifier);
std::shared_ptr<Device> getDevice(const comms::DiscoveredDevice &device)
{ return getDevice(device.deviceIdentifier); }
void destroyDeviceReq(
std::shared_ptr<Device> device,
livoxProto1_destroyDeviceReqCbFn callback);
std::optional<std::shared_ptr<Device>> getDevice(
const std::string &deviceIdentifier);
std::optional<std::shared_ptr<Device>> getDevice(
const comms::DiscoveredDevice &device)
{
return getDevice(device.deviceIdentifier);
}
private:
// Helper methods
bool isDeviceKnown(const std::string& deviceIdentifier);
// Configuration
static constexpr int RETRY_DELAY_SECONDS = 3; // <N> seconds delay
public:
std::vector<std::shared_ptr<Device>> devices;
comms::BroadcastListener broadcastListener;
// Nested continuation class for async device creation
class GetOrCreateDeviceReq;
class DestroyDeviceReq;
};
void main(const std::shared_ptr<smo::ComponentThread> &componentThread);
void main(
const std::shared_ptr<smo::ComponentThread> &componentThread,
const smo::sense_api::SmoCallbacks& smoCallbacks);
void exit(void);
// Global state structure
@@ -50,6 +66,7 @@ struct ProtoState
bool isInitialized = false;
std::shared_ptr<smo::ComponentThread> componentThread;
std::unique_ptr<DeviceManager> deviceManager;
smo::sense_api::SmoCallbacks smoCallbacks;
};
// Access to global state for extern "C" functions