pub struct UdevMonitor { /* private fields */ }Expand description
Handles device event sources.
Implementations§
Source§impl UdevMonitor
impl UdevMonitor
Sourcepub fn new_from_netlink_fd<N: Into<UdevMonitorNetlinkGroup> + Display + Copy>(
udev: Arc<Udev>,
name: N,
fd: i32,
) -> Result<Self>
pub fn new_from_netlink_fd<N: Into<UdevMonitorNetlinkGroup> + Display + Copy>( udev: Arc<Udev>, name: N, fd: i32, ) -> Result<Self>
Creates a UdevMonitor from group name and socket file descriptor.
Sourcepub fn new_from_netlink<N: Into<UdevMonitorNetlinkGroup> + Display + Copy>(
udev: Arc<Udev>,
name: N,
) -> Result<Self>
pub fn new_from_netlink<N: Into<UdevMonitorNetlinkGroup> + Display + Copy>( udev: Arc<Udev>, name: N, ) -> Result<Self>
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
Sourcepub fn with_sock(self, val: i32) -> Self
pub fn with_sock(self, val: i32) -> Self
Builder function that sets the socket file descriptor.
Sourcepub const fn snl(&self) -> &UdevSocket
pub const fn snl(&self) -> &UdevSocket
Gets a reference to the SNL UdevSocket.
Sourcepub fn set_snl(&mut self, val: UdevSocket)
pub fn set_snl(&mut self, val: UdevSocket)
Sets the SNL UdevSocket.
NOTE: the SNL socket is only set for UdevSocket::Netlink sockets.
Sourcepub fn with_snl(self, val: UdevSocket) -> Self
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.
Sourcepub const fn snl_group(&self) -> UdevMonitorNetlinkGroup
pub const fn snl_group(&self) -> UdevMonitorNetlinkGroup
Gets the SNL UdevMonitorNetlinkGroup.
Sourcepub fn set_snl_group<G: Into<UdevMonitorNetlinkGroup>>(&mut self, val: G)
pub fn set_snl_group<G: Into<UdevMonitorNetlinkGroup>>(&mut self, val: G)
Sets the SNL UdevMonitorNetlinkGroup.
Sourcepub fn with_snl_group<G: Into<UdevMonitorNetlinkGroup>>(self, val: G) -> Self
pub fn with_snl_group<G: Into<UdevMonitorNetlinkGroup>>(self, val: G) -> Self
Builder function that sets the SNL UdevMonitorNetlinkGroup.
Sourcepub const fn snl_trusted_sender(&self) -> &UdevSocket
pub const fn snl_trusted_sender(&self) -> &UdevSocket
Gets a reference to the SNL trusted sender UdevSocket.
Sourcepub fn set_snl_trusted_sender(&mut self, val: UdevSocket)
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.
Sourcepub fn with_snl_trusted_sender(self, val: UdevSocket) -> Self
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.
Sourcepub const fn snl_destination(&self) -> &UdevSocket
pub const fn snl_destination(&self) -> &UdevSocket
Gets a reference to the SNL destination UdevSocket.
Sourcepub fn set_snl_destination(&mut self, val: UdevSocket)
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.
Sourcepub fn with_snl_destination(self, val: UdevSocket) -> Self
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.
Sourcepub const fn snl_destination_group(&self) -> UdevMonitorNetlinkGroup
pub const fn snl_destination_group(&self) -> UdevMonitorNetlinkGroup
Gets the SNL destination UdevMonitorNetlinkGroup.
Sourcepub fn set_snl_destination_group<G: Into<UdevMonitorNetlinkGroup>>(
&mut self,
val: G,
)
pub fn set_snl_destination_group<G: Into<UdevMonitorNetlinkGroup>>( &mut self, val: G, )
Sets the SNL destination UdevMonitorNetlinkGroup.
Sourcepub fn with_snl_destination_group<G: Into<UdevMonitorNetlinkGroup>>(
self,
val: G,
) -> Self
pub fn with_snl_destination_group<G: Into<UdevMonitorNetlinkGroup>>( self, val: G, ) -> Self
Builder function that sets the SNL destination UdevMonitorNetlinkGroup.
Sourcepub const fn filter_subsystem_list(&self) -> &UdevList
pub const fn filter_subsystem_list(&self) -> &UdevList
Gets a reference to the filter subsystem UdevList.
Sourcepub fn filter_subsystem_list_mut(&mut self) -> &mut UdevList
pub fn filter_subsystem_list_mut(&mut self) -> &mut UdevList
Gets a mutable reference to the filter subsystem UdevList.
Sourcepub fn set_filter_subsystem_list<L: Into<UdevEntryList>>(&mut self, list: L)
pub fn set_filter_subsystem_list<L: Into<UdevEntryList>>(&mut self, list: L)
Sets the filter subsystem UdevList.
Sourcepub fn with_filter_subsystem_list<L: Into<UdevEntryList>>(self, list: L) -> Self
pub fn with_filter_subsystem_list<L: Into<UdevEntryList>>(self, list: L) -> Self
Builder function that sets the filter subsystem UdevList.
Sourcepub const fn filter_tag_list(&self) -> &UdevList
pub const fn filter_tag_list(&self) -> &UdevList
Gets a reference to the filter tag UdevList.
Sourcepub fn filter_tag_list_mut(&mut self) -> &mut UdevList
pub fn filter_tag_list_mut(&mut self) -> &mut UdevList
Gets a mutable reference to the filter tag UdevList.
Sourcepub fn set_filter_tag_list<L: Into<UdevEntryList>>(&mut self, list: L)
pub fn set_filter_tag_list<L: Into<UdevEntryList>>(&mut self, list: L)
Sets the filter tag UdevList.
Sourcepub fn with_filter_tag_list<L: Into<UdevEntryList>>(self, list: L) -> Self
pub fn with_filter_tag_list<L: Into<UdevEntryList>>(self, list: L) -> Self
Builder function that sets the filter tag UdevList.
Sourcepub const fn bound(&self) -> bool
pub const fn bound(&self) -> bool
Gets whether the UdevMonitor is bound to a socket.
Sourcepub fn passes_filter(&self, device: &mut UdevDevice) -> bool
pub fn passes_filter(&self, device: &mut UdevDevice) -> bool
Gets whether the UdevDevice passes the UdevMonitor filters.
Sourcepub fn filter_update(&mut self) -> Result<()>
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.
Sourcepub fn enable_receiving(&mut self) -> Result<()>
pub fn enable_receiving(&mut self) -> Result<()>
Binds the UdevMonitor socket to the event source.
Sourcepub fn set_receive_buffer_size(&mut self, size: usize) -> Result<()>
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.
Sourcepub fn receive_device(&mut self) -> Result<UdevDevice>
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.
Sourcepub fn send_device(
&mut self,
destination: Option<&mut Self>,
device: &mut UdevDevice,
) -> Result<isize>
pub fn send_device( &mut self, destination: Option<&mut Self>, device: &mut UdevDevice, ) -> Result<isize>
Sends an UdevDevice from one UdevMonitor to another.
Sourcepub fn filter_add_match_subsystem_devtype(
&mut self,
subsystem: &str,
devtype: &str,
) -> Result<&UdevEntry>
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.
Sourcepub fn filter_add_match_tag(&mut self, tag: &str) -> Result<&UdevEntry>
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.
Sourcepub fn filter_remove(&mut self) -> Result<()>
pub fn filter_remove(&mut self) -> Result<()>
Removes all filters from the UdevMonitor.
Returns Ok(()) on success, Err(Error) otherwise.