pub struct Mainloop {
    pub _inner: Rc<MainloopInner<MainloopInternal>>,
}
Expand description

This acts as a safe interface to the internal PA Mainloop.

The mainloop object pointers are further enclosed here in a ref counted wrapper, allowing this outer wrapper to have clean methods for creating event objects, which can cleanly pass a copy of the inner ref counted mainloop object to them. Giving this to events serves two purposes, firstly because they need the API pointer, secondly, it ensures that event objects do not outlive the mainloop object.

Fields§

§_inner: Rc<MainloopInner<MainloopInternal>>

The ref-counted inner data.

Implementations§

source§

impl Mainloop

source

pub fn new() -> Option<Self>

Allocates a new threaded main loop object.

You have to call start() before the event loop thread starts running.

source

pub fn start(&mut self) -> Result<(), PAErr>

Starts the event loop thread.

source

pub fn stop(&mut self)

Terminates the event loop thread cleanly.

Make sure to unlock the mainloop object before calling this function.

source

pub fn lock(&mut self)

Locks the event loop object, effectively blocking the event loop thread from processing events.

You can use this to enforce exclusive access to all objects attached to the event loop. This lock is recursive. This function may not be called inside the event loop thread. Events that are dispatched from the event loop thread are executed with this lock held.

source

pub fn unlock(&mut self)

Unlocks the event loop object, inverse of lock().

source

pub fn wait(&mut self)

Waits for an event to be signalled by the event loop thread.

You can use this to pass data from the event loop thread to the main thread in a synchronized fashion. This function may not be called inside the event loop thread. Prior to this call the event loop object needs to be locked using lock(). While waiting the lock will be released. Immediately before returning it will be acquired again. This function may spuriously wake up even without signal() being called. You need to make sure to handle that!

source

pub fn signal(&mut self, wait_for_accept: bool)

Signals all threads waiting for a signalling event in wait().

If wait_for_accept is true, do not return before the signal was accepted by an accept() call. While waiting for that condition the event loop object is unlocked.

source

pub fn accept(&mut self)

Accepts a signal from the event thread issued with signal().

This call should only be used in conjunction with signal() with wait_for_accept as true.

source

pub fn get_retval(&self) -> Retval

Gets the return value as specified with the main loop’s quit routine (used internally by threaded mainloop).

source

pub fn get_api<'a>(&self) -> &'a MainloopApi

Gets the main loop abstraction layer vtable for this main loop.

There is no need to free this object as it is owned by the loop and is destroyed when the loop is freed.

Talking to PA directly with C requires fetching this pointer explicitly via this function. This is actually unnecessary through this binding. The pointer is retrieved automatically upon Mainloop creation, stored internally, and automatically obtained from it by functions that need it.

source

pub fn in_thread(&self) -> bool

Checks whether or not we are in the event loop thread (returns true if so).

source

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

Sets the name of the thread.

Trait Implementations§

source§

impl Mainloop for Mainloop

§

type MI = MainloopInner<pa_threaded_mainloop>

Inner mainloop type.
source§

fn inner(&self) -> Rc<MainloopInner<MainloopInternal>>

Get inner mainloop.
source§

fn new_io_event( &mut self, fd: i32, events: IoEventFlagSet, callback: Box<dyn FnMut(IoEventRef<Self::MI>, i32, IoEventFlagSet) + 'static> ) -> Option<IoEvent<Self::MI>>

Creates a new IO event. Read more
source§

fn new_timer_event( &mut self, tv: &UnixTs, callback: Box<dyn FnMut(TimeEventRef<Self::MI>) + 'static> ) -> Option<TimeEvent<Self::MI>>

Creates a new timer event. Read more
source§

fn new_timer_event_rt( &mut self, t: MonotonicTs, callback: Box<dyn FnMut(TimeEventRef<Self::MI>) + 'static> ) -> Option<TimeEvent<Self::MI>>

Creates a new monotonic-based timer event. Read more
source§

fn new_deferred_event( &mut self, callback: Box<dyn FnMut(DeferEventRef<Self::MI>) + 'static> ) -> Option<DeferEvent<Self::MI>>

Creates a new deferred event. Read more
source§

fn once_event(&mut self, callback: Box<dyn FnMut() + 'static>)

Runs the specified callback once from the main loop using an anonymous defer event. Read more
source§

fn quit(&mut self, retval: Retval)

Calls quit
source§

impl MainloopSignals for Mainloop

source§

fn init_signals(&mut self) -> Result<(), PAErr>

Initializes the UNIX signal subsystem and bind it to the specified main loop.
source§

fn signals_done(&self)

Cleans up the signal subsystem.

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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 Twhere 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 Twhere 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.