]> code.delx.au - pulseaudio/blob - src/tests/asyncmsgq-test.c
94bfcea1e50a7bacc0f3072ef032f955b941a925
[pulseaudio] / src / tests / asyncmsgq-test.c
1 /***
2 This file is part of PulseAudio.
3
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.1 of the License,
7 or (at your option) any later version.
8
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.
13
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
17 USA.
18 ***/
19
20 #ifdef HAVE_CONFIG_H
21 #include <config.h>
22 #endif
23
24 #include <assert.h>
25 #include <stdlib.h>
26 #include <unistd.h>
27
28 #include <pulse/util.h>
29 #include <pulse/xmalloc.h>
30 #include <pulsecore/asyncmsgq.h>
31 #include <pulsecore/thread.h>
32 #include <pulsecore/log.h>
33 #include <pulsecore/core-util.h>
34 #include <pulsecore/macro.h>
35
36 enum {
37 OPERATION_A,
38 OPERATION_B,
39 OPERATION_C,
40 QUIT
41 };
42
43 static void the_thread(void *_q) {
44 pa_asyncmsgq *q = _q;
45 int quit = 0;
46
47 do {
48 int code = 0;
49
50 pa_assert_se(pa_asyncmsgq_get(q, NULL, &code, NULL, NULL, NULL, 1) == 0);
51
52 switch (code) {
53
54 case OPERATION_A:
55 printf("Operation A\n");
56 break;
57
58 case OPERATION_B:
59 printf("Operation B\n");
60 break;
61
62 case OPERATION_C:
63 printf("Operation C\n");
64 break;
65
66 case QUIT:
67 printf("quit\n");
68 quit = 1;
69 break;
70 }
71
72 pa_asyncmsgq_done(q, 0);
73
74 } while (!quit);
75 }
76
77 int main(int argc, char *argv[]) {
78 pa_asyncmsgq *q;
79 pa_thread *t;
80
81 pa_assert_se(q = pa_asyncmsgq_new(0));
82
83 pa_assert_se(t = pa_thread_new("test", the_thread, q));
84
85 printf("Operation A post\n");
86 pa_asyncmsgq_post(q, NULL, OPERATION_A, NULL, 0, NULL, NULL);
87
88 pa_thread_yield();
89
90 printf("Operation B post\n");
91 pa_asyncmsgq_post(q, NULL, OPERATION_B, NULL, 0, NULL, NULL);
92
93 pa_thread_yield();
94
95 printf("Operation C send\n");
96 pa_asyncmsgq_send(q, NULL, OPERATION_C, NULL, 0, NULL);
97
98 pa_thread_yield();
99
100 printf("Quit post\n");
101 pa_asyncmsgq_post(q, NULL, QUIT, NULL, 0, NULL, NULL);
102
103 pa_thread_free(t);
104
105 pa_asyncmsgq_unref(q);
106
107 return 0;
108 }