pub struct ThreadLooper { /* private fields */ }Expand description
A thread-local native ALooper *. This promises that there is a looper associated with the
current thread.
Implementations§
Source§impl ThreadLooper
impl ThreadLooper
Sourcepub fn for_thread() -> Option<Self>
pub fn for_thread() -> Option<Self>
Returns the looper associated with the current thread, if any.
Sourcepub fn poll_once(&self) -> Result<Poll<'_>, LooperError>
pub fn poll_once(&self) -> Result<Poll<'_>, LooperError>
Polls the looper, blocking on processing an event.
Sourcepub fn poll_once_timeout(
&self,
timeout: Duration,
) -> Result<Poll<'_>, LooperError>
pub fn poll_once_timeout( &self, timeout: Duration, ) -> Result<Poll<'_>, LooperError>
Polls the looper, blocking on processing an event, but with a timeout. Give a timeout of
Duration::ZERO to make this non-blocking.
It panics if the timeout is larger than expressible as an i32 of milliseconds (roughly 25
days).
Sourcepub fn poll_all(&self) -> Result<Poll<'_>, LooperError>
pub fn poll_all(&self) -> Result<Poll<'_>, LooperError>
Repeatedly polls the looper, blocking on processing an event.
This function will never return Poll::Callback.
Sourcepub fn poll_all_timeout(
&self,
timeout: Duration,
) -> Result<Poll<'_>, LooperError>
pub fn poll_all_timeout( &self, timeout: Duration, ) -> Result<Poll<'_>, LooperError>
Repeatedly polls the looper, blocking on processing an event, but with a timeout. Give a
timeout of Duration::ZERO to make this non-blocking.
This function will never return Poll::Callback.
It panics if the timeout is larger than expressible as an i32 of milliseconds (roughly 25
days).
Sourcepub fn add_fd_with_callback<F: FnMut(BorrowedFd<'_>, FdEvent) -> bool>(
&self,
fd: BorrowedFd<'_>,
events: FdEvent,
callback: F,
) -> Result<(), LooperError>
pub fn add_fd_with_callback<F: FnMut(BorrowedFd<'_>, FdEvent) -> bool>( &self, fd: BorrowedFd<'_>, events: FdEvent, callback: F, ) -> Result<(), LooperError>
Adds a file descriptor to be polled, with a callback that is invoked when any of the
FdEvents described in events is triggered.
The callback receives the file descriptor it is associated with and a bitmask of the poll
events that were triggered (typically FdEvent::INPUT). It should return true to
continue receiving callbacks, or false to have the callback unregistered.
See also the NDK docs.
Note that this will leak a Box unless the callback returns false to unregister
itself.
§Threading
This function will be called on the current thread when this ThreadLooper is
polled. A callback can also be registered from other threads via the equivalent
ForeignLooper::add_fd_with_callback() function, which requires a Send bound.
§Safety
The caller should guarantee that this file descriptor stays open until it is removed via
remove_fd() or by returning false from the callback,
and for however long the caller wishes to use this file descriptor inside and after the
callback.
Sourcepub fn as_foreign(&self) -> &ForeignLooper
pub fn as_foreign(&self) -> &ForeignLooper
Returns a reference to the ForeignLooper that is associated with the current thread.