MainLoop

Struct MainLoop 

Source
pub struct MainLoop { /* private fields */ }
Expand description

An event loop implementation. This event loop is used for communication with PipeWire, and provides a number of primitives for integration with applications and any other event loops or event sources they might have.

Many of these primitives are quite low-level, and it is also possible to use the main loop only for PipeWire-related events. This can be done by creating the MainLoop and invoking MainLoop::run on a separate thread. In this case, it is important to make sure that any access to common data structures is protected from concurrent access. The MainLoop::lock and MainLoop::unlock methods provide such a mechanism.

Implementations§

Source§

impl MainLoop

Source

pub fn new(props: &Properties) -> Option<MainLoop>

Create a new main loop.

Source

pub fn run(&self)

Run the main loop. This takes over executation of the current thread until MainLoop::quit is invoked.

Source

pub fn quit(&self)

Terminate execution of the main loop.

Source

pub fn add_listener(&self, events: MainLoopEvents) -> HookId

Add a listener for main loop events.

Source

pub fn remove_listener(&self, hook_id: HookId)

Remove a set of event listeners.

Source

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

Run one iteration of the loop, returning if no events occurred in timeout time. A value of None signifies an infinite timeout. Returns the number of iterations performed.

Source

pub fn lock(&self) -> Result<()>

Take the main loop lock, preventing it from running until the lock is released. The main loop takes this lock in each of its iterations.

Source

pub fn unlock(&self) -> Result<()>

Release the main loop lock, allowing it to run again.

Source

pub fn get_time(&self, timeout: Duration) -> Result<timespec>

Get the time corresponding to the specified timeout, which can be used with MainLoop::wait.

Source

pub fn wait(&self, abstime: &timespec) -> Result<()>

Wait until the specified time or until signalled.

Source

pub fn signal(&self, wait_for_accept: bool) -> Result<()>

Signal any threads waiting with MainLoop::wait to wake up.

Source

pub fn accept(&self) -> Result<()>

Acknowledge a MainLoop::signal with wait_for_accept: true, allowing that thread to proceed.

Source

pub fn add_io( &self, fd: RawFd, mask: Io, close: bool, func: Box<SourceIoFn>, ) -> Option<Source>

Add an I/O event source using the given fd.

Source

pub fn update_io(&self, source: &mut Source, mask: Io) -> Result<i32>

Update the set of events of interest (given by mask).

Source

pub fn add_idle(&self, enabled: bool, func: Box<SourceIdleFn>) -> Option<Source>

Add an idle event source (called after each iteration of the main loop).

Source

pub fn enable_idle(&self, source: &mut Source, enabled: bool) -> Result<i32>

Enable or disable an idle event source.

Source

pub fn add_event(&self, func: Box<SourceEventFn>) -> Option<Source>

Add a source which can be triggered using Self::signal_event.

Source

pub fn signal_event(&self, source: &mut Source) -> Result<i32>

Signal a source added with Self::add_event.

Source

pub fn add_timer(&self, func: Box<SourceTimerFn>) -> Option<Source>

Add a timer source.

Source

pub fn update_timer( &self, source: &mut Source, value: &timespec, interval: Option<&timespec>, absolute: bool, ) -> Result<i32>

Update the timer interval of a timer source.

Source

pub fn add_signal( &self, signal_number: i32, func: Box<SourceSignalFn>, ) -> Option<Source>

Add a source triggered by UNIX signals.

Source

pub fn destroy_source(&self, source: Source)

Remove and destroy an event source.

Source

pub fn set_name(&mut self, name: &str)

Set the main loop name.

Trait Implementations§

Source§

impl Clone for MainLoop

Source§

fn clone(&self) -> MainLoop

Returns a duplicate 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 Refcounted for MainLoop

Source§

type WeakRef = WeakMainLoop

The type of a weak reference to the object
Source§

fn upgrade(this: &Self::WeakRef) -> Option<Self>

Try to convert a weak reference to a strong reference. If the underlying object isstill alive, returns a Some continaing the value. If the underlying object’s strong reference count dropped to zero, and was thus freed, this returns None.
Source§

fn downgrade(&self) -> Self::WeakRef

Create a weak reference to the object. This reference does not impact the object’s lifecycle, and merely allows us the option to try to retrieve the object using Self::upgrade().
Source§

impl Send for MainLoop

Source§

impl Sync for MainLoop

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

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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,

Source§

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

Source§

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

Source§

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.