Get device by id
[platform/core/multimedia/libmm-sound.git] / testsuite / mm_sound_testsuite_simple.c
1 /*
2  * libmm-sound
3  *
4  * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact: Seungbae Shin <seungbae.shin@samsung.com>
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  *
20  */
21
22 #include <stdio.h>
23 #include <string.h>
24 #include <stdlib.h>
25
26 #define debug_log(msg, args...) fprintf(stderr, msg, ##args)
27 #define debug_error(msg, args...) fprintf(stderr, msg, ##args)
28 #define MAX_STRING_LEN 256
29 #define MAX_PATH_LEN            1024
30 #define MIN_TONE_PLAY_TIME 300
31 #include "../include/mm_sound.h"
32 #ifdef USE_FOCUS
33 #include "../include/mm_sound_focus.h"
34 #endif
35 #include "../include/mm_sound_common.h"
36 #include "../include/mm_sound_private.h"
37 #include "../include/mm_sound_pa_client.h"
38
39 #include <glib.h>
40
41 #include <pthread.h>
42
43 #include <sys/types.h>
44 #include <sys/stat.h>
45 #include <unistd.h>
46 #include <dirent.h>
47 #include <vconf.h>
48 #include <mm_session_private.h>
49
50 #define POWERON_FILE    "/usr/share/feedback/sound/operation/power_on.wav"
51 #define KEYTONE_FILE    "/usr/share/feedback/sound/operation/operation.wav"
52
53
54 // For testsuite status
55 enum {
56     CURRENT_STATUS_MAINMENU = 0,
57     CURRENT_STATUS_FILENAME = 1,
58     CURRENT_STATUS_POSITION = 2,
59     CURRENT_STATUS_DIRNAME = 3,
60 };
61
62 int g_menu_state = CURRENT_STATUS_MAINMENU;
63
64 volume_type_t g_volume_type = VOLUME_TYPE_MEDIA;
65 unsigned int g_volume_value;
66
67 GIOChannel *stdin_channel;
68 char g_file_name[MAX_STRING_LEN];
69 char g_dir_name[MAX_PATH_LEN];
70
71 #ifdef USE_FOCUS
72 int g_focus_watch_index = -1;
73 #endif
74 GMainLoop* g_loop;
75
76 unsigned int g_subs_id_test, g_subs_id_volume, g_subs_id_device_conn, g_subs_id_device_info;
77
78 // Function
79 static void interpret (char *buf);
80 gboolean timeout_menu_display(void *data);
81 gboolean timeout_quit_program(void *data);
82 gboolean input (GIOChannel *channel);
83
84 void mycallback(void *data, int id)
85 {
86         char *str = (char*)data;
87         if(data != NULL)
88                 debug_log("mycallback called (user data:%s ,id:%d)\n", str, id);
89         else
90                 debug_log("mycallback called (no user data)\n");
91 }
92 volatile char test_callback_done;
93 void test_callback(void *data, int id)
94 {
95         debug_log("test_callback is called\n");
96         test_callback_done = 1;
97 }
98 void mm_sound_test_cb1(int a, void *user_data)
99 {
100         debug_log("dbus test user callback called: param(%d), userdata(%d)\n", a, (int)user_data);
101         g_print("my callback pid : %u  tid : %ld\n", getpid(), pthread_self());
102 }
103 void device_connected_cb (MMSoundDevice_t device_h, bool is_connected, void *user_data)
104 {
105         int ret = 0;
106         mm_sound_device_type_e device_type = 0;
107         mm_sound_device_io_direction_e io_direction = 0;
108         mm_sound_device_state_e state = 0;
109         int id = 0;
110         char *name = NULL;
111         debug_log("*** device_connected_cb is called, device_h[%p], is_connected[%d], user_date[%p]\n", device_h, is_connected, user_data);
112         ret = mm_sound_get_device_type(device_h, &device_type);
113         if (ret) {
114                 debug_error("failed to mm_sound_get_device_type()\n");
115         }
116         ret = mm_sound_get_device_io_direction(device_h, &io_direction);
117         if (ret) {
118                 debug_error("failed to mm_sound_get_device_io_direction()\n");
119         }
120         ret = mm_sound_get_device_state(device_h, &state);
121         if (ret) {
122                 debug_error("failed to mm_sound_get_device_state()\n");
123         }
124         ret = mm_sound_get_device_id(device_h, &id);
125         if (ret) {
126                 debug_error("failed to mm_sound_get_device_id()\n");
127         }
128         ret = mm_sound_get_device_name(device_h, &name);
129         if (ret) {
130                 debug_error("failed to mm_sound_get_device_name()\n");
131         }
132         debug_log("*** --- type[%d], id[%d], io_direction[%d], state[%d], name[%s]\n", device_type, id, io_direction, state, name);
133 }
134 void device_info_changed_cb (MMSoundDevice_t device_h, int changed_info_type, void *user_data)
135 {
136         int ret = 0;
137         mm_sound_device_type_e device_type = 0;
138         mm_sound_device_io_direction_e io_direction = 0;
139         mm_sound_device_state_e state = 0;
140         int id = 0;
141         char *name = NULL;
142         debug_log("*** device_info_changed_cb is called, device_h[%p], changed_info_type[%d], user_date[%p]\n", device_h, changed_info_type, user_data);
143         ret = mm_sound_get_device_type(device_h, &device_type);
144         if (ret) {
145                 debug_error("failed to mm_sound_get_device_type()\n");
146         }
147         ret = mm_sound_get_device_io_direction(device_h, &io_direction);
148         if (ret) {
149                 debug_error("failed to mm_sound_get_device_io_direction()\n");
150         }
151         ret = mm_sound_get_device_state(device_h, &state);
152         if (ret) {
153                 debug_error("failed to mm_sound_get_device_state()\n");
154         }
155         ret = mm_sound_get_device_id(device_h, &id);
156         if (ret) {
157                 debug_error("failed to mm_sound_get_device_id()\n");
158         }
159         ret = mm_sound_get_device_name(device_h, &name);
160         if (ret) {
161                 debug_error("failed to mm_sound_get_device_name()\n");
162         }
163         debug_log("*** --- type[%d], id[%d], io_direction[%d], state[%d], name[%s]\n", device_type, id, io_direction, state, name);
164 }
165 #ifdef USE_FOCUS
166 void focus_cb0(int index, mm_sound_focus_type_e type, mm_sound_focus_state_e state, const char *reason_for_change, int option, const char *ext_info, void *user_data)
167 {
168         char *_state = NULL;
169         if (state == FOCUS_IS_RELEASED)
170                 _state = "RELEASED";
171         else
172                 _state = "ACQUIRED";
173         debug_log("*** focus_cb0 is called, index[%d], focus_type[%d], state[%s], reason_for_change[%s], option[0x%x], ext_info[%s], user_data[%s]\n",
174                         index, type, _state, reason_for_change, option, ext_info, (char*)user_data);
175 }
176 void focus_cb1(int index, mm_sound_focus_type_e type, mm_sound_focus_state_e state, const char *reason_for_change, int option, const char *ext_info, void *user_data)
177 {
178         char *_state = NULL;
179         if (state == FOCUS_IS_RELEASED)
180                 _state = "RELEASED";
181         else
182                 _state = "ACQUIRED";
183         debug_log("*** focus_cb1 is called, index[%d], focus_type[%d], state[%s], reason_for_change[%s], option[0x%x], ext_info[%s], user_data[%s]\n",
184                         index, type, _state, reason_for_change, option, ext_info, (char*)user_data);
185 }
186 void focus_watch_cb(int index, mm_sound_focus_type_e type, mm_sound_focus_state_e state, const char *reason_for_change, const char *ext_info, void *user_data)
187 {
188         char *_state = NULL;
189         if (state == FOCUS_IS_RELEASED)
190                 _state = "RELEASED";
191         else
192                 _state = "ACQUIRED";
193         debug_log("*** focus_watch_cb is called, index[%d], focus_type[%d], state[%s], reason_for_change[%s], ext_info[%s], user_data[%s]\n",
194                         index, type, _state, reason_for_change, ext_info, (char*)user_data);
195 }
196 #endif
197 void quit_program()
198 {
199         g_main_loop_quit(g_loop);
200 }
201
202 static void displaymenu()
203 {
204         if (g_menu_state == CURRENT_STATUS_MAINMENU) {
205                 g_print("==================================================================\n");
206                 g_print("       Sound Path APIs\n");
207                 g_print("==================================================================\n");
208                 g_print("1. Play speaker  \t");
209                 g_print("2. Play headset  \n");
210                 g_print("3. (blank)     \n");
211                 g_print("4. Rec. with mic \t");
212                 g_print("5. (blank)     \t");
213                 g_print("6. Call receiver \n");
214                 g_print("7. Call end      \t");
215                 g_print("8. VT call speaker  \t");
216                 g_print("9. VT call end      \n");
217                 g_print("==================================================================\n");
218                 g_print("       Sound Play APIs\n");
219                 g_print("==================================================================\n");
220                 g_print("k : Key Sound     \t");
221                 g_print("an : play sound    \t");
222                 g_print("as : play sound with stream type\t");
223                 g_print("A : play loud solo\n");
224                 g_print("c : play sound ex \t");
225                 g_print("FN : Play DTMF     \t");
226                 g_print("FS : Play DTMF with stream type\t");
227                 g_print("b : Play directory\n");
228                 g_print("s : Stop play     \t");
229                 g_print("m : stereo to mono\n");
230                 g_print("==================================================================\n");
231                 g_print("       Volume APIs\n");
232                 g_print("==================================================================\n");
233                 g_print("q : Get media    \t");
234                 g_print("w : Inc. media   \t");
235                 g_print("e : Dec. media   \n");
236                 g_print("r : Get system   \t");
237                 g_print("t : Inc. system  \t");
238                 g_print("y : Dec. system  \n");
239                 g_print("g : Get voice   \t");
240                 g_print("h : Inc. voice  \t");
241                 g_print("j : Dec. voice  \n");
242                 g_print("==================================================================\n");
243                 g_print("       Audio route APIs\n");
244                 g_print("==================================================================\n");
245                 g_print("u : Foreach Available Routes \t");
246                 g_print("i : Get Active Devices     \n");
247                 g_print("o : Add Available Routes Callback   \t");
248                 g_print("O : Remove Available Routes Callback   \n");
249                 g_print("p : Add Active Route Callback\t");
250                 g_print("P : Remove Active Route Callback \n");
251                 g_print("{ : Get BT A2DP Status\n");
252                 g_print("} : Set Active Route\n");
253                 g_print("==================================================================\n");
254                 g_print("       Session Test\n");
255                 g_print("==================================================================\n");
256                 g_print("z : Call start \t");
257                 g_print("Z : VideoCall start \t");
258                 g_print("N : Notification start \n");
259                 g_print("n : VOIP start \t");
260                 g_print("v : Session end   \n");
261                 g_print("==================================================================\n");
262                 g_print("       Audio device APIs\n");
263                 g_print("==================================================================\n");
264                 g_print("L : Get current list of connected devices \n");
265                 g_print("I : Get device by id \n");
266                 g_print("C : Add device connected callback \t");
267                 g_print("D : Remove device connected callback \n");
268                 g_print("Q : Add device info. changed callback \t");
269                 g_print("W : Remove device info. changed callback \n");
270                 g_print("==================================================================\n");
271 #ifdef USE_FOCUS
272                 g_print("       Focus APIs\n");
273                 g_print("==================================================================\n");
274                 g_print("DS : signal subscribe for stream info\t");
275                 g_print("DU : signal unsubscribe for stream info\n");
276                 g_print("SS : Send signal for stream info\n");
277                 g_print("GU : Get Focus id\n");
278                 g_print("SF : Set Focus Callback\t");
279                 g_print("FFS : Set Focus Callback for session\t");
280                 g_print("UF : Unset Focus Callback\n");
281                 g_print("DF : Disable Auto Focus Reacquirement\t");
282                 g_print("AF : Acquire Focus\t");
283                 g_print("RF : Release Focus\n");
284                 g_print("WS : Set Focus Watch Callback\t");
285                 g_print("WFS : Set Focus Watch Callback for session\t");
286                 g_print("WU : Unset Focus Watch Callback\n");
287                 g_print("==================================================================\n");
288 #endif
289                 g_print("d : Input Directory \t");
290                 g_print("f : Input File name \t");
291                 g_print("x : Exit Program \n");
292                 g_print("==================================================================\n");
293                 g_print(" Input command >>>>>>>> ");
294         }
295         else if (g_menu_state == CURRENT_STATUS_FILENAME) {
296                 g_print(">>>>Input file name to play : ");
297         }
298         else if (g_menu_state == CURRENT_STATUS_DIRNAME) {
299                         g_print(">>>>Input directory which contain audio files : ");
300         }
301         else {
302                 g_print("**** Unknown status.\n");
303                 quit_program();
304         }
305 }
306
307 gboolean timeout_menu_display(void* data)
308 {
309         displaymenu();
310         return FALSE;
311 }
312
313 gboolean timeout_quit_program(void* data)
314 {
315         quit_program();
316         return FALSE;
317 }
318
319 gboolean input (GIOChannel *channel)
320 {
321         GError *err = NULL;
322         gchar *buf = NULL;
323         gsize length = 0;
324
325         if (g_io_channel_read_line(channel, &buf, &length, NULL, &err) == G_IO_STATUS_NORMAL) {
326                 if (length > 1) {
327                         g_strstrip(buf);
328                         interpret(buf);
329                 }
330                 g_free(buf);
331         }
332
333         return TRUE;
334 }
335
336
337 static void input_filename(char *filename)
338 {
339         MMSOUND_STRNCPY(g_file_name, filename, MAX_STRING_LEN);
340         g_print("\nThe input filename is '%s' \n\n",g_file_name);
341
342 }
343
344 static void input_dirname(char *dirname)
345 {
346         MMSOUND_STRNCPY(g_dir_name, dirname, MAX_PATH_LEN);
347         g_print("\nThe input directory is '%s' \n\n",g_dir_name);
348 }
349
350 #ifdef USE_FOCUS
351 static void __mm_sound_signal_cb1 (mm_sound_signal_name_t signal, int value, void *user_data)
352 {
353         int _value = 0;
354         g_print ("[%s] signal[%d], value[%d], user_data[%p]]\n", __func__, signal, value, user_data);
355         mm_sound_get_signal_value (signal, &_value);
356         g_print (" -- get value : %d\n", _value);
357 }
358
359 static void __mm_sound_signal_cb2 (mm_sound_signal_name_t signal, int value, void *user_data)
360 {
361         int _value = 0;
362         g_print ("[%s] signal[%d], value[%d], user_data[%p]]\n", __func__, signal, value, user_data);
363         mm_sound_get_signal_value (signal, &_value);
364         g_print (" -- get value : %d\n", _value);
365 }
366
367 unsigned int g_subscribe_id1 = 0;
368 unsigned int g_subscribe_id2 = 0;
369 #endif
370
371 static void interpret (char *cmd)
372 {
373         int ret=0;
374         static int handle = -1;
375         MMSoundPlayParam soundparam = {0,};
376
377         switch (g_menu_state)
378         {
379                 case CURRENT_STATUS_MAINMENU:
380 #ifdef USE_FOCUS
381                         if(strncmp(cmd, "DS", 2) == 0) {
382                                 ret = mm_sound_subscribe_signal(MM_SOUND_SIGNAL_RELEASE_INTERNAL_FOCUS, &g_subscribe_id1, __mm_sound_signal_cb1, NULL);
383                                 if(ret < 0)
384                                         debug_log("mm_sound_subscribe_signal() failed with 0x%x\n", ret);
385                                 else
386                                         debug_log("id: %u, callback:%p\n", g_subscribe_id1, __mm_sound_signal_cb1);
387                                 ret = mm_sound_subscribe_signal(MM_SOUND_SIGNAL_RELEASE_INTERNAL_FOCUS, &g_subscribe_id2, __mm_sound_signal_cb2, NULL);
388                                 if(ret < 0)
389                                         debug_log("mm_sound_subscribe_signal() failed with 0x%x\n", ret);
390                                 else
391                                         debug_log("id: %u, callback:%p\n", g_subscribe_id2, __mm_sound_signal_cb2);
392                         }
393
394                         else if(strncmp(cmd, "DU", 2) == 0) {
395                                 mm_sound_unsubscribe_signal(g_subscribe_id1);
396                                 debug_log("unsubscribe_signal for id[%d]\n", g_subscribe_id1);
397                                 mm_sound_unsubscribe_signal(g_subscribe_id2);
398                                 debug_log("unsubscribe_signal for id[%d]\n", g_subscribe_id2);
399                         }
400
401                         else if(strncmp(cmd, "SS", 2) == 0) {
402                                 int value = 0;
403                                 ret = mm_sound_send_signal(MM_SOUND_SIGNAL_RELEASE_INTERNAL_FOCUS, 1);
404                                 if(ret < 0)
405                                         debug_log("mm_sound_send_signal() failed with 0x%x\n", ret);
406                                 else
407                                         debug_log("mm_sound_send_signal for signal[%d], value[%d] is success\n", MM_SOUND_SIGNAL_RELEASE_INTERNAL_FOCUS, 1);
408                                 mm_sound_get_signal_value (MM_SOUND_SIGNAL_RELEASE_INTERNAL_FOCUS, &value);
409                                 g_print (" -- get value of RELEASE_INTERNAL_FOCUS : %d\n", value);
410                                 ret = mm_sound_send_signal(MM_SOUND_SIGNAL_RELEASE_INTERNAL_FOCUS, 0);
411                                 if(ret < 0)
412                                         debug_log("mm_sound_send_signal() failed with 0x%x\n", ret);
413                                 else
414                                         debug_log("mm_sound_send_signal for signal[%d], value[%d] is success\n", MM_SOUND_SIGNAL_RELEASE_INTERNAL_FOCUS, 0);
415                                 mm_sound_get_signal_value (MM_SOUND_SIGNAL_RELEASE_INTERNAL_FOCUS, &value);
416                                 g_print (" -- get value of RELEASE_INTERNAL_FOCUS : %d\n", value);
417                         }
418
419                         else if(strncmp(cmd, "GU", 2) == 0) {
420                                 int id = 0;
421                                 ret = mm_sound_focus_get_id(&id);
422                                 if(ret < 0)
423                                         debug_log("mm_sound_focus_get_id() failed with 0x%x\n", ret);
424                                 else
425                                         debug_log("id : %d\n", id);
426                         }
427
428                         else if(strncmp(cmd, "SF", 2) == 0) {
429                                 int ret = 0;
430                                 char input_string[128];
431                                 char flag_1, flag_2;
432                                 int id = 0;
433                                 char *stream_type = NULL;
434                                 const char *user_data = "this is user data";
435
436                                 fflush(stdin);
437                                 g_print ("1. Media\n");
438                                 g_print ("2. Alarm\n");
439                                 g_print ("3. Notification\n");
440                                 g_print ("4. Emergency\n");
441                                 g_print ("5. Voice Information\n");
442                                 g_print ("6. Ringtone\n");
443                                 g_print ("7. Ringtone Call\n");
444                                 g_print ("8. VOIP\n");
445                                 g_print ("0. Voice Recognition\n");
446                                 g_print("> select id and stream type: (eg. 0 3)");
447
448                                 if (fgets(input_string, sizeof(input_string)-1, stdin)) {
449                                         g_print ("### fgets return  NULL\n");
450                                 }
451                                 flag_1 = input_string[0];
452                                 flag_2 = input_string[2];
453
454                                 if(flag_1 == '0') { id = 0; }
455                                 else if(flag_1 == '1') { id = 1; }
456                                 else if(flag_1 == '2') { id = 2; }
457                                 else { id = 2; }
458                                 if(flag_2 == '1') { stream_type = "media"; }
459                                 else if(flag_2 == '2') { stream_type = "alarm"; }
460                                 else if(flag_2 == '3') { stream_type = "notification"; }
461                                 else if(flag_2 == '4') { stream_type = "emergency"; }
462                                 else if(flag_2 == '5') { stream_type = "voice-information"; }
463                                 else if(flag_2 == '6') { stream_type = "ringtone"; }
464                                 else if(flag_2 == '7') { stream_type = "ringtone-call"; }
465                                 else if(flag_2 == '8') { stream_type = "voip"; }
466                                 else if(flag_2 == '0') { stream_type = "voice-recognition"; }
467                                 else { stream_type = "media"; }
468
469                                 ret = mm_sound_register_focus(id, stream_type, (id == 0)? focus_cb0 : focus_cb1, (void*)user_data);
470                                 if (ret) {
471                                         g_print("failed to mm_sound_register_focus(), ret[0x%x]\n", ret);
472                                 } else {
473                                         g_print("id[%d], stream_type[%s], callback fun[%p]\n", id, stream_type, (id == 0)? focus_cb0 : focus_cb1);
474                                 }
475                         }
476
477                         else if(strncmp(cmd, "FFS", 3) == 0) {
478                                 int ret = 0;
479                                 char input_string[128];
480                                 char flag_1, flag_2;
481                                 int id = 0;
482                                 char *stream_type = NULL;
483                                 const char *user_data = "this is user data";
484
485                                 fflush(stdin);
486                                 g_print ("1. Media\n");
487                                 g_print ("2. Alarm\n");
488                                 g_print ("3. Notification\n");
489                                 g_print ("4. Emergency\n");
490                                 g_print ("5. Voice Information\n");
491                                 g_print ("6. Ringtone\n");
492                                 g_print ("7. Ringtone Call\n");
493                                 g_print ("8. VOIP\n");
494                                 g_print ("0. Voice Recognition\n");
495                                 g_print("> select id and stream type: (eg. 0 3)");
496
497                                 if (fgets(input_string, sizeof(input_string)-1, stdin)) {
498                                         g_print ("### fgets return  NULL\n");
499                                 }
500                                 flag_1 = input_string[0];
501                                 flag_2 = input_string[2];
502
503                                 if(flag_1 == '0') { id = 0; }
504                                 else if(flag_1 == '1') { id = 1; }
505                                 else if(flag_1 == '2') { id = 2; }
506                                 else { id = 2; }
507                                 if(flag_2 == '1') { stream_type = "media"; }
508                                 else if(flag_2 == '2') { stream_type = "alarm"; }
509                                 else if(flag_2 == '3') { stream_type = "notification"; }
510                                 else if(flag_2 == '4') { stream_type = "emergency"; }
511                                 else if(flag_2 == '5') { stream_type = "voice-information"; }
512                                 else if(flag_2 == '6') { stream_type = "ringtone"; }
513                                 else if(flag_2 == '7') { stream_type = "ringtone-call"; }
514                                 else if(flag_2 == '8') { stream_type = "voip"; }
515                                 else if(flag_2 == '0') { stream_type = "voice-recognition"; }
516                                 else { stream_type = "media"; }
517
518                                 ret = mm_sound_register_focus_for_session(id, getpid(), stream_type, (id == 0)? focus_cb0 : focus_cb1, (void*)user_data);
519                                 if (ret) {
520                                         g_print("failed to mm_sound_register_focus_for_session(), ret[0x%x]\n", ret);
521                                 } else {
522                                         g_print("id[%d], stream_type[%s], callback fun[%p]\n", id, stream_type, (id == 0)? focus_cb0 : focus_cb1);
523                                 }
524                         }
525
526                         else if(strncmp(cmd, "UF", 2) == 0) {
527                                 int ret = 0;
528                                 char input_string[128];
529                                 char flag_1;
530                                 int id = 0;
531                                 fflush(stdin);
532                                 g_print("> select id:");
533                                 if (fgets(input_string, sizeof(input_string)-1, stdin)) {
534                                         g_print ("### fgets return  NULL\n");
535                                 }
536                                 flag_1 = input_string[0];
537                                 if(flag_1 == '0') { id = 0; }
538                                 else if(flag_1 == '1') { id = 1; }
539                                 else if(flag_1 == '2') { id = 2; }
540                                 else { id = 2; }
541                                 ret = mm_sound_unregister_focus(id);
542                                 if (ret) {
543                                         g_print("failed to mm_sound_unregister_focus(), ret[0x%x]\n", ret);
544                                 }
545                         }
546
547                         else if(strncmp(cmd, "DF", 2) == 0) {
548                                 int ret = 0;
549                                 char input_string[128];
550                                 char flag_1, flag_2;
551                                 int id = 0;
552                                 bool reacquisition = true;
553                                 fflush(stdin);
554                                 g_print ("1. enable auto reacquirement\n");
555                                 g_print ("2. disable auto reacquirement\n");
556                                 g_print("> select id and option: (eg. 0 1)");
557                                 if (fgets(input_string, sizeof(input_string)-1, stdin)) {
558                                         g_print ("### fgets return  NULL\n");
559                                 }
560                                 flag_1 = input_string[0];
561                                 flag_2 = input_string[2];
562
563                                 if(flag_1 == '0') { id = 0; }
564                                 else if(flag_1 == '1') { id = 1; }
565                                 else if(flag_1 == '2') { id = 2; }
566                                 else { id = 2; }
567
568                                 if(flag_2 == '1') { reacquisition = true; }
569                                 else if(flag_2 == '2') { reacquisition = false; }
570                                 else { reacquisition = true; }
571                                 ret = mm_sound_set_focus_reacquisition(id, reacquisition);
572                                 if (ret) {
573                                         g_print("failed to mm_sound_disable_focus_reacquirement(), ret[0x%x]\n", ret);
574                                 }
575                         }
576
577                         else if(strncmp(cmd, "AF", 2) == 0) {
578                                 int ret = 0;
579                                 char input_string[128];
580                                 char flag_1, flag_2;
581                                 int id = 0;
582                                 mm_sound_focus_type_e type = FOCUS_FOR_PLAYBACK;
583                                 fflush(stdin);
584                                 g_print ("1. focus for playback\n");
585                                 g_print ("2. focus for recording\n");
586                                 g_print ("3. focus for both\n");
587                                 g_print("> select id and focus_type: (eg. 0 1)");
588                                 if (fgets(input_string, sizeof(input_string)-1, stdin)) {
589                                         g_print ("### fgets return  NULL\n");
590                                 }
591                                 flag_1 = input_string[0];
592                                 flag_2 = input_string[2];
593
594                                 if(flag_1 == '0') { id = 0; }
595                                 else if(flag_1 == '1') { id = 1; }
596                                 else { id = 2; }
597
598                                 if(flag_2 == '1') { type = FOCUS_FOR_PLAYBACK; }
599                                 else if(flag_2 == '2') { type = FOCUS_FOR_CAPTURE; }
600                                 else { type = FOCUS_FOR_BOTH; }
601                                 ret = mm_sound_acquire_focus(id, type, "additional_info. for acquire");
602                                 if (ret) {
603                                         g_print("failed to mm_sound_acquire_focus(), ret[0x%x]\n", ret);
604                                 }
605                         }
606
607                         else if(strncmp(cmd, "RF", 2) == 0) {
608                                 int ret = 0;
609                                 char input_string[128];
610                                 char flag_1, flag_2;
611                                 int id = 0;
612                                 mm_sound_focus_type_e type = FOCUS_FOR_PLAYBACK;
613                                 fflush(stdin);
614                                 g_print ("1. focus for playback\n");
615                                 g_print ("2. focus for recording\n");
616                                 g_print ("3. focus for all\n");
617                                 g_print("> select id and focus_type: (eg. 0 1)");
618                                 if (fgets(input_string, sizeof(input_string)-1, stdin)) {
619                                         g_print ("### fgets return  NULL\n");
620                                 }
621                                 flag_1 = input_string[0];
622                                 flag_2 = input_string[2];
623
624                                 if(flag_1 == '0') { id = 0; }
625                                 else if(flag_1 == '1') { id = 1; }
626                                 else { id = 2; }
627
628                                 if(flag_2 == '1') { type = FOCUS_FOR_PLAYBACK; }
629                                 else if(flag_2 == '2') { type = FOCUS_FOR_CAPTURE; }
630                                 else { type = FOCUS_FOR_BOTH; }
631                                 ret = mm_sound_release_focus(id, type, "additional_info. for release");
632                                 if (ret) {
633                                         g_print("failed to mm_sound_release_focus(), ret[0x%x]\n", ret);
634                                 }
635                         }
636
637                         else if(strncmp(cmd, "WFS", 3) == 0) {
638                                 int ret = 0;
639                                 char input_string[128];
640                                 char flag_1;
641                                 int type = 0;
642                                 const char *user_data = "this is user data for watch";
643
644                                 fflush(stdin);
645                                 g_print ("1. playback\n");
646                                 g_print ("2. recording\n");
647                                 g_print ("3. both\n");
648                                 g_print("> select interest focus type:");
649
650                                 if (fgets(input_string, sizeof(input_string)-1, stdin)) {
651                                         g_print ("### fgets return  NULL\n");
652                                 }
653                                 flag_1 = input_string[0];
654
655                                 if(flag_1 == '1') { type = 1; }
656                                 else if(flag_1 == '2') { type = 2; }
657                                 else if(flag_1 == '3') { type = 3; }
658                                 else { type = 1; }
659                                 ret = mm_sound_set_focus_watch_callback_for_session(getpid(), type, focus_watch_cb, (void*)user_data, &g_focus_watch_index);
660                                 if (ret) {
661                                         g_print("failed to mm_sound_set_focus_watch_callback(), ret[0x%x]\n", ret);
662                                 } else {
663                                         g_print("index[%d], type[%d], callback fun[%p]\n", g_focus_watch_index, type, focus_watch_cb);
664                                 }
665                         }
666
667                         else if(strncmp(cmd, "WS", 2) == 0) {
668                                 int ret = 0;
669                                 char input_string[128];
670                                 char flag_1;
671                                 int type = 0;
672                                 const char *user_data = "this is user data for watch";
673
674                                 fflush(stdin);
675                                 g_print ("1. playback\n");
676                                 g_print ("2. recording\n");
677                                 g_print ("3. both\n");
678                                 g_print("> select interest focus type:");
679
680                                 if (fgets(input_string, sizeof(input_string)-1, stdin)) {
681                                         g_print ("### fgets return  NULL\n");
682                                 }
683                                 flag_1 = input_string[0];
684
685                                 if(flag_1 == '1') { type = 1; }
686                                 else if(flag_1 == '2') { type = 2; }
687                                 else if(flag_1 == '3') { type = 3; }
688                                 else { type = 1; }
689                                 ret = mm_sound_set_focus_watch_callback(type, focus_watch_cb, (void*)user_data, &g_focus_watch_index);
690                                 if (ret) {
691                                         g_print("failed to mm_sound_set_focus_watch_callback(), ret[0x%x]\n", ret);
692                                 } else {
693                                         g_print("index[%d], type[%d], callback fun[%p]\n", g_focus_watch_index, type, focus_watch_cb);
694                                 }
695                         }
696
697                         else if(strncmp(cmd, "WU", 2) == 0) {
698                                 int ret = 0;
699                                 ret = mm_sound_unset_focus_watch_callback(g_focus_watch_index);
700                                 if (ret) {
701                                         g_print("failed to mm_sound_unset_focus_watch_callback(), ret[0x%x]\n", ret);
702                                 }
703                         }
704
705                         else if(strncmp(cmd, "k", 1) == 0)
706 #else
707                         if(strncmp(cmd, "k", 1) == 0)
708 #endif
709                         {
710                                 ret = mm_sound_play_keysound(KEYTONE_FILE, 0);
711                                 if(ret < 0)
712                                         debug_log("keysound play failed with 0x%x\n", ret);
713                         }
714                         else if (strcmp(cmd, "dbus-m") == 0) {
715                             int ret = 0;
716                             int a = 3;
717                             int b = 4;
718                             int result_val = 0;
719                             g_print("dbus method test call\n");
720                             ret = mm_sound_test(a, b, &result_val);
721                             if (ret) {
722                                 g_print("failed to mm_sound_test(), ret[0x%x]\n", ret);
723                             } else {
724                                 g_print("Got answer : %d\n", result_val);
725                             }
726                         } else if (strcmp(cmd, "dbus-a") == 0) {
727                             int ret = 0;
728                             int user_data = 3;
729                             g_print("dbus method test add callback\n");
730                             g_print("my testsuite pid : %u  tid : %ld\n", getpid(), pthread_self());
731                             ret = mm_sound_add_test_callback(mm_sound_test_cb1, (void *)user_data, &g_subs_id_test);
732                             if (ret) {
733                                 g_print("failed to mm_sound_add_test_callback(), ret[0x%x]\n", ret);
734                             } else {
735                                 g_print("add test callback success\n");
736                             }
737                         } else if (strcmp(cmd, "dbus-r") == 0) {
738                             int ret = 0;
739                             g_print("dbus method test remove callback\n");
740                             ret = mm_sound_remove_test_callback(g_subs_id_test);
741                             if (ret) {
742                                 g_print("failed to mm_sound_remove_test_callback(), ret[0x%x]\n", ret);
743                             } else {
744                                 g_print("remove test callback success\n");
745                             }
746                         }
747                         else if(strncmp(cmd, "q", 1) == 0)
748                         {//get media volume
749                                 unsigned int value = 100;
750                                 ret = mm_sound_volume_get_value(g_volume_type, &value);
751                                 if(ret < 0) {
752                                         debug_log("mm_sound_volume_get_value 0x%x\n", ret);
753                                 }
754                                 else{
755                                         g_print("*** MEDIA VOLUME : %u ***\n", value);
756                                         g_volume_value = value;
757                                 }
758                         }
759                         else if(strncmp(cmd, "e", 1) == 0)
760                         {//set media volume down
761                                 unsigned int value = 100;
762                                 ret = mm_sound_volume_get_value(g_volume_type, &value);
763                                 if(ret < 0) {
764                                         debug_log("mm_sound_volume_get_value 0x%x\n", ret);
765                                 }
766                                 else {
767                                         if(value != 0) {
768                                                 value--;
769                                         }
770
771                                         ret = mm_sound_volume_set_value(g_volume_type, value);
772                                         if(ret < 0) {
773                                                 debug_log("mm_sound_volume_set_value 0x%x\n", ret);
774                                         }
775                                 }
776                         }
777                         else if(strncmp(cmd, "r", 1) == 0)
778                         {//get media volume
779                                 unsigned int value = 100;
780                                 ret = mm_sound_volume_get_value(VOLUME_TYPE_SYSTEM, &value);
781                                 if(ret < 0) {
782                                         debug_log("mm_sound_volume_get_value 0x%x\n", ret);
783                                 }
784                                 else{
785                                         g_print("*** SYSTEM VOLUME : %u ***\n", value);
786                                         g_volume_value = value;
787                                 }
788                         }
789                         else if(strncmp(cmd, "y", 1) == 0)
790                         {//set media volume down
791                                 unsigned int value = 100;
792                                 ret = mm_sound_volume_get_value(VOLUME_TYPE_SYSTEM, &value);
793                                 if(ret < 0) {
794                                         debug_log("mm_sound_volume_get_value 0x%x\n", ret);
795                                 }
796                                 else {
797                                         if(value != 0) {
798                                                 value--;
799                                         }
800
801                                         ret = mm_sound_volume_set_value(VOLUME_TYPE_SYSTEM, value);
802                                         if(ret < 0) {
803                                                 debug_log("mm_sound_volume_set_value 0x%x\n", ret);
804                                         }else {
805                                                 g_print("Current System volume is %d\n", value);
806                                         }
807                                 }
808                         }
809                         else if(strncmp(cmd, "g", 1) == 0)
810                         {//get voice volume
811                                 unsigned int value = 100;
812                                 ret = mm_sound_volume_get_value(VOLUME_TYPE_VOICE, &value);
813                                 if(ret < 0) {
814                                         debug_log("mm_sound_volume_get_value 0x%x\n", ret);
815                                 }
816                                 else{
817                                         g_print("*** VOICE VOLUME : %u ***\n", value);
818                                         g_volume_value = value;
819                                 }
820                         }
821                         else if(strncmp(cmd, "j", 1) == 0)
822                         {//set voice volume down
823                                 unsigned int value = 100;
824                                 ret = mm_sound_volume_get_value(VOLUME_TYPE_VOICE, &value);
825                                 if(ret < 0) {
826                                         debug_log("mm_sound_volume_get_value 0x%x\n", ret);
827                                 }
828                                 else {
829                                         if(value != 0) {
830                                                 value--;
831                                         }
832
833                                         ret = mm_sound_volume_set_value(VOLUME_TYPE_VOICE, value);
834                                         if(ret < 0) {
835                                                 debug_log("mm_sound_volume_set_value 0x%x\n", ret);
836                                         }else {
837                                                 g_print("Current Voice volume is %d\n", value);
838                                         }
839                                 }
840                         }
841                         else if(strncmp(cmd, "an", 2) == 0)
842                         {
843                                 debug_log("volume is %d type, %d\n", g_volume_type, g_volume_value);
844                                 ret = mm_sound_play_sound(g_file_name, g_volume_type, mycallback ,"USERDATA", &handle);
845                                 if(ret < 0)
846                                         debug_log("mm_sound_play_sound() failed with 0x%x\n", ret);
847                         }
848                         else if(strncmp(cmd, "as", 2) == 0)
849                         {
850                                 debug_log("stream %s type, %d\n", "media", g_volume_value);
851                                 ret = mm_sound_play_sound_with_stream_info(g_file_name, "media", -1, 1, mycallback ,"USERDATA", &handle);
852                                 if(ret < 0)
853                                         debug_log("mm_sound_play_sound() failed with 0x%x\n", ret);
854                         }
855                         else if(strncmp(cmd, "A", 1) == 0)
856                         {
857                                 debug_log("volume is %d type, %d\n", g_volume_type, g_volume_value);
858                                 ret = mm_sound_play_loud_solo_sound(g_file_name, g_volume_type, mycallback ,"USERDATA", &handle);
859                                 if(ret < 0)
860                                         debug_log("mm_sound_play_sound_loud_solo() failed with 0x%x\n", ret);
861                         }
862                         else if(strncmp(cmd, "FN", 2) == 0)
863                         {
864                                 char num = 0;
865                                 char input_string[128] = "";
866                                 char *tok = NULL;
867                                 int tonetime=0;
868                                 double volume=1.0;
869                                 int volume_type = -1;
870                                 bool enable_session = 0;
871                                 MMSoundTone_t tone = MM_SOUND_TONE_DTMF_0;
872
873                                 while(num != 'q') {
874                                         fflush(stdin);
875                                         g_print("enter number(0~H exit:q), volume type(0~7),  volume(0.0~1.0),  time(ms), enable_session(0:unable , 1:enable):\t ");
876                                         if (fgets(input_string, sizeof(input_string)-1, stdin) == NULL) {
877                                                 g_print ("### fgets return  NULL\n");
878                                         }
879                                         tok = strtok(input_string, " ");
880                                         if(!tok) continue;
881                                         if(tok[0] == 'q') {
882                                                 break;
883                                         }
884                                         else if(tok[0] < '0' || tok[0] > '~') {
885                                                 if(tok[0] == '*' || tok[0] == '#')
886                                                         ;
887                                                 else
888                                                         continue;
889                                         }
890                                         num = tok[0];
891                                         if(num >= '0' && num <= '9') {
892                                                 tone = (MMSoundTone_t)(num - '0');
893                                         }
894                                         else if(num == '*') {
895                                                 tone = MM_SOUND_TONE_DTMF_S;
896                                         }
897                                         else if(num == '#') {
898                                                 tone =MM_SOUND_TONE_DTMF_P;
899                                         }
900                                         else if(num == 'A') {   tone = MM_SOUND_TONE_DTMF_A;    }
901                                         else if(num == 'B') {   tone = MM_SOUND_TONE_DTMF_B;    }
902                                         else if(num == 'C') {   tone = MM_SOUND_TONE_DTMF_C;    }
903                                         else if(num == 'D') {   tone = MM_SOUND_TONE_DTMF_D;    }
904                                         else if(num == 'E') {   tone = MM_SOUND_TONE_SUP_DIAL;  }
905                                         else if(num == 'F') {   tone = MM_SOUND_TONE_ANSI_DIAL; }
906                                         else if(num == 'G') {   tone = MM_SOUND_TONE_JAPAN_DIAL;        }
907                                         else if(num == 'H') {   tone = MM_SOUND_TONE_SUP_BUSY;          }
908                                         else if(num == 'I') {           tone = MM_SOUND_TONE_ANSI_BUSY;         }
909                                         else if(num == 'J') {           tone = MM_SOUND_TONE_JAPAN_BUSY;                }
910                                         else if(num == 'K') {   tone = MM_SOUND_TONE_SUP_CONGESTION;            }
911                                         else if(num == 'L') {           tone = MM_SOUND_TONE_ANSI_CONGESTION;           }
912                                         else if(num == 'M') {   tone = MM_SOUND_TONE_SUP_RADIO_ACK;             }
913                                         else if(num == 'N') {   tone = MM_SOUND_TONE_JAPAN_RADIO_ACK;           }
914                                         else if(num == 'O') {   tone = MM_SOUND_TONE_SUP_RADIO_NOTAVAIL;        }
915                                         else if(num == 'P') {   tone = MM_SOUND_TONE_SUP_ERROR;         }
916                                         else if(num == 'Q') {   tone = MM_SOUND_TONE_SUP_CALL_WAITING;  }
917                                         else if(num == 'R') {   tone = MM_SOUND_TONE_ANSI_CALL_WAITING; }
918                                         else if(num == 'S') {   tone = MM_SOUND_TONE_SUP_RINGTONE;              }
919                                         else if(num == 'T') {   tone = MM_SOUND_TONE_ANSI_RINGTONE;     }
920                                         else if(num == 'U') {   tone = MM_SOUND_TONE_PROP_BEEP;         }
921                                         else if(num == 'V') {   tone = MM_SOUND_TONE_PROP_ACK;          }
922                                         else if(num == 'W') {   tone = MM_SOUND_TONE_PROP_NACK; }
923                                         else if(num == 'X') {   tone = MM_SOUND_TONE_PROP_PROMPT;       }
924                                         else if(num == 'Y') {   tone = MM_SOUND_TONE_PROP_BEEP2;        }
925                                         else if(num == 'Z')  {  tone =MM_SOUND_TONE_CDMA_HIGH_SLS;      }
926                                         else if(num == '[')  {  tone = MM_SOUND_TONE_CDMA_MED_SLS;      }
927                                         else if(num == ']')  {  tone = MM_SOUND_TONE_CDMA_LOW_SLS;      }
928                                         else if(num == '^')  {  tone =MM_SOUND_TONE_CDMA_HIGH_S_X4;     }
929                                         else if(num == '_')  {  tone =MM_SOUND_TONE_CDMA_MED_S_X4;      }
930                                         else if(num == 'a')  {  tone =MM_SOUND_TONE_CDMA_LOW_S_X4;      }
931                                         else if(num == 'b')  {  tone =MM_SOUND_TONE_CDMA_HIGH_PBX_L;    }
932                                         else if(num == 'c')  {  tone =MM_SOUND_TONE_CDMA_MED_PBX_L;     }
933                                         else if(num == 'd')  {  tone =MM_SOUND_TONE_CDMA_LOW_PBX_L;     }
934                                         else if(num == 'e')  {  tone =MM_SOUND_TONE_CDMA_HIGH_PBX_SS;   }
935                                         else if(num == 'f')  {  tone =MM_SOUND_TONE_CDMA_MED_PBX_SS;    }
936                                         else if(num == 'g')  {  tone =MM_SOUND_TONE_CDMA_LOW_PBX_SS;    }
937                                         else if(num == 'h')  {  tone =MM_SOUND_TONE_CDMA_HIGH_PBX_SSL;  }
938                                         else if(num == 'i')  {          tone =MM_SOUND_TONE_CDMA_MED_PBX_SSL;   }
939                                         else if(num == 'j')  {  tone =MM_SOUND_TONE_CDMA_LOW_PBX_SSL;           }
940                                         else if(num == 'k')  {  tone =MM_SOUND_TONE_CDMA_HIGH_PBX_SLS;  }
941                                         else if(num == 'l')  {          tone =MM_SOUND_TONE_CDMA_MED_PBX_SLS;   }
942                                         else if(num == 'm')  {  tone =MM_SOUND_TONE_CDMA_LOW_PBX_SLS;           }
943                                         else if(num == 'n')  {  tone =MM_SOUND_TONE_CDMA_HIGH_PBX_S_X4; }
944                                         else if(num == 'o')  {  tone =MM_SOUND_TONE_CDMA_MED_PBX_S_X4;  }
945                                         else if(num == 'p')  {  tone =MM_SOUND_TONE_CDMA_LOW_PBX_S_X4;  }
946                                         else if(num == 'q')  {  tone =MM_SOUND_TONE_CDMA_ALERT_NETWORK_LITE;    }
947                                         else if(num == 'r')  {  tone =MM_SOUND_TONE_CDMA_ALERT_AUTOREDIAL_LITE; }
948                                         else if(num == 's')  {  tone =MM_SOUND_TONE_CDMA_ONE_MIN_BEEP;  }
949                                         else if(num == 't')  {  tone =MM_SOUND_TONE_CDMA_KEYPAD_VOLUME_KEY_LITE;                }
950                                         else if(num == 'u')  {  tone =MM_SOUND_TONE_CDMA_PRESSHOLDKEY_LITE;     }
951                                         else if(num == 'v')  {  tone =MM_SOUND_TONE_CDMA_ALERT_INCALL_LITE;     }
952                                         else if(num == 'w')  {  tone =MM_SOUND_TONE_CDMA_EMERGENCY_RINGBACK;    }
953                                         else if(num == 'x')  {  tone =MM_SOUND_TONE_CDMA_ALERT_CALL_GUARD;      }
954                                         else if(num == 'y')  {  tone =MM_SOUND_TONE_CDMA_SOFT_ERROR_LITE;       }
955                                         else if(num == 'z')  {  tone =MM_SOUND_TONE_CDMA_CALLDROP_LITE; }
956                                         else if(num == '{')  {  tone =MM_SOUND_TONE_LOW_FRE;    }
957                                         else if(num == '}')  {  tone =MM_SOUND_TONE_MED_FRE;    }
958                                         else if(num == '~')  {  tone =MM_SOUND_TONE_HIGH_FRE; }
959                                         tok = strtok(NULL, " ");
960                                         if(tok)  volume_type = (double)atoi(tok);
961
962                                         tok = strtok(NULL, " ");
963                                         if(tok)  volume = (double)atof(tok);
964
965                                         tok = strtok(NULL, " ");
966                                         if(tok)
967                                         {
968                                                 tonetime = atoi(tok);
969                                         }
970                                         else
971                                         {
972                                                 tonetime = MIN_TONE_PLAY_TIME;
973                                         }
974
975                                         tok = strtok(NULL, " ");
976                                         if(tok)  enable_session = (bool)atof(tok);
977
978                                         debug_log("volume type: %d\t volume is %f\t tonetime: %d\t enable_session %d \n", volume_type, volume, tonetime, enable_session);
979                                         ret = mm_sound_play_tone_ex(tone, volume_type, volume, tonetime, &handle, enable_session);
980                                         if(ret<0)
981                                                 debug_log ("[magpie] Play DTMF sound cannot be played ! %d\n", handle);
982                                 }
983                         }
984                         else if(strncmp(cmd, "FS", 2) == 0)
985                         {
986                                 char num = 0;
987                                 char input_string[128] = "";
988                                 char *tok = NULL;
989                                 char *stream_type = NULL;
990                                 int tonetime=0;
991                                 double volume=1.0;
992                                 MMSoundTone_t tone = MM_SOUND_TONE_DTMF_0;
993
994                                 while(num != 'q') {
995                                         fflush(stdin);
996                                         g_print("enter number(0~H exit:q), stream type(media, system, ...),  volume(0.0~1.0),  time(ms):\t ");
997                                         if (fgets(input_string, sizeof(input_string)-1, stdin) == NULL) {
998                                                 g_print ("### fgets return  NULL\n");
999                                         }
1000                                         tok = strtok(input_string, " ");
1001                                         if(!tok) continue;
1002                                         if(tok[0] == 'q') {
1003                                                 break;
1004                                         }
1005                                         else if(tok[0] < '0' || tok[0] > '~') {
1006                                                 if(tok[0] == '*' || tok[0] == '#')
1007                                                         ;
1008                                                 else
1009                                                         continue;
1010                                         }
1011                                         num = tok[0];
1012                                         if(num >= '0' && num <= '9') {
1013                                                 tone = (MMSoundTone_t)(num - '0');
1014                                         }
1015                                         else if(num == '*') {
1016                                                 tone = MM_SOUND_TONE_DTMF_S;
1017                                         }
1018                                         else if(num == '#') {
1019                                                 tone =MM_SOUND_TONE_DTMF_P;
1020                                         }
1021                                         else if(num == 'A') {   tone = MM_SOUND_TONE_DTMF_A;    }
1022                                         else if(num == 'B') {   tone = MM_SOUND_TONE_DTMF_B;    }
1023                                         else if(num == 'C') {   tone = MM_SOUND_TONE_DTMF_C;    }
1024                                         else if(num == 'D') {   tone = MM_SOUND_TONE_DTMF_D;    }
1025                                         else if(num == 'E') {   tone = MM_SOUND_TONE_SUP_DIAL;  }
1026                                         else if(num == 'F') {   tone = MM_SOUND_TONE_ANSI_DIAL; }
1027                                         else if(num == 'G') {   tone = MM_SOUND_TONE_JAPAN_DIAL;        }
1028                                         else if(num == 'H') {   tone = MM_SOUND_TONE_SUP_BUSY;          }
1029                                         else if(num == 'I') {           tone = MM_SOUND_TONE_ANSI_BUSY;         }
1030                                         else if(num == 'J') {           tone = MM_SOUND_TONE_JAPAN_BUSY;                }
1031                                         else if(num == 'K') {   tone = MM_SOUND_TONE_SUP_CONGESTION;            }
1032                                         else if(num == 'L') {           tone = MM_SOUND_TONE_ANSI_CONGESTION;           }
1033                                         else if(num == 'M') {   tone = MM_SOUND_TONE_SUP_RADIO_ACK;             }
1034                                         else if(num == 'N') {   tone = MM_SOUND_TONE_JAPAN_RADIO_ACK;           }
1035                                         else if(num == 'O') {   tone = MM_SOUND_TONE_SUP_RADIO_NOTAVAIL;        }
1036                                         else if(num == 'P') {   tone = MM_SOUND_TONE_SUP_ERROR;         }
1037                                         else if(num == 'Q') {   tone = MM_SOUND_TONE_SUP_CALL_WAITING;  }
1038                                         else if(num == 'R') {   tone = MM_SOUND_TONE_ANSI_CALL_WAITING; }
1039                                         else if(num == 'S') {   tone = MM_SOUND_TONE_SUP_RINGTONE;              }
1040                                         else if(num == 'T') {   tone = MM_SOUND_TONE_ANSI_RINGTONE;     }
1041                                         else if(num == 'U') {   tone = MM_SOUND_TONE_PROP_BEEP;         }
1042                                         else if(num == 'V') {   tone = MM_SOUND_TONE_PROP_ACK;          }
1043                                         else if(num == 'W') {   tone = MM_SOUND_TONE_PROP_NACK; }
1044                                         else if(num == 'X') {   tone = MM_SOUND_TONE_PROP_PROMPT;       }
1045                                         else if(num == 'Y') {   tone = MM_SOUND_TONE_PROP_BEEP2;        }
1046                                         else if(num == 'Z')  {  tone =MM_SOUND_TONE_CDMA_HIGH_SLS;      }
1047                                         else if(num == '[')  {  tone = MM_SOUND_TONE_CDMA_MED_SLS;      }
1048                                         else if(num == ']')  {  tone = MM_SOUND_TONE_CDMA_LOW_SLS;      }
1049                                         else if(num == '^')  {  tone =MM_SOUND_TONE_CDMA_HIGH_S_X4;     }
1050                                         else if(num == '_')  {  tone =MM_SOUND_TONE_CDMA_MED_S_X4;      }
1051                                         else if(num == 'a')  {  tone =MM_SOUND_TONE_CDMA_LOW_S_X4;      }
1052                                         else if(num == 'b')  {  tone =MM_SOUND_TONE_CDMA_HIGH_PBX_L;    }
1053                                         else if(num == 'c')  {  tone =MM_SOUND_TONE_CDMA_MED_PBX_L;     }
1054                                         else if(num == 'd')  {  tone =MM_SOUND_TONE_CDMA_LOW_PBX_L;     }
1055                                         else if(num == 'e')  {  tone =MM_SOUND_TONE_CDMA_HIGH_PBX_SS;   }
1056                                         else if(num == 'f')  {  tone =MM_SOUND_TONE_CDMA_MED_PBX_SS;    }
1057                                         else if(num == 'g')  {  tone =MM_SOUND_TONE_CDMA_LOW_PBX_SS;    }
1058                                         else if(num == 'h')  {  tone =MM_SOUND_TONE_CDMA_HIGH_PBX_SSL;  }
1059                                         else if(num == 'i')  {          tone =MM_SOUND_TONE_CDMA_MED_PBX_SSL;   }
1060                                         else if(num == 'j')  {  tone =MM_SOUND_TONE_CDMA_LOW_PBX_SSL;           }
1061                                         else if(num == 'k')  {  tone =MM_SOUND_TONE_CDMA_HIGH_PBX_SLS;  }
1062                                         else if(num == 'l')  {          tone =MM_SOUND_TONE_CDMA_MED_PBX_SLS;   }
1063                                         else if(num == 'm')  {  tone =MM_SOUND_TONE_CDMA_LOW_PBX_SLS;           }
1064                                         else if(num == 'n')  {  tone =MM_SOUND_TONE_CDMA_HIGH_PBX_S_X4; }
1065                                         else if(num == 'o')  {  tone =MM_SOUND_TONE_CDMA_MED_PBX_S_X4;  }
1066                                         else if(num == 'p')  {  tone =MM_SOUND_TONE_CDMA_LOW_PBX_S_X4;  }
1067                                         else if(num == 'q')  {  tone =MM_SOUND_TONE_CDMA_ALERT_NETWORK_LITE;    }
1068                                         else if(num == 'r')  {  tone =MM_SOUND_TONE_CDMA_ALERT_AUTOREDIAL_LITE; }
1069                                         else if(num == 's')  {  tone =MM_SOUND_TONE_CDMA_ONE_MIN_BEEP;  }
1070                                         else if(num == 't')  {  tone =MM_SOUND_TONE_CDMA_KEYPAD_VOLUME_KEY_LITE;                }
1071                                         else if(num == 'u')  {  tone =MM_SOUND_TONE_CDMA_PRESSHOLDKEY_LITE;     }
1072                                         else if(num == 'v')  {  tone =MM_SOUND_TONE_CDMA_ALERT_INCALL_LITE;     }
1073                                         else if(num == 'w')  {  tone =MM_SOUND_TONE_CDMA_EMERGENCY_RINGBACK;    }
1074                                         else if(num == 'x')  {  tone =MM_SOUND_TONE_CDMA_ALERT_CALL_GUARD;      }
1075                                         else if(num == 'y')  {  tone =MM_SOUND_TONE_CDMA_SOFT_ERROR_LITE;       }
1076                                         else if(num == 'z')  {  tone =MM_SOUND_TONE_CDMA_CALLDROP_LITE; }
1077                                         else if(num == '{')  {  tone =MM_SOUND_TONE_LOW_FRE;    }
1078                                         else if(num == '}')  {  tone =MM_SOUND_TONE_MED_FRE;    }
1079                                         else if(num == '~')  {  tone =MM_SOUND_TONE_HIGH_FRE; }
1080
1081                                         stream_type = strtok(NULL, " ");
1082
1083                                         tok = strtok(NULL, " ");
1084                                         if(tok)  volume = (double)atof(tok);
1085
1086                                         tok = strtok(NULL, " ");
1087                                         if(tok)
1088                                         {
1089                                                 tonetime = atoi(tok);
1090                                         }
1091                                         else
1092                                         {
1093                                                 tonetime = MIN_TONE_PLAY_TIME;
1094                                         }
1095
1096                                         debug_log("stream type: %s\t volume is %f\t tonetime: %d\n", stream_type, volume, tonetime);
1097                                         ret = mm_sound_play_tone_with_stream_info(tone, stream_type, -1, volume, tonetime, &handle);
1098                                         if(ret<0)
1099                                                 debug_log ("[magpie] Play DTMF sound with stream type cannot be played ! %d\n", handle);
1100                                 }
1101                         }
1102                         else if (strncmp (cmd, "b",1) == 0)
1103                         {
1104                                 DIR     *basedir;
1105                                 struct dirent *entry;
1106                                 struct stat file_stat;
1107                                 char fullpath[MAX_PATH_LEN]="";
1108                                 struct timespec start_time = {0,};
1109                                 struct timespec current_time = {0,};
1110
1111                                 if(g_dir_name[strlen(g_dir_name)-1] == '/')
1112                                         g_dir_name[strlen(g_dir_name)-1] = '\0';
1113
1114                                 basedir = opendir(g_dir_name);
1115                                 if(basedir != NULL)
1116                                 {
1117                                         while( (entry = readdir(basedir)) != NULL)
1118                                         {
1119                                                 int playfail =0;
1120                                                 int mywait = 0;
1121                                                 if(entry->d_name[0] == '.')
1122                                                         continue;
1123                                                 memset(fullpath, '\0' ,sizeof(fullpath));
1124                                                 snprintf(fullpath, sizeof(fullpath)-1,"%s/%s", g_dir_name, entry->d_name);
1125                                                 debug_log("Try %s\n", fullpath);
1126
1127                                                 if (lstat(fullpath, &file_stat) == -1)
1128                                                         continue;
1129
1130                                                 if(S_ISREG(file_stat.st_mode))
1131                                                 {
1132                                                         test_callback_done = 0 ;
1133                                                         start_time.tv_sec = (long int)(time(NULL));
1134                                                         start_time.tv_nsec = 0;
1135                                                         ret = mm_sound_play_sound(fullpath, g_volume_type, test_callback, NULL, &handle);
1136                                                         if(ret != MM_ERROR_NONE)
1137                                                         {
1138                                                                 debug_log("Play file error : %s\n", fullpath);
1139                                                                 sleep(4);
1140                                                                 playfail = 1;
1141                                                         }
1142                                                 }
1143                                                 else
1144                                                 {
1145                                                         debug_log("this is not regular file : %s\n", fullpath);
1146                                                         playfail = 1;
1147                                                 }
1148                                                 while((test_callback_done == 0) && (playfail ==0))
1149                                                 {
1150                                                         current_time.tv_sec = (long int)(time(NULL));
1151                                                         current_time.tv_nsec = 0;
1152                                                         if(current_time.tv_sec - start_time.tv_sec > 200)
1153                                                         {
1154                                                                 if((++mywait)%5 == 0)
1155                                                                 {
1156                                                                         debug_log("I'm waiting callback for %d seconds after play %s\n",
1157                                                                                         (int)(current_time.tv_sec - start_time.tv_sec),
1158                                                                                         fullpath);
1159                                                                 }
1160                                                         }
1161                                                         sleep(2);
1162                                                 }
1163                                                 debug_log("goto next file\n");
1164                                         }
1165                                         closedir(basedir);
1166                                 }
1167                                 else
1168                                 {
1169                                         debug_log("Cannot Open such a directory %s\n", g_dir_name);
1170                                 }
1171
1172                         }
1173
1174                 else if (strncmp (cmd, "c",1) == 0)
1175                 {
1176                         soundparam.volume = g_volume_value;
1177                         soundparam.loop = -1;   /* loop case */
1178                         soundparam.callback = mycallback;
1179                         soundparam.data = NULL;
1180                         soundparam.mem_ptr = NULL;
1181                         soundparam.mem_size = 0;
1182                         soundparam.filename = g_file_name;
1183                         soundparam.volume_config = g_volume_type;
1184
1185                         if ((mm_sound_play_sound_ex (&soundparam, &handle))<0)
1186                                 debug_log ("Play EX sound cannot be played !\n");
1187
1188                         debug_log ("Ex sound is played Handle is [%d]\n", handle);
1189                 }
1190                 else if (strncmp (cmd, "f",1) == 0) {
1191                         g_menu_state=CURRENT_STATUS_FILENAME;
1192                 }
1193
1194                 else if (strncmp (cmd, "d",1) == 0) {
1195                         g_menu_state=CURRENT_STATUS_DIRNAME;
1196                 }
1197                 else if (strncmp (cmd, "s",1) == 0) {
1198                         if(mm_sound_stop_sound(handle))
1199                                 debug_log (" Cannot stop sound !!! %d \n", handle);
1200                 }
1201                 else if (strncmp (cmd, "1",1) == 0) {
1202                         //ap to spk
1203                         g_print("Not supported - Set path for speaker playback\n");
1204                 }
1205
1206                 else if (strncmp (cmd, "2",1) == 0) {
1207                         //ap to headset
1208                         g_print("Not supported - Set path for headset playback\n");
1209                 }
1210                 else if (strncmp (cmd, "3",1) == 0) {
1211
1212                 }
1213                 else if (strncmp (cmd, "4",1) == 0) {
1214                         //recording
1215                         g_print("Not supported - Set path for recording with main mic\n");
1216                 }
1217                 else if (strncmp (cmd, "5",1) == 0) {
1218
1219                 }
1220                 else if (strncmp (cmd, "6",1) == 0) {
1221                         //voice call
1222                         g_print("Not supported - Set path for voicecall\n");
1223                 }
1224                 else if (strncmp (cmd, "7",1) == 0) {
1225                         //voicecall release
1226                         g_print("Not supported - release path for voicecall\n");
1227                 }
1228                 else if (strncmp (cmd, "8",1) == 0) {
1229                         //voice call
1230                         g_print("Not supported - Set path for VT call\n");
1231                 }
1232
1233                 else if (strncmp (cmd, "9",1) == 0) {
1234                         //voicecall release
1235                         g_print("Not supported - release path for VT call\n");
1236                 }
1237
1238                 /* -------------------------- Route Test : Starts -------------------------- */
1239 #if 0
1240                 g_print("==================================================================\n");
1241                 g_print("       Audio route APIs\n");
1242                 g_print("==================================================================\n");
1243                 g_print("u : Foreach Available Routes \t");
1244                 g_print("i : Get Active Devices     \n");
1245                 g_print("o : Add Available Routes Callback   \t");
1246                 g_print("O : Remove Available Routes Callback   \n");
1247                 g_print("p : Add Active Route Callback\t");
1248                 g_print("P : Remove Active Route Callback \n");
1249                 g_print("{ : Get BT A2DP Status\n");
1250 #endif
1251                 else if(strncmp(cmd, "z", 1) == 0) {
1252                         if(MM_ERROR_NONE != mm_session_init(MM_SESSION_TYPE_CALL))
1253                         {
1254                                 g_print("Call session init failed\n");
1255                         }
1256                 }
1257                 else if(strncmp(cmd, "Z", 1) == 0) {
1258                         if(MM_ERROR_NONE != mm_session_init(MM_SESSION_TYPE_VIDEOCALL))
1259                         {
1260                                 g_print("VideoCall session init failed\n");
1261                         }
1262                 }
1263                 else if(strncmp(cmd, "N", 1) == 0) {
1264                         if(MM_ERROR_NONE != mm_session_init(MM_SESSION_TYPE_NOTIFY))
1265                         {
1266                                 g_print("Notify session init failed\n");
1267                         }
1268                 }
1269                 else if(strncmp(cmd, "n", 1) == 0) {
1270                         if(MM_ERROR_NONE != mm_session_init(MM_SESSION_TYPE_VOIP))
1271                         {
1272                                 g_print("VOIP session init failed\n");
1273                         }
1274                 }
1275                 else if(strncmp(cmd, "v", 1) == 0) {
1276                         if(MM_ERROR_NONE != mm_session_finish())
1277                         {
1278                                 g_print("Call session finish failed\n");
1279                         }
1280                 }
1281
1282                 else if(strncmp(cmd, "L", 1) == 0) {
1283                         int ret = 0;
1284                         mm_sound_device_flags_e flags = MM_SOUND_DEVICE_ALL_FLAG;
1285                         MMSoundDeviceList_t device_list;
1286                         mm_sound_device_type_e device_type = 0;
1287                         mm_sound_device_io_direction_e io_direction = 0;
1288                         mm_sound_device_state_e state = 0;
1289                         int id = 0;
1290                         char *name = NULL;
1291                         MMSoundDevice_t device_h = NULL;
1292                         int dret = MM_ERROR_NONE;
1293
1294                         ret = mm_sound_get_current_device_list(flags, &device_list);
1295                         if (ret) {
1296                                 g_print("failed to mm_sound_get_current_device_list(), ret[0x%x]\n", ret);
1297                         } else {
1298                                 g_print("device_list[%p], device_h[%p]\n", device_list, device_h);
1299                                 do {
1300                                         dret = mm_sound_get_next_device (device_list, &device_h);
1301                                         if (dret) {
1302                                                 debug_error("failed to mm_sound_get_next_device(), dret[0x%x]\n", dret);
1303                                         } else {
1304                                                 ret = mm_sound_get_device_type(device_h, &device_type);
1305                                                 if (ret) {
1306                                                         debug_error("failed to mm_sound_get_device_type()\n");
1307                                                 }
1308                                                 ret = mm_sound_get_device_io_direction(device_h, &io_direction);
1309                                                 if (ret) {
1310                                                         debug_error("failed to mm_sound_get_device_io_direction()\n");
1311                                                 }
1312                                                 ret = mm_sound_get_device_state(device_h, &state);
1313                                                 if (ret) {
1314                                                         debug_error("failed to mm_sound_get_device_state()\n");
1315                                                 }
1316                                                 ret = mm_sound_get_device_id(device_h, &id);
1317                                                 if (ret) {
1318                                                         debug_error("failed to mm_sound_get_device_id()\n");
1319                                                 }
1320                                                 ret = mm_sound_get_device_name(device_h, &name);
1321                                                 if (ret) {
1322                                                         debug_error("failed to mm_sound_get_device_name()\n");
1323                                                 }
1324                                                 debug_log("*** --- [NEXT DEVICE] type[%d], id[%d], io_direction[%d], state[%d], name[%s]\n", device_type, id, io_direction, state, name);
1325                                         }
1326                                 } while (dret == MM_ERROR_NONE);
1327                                 do {
1328                                         dret = MM_ERROR_NONE;
1329                                         dret = mm_sound_get_prev_device (device_list, &device_h);
1330                                         if (dret) {
1331                                                 debug_error("failed to mm_sound_get_prev_device(), dret[0x%x]\n", dret);
1332                                         } else {
1333                                                 ret = mm_sound_get_device_type(device_h, &device_type);
1334                                                 if (ret) {
1335                                                         debug_error("failed to mm_sound_get_device_type()\n");
1336                                                 }
1337                                                 ret = mm_sound_get_device_io_direction(device_h, &io_direction);
1338                                                 if (ret) {
1339                                                         debug_error("failed to mm_sound_get_device_io_direction()\n");
1340                                                 }
1341                                                 ret = mm_sound_get_device_state(device_h, &state);
1342                                                 if (ret) {
1343                                                         debug_error("failed to mm_sound_get_device_state()\n");
1344                                                 }
1345                                                 ret = mm_sound_get_device_id(device_h, &id);
1346                                                 if (ret) {
1347                                                         debug_error("failed to mm_sound_get_device_id()\n");
1348                                                 }
1349                                                 ret = mm_sound_get_device_name(device_h, &name);
1350                                                 if (ret) {
1351                                                         debug_error("failed to mm_sound_get_device_name()\n");
1352                                                 }
1353                                                 debug_log("*** --- [PREV DEVICE] type[%d], id[%d], io_direction[%d], state[%d], name[%s]\n", device_type, id, io_direction, state, name);
1354                                         }
1355                                 } while (dret == MM_ERROR_NONE);
1356                         }
1357                 }
1358
1359                 else if(strncmp(cmd, "I", 1) == 0) {
1360                         int ret = 0;
1361                         MMSoundDevice_t device_h = NULL;
1362                         mm_sound_device_type_e device_type = 0;
1363                         mm_sound_device_io_direction_e io_direction = 0;
1364                         mm_sound_device_state_e state = 0;
1365                         char *name;
1366                         int id = 0, input_id = 0;
1367                         char input_string[128];
1368
1369                         fflush(stdin);
1370                         g_print ("> Input id : ");
1371
1372                         if (fgets(input_string, sizeof(input_string)-1, stdin)) {
1373                                 input_id = atoi(input_string);
1374
1375                                 ret = mm_sound_get_device_by_id(input_id, &device_h);
1376                                 if (ret == MM_ERROR_NONE) {
1377                                         ret = mm_sound_get_device_type(device_h, &device_type);
1378                                         if (ret)
1379                                                 g_print("failed to mm_sound_get_device_type()\n");
1380                                         ret = mm_sound_get_device_io_direction(device_h, &io_direction);
1381                                         if (ret)
1382                                                 g_print("failed to mm_sound_get_device_io_direction()\n");
1383                                         ret = mm_sound_get_device_state(device_h, &state);
1384                                         if (ret)
1385                                                 g_print("failed to mm_sound_get_device_state()\n");
1386                                         ret = mm_sound_get_device_id(device_h, &id);
1387                                         if (ret)
1388                                                 g_print("failed to mm_sound_get_device_id()\n");
1389                                         ret = mm_sound_get_device_name(device_h, &name);
1390                                         if (ret)
1391                                                 g_print("failed to mm_sound_get_device_name()\n");
1392                                         g_print("*** --- type[%d], id[%d], io_direction[%d], state[%d], name[%s]\n", device_type, id, io_direction, state, name);
1393                                 } else {
1394                                         g_print("failed to mm_sound_get_device_by_id()\n");
1395                                 }
1396                         } else {
1397                                 g_print("### fgets return  NULL\n");
1398                         }
1399                 }
1400
1401                 else if(strncmp(cmd, "C", 1) == 0) {
1402                         int ret = 0;
1403                         char input_string[128];
1404                         mm_sound_device_flags_e device_flag_1 = MM_SOUND_DEVICE_ALL_FLAG;
1405                         mm_sound_device_flags_e device_flag_2 = MM_SOUND_DEVICE_ALL_FLAG;
1406                         mm_sound_device_flags_e device_flag_3 = MM_SOUND_DEVICE_ALL_FLAG;
1407
1408                         char flag_1, flag_2, flag_3;
1409
1410                         fflush(stdin);
1411                         g_print ("1. IO_DIRECTION_IN_FLAG\n");
1412                         g_print ("2. IO_DIRECTION_OUT_FLAG\n");
1413                         g_print ("3. IO_DIRECTION_BOTH_FLAG\n");
1414                         g_print ("4. TYPE_INTERNAL_FLAG\n");
1415                         g_print ("5. TYPE_EXTERNAL_FLAG\n");
1416                         g_print ("6. STATE_DEACTIVATED_FLAG\n");
1417                         g_print ("7. STATE_ACTIVATED_FLAG\n");
1418                         g_print ("8. ALL_FLAG\n");
1419                         g_print("> select flag numbers (total 3):  (eg. 2 5 7)");
1420
1421                         if (fgets(input_string, sizeof(input_string)-1, stdin)) {
1422                                 g_print ("### fgets return  NULL\n");
1423                         }
1424                         flag_1 = input_string[0];
1425                         flag_2 = input_string[2];
1426                         flag_3 = input_string[4];
1427
1428                         if(flag_1 == '1') { device_flag_1 = MM_SOUND_DEVICE_IO_DIRECTION_IN_FLAG; }
1429                         else if(flag_1 == '2') { device_flag_1 = MM_SOUND_DEVICE_IO_DIRECTION_OUT_FLAG; }
1430                         else if(flag_1 == '3') { device_flag_1 = MM_SOUND_DEVICE_IO_DIRECTION_BOTH_FLAG; }
1431                         else if(flag_1 == '4') { device_flag_1 = MM_SOUND_DEVICE_TYPE_INTERNAL_FLAG; }
1432                         else if(flag_1 == '5') { device_flag_1 = MM_SOUND_DEVICE_TYPE_EXTERNAL_FLAG; }
1433                         else if(flag_1 == '6') { device_flag_1 = MM_SOUND_DEVICE_STATE_DEACTIVATED_FLAG; }
1434                         else if(flag_1 == '7') { device_flag_1 = MM_SOUND_DEVICE_STATE_ACTIVATED_FLAG; }
1435                         else if(flag_1 == '8') { device_flag_1 = MM_SOUND_DEVICE_ALL_FLAG; }
1436                         if(flag_2 == '1') { device_flag_2 = MM_SOUND_DEVICE_IO_DIRECTION_IN_FLAG; }
1437                         else if(flag_2 == '2') { device_flag_2 = MM_SOUND_DEVICE_IO_DIRECTION_OUT_FLAG; }
1438                         else if(flag_2 == '3') { device_flag_2 = MM_SOUND_DEVICE_IO_DIRECTION_BOTH_FLAG; }
1439                         else if(flag_2 == '4') { device_flag_2 = MM_SOUND_DEVICE_TYPE_INTERNAL_FLAG; }
1440                         else if(flag_2 == '5') { device_flag_2 = MM_SOUND_DEVICE_TYPE_EXTERNAL_FLAG; }
1441                         else if(flag_2 == '6') { device_flag_2 = MM_SOUND_DEVICE_STATE_DEACTIVATED_FLAG; }
1442                         else if(flag_2 == '7') { device_flag_2 = MM_SOUND_DEVICE_STATE_ACTIVATED_FLAG; }
1443                         else if(flag_2 == '8') { device_flag_2 = MM_SOUND_DEVICE_ALL_FLAG; }
1444                         if(flag_3 == '1') { device_flag_3 = MM_SOUND_DEVICE_IO_DIRECTION_IN_FLAG; }
1445                         else if(flag_3 == '2') { device_flag_3 = MM_SOUND_DEVICE_IO_DIRECTION_OUT_FLAG; }
1446                         else if(flag_3 == '3') { device_flag_3 = MM_SOUND_DEVICE_IO_DIRECTION_BOTH_FLAG; }
1447                         else if(flag_3 == '4') { device_flag_3 = MM_SOUND_DEVICE_TYPE_INTERNAL_FLAG; }
1448                         else if(flag_3 == '5') { device_flag_3 = MM_SOUND_DEVICE_TYPE_EXTERNAL_FLAG; }
1449                         else if(flag_3 == '6') { device_flag_3 = MM_SOUND_DEVICE_STATE_DEACTIVATED_FLAG; }
1450                         else if(flag_3 == '7') { device_flag_3 = MM_SOUND_DEVICE_STATE_ACTIVATED_FLAG; }
1451                         else if(flag_3 == '8') { device_flag_3 = MM_SOUND_DEVICE_ALL_FLAG; }
1452                         g_print("device_connected_callback");
1453                         ret = mm_sound_add_device_connected_callback(device_flag_1|device_flag_2|device_flag_3, device_connected_cb, NULL, &g_subs_id_device_conn);
1454                         if (ret) {
1455                                 g_print("failed to mm_sound_add_device_connected_callback(), ret[0x%x]\n", ret);
1456                         } else {
1457                                 g_print("device_flags[0x%x], callback fun[%p], subs_id[%u]\n", device_flag_1|device_flag_2|device_flag_3, device_connected_cb, g_subs_id_device_conn);
1458                         }
1459                 }
1460
1461                 else if(strncmp(cmd, "D", 1) == 0) {
1462                         int ret = 0;
1463                         ret = mm_sound_remove_device_connected_callback(g_subs_id_device_conn);
1464                         if (ret) {
1465                                 g_print("failed to mm_sound_remove_device_connected_callback(), ret[0x%x]\n", ret);
1466                         }
1467                 }
1468                 else if(strncmp(cmd, "Q", 1) == 0) {
1469                         int ret = 0;
1470                         char input_string[128];
1471                         mm_sound_device_flags_e device_flag_1 = MM_SOUND_DEVICE_ALL_FLAG;
1472                         mm_sound_device_flags_e device_flag_2 = MM_SOUND_DEVICE_ALL_FLAG;
1473                         mm_sound_device_flags_e device_flag_3 = MM_SOUND_DEVICE_ALL_FLAG;
1474
1475                         char flag_1, flag_2, flag_3;
1476
1477                         fflush(stdin);
1478                         g_print ("1. IO_DIRECTION_IN_FLAG\n");
1479                         g_print ("2. IO_DIRECTION_OUT_FLAG\n");
1480                         g_print ("3. IO_DIRECTION_BOTH_FLAG\n");
1481                         g_print ("4. TYPE_INTERNAL_FLAG\n");
1482                         g_print ("5. TYPE_EXTERNAL_FLAG\n");
1483                         g_print ("6. STATE_DEACTIVATED_FLAG\n");
1484                         g_print ("7. STATE_ACTIVATED_FLAG\n");
1485                         g_print ("8. ALL_FLAG\n");
1486                         g_print("> select flag numbers (total 3):  (eg. 2 5 7)");
1487
1488                         if (fgets(input_string, sizeof(input_string)-1, stdin)) {
1489                                 g_print ("### fgets return  NULL\n");
1490                         }
1491                         flag_1 = input_string[0];
1492                         flag_2 = input_string[2];
1493                         flag_3 = input_string[4];
1494
1495                         if(flag_1 == '1') { device_flag_1 = MM_SOUND_DEVICE_IO_DIRECTION_IN_FLAG; }
1496                         else if(flag_1 == '2') { device_flag_1 = MM_SOUND_DEVICE_IO_DIRECTION_OUT_FLAG; }
1497                         else if(flag_1 == '3') { device_flag_1 = MM_SOUND_DEVICE_IO_DIRECTION_BOTH_FLAG; }
1498                         else if(flag_1 == '4') { device_flag_1 = MM_SOUND_DEVICE_TYPE_INTERNAL_FLAG; }
1499                         else if(flag_1 == '5') { device_flag_1 = MM_SOUND_DEVICE_TYPE_EXTERNAL_FLAG; }
1500                         else if(flag_1 == '6') { device_flag_1 = MM_SOUND_DEVICE_STATE_DEACTIVATED_FLAG; }
1501                         else if(flag_1 == '7') { device_flag_1 = MM_SOUND_DEVICE_STATE_ACTIVATED_FLAG; }
1502                         else if(flag_1 == '8') { device_flag_1 = MM_SOUND_DEVICE_ALL_FLAG; }
1503                         if(flag_2 == '1') { device_flag_2 = MM_SOUND_DEVICE_IO_DIRECTION_IN_FLAG; }
1504                         else if(flag_2 == '2') { device_flag_2 = MM_SOUND_DEVICE_IO_DIRECTION_OUT_FLAG; }
1505                         else if(flag_2 == '3') { device_flag_2 = MM_SOUND_DEVICE_IO_DIRECTION_BOTH_FLAG; }
1506                         else if(flag_2 == '4') { device_flag_2 = MM_SOUND_DEVICE_TYPE_INTERNAL_FLAG; }
1507                         else if(flag_2 == '5') { device_flag_2 = MM_SOUND_DEVICE_TYPE_EXTERNAL_FLAG; }
1508                         else if(flag_2 == '6') { device_flag_2 = MM_SOUND_DEVICE_STATE_DEACTIVATED_FLAG; }
1509                         else if(flag_2 == '7') { device_flag_2 = MM_SOUND_DEVICE_STATE_ACTIVATED_FLAG; }
1510                         else if(flag_2 == '8') { device_flag_2 = MM_SOUND_DEVICE_ALL_FLAG; }
1511                         if(flag_3 == '1') { device_flag_3 = MM_SOUND_DEVICE_IO_DIRECTION_IN_FLAG; }
1512                         else if(flag_3 == '2') { device_flag_3 = MM_SOUND_DEVICE_IO_DIRECTION_OUT_FLAG; }
1513                         else if(flag_3 == '3') { device_flag_3 = MM_SOUND_DEVICE_IO_DIRECTION_BOTH_FLAG; }
1514                         else if(flag_3 == '4') { device_flag_3 = MM_SOUND_DEVICE_TYPE_INTERNAL_FLAG; }
1515                         else if(flag_3 == '5') { device_flag_3 = MM_SOUND_DEVICE_TYPE_EXTERNAL_FLAG; }
1516                         else if(flag_3 == '6') { device_flag_3 = MM_SOUND_DEVICE_STATE_DEACTIVATED_FLAG; }
1517                         else if(flag_3 == '7') { device_flag_3 = MM_SOUND_DEVICE_STATE_ACTIVATED_FLAG; }
1518                         else if(flag_3 == '8') { device_flag_3 = MM_SOUND_DEVICE_ALL_FLAG; }
1519                         g_print("add_device_info_changed");
1520                         ret = mm_sound_add_device_information_changed_callback(device_flag_1 | device_flag_2 | device_flag_3, device_info_changed_cb, NULL, &g_subs_id_device_info);
1521                         if (ret) {
1522                                 g_print("failed to mm_sound_add_device_information_changed_callback(), ret[0x%x]\n", ret);
1523                         } else {
1524                                 g_print("device_flags[0x%x], callback fun[%p], subs_id[%u]\n", device_flag_1|device_flag_2|device_flag_3, device_info_changed_cb, g_subs_id_device_info);
1525                         }
1526                 }
1527
1528                 else if(strncmp(cmd, "W", 1) == 0) {
1529                         int ret = 0;
1530                         ret = mm_sound_remove_device_information_changed_callback(g_subs_id_device_info);
1531                         if (ret) {
1532                                 g_print("failed to mm_sound_remove_device_information_changed_callback(), ret[0x%x]\n", ret);
1533                         }
1534                 }
1535
1536                 else if (strncmp(cmd, "x", 1) == 0) {
1537                         quit_program();
1538                 }
1539                 break;
1540
1541         case CURRENT_STATUS_FILENAME:
1542                 input_filename(cmd);
1543                 g_menu_state=CURRENT_STATUS_MAINMENU;
1544                 break;
1545
1546         case CURRENT_STATUS_DIRNAME:
1547                 input_dirname(cmd);
1548                 g_menu_state=CURRENT_STATUS_MAINMENU;
1549                 break;
1550         case CURRENT_STATUS_POSITION:
1551                 break;
1552         }
1553         //g_timeout_add(100, timeout_menu_display, 0);
1554 }
1555
1556 void volume_change_callback(volume_type_t type, unsigned int volume, void *user_data)
1557 {
1558         if (type == VOLUME_TYPE_MEDIA)
1559                 g_print("Volume Callback Runs :::: MEDIA VALUME %d\n", volume);
1560 }
1561
1562 int main(int argc, char *argv[])
1563 {
1564         int ret = 0;
1565
1566         stdin_channel = g_io_channel_unix_new(0);
1567         g_io_add_watch(stdin_channel, G_IO_IN, (GIOFunc)input, NULL);
1568         g_loop = g_main_loop_new (NULL, 1);
1569
1570         MMSOUND_STRNCPY(g_file_name, POWERON_FILE, MAX_STRING_LEN);
1571         g_print("\nThe input filename is '%s' \n\n",g_file_name);
1572
1573         /* test volume changed callback */
1574         g_print("callback function addr :: %p\n", volume_change_callback);
1575         g_volume_type = VOLUME_TYPE_MEDIA;
1576         ret = mm_sound_volume_get_value(g_volume_type, &g_volume_value);
1577         if(ret < 0) {
1578                 g_print("mm_sound_volume_get_value 0x%x\n", ret);
1579         }
1580         mm_sound_add_volume_changed_callback(volume_change_callback, (void*) &g_volume_type, &g_subs_id_volume);
1581
1582         displaymenu();
1583         g_main_loop_run (g_loop);
1584
1585         return 0;
1586 }
1587