From d88dd2cf44f7615cf33a2626048dd959d5671c73 Mon Sep 17 00:00:00 2001 From: Hayodea Hekol Date: Sun, 2 Nov 2025 19:16:22 -0400 Subject: [PATCH] livoxGen1: Make use of livoxProto1_getPcloudDataFdDesc --- commonLibs/livoxProto1/livoxProto1.cpp | 2 +- commonLibs/livoxProto1/livoxProto1.h | 1 + commonLibs/livoxProto1/udpCommandDemuxer.h | 7 +++ .../livoxGen1/ioUringAssemblyEngine.cpp | 4 +- stimBuffApis/livoxGen1/livoxGen1.cpp | 58 +++++++++---------- 5 files changed, 38 insertions(+), 34 deletions(-) diff --git a/commonLibs/livoxProto1/livoxProto1.cpp b/commonLibs/livoxProto1/livoxProto1.cpp index e108cfc..7948747 100644 --- a/commonLibs/livoxProto1/livoxProto1.cpp +++ b/commonLibs/livoxProto1/livoxProto1.cpp @@ -116,7 +116,7 @@ livoxProto1_getPcloudDataFdDesc(void) + ": DeviceManager not initialized"); } - return protoState.deviceManager->udpCommandDemuxer.pcloudDataSocketDesc; + return protoState.deviceManager->udpCommandDemuxer.getPcloudDataFdDesc(); } } // extern "C" diff --git a/commonLibs/livoxProto1/livoxProto1.h b/commonLibs/livoxProto1/livoxProto1.h index 4b865f8..4c5dabc 100644 --- a/commonLibs/livoxProto1/livoxProto1.h +++ b/commonLibs/livoxProto1/livoxProto1.h @@ -6,6 +6,7 @@ #include #include #include +#include // Forward declarations namespace smo { diff --git a/commonLibs/livoxProto1/udpCommandDemuxer.h b/commonLibs/livoxProto1/udpCommandDemuxer.h index 03e8b4d..1bdc4cf 100644 --- a/commonLibs/livoxProto1/udpCommandDemuxer.h +++ b/commonLibs/livoxProto1/udpCommandDemuxer.h @@ -53,6 +53,13 @@ public: return cmdEndpointFdDesc; } + // Get shared pointer to pcloud data fd for use in IoUringAssemblyEngine + std::shared_ptr + getPcloudDataFdDesc() const + { + return pcloudDataSocketDesc; + } + private: void setupSockets(); void setupCommandSocket(); diff --git a/stimBuffApis/livoxGen1/ioUringAssemblyEngine.cpp b/stimBuffApis/livoxGen1/ioUringAssemblyEngine.cpp index 772fb3c..7b78f38 100644 --- a/stimBuffApis/livoxGen1/ioUringAssemblyEngine.cpp +++ b/stimBuffApis/livoxGen1/ioUringAssemblyEngine.cpp @@ -4,6 +4,7 @@ #include #include "ioUringAssemblyEngine.h" #include "pcloudStimulusBuffer.h" +#include "livoxGen1.h" namespace smo { namespace stim_buff { @@ -44,7 +45,8 @@ bool IoUringAssemblyEngine::setup() { return false; } // Get UDP socket file descriptor - int udpFd = parent.device->pcloudDataSocketDesc->native_handle(); + int udpFd = (*livoxProto1.livoxProto1_getPcloudDataFdDesc)() + ->native_handle(); if (udpFd < 0) { return false; } diff --git a/stimBuffApis/livoxGen1/livoxGen1.cpp b/stimBuffApis/livoxGen1/livoxGen1.cpp index 8c84078..4a2906d 100644 --- a/stimBuffApis/livoxGen1/livoxGen1.cpp +++ b/stimBuffApis/livoxGen1/livoxGen1.cpp @@ -45,40 +45,28 @@ getStimBuff(const std::shared_ptr& spec) return nullptr; } -// LivoxProto1 library state -struct LivoxProto1DllState +// LivoxProto1DllState constructor implementation +LivoxProto1DllState::LivoxProto1DllState() +: dlopenHandle(nullptr, DlCloser), + livoxProto1_main(nullptr), + livoxProto1_exit(nullptr), + livoxProto1_getOrCreateDeviceReq(nullptr), + livoxProto1_destroyDeviceReq(nullptr), + livoxProto1_device_enablePcloudDataReq(nullptr), + livoxProto1_device_disablePcloudDataReq(nullptr), + livoxProto1_device_getReturnModeReq(nullptr), + livoxProto1_getPcloudDataFdDesc(nullptr) +{} + +// LivoxProto1DllState DlCloser implementation +void LivoxProto1DllState::DlCloser(void* handle) { - LivoxProto1DllState() - : dlopenHandle(nullptr, DlCloser), - livoxProto1_main(nullptr), - livoxProto1_exit(nullptr), - livoxProto1_getOrCreateDeviceReq(nullptr), - livoxProto1_destroyDeviceReq(nullptr), - livoxProto1_device_enablePcloudDataReq(nullptr), - livoxProto1_device_disablePcloudDataReq(nullptr), - livoxProto1_device_getReturnModeReq(nullptr) - {} - - static void DlCloser(void* handle) - { - if (handle) { - dlclose(handle); - } + if (handle) { + dlclose(handle); } +} - std::unique_ptr dlopenHandle; - livoxProto1_mainFn *livoxProto1_main; - livoxProto1_exitFn *livoxProto1_exit; - livoxProto1_getOrCreateDeviceReqFn *livoxProto1_getOrCreateDeviceReq; - livoxProto1_destroyDeviceReqFn *livoxProto1_destroyDeviceReq; - livoxProto1_device_enablePcloudDataReqFn - *livoxProto1_device_enablePcloudDataReq; - livoxProto1_device_disablePcloudDataReqFn - *livoxProto1_device_disablePcloudDataReq; - livoxProto1_device_getReturnModeReqFn *livoxProto1_device_getReturnModeReq; -}; - -static LivoxProto1DllState livoxProto1; +LivoxProto1DllState livoxProto1; // Continuation classes for async operations class AttachDeviceReq @@ -470,13 +458,19 @@ extern "C" int livoxGen1_initializeInd(void) dlsym( livoxProto1.dlopenHandle.get(), "livoxProto1_device_getReturnModeReq")); + livoxProto1.livoxProto1_getPcloudDataFdDesc = reinterpret_cast< + livoxProto1_getPcloudDataFdDescFn *>( + dlsym( + livoxProto1.dlopenHandle.get(), + "livoxProto1_getPcloudDataFdDesc")); if (!livoxProto1.livoxProto1_main || !livoxProto1.livoxProto1_exit || !livoxProto1.livoxProto1_getOrCreateDeviceReq || !livoxProto1.livoxProto1_destroyDeviceReq || !livoxProto1.livoxProto1_device_enablePcloudDataReq || !livoxProto1.livoxProto1_device_disablePcloudDataReq - || !livoxProto1.livoxProto1_device_getReturnModeReq) + || !livoxProto1.livoxProto1_device_getReturnModeReq + || !livoxProto1.livoxProto1_getPcloudDataFdDesc) { throw std::runtime_error( std::string(__func__) +