Fix spelling errata
[platform/core/uifw/voice-control.git] / client / vc_mgr.c
1 /*
2 * Copyright (c) 2011-2015 Samsung Electronics Co., Ltd All Rights Reserved
3 *
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #include <aul.h>
18 #include <system_info.h>
19 #include <cynara-client.h>
20 #include <cynara-error.h>
21 #include <cynara-session.h>
22
23 #include "vc_cmd_db.h"
24 #include "vc_config_mgr.h"
25 #include "vc_command.h"
26 #include "vc_info_parser.h"
27 #include "vc_json_parser.h"
28 #include "vc_main.h"
29 #include "vc_mgr_client.h"
30 #include "vc_mgr_dbus.h"
31 #include "vc_mgr_data.h"
32 #include "vc_mgr_player.h"
33 #include "voice_control.h"
34 #include "voice_control_command.h"
35 #include "voice_control_command_expand.h"
36 #include "voice_control_common.h"
37 #include "voice_control_manager.h"
38 #include "voice_control_manager_internal.h"
39
40
41 #define VC_MANAGER_CONFIG_HANDLE        100000
42
43 static Ecore_Timer* g_m_connect_timer = NULL;
44
45 static Ecore_Timer* g_m_set_volume_timer = NULL;
46
47 static vc_h g_vc_m = NULL;
48
49 static GSList* g_demandable_client_list = NULL;
50
51 static float g_volume_db = 0;
52
53 static float g_prev_volume_db = 0;
54
55 static float g_cur_volume_db = 0;
56
57 static int g_daemon_pid = 0;
58
59 static int g_feature_enabled = -1;
60
61 static int g_privilege_allowed = -1;
62 static cynara *p_cynara = NULL;
63
64 static bool g_err_callback_status = false;
65
66 /* for TTS feedback */
67 static int g_feedback_rate = 16000;
68 static vc_audio_channel_e g_feedback_audio_channel = 0;
69 static vc_audio_type_e g_feedback_audio_type = 0;
70
71
72 static Eina_Bool __vc_mgr_notify_state_changed(void *data);
73 static void __vc_mgr_notify_error(void *data);
74 static Eina_Bool __vc_mgr_notify_result(void *data);
75
76 static const char* __vc_mgr_get_error_code(vc_error_e err)
77 {
78         switch (err) {
79         case VC_ERROR_NONE:                     return "VC_ERROR_NONE";
80         case VC_ERROR_OUT_OF_MEMORY:            return "VC_ERROR_OUT_OF_MEMORY";
81         case VC_ERROR_IO_ERROR:                 return "VC_ERROR_IO_ERROR";
82         case VC_ERROR_INVALID_PARAMETER:        return "VC_ERROR_INVALID_PARAMETER";
83         case VC_ERROR_TIMED_OUT:                return "VC_ERROR_TIMED_OUT";
84         case VC_ERROR_RECORDER_BUSY:            return "VC_ERROR_RECORDER_BUSY";
85         case VC_ERROR_INVALID_STATE:            return "VC_ERROR_INVALID_STATE";
86         case VC_ERROR_INVALID_LANGUAGE:         return "VC_ERROR_INVALID_LANGUAGE";
87         case VC_ERROR_ENGINE_NOT_FOUND:         return "VC_ERROR_ENGINE_NOT_FOUND";
88         case VC_ERROR_OPERATION_FAILED:         return "VC_ERROR_OPERATION_FAILED";
89         default:                                return "Invalid error code";
90         }
91         return NULL;
92 }
93
94 static void __vc_mgr_lang_changed_cb(const char* before_lang, const char* current_lang)
95 {
96         SLOG(LOG_DEBUG, TAG_VCM, "Lang changed : Before lang(%s) Current lang(%s)",
97                                 before_lang, current_lang);
98
99         vc_current_language_changed_cb callback = NULL;
100         void* lang_user_data;
101         vc_mgr_client_get_current_lang_changed_cb(g_vc_m, &callback, &lang_user_data);
102
103         if (NULL != callback) {
104                 vc_mgr_client_use_callback(g_vc_m);
105                 callback(before_lang, current_lang, lang_user_data);
106                 vc_mgr_client_not_use_callback(g_vc_m);
107                 SLOG(LOG_DEBUG, TAG_VCM, "Language changed callback is called");
108         } else {
109                 SLOG(LOG_WARN, TAG_VCM, "[WARNING] Language changed callback is null");
110         }
111
112         return;
113 }
114
115 static int __vc_mgr_get_feature_enabled()
116 {
117         if (0 == g_feature_enabled) {
118                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Voice control feature NOT supported");
119                 return VC_ERROR_NOT_SUPPORTED;
120         } else if (-1 == g_feature_enabled) {
121                 bool vc_supported = false;
122                 bool mic_supported = false;
123                 if (0 == system_info_get_platform_bool(VC_FEATURE_PATH, &vc_supported)) {
124                         if (0 == system_info_get_platform_bool(VC_MIC_FEATURE_PATH, &mic_supported)) {
125                                 if (false == vc_supported || false == mic_supported) {
126                                         SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Voice control feature NOT supported");
127                                         g_feature_enabled = 0;
128                                         return VC_ERROR_NOT_SUPPORTED;
129                                 }
130
131                                 g_feature_enabled = 1;
132                         }
133                 }
134         }
135
136         return 0;
137 }
138
139 static int __check_privilege_initialize()
140 {
141         int ret = cynara_initialize(&p_cynara, NULL);
142         if (CYNARA_API_SUCCESS != ret)
143                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] fail to initialize");
144
145         return ret == CYNARA_API_SUCCESS;
146 }
147
148 static int __check_privilege(const char* uid, const char * privilege)
149 {
150         FILE *fp = NULL;
151         char label_path[1024] = "/proc/self/attr/current";
152         char smack_label[1024] = {'\0',};
153
154         if (!p_cynara) {
155                 return false;
156         }
157
158         fp = fopen(label_path, "r");
159         if (fp != NULL) {
160                 if (fread(smack_label, 1, sizeof(smack_label), fp) <= 0)
161                         SLOG(LOG_ERROR, TAG_VCM, "[ERROR] fail to fread");
162
163                 fclose(fp);
164         }
165
166         pid_t pid = getpid();
167         char *session = cynara_session_from_pid(pid);
168         int ret = cynara_check(p_cynara, smack_label, session, uid, privilege);
169         SLOG(LOG_DEBUG, TAG_VCM, "[Client]cynara_check returned %d(%s)", ret, (CYNARA_API_ACCESS_ALLOWED == ret) ? "Allowed" : "Denied");
170         if (session)
171                 free(session);
172
173         if (ret != CYNARA_API_ACCESS_ALLOWED)
174                 return false;
175
176         return true;
177 }
178
179 static void __check_privilege_deinitialize()
180 {
181         if (p_cynara)
182                 cynara_finish(p_cynara);
183         p_cynara = NULL;
184 }
185
186 static int __vc_mgr_check_privilege()
187 {
188         char uid[16];
189
190         if (0 == g_privilege_allowed) {
191                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Permission is denied");
192                 return VC_ERROR_PERMISSION_DENIED;
193         } else if (-1 == g_privilege_allowed) {
194                 if (false == __check_privilege_initialize()) {
195                         SLOG(LOG_ERROR, TAG_VCM, "[ERROR] privilege initialize is failed");
196                         return VC_ERROR_PERMISSION_DENIED;
197                 }
198                 snprintf(uid, 16, "%d", getuid());
199                 /* check 'recorder' privilege */
200                 if (false == __check_privilege(uid, VC_PRIVILEGE)) {
201                         SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Permission is denied(%s)", VC_PRIVILEGE);
202                         g_privilege_allowed = 0;
203                         __check_privilege_deinitialize();
204                         return VC_ERROR_PERMISSION_DENIED;
205                 }
206                 /* check 'voicecontrol.manager' privilege */
207                 if (false == __check_privilege(uid, VC_MGR_PRIVILEGE)) {
208                         SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Permission is denied(%s)", VC_MGR_PRIVILEGE);
209                         g_privilege_allowed = 0;
210                         __check_privilege_deinitialize();
211                         return VC_ERROR_PERMISSION_DENIED;
212                 }
213                 __check_privilege_deinitialize();
214         }
215
216         g_privilege_allowed = 1;
217         return VC_ERROR_NONE;
218 }
219
220 int vc_mgr_initialize(void)
221 {
222         SLOG(LOG_ERROR, TAG_VCM, "@@@ [Manager] Initialize");
223
224
225         if (0 != __vc_mgr_get_feature_enabled()) {
226                 SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] not supported");
227                 return VC_ERROR_NOT_SUPPORTED;
228         }
229
230         if (0 != __vc_mgr_check_privilege()) {
231                 return VC_ERROR_PERMISSION_DENIED;
232         }
233
234         /* check handle */
235         if (true == vc_mgr_client_is_valid(g_vc_m)) {
236                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Already initialized");
237                 return VC_ERROR_NONE;
238         }
239
240         if (0 != vc_mgr_dbus_open_connection()) {
241                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to open connection");
242                 return VC_ERROR_OPERATION_FAILED;
243         }
244
245         if (0 != vc_mgr_client_create(&g_vc_m)) {
246                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to create client!!!!!");
247                 return VC_ERROR_OUT_OF_MEMORY;
248         }
249
250         int ret = vc_config_mgr_initialize(g_vc_m->handle + VC_MANAGER_CONFIG_HANDLE);
251         if (0 != ret) {
252                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to init config manager : %d", ret);
253                 vc_mgr_client_destroy(g_vc_m);
254                 return VC_ERROR_OPERATION_FAILED;
255         }
256
257         ret = vc_config_mgr_set_lang_cb(g_vc_m->handle + VC_MANAGER_CONFIG_HANDLE, __vc_mgr_lang_changed_cb);
258         if (0 != ret) {
259                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to set callback : %d", ret);
260                 vc_config_mgr_finalize(g_vc_m->handle + VC_MANAGER_CONFIG_HANDLE);
261                 vc_mgr_client_destroy(g_vc_m);
262                 return VC_ERROR_OPERATION_FAILED;
263         }
264
265         ret = vc_db_initialize();
266         if (0 != ret) {
267                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to initialize DB : %d", ret);
268                 vc_config_mgr_finalize(g_vc_m->handle + VC_MANAGER_CONFIG_HANDLE);
269                 vc_mgr_client_destroy(g_vc_m);
270                 return ret;
271         }
272
273         /* for TTS feedback */
274 /*      ret = vc_mgr_player_init();
275         if (0 != ret) {
276                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to initialize VC mgr player : %d", ret);
277         }
278 */
279         SLOG(LOG_ERROR, TAG_VCM, "[Success] pid(%d)", g_vc_m->handle);
280
281         SLOG(LOG_DEBUG, TAG_VCM, "@@@");
282
283         return VC_ERROR_NONE;
284 }
285
286 static void __vc_mgr_internal_unprepare()
287 {
288         int ret = vc_mgr_dbus_request_finalize(g_vc_m->handle);
289         if (0 != ret) {
290                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to request finalize : %s", __vc_mgr_get_error_code(ret));
291         }
292
293         vc_mgr_client_set_internal_state(g_vc_m, VC_INTERNAL_STATE_NONE);
294         return;
295 }
296
297 int vc_mgr_deinitialize(void)
298 {
299         SLOG(LOG_ERROR, TAG_VCM, "@@@ [Manager] Deinitialize");
300
301         if (0 != __vc_mgr_get_feature_enabled()) {
302                 SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] not supported");
303                 return VC_ERROR_NOT_SUPPORTED;
304         }
305
306         if (0 != __vc_mgr_check_privilege()) {
307                 return VC_ERROR_PERMISSION_DENIED;
308         }
309
310         if (false == vc_mgr_client_is_valid(g_vc_m)) {
311                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] NOT initialized");
312                 SLOG(LOG_DEBUG, TAG_VCM, "@@@");
313                 return VC_ERROR_INVALID_STATE;
314         }
315
316         vc_state_e state;
317         vc_mgr_client_get_client_state(g_vc_m, &state);
318
319         /* check state */
320         switch (state) {
321         case VC_STATE_READY:
322                 __vc_mgr_internal_unprepare();
323                 /* no break. need to next step*/
324         case VC_STATE_INITIALIZED:
325                 if (NULL != g_m_connect_timer) {
326                         SLOG(LOG_DEBUG, TAG_VCM, "Connect Timer is deleted");
327                         ecore_timer_del(g_m_connect_timer);
328                         g_m_connect_timer = NULL;
329                 }
330
331                 vc_config_mgr_unset_lang_cb(g_vc_m->handle + VC_MANAGER_CONFIG_HANDLE);
332                 vc_config_mgr_finalize(g_vc_m->handle + VC_MANAGER_CONFIG_HANDLE);
333
334                 /* Free client resources */
335                 vc_mgr_client_destroy(g_vc_m);
336                 g_vc_m = NULL;
337                 break;
338         case VC_STATE_NONE:
339                 break;
340         }
341
342         SLOG(LOG_DEBUG, TAG_VCM, "Success: destroy");
343
344         int cnt = VC_COMMAND_TYPE_FOREGROUND;
345         do {
346                 int ret = vc_cmd_parser_delete_file(getpid(), cnt);
347                 if (0 != ret)
348                         SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to delete file, type(%d), ret(%d)", cnt, ret);
349         } while (VC_COMMAND_TYPE_EXCLUSIVE >= ++cnt);
350
351         int ret = vc_db_finalize();
352         if (0 != ret) {
353                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to finalize DB, ret(%d)", ret);
354         }
355
356         /* for TTS feedback */
357 /*      ret = vc_mgr_player_release();
358         if (0 != ret) {
359                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to release VC mgr player(%d)", ret);
360         }
361 */
362         if (0 != vc_mgr_dbus_close_connection()) {
363                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to close connection");
364         }
365
366         SLOG(LOG_ERROR, TAG_VCM, "@@@");
367
368         return VC_ERROR_NONE;
369 }
370
371 static Eina_Bool __vc_mgr_connect_daemon(void *data)
372 {
373         /* request initialization */
374         int ret = -1;
375         int service_state = 0;
376         int foreground = VC_RUNTIME_INFO_NO_FOREGROUND;
377
378         g_m_connect_timer = NULL;
379
380         ret = vc_mgr_dbus_request_initialize(g_vc_m->handle, &service_state, &foreground, &g_daemon_pid);
381
382         if (VC_ERROR_ENGINE_NOT_FOUND == ret) {
383                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to initialize : %s", __vc_mgr_get_error_code(ret));
384
385                 vc_mgr_client_set_error(g_vc_m, VC_ERROR_ENGINE_NOT_FOUND);
386                 ecore_main_loop_thread_safe_call_async(__vc_mgr_notify_error, (void*)g_vc_m);
387
388                 SLOG(LOG_DEBUG, TAG_VCM, "@@@");
389                 return EINA_FALSE;
390
391         } else if (0 != ret) {
392                 SLOG(LOG_ERROR, TAG_VCM, "[WARNING] Fail to connection. Retry to connect : %s", __vc_mgr_get_error_code(ret));
393                 return EINA_TRUE;
394         } else {
395                 /* Success to connect */
396         }
397
398         /* Set service state */
399         vc_service_state_e previous_service_state;
400         vc_mgr_client_get_service_state(g_vc_m, &previous_service_state);
401
402         vc_mgr_client_set_service_state(g_vc_m, (vc_service_state_e)service_state);
403
404         vc_service_state_changed_cb service_changed_callback = NULL;
405         void* user_data = NULL;
406         vc_mgr_client_get_service_state_changed_cb(g_vc_m, &service_changed_callback, &user_data);
407
408         if (NULL != service_changed_callback) {
409                 vc_mgr_client_use_callback(g_vc_m);
410                 service_changed_callback(previous_service_state, service_state, user_data);
411                 vc_mgr_client_not_use_callback(g_vc_m);
412                 SLOG(LOG_DEBUG, TAG_VCM, "Service state changed callback is called");
413         } else {
414                 SLOG(LOG_WARN, TAG_VCM, "[WARNING] Service state changed callback is null");
415         }
416
417         /* Set foreground */
418         vc_mgr_client_set_foreground(g_vc_m, foreground, true);
419
420         SLOG(LOG_ERROR, TAG_VCM, "[SUCCESS] Connected daemon");
421
422         /* Set client state */
423         vc_mgr_client_set_client_state(g_vc_m, VC_STATE_READY);
424
425         vc_state_changed_cb changed_callback = NULL;
426         vc_mgr_client_get_state_changed_cb(g_vc_m, &changed_callback, &user_data);
427
428         vc_state_e current_state;
429         vc_state_e before_state;
430
431         vc_mgr_client_get_before_state(g_vc_m, &current_state, &before_state);
432
433         if (NULL != changed_callback) {
434                 vc_mgr_client_use_callback(g_vc_m);
435                 changed_callback(before_state, current_state, user_data);
436                 vc_mgr_client_not_use_callback(g_vc_m);
437                 SLOG(LOG_DEBUG, TAG_VCM, "State changed callback is called");
438         } else {
439                 SLOG(LOG_WARN, TAG_VCM, "[WARNING] State changed callback is null");
440         }
441
442         SLOG(LOG_DEBUG, TAG_VCM, "@@@");
443
444         return EINA_FALSE;
445 }
446
447 static void __start_prepare_thread(void *data, Ecore_Thread *thread)
448 {
449         SLOG(LOG_ERROR, TAG_VCM, "@@@ Start prepare thread");
450         int ret = 1, retry_count = 0;
451
452         /* Send hello */
453         while (0 != ret) {
454
455                 if (retry_count == 10) {
456                         SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to request hello !!");
457                         return;
458                 }
459
460                 ret = vc_mgr_dbus_request_hello();
461                 if (ret == 0) {
462                         SLOG(LOG_DEBUG, TAG_VCM, "Success to request hello. retry count(%d)", retry_count);
463                         break;
464                 } else {
465                         retry_count++;
466                 }
467         }
468
469         ret = 1;
470         retry_count = 0;
471         while (0 != ret) {
472                 if (retry_count == 10) {
473                         SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to connect daemon !!");
474                         return;
475                 }
476                 ret = __vc_mgr_connect_daemon(NULL);
477                 if (ret == 0)
478                         break;
479                 else
480                         retry_count++;
481         }
482
483         return;
484 }
485
486 static void __end_prepare_thread(void *data, Ecore_Thread *thread)
487 {
488         SLOG(LOG_DEBUG, TAG_VCM, "@@@ End prepare thread");
489 }
490
491 int vc_mgr_prepare(void)
492 {
493         SLOG(LOG_ERROR, TAG_VCM, "@@@ [Manager] Prepare");
494
495         if (0 != __vc_mgr_get_feature_enabled()) {
496                 SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] not supported");
497                 return VC_ERROR_NOT_SUPPORTED;
498         }
499
500         if (0 != __vc_mgr_check_privilege()) {
501                 return VC_ERROR_PERMISSION_DENIED;
502         }
503
504         vc_state_e state;
505         if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) {
506                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] A handle is not available");
507                 SLOG(LOG_DEBUG, TAG_VCM, "@@@");
508                 return VC_ERROR_INVALID_STATE;
509         }
510
511         /* check state */
512         if (state != VC_STATE_INITIALIZED) {
513                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Invalid State: Current state is not 'CREATED'");
514                 SLOG(LOG_DEBUG, TAG_VCM, "@@@");
515                 return VC_ERROR_INVALID_STATE;
516         }
517
518         ecore_thread_run(__start_prepare_thread, __end_prepare_thread, NULL, NULL);
519
520         SLOG(LOG_DEBUG, TAG_VCM, "@@@");
521
522         return VC_ERROR_NONE;
523 }
524
525 int vc_mgr_unprepare(void)
526 {
527         SLOG(LOG_ERROR, TAG_VCM, "@@@ [Manager] Unprepare");
528
529         if (0 != __vc_mgr_get_feature_enabled()) {
530                 SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] not supported");
531                 return VC_ERROR_NOT_SUPPORTED;
532         }
533
534         if (0 != __vc_mgr_check_privilege()) {
535                 return VC_ERROR_PERMISSION_DENIED;
536         }
537
538         vc_state_e state;
539         if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) {
540                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] A handle is not available");
541                 SLOG(LOG_DEBUG, TAG_VCM, "@@@");
542                 return VC_ERROR_INVALID_STATE;
543         }
544
545         /* check state */
546         if (state != VC_STATE_READY) {
547                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Invalid State: Current state is not 'READY'");
548                 SLOG(LOG_DEBUG, TAG_VCM, "@@@");
549                 return VC_ERROR_INVALID_STATE;
550         }
551
552         __vc_mgr_internal_unprepare();
553
554         vc_mgr_client_set_client_state(g_vc_m, VC_STATE_INITIALIZED);
555         ecore_timer_add(0, __vc_mgr_notify_state_changed, g_vc_m);
556
557         SLOG(LOG_DEBUG, TAG_VCM, "@@@");
558
559         return VC_ERROR_NONE;
560 }
561
562 int vc_mgr_foreach_supported_languages(vc_supported_language_cb callback, void* user_data)
563 {
564         SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] Foreach Supported Language");
565
566         if (0 != __vc_mgr_get_feature_enabled()) {
567                 SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] not supported");
568                 return VC_ERROR_NOT_SUPPORTED;
569         }
570
571         if (0 != __vc_mgr_check_privilege()) {
572                 return VC_ERROR_PERMISSION_DENIED;
573         }
574
575         if (NULL == callback) {
576                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Input parameter is NULL");
577                 SLOG(LOG_DEBUG, TAG_VCM, "@@@");
578                 return VC_ERROR_INVALID_PARAMETER;
579         }
580
581         vc_state_e state;
582         if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) {
583                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] A handle is not available");
584                 SLOG(LOG_DEBUG, TAG_VCM, "@@@");
585                 return VC_ERROR_INVALID_STATE;
586         }
587
588         int ret = -1;
589         ret = vc_config_mgr_get_language_list(callback, user_data);
590         if (0 != ret) {
591                 ret = vc_config_convert_error_code((vc_config_error_e)ret);
592                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to get languages : %s", __vc_mgr_get_error_code(ret));
593         }
594
595         SLOG(LOG_DEBUG, TAG_VCM, "@@@");
596
597         return VC_ERROR_NONE;
598 }
599
600 int vc_mgr_get_current_language(char** language)
601 {
602         if (0 != __vc_mgr_get_feature_enabled()) {
603                 SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] not supported");
604                 return VC_ERROR_NOT_SUPPORTED;
605         }
606
607         if (0 != __vc_mgr_check_privilege()) {
608                 return VC_ERROR_PERMISSION_DENIED;
609         }
610
611         if (NULL == language) {
612                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Input parameter is NULL");
613                 return VC_ERROR_INVALID_PARAMETER;
614         }
615
616         vc_state_e state;
617         if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) {
618                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] A handle is not available");
619                 return VC_ERROR_INVALID_STATE;
620         }
621
622         int ret = -1;
623         ret = vc_config_mgr_get_default_language(language);
624         if (0 != ret) {
625                 ret = vc_config_convert_error_code((vc_config_error_e)ret);
626                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to get current languages : %s", __vc_mgr_get_error_code(ret));
627         } else {
628                 SLOG(LOG_ERROR, TAG_VCM, "[Get current language] language : %s", *language);
629         }
630
631         return ret;
632 }
633
634 int vc_mgr_get_state(vc_state_e* state)
635 {
636         SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] Get State");
637
638         if (0 != __vc_mgr_get_feature_enabled()) {
639                 SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] not supported");
640                 return VC_ERROR_NOT_SUPPORTED;
641         }
642
643         if (0 != __vc_mgr_check_privilege()) {
644                 return VC_ERROR_PERMISSION_DENIED;
645         }
646
647         if (NULL == state) {
648                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Input parameter is NULL");
649                 return VC_ERROR_INVALID_PARAMETER;
650         }
651
652         vc_state_e temp;
653         if (0 != vc_mgr_client_get_client_state(g_vc_m, &temp)) {
654                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] A handle is not available");
655                 SLOG(LOG_DEBUG, TAG_VCM, "@@@");
656                 return VC_ERROR_INVALID_STATE;
657         }
658
659         *state = temp;
660
661         switch (*state) {
662         case VC_STATE_NONE:             SLOG(LOG_DEBUG, TAG_VCM, "Current state is 'None'");            break;
663         case VC_STATE_INITIALIZED:      SLOG(LOG_DEBUG, TAG_VCM, "Current state is 'Created'");         break;
664         case VC_STATE_READY:            SLOG(LOG_DEBUG, TAG_VCM, "Current state is 'Ready'");           break;
665         default:                        SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Invalid state");
666         }
667
668         SLOG(LOG_DEBUG, TAG_VCM, "@@@");
669
670         return VC_ERROR_NONE;
671 }
672
673 int vc_mgr_get_service_state(vc_service_state_e* state)
674 {
675         SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] Get Service State");
676
677         if (0 != __vc_mgr_get_feature_enabled()) {
678                 SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] not supported");
679                 return VC_ERROR_NOT_SUPPORTED;
680         }
681
682         if (0 != __vc_mgr_check_privilege()) {
683                 return VC_ERROR_PERMISSION_DENIED;
684         }
685
686         if (NULL == state) {
687                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Input parameter is NULL");
688                 return VC_ERROR_INVALID_PARAMETER;
689         }
690
691         vc_state_e client_state;
692         if (0 != vc_mgr_client_get_client_state(g_vc_m, &client_state)) {
693                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] A handle is not available");
694                 return VC_ERROR_INVALID_STATE;
695         }
696
697         /* check state */
698         if (client_state != VC_STATE_READY) {
699                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Current state is not 'READY'");
700                 return VC_ERROR_INVALID_STATE;
701         }
702
703         /* get service state */
704         vc_service_state_e service_state;
705         if (0 != vc_mgr_client_get_service_state(g_vc_m, &service_state)) {
706                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to get service state");
707                 return VC_ERROR_OPERATION_FAILED;
708         }
709
710         *state = service_state;
711
712         switch (*state) {
713         case VC_SERVICE_STATE_NONE:             SLOG(LOG_DEBUG, TAG_VCM, "Current service state is 'None'");            break;
714         case VC_SERVICE_STATE_READY:            SLOG(LOG_DEBUG, TAG_VCM, "Current service state is 'Ready'");           break;
715         case VC_SERVICE_STATE_RECORDING:        SLOG(LOG_DEBUG, TAG_VCM, "Current service state is 'Recording'");       break;
716         case VC_SERVICE_STATE_PROCESSING:       SLOG(LOG_DEBUG, TAG_VCM, "Current service state is 'Processing'");      break;
717         default:                                SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Invalid state");
718         }
719
720         SLOG(LOG_DEBUG, TAG_VCM, "@@@");
721
722         return VC_ERROR_NONE;
723 }
724
725 int vc_mgr_set_demandable_client_rule(const char* rule)
726 {
727         SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] Set Demandable client rule");
728
729         if (0 != __vc_mgr_get_feature_enabled()) {
730                 SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] not supported");
731                 return VC_ERROR_NOT_SUPPORTED;
732         }
733
734         if (0 != __vc_mgr_check_privilege()) {
735                 return VC_ERROR_PERMISSION_DENIED;
736         }
737
738         vc_state_e state;
739         if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) {
740                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] A handle is not available");
741                 SLOG(LOG_DEBUG, TAG_VCM, "@@@");
742                 return VC_ERROR_INVALID_STATE;
743         }
744
745         /* check state */
746         if (state != VC_STATE_READY) {
747                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Invalid State: Current state is not 'READY'");
748                 SLOG(LOG_DEBUG, TAG_VCM, "@@@");
749                 return VC_ERROR_INVALID_STATE;
750         }
751
752         int ret = -1;
753         ret = vc_info_parser_set_demandable_client(rule);
754         if (0 != ret) {
755                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] rule is NOT valid");
756                 SLOG(LOG_DEBUG, TAG_VCM, "@@@");
757                 return VC_ERROR_INVALID_PARAMETER;
758         }
759
760         if (0 != vc_info_parser_get_demandable_clients(&g_demandable_client_list)) {
761                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to get demandable clients");
762                 return VC_ERROR_OPERATION_FAILED;
763         }
764
765         SLOG(LOG_DEBUG, TAG_VCM, "@@@");
766
767         return 0;
768 }
769
770 int vc_mgr_unset_demandable_client_rule(void)
771 {
772         if (0 != __vc_mgr_get_feature_enabled()) {
773                 SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] not supported");
774                 return VC_ERROR_NOT_SUPPORTED;
775         }
776
777         if (0 != __vc_mgr_check_privilege()) {
778                 return VC_ERROR_PERMISSION_DENIED;
779         }
780
781         vc_info_parser_set_demandable_client(NULL);
782
783         int count = 0;
784         int ret = -1;
785         while (0 != ret) {
786                 ret = vc_mgr_dbus_request_demandable_client(g_vc_m->handle);
787                 if (0 != ret) {
788                         if (VC_ERROR_TIMED_OUT != ret) {
789                                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to request unset client rule to daemon : %s", __vc_mgr_get_error_code(ret));
790                                 break;
791                         } else {
792                                 SLOG(LOG_WARN, TAG_VCM, "[WARNING] retry request unset client rule : %s", __vc_mgr_get_error_code(ret));
793                                 usleep(10000);
794                                 count++;
795                                 if (VC_RETRY_COUNT == count) {
796                                         SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to request");
797                                         break;
798                                 }
799                         }
800                 }
801         }
802
803         return 0;
804 }
805
806 int vc_mgr_is_command_format_supported(int format, bool* support)
807 {
808         SLOG(LOG_ERROR, TAG_VCM, "@@@ [Manager] Is command type supported");
809
810         if (0 != __vc_mgr_get_feature_enabled()) {
811                 SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] not supported");
812                 return VC_ERROR_NOT_SUPPORTED;
813         }
814
815         if (0 != __vc_mgr_check_privilege()) {
816                 return VC_ERROR_PERMISSION_DENIED;
817         }
818
819         if (NULL == support) {
820                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Invalid parameter, support is NULL ptr");
821                 return VC_ERROR_INVALID_PARAMETER;
822         }
823
824         vc_state_e state;
825         if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) {
826                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] A handle is not available");
827                 SLOG(LOG_DEBUG, TAG_VCM, "@@@");
828                 return VC_ERROR_INVALID_STATE;
829         }
830
831         /* check support */
832         bool non_fixed_support = false;
833         if (0 != vc_config_mgr_get_nonfixed_support(&non_fixed_support)) {
834                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to get nonfixed support info");
835         }
836
837         switch (format) {
838         case VC_CMD_FORMAT_FIXED:               *support = true;                break;
839         case VC_CMD_FORMAT_FIXED_AND_VFIXED:    *support = true;                break;
840         case VC_CMD_FORMAT_VFIXED_AND_FIXED:    *support = true;                break;
841         case VC_CMD_FORMAT_FIXED_AND_NONFIXED:  *support = non_fixed_support;   break;
842         case VC_CMD_FORMAT_NONFIXED_AND_FIXED:  *support = non_fixed_support;   break;
843         default:                                *support = false;               break;
844         }
845
846         SLOG(LOG_ERROR, TAG_VCM, "[DEBUG] Format(%d) support(%s)", format, *support ? "true" : "false");
847
848         SLOG(LOG_DEBUG, TAG_VCM, "@@@");
849
850         return VC_ERROR_NONE;
851 }
852
853 int vc_mgr_enable_command_type(int cmd_type)
854 {
855         SLOG(LOG_ERROR, TAG_VCM, "@@@ [Manager] Enable Command Type, cmd_type(%d)", cmd_type);
856
857         if (0 != __vc_mgr_get_feature_enabled()) {
858                 SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] not supported");
859                 return VC_ERROR_NOT_SUPPORTED;
860         }
861
862         if (0 != __vc_mgr_check_privilege()) {
863                 return VC_ERROR_PERMISSION_DENIED;
864         }
865
866         if (VC_COMMAND_TYPE_FOREGROUND > cmd_type || VC_COMMAND_TYPE_EXCLUSIVE < cmd_type) {
867                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] cmd_type is not valid. (%d)", cmd_type);
868                 return VC_ERROR_INVALID_PARAMETER;
869         }
870
871         vc_state_e state;
872         if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) {
873                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] A handle is not available");
874                 SLOG(LOG_DEBUG, TAG_VCM, "@@@");
875                 return VC_ERROR_INVALID_STATE;
876         }
877
878         /* check state */
879         if (state != VC_STATE_READY) {
880                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Invalid State: Current state is not 'READY'");
881                 SLOG(LOG_DEBUG, TAG_VCM, "@@@");
882                 return VC_ERROR_INVALID_STATE;
883         }
884
885         /* Check service state */
886         vc_service_state_e service_state = -1;
887         vc_mgr_client_get_service_state(g_vc_m, &service_state);
888         if (service_state != VC_SERVICE_STATE_READY) {
889                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Invalid State: service state is not 'READY'");
890                 SLOG(LOG_DEBUG, TAG_VCM, "@@@");
891                 return VC_ERROR_INVALID_STATE;
892         }
893
894         int ret;
895         int count = 0;
896         do {
897                 ret = vc_mgr_dbus_request_enable_command_type(g_vc_m->handle, cmd_type);
898                 if (0 != ret) {
899                         if (VC_ERROR_TIMED_OUT != ret) {
900                                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to request enable command type : %s", __vc_mgr_get_error_code(ret));
901                                 break;
902                         } else {
903                                 SLOG(LOG_WARN, TAG_VCM, "[WARNING] retry request enable command type : %s", __vc_mgr_get_error_code(ret));
904                                 usleep(10000);
905                                 count++;
906                                 if (VC_RETRY_COUNT == count) {
907                                         SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to request");
908                                         break;
909                                 }
910                         }
911                 }
912         } while (0 != ret);
913
914         SLOG(LOG_ERROR, TAG_VCM, "@@@, ret(%d)", ret);
915
916         return ret;
917 }
918
919 int vc_mgr_disable_command_type(int cmd_type)
920 {
921         SLOG(LOG_ERROR, TAG_VCM, "@@@ [Manager] Disable Command Type, cmd_type(%d)", cmd_type);
922
923         if (0 != __vc_mgr_get_feature_enabled()) {
924                 SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] not supported");
925                 return VC_ERROR_NOT_SUPPORTED;
926         }
927
928         if (0 != __vc_mgr_check_privilege()) {
929                 return VC_ERROR_PERMISSION_DENIED;
930         }
931
932         if (VC_COMMAND_TYPE_FOREGROUND > cmd_type || VC_COMMAND_TYPE_EXCLUSIVE < cmd_type) {
933                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] cmd type is not valid, (%d)", cmd_type);
934                 return VC_ERROR_INVALID_PARAMETER;
935         }
936
937         vc_state_e state;
938         if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) {
939                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] A handle is not available");
940                 SLOG(LOG_DEBUG, TAG_VCM, "@@@");
941                 return VC_ERROR_INVALID_STATE;
942         }
943
944         /* check state */
945         if (state != VC_STATE_READY) {
946                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Invalid State: Current state is not 'READY'");
947                 SLOG(LOG_DEBUG, TAG_VCM, "@@@");
948                 return VC_ERROR_INVALID_STATE;
949         }
950
951         /* Check service state */
952         vc_service_state_e service_state = -1;
953         vc_mgr_client_get_service_state(g_vc_m, &service_state);
954         if (service_state != VC_SERVICE_STATE_READY) {
955                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Invalid State: service state is not 'READY'");
956                 SLOG(LOG_DEBUG, TAG_VCM, "@@@");
957                 return VC_ERROR_INVALID_STATE;
958         }
959
960         int ret;
961         int count = 0;
962         do {
963                 ret = vc_mgr_dbus_request_disable_command_type(g_vc_m->handle, cmd_type);
964                 if (0 != ret) {
965                         if (VC_ERROR_TIMED_OUT != ret) {
966                                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to request disable command type : %s", __vc_mgr_get_error_code(ret));
967                                 break;
968                         } else {
969                                 SLOG(LOG_WARN, TAG_VCM, "[WARNING] retry request disable command type : %s", __vc_mgr_get_error_code(ret));
970                                 usleep(10000);
971                                 count++;
972                                 if (VC_RETRY_COUNT == count) {
973                                         SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to request");
974                                         break;
975                                 }
976                         }
977                 }
978         } while (0 != ret);
979
980         SLOG(LOG_ERROR, TAG_VCM, "@@@, ret(%d)", ret);
981
982         return ret;
983 }
984
985 int vc_mgr_set_command_list(vc_cmd_list_h vc_cmd_list)
986 {
987         SLOG(LOG_ERROR, TAG_VCM, "@@@ [Manager] Set Command list");
988
989         if (0 != __vc_mgr_get_feature_enabled()) {
990                 SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] not supported");
991                 return VC_ERROR_NOT_SUPPORTED;
992         }
993
994         if (0 != __vc_mgr_check_privilege()) {
995                 return VC_ERROR_PERMISSION_DENIED;
996         }
997
998         vc_state_e state;
999         if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) {
1000                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] A handle is not available");
1001                 SLOG(LOG_DEBUG, TAG_VCM, "@@@");
1002                 return VC_ERROR_INVALID_STATE;
1003         }
1004
1005         /* check state */
1006         if (state != VC_STATE_READY) {
1007                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Invalid State: Current state is not 'READY'");
1008                 SLOG(LOG_DEBUG, TAG_VCM, "@@@");
1009                 return VC_ERROR_INVALID_STATE;
1010         }
1011
1012         /* Check service state */
1013         vc_service_state_e service_state = -1;
1014         vc_mgr_client_get_service_state(g_vc_m, &service_state);
1015         if (service_state != VC_SERVICE_STATE_READY) {
1016                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Invalid State: service state is not 'READY'");
1017                 SLOG(LOG_DEBUG, TAG_VCM, "@@@");
1018                 return VC_ERROR_INVALID_STATE;
1019         }
1020
1021         if (NULL == vc_cmd_list) {
1022                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Input parameter is NULL");
1023                 return VC_ERROR_INVALID_PARAMETER;
1024         }
1025
1026         vc_cmd_list_s* list = NULL;
1027         list = (vc_cmd_list_s*)vc_cmd_list;
1028         SLOG(LOG_INFO, TAG_VCM, "[List] (%p) (%p)", list, list->list);
1029
1030         if (NULL == list->list) {
1031                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Invalid command list");
1032                 return VC_ERROR_INVALID_PARAMETER;
1033         }
1034
1035         int i;
1036         int ret;
1037         bool success_save = false;
1038         for (i = VC_COMMAND_TYPE_FOREGROUND; i <= VC_COMMAND_TYPE_EXCLUSIVE; i++) {
1039                 ret = vc_cmd_parser_delete_file(getpid(), i);
1040                 if (0 != ret)
1041                         SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to delete file, type(%d), ret(%d)", i, ret);
1042
1043                 ret = vc_cmd_parser_save_file(getpid(), i, list->list, NULL);
1044                 if (0 != ret) {
1045                         SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to save file, type(%d), ret(%d)", i, ret);
1046                 } else {
1047                         SLOG(LOG_DEBUG, TAG_VCM, "[SUCCESS] Save file, type(%d)", i);
1048                         success_save = true;
1049                 }
1050         }
1051
1052         if (true != success_save) {
1053                 ret = VC_ERROR_INVALID_PARAMETER;
1054                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to save command group : %s", __vc_mgr_get_error_code(ret));
1055         } else {
1056                 int count = 0;
1057                 do {
1058                         ret = vc_mgr_dbus_request_set_command(g_vc_m->handle);
1059                         if (0 != ret) {
1060                                 if (VC_ERROR_TIMED_OUT != ret) {
1061                                         SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to request set command to daemon : %s", __vc_mgr_get_error_code(ret));
1062                                         break;
1063                                 } else {
1064                                         SLOG(LOG_WARN, TAG_VCM, "[WARNING] retry request set command : %s", __vc_mgr_get_error_code(ret));
1065                                         usleep(10000);
1066                                         count++;
1067                                         if (VC_RETRY_COUNT == count) {
1068                                                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to request");
1069                                                 break;
1070                                         }
1071                                 }
1072                         }
1073                 } while (0 != ret);
1074         }
1075
1076         SLOG(LOG_ERROR, TAG_VCM, "@@@, ret(%d)", ret);
1077
1078         return ret;
1079 }
1080
1081 int vc_mgr_unset_command_list(void)
1082 {
1083         SLOG(LOG_ERROR, TAG_VCM, "@@@ [Manager] Unset Command list");
1084
1085         if (0 != __vc_mgr_get_feature_enabled()) {
1086                 SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] not supported");
1087                 return VC_ERROR_NOT_SUPPORTED;
1088         }
1089
1090         if (0 != __vc_mgr_check_privilege()) {
1091                 return VC_ERROR_PERMISSION_DENIED;
1092         }
1093
1094         vc_state_e state;
1095         if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) {
1096                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] A handle is not available");
1097                 return VC_ERROR_INVALID_STATE;
1098         }
1099
1100         /* check state */
1101         if (state != VC_STATE_READY) {
1102                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Current state is not 'READY'");
1103                 return VC_ERROR_INVALID_STATE;
1104         }
1105
1106         int count = 0;
1107         int ret = -1;
1108         while (0 != ret) {
1109                 ret = vc_mgr_dbus_request_unset_command(g_vc_m->handle);
1110                 if (0 != ret) {
1111                         if (VC_ERROR_TIMED_OUT != ret) {
1112                                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to request unset command to daemon : %s", __vc_mgr_get_error_code(ret));
1113                                 break;
1114                         } else {
1115                                 SLOG(LOG_WARN, TAG_VCM, "[WARNING] retry request unset command : %s", __vc_mgr_get_error_code(ret));
1116                                 usleep(10000);
1117                                 count++;
1118                                 if (VC_RETRY_COUNT == count) {
1119                                         SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to request");
1120                                         break;
1121                                 }
1122                         }
1123                 }
1124         }
1125
1126         int i;
1127         for (i = VC_COMMAND_TYPE_FOREGROUND; i <= VC_COMMAND_TYPE_EXCLUSIVE; i++) {
1128                 ret = vc_cmd_parser_delete_file(getpid(), i);
1129                 if (0 != ret)
1130                         SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to delete file, type(%d), ret(%d)", i, ret);
1131         }
1132
1133         SLOG(LOG_ERROR, TAG_VCM, "@@@");
1134
1135         return 0;
1136 }
1137
1138 int vc_mgr_set_command_list_from_file(const char* file_path, int type)
1139 {
1140         SLOG(LOG_ERROR, TAG_VCM, "@@@ [Manager] Set Command list from file, type(%d)", type);
1141
1142         if (0 != __vc_mgr_get_feature_enabled()) {
1143                 SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] not supported");
1144                 return VC_ERROR_NOT_SUPPORTED;
1145         }
1146
1147         if (0 != __vc_mgr_check_privilege()) {
1148                 return VC_ERROR_PERMISSION_DENIED;
1149         }
1150
1151         if (NULL == file_path) {
1152                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Invalid parameter!!");
1153                 return VC_ERROR_INVALID_PARAMETER;
1154         } else {
1155                 SLOG(LOG_DEBUG, TAG_VCM, "@@@ File path: %s", file_path);
1156         }
1157
1158         /* check type */
1159         if (VC_COMMAND_TYPE_FOREGROUND > type || VC_COMMAND_TYPE_EXCLUSIVE < type) {
1160                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Invalid command type: input type is %d", type);
1161                 SLOG(LOG_DEBUG, TAG_VCM, "@@@");
1162                 return VC_ERROR_INVALID_PARAMETER;
1163         }
1164
1165         vc_state_e state;
1166         if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) {
1167                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] A handle is not available");
1168                 return VC_ERROR_INVALID_STATE;
1169         }
1170
1171         /* check state */
1172         if (state != VC_STATE_READY) {
1173                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Invalid State: Current state is not 'READY'");
1174                 return VC_ERROR_INVALID_STATE;
1175         }
1176
1177         /* Check service state */
1178         vc_service_state_e service_state = -1;
1179         vc_mgr_client_get_service_state(g_vc_m, &service_state);
1180         if (service_state != VC_SERVICE_STATE_READY) {
1181                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Invalid State: service state is not 'READY'");
1182                 return VC_ERROR_INVALID_STATE;
1183         }
1184
1185         int ret = vc_cmd_parser_delete_file(getpid(), type);
1186         if (0 != ret)
1187                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to delete file, type(4), ret(%d)", ret);
1188
1189         if (0 != vc_json_set_commands_from_file(file_path, type, NULL)) {
1190                 ret = VC_ERROR_INVALID_PARAMETER;
1191                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to save command list (%d)", ret);
1192         } else {
1193                 int count = 0;
1194                 do {
1195                         ret = vc_mgr_dbus_request_set_command(g_vc_m->handle);
1196                         if (0 != ret) {
1197                                 if (VC_ERROR_TIMED_OUT != ret) {
1198                                         SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to request set command to daemon : %s", __vc_mgr_get_error_code(ret));
1199                                         break;
1200                                 } else {
1201                                         SLOG(LOG_WARN, TAG_VCM, "[WARNING] retry request set command : %s", __vc_mgr_get_error_code(ret));
1202                                         usleep(10000);
1203                                         count++;
1204                                         if (VC_RETRY_COUNT == count) {
1205                                                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to request");
1206                                                 break;
1207                                         }
1208                                 }
1209                         }
1210                 } while (0 != ret);
1211         }
1212
1213         SLOG(LOG_ERROR, TAG_VCM, "@@@, ret(%d)", ret);
1214
1215         return ret;
1216 }
1217
1218 int vc_mgr_set_preloaded_commands_from_file(const char* file_path)
1219 {
1220         SLOG(LOG_ERROR, TAG_VCM, "@@@ [Manager] Set preloaded command list");
1221
1222         if (0 != __vc_mgr_get_feature_enabled()) {
1223                 SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] not supported");
1224                 return VC_ERROR_NOT_SUPPORTED;
1225         }
1226
1227         if (0 != __vc_mgr_check_privilege()) {
1228                 return VC_ERROR_PERMISSION_DENIED;
1229         }
1230
1231         if (NULL == file_path) {
1232                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Invalid parameter!! file_path is NULL ptr");
1233                 return VC_ERROR_INVALID_PARAMETER;
1234         } else {
1235                 SLOG(LOG_DEBUG, TAG_VCM, "@@@ File path: %s", file_path);
1236         }
1237
1238         vc_state_e state;
1239         if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) {
1240                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] A handle is not available");
1241                 return VC_ERROR_INVALID_STATE;
1242         }
1243
1244         /* check state */
1245         if (state != VC_STATE_READY) {
1246                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Invalid State: Current state is not 'READY'");
1247                 return VC_ERROR_INVALID_STATE;
1248         }
1249
1250         /* Check service state */
1251         vc_service_state_e service_state = -1;
1252         vc_mgr_client_get_service_state(g_vc_m, &service_state);
1253         if (service_state != VC_SERVICE_STATE_READY) {
1254                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Invalid State: service state is not 'READY'");
1255                 return VC_ERROR_INVALID_STATE;
1256         }
1257
1258         /* Only support to set background commands for preloaded application */
1259         int ret = vc_json_set_commands_from_file(file_path, VC_COMMAND_TYPE_BACKGROUND, NULL);
1260         if (0 != ret)
1261                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to insert preloaded commands into db");
1262
1263         SLOG(LOG_ERROR, TAG_VCM, "@@@, ret(%d)", ret);
1264         return ret;
1265 }
1266
1267 int vc_mgr_set_audio_type(const char* audio_id)
1268 {
1269         SLOG(LOG_ERROR, TAG_VCM, "@@@ [Manager] Set audio type, audio_id(%s)", audio_id);
1270
1271         if (0 != __vc_mgr_get_feature_enabled()) {
1272                 SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] not supported");
1273                 return VC_ERROR_NOT_SUPPORTED;
1274         }
1275
1276         if (0 != __vc_mgr_check_privilege()) {
1277                 return VC_ERROR_PERMISSION_DENIED;
1278         }
1279
1280         if (NULL == audio_id) {
1281                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Input parameter is NULL");
1282                 return VC_ERROR_INVALID_PARAMETER;
1283         }
1284
1285         vc_state_e state;
1286         if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) {
1287                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] A handle is not available");
1288                 SLOG(LOG_DEBUG, TAG_VCM, "@@@");
1289                 return VC_ERROR_INVALID_STATE;
1290         }
1291
1292         /* check state */
1293         if (state != VC_STATE_READY) {
1294                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Invalid State: Current state is not 'READY'");
1295                 SLOG(LOG_DEBUG, TAG_VCM, "@@@");
1296                 return VC_ERROR_INVALID_STATE;
1297         }
1298
1299         /* Check service state */
1300         vc_service_state_e service_state = -1;
1301         vc_mgr_client_get_service_state(g_vc_m, &service_state);
1302         if (service_state != VC_SERVICE_STATE_READY) {
1303                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Invalid State: service state is not 'READY'");
1304                 SLOG(LOG_DEBUG, TAG_VCM, "@@@");
1305                 return VC_ERROR_INVALID_STATE;
1306         }
1307
1308         int ret = -1;
1309         int count = 0;
1310
1311         /* Request */
1312         while (0 != ret) {
1313                 ret = vc_mgr_dbus_request_set_audio_type(g_vc_m->handle, audio_id);
1314                 if (0 != ret) {
1315                         if (VC_ERROR_TIMED_OUT != ret) {
1316                                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to set audio type : %s", __vc_mgr_get_error_code(ret));
1317                                 break;
1318                         } else {
1319                                 SLOG(LOG_WARN, TAG_VCM, "[WARNING] retry to set audio type : %s", __vc_mgr_get_error_code(ret));
1320                                 usleep(10000);
1321                                 count++;
1322                                 if (VC_RETRY_COUNT == count) {
1323                                         SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to request");
1324                                         break;
1325                                 }
1326                         }
1327                 } else {
1328                         SLOG(LOG_DEBUG, TAG_VCM, "[SUCCESS] Set audio type");
1329                         /* Save */
1330                         vc_mgr_client_set_audio_type(g_vc_m, audio_id);
1331                 }
1332         }
1333
1334         SLOG(LOG_ERROR, TAG_VCM, "@@@, ret(%d)", ret);
1335
1336         return ret;
1337 }
1338
1339 int vc_mgr_get_audio_type(char** audio_id)
1340 {
1341         SLOG(LOG_ERROR, TAG_VCM, "@@@ [Manager] Get audio type");
1342
1343         if (0 != __vc_mgr_get_feature_enabled()) {
1344                 SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] not supported");
1345                 return VC_ERROR_NOT_SUPPORTED;
1346         }
1347
1348         if (0 != __vc_mgr_check_privilege()) {
1349                 return VC_ERROR_PERMISSION_DENIED;
1350         }
1351
1352         if (NULL == audio_id) {
1353                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Input parameter is NULL");
1354                 return VC_ERROR_INVALID_PARAMETER;
1355         }
1356
1357         vc_state_e state;
1358         if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) {
1359                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] A handle is not available");
1360                 SLOG(LOG_DEBUG, TAG_VCM, "@@@");
1361                 return VC_ERROR_INVALID_STATE;
1362         }
1363
1364         /* check state */
1365         if (state != VC_STATE_READY) {
1366                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Invalid State: Current state is not 'READY'");
1367                 SLOG(LOG_DEBUG, TAG_VCM, "@@@");
1368                 return VC_ERROR_INVALID_STATE;
1369         }
1370
1371         /* Check service state */
1372         vc_service_state_e service_state = -1;
1373         vc_mgr_client_get_service_state(g_vc_m, &service_state);
1374         if (service_state != VC_SERVICE_STATE_READY) {
1375                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Invalid State: service state is not 'READY'");
1376                 SLOG(LOG_DEBUG, TAG_VCM, "@@@");
1377                 return VC_ERROR_INVALID_STATE;
1378         }
1379
1380         char* temp = NULL;
1381
1382         vc_mgr_client_get_audio_type(g_vc_m, &temp);
1383
1384         if (NULL == temp) {
1385                 /* Not initiallized */
1386                 int ret = -1;
1387                 int count = 0;
1388                 while (0 != ret) {
1389                         ret = vc_mgr_dbus_request_get_audio_type(g_vc_m->handle, &temp);
1390                         if (0 != ret) {
1391                                 if (VC_ERROR_TIMED_OUT != ret) {
1392                                         SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to get audio type : %s", __vc_mgr_get_error_code(ret));
1393                                         break;
1394                                 } else {
1395                                         SLOG(LOG_WARN, TAG_VCM, "[WARNING] retry to get audio type : %s", __vc_mgr_get_error_code(ret));
1396                                         usleep(10000);
1397                                         count++;
1398                                         if (VC_RETRY_COUNT == count) {
1399                                                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to request");
1400                                                 break;
1401                                         }
1402                                 }
1403                         } else {
1404                                 SLOG(LOG_ERROR, TAG_VCM, "[SUCCESS] Get audio type : %s", temp);
1405                                 /* Save */
1406                                 vc_mgr_client_set_audio_type(g_vc_m, temp);
1407                         }
1408                 }
1409         }
1410
1411         if (NULL != temp) {
1412                 *audio_id = strdup(temp);
1413                 free(temp);
1414                 temp = NULL;
1415         }
1416
1417         return 0;
1418 }
1419
1420 int vc_mgr_get_current_commands(vc_cmd_list_h* vc_cmd_list)
1421 {
1422         SLOG(LOG_ERROR, TAG_VCM, "@@@ [Manager] Foreach current commands");
1423
1424         if (0 != __vc_mgr_get_feature_enabled()) {
1425                 SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] not supported");
1426                 return VC_ERROR_NOT_SUPPORTED;
1427         }
1428
1429         if (0 != __vc_mgr_check_privilege()) {
1430                 return VC_ERROR_PERMISSION_DENIED;
1431         }
1432
1433         vc_state_e state;
1434         if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) {
1435                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] A handle is not available");
1436                 SLOG(LOG_DEBUG, TAG_VCM, "@@@");
1437                 return VC_ERROR_INVALID_STATE;
1438         }
1439
1440         /* check state */
1441         if (state != VC_STATE_READY) {
1442                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Invalid State: Current state is not 'READY'");
1443                 SLOG(LOG_DEBUG, TAG_VCM, "@@@");
1444                 return VC_ERROR_INVALID_STATE;
1445         }
1446
1447         /* Check service state */
1448         vc_service_state_e service_state = -1;
1449         vc_mgr_client_get_service_state(g_vc_m, &service_state);
1450         if (service_state != VC_SERVICE_STATE_READY) {
1451                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Invalid State: service state is not 'READY'");
1452                 SLOG(LOG_DEBUG, TAG_VCM, "@@@");
1453                 return VC_ERROR_INVALID_STATE;
1454         }
1455
1456         if (NULL == vc_cmd_list) {
1457                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Invalid Parameter");
1458                 SLOG(LOG_DEBUG, TAG_VCM, "@@@");
1459                 return VC_ERROR_INVALID_PARAMETER;
1460         }
1461
1462         vc_cmd_list_h temp_list = NULL;
1463         if (0 != vc_cmd_list_create(&temp_list)) {
1464                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to create list");
1465                 return VC_ERROR_INVALID_PARAMETER;
1466         }
1467
1468         *vc_cmd_list = temp_list;
1469
1470         int fg_pid = 0;
1471         int mgr_pid = 0;
1472         int count = 0;
1473         int ret = -1;
1474
1475         /* Get foreground pid */
1476         if (0 != vc_mgr_client_get_foreground(g_vc_m, &fg_pid)) {
1477                 /* There is no foreground app for voice control */
1478                 SLOG(LOG_WARN, TAG_VCM, "[Manager WARNING] No foreground pid for voice control");
1479         } else {
1480                 SLOG(LOG_DEBUG, TAG_VCM, "[Manager] Foreground pid(%d)", fg_pid);
1481         }
1482
1483         if (0 != vc_mgr_client_get_pid(g_vc_m, &mgr_pid)) {
1484                 SLOG(LOG_DEBUG, TAG_VCM, "[Manager] Fail to get manager pid");
1485                 return VC_ERROR_OPERATION_FAILED;
1486         } else {
1487                 SLOG(LOG_DEBUG, TAG_VCM, "[Manager] Manager pid(%d)", mgr_pid);
1488         }
1489
1490         /* Get system command */
1491         ret = vc_cmd_parser_append_commands(mgr_pid, VC_COMMAND_TYPE_SYSTEM, temp_list);
1492         if (0 != ret) {
1493                 SLOG(LOG_DEBUG, TAG_VCM, "[Manager] No system commands");
1494         }
1495
1496         /* Request */
1497         ret = -1;
1498         count = 0;
1499         while (0 != ret) {
1500                 ret = vc_mgr_dbus_request_set_client_info(g_vc_m->handle);
1501                 if (0 != ret) {
1502                         if (VC_ERROR_TIMED_OUT != ret) {
1503                                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to set client info : %s", __vc_mgr_get_error_code(ret));
1504                                 break;
1505                         } else {
1506                                 SLOG(LOG_WARN, TAG_VCM, "[WARNING] retry to set client info : %s", __vc_mgr_get_error_code(ret));
1507                                 usleep(10000);
1508                                 count++;
1509                                 if (VC_RETRY_COUNT == count) {
1510                                         SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to request");
1511                                         break;
1512                                 }
1513                         }
1514                 } else {
1515                         SLOG(LOG_DEBUG, TAG_VCM, "[SUCCESS] Set client info");
1516                 }
1517         }
1518
1519         GSList *iter = NULL;
1520         GSList* client_info_list = NULL;
1521         vc_client_info_s *client_info = NULL;
1522         bool is_fgpid = false;
1523
1524         if (0 != vc_info_parser_get_client_info(&client_info_list)) {
1525                 SLOG(LOG_DEBUG, TAG_VCM, "[DEBUG] No client");
1526                 return 0;
1527         }
1528
1529         if (VC_NO_FOREGROUND_PID != fg_pid) {
1530                 iter = g_slist_nth(client_info_list, 0);
1531                 while (NULL != iter) {
1532                         client_info = iter->data;
1533                         if (NULL != client_info) {
1534                                 if (fg_pid == client_info->pid) {
1535                                         is_fgpid = true;
1536                                         break;
1537                                 }
1538                         }
1539                         iter = g_slist_next(iter);
1540                 }
1541         }
1542
1543         /* Get foreground commands and widget */
1544         if (true == is_fgpid) {
1545                 /* Get handle */
1546                 SLOG(LOG_DEBUG, TAG_VCM, "[Manager] fore cmd(%d)", client_info->fg_cmd);
1547
1548                 /* Get foreground command */
1549                 if (true == client_info->fg_cmd) {
1550                         ret = vc_cmd_parser_append_commands(fg_pid, VC_COMMAND_TYPE_FOREGROUND, temp_list);
1551                         if (0 != ret) {
1552                                 SLOG(LOG_ERROR, TAG_VCM, "[Client Data ERROR] Fail to get the fg command list");
1553                         }
1554                 } else {
1555                         SLOG(LOG_DEBUG, TAG_VCM, "[Manager] No foreground commands");
1556                 }
1557
1558                 /* Check exclusive option */
1559                 if (true == client_info->exclusive_cmd) {
1560                         SLOG(LOG_DEBUG, TAG_VCM, "[Manager] Exclusive command is ON");
1561
1562                         /* Set background command for exclusive option */
1563                         if (true == client_info->bg_cmd) {
1564                                 SLOG(LOG_DEBUG, TAG_VCM, "[Manager] Set background command");
1565                                 ret = vc_cmd_parser_append_commands(client_info->pid, VC_COMMAND_TYPE_BACKGROUND, temp_list);
1566                                 if (0 != ret) {
1567                                         SLOG(LOG_ERROR, TAG_VCM, "[Client Data ERROR] Fail to get the bg command list : pid(%d)", client_info->pid);
1568                                 }
1569                         }
1570
1571                         /* need to release client info */
1572                         iter = g_slist_nth(client_info_list, 0);
1573
1574                         while (NULL != iter) {
1575                                 client_info = iter->data;
1576                                 if (NULL != client_info) {
1577                                         free(client_info);
1578                                 }
1579                                 client_info_list = g_slist_remove_link(client_info_list, iter);
1580                                 iter = g_slist_nth(client_info_list, 0);
1581                         }
1582
1583                         SLOG(LOG_DEBUG, TAG_VCM, "@@@");
1584
1585                         return 0;
1586                 }
1587         } else {
1588                 SLOG(LOG_DEBUG, TAG_VCM, "[Manager] No foreground app");
1589         }
1590
1591         /* Get background commands */
1592         if (0 < g_slist_length(client_info_list)) {
1593                 iter = g_slist_nth(client_info_list, 0);
1594
1595                 while (NULL != iter) {
1596                         client_info = iter->data;
1597
1598                         if (NULL != client_info) {
1599                                 SLOG(LOG_DEBUG, TAG_VCM, "[Manager] Pid(%d) Back cmd(%d)", client_info->pid, client_info->bg_cmd);
1600                                 if (true == client_info->bg_cmd) {
1601                                         ret = vc_cmd_parser_append_commands(client_info->pid, VC_COMMAND_TYPE_BACKGROUND, temp_list);
1602                                         if (0 != ret) {
1603                                                 SLOG(LOG_ERROR, TAG_VCM, "[Client Data ERROR] Fail to get the bg command list : pid(%d)", client_info->pid);
1604                                         }
1605                                 }
1606                                 free(client_info);
1607                         }
1608                         client_info_list = g_slist_remove_link(client_info_list, iter);
1609
1610                         iter = g_slist_nth(client_info_list, 0);
1611                 }
1612         } else {
1613                 /* NO client */
1614                 SLOG(LOG_DEBUG, TAG_VCM, "[Manager] No background commands");
1615         }
1616
1617         SLOG(LOG_ERROR, TAG_VCM, "@@@");
1618
1619         return 0;
1620 }
1621
1622 int vc_mgr_set_recognition_mode(vc_recognition_mode_e mode)
1623 {
1624         SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] Set recognition mode = %d", mode);
1625
1626         if (0 != __vc_mgr_get_feature_enabled()) {
1627                 SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] not supported");
1628                 return VC_ERROR_NOT_SUPPORTED;
1629         }
1630
1631         if (0 != __vc_mgr_check_privilege()) {
1632                 return VC_ERROR_PERMISSION_DENIED;
1633         }
1634
1635         /* check vc recognition mode */
1636         if (mode > VC_RECOGNITION_MODE_MANUAL) {
1637                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] invalid parameter: 'mode' is not supported mode (%d)", mode);
1638                 return VC_ERROR_INVALID_PARAMETER;
1639         }
1640
1641         vc_state_e state;
1642         if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) {
1643                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] A handle is not available");
1644                 SLOG(LOG_DEBUG, TAG_VCM, "@@@");
1645                 return VC_ERROR_INVALID_STATE;
1646         }
1647
1648         /* check state */
1649         if (state != VC_STATE_READY) {
1650                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Invalid State: Current state is not 'READY'");
1651                 SLOG(LOG_DEBUG, TAG_VCM, "@@@");
1652                 return VC_ERROR_INVALID_STATE;
1653         }
1654
1655         /* Check service state */
1656         vc_service_state_e service_state = -1;
1657         vc_mgr_client_get_service_state(g_vc_m, &service_state);
1658         if (service_state != VC_SERVICE_STATE_READY) {
1659                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Invalid State: service state is not 'READY'");
1660                 SLOG(LOG_DEBUG, TAG_VCM, "@@@");
1661                 return VC_ERROR_INVALID_STATE;
1662         }
1663
1664         vc_mgr_client_set_recognition_mode(g_vc_m, mode);
1665         return 0;
1666 }
1667
1668 int vc_mgr_get_recognition_mode(vc_recognition_mode_e* mode)
1669 {
1670         if (0 != __vc_mgr_get_feature_enabled()) {
1671                 SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] not supported");
1672                 return VC_ERROR_NOT_SUPPORTED;
1673         }
1674
1675         if (0 != __vc_mgr_check_privilege()) {
1676                 return VC_ERROR_PERMISSION_DENIED;
1677         }
1678
1679         int ret = -1;
1680
1681         if (NULL == mode) {
1682                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Invalid parameter, mode is NULL ptr");
1683                 return VC_ERROR_INVALID_PARAMETER;
1684         }
1685
1686         ret = vc_mgr_client_get_recognition_mode(g_vc_m, mode);
1687         if (0 != ret) {
1688                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to get recognition mode");
1689                 return ret;
1690         }
1691
1692         SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] Get recognition mode = %d", *mode);
1693         return 0;
1694 }
1695
1696 int vc_mgr_set_private_data(const char* key, const char* data)
1697 {
1698         SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] Set private data");
1699
1700         if (0 != __vc_mgr_get_feature_enabled()) {
1701                 SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] not supported");
1702                 return VC_ERROR_NOT_SUPPORTED;
1703         }
1704
1705         if (0 != __vc_mgr_check_privilege()) {
1706                 return VC_ERROR_PERMISSION_DENIED;
1707         }
1708
1709         if (NULL == key) {
1710                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Invalid parameter");
1711                 return VC_ERROR_INVALID_PARAMETER;
1712         }
1713
1714         vc_state_e state;
1715         if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) {
1716                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] A handle is not available");
1717                 SLOG(LOG_DEBUG, TAG_VCM, "@@@");
1718                 return VC_ERROR_INVALID_STATE;
1719         }
1720
1721         /* check state */
1722         if (state != VC_STATE_READY) {
1723                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Invalid State: Current state is not 'READY'");
1724                 SLOG(LOG_DEBUG, TAG_VCM, "@@@");
1725                 return VC_ERROR_INVALID_STATE;
1726         }
1727
1728         /* Check service state */
1729         vc_service_state_e service_state = -1;
1730         vc_mgr_client_get_service_state(g_vc_m, &service_state);
1731         if (service_state != VC_SERVICE_STATE_READY) {
1732                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Invalid State: service state is not 'READY'");
1733                 SLOG(LOG_DEBUG, TAG_VCM, "@@@");
1734                 return VC_ERROR_INVALID_STATE;
1735         }
1736
1737         int ret = -1;
1738         ret = vc_mgr_dbus_request_set_private_data(g_vc_m->handle, key, data);
1739         if (0 != ret) {
1740                 SLOG(LOG_DEBUG, TAG_VCM, "[ERROR] Fail to set private data : %s", __vc_mgr_get_error_code(ret));
1741                 return ret;
1742         } else {
1743                 SLOG(LOG_DEBUG, TAG_VCM, "[SUCCESS] Set private data");
1744         }
1745
1746         SLOG(LOG_DEBUG, TAG_VCM, "@@@");
1747
1748         return 0;
1749 }
1750
1751 int vc_mgr_get_private_data(const char* key, char** data)
1752 {
1753         SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] Get private data");
1754
1755         if (0 != __vc_mgr_get_feature_enabled()) {
1756                 SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] not supported");
1757                 return VC_ERROR_NOT_SUPPORTED;
1758         }
1759
1760         if (0 != __vc_mgr_check_privilege()) {
1761                 return VC_ERROR_PERMISSION_DENIED;
1762         }
1763
1764         if (NULL == key || NULL == data) {
1765                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Invalid parameter");
1766                 return VC_ERROR_INVALID_PARAMETER;
1767         }
1768
1769         vc_state_e state;
1770         if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) {
1771                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] A handle is not available");
1772                 SLOG(LOG_DEBUG, TAG_VCM, "@@@");
1773                 return VC_ERROR_INVALID_STATE;
1774         }
1775
1776         /* check state */
1777         if (state != VC_STATE_READY) {
1778                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Invalid State: Current state is not 'READY'");
1779                 SLOG(LOG_DEBUG, TAG_VCM, "@@@");
1780                 return VC_ERROR_INVALID_STATE;
1781         }
1782
1783         /* Check service state */
1784         vc_service_state_e service_state = -1;
1785         vc_mgr_client_get_service_state(g_vc_m, &service_state);
1786         if (service_state != VC_SERVICE_STATE_READY) {
1787                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Invalid State: service state is not 'READY'");
1788                 SLOG(LOG_DEBUG, TAG_VCM, "@@@");
1789                 return VC_ERROR_INVALID_STATE;
1790         }
1791
1792         int ret = -1;
1793         int count = 0;
1794         char* temp = NULL;
1795
1796         while (0 != ret) {
1797                 ret = vc_mgr_dbus_request_get_private_data(g_vc_m->handle, key, &temp);
1798                 if (0 != ret) {
1799                         if (VC_ERROR_TIMED_OUT != ret) {
1800                                 SLOG(LOG_DEBUG, TAG_VCM, "[ERROR] Fail to get private data request : %s", __vc_mgr_get_error_code(ret));
1801                                 break;
1802                         } else {
1803                                 SLOG(LOG_WARN, TAG_VCM, "[WARNING] retry get private data request : %s", __vc_mgr_get_error_code(ret));
1804                                 usleep(10000);
1805                                 count++;
1806                                 if (VC_RETRY_COUNT == count) {
1807                                         SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to request");
1808                                         break;
1809                                 }
1810                         }
1811                 } else {
1812                         SLOG(LOG_DEBUG, TAG_VCM, "[SUCCESS] Get private data, key(%s), data(%s)", key, temp);
1813                 }
1814         }
1815
1816         if (NULL != temp) {
1817                 *data = strdup(temp);
1818                 free(temp);
1819                 temp = NULL;
1820         }
1821
1822         SLOG(LOG_DEBUG, TAG_VCM, "@@@");
1823
1824         return 0;
1825 }
1826
1827 int vc_mgr_set_domain(const char* domain)
1828 {
1829         SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] Set domain");
1830
1831         if (0 != __vc_mgr_get_feature_enabled()) {
1832                 SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] not supported");
1833                 return VC_ERROR_NOT_SUPPORTED;
1834         }
1835
1836         if (0 != __vc_mgr_check_privilege()) {
1837                 return VC_ERROR_PERMISSION_DENIED;
1838         }
1839
1840         if (NULL == domain) {
1841                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Invalid parameter");
1842                 return VC_ERROR_INVALID_PARAMETER;
1843         }
1844
1845         vc_state_e state;
1846         if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) {
1847                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] A handle is not available");
1848                 SLOG(LOG_DEBUG, TAG_VCM, "@@@");
1849                 return VC_ERROR_INVALID_STATE;
1850         }
1851
1852         /* check state */
1853         if (state != VC_STATE_READY) {
1854                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Invalid State: Current state is not 'READY'");
1855                 SLOG(LOG_DEBUG, TAG_VCM, "@@@");
1856                 return VC_ERROR_INVALID_STATE;
1857         }
1858
1859         /* Check service state */
1860         vc_service_state_e service_state = -1;
1861         vc_mgr_client_get_service_state(g_vc_m, &service_state);
1862         if (service_state != VC_SERVICE_STATE_READY) {
1863                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Invalid State: service state is not 'READY'");
1864                 SLOG(LOG_DEBUG, TAG_VCM, "@@@");
1865                 return VC_ERROR_INVALID_STATE;
1866         }
1867
1868         int ret = -1;
1869         int count = 0;
1870         while (0 != ret) {
1871                 ret = vc_mgr_dbus_request_set_domain(g_vc_m->handle, domain);
1872                 if (0 != ret) {
1873                         if (VC_ERROR_TIMED_OUT != ret) {
1874                                 SLOG(LOG_DEBUG, TAG_VCM, "[ERROR] Fail to set domain request : %s", __vc_mgr_get_error_code(ret));
1875                                 break;
1876                         } else {
1877                                 SLOG(LOG_WARN, TAG_VCM, "[WARNING] retry set domain request : %s", __vc_mgr_get_error_code(ret));
1878                                 usleep(10000);
1879                                 count++;
1880                                 if (VC_RETRY_COUNT == count) {
1881                                         SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to request");
1882                                         break;
1883                                 }
1884                         }
1885                 } else {
1886                         SLOG(LOG_DEBUG, TAG_VCM, "[SUCCESS] Set domain");
1887                 }
1888         }
1889         SLOG(LOG_DEBUG, TAG_VCM, "@@@");
1890
1891         return 0;
1892 }
1893
1894 int vc_mgr_do_action(vc_send_event_type_e type, char* send_event)
1895 {
1896         SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] do action");
1897
1898         if (0 != __vc_mgr_get_feature_enabled()) {
1899                 SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] not supported");
1900                 return VC_ERROR_NOT_SUPPORTED;
1901         }
1902
1903         if (0 != __vc_mgr_check_privilege()) {
1904                 return VC_ERROR_PERMISSION_DENIED;
1905         }
1906
1907         if (NULL == send_event) {
1908                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Invalid parameter");
1909                 return VC_ERROR_INVALID_PARAMETER;
1910         }
1911
1912         vc_state_e state;
1913         if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) {
1914                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] A handle is not available");
1915                 SLOG(LOG_DEBUG, TAG_VCM, "@@@");
1916                 return VC_ERROR_INVALID_STATE;
1917         }
1918
1919         /* check state */
1920         if (state != VC_STATE_READY) {
1921                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Invalid State: Current state is not 'READY'");
1922                 SLOG(LOG_DEBUG, TAG_VCM, "@@@");
1923                 return VC_ERROR_INVALID_STATE;
1924         }
1925
1926         /* Check service state */
1927         vc_service_state_e service_state = -1;
1928         vc_mgr_client_get_service_state(g_vc_m, &service_state);
1929         if (service_state != VC_SERVICE_STATE_READY) {
1930                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Invalid State: service state is not 'READY'");
1931                 SLOG(LOG_DEBUG, TAG_VCM, "@@@");
1932                 return VC_ERROR_INVALID_STATE;
1933         }
1934
1935         int ret = -1;
1936         ret = vc_mgr_dbus_request_do_action(g_vc_m->handle, type, send_event);
1937         if (0 != ret) {
1938                 SLOG(LOG_DEBUG, TAG_VCM, "[ERROR] Fail to do action request : %s", __vc_mgr_get_error_code(ret));
1939                 return ret;
1940         } else {
1941                 SLOG(LOG_DEBUG, TAG_VCM, "[SUCCESS] do action");
1942         }
1943         SLOG(LOG_DEBUG, TAG_VCM, "@@@");
1944
1945         return 0;
1946 }
1947
1948 int vc_mgr_send_specific_engine_request(const char* engine_app_id, const char* event, const char* request)
1949 {
1950         SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] specific engine request. engine app id(%s), event(%s), request(%s)", engine_app_id, event, request);
1951
1952         if (NULL == engine_app_id || NULL == event) {
1953                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Invalid parameter");
1954                 return VC_ERROR_INVALID_PARAMETER;
1955         }
1956
1957         if (NULL == request) {
1958                 SLOG(LOG_ERROR, TAG_VCM, "[INFO] Input parameter is NULL. (no request)");
1959         }
1960
1961         vc_state_e state;
1962         if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) {
1963                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] A handle is not available");
1964                 SLOG(LOG_DEBUG, TAG_VCM, "@@@");
1965                 return VC_ERROR_INVALID_STATE;
1966         }
1967
1968         /* check state */
1969         if (state != VC_STATE_READY) {
1970                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Invalid State: Current state(%d) is not 'READY'", state);
1971                 SLOG(LOG_DEBUG, TAG_VCM, "@@@");
1972                 return VC_ERROR_INVALID_STATE;
1973         }
1974
1975         /* Check service state */
1976         vc_service_state_e service_state = -1;
1977         vc_mgr_client_get_service_state(g_vc_m, &service_state);
1978         if (service_state != VC_SERVICE_STATE_READY) {
1979                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Invalid State: service state(%d) is not 'READY'", service_state);
1980                 SLOG(LOG_DEBUG, TAG_VCM, "@@@");
1981                 return VC_ERROR_INVALID_STATE;
1982         }
1983
1984         int ret = -1;
1985         ret = vc_mgr_dbus_send_specific_engine_request(g_vc_m->handle, engine_app_id, event, request);
1986         if (0 != ret) {
1987                 SLOG(LOG_DEBUG, TAG_VCM, "[ERROR] Fail to specific engine request : %s", __vc_mgr_get_error_code(ret));
1988                 return ret;
1989         } else {
1990                 SLOG(LOG_DEBUG, TAG_VCM, "[SUCCESS] specific engine request");
1991         }
1992         SLOG(LOG_DEBUG, TAG_VCM, "@@@");
1993
1994         return 0;
1995 }
1996
1997 int vc_mgr_start(bool exclusive_command_option)
1998 {
1999         SLOG(LOG_ERROR, TAG_VCM, "@@@ [Manager] Request start");
2000
2001         if (0 != __vc_mgr_get_feature_enabled()) {
2002                 SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] not supported");
2003                 return VC_ERROR_NOT_SUPPORTED;
2004         }
2005
2006         if (0 != __vc_mgr_check_privilege()) {
2007                 return VC_ERROR_PERMISSION_DENIED;
2008         }
2009
2010         vc_state_e state;
2011         if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) {
2012                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] A handle is not available");
2013                 SLOG(LOG_DEBUG, TAG_VCM, "@@@");
2014                 return VC_ERROR_INVALID_STATE;
2015         }
2016
2017         /* check state */
2018         if (state != VC_STATE_READY) {
2019                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Invalid State: Current state is not 'READY'");
2020                 SLOG(LOG_DEBUG, TAG_VCM, "@@@");
2021                 return VC_ERROR_INVALID_STATE;
2022         }
2023
2024         /* Check service state */
2025         vc_service_state_e service_state = -1;
2026         vc_mgr_client_get_service_state(g_vc_m, &service_state);
2027         if (service_state != VC_SERVICE_STATE_READY) {
2028                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Invalid State: service state is not 'READY'");
2029                 SLOG(LOG_DEBUG, TAG_VCM, "@@@");
2030                 return VC_ERROR_INVALID_STATE;
2031         }
2032
2033         /* Check internal state for async */
2034         vc_internal_state_e internal_state = -1;
2035         vc_mgr_client_get_internal_state(g_vc_m, &internal_state);
2036         if (internal_state != VC_INTERNAL_STATE_NONE) {
2037                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Invalid State : Internal state is NOT none : %d", internal_state);
2038                 return VC_ERROR_IN_PROGRESS_TO_RECORDING;
2039         }
2040
2041         vc_mgr_client_set_exclusive_command(g_vc_m, exclusive_command_option);
2042
2043         bool start_by_client = false;
2044         if (0 != vc_mgr_client_get_start_by_client(g_vc_m, &start_by_client)) {
2045                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to get start by client");
2046         }
2047
2048         int ret;
2049         int count = 0;
2050         vc_recognition_mode_e recognition_mode = VC_RECOGNITION_MODE_STOP_BY_SILENCE;
2051         if (0 != vc_mgr_get_recognition_mode(&recognition_mode)) {
2052                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to get recognition mode");
2053         }
2054
2055         /* Request */
2056         ret = -1;
2057         count = 0;
2058         while (0 != ret) {
2059                 vc_mgr_client_set_internal_state(g_vc_m, VC_INTERNAL_STATE_STARTING);
2060                 ret = vc_mgr_dbus_request_start(g_vc_m->handle, (int)recognition_mode, exclusive_command_option, start_by_client);
2061                 if (0 != ret) {
2062                         if (VC_ERROR_TIMED_OUT != ret) {
2063                                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to start request start : %s", __vc_mgr_get_error_code(ret));
2064                                 vc_mgr_client_set_internal_state(g_vc_m, VC_INTERNAL_STATE_NONE);
2065                                 break;
2066                         } else {
2067                                 SLOG(LOG_WARN, TAG_VCM, "[WARNING] retry start request start : %s", __vc_mgr_get_error_code(ret));
2068                                 usleep(10000);
2069                                 count++;
2070                                 if (VC_RETRY_COUNT == count) {
2071                                         SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to request");
2072                                         vc_mgr_client_set_exclusive_command(g_vc_m, false);
2073                                         vc_mgr_client_set_internal_state(g_vc_m, VC_INTERNAL_STATE_NONE);
2074                                         break;
2075                                 }
2076                         }
2077                 } else {
2078                         SLOG(LOG_DEBUG, TAG_VCM, "[SUCCESS] start recognition");
2079                 }
2080         }
2081
2082         g_volume_db = 0;
2083         g_prev_volume_db = 0;
2084         g_cur_volume_db = 0;
2085
2086         SLOG(LOG_ERROR, TAG_VCM, "@@@, ret(%d)", ret);
2087
2088         return ret;
2089 }
2090
2091 int vc_mgr_stop(void)
2092 {
2093         SLOG(LOG_ERROR, TAG_VCM, "@@@ [Manager] Request stop");
2094
2095         if (0 != __vc_mgr_get_feature_enabled()) {
2096                 SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] not supported");
2097                 return VC_ERROR_NOT_SUPPORTED;
2098         }
2099
2100         if (0 != __vc_mgr_check_privilege()) {
2101                 return VC_ERROR_PERMISSION_DENIED;
2102         }
2103
2104         vc_state_e state;
2105         if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) {
2106                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] A handle is not available");
2107                 SLOG(LOG_DEBUG, TAG_VCM, "@@@");
2108                 return VC_ERROR_INVALID_STATE;
2109         }
2110
2111         /* check state */
2112         if (state != VC_STATE_READY) {
2113                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Invalid State: client state is not 'READY'");
2114                 SLOG(LOG_DEBUG, TAG_VCM, "@@@");
2115                 return VC_ERROR_INVALID_STATE;
2116         }
2117
2118         /* Check service state */
2119         vc_service_state_e service_state = -1;
2120         vc_mgr_client_get_service_state(g_vc_m, &service_state);
2121         if (service_state != VC_SERVICE_STATE_RECORDING) {
2122                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Invalid State: service state is not 'RECORDING'");
2123                 SLOG(LOG_DEBUG, TAG_VCM, "@@@");
2124                 return VC_ERROR_INVALID_STATE;
2125         }
2126
2127         /* Check internal state for async */
2128         vc_internal_state_e internal_state = -1;
2129         vc_mgr_client_get_internal_state(g_vc_m, &internal_state);
2130         if (VC_INTERNAL_STATE_STARTING == internal_state) {
2131                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Invalid State : Internal state is STARTING");
2132                 return VC_ERROR_IN_PROGRESS_TO_RECORDING;
2133         } else if (VC_INTERNAL_STATE_STOPPING == internal_state) {
2134                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Invalid State : Internal state is STOPPING");
2135                 return VC_ERROR_IN_PROGRESS_TO_PROCESSING;
2136         } else if (VC_INTERNAL_STATE_CANCELING == internal_state) {
2137                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Invalid State : Internal state is CANCELING");
2138                 return VC_ERROR_IN_PROGRESS_TO_READY;
2139         }
2140
2141         int ret = -1;
2142         int count = 0;
2143         /* do request */
2144         while (0 != ret) {
2145                 vc_mgr_client_set_internal_state(g_vc_m, VC_INTERNAL_STATE_STOPPING);
2146                 ret = vc_mgr_dbus_request_stop(g_vc_m->handle);
2147                 if (0 != ret) {
2148                         if (VC_ERROR_TIMED_OUT != ret) {
2149                                 SLOG(LOG_DEBUG, TAG_VCM, "[ERROR] Fail to stop request : %s", __vc_mgr_get_error_code(ret));
2150                                 vc_mgr_client_set_internal_state(g_vc_m, VC_INTERNAL_STATE_NONE);
2151                                 break;
2152                         } else {
2153                                 SLOG(LOG_WARN, TAG_VCM, "[WARNING] retry stop request : %s", __vc_mgr_get_error_code(ret));
2154                                 usleep(10000);
2155                                 count++;
2156                                 if (VC_RETRY_COUNT == count) {
2157                                         SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to request");
2158                                         vc_mgr_client_set_internal_state(g_vc_m, VC_INTERNAL_STATE_NONE);
2159                                         break;
2160                                 }
2161                         }
2162                 } else {
2163                         SLOG(LOG_DEBUG, TAG_VCM, "[SUCCESS] Stop recognition");
2164                 }
2165         }
2166
2167         SLOG(LOG_DEBUG, TAG_VCM, "@@@");
2168
2169         return ret;
2170 }
2171
2172 int vc_mgr_cancel(void)
2173 {
2174         SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] Request cancel");
2175
2176         if (0 != __vc_mgr_get_feature_enabled()) {
2177                 SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] not supported");
2178                 return VC_ERROR_NOT_SUPPORTED;
2179         }
2180
2181         if (0 != __vc_mgr_check_privilege()) {
2182                 return VC_ERROR_PERMISSION_DENIED;
2183         }
2184
2185         vc_state_e state;
2186         if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) {
2187                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] A handle is not available");
2188                 SLOG(LOG_DEBUG, TAG_VCM, "@@@");
2189                 return VC_ERROR_INVALID_STATE;
2190         }
2191
2192         /* check state */
2193         if (state != VC_STATE_READY) {
2194                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Invalid State: client state is not 'READY'");
2195                 SLOG(LOG_DEBUG, TAG_VCM, "@@@");
2196                 return VC_ERROR_INVALID_STATE;
2197         }
2198
2199         /* Check service state */
2200         vc_service_state_e service_state = -1;
2201         vc_mgr_client_get_service_state(g_vc_m, &service_state);
2202         if (service_state == VC_SERVICE_STATE_NONE) {
2203                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Invalid State");
2204                 SLOG(LOG_DEBUG, TAG_VCM, "@@@");
2205                 return VC_ERROR_INVALID_STATE;
2206         }
2207
2208         vc_internal_state_e internal_state = -1;
2209         vc_mgr_client_get_internal_state(g_vc_m, &internal_state);
2210         if (VC_INTERNAL_STATE_STARTING == internal_state) {
2211                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Invalid State : Internal state is STARTING");
2212                 return VC_ERROR_IN_PROGRESS_TO_RECORDING;
2213         } else if (VC_INTERNAL_STATE_STOPPING == internal_state) {
2214                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Invalid State : Internal state is STOPPING");
2215                 return VC_ERROR_IN_PROGRESS_TO_PROCESSING;
2216         } else if (VC_INTERNAL_STATE_CANCELING == internal_state) {
2217                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Invalid State : Internal state is CANCELING");
2218                 return VC_ERROR_IN_PROGRESS_TO_READY;
2219         }
2220
2221         int ret = -1;
2222         int count = 0;
2223         while (0 != ret) {
2224                 vc_mgr_client_set_internal_state(g_vc_m, VC_INTERNAL_STATE_CANCELING);
2225                 ret = vc_mgr_dbus_request_cancel(g_vc_m->handle);
2226                 if (0 != ret) {
2227                         if (VC_ERROR_TIMED_OUT != ret) {
2228                                 SLOG(LOG_DEBUG, TAG_VCM, "[ERROR] Fail to cancel request : %s", __vc_mgr_get_error_code(ret));
2229                                 vc_mgr_client_set_internal_state(g_vc_m, VC_INTERNAL_STATE_NONE);
2230                                 break;
2231                         } else {
2232                                 SLOG(LOG_WARN, TAG_VCM, "[WARNING] retry cancel request : %s", __vc_mgr_get_error_code(ret));
2233                                 usleep(10000);
2234                                 count++;
2235                                 if (VC_RETRY_COUNT == count) {
2236                                         SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to request");
2237                                         vc_mgr_client_set_internal_state(g_vc_m, VC_INTERNAL_STATE_NONE);
2238                                         break;
2239                                 }
2240                         }
2241                 } else {
2242                         SLOG(LOG_DEBUG, TAG_VCM, "[SUCCESS] Cancel recognition");
2243                 }
2244         }
2245
2246         vc_mgr_client_set_exclusive_command(g_vc_m, false);
2247
2248         SLOG(LOG_DEBUG, TAG_VCM, "@@@");
2249
2250         return ret;
2251 }
2252
2253 static int g_cnt = 0;
2254 static Eina_Bool __vc_mgr_set_volume(void* data)
2255 {
2256         g_cnt++;
2257         g_volume_db = g_prev_volume_db + (g_cur_volume_db - g_prev_volume_db) / 5 * g_cnt;
2258
2259         SLOG(LOG_DEBUG, TAG_VCM, "Set volume (%f)(%f)", g_volume_db, g_cur_volume_db);
2260
2261         if (0 == g_cnt % 5) {
2262                 return EINA_FALSE;
2263         }
2264         return EINA_TRUE;
2265 }
2266
2267 int __vc_mgr_cb_set_volume(float volume)
2268 {
2269         g_prev_volume_db = g_volume_db;
2270         g_cur_volume_db = volume;
2271
2272         g_volume_db = g_prev_volume_db + (g_cur_volume_db - g_prev_volume_db) / 5;
2273
2274         if (NULL != g_m_set_volume_timer) {
2275                 ecore_timer_del(g_m_set_volume_timer);
2276         }
2277
2278         g_cnt = 1;
2279         g_m_set_volume_timer = ecore_timer_add(0.05, __vc_mgr_set_volume, NULL);
2280
2281         return 0;
2282 }
2283
2284 int vc_mgr_get_recording_volume(float* volume)
2285 {
2286         if (0 != __vc_mgr_get_feature_enabled()) {
2287                 SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] not supported");
2288                 return VC_ERROR_NOT_SUPPORTED;
2289         }
2290
2291         if (0 != __vc_mgr_check_privilege()) {
2292                 return VC_ERROR_PERMISSION_DENIED;
2293         }
2294
2295         if (NULL == volume) {
2296                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Input parameter is NULL");
2297                 return VC_ERROR_INVALID_PARAMETER;
2298         }
2299
2300         vc_service_state_e service_state = -1;
2301         if (0 != vc_mgr_client_get_service_state(g_vc_m, &service_state)) {
2302                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] A handle is not available");
2303                 return VC_ERROR_INVALID_STATE;
2304         }
2305
2306         /* check state */
2307         if (VC_SERVICE_STATE_RECORDING != service_state) {
2308                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Invalid State: Service state is not 'RECORDING'");
2309                 return VC_ERROR_INVALID_STATE;
2310         }
2311
2312         *volume = g_volume_db;
2313
2314         return 0;
2315 }
2316
2317 int __vc_mgr_cb_set_foreground(int pid, bool value)
2318 {
2319         vc_mgr_client_set_foreground(g_vc_m, pid, value);
2320
2321         /* get authorized valid app */
2322         int tmp_pid;
2323         if (0 != vc_mgr_client_get_valid_authorized_client(g_vc_m, &tmp_pid)) {
2324                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to get authorized valid app");
2325                 return VC_ERROR_INVALID_PARAMETER;
2326         }
2327
2328         if (true == value) {
2329                 /* compare & set valid */
2330                 if (tmp_pid != pid) {
2331                         SLOG(LOG_DEBUG, TAG_VCM, "Authority(%d) changed to invalid", tmp_pid);
2332
2333                         /* set authorized valid */
2334                         if (true == vc_mgr_client_is_authorized_client(g_vc_m, pid)) {
2335                                 SLOG(LOG_DEBUG, TAG_VCM, "Authority(%d) change to valid", pid);
2336                                 vc_mgr_client_set_valid_authorized_client(g_vc_m, pid);
2337                         } else {
2338                                 SLOG(LOG_DEBUG, TAG_VCM, "No valid Authority");
2339                                 vc_mgr_client_set_valid_authorized_client(g_vc_m, -1);
2340                         }
2341                 }
2342         } else {
2343                 if (tmp_pid == pid) {
2344                         SLOG(LOG_DEBUG, TAG_VCM, "Authority(%d) changed to invalid", tmp_pid);
2345                         vc_mgr_client_set_valid_authorized_client(g_vc_m, -1);
2346                 }
2347         }
2348
2349         return 0;
2350 }
2351
2352 int vc_mgr_set_selected_results(vc_cmd_list_h vc_cmd_list)
2353 {
2354         SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] Select result");
2355
2356         if (0 != __vc_mgr_get_feature_enabled()) {
2357                 SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] not supported");
2358                 return VC_ERROR_NOT_SUPPORTED;
2359         }
2360
2361         if (0 != __vc_mgr_check_privilege()) {
2362                 return VC_ERROR_PERMISSION_DENIED;
2363         }
2364
2365         /* Do not check state for 'restart continuously' mode */
2366
2367         vc_service_state_e service_state = -1;
2368         vc_mgr_client_get_service_state(g_vc_m, &service_state);
2369         if (service_state != VC_SERVICE_STATE_PROCESSING) {
2370                 vc_recognition_mode_e recognition_mode;
2371                 vc_mgr_get_recognition_mode(&recognition_mode);
2372
2373                 if (VC_RECOGNITION_MODE_RESTART_CONTINUOUSLY != recognition_mode) {
2374                         SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Invalid State: service state is not 'PROCESSING' and mode is not 'Restart continuously'");
2375                         SLOG(LOG_DEBUG, TAG_VCM, "@@@");
2376                         return VC_ERROR_INVALID_STATE;
2377                 }
2378         }
2379
2380         if (NULL != vc_cmd_list) {
2381                 int event = 0;
2382                 char* result_text = NULL;
2383
2384                 vc_mgr_client_get_all_result(g_vc_m, &event, &result_text);
2385
2386                 vc_info_parser_set_result(result_text, event, NULL, vc_cmd_list, false);
2387
2388                 if (NULL != result_text) {
2389                         free(result_text);
2390                         result_text = NULL;
2391                 }
2392         }
2393
2394         /* Request */
2395         int ret = -1;
2396         ret = vc_mgr_dbus_send_result_selection(g_vc_m->handle);
2397         if (0 != ret) {
2398                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to send result selection : %s", __vc_mgr_get_error_code(ret));
2399                 return ret;
2400         } else {
2401                 SLOG(LOG_DEBUG, TAG_VCM, "[SUCCESS] result selection");
2402         }
2403
2404         vc_mgr_client_unset_all_result(g_vc_m);
2405
2406         SLOG(LOG_DEBUG, TAG_VCM, "@@@");
2407
2408         return 0;
2409 }
2410
2411 static Eina_Bool __vc_mgr_set_select_result(void *data)
2412 {
2413         vc_mgr_set_selected_results(NULL);
2414         return EINA_FALSE;
2415 }
2416
2417 static void __vc_mgr_notify_all_result(vc_result_type_e result_type)
2418 {
2419         char* temp_text = NULL;
2420         int event;
2421         char* temp_message = NULL;
2422         vc_cmd_list_h vc_cmd_list = NULL;
2423
2424         vc_mgr_all_result_cb all_callback = NULL;
2425         void* all_user_data = NULL;
2426
2427         vc_mgr_client_get_all_result_cb(g_vc_m, &all_callback, &all_user_data);
2428         if (NULL == all_callback) {
2429                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] All result callback is NULL");
2430                 return;
2431         }
2432
2433         if (0 != vc_cmd_list_create(&vc_cmd_list)) {
2434                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to create command list");
2435                 return;
2436         }
2437
2438         vc_info_parser_get_result(&temp_text, &event, &temp_message, -1, vc_cmd_list, vc_mgr_client_get_exclusive_command(g_vc_m));
2439
2440         SECURE_SLOG(LOG_INFO, TAG_VCM, "Result info : result type(%d) result text(%s) event(%d) result_message(%s)",
2441                 result_type, temp_text, event, temp_message);
2442
2443         vc_cmd_print_list(vc_cmd_list);
2444
2445         bool cb_ret;
2446
2447         vc_mgr_client_set_all_result(g_vc_m, event, temp_text);
2448
2449         vc_mgr_client_use_callback(g_vc_m);
2450         cb_ret = all_callback(event, vc_cmd_list, temp_text, temp_message, all_user_data);
2451         vc_mgr_client_not_use_callback(g_vc_m);
2452
2453         if (true == vc_mgr_client_get_exclusive_command(g_vc_m)) {
2454                 /* exclusive */
2455                 vc_result_cb callback = NULL;
2456                 void* user_data = NULL;
2457
2458                 vc_mgr_client_get_result_cb(g_vc_m, &callback, &user_data);
2459                 if (NULL == callback) {
2460                         SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Client result callback is NULL");
2461                         return;
2462                 }
2463
2464                 vc_mgr_client_use_callback(g_vc_m);
2465                 callback(event, vc_cmd_list, temp_text, user_data);
2466                 vc_mgr_client_not_use_callback(g_vc_m);
2467                 SLOG(LOG_DEBUG, TAG_VCM, "Exclusive result callback called");
2468
2469                 /* Release result */
2470                 if (NULL != temp_text) {
2471                         free(temp_text);
2472                         temp_text = NULL;
2473                 }
2474                 if (NULL != temp_message) {
2475                         free(temp_message);
2476                         temp_message = NULL;
2477                 }
2478
2479                 /* Release list */
2480                 vc_cmd_list_destroy(vc_cmd_list, true);
2481
2482                 vc_mgr_client_set_exclusive_command(g_vc_m, false);
2483
2484                 return;
2485         }
2486
2487         int count = 0;
2488         vc_cmd_list_get_count(vc_cmd_list, &count);
2489         if (0 < count) {
2490                 if (true == cb_ret) {
2491                         SLOG(LOG_DEBUG, TAG_VCM, "Callback result is true");
2492                         if (VC_RESULT_TYPE_NOTIFICATION != result_type)
2493                                 ecore_idler_add(__vc_mgr_set_select_result, NULL);
2494                 } else {
2495                         SLOG(LOG_DEBUG, TAG_VCM, "Callback result is false");
2496                         /* need to select conflicted result */
2497                 }
2498         } else {
2499                 if (VC_RESULT_TYPE_NOTIFICATION != result_type)
2500                         ecore_idler_add(__vc_mgr_set_select_result, NULL);
2501
2502                 vc_mgr_client_set_exclusive_command(g_vc_m, false);
2503                 vc_mgr_client_unset_all_result(g_vc_m);
2504         }
2505
2506         /* Release result */
2507         if (NULL != temp_text) {
2508                 free(temp_text);
2509                 temp_text = NULL;
2510         }
2511         if (NULL != temp_message) {
2512                 free(temp_message);
2513                 temp_message = NULL;
2514         }
2515
2516         /* Release list */
2517         vc_cmd_list_destroy(vc_cmd_list, true);
2518
2519         return;
2520 }
2521
2522 static Eina_Bool __vc_mgr_notify_result(void *data)
2523 {
2524         char* temp_text = NULL;
2525         int event;
2526         vc_cmd_list_h vc_cmd_list = NULL;
2527
2528         vc_result_cb callback = NULL;
2529         void* user_data = NULL;
2530
2531         vc_mgr_client_get_result_cb(g_vc_m, &callback, &user_data);
2532         if (NULL == callback) {
2533                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Client result callback is NULL");
2534                 return EINA_FALSE;
2535         }
2536
2537         if (0 != vc_cmd_list_create(&vc_cmd_list)) {
2538                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to create command list");
2539                 return EINA_FALSE;
2540         }
2541
2542         vc_info_parser_get_result(&temp_text, &event, NULL, getpid(), vc_cmd_list, false);
2543
2544         SECURE_SLOG(LOG_INFO, TAG_VCM, "Result : result text(%s) event(%d)", temp_text, event);
2545
2546         vc_cmd_print_list(vc_cmd_list);
2547
2548         vc_mgr_client_use_callback(g_vc_m);
2549         callback(event, vc_cmd_list, temp_text, user_data);
2550         vc_mgr_client_not_use_callback(g_vc_m);
2551         SLOG(LOG_INFO, TAG_VCM, "Result callback called");
2552
2553         vc_cmd_list_destroy(vc_cmd_list, true);
2554
2555         /* Release result */
2556         if (NULL != temp_text)  free(temp_text);
2557
2558         return EINA_FALSE;
2559 }
2560
2561 void __vc_mgr_cb_all_result(vc_result_type_e type)
2562 {
2563         if (false == vc_mgr_client_get_exclusive_command(g_vc_m)) {
2564                 __vc_mgr_notify_all_result(type);
2565         } else {
2566                 __vc_mgr_notify_result(0);
2567         }
2568
2569         return;
2570 }
2571
2572 void __vc_mgr_cb_pre_result(vc_pre_result_event_e event, const char* pre_result)
2573 {
2574         vc_mgr_pre_result_cb callback = NULL;
2575         void* user_data = NULL;
2576
2577         vc_mgr_client_get_pre_result_cb(g_vc_m, &callback, &user_data);
2578         if (NULL == callback) {
2579                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Client pre result callback is NULL");
2580                 return;
2581         }
2582
2583         vc_mgr_client_use_callback(g_vc_m);
2584         callback(event, pre_result, user_data);
2585         vc_mgr_client_not_use_callback(g_vc_m);
2586         SLOG(LOG_DEBUG, TAG_VCM, "Pre result callback is called");
2587
2588         return;
2589 }
2590
2591 void __vc_mgr_cb_system_result()
2592 {
2593         __vc_mgr_notify_result(NULL);
2594         return;
2595 }
2596
2597 static Eina_Bool __vc_mgr_speech_detected(void *data)
2598 {
2599         vc_mgr_begin_speech_detected_cb callback = NULL;
2600         void* user_data = NULL;
2601
2602         vc_mgr_client_get_speech_detected_cb(g_vc_m, &callback, &user_data);
2603         if (NULL == callback) {
2604                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Client speech detected callback is NULL");
2605                 return EINA_FALSE;
2606         }
2607
2608         vc_mgr_client_use_callback(g_vc_m);
2609         callback(user_data);
2610         vc_mgr_client_not_use_callback(g_vc_m);
2611         SLOG(LOG_DEBUG, TAG_VCM, "Speech detected callback called");
2612
2613         return EINA_FALSE;
2614 }
2615
2616 void __vc_mgr_cb_speech_detected()
2617 {
2618         __vc_mgr_speech_detected(NULL);
2619
2620         return;
2621 }
2622
2623 int vc_mgr_set_all_result_cb(vc_mgr_all_result_cb callback, void* user_data)
2624 {
2625         if (0 != __vc_mgr_get_feature_enabled()) {
2626                 SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] not supported");
2627                 return VC_ERROR_NOT_SUPPORTED;
2628         }
2629
2630         if (0 != __vc_mgr_check_privilege()) {
2631                 return VC_ERROR_PERMISSION_DENIED;
2632         }
2633
2634         if (NULL == callback)
2635                 return VC_ERROR_INVALID_PARAMETER;
2636
2637         vc_state_e state;
2638         if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) {
2639                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Set result callback : A handle is not available");
2640                 return VC_ERROR_INVALID_STATE;
2641         }
2642
2643         /* check state */
2644         if (state != VC_STATE_INITIALIZED) {
2645                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Set result callback : Current state is not 'Initialized'");
2646                 return VC_ERROR_INVALID_STATE;
2647         }
2648
2649         vc_mgr_client_set_all_result_cb(g_vc_m, callback, user_data);
2650
2651         SLOG(LOG_DEBUG, TAG_VCM, "[SUCCESS] Set all result callback");
2652
2653         return 0;
2654 }
2655
2656 int vc_mgr_unset_all_result_cb(void)
2657 {
2658         if (0 != __vc_mgr_get_feature_enabled()) {
2659                 SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] not supported");
2660                 return VC_ERROR_NOT_SUPPORTED;
2661         }
2662
2663         if (0 != __vc_mgr_check_privilege()) {
2664                 return VC_ERROR_PERMISSION_DENIED;
2665         }
2666
2667         vc_state_e state;
2668         if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) {
2669                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Unset result callback : A handle is not available");
2670                 return VC_ERROR_INVALID_STATE;
2671         }
2672
2673         /* check state */
2674         if (state != VC_STATE_INITIALIZED) {
2675                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Unset result callback : Current state is not 'Initialized'");
2676                 return VC_ERROR_INVALID_STATE;
2677         }
2678
2679         vc_mgr_client_set_all_result_cb(g_vc_m, NULL, NULL);
2680
2681         return 0;
2682 }
2683
2684 int vc_mgr_set_result_cb(vc_result_cb callback, void* user_data)
2685 {
2686         if (0 != __vc_mgr_get_feature_enabled()) {
2687                 SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] not supported");
2688                 return VC_ERROR_NOT_SUPPORTED;
2689         }
2690
2691         if (0 != __vc_mgr_check_privilege()) {
2692                 return VC_ERROR_PERMISSION_DENIED;
2693         }
2694
2695         if (NULL == callback)
2696                 return VC_ERROR_INVALID_PARAMETER;
2697
2698         vc_state_e state;
2699         if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) {
2700                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Set result callback : A handle is not available");
2701                 return VC_ERROR_INVALID_STATE;
2702         }
2703
2704         /* check state */
2705         if (state != VC_STATE_INITIALIZED) {
2706                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Set result callback : Current state is not 'Initialized'");
2707                 return VC_ERROR_INVALID_STATE;
2708         }
2709
2710         vc_mgr_client_set_result_cb(g_vc_m, callback, user_data);
2711
2712         return 0;
2713 }
2714
2715 int vc_mgr_unset_result_cb(void)
2716 {
2717         if (0 != __vc_mgr_get_feature_enabled()) {
2718                 SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] not supported");
2719                 return VC_ERROR_NOT_SUPPORTED;
2720         }
2721
2722         if (0 != __vc_mgr_check_privilege()) {
2723                 return VC_ERROR_PERMISSION_DENIED;
2724         }
2725
2726         vc_state_e state;
2727         if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) {
2728                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Unset result callback : A handle is not available");
2729                 return VC_ERROR_INVALID_STATE;
2730         }
2731
2732         /* check state */
2733         if (state != VC_STATE_INITIALIZED) {
2734                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Unset result callback : Current state is not 'Initialized'");
2735                 return VC_ERROR_INVALID_STATE;
2736         }
2737
2738         vc_mgr_client_set_result_cb(g_vc_m, NULL, NULL);
2739
2740         return 0;
2741 }
2742
2743 int vc_mgr_set_pre_result_cb(vc_mgr_pre_result_cb callback, void* user_data)
2744 {
2745         if (0 != __vc_mgr_get_feature_enabled()) {
2746                 SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] not supported");
2747                 return VC_ERROR_NOT_SUPPORTED;
2748         }
2749
2750         if (0 != __vc_mgr_check_privilege()) {
2751                 return VC_ERROR_PERMISSION_DENIED;
2752         }
2753
2754         if (NULL == callback)
2755                 return VC_ERROR_INVALID_PARAMETER;
2756
2757         vc_state_e state;
2758         if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) {
2759                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Set pre result callback : A handle is not available");
2760                 return VC_ERROR_INVALID_STATE;
2761         }
2762
2763         /* check state */
2764         if (state != VC_STATE_INITIALIZED) {
2765                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Set pre result callback : Current state is not 'Initialized'");
2766                 return VC_ERROR_INVALID_STATE;
2767         }
2768
2769         vc_mgr_client_set_pre_result_cb(g_vc_m, callback, user_data);
2770
2771         return 0;
2772 }
2773
2774 int vc_mgr_unset_pre_result_cb(void)
2775 {
2776         if (0 != __vc_mgr_get_feature_enabled()) {
2777                 SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] not supported");
2778                 return VC_ERROR_NOT_SUPPORTED;
2779         }
2780
2781         if (0 != __vc_mgr_check_privilege()) {
2782                 return VC_ERROR_PERMISSION_DENIED;
2783         }
2784
2785         vc_state_e state;
2786         if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) {
2787                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Unset pre result callback : A handle is not available");
2788                 return VC_ERROR_INVALID_STATE;
2789         }
2790
2791         /* check state */
2792         if (state != VC_STATE_INITIALIZED) {
2793                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Unset pre result callback : Current state is not 'Initialize'");
2794                 return VC_ERROR_INVALID_STATE;
2795         }
2796
2797         vc_mgr_client_set_pre_result_cb(g_vc_m, NULL, NULL);
2798
2799         return 0;
2800 }
2801
2802 int vc_mgr_get_error_message(char** err_msg)
2803 {
2804         SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] Get error message");
2805
2806         if (0 != __vc_mgr_get_feature_enabled()) {
2807                 SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] not supported");
2808                 return VC_ERROR_NOT_SUPPORTED;
2809         }
2810
2811         if (0 != __vc_mgr_check_privilege()) {
2812                 return VC_ERROR_PERMISSION_DENIED;
2813         }
2814
2815         if (NULL == err_msg) {
2816                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] invalid parameter");
2817                 return VC_ERROR_INVALID_PARAMETER;
2818         }
2819
2820         if (false == g_err_callback_status) {
2821                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Not in error callback");
2822                 return VC_ERROR_OPERATION_FAILED;
2823         }
2824
2825         int ret;
2826         ret = vc_mgr_client_get_error_message(g_vc_m, err_msg);
2827         if (0 != ret) {
2828                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to get error message");
2829         }
2830
2831         SLOG(LOG_DEBUG, TAG_VCM, "@@@");
2832
2833         return ret;
2834 }
2835
2836 static void __vc_mgr_notify_error(void *data)
2837 {
2838         vc_h vc_m = (vc_h)data;
2839
2840         vc_error_cb callback = NULL;
2841         void* user_data = NULL;
2842         int reason;
2843
2844         vc_mgr_client_get_error_cb(vc_m, &callback, &user_data);
2845         vc_mgr_client_get_error(vc_m, &reason);
2846
2847         if (NULL != callback) {
2848                 vc_mgr_client_use_callback(vc_m);
2849                 g_err_callback_status = true;
2850                 callback(reason, user_data);
2851                 g_err_callback_status = false;
2852                 vc_mgr_client_not_use_callback(vc_m);
2853                 SLOG(LOG_DEBUG, TAG_VCM, "Error callback is called");
2854         } else {
2855                 SLOG(LOG_WARN, TAG_VCM, "[WARNING] Error callback is null");
2856         }
2857 }
2858
2859 int __vc_mgr_cb_error(int reason, int daemon_pid, char* msg)
2860 {
2861         vc_state_e state;
2862         if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) {
2863                 SLOG(LOG_ERROR, TAG_VCM, "[WARNING] Invalid client");
2864                 return -1;
2865         }
2866
2867         /* check state */
2868         if (state != VC_STATE_READY) {
2869                 SLOG(LOG_ERROR, TAG_VCM, "[WARNING] not connected client yet");
2870                 return -1;
2871         }
2872
2873         vc_mgr_client_set_internal_state(g_vc_m, VC_INTERNAL_STATE_NONE);
2874
2875         if (VC_ERROR_SERVICE_RESET == reason) {
2876                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] VC daemon reset");
2877
2878                 vc_mgr_client_set_client_state(g_vc_m, VC_STATE_INITIALIZED);
2879                 __vc_mgr_notify_state_changed(g_vc_m);
2880
2881                 if (0 != vc_mgr_prepare()) {
2882                         SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to prepare");
2883                 }
2884         }
2885
2886         SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Error reason(%d), msg(%s)", reason, msg);
2887
2888         vc_mgr_client_set_error(g_vc_m, reason);
2889         vc_mgr_client_set_error_message(g_vc_m, msg);
2890         __vc_mgr_notify_error(g_vc_m);
2891
2892         return 0;
2893 }
2894
2895 static Eina_Bool __vc_mgr_notify_state_changed(void *data)
2896 {
2897         vc_state_changed_cb changed_callback = NULL;
2898         void* user_data;
2899
2900         vc_mgr_client_get_state_changed_cb(g_vc_m, &changed_callback, &user_data);
2901
2902         vc_state_e current_state;
2903         vc_state_e before_state;
2904
2905         vc_mgr_client_get_before_state(g_vc_m, &current_state, &before_state);
2906
2907         if (NULL != changed_callback) {
2908                 vc_mgr_client_use_callback(g_vc_m);
2909                 changed_callback(before_state, current_state, user_data);
2910                 vc_mgr_client_not_use_callback(g_vc_m);
2911                 SLOG(LOG_DEBUG, TAG_VCM, "State changed callback is called");
2912         } else {
2913                 SLOG(LOG_WARN, TAG_VCM, "[WARNING] State changed callback is null");
2914         }
2915
2916         return EINA_FALSE;
2917 }
2918
2919 int vc_mgr_set_state_changed_cb(vc_state_changed_cb callback, void* user_data)
2920 {
2921         if (0 != __vc_mgr_get_feature_enabled()) {
2922                 SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] not supported");
2923                 return VC_ERROR_NOT_SUPPORTED;
2924         }
2925
2926         if (0 != __vc_mgr_check_privilege()) {
2927                 return VC_ERROR_PERMISSION_DENIED;
2928         }
2929
2930         if (callback == NULL)
2931                 return VC_ERROR_INVALID_PARAMETER;
2932
2933         vc_state_e state;
2934         if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) {
2935                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Set state changed callback : A handle is not available");
2936                 return VC_ERROR_INVALID_STATE;
2937         }
2938
2939         /* check state */
2940         if (state != VC_STATE_INITIALIZED) {
2941                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Set state changed callback : Current state is not 'Initialized'");
2942                 return VC_ERROR_INVALID_STATE;
2943         }
2944
2945         vc_mgr_client_set_state_changed_cb(g_vc_m, callback, user_data);
2946
2947         SLOG(LOG_DEBUG, TAG_VCM, "[SUCCESS] Set state changed callback");
2948         return 0;
2949 }
2950
2951 int vc_mgr_unset_state_changed_cb(void)
2952 {
2953         if (0 != __vc_mgr_get_feature_enabled()) {
2954                 SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] not supported");
2955                 return VC_ERROR_NOT_SUPPORTED;
2956         }
2957
2958         if (0 != __vc_mgr_check_privilege()) {
2959                 return VC_ERROR_PERMISSION_DENIED;
2960         }
2961
2962         vc_state_e state;
2963         if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) {
2964                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Unset state changed callback : A handle is not available");
2965                 return VC_ERROR_INVALID_STATE;
2966         }
2967
2968         /* check state */
2969         if (state != VC_STATE_INITIALIZED) {
2970                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Unset state changed callback : Current state is not 'Initialized'");
2971                 return VC_ERROR_INVALID_STATE;
2972         }
2973
2974         vc_mgr_client_set_state_changed_cb(g_vc_m, NULL, NULL);
2975
2976         return 0;
2977 }
2978
2979 int __vc_mgr_cb_service_state(int state)
2980 {
2981         vc_service_state_e current_state = (vc_service_state_e)state;
2982         vc_service_state_e before_state;
2983         vc_mgr_client_get_service_state(g_vc_m, &before_state);
2984
2985         SLOG(LOG_DEBUG, TAG_VCM, "Service State changed : Before(%d) Current(%d)",
2986                 before_state, current_state);
2987
2988         vc_internal_state_e internal_state = -1;
2989         vc_mgr_client_get_internal_state(g_vc_m, &internal_state);
2990         if ((VC_INTERNAL_STATE_STARTING == internal_state && VC_SERVICE_STATE_RECORDING == current_state) ||
2991                 (VC_INTERNAL_STATE_STOPPING == internal_state && VC_SERVICE_STATE_PROCESSING == current_state) ||
2992                 (VC_INTERNAL_STATE_CANCELING == internal_state && VC_SERVICE_STATE_READY == current_state)) {
2993                         SLOG(LOG_DEBUG, TAG_VCM, "Internal state is changed to NONE");
2994                         vc_mgr_client_set_internal_state(g_vc_m, VC_INTERNAL_STATE_NONE);
2995         }
2996
2997         if (current_state == before_state) {
2998                 SLOG(LOG_WARN, TAG_VCM, "Service State NOT changed : Before(%d) Current(%d)",
2999                         before_state, current_state);
3000                 return 0;
3001         }
3002
3003         /* Save service state */
3004         vc_mgr_client_set_service_state(g_vc_m, current_state);
3005
3006         vc_service_state_changed_cb callback = NULL;
3007         void* service_user_data = NULL;
3008         vc_mgr_client_get_service_state_changed_cb(g_vc_m, &callback, &service_user_data);
3009
3010         if (NULL != callback) {
3011                 vc_mgr_client_use_callback(g_vc_m);
3012                 callback(before_state, current_state, service_user_data);
3013                 vc_mgr_client_not_use_callback(g_vc_m);
3014                 SLOG(LOG_DEBUG, TAG_VCM, "Service state changed callback is called");
3015         } else {
3016                 SLOG(LOG_WARN, TAG_VCM, "[WARNING] Service state changed callback is null");
3017         }
3018
3019         return 0;
3020 }
3021
3022 int vc_mgr_set_service_state_changed_cb(vc_service_state_changed_cb callback, void* user_data)
3023 {
3024         if (0 != __vc_mgr_get_feature_enabled()) {
3025                 SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] not supported");
3026                 return VC_ERROR_NOT_SUPPORTED;
3027         }
3028
3029         if (0 != __vc_mgr_check_privilege()) {
3030                 return VC_ERROR_PERMISSION_DENIED;
3031         }
3032
3033         if (callback == NULL)
3034                 return VC_ERROR_INVALID_PARAMETER;
3035
3036         vc_state_e state;
3037         if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) {
3038                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Set state changed callback : A handle is not available");
3039                 return VC_ERROR_INVALID_STATE;
3040         }
3041
3042         /* check state */
3043         if (state != VC_STATE_INITIALIZED) {
3044                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Set state changed callback : Current state is not 'Initialized'");
3045                 return VC_ERROR_INVALID_STATE;
3046         }
3047
3048         vc_mgr_client_set_service_state_changed_cb(g_vc_m, callback, user_data);
3049
3050         SLOG(LOG_DEBUG, TAG_VCM, "[SUCCESS] Set service state changed callback");
3051         return 0;
3052 }
3053
3054 int vc_mgr_unset_service_state_changed_cb(void)
3055 {
3056         if (0 != __vc_mgr_get_feature_enabled()) {
3057                 SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] not supported");
3058                 return VC_ERROR_NOT_SUPPORTED;
3059         }
3060
3061         if (0 != __vc_mgr_check_privilege()) {
3062                 return VC_ERROR_PERMISSION_DENIED;
3063         }
3064
3065         vc_state_e state;
3066         if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) {
3067                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Unset state changed callback : A handle is not available");
3068                 return VC_ERROR_INVALID_STATE;
3069         }
3070
3071         /* check state */
3072         if (state != VC_STATE_INITIALIZED) {
3073                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Unset state changed callback : Current state is not 'Initialized'");
3074                 return VC_ERROR_INVALID_STATE;
3075         }
3076
3077         vc_mgr_client_set_service_state_changed_cb(g_vc_m, NULL, NULL);
3078         return 0;
3079 }
3080
3081 int vc_mgr_set_speech_detected_cb(vc_mgr_begin_speech_detected_cb callback, void* user_data)
3082 {
3083         if (0 != __vc_mgr_get_feature_enabled()) {
3084                 SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] not supported");
3085                 return VC_ERROR_NOT_SUPPORTED;
3086         }
3087
3088         if (0 != __vc_mgr_check_privilege()) {
3089                 return VC_ERROR_PERMISSION_DENIED;
3090         }
3091
3092         if (callback == NULL)
3093                 return VC_ERROR_INVALID_PARAMETER;
3094
3095         vc_state_e state;
3096         if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) {
3097                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Set state changed callback : A handle is not available");
3098                 return VC_ERROR_INVALID_STATE;
3099         }
3100
3101         /* check state */
3102         if (state != VC_STATE_INITIALIZED) {
3103                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Set speech detected callback : Current state is not 'Initialized'");
3104                 return VC_ERROR_INVALID_STATE;
3105         }
3106
3107         vc_mgr_client_set_speech_detected_cb(g_vc_m, callback, user_data);
3108
3109         SLOG(LOG_DEBUG, TAG_VCM, "[SUCCESS] Set speech detected callback");
3110         return 0;
3111 }
3112
3113 int vc_mgr_unset_speech_detected_cb(void)
3114 {
3115         if (0 != __vc_mgr_get_feature_enabled()) {
3116                 SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] not supported");
3117                 return VC_ERROR_NOT_SUPPORTED;
3118         }
3119
3120         if (0 != __vc_mgr_check_privilege()) {
3121                 return VC_ERROR_PERMISSION_DENIED;
3122         }
3123
3124         vc_state_e state;
3125         if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) {
3126                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Unset state changed callback : A handle is not available");
3127                 return VC_ERROR_INVALID_STATE;
3128         }
3129
3130         /* check state */
3131         if (state != VC_STATE_INITIALIZED) {
3132                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Unset state changed callback : Current state is not 'Initialized'");
3133                 return VC_ERROR_INVALID_STATE;
3134         }
3135
3136         vc_mgr_client_set_speech_detected_cb(g_vc_m, NULL, NULL);
3137         return 0;
3138 }
3139
3140 int vc_mgr_set_current_language_changed_cb(vc_current_language_changed_cb callback, void* user_data)
3141 {
3142         if (0 != __vc_mgr_get_feature_enabled()) {
3143                 SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] not supported");
3144                 return VC_ERROR_NOT_SUPPORTED;
3145         }
3146
3147         if (0 != __vc_mgr_check_privilege()) {
3148                 return VC_ERROR_PERMISSION_DENIED;
3149         }
3150
3151         if (NULL == callback)
3152                 return VC_ERROR_INVALID_PARAMETER;
3153
3154         vc_state_e state;
3155         if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) {
3156                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Set current language changed : A handle is not available");
3157                 return VC_ERROR_INVALID_STATE;
3158         }
3159
3160         /* check state */
3161         if (state != VC_STATE_INITIALIZED) {
3162                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Set current language changed : Current state is not 'Initialized'");
3163                 return VC_ERROR_INVALID_STATE;
3164         }
3165
3166         vc_mgr_client_set_current_lang_changed_cb(g_vc_m, callback, user_data);
3167
3168         SLOG(LOG_DEBUG, TAG_VCM, "[SUCCESS] Set current language changed callback");
3169         return 0;
3170 }
3171
3172 int vc_mgr_unset_current_language_changed_cb(void)
3173 {
3174         if (0 != __vc_mgr_get_feature_enabled()) {
3175                 SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] not supported");
3176                 return VC_ERROR_NOT_SUPPORTED;
3177         }
3178
3179         if (0 != __vc_mgr_check_privilege()) {
3180                 return VC_ERROR_PERMISSION_DENIED;
3181         }
3182
3183         vc_state_e state;
3184         if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) {
3185                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Unset current language changed : A handle is not available");
3186                 return VC_ERROR_INVALID_STATE;
3187         }
3188
3189         /* check state */
3190         if (state != VC_STATE_INITIALIZED) {
3191                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Unset current language changed : Current state is not 'Initialized'");
3192                 return VC_ERROR_INVALID_STATE;
3193         }
3194
3195         vc_mgr_client_set_current_lang_changed_cb(g_vc_m, NULL, NULL);
3196
3197         return 0;
3198 }
3199
3200 int vc_mgr_set_error_cb(vc_error_cb callback, void* user_data)
3201 {
3202         if (0 != __vc_mgr_get_feature_enabled()) {
3203                 SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] not supported");
3204                 return VC_ERROR_NOT_SUPPORTED;
3205         }
3206
3207         if (0 != __vc_mgr_check_privilege()) {
3208                 return VC_ERROR_PERMISSION_DENIED;
3209         }
3210
3211         if (NULL == callback)
3212                 return VC_ERROR_INVALID_PARAMETER;
3213
3214         vc_state_e state;
3215         if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) {
3216                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Set error callback : A handle is not available");
3217                 return VC_ERROR_INVALID_STATE;
3218         }
3219
3220         /* check state */
3221         if (state != VC_STATE_INITIALIZED) {
3222                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Set error callback : Current state is not 'Initialized'");
3223                 return VC_ERROR_INVALID_STATE;
3224         }
3225
3226         vc_mgr_client_set_error_cb(g_vc_m, callback,  user_data);
3227
3228         return 0;
3229 }
3230
3231 int vc_mgr_unset_error_cb(void)
3232 {
3233         if (0 != __vc_mgr_get_feature_enabled()) {
3234                 SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] not supported");
3235                 return VC_ERROR_NOT_SUPPORTED;
3236         }
3237
3238         if (0 != __vc_mgr_check_privilege()) {
3239                 return VC_ERROR_PERMISSION_DENIED;
3240         }
3241
3242         vc_state_e state;
3243         if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) {
3244                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Unset error callback : A handle is not available");
3245                 return VC_ERROR_INVALID_STATE;
3246         }
3247
3248         /* check state */
3249         if (state != VC_STATE_INITIALIZED) {
3250                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Unset error callback : Current state is not 'Initialized'");
3251                 return VC_ERROR_INVALID_STATE;
3252         }
3253
3254         vc_mgr_client_set_error_cb(g_vc_m, NULL, NULL);
3255
3256         return 0;
3257 }
3258
3259 int __vc_mgr_cb_dialog(int pid, const char* disp_text, const char* utt_text, bool continuous)
3260 {
3261         vc_mgr_dialog_request_cb callback = NULL;
3262         void* user_data = NULL;
3263
3264         vc_mgr_client_get_dialog_request_cb(g_vc_m, &callback, &user_data);
3265
3266         if (NULL != callback) {
3267                 vc_mgr_client_use_callback(g_vc_m);
3268                 callback(pid, disp_text, utt_text, continuous, user_data);
3269                 vc_mgr_client_not_use_callback(g_vc_m);
3270                 SLOG(LOG_DEBUG, TAG_VCM, "Dialog callback is called, disp_text(%s), utt)text(%s), continuous(%d)", disp_text, utt_text, continuous);
3271         } else {
3272                 SLOG(LOG_WARN, TAG_VCM, "[WARNING] Error callback is null");
3273         }
3274
3275         return 0;
3276 }
3277
3278 int __vc_mgr_cb_private_data_set(const char* key, const char* data)
3279 {
3280         vc_mgr_private_data_set_cb callback = NULL;
3281         void* user_data = NULL;
3282         int ret = -1;
3283
3284         vc_mgr_client_get_private_data_set_cb(g_vc_m, &callback, &user_data);
3285
3286         if (NULL != callback) {
3287                 vc_mgr_client_use_callback(g_vc_m);
3288                 ret = callback(key, data, user_data);
3289                 vc_mgr_client_not_use_callback(g_vc_m);
3290                 SLOG(LOG_DEBUG, TAG_VCM, "Private data set callback is called");
3291         } else {
3292                 SLOG(LOG_WARN, TAG_VCM, "[WARNING] Private data set callback is null");
3293         }
3294
3295         return ret;
3296 }
3297
3298 int __vc_mgr_cb_private_data_requested(const char* key, char** data)
3299 {
3300         vc_mgr_private_data_requested_cb callback = NULL;
3301         void* user_data = NULL;
3302         int ret = -1;
3303
3304         vc_mgr_client_get_private_data_requested_cb(g_vc_m, &callback, &user_data);
3305
3306         if (NULL != callback) {
3307                 vc_mgr_client_use_callback(g_vc_m);
3308                 ret = callback(key, data, user_data);
3309                 vc_mgr_client_not_use_callback(g_vc_m);
3310                 SLOG(LOG_DEBUG, TAG_VCM, "Private data requested callback is called");
3311         } else {
3312                 SLOG(LOG_WARN, TAG_VCM, "[WARNING] Private data requested callback is null");
3313         }
3314
3315         return ret;
3316 }
3317
3318 /* for TTS feedback */
3319 int __vc_mgr_cb_feedback_audio_format(int rate, vc_audio_channel_e channel, vc_audio_type_e audio_type)
3320 {
3321         vc_mgr_feedback_audio_format_cb callback = NULL;
3322         void* user_data = NULL;
3323
3324         /* set global audio formats */
3325         g_feedback_rate = rate;
3326         g_feedback_audio_channel = channel;
3327         g_feedback_audio_type = audio_type;
3328
3329         vc_mgr_client_get_feedback_audio_format_cb(g_vc_m, &callback, &user_data);
3330
3331         if (NULL != callback) {
3332                 vc_mgr_client_use_callback(g_vc_m);
3333                 callback(rate, channel, audio_type, user_data);
3334                 vc_mgr_client_not_use_callback(g_vc_m);
3335                 SLOG(LOG_DEBUG, TAG_VCM, "TTS feedback audio format callback is called");
3336         } else {
3337                 SLOG(LOG_WARN, TAG_VCM, "[WARNING] TTS feedback audio format callback is null");
3338         }
3339
3340         return VC_ERROR_NONE;
3341 }
3342
3343 int __vc_mgr_cb_feedback_streaming(vc_feedback_event_e event, char* buffer, int len)
3344 {
3345         /* add feedback data */
3346         vc_feedback_data_s* temp_feedback_data = NULL;
3347         temp_feedback_data = (vc_feedback_data_s*)calloc(1, sizeof(vc_feedback_data_s));
3348         if (NULL == temp_feedback_data) {
3349                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Out of memory");
3350                 return VC_ERROR_OUT_OF_MEMORY;
3351         }
3352
3353         temp_feedback_data->data = NULL;
3354         temp_feedback_data->rate = g_feedback_rate;
3355         temp_feedback_data->data_size = 0;
3356
3357         if (0 < len) {
3358                 temp_feedback_data->data = (char*)calloc(len + 5, sizeof(char));
3359                 if (NULL != temp_feedback_data->data) {
3360                         memcpy(temp_feedback_data->data, buffer, len);
3361                         temp_feedback_data->data_size = len;
3362                         SLOG(LOG_DEBUG, TAG_VCM, "[DEBUG][memcpy] data(%p) size(%d)",
3363                                         temp_feedback_data->data, temp_feedback_data->data_size);
3364                 } else {
3365                         SLOG(LOG_ERROR, TAG_VCM, "[ERROR] fail to allocate memory");
3366                 }
3367         } else {
3368                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] feedback data is NULL");
3369         }
3370
3371         temp_feedback_data->event = event;
3372         temp_feedback_data->audio_type = g_feedback_audio_type;
3373         temp_feedback_data->channel = g_feedback_audio_channel;
3374
3375         int ret = vc_mgr_data_add_feedback_data(temp_feedback_data);
3376         if (0 != ret) {
3377                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to add feedback data");
3378                 if (NULL != temp_feedback_data->data) {
3379                         free(temp_feedback_data->data);
3380                         temp_feedback_data->data = NULL;
3381                 }
3382                 if (NULL != temp_feedback_data) {
3383                         free(temp_feedback_data);
3384                         temp_feedback_data = NULL;
3385                 }
3386
3387                 return ret;
3388         }
3389
3390         return VC_ERROR_NONE;
3391 }
3392
3393 int vc_mgr_set_dialog_request_cb(vc_mgr_dialog_request_cb callback, void* user_data)
3394 {
3395         if (0 != __vc_mgr_get_feature_enabled()) {
3396                 SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] not supported");
3397                 return VC_ERROR_NOT_SUPPORTED;
3398         }
3399
3400         if (0 != __vc_mgr_check_privilege()) {
3401                 return VC_ERROR_PERMISSION_DENIED;
3402         }
3403
3404         if (NULL == callback)
3405                 return VC_ERROR_INVALID_PARAMETER;
3406
3407         vc_state_e state;
3408         if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) {
3409                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Set error callback : A handle is not available");
3410                 return VC_ERROR_INVALID_STATE;
3411         }
3412
3413         /* check state */
3414         if (state != VC_STATE_INITIALIZED) {
3415                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Set error callback : Current state is not 'Initialized'");
3416                 return VC_ERROR_INVALID_STATE;
3417         }
3418
3419         vc_mgr_client_set_dialog_request_cb(g_vc_m, callback,  user_data);
3420
3421         return 0;
3422 }
3423
3424 int vc_mgr_unset_dialog_request_cb(void)
3425 {
3426         if (0 != __vc_mgr_get_feature_enabled()) {
3427                 SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] not supported");
3428                 return VC_ERROR_NOT_SUPPORTED;
3429         }
3430
3431         if (0 != __vc_mgr_check_privilege()) {
3432                 return VC_ERROR_PERMISSION_DENIED;
3433         }
3434
3435         vc_state_e state;
3436         if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) {
3437                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Unset error callback : A handle is not available");
3438                 return VC_ERROR_INVALID_STATE;
3439         }
3440
3441         /* check state */
3442         if (state != VC_STATE_INITIALIZED) {
3443                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Unset error callback : Current state is not 'Initialized'");
3444                 return VC_ERROR_INVALID_STATE;
3445         }
3446
3447         vc_mgr_client_set_dialog_request_cb(g_vc_m, NULL, NULL);
3448
3449         return 0;
3450 }
3451
3452 int vc_mgr_set_private_data_set_cb(vc_mgr_private_data_set_cb callback, void* user_data)
3453 {
3454         if (0 != __vc_mgr_get_feature_enabled()) {
3455                 SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] not supported");
3456                 return VC_ERROR_NOT_SUPPORTED;
3457         }
3458
3459         if (0 != __vc_mgr_check_privilege()) {
3460                 return VC_ERROR_PERMISSION_DENIED;
3461         }
3462
3463         if (NULL == callback)
3464                 return VC_ERROR_INVALID_PARAMETER;
3465
3466         vc_state_e state;
3467         if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) {
3468                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Set private data set callback : A handle is not available");
3469                 return VC_ERROR_INVALID_STATE;
3470         }
3471
3472         /* check state */
3473         if (VC_STATE_INITIALIZED != state) {
3474                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Set private data set callback : Current state is not 'Initialized'");
3475                 return VC_ERROR_INVALID_STATE;
3476         }
3477
3478         vc_mgr_client_set_private_data_set_cb(g_vc_m, callback, user_data);
3479
3480         return 0;
3481 }
3482
3483 int vc_mgr_unset_private_data_set_cb(void)
3484 {
3485         if (0 != __vc_mgr_get_feature_enabled()) {
3486                 SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] not supported");
3487                 return VC_ERROR_NOT_SUPPORTED;
3488         }
3489
3490         if (0 != __vc_mgr_check_privilege()) {
3491                 return VC_ERROR_PERMISSION_DENIED;
3492         }
3493
3494         vc_state_e state;
3495         if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) {
3496                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Unset private data set callback : A handle is not available");
3497                 return VC_ERROR_INVALID_STATE;
3498         }
3499
3500         /* check state */
3501         if (VC_STATE_INITIALIZED != state) {
3502                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Unset private data set callback : Current state is not 'Initialized'");
3503                 return VC_ERROR_INVALID_STATE;
3504         }
3505
3506         vc_mgr_client_set_private_data_set_cb(g_vc_m, NULL, NULL);
3507
3508         return 0;
3509 }
3510
3511 int vc_mgr_set_private_data_requested_cb(vc_mgr_private_data_requested_cb callback, void* user_data)
3512 {
3513         if (0 != __vc_mgr_get_feature_enabled()) {
3514                 SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] not supported");
3515                 return VC_ERROR_NOT_SUPPORTED;
3516         }
3517
3518         if (0 != __vc_mgr_check_privilege()) {
3519                 return VC_ERROR_PERMISSION_DENIED;
3520         }
3521
3522         if (NULL == callback)
3523                 return VC_ERROR_INVALID_PARAMETER;
3524
3525         vc_state_e state;
3526         if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) {
3527                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Set private data requested callback : A handle is not available");
3528                 return VC_ERROR_INVALID_STATE;
3529         }
3530
3531         /* check state*/
3532         if (VC_STATE_INITIALIZED != state) {
3533                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Set private data requested callback : Current state is not 'Initialized'");
3534                 return VC_ERROR_INVALID_STATE;
3535         }
3536
3537         vc_mgr_client_set_private_data_requested_cb(g_vc_m, callback, user_data);
3538
3539         return 0;
3540 }
3541
3542 int vc_mgr_unset_private_data_requested_cb(void)
3543 {
3544         if (0 != __vc_mgr_get_feature_enabled()) {
3545                 SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] not supported");
3546                 return VC_ERROR_NOT_SUPPORTED;
3547         }
3548
3549         if (0 != __vc_mgr_check_privilege()) {
3550                 return VC_ERROR_PERMISSION_DENIED;
3551         }
3552
3553         vc_state_e state;
3554         if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) {
3555                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Unset private data requested callback : A handle is not available");
3556                 return VC_ERROR_INVALID_STATE;
3557         }
3558
3559         /* check state */
3560         if (VC_STATE_INITIALIZED != state) {
3561                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Unset private data requested callback : Current state is not 'Initialized'");
3562                 return VC_ERROR_INVALID_STATE;
3563         }
3564
3565         vc_mgr_client_set_private_data_requested_cb(g_vc_m, NULL, NULL);
3566
3567         return 0;
3568 }
3569
3570 static bool __vc_mgr_check_demandable_client(int pid)
3571 {
3572         if (0 == g_slist_length(g_demandable_client_list)) {
3573                 SLOG(LOG_WARN, TAG_VCM, "[WARNING] No demandable clients");
3574                 return false;
3575         }
3576
3577         char appid[1024] = {'\0', };
3578         if (0 != aul_app_get_appid_bypid(pid, appid, sizeof(appid) - 1)) {
3579                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to get callee appid by pid");
3580                 return false;
3581         }
3582         SLOG(LOG_DEBUG, TAG_VCM, "[CHECK] Appid - %s", appid);
3583
3584         GSList *iter = NULL;
3585         vc_demandable_client_s* temp_client;
3586         iter = g_slist_nth(g_demandable_client_list, 0);
3587
3588         while (NULL != iter) {
3589                 temp_client = iter->data;
3590
3591                 if (NULL != temp_client) {
3592                         if (NULL != temp_client->appid) {
3593                                 if (!strcmp(temp_client->appid, appid)) {
3594                                         SLOG(LOG_DEBUG, TAG_VCM, "pid(%d) is available", pid);
3595                                         return true;
3596                                 }
3597                         }
3598                 }
3599
3600                 iter = g_slist_next(iter);
3601         }
3602
3603         return false;
3604 }
3605
3606 /* Authority */
3607 int __vc_mgr_request_auth_enable(int pid)
3608 {
3609         if (false == __vc_mgr_check_demandable_client(pid)) {
3610                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Not demandable client");
3611                 return VC_ERROR_INVALID_PARAMETER;
3612         }
3613
3614         /* check already authorized */
3615         if (true == vc_mgr_client_is_authorized_client(g_vc_m, pid)) {
3616                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Already authorized");
3617                 return VC_ERROR_INVALID_PARAMETER;
3618         }
3619
3620         /* add authorized list */
3621         if (0 != vc_mgr_client_add_authorized_client(g_vc_m, pid)) {
3622                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to add authorized client");
3623                 return VC_ERROR_OPERATION_FAILED;
3624         }
3625
3626         /* foreground check */
3627         int fore_pid = 0;
3628         if (0 != vc_mgr_client_get_foreground(g_vc_m, &fore_pid)) {
3629                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to get foreground");
3630                 return VC_ERROR_OPERATION_FAILED;
3631         }
3632
3633         if (pid == fore_pid) {
3634                 vc_mgr_client_set_valid_authorized_client(g_vc_m, pid);
3635         }
3636
3637         return 0;
3638 }
3639
3640 int __vc_mgr_request_auth_disable(int pid)
3641 {
3642         /* check authorized */
3643         if (false == vc_mgr_client_is_authorized_client(g_vc_m, pid)) {
3644                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] No authorized");
3645                 return VC_ERROR_INVALID_PARAMETER;
3646         }
3647
3648         /* remove authorized list */
3649         if (0 != vc_mgr_client_remove_authorized_client(g_vc_m, pid)) {
3650                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to remove authorized client");
3651                 return VC_ERROR_OPERATION_FAILED;
3652         }
3653
3654         /* check authority valid */
3655         if (true == vc_mgr_client_is_valid_authorized_client(g_vc_m, pid)) {
3656                 SLOG(LOG_DEBUG, TAG_VCM, "Valid authorized client is removed");
3657                 if (0 != vc_mgr_client_set_valid_authorized_client(g_vc_m, -1)) {
3658                         SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to set valid authorized client");
3659                         return VC_ERROR_OPERATION_FAILED;
3660                 }
3661         }
3662
3663         return 0;
3664 }
3665
3666 static Eina_Bool __request_auth_start(void* data)
3667 {
3668         SLOG(LOG_DEBUG, TAG_VCM, "Request Start");
3669
3670         if (0 != vc_mgr_client_set_start_by_client(g_vc_m, true)) {
3671                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to set start by client");
3672         }
3673
3674         if (0 != vc_mgr_start(false)) {
3675                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Request start is failed");
3676                 /* TODO - Error handling? */
3677         }
3678
3679         if (0 != vc_mgr_client_set_start_by_client(g_vc_m, false)) {
3680                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to set start by client");
3681         }
3682
3683
3684         return EINA_FALSE;
3685 }
3686
3687 int __vc_mgr_request_auth_start(int pid)
3688 {
3689         /* check authorized */
3690         if (false == vc_mgr_client_is_valid_authorized_client(g_vc_m, pid)) {
3691                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] No valid authorized client");
3692                 return VC_ERROR_INVALID_PARAMETER;
3693         }
3694
3695         /* add timer for start recording */
3696         ecore_timer_add(0, __request_auth_start, NULL);
3697
3698         return 0;
3699 }
3700
3701 static Eina_Bool __request_auth_stop(void* data)
3702 {
3703         SLOG(LOG_DEBUG, TAG_VCM, "Request Stop");
3704
3705         if (0 != vc_mgr_stop()) {
3706                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Request stop is failed");
3707                 /* TODO - Error handling? */
3708         }
3709
3710         return EINA_FALSE;
3711 }
3712
3713 int __vc_mgr_request_auth_stop(int pid)
3714 {
3715         /* check authorized */
3716         if (false == vc_mgr_client_is_valid_authorized_client(g_vc_m, pid)) {
3717                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] No valid authorized client");
3718                 return VC_ERROR_INVALID_PARAMETER;
3719         }
3720
3721         /* add timer for start recording */
3722         ecore_timer_add(0, __request_auth_stop, NULL);
3723
3724         return 0;
3725 }
3726
3727 static Eina_Bool __request_auth_cancel(void* data)
3728 {
3729         SLOG(LOG_DEBUG, TAG_VCM, "Request Cancel");
3730
3731         if (0 != vc_mgr_cancel()) {
3732                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Request cancel is failed");
3733                 /* TODO - Error handling? */
3734         }
3735
3736         return EINA_FALSE;
3737 }
3738
3739 int __vc_mgr_request_auth_cancel(int pid)
3740 {
3741         /* check authorized */
3742         if (false == vc_mgr_client_is_valid_authorized_client(g_vc_m, pid)) {
3743                 SLOG(LOG_ERROR,  TAG_VCM, "[ERROR] No valid authorized client");
3744                 return VC_ERROR_INVALID_PARAMETER;
3745         }
3746
3747         /* add timer for start recording */
3748         ecore_timer_add(0, __request_auth_cancel, NULL);
3749
3750         return 0;
3751 }
3752
3753 int vc_mgr_set_specific_engine_result_cb(vc_mgr_specific_engine_result_cb callback, void* user_data)
3754 {
3755         if (0 != __vc_mgr_get_feature_enabled()) {
3756                 return VC_ERROR_NOT_SUPPORTED;
3757         }
3758
3759         if (NULL == callback)
3760                 return VC_ERROR_INVALID_PARAMETER;
3761
3762         vc_state_e state;
3763         if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) {
3764                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Set specific engine result callback : A handle is not available");
3765                 return VC_ERROR_INVALID_STATE;
3766         }
3767
3768         /* check state */
3769         if (state != VC_STATE_INITIALIZED) {
3770                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Set specific engine result callback : Current state(%d) is not 'Initialized'", state);
3771                 return VC_ERROR_INVALID_STATE;
3772         }
3773
3774         vc_mgr_client_set_specific_engine_result_cb(g_vc_m, callback, user_data);
3775
3776         return 0;
3777 }
3778 int vc_mgr_unset_specific_engine_result_cb(void)
3779 {
3780         if (0 != __vc_mgr_get_feature_enabled()) {
3781                 return VC_ERROR_NOT_SUPPORTED;
3782         }
3783
3784         vc_state_e state;
3785         if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) {
3786                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Unset specific engine result callback : A handle is not available");
3787                 return VC_ERROR_INVALID_STATE;
3788         }
3789
3790         /* check state */
3791         if (state != VC_STATE_INITIALIZED) {
3792                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Unset specific engine result callback : Current state(%d) is not 'Initialize'", state);
3793                 return VC_ERROR_INVALID_STATE;
3794         }
3795
3796         vc_mgr_client_set_specific_engine_result_cb(g_vc_m, NULL, NULL);
3797
3798         return 0;
3799 }
3800
3801 void __vc_mgr_cb_specific_engine_result(const char* engine_app_id, const char* event, const char* result)
3802 {
3803         vc_mgr_specific_engine_result_cb callback = NULL;
3804         void* user_data = NULL;
3805
3806         vc_mgr_client_get_specific_engine_result_cb(g_vc_m, &callback, &user_data);
3807         if (NULL == callback) {
3808                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Client specific engine result callback is NULL");
3809                 return;
3810         }
3811
3812         vc_mgr_client_use_callback(g_vc_m);
3813         callback(engine_app_id, event, result, user_data);
3814         vc_mgr_client_not_use_callback(g_vc_m);
3815         SLOG(LOG_DEBUG, TAG_VCM, "Specific engine result callback is called, engine app id(%s), event(%s), result(%s)", engine_app_id, event, result);
3816
3817         return;
3818 }
3819
3820 /* for TTS feedback */
3821 int vc_mgr_set_feedback_audio_format_cb(vc_mgr_feedback_audio_format_cb callback, void* user_data)
3822 {
3823         if (NULL == callback)
3824                 return VC_ERROR_INVALID_PARAMETER;
3825
3826         vc_state_e state;
3827         if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) {
3828                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Set feedback audio format callback : A handle is not available");
3829                 return VC_ERROR_INVALID_STATE;
3830         }
3831
3832         /* check state */
3833         if (VC_STATE_INITIALIZED != state) {
3834                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Set feedback audio format callback : Current state is not 'Initialized' (%d)", state);
3835                 return VC_ERROR_INVALID_STATE;
3836         }
3837
3838         vc_mgr_client_set_feedback_audio_format_cb(g_vc_m, callback, user_data);
3839
3840         SLOG(LOG_DEBUG, TAG_VCM, "[SUCCESS] Set feedback audio format callback");
3841
3842         return 0;
3843 }
3844
3845 int vc_mgr_unset_feedback_audio_format_cb()
3846 {
3847         vc_state_e state;
3848         if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) {
3849                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Unset feedback audio format callback : A handle is not available");
3850                 return VC_ERROR_INVALID_STATE;
3851         }
3852
3853         /* check state */
3854         if (VC_STATE_INITIALIZED != state) {
3855                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Unset feedback audio format callback : Current state is not 'Initialized' (%d)", state);
3856                 return VC_ERROR_INVALID_STATE;
3857         }
3858
3859         vc_mgr_client_set_feedback_audio_format_cb(g_vc_m, NULL, NULL);
3860
3861         SLOG(LOG_DEBUG, TAG_VCM, "[SUCCESS] Unset feedback audio format callback");
3862
3863         return 0;
3864 }
3865
3866 int vc_mgr_set_feedback_streaming_cb(vc_mgr_feedback_streaming_cb callback, void* user_data)
3867 {
3868         if (NULL == callback)
3869                 return VC_ERROR_INVALID_PARAMETER;
3870
3871         vc_state_e state;
3872         if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) {
3873                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Set feedback streaming callback : A handle is not available");
3874                 return VC_ERROR_INVALID_STATE;
3875         }
3876
3877         /* check state */
3878         if (VC_STATE_INITIALIZED != state) {
3879                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Set feedback streaming callback : Current state is not 'Initialized' (%d)", state);
3880                 return VC_ERROR_INVALID_STATE;
3881         }
3882
3883         vc_mgr_client_set_feedback_streaming_cb(g_vc_m, callback, user_data);
3884
3885         SLOG(LOG_DEBUG, TAG_VCM, "[SUCCESS] Set feedback streaming callback");
3886
3887         return 0;
3888 }
3889
3890 int vc_mgr_unset_feedback_streaming_cb()
3891 {
3892         vc_state_e state;
3893         if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) {
3894                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Unset feedback streaming callback : A handle is not available");
3895                 return VC_ERROR_INVALID_STATE;
3896         }
3897
3898         /* check state */
3899         if (VC_STATE_INITIALIZED != state) {
3900                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Unset feedback streaming callback : Current state is not 'Initialized' (%d)", state);
3901                 return VC_ERROR_INVALID_STATE;
3902         }
3903
3904         vc_mgr_client_set_feedback_streaming_cb(g_vc_m, NULL, NULL);
3905
3906         SLOG(LOG_DEBUG, TAG_VCM, "[SUCCESS] Unset feedback streaming callback");
3907
3908         return 0;
3909 }
3910
3911 static void __tts_feedback_thread(void* data, Ecore_Thread* thread)
3912 {
3913         SLOG(LOG_DEBUG, TAG_VCM, "[SUCCESS] Start thread");
3914
3915         vc_feedback_data_s* feedback_data = NULL;
3916         vc_mgr_feedback_streaming_cb callback = NULL;
3917         void* user_data = NULL;
3918
3919         vc_mgr_client_get_feedback_streaming_cb(g_vc_m, &callback, &user_data);
3920         if (NULL == callback) {
3921                 SLOG(LOG_WARN, TAG_VCM, "[WARNING] TTS feedback streaming callback is null");
3922                 return;
3923         }
3924
3925         while (1) {
3926                 int ret = -1;
3927                 int cnt = 0;
3928
3929                 /* get feedback data */
3930                 ret = vc_mgr_data_get_feedback_data(&feedback_data);
3931                 if (0 != ret || NULL == feedback_data) {
3932                         /* empty queue */
3933                         SLOG(LOG_DEBUG, TAG_VCM, "[DEBUG] No feedback data. Waiting mode");
3934
3935                         /* waiting */
3936                         while (1) {
3937                                 usleep(10000);
3938                                 if (0 < vc_mgr_data_get_feedback_data_size()) {
3939                                         SLOG(LOG_INFO, TAG_VCM, "[INFO] Resume thread");
3940                                         break;
3941                                 }
3942                                 if (200 < cnt) {
3943                                         SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Wrong request, there's no pcm data");
3944                                         return;
3945                                 }
3946                                 cnt++;
3947                         }
3948                         SLOG(LOG_INFO, TAG_VCM, "[INFO] Finish to wait for new feedback data come");
3949
3950                         /* resume feedback thread */
3951                         continue;
3952                 }
3953
3954                 SLOG(LOG_DEBUG, TAG_VCM, "TTS feedback streaming callback is called");
3955                 vc_mgr_client_use_callback(g_vc_m);
3956                 callback(feedback_data->event, feedback_data->data, feedback_data->data_size, user_data);
3957                 vc_mgr_client_not_use_callback(g_vc_m);
3958
3959                 /* If no feedback data and EVENT_FINISH */
3960                 if (0 >= vc_mgr_data_get_feedback_data_size() && VC_FEEDBACK_EVENT_FINISH == feedback_data->event) {
3961                         SLOG(LOG_INFO, TAG_VCM, "[INFO] Finish feedback");
3962                         break;
3963                 }
3964         }
3965 }
3966
3967 static void __end_tts_feedback_thread(void* data, Ecore_Thread* thread)
3968 {
3969         SLOG(LOG_DEBUG, TAG_VCM, "[SUCCESS] End thread");
3970 }
3971
3972 int vc_mgr_start_feedback(void)
3973 {
3974         SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] Request start TTS feedback");
3975
3976         vc_state_e state;
3977         if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) {
3978                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Start feedback : A handle is not available");
3979                 return VC_ERROR_INVALID_STATE;
3980         }
3981
3982         /* check state */
3983         if (VC_STATE_READY != state) {
3984                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Start feedback : Current state is not 'Ready' (%d)", state);
3985                 return VC_ERROR_INVALID_STATE;
3986         }
3987
3988 #if 1
3989         ecore_thread_run(__tts_feedback_thread, __end_tts_feedback_thread, NULL, NULL);
3990 #else
3991         /* start playing TTS feedback */
3992         int ret = -1;
3993         ret = vc_mgr_player_play();
3994         if (0 != ret) {
3995                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to player play, ret(%d)", ret);
3996         }
3997 #endif
3998         return 0;
3999 }
4000
4001 int vc_mgr_stop_feedback(void)
4002 {
4003         SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] Request stop TTS feedback");
4004
4005         vc_state_e state;
4006         if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) {
4007                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Stop feedback : A handle is not available");
4008                 return VC_ERROR_INVALID_STATE;
4009         }
4010
4011         /* check state */
4012         if (VC_STATE_READY != state) {
4013                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Stop feedback : Current state is not 'Ready' (%d)", state);
4014                 return VC_ERROR_INVALID_STATE;
4015         }
4016
4017 #if 1
4018         int ret = -1;
4019
4020         while (1) {
4021                 vc_feedback_data_s* feedback_data = NULL;
4022
4023                 /* get feedback data */
4024                 ret = vc_mgr_data_get_feedback_data(&feedback_data);
4025                 if (0 != ret || NULL == feedback_data) {
4026                         /* empty queue */
4027                         SLOG(LOG_INFO, TAG_VCM, "[INFO] No feedback data to stop any more");
4028                         return 0;
4029                 }
4030                 ret = vc_mgr_data_clear_feedback_data(&feedback_data);
4031                 if (0 != ret) {
4032                         SLOG(LOG_INFO, TAG_VCM, "[ERROR] Fail to clear data, ret(%d)", ret);
4033                         break;
4034                 }
4035         }
4036 #else
4037         /* request to stop playing TTS feedback */
4038         int ret = -1;
4039         ret = vc_mgr_player_stop();
4040         if (0 != ret) {
4041                 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to player stop, ret(%d)", ret);
4042         }
4043 #endif
4044         return ret;
4045 }