[Pcloud]StimProducer: Impl addAttachedStimBuffIfNotExists
Reduces code duplication, centralizes checking and enforces consistent behaviour across producers. Also reordered the writes to the sh_ptr<StimulusBuffer>s such that the pointers are written last.
This commit is contained in:
@@ -52,6 +52,28 @@ bool StimulusProducer::hasBufferWithQualeIfaceApi(
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool StimulusProducer::addAttachedStimulusBufferIfNotExists(
|
||||||
|
const std::shared_ptr<StimulusBuffer>& buffer)
|
||||||
|
{
|
||||||
|
if (!buffer) { return false; }
|
||||||
|
|
||||||
|
auto it = std::find_if(
|
||||||
|
attachedStimulusBuffers.begin(),
|
||||||
|
attachedStimulusBuffers.end(),
|
||||||
|
[&](const std::shared_ptr<StimulusBuffer>& buf) {
|
||||||
|
return buf && buffer &&
|
||||||
|
buf->deviceAttachmentSpec && buffer->deviceAttachmentSpec &&
|
||||||
|
*(buf->deviceAttachmentSpec) == *(buffer->deviceAttachmentSpec);
|
||||||
|
});
|
||||||
|
|
||||||
|
if (it != attachedStimulusBuffers.end()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
attachedStimulusBuffers.push_back(buffer);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
void StimulusProducer::destroyAttachedStimulusBuffer(
|
void StimulusProducer::destroyAttachedStimulusBuffer(
|
||||||
const std::shared_ptr<StimulusBuffer>& buffer)
|
const std::shared_ptr<StimulusBuffer>& buffer)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -76,6 +76,9 @@ public:
|
|||||||
const std::shared_ptr<device::DeviceAttachmentSpec>
|
const std::shared_ptr<device::DeviceAttachmentSpec>
|
||||||
&deviceAttachmentSpec) = 0;
|
&deviceAttachmentSpec) = 0;
|
||||||
|
|
||||||
|
bool addAttachedStimulusBufferIfNotExists(
|
||||||
|
const std::shared_ptr<StimulusBuffer>& buffer);
|
||||||
|
|
||||||
virtual void destroyAttachedStimulusBuffer(
|
virtual void destroyAttachedStimulusBuffer(
|
||||||
const std::shared_ptr<StimulusBuffer>& buffer);
|
const std::shared_ptr<StimulusBuffer>& buffer);
|
||||||
|
|
||||||
|
|||||||
@@ -265,8 +265,8 @@ std::cout << __func__ << ": $$$$$$$ Creating MeshStimulusBuffer" << std::endl;
|
|||||||
|
|
||||||
std::cout << __func__ << ": $$$$$$$ Created MeshStimulusBuffer" << std::endl;
|
std::cout << __func__ << ": $$$$$$$ Created MeshStimulusBuffer" << std::endl;
|
||||||
this->stop();
|
this->stop();
|
||||||
|
addAttachedStimulusBufferIfNotExists(meshBuffer);
|
||||||
meshStimulusBuffer = meshBuffer;
|
meshStimulusBuffer = meshBuffer;
|
||||||
attachedStimulusBuffers.push_back(meshBuffer);
|
|
||||||
this->start();
|
this->start();
|
||||||
return meshBuffer;
|
return meshBuffer;
|
||||||
}
|
}
|
||||||
@@ -288,8 +288,8 @@ std::cout << __func__ << ": $$$$$$$ Creating PcloudIntensityStimulusBuffer" << s
|
|||||||
|
|
||||||
std::cout << __func__ << ": $$$$$$$ Created PcloudIntensityStimulusBuffer" << std::endl;
|
std::cout << __func__ << ": $$$$$$$ Created PcloudIntensityStimulusBuffer" << std::endl;
|
||||||
this->stop();
|
this->stop();
|
||||||
|
addAttachedStimulusBufferIfNotExists(intensityBuffer);
|
||||||
intensityStimulusBuffer = intensityBuffer;
|
intensityStimulusBuffer = intensityBuffer;
|
||||||
attachedStimulusBuffers.push_back(intensityBuffer);
|
|
||||||
this->start();
|
this->start();
|
||||||
return intensityBuffer;
|
return intensityBuffer;
|
||||||
}
|
}
|
||||||
@@ -321,8 +321,8 @@ std::cout << __func__ << ": $$$$$$$ Created PcloudIntensityStimulusBuffer" << st
|
|||||||
|
|
||||||
std::cout << __func__ << ": $$$$$$$ Created PcloudAmbienceStimulusBuffer" << std::endl;
|
std::cout << __func__ << ": $$$$$$$ Created PcloudAmbienceStimulusBuffer" << std::endl;
|
||||||
this->stop();
|
this->stop();
|
||||||
|
addAttachedStimulusBufferIfNotExists(ambienceBuffer);
|
||||||
ambienceStimulusBuffer = ambienceBuffer;
|
ambienceStimulusBuffer = ambienceBuffer;
|
||||||
attachedStimulusBuffers.push_back(ambienceBuffer);
|
|
||||||
this->start();
|
this->start();
|
||||||
return ambienceBuffer;
|
return ambienceBuffer;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user