Fix errors which are created by solving merge conflict
[platform/core/uifw/voice-control.git] / server / vce.c
1 /*
2 * Copyright (c) 2011-2017 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
18 #include <cynara-client.h>
19 #include <cynara-error.h>
20 #include <cynara-session.h>
21 #include <system_info.h>
22 #include "vcd_tidl.h"
23 #include "vcd_main.h"
24 #include "vcd_server.h"
25
26 #include "vce.h"
27
28 static int g_feature_enabled = -1;
29 static bool g_privilege_allowed = false;
30
31 static pthread_mutex_t g_cynara_mutex = PTHREAD_MUTEX_INITIALIZER;
32 static cynara *p_cynara = NULL;
33
34 static int __vce_get_feature_enabled()
35 {
36         if (0 == g_feature_enabled) {
37                 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Voice control feature NOT supported");
38                 return VCE_ERROR_NOT_SUPPORTED;
39         } else if (-1 == g_feature_enabled) {
40                 bool vc_supported = false;
41                 bool mic_supported = false;
42                 if (0 == system_info_get_platform_bool(VC_FEATURE_PATH, &vc_supported)) {
43                         if (0 == system_info_get_platform_bool(VC_MIC_FEATURE_PATH, &mic_supported)) {
44                                 if (false == vc_supported || false == mic_supported) {
45                                         SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Voice control feature NOT supported");
46                                         g_feature_enabled = 0;
47                                         return VCE_ERROR_NOT_SUPPORTED;
48                                 }
49
50                                 g_feature_enabled = 1;
51                         } else {
52                                 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to get feature value");
53                                 return VCE_ERROR_NOT_SUPPORTED;
54                         }
55                 } else {
56                         SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to get feature value");
57                         return VCE_ERROR_NOT_SUPPORTED;
58                 }
59         }
60
61         return VCE_ERROR_NONE;
62 }
63
64 static int __check_privilege_initialize()
65 {
66         int ret = cynara_initialize(&p_cynara, NULL);
67         if (CYNARA_API_SUCCESS != ret)
68                 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] fail to initialize");
69
70         return ret == CYNARA_API_SUCCESS;
71 }
72
73 static int __check_privilege(const char* uid, const char * privilege)
74 {
75         FILE *fp = NULL;
76         char label_path[1024] = "/proc/self/attr/current";
77         char smack_label[1024] = {'\0',};
78
79         if (!p_cynara) {
80                 return false;
81         }
82
83         fp = fopen(label_path, "r");
84         if (fp != NULL) {
85                 if (0 >= fread(smack_label, 1, sizeof(smack_label), fp))
86                         SLOG(LOG_ERROR, TAG_VCD, "[ERROR] fail to fread");
87
88                 fclose(fp);
89         }
90
91         pid_t pid = getpid();
92         char *session = cynara_session_from_pid(pid);
93         int ret = cynara_check(p_cynara, smack_label, session, uid, privilege);
94         SLOG(LOG_INFO, TAG_VCD, "[Client]cynara_check returned %d(%s)", ret, (CYNARA_API_ACCESS_ALLOWED == ret) ? "Allowed" : "Denied");
95         if (session)
96                 free(session);
97
98         if (ret != CYNARA_API_ACCESS_ALLOWED)
99                 return false;
100         return true;
101 }
102
103 static void __check_privilege_deinitialize()
104 {
105         if (p_cynara)
106         {
107                 int ret = cynara_finish(p_cynara);
108                 if (ret != CYNARA_API_SUCCESS)
109                         SLOG(LOG_ERROR, TAG_VCD, "[ERROR] cynara finish %d", ret);
110         }
111         p_cynara = NULL;
112 }
113
114 static int __vce_check_privilege()
115 {
116         if (true == g_privilege_allowed)
117                 return VC_ERROR_NONE;
118
119         pthread_mutex_lock(&g_cynara_mutex);
120
121         if (false == g_privilege_allowed) {
122                 bool ret = true;
123                 ret = __check_privilege_initialize();
124                 if (false == ret) {
125                         SLOG(LOG_ERROR, TAG_VCD, "[ERROR] privilege initialize is failed");
126                         pthread_mutex_unlock(&g_cynara_mutex);
127                         return VCE_ERROR_PERMISSION_DENIED;
128                 }
129
130                 char uid[32];
131                 snprintf(uid, 32, "%d", getuid());
132                 ret = true;
133                 ret = __check_privilege(uid, VC_PRIVILEGE_RECORDER);
134                 if (false == ret) {
135                         //LCOV_EXCL_START
136                         SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Permission is denied(%s)(%s)", VC_PRIVILEGE_RECORDER, uid);
137                         __check_privilege_deinitialize();
138                         g_privilege_allowed = false;
139                         pthread_mutex_unlock(&g_cynara_mutex);
140                         return VCE_ERROR_PERMISSION_DENIED;
141                         //LCOV_EXCL_STOP
142                 }
143
144                 ret = __check_privilege(uid, VC_PRIVILEGE_APPMGR_LAUNCH);
145                 if (false == ret) {
146                         //LCOV_EXCL_START
147                         SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Permission is denied(%s)(%s)", VC_PRIVILEGE_APPMGR_LAUNCH, uid);
148                         __check_privilege_deinitialize();
149                         g_privilege_allowed = false;
150                         pthread_mutex_unlock(&g_cynara_mutex);
151                         return VCE_ERROR_PERMISSION_DENIED;
152                         //LCOV_EXCL_STOP
153                 }
154
155                 ret = __check_privilege(uid, VC_PRIVILEGE_DATASHARING);
156                 if (false == ret) {
157                         //LCOV_EXCL_START
158                         SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Permission is denied(%s)(%s)", VC_PRIVILEGE_DATASHARING, uid);
159                         __check_privilege_deinitialize();
160                         g_privilege_allowed = false;
161                         pthread_mutex_unlock(&g_cynara_mutex);
162                         return VCE_ERROR_PERMISSION_DENIED;
163                         //LCOV_EXCL_STOP
164                 }
165
166                 __check_privilege_deinitialize();
167
168         }
169
170         g_privilege_allowed = true;
171         pthread_mutex_unlock(&g_cynara_mutex);
172         return VCE_ERROR_NONE;
173 }
174
175 int __check_engine_feature_privilege()
176 {
177         if (0 != __vce_get_feature_enabled()) {
178                 return VCE_ERROR_NOT_SUPPORTED;
179         }
180         if (0 != __vce_check_privilege()) {
181                 return VCE_ERROR_PERMISSION_DENIED;
182         }
183
184         return VCE_ERROR_NONE;
185 }
186
187 int vce_main(int argc, char** argv, vce_request_callback_s *callback)
188 {
189         int ret;
190         ret = __check_engine_feature_privilege();
191         if (VCE_ERROR_NONE != ret)
192                 return ret;
193
194         SLOG(LOG_DEBUG, TAG_VCD, "  ");
195         SLOG(LOG_DEBUG, TAG_VCD, "  ");
196         SLOG(LOG_INFO, TAG_VCD, "===== VC Engine Service Initialize");
197
198         ret = VCE_ERROR_NONE;
199
200         if (!ecore_init()) {
201                 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail ecore_init()");
202                 return VCE_ERROR_OPERATION_FAILED;
203         }
204
205         ret = vcd_initialize(callback);
206         if (0 != ret) {
207                 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to initialize");
208                 ecore_shutdown();
209                 return ret;
210         }
211
212         SLOG(LOG_INFO, TAG_VCD, "[Main] VC Engine Service start...");
213
214         SLOG(LOG_DEBUG, TAG_VCD, "=====");
215         SLOG(LOG_DEBUG, TAG_VCD, "  ");
216         SLOG(LOG_DEBUG, TAG_VCD, "  ");
217
218         return VCE_ERROR_NONE;
219 }
220
221 int vce_send_result(vce_result_event_e event, int* result_id, int count, const char* all_result, const char* non_fixed_result, const char* nlu_result, const char* msg, int* user_info, void *user_data)
222 {
223         int ret = VCE_ERROR_NONE;
224         ret = __check_engine_feature_privilege();
225         if (VCE_ERROR_NONE != ret)
226                 return ret;
227
228         if (event < VCE_RESULT_EVENT_SUCCESS || event > VCE_RESULT_EVENT_ERROR) {
229                 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Invalid parameter");
230                 return VCE_ERROR_INVALID_PARAMETER;
231         }
232
233         if (NULL == all_result || NULL == non_fixed_result || NULL == nlu_result) {
234                 SLOG(LOG_ERROR, TAG_VCD, "[INFO] Input parameter is NULL. (no result)");
235         }
236
237         ret = vcd_send_result(event, result_id, count, all_result, non_fixed_result, nlu_result, msg, user_info, user_data);
238         if (0 != ret) {
239                 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to send result");
240         } else {
241                 SLOG(LOG_INFO, TAG_VCD, "[INFO] Success to send result");
242         }
243
244         return ret;
245 }
246
247
248 int vce_send_asr_result(vce_asr_result_event_e event, const char* asr_result, void *user_data)
249 {
250         int ret = VCE_ERROR_NONE;
251         ret = __check_engine_feature_privilege();
252         if (VCE_ERROR_NONE != ret)
253                 return ret;
254
255         if (event < VCE_ASR_RESULT_EVENT_FINAL_RESULT || event > VCE_ASR_RESULT_EVENT_ERROR) {
256                 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Invalid parameter");
257                 return VCE_ERROR_INVALID_PARAMETER;
258         }
259
260         if (NULL == asr_result) {
261                 SLOG(LOG_ERROR, TAG_VCD, "[INFO] Input parameter is NULL. (no result)");
262         }
263
264         ret = vcd_send_asr_result(event, asr_result, user_data);
265         if (0 != ret) {
266                 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to send ASR result");
267         } else {
268                 SLOG(LOG_INFO, TAG_VCD, "[INFO] Success to send ASR result");
269         }
270
271         return ret;
272 }
273
274 int vce_send_specific_engine_result(const char* engine_app_id, const char* event, const char* result, void *user_info)
275 {
276         int ret = VCE_ERROR_NONE;
277         ret = __check_engine_feature_privilege();
278         if (VCE_ERROR_NONE != ret)
279                 return ret;
280
281         if (NULL == engine_app_id || NULL == event) {
282                 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Invalid parameter");
283                 return VCE_ERROR_INVALID_PARAMETER;
284         }
285
286         if (NULL == result) {
287                 SLOG(LOG_ERROR, TAG_VCD, "[INFO] Input parameter is NULL. (no result)");
288         }
289
290         ret = vcd_send_specific_engine_result(engine_app_id, event, result, user_info);
291         if (0 != ret) {
292                 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to send specific engine result, ret(%d)", ret);
293         } else {
294                 SLOG(LOG_INFO, TAG_VCD, "[INFO] Success to send specific engine result, event(%s), result(%s)", event, result);
295         }
296
297         return ret;
298 }
299
300 int vce_send_nlg_result(const char* nlg_result, void *user_data)
301 {
302         int ret = VCE_ERROR_NONE;
303         ret = __check_engine_feature_privilege();
304         if (VCE_ERROR_NONE != ret)
305                 return ret;
306
307         if (NULL == nlg_result) {
308                 SLOG(LOG_ERROR, TAG_VCD, "[INFO] Input parameter is NULL. (no result)");
309         }
310
311         ret = vcd_send_nlg_result(nlg_result, user_data);
312         if (0 != ret) {
313                 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to send NLG result");
314         } else {
315                 SLOG(LOG_INFO, TAG_VCD, "[INFO] Success to send NLG result");
316         }
317
318         return ret;
319 }
320
321 int vce_send_error(vce_error_e error, const char* msg, void *user_data)
322 {
323         int ret = VCE_ERROR_NONE;
324         ret = __check_engine_feature_privilege();
325         if (VCE_ERROR_NONE != ret)
326                 return ret;
327
328         if (NULL == msg) {
329                 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Input parameter is NULL. (no error message)");
330         }
331
332         ret = vcd_send_error(error, msg, user_data);
333
334         if (0 != ret) {
335                 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to send error");
336         }
337
338         return ret;
339 }
340
341
342 /* Daemon API */
343 int vce_get_foreach_command(vce_cmd_h vce_command, vce_command_cb callback, void* user_data)
344 {
345         if (0 != __vce_get_feature_enabled()) {
346                 return VCE_ERROR_NOT_SUPPORTED;
347         }
348
349         int ret = VCE_ERROR_NONE;
350
351         ret = vcd_get_foreach_command(vce_command, callback, user_data);
352         if (0 != ret) {
353                 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to get foreach command");
354         }
355
356         return ret;
357 }
358
359 int vce_get_command_count(vce_cmd_h vce_command, int* count)
360 {
361         if (0 != __vce_get_feature_enabled()) {
362                 return VCE_ERROR_NOT_SUPPORTED;
363         }
364
365         int ret = VCE_ERROR_NONE;
366
367         if (NULL == count) {
368                 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Invalid parameter");
369                 return VCE_ERROR_INVALID_PARAMETER;
370         }
371         ret = vcd_get_command_count(vce_command, count);
372         if (0 != ret) {
373                 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to get command count");
374         }
375
376         return ret;
377 }
378
379 int vce_get_audio_type(char** audio_type)
380 {
381         int ret;
382         ret = __check_engine_feature_privilege();
383         if (VCE_ERROR_NONE != ret)
384                 return ret;
385
386         ret = vcd_get_audio_type(audio_type);
387         if (0 != ret) {
388                 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to get audio type");
389         }
390
391         return ret;
392 }
393
394 int vce_set_private_data(const char* key, const char* data)
395 {
396         int ret;
397         ret = __check_engine_feature_privilege();
398         if (VCE_ERROR_NONE != ret)
399                 return ret;
400
401         if (NULL == key || NULL == data) {
402                 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Invalid parameter");
403                 return VCE_ERROR_INVALID_PARAMETER;
404         }
405
406         // TODO: Shoud be added updateEvent to client, need to ACR for update state.
407         // if (!strncmp(key, "UpdateEventStart", strlen(key)))
408         //      ret = vce_send_update_status(VCE_UPDATE_EVENT_START, NULL);
409         // else if (!strncmp(key, "UpdateEventComplete", strlen(key)))
410         //      ret = vce_send_update_status(VCE_UPDATE_EVENT_FINISH, NULL);
411         // else if (!strncmp(key, "UpdateEventFail", strlen(key)))
412         //      ret = vce_send_update_status(VCE_UPDATE_EVENT_FAIL, data);
413         // if (0 != ret) {
414         //      SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to send update status, event(%s), msg(%s): ret(%d)", key, data, ret);
415         //      return ret;
416         // }
417
418         ret = vcd_set_private_data(key, data);
419         if (0 != ret) {
420                 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to set private data to vc manager");
421         }
422
423         return ret;
424 }
425
426 int vce_get_private_data(const char* key, char** data)
427 {
428         int ret;
429         ret = __check_engine_feature_privilege();
430         if (VCE_ERROR_NONE != ret)
431                 return ret;
432
433         if (NULL == key || NULL == data) {
434                 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Invalid parameter");
435                 return VCE_ERROR_INVALID_PARAMETER;
436         }
437
438         ret = vcd_get_private_data(key, data);
439         if (0 != ret) {
440                 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to get private data from vc manager");
441         }
442
443         return ret;
444 }
445
446 int vce_start_recording()
447 {
448         int ret;
449         ret = __check_engine_feature_privilege();
450         if (VCE_ERROR_NONE != ret)
451                 return ret;
452
453         ret = vcd_start_recording();
454         if (0 != ret) {
455                 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to start recording");
456         }
457
458         return ret;
459 }
460
461 int vce_stop_recording()
462 {
463         int ret;
464         ret = __check_engine_feature_privilege();
465         if (VCE_ERROR_NONE != ret)
466                 return ret;
467
468         ret = vcd_stop_recording();
469         if (0 != ret) {
470                 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to stop recording");
471         }
472
473         return ret;
474 }
475
476 int vce_send_update_status(vce_update_event_e update_event, const char* msg)
477 {
478         int ret;
479         ret = __check_engine_feature_privilege();
480         if (VCE_ERROR_NONE != ret)
481                 return ret;
482
483         ret = vcd_send_update_status(update_event, msg);
484         if (0 != ret) {
485                 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to send update status");
486         }
487
488         return ret;
489 }
490
491 int vce_set_private_data_set_cb(vce_private_data_set_cb callback_func)
492 {
493         int ret;
494         ret = __check_engine_feature_privilege();
495         if (VCE_ERROR_NONE != ret)
496                 return ret;
497
498         if (NULL == callback_func) {
499                 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Invalid parameter");
500                 return VCE_ERROR_INVALID_PARAMETER;
501         }
502
503         ret = vcd_set_private_data_set_cb(callback_func);
504         if (0 != ret) {
505                 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to set private data set cb");
506         }
507
508         return ret;
509 }
510
511 int vce_set_private_data_requested_cb(vce_private_data_requested_cb callback_func)
512 {
513         int ret;
514         ret = __check_engine_feature_privilege();
515         if (VCE_ERROR_NONE != ret)
516                 return ret;
517
518         if (NULL == callback_func) {
519                 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Invalid parameter");
520                 return VCE_ERROR_INVALID_PARAMETER;
521         }
522
523         ret = vcd_set_private_data_requested_cb(callback_func);
524         if (0 != ret) {
525                 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to set private data requested cb");
526         }
527
528         return ret;
529 }
530
531 int vce_set_nlu_base_info_requested_cb(vce_nlu_base_info_requested_cb callback_func)
532 {
533         if (0 != __vce_get_feature_enabled()) {
534                 return VCE_ERROR_NOT_SUPPORTED;
535         }
536
537         if (NULL == callback_func) {
538                 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Invalid parameter");
539                 return VCE_ERROR_INVALID_PARAMETER;
540         }
541
542         int ret = vcd_set_nlu_base_info_requested_cb(callback_func);
543         if (0 != ret) {
544                 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to set nlu-base info requested cb");
545         }
546
547         return ret;
548 }
549
550 int vce_set_specific_engine_request_cb(vce_specific_engine_request_cb callback_func)
551 {
552         if (0 != __vce_get_feature_enabled()) {
553                 return VCE_ERROR_NOT_SUPPORTED;
554         }
555
556         if (NULL == callback_func) {
557                 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Invalid parameter");
558                 return VCE_ERROR_INVALID_PARAMETER;
559         }
560
561         int ret = vcd_set_specific_engine_request_cb(callback_func);
562         if (0 != ret) {
563                 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to set specific engine request cb");
564         }
565
566         return ret;
567 }
568
569 int vce_unset_specific_engine_request_cb(void)
570 {
571         if (0 != __vce_get_feature_enabled()) {
572                 return VCE_ERROR_NOT_SUPPORTED;
573         }
574
575         int ret = vcd_set_specific_engine_request_cb(NULL);
576         if (0 != ret) {
577                 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to unset specific engine request cb");
578         }
579
580         return ret;
581 }
582
583 /* for TTS feedback */
584 int vce_send_feedback_audio_format(int rate, vce_audio_channel_e channel, vce_audio_type_e audio_type)
585 {
586         int ret = VCE_ERROR_NONE;
587         ret = __check_engine_feature_privilege();
588         if (VCE_ERROR_NONE != ret)
589                 return ret;
590
591         if (channel < VCE_AUDIO_CHANNEL_MONO || channel > VCE_AUDIO_CHANNEL_STEREO) {
592                 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Invalid parameter");
593                 return VCE_ERROR_INVALID_PARAMETER;
594         }
595
596         if (audio_type < VCE_AUDIO_TYPE_PCM_S16_LE || audio_type > VCE_AUDIO_TYPE_PCM_U8) {
597                 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Invalid parameter");
598                 return VCE_ERROR_INVALID_PARAMETER;
599         }
600
601         ret = vcd_send_feedback_audio_format(rate, channel, audio_type);
602         if (0 != ret) {
603                 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to send feedback audio format");
604         }
605
606         return ret;
607 }
608
609 int vce_send_feedback_streaming(vce_feedback_event_e event, char* buffer, int len)
610 {
611         int ret = VCE_ERROR_NONE;
612         ret = __check_engine_feature_privilege();
613         if (VCE_ERROR_NONE != ret)
614                 return ret;
615
616         if (NULL == buffer) {
617                 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Input parameter is NULL");
618                 return VCE_ERROR_INVALID_PARAMETER;
619         }
620
621         ret = vcd_send_feedback_streaming(event, buffer, len);
622         if (0 != ret) {
623                 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to send feedback streaming");
624         }
625
626         return ret;
627 }
628
629 int vce_set_request_tts_cb(vce_request_tts_cb callback_func, void* user_data)
630 {
631         if (NULL == callback_func) {
632                 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Invalid parameter");
633                 return VCE_ERROR_INVALID_PARAMETER;
634         }
635
636         int ret = vcd_set_request_tts_cb(callback_func, user_data);
637         if (0 != ret) {
638                 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to set request tts cb");
639         }
640
641         return ret;
642 }
643
644 int vce_unset_request_tts_cb(void)
645 {
646         int ret = vcd_set_request_tts_cb(NULL, NULL);
647         if (0 != ret) {
648                 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to unset request tts cb");
649         }
650
651         return ret;
652 }
653
654 int vce_set_cancel_tts_cb(vce_cancel_tts_cb callback_func, void* user_data)
655 {
656         if (NULL == callback_func) {
657                 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Invalid parameter");
658                 return VCE_ERROR_INVALID_PARAMETER;
659         }
660
661         int ret = vcd_set_cancel_tts_cb(callback_func, user_data);
662         if (0 != ret) {
663                 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to set cancel tts cb");
664         }
665
666         return ret;
667 }
668
669 int vce_unset_cancel_tts_cb(void)
670 {
671         int ret = vcd_set_cancel_tts_cb(NULL, NULL);
672         if (0 != ret) {
673                 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to unset cancel tts cb");
674         }
675
676         return ret;
677 }
678
679 int vce_set_tts_audio_format_request_cb(vce_tts_audio_format_request_cb callback_func, void* user_data)
680 {
681         if (NULL == callback_func) {
682                 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Invalid parameter");
683                 return VCE_ERROR_INVALID_PARAMETER;
684         }
685
686         int ret = vcd_set_tts_audio_format_request_cb(callback_func, user_data);
687         if (0 != ret) {
688                 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to set get tts audio format cb");
689         }
690
691         return ret;
692 }
693
694 int vce_unset_get_tts_audio_format_cb(void)
695 {
696         int ret = vcd_set_tts_audio_format_request_cb(NULL, NULL);
697         if (0 != ret) {
698                 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to unset request tts cb");
699         }
700
701         return ret;
702 }