]> code.delx.au - pulseaudio/blob - src/pulsecore/rtpoll.h
add new realtime event loop abstraction which precise time keeping by using hrtimers...
[pulseaudio] / src / pulsecore / rtpoll.h
1 #ifndef foopulsertpollhfoo
2 #define foopulsertpollhfoo
3
4 /* $Id$ */
5
6 /***
7 This file is part of PulseAudio.
8
9 Copyright 2004-2006 Lennart Poettering
10
11 PulseAudio is free software; you can redistribute it and/or modify
12 it under the terms of the GNU Lesser General Public License as
13 published by the Free Software Foundation; either version 2.1 of the
14 License, or (at your option) any later version.
15
16 PulseAudio is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 Lesser General Public License for more details.
20
21 You should have received a copy of the GNU Lesser General Public
22 License along with PulseAudio; if not, write to the Free Software
23 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
24 USA.
25 ***/
26
27 #include <poll.h>
28 #include <sys/types.h>
29
30 #include <pulse/sample.h>
31
32 /* An implementation of a "real-time" poll loop. Basically, this is
33 * yet another wrapper around poll(). However it has certain
34 * advantages over pa_mainloop and suchlike:
35 *
36 * 1) It uses timer_create() and POSIX real time signals to guarantee
37 * optimal high-resolution timing. Starting with Linux 2.6.21 hrtimers
38 * are available, and since right now only nanosleep() and the POSIX
39 * clock and timer interfaces have been ported to hrtimers (and not
40 * ppoll/pselect!) we have to combine ppoll() with timer_create(). The
41 * fact that POSIX timers and POSIX rt signals are used internally is
42 * completely hidden.
43 *
44 * 2) It allows raw access to the pollfd data to users
45 *
46 * 3) It allows arbitrary functions to be run before entering the
47 * actual poll() and after it.
48 *
49 * Only a single interval timer is supported..*/
50
51 typedef struct pa_rtpoll pa_rtpoll;
52 typedef struct pa_rtpoll_item pa_rtpoll_item;
53
54 pa_rtpoll *pa_rtpoll_new(void);
55 void pa_rtpoll_free(pa_rtpoll *p);
56
57 void pa_rtpoll_install(pa_rtpoll *p);
58
59 int pa_rtpoll_run(pa_rtpoll *f);
60 void pa_rtpoll_set_itimer(pa_rtpoll *p, pa_usec_t usec);
61
62 pa_rtpoll_item *pa_rtpoll_item_new(pa_rtpoll *p, unsigned n_fds);
63 void pa_rtpoll_item_free(pa_rtpoll_item *i);
64
65 struct pollfd *pa_rtpoll_item_get_pollfd(pa_rtpoll_item *i, unsigned *n_fds);
66
67 void pa_rtpoll_item_set_before_callback(pa_rtpoll_item *i, int (*before_cb)(pa_rtpoll_item *i));
68 void pa_rtpoll_item_set_after_callback(pa_rtpoll_item *i, void (*after_cb)(pa_rtpoll_item *i));
69 void pa_rtpoll_item_set_userdata(pa_rtpoll_item *i, void *userdata);
70
71 #endif