Remove unnecessary logs
[platform/core/uifw/voice-control.git] / client / vc_widget_tidl.c
1 /*
2 * Copyright (c) 2022 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 <pthread.h>
18 #include <rpc-port.h>
19
20 #include "vc_main.h"
21 #include "vc_widget_client.h"
22 #include "vc_widget_tidl.h"
23 #include "vc_widget_proxy.h"
24 #include "vc_widget_stub.h"
25
26 typedef struct {
27         bool connected;
28         bool connection_requesting;
29         bool register_callback_invoked;
30         rpc_port_proxy_vc_widget_proxy_vc_widget_h rpc_h;
31         rpc_port_proxy_vc_widget_proxy_vc_widget_notify_cb_h notify_cb_h;
32 } vc_widget_tidl_info_s;
33
34 typedef struct {
35         bool connected;
36         bool register_callback_requesting;
37 } vcd_widget_tidl_info_s;
38
39 static vc_widget_tidl_info_s* g_proxy_tidl_info = NULL;
40
41 static vcd_widget_tidl_info_s* g_stub_tidl_info = NULL;
42
43 static pthread_mutex_t g_w_tidl_mutex = PTHREAD_MUTEX_INITIALIZER;
44 static pthread_mutex_t g_w_init_mutex = PTHREAD_MUTEX_INITIALIZER;
45
46 static rpc_port_stub_vc_widget_stub_vcd_widget_callback_s g_widget_callback;
47
48 extern int __vc_widget_cb_error(int reason, int daemon_pid, char* msg);
49
50 extern void __vc_widget_cb_show_tooltip(int pid, bool show);
51
52 extern void __vc_widget_cb_result();
53
54 extern bool __vc_widget_cb_asr_result(int event, const char* asr_result);
55
56 extern int __vc_widget_cb_service_state(int state);
57
58 static void __notify_cb(void *user_data, bundle *msg)
59 {
60         char* method = NULL;
61         char* val = NULL;
62         SLOG(LOG_DEBUG, TAG_VCW, "__notify_cb is invoked");
63
64         bundle_get_str(msg, VC_BUNDLE_METHOD, &method);
65
66         if (0 == strncmp(VCD_WIDGET_METHOD_HELLO, method, strlen(VCD_WIDGET_METHOD_HELLO))) {
67                 SLOG(LOG_INFO, TAG_VCW, "@@@ Get widget hello");
68                 bundle_get_str(msg, VC_BUNDLE_PID, &val);
69                 if (val) {
70                         SLOG(LOG_DEBUG, TAG_VCW, "@@ vc widget get hello : pid(%d) ", atoi(val));
71                 } else {
72                         SLOG(LOG_ERROR, TAG_VCW, "@@ vc widget get hello : invalid pid ");
73                 }
74         } /* VCD_METHOD_HELLO */
75
76         else if (0 == strncmp(VCD_WIDGET_METHOD_SET_SERVICE_STATE, method, strlen(VCD_WIDGET_METHOD_SET_SERVICE_STATE))) {
77                 bundle_get_str(msg, VC_BUNDLE_SERVICE_STATE, &val);
78                 int state = 0;
79                 if (val) {
80                         state = atoi(val);
81                         SLOG(LOG_INFO, TAG_VCW, "@@ service state changed : %d", state);
82                         __vc_widget_cb_service_state(state);
83                 }
84         } /* VCD_WIDGET_METHOD_SET_SERVICE_STATE */
85
86         else if (0 == strncmp(VCD_WIDGET_METHOD_SHOW_TOOLTIP, method, strlen(VCD_WIDGET_METHOD_SHOW_TOOLTIP))) {
87                 SLOG(LOG_DEBUG, TAG_VCW, "@@@ Show / Hide tooltip");
88                 char* temp_show = NULL;
89                 bundle_get_str(msg, VC_BUNDLE_PID, &val);
90                 bundle_get_str(msg, VC_BUNDLE_SHOW, &temp_show);
91                 int pid = 0;
92                 int show = 0;
93
94                 if (val) {
95                         pid = atoi(val);
96                 }
97                 if (temp_show) {
98                         show = atoi(temp_show);
99                 }
100
101                 if(pid > 0){
102                         SLOG(LOG_DEBUG, TAG_VCW, "@@ vc widget show tooltip : pid(%d), show(%d)", pid, show);
103                         __vc_widget_cb_show_tooltip(pid, (bool)show);
104                 } else {
105                         SLOG(LOG_ERROR, TAG_VCW, "@@ vc widget show tooltip : invalid pid");
106                 }
107         } /* VCD_WIDGET_METHOD_SHOW_TOOLTIP */
108
109         else if (0 == strncmp(VCD_WIDGET_METHOD_RESULT, method, strlen(VCD_WIDGET_METHOD_RESULT))) {
110                 SLOG(LOG_DEBUG, TAG_VCW, "@@@ Get widget result");
111
112                 __vc_widget_cb_result();
113         } /* VCD_WIDGET_METHOD_RESULT */
114
115         else if (0 == strncmp(VCD_WIDGET_METHOD_ERROR, method, strlen(VCD_WIDGET_METHOD_ERROR))) {
116                 SLOG(LOG_INFO, TAG_VCW, "@@@ Get Pre Result");
117                 char* temp_reason = NULL;
118                 char* temp_daemon_pid = NULL;
119                 char* err_msg = NULL;
120
121                 bundle_get_str(msg, VC_BUNDLE_REASON, &temp_reason);
122                 bundle_get_str(msg, VC_BUNDLE_DAEMON_PID, &temp_daemon_pid);
123                 bundle_get_str(msg, VC_BUNDLE_ERR_MSG, &err_msg);
124                 int reason = 0;
125                 int daemon_pid = 0;
126
127                 if (NULL != temp_reason) {
128                         reason = atoi(temp_reason);
129                 }
130                 if (NULL != temp_daemon_pid) {
131                         daemon_pid = atoi(temp_daemon_pid);
132                 }
133
134                 SLOG(LOG_DEBUG, TAG_VCW, "@@ vc widget get error message : reason(%d), daemon_pid(%d), msg(%s)", reason, daemon_pid, err_msg);
135                 __vc_widget_cb_error(reason, daemon_pid, err_msg);
136         } /* VCD_WIDGET_METHOD_ERROR */
137
138         else {
139                 SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Invalid msg");
140         }
141
142         SLOG(LOG_DEBUG, TAG_VCW, "@@@ __notify_cb DONE");
143 }
144
145 static void __on_connected(rpc_port_proxy_vc_widget_proxy_vc_widget_h h, void *user_data)
146 {
147         g_proxy_tidl_info->connected = true;
148         g_proxy_tidl_info->connection_requesting = false;
149         g_proxy_tidl_info->register_callback_invoked = false;
150
151         SLOG(LOG_INFO, TAG_VCW, "Connected to server");
152 }
153
154 static void __on_disconnected(rpc_port_proxy_vc_widget_proxy_vc_widget_h h, void *user_data)
155 {
156         g_proxy_tidl_info->connected = false;
157         g_proxy_tidl_info->connection_requesting = false;
158         g_proxy_tidl_info->register_callback_invoked = false;
159
160         SLOG(LOG_INFO, TAG_VCW, "Disonnected to server");
161
162         SLOG(LOG_INFO, TAG_VCW, "Re-connection start");
163         __vc_widget_cb_error(VC_ERROR_SERVICE_RESET, -1, "Server Disconnected, re-launch");
164 }
165
166 static void __on_rejected(rpc_port_proxy_vc_widget_proxy_vc_widget_h h, void *user_data)
167 {
168         g_proxy_tidl_info->connection_requesting = false;
169         g_proxy_tidl_info->register_callback_invoked = false;
170
171         SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Rejected from server");
172 }
173
174
175 static rpc_port_proxy_vc_widget_proxy_vc_widget_h __create_rpc_port(const char* engine_app_id)
176 {
177         SLOG(LOG_DEBUG, TAG_VCW, "[TIDL] __create_rpc_port");
178         rpc_port_proxy_vc_widget_proxy_vc_widget_callback_s rpc_callback = {
179                 .connected = __on_connected,
180                 .disconnected = __on_disconnected,
181                 .rejected = __on_rejected
182         };
183
184         rpc_port_proxy_vc_widget_proxy_vc_widget_h handle = NULL;
185         if (0 != rpc_port_proxy_vc_widget_proxy_vc_widget_create(engine_app_id, &rpc_callback, NULL, &handle)) {
186                 SLOG(LOG_ERROR, TAG_VCW, "[TIDL ERROR] Fail to create proxy");
187                 return NULL;
188         }
189
190         return handle;
191 }
192
193 static void __vcd_widget_create_cb(rpc_port_stub_vc_widget_stub_vcd_widget_context_h context, void *user_data)
194 {
195         g_stub_tidl_info->connected = true;
196         g_stub_tidl_info->register_callback_requesting = false;
197
198         SLOG(LOG_DEBUG, TAG_VCW, "Connected to server");
199
200         char *sender = NULL;
201
202         rpc_port_stub_vc_widget_stub_vcd_widget_context_get_sender(context, &sender);
203         if (!sender) {
204                 SLOG(LOG_ERROR, TAG_VCW, "@@@ Sender is NULL");
205                 return;
206         }
207
208         SLOG(LOG_DEBUG, TAG_VCW, "@@@ Server connect. appid(%s)", sender);
209         free(sender);
210 }
211
212 static void __vcd_widget_terminate_cb(rpc_port_stub_vc_widget_stub_vcd_widget_context_h context, void *user_data)
213 {
214         g_stub_tidl_info->connected = false;
215         g_stub_tidl_info->register_callback_requesting = false;
216
217         rpc_port_stub_vc_widget_stub_vcd_widget_context_set_tag(context, NULL);
218
219         char *sender = NULL;
220         rpc_port_stub_vc_widget_stub_vcd_widget_context_get_sender(context, &sender);
221         if (!sender)
222                 return;
223
224         SLOG(LOG_INFO, TAG_VCW, "@@@ Server disconnect. appid(%s)", sender);
225         free(sender);
226 }
227
228 static int __vcd_widget_asr_result_cb(rpc_port_stub_vc_widget_stub_vcd_widget_context_h context, int pid, int event, const char *asr_result, bool *is_consumed, void *user_data)
229 {
230         SLOG(LOG_DEBUG, TAG_VCW, "@@@ Get widget asr result");
231
232         bool result = false;
233         result = __vc_widget_cb_asr_result(event, asr_result);
234         *is_consumed = result;
235
236         return VC_ERROR_NONE;
237 }
238
239 static void __register_stub_callback()
240 {
241         if (g_stub_tidl_info->register_callback_requesting) {
242                 return;
243         }
244
245         SLOG(LOG_DEBUG, TAG_VCW, "[TIDL] __register_stub_callback");
246
247         g_widget_callback.create = __vcd_widget_create_cb;
248         g_widget_callback.terminate = __vcd_widget_terminate_cb;
249         g_widget_callback.send_asr_result = __vcd_widget_asr_result_cb;
250
251         int ret = -1;
252         ret = rpc_port_stub_vc_widget_stub_vcd_widget_register(&g_widget_callback, NULL);
253         if (0 == ret) {
254                 SLOG(LOG_DEBUG, TAG_VCW, "register callback");
255                 g_stub_tidl_info->register_callback_requesting = true;
256                 return;
257         }
258
259         SLOG(LOG_ERROR, TAG_VCW, "Fail to rister callback(%d)", ret);
260         return;
261 }
262
263 int vc_widget_tidl_open_connection()
264 {
265         SLOG(LOG_DEBUG, TAG_VCW, "[TIDL] vc_widget_tidl_open_connection");
266         pthread_mutex_lock(&g_w_tidl_mutex);
267
268         if (NULL != g_proxy_tidl_info) {
269                 SLOG(LOG_ERROR, TAG_VCW, "[TIDL ERROR] g_proxy_tidl_info already created");
270                 pthread_mutex_unlock(&g_w_tidl_mutex);
271                 return VC_ERROR_NONE;
272         }
273
274         g_proxy_tidl_info = (vc_widget_tidl_info_s*)calloc(1, sizeof(vc_widget_tidl_info_s));
275
276         if (NULL == g_proxy_tidl_info) {
277                 SLOG(LOG_ERROR, TAG_VCW, "[TIDL ERROR] Fail to create vc_widget_tidl_info_s");
278                 pthread_mutex_unlock(&g_w_tidl_mutex);
279                 return VC_ERROR_OUT_OF_MEMORY;
280         }
281
282         char* engine_app_id = vconf_get_str(VC_ENGINE_DB_DEFAULT);
283         if (NULL == engine_app_id) {
284                 SLOG(LOG_ERROR, TAG_VCW, "[TIDL] vconf not found");
285                 free(g_proxy_tidl_info);
286                 g_proxy_tidl_info = NULL;
287                 pthread_mutex_unlock(&g_w_tidl_mutex);
288                 return VC_ERROR_ENGINE_NOT_FOUND;
289         }
290
291         g_proxy_tidl_info->rpc_h = __create_rpc_port(engine_app_id);
292         if (NULL == g_proxy_tidl_info->rpc_h) {
293                 SLOG(LOG_ERROR, TAG_VCW, "[TIDL ERROR] Fail to create proxy");
294                 free(engine_app_id);
295                 free(g_proxy_tidl_info);
296                 g_proxy_tidl_info = NULL;
297                 pthread_mutex_unlock(&g_w_tidl_mutex);
298                 return VC_ERROR_OPERATION_FAILED;
299         }
300
301         SLOG(LOG_INFO, TAG_VCW, "[TIDL] rpc_h(%p), engine_app_id(%s)", g_proxy_tidl_info->rpc_h, engine_app_id);
302         free(engine_app_id);
303
304         g_stub_tidl_info = (vcd_widget_tidl_info_s*)calloc(1, sizeof(vcd_widget_tidl_info_s));
305
306         if (NULL == g_stub_tidl_info) {
307                 SLOG(LOG_ERROR, TAG_VCW, "[TIDL ERROR] Fail to create vcd_widget_tidl_info_s");
308                 pthread_mutex_unlock(&g_w_tidl_mutex);
309                 return VC_ERROR_OUT_OF_MEMORY;
310         }
311
312         __register_stub_callback();
313
314         pthread_mutex_unlock(&g_w_tidl_mutex);
315
316         return VC_ERROR_NONE;
317 }
318
319 int vc_widget_tidl_close_connection()
320 {
321         SLOG(LOG_DEBUG, TAG_VCW, "[TIDL] vc_widget_tidl_close_connection");
322         pthread_mutex_lock(&g_w_tidl_mutex);
323
324         if (NULL == g_proxy_tidl_info) {
325                 SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to get tidl info");
326                 pthread_mutex_unlock(&g_w_tidl_mutex);
327                 return VC_ERROR_OPERATION_FAILED;
328         }
329
330         if (0 != rpc_port_proxy_vc_widget_proxy_vc_widget_destroy(g_proxy_tidl_info->rpc_h)) {
331                 SLOG(LOG_ERROR, TAG_VCW, "[TIDL ERROR] Fail to destroy tidl handle");
332                 pthread_mutex_unlock(&g_w_tidl_mutex);
333                 return VC_ERROR_OPERATION_FAILED;
334         }
335
336         g_proxy_tidl_info->rpc_h = NULL;
337         g_proxy_tidl_info->notify_cb_h = NULL;
338
339         free(g_proxy_tidl_info);
340         g_proxy_tidl_info = NULL;
341
342         free(g_stub_tidl_info);
343         g_stub_tidl_info = NULL;
344
345         pthread_mutex_unlock(&g_w_tidl_mutex);
346
347         return VC_ERROR_NONE;
348 }
349
350 static void __request_tidl_connect()
351 {
352         if (g_proxy_tidl_info->connection_requesting) {
353                 return;
354         }
355
356         int ret = rpc_port_proxy_vc_widget_proxy_vc_widget_connect(g_proxy_tidl_info->rpc_h);
357         SLOG(LOG_INFO, TAG_VCW, "[INFO] Request connection to stub. ret(%d)", ret);
358
359         if (0 == ret) {
360                 g_proxy_tidl_info->connection_requesting = true;
361         }
362 }
363
364 static int __create_callback_handles()
365 {
366         if (NULL != g_proxy_tidl_info->notify_cb_h) {
367                 rpc_port_proxy_vc_widget_proxy_vc_widget_notify_cb_dispose(g_proxy_tidl_info->rpc_h, g_proxy_tidl_info->notify_cb_h);
368                 g_proxy_tidl_info->notify_cb_h = NULL;
369         }
370
371         if (RPC_PORT_ERROR_NONE != rpc_port_proxy_vc_widget_proxy_vc_widget_notify_cb_create(&g_proxy_tidl_info->notify_cb_h)) {
372                 return VC_ERROR_OUT_OF_MEMORY;
373         }
374
375         rpc_port_proxy_vc_widget_proxy_vc_widget_notify_cb_set_callback(g_proxy_tidl_info->notify_cb_h, __notify_cb, NULL);
376
377         rpc_port_proxy_vc_widget_proxy_vc_widget_notify_cb_set_once(g_proxy_tidl_info->notify_cb_h, false);
378
379         return VC_ERROR_NONE;
380 }
381
382 static int __invoke_register_callback()
383 {
384         if (g_proxy_tidl_info->register_callback_invoked) {
385                 SLOG(LOG_ERROR, TAG_VCW, "[INFO] Already register callback is invoked");
386                 return VC_ERROR_NONE;
387         }
388
389         int ret = __create_callback_handles(g_proxy_tidl_info);
390         if (VC_ERROR_NONE != ret) {
391                 SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to create callback handle. ret(%d)", ret);
392                 return VC_ERROR_OPERATION_FAILED;
393         }
394
395         rpc_port_proxy_vc_widget_proxy_vc_widget_invoke_register_cb(g_proxy_tidl_info->rpc_h, getpid(), g_proxy_tidl_info->notify_cb_h);
396         g_proxy_tidl_info->register_callback_invoked = true;
397         return VC_ERROR_NONE;
398 }
399
400 int vc_widget_tidl_request_hello()
401 {
402         SLOG(LOG_DEBUG, TAG_VCW, "[TIDL] vc_widget_tidl_request_hello");
403
404         if (NULL == g_proxy_tidl_info) {
405                 SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to get proxy tidl info");
406                 return VC_ERROR_OPERATION_FAILED;
407         }
408
409         if (!g_proxy_tidl_info->connected) {
410                 SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Proxy Not Connected");
411                 __request_tidl_connect();
412                 return VC_ERROR_OPERATION_FAILED;
413         }
414
415         if (VC_ERROR_NONE != __invoke_register_callback()) {
416                 SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to invoke register callback");
417                 return VC_ERROR_OPERATION_FAILED;
418         }
419
420         if (NULL == g_stub_tidl_info) {
421                 SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to get stub tidl info");
422                 return VC_ERROR_OPERATION_FAILED;
423         }
424
425         if (!g_stub_tidl_info->connected) {
426                 SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Stub Not Connected");
427                 __register_stub_callback();
428                 return VC_ERROR_OPERATION_FAILED;
429         }
430
431         SLOG(LOG_DEBUG, TAG_VCW, ">>>>> VCW Hello");
432
433         SLOG(LOG_DEBUG, TAG_VCW, "<<<<");
434
435         return VC_ERROR_NONE;
436 }
437
438 int vc_widget_tidl_request_initialize(int pid, int* service_state, int* daemon_pid)
439 {
440         pthread_mutex_lock(&g_w_init_mutex);
441         SLOG(LOG_DEBUG, TAG_VCW, "[TIDL] vc_widget_tidl_request_initialize");
442
443         if (NULL == g_proxy_tidl_info) {
444                 SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to get tidl info");
445                 pthread_mutex_unlock(&g_w_init_mutex);
446                 return VC_ERROR_OPERATION_FAILED;
447         }
448
449         int temp_service_state = 0;
450         int temp_daemon_pid = 0;
451         int ret = rpc_port_proxy_vc_widget_proxy_vc_widget_invoke_initialize(g_proxy_tidl_info->rpc_h, pid, &temp_service_state, &temp_daemon_pid);
452         if (RPC_PORT_ERROR_NONE != ret) {
453                 SLOG(LOG_ERROR, TAG_VCW, "[TIDL ERROR] Request vc widget initialize : Fail to invoke message, error(%d)", ret);
454                 pthread_mutex_unlock(&g_w_init_mutex);
455                 return ret;
456         }
457
458         *service_state = temp_service_state;
459         *daemon_pid = temp_daemon_pid;
460
461         pthread_mutex_unlock(&g_w_init_mutex);
462         SLOG(LOG_DEBUG, TAG_VCW, "[TIDL] vc widget initialize: service_state(%d), daemon_pid(%d)", *service_state, *daemon_pid);
463
464         return VC_ERROR_NONE;
465 }
466
467 int vc_widget_tidl_request_finalize(int pid)
468 {
469         pthread_mutex_lock(&g_w_init_mutex);
470         SLOG(LOG_DEBUG, TAG_VCW, "[TIDL] vc_widget_tidl_request_finalize");
471
472         if (NULL == g_proxy_tidl_info) {
473                 SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to get tidl info");
474                 pthread_mutex_unlock(&g_w_init_mutex);
475                 return VC_ERROR_OPERATION_FAILED;
476         }
477
478         if (!g_proxy_tidl_info->connected) {
479                 SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Not Connected");
480                 pthread_mutex_unlock(&g_w_init_mutex);
481                 return VC_ERROR_OPERATION_FAILED;
482         }
483
484         int ret = rpc_port_proxy_vc_widget_proxy_vc_widget_invoke_finalize(g_proxy_tidl_info->rpc_h, pid);
485         if (RPC_PORT_ERROR_NONE != ret) {
486                 SLOG(LOG_ERROR, TAG_VCW, "[TIDL ERROR] Request vc widget finalize : Fail to invoke message, error(%d)", ret);
487                 pthread_mutex_unlock(&g_w_init_mutex);
488                 return ret;
489         }
490
491         pthread_mutex_unlock(&g_w_init_mutex);
492         return VC_ERROR_NONE;
493 }
494
495 int vc_widget_tidl_request_start_recording(int pid, bool command)
496 {
497         SLOG(LOG_DEBUG, TAG_VCW, "[TIDL] vc_widget_tidl_request_start_recording");
498
499         if (NULL == g_proxy_tidl_info) {
500                 SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to get tidl info");
501                 return VC_ERROR_OPERATION_FAILED;
502         }
503
504         if (!g_proxy_tidl_info->connected) {
505                 SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Not Connected");
506                 return VC_ERROR_OPERATION_FAILED;
507         }
508
509         int ret = rpc_port_proxy_vc_widget_proxy_vc_widget_invoke_start_recording(g_proxy_tidl_info->rpc_h, pid, (int)command);
510         if (RPC_PORT_ERROR_NONE != ret) {
511                 SLOG(LOG_ERROR, TAG_VCW, "[TIDL ERROR] Request vc widget start recording : Fail to invoke message, error(%d)", ret);
512                 return ret;
513         }
514
515         return VC_ERROR_NONE;
516 }
517
518 int vc_widget_tidl_set_foreground(int pid, bool value)
519 {
520         SLOG(LOG_DEBUG, TAG_VCW, "[TIDL] vc_widget_tidl_set_foreground");
521
522         if (NULL == g_proxy_tidl_info) {
523                 SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to get tidl info");
524                 return VC_ERROR_OPERATION_FAILED;
525         }
526
527         if (!g_proxy_tidl_info->connected) {
528                 SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Not Connected");
529                 return VC_ERROR_OPERATION_FAILED;
530         }
531
532         // TODO: Error tolerance cannot be applied because this function is asynchronous.
533         rpc_port_proxy_vc_widget_proxy_vc_widget_invoke_set_foreground(g_proxy_tidl_info->rpc_h, pid, (int)value);
534
535         return VC_ERROR_NONE;
536 }
537
538 int vc_widget_tidl_request_enable_asr_result(int pid, bool enable)
539 {
540         SLOG(LOG_DEBUG, TAG_VCW, "[TIDL] vc_widget_tidl_request_enable_asr_result");
541
542         if (NULL == g_proxy_tidl_info) {
543                 SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to get tidl info");
544                 return VC_ERROR_OPERATION_FAILED;
545         }
546
547         if (!g_proxy_tidl_info->connected) {
548                 SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Not Connected");
549                 return VC_ERROR_OPERATION_FAILED;
550         }
551
552         int ret = rpc_port_proxy_vc_widget_proxy_vc_widget_invoke_enable_asr_result(g_proxy_tidl_info->rpc_h, pid, (int)enable);
553         if (RPC_PORT_ERROR_NONE != ret) {
554                 SLOG(LOG_ERROR, TAG_VCW, "[TIDL ERROR] Request vc widget enable asr result : Fail to invoke message, error(%d)", ret);
555                 return ret;
556         }
557
558         return VC_ERROR_NONE;
559 }
560
561 int vc_widget_tidl_request_start(int pid, int silence)
562 {
563         SLOG(LOG_DEBUG, TAG_VCW, "[TIDL] vc_widget_tidl_request_start");
564
565         if (NULL == g_proxy_tidl_info) {
566                 SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to get tidl info");
567                 return VC_ERROR_OPERATION_FAILED;
568         }
569
570         if (!g_proxy_tidl_info->connected) {
571                 SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Not Connected");
572                 return VC_ERROR_OPERATION_FAILED;
573         }
574
575         int ret = rpc_port_proxy_vc_widget_proxy_vc_widget_invoke_start(g_proxy_tidl_info->rpc_h, pid, silence);
576         if (RPC_PORT_ERROR_NONE != ret) {
577                 SLOG(LOG_ERROR, TAG_VCW, "[TIDL ERROR] Request vc widget start : Fail to invoke message, error(%d)", ret);
578                 return ret;
579         }
580
581         return VC_ERROR_NONE;
582 }
583
584 int vc_widget_tidl_request_stop(int pid)
585 {
586         SLOG(LOG_DEBUG, TAG_VCW, "[TIDL] vc_widget_tidl_request_stop");
587
588         if (NULL == g_proxy_tidl_info) {
589                 SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to get tidl info");
590                 return VC_ERROR_OPERATION_FAILED;
591         }
592
593         if (!g_proxy_tidl_info->connected) {
594                 SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Not Connected");
595                 return VC_ERROR_OPERATION_FAILED;
596         }
597
598         int ret = rpc_port_proxy_vc_widget_proxy_vc_widget_invoke_stop(g_proxy_tidl_info->rpc_h, pid);
599         if (RPC_PORT_ERROR_NONE != ret) {
600                 SLOG(LOG_ERROR, TAG_VCW, "[TIDL ERROR] Request vc widget stop : Fail to invoke message, error(%d)", ret);
601                 return ret;
602         }
603
604         return VC_ERROR_NONE;
605 }
606
607 int vc_widget_tidl_request_cancel(int pid)
608 {
609         SLOG(LOG_DEBUG, TAG_VCW, "[TIDL] vc_widget_tidl_request_cancel");
610
611         if (NULL == g_proxy_tidl_info) {
612                 SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to get tidl info");
613                 return VC_ERROR_OPERATION_FAILED;
614         }
615
616         if (!g_proxy_tidl_info->connected) {
617                 SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Not Connected");
618                 return VC_ERROR_OPERATION_FAILED;
619         }
620
621         int ret = rpc_port_proxy_vc_widget_proxy_vc_widget_invoke_cancel(g_proxy_tidl_info->rpc_h, pid);
622         if (RPC_PORT_ERROR_NONE != ret) {
623                 SLOG(LOG_ERROR, TAG_VCW, "[TIDL ERROR] Request vc widget cancel : Fail to invoke message, error(%d)", ret);
624                 return ret;
625         }
626
627         return VC_ERROR_NONE;
628 }