StimulusProducer: add duplicate-quale guard and attach-identity buffer lookup.
Provide ensureNoDuplicateQualeIface and getAttachedStimulusBufferByAttachIdentity so session-scoped stimBuff plugins can reject duplicate quales and detach by stable DAP line identity rather than full spec equality. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -82,6 +82,32 @@ std::shared_ptr<StimulusBuffer> StimulusProducer::getAttachedStimulusBuffer(
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::shared_ptr<StimulusBuffer> StimulusProducer::getAttachedStimulusBufferByAttachIdentity(
|
||||
const std::string& deviceIdentifier,
|
||||
const std::string& qualeIfaceApi) const
|
||||
{
|
||||
for (const auto& buffer : attachedStimulusBuffers)
|
||||
{
|
||||
if (!buffer || !buffer->deviceAttachmentSpec)
|
||||
{
|
||||
throw std::runtime_error(
|
||||
"StimulusProducer::getAttachedStimulusBufferByAttachIdentity: "
|
||||
"encountered null buffer or null deviceAttachmentSpec in "
|
||||
"attachedStimulusBuffers (should never happen)");
|
||||
}
|
||||
|
||||
if (buffer->deviceAttachmentSpec->deviceIdentifier != deviceIdentifier)
|
||||
{ continue; }
|
||||
|
||||
if (buffer->deviceAttachmentSpec->qualeIfaceApi != qualeIfaceApi)
|
||||
{ continue; }
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool StimulusProducer::hasBufferWithQualeIfaceApi(
|
||||
const std::string& qualeIfaceApi) const
|
||||
{
|
||||
@@ -104,6 +130,18 @@ bool StimulusProducer::hasBufferWithQualeIfaceApi(
|
||||
return false;
|
||||
}
|
||||
|
||||
void StimulusProducer::ensureNoDuplicateQualeIface(
|
||||
const std::string& qualeIfaceApi) const
|
||||
{
|
||||
if (!hasBufferWithQualeIfaceApi(qualeIfaceApi)) {
|
||||
return;
|
||||
}
|
||||
|
||||
throw std::runtime_error(
|
||||
"duplicate qualeIface '" + qualeIfaceApi
|
||||
+ "' for this producer session");
|
||||
}
|
||||
|
||||
bool StimulusProducer::addAttachedStimulusBufferIfNotExists(
|
||||
const std::shared_ptr<StimulusBuffer>& buffer)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user