Skip to content

Detection Worker Adapter

app.infrastructure.adapters.detection_worker_adapter

View source code

Explicit adapter wrapping DetectionWorker to DetectionWorkerInterface.

See Also

Layer: Infrastructure. Context: Implements concrete processing and I/O behind application-facing contracts.

DetectionWorkerAdapter

Bases: DetectionWorkerInterface

Explicit adapter that wraps a concrete DetectionWorker instance and exposes the DetectionWorkerInterface contract.

In normal usage the concrete DetectionWorker already satisfies DetectionWorkerInterface via structural subtyping (Protocol), so this adapter is not required for runtime correctness. It exists to:

  • Provide an explicit, named boundary at the infrastructure/application seam.
  • Enable test doubles that replace the real worker without subclassing DetectionWorker.
Note

Qt signals (batch_ready, progress_updated, finished_processing, error_occurred) are not part of the interface contract and remain on the concrete worker. Callers that need to connect signals must hold a reference to the concrete DetectionWorker directly.

PARAMETER DESCRIPTION
worker

Concrete detection worker wrapped by this adapter.

TYPE: DetectionWorker

batch_ready property

Expose the Qt signal so existing connect call-sites work unchanged.

progress_updated property

Expose the Qt signal so existing connect call-sites work unchanged.

__init__(worker: DetectionWorker) -> None

get_all_detections() -> dict[int, list[DetectionResult]]

Return all cached detections grouped by frame index.

RETURNS DESCRIPTION
dict[int, list[DetectionResult]]

New mapping copied from the wrapped worker's cache.

get_detections(frame_index: int) -> list[DetectionResult] | None

Return cached detections for one frame.

PARAMETER DESCRIPTION
frame_index

Zero-based index of the frame whose detections are requested.

TYPE: int

RETURNS DESCRIPTION
list[DetectionResult] | None

Detections for the frame, or None when the worker has no stored result.

isRunning() -> bool

Return whether the worker thread is running.

RETURNS DESCRIPTION
bool

True while the wrapped detection worker is active.

is_complete() -> bool

Return whether the worker has processed all frames.

RETURNS DESCRIPTION
bool

True when detection is complete.

start() -> None

Start the wrapped detection worker.

stop() -> None

Stop the wrapped detection worker.