livoxGen1: Add correctness checks to attachDeviceReq

This commit is contained in:
2025-11-15 19:41:31 -04:00
parent 340604c4ea
commit 2d1c026cc2
2 changed files with 51 additions and 14 deletions
+43 -12
View File
@@ -258,6 +258,13 @@ public:
return; return;
} }
if (1 || smoHooksPtr->OptionParser_getOptions().verbose)
{
std::cout << __func__ << ": Got return mode (" << (int)mode
<< ") for device: " << context->spec->deviceSelector
<< std::endl;
}
/* Check if PcloudStimulusProducer already exists /* Check if PcloudStimulusProducer already exists
* (race condition or double-add) * (race condition or double-add)
*/ */
@@ -280,17 +287,43 @@ public:
context->stimProducer = pcloudDataProducer; context->stimProducer = pcloudDataProducer;
context->deviceTmp->nAttachedStimulusProducers++; context->deviceTmp->nAttachedStimulusProducers++;
if (context->deviceTmp->nAttachedStimulusProducers > 2)
{
throw std::runtime_error(
std::string(__func__) + ": Each LivoxGen1 device can only have "
"at most two StimulusProducers attached to it. Found "
+ std::to_string(
context->deviceTmp->nAttachedStimulusProducers) + ".");
}
attachedStimulusProducers.push_back(pcloudDataProducer); attachedStimulusProducers.push_back(pcloudDataProducer);
if (false
/*attachedStimulusProducers.size() >= 2*nDevicesKnownToGen1Lib */)
{
/** TODO:
* It would be nice to add an nDevicesKnownToGen1Lib counter, and
* then add a check here to ensure that
* attachedStimulusProducers.size() is always less than or equal to
* 2*nDevicesKnownToGen1Lib.
*
* (2 stim producers per device).
*/
#if 0
throw std::runtime_error(
std::string(__func__) + ": Number of StimulusProducers attached "
"to LivoxGen1 devices known to the library ("
+ std::to_string(attachedStimulusProducers.size())
+ ") is greater than "
"expected. Lib knows about "
+ std::to_string(nDevicesKnownToGen1Lib) + " devices, "
"so there should be at most "
+ std::to_string(2*nDevicesKnownToGen1Lib)
+ " StimulusProducers attached to devices.");
#endif
}
pcloudDataProducer->start(); pcloudDataProducer->start();
if (1 || smoHooksPtr->OptionParser_getOptions().verbose)
{
std::cout << __func__ << ": Got return mode (" << (int)mode
<< ") for device: " << context->spec->deviceSelector
<< std::endl;
}
// Ensure StimBuffer is attached // Ensure StimBuffer is attached
attachDeviceReq4_doCreateStimBuff_maybeDirectlyCalled(context); attachDeviceReq4_doCreateStimBuff_maybeDirectlyCalled(context);
} }
@@ -651,12 +684,10 @@ extern "C" void livoxGen1_attachDeviceReq(
auto request = std::make_shared<AttachDeviceReq>(desc, cb); auto request = std::make_shared<AttachDeviceReq>(desc, cb);
// Case 1: Check if StimBuffer already exists // Case 1: Check if StimBuffer already exists
auto stimProducerBase = getStimulusProducer(desc); auto stimProducer = std::dynamic_pointer_cast<PcloudStimulusProducer>(
if (stimProducerBase) getStimulusProducer(desc));
if (stimProducer)
{ {
auto stimProducer = std::static_pointer_cast<PcloudStimulusProducer>(
stimProducerBase);
auto existingBuffer = stimProducer->getAttachedStimulusBuffer(desc); auto existingBuffer = stimProducer->getAttachedStimulusBuffer(desc);
if (existingBuffer) if (existingBuffer)
{ {
@@ -68,6 +68,9 @@ collationBuffer(
void PcloudStimulusProducer::start() void PcloudStimulusProducer::start()
{ {
std::cout << __func__ << ": Starting PcloudStimulusProducer for device "
<< device->discoveredDevice.deviceIdentifier << std::endl;
// Call ioUringAssemblyEngine setup() as the first step // Call ioUringAssemblyEngine setup() as the first step
if (!ioUringAssemblyEngine.setup()) if (!ioUringAssemblyEngine.setup())
{ {
@@ -89,6 +92,9 @@ void PcloudStimulusProducer::start()
void PcloudStimulusProducer::stop() void PcloudStimulusProducer::stop()
{ {
std::cout << __func__ << ": Stopping PcloudStimulusProducer for device "
<< device->discoveredDevice.deviceIdentifier << std::endl;
// Call base class stop() as the first step // Call base class stop() as the first step
StimulusProducer::stop(); StimulusProducer::stop();
// Call ioUringAssemblyEngine stop() as the final step // Call ioUringAssemblyEngine stop() as the final step