Rename PcloudStimulusBuffer=>PcloudDataProducer
This prepares us for the split up of classes. We're going to split StimulusBuffer into two base classes: StimulusBuffer and StimulusProducer.
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
#include <callableTracer.h>
|
||||
#include <spinLock.h>
|
||||
#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),
|
||||
|
||||
@@ -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> frameAssemblyDesc;
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
#include <livoxProto1/protocol.h>
|
||||
#include <asynchronousContinuation.h>
|
||||
#include <boost/asio/deadline_timer.hpp>
|
||||
#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<std::shared_ptr<StimulusBuffer>> attachedStimBuffs;
|
||||
// Local collection of stimulus producers
|
||||
static std::vector<std::shared_ptr<StimulusBuffer>> attachedDataProducers;
|
||||
|
||||
// Get stimulus buffer by device attachment spec
|
||||
// Get stimulus producer by device attachment spec
|
||||
static std::shared_ptr<StimulusBuffer>
|
||||
getStimBuff(const std::shared_ptr<smo::device::DeviceAttachmentSpec>& spec)
|
||||
getDataProducer(const std::shared_ptr<smo::device::DeviceAttachmentSpec>& 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<smo::device::DeviceAttachmentSpec> spec;
|
||||
std::shared_ptr<PcloudStimulusBuffer> stimBuff;
|
||||
std::shared_ptr<PcloudDataProducer> stimProducer;
|
||||
std::shared_ptr<livoxProto1::Device> 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<PcloudStimulusBuffer>(
|
||||
auto pcloudDataProducer = std::make_shared<PcloudDataProducer>(
|
||||
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<boost::asio::deadline_timer>(
|
||||
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<smo::device::DeviceAttachmentSpec>& spec,
|
||||
const std::shared_ptr<PcloudStimulusBuffer>& stimBuff,
|
||||
const std::shared_ptr<PcloudDataProducer>& stimProducer,
|
||||
smo::Callback<sal_mlo_detachDeviceReqCbFn> cb)
|
||||
: smo::NonPostedAsynchronousContinuation<sal_mlo_detachDeviceReqCbFn>(
|
||||
std::move(cb)),
|
||||
spec(spec), stimBuff(stimBuff)
|
||||
spec(spec), stimProducer(stimProducer)
|
||||
{}
|
||||
|
||||
public:
|
||||
const std::shared_ptr<smo::device::DeviceAttachmentSpec> spec;
|
||||
std::shared_ptr<PcloudStimulusBuffer> stimBuff;
|
||||
std::shared_ptr<PcloudDataProducer> stimProducer;
|
||||
private:
|
||||
std::unique_ptr<boost::asio::deadline_timer> 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<boost::asio::deadline_timer>(
|
||||
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<AttachDeviceReq>(desc, cb);
|
||||
|
||||
// Check if stimulus buffer already exists in the collection
|
||||
auto pcloudStimBuff = std::static_pointer_cast<PcloudStimulusBuffer>(
|
||||
getStimBuff(desc));
|
||||
// Check if stimulus producer already exists in the collection
|
||||
auto pcloudDataProducer = std::static_pointer_cast<PcloudDataProducer>(
|
||||
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<smo::stim_buff::sal_mlo_detachDeviceReqCbFn> cb
|
||||
)
|
||||
{
|
||||
// Check if stimulus buffer exists in the collection
|
||||
auto stimBuff = std::static_pointer_cast<PcloudStimulusBuffer>(
|
||||
getStimBuff(desc));
|
||||
// Check if stimulus producer exists in the collection
|
||||
auto stimProducer = std::static_pointer_cast<PcloudDataProducer>(
|
||||
getDataProducer(desc));
|
||||
|
||||
if (!stimBuff)
|
||||
if (!stimProducer)
|
||||
{
|
||||
cb.callbackFn(false, desc);
|
||||
return;
|
||||
}
|
||||
|
||||
auto request = std::make_shared<DetachDeviceReq>(
|
||||
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,
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
#include <user/stimulusFrame.h>
|
||||
#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),
|
||||
|
||||
@@ -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;
|
||||
|
||||
+10
-10
@@ -7,7 +7,7 @@
|
||||
#include <componentThread.h>
|
||||
#include <asynchronousLoop.h>
|
||||
#include <user/stimulusFrame.h>
|
||||
#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<size_t>(sysconf(_SC_PAGE_SIZE)), sizeof(void *));
|
||||
|
||||
PcloudStimulusBuffer::PcloudStimulusBuffer(
|
||||
PcloudDataProducer::PcloudDataProducer(
|
||||
const std::shared_ptr<device::DeviceAttachmentSpec> &deviceAttachmentSpec,
|
||||
std::shared_ptr<livoxProto1::Device> &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<produceFrameReqCbFn>
|
||||
{
|
||||
private:
|
||||
PcloudStimulusBuffer& stimBuff;
|
||||
PcloudDataProducer& stimBuff;
|
||||
AsynchronousLoop frameAssemblyResult;
|
||||
StimulusFrame& stimulusFrame;
|
||||
|
||||
public:
|
||||
ProduceFrameReq(
|
||||
PcloudStimulusBuffer& buffer,
|
||||
PcloudDataProducer& buffer,
|
||||
const std::shared_ptr<ComponentThread>& caller,
|
||||
Callback<produceFrameReqCbFn> cb)
|
||||
: PostedAsynchronousContinuation<produceFrameReqCbFn>(caller, cb),
|
||||
@@ -207,7 +207,7 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
void PcloudStimulusBuffer::produceFrameReq(
|
||||
void PcloudDataProducer::produceFrameReq(
|
||||
smo::Callback<produceFrameReqCbFn> callback)
|
||||
{
|
||||
/** EXPLANATION:
|
||||
+13
-11
@@ -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 <functional>
|
||||
#include <atomic>
|
||||
#include <user/stimulusBuffer.h>
|
||||
#include <livoxProto1/device.h>
|
||||
#include <asynchronousContinuation.h>
|
||||
@@ -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<device::DeviceAttachmentSpec> &deviceAttachmentSpec,
|
||||
std::shared_ptr<livoxProto1::Device> &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<size_t> 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
|
||||
Reference in New Issue
Block a user