Unify bundle data in client, mgr, and widget
[platform/core/uifw/voice-control.git] / client / vc_tidl.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 "vc_command.h"
18 #include "vc_tidl.h"
19 #include "vc_proxy.h"
20 #include "vc_main.h"
21
22 #include <vconf.h>
23
24 typedef struct {
25         int pid;
26         bool connected;
27         bool connection_requesting;
28         bool register_notify_callback_invoked;
29         bool register_feedback_callback_invoked;
30
31         rpc_port_proxy_vc_proxy_vc_h rpc_h;
32         rpc_port_proxy_vc_proxy_vc_notify_cb_h notify_cb_h;
33         rpc_port_proxy_vc_proxy_vc_feedback_cb_h feedback_cb_h;
34
35         char* engine_appid;
36 } vc_tidl_info_s;
37
38 static GList* g_tidl_infos = NULL;
39
40 extern int __vc_cb_error(int reason, int daemon_pid, char* msg);
41 extern int __vc_cb_error_to_app(int pid, int reason, char* msg);
42 extern void __vc_cb_result();
43 extern int __vc_cb_service_state(int state);
44 extern int __vc_cb_manager_pid(int manager_pid);
45 extern int __vc_cb_tts_streaming(int utt_id, vc_feedback_event_e event, char* buffer, int len);
46 extern int __vc_cb_utterance_status(int utt_id, int utt_status);
47
48
49 static vc_tidl_info_s* __get_tidl_info_s(int pid)
50 {
51         GList* iter = NULL;
52         vc_tidl_info_s* info = NULL;
53
54         if (g_list_length(g_tidl_infos) > 0) {
55                 /* Get a first item */
56                 iter = g_list_first(g_tidl_infos);
57
58                 while (NULL != iter) {
59                         info = iter->data;
60
61                         if (info->pid == pid) {
62                                 return info;
63                         }
64
65                         /* Next item */
66                         iter = g_list_next(iter);
67                 }
68         }
69
70         return NULL;
71 }
72
73 static char* __get_engine_appid(void)
74 {
75         char* engine_name = vconf_get_str(VC_ENGINE_DB_DEFAULT);
76         if (NULL == engine_name) {
77                 SLOG(LOG_WARN, TAG_VCC, "[WARNING] Fail to get engine name. Please use default engine name.");
78                 engine_name = strdup("org.tizen.vc-engine-default");
79         }
80
81         char* appid = strdup(engine_name);
82
83         SLOG(LOG_INFO, TAG_VCC, "[INFO] VC engine appid(%s)", appid);
84
85         return appid;
86 }
87
88 static void __on_connected(rpc_port_proxy_vc_proxy_vc_h h, void* user_data)
89 {
90         unsigned int pid = (uintptr_t)user_data;
91
92         vc_tidl_info_s* info = __get_tidl_info_s(pid);
93         RETM_IF(NULL == info, "[ERROR] Fail to get tidl info");
94
95         info->connected = true;
96         info->connection_requesting = false;
97         info->register_notify_callback_invoked = false;
98
99         SLOG(LOG_INFO, TAG_VCC, "[INFO] Connected to server");
100 }
101
102 static void __on_disconnected(rpc_port_proxy_vc_proxy_vc_h h, void* user_data)
103 {
104         unsigned int pid = (uintptr_t)user_data;
105
106         vc_tidl_info_s* info = __get_tidl_info_s(pid);
107         RETM_IF(NULL == info, "[ERROR] Fail to get tidl info");
108
109         info->connected = false;
110         info->connection_requesting = false;
111         info->register_notify_callback_invoked = false;
112
113         /* retry to connect */
114         SLOG(LOG_INFO, TAG_VCC, "[INFO] Disconnected to server");
115 }
116
117 static void __on_rejected(rpc_port_proxy_vc_proxy_vc_h h, void* user_data)
118 {
119         unsigned int pid = (uintptr_t)user_data;
120
121         vc_tidl_info_s* info = __get_tidl_info_s(pid);
122         RETM_IF(NULL == info, "[ERROR] Fail to get tidl info");
123
124         info->connection_requesting = false;
125         info->register_notify_callback_invoked = false;
126
127         SLOG(LOG_INFO, TAG_VCC, "[INFO] Rejected from server(%d)", pid);
128 }
129
130
131 static rpc_port_proxy_vc_proxy_vc_h __create_rpc_port(int pid, const char* engine_app_id)
132 {
133         SLOG(LOG_INFO, TAG_VCC, "[INFO] vc __create_rpc_port");
134
135         rpc_port_proxy_vc_proxy_vc_callback_s rpc_callback = {
136                 .connected = __on_connected,
137                 .disconnected = __on_disconnected,
138                 .rejected = __on_rejected
139         };
140
141         rpc_port_proxy_vc_proxy_vc_h handle = NULL;
142         uintptr_t ptr_pid = pid;
143         if (0 != rpc_port_proxy_vc_proxy_vc_create(engine_app_id, &rpc_callback, (void*)ptr_pid, &handle)) {
144                 return NULL;
145         }
146         SLOG(LOG_DEBUG, TAG_VCC, "[DEBUG] Succeed rpc_port_proxy_vc_proxy_vc_create");
147
148         return handle;
149 }
150
151 static void __request_tidl_connect(vc_tidl_info_s* info)
152 {
153         if (info->connection_requesting) {
154                 SLOG(LOG_INFO, TAG_VCC, "[TIDL] Already connection is requested. Skip to call rpc_port_proxy_vc_proxy_vc_connect().");
155                 return;
156         }
157
158         int ret = rpc_port_proxy_vc_proxy_vc_connect(info->rpc_h);
159         if (0 != ret) {
160                 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Fail to request connection to stub. ret(%d)", ret);
161                 return;
162         }
163
164         SLOG(LOG_INFO, TAG_VCC, "[INFO] Request connection to stub. ret(%d)", ret);
165         info->connection_requesting = true;
166 }
167
168 static void __notify_cb(void* user_data, int pid, bundle* msg)
169 {
170         // corresponding to listener_event_callback
171         char* method = NULL;
172
173         SLOG(LOG_DEBUG, TAG_VCC, "__notify_cb is invoked pid(%d)", pid);
174
175         bundle_get_str(msg, VC_BUNDLE_METHOD, &method);
176
177         if (0 == strncmp(VCD_METHOD_HELLO, method, strlen(VCD_METHOD_HELLO))) {
178         } /* VCD_METHOD_HELLO */
179         else if (0 == strncmp(VCD_METHOD_SET_SERVICE_STATE, method, strlen(VCD_METHOD_SET_SERVICE_STATE))) {
180                 /* signal!!! */
181                 char* state = NULL;
182                 bundle_get_str(msg, VC_BUNDLE_SERVICE_STATE, &state);
183                 if (state) {
184                         __vc_cb_service_state(atoi(state));
185                 }
186         } /* VCD_METHOD_SET_SERVICE_STATE */
187         else if (0 == strncmp(VCD_METHOD_RESULT, method, strlen(VCD_METHOD_RESULT))) {
188                 SLOG(LOG_DEBUG, TAG_VCC, "@@@ Get Client Result");
189
190                 __vc_cb_result();
191         } /* VCD_METHOD_RESULT */
192         else if (0 == strncmp(VCD_METHOD_SEND_MANAGER_PID, method, strlen(VCD_METHOD_SEND_MANAGER_PID))) {
193                 /* signal!!! */
194                 char* manager_pid = NULL;
195                 bundle_get_str(msg, VC_BUNDLE_MANAGER_PID, &manager_pid);
196                 if (manager_pid) {
197                         SLOG(LOG_DEBUG, TAG_VCC, "@@ manager pid is changed : %d", atoi(manager_pid));
198                         __vc_cb_manager_pid(atoi(manager_pid));
199                 }
200         } /* VCD_METHOD_SEND_MANAGER_PID */
201         else if (0 == strncmp(VCD_METHOD_ERROR, method, strlen(VCD_METHOD_ERROR))) {
202                 /* signal!!! */
203                 char* reason = NULL;
204                 char* daemon_pid = NULL;
205                 char* err_msg = NULL;
206                 
207                 bundle_get_str(msg, VC_BUNDLE_REASON, &reason);
208                 bundle_get_str(msg, VC_BUNDLE_DAEMON_PID, &daemon_pid);
209                 bundle_get_str(msg, VC_BUNDLE_ERR_MSG, &err_msg);
210
211                 SLOG(LOG_DEBUG, TAG_VCC, "@@ vc Get Error message : reason(%d), daemon_pid(%d), msg(%s)", atoi(reason), atoi(daemon_pid), err_msg);
212                 __vc_cb_error(atoi(reason), atoi(daemon_pid), err_msg);
213         } /* VCD_METHOD_ERROR */
214         else if (0 == strncmp(VCD_METHOD_ERROR_TO_APP, method, strlen(VCD_METHOD_ERROR_TO_APP))) {
215                 /* signal!!! */
216                 char* pid;
217                 char* reason;
218                 char* err_msg = NULL;
219
220                 bundle_get_str(msg, VC_BUNDLE_PID, &pid);
221                 bundle_get_str(msg, VC_BUNDLE_REASON, &reason);
222                 bundle_get_str(msg, VC_BUNDLE_ERR_MSG, &err_msg);
223
224                 SLOG(LOG_DEBUG, TAG_VCC, "@@ vc Get Error message : reason(%d), pid(%d), msg(%s)", atoi(reason), atoi(pid), err_msg);
225                 __vc_cb_error_to_app(atoi(pid), atoi(reason), err_msg);
226         } /* VCD_METHOD_ERROR_TO_APP */
227         else if (0 == strncmp(VC_MANAGER_METHOD_UTTERANCE_STATUS, method, strlen(VC_MANAGER_METHOD_UTTERANCE_STATUS))) {
228                 /* signal!!! */
229                 char* pid = NULL;
230                 char* utt_id = NULL;
231                 char* utt_status = NULL;
232
233                 bundle_get_str(msg, VC_BUNDLE_PID, &pid);
234                 bundle_get_str(msg, VC_BUNDLE_UTT_ID, &utt_id);
235                 bundle_get_str(msg, VC_BUNDLE_UTT_STATUS, &utt_status);
236
237                 SLOG(LOG_DEBUG, TAG_VCC, "@@ vc Get utterance status : pid(%d), utt_id(%d), utt_status(%d)", atoi(pid), atoi(utt_id), atoi(utt_status));
238                 __vc_cb_utterance_status(atoi(utt_id), atoi(utt_status));
239         } /* VC_MANAGER_METHOD_UTTERANCE_STATUS */
240         else {
241                 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Invalid msg");
242         }
243 }
244
245 void __feedback_cb(void *user_data, int utt_id, int event, rpc_port_proxy_vc_proxy_array_char_h pcm_data, int len)
246 {
247         // corresponding to listener_event_callback (only for tts_streaming)
248         SLOG(LOG_DEBUG, TAG_VCC, "__feedback_cb is invoked. utt_id(%d), event(%d), pcm_len(%d)", utt_id, event, len);
249
250         char* data_char = NULL;
251         rpc_port_proxy_vc_proxy_array_char_get(pcm_data, &data_char, &len);
252
253         /* VCD_METHOD_FEEDBACK_STREAMING */
254         __vc_cb_tts_streaming(utt_id, event, data_char, len);
255
256         if (NULL != data_char) {
257                 free(data_char);
258                 data_char = NULL;
259         }
260
261 }
262
263 static int __create_notify_callback_handle(vc_tidl_info_s* info)
264 {
265         if (NULL == info) {
266                 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Invalid parameter");
267                 return VC_ERROR_INVALID_PARAMETER;
268         }
269
270         if (NULL != info->notify_cb_h) {
271                 rpc_port_proxy_vc_proxy_vc_notify_cb_dispose(info->rpc_h, info->notify_cb_h);
272                 info->notify_cb_h = NULL;
273         }
274
275         int ret = rpc_port_proxy_vc_proxy_vc_notify_cb_create(&info->notify_cb_h);
276         if (RPC_PORT_ERROR_NONE != ret) {
277                 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Fail to invoke rpc_port_proxy_vc_proxy_vc_notify_cb_create(). err(%d)", ret);
278                 return VC_ERROR_OUT_OF_MEMORY;
279         }
280
281         rpc_port_proxy_vc_proxy_vc_notify_cb_set_callback(info->notify_cb_h, __notify_cb, NULL);
282         rpc_port_proxy_vc_proxy_vc_notify_cb_set_once(info->notify_cb_h, false);
283
284         return VC_ERROR_NONE;
285 }
286
287 static int __create_feedback_callback_handle(vc_tidl_info_s* info)
288 {
289         if (NULL == info) {
290                 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Invalid parameter");
291                 return VC_ERROR_INVALID_PARAMETER;
292         }
293
294         if (NULL != info->feedback_cb_h) {
295                 rpc_port_proxy_vc_proxy_vc_feedback_cb_dispose(info->rpc_h, info->feedback_cb_h);
296                 info->feedback_cb_h = NULL;
297         }
298
299         int ret = rpc_port_proxy_vc_proxy_vc_feedback_cb_create(&info->feedback_cb_h);
300         if (RPC_PORT_ERROR_NONE != ret) {
301                 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Fail to invoke rpc_port_proxy_vc_proxy_vc_feedback_cb_create(). err(%d)", ret);
302                 return VC_ERROR_OUT_OF_MEMORY;
303         }
304
305         rpc_port_proxy_vc_proxy_vc_feedback_cb_set_callback(info->feedback_cb_h, __feedback_cb, NULL);
306         rpc_port_proxy_vc_proxy_vc_feedback_cb_set_once(info->feedback_cb_h, false);
307
308         return VC_ERROR_NONE;
309 }
310
311 static int __invoke_register_notify_callback(int pid, vc_tidl_info_s* info)
312 {
313         if (info->register_notify_callback_invoked) {
314                 SLOG(LOG_ERROR, TAG_VCC, "[INFO] Already register callback is invoked");
315                 return VC_ERROR_NONE;
316         }
317
318         int ret = __create_notify_callback_handle(info);
319         if (VC_ERROR_NONE != ret) {
320                 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Fail to create callback handle. ret(%d)", ret);
321                 return VC_ERROR_OPERATION_FAILED;
322         }
323
324         rpc_port_proxy_vc_proxy_vc_invoke_register_notify_cb(info->rpc_h, pid, info->notify_cb_h);
325         info->register_notify_callback_invoked = true;
326         return VC_ERROR_NONE;
327 }
328
329 static int __invoke_register_feedback_callback(int pid, vc_tidl_info_s* info)
330 {
331         if (info->register_feedback_callback_invoked) {
332                 SLOG(LOG_ERROR, TAG_VCC, "[INFO] Already register callback is invoked");
333                 return VC_ERROR_NONE;
334         }
335
336         int ret = __create_feedback_callback_handle(info);
337         if (VC_ERROR_NONE != ret) {
338                 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Fail to create callback handle. ret(%d)", ret);
339                 return VC_ERROR_OPERATION_FAILED;
340         }
341
342         rpc_port_proxy_vc_proxy_vc_invoke_register_feedback_cb(info->rpc_h, pid, info->feedback_cb_h);
343         info->register_feedback_callback_invoked = true;
344         return VC_ERROR_NONE;
345 }
346
347 int vc_tidl_open_connection()
348 {
349         SLOG(LOG_INFO, TAG_VCC, "[TIDL] vc_tidl_open_connection");
350
351         vc_tidl_info_s* info = (vc_tidl_info_s*)calloc(1, sizeof(vc_tidl_info_s));
352         if (NULL == info) {
353                 SLOG(LOG_ERROR, TAG_VCC, "[TIDL ERROR] Fail to create tidl_info_s");
354                 return VC_ERROR_OUT_OF_MEMORY;
355         }
356
357         int pid = getpid();
358         char* engine_appid = __get_engine_appid();
359
360         info->rpc_h = __create_rpc_port(pid, engine_appid);
361         if (NULL == info->rpc_h) {
362                 SLOG(LOG_ERROR, TAG_VCC, "[TIDL ERROR] Fail to create proxy");
363                 free(info);
364                 return VC_ERROR_OPERATION_FAILED;
365         }
366
367         info->pid = pid;
368         g_tidl_infos = g_list_append(g_tidl_infos, info);
369
370         SLOG(LOG_ERROR, TAG_VCC, "[TIDL] pid(%d) rpc_h(%p), engine_appid(%s)", pid, info->rpc_h, info->engine_appid);
371         return VC_ERROR_NONE;
372
373 }
374
375 int vc_tidl_close_connection()
376 {
377         SLOG(LOG_INFO, TAG_VCC, "[TIDL] vc_tidl_close_connection");
378
379         int pid = getpid();
380         vc_tidl_info_s* info = __get_tidl_info_s(pid);
381         RETVM_IF(NULL == info, VC_ERROR_INVALID_PARAMETER, "[ERROR] Fail to get tidl info");
382
383         if (0 != rpc_port_proxy_vc_proxy_vc_destroy(info->rpc_h)) {
384                 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Fail to disconnect");
385                 return VC_ERROR_OPERATION_FAILED;
386         }
387
388         info->rpc_h = NULL;
389         info->notify_cb_h = NULL;
390
391         g_tidl_infos = g_list_remove(g_tidl_infos, info);
392         free(info);
393
394         return VC_ERROR_NONE;
395 }
396
397 int vc_tidl_request_hello()
398 {
399         SLOG(LOG_INFO, TAG_VCC, "[TIDL] vc_tidl_request_hello");
400
401         int pid = getpid();
402         vc_tidl_info_s* info = __get_tidl_info_s(pid);
403         RETVM_IF(NULL == info, VC_ERROR_INVALID_PARAMETER, "[ERROR] Fail to get tidl info");
404
405         if (!info->connected) {
406                 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Not Connected. Call __request_tidl_connect()");
407                 __request_tidl_connect(info);
408                 return VC_ERROR_OPERATION_FAILED;
409         }
410
411         SLOG(LOG_DEBUG, TAG_VCC, ">>>>> VCC Hello");
412         if (VC_ERROR_NONE != __invoke_register_notify_callback(pid, info)) {
413                 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Fail to invoke register callback");
414                 return VC_ERROR_OPERATION_FAILED;
415         }
416
417         SLOG(LOG_DEBUG, TAG_VCC, "<<<<");
418         return VC_ERROR_NONE;
419
420 }
421
422 static int __covert_unhandled_error(int ret)
423 {
424         if (RPC_PORT_ERROR_IO_ERROR == ret || RPC_PORT_ERROR_OUT_OF_MEMORY == ret) {
425                 return VC_ERROR_OPERATION_FAILED;
426         }
427
428         return ret;
429 }
430
431 int vc_tidl_request_initialize(int pid, int* mgr_pid, int* service_state, int* daemon_pid)
432 {
433         SLOG(LOG_INFO, TAG_VCC, "[TIDL] vc_tidl_request_initialize");
434
435         vc_tidl_info_s* info = __get_tidl_info_s(pid);
436         RETVM_IF(NULL == info, VC_ERROR_INVALID_PARAMETER, "[ERROR] Fail to get tidl info");
437         RETVM_IF(false == info->connected, VC_ERROR_OPERATION_FAILED, "[ERROR] Not Connected");
438
439         int ret = rpc_port_proxy_vc_proxy_vc_invoke_initialize(info->rpc_h, pid, mgr_pid, service_state, daemon_pid);
440         if (RPC_PORT_ERROR_NONE != ret) {
441                 SLOG(LOG_ERROR, TAG_VCC, ">>>> Request vc initialize : Fail to invoke message. err(%d)", ret);
442                 return __covert_unhandled_error(ret);
443         }
444
445         SLOG(LOG_DEBUG, TAG_VCC, "@@ vc initialize : mgr = %d service = %d daemon_pid = %d", *mgr_pid, *service_state, *daemon_pid); //LCOV_EXCL_LINE
446
447         return VC_ERROR_NONE;
448 }
449
450 int vc_tidl_request_finalize(int pid)
451 {
452         SLOG(LOG_INFO, TAG_VCC, "[TIDL] vc_tidl_request_finalize");
453
454         vc_tidl_info_s* info = __get_tidl_info_s(pid);
455         RETVM_IF(NULL == info, VC_ERROR_INVALID_PARAMETER, "[ERROR] Fail to get tidl info");
456         RETVM_IF(false == info->connected, VC_ERROR_OPERATION_FAILED, "[ERROR] Not Connected");
457
458         int ret = rpc_port_proxy_vc_proxy_vc_invoke_finalize(info->rpc_h, pid);
459         if (RPC_PORT_ERROR_NONE != ret) {
460                 SLOG(LOG_ERROR, TAG_VCC, ">>>> Request vc finalize : Fail to invoke message. err(%d)", ret);
461                 return __covert_unhandled_error(ret);
462         }
463
464         SLOG(LOG_DEBUG, TAG_VCC, "@@ vc finalize : result = %d", ret);
465
466         return VC_ERROR_NONE;
467 }
468
469 int vc_tidl_request_set_command(int pid, vc_cmd_type_e cmd_type)
470 {
471         SLOG(LOG_INFO, TAG_VCC, "[TIDL] vc_tidl_request_set_command");
472
473         vc_tidl_info_s* info = __get_tidl_info_s(pid);
474         RETVM_IF(NULL == info, VC_ERROR_INVALID_PARAMETER, "[ERROR] Fail to get tidl info");
475         RETVM_IF(false == info->connected, VC_ERROR_OPERATION_FAILED, "[ERROR] Not Connected");
476
477         int ret = rpc_port_proxy_vc_proxy_vc_invoke_set_command(info->rpc_h, pid, cmd_type);
478         if (RPC_PORT_ERROR_NONE != ret) {
479                 SLOG(LOG_ERROR, TAG_VCC, ">>>> Request vc set command : Fail to invoke message. err(%d)", ret);
480                 return __covert_unhandled_error(ret);
481         }
482
483         SLOG(LOG_DEBUG, TAG_VCC, "@@ vc set command : pid(%d), cmd_type(%d)", pid, cmd_type);
484
485         return VC_ERROR_NONE;
486 }
487
488 int vc_tidl_request_unset_command(int pid, vc_cmd_type_e cmd_type)
489 {
490         SLOG(LOG_INFO, TAG_VCC, "[TIDL] vc_tidl_request_unset_command");
491
492         vc_tidl_info_s* info = __get_tidl_info_s(pid);
493         RETVM_IF(NULL == info, VC_ERROR_INVALID_PARAMETER, "[ERROR] Fail to get tidl info");
494         RETVM_IF(false == info->connected, VC_ERROR_OPERATION_FAILED, "[ERROR] Not Connected");
495
496         int ret = rpc_port_proxy_vc_proxy_vc_invoke_unset_command(info->rpc_h, pid, cmd_type);
497         if (RPC_PORT_ERROR_NONE != ret) {
498                 SLOG(LOG_ERROR, TAG_VCC, ">>>> Request vc unset command : Fail to invoke message. err(%d)", ret);
499                 return __covert_unhandled_error(ret);
500         }
501
502         SLOG(LOG_DEBUG, TAG_VCC, "@@ vc unset command : pid(%d), cmd_type(%d)", pid, cmd_type);
503
504         return VC_ERROR_NONE;
505 }
506
507 int vc_tidl_request_set_foreground(int pid, bool value)
508 {
509         // method no reply --> async
510         SLOG(LOG_INFO, TAG_VCC, "[TIDL] vc_tidl_request_set_foreground");
511
512         vc_tidl_info_s* info = __get_tidl_info_s(pid);
513         RETVM_IF(NULL == info, VC_ERROR_INVALID_PARAMETER, "[ERROR] Fail to get tidl info");
514         RETVM_IF(false == info->connected, VC_ERROR_OPERATION_FAILED, "[ERROR] Not Connected");
515
516         int ret = rpc_port_proxy_vc_proxy_vc_invoke_set_foreground(info->rpc_h, pid, value);
517         if (RPC_PORT_ERROR_NONE != ret) {
518                 SLOG(LOG_ERROR, TAG_VCC, ">>>> Request vc set foreground : Fail to invoke message. err(%d)", ret);
519                 return __covert_unhandled_error(ret);
520         }
521
522         SLOG(LOG_DEBUG, TAG_VCC, "@@ vc set foreground : pid(%d), value(%d)", pid, value);
523
524         return VC_ERROR_NONE;
525 }
526
527 int vc_tidl_request_set_server_dialog(int pid, const char* app_id, const char* credential)
528 {
529         SLOG(LOG_INFO, TAG_VCC, "[TIDL] vc_tidl_request_set_server_dialog");
530
531         vc_tidl_info_s* info = __get_tidl_info_s(pid);
532         RETVM_IF(NULL == info, VC_ERROR_INVALID_PARAMETER, "[ERROR] Fail to get tidl info");
533         RETVM_IF(false == info->connected, VC_ERROR_OPERATION_FAILED, "[ERROR] Not Connected");
534
535         int ret = rpc_port_proxy_vc_proxy_vc_invoke_set_server_dialog(info->rpc_h, pid, app_id, credential);
536         if (RPC_PORT_ERROR_NONE != ret) {
537                 SLOG(LOG_ERROR, TAG_VCC, ">>>> Request vc set server dialog : Fail to invoke message. err(%d)", ret);
538                 return __covert_unhandled_error(ret);
539         }
540
541         SLOG(LOG_DEBUG, TAG_VCC, "@@ vc set server dialog : pid(%d), app_id(%s), credential(%s)", pid, app_id, credential);
542
543         return VC_ERROR_NONE;
544 }
545
546 int vc_tidl_request_request_dialog(int pid, const char* disp_text, const char* utt_text, bool continuous)
547 {
548         // method no reply --> async
549         SLOG(LOG_INFO, TAG_VCC, "[TIDL] vc_tidl_request_request_dialog");
550
551         vc_tidl_info_s* info = __get_tidl_info_s(pid);
552         RETVM_IF(NULL == info, VC_ERROR_INVALID_PARAMETER, "[ERROR] Fail to get tidl info");
553         RETVM_IF(false == info->connected, VC_ERROR_OPERATION_FAILED, "[ERROR] Not Connected");
554
555         int ret = rpc_port_proxy_vc_proxy_vc_invoke_request_dialog(info->rpc_h, pid, disp_text, utt_text, continuous);
556         if (RPC_PORT_ERROR_NONE != ret) {
557                 SLOG(LOG_ERROR, TAG_VCC, ">>>> Request vc request dialog : Fail to invoke message. err(%d)", ret);
558                 return __covert_unhandled_error(ret);
559         }
560
561         SLOG(LOG_DEBUG, TAG_VCC, "@@ vc request dialog : pid(%d), disp_text(%s), utt_text(%s), continuous(%d)", pid, disp_text, utt_text, continuous);
562
563         return VC_ERROR_NONE;
564 }
565
566 int vc_tidl_request_is_system_command_valid(int pid, bool* is_sys_cmd_valid)
567 {
568         SLOG(LOG_INFO, TAG_VCC, "[TIDL] vc_tidl_request_is_system_command_valid");
569
570         vc_tidl_info_s* info = __get_tidl_info_s(pid);
571         RETVM_IF(NULL == info, VC_ERROR_INVALID_PARAMETER, "[ERROR] Fail to get tidl info");
572         RETVM_IF(false == info->connected, VC_ERROR_OPERATION_FAILED, "[ERROR] Not Connected");
573
574         int ret = rpc_port_proxy_vc_proxy_vc_invoke_is_system_command_valid(info->rpc_h, pid, is_sys_cmd_valid);
575         if (RPC_PORT_ERROR_NONE != ret) {
576                 SLOG(LOG_ERROR, TAG_VCC, ">>>> Request vc is system command valid : Fail to invoke message. err(%d)", ret);
577                 return __covert_unhandled_error(ret);
578         }
579
580         SLOG(LOG_DEBUG, TAG_VCC, "@@ vc is system command valid : pid(%d), is_sys_cmd_valid(%d)", pid, *is_sys_cmd_valid);
581
582         return VC_ERROR_NONE;
583 }
584
585 /* Authority */
586 int vc_tidl_request_auth_enable(int pid, int mgr_pid)
587 {
588         SLOG(LOG_INFO, TAG_VCC, "[TIDL] vc_tidl_request_auth_enable");
589
590         vc_tidl_info_s* info = __get_tidl_info_s(pid);
591         RETVM_IF(NULL == info, VC_ERROR_INVALID_PARAMETER, "[ERROR] Fail to get tidl info");
592         RETVM_IF(false == info->connected, VC_ERROR_OPERATION_FAILED, "[ERROR] Not Connected");
593
594         int ret = rpc_port_proxy_vc_proxy_vc_invoke_auth_enable(info->rpc_h, pid, mgr_pid);
595         if (RPC_PORT_ERROR_NONE != ret) {
596                 SLOG(LOG_ERROR, TAG_VCC, ">>>> Request vc auth enable : Fail to invoke message. err(%d)", ret);
597                 return __covert_unhandled_error(ret);
598         }
599
600         SLOG(LOG_DEBUG, TAG_VCC, "@@ vc auth enable : pid(%d), mgr_pid(%d)", pid, mgr_pid);
601
602         return VC_ERROR_NONE;
603 }
604
605 int vc_tidl_request_auth_disable(int pid, int mgr_pid)
606 {
607         SLOG(LOG_INFO, TAG_VCC, "[TIDL] vc_tidl_request_auth_disable");
608
609         vc_tidl_info_s* info = __get_tidl_info_s(pid);
610         RETVM_IF(NULL == info, VC_ERROR_INVALID_PARAMETER, "[ERROR] Fail to get tidl info");
611         RETVM_IF(false == info->connected, VC_ERROR_OPERATION_FAILED, "[ERROR] Not Connected");
612
613         int ret = rpc_port_proxy_vc_proxy_vc_invoke_auth_disable(info->rpc_h, pid, mgr_pid);
614         if (RPC_PORT_ERROR_NONE != ret) {
615                 SLOG(LOG_ERROR, TAG_VCC, ">>>> Request vc auth disable : Fail to invoke message. err(%d)", ret);
616                 return __covert_unhandled_error(ret);
617         }
618
619         SLOG(LOG_DEBUG, TAG_VCC, "@@ vc auth disable : pid(%d), mgr_pid(%d)", pid, mgr_pid);
620
621         return VC_ERROR_NONE;
622 }
623
624 int vc_tidl_request_auth_start(int pid, int mgr_pid)
625 {
626         SLOG(LOG_INFO, TAG_VCC, "[TIDL] vc_tidl_request_auth_start");
627
628         vc_tidl_info_s* info = __get_tidl_info_s(pid);
629         RETVM_IF(NULL == info, VC_ERROR_INVALID_PARAMETER, "[ERROR] Fail to get tidl info");
630         RETVM_IF(false == info->connected, VC_ERROR_OPERATION_FAILED, "[ERROR] Not Connected");
631
632         int ret = rpc_port_proxy_vc_proxy_vc_invoke_auth_start(info->rpc_h, pid, mgr_pid);
633         if (RPC_PORT_ERROR_NONE != ret) {
634                 SLOG(LOG_ERROR, TAG_VCC, ">>>> Request vc auth start : Fail to invoke message. err(%d)", ret);
635                 return __covert_unhandled_error(ret);
636         }
637
638         SLOG(LOG_DEBUG, TAG_VCC, "@@ vc auth start : pid(%d), mgr_pid(%d)", pid, mgr_pid);
639
640         return VC_ERROR_NONE;
641 }
642
643 int vc_tidl_request_auth_stop(int pid, int mgr_pid)
644 {
645         SLOG(LOG_INFO, TAG_VCC, "[TIDL] vc_tidl_request_auth_stop");
646
647         vc_tidl_info_s* info = __get_tidl_info_s(pid);
648         RETVM_IF(NULL == info, VC_ERROR_INVALID_PARAMETER, "[ERROR] Fail to get tidl info");
649         RETVM_IF(false == info->connected, VC_ERROR_OPERATION_FAILED, "[ERROR] Not Connected");
650
651         int ret = rpc_port_proxy_vc_proxy_vc_invoke_auth_stop(info->rpc_h, pid, mgr_pid);
652         if (RPC_PORT_ERROR_NONE != ret) {
653                 SLOG(LOG_ERROR, TAG_VCC, ">>>> Request vc auth stop : Fail to invoke message. err(%d)", ret);
654                 return __covert_unhandled_error(ret);
655         }
656
657         SLOG(LOG_DEBUG, TAG_VCC, "@@ vc auth stop : pid(%d), mgr_pid(%d)", pid, mgr_pid);
658
659         return VC_ERROR_NONE;
660 }
661
662 int vc_tidl_request_auth_cancel(int pid, int mgr_pid)
663 {
664         SLOG(LOG_INFO, TAG_VCC, "[TIDL] vc_tidl_request_auth_cancel");
665
666         vc_tidl_info_s* info = __get_tidl_info_s(pid);
667         RETVM_IF(NULL == info, VC_ERROR_INVALID_PARAMETER, "[ERROR] Fail to get tidl info");
668         RETVM_IF(false == info->connected, VC_ERROR_OPERATION_FAILED, "[ERROR] Not Connected");
669
670         int ret = rpc_port_proxy_vc_proxy_vc_invoke_auth_cancel(info->rpc_h, pid, mgr_pid);
671         if (RPC_PORT_ERROR_NONE != ret) {
672                 SLOG(LOG_ERROR, TAG_VCC, ">>>> Request vc auth cancel : Fail to invoke message. err(%d)", ret);
673                 return __covert_unhandled_error(ret);
674         }
675
676         SLOG(LOG_DEBUG, TAG_VCC, "@@ vc auth cancel : pid(%d), mgr_pid(%d)", pid, mgr_pid);
677
678         return VC_ERROR_NONE;
679 }
680
681 /* tts feedback */
682 int vc_tidl_request_request_tts(int pid, const char* text, const char* language, bool to_vcm, int* utt_id)
683 {
684         SLOG(LOG_INFO, TAG_VCC, "[TIDL] vc_tidl_request_request_tts");
685
686         vc_tidl_info_s* info = __get_tidl_info_s(pid);
687         RETVM_IF(NULL == info, VC_ERROR_INVALID_PARAMETER, "[ERROR] Fail to get tidl info");
688         RETVM_IF(false == info->connected, VC_ERROR_OPERATION_FAILED, "[ERROR] Not Connected");
689
690         if (VC_ERROR_NONE != __invoke_register_feedback_callback(pid, info)) {
691                 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Fail to invoke register feedback callback");
692                 return VC_ERROR_OPERATION_FAILED;
693         }
694
695         int ret = rpc_port_proxy_vc_proxy_vc_invoke_request_tts(info->rpc_h, pid, text, language, to_vcm, utt_id);
696         if (RPC_PORT_ERROR_NONE != ret) {
697                 SLOG(LOG_ERROR, TAG_VCC, ">>>> Request vc request tts : Fail to invoke message. err(%d)", ret);
698                 return __covert_unhandled_error(ret);
699         }
700
701         SLOG(LOG_DEBUG, TAG_VCC, "@@ vc request tts : pid(%d)", pid);
702
703         return VC_ERROR_NONE;
704 }
705
706 int vc_tidl_request_cancel_tts(int pid, int utt_id)
707 {
708         SLOG(LOG_INFO, TAG_VCC, "[TIDL] vc_tidl_request_cancel_tts");
709
710         vc_tidl_info_s* info = __get_tidl_info_s(pid);
711         RETVM_IF(NULL == info, VC_ERROR_INVALID_PARAMETER, "[ERROR] Fail to get tidl info");
712         RETVM_IF(false == info->connected, VC_ERROR_OPERATION_FAILED, "[ERROR] Not Connected");
713
714         int ret = rpc_port_proxy_vc_proxy_vc_invoke_cancel_tts(info->rpc_h, pid, utt_id);
715         if (RPC_PORT_ERROR_NONE != ret) {
716                 SLOG(LOG_ERROR, TAG_VCC, ">>>> Request vc cancel tts : Fail to invoke message. err(%d)", ret);
717                 return __covert_unhandled_error(ret);
718         }
719
720         SLOG(LOG_DEBUG, TAG_VCC, "@@ vc cancel tts : pid(%d), utt_id(%d)", pid, utt_id);
721
722         return VC_ERROR_NONE;
723 }
724
725 int vc_tidl_request_get_tts_audio_format(int pid, int* rate, vc_audio_channel_e* channel, vc_audio_type_e* audio_type)
726 {
727         SLOG(LOG_INFO, TAG_VCC, "[TIDL] vc_tidl_request_get_tts_audio_format");
728
729         vc_tidl_info_s* info = __get_tidl_info_s(pid);
730         RETVM_IF(NULL == info, VC_ERROR_INVALID_PARAMETER, "[ERROR] Fail to get tidl info");
731         RETVM_IF(false == info->connected, VC_ERROR_OPERATION_FAILED, "[ERROR] Not Connected");
732
733         int ret = rpc_port_proxy_vc_proxy_vc_invoke_get_tts_audio_format(info->rpc_h, pid, rate, (int*)channel, (int*)audio_type);
734         if (RPC_PORT_ERROR_NONE != ret) {
735                 SLOG(LOG_ERROR, TAG_VCC, ">>>> Request vc get tts audio format: Fail to invoke message. err(%d)", ret);
736                 return __covert_unhandled_error(ret);
737         }
738
739         SLOG(LOG_DEBUG, TAG_VCC, "@@ vc get tts audio format : pid(%d), rate(%d), channel(%d), audio_type(%d)", pid, *rate, *channel, *audio_type);
740
741         return VC_ERROR_NONE;
742 }