[][src]Trait calloop::EventSource

pub trait EventSource {
    type Event;
    type Metadata;
    type Ret;
    fn process_events<F>(
        &mut self,
        readiness: Readiness,
        token: Token,
        callback: F
    ) -> Result<()>
    where
        F: FnMut(Self::Event, &mut Self::Metadata) -> Self::Ret
;
fn register(&mut self, poll: &mut Poll, token: Token) -> Result<()>;
fn reregister(&mut self, poll: &mut Poll, token: Token) -> Result<()>;
fn unregister(&mut self, poll: &mut Poll) -> Result<()>; }

Trait representing an event source

This is the trait you need to implement if you wish to create your own calloop-compatible event sources.

The 3 type parameter define the type of closure the user will need to provide to process events for your event source.

The process_events method will be called when one of the FD you registered is ready, with the associated readiness and token.

The last 3 methods are plumbing to let your source register itself with the polling system. See their documentation for details.

Associated Types

type Event

The type of events generated by your source.

type Metadata

Some metadata of your event source

This is typically useful if your source contains some internal state that the user may need to interact with when processing events. The user callback will receive a &mut Metadata reference.

Just set to () if not needed.

type Ret

The return type of the user callback

If the user needs to return some value back to your event source once its processing is finshed (to indicate success or failure for example), you can specify it using this type.

Just set to () if not needed.

Loading content...

Required methods

fn process_events<F>(
    &mut self,
    readiness: Readiness,
    token: Token,
    callback: F
) -> Result<()> where
    F: FnMut(Self::Event, &mut Self::Metadata) -> Self::Ret

Process any relevant events

This method will be called every time one of the FD you registered becomes ready, including the readiness details and the associated token.

Your event source will then do some processing of the file descriptor(s) to generate events, and call the provided callback for each one of them.

You should ensure you drained the file descriptors of their events, especially if using edge-triggered mode.

fn register(&mut self, poll: &mut Poll, token: Token) -> Result<()>

Register yourself to this poll instance

You should register all your relevant file descriptors to the provided Poll using its Poll::register method.

If you need to register more than one file descriptor, you can change the sub_id field of the Token to differentiate between them.

fn reregister(&mut self, poll: &mut Poll, token: Token) -> Result<()>

Re-register your file descriptors

Your should update the registration of all your relevant file descriptor to the provided Poll using its Poll::reregister, if necessary.

fn unregister(&mut self, poll: &mut Poll) -> Result<()>

Unregister your file descriptors

You should unregister all your file descriptors from this Poll using its Poll::unregister method.

Loading content...

Implementors

impl EventSource for PingSource[src]

type Event = ()

type Metadata = ()

type Ret = ()

impl EventSource for Signals[src]

type Event = Event

type Metadata = ()

type Ret = ()

impl<F: AsRawFd> EventSource for Generic<F>[src]

type Event = Readiness

type Metadata = F

type Ret = Result<()>

impl<T: 'static> EventSource for Channel<T>[src]

type Event = Event<T>

type Metadata = ()

type Ret = ()

impl<T: 'static> EventSource for Timer<T>[src]

type Event = T

type Metadata = TimerHandle<T>

type Ret = ()

Loading content...