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