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:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user