Struct DeviceManager

Source
pub struct DeviceManager {
    devices: Mutex<BTreeMap<usize, SharedDevice>>,
    device_by_name: Mutex<BTreeMap<String, SharedDevice>>,
    name_to_id: Mutex<BTreeMap<String, usize>>,
    drivers: Mutex<BTreeMap<DriverPriority, Vec<Box<dyn DeviceDriver>>>>,
    next_device_id: AtomicUsize,
}
Expand description

DeviceManager

This struct is the main device management system. It handles all devices and drivers with priority-based initialization.

§Fields

  • devices: A mutex-protected map of all registered devices by ID.
  • device_by_name: A mutex-protected map of devices by name.
  • name_to_id: A mutex-protected map from device name to device ID.
  • drivers: A mutex-protected map of device drivers organized by priority.
  • next_device_id: Atomic counter for generating unique device IDs.

Fields§

§devices: Mutex<BTreeMap<usize, SharedDevice>>§device_by_name: Mutex<BTreeMap<String, SharedDevice>>§name_to_id: Mutex<BTreeMap<String, usize>>§drivers: Mutex<BTreeMap<DriverPriority, Vec<Box<dyn DeviceDriver>>>>§next_device_id: AtomicUsize

Implementations§

Source§

impl DeviceManager

Source

const fn new() -> Self

Source

pub fn get_manager() -> &'static DeviceManager

Source

pub fn get_mut_manager() -> &'static mut DeviceManager

Source

pub fn register_device(&self, device: Arc<dyn Device>) -> usize

Register a device with the manager

§Arguments
  • device: The device to register.
§Returns
  • The id of the registered device.
§Example
let device = Arc::new(MyDevice::new());
let id = DeviceManager::get_mut_manager().register_device(device);
Source

pub fn register_device_with_name( &self, name: String, device: Arc<dyn Device>, ) -> usize

Register a device with the manager by name

§Arguments
  • name: The name of the device.
  • device: The device to register.
§Returns
  • The id of the registered device.
Source

pub fn get_device(&self, id: usize) -> Option<SharedDevice>

Get a device by ID

§Arguments
  • id: The id of the device to get.
§Returns
  • The device if found, or None if not found.
Source

pub fn get_device_by_name(&self, name: &str) -> Option<SharedDevice>

Get a device by name

§Arguments
  • name: The name of the device to get.
§Returns
  • The device if found, or None if not found.
Source

pub fn get_device_id_by_name(&self, name: &str) -> Option<usize>

Get a device ID by name

§Arguments
  • name: The name of the device to find.
§Returns
  • The device ID if found, or None if not found.
Source

pub fn get_devices_count(&self) -> usize

Get the number of devices

§Returns

The number of devices.

Source

pub fn get_first_device_by_type(&self, device_type: DeviceType) -> Option<usize>

Get the first device of a specific type

§Arguments
  • device_type: The device type to find.
§Returns
  • The first device ID of the specified type, or None if not found.
Source

pub fn get_named_devices(&self) -> Vec<(String, SharedDevice)>

Get all devices registered by name

Returns an iterator over (name, device) pairs for all devices that were registered with explicit names.

§Returns

Vector of (name, device) tuples

Source

pub fn borrow_drivers( &self, ) -> &Mutex<BTreeMap<DriverPriority, Vec<Box<dyn DeviceDriver>>>>

Source

pub fn populate_devices(&mut self)

Populates devices from the FDT (Flattened Device Tree).

This function searches for the /soc node in the FDT and iterates through its children. For each child node, it checks if there is a compatible driver registered. If a matching driver is found, it probes the device using the driver’s probe method. If the probe is successful, the device is registered with the driver.

Source

pub fn populate_devices_by_priority( &mut self, priorities: Option<&[DriverPriority]>, )

Populate devices using drivers of specific priority levels

§Arguments
  • priorities - Optional slice of priority levels to use. If None, uses all priorities in order.
Source

pub fn register_driver( &mut self, driver: Box<dyn DeviceDriver>, priority: DriverPriority, )

Registers a device driver with the device manager.

This function takes a boxed device driver and adds it to the list of registered drivers at the specified priority level.

§Arguments
  • driver - A boxed device driver that implements the DeviceDriver trait.
  • priority - The priority level for this driver.
§Example
let driver = Box::new(MyDeviceDriver::new());
DeviceManager::get_mut_manager().register_driver(driver, DriverPriority::Standard);
Source

pub fn register_driver_default(&mut self, driver: Box<dyn DeviceDriver>)

Registers a device driver with default Standard priority.

This is a convenience method for backward compatibility.

§Arguments
  • driver - A boxed device driver that implements the DeviceDriver trait.

Auto Trait Implementations§

§

impl !Freeze for DeviceManager

§

impl !RefUnwindSafe for DeviceManager

§

impl !Send for DeviceManager

§

impl !Sync for DeviceManager

§

impl Unpin for DeviceManager

§

impl !UnwindSafe for DeviceManager

Blanket Implementations§

§

impl<T> Any for T
where T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Borrow<T> for T
where T: ?Sized,

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

impl<T> BorrowMut<T> for T
where T: ?Sized,

§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, U> Into<U> for T
where U: From<T>,

§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.