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
impl MainLoop
Sourcepub fn new(props: &Properties) -> Option<MainLoop>
pub fn new(props: &Properties) -> Option<MainLoop>
Create a new main loop.
Sourcepub fn run(&self)
pub fn run(&self)
Run the main loop. This takes over executation of the current thread until MainLoop::quit is invoked.
Sourcepub fn add_listener(&self, events: MainLoopEvents) -> HookId
pub fn add_listener(&self, events: MainLoopEvents) -> HookId
Add a listener for main loop events.
Sourcepub fn remove_listener(&self, hook_id: HookId)
pub fn remove_listener(&self, hook_id: HookId)
Remove a set of event listeners.
Sourcepub fn iterate(&self, timeout: Option<Duration>) -> Result<i32>
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.
Sourcepub fn lock(&self) -> Result<()>
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.
Sourcepub fn get_time(&self, timeout: Duration) -> Result<timespec>
pub fn get_time(&self, timeout: Duration) -> Result<timespec>
Get the time corresponding to the specified timeout, which can be used with MainLoop::wait.
Sourcepub fn wait(&self, abstime: ×pec) -> Result<()>
pub fn wait(&self, abstime: ×pec) -> Result<()>
Wait until the specified time or until signalled.
Sourcepub fn signal(&self, wait_for_accept: bool) -> Result<()>
pub fn signal(&self, wait_for_accept: bool) -> Result<()>
Signal any threads waiting with MainLoop::wait to wake up.
Sourcepub fn accept(&self) -> Result<()>
pub fn accept(&self) -> Result<()>
Acknowledge a MainLoop::signal with wait_for_accept: true, allowing that thread to
proceed.
Sourcepub fn add_io(
&self,
fd: RawFd,
mask: Io,
close: bool,
func: Box<SourceIoFn>,
) -> Option<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.
Sourcepub fn update_io(&self, source: &mut Source, mask: Io) -> Result<i32>
pub fn update_io(&self, source: &mut Source, mask: Io) -> Result<i32>
Update the set of events of interest (given by mask).
Sourcepub fn add_idle(&self, enabled: bool, func: Box<SourceIdleFn>) -> Option<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).
Sourcepub fn enable_idle(&self, source: &mut Source, enabled: bool) -> Result<i32>
pub fn enable_idle(&self, source: &mut Source, enabled: bool) -> Result<i32>
Enable or disable an idle event source.
Sourcepub fn add_event(&self, func: Box<SourceEventFn>) -> Option<Source>
pub fn add_event(&self, func: Box<SourceEventFn>) -> Option<Source>
Add a source which can be triggered using Self::signal_event.
Sourcepub fn signal_event(&self, source: &mut Source) -> Result<i32>
pub fn signal_event(&self, source: &mut Source) -> Result<i32>
Signal a source added with Self::add_event.
Sourcepub fn update_timer(
&self,
source: &mut Source,
value: ×pec,
interval: Option<×pec>,
absolute: bool,
) -> Result<i32>
pub fn update_timer( &self, source: &mut Source, value: ×pec, interval: Option<×pec>, absolute: bool, ) -> Result<i32>
Update the timer interval of a timer source.
Sourcepub fn add_signal(
&self,
signal_number: i32,
func: Box<SourceSignalFn>,
) -> Option<Source>
pub fn add_signal( &self, signal_number: i32, func: Box<SourceSignalFn>, ) -> Option<Source>
Add a source triggered by UNIX signals.
Sourcepub fn destroy_source(&self, source: Source)
pub fn destroy_source(&self, source: Source)
Remove and destroy an event source.
Trait Implementations§
Source§impl Refcounted for MainLoop
impl Refcounted for MainLoop
Source§type WeakRef = WeakMainLoop
type WeakRef = WeakMainLoop
Source§fn upgrade(this: &Self::WeakRef) -> Option<Self>
fn upgrade(this: &Self::WeakRef) -> Option<Self>
Some continaing the value. If the underlying object’s strong reference
count dropped to zero, and was thus freed, this returns None.