Initialize Tizen 2.3
[framework/multimedia/audio-session-manager.git] / mobile / test / asm_testsuite.c
1 #include <stdio.h>
2 #include <glib.h>
3 #include <stdlib.h>
4
5 #include <audio-session-manager.h>
6
7
8 GMainLoop *g_loop;
9 GThreadPool* g_pool;
10 gint asm_handle = -1;
11 gint event_type = ASM_EVENT_NONE;
12 gint asm_state = ASM_STATE_NONE;
13 ASM_resource_t g_resource = ASM_RESOURCE_NONE;
14 gboolean thread_run;
15
16 ASM_cb_result_t
17 asm_callback (int handle, ASM_event_sources_t event_src, ASM_sound_commands_t command, unsigned int sound_status, void* cb_data)
18 {
19         g_print ("\n[%s][%d] handle = %d, event src = %d, command = %d, sound_state = %d\n\n", __func__, __LINE__, handle ,event_src, command, sound_status);
20         return ASM_CB_RES_IGNORE;
21 }
22
23 void print_menu_main(void)
24 {
25         printf("========ASM Testsuite======\n");
26         printf(" r. Register ASM\n");
27         printf(" s. Set state\n");
28         printf(" u. Unregister ASM\n");
29         printf(" q. Quit\n");
30         printf("============================\n");
31         printf(">> ");
32 }
33
34 void menu_unregister(void)
35 {
36         gint errorcode = 0;
37         if(asm_handle == -1) {
38                 g_print("Register sound first..\n\n");
39                 return;
40         }
41         if( !ASM_unregister_sound(asm_handle, event_type, &errorcode) ) {
42                 g_print("Unregister sound failed 0x%X\n\n", errorcode);
43         } else {
44                 g_print("Unregister success..\n\n");
45                 asm_handle = -1;
46         }
47 }
48
49 void menu_register(void)
50 {
51         char key = 0;
52         int input = 0;
53         gint errorcode = 0;
54         gint pid = -1;
55         g_resource = ASM_RESOURCE_NONE;
56
57         while(1) {
58                 printf("==========select ASM event=============\n");
59                 printf(" 0. ASM_EVENT_SHARE_MMPLAYER \n");
60                 printf(" 1. ASM_EVENT_SHARE_MMCAMCORDER\n");
61                 printf(" 2. ASM_EVENT_SHARE_MMSOUND\n");
62                 printf(" 3. ASM_EVENT_SHARE_OPENAL\n");
63                 printf(" 4. ASM_EVENT_SHARE_AVSYSTEM\n");
64                 printf(" 5. ASM_EVENT_SHARE_FMRADIO\n");
65                 printf(" 6. ASM_EVENT_EXCLUSIVE_MMPLAYER\n");
66                 printf(" 7. ASM_EVENT_EXCLUSIVE_MMCAMCORDER\n");
67                 printf(" 8. ASM_EVENT_EXCLUSIVE_MMSOUND\n");
68                 printf(" 9. ASM_EVENT_EXCLUSIVE_OPENAL\n");
69                 printf(" a. ASM_EVENT_EXCLUSIVE_AVSYSTEM\n");
70                 printf(" b. ASM_EVENT_EXCLUSIVE_FMRADIO\n");
71                 printf(" c. ASM_EVENT_NOTIFY\n");
72                 printf(" d. ASM_EVENT_CALL\n");
73                 printf(" e. ASM_EVENT_EARJACK_UNPLUG\n");
74                 printf(" f. ASM_EVENT_ALARM\n");
75                 printf(" g. ASM_EVENT_VIDEOCALL\n");
76                 printf(" h. ASM_EVENT_MONITOR\n");
77                 printf(" i. ASM_EVENT_RICHCALL\n");
78                 printf(" j. ASM_EVENT_EMERGENCY\n");
79                 printf(" k. ASM_EVENT_EXCLUSIVE_RESOURCE\n");
80                 printf(" q. Back to main menu\n");
81                 printf("=======================================\n");
82                 printf(">> ");
83
84
85                 while( (input = getchar())!= '\n' && input != EOF) {
86                         key = (char)input;
87                 }
88                 switch (key) {
89                         case '0':
90                                 event_type = ASM_EVENT_SHARE_MMPLAYER;
91                                 break;
92                         case '1':
93                                 event_type = ASM_EVENT_SHARE_MMCAMCORDER;
94                                 g_resource = ASM_RESOURCE_CAMERA;
95                                 break;
96                         case '2':
97                                 event_type = ASM_EVENT_SHARE_MMSOUND;
98                                 break;
99                         case '3':
100                                 event_type = ASM_EVENT_SHARE_OPENAL;
101                                 break;
102                         case '4':
103                                 event_type = ASM_EVENT_SHARE_AVSYSTEM;
104                                 break;
105                         case '5':
106                                 event_type = ASM_EVENT_SHARE_FMRADIO;
107                                 break;
108                         case '6':
109                                 event_type = ASM_EVENT_EXCLUSIVE_MMPLAYER;
110                                 break;
111                         case '7':
112                                 event_type = ASM_EVENT_EXCLUSIVE_MMCAMCORDER;
113                                 g_resource = ASM_RESOURCE_CAMERA;
114                                 break;
115                         case '8':
116                                 event_type = ASM_EVENT_EXCLUSIVE_MMSOUND;
117                                 break;
118                         case '9':
119                                 event_type = ASM_EVENT_EXCLUSIVE_OPENAL;
120                                 break;
121                         case 'a':
122                                 event_type = ASM_EVENT_EXCLUSIVE_AVSYSTEM;
123                                 break;
124                         case 'b':
125                                 event_type = ASM_EVENT_EXCLUSIVE_FMRADIO;
126                                 break;
127                         case 'c':
128                                 event_type = ASM_EVENT_NOTIFY;
129                                 break;
130                         case 'd':
131                                 event_type = ASM_EVENT_CALL;
132                                 break;
133                         case 'e':
134                                 event_type = ASM_EVENT_EARJACK_UNPLUG;
135                                 break;
136                         case 'f':
137                                 event_type = ASM_EVENT_ALARM;
138                                 break;
139                         case 'g':
140                                 event_type = ASM_EVENT_VIDEOCALL;
141                                 g_resource = ASM_RESOURCE_CAMERA;
142                                 break;
143                         case 'h':
144                                 event_type = ASM_EVENT_MONITOR;
145                                 break;
146                         case 'i':
147                                 event_type = ASM_EVENT_RICH_CALL;
148                                 g_resource = ASM_RESOURCE_CAMERA;
149                                 break;
150                         case 'j':
151                                 event_type = ASM_EVENT_EMERGENCY;
152                                 break;
153                         case 'k':
154                                 event_type = ASM_EVENT_EXCLUSIVE_RESOURCE;
155                                 /* temporarily set it ASM_RESOURCE_CAMERA */
156                                 g_resource = ASM_RESOURCE_CAMERA;
157                                 break;
158                         case 'q':
159                                 return;
160                         default :
161                                 g_print("select event again...\n");
162                                 event_type = -1;
163                                 break;
164                 }
165                 if (event_type == -1) {
166                         continue;
167                 }
168                 if( ! ASM_register_sound(pid, &asm_handle, event_type, ASM_STATE_NONE, asm_callback, NULL, g_resource, &errorcode)) {
169                         g_print("ASM_register_sound() failed, error = %x\n\n", errorcode);
170                         break;
171                 } else {
172                         g_print("ASM_register_sound() success, ASM handle=%d, ASM_EVENT=%d, ASM_RESOURCE=%d, ASM_STATE_NONE.\n\n", asm_handle, event_type, g_resource);
173                         break;
174                 }
175         }
176 }
177
178 void menu_set_state(void)
179 {
180         int ret = 0;
181         char key = 0;
182         int input = 0;
183         while(1) {
184                 printf("==========ASM state==========\n");
185                 printf(" 0. ASM_STATE_IGNORE\n");
186                 printf(" 1. ASM_STATE_NONE\n");
187                 printf(" 2. ASM_STATE_PLAYING\n");
188                 printf(" 3. ASM_STATE_WAITING\n");
189                 printf(" 4. ASM_STATE_STOP\n");
190                 printf(" 5. ASM_STATE_PAUSE\n");
191                 printf(" 6. ASM_STATE_PAUSE_BY_APP\n");
192                 printf(" q. Back to main menu\n");
193                 printf("=============================\n");
194                 printf(">> ");
195                 while( (input = getchar())!= '\n' && input != EOF) {
196                         key = (char)input;
197                 }
198
199                 switch (key) {
200                         case '0':
201                                 asm_state = ASM_STATE_IGNORE;
202                                 break;
203                         case '1':
204                                 asm_state = ASM_STATE_NONE;
205                                 break;
206                         case '2':
207                                 asm_state = ASM_STATE_PLAYING;
208                                 break;
209                         case '3':
210                                 asm_state = ASM_STATE_WAITING;
211                                 break;
212                         case '4':
213                                 asm_state = ASM_STATE_STOP;
214                                 break;
215                         case '5':
216                                 asm_state = ASM_STATE_PAUSE;
217                                 break;
218                         case '6':
219                                 asm_state = ASM_STATE_PAUSE_BY_APP;
220                                 break;
221                         case 'q':
222                                 return;
223                         default :
224                                 g_print("select ASM state again...\n");
225                                 asm_state = 9;
226                 }
227                 if (asm_state == 9) {
228                         continue;
229                 }
230                 /* set ASM sound state */
231                 if( ! ASM_set_sound_state( asm_handle, event_type, asm_state, g_resource, &ret) ) {
232                         g_print("ASM_set_sound_state() failed, Set state to [%d] failed 0x%X\n\n", asm_state, ret);
233                         break;
234                 } else {
235                         g_print("ASM_set_sound_state() success, ASM handle=%d, ASM_EVENT=%d, ASM_RESOURCE=%d, ASM_STATE=%d\n\n", asm_handle, event_type, g_resource, asm_state);
236                         break;
237                 }
238         }
239 }
240
241 gpointer keythread(gpointer data)
242 {
243         int input = 0;
244         char key = 0;
245
246         while (thread_run) {
247                 print_menu_main();
248                 while( (input = getchar())!= '\n' && input != EOF) {
249                         key = (char)input;
250                 }
251
252                 switch (key) {
253                         case 'r':
254                                 menu_register();
255                                 break;
256                         case 's':
257                                 menu_set_state();
258                                 break;
259                         case 'u':
260                                 menu_unregister();
261                                 break;
262                         case 'q':
263                                 if(asm_handle != -1) {
264                                         menu_unregister();
265                                 }
266                                 g_main_loop_quit(g_loop);
267                                 break;
268                         default :
269                                 g_print("wrong input, select again...\n\n");
270                 } /* switch (key) */
271         } /* while () */
272         return NULL;
273 }
274
275 int main ()
276 {
277         g_thread_init (NULL);
278         thread_run = TRUE;
279
280         g_loop = g_main_loop_new (NULL, 0);
281         GThread * command_thread = g_thread_create (keythread, NULL, FALSE, NULL);
282         if (!command_thread) {
283                 g_print ("key thread creation failure\n");
284                 return 0;
285         }
286
287         g_main_loop_run (g_loop);
288         g_print ("loop finished !!\n");
289         thread_run = FALSE;
290         if (command_thread) {
291                 g_thread_join (command_thread);
292                 command_thread = NULL;
293         }
294
295         return 0;
296 }