Skip to main content

bb_ops/syscalls/triggers/
event_source.rs

1//! `EventSource` syscall - emits Trigger on bus events.
2//!
3//! Subscription wiring: the Node install path parses each
4//! `EventSource` NodeProto's `kind` attribute and calls
5//! `Engine::register_event_subscription` so the engine's bus drain
6//! pushes the op onto the frontier when a matching event arrives.
7//! The op body fires the trigger output; repeated firings come from
8//! repeated event arrivals.
9
10use bb_ir::proto::onnx::NodeProto;
11use bb_runtime::atomic::DispatchResult;
12use bb_runtime::bus::OpError;
13use bb_runtime::runtime::RuntimeResourceRef;
14use bb_runtime::slot_value::SlotValue;
15use bb_runtime::syscall::values::TriggerValue;
16
17/// Marker struct.
18pub struct EventSourceOp;
19
20/// Op domain.
21pub const DOMAIN: &str = "ai.bytesandbrains.syscall";
22/// Op type name.
23pub const OP_TYPE: &str = "EventSource";
24
25/// Invoke fn - emits Trigger output on every firing.
26pub fn invoke(
27    _node: &NodeProto,
28    _inputs: &[(&str, &dyn SlotValue)],
29    _ctx: &mut RuntimeResourceRef<'_>,
30) -> Result<DispatchResult, OpError> {
31    Ok(DispatchResult::Immediate(vec![(
32        "event".to_string(),
33        Box::new(TriggerValue),
34    )]))
35}
36
37use bb_runtime::registry::OpRegistration as _BbOpsSyscallReg;
38
39inventory::submit! {
40    _BbOpsSyscallReg {
41        domain: DOMAIN,
42        op_type: OP_TYPE,
43        invoke,
44        kind: bb_runtime::registry::RegistrationKind::Syscall,
45    }
46}