use crate::{ok, sys, AsHandleRef, Handle, HandleBased, HandleRef, Port, Status};
#[derive(Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
#[repr(transparent)]
pub struct Interrupt(Handle);
impl_handle_based!(Interrupt);
impl Interrupt {
pub fn bind_port(&self, port: &Port, key: u64) -> Result<(), Status> {
let options = sys::ZX_INTERRUPT_BIND;
let status =
unsafe { sys::zx_interrupt_bind(self.raw_handle(), port.raw_handle(), key, options) };
ok(status)
}
pub fn ack(&self) -> Result<(), Status> {
let status = unsafe { sys::zx_interrupt_ack(self.raw_handle()) };
ok(status)
}
}
#[cfg(test)]
mod tests {
use crate::{Handle, Interrupt, Port, PortOptions, Status};
#[test]
fn bind() {
let interrupt: Interrupt = Handle::invalid().into();
let port = Port::create_with_opts(PortOptions::BIND_TO_INTERRUPT);
let key = 1;
let result = interrupt.bind_port(&port, key);
assert_eq!(result.err(), Some(Status::BAD_HANDLE));
}
#[test]
fn ack() {
let interrupt: Interrupt = Handle::invalid().into();
let result = interrupt.ack();
assert_eq!(result.err(), Some(Status::BAD_HANDLE));
}
}