SwitchingDiscoveryDao

A switch-aware DiscoveryDao that resolves the active database on every call instead of pinning the one that was current at injection time. This is what Koin hands to feature:discovery consumers (ViewModels and the scan engine), which hold their DAO for their whole lifetime:

  • Flow methods re-latch through DatabaseProvider.observeCurrentDb, so an open discovery screen follows a device/DB switch and recovers from a wedged active Room pool.

  • Suspend methods go through DatabaseProvider.withDb, so writes register with the cross-transport merge drain barrier (a mid-scan merge can't snapshot-then-retire the DB underneath an in-flight session write). A callback is never replayed after it starts, so higher layers must make any retry policy explicit where idempotency is known.

withDb can return null while no database is available. Collection reads use empty defaults, count reads return zero, and operations that require a created row retain non-null checks so callers cannot proceed with an invalid id.

Constructors

Link copied to clipboard
constructor(dbManager: DatabaseProvider)

Functions

Link copied to clipboard
open suspend override fun deleteSession(sessionId: Long)
Link copied to clipboard
open override fun getAllSessions(): Flow<List<DiscoverySessionEntity>>
Link copied to clipboard
open suspend override fun getAllSessionsSnapshot(): List<DiscoverySessionEntity>

Snapshot used by DatabaseMerger to append a transport's discovery sessions to the unified DB.

Link copied to clipboard
open suspend override fun getDiscoveredNodes(presetResultId: Long): List<DiscoveredNodeEntity>
Link copied to clipboard
open override fun getDiscoveredNodesFlow(presetResultId: Long): Flow<List<DiscoveredNodeEntity>>
Link copied to clipboard
open suspend override fun getInterruptedSession(deviceAddress: String): DiscoverySessionEntity?

The most recent recoverable session for deviceAddress. This includes active/interrupted scans and terminal scans whose home-radio restoration is still pending, so callers must inspect completionStatus rather than assuming an unfinished scan.

Link copied to clipboard
open suspend override fun getMaxDistance(sessionId: Long): Double?
Link copied to clipboard
open suspend override fun getPresetResults(sessionId: Long): List<DiscoveryPresetResultEntity>
Link copied to clipboard
open override fun getPresetResultsFlow(sessionId: Long): Flow<List<DiscoveryPresetResultEntity>>
Link copied to clipboard
open suspend override fun getSession(sessionId: Long): DiscoverySessionEntity?
Link copied to clipboard
open override fun getSessionFlow(sessionId: Long): Flow<DiscoverySessionEntity?>
Link copied to clipboard
open suspend override fun getSessionWithResults(sessionId: Long): DiscoverySessionEntity?
Link copied to clipboard
open suspend override fun getUniqueNodeCount(sessionId: Long): Int
Link copied to clipboard
open suspend override fun getUniqueNodeNums(sessionId: Long): List<Long>
Link copied to clipboard
open suspend override fun insertDiscoveredNode(node: DiscoveredNodeEntity): Long
Link copied to clipboard
open suspend override fun insertDiscoveredNodes(nodes: List<DiscoveredNodeEntity>)
Link copied to clipboard
open suspend override fun insertPresetResult(result: DiscoveryPresetResultEntity): Long
Link copied to clipboard
open suspend override fun insertSession(session: DiscoverySessionEntity): Long
Link copied to clipboard
open suspend override fun markInterruptedSessions()
Link copied to clipboard
open suspend override fun updateDiscoveredNode(node: DiscoveredNodeEntity)
Link copied to clipboard
open suspend override fun updatePresetResult(result: DiscoveryPresetResultEntity)
Link copied to clipboard
open suspend override fun updateRecoverableSessionCompletionStatus(sessionId: Long, status: String): Int
Link copied to clipboard
open suspend override fun updateSession(session: DiscoverySessionEntity)
Link copied to clipboard
open suspend override fun updateSessionAggregates(sessionId: Long, totalUniqueNodes: Int, totalDwellSeconds: Long, totalMessages: Int, totalSensorPackets: Int, furthestNodeDistance: Double, avgChannelUtilization: Double)
Link copied to clipboard
open suspend override fun updateSessionCompletionStatus(sessionId: Long, status: String): Int