use bb_ir::proto::onnx::NodeProto;
use bb_runtime::atomic::DispatchResult;
use bb_runtime::bus::OpError;
use bb_runtime::runtime::RuntimeResourceRef;
use bb_runtime::slot_value::SlotValue;
use bb_runtime::syscall::values::TriggerValue;
pub struct DeadlineCheckOp;
pub const DOMAIN: &str = "ai.bytesandbrains.syscall";
pub const OP_TYPE: &str = "DeadlineCheck";
pub const ATTR_DEADLINE_NS: &str = "deadline_ns";
pub fn invoke(
node: &NodeProto,
_inputs: &[(&str, &dyn SlotValue)],
ctx: &mut RuntimeResourceRef<'_>,
) -> Result<DispatchResult, OpError> {
let deadline_ns = node
.attribute
.iter()
.find(|a| a.name == ATTR_DEADLINE_NS)
.map(|a| a.i as u64)
.ok_or_else(|| OpError {
detail: format!("DeadlineCheck missing required `{ATTR_DEADLINE_NS}` attribute"),
..Default::default()
})?;
let now_ns = ctx.time.scheduler.now_ns();
if now_ns >= deadline_ns {
return Err(OpError {
detail: "deadline exceeded".to_string(),
..Default::default()
});
}
Ok(DispatchResult::Immediate(vec![(
"trigger".to_string(),
Box::new(TriggerValue),
)]))
}
use bb_runtime::registry::OpRegistration as _BbOpsSyscallReg;
inventory::submit! {
_BbOpsSyscallReg {
domain: DOMAIN,
op_type: OP_TYPE,
invoke,
kind: bb_runtime::registry::RegistrationKind::Syscall,
}
}