pub struct TelemetryCollector<T: Transcendental, const BUF_SIZE: usize, const QUEUE_CAP: usize> { /* private fields */ }Expand description
Non-real-time consumer of telemetry frames from a shared SpscQueue.
Runs on the control thread (or any non-RT context). Drains available frames from the ring buffer and delivers them to a user-supplied callback.
§Example
use std::sync::Arc;
use rill_core::queues::spsc::SpscQueue;
use rill_core::queues::TelemetryBlock;
use rill_telemetry::collector::TelemetryCollector;
let queue = Arc::new(SpscQueue::<TelemetryBlock<f32, 64>, 8>::new());
let mut collector = TelemetryCollector::new(queue, |frame| {
println!("peak={} rms={} dc={}", frame.peak, frame.rms, frame.dc_offset);
});
collector.poll(); // drain available framesImplementations§
Source§impl<T: Transcendental, const BUF_SIZE: usize, const QUEUE_CAP: usize> TelemetryCollector<T, BUF_SIZE, QUEUE_CAP>
impl<T: Transcendental, const BUF_SIZE: usize, const QUEUE_CAP: usize> TelemetryCollector<T, BUF_SIZE, QUEUE_CAP>
Sourcepub fn new(
queue: Arc<SpscQueue<TelemetryBlock<T, BUF_SIZE>, QUEUE_CAP>>,
callback: impl FnMut(TelemetryBlock<T, BUF_SIZE>) + 'static,
) -> Self
pub fn new( queue: Arc<SpscQueue<TelemetryBlock<T, BUF_SIZE>, QUEUE_CAP>>, callback: impl FnMut(TelemetryBlock<T, BUF_SIZE>) + 'static, ) -> Self
Create a new collector backed by the shared ring buffer.
The callback is invoked for every frame drained from the queue.
Sourcepub fn poll(&mut self) -> usize
pub fn poll(&mut self) -> usize
Drain all available telemetry frames from the ring buffer.
Returns the number of frames processed.
Sourcepub fn poll_n(&mut self, max: usize) -> usize
pub fn poll_n(&mut self, max: usize) -> usize
Drain at most max frames from the ring buffer.
Useful when you want to bound processing time per tick.
Sourcepub fn available(&self) -> usize
pub fn available(&self) -> usize
Number of frames currently available in the ring buffer (approximate).
Sourcepub fn into_queue(
self,
) -> Arc<SpscQueue<TelemetryBlock<T, BUF_SIZE>, QUEUE_CAP>>
pub fn into_queue( self, ) -> Arc<SpscQueue<TelemetryBlock<T, BUF_SIZE>, QUEUE_CAP>>
Consume the collector and return the underlying queue Arc.
Auto Trait Implementations§
impl<T, const BUF_SIZE: usize, const QUEUE_CAP: usize> !RefUnwindSafe for TelemetryCollector<T, BUF_SIZE, QUEUE_CAP>
impl<T, const BUF_SIZE: usize, const QUEUE_CAP: usize> !Send for TelemetryCollector<T, BUF_SIZE, QUEUE_CAP>
impl<T, const BUF_SIZE: usize, const QUEUE_CAP: usize> !Sync for TelemetryCollector<T, BUF_SIZE, QUEUE_CAP>
impl<T, const BUF_SIZE: usize, const QUEUE_CAP: usize> !UnwindSafe for TelemetryCollector<T, BUF_SIZE, QUEUE_CAP>
impl<T, const BUF_SIZE: usize, const QUEUE_CAP: usize> Freeze for TelemetryCollector<T, BUF_SIZE, QUEUE_CAP>
impl<T, const BUF_SIZE: usize, const QUEUE_CAP: usize> Unpin for TelemetryCollector<T, BUF_SIZE, QUEUE_CAP>
impl<T, const BUF_SIZE: usize, const QUEUE_CAP: usize> UnsafeUnpin for TelemetryCollector<T, BUF_SIZE, QUEUE_CAP>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more