StimBuff: Make virtual so we can dynamic_cast in getOrCreateStimBuff
This commit is contained in:
@@ -30,6 +30,8 @@ static SmoThreadingModelDesc smoThreadingModelDesc;
|
||||
// Local collection of stimulus producers
|
||||
static std::vector<std::shared_ptr<StimulusProducer>> attachedStimulusProducers;
|
||||
|
||||
static bool isSupportedQualeIfaceApi(const std::string& qualeIfaceApi);
|
||||
|
||||
// Check if a StimulusProducer matches the requested stim feature
|
||||
static bool isProducerForStimFeature(
|
||||
const std::shared_ptr<StimulusProducer>& stimProducer,
|
||||
@@ -192,6 +194,17 @@ private:
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check for duplicate qualeIfaceApi
|
||||
const std::string& qualeIfaceApi = context->spec->qualeIfaceApi;
|
||||
if (context->stimProducer->hasBufferWithQualeIfaceApi(qualeIfaceApi))
|
||||
{
|
||||
std::cerr << __func__ << ": Buffer with qualeIfaceApi '"
|
||||
<< qualeIfaceApi << "' already exists for this producer. "
|
||||
"Each producer can only have one buffer per qualeIfaceApi."
|
||||
<< std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
// Parse histbuffMs
|
||||
int histbuffMs = parseHistbuffMs(context->spec);
|
||||
|
||||
@@ -203,7 +216,7 @@ private:
|
||||
std::cerr << __func__ << ": Failed to create StimBuffer: "
|
||||
<< e.what() << ". Producer is committed, DeviceReattacher will retry."
|
||||
<< std::endl;
|
||||
// Return false so DeviceReattacher can retry later
|
||||
// Return false so caller can handle error callback
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -604,6 +617,13 @@ static const StimBuffApiDesc livoxGen1ApiDesc = {
|
||||
}
|
||||
};
|
||||
|
||||
static bool isSupportedQualeIfaceApi(const std::string& qualeIfaceApi)
|
||||
{
|
||||
// Check if this is a supported (implemented) qualeIfaceApi
|
||||
return qualeIfaceApi == "mesh" || qualeIfaceApi == "pcloudIntensity" ||
|
||||
qualeIfaceApi == "pcloudAmbience";
|
||||
}
|
||||
|
||||
// Callback function implementations
|
||||
extern "C" int livoxGen1_initializeInd(void)
|
||||
{
|
||||
@@ -713,6 +733,29 @@ extern "C" void livoxGen1_attachDeviceReq(
|
||||
"not available");
|
||||
}
|
||||
|
||||
// Validate qualeIfaceApi
|
||||
const std::string& qualeIfaceApi = desc->qualeIfaceApi;
|
||||
if (qualeIfaceApi == "gyro" || qualeIfaceApi == "accel")
|
||||
{
|
||||
// These are for ImuStimulusProducer (not yet implemented)
|
||||
std::cerr << __func__ << ": qualeIfaceApi '" << qualeIfaceApi
|
||||
<< "' requires ImuStimulusProducer which is not yet implemented"
|
||||
<< std::endl;
|
||||
cb.callbackFn(false, desc);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!isSupportedQualeIfaceApi(qualeIfaceApi))
|
||||
{
|
||||
// Unknown qualeIfaceApi
|
||||
std::cerr << __func__ << ": Unsupported qualeIfaceApi '"
|
||||
<< qualeIfaceApi << "' for LivoxGen1. "
|
||||
"Supported values: mesh, pcloudIntensity, pcloudAmbience"
|
||||
<< std::endl;
|
||||
cb.callbackFn(false, desc);
|
||||
return;
|
||||
}
|
||||
|
||||
auto request = std::make_shared<AttachDeviceReq>(desc, cb);
|
||||
|
||||
// Case 1: Check if StimBuffer already exists
|
||||
@@ -740,7 +783,23 @@ extern "C" void livoxGen1_attachDeviceReq(
|
||||
}
|
||||
else
|
||||
{
|
||||
// StimProducer exists, StimBuffer doesn't
|
||||
/** EXPLANATION:
|
||||
* StimProducer exists, StimBuffer doesn't (DASpec doesn't match)
|
||||
* Check if producer already has a buffer with the requested
|
||||
* qualeIfaceApi but different DASpec - this is not allowed.
|
||||
*/
|
||||
if (stimProducer->hasBufferWithQualeIfaceApi(desc->qualeIfaceApi))
|
||||
{
|
||||
std::cerr << __func__ << ": Producer already has a buffer with "
|
||||
"qualeIfaceApi '" << desc->qualeIfaceApi
|
||||
<< "' but with a different DeviceAttachmentSpec. "
|
||||
"A single LivoxGen1 device cannot support multiple DASpecs "
|
||||
"with the same qualeIfaceApi." << std::endl;
|
||||
|
||||
cb.callbackFn(false, desc);
|
||||
return;
|
||||
}
|
||||
|
||||
request->stimProducer = stimProducer;
|
||||
// Ensure StimBuffer is attached and enable pcloud data if needed
|
||||
request->attachDeviceReq4_doCreateStimBuff_maybeDirectlyCalled(
|
||||
|
||||
Reference in New Issue
Block a user