machina_virtio_device/
notify.rs1use fidl_fuchsia_virtualization_hardware::{
6 EVENT_SET_CONFIG, EVENT_SET_INTERRUPT, EVENT_SET_QUEUE,
7};
8use virtio_device::queue::DriverNotify;
9use zx::{self as zx, AsHandleRef};
10
11const USER_SIGNALS: [zx::Signals; 8] = [
12 zx::Signals::USER_0,
13 zx::Signals::USER_1,
14 zx::Signals::USER_2,
15 zx::Signals::USER_3,
16 zx::Signals::USER_4,
17 zx::Signals::USER_5,
18 zx::Signals::USER_6,
19 zx::Signals::USER_7,
20];
21
22#[derive(Clone)]
30pub struct NotifyEvent(std::sync::Arc<zx::Event>);
31
32impl NotifyEvent {
33 pub fn new(event: zx::Event) -> NotifyEvent {
35 NotifyEvent(std::sync::Arc::new(event))
36 }
37}
38
39impl NotifyEvent {
40 fn signal(&self, event: usize) -> Result<(), zx::Status> {
41 self.0.as_handle_ref().signal(
42 zx::Signals::empty(),
43 USER_SIGNALS[event] | USER_SIGNALS[EVENT_SET_INTERRUPT as usize],
44 )
45 }
46
47 pub fn signal_queue(&self) -> Result<(), zx::Status> {
48 self.signal(EVENT_SET_QUEUE as usize)
49 }
50
51 pub fn signal_config(&self) -> Result<(), zx::Status> {
52 self.signal(EVENT_SET_CONFIG as usize)
53 }
54}
55
56impl DriverNotify for NotifyEvent {
57 fn notify(&self) {
58 self.signal_queue().unwrap();
62 }
63}