Skip to content

ISubscription Interface

A single, independent, filtered view onto the frames of one ICanBusService (arc42 §5.3 "Multi-Protokoll-Demux"; FR-RAW-010..012, FR-RAW-015).

public interface ISubscription : System.IDisposable

Implements IDisposable

Remarks

Each subscription owns its own bounded buffer, so a slow (or never-drained) consumer only drops its own oldest frames and can never delay delivery to other subscriptions or to the underlying bus's own FrameObserved event (FR-RAW-011).

Disposing the subscription deterministically deregisters it from the service (it stops receiving frames) and completes Frames, so any in-flight await foreach terminates gracefully. Dispose is idempotent (FR-RAW-012).

Frames is exposed without a cancellation-token parameter to match the arc42 interface shape; pass a token via subscription.Frames.WithCancellation(token) to stop enumerating early.

The stream carries CanFrameEvent, not a bare frame: the bus reports an echo flag and a receive timestamp alongside every frame, and a demux that dropped them forced every protocol layer above to guess at the first and do without the second. A subscription that did not ask for echoes never sees one at all, so the flag matters only to a caller that opted in.

Properties

ISubscription.Frames Property

Asynchronously yields the frames accepted by this subscription's filter, in arrival order, from its own buffer. Completes when the subscription (or its owning service) is disposed.

System.Collections.Generic.IAsyncEnumerable<CanKit.Pro.RawCan.CanFrameEvent> Frames { get; }

Property Value

IAsyncEnumerable<CanFrameEvent>

Methods

ISubscription.Reconfigure(CanIdFilter) Method

Replaces this subscription's filter with an ID-range/mask fast-path filter (FR-RAW-014). Any previously configured predicate is cleared. Frames already buffered are not retroactively filtered; only frames observed after this call follow the new criterion.

void Reconfigure(CanKit.Pro.RawCan.CanIdFilter filter);

Parameters

filter CanIdFilter

The new filter. Must not be a default-initialized struct when a meaningful filter is required — use Reconfigure(Func<CanFrameEvent,bool>) with null to accept all frames.

Remarks

The echo choice made at Subscribe time is not part of the filter and is not affected by reconfiguring one.

ISubscription.Reconfigure(Func<CanFrameEvent,bool>) Method

Replaces this subscription's filter with a generic predicate, or accepts all frames when predicate is null (FR-RAW-014). Any previously configured CanIdFilter is cleared. Frames already buffered are not retroactively filtered; only frames observed after this call follow the new criterion.

void Reconfigure(System.Func<CanKit.Pro.RawCan.CanFrameEvent,bool>? predicate);

Parameters

predicate Func<CanFrameEvent,Boolean>

Remarks

The predicate runs on the bus's dispatch thread, before the payload is copied into this subscription's buffer, so the Frame it inspects aliases the adapter's RX lease and must not be retained beyond the call. The echo choice made at Subscribe time is not part of the filter and is not affected by reconfiguring one: a predicate on a subscription that did not opt in is never even offered an echo.

ISubscription.TryRead(CanFrameEvent) Method

Non-blocking: try to remove one already-buffered frame from this subscription. Returns false if the buffer is currently empty.

bool TryRead(out CanKit.Pro.RawCan.CanFrameEvent frameEvent);

Parameters

frameEvent CanFrameEvent

The buffered frame, if any; otherwise the default value.

Returns

Boolean
true if a frame was removed; false if the buffer was empty.

Remarks

This is the synchronous counterpart to Frames: it never awaits and never waits for a frame to arrive, it only removes what has already been queued at the moment of the call. It is intended for consumers that need to snapshot-then-drop stale traffic (for example, a request/reply client draining background chatter before issuing its request) without racing an async enumerator against a wall-clock deadline.