class Fl_Poll
#include <FL/Fl_Poll.H>
This object provides the underlying time and event mechanism for
FL. It is mostly a wrapper for the Unix poll() or select() call. It
does not itself call X, although the X file descriptor is usually
installed as one of the fd's to pay attention to. Fl_Poll may be used
by itself without including any other code from FL. Fl_Poll is not
provided on non-Unix implementations of FL.
extern Fl_Poll fl_poll;
There is exactly one static instance of this object. You can
create more, but you must call clear() to initialize them. FL always
refers to the static one.
Time is a floating-point number of seconds.
The void* argument is arbitrary user data that is passed to the
callbacks.
There is a maximum of 8 of each type of callback. Adding more will
silently delete some older callback. If you need more you must
recompile the source.
Callbacks
void fl_poll.clear();
Removes all the callbacks. You should also use this to initialize
your own Fl_Poll.
void fl_poll.add(int fd, short events, void (*cb)(int,void*), void* v=0);
Add file descriptor fd to listen to. events is any
combination of POLLIN, POLLOUT
, and POLLERR
(if your system uses the poll() call you may be able to use other
symbols defined in <poll.h>. The most common value is POLLIN. When
the fd becomes ready the callback is done. The callback is passed
fd and the arbitrary void* argument.
void fl_poll.remove(int fd);
Remove all the callbacks for fd, if any.
void fl_poll.add_timeout(float t,void
(*cb)(void*),void* v=0);
Adds a callback for when a certain amount of time passes. This is a
one-shot callback. To make it repeat the callback must add_timeout
again. The time is actually measured from just after the previous
poll() returned, which is correct for making things happen a certain
amount of time after a user input.
void fl_poll.remove_timeout(void (*cb)(void*), void* v=0);
Delete a timeout callback. Both the callback and the argument must
match. If the callback does not exist or has already happened then
this does nothing.
void fl_poll.add_test(int (*test)(void*), void (*cb)(void*), void* v=0);
Adds a test that is done before any system calls. If the test
function returns non-zero then the callback function is done.
This is often necessary if you are using a library that insists on
reading and buffering input from a device but not acting on it. For
instance glFlush() apparently reads all pending X events, thus causing
the file descriptor to be non-ready, yet there are events that need
actions that can be detected with XQueued(). Such libraries are (imho)
broken because they waste time doing poll() that the caller will
need to do again anyway.
void fl_poll.remove_test(int (*test)(void*), void
(*cb)(void*), void* v=0);
Delete a test and callback. The test, callback, and argument must all
match. This does nothing if the test does not exist.
void fl_poll.set_idle(void (*cb)());
If the idle callback is set it will be called continuously (actually
it is called once each time wait() is called and then wait returns
immediately). This can be used for background processing. This
will absorb all your machine's time! To turn off the idle
processing use fl_poll.set_idle(0). There is only one idle callback,
if you want several you will have to set up your own queue mechanisim
and make this idle callback call that.
Interaction
int fl_poll.wait();
Waits until some callback needs to be called, then does that callback
(and possibly others that become ready at the same time) and then
returns. The return value is whatever poll() returns.
float fl_poll.wait(float time);
Waits until either some callback needs to be called or the given time
passes. It then does the callback, and returns the time remaining
(this may be 0 or negative depending on how long the system call
takes). The time is measured from the last time poll() returned or
from the last reset() call.
float fl_poll.reset();
Reset the clock that wait(time) or timeouts are measured from. The
returned value is the amount of time elapsed before reset() was
called.
int fl_poll.check();
Similar to wait(0), but because this does not calculate the remaining
time it may be faster on some systems. The return value is whatever
poll() returns.
int fl_poll.ready();
If this returns non-zero then there is a callback ready to be called
immediately, and thus wait() will return quickly. Unlike check() this
will not call any callbacks, although it may call the test functions.
void fl_poll.run();
This is an inline wrapper for "for (;;) wait()".
(back to contents)