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<'_>
impl KernelCtx<'_>
pub fn num_inputs(&self) -> usize
pub fn num_outputs(&self) -> usize
Sourcepub fn input(&self, idx: usize) -> Option<&Packet>
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.
pub fn input_count(&self, idx: usize) -> usize
pub fn input_at(&self, idx: usize, k: usize) -> Option<&Packet>
Sourcepub fn take_input(&mut self, idx: usize) -> Packet
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.
Sourcepub fn input_timestamp(&self) -> Timestamp
pub fn input_timestamp(&self) -> Timestamp
The (aligned) timestamp of this activation.
Sourcepub fn input_is_done(&self, idx: usize) -> bool
pub fn input_is_done(&self, idx: usize) -> bool
Whether this input port is finished — upstream closed and drained.
Sourcepub fn emit(&mut self, out_idx: usize, pkt: Packet) -> Result<()>
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.
Sourcepub fn forward(&mut self, in_idx: usize, out_idx: usize) -> Result<()>
pub fn forward(&mut self, in_idx: usize, out_idx: usize) -> Result<()>
Zero-copy passthrough: forward input in_idx to output out_idx.
Sourcepub fn set_next_bound(&mut self, out_idx: usize, bound: Timestamp)
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.
Sourcepub fn source_done(&mut self)
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.
Sourcepub fn source_yield(&mut self, delay: Duration)
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.
Sourcepub fn set_error(&mut self, msg: &str)
pub fn set_error(&mut self, msg: &str)
Record a failure reason (usually paired with return Err(cc.fail(...))).
Sourcepub fn fail(&self, msg: &str) -> Error
pub fn fail(&self, msg: &str) -> Error
Build a kernel error carrying a reason, for return Err(cc.fail("...")).
Sourcepub fn log(&self, level: i32, msg: &str)
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.
Sourcepub fn log_enabled(&self) -> bool
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));
}Sourcepub fn counter_add(&self, name: &str, delta: i64)
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.
Sourcepub fn has_option(&self, key: &str) -> bool
pub fn has_option(&self, key: &str) -> bool
Whether the node declared this option. Paths may be dotted, e.g. "roi.x".
pub fn option_i64(&self, key: &str, def: i64) -> i64
pub fn option_f64(&self, key: &str, def: f64) -> f64
pub fn option_bool(&self, key: &str, def: bool) -> bool
pub fn option_str<'s>(&'s self, key: &str, def: &'s str) -> &'s str
Sourcepub fn has_side_packet(&self, name: &str) -> bool
pub fn has_side_packet(&self, name: &str) -> bool
Whether a host-injected constant input exists.
Sourcepub fn side_packet(&self, name: &str) -> Option<&Packet>
pub fn side_packet(&self, name: &str) -> Option<&Packet>
Borrow a host-injected constant input.