UdevMonitor

Struct UdevMonitor 

Source
pub struct UdevMonitor { /* private fields */ }
Expand description

Handles device event sources.

Implementations§

Source§

impl UdevMonitor

Source

pub fn new(udev: Arc<Udev>) -> Result<Self>

Creates a new UdevMonitor.

Creates a UdevMonitor from group name and socket file descriptor.

Creates a new UdevMonitor from the provided parameters.

Parameters:

udev: udev library context name: name of event source

From the libudev documentation:

Create new udev monitor and connect to a specified event
source. Valid sources identifiers are "udev" and "kernel".

Applications should usually not connect directly to the
"kernel" events, because the devices might not be usable
at that time, before `udev` has configured them, and created
device nodes. Accessing devices at the same time as `udev`,
might result in unpredictable behavior. The "`udev`" events
are sent out after `udev` has finished its event processing,
all rules have been processed, and needed device nodes are
created.

Returns: a new UdevMonitor, or Error, in case of an error

Source

pub const fn udev(&self) -> &Arc<Udev>

Gets a reference to the Udev context.

Source

pub const fn sock(&self) -> i32

Gets the socket file descriptor.

Source

pub fn set_sock(&mut self, val: i32)

Sets the socket file descriptor.

Source

pub fn with_sock(self, val: i32) -> Self

Builder function that sets the socket file descriptor.

Source

pub const fn snl(&self) -> &UdevSocket

Gets a reference to the SNL UdevSocket.

Source

pub fn set_snl(&mut self, val: UdevSocket)

Sets the SNL UdevSocket.

NOTE: the SNL socket is only set for UdevSocket::Netlink sockets.

Source

pub fn with_snl(self, val: UdevSocket) -> Self

Builder function that sets the SNL UdevSocket.

NOTE: the SNL socket is only set for UdevSocket::Netlink sockets.

Source

pub const fn snl_group(&self) -> UdevMonitorNetlinkGroup

Source

pub fn set_snl_group<G: Into<UdevMonitorNetlinkGroup>>(&mut self, val: G)

Source

pub fn with_snl_group<G: Into<UdevMonitorNetlinkGroup>>(self, val: G) -> Self

Builder function that sets the SNL UdevMonitorNetlinkGroup.

Source

pub const fn snl_trusted_sender(&self) -> &UdevSocket

Gets a reference to the SNL trusted sender UdevSocket.

Source

pub fn set_snl_trusted_sender(&mut self, val: UdevSocket)

Sets the SNL trusted sender UdevSocket.

NOTE: the SNL socket is only set for UdevSocket::Netlink sockets.

Source

pub fn with_snl_trusted_sender(self, val: UdevSocket) -> Self

Builder function that sets the SNL trusted sender UdevSocket.

NOTE: the SNL socket is only set for UdevSocket::Netlink sockets.

Source

pub const fn snl_destination(&self) -> &UdevSocket

Gets a reference to the SNL destination UdevSocket.

Source

pub fn set_snl_destination(&mut self, val: UdevSocket)

Sets the SNL destination UdevSocket.

NOTE: the SNL socket is only set for UdevSocket::Netlink sockets.

Source

pub fn with_snl_destination(self, val: UdevSocket) -> Self

Builder function that sets the SNL destination UdevSocket.

NOTE: the SNL socket is only set for UdevSocket::Netlink sockets.

Source

pub const fn snl_destination_group(&self) -> UdevMonitorNetlinkGroup

Gets the SNL destination UdevMonitorNetlinkGroup.

Source

pub fn set_snl_destination_group<G: Into<UdevMonitorNetlinkGroup>>( &mut self, val: G, )

Sets the SNL destination UdevMonitorNetlinkGroup.

Source

pub fn with_snl_destination_group<G: Into<UdevMonitorNetlinkGroup>>( self, val: G, ) -> Self

Builder function that sets the SNL destination UdevMonitorNetlinkGroup.

Source

pub const fn addrlen(&self) -> usize

Gets the socket address length.

Source

pub const fn filter_subsystem_list(&self) -> &UdevList

Gets a reference to the filter subsystem UdevList.

Source

pub fn filter_subsystem_list_mut(&mut self) -> &mut UdevList

Gets a mutable reference to the filter subsystem UdevList.

Source

pub fn set_filter_subsystem_list<L: Into<UdevEntryList>>(&mut self, list: L)

Sets the filter subsystem UdevList.

Source

pub fn with_filter_subsystem_list<L: Into<UdevEntryList>>(self, list: L) -> Self

Builder function that sets the filter subsystem UdevList.

Source

pub const fn filter_tag_list(&self) -> &UdevList

Gets a reference to the filter tag UdevList.

Source

pub fn filter_tag_list_mut(&mut self) -> &mut UdevList

Gets a mutable reference to the filter tag UdevList.

Source

pub fn set_filter_tag_list<L: Into<UdevEntryList>>(&mut self, list: L)

Sets the filter tag UdevList.

Source

pub fn with_filter_tag_list<L: Into<UdevEntryList>>(self, list: L) -> Self

Builder function that sets the filter tag UdevList.

Source

pub const fn bound(&self) -> bool

Gets whether the UdevMonitor is bound to a socket.

Source

pub fn passes_filter(&self, device: &mut UdevDevice) -> bool

Gets whether the UdevDevice passes the UdevMonitor filters.

Source

pub fn filter_update(&mut self) -> Result<()>

Updates the monitor socket filter.

From the libudev documentation:

Update the installed socket filter. This is only needed,
if the filter was removed or changed.

Returns: Ok(()) on success, Err(Error) otherwise.

Source

pub fn enable_receiving(&mut self) -> Result<()>

Binds the UdevMonitor socket to the event source.

Source

pub fn set_receive_buffer_size(&mut self, size: usize) -> Result<()>

Sets the size of the kernel socket buffer.

From the libudev documentation:

Set the size of the kernel socket buffer. This call needs the
appropriate privileges to succeed.

Returns: Ok(()) on success, Err(Error) otherwise.

Source

pub fn receive_device(&mut self) -> Result<UdevDevice>

Receives data from the UdevMonitor socket.

From the libudev documentation:

Receive data from the udev monitor socket, allocate a new udev
device, fill in the received data, and return the device.

Only socket connections with uid=0 are accepted.

The monitor socket is by default set to NONBLOCK. A variant of poll() on
the file descriptor returned by udev_monitor_get_fd() should to be used to
wake up when new devices arrive, or alternatively the file descriptor
switched into blocking mode.

If polling, our equivalent of udev_monitor_get_fd() are the AsFd and AsRawFd trait implementations.

Returns: Ok(UdevDevice) on success, Err(Error) otherwise.

Source

pub fn send_device( &mut self, destination: Option<&mut Self>, device: &mut UdevDevice, ) -> Result<isize>

Sends an UdevDevice from one UdevMonitor to another.

Source

pub fn filter_add_match_subsystem_devtype( &mut self, subsystem: &str, devtype: &str, ) -> Result<&UdevEntry>

Adds an UdevEntry into the filter subsystem list.

From libudev documentation:

Parameters:

  • subsystem: the subsystem value to match the incoming devices against
    • must be non-empty
  • devtype: the devtype value to match the incoming devices against
This filter is efficiently executed inside the kernel, and libudev subscribers
will usually not be woken up for devices which do not match.

The filter must be installed before the monitor is switched to listening mode.

Returns Ok on success, Err otherwise.

Source

pub fn filter_add_match_tag(&mut self, tag: &str) -> Result<&UdevEntry>

Adds an UdevEntry into the filter tag list.

From libudev documentation:

  • tag: the name of a tag
    • must be non-empty
This filter is efficiently executed inside the kernel, and libudev subscribers
will usually not be woken up for devices which do not match.

The filter must be installed before the monitor is switched to listening mode.

Returns Ok on success, Err otherwise.

Source

pub fn filter_remove(&mut self) -> Result<()>

Removes all filters from the UdevMonitor.

Returns Ok(()) on success, Err(Error) otherwise.

Trait Implementations§

Source§

impl AsFd for UdevMonitor

Source§

fn as_fd(&self) -> BorrowedFd<'_>

Borrows the file descriptor. Read more
Source§

impl AsRawFd for UdevMonitor

Source§

fn as_raw_fd(&self) -> RawFd

Extracts the raw file descriptor. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

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

Source§

type Error = Infallible

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

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

Performs the conversion.
Source§

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

Source§

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

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

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

Performs the conversion.