Update version to 1.70.7
[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_METHOD_SET_SERVICE_STATE, method, strlen(VCD_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_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         __vc_widget_cb_error(VC_ERROR_SERVICE_RESET, -1, "Server Disconnected");
163 }
164
165 static void __on_rejected(rpc_port_proxy_vc_widget_proxy_vc_widget_h h, void *user_data)
166 {
167         g_proxy_tidl_info->connection_requesting = false;
168         g_proxy_tidl_info->register_callback_invoked = false;
169
170         SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Rejected from server");
171 }
172
173
174 static rpc_port_proxy_vc_widget_proxy_vc_widget_h __create_rpc_port(const char* engine_app_id)
175 {
176         SLOG(LOG_DEBUG, TAG_VCW, "[TIDL] __create_rpc_port");
177         rpc_port_proxy_vc_widget_proxy_vc_widget_callback_s rpc_callback = {
178                 .connected = __on_connected,
179                 .disconnected = __on_disconnected,
180                 .rejected = __on_rejected
181         };
182
183         rpc_port_proxy_vc_widget_proxy_vc_widget_h handle = NULL;
184         if (0 != rpc_port_proxy_vc_widget_proxy_vc_widget_create(engine_app_id, &rpc_callback, NULL, &handle)) {
185                 SLOG(LOG_ERROR, TAG_VCW, "[TIDL ERROR] Fail to create proxy");
186                 return NULL;
187         }
188
189         return handle;
190 }
191
192 static void __vcd_widget_create_cb(rpc_port_stub_vc_widget_stub_vcd_widget_context_h context, void *user_data)
193 {
194         g_stub_tidl_info->connected = true;
195         g_stub_tidl_info->register_callback_requesting = false;
196
197         SLOG(LOG_DEBUG, TAG_VCW, "Connected to server");
198
199         char *sender = NULL;
200
201         rpc_port_stub_vc_widget_stub_vcd_widget_context_get_sender(context, &sender);
202         if (!sender) {
203                 SLOG(LOG_ERROR, TAG_VCW, "@@@ Sender is NULL");
204                 return;
205         }
206
207         SLOG(LOG_DEBUG, TAG_VCW, "@@@ Server connect. appid(%s)", sender);
208         free(sender);
209 }
210
211 static void __vcd_widget_terminate_cb(rpc_port_stub_vc_widget_stub_vcd_widget_context_h context, void *user_data)
212 {
213         g_stub_tidl_info->connected = false;
214         g_stub_tidl_info->register_callback_requesting = false;
215
216         rpc_port_stub_vc_widget_stub_vcd_widget_context_set_tag(context, NULL);
217
218         char *sender = NULL;
219         rpc_port_stub_vc_widget_stub_vcd_widget_context_get_sender(context, &sender);
220         if (!sender)
221                 return;
222
223         SLOG(LOG_INFO, TAG_VCW, "@@@ Server disconnect. appid(%s)", sender);
224         free(sender);
225 }
226
227 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)
228 {
229         SLOG(LOG_DEBUG, TAG_VCW, "@@@ Get widget asr result");
230
231         bool result = false;
232         result = __vc_widget_cb_asr_result(event, asr_result);
233         *is_consumed = result;
234
235         return VC_ERROR_NONE;
236 }
237
238 static void __register_stub_callback()
239 {
240         if (g_stub_tidl_info->register_callback_requesting) {
241                 return;
242         }
243
244         SLOG(LOG_DEBUG, TAG_VCW, "[TIDL] __register_stub_callback");
245
246         g_widget_callback.create = __vcd_widget_create_cb;
247         g_widget_callback.terminate = __vcd_widget_terminate_cb;
248         g_widget_callback.send_asr_result = __vcd_widget_asr_result_cb;
249
250         int ret = -1;
251         ret = rpc_port_stub_vc_widget_stub_vcd_widget_register(&g_widget_callback, NULL);
252         if (0 == ret) {
253                 SLOG(LOG_DEBUG, TAG_VCW, "register callback");
254                 g_stub_tidl_info->register_callback_requesting = true;
255                 return;
256         }
257
258         SLOG(LOG_ERROR, TAG_VCW, "Fail to rister callback(%d)", ret);
259         return;
260 }
261
262 int vc_widget_tidl_open_connection()
263 {
264         SLOG(LOG_DEBUG, TAG_VCW, "[TIDL] vc_widget_tidl_open_connection");
265         pthread_mutex_lock(&g_w_tidl_mutex);
266
267         if (NULL != g_proxy_tidl_info) {
268                 SLOG(LOG_ERROR, TAG_VCW, "[TIDL ERROR] g_proxy_tidl_info already created");
269                 pthread_mutex_unlock(&g_w_tidl_mutex);
270                 return VC_ERROR_NONE;
271         }
272
273         g_proxy_tidl_info = (vc_widget_tidl_info_s*)calloc(1, sizeof(vc_widget_tidl_info_s));
274
275         if (NULL == g_proxy_tidl_info) {
276                 SLOG(LOG_ERROR, TAG_VCW, "[TIDL ERROR] Fail to create vc_widget_tidl_info_s");
277                 pthread_mutex_unlock(&g_w_tidl_mutex);
278                 return VC_ERROR_OUT_OF_MEMORY;
279         }
280
281         char* engine_app_id = vconf_get_str(VC_ENGINE_DB_DEFAULT);
282         if (NULL == engine_app_id) {
283                 SLOG(LOG_ERROR, TAG_VCW, "[TIDL] vconf not found");
284                 free(g_proxy_tidl_info);
285                 g_proxy_tidl_info = NULL;
286                 pthread_mutex_unlock(&g_w_tidl_mutex);
287                 return VC_ERROR_ENGINE_NOT_FOUND;
288         }
289
290         g_proxy_tidl_info->rpc_h = __create_rpc_port(engine_app_id);
291         if (NULL == g_proxy_tidl_info->rpc_h) {
292                 SLOG(LOG_ERROR, TAG_VCW, "[TIDL ERROR] Fail to create proxy");
293                 free(engine_app_id);
294                 free(g_proxy_tidl_info);
295                 g_proxy_tidl_info = NULL;
296                 pthread_mutex_unlock(&g_w_tidl_mutex);
297                 return VC_ERROR_OPERATION_FAILED;
298         }
299
300         SLOG(LOG_INFO, TAG_VCW, "[TIDL] rpc_h(%p), engine_app_id(%s)", g_proxy_tidl_info->rpc_h, engine_app_id);
301         free(engine_app_id);
302
303         g_stub_tidl_info = (vcd_widget_tidl_info_s*)calloc(1, sizeof(vcd_widget_tidl_info_s));
304
305         if (NULL == g_stub_tidl_info) {
306                 SLOG(LOG_ERROR, TAG_VCW, "[TIDL ERROR] Fail to create vcd_widget_tidl_info_s");
307                 pthread_mutex_unlock(&g_w_tidl_mutex);
308                 return VC_ERROR_OUT_OF_MEMORY;
309         }
310
311         __register_stub_callback();
312
313         pthread_mutex_unlock(&g_w_tidl_mutex);
314
315         return VC_ERROR_NONE;
316 }
317
318 int vc_widget_tidl_close_connection()
319 {
320         SLOG(LOG_DEBUG, TAG_VCW, "[TIDL] vc_widget_tidl_close_connection");
321         pthread_mutex_lock(&g_w_tidl_mutex);
322
323         if (NULL == g_proxy_tidl_info) {
324                 SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to get tidl info");
325                 pthread_mutex_unlock(&g_w_tidl_mutex);
326                 return VC_ERROR_OPERATION_FAILED;
327         }
328
329         if (0 != rpc_port_proxy_vc_widget_proxy_vc_widget_destroy(g_proxy_tidl_info->rpc_h)) {
330                 SLOG(LOG_ERROR, TAG_VCW, "[TIDL ERROR] Fail to destroy tidl handle");
331                 pthread_mutex_unlock(&g_w_tidl_mutex);
332                 return VC_ERROR_OPERATION_FAILED;
333         }
334
335         g_proxy_tidl_info->rpc_h = NULL;
336         g_proxy_tidl_info->notify_cb_h = NULL;
337
338         free(g_proxy_tidl_info);
339         g_proxy_tidl_info = NULL;
340
341         free(g_stub_tidl_info);
342         g_stub_tidl_info = NULL;
343
344         pthread_mutex_unlock(&g_w_tidl_mutex);
345
346         return VC_ERROR_NONE;
347 }
348
349 static int __convert_unhandled_error(int ret)
350 {
351         if (RPC_PORT_ERROR_IO_ERROR == ret || RPC_PORT_ERROR_OUT_OF_MEMORY == ret) {
352                 return VC_ERROR_OPERATION_FAILED;
353         }
354
355         return ret;
356 }
357
358 static void __request_tidl_connect()
359 {
360         if (g_proxy_tidl_info->connection_requesting) {
361                 return;
362         }
363
364         int ret = rpc_port_proxy_vc_widget_proxy_vc_widget_connect(g_proxy_tidl_info->rpc_h);
365         SLOG(LOG_INFO, TAG_VCW, "[INFO] Request connection to stub. ret(%d)", ret);
366
367         if (0 == ret) {
368                 g_proxy_tidl_info->connection_requesting = true;
369         }
370 }
371
372 static int __create_callback_handles()
373 {
374         if (NULL != g_proxy_tidl_info->notify_cb_h) {
375                 rpc_port_proxy_vc_widget_proxy_vc_widget_notify_cb_dispose(g_proxy_tidl_info->rpc_h, g_proxy_tidl_info->notify_cb_h);
376                 g_proxy_tidl_info->notify_cb_h = NULL;
377         }
378
379         if (RPC_PORT_ERROR_NONE != rpc_port_proxy_vc_widget_proxy_vc_widget_notify_cb_create(&g_proxy_tidl_info->notify_cb_h)) {
380                 return VC_ERROR_OUT_OF_MEMORY;
381         }
382
383         rpc_port_proxy_vc_widget_proxy_vc_widget_notify_cb_set_callback(g_proxy_tidl_info->notify_cb_h, __notify_cb, NULL);
384
385         rpc_port_proxy_vc_widget_proxy_vc_widget_notify_cb_set_once(g_proxy_tidl_info->notify_cb_h, false);
386
387         return VC_ERROR_NONE;
388 }
389
390 static int __invoke_register_callback()
391 {
392         if (g_proxy_tidl_info->register_callback_invoked) {
393                 SLOG(LOG_ERROR, TAG_VCW, "[INFO] Already register callback is invoked");
394                 return VC_ERROR_NONE;
395         }
396
397         int ret = __create_callback_handles(g_proxy_tidl_info);
398         if (VC_ERROR_NONE != ret) {
399                 SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to create callback handle. ret(%d)", ret);
400                 return VC_ERROR_OPERATION_FAILED;
401         }
402
403         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);
404         g_proxy_tidl_info->register_callback_invoked = true;
405         return VC_ERROR_NONE;
406 }
407
408 int vc_widget_tidl_request_hello()
409 {
410         SLOG(LOG_DEBUG, TAG_VCW, "[TIDL] vc_widget_tidl_request_hello");
411
412         if (NULL == g_proxy_tidl_info) {
413                 SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to get proxy tidl info");
414                 return VC_ERROR_OPERATION_FAILED;
415         }
416
417         if (!g_proxy_tidl_info->connected) {
418                 SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Proxy Not Connected");
419                 __request_tidl_connect();
420                 return VC_ERROR_OPERATION_FAILED;
421         }
422
423         if (VC_ERROR_NONE != __invoke_register_callback()) {
424                 SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to invoke register callback");
425                 return VC_ERROR_OPERATION_FAILED;
426         }
427
428         if (NULL == g_stub_tidl_info) {
429                 SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to get stub tidl info");
430                 return VC_ERROR_OPERATION_FAILED;
431         }
432
433         if (!g_stub_tidl_info->connected) {
434                 SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Stub Not Connected");
435                 __register_stub_callback();
436                 return VC_ERROR_OPERATION_FAILED;
437         }
438
439         SLOG(LOG_DEBUG, TAG_VCW, ">>>>> VCW Hello");
440
441         SLOG(LOG_DEBUG, TAG_VCW, "<<<<");
442
443         return VC_ERROR_NONE;
444 }
445
446 int vc_widget_tidl_request_initialize(int pid, int* service_state, int* daemon_pid)
447 {
448         pthread_mutex_lock(&g_w_init_mutex);
449         SLOG(LOG_DEBUG, TAG_VCW, "[TIDL] vc_widget_tidl_request_initialize");
450
451         if (NULL == g_proxy_tidl_info) {
452                 SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to get tidl info");
453                 pthread_mutex_unlock(&g_w_init_mutex);
454                 return VC_ERROR_OPERATION_FAILED;
455         }
456
457         int temp_service_state = 0;
458         int temp_daemon_pid = 0;
459         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);
460         int exception = get_last_result();
461         if (RPC_PORT_ERROR_NONE != exception) {
462                 ret = __convert_unhandled_error(exception);
463         }
464
465         if (VC_ERROR_NONE != ret) {
466                 SLOG(LOG_ERROR, TAG_VCW, "[TIDL ERROR] Request vc widget initialize : Fail to invoke message, error(%d)", ret);
467                 pthread_mutex_unlock(&g_w_init_mutex);
468                 return ret;
469         }
470
471         *service_state = temp_service_state;
472         *daemon_pid = temp_daemon_pid;
473
474         pthread_mutex_unlock(&g_w_init_mutex);
475         SLOG(LOG_DEBUG, TAG_VCW, "[TIDL] vc widget initialize: service_state(%d), daemon_pid(%d)", *service_state, *daemon_pid);
476
477         return VC_ERROR_NONE;
478 }
479
480 int vc_widget_tidl_request_finalize(int pid)
481 {
482         pthread_mutex_lock(&g_w_init_mutex);
483         SLOG(LOG_DEBUG, TAG_VCW, "[TIDL] vc_widget_tidl_request_finalize");
484
485         if (NULL == g_proxy_tidl_info) {
486                 SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to get tidl info");
487                 pthread_mutex_unlock(&g_w_init_mutex);
488                 return VC_ERROR_OPERATION_FAILED;
489         }
490
491         if (!g_proxy_tidl_info->connected) {
492                 SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Not Connected");
493                 pthread_mutex_unlock(&g_w_init_mutex);
494                 return VC_ERROR_OPERATION_FAILED;
495         }
496
497         int ret = rpc_port_proxy_vc_widget_proxy_vc_widget_invoke_finalize(g_proxy_tidl_info->rpc_h, pid);
498         int exception = get_last_result();
499         if (RPC_PORT_ERROR_NONE != exception) {
500                 ret = __convert_unhandled_error(exception);
501         }
502
503         if (VC_ERROR_NONE != ret) {
504                 SLOG(LOG_ERROR, TAG_VCW, "[TIDL ERROR] Request vc widget finalize : Fail to invoke finalize, error(%d)", ret);
505                 pthread_mutex_unlock(&g_w_init_mutex);
506                 return ret;
507         }
508
509         ret = rpc_port_proxy_vc_widget_proxy_vc_widget_disconnect(g_proxy_tidl_info->rpc_h);
510         exception = get_last_result();
511         if (RPC_PORT_ERROR_NONE != exception) {
512                 ret = __convert_unhandled_error(exception);
513         }
514
515         if (VC_ERROR_NONE != ret) {
516                 SLOG(LOG_ERROR, TAG_VCW, "[TIDL ERROR] Request vc widget finalize : Fail to disconnect, error(%d)", ret);
517                 pthread_mutex_unlock(&g_w_init_mutex);
518                 return ret;
519         }
520
521         pthread_mutex_unlock(&g_w_init_mutex);
522         return VC_ERROR_NONE;
523 }
524
525 int vc_widget_tidl_request_start_recording(int pid, bool command)
526 {
527         SLOG(LOG_DEBUG, TAG_VCW, "[TIDL] vc_widget_tidl_request_start_recording");
528
529         if (NULL == g_proxy_tidl_info) {
530                 SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to get tidl info");
531                 return VC_ERROR_OPERATION_FAILED;
532         }
533
534         if (!g_proxy_tidl_info->connected) {
535                 SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Not Connected");
536                 return VC_ERROR_OPERATION_FAILED;
537         }
538
539         int ret = rpc_port_proxy_vc_widget_proxy_vc_widget_invoke_start_recording(g_proxy_tidl_info->rpc_h, pid, (int)command);
540         int exception = get_last_result();
541         if (RPC_PORT_ERROR_NONE != exception) {
542                 ret = __convert_unhandled_error(exception);
543         }
544
545         if (VC_ERROR_NONE != ret) {
546                 SLOG(LOG_ERROR, TAG_VCW, "[TIDL ERROR] Request vc widget start recording : Fail to invoke message, error(%d)", ret);
547                 return ret;
548         }
549
550         return VC_ERROR_NONE;
551 }
552
553 int vc_widget_tidl_set_foreground(int pid, bool value)
554 {
555         SLOG(LOG_DEBUG, TAG_VCW, "[TIDL] vc_widget_tidl_set_foreground");
556
557         if (NULL == g_proxy_tidl_info) {
558                 SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to get tidl info");
559                 return VC_ERROR_OPERATION_FAILED;
560         }
561
562         if (!g_proxy_tidl_info->connected) {
563                 SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Not Connected");
564                 return VC_ERROR_OPERATION_FAILED;
565         }
566
567         // TODO: Error tolerance cannot be applied because this function is asynchronous.
568         rpc_port_proxy_vc_widget_proxy_vc_widget_invoke_set_foreground(g_proxy_tidl_info->rpc_h, pid, (int)value);
569
570         return VC_ERROR_NONE;
571 }
572
573 int vc_widget_tidl_request_enable_asr_result(int pid, bool enable)
574 {
575         SLOG(LOG_DEBUG, TAG_VCW, "[TIDL] vc_widget_tidl_request_enable_asr_result");
576
577         if (NULL == g_proxy_tidl_info) {
578                 SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to get tidl info");
579                 return VC_ERROR_OPERATION_FAILED;
580         }
581
582         if (!g_proxy_tidl_info->connected) {
583                 SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Not Connected");
584                 return VC_ERROR_OPERATION_FAILED;
585         }
586
587         int ret = rpc_port_proxy_vc_widget_proxy_vc_widget_invoke_enable_asr_result(g_proxy_tidl_info->rpc_h, pid, (int)enable);
588         int exception = get_last_result();
589         if (RPC_PORT_ERROR_NONE != exception) {
590                 ret = __convert_unhandled_error(exception);
591         }
592
593         if (VC_ERROR_NONE != ret) {
594                 SLOG(LOG_ERROR, TAG_VCW, "[TIDL ERROR] Request vc widget enable asr result : Fail to invoke message, error(%d)", ret);
595                 return ret;
596         }
597
598         return VC_ERROR_NONE;
599 }
600
601 int vc_widget_tidl_request_start(int pid, int silence)
602 {
603         SLOG(LOG_DEBUG, TAG_VCW, "[TIDL] vc_widget_tidl_request_start");
604
605         if (NULL == g_proxy_tidl_info) {
606                 SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to get tidl info");
607                 return VC_ERROR_OPERATION_FAILED;
608         }
609
610         if (!g_proxy_tidl_info->connected) {
611                 SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Not Connected");
612                 return VC_ERROR_OPERATION_FAILED;
613         }
614
615         int ret = rpc_port_proxy_vc_widget_proxy_vc_widget_invoke_start(g_proxy_tidl_info->rpc_h, pid, silence);
616         int exception = get_last_result();
617         if (RPC_PORT_ERROR_NONE != exception) {
618                 ret = __convert_unhandled_error(exception);
619         }
620
621         if (VC_ERROR_NONE != ret) {
622                 SLOG(LOG_ERROR, TAG_VCW, "[TIDL ERROR] Request vc widget start : Fail to invoke message, error(%d)", ret);
623                 return ret;
624         }
625
626         return VC_ERROR_NONE;
627 }
628
629 int vc_widget_tidl_request_stop(int pid)
630 {
631         SLOG(LOG_DEBUG, TAG_VCW, "[TIDL] vc_widget_tidl_request_stop");
632
633         if (NULL == g_proxy_tidl_info) {
634                 SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to get tidl info");
635                 return VC_ERROR_OPERATION_FAILED;
636         }
637
638         if (!g_proxy_tidl_info->connected) {
639                 SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Not Connected");
640                 return VC_ERROR_OPERATION_FAILED;
641         }
642
643         int ret = rpc_port_proxy_vc_widget_proxy_vc_widget_invoke_stop(g_proxy_tidl_info->rpc_h, pid);
644         int exception = get_last_result();
645         if (RPC_PORT_ERROR_NONE != exception) {
646                 ret = __convert_unhandled_error(exception);
647         }
648
649         if (VC_ERROR_NONE != ret) {
650                 SLOG(LOG_ERROR, TAG_VCW, "[TIDL ERROR] Request vc widget stop : Fail to invoke message, error(%d)", ret);
651                 return ret;
652         }
653
654         return VC_ERROR_NONE;
655 }
656
657 int vc_widget_tidl_request_cancel(int pid)
658 {
659         SLOG(LOG_DEBUG, TAG_VCW, "[TIDL] vc_widget_tidl_request_cancel");
660
661         if (NULL == g_proxy_tidl_info) {
662                 SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to get tidl info");
663                 return VC_ERROR_OPERATION_FAILED;
664         }
665
666         if (!g_proxy_tidl_info->connected) {
667                 SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Not Connected");
668                 return VC_ERROR_OPERATION_FAILED;
669         }
670
671         int ret = rpc_port_proxy_vc_widget_proxy_vc_widget_invoke_cancel(g_proxy_tidl_info->rpc_h, pid);
672         int exception = get_last_result();
673         if (RPC_PORT_ERROR_NONE != exception) {
674                 ret = __convert_unhandled_error(exception);
675         }
676
677         if (VC_ERROR_NONE != ret) {
678                 SLOG(LOG_ERROR, TAG_VCW, "[TIDL ERROR] Request vc widget cancel : Fail to invoke message, error(%d)", ret);
679                 return ret;
680         }
681
682         return VC_ERROR_NONE;
683 }