]> code.delx.au - pulseaudio/blob - src/tests/rtpoll-test.c
add test program for pa_rtpoll
[pulseaudio] / src / tests / rtpoll-test.c
1 /* $Id: thread-test.c 1621 2007-08-10 22:00:22Z lennart $ */
2
3 /***
4 This file is part of PulseAudio.
5
6 PulseAudio is free software; you can redistribute it and/or modify
7 it under the terms of the GNU Lesser General Public License as published
8 by the Free Software Foundation; either version 2 of the License,
9 or (at your option) any later version.
10
11 PulseAudio is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public License
17 along with PulseAudio; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19 USA.
20 ***/
21
22 #ifdef HAVE_CONFIG_H
23 #include <config.h>
24 #endif
25
26 #include <signal.h>
27
28 #include <pulsecore/log.h>
29 #include <pulsecore/rtpoll.h>
30 #include <pulsecore/rtsig.h>
31
32 static int before(pa_rtpoll_item *i) {
33 pa_log("before");
34 return 0;
35 }
36
37 static void after(pa_rtpoll_item *i) {
38 pa_log("after");
39 }
40
41 int main(int argc, char *argv[]) {
42 pa_rtpoll *p;
43 pa_rtpoll_item *i;
44 struct pollfd *pollfd;
45
46 pa_rtsig_configure(SIGRTMIN+10, SIGRTMAX);
47
48 p = pa_rtpoll_new();
49
50 i = pa_rtpoll_item_new(p, 1);
51 pa_rtpoll_item_set_before_callback(i, before);
52 pa_rtpoll_item_set_after_callback(i, after);
53
54 pollfd = pa_rtpoll_item_get_pollfd(i, NULL);
55 pollfd->fd = 0;
56 pollfd->events = POLLIN;
57
58 pa_rtpoll_install(p);
59 pa_rtpoll_set_itimer(p, 10000000); /* 10 s */
60
61 pa_rtpoll_run(p);
62
63 pa_rtpoll_item_free(i);
64
65 i = pa_rtpoll_item_new(p, 1);
66 pa_rtpoll_item_set_before_callback(i, before);
67 pa_rtpoll_item_set_after_callback(i, after);
68
69 pollfd = pa_rtpoll_item_get_pollfd(i, NULL);
70 pollfd->fd = 0;
71 pollfd->events = POLLIN;
72
73 pa_rtpoll_run(p);
74
75 pa_rtpoll_item_free(i);
76
77 pa_rtpoll_free(p);
78
79 return 0;
80 }