]>
code.delx.au - pulseaudio/blob - polyp/mainloop-test.c
92b83c145b45af623e8fa40f7310e68b1c68e41f
4 This file is part of polypaudio.
6 polypaudio is free software; you can redistribute it and/or modify
7 it under the terms of the GNU 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 polypaudio 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 General Public License
17 along with polypaudio; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
34 #include "glib-mainloop.h"
35 static GMainLoop
* glib_main_loop
= NULL
;
37 #if GLIB_MAJOR_VERSION >= 2
44 #else /* GLIB_MAIN_LOOP */
46 #endif /* GLIB_MAIN_LOOP */
48 static struct pa_defer_event
*de
;
50 static void iocb(struct pa_mainloop_api
*a
, struct pa_io_event
*e
, int fd
, enum pa_io_event_flags f
, void *userdata
) {
52 read(fd
, &c
, sizeof(c
));
53 fprintf(stderr
, "IO EVENT: %c\n", c
< 32 ? '.' : c
);
54 a
->defer_enable(de
, 1);
57 static void dcb(struct pa_mainloop_api
*a
, struct pa_defer_event
*e
, void *userdata
) {
58 fprintf(stderr
, "DEFER EVENT\n");
59 a
->defer_enable(e
, 0);
62 static void tcb(struct pa_mainloop_api
*a
, struct pa_time_event
*e
, const struct timeval
*tv
, void *userdata
) {
63 fprintf(stderr
, "TIME EVENT\n");
65 #if defined(GLIB_MAIN_LOOP) && defined(GLIB20)
66 g_main_loop_quit(glib_main_loop
);
67 #elif defined(GLIB_MAIN_LOOP)
68 g_main_quit(glib_main_loop
);
74 int main(int argc
, char *argv
[]) {
75 struct pa_mainloop_api
*a
;
76 struct pa_io_event
*ioe
;
77 struct pa_time_event
*te
;
81 struct pa_glib_mainloop
*g
;
84 glib_main_loop
= g_main_loop_new(NULL
, FALSE
);
85 assert(glib_main_loop
);
87 g
= pa_glib_mainloop_new(NULL
);
89 glib_main_loop
= g_main_new(FALSE
);
90 assert(glib_main_loop
);
92 g
= pa_glib_mainloop_new();
96 a
= pa_glib_mainloop_get_api(g
);
98 #else /* GLIB_MAIN_LOOP */
99 struct pa_mainloop
*m
;
101 m
= pa_mainloop_new();
104 a
= pa_mainloop_get_api(m
);
106 #endif /* GLIB_MAIN_LOOP */
108 ioe
= a
->io_new(a
, 0, PA_IO_EVENT_INPUT
, iocb
, NULL
);
111 de
= a
->defer_new(a
, dcb
, NULL
);
114 gettimeofday(&tv
, NULL
);
116 te
= a
->time_new(a
, &tv
, tcb
, NULL
);
118 #if defined(GLIB_MAIN_LOOP) && defined(GLIB20)
119 g_main_loop_run(glib_main_loop
);
120 #elif defined(GLIB_MAIN_LOOP)
121 g_main_run(glib_main_loop
);
123 pa_mainloop_run(m
, NULL
);
130 #ifdef GLIB_MAIN_LOOP
131 pa_glib_mainloop_free(g
);
133 g_main_loop_unref(glib_main_loop
);
135 g_main_destroy(glib_main_loop
);