Struct devices::utils::event_loop::EventLoop
source · pub struct EventLoop {
fail_handle: Option<Arc<dyn FailHandle>>,
poll_ctx: Arc<WaitContext<Descriptor>>,
handlers: Arc<Mutex<BTreeMap<Descriptor, Weak<dyn EventHandler>>>>,
stop_evt: Event,
}
Expand description
EventLoop is an event loop blocked on a set of fds. When a monitered events is triggered, event loop will invoke the mapped handler.
Fields§
§fail_handle: Option<Arc<dyn FailHandle>>
§poll_ctx: Arc<WaitContext<Descriptor>>
§handlers: Arc<Mutex<BTreeMap<Descriptor, Weak<dyn EventHandler>>>>
§stop_evt: Event
Implementations§
source§impl EventLoop
impl EventLoop
sourcepub fn start(
name: String,
fail_handle: Option<Arc<dyn FailHandle>>
) -> Result<(EventLoop, JoinHandle<()>), Error>
pub fn start( name: String, fail_handle: Option<Arc<dyn FailHandle>> ) -> Result<(EventLoop, JoinHandle<()>), Error>
Start an event loop. An optional fail handle could be passed to the event loop.
sourcepub fn add_event(
&self,
descriptor: &dyn AsRawDescriptor,
event_type: EventType,
handler: Weak<dyn EventHandler>
) -> Result<(), Error>
pub fn add_event( &self, descriptor: &dyn AsRawDescriptor, event_type: EventType, handler: Weak<dyn EventHandler> ) -> Result<(), Error>
Add a new event to event loop. The event handler will be invoked when event
happens on
descriptor
.
If the same descriptor
is added multiple times, the old handler will be replaced.
EventLoop will not keep handler
alive, if handler is dropped when event
is triggered,
the event will be removed.
sourcepub fn remove_event_for_descriptor(
&self,
descriptor: &dyn AsRawDescriptor
) -> Result<(), Error>
pub fn remove_event_for_descriptor( &self, descriptor: &dyn AsRawDescriptor ) -> Result<(), Error>
Removes event for this descriptor
. This function is safe to call even when the
descriptor
is not actively being polled because it’s been paused.
EventLoop does not guarantee all events for descriptor
is handled.
sourcepub fn pause_event_for_descriptor(
&self,
descriptor: &dyn AsRawDescriptor
) -> Result<(), Error>
pub fn pause_event_for_descriptor( &self, descriptor: &dyn AsRawDescriptor ) -> Result<(), Error>
Pauses polling on the given descriptor
. It keeps a reference to the descriptor
and its
handler so it can be resumed by calling resume_event_for_descriptor()
.
sourcepub fn resume_event_for_descriptor(
&self,
descriptor: &dyn AsRawDescriptor,
event_type: EventType
) -> Result<(), Error>
pub fn resume_event_for_descriptor( &self, descriptor: &dyn AsRawDescriptor, event_type: EventType ) -> Result<(), Error>
Resumes polling on the given descriptor
with the previously-provided handler. If
descriptor
was not paused beforehand, this function does nothing. If descriptor
does
not exist in the event loop, it returns an error.
event_type
does not need to match the previously registered event type.
Auto Trait Implementations§
impl !RefUnwindSafe for EventLoop
impl Send for EventLoop
impl Sync for EventLoop
impl Unpin for EventLoop
impl !UnwindSafe for EventLoop
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.