Trait libpulse_binding::mainloop::api::Mainloop
source · pub trait Mainloop {
type MI: MainloopInnerType;
// Required method
fn inner(&self) -> Rc<Self::MI>;
// Provided methods
fn new_io_event(
&mut self,
fd: i32,
events: IoEventFlagSet,
callback: Box<dyn FnMut(IoEventRef<Self::MI>, i32, IoEventFlagSet) + 'static>
) -> Option<IoEvent<Self::MI>> { ... }
fn new_timer_event(
&mut self,
tv: &UnixTs,
callback: Box<dyn FnMut(TimeEventRef<Self::MI>) + 'static>
) -> Option<TimeEvent<Self::MI>> { ... }
fn new_timer_event_rt(
&mut self,
t: MonotonicTs,
callback: Box<dyn FnMut(TimeEventRef<Self::MI>) + 'static>
) -> Option<TimeEvent<Self::MI>> { ... }
fn new_deferred_event(
&mut self,
callback: Box<dyn FnMut(DeferEventRef<Self::MI>) + 'static>
) -> Option<DeferEvent<Self::MI>> { ... }
fn once_event(&mut self, callback: Box<dyn FnMut() + 'static>) { ... }
fn quit(&mut self, retval: Retval) { ... }
}
Expand description
Mainloop trait, to be implemented by the different types of mainloops.
Required Associated Types§
sourcetype MI: MainloopInnerType
type MI: MainloopInnerType
Inner mainloop type.
Required Methods§
Provided Methods§
sourcefn new_io_event(
&mut self,
fd: i32,
events: IoEventFlagSet,
callback: Box<dyn FnMut(IoEventRef<Self::MI>, i32, IoEventFlagSet) + 'static>
) -> Option<IoEvent<Self::MI>>
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.
Note: You must ensure that the returned event object lives for as long as you want its
event(s) to fire, as its Drop
implementation destroys the event source. I.e. if you create
a new event, but then immediately drop the object returned here, no event will fire!
The given callback must accept three parameters, an IoEventRef
object, a copy of the
given file descriptor, and an event flag set, indicating the event(s) that occurred. The
DeferEventRef
object gives you some opportunity to manage the event source from within
it’s callback execution.
sourcefn new_timer_event(
&mut self,
tv: &UnixTs,
callback: Box<dyn FnMut(TimeEventRef<Self::MI>) + 'static>
) -> Option<TimeEvent<Self::MI>>
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.
Note: You must ensure that the returned event object lives for as long as you want its
event(s) to fire, as its Drop
implementation destroys the event source. I.e. if you create
a new event, but then immediately drop the object returned here, no event will fire!
The callback must take a TimeEventRef
object, which gives you some opportunity to
manage the event source from within it’s callback execution.
Example event set to fire in five seconds time:
use libpulse_binding::time::{UnixTs, MicroSeconds};
let _t_event = mainloop.new_timer_event(
&(UnixTs::now() + MicroSeconds::from_secs(5).unwrap()),
Box::new(|_| { println!("Timer event fired!"); }));
sourcefn new_timer_event_rt(
&mut self,
t: MonotonicTs,
callback: Box<dyn FnMut(TimeEventRef<Self::MI>) + 'static>
) -> Option<TimeEvent<Self::MI>>
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.
Asserts that t
is not MicroSeconds::INVALID
.
This is an alternative to the new_timer_event
method, taking a monotonic based time value.
Note: You must ensure that the returned event object lives for as long as you want its
event(s) to fire, as its Drop
implementation destroys the event source. I.e. if you create
a new event, but then immediately drop the object returned here, no event will fire!
The callback must take a TimeEventRef
object, which gives you some opportunity to
manage the event source from within it’s callback execution.
Example event set to fire in five seconds time:
use libpulse_binding::time::{MonotonicTs, MicroSeconds};
let _t_event = mainloop.new_timer_event_rt(
MonotonicTs::now() + MicroSeconds::from_secs(5).unwrap(),
Box::new(|_| { println!("Timer event fired!"); }));
sourcefn new_deferred_event(
&mut self,
callback: Box<dyn FnMut(DeferEventRef<Self::MI>) + 'static>
) -> Option<DeferEvent<Self::MI>>
fn new_deferred_event( &mut self, callback: Box<dyn FnMut(DeferEventRef<Self::MI>) + 'static> ) -> Option<DeferEvent<Self::MI>>
Creates a new deferred event.
Note: You must ensure that the returned event object lives for as long as you want its
event(s) to fire, as its Drop
implementation destroys the event source. I.e. if you create
a new event, but then immediately drop the object returned here, no event will fire!
The callback must take a DeferEventRef
object, which gives you some opportunity to
manage the event source from within it’s callback execution.
sourcefn once_event(&mut self, callback: Box<dyn FnMut() + 'static>)
fn once_event(&mut self, callback: Box<dyn FnMut() + 'static>)
Runs the specified callback once from the main loop using an anonymous defer event.
If the mainloop runs in a different thread, you need to follow the mainloop implementation’s
rules regarding how to safely create defer events. In particular, if you’re using
mainloop::threaded
, you must lock the mainloop before
calling this function.