添加irqdesc的抽象,并在系统初始化时创建irqdesc (#522)

* 添加irqdesc的抽象,并在系统初始化时创建irqdesc
This commit is contained in:
LoGin
2024-02-19 00:36:36 +08:00
committed by GitHub
parent ce5850adbf
commit 3bc96fa4a9
13 changed files with 702 additions and 19 deletions

View File

@ -873,3 +873,45 @@ impl DeviceMatcher<&str> for DeviceMatchName {
return device.name() == data;
}
}
/// Cookie to identify the device
#[derive(Debug, Clone)]
pub struct DeviceId {
data: Option<&'static str>,
allocated: Option<String>,
}
impl DeviceId {
#[allow(dead_code)]
pub fn new(data: Option<&'static str>, allocated: Option<String>) -> Option<Self> {
if data.is_none() && allocated.is_none() {
return None;
}
// 如果data和allocated都有值那么返回None
if data.is_some() && allocated.is_some() {
return None;
}
return Some(Self { data, allocated });
}
pub fn id(&self) -> Option<&str> {
if self.data.is_some() {
return Some(self.data.unwrap());
} else {
return self.allocated.as_deref();
}
}
pub fn set_allocated(&mut self, allocated: String) {
self.allocated = Some(allocated);
self.data = None;
}
}
impl PartialEq for DeviceId {
fn eq(&self, other: &Self) -> bool {
return self.id() == other.id();
}
}