[idd] transport: centralize source identity

This commit is contained in:
Geoffrey McRae
2026-08-13 21:42:24 +10:00
parent 84bda112ac
commit cd6bcc3a41
4 changed files with 24 additions and 23 deletions

View File

@@ -22,15 +22,11 @@
#include "input/IInputSink.h"
static bool SameSource(const SourceKey& left, const SourceKey& right)
{
return left.backend == right.backend && left.epoch == right.epoch &&
left.client == right.client && left.generation == right.generation;
}
static bool SameClient(const SourceKey& left, const SourceKey& right)
{
return left.backend == right.backend && left.epoch == right.epoch &&
return
left.backend == right.backend &&
left.epoch == right.epoch &&
left.client == right.client;
}
@@ -307,7 +303,7 @@ void CInputHub::CommitInteraction(
const SourceKey& source, const InteractionPermit& permit)
{
if (!source.backend || !source.epoch || !source.client || !permit.serial ||
!SameSource(source, permit.source))
source != permit.source)
return;
CSRWExclusiveLock lock(m_lock);
@@ -497,7 +493,7 @@ bool CInputHub::BindingPresent(const SourceKey& source) const
bool CInputHub::OwnerValid(const SourceKey& source) const
{
return SourceValid(source) && SameSource(m_owner, source);
return SourceValid(source) && m_owner == source;
}
void CInputHub::ClearInteraction()
@@ -558,8 +554,7 @@ InputTargetState CInputHub::GetState(const SourceKey& source)
return result;
if (!m_owner.backend)
result.available = true;
else if (source.client && source.generation &&
SameSource(m_owner, source))
else if (source.client && source.generation && m_owner == source)
{
result.available = true;
result.owned = true;
@@ -600,7 +595,7 @@ InputResult CInputHub::Claim(const SourceKey& source)
if (!CheckState())
return InputResult::UNAVAILABLE;
if (m_owner.backend)
return SameSource(m_owner, source) ?
return m_owner == source ?
InputResult::ACCEPTED : InputResult::BUSY;
if (!m_sink->Reset() || m_sink->GetState() != m_sinkState)
{

View File

@@ -45,13 +45,6 @@ CRecoveryHub::CRecoveryHub() :
{
}
bool CRecoveryHub::SameSource(
const SourceKey& left, const SourceKey& right)
{
return left.backend == right.backend && left.epoch == right.epoch &&
left.client == right.client && left.generation == right.generation;
}
bool CRecoveryHub::SameEpoch(
const SourceKey& source, BackendId backend, uint32_t epoch)
{
@@ -61,7 +54,7 @@ bool CRecoveryHub::SameEpoch(
bool CRecoveryHub::SameRequest(const Request& request,
const SourceKey& source, uint64_t session, uint32_t serial, bool active)
{
return SameSource(request.source, source) && request.session == session &&
return request.source == source && request.session == session &&
request.serial == serial && request.active == active;
}
@@ -83,7 +76,7 @@ unsigned CRecoveryHub::FindSourceLocked(const SourceKey& source) const
{
for (unsigned i = 0; i < MAX_REQUESTS; ++i)
if (m_requests[i].state != SlotState::FREE &&
SameSource(m_requests[i].source, source))
m_requests[i].source == source)
return i;
return MAX_REQUESTS;
}

View File

@@ -96,7 +96,6 @@ private:
bool m_knownValid = false;
bool m_monitorReady = false;
static bool SameSource(const SourceKey& left, const SourceKey& right);
static bool SameEpoch(
const SourceKey& source, BackendId backend, uint32_t epoch);
static bool SameRequest(const Request& request, const SourceKey& source,

View File

@@ -40,6 +40,20 @@ struct SourceKey
uint32_t generation = 0;
};
inline bool operator==(const SourceKey& left, const SourceKey& right)
{
return
left.backend == right.backend &&
left.epoch == right.epoch &&
left.client == right.client &&
left.generation == right.generation;
}
inline bool operator!=(const SourceKey& left, const SourceKey& right)
{
return !(left == right);
}
enum class InteractionResult
{
ACCEPTED,