]>
code.delx.au - pulseaudio/blob - polyp/glib-test.c
99196c4a68acb5527e91bbbbb8229fd5346bea7c
6 /*#define GLIB_MAIN_LOOP*/
10 #include "glib-mainloop.h"
11 static GMainLoop
* glib_main_loop
= NULL
;
16 static void iocb(struct pa_mainloop_api
*a
, struct pa_io_event
*e
, int fd
, enum pa_io_event_flags f
, void *userdata
) {
18 read(fd
, &c
, sizeof(c
));
19 fprintf(stderr
, "IO EVENT: %c\n", c
< 32 ? '.' : c
);
22 static void dcb(struct pa_mainloop_api
*a
, struct pa_defer_event
*e
, void *userdata
) {
23 fprintf(stderr
, "DEFER EVENT\n");
24 a
->defer_enable(e
, 0);
27 static void tcb(struct pa_mainloop_api
*a
, struct pa_time_event
*e
, const struct timeval
*tv
, void *userdata
) {
28 fprintf(stderr
, "TIME EVENT\n");
31 g_main_loop_quit(glib_main_loop
);
37 int main(int argc
, char *argv
[]) {
38 struct pa_mainloop_api
*a
;
39 struct pa_io_event
*ioe
;
40 struct pa_defer_event
*de
;
41 struct pa_time_event
*te
;
45 struct pa_glib_mainloop
*g
;
46 glib_main_loop
= g_main_loop_new(NULL
, FALSE
);
47 assert(glib_main_loop
);
49 g
= pa_glib_mainloop_new(NULL
);
52 a
= pa_glib_mainloop_get_api(g
);
55 struct pa_mainloop
*m
;
57 m
= pa_mainloop_new();
60 a
= pa_mainloop_get_api(m
);
64 ioe
= a
->io_new(a
, 0, PA_IO_EVENT_INPUT
, iocb
, NULL
);
67 de
= a
->defer_new(a
, dcb
, NULL
);
70 gettimeofday(&tv
, NULL
);
72 te
= a
->time_new(a
, &tv
, tcb
, NULL
);
75 g_main_loop_run(glib_main_loop
);
77 pa_mainloop_run(m
, NULL
);
85 pa_glib_mainloop_free(g
);
86 g_main_loop_unref(glib_main_loop
);