livoxGen1: Rn attachedDataProducers=>attachedStimulusProducers

Also compare producers only by device selector and not by the rest
of their stored DASpec.
This commit is contained in:
2025-11-14 23:26:13 -04:00
parent 98a493a8a1
commit 7d86ecadc4
+17 -14
View File
@@ -28,19 +28,22 @@ const SmoCallbacks* smoHooksPtr = nullptr;
static SmoThreadingModelDesc smoThreadingModelDesc; static SmoThreadingModelDesc smoThreadingModelDesc;
// Local collection of stimulus producers // Local collection of stimulus producers
static std::vector<std::shared_ptr<StimulusProducer>> attachedDataProducers; static std::vector<std::shared_ptr<StimulusProducer>> attachedStimulusProducers;
// Get stimulus producer by device attachment spec // Get stimulus producer by device attachment spec
static std::shared_ptr<StimulusProducer> static std::shared_ptr<StimulusProducer>
getDataProducer(const std::shared_ptr<smo::device::DeviceAttachmentSpec>& spec) getStimulusProducer(
const std::shared_ptr<smo::device::DeviceAttachmentSpec>& spec
)
{ {
for (const auto& dataProducer : attachedDataProducers) for (const auto& stimProducer : attachedStimulusProducers)
{ {
// Compare device selectors to find matching buffer // Compare device selectors to find matching buffer
if (dataProducer->deviceAttachmentSpec->deviceSelector if (livoxProto1::comms::deviceIdentifiersEqual(
== spec->deviceSelector) stimProducer->deviceAttachmentSpec->deviceSelector,
spec->deviceSelector))
{ {
return dataProducer; return stimProducer;
} }
} }
@@ -202,7 +205,7 @@ public:
context->stimProducer = pcloudDataProducer; context->stimProducer = pcloudDataProducer;
context->deviceTmp->nAttachedStimBuffs++; context->deviceTmp->nAttachedStimBuffs++;
attachedDataProducers.push_back(pcloudDataProducer); attachedStimulusProducers.push_back(pcloudDataProducer);
pcloudDataProducer->start(); pcloudDataProducer->start();
@@ -342,10 +345,10 @@ public:
// Remove stimulus producer from collection before destroying device // Remove stimulus producer from collection before destroying device
context->stimProducer->device->nAttachedStimBuffs--; context->stimProducer->device->nAttachedStimBuffs--;
auto it = std::find( auto it = std::find(
attachedDataProducers.begin(), attachedDataProducers.end(), attachedStimulusProducers.begin(), attachedStimulusProducers.end(),
context->stimProducer); context->stimProducer);
if (it != attachedDataProducers.end()) if (it != attachedStimulusProducers.end())
{ attachedDataProducers.erase(it); } { attachedStimulusProducers.erase(it); }
(*livoxProto1.livoxProto1_destroyDeviceReq)( (*livoxProto1.livoxProto1_destroyDeviceReq)(
context->stimProducer->device, context->stimProducer->device,
@@ -367,7 +370,7 @@ public:
/** NOTE: /** NOTE:
* There's a decent argument for falling through here and still * There's a decent argument for falling through here and still
* removing the stimulus producer from attachedDataProducers. * removing the stimulus producer from attachedStimulusProducers.
*/ */
context->callOriginalCb(false, context->spec); context->callOriginalCb(false, context->spec);
return; return;
@@ -490,7 +493,7 @@ extern "C" int livoxGen1_initializeInd(void)
extern "C" int livoxGen1_finalizeInd(void) extern "C" int livoxGen1_finalizeInd(void)
{ {
attachedDataProducers.clear(); attachedStimulusProducers.clear();
// Call LivoxProto1 library exit function // Call LivoxProto1 library exit function
if (livoxProto1.livoxProto1_exit) { if (livoxProto1.livoxProto1_exit) {
@@ -520,7 +523,7 @@ extern "C" void livoxGen1_attachDeviceReq(
// Check if stimulus producer already exists in the collection // Check if stimulus producer already exists in the collection
auto pcloudDataProducer = std::static_pointer_cast<PcloudDataProducer>( auto pcloudDataProducer = std::static_pointer_cast<PcloudDataProducer>(
getDataProducer(desc)); getStimulusProducer(desc));
if (pcloudDataProducer) if (pcloudDataProducer)
{ {
@@ -651,7 +654,7 @@ extern "C" void livoxGen1_detachDeviceReq(
{ {
// Check if stimulus producer exists in the collection // Check if stimulus producer exists in the collection
auto stimProducer = std::static_pointer_cast<PcloudDataProducer>( auto stimProducer = std::static_pointer_cast<PcloudDataProducer>(
getDataProducer(desc)); getStimulusProducer(desc));
if (!stimProducer) if (!stimProducer)
{ {