//! A tree of hardware devices use { crate::alloc::string::ToString, alloc::{string::String, vec::Vec}, core::fmt, hashbrown::HashMap, }; /// A device object. /// TODO define device pub type Device = xml::XMLElement; /// A tree of devices // TODO: alphabatize this list #[derive(Debug)] pub struct DeviceTree { /// The device tree pub devices: HashMap>, } impl DeviceTree { /// Build the device tree. Does not populate the device tree pub fn new() -> Self { let mut dt = Self { devices: HashMap::new(), }; // Human input devices { dt.devices.insert("Mice".to_string(), Vec::new()); dt.devices.insert("Keyboards".to_string(), Vec::new()); dt.devices.insert("Controllers".to_string(), Vec::new()); // Human Input Devices that do not fit into other catagories go in this spot dt.devices.insert("Generic HIDs".to_string(), Vec::new()); } { dt.devices.insert("Disk Drives".to_string(), Vec::new()); dt.devices.insert("CD Drives".to_string(), Vec::new()); } dt.devices.insert("Batteries".to_string(), Vec::new()); dt.devices.insert("Monitors".to_string(), Vec::new()); dt.devices.insert("GPUs".to_string(), Vec::new()); dt.devices.insert("CPUs".to_string(), Vec::new()); dt.devices.insert("USB".to_string(), Vec::new()); dt.devices.insert("Serial Ports".to_string(), Vec::new()); dt.devices.insert("Cameras".to_string(), Vec::new()); dt.devices .insert("Biometric Devices".to_string(), Vec::new()); dt } } use crate::utils::TAB; use crate::tab; impl fmt::Display for DeviceTree { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { writeln!(f)?; for (device_type, devices) in &self.devices { writeln!(f, "\r{}{}/\r", tab!(1), device_type)?; for device in devices { writeln!(f, "{}{}/\r", tab!(2), device.name)?; for attr in &device.attributes { writeln!(f, "{}{}\r", tab!(3), attr)?; } for child in &device.children { writeln!(f, "{}{}\r", tab!(3), child.name)?; for attr in &child.attributes { writeln!(f, "{}{}\r", tab!(4), attr)?; } for child in &child.children { writeln!(f, "{}{}\r", tab!(4), child.name)?; for attr in &child.attributes { writeln!(f, "{}{}\r", tab!(5), attr)?; } } } } } Ok(()) } }