]>
code.delx.au - pulseaudio/blob - src/tests/mainloop-test.c
4 This file is part of PulseAudio.
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.
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.
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
31 #include <pulse/timeval.h>
33 #include <pulsecore/core-util.h>
34 #include <pulsecore/gccmacro.h>
39 #include <pulse/glib-mainloop.h>
41 static GMainLoop
* glib_main_loop
= NULL
;
43 #else /* GLIB_MAIN_LOOP */
44 #include <pulse/mainloop.h>
45 #endif /* GLIB_MAIN_LOOP */
47 static pa_defer_event
*de
;
49 static void iocb(pa_mainloop_api
*a
, pa_io_event
*e
, int fd
, pa_io_event_flags_t f
, void *userdata
) {
51 read(fd
, &c
, sizeof(c
));
52 fprintf(stderr
, "IO EVENT: %c\n", c
< 32 ? '.' : c
);
53 a
->defer_enable(de
, 1);
56 static void dcb(pa_mainloop_api
*a
, pa_defer_event
*e
, void *userdata
) {
57 fprintf(stderr
, "DEFER EVENT\n");
58 a
->defer_enable(e
, 0);
61 static void tcb(pa_mainloop_api
*a
, pa_time_event
*e
, const struct timeval
*tv
, void *userdata
) {
62 fprintf(stderr
, "TIME EVENT\n");
64 #if defined(GLIB_MAIN_LOOP)
65 g_main_loop_quit(glib_main_loop
);
71 int main(PA_GCC_UNUSED
int argc
, PA_GCC_UNUSED
char *argv
[]) {
80 glib_main_loop
= g_main_loop_new(NULL
, FALSE
);
81 assert(glib_main_loop
);
83 g
= pa_glib_mainloop_new(NULL
);
86 a
= pa_glib_mainloop_get_api(g
);
88 #else /* GLIB_MAIN_LOOP */
91 m
= pa_mainloop_new();
94 a
= pa_mainloop_get_api(m
);
96 #endif /* GLIB_MAIN_LOOP */
98 ioe
= a
->io_new(a
, 0, PA_IO_EVENT_INPUT
, iocb
, NULL
);
101 de
= a
->defer_new(a
, dcb
, NULL
);
104 pa_gettimeofday(&tv
);
106 te
= a
->time_new(a
, &tv
, tcb
, NULL
);
108 #if defined(GLIB_MAIN_LOOP)
109 g_main_loop_run(glib_main_loop
);
111 pa_mainloop_run(m
, NULL
);
118 #ifdef GLIB_MAIN_LOOP
119 pa_glib_mainloop_free(g
);
120 g_main_loop_unref(glib_main_loop
);