Fix coverity defects
[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 #include "../include/mm_sound_focus.h"
33 #include "../include/mm_sound_common.h"
34 #include "../include/mm_sound_private.h"
35 #include "../include/mm_sound_pa_client.h"
36
37 #include <glib.h>
38
39 #include <pthread.h>
40
41 #include <sys/types.h>
42 #include <sys/stat.h>
43 #include <unistd.h>
44 #include <dirent.h>
45 #include <vconf.h>
46
47 #define POWERON_FILE    "/usr/share/feedback/sound/operation/power_on.wav"
48 #define KEYTONE_FILE    "/usr/share/feedback/sound/operation/operation.wav"
49
50 enum {
51         CURRENT_STATUS_MAINMENU = 0,
52         CURRENT_STATUS_FILENAME = 1,
53         CURRENT_STATUS_POSITION = 2,
54         CURRENT_STATUS_DIRNAME = 3,
55 };
56
57 int g_menu_state = CURRENT_STATUS_MAINMENU;
58 volume_type_t g_volume_type = VOLUME_TYPE_MEDIA;
59 unsigned int g_volume_value;
60 GIOChannel *stdin_channel;
61 char g_file_name[MAX_STRING_LEN];
62 char g_dir_name[MAX_PATH_LEN];
63 int g_focus_watch_index = -1;
64 GMainLoop* g_loop;
65 unsigned int g_subs_id_test, g_subs_id_volume, g_subs_id_device_conn, g_subs_id_device_state;
66
67 static void interpret(char *buf);
68 gboolean timeout_menu_display(void *data);
69 gboolean timeout_quit_program(void *data);
70 gboolean input(GIOChannel *channel);
71
72 void mycallback(void *data, int id)
73 {
74         char *str = (char*)data;
75         if (data != NULL)
76                 debug_log("mycallback called (user data:%s ,id:%d)", str, id);
77         else
78                 debug_log("mycallback called (no user data)");
79 }
80 volatile char test_callback_done;
81 void test_callback(void *data, int id)
82 {
83         debug_log("test_callback is called");
84         test_callback_done = 1;
85 }
86 void mm_sound_test_cb1(int a, void *user_data)
87 {
88         debug_log("dbus test user callback called: param(%d), userdata(%d)", a, (int)user_data);
89         g_print("my callback pid : %u  tid : %ld\n", getpid(), pthread_self());
90 }
91 void device_connected_cb(MMSoundDevice_t device_h, bool is_connected, void *user_data)
92 {
93         int ret = 0;
94         mm_sound_device_type_e device_type = 0;
95         mm_sound_device_io_direction_e io_direction = 0;
96         mm_sound_device_state_e state = 0;
97         int id = 0;
98         int vendor_id = -1, product_id = -1;
99         char *name = NULL;
100
101         debug_log("*** device_connected_cb is called, device_h[%p], is_connected[%d], user_data[%p]", device_h, is_connected, user_data);
102         ret = mm_sound_get_device_type(device_h, &device_type);
103         if (ret)
104                 debug_error("failed to mm_sound_get_device_type()");
105         ret = mm_sound_get_device_io_direction(device_h, &io_direction);
106         if (ret)
107                 debug_error("failed to mm_sound_get_device_io_direction()");
108         ret = mm_sound_get_device_state(device_h, &state);
109         if (ret)
110                 debug_error("failed to mm_sound_get_device_state()");
111         ret = mm_sound_get_device_id(device_h, &id);
112         if (ret)
113                 debug_error("failed to mm_sound_get_device_id()");
114         ret = mm_sound_get_device_name(device_h, &name);
115         if (ret)
116                 debug_error("failed to mm_sound_get_device_name()");
117         ret = mm_sound_get_device_vendor_id(device_h, &vendor_id);
118         if (ret)
119                 debug_error("failed to mm_sound_get_device_vendor_id()");
120         ret = mm_sound_get_device_product_id(device_h, &product_id);
121         if (ret)
122                 debug_error("failed to mm_sound_get_device_produt_id()");
123         debug_log("*** --- type[%d], id[%d], io_direction[%d], state[%d], name[%s], "
124                         "vendor-id(%04x) product-id(%04x)",
125                         device_type, id, io_direction, state, name, vendor_id, product_id);
126 }
127 void device_state_changed_cb(MMSoundDevice_t device_h, mm_sound_device_state_e new_state, void *user_data)
128 {
129         int ret = 0;
130         mm_sound_device_type_e device_type = 0;
131         mm_sound_device_io_direction_e io_direction = 0;
132         mm_sound_device_state_e state = 0;
133         int id = 0;
134         char *name = NULL;
135         int vendor_id = -1, product_id = -1;
136
137         debug_log("*** device_state_changed_cb is called, device_h[%p], state[%d], user_data[%p]", device_h, new_state, user_data);
138         ret = mm_sound_get_device_type(device_h, &device_type);
139         if (ret)
140                 debug_error("failed to mm_sound_get_device_type()");
141         ret = mm_sound_get_device_io_direction(device_h, &io_direction);
142         if (ret)
143                 debug_error("failed to mm_sound_get_device_io_direction()");
144         ret = mm_sound_get_device_state(device_h, &state);
145         if (ret)
146                 debug_error("failed to mm_sound_get_device_state()");
147         ret = mm_sound_get_device_id(device_h, &id);
148         if (ret)
149                 debug_error("failed to mm_sound_get_device_id()");
150         ret = mm_sound_get_device_name(device_h, &name);
151         if (ret)
152                 debug_error("failed to mm_sound_get_device_name()");
153         ret = mm_sound_get_device_vendor_id(device_h, &vendor_id);
154         if (ret)
155                 debug_error("failed to mm_sound_get_device_vendor_id()");
156         ret = mm_sound_get_device_product_id(device_h, &product_id);
157         if (ret)
158                 debug_error("failed to mm_sound_get_device_produt_id()");
159         debug_log("*** --- type[%d], id[%d], io_direction[%d], state[%d], name[%s], "
160                         "vendor-id(%04x) product-id(%04x)",
161                         device_type, id, io_direction, state, name, vendor_id, product_id);
162 }
163
164 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)
165 {
166         char *_state = NULL;
167         if (state == FOCUS_IS_RELEASED)
168                 _state = "RELEASED";
169         else
170                 _state = "ACQUIRED";
171         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]",
172                         index, type, _state, reason_for_change, option, ext_info, (char*)user_data);
173 }
174 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)
175 {
176         char *_state = NULL;
177         if (state == FOCUS_IS_RELEASED)
178                 _state = "RELEASED";
179         else
180                 _state = "ACQUIRED";
181         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]",
182                         index, type, _state, reason_for_change, option, ext_info, (char*)user_data);
183 }
184 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)
185 {
186         char *_state = NULL;
187         if (state == FOCUS_IS_RELEASED)
188                 _state = "RELEASED";
189         else
190                 _state = "ACQUIRED";
191         debug_log("*** focus_watch_cb is called, index[%d], focus_type[%d], state[%s], reason_for_change[%s], ext_info[%s], user_data[%s]",
192                         index, type, _state, reason_for_change, ext_info, (char*)user_data);
193 }
194
195 void quit_program()
196 {
197         g_main_loop_quit(g_loop);
198 }
199
200 static void displaymenu()
201 {
202         if (g_menu_state == CURRENT_STATUS_MAINMENU) {
203                 g_print("==================================================================\n");
204                 g_print("       Sound Play APIs\n");
205                 g_print("==================================================================\n");
206                 g_print("k : Key Sound     \t");
207                 g_print("as : play sound with stream type\n");
208                 g_print("FS : Play DTMF with stream type\t");
209                 g_print("b : Play directory\n");
210                 g_print("s : Stop play     \n");
211                 g_print("==================================================================\n");
212                 g_print("       Volume APIs\n");
213                 g_print("==================================================================\n");
214                 g_print("q : Get media    \t");
215                 g_print("w : Inc. media   \t");
216                 g_print("e : Dec. media   \n");
217                 g_print("r : Get system   \t");
218                 g_print("t : Inc. system  \t");
219                 g_print("y : Dec. system  \n");
220                 g_print("g : Get voice   \t");
221                 g_print("h : Inc. voice  \t");
222                 g_print("j : Dec. voice  \n");
223                 g_print("==================================================================\n");
224                 g_print("       Audio route APIs\n");
225                 g_print("==================================================================\n");
226                 g_print("u : Foreach Available Routes \t");
227                 g_print("i : Get Active Devices     \n");
228                 g_print("o : Add Available Routes Callback   \t");
229                 g_print("O : Remove Available Routes Callback   \n");
230                 g_print("p : Add Active Route Callback\t");
231                 g_print("P : Remove Active Route Callback \n");
232                 g_print("{ : Get BT A2DP Status\n");
233                 g_print("} : Set Active Route\n");
234                 g_print("==================================================================\n");
235                 g_print("       Audio device APIs\n");
236                 g_print("==================================================================\n");
237                 g_print("L : Get current list of connected devices \n");
238                 g_print("I : Get device by id \n");
239                 g_print("C : Add device connected callback \t");
240                 g_print("D : Remove device connected callback \n");
241                 g_print("Q : Add device state. changed callback \t");
242                 g_print("W : Remove device state. changed callback \n");
243                 g_print("==================================================================\n");
244                 g_print("       Focus APIs\n");
245                 g_print("==================================================================\n");
246                 g_print("GU : Get Focus id\n");
247                 g_print("SF : Set Focus Callback\t");
248                 g_print("UF : Unset Focus Callback\n");
249                 g_print("DF : Disable Auto Focus Reacquirement\t");
250                 g_print("AF : Acquire Focus\t");
251                 g_print("RF : Release Focus\n");
252                 g_print("WS : Set Focus Watch Callback\t");
253                 g_print("WU : Unset Focus Watch Callback\n");
254                 g_print("==================================================================\n");
255                 g_print("d : Input Directory \t");
256                 g_print("f : Input File name \t");
257                 g_print("x : Exit Program \n");
258                 g_print("==================================================================\n");
259                 g_print(" Input command >>>>>>>> ");
260         } else if (g_menu_state == CURRENT_STATUS_FILENAME) {
261                 g_print(">>>>Input file name to play : ");
262         } else if (g_menu_state == CURRENT_STATUS_DIRNAME) {
263                         g_print(">>>>Input directory which contain audio files : ");
264         } else {
265                 g_print("**** Unknown status.\n");
266                 quit_program();
267         }
268 }
269
270 gboolean timeout_menu_display(void* data)
271 {
272         displaymenu();
273         return FALSE;
274 }
275
276 gboolean timeout_quit_program(void* data)
277 {
278         quit_program();
279         return FALSE;
280 }
281
282 gboolean input(GIOChannel *channel)
283 {
284         GError *err = NULL;
285         gchar *buf = NULL;
286         gsize length = 0;
287
288         if (g_io_channel_read_line(channel, &buf, &length, NULL, &err) == G_IO_STATUS_NORMAL) {
289                 if (length > 1) {
290                         g_strstrip(buf);
291                         interpret(buf);
292                 }
293                 g_free(buf);
294         }
295
296         return TRUE;
297 }
298
299
300 static void input_filename(char *filename)
301 {
302         MMSOUND_STRNCPY(g_file_name, filename, MAX_STRING_LEN);
303         g_print("\nThe input filename is '%s' \n\n", g_file_name);
304
305 }
306
307 static void input_dirname(char *dirname)
308 {
309         MMSOUND_STRNCPY(g_dir_name, dirname, MAX_PATH_LEN);
310         g_print("\nThe input directory is '%s' \n\n", g_dir_name);
311 }
312
313 static void interpret(char *cmd)
314 {
315         int ret = 0;
316         static int handle = -1;
317
318         switch (g_menu_state) {
319         case CURRENT_STATUS_MAINMENU:
320                 if (strncmp(cmd, "GU", 2) == 0) {
321                         int id = 0;
322                         ret = mm_sound_focus_get_id(&id);
323                         if (ret < 0)
324                                 debug_log("mm_sound_focus_get_id() failed with 0x%x", ret);
325                         else
326                                 debug_log("id : %d", id);
327
328                 } else if (strncmp(cmd, "SF", 2) == 0) {
329                         int ret = 0;
330                         char input_string[128];
331                         char flag_1, flag_2;
332                         int id = 2;
333                         char *stream_type = "media";
334                         const char *user_data = "this is user data";
335
336                         fflush(stdin);
337                         g_print("1. Media\n");
338                         g_print("2. Alarm\n");
339                         g_print("3. Notification\n");
340                         g_print("4. Emergency\n");
341                         g_print("5. Voice Information\n");
342                         g_print("6. Ringtone\n");
343                         g_print("7. Ringtone Call\n");
344                         g_print("8. VOIP\n");
345                         g_print("0. Voice Recognition\n");
346                         g_print("> select id and stream type: (eg. 0 3)");
347
348                         if (fgets(input_string, sizeof(input_string)-1, stdin)) {
349                                 flag_1 = input_string[0];
350                                 flag_2 = input_string[2];
351
352                                 if (flag_1 == '0')
353                                         id = 0;
354                                 else if (flag_1 == '1')
355                                         id = 1;
356                                 else if (flag_1 == '2')
357                                         id = 2;
358
359                                 if (flag_2 == '1')
360                                         stream_type = "media";
361                                 else if (flag_2 == '2')
362                                         stream_type = "alarm";
363                                 else if (flag_2 == '3')
364                                         stream_type = "notification";
365                                 else if (flag_2 == '4')
366                                         stream_type = "emergency";
367                                 else if (flag_2 == '5')
368                                         stream_type = "voice-information";
369                                 else if (flag_2 == '6')
370                                         stream_type = "ringtone";
371                                 else if (flag_2 == '7')
372                                         stream_type = "ringtone-call";
373                                 else if (flag_2 == '8')
374                                         stream_type = "voip";
375                                 else if (flag_2 == '0')
376                                         stream_type = "voice-recognition";
377
378                                 ret = mm_sound_register_focus(id, stream_type, (id == 0) ? focus_cb0 : focus_cb1, (void*)user_data);
379                                 if (ret)
380                                         g_print("failed to mm_sound_register_focus(), ret[0x%x]\n", ret);
381                                 else
382                                         g_print("id[%d], stream_type[%s], callback fun[%p]\n", id, stream_type, (id == 0) ? focus_cb0 : focus_cb1);
383
384                         } else {
385                                 g_print("### fgets return  NULL\n");
386                         }
387                 } else if (strncmp(cmd, "UF", 2) == 0) {
388                         int ret = 0;
389                         char input_string[128];
390                         char flag_1;
391                         int id = 2;
392                         fflush(stdin);
393                         g_print("> select id:");
394                         if (fgets(input_string, sizeof(input_string)-1, stdin)) {
395                                 flag_1 = input_string[0];
396                                 if (flag_1 == '0')
397                                         id = 0;
398                                 else if (flag_1 == '1')
399                                         id = 1;
400                                 else if (flag_1 == '2')
401                                         id = 2;
402                                 ret = mm_sound_unregister_focus(id);
403                                 if (ret)
404                                         g_print("failed to mm_sound_unregister_focus(), ret[0x%x]\n", ret);
405                         } else {
406                                 g_print("### fgets return  NULL\n");
407                         }
408                 } else if (strncmp(cmd, "DF", 2) == 0) {
409                         int ret = 0;
410                         char input_string[128];
411                         char flag_1, flag_2;
412                         int id = 2;
413                         bool reacquisition = true;
414                         fflush(stdin);
415                         g_print("1. enable auto reacquirement\n");
416                         g_print("2. disable auto reacquirement\n");
417                         g_print("> select id and option: (eg. 0 1)");
418                         if (fgets(input_string, sizeof(input_string)-1, stdin)) {
419                                 flag_1 = input_string[0];
420                                 flag_2 = input_string[2];
421
422                                 if (flag_1 == '0')
423                                         id = 0;
424                                 else if (flag_1 == '1')
425                                         id = 1;
426                                 else if (flag_1 == '2')
427                                         id = 2;
428
429                                 if (flag_2 == '1')
430                                         reacquisition = true;
431                                 else if (flag_2 == '2')
432                                         reacquisition = false;
433
434                                 ret = mm_sound_set_focus_reacquisition(id, reacquisition);
435                                 if (ret)
436                                         g_print("failed to mm_sound_disable_focus_reacquirement(), ret[0x%x]\n", ret);
437                         } else {
438                                 g_print("### fgets return  NULL\n");
439                         }
440                 }
441
442                 else if (strncmp(cmd, "AF", 2) == 0) {
443                         int ret = 0;
444                         char input_string[128];
445                         char flag_1, flag_2;
446                         int id = 0;
447                         mm_sound_focus_type_e type = FOCUS_FOR_PLAYBACK;
448                         fflush(stdin);
449                         g_print("1. focus for playback\n");
450                         g_print("2. focus for recording\n");
451                         g_print("3. focus for both\n");
452                         g_print("> select id and focus_type: (eg. 0 1)");
453                         if (fgets(input_string, sizeof(input_string)-1, stdin)) {
454                                 flag_1 = input_string[0];
455                                 flag_2 = input_string[2];
456
457                                 if (flag_1 == '0')
458                                         id = 0;
459                                 else if (flag_1 == '1')
460                                         id = 1;
461                                 else
462                                         id = 2;
463
464                                 if (flag_2 == '1')
465                                         type = FOCUS_FOR_PLAYBACK;
466                                 else if (flag_2 == '2')
467                                         type = FOCUS_FOR_CAPTURE;
468                                 else
469                                         type = FOCUS_FOR_BOTH;
470                                 ret = mm_sound_acquire_focus(id, type, "additional_info. for acquire");
471                                 if (ret)
472                                         g_print("failed to mm_sound_acquire_focus(), ret[0x%x]\n", ret);
473
474                         } else {
475                                 g_print("### fgets return  NULL\n");
476                         }
477
478                 } else if (strncmp(cmd, "RF", 2) == 0) {
479                         int ret = 0;
480                         char input_string[128];
481                         char flag_1, flag_2;
482                         int id = 0;
483                         mm_sound_focus_type_e type = FOCUS_FOR_PLAYBACK;
484                         fflush(stdin);
485                         g_print("1. focus for playback\n");
486                         g_print("2. focus for recording\n");
487                         g_print("3. focus for all\n");
488                         g_print("> select id and focus_type: (eg. 0 1)");
489                         if (fgets(input_string, sizeof(input_string)-1, stdin)) {
490                                 flag_1 = input_string[0];
491                                 flag_2 = input_string[2];
492
493                                 if (flag_1 == '0')
494                                         id = 0;
495                                 else if (flag_1 == '1')
496                                         id = 1;
497                                 else
498                                         id = 2;
499
500                                 if (flag_2 == '1')
501                                         type = FOCUS_FOR_PLAYBACK;
502                                 else if (flag_2 == '2')
503                                         type = FOCUS_FOR_CAPTURE;
504                                 else
505                                         type = FOCUS_FOR_BOTH;
506                                 ret = mm_sound_release_focus(id, type, "additional_info. for release");
507                                 if (ret)
508                                         g_print("failed to mm_sound_release_focus(), ret[0x%x]\n", ret);
509
510                         } else {
511                                 g_print("### fgets return  NULL\n");
512                         }
513
514                 } else if (strncmp(cmd, "WS", 2) == 0) {
515                         int ret = 0;
516                         char input_string[128];
517                         char flag_1;
518                         int type = 0;
519                         const char *user_data = "this is user data for watch";
520
521                         fflush(stdin);
522                         g_print("1. playback\n");
523                         g_print("2. recording\n");
524                         g_print("3. both\n");
525                         g_print("> select interest focus type:");
526
527                         if (fgets(input_string, sizeof(input_string)-1, stdin)) {
528                                 flag_1 = input_string[0];
529
530                                 if (flag_1 == '1')
531                                         type = 1;
532                                 else if (flag_1 == '2')
533                                         type = 2;
534                                 else if (flag_1 == '3')
535                                         type = 3;
536                                 else
537                                         type = 1;
538                                 ret = mm_sound_set_focus_watch_callback(type, focus_watch_cb, (void*)user_data, &g_focus_watch_index);
539                                 if (ret)
540                                         g_print("failed to mm_sound_set_focus_watch_callback(), ret[0x%x]\n", ret);
541                                 else
542                                         g_print("index[%d], type[%d], callback fun[%p]\n", g_focus_watch_index, type, focus_watch_cb);
543                         } else {
544                                 g_print("### fgets return  NULL\n");
545                         }
546
547                 } else if (strncmp(cmd, "WU", 2) == 0) {
548                         int ret = 0;
549                         ret = mm_sound_unset_focus_watch_callback(g_focus_watch_index);
550                         if (ret)
551                                 g_print("failed to mm_sound_unset_focus_watch_callback(), ret[0x%x]\n", ret);
552                 } else if (strncmp(cmd, "k", 1) == 0) {
553                         ret = mm_sound_play_keysound(KEYTONE_FILE, 0);
554                         if (ret < 0)
555                                 debug_log("keysound play failed with 0x%x", ret);
556                 } else if (strcmp(cmd, "dbus-m") == 0) {
557                         int ret = 0;
558                         int a = 3;
559                         int b = 4;
560                         int result_val = 0;
561                         g_print("dbus method test call\n");
562                         ret = mm_sound_test(a, b, &result_val);
563                         if (ret)
564                                 g_print("failed to mm_sound_test(), ret[0x%x]\n", ret);
565                         else
566                                 g_print("Got answer : %d\n", result_val);
567
568                 } else if (strcmp(cmd, "dbus-a") == 0) {
569                         int ret = 0;
570                         int user_data = 3;
571                         g_print("dbus method test add callback\n");
572                         g_print("my testsuite pid : %u  tid : %ld\n", getpid(), pthread_self());
573                         ret = mm_sound_add_test_callback(mm_sound_test_cb1, (void *)user_data, &g_subs_id_test);
574                         if (ret)
575                                 g_print("failed to mm_sound_add_test_callback(), ret[0x%x]\n", ret);
576                         else
577                                 g_print("add test callback success\n");
578
579                 } else if (strcmp(cmd, "dbus-r") == 0) {
580                         int ret = 0;
581                         g_print("dbus method test remove callback\n");
582                         ret = mm_sound_remove_test_callback(g_subs_id_test);
583                         if (ret)
584                                 g_print("failed to mm_sound_remove_test_callback(), ret[0x%x]\n", ret);
585                         else
586                                 g_print("remove test callback success\n");
587
588                 } else if (strncmp(cmd, "q", 1) == 0) {
589                         unsigned int value = 100;
590                         ret = mm_sound_volume_get_value(g_volume_type, &value);
591                         if (ret < 0) {
592                                 debug_log("mm_sound_volume_get_value 0x%x", ret);
593                         } else {
594                                 g_print("*** MEDIA VOLUME : %u ***\n", value);
595                                 g_volume_value = value;
596                         }
597
598                 } else if (strncmp(cmd, "e", 1) == 0) {
599                         unsigned int value = 100;
600                         ret = mm_sound_volume_get_value(g_volume_type, &value);
601                         if (ret < 0) {
602                                 debug_log("mm_sound_volume_get_value 0x%x", ret);
603                         } else {
604                                 if (value != 0)
605                                         value--;
606                                 ret = mm_sound_volume_set_value(g_volume_type, value);
607                                 if (ret < 0)
608                                         debug_log("mm_sound_volume_set_value 0x%x", ret);
609                         }
610
611                 } else if (strncmp(cmd, "r", 1) == 0) {
612                         unsigned int value = 100;
613                         ret = mm_sound_volume_get_value(VOLUME_TYPE_SYSTEM, &value);
614                         if (ret < 0) {
615                                 debug_log("mm_sound_volume_get_value 0x%x", ret);
616                         } else {
617                                 g_print("*** SYSTEM VOLUME : %u ***\n", value);
618                                 g_volume_value = value;
619                         }
620
621                 } else if (strncmp(cmd, "y", 1) == 0) {
622                         unsigned int value = 100;
623                         ret = mm_sound_volume_get_value(VOLUME_TYPE_SYSTEM, &value);
624                         if (ret < 0) {
625                                 debug_log("mm_sound_volume_get_value 0x%x", ret);
626                         } else {
627                                 if (value != 0)
628                                         value--;
629
630                                 ret = mm_sound_volume_set_value(VOLUME_TYPE_SYSTEM, value);
631                                 if (ret < 0)
632                                         debug_log("mm_sound_volume_set_value 0x%x", ret);
633                                 else
634                                         g_print("Current System volume is %d\n", value);
635                         }
636
637                 } else if (strncmp(cmd, "g", 1) == 0) {
638                         unsigned int value = 100;
639                         ret = mm_sound_volume_get_value(VOLUME_TYPE_VOICE, &value);
640                         if (ret < 0) {
641                                 debug_log("mm_sound_volume_get_value 0x%x", ret);
642                         } else {
643                                 g_print("*** VOICE VOLUME : %u ***\n", value);
644                                 g_volume_value = value;
645                         }
646
647                 } else if (strncmp(cmd, "j", 1) == 0) {
648                         unsigned int value = 100;
649                         ret = mm_sound_volume_get_value(VOLUME_TYPE_VOICE, &value);
650                         if (ret < 0) {
651                                 debug_log("mm_sound_volume_get_value 0x%x", ret);
652                         } else {
653                                 if (value != 0)
654                                         value--;
655
656                                 ret = mm_sound_volume_set_value(VOLUME_TYPE_VOICE, value);
657                                 if (ret < 0)
658                                         debug_log("mm_sound_volume_set_value 0x%x", ret);
659                                 else
660                                         g_print("Current Voice volume is %d\n", value);
661                         }
662
663                 } else if (strncmp(cmd, "as", 2) == 0) {
664                         debug_log("stream %s type, %d", "media", g_volume_value);
665                         ret = mm_sound_play_sound_with_stream_info(g_file_name, "media", -1, 1, mycallback, "USERDATA", &handle);
666                         if (ret < 0)
667                                 debug_log("mm_sound_play_sound() failed with 0x%x", ret);
668
669                 } else if (strncmp(cmd, "FS", 2) == 0) {
670                         char num = 0;
671                         char input_string[128] = "";
672                         char *tok = NULL;
673                         char *ptr = NULL;
674                         char *stream_type = NULL;
675                         int tonetime = 0;
676                         double volume = 1.0;
677                         MMSoundTone_t tone = MM_SOUND_TONE_DTMF_0;
678
679                         while (num != 'q') {
680                                 fflush(stdin);
681                                 g_print("enter number(0~H exit:q), stream type(media, system, ...),  volume(0.0~1.0),  time(ms):\t ");
682                                 if (fgets(input_string, sizeof(input_string)-1, stdin)) {
683                                         tok = strtok_r(input_string, " ", &ptr);
684                                         if (!tok)
685                                                 continue;
686                                         if (tok[0] == 'q') {
687                                                 break;
688                                         } else if (tok[0] < '0' || tok[0] > '~') {
689                                                 if (tok[0] != '*' && tok[0] != '#')
690                                                         continue;
691                                         }
692                                         num = tok[0];
693                                         if (num >= '0' && num <= '9')
694                                                 tone = (MMSoundTone_t)(num - '0');
695                                         else if (num == '*')
696                                                 tone = MM_SOUND_TONE_DTMF_S;
697                                         else if (num == '#')
698                                                 tone = MM_SOUND_TONE_DTMF_P;
699                                         else if (num == 'A')
700                                                 tone = MM_SOUND_TONE_DTMF_A;
701                                         else if (num == 'B')
702                                                 tone = MM_SOUND_TONE_DTMF_B;
703                                         else if (num == 'C')
704                                                 tone = MM_SOUND_TONE_DTMF_C;
705                                         else if (num == 'D')
706                                                 tone = MM_SOUND_TONE_DTMF_D;
707                                         else if (num == 'E')
708                                                 tone = MM_SOUND_TONE_SUP_DIAL;
709                                         else if (num == 'F')
710                                                 tone = MM_SOUND_TONE_ANSI_DIAL;
711                                         else if (num == 'G')
712                                                 tone = MM_SOUND_TONE_JAPAN_DIAL;
713                                         else if (num == 'H')
714                                                 tone = MM_SOUND_TONE_SUP_BUSY;
715                                         else if (num == 'I')
716                                                 tone = MM_SOUND_TONE_ANSI_BUSY;
717                                         else if (num == 'J')
718                                                 tone = MM_SOUND_TONE_JAPAN_BUSY;
719                                         else if (num == 'K')
720                                                 tone = MM_SOUND_TONE_SUP_CONGESTION;
721                                         else if (num == 'L')
722                                                 tone = MM_SOUND_TONE_ANSI_CONGESTION;
723                                         else if (num == 'M')
724                                                 tone = MM_SOUND_TONE_SUP_RADIO_ACK;
725                                         else if (num == 'N')
726                                                 tone = MM_SOUND_TONE_JAPAN_RADIO_ACK;
727                                         else if (num == 'O')
728                                                 tone = MM_SOUND_TONE_SUP_RADIO_NOTAVAIL;
729                                         else if (num == 'P')
730                                                 tone = MM_SOUND_TONE_SUP_ERROR;
731                                         else if (num == 'Q')
732                                                 tone = MM_SOUND_TONE_SUP_CALL_WAITING;
733                                         else if (num == 'R')
734                                                 tone = MM_SOUND_TONE_ANSI_CALL_WAITING;
735                                         else if (num == 'S')
736                                                 tone = MM_SOUND_TONE_SUP_RINGTONE;
737                                         else if (num == 'T')
738                                                 tone = MM_SOUND_TONE_ANSI_RINGTONE;
739                                         else if (num == 'U')
740                                                 tone = MM_SOUND_TONE_PROP_BEEP;
741                                         else if (num == 'V')
742                                                 tone = MM_SOUND_TONE_PROP_ACK;
743                                         else if (num == 'W')
744                                                 tone = MM_SOUND_TONE_PROP_NACK;
745                                         else if (num == 'X')
746                                                 tone = MM_SOUND_TONE_PROP_PROMPT;
747                                         else if (num == 'Y')
748                                                 tone = MM_SOUND_TONE_PROP_BEEP2;
749                                         else if (num == 'Z')
750                                                 tone = MM_SOUND_TONE_CDMA_HIGH_SLS;
751                                         else if (num == '[')
752                                                 tone = MM_SOUND_TONE_CDMA_MED_SLS;
753                                         else if (num == ']')
754                                                 tone = MM_SOUND_TONE_CDMA_LOW_SLS;
755                                         else if (num == '^')
756                                                 tone = MM_SOUND_TONE_CDMA_HIGH_S_X4;
757                                         else if (num == '_')
758                                                 tone = MM_SOUND_TONE_CDMA_MED_S_X4;
759                                         else if (num == 'a')
760                                                 tone = MM_SOUND_TONE_CDMA_LOW_S_X4;
761                                         else if (num == 'b')
762                                                 tone = MM_SOUND_TONE_CDMA_HIGH_PBX_L;
763                                         else if (num == 'c')
764                                                 tone = MM_SOUND_TONE_CDMA_MED_PBX_L;
765                                         else if (num == 'd')
766                                                 tone = MM_SOUND_TONE_CDMA_LOW_PBX_L;
767                                         else if (num == 'e')
768                                                 tone = MM_SOUND_TONE_CDMA_HIGH_PBX_SS;
769                                         else if (num == 'f')
770                                                 tone = MM_SOUND_TONE_CDMA_MED_PBX_SS;
771                                         else if (num == 'g')
772                                                 tone = MM_SOUND_TONE_CDMA_LOW_PBX_SS;
773                                         else if (num == 'h')
774                                                 tone = MM_SOUND_TONE_CDMA_HIGH_PBX_SSL;
775                                         else if (num == 'i')
776                                                 tone = MM_SOUND_TONE_CDMA_MED_PBX_SSL;
777                                         else if (num == 'j')
778                                                 tone = MM_SOUND_TONE_CDMA_LOW_PBX_SSL;
779                                         else if (num == 'k')
780                                                 tone = MM_SOUND_TONE_CDMA_HIGH_PBX_SLS;
781                                         else if (num == 'l')
782                                                 tone = MM_SOUND_TONE_CDMA_MED_PBX_SLS;
783                                         else if (num == 'm')
784                                                 tone = MM_SOUND_TONE_CDMA_LOW_PBX_SLS;
785                                         else if (num == 'n')
786                                                 tone = MM_SOUND_TONE_CDMA_HIGH_PBX_S_X4;
787                                         else if (num == 'o')
788                                                 tone = MM_SOUND_TONE_CDMA_MED_PBX_S_X4;
789                                         else if (num == 'p')
790                                                 tone = MM_SOUND_TONE_CDMA_LOW_PBX_S_X4;
791                                         else if (num == 'q')
792                                                 tone = MM_SOUND_TONE_CDMA_ALERT_NETWORK_LITE;
793                                         else if (num == 'r')
794                                                 tone = MM_SOUND_TONE_CDMA_ALERT_AUTOREDIAL_LITE;
795                                         else if (num == 's')
796                                                 tone = MM_SOUND_TONE_CDMA_ONE_MIN_BEEP;
797                                         else if (num == 't')
798                                                 tone = MM_SOUND_TONE_CDMA_KEYPAD_VOLUME_KEY_LITE;
799                                         else if (num == 'u')
800                                                 tone = MM_SOUND_TONE_CDMA_PRESSHOLDKEY_LITE;
801                                         else if (num == 'v')
802                                                 tone = MM_SOUND_TONE_CDMA_ALERT_INCALL_LITE;
803                                         else if (num == 'w')
804                                                 tone = MM_SOUND_TONE_CDMA_EMERGENCY_RINGBACK;
805                                         else if (num == 'x')
806                                                 tone = MM_SOUND_TONE_CDMA_ALERT_CALL_GUARD;
807                                         else if (num == 'y')
808                                                 tone = MM_SOUND_TONE_CDMA_SOFT_ERROR_LITE;
809                                         else if (num == 'z')
810                                                 tone = MM_SOUND_TONE_CDMA_CALLDROP_LITE;
811                                         else if (num == '{')
812                                                 tone = MM_SOUND_TONE_LOW_FRE;
813                                         else if (num == '}')
814                                                 tone = MM_SOUND_TONE_MED_FRE;
815                                         else if (num == '~')
816                                                 tone = MM_SOUND_TONE_HIGH_FRE;
817
818                                         stream_type = strtok_r(NULL, " ", &ptr);
819
820                                         tok = strtok_r(NULL, " ", &ptr);
821                                         if (tok)
822                                                 volume = (double)atof(tok);
823
824                                         tok = strtok_r(NULL, " ", &ptr);
825                                         if (tok)
826                                                 tonetime = atoi(tok);
827                                         else
828                                                 tonetime = MIN_TONE_PLAY_TIME;
829
830                                         debug_log("stream type: %s\t volume is %f\t tonetime: %d", stream_type, volume, tonetime);
831                                         ret = mm_sound_play_tone_with_stream_info(tone, stream_type, -1, volume, tonetime, &handle);
832                                         if (ret < 0)
833                                                 debug_log("failed to mm_sound_play_tone_with_stream_info(), ret[0x%x]", ret);
834                                 } else {
835                                         g_print("### fgets return  NULL\n");
836                                 }
837                         }
838
839                 } else if (strncmp(cmd, "b", 1) == 0) {
840                         DIR     *basedir;
841                         struct dirent *entry = NULL;
842                         struct dirent *prev_entry = NULL;
843                         int entry_len;
844                         int ret;
845                         struct stat file_stat;
846                         char fullpath[MAX_PATH_LEN] = "";
847                         struct timespec start_time = {0,};
848                         struct timespec current_time = {0,};
849
850                         if (g_dir_name[strlen(g_dir_name)-1] == '/')
851                                 g_dir_name[strlen(g_dir_name)-1] = '\0';
852
853                         basedir = opendir(g_dir_name);
854                         if (basedir != NULL) {
855                                 entry_len = offsetof(struct dirent, d_name) + fpathconf(dirfd(basedir), MAX_STRING_LEN) + 1;
856                                 prev_entry = malloc(entry_len);
857
858                                 while (1) {
859                                         int playfail = 0;
860                                         int mywait = 0;
861
862                                         ret = readdir_r(basedir, prev_entry, &entry);
863                                         if (ret == 0) {
864                                                 debug_error("error on readdir_r(%p)", basedir);
865                                                 break;
866                                         }
867                                         if (entry == NULL)
868                                                 break;
869
870                                         if (entry->d_name[0] == '.')
871                                                 continue;
872                                         memset(fullpath, '\0', sizeof(fullpath));
873                                         snprintf(fullpath, sizeof(fullpath) - 1, "%s/%s", g_dir_name, entry->d_name);
874                                         debug_log("Try %s", fullpath);
875
876                                         if (lstat(fullpath, &file_stat) == -1)
877                                                 continue;
878
879                                         if (S_ISREG(file_stat.st_mode)) {
880                                                 test_callback_done = 0 ;
881                                                 start_time.tv_sec = (long int)(time(NULL));
882                                                 start_time.tv_nsec = 0;
883
884                                                 ret = mm_sound_play_sound_with_stream_info(fullpath, "media", -1, 1, test_callback, "USERDATA", &handle);
885                                                 if (ret != MM_ERROR_NONE) {
886                                                         debug_log("Play file error : %s", fullpath);
887                                                         sleep(4);
888                                                         playfail = 1;
889                                                 }
890                                         } else {
891                                                 debug_log("this is not regular file : %s", fullpath);
892                                                 playfail = 1;
893                                         }
894                                         while ((test_callback_done == 0) && (playfail == 0)) {
895                                                 current_time.tv_sec = (long int)(time(NULL));
896                                                 current_time.tv_nsec = 0;
897                                                 if (current_time.tv_sec - start_time.tv_sec > 200) {
898                                                         if ((++mywait)%5 == 0) {
899                                                                 debug_log("I'm waiting callback for %d seconds after play %s",
900                                                                                 (int)(current_time.tv_sec - start_time.tv_sec), fullpath);
901                                                         }
902                                                 }
903                                                 sleep(2);
904                                         }
905                                         debug_log("goto next file");
906                                 }
907                                 free(prev_entry);
908                                 closedir(basedir);
909                         } else {
910                                 debug_log("Cannot Open such a directory %s", g_dir_name);
911                         }
912
913                 } else if (strncmp(cmd, "f", 1) == 0) {
914                         g_menu_state = CURRENT_STATUS_FILENAME;
915
916                 } else if (strncmp(cmd, "d", 1) == 0) {
917                         g_menu_state = CURRENT_STATUS_DIRNAME;
918
919                 } else if (strncmp(cmd, "s", 1) == 0) {
920                         if (mm_sound_stop_sound(handle))
921                                 debug_log(" Cannot stop sound !!! %d ", handle);
922
923                 } else if (strncmp(cmd, "L", 1) == 0) {
924                         int ret = 0;
925                         mm_sound_device_flags_e flags = MM_SOUND_DEVICE_ALL_FLAG;
926                         MMSoundDeviceList_t device_list;
927                         mm_sound_device_type_e device_type = 0;
928                         mm_sound_device_io_direction_e io_direction = 0;
929                         mm_sound_device_state_e state = 0;
930                         int id = 0;
931                         char *name = NULL;
932                         MMSoundDevice_t device_h = NULL;
933                         int dret = MM_ERROR_NONE;
934                         int product_id = -1, vendor_id = -1;
935
936                         ret = mm_sound_get_current_device_list(flags, &device_list);
937                         if (ret) {
938                                 g_print("failed to mm_sound_get_current_device_list(), ret[0x%x]\n", ret);
939                         } else {
940                                 g_print("device_list[%p], device_h[%p]\n", device_list, device_h);
941                                 do {
942                                         dret = mm_sound_get_next_device(device_list, &device_h);
943                                         if (dret) {
944                                                 debug_error("failed to mm_sound_get_next_device(), dret[0x%x]\n", dret);
945                                         } else {
946                                                 ret = mm_sound_get_device_type(device_h, &device_type);
947                                                 if (ret)
948                                                         debug_error("failed to mm_sound_get_device_type()");
949                                                 ret = mm_sound_get_device_io_direction(device_h, &io_direction);
950                                                 if (ret)
951                                                         debug_error("failed to mm_sound_get_device_io_direction()");
952                                                 ret = mm_sound_get_device_state(device_h, &state);
953                                                 if (ret)
954                                                         debug_error("failed to mm_sound_get_device_state()");
955                                                 ret = mm_sound_get_device_id(device_h, &id);
956                                                 if (ret)
957                                                         debug_error("failed to mm_sound_get_device_id()");
958                                                 ret = mm_sound_get_device_name(device_h, &name);
959                                                 if (ret)
960                                                         debug_error("failed to mm_sound_get_device_name()");
961                                                 ret = mm_sound_get_device_vendor_id(device_h, &vendor_id);
962                                                 if (ret)
963                                                         debug_error("failed to mm_sound_get_device_vendor_id()");
964                                                 ret = mm_sound_get_device_product_id(device_h, &product_id);
965                                                 if (ret)
966                                                         debug_error("failed to mm_sound_get_device_product_id()");
967                                                 debug_log("*** --- [NEXT DEVICE] type[%d], id[%d], io_direction[%d], state[%d], "
968                                                                 "name[%s] vendor_id[%04x] product_id[%04x]",
969                                                                 device_type, id, io_direction, state, name, vendor_id, product_id);
970                                         }
971                                 } while (dret == MM_ERROR_NONE);
972                                 do {
973                                         dret = MM_ERROR_NONE;
974                                         dret = mm_sound_get_prev_device(device_list, &device_h);
975                                         if (dret) {
976                                                 debug_error("failed to mm_sound_get_prev_device(), dret[0x%x]", dret);
977                                         } else {
978                                                 ret = mm_sound_get_device_type(device_h, &device_type);
979                                                 if (ret)
980                                                         debug_error("failed to mm_sound_get_device_type()");
981                                                 ret = mm_sound_get_device_io_direction(device_h, &io_direction);
982                                                 if (ret)
983                                                         debug_error("failed to mm_sound_get_device_io_direction()");
984                                                 ret = mm_sound_get_device_state(device_h, &state);
985                                                 if (ret)
986                                                         debug_error("failed to mm_sound_get_device_state()");
987                                                 ret = mm_sound_get_device_id(device_h, &id);
988                                                 if (ret)
989                                                         debug_error("failed to mm_sound_get_device_id()");
990                                                 ret = mm_sound_get_device_name(device_h, &name);
991                                                 if (ret)
992                                                         debug_error("failed to mm_sound_get_device_name()");
993                                                 ret = mm_sound_get_device_vendor_id(device_h, &vendor_id);
994                                                 if (ret)
995                                                         debug_error("failed to mm_sound_get_device_vendor_id()");
996                                                 ret = mm_sound_get_device_product_id(device_h, &product_id);
997                                                 if (ret)
998                                                         debug_error("failed to mm_sound_get_device_product_id()");
999                                                 debug_log("*** --- [PREV DEVICE] type[%d], id[%d], io_direction[%d], state[%d], "
1000                                                                 "name[%s] vendor_id[%04x] product_id[%04x]",
1001                                                                 device_type, id, io_direction, state, name, vendor_id, product_id);
1002                                         }
1003                                 } while (dret == MM_ERROR_NONE);
1004                         }
1005
1006                 } else if (strncmp(cmd, "I", 1) == 0) {
1007                         int ret = 0;
1008                         MMSoundDevice_t device_h = NULL;
1009                         mm_sound_device_type_e device_type = 0;
1010                         mm_sound_device_io_direction_e io_direction = 0;
1011                         mm_sound_device_state_e state = 0;
1012                         char *name;
1013                         int id = 0, input_id = 0;
1014                         char input_string[128];
1015
1016                         fflush(stdin);
1017                         g_print("> Input id : ");
1018
1019                         if (fgets(input_string, sizeof(input_string)-1, stdin)) {
1020                                 input_id = atoi(input_string);
1021
1022                                 ret = mm_sound_get_device_by_id(input_id, &device_h);
1023                                 if (ret == MM_ERROR_NONE) {
1024                                         ret = mm_sound_get_device_type(device_h, &device_type);
1025                                         if (ret)
1026                                                 g_print("failed to mm_sound_get_device_type()\n");
1027                                         ret = mm_sound_get_device_io_direction(device_h, &io_direction);
1028                                         if (ret)
1029                                                 g_print("failed to mm_sound_get_device_io_direction()\n");
1030                                         ret = mm_sound_get_device_state(device_h, &state);
1031                                         if (ret)
1032                                                 g_print("failed to mm_sound_get_device_state()\n");
1033                                         ret = mm_sound_get_device_id(device_h, &id);
1034                                         if (ret)
1035                                                 g_print("failed to mm_sound_get_device_id()\n");
1036                                         ret = mm_sound_get_device_name(device_h, &name);
1037                                         if (ret)
1038                                                 g_print("failed to mm_sound_get_device_name()\n");
1039                                         g_print("*** --- type[%d], id[%d], io_direction[%d], state[%d], name[%s]\n", device_type, id, io_direction, state, name);
1040                                 } else {
1041                                         g_print("failed to mm_sound_get_device_by_id()\n");
1042                                 }
1043
1044                                 ret = mm_sound_free_device(device_h);
1045                                 if (ret)
1046                                         g_print("failed to mm_sound_free_device()\n");
1047                         } else {
1048                                 g_print("### fgets return  NULL\n");
1049                         }
1050
1051                 } else if (strncmp(cmd, "C", 1) == 0) {
1052                         int ret = 0;
1053                         char input_string[128];
1054                         mm_sound_device_flags_e device_flag_1 = MM_SOUND_DEVICE_ALL_FLAG;
1055                         mm_sound_device_flags_e device_flag_2 = MM_SOUND_DEVICE_ALL_FLAG;
1056                         mm_sound_device_flags_e device_flag_3 = MM_SOUND_DEVICE_ALL_FLAG;
1057
1058                         char flag_1, flag_2, flag_3;
1059
1060                         fflush(stdin);
1061                         g_print("1. IO_DIRECTION_IN_FLAG\n");
1062                         g_print("2. IO_DIRECTION_OUT_FLAG\n");
1063                         g_print("3. IO_DIRECTION_BOTH_FLAG\n");
1064                         g_print("4. TYPE_INTERNAL_FLAG\n");
1065                         g_print("5. TYPE_EXTERNAL_FLAG\n");
1066                         g_print("6. STATE_DEACTIVATED_FLAG\n");
1067                         g_print("7. STATE_ACTIVATED_FLAG\n");
1068                         g_print("8. ALL_FLAG\n");
1069                         g_print("> select flag numbers (total 3):  (eg. 2 5 7)");
1070
1071                         if (fgets(input_string, sizeof(input_string)-1, stdin)) {
1072                                 flag_1 = input_string[0];
1073                                 flag_2 = input_string[2];
1074                                 flag_3 = input_string[4];
1075
1076                                 if (flag_1 == '1')
1077                                         device_flag_1 = MM_SOUND_DEVICE_IO_DIRECTION_IN_FLAG;
1078                                 else if (flag_1 == '2')
1079                                         device_flag_1 = MM_SOUND_DEVICE_IO_DIRECTION_OUT_FLAG;
1080                                 else if (flag_1 == '3')
1081                                         device_flag_1 = MM_SOUND_DEVICE_IO_DIRECTION_BOTH_FLAG;
1082                                 else if (flag_1 == '4')
1083                                         device_flag_1 = MM_SOUND_DEVICE_TYPE_INTERNAL_FLAG;
1084                                 else if (flag_1 == '5')
1085                                         device_flag_1 = MM_SOUND_DEVICE_TYPE_EXTERNAL_FLAG;
1086                                 else if (flag_1 == '6')
1087                                         device_flag_1 = MM_SOUND_DEVICE_STATE_DEACTIVATED_FLAG;
1088                                 else if (flag_1 == '7')
1089                                         device_flag_1 = MM_SOUND_DEVICE_STATE_ACTIVATED_FLAG;
1090                                 else if (flag_1 == '8')
1091                                         device_flag_1 = MM_SOUND_DEVICE_ALL_FLAG;
1092
1093                                 if (flag_2 == '1')device_flag_2 = MM_SOUND_DEVICE_IO_DIRECTION_IN_FLAG;
1094                                 else if (flag_2 == '2')
1095                                         device_flag_2 = MM_SOUND_DEVICE_IO_DIRECTION_OUT_FLAG;
1096                                 else if (flag_2 == '3')
1097                                         device_flag_2 = MM_SOUND_DEVICE_IO_DIRECTION_BOTH_FLAG;
1098                                 else if (flag_2 == '4')
1099                                         device_flag_2 = MM_SOUND_DEVICE_TYPE_INTERNAL_FLAG;
1100                                 else if (flag_2 == '5')
1101                                         device_flag_2 = MM_SOUND_DEVICE_TYPE_EXTERNAL_FLAG;
1102                                 else if (flag_2 == '6')
1103                                         device_flag_2 = MM_SOUND_DEVICE_STATE_DEACTIVATED_FLAG;
1104                                 else if (flag_2 == '7')
1105                                         device_flag_2 = MM_SOUND_DEVICE_STATE_ACTIVATED_FLAG;
1106                                 else if (flag_2 == '8')
1107                                         device_flag_2 = MM_SOUND_DEVICE_ALL_FLAG;
1108
1109                                 if (flag_3 == '1')
1110                                         device_flag_3 = MM_SOUND_DEVICE_IO_DIRECTION_IN_FLAG;
1111                                 else if (flag_3 == '2')
1112                                         device_flag_3 = MM_SOUND_DEVICE_IO_DIRECTION_OUT_FLAG;
1113                                 else if (flag_3 == '3')
1114                                         device_flag_3 = MM_SOUND_DEVICE_IO_DIRECTION_BOTH_FLAG;
1115                                 else if (flag_3 == '4')
1116                                         device_flag_3 = MM_SOUND_DEVICE_TYPE_INTERNAL_FLAG;
1117                                 else if (flag_3 == '5')
1118                                         device_flag_3 = MM_SOUND_DEVICE_TYPE_EXTERNAL_FLAG;
1119                                 else if (flag_3 == '6')
1120                                         device_flag_3 = MM_SOUND_DEVICE_STATE_DEACTIVATED_FLAG;
1121                                 else if (flag_3 == '7')
1122                                         device_flag_3 = MM_SOUND_DEVICE_STATE_ACTIVATED_FLAG;
1123                                 else if (flag_3 == '8')
1124                                         device_flag_3 = MM_SOUND_DEVICE_ALL_FLAG;
1125
1126                                 g_print("device_connected_callback");
1127                                 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);
1128                                 if (ret)
1129                                         g_print("failed to mm_sound_add_device_connected_callback(), ret[0x%x]\n", ret);
1130                                 else
1131                                         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);
1132                         } else {
1133                                 g_print("### fgets return  NULL\n");
1134                         }
1135
1136                 } else if (strncmp(cmd, "D", 1) == 0) {
1137                         int ret = 0;
1138                         ret = mm_sound_remove_device_connected_callback(g_subs_id_device_conn);
1139                         if (ret)
1140                                 g_print("failed to mm_sound_remove_device_connected_callback(), ret[0x%x]\n", ret);
1141
1142                 } else if (strncmp(cmd, "Q", 1) == 0) {
1143                         int ret = 0;
1144                         char input_string[128];
1145                         mm_sound_device_flags_e device_flag_1 = MM_SOUND_DEVICE_ALL_FLAG;
1146                         mm_sound_device_flags_e device_flag_2 = MM_SOUND_DEVICE_ALL_FLAG;
1147                         mm_sound_device_flags_e device_flag_3 = MM_SOUND_DEVICE_ALL_FLAG;
1148
1149                         char flag_1, flag_2, flag_3;
1150
1151                         fflush(stdin);
1152                         g_print("1. IO_DIRECTION_IN_FLAG\n");
1153                         g_print("2. IO_DIRECTION_OUT_FLAG\n");
1154                         g_print("3. IO_DIRECTION_BOTH_FLAG\n");
1155                         g_print("4. TYPE_INTERNAL_FLAG\n");
1156                         g_print("5. TYPE_EXTERNAL_FLAG\n");
1157                         g_print("6. STATE_DEACTIVATED_FLAG\n");
1158                         g_print("7. STATE_ACTIVATED_FLAG\n");
1159                         g_print("8. ALL_FLAG\n");
1160                         g_print("> select flag numbers (total 3):  (eg. 2 5 7)");
1161
1162                         if (fgets(input_string, sizeof(input_string)-1, stdin)) {
1163                                 flag_1 = input_string[0];
1164                                 flag_2 = input_string[2];
1165                                 flag_3 = input_string[4];
1166
1167                                 if (flag_1 == '1')
1168                                         device_flag_1 = MM_SOUND_DEVICE_IO_DIRECTION_IN_FLAG;
1169                                 else if (flag_1 == '2')
1170                                         device_flag_1 = MM_SOUND_DEVICE_IO_DIRECTION_OUT_FLAG;
1171                                 else if (flag_1 == '3')
1172                                         device_flag_1 = MM_SOUND_DEVICE_IO_DIRECTION_BOTH_FLAG;
1173                                 else if (flag_1 == '4')
1174                                         device_flag_1 = MM_SOUND_DEVICE_TYPE_INTERNAL_FLAG;
1175                                 else if (flag_1 == '5')
1176                                         device_flag_1 = MM_SOUND_DEVICE_TYPE_EXTERNAL_FLAG;
1177                                 else if (flag_1 == '6')
1178                                         device_flag_1 = MM_SOUND_DEVICE_STATE_DEACTIVATED_FLAG;
1179                                 else if (flag_1 == '7')
1180                                         device_flag_1 = MM_SOUND_DEVICE_STATE_ACTIVATED_FLAG;
1181                                 else if (flag_1 == '8')
1182                                         device_flag_1 = MM_SOUND_DEVICE_ALL_FLAG;
1183
1184                                 if (flag_2 == '1')
1185                                         device_flag_2 = MM_SOUND_DEVICE_IO_DIRECTION_IN_FLAG;
1186                                 else if (flag_2 == '2')
1187                                         device_flag_2 = MM_SOUND_DEVICE_IO_DIRECTION_OUT_FLAG;
1188                                 else if (flag_2 == '3')
1189                                         device_flag_2 = MM_SOUND_DEVICE_IO_DIRECTION_BOTH_FLAG;
1190                                 else if (flag_2 == '4')
1191                                         device_flag_2 = MM_SOUND_DEVICE_TYPE_INTERNAL_FLAG;
1192                                 else if (flag_2 == '5')
1193                                         device_flag_2 = MM_SOUND_DEVICE_TYPE_EXTERNAL_FLAG;
1194                                 else if (flag_2 == '6')
1195                                         device_flag_2 = MM_SOUND_DEVICE_STATE_DEACTIVATED_FLAG;
1196                                 else if (flag_2 == '7')
1197                                         device_flag_2 = MM_SOUND_DEVICE_STATE_ACTIVATED_FLAG;
1198                                 else if (flag_2 == '8')
1199                                         device_flag_2 = MM_SOUND_DEVICE_ALL_FLAG;
1200
1201                                 if (flag_3 == '1')
1202                                         device_flag_3 = MM_SOUND_DEVICE_IO_DIRECTION_IN_FLAG;
1203                                 else if (flag_3 == '2')
1204                                         device_flag_3 = MM_SOUND_DEVICE_IO_DIRECTION_OUT_FLAG;
1205                                 else if (flag_3 == '3')
1206                                         device_flag_3 = MM_SOUND_DEVICE_IO_DIRECTION_BOTH_FLAG;
1207                                 else if (flag_3 == '4')
1208                                         device_flag_3 = MM_SOUND_DEVICE_TYPE_INTERNAL_FLAG;
1209                                 else if (flag_3 == '5')
1210                                         device_flag_3 = MM_SOUND_DEVICE_TYPE_EXTERNAL_FLAG;
1211                                 else if (flag_3 == '6')
1212                                         device_flag_3 = MM_SOUND_DEVICE_STATE_DEACTIVATED_FLAG;
1213                                 else if (flag_3 == '7')
1214                                         device_flag_3 = MM_SOUND_DEVICE_STATE_ACTIVATED_FLAG;
1215                                 else if (flag_3 == '8')
1216                                         device_flag_3 = MM_SOUND_DEVICE_ALL_FLAG;
1217
1218                                 g_print("add_device_state_changed");
1219                                 ret = mm_sound_add_device_state_changed_callback(device_flag_1 | device_flag_2 | device_flag_3, device_state_changed_cb, NULL, &g_subs_id_device_state);
1220                                 if (ret)
1221                                         g_print("failed to mm_sound_add_device_state_changed_callback(), ret[0x%x]\n", ret);
1222                                 else
1223                                         g_print("device_flags[0x%x], callback fun[%p], subs_id[%u]\n", device_flag_1|device_flag_2|device_flag_3, device_state_changed_cb, g_subs_id_device_state);
1224
1225                         } else {
1226                                 g_print("### fgets return  NULL\n");
1227                         }
1228
1229                 } else if (strncmp(cmd, "W", 1) == 0) {
1230                         int ret = 0;
1231                         ret = mm_sound_remove_device_state_changed_callback(g_subs_id_device_state);
1232                         if (ret)
1233                                 g_print("failed to mm_sound_remove_device_state_changed_callback(), ret[0x%x]\n", ret);
1234
1235                 } else if (strncmp(cmd, "x", 1) == 0) {
1236                         quit_program();
1237                 }
1238                 break;
1239
1240         case CURRENT_STATUS_FILENAME:
1241                 input_filename(cmd);
1242                 g_menu_state = CURRENT_STATUS_MAINMENU;
1243                 break;
1244
1245         case CURRENT_STATUS_DIRNAME:
1246                 input_dirname(cmd);
1247                 g_menu_state = CURRENT_STATUS_MAINMENU;
1248                 break;
1249
1250         case CURRENT_STATUS_POSITION:
1251                 break;
1252
1253         }
1254 }
1255
1256 void volume_change_callback(volume_type_t type, unsigned int volume, void *user_data)
1257 {
1258         if (type == VOLUME_TYPE_MEDIA)
1259                 g_print("Volume Callback Runs :::: MEDIA VALUME %d\n", volume);
1260 }
1261
1262 int main(int argc, char *argv[])
1263 {
1264         int ret = 0;
1265
1266         stdin_channel = g_io_channel_unix_new(0);
1267         g_io_add_watch(stdin_channel, G_IO_IN, (GIOFunc)input, NULL);
1268         g_loop = g_main_loop_new(NULL, 1);
1269
1270         MMSOUND_STRNCPY(g_file_name, POWERON_FILE, MAX_STRING_LEN);
1271         g_print("\nThe input filename is '%s' \n\n", g_file_name);
1272
1273         /* test volume changed callback */
1274         g_print("callback function addr :: %p\n", volume_change_callback);
1275         g_volume_type = VOLUME_TYPE_MEDIA;
1276         ret = mm_sound_volume_get_value(g_volume_type, &g_volume_value);
1277         if (ret < 0)
1278                 g_print("mm_sound_volume_get_value 0x%x\n", ret);
1279
1280         mm_sound_add_volume_changed_callback(volume_change_callback, (void*) &g_volume_type, &g_subs_id_volume);
1281
1282         displaymenu();
1283         g_main_loop_run(g_loop);
1284
1285         return 0;
1286 }