Struct pipewire::loop_::LoopRef

source ·
pub struct LoopRef(/* private fields */);
Expand description

A transparent wrapper around a raw pw_loop. It is usually only seen in a reference (&LoopRef).

An owned version, Loop, is available, which lets you create and own a pw_loop, but other objects, such as MainLoop, also contain them.

Implementations§

source§

impl LoopRef

source

pub fn as_raw(&self) -> &pw_loop

source

pub fn as_raw_ptr(&self) -> *mut pw_loop

source

pub fn fd(&self) -> BorrowedFd<'_>

Get the file descriptor backing this loop.

source

pub unsafe fn enter(&self)

Enter a loop

Start an iteration of the loop. This function should be called before calling iterate and is typically used to capture the thread that this loop will run in.

§Safety

Each call of enter must be paired with a call of leave.

source

pub unsafe fn leave(&self)

Leave a loop

Ends the iteration of a loop. This should be called after calling iterate.

§Safety

Each call of leave must be paired with a call of enter.

source

pub fn iterate(&self, timeout: Duration) -> i32

Perform one iteration of the loop.

An optional timeout can be provided. 0 for no timeout, -1 for infinite timeout.

This function will block up to the provided timeout and then dispatch the fds with activity. The number of dispatched fds is returned.

This will automatically call Self::enter() on the loop before iterating, and Self::leave() afterwards.

§Panics

This function will panic if the provided timeout as milliseconds does not fit inside a c_int integer.

source

pub unsafe fn iterate_unguarded(&self, timeout: Duration) -> i32

A variant of iterate() that does not call Self::enter() and Self::leave() on the loop.

§Safety

Before calling this, Self::enter() must be called, and Self::leave() must be called afterwards.

source

pub fn add_io<I, F>( &self, io: I, event_mask: IoFlags, callback: F ) -> IoSource<'_, I>
where I: AsRawFd, F: Fn(&mut I) + 'static, Self: Sized,

Register some type of IO object with a callback that is called when reading/writing on the IO object is available.

The specified event_mask determines whether to trigger when either input, output, or any of the two is available.

The returned IoSource needs to take ownership of the IO object, but will provide a reference to the callback when called.

source

pub fn add_idle<F>(&self, enabled: bool, callback: F) -> IdleSource<'_>
where F: Fn() + 'static,

Register a callback to be called whenever the loop is idle.

This can be enabled and disabled as needed with the enabled parameter, and also with the enable method on the returned source.

source

pub fn add_signal_local<F>( &self, signal: Signal, callback: F ) -> SignalSource<'_>
where F: Fn() + 'static, Self: Sized,

Register a signal with a callback that is called when the signal is sent.

For example, this can be used to quit the loop when the process receives the SIGTERM signal.

source

pub fn add_event<F>(&self, callback: F) -> EventSource<'_>
where F: Fn() + 'static, Self: Sized,

Register a new event with a callback that is called when the event happens.

The returned EventSource can be used to trigger the event.

source

pub fn add_timer<F>(&self, callback: F) -> TimerSource<'_>
where F: Fn(u64) + 'static, Self: Sized,

Register a timer with the loop with a callback that is called after the timer expired.

The timer will start out inactive, and the returned TimerSource can be used to arm the timer, or disarm it again.

The callback will be provided with the number of timer expirations since the callback was last called.

Trait Implementations§

source§

impl AsRef<LoopRef> for Loop

source§

fn as_ref(&self) -> &LoopRef

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl AsRef<LoopRef> for MainLoop

source§

fn as_ref(&self) -> &LoopRef

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl AsRef<LoopRef> for ThreadLoop

source§

fn as_ref(&self) -> &LoopRef

Converts this type into a shared reference of the (usually inferred) input type.

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.