eloop: move callback declarations into correct order

Use same order as the function definitions.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
fbdev: add few implementation hints

fbdev is still not ready but we add some hints so implmenting it later
will be easier.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
eloop: allow enabling/disabling fd sources

We sometimes want to be able to enable/disable an fd-source without
allocating memory (for a short period, for instance). Therefore, introduce
two new functions to enable and disable an fd source.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
eloop: correctly forward error codes

Instead of ignoring epoll errors we should forward them to the caller. The
caller can then still decide to ignore errors.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
eloop: allow enabling/disabling timer sources

Similar to the fd_enable/disable functions we now also allow the same
operations on timer sources.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
eloop: allow enabling/disabling counter sources

Similar to fd and timer sources we now also support disabling counter
sources via similar functions.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
eloop: forward EOF and I/O errors of counters to caller

Instead of silently dropping read() errors we now disable the counter and
call the user-supplied callback with 0 as argument so they can react on
errors.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
eloop: forward timer HUP and I/O errors to caller

Similar to counter callbacks we now call timer callbacks with 0 as
argument on errors and disable the timer source.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
eloop: fix not returning new counter object

We forgot to actually store the pointer to the new counter object in the
\out variable. Fix this now.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
eloop: use counter source for idle events

epoll has the great feature that the poll object is an fd itself. However,
if we want to use idle-sources, we couldn't add them to the epoll set.
Now, we use a counter source for all idle sources so if we add a single
event-loop as source to another event loop, the idle sources will get
dispatched correctly. Furthermore, we now longer block after handling idle
sources but instead now correctly run idle sources every next round
without sleeping for fd events in between.
Unregister idle sources to avoid hogging the CPU.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
eloop: add more comments

Add comments describing each source and the nesting features.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
eloop: dynamically reallocate dispatch cache

We do not maintain event caches so we must make sure that every event
source gets dispatched. If we call epoll_wait() and our buffer gets
filled everytime, then there might be an event source that does not get
dispatched because it is always above the buffer range. Therefore, we now
dynamically increase the cache size when it once gets filled up.

This gets critical if we handle thousands of clients or fds, however, our
use case is limited to some system resources and hence does not suffer
here.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
eloop: add initial gtk-doc comments

Add gtk-doc compatible comments to most of the functions in eloop.c.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>