Skip to main content

bb_ops/syscalls/triggers/
on_trigger.rs

1//! `OnTrigger` syscall - passes the input trigger through.
2
3use bb_ir::proto::onnx::NodeProto;
4use bb_runtime::atomic::DispatchResult;
5use bb_runtime::bus::OpError;
6use bb_runtime::runtime::RuntimeResourceRef;
7use bb_runtime::slot_value::SlotValue;
8use bb_runtime::syscall::values::TriggerValue;
9
10/// Marker struct.
11pub struct OnTriggerOp;
12
13/// Op domain.
14pub const DOMAIN: &str = "ai.bytesandbrains.syscall";
15/// Op type name.
16pub const OP_TYPE: &str = "OnTrigger";
17
18/// Invoke fn - re-emits the input trigger.
19pub fn invoke(
20    _node: &NodeProto,
21    inputs: &[(&str, &dyn SlotValue)],
22    _ctx: &mut RuntimeResourceRef<'_>,
23) -> Result<DispatchResult, OpError> {
24    if inputs.is_empty() {
25        return Err(OpError {
26            detail: "OnTrigger requires one input".to_string(),
27            ..Default::default()
28        });
29    }
30    Ok(DispatchResult::Immediate(vec![(
31        "trigger".to_string(),
32        Box::new(TriggerValue),
33    )]))
34}
35
36use bb_runtime::registry::OpRegistration as _BbOpsSyscallReg;
37
38inventory::submit! {
39    _BbOpsSyscallReg {
40        domain: DOMAIN,
41        op_type: OP_TYPE,
42        invoke,
43        kind: bb_runtime::registry::RegistrationKind::Syscall,
44    }
45}