[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;
|
||||
}
|
||||
|
||||
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(
|
||||
const std::shared_ptr<StimulusBuffer>& buffer)
|
||||
{
|
||||
|
||||
@@ -76,6 +76,9 @@ public:
|
||||
const std::shared_ptr<device::DeviceAttachmentSpec>
|
||||
&deviceAttachmentSpec) = 0;
|
||||
|
||||
bool addAttachedStimulusBufferIfNotExists(
|
||||
const std::shared_ptr<StimulusBuffer>& buffer);
|
||||
|
||||
virtual void destroyAttachedStimulusBuffer(
|
||||
const std::shared_ptr<StimulusBuffer>& buffer);
|
||||
|
||||
|
||||
@@ -265,8 +265,8 @@ std::cout << __func__ << ": $$$$$$$ Creating MeshStimulusBuffer" << std::endl;
|
||||
|
||||
std::cout << __func__ << ": $$$$$$$ Created MeshStimulusBuffer" << std::endl;
|
||||
this->stop();
|
||||
addAttachedStimulusBufferIfNotExists(meshBuffer);
|
||||
meshStimulusBuffer = meshBuffer;
|
||||
attachedStimulusBuffers.push_back(meshBuffer);
|
||||
this->start();
|
||||
return meshBuffer;
|
||||
}
|
||||
@@ -288,8 +288,8 @@ std::cout << __func__ << ": $$$$$$$ Creating PcloudIntensityStimulusBuffer" << s
|
||||
|
||||
std::cout << __func__ << ": $$$$$$$ Created PcloudIntensityStimulusBuffer" << std::endl;
|
||||
this->stop();
|
||||
addAttachedStimulusBufferIfNotExists(intensityBuffer);
|
||||
intensityStimulusBuffer = intensityBuffer;
|
||||
attachedStimulusBuffers.push_back(intensityBuffer);
|
||||
this->start();
|
||||
return intensityBuffer;
|
||||
}
|
||||
@@ -321,8 +321,8 @@ std::cout << __func__ << ": $$$$$$$ Created PcloudIntensityStimulusBuffer" << st
|
||||
|
||||
std::cout << __func__ << ": $$$$$$$ Created PcloudAmbienceStimulusBuffer" << std::endl;
|
||||
this->stop();
|
||||
addAttachedStimulusBufferIfNotExists(ambienceBuffer);
|
||||
ambienceStimulusBuffer = ambienceBuffer;
|
||||
attachedStimulusBuffers.push_back(ambienceBuffer);
|
||||
this->start();
|
||||
return ambienceBuffer;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user