]>
code.delx.au - pulseaudio/blob - src/tests/mainloop-test.c
2 This file is part of PulseAudio.
4 PulseAudio is free software; you can redistribute it and/or modify
5 it under the terms of the GNU Lesser General Public License as published
6 by the Free Software Foundation; either version 2 of the License,
7 or (at your option) any later version.
9 PulseAudio is distributed in the hope that it will be useful, but
10 WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public License
15 along with PulseAudio; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
29 #include <pulse/timeval.h>
30 #include <pulse/gccmacro.h>
32 #include <pulsecore/core-util.h>
37 #include <pulse/glib-mainloop.h>
39 static GMainLoop
* glib_main_loop
= NULL
;
41 #else /* GLIB_MAIN_LOOP */
42 #include <pulse/mainloop.h>
43 #endif /* GLIB_MAIN_LOOP */
45 static pa_defer_event
*de
;
47 static void iocb(pa_mainloop_api
*a
, pa_io_event
*e
, int fd
, pa_io_event_flags_t f
, void *userdata
) {
49 read(fd
, &c
, sizeof(c
));
50 fprintf(stderr
, "IO EVENT: %c\n", c
< 32 ? '.' : c
);
51 a
->defer_enable(de
, 1);
54 static void dcb(pa_mainloop_api
*a
, pa_defer_event
*e
, void *userdata
) {
55 fprintf(stderr
, "DEFER EVENT\n");
56 a
->defer_enable(e
, 0);
59 static void tcb(pa_mainloop_api
*a
, pa_time_event
*e
, const struct timeval
*tv
, void *userdata
) {
60 fprintf(stderr
, "TIME EVENT\n");
62 #if defined(GLIB_MAIN_LOOP)
63 g_main_loop_quit(glib_main_loop
);
69 int main(PA_GCC_UNUSED
int argc
, PA_GCC_UNUSED
char *argv
[]) {
78 glib_main_loop
= g_main_loop_new(NULL
, FALSE
);
79 assert(glib_main_loop
);
81 g
= pa_glib_mainloop_new(NULL
);
84 a
= pa_glib_mainloop_get_api(g
);
86 #else /* GLIB_MAIN_LOOP */
89 m
= pa_mainloop_new();
92 a
= pa_mainloop_get_api(m
);
94 #endif /* GLIB_MAIN_LOOP */
96 ioe
= a
->io_new(a
, 0, PA_IO_EVENT_INPUT
, iocb
, NULL
);
99 de
= a
->defer_new(a
, dcb
, NULL
);
102 pa_gettimeofday(&tv
);
104 te
= a
->time_new(a
, &tv
, tcb
, NULL
);
106 #if defined(GLIB_MAIN_LOOP)
107 g_main_loop_run(glib_main_loop
);
109 pa_mainloop_run(m
, NULL
);
116 #ifdef GLIB_MAIN_LOOP
117 pa_glib_mainloop_free(g
);
118 g_main_loop_unref(glib_main_loop
);