Refactor drivers

This commit is contained in:
Yuke Peng
2023-11-20 20:37:51 +08:00
committed by Tate, Hongliang Tian
parent d809eca81d
commit edd808bd3d
12 changed files with 87 additions and 67 deletions

View File

@ -25,7 +25,7 @@ pub fn register_device(name: String, device: Arc<dyn AnyConsoleDevice>) {
COMPONENT
.get()
.unwrap()
.console_table
.console_device_table
.lock()
.insert(name, device);
}
@ -34,15 +34,15 @@ pub fn get_device(str: &str) -> Option<Arc<dyn AnyConsoleDevice>> {
COMPONENT
.get()
.unwrap()
.console_table
.console_device_table
.lock()
.get(str)
.cloned()
}
pub fn all_devices() -> Vec<(String, Arc<dyn AnyConsoleDevice>)> {
let consoles = COMPONENT.get().unwrap().console_table.lock();
consoles
let console_devs = COMPONENT.get().unwrap().console_device_table.lock();
console_devs
.iter()
.map(|(name, device)| (name.clone(), device.clone()))
.collect()
@ -59,13 +59,13 @@ fn component_init() -> Result<(), ComponentInitError> {
#[derive(Debug)]
struct Component {
console_table: SpinLock<BTreeMap<String, Arc<dyn AnyConsoleDevice>>>,
console_device_table: SpinLock<BTreeMap<String, Arc<dyn AnyConsoleDevice>>>,
}
impl Component {
pub fn init() -> Result<Self, ComponentInitError> {
Ok(Self {
console_table: SpinLock::new(BTreeMap::new()),
console_device_table: SpinLock::new(BTreeMap::new()),
})
}
}