Commit fd5b7b29 authored by jD91mZM2's avatar jD91mZM2

Make it edge-triggered

parent 202ead3b
......@@ -14,7 +14,7 @@ use syscall::{physmap, physunmap, Packet, SchemeMut, EVENT_READ, MAP_WRITE, MAP_
use mode_info::VBEModeInfo;
use primitive::fast_set64;
use scheme::DisplayScheme;
use scheme::{DisplayScheme, HandleKind};
pub mod display;
pub mod mode_info;
......@@ -91,24 +91,37 @@ fn main() {
}
}
for (handle_id, handle) in scheme.handles.iter() {
if handle.events & EVENT_READ != 0 {
if let Some(count) = scheme.can_read(*handle_id) {
if count > 0 {
let event_packet = Packet {
id: 0,
pid: 0,
uid: 0,
gid: 0,
a: syscall::number::SYS_FEVENT,
b: *handle_id,
c: EVENT_READ,
d: count
};
socket.write(&event_packet).expect("vesad: failed to write display event");
}
for (handle_id, handle) in scheme.handles.iter_mut() {
if handle.events & EVENT_READ == 0 {
continue;
}
// Can't use scheme.can_read() because we borrow handles as mutable.
// (and because it'd treat O_NONBLOCK sockets differently)
let count = if let HandleKind::Screen(screen_i) = handle.kind {
scheme.screens.get(&screen_i)
.and_then(|screen| screen.can_read())
.unwrap_or(0)
} else { 0 };
if count > 0 {
if !handle.notified_read {
handle.notified_read = true;
let event_packet = Packet {
id: 0,
pid: 0,
uid: 0,
gid: 0,
a: syscall::number::SYS_FEVENT,
b: *handle_id,
c: EVENT_READ,
d: count
};
socket.write(&event_packet).expect("vesad: failed to write display event");
}
} else {
handle.notified_read = false;
}
}
}
......
......@@ -18,6 +18,7 @@ pub struct Handle {
pub kind: HandleKind,
pub flags: usize,
pub events: usize,
pub notified_read: bool
}
pub struct DisplayScheme {
......@@ -57,14 +58,11 @@ impl DisplayScheme {
if let Some(handle) = self.handles.get(&id) {
if let HandleKind::Screen(screen_i) = handle.kind {
if let Some(screen) = self.screens.get(&screen_i) {
match screen.can_read() {
Some(count) => return Some(count),
None => if handle.flags & O_NONBLOCK == O_NONBLOCK {
return Some(0);
} else {
return None;
}
}
screen.can_read().or(if handle.flags & O_NONBLOCK == O_NONBLOCK {
Some(0)
} else {
None
});
}
}
}
......@@ -84,6 +82,7 @@ impl SchemeMut for DisplayScheme {
kind: HandleKind::Input,
flags: flags,
events: 0,
notified_read: false
});
Ok(id)
......@@ -108,6 +107,7 @@ impl SchemeMut for DisplayScheme {
kind: HandleKind::Screen(screen_i),
flags: flags,
events: 0,
notified_read: false
});
Ok(id)
......@@ -135,6 +135,8 @@ impl SchemeMut for DisplayScheme {
fn fevent(&mut self, id: usize, flags: usize) -> Result<usize> {
let handle = self.handles.get_mut(&id).ok_or(Error::new(EBADF))?;
handle.notified_read = false;
if let HandleKind::Screen(_screen_i) = handle.kind {
handle.events = flags;
Ok(id)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment