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