StimBuff: Make virtual so we can dynamic_cast in getOrCreateStimBuff
This commit is contained in:
@@ -106,6 +106,40 @@ void produceStimFrameAck(void)
|
||||
{
|
||||
}
|
||||
|
||||
std::shared_ptr<StimulusBuffer>
|
||||
PcloudStimulusProducer::getAttachedStimulusBuffer(
|
||||
const std::shared_ptr<device::DeviceAttachmentSpec>& spec) const
|
||||
{
|
||||
// Call base class implementation
|
||||
auto buffer = StimulusProducer::getAttachedStimulusBuffer(spec);
|
||||
if (!buffer)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// Optionally validate/upcast the buffer type matches expected type
|
||||
// based on qualeIfaceApi (for type safety)
|
||||
const std::string& qualeIfaceApi = spec->qualeIfaceApi;
|
||||
if (qualeIfaceApi == "mesh")
|
||||
{
|
||||
if (std::dynamic_pointer_cast<MeshStimulusBuffer>(buffer))
|
||||
{ return buffer; }
|
||||
}
|
||||
else if (qualeIfaceApi == "pcloudIntensity")
|
||||
{
|
||||
if (std::dynamic_pointer_cast<PcloudIntensityStimulusBuffer>(buffer))
|
||||
{ return buffer; }
|
||||
}
|
||||
else if (qualeIfaceApi == "pcloudAmbience")
|
||||
{
|
||||
if (std::dynamic_pointer_cast<PcloudAmbienceStimulusBuffer>(buffer))
|
||||
{ return buffer; }
|
||||
}
|
||||
|
||||
// Type mismatch - return nullptr
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::shared_ptr<StimulusBuffer>
|
||||
PcloudStimulusProducer::getOrCreateAttachedStimulusBuffer(
|
||||
const std::shared_ptr<device::DeviceAttachmentSpec>& deviceAttachmentSpec,
|
||||
@@ -117,15 +151,43 @@ PcloudStimulusProducer::getOrCreateAttachedStimulusBuffer(
|
||||
if (existingBuffer)
|
||||
{ return existingBuffer; }
|
||||
|
||||
// Create new MeshStimulusBuffer (for now, always use XYZ type)
|
||||
auto buffer = std::make_shared<MeshStimulusBuffer>(
|
||||
*this, deviceAttachmentSpec, histbuffMs, openClInputConstraints);
|
||||
// Parse qualeIfaceApi to determine buffer type
|
||||
const std::string& qualeIfaceApi = deviceAttachmentSpec->qualeIfaceApi;
|
||||
|
||||
// Add to collection
|
||||
attachedStimulusBuffers.push_back(buffer);
|
||||
// Update specialized member
|
||||
meshStimulusBuffer = buffer;
|
||||
return buffer;
|
||||
if (qualeIfaceApi == "mesh")
|
||||
{
|
||||
auto meshBuffer = std::make_shared<MeshStimulusBuffer>(
|
||||
*this, deviceAttachmentSpec, histbuffMs, openClInputConstraints);
|
||||
|
||||
meshStimulusBuffer = meshBuffer;
|
||||
attachedStimulusBuffers.push_back(meshBuffer);
|
||||
return meshBuffer;
|
||||
}
|
||||
else if (qualeIfaceApi == "pcloudIntensity")
|
||||
{
|
||||
auto intensityBuffer = std::make_shared<PcloudIntensityStimulusBuffer>(
|
||||
*this, deviceAttachmentSpec, histbuffMs, openClInputConstraints);
|
||||
|
||||
intensityStimulusBuffer = intensityBuffer;
|
||||
attachedStimulusBuffers.push_back(intensityBuffer);
|
||||
return intensityBuffer;
|
||||
}
|
||||
else if (qualeIfaceApi == "pcloudAmbience")
|
||||
{
|
||||
auto ambienceBuffer = std::make_shared<PcloudAmbienceStimulusBuffer>(
|
||||
*this, deviceAttachmentSpec, histbuffMs, openClInputConstraints);
|
||||
|
||||
ambienceStimulusBuffer = ambienceBuffer;
|
||||
attachedStimulusBuffers.push_back(ambienceBuffer);
|
||||
return ambienceBuffer;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw std::runtime_error(
|
||||
"Unsupported qualeIfaceApi: '" + qualeIfaceApi + "' for "
|
||||
"PcloudStimulusProducer. "
|
||||
"Supported values: mesh, pcloudIntensity, pcloudAmbience");
|
||||
}
|
||||
}
|
||||
|
||||
void PcloudStimulusProducer::stimFrameProductionTimesliceInd()
|
||||
|
||||
Reference in New Issue
Block a user