livoxGen1: Add correctness checks to attachDeviceReq
This commit is contained in:
@@ -67,8 +67,8 @@ getStimulusProducer(
|
||||
{
|
||||
// Compare device selectors to find matching buffer
|
||||
if (livoxProto1::comms::deviceIdentifiersEqual(
|
||||
stimProducer->deviceAttachmentSpec->deviceSelector,
|
||||
spec->deviceSelector)
|
||||
stimProducer->deviceAttachmentSpec->deviceSelector,
|
||||
spec->deviceSelector)
|
||||
&& isProducerForStimFeature(stimProducer, spec->qualeIfaceApi))
|
||||
{
|
||||
return stimProducer;
|
||||
@@ -258,6 +258,13 @@ public:
|
||||
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
|
||||
* (race condition or double-add)
|
||||
*/
|
||||
@@ -280,17 +287,43 @@ public:
|
||||
|
||||
context->stimProducer = pcloudDataProducer;
|
||||
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);
|
||||
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();
|
||||
|
||||
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
|
||||
attachDeviceReq4_doCreateStimBuff_maybeDirectlyCalled(context);
|
||||
}
|
||||
@@ -651,12 +684,10 @@ extern "C" void livoxGen1_attachDeviceReq(
|
||||
auto request = std::make_shared<AttachDeviceReq>(desc, cb);
|
||||
|
||||
// Case 1: Check if StimBuffer already exists
|
||||
auto stimProducerBase = getStimulusProducer(desc);
|
||||
if (stimProducerBase)
|
||||
auto stimProducer = std::dynamic_pointer_cast<PcloudStimulusProducer>(
|
||||
getStimulusProducer(desc));
|
||||
if (stimProducer)
|
||||
{
|
||||
auto stimProducer = std::static_pointer_cast<PcloudStimulusProducer>(
|
||||
stimProducerBase);
|
||||
|
||||
auto existingBuffer = stimProducer->getAttachedStimulusBuffer(desc);
|
||||
if (existingBuffer)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user