diff --git a/stimBuffApis/livoxGen1/CMakeLists.txt b/stimBuffApis/livoxGen1/CMakeLists.txt index 21a7c0f..a7bb062 100644 --- a/stimBuffApis/livoxGen1/CMakeLists.txt +++ b/stimBuffApis/livoxGen1/CMakeLists.txt @@ -59,7 +59,7 @@ if(ENABLE_STIMBUFFAPI_livoxGen1) add_library(livoxGen1 SHARED livoxGen1.cpp stagingBuffer.cpp - pcloudStimulusBuffer.cpp + pcloudDataProducer.cpp ioUringAssemblyEngine.cpp openClCollatingAndMeshingEngine.cpp openClKernels.cl.S diff --git a/stimBuffApis/livoxGen1/ioUringAssemblyEngine.cpp b/stimBuffApis/livoxGen1/ioUringAssemblyEngine.cpp index ef22923..dfacf3f 100644 --- a/stimBuffApis/livoxGen1/ioUringAssemblyEngine.cpp +++ b/stimBuffApis/livoxGen1/ioUringAssemblyEngine.cpp @@ -24,7 +24,7 @@ #include #include #include "ioUringAssemblyEngine.h" -#include "pcloudStimulusBuffer.h" +#include "pcloudDataProducer.h" #include "livoxGen1.h" // #define REGISTER_IOURING_BUFFERS @@ -56,7 +56,7 @@ struct DummyLivoxEthHeader }; IoUringAssemblyEngine::IoUringAssemblyEngine( - PcloudStimulusBuffer& parent_, size_t nDgramsPerStagingBufferFrame_) + PcloudDataProducer& parent_, size_t nDgramsPerStagingBufferFrame_) : parent(parent_), frameAssemblyDesc(nullptr), ring{}, eventfdFd(-1), eventfdDesc(nullptr), eventfd_value(0), diff --git a/stimBuffApis/livoxGen1/ioUringAssemblyEngine.h b/stimBuffApis/livoxGen1/ioUringAssemblyEngine.h index 4c3ddf0..865b170 100644 --- a/stimBuffApis/livoxGen1/ioUringAssemblyEngine.h +++ b/stimBuffApis/livoxGen1/ioUringAssemblyEngine.h @@ -24,13 +24,13 @@ namespace smo { namespace stim_buff { -class PcloudStimulusBuffer; +class PcloudDataProducer; class IoUringAssemblyEngine { public: explicit IoUringAssemblyEngine( - PcloudStimulusBuffer& parent, size_t nDgramsPerStagingBufferFrame); + PcloudDataProducer& parent, size_t nDgramsPerStagingBufferFrame); ~IoUringAssemblyEngine() = default; bool setup(); @@ -53,7 +53,7 @@ private: bool stop(); private: - PcloudStimulusBuffer& parent; + PcloudDataProducer& parent; // Cached descriptor for reuse across iterations std::shared_ptr frameAssemblyDesc; diff --git a/stimBuffApis/livoxGen1/livoxGen1.cpp b/stimBuffApis/livoxGen1/livoxGen1.cpp index 007cd1e..9e5116f 100644 --- a/stimBuffApis/livoxGen1/livoxGen1.cpp +++ b/stimBuffApis/livoxGen1/livoxGen1.cpp @@ -16,7 +16,7 @@ #include #include #include -#include "pcloudStimulusBuffer.h" +#include "pcloudDataProducer.h" #include "livoxGen1.h" @@ -27,20 +27,20 @@ namespace stim_buff { const SmoCallbacks* smoHooksPtr = nullptr; static SmoThreadingModelDesc smoThreadingModelDesc; -// Local collection of stimulus buffers -static std::vector> attachedStimBuffs; +// Local collection of stimulus producers +static std::vector> attachedDataProducers; -// Get stimulus buffer by device attachment spec +// Get stimulus producer by device attachment spec static std::shared_ptr -getStimBuff(const std::shared_ptr& spec) +getDataProducer(const std::shared_ptr& spec) { - for (const auto& stimBuff : attachedStimBuffs) + for (const auto& dataProducer : attachedDataProducers) { // Compare device selectors to find matching buffer - if (stimBuff->deviceAttachmentSpec->deviceSelector + if (dataProducer->deviceAttachmentSpec->deviceSelector == spec->deviceSelector) { - return stimBuff; + return dataProducer; } } @@ -85,7 +85,7 @@ public: public: const std::shared_ptr spec; - std::shared_ptr stimBuff; + std::shared_ptr stimProducer; std::shared_ptr deviceTmp; private: @@ -193,17 +193,17 @@ public: } } - // Create and add PcloudStimulusBuffer to collection now that device is ready + // Create and add PcloudDataProducer to collection now that device is ready StimulusBuffer::PcloudFormatDesc formatDesc; formatDesc.format = StimulusBuffer::PcloudFormatDesc::Format::XYZI; - auto pcloudStimBuff = std::make_shared( + auto pcloudDataProducer = std::make_shared( context->spec, context->deviceTmp, formatDesc, histbuffMs, 30); - context->stimBuff = pcloudStimBuff; + context->stimProducer = pcloudDataProducer; context->deviceTmp->nAttachedStimBuffs++; - attachedStimBuffs.push_back(pcloudStimBuff); + attachedDataProducers.push_back(pcloudDataProducer); - pcloudStimBuff->start(); + pcloudDataProducer->start(); if (1 || smoHooksPtr->OptionParser_getOptions().verbose) { @@ -221,7 +221,7 @@ public: { // Initialize timer with device's component thread delayTimer = std::make_unique( - context->stimBuff->device->componentThread->getIoService()); + context->stimProducer->device->componentThread->getIoService()); delayTimer->expires_from_now(boost::posix_time::milliseconds(5)); delayTimer->async_wait( @@ -244,7 +244,7 @@ public: } (*livoxProto1.livoxProto1_device_enablePcloudDataReq)( - context->stimBuff->device, + context->stimProducer->device, {context, std::bind( &AttachDeviceReq::attachDeviceReq5, context.get(), context, @@ -280,16 +280,16 @@ class DetachDeviceReq public: DetachDeviceReq( const std::shared_ptr& spec, - const std::shared_ptr& stimBuff, + const std::shared_ptr& stimProducer, smo::Callback cb) : smo::NonPostedAsynchronousContinuation( std::move(cb)), - spec(spec), stimBuff(stimBuff) + spec(spec), stimProducer(stimProducer) {} public: const std::shared_ptr spec; - std::shared_ptr stimBuff; + std::shared_ptr stimProducer; private: std::unique_ptr delayTimer; @@ -301,7 +301,7 @@ public: if (!success) { std::cerr << __func__ << ": Failed to disable pcloud data for " - "stimbuff " << context->spec->deviceSelector << std::endl; + "stim producer " << context->spec->deviceSelector << std::endl; // Fallthrough. } @@ -315,7 +315,7 @@ public: { // Initialize timer with device's component thread delayTimer = std::make_unique( - context->stimBuff->device->componentThread->getIoService()); + context->stimProducer->device->componentThread->getIoService()); delayTimer->expires_from_now(boost::posix_time::milliseconds(5)); delayTimer->async_wait( @@ -337,17 +337,17 @@ public: // Fallthrough. } - context->stimBuff->stop(); - // Remove stimulus buffer from collection before destroying device - context->stimBuff->device->nAttachedStimBuffs--; + context->stimProducer->stop(); + // Remove stimulus producer from collection before destroying device + context->stimProducer->device->nAttachedStimBuffs--; auto it = std::find( - attachedStimBuffs.begin(), attachedStimBuffs.end(), - context->stimBuff); - if (it != attachedStimBuffs.end()) - { attachedStimBuffs.erase(it); } + attachedDataProducers.begin(), attachedDataProducers.end(), + context->stimProducer); + if (it != attachedDataProducers.end()) + { attachedDataProducers.erase(it); } (*livoxProto1.livoxProto1_destroyDeviceReq)( - context->stimBuff->device, + context->stimProducer->device, {context, std::bind( &DetachDeviceReq::detachDeviceReq2, context.get(), context, @@ -361,12 +361,12 @@ public: if (!success) { std::cerr << __func__ << ": Failed to destroy dev " - "device " << context->spec->deviceSelector << " for stimbuff." - "\n"; + "device " << context->spec->deviceSelector << " for stim " + "producer.\n"; /** NOTE: * There's a decent argument for falling through here and still - * removing the stimulus buffer from attachedStimBuffs. + * removing the stimulus producer from attachedDataProducers. */ context->callOriginalCb(false, context->spec); return; @@ -374,8 +374,8 @@ public: if (1 || smoHooksPtr->OptionParser_getOptions().verbose) { - std::cout << __func__ << ": Successfully detached pcloud stimbuff " - "for device " << context->spec->deviceSelector + std::cout << __func__ << ": Successfully detached pcloud stim " + "producer for device " << context->spec->deviceSelector << " and possibly also destroyed device.\n"; } @@ -489,7 +489,7 @@ extern "C" int livoxGen1_initializeInd(void) extern "C" int livoxGen1_finalizeInd(void) { - attachedStimBuffs.clear(); + attachedDataProducers.clear(); // Call LivoxProto1 library exit function if (livoxProto1.livoxProto1_exit) { @@ -517,16 +517,16 @@ extern "C" void livoxGen1_attachDeviceReq( auto request = std::make_shared(desc, cb); - // Check if stimulus buffer already exists in the collection - auto pcloudStimBuff = std::static_pointer_cast( - getStimBuff(desc)); + // Check if stimulus producer already exists in the collection + auto pcloudDataProducer = std::static_pointer_cast( + getDataProducer(desc)); - if (pcloudStimBuff) + if (pcloudDataProducer) { - request->stimBuff = pcloudStimBuff; + request->stimProducer = pcloudDataProducer; // Check if device's point cloud data is already active - if (pcloudStimBuff->device && pcloudStimBuff->device->pcloudDataActive) + if (pcloudDataProducer->device && pcloudDataProducer->device->pcloudDataActive) { // Point cloud data is already active, call success callback request->callOriginalCb(true, request->spec); @@ -537,7 +537,7 @@ extern "C" void livoxGen1_attachDeviceReq( * sent to device prior to us reaching here. */ (*livoxProto1.livoxProto1_device_enablePcloudDataReq)( - pcloudStimBuff->device, + pcloudDataProducer->device, {request, std::bind( &AttachDeviceReq::attachDeviceReq5, request.get(), request, @@ -648,22 +648,22 @@ extern "C" void livoxGen1_detachDeviceReq( Callback cb ) { - // Check if stimulus buffer exists in the collection - auto stimBuff = std::static_pointer_cast( - getStimBuff(desc)); + // Check if stimulus producer exists in the collection + auto stimProducer = std::static_pointer_cast( + getDataProducer(desc)); - if (!stimBuff) + if (!stimProducer) { cb.callbackFn(false, desc); return; } auto request = std::make_shared( - desc, stimBuff, cb); + desc, stimProducer, cb); // Disable point cloud data first (*livoxProto1.livoxProto1_device_disablePcloudDataReq)( - stimBuff->device, + stimProducer->device, {request, std::bind( &DetachDeviceReq::detachDeviceReq1, request.get(), request, diff --git a/stimBuffApis/livoxGen1/openClCollatingAndMeshingEngine.cpp b/stimBuffApis/livoxGen1/openClCollatingAndMeshingEngine.cpp index 79dd943..f646732 100644 --- a/stimBuffApis/livoxGen1/openClCollatingAndMeshingEngine.cpp +++ b/stimBuffApis/livoxGen1/openClCollatingAndMeshingEngine.cpp @@ -13,7 +13,7 @@ #include #include "livoxGen1.h" #include "openClCollatingAndMeshingEngine.h" -#include "pcloudStimulusBuffer.h" +#include "pcloudDataProducer.h" #include "openClKernels.h" #include "frameAssemblyDesc.h" #include "ioUringAssemblyEngine.h" @@ -82,7 +82,7 @@ static bool validateOpenClVersion( } OpenClCollatingAndMeshingEngine::OpenClCollatingAndMeshingEngine( - PcloudStimulusBuffer& parent_) + PcloudDataProducer& parent_) : parent(parent_), platform(nullptr), device(nullptr), diff --git a/stimBuffApis/livoxGen1/openClCollatingAndMeshingEngine.h b/stimBuffApis/livoxGen1/openClCollatingAndMeshingEngine.h index 5d5b5e0..299119c 100644 --- a/stimBuffApis/livoxGen1/openClCollatingAndMeshingEngine.h +++ b/stimBuffApis/livoxGen1/openClCollatingAndMeshingEngine.h @@ -21,12 +21,12 @@ namespace smo { namespace stim_buff { -class PcloudStimulusBuffer; +class PcloudDataProducer; class OpenClCollatingAndMeshingEngine { public: - explicit OpenClCollatingAndMeshingEngine(PcloudStimulusBuffer& parent); + explicit OpenClCollatingAndMeshingEngine(PcloudDataProducer& parent); ~OpenClCollatingAndMeshingEngine(); // Non-copyable, movable @@ -70,7 +70,7 @@ public: std::chrono::milliseconds getCollateKernelDuration() const; private: - PcloudStimulusBuffer& parent; + PcloudDataProducer& parent; // OpenCL infrastructure cl_platform_id platform; diff --git a/stimBuffApis/livoxGen1/pcloudStimulusBuffer.cpp b/stimBuffApis/livoxGen1/pcloudDataProducer.cpp similarity index 93% rename from stimBuffApis/livoxGen1/pcloudStimulusBuffer.cpp rename to stimBuffApis/livoxGen1/pcloudDataProducer.cpp index 8470ec3..8b5cf9b 100644 --- a/stimBuffApis/livoxGen1/pcloudStimulusBuffer.cpp +++ b/stimBuffApis/livoxGen1/pcloudDataProducer.cpp @@ -7,7 +7,7 @@ #include #include #include -#include "pcloudStimulusBuffer.h" +#include "pcloudDataProducer.h" #include "frameAssemblyDesc.h" namespace smo { @@ -19,7 +19,7 @@ extern const SmoCallbacks* smoHooksPtr; static SpMcRingBuffer::InputEngineConstraints openClInputConstraints( static_cast(sysconf(_SC_PAGE_SIZE)), sizeof(void *)); -PcloudStimulusBuffer::PcloudStimulusBuffer( +PcloudDataProducer::PcloudDataProducer( const std::shared_ptr &deviceAttachmentSpec, std::shared_ptr &device, const PcloudFormatDesc& formatDesc, @@ -61,7 +61,7 @@ collationBuffer( #endif { std::string errMsg = std::string(__func__) + - ": PcloudStimulusBuffer constructor called on non-world/body thread " + + ": PcloudDataProducer constructor called on non-world/body thread " + smoHooksPtr->ComponentThread_getSelf()->name; std::cout << errMsg << std::endl; @@ -69,7 +69,7 @@ collationBuffer( } } -void PcloudStimulusBuffer::start() +void PcloudDataProducer::start() { // Call ioUringAssemblyEngine setup() as the first step if (!ioUringAssemblyEngine.setup()) @@ -90,7 +90,7 @@ void PcloudStimulusBuffer::start() StimulusBuffer::start(); } -void PcloudStimulusBuffer::stop() +void PcloudDataProducer::stop() { // Call base class stop() as the first step StimulusBuffer::stop(); @@ -103,22 +103,22 @@ void produceStimFrameAck(void) { } -void PcloudStimulusBuffer::stimFrameProductionTimesliceInd() +void PcloudDataProducer::stimFrameProductionTimesliceInd() { produceFrameReq({nullptr, nullptr}); } -class PcloudStimulusBuffer::ProduceFrameReq +class PcloudDataProducer::ProduceFrameReq : public PostedAsynchronousContinuation { private: - PcloudStimulusBuffer& stimBuff; + PcloudDataProducer& stimBuff; AsynchronousLoop frameAssemblyResult; StimulusFrame& stimulusFrame; public: ProduceFrameReq( - PcloudStimulusBuffer& buffer, + PcloudDataProducer& buffer, const std::shared_ptr& caller, Callback cb) : PostedAsynchronousContinuation(caller, cb), @@ -207,7 +207,7 @@ public: } }; -void PcloudStimulusBuffer::produceFrameReq( +void PcloudDataProducer::produceFrameReq( smo::Callback callback) { /** EXPLANATION: diff --git a/stimBuffApis/livoxGen1/pcloudStimulusBuffer.h b/stimBuffApis/livoxGen1/pcloudDataProducer.h similarity index 71% rename from stimBuffApis/livoxGen1/pcloudStimulusBuffer.h rename to stimBuffApis/livoxGen1/pcloudDataProducer.h index e663932..2340298 100644 --- a/stimBuffApis/livoxGen1/pcloudStimulusBuffer.h +++ b/stimBuffApis/livoxGen1/pcloudDataProducer.h @@ -1,7 +1,8 @@ -#ifndef _LIVOX_GEN1_PCLOUD_STIMULUS_BUFFER_H -#define _LIVOX_GEN1_PCLOUD_STIMULUS_BUFFER_H +#ifndef _LIVOX_GEN1_PCLOUD_DATA_PRODUCER_H +#define _LIVOX_GEN1_PCLOUD_DATA_PRODUCER_H #include +#include #include #include #include @@ -14,31 +15,31 @@ namespace smo { namespace stim_buff { /** - * PcloudStimulusBuffer is a specialized StimulusBuffer for point cloud data. + * PcloudDataProducer is a specialized StimulusBuffer for point cloud data. * * This class extends StimulusBuffer to handle point cloud-specific stimulus * frames, particularly those generated from LiDAR point cloud data. It * provides additional functionality for managing point cloud frame metadata * and processing. */ -class PcloudStimulusBuffer +class PcloudDataProducer : public StimulusBuffer { public: - explicit PcloudStimulusBuffer( + explicit PcloudDataProducer( const std::shared_ptr &deviceAttachmentSpec, std::shared_ptr &device, const PcloudFormatDesc& formatDesc, int histbuffMs, size_t nDgramsPerStagingBufferFrame); - ~PcloudStimulusBuffer() = default; + ~PcloudDataProducer() = default; // Non-copyable, movable - PcloudStimulusBuffer(const PcloudStimulusBuffer&) = delete; - PcloudStimulusBuffer& operator=(const PcloudStimulusBuffer&) = delete; - PcloudStimulusBuffer(PcloudStimulusBuffer&&) = default; - PcloudStimulusBuffer& operator=(PcloudStimulusBuffer&&) = default; + PcloudDataProducer(const PcloudDataProducer&) = delete; + PcloudDataProducer& operator=(const PcloudDataProducer&) = delete; + PcloudDataProducer(PcloudDataProducer&&) = default; + PcloudDataProducer& operator=(PcloudDataProducer&&) = default; // Control methods void start() override; @@ -59,6 +60,7 @@ public: StagingBuffer assemblyBuffer; IoUringAssemblyEngine ioUringAssemblyEngine; StagingBuffer collationBuffer; + std::atomic nAttachedStimBuffs{0}; private: class ProduceFrameReq; @@ -67,4 +69,4 @@ private: } // namespace stim_buff } // namespace smo -#endif // _LIVOX_GEN1_PCLOUD_STIMULUS_BUFFER_H +#endif // _LIVOX_GEN1_PCLOUD_DATA_PRODUCER_H