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