Struct ndk::looper::ForeignLooper

source ·
pub struct ForeignLooper { /* private fields */ }
Expand description

A native ALooper *, not necessarily allocated with the current thread.

Implementations§

source§

impl ForeignLooper

source

pub fn for_thread() -> Option<Self>

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

source

pub unsafe fn from_ptr(ptr: NonNull<ALooper>) -> Self

Construct a ForeignLooper object from the given pointer.

§Safety

By calling this function, you guarantee that the pointer is a valid, non-null pointer to an NDK ffi::ALooper.

source

pub fn ptr(&self) -> NonNull<ALooper>

Returns a pointer to the NDK ALooper object.

source

pub fn wake(&self)

Wakes the looper. An event of Poll::Wake will be sent.

source

pub fn add_fd( &self, fd: BorrowedFd<'_>, ident: i32, events: FdEvent, data: *mut c_void ) -> Result<(), LooperError>

Adds a file descriptor to be polled, without a callback.

See also the NDK docs.

§Safety

The caller should guarantee that this file descriptor stays open until it is removed via remove_fd(), and for however long the caller wishes to use this file descriptor when it is returned in Poll::Event::fd.

source

pub fn add_fd_with_callback<F: FnMut(BorrowedFd<'_>, FdEvent) -> bool + Send>( &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 looper thread where and when it is polled. For registering callbacks without Send requirement, call the equivalent ThreadLooper::add_fd_with_callback() function on the Looper thread.

§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 remove_fd(&self, fd: BorrowedFd<'_>) -> Result<bool, LooperError>

Removes a previously added file descriptor from the looper.

Returns true if the file descriptor was removed, false if it was not previously registered.

§Safety

When this method returns, it is safe to close the file descriptor since the looper will no longer have a reference to it. However, it is possible for the callback to already be running or for it to run one last time if the file descriptor was already signalled. Calling code is responsible for ensuring that this case is safely handled. For example, if the callback takes care of removing itself during its own execution either by returning 0 or by calling this method, then it can be guaranteed to not be invoked again at any later time unless registered anew.

Note that unregistering a file descriptor with callback will leak a Box created in add_fd_with_callback(). Consider returning false from the callback instead to drop it.

Trait Implementations§

source§

impl Clone for ForeignLooper

source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for ForeignLooper

source§

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

Formats the value using the given formatter. Read more
source§

impl Drop for ForeignLooper

source§

fn drop(&mut self)

Executes the destructor for this type. Read more
source§

impl Send for ForeignLooper

source§

impl Sync for ForeignLooper

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> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.