Merge branch 'simplify_fbbootlogd' into 'master'
Simplify fbbootlogd See merge request redox-os/drivers!238
This commit is contained in:
@@ -16,7 +16,6 @@ use crate::scheme::FbbootlogScheme;
|
||||
|
||||
mod display;
|
||||
mod scheme;
|
||||
mod text;
|
||||
|
||||
fn main() {
|
||||
redox_daemon::Daemon::new(|daemon| inner(daemon)).expect("failed to create daemon");
|
||||
|
||||
@@ -1,31 +1,20 @@
|
||||
use std::collections::BTreeMap;
|
||||
use std::collections::VecDeque;
|
||||
|
||||
use redox_scheme::Scheme;
|
||||
use syscall::{Error, EventFlags, Result, EBADF, EINVAL, ENOENT};
|
||||
use syscall::{Error, Result, EINVAL, ENOENT};
|
||||
|
||||
use crate::display::Display;
|
||||
use crate::text::TextScreen;
|
||||
|
||||
pub struct Handle {
|
||||
pub events: EventFlags,
|
||||
pub notified_read: bool,
|
||||
}
|
||||
|
||||
pub struct FbbootlogScheme {
|
||||
pub screen: TextScreen,
|
||||
next_id: usize,
|
||||
pub handles: BTreeMap<usize, Handle>,
|
||||
display: Display,
|
||||
text_screen: console_draw::TextScreen,
|
||||
}
|
||||
|
||||
impl FbbootlogScheme {
|
||||
pub fn new() -> FbbootlogScheme {
|
||||
let display = Display::open_first_vt().expect("Failed to open display for vt");
|
||||
let screen = TextScreen::new(display);
|
||||
|
||||
FbbootlogScheme {
|
||||
screen,
|
||||
next_id: 0,
|
||||
handles: BTreeMap::new(),
|
||||
display: Display::open_first_vt().expect("Failed to open display for vt"),
|
||||
text_screen: console_draw::TextScreen::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -36,32 +25,10 @@ impl Scheme for FbbootlogScheme {
|
||||
return Err(Error::new(ENOENT));
|
||||
}
|
||||
|
||||
let id = self.next_id;
|
||||
self.next_id += 1;
|
||||
|
||||
self.handles.insert(
|
||||
id,
|
||||
Handle {
|
||||
events: EventFlags::empty(),
|
||||
notified_read: false,
|
||||
},
|
||||
);
|
||||
|
||||
Ok(id)
|
||||
Ok(0)
|
||||
}
|
||||
|
||||
fn fevent(&mut self, id: usize, flags: syscall::EventFlags) -> Result<syscall::EventFlags> {
|
||||
let handle = self.handles.get_mut(&id).ok_or(Error::new(EBADF))?;
|
||||
|
||||
handle.notified_read = false;
|
||||
|
||||
handle.events = flags;
|
||||
Ok(syscall::EventFlags::empty())
|
||||
}
|
||||
|
||||
fn fpath(&mut self, id: usize, buf: &mut [u8]) -> Result<usize> {
|
||||
let _handle = self.handles.get(&id).ok_or(Error::new(EBADF))?;
|
||||
|
||||
fn fpath(&mut self, _id: usize, buf: &mut [u8]) -> Result<usize> {
|
||||
let path = b"fbbootlog:";
|
||||
|
||||
let mut i = 0;
|
||||
@@ -73,32 +40,39 @@ impl Scheme for FbbootlogScheme {
|
||||
Ok(i)
|
||||
}
|
||||
|
||||
fn fsync(&mut self, id: usize) -> Result<usize> {
|
||||
let _handle = self.handles.get(&id).ok_or(Error::new(EBADF))?;
|
||||
|
||||
return Ok(0);
|
||||
fn fsync(&mut self, _id: usize) -> Result<usize> {
|
||||
Ok(0)
|
||||
}
|
||||
|
||||
fn read(
|
||||
&mut self,
|
||||
id: usize,
|
||||
_id: usize,
|
||||
_buf: &mut [u8],
|
||||
_offset: u64,
|
||||
_fcntl_flags: u32,
|
||||
) -> Result<usize> {
|
||||
let _handle = self.handles.get(&id).ok_or(Error::new(EBADF))?;
|
||||
|
||||
Err(Error::new(EINVAL))
|
||||
}
|
||||
|
||||
fn write(&mut self, id: usize, buf: &[u8], _offset: u64, _fcntl_flags: u32) -> Result<usize> {
|
||||
let _handle = self.handles.get(&id).ok_or(Error::new(EBADF))?;
|
||||
fn write(&mut self, _id: usize, buf: &[u8], _offset: u64, _fcntl_flags: u32) -> Result<usize> {
|
||||
let mut map = self.display.map.lock().unwrap();
|
||||
let damage = self.text_screen.write(
|
||||
&mut console_draw::DisplayMap {
|
||||
offscreen: map.inner.ptr_mut(),
|
||||
width: map.inner.width(),
|
||||
height: map.inner.height(),
|
||||
},
|
||||
buf,
|
||||
&mut VecDeque::new(),
|
||||
);
|
||||
drop(map);
|
||||
|
||||
self.screen.write(buf)
|
||||
self.display.sync_rects(damage);
|
||||
|
||||
Ok(buf.len())
|
||||
}
|
||||
|
||||
fn close(&mut self, id: usize) -> Result<usize> {
|
||||
self.handles.remove(&id).ok_or(Error::new(EBADF))?;
|
||||
fn close(&mut self, _id: usize) -> Result<usize> {
|
||||
Ok(0)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,41 +0,0 @@
|
||||
extern crate ransid;
|
||||
|
||||
use std::collections::VecDeque;
|
||||
|
||||
use syscall::error::*;
|
||||
|
||||
use crate::display::Display;
|
||||
|
||||
pub struct TextScreen {
|
||||
pub display: Display,
|
||||
inner: console_draw::TextScreen,
|
||||
}
|
||||
|
||||
impl TextScreen {
|
||||
pub fn new(display: Display) -> TextScreen {
|
||||
TextScreen {
|
||||
display,
|
||||
inner: console_draw::TextScreen::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl TextScreen {
|
||||
pub fn write(&mut self, buf: &[u8]) -> Result<usize> {
|
||||
let mut map = self.display.map.lock().unwrap();
|
||||
let damage = self.inner.write(
|
||||
&mut console_draw::DisplayMap {
|
||||
offscreen: map.inner.ptr_mut(),
|
||||
width: map.inner.width(),
|
||||
height: map.inner.height(),
|
||||
},
|
||||
buf,
|
||||
&mut VecDeque::new(),
|
||||
);
|
||||
drop(map);
|
||||
|
||||
self.display.sync_rects(damage);
|
||||
|
||||
Ok(buf.len())
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user