Struct ndk::looper::ThreadLooper

source ·
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

source

pub fn prepare() -> Self

Prepares a looper for the current thread and returns it

source

pub fn for_thread() -> Option<Self>

Returns the looper associated with the current thread, if any.

source

pub fn poll_once(&self) -> Result<Poll<'_>, LooperError>

Polls the looper, blocking on processing an event.

source

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).

source

pub fn poll_all(&self) -> Result<Poll<'_>, LooperError>

Repeatedly polls the looper, blocking on processing an event.

This function will never return Poll::Callback.

source

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).

source

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.

source

pub fn as_foreign(&self) -> &ForeignLooper

Returns a reference to the ForeignLooper that is associated with the current thread.

source

pub fn into_foreign(self) -> ForeignLooper

Trait Implementations§

source§

impl Debug for ThreadLooper

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. 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>,

§

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>,

§

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.