Skip to main content

KernelCtx

Struct KernelCtx 

Source
pub struct KernelCtx<'a> { /* private fields */ }
Expand description

The context of one kernel callback — a safe wrapper around the internal Context.

Valid only for the duration of the callback; it must not be stored. While a kernel runs the engine holds no internal lock, so a kernel is free to block, lock, or acquire the GIL here.

Implementations§

Source§

impl KernelCtx<'_>

Source

pub fn num_inputs(&self) -> usize

Source

pub fn num_outputs(&self) -> usize

Source

pub fn input(&self, idx: usize) -> Option<&Packet>

Borrow input packet idx (single-packet policies). Under the batch policy use input_count / input_at to walk the batch.

Source

pub fn input_count(&self, idx: usize) -> usize

Source

pub fn input_at(&self, idx: usize, k: usize) -> Option<&Packet>

Source

pub fn take_input(&mut self, idx: usize) -> Packet

Take ownership of an input packet — the first step to a copy-free mutation, since copy-on-write only avoids the copy when this is the sole reference.

Source

pub fn input_timestamp(&self) -> Timestamp

The (aligned) timestamp of this activation.

Source

pub fn input_is_done(&self, idx: usize) -> bool

Whether this input port is finished — upstream closed and drained.

Source

pub fn emit(&mut self, out_idx: usize, pkt: Packet) -> Result<()>

Produce a packet on output port out_idx. An unset timestamp inherits this activation’s timestamp. The resulting timestamp must be legal stream data; in close, supply an explicit timestamp because the activation timestamp is Done.

Source

pub fn forward(&mut self, in_idx: usize, out_idx: usize) -> Result<()>

Zero-copy passthrough: forward input in_idx to output out_idx.

Source

pub fn set_next_bound(&mut self, out_idx: usize, bound: Timestamp)

Advance the downstream timestamp bound when producing nothing — otherwise consumers keep waiting for a packet that will never arrive.

Source

pub fn source_done(&mut self)

For a source kernel (no inputs): report that it has produced everything, so the engine closes the stream and terminates.

Source

pub fn source_yield(&mut self, delay: Duration)

For a source kernel (no inputs): cooperatively release the worker and ask the engine to invoke the source again after delay.

Source

pub fn set_error(&mut self, msg: &str)

Record a failure reason (usually paired with return Err(cc.fail(...))).

Source

pub fn fail(&self, msg: &str) -> Error

Build a kernel error carrying a reason, for return Err(cc.fail("...")).

Source

pub fn log(&self, level: i32, msg: &str)

Write an engine log line (levels are the LOG_* constants in crate::runtime). This goes through the engine’s log callback rather than stealing the host’s stdout.

Source

pub fn log_enabled(&self) -> bool

Whether a log sink is installed. Ask before formatting — format! allocates, and kernel logging is often per-packet, so it should cost nothing when nobody is listening:

ⓘ
if cc.log_enabled() {
    cc.log(LOG_DEBUG, &format!("frame {}", n));
}
Source

pub fn counter_add(&self, name: &str, delta: i64)

Add to a named per-graph counter. Easier to assert on than a log line — read it back afterwards with crate::Graph::counter_value.

Source

pub fn has_option(&self, key: &str) -> bool

Whether the node declared this option. Paths may be dotted, e.g. "roi.x".

Source

pub fn option_i64(&self, key: &str, def: i64) -> i64

Source

pub fn option_f64(&self, key: &str, def: f64) -> f64

Source

pub fn option_bool(&self, key: &str, def: bool) -> bool

Source

pub fn option_str<'s>(&'s self, key: &str, def: &'s str) -> &'s str

Source

pub fn has_side_packet(&self, name: &str) -> bool

Whether a host-injected constant input exists.

Source

pub fn side_packet(&self, name: &str) -> Option<&Packet>

Borrow a host-injected constant input.

Auto Trait Implementations§

§

impl<'a> !RefUnwindSafe for KernelCtx<'a>

§

impl<'a> !UnwindSafe for KernelCtx<'a>

§

impl<'a> Freeze for KernelCtx<'a>

§

impl<'a> Send for KernelCtx<'a>

§

impl<'a> Sync for KernelCtx<'a>

§

impl<'a> Unpin for KernelCtx<'a>

§

impl<'a> UnsafeUnpin for KernelCtx<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.