ac18b4b0fe410a504ef3eed4ef52f7fa67debaef
[platform/core/uifw/voice-control.git] / server / vcd_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 <bundle.h>
18
19 #include "vcd_client_data.h"
20 #include "vcd_main.h"
21 #include "vcd_server.h"
22 #include "vcd_config.h"
23
24 #include "vcd_tidl.h"
25 #include "vcd_stub.h"
26 #include "vcd_setting_stub.h"
27 #include "vcd_mgr_stub.h"
28 #include "vcd_mgr_proxy.h"
29 #include "vcd_widget_stub.h"
30 #include "vcd_widget_proxy.h"
31
32 static rpc_port_stub_vcd_mgr_stub_vc_mgr_callback_s g_mgr_callback;
33
34 static pthread_mutex_t g_mgr_tidl_info_mutex = PTHREAD_MUTEX_INITIALIZER;
35
36 static rpc_port_stub_vcd_widget_stub_vc_widget_callback_s g_widget_callback;
37
38 static pthread_mutex_t g_widget_tidl_info_mutex = PTHREAD_MUTEX_INITIALIZER;
39
40 static rpc_port_stub_vcd_stub_vc_callback_s g_client_callback;
41
42 static pthread_mutex_t g_client_tidl_info_mutex = PTHREAD_MUTEX_INITIALIZER;
43
44 static rpc_port_stub_vcd_setting_stub_vc_setting_callback_s g_setting_callback;
45
46 static pthread_mutex_t g_setting_tidl_info_mutex = PTHREAD_MUTEX_INITIALIZER;
47
48 static int g_volume_count = 0;
49
50 extern int __client_tidl_open_connection();
51 extern int __client_tidl_close_connection();
52 extern int __mgr_tidl_open_connection();
53 extern int __mgr_tidl_close_connection();
54 extern int __widget_tidl_open_connection();
55 extern int __widget_tidl_close_connection();
56 extern int __setting_tidl_open_connection();
57 extern int __setting_tidl_close_connection();
58
59
60 /**
61  * For common request
62  */
63 static void __request_tidl_connect(vcd_client_type_e type, int pid)
64 {
65         char* type_str = NULL;
66         int ret = -1;
67
68         if (VCD_CLIENT_TYPE_MANAGER == type) {
69                 manager_tidl_info_s* mgr_tidl_info = vcd_client_manager_get_tidl_info();
70                 if (NULL == mgr_tidl_info) {
71                         SLOG(LOG_ERROR, TAG_VCD, "[TIDL] manager tidl info not allocated");
72                         return;
73                 }
74
75                 if (mgr_tidl_info->connection_requesting) {
76                         return;
77                 }
78
79                 ret = rpc_port_proxy_vcd_mgr_proxy_vcd_mgr_connect(mgr_tidl_info->rpc_h);
80
81                 if (0 == ret) {
82                         mgr_tidl_info->connection_requesting = true;
83                 }
84                 type_str = "manager";
85         // TODO: uncomment after client done
86         // } else if (VCD_CLIENT_TYPE_NORMAL == type) {
87         //      client_tidl_info_s* client_tidl_info = vcd_client_client_get_tidl_info(pid);
88         //      if (NULL == client_tidl_info) {
89         //              SLOG(LOG_ERROR, TAG_VCD, "[TIDL] client tidl info not allocated");
90         //              return;
91         //      }
92
93         //      if (client_tidl_info->connection_requesting) {
94         //              return;
95         //      }
96
97         //      ret = rpc_port_proxy_vcd_client_connect(client_tidl_info->rpc_h);
98
99         //      if (0 == ret) {
100         //      SLOG(LOG_ERROR, TAG_VCD, "[TIDL] tidl proxy info not allocated");
101         //              client_tidl_info->connection_requesting = true;
102         //      }
103         //      type_str = "client";
104         } else if (VCD_CLIENT_TYPE_WIDGET == type) {
105                 widget_tidl_info_s* widget_tidl_info = vcd_client_widget_get_tidl_info(pid);
106                 if (NULL == widget_tidl_info) {
107                         SLOG(LOG_ERROR, TAG_VCD, "[TIDL] widget tidl info not allocated");
108                         return;
109                 }
110
111                 if (widget_tidl_info->connection_requesting) {
112                         return;
113                 }
114
115                 ret = rpc_port_proxy_vcd_widget_proxy_vcd_widget_connect(widget_tidl_info->rpc_h);
116
117                 if (0 == ret) {
118                 SLOG(LOG_ERROR, TAG_VCD, "[TIDL] tidl proxy info not allocated");
119                         widget_tidl_info->connection_requesting = true;
120                 }
121                 type_str = "widget";
122         } else {
123                 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] client type is NOT valid(%d)", type);
124                 return;
125         }
126
127         if (RPC_PORT_ERROR_NONE != ret) {
128                 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Request connection to %s stub. ret(%d)", type_str, ret);
129         } else {
130                 SLOG(LOG_INFO, TAG_VCD, "[INFO] Request connection to %s stub. ret(%d)", type_str, ret);
131         }
132 }
133
134 void __send_msg_to_mgr(bundle* msg)
135 {
136         pthread_mutex_lock(&g_mgr_tidl_info_mutex);
137
138         SLOG(LOG_INFO, TAG_VCD, "[TIDL] message to manager");
139         manager_tidl_info_s* mgr_tidl_info = vcd_client_manager_get_tidl_info();
140         if (NULL == mgr_tidl_info) {
141                 SLOG(LOG_ERROR, TAG_VCD, "[TIDL] tidl proxy info not allocated");
142                 pthread_mutex_unlock(&g_mgr_tidl_info_mutex);
143                 return;
144         }
145
146         rpc_port_stub_vcd_mgr_stub_vc_mgr_notify_cb_h handle = mgr_tidl_info->notify_cb;
147         if (NULL == handle) {
148                 SLOG(LOG_ERROR, TAG_VCD, "[TIDL] notify callback handle is null");
149                 pthread_mutex_unlock(&g_mgr_tidl_info_mutex);
150                 return;
151         }
152
153         if (0 != rpc_port_stub_vcd_mgr_stub_vc_mgr_notify_cb_invoke(handle, msg)) {
154                 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to send msg");
155                 pthread_mutex_unlock(&g_mgr_tidl_info_mutex);
156                 return;
157         }
158         pthread_mutex_unlock(&g_mgr_tidl_info_mutex);
159         return;
160 }
161
162 void __send_msg(bundle* msg, vcd_client_type_e type, int pid)
163 {
164         SLOG(LOG_INFO, TAG_VCD, "[TIDL] send msg start");
165
166         if (VCD_CLIENT_TYPE_MANAGER == type) {
167                 __send_msg_to_mgr(msg);
168         } else if (VCD_CLIENT_TYPE_NORMAL == type) {
169                 pthread_mutex_lock(&g_client_tidl_info_mutex);
170
171                 SLOG(LOG_INFO, TAG_VCD, "[TIDL] message to client");
172                 client_tidl_info_s* client_tidl_info = vcd_client_get_tidl_info(pid);
173                 if (NULL == client_tidl_info) {
174                         SLOG(LOG_ERROR, TAG_VCD, "[TIDL] tidl proxy info not allocated");
175                         pthread_mutex_unlock(&g_client_tidl_info_mutex);
176                         return;
177                 }
178
179                 rpc_port_stub_vcd_stub_vc_notify_cb_h handle = client_tidl_info->notify_cb;
180                 if (NULL == handle) {
181                         SLOG(LOG_ERROR, TAG_VCD, "[TIDL] notify callback handle is null");
182                         pthread_mutex_unlock(&g_client_tidl_info_mutex);
183                         return;
184                 }
185
186                 if (0 != rpc_port_stub_vcd_stub_vc_notify_cb_invoke(handle, pid, msg)) {
187                         SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to send msg");
188                         pthread_mutex_unlock(&g_client_tidl_info_mutex);
189                         return;
190                 }
191                 pthread_mutex_unlock(&g_client_tidl_info_mutex);
192         } else if (VCD_CLIENT_TYPE_WIDGET == type) {
193                 pthread_mutex_lock(&g_widget_tidl_info_mutex);
194
195                 SLOG(LOG_INFO, TAG_VCD, "[TIDL] message to widget");
196                 widget_tidl_info_s* widget_tidl_info = vcd_client_widget_get_tidl_info(pid);
197                 if (NULL == widget_tidl_info) {
198                         SLOG(LOG_ERROR, TAG_VCD, "[TIDL] tidl proxy info not allocated");
199                         pthread_mutex_unlock(&g_widget_tidl_info_mutex);
200                         return;
201                 }
202
203                 rpc_port_stub_vcd_widget_stub_vc_widget_notify_cb_h handle = widget_tidl_info->notify_cb;
204                 if (NULL == handle) {
205                         SLOG(LOG_ERROR, TAG_VCD, "[TIDL] notify callback handle is null");
206                         pthread_mutex_unlock(&g_widget_tidl_info_mutex);
207                         return;
208                 }
209
210                 if (0 != rpc_port_stub_vcd_widget_stub_vc_widget_notify_cb_invoke(handle, msg)) {
211                         SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to send msg");
212                         pthread_mutex_unlock(&g_widget_tidl_info_mutex);
213                         return;
214                 }
215                 pthread_mutex_unlock(&g_widget_tidl_info_mutex);
216         } else {
217                 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] client type is NOT valid(%d)", type);
218                 return;
219         }
220 }
221
222 void __send_signal(bundle* msg, vcd_client_type_e type)
223 {
224         SLOG(LOG_INFO, TAG_VCD, "[TIDL] send signal start");
225
226         if (VCD_CLIENT_TYPE_MANAGER == type) {
227                 __send_msg_to_mgr(msg);
228         } /* signal to MANAGER */
229         else if (VCD_CLIENT_TYPE_NORMAL == type) {
230                 pthread_mutex_lock(&g_client_tidl_info_mutex);
231                 // get all pids
232                 int* client_list = NULL;
233                 int client_count = 0;
234                 int ret = -1;
235                 ret = vcd_client_get_tidl_list(&client_list, &client_count);
236
237                 client_tidl_info_s* client_tidl_info = NULL;
238                 int pid = -1;
239
240                 if (0 == ret && 0 < client_count) {
241                         for (int i = 0 ; i < client_count ; i++) {
242                                 pid = client_list[i];
243
244                                 client_tidl_info = vcd_client_get_tidl_info(pid);
245                                 if (NULL == client_tidl_info) {
246                                         SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to get tidl info. pid(%d)", pid);
247                                         continue;
248                                 }
249
250                                 if (0 != rpc_port_stub_vcd_stub_vc_notify_cb_invoke(client_tidl_info->notify_cb, pid, msg)) {
251                                         SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to send msg");
252                                         continue;
253                                 }
254                         }
255                 }
256                 pthread_mutex_unlock(&g_client_tidl_info_mutex);
257         } /* signal to clients */
258         else if (VCD_CLIENT_TYPE_WIDGET == type) {
259                 pthread_mutex_lock(&g_widget_tidl_info_mutex);
260                 GSList *iter = NULL;
261                 GSList* widget_list = vcd_client_widget_get_tidl_info_list();
262
263                 int count = g_slist_length(widget_list);
264                 int i;
265
266                 widget_tidl_info_s *widget_tidl_info = NULL;
267
268                 if (0 < count) {
269                         iter = g_slist_nth(widget_list, 0);
270                         for (i = 0; i < count; i++) {
271                                 if (NULL == iter) {
272                                         SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] widget list iterator broken");
273                                         break;
274                                 }
275
276                                 widget_tidl_info = iter->data;
277
278                                 if (NULL == widget_tidl_info) {
279                                         SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] widget list data broken");
280                                         break;
281                                 }
282
283                                 SLOG(LOG_INFO, TAG_VCD, "[TIDL] message to widget");
284
285                                 rpc_port_stub_vcd_widget_stub_vc_widget_notify_cb_h handle = widget_tidl_info->notify_cb;
286                                 if (NULL == handle) {
287                                         SLOG(LOG_ERROR, TAG_VCD, "[TIDL] notify callback handle is null");
288                                         break;
289                                 }
290
291                                 if (0 != rpc_port_stub_vcd_widget_stub_vc_widget_notify_cb_invoke(handle, msg)) {
292                                         SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to send msg");
293                                         break;
294                                 }
295
296                                 iter = g_slist_next(iter);
297                         }
298                 }
299                 pthread_mutex_unlock(&g_widget_tidl_info_mutex);
300         } /* signal to widgets */
301 }
302
303
304 /**
305  * TIDL callback functions for VC client
306  */
307 static void __vc_create_cb(rpc_port_stub_vcd_stub_vc_context_h context, void *user_data)
308 {
309         SLOG(LOG_INFO, TAG_VCD, "[TIDL] __vc_create_cb");
310
311         char *sender = NULL;
312
313         rpc_port_stub_vcd_stub_vc_context_get_sender(context, &sender);
314         if (!sender) {
315                 SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Sender is NULL");
316                 return;
317         }
318
319         SLOG(LOG_INFO, TAG_VCD, "[TIDL] sender(%s)", sender);           // sender (app_id)
320         free(sender);
321 }
322
323 static void __vc_terminate_cb(rpc_port_stub_vcd_stub_vc_context_h context, void *user_data)
324 {
325         SLOG(LOG_INFO, TAG_VCD, "[TIDL] __vc_terminate_cb");
326
327         void* tag = NULL;
328         rpc_port_stub_vcd_stub_vc_context_get_tag(context, &tag);
329
330         if (NULL != tag) {
331                 int pid = (uintptr_t)tag;
332                 SLOG(LOG_DEBUG, TAG_VCD, "@@@ VC FINALIZE. pid(%u)", pid);
333
334                 pthread_mutex_lock(&g_client_tidl_info_mutex);
335                 client_tidl_info_s* tidl_info = vcd_client_get_tidl_info(pid);
336                 if (NULL == tidl_info) {
337                         SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to get client tidl info.");
338                         pthread_mutex_unlock(&g_client_tidl_info_mutex);
339                         return;
340                 }
341
342                 if (0 != vcd_client_unset_tidl_notify_cb(pid)) {
343                         SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to unset notify callback");
344                 }
345                 if (0 != vcd_client_unset_tidl_feedback_cb(pid)) {
346                         SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to unset feedback callback");
347                 }
348
349                 if (0 != vcd_client_delete_tidl_info(pid)) {
350                         SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to delete client tidl info");
351                 }
352                 tidl_info = NULL;
353
354                 SLOG(LOG_DEBUG, TAG_VCD, "@@@");
355
356                 pthread_mutex_unlock(&g_client_tidl_info_mutex);
357
358         }
359         rpc_port_stub_vcd_stub_vc_context_set_tag(context, NULL);
360 }
361
362 static void __vc_register_notify_cb_cb(rpc_port_stub_vcd_stub_vc_context_h context, int pid, rpc_port_stub_vcd_stub_vc_notify_cb_h callback, void *user_data)
363 {
364         SLOG(LOG_INFO, TAG_VCD, "[TIDL] __vc_register_notify_cb_cb. pid(%d)", pid);
365
366         if (NULL == callback) {
367                 SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] callback is null.");
368                 return;
369         }
370
371         int ret = -1;
372         ret = vcd_client_add_tidl_info(pid);
373         if (0 != ret) {
374                 SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to add tidl info.");
375                 return;
376         }
377
378         ret = vcd_client_set_tidl_notify_cb(pid, callback, user_data);
379         if (0 != ret) {
380                 SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to set notify callback.");
381         } else {
382                 SLOG(LOG_INFO, TAG_VCD, "[TIDL] Succeed to set notify callback.");
383         }
384 }
385
386 static int __vc_register_notify_cb_sync_cb(rpc_port_stub_vcd_stub_vc_context_h context, int pid, rpc_port_stub_vcd_stub_vc_notify_cb_h callback, void *user_data)
387 {
388         SLOG(LOG_INFO, TAG_VCD, "[TIDL] __vc_register_notify_cb_sync_cb. pid(%d)", pid);
389
390         if (NULL == callback) {
391                 SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] callback is null.");
392                 return VCD_ERROR_INVALID_PARAMETER;
393         }
394
395         int ret = -1;
396         ret = vcd_client_add_tidl_info(pid);
397         if (0 != ret) {
398                 SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to add tidl info.");
399                 return ret;
400         }
401         
402         ret = vcd_client_set_tidl_notify_cb(pid, callback, user_data);
403         if (0 != ret) {
404                 SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to set notify callback.");
405         } else {
406                 SLOG(LOG_INFO, TAG_VCD, "[TIDL] Succeed to set notify callback.");
407         }
408
409         return ret;
410 }
411
412 static void __vc_register_feedback_cb_cb(rpc_port_stub_vcd_stub_vc_context_h context, int pid, rpc_port_stub_vcd_stub_vc_feedback_cb_h callback, void *user_data)
413 {
414         SLOG(LOG_INFO, TAG_VCD, "[TIDL] __vc_register_feedback_cb_cb. pid(%d)", pid);
415
416         if (NULL == callback) {
417                 SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] callback is null.");
418                 return;
419         }
420
421         int ret = -1;
422         ret = vcd_client_add_tidl_info(pid);
423         if (0 != ret) {
424                 SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to add tidl info.");
425                 return;
426         }
427
428         ret = vcd_client_set_tidl_feedback_cb(pid, callback, user_data);
429         if (0 != ret) {
430                 SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to set feedback callback.");
431         } else {
432                 SLOG(LOG_INFO, TAG_VCD, "[TIDL] Succeed to set feedback callback.");
433         }
434 }
435
436 static int __vc_register_feedback_cb_sync_cb(rpc_port_stub_vcd_stub_vc_context_h context, int pid, rpc_port_stub_vcd_stub_vc_feedback_cb_h callback, void *user_data)
437 {
438         SLOG(LOG_INFO, TAG_VCD, "[TIDL] __vc_register_feedback_cb_sync_cb. pid(%d)", pid);
439
440         if (NULL == callback) {
441                 SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] callback is null.");
442                 return VCD_ERROR_INVALID_PARAMETER;
443         }
444
445         int ret = -1;
446         ret = vcd_client_add_tidl_info(pid);
447         if (0 != ret) {
448                 SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to add tidl info.");
449                 return ret;
450         }
451         
452         ret = vcd_client_set_tidl_feedback_cb(pid, callback, user_data);
453         if (0 != ret) {
454                 SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to set feedback callback.");
455         } else {
456                 SLOG(LOG_INFO, TAG_VCD, "[TIDL] Succeed to set feedback callback.");
457         }
458
459         return ret;
460 }
461
462 static int __vc_initialize_cb(rpc_port_stub_vcd_stub_vc_context_h context, int pid, int *mgr_pid, int *service_state, int *daemon_pid, void *user_data)
463 {
464         SLOG(LOG_INFO, TAG_VCD, "[TIDL] __vc_initialize_cb. pid(%d)", pid);
465
466         int ret = VCD_ERROR_OPERATION_FAILED;
467
468         uintptr_t ptr_pid = pid;
469         rpc_port_stub_vcd_stub_vc_context_set_tag(context, (void*)ptr_pid);
470
471         ret = vcd_server_initialize(pid);
472         *service_state = vcd_server_get_service_state();
473         *daemon_pid = getpid();
474         *mgr_pid = vcd_client_manager_get_pid();
475
476         if (VCD_ERROR_NONE == ret) {
477                 SLOG(LOG_INFO, TAG_VCD, "[IN] vcd initialize : pid(%d) daemon_pid(%d)", pid, *daemon_pid);
478         } else {
479                 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to vcd initialize : pid(%d) daemon_pid(%d) ret(%d)", pid, *daemon_pid, ret);
480         }
481
482         return ret;
483 }
484
485 static int __vc_finalize_cb(rpc_port_stub_vcd_stub_vc_context_h context, int pid, void *user_data)
486 {
487         SLOG(LOG_INFO, TAG_VCD, "[TIDL] __vc_finalize_cb");
488
489         int ret = VCD_ERROR_OPERATION_FAILED;
490
491         ret = vcd_server_finalize(pid);
492         if (VCD_ERROR_NONE == ret) {
493                 SLOG(LOG_INFO, TAG_VCD, "[IN] vcd finalize : pid(%d)", pid);
494         } else {
495                 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to vcd finalize : pid(%d) ret(%d)", pid, ret);
496         }
497
498         return ret;
499 }
500
501 static int __vc_set_command_cb(rpc_port_stub_vcd_stub_vc_context_h context, int pid, int cmd_type, void *user_data)
502 {
503         SLOG(LOG_INFO, TAG_VCD, "[TIDL] __vc_set_command_cb");
504
505         int ret = VCD_ERROR_OPERATION_FAILED;
506
507         ret = vcd_server_set_command(pid, (vc_cmd_type_e)cmd_type);
508         if (VCD_ERROR_NONE == ret) {
509                 SLOG(LOG_INFO, TAG_VCD, "[IN] vcd set command : pid(%d), cmd_type(%d)", pid, cmd_type);
510         } else {
511                 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to vcd set command : pid(%d), cmd_type(%d) ret(%d)", pid, cmd_type, ret);
512         }
513
514         return ret;
515 }
516
517 static int __vc_unset_command_cb(rpc_port_stub_vcd_stub_vc_context_h context, int pid, int cmd_type, void *user_data)
518 {
519         SLOG(LOG_INFO, TAG_VCD, "[TIDL] __vc_unset_command_cb");
520
521         int ret = VCD_ERROR_OPERATION_FAILED;
522
523         ret = vcd_server_unset_command(pid, (vc_cmd_type_e)cmd_type);
524         if (VCD_ERROR_NONE == ret) {
525                 SLOG(LOG_INFO, TAG_VCD, "[IN] vcd unset command : pid(%d), cmd_type(%d)", pid, cmd_type);
526         } else {
527                 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to vcd unset command : pid(%d), cmd_type(%d) ret(%d)", pid, cmd_type, ret);
528         }
529         
530         return ret;
531 }
532
533 static int __vc_set_foreground_cb(rpc_port_stub_vcd_stub_vc_context_h context, int pid, bool value, void *user_data)
534 {
535         // check more...
536         SLOG(LOG_INFO, TAG_VCD, "[TIDL] __vc_set_foreground_cb");
537
538         int ret = VCD_ERROR_OPERATION_FAILED;
539
540         ret = vcd_server_set_foreground(pid, value);
541         if (VCD_ERROR_NONE != ret) {
542                 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to vcd set foreground : pid(%d) ret(%d)", pid, ret);
543                 return ret;
544         }
545         
546         SLOG(LOG_INFO, TAG_VCD, "[IN] vcd set foreground : pid(%d)", pid);
547         vcdc_send_request_set_foreground(pid, value);
548
549         return ret;
550 }
551
552 static int __vc_set_server_dialog_cb(rpc_port_stub_vcd_stub_vc_context_h context, int pid, const char *app_id, const char *credential, void *user_data)
553 {
554         SLOG(LOG_INFO, TAG_VCD, "[TIDL] __vc_set_server_dialog_cb");
555
556         int ret = VCD_ERROR_OPERATION_FAILED;
557
558         ret = vcd_server_set_server_dialog(pid, app_id, credential);
559         if (VCD_ERROR_NONE == ret) {
560                 SLOG(LOG_INFO, TAG_VCD, "[IN] vcd set server dialog : pid(%d), app_id(%s)", pid, app_id);
561         } else {
562                 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to vcd set server dialog : pid(%d), app_id(%s) ret(%d)", pid, app_id, ret);
563         }
564         
565         return ret;
566 }
567
568 static int __vc_request_dialog_cb(rpc_port_stub_vcd_stub_vc_context_h context, int pid, const char *disp_text, const char *utt_text, bool continuous, void *user_data)
569 {
570         SLOG(LOG_INFO, TAG_VCD, "[TIDL] __vc_request_dialog_cb");
571
572         int ret = VCD_ERROR_OPERATION_FAILED;
573
574         ret = vcd_server_dialog(pid, disp_text, utt_text, continuous);
575         if (VCD_ERROR_NONE == ret) {
576                 SLOG(LOG_INFO, TAG_VCD, "[IN] vcd request dialog : pid(%d), disp_text(%s), utt_text(%s), continuous(%d)", pid, disp_text, utt_text, continuous);
577         } else {
578                 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to vcd request dialog : pid(%d), disp_text(%s), utt_text(%s), continuous(%d), ret(%d)", pid, disp_text, utt_text, continuous, ret);
579         }
580         
581         return VCD_ERROR_NONE;
582 }
583
584 static int __vc_is_system_command_valid_cb(rpc_port_stub_vcd_stub_vc_context_h context, int pid, bool *is_sys_cmd_valid, void *user_data)
585 {
586         SLOG(LOG_INFO, TAG_VCD, "[TIDL] __vc_is_system_command_valid_cb");
587
588         int ret = VCD_ERROR_OPERATION_FAILED;
589
590         ret = vcd_server_is_system_command_valid(pid, (int*)is_sys_cmd_valid);
591         if (VCD_ERROR_NONE == ret) {
592                 SLOG(LOG_INFO, TAG_VCD, "[IN] vcd check system command is valid : pid(%d), is_sys_cmd_valid(%d)", pid, *is_sys_cmd_valid);
593         } else {
594                 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to vcd check system command is valid : pid(%d), ret(%d)", pid, ret);
595         }
596         
597         return ret;
598 }
599
600 static int __vc_auth_enable_cb(rpc_port_stub_vcd_stub_vc_context_h context, int pid, int mgr_pid, void *user_data)
601 {
602         SLOG(LOG_INFO, TAG_VCD, "[TIDL] __vc_auth_enable_cb. Send a request to vc_mgr");
603
604         int ret = VCD_ERROR_OPERATION_FAILED;
605         ret = vcdc_send_request_auth_enable(pid);
606         if (VCD_ERROR_NONE == ret) {
607                 SLOG(LOG_INFO, TAG_VCD, "[SUCCESS] Send request auth enable. pid(%d), mgr_pid(%d)", pid, mgr_pid);
608         } else {
609                 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to send request auth enable. ret(%d), pid(%d), mgr_pid(%d)", ret, pid, mgr_pid);
610         }
611
612         return ret;
613 }
614
615 static int __vc_auth_disable_cb(rpc_port_stub_vcd_stub_vc_context_h context, int pid, int mgr_pid, void *user_data)
616 {
617         SLOG(LOG_INFO, TAG_VCD, "[TIDL] __vc_auth_disable_cb. Send a request to vc_mgr");
618
619         int ret = VCD_ERROR_OPERATION_FAILED;
620         ret = vcdc_send_request_auth_disable(pid);
621         if (VCD_ERROR_NONE == ret) {
622                 SLOG(LOG_INFO, TAG_VCD, "[SUCCESS] Send request auth disable. pid(%d), mgr_pid(%d)", pid, mgr_pid);
623         } else {
624                 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to send request auth disable. ret(%d), pid(%d), mgr_pid(%d)", ret, pid, mgr_pid);
625         }
626
627         return ret;
628 }
629
630 static int __vc_auth_start_cb(rpc_port_stub_vcd_stub_vc_context_h context, int pid, int mgr_pid, void *user_data)
631 {
632         SLOG(LOG_INFO, TAG_VCD, "[TIDL] __vc_auth_start_cb. Send a request to vc_mgr");
633
634         int ret = VCD_ERROR_OPERATION_FAILED;
635         ret = vcdc_send_request_auth_start(pid);
636         if (VCD_ERROR_NONE == ret) {
637                 SLOG(LOG_INFO, TAG_VCD, "[SUCCESS] Send request auth start. pid(%d), mgr_pid(%d)", pid, mgr_pid);
638         } else {
639                 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to send request auth start. ret(%d), pid(%d), mgr_pid(%d)", ret, pid, mgr_pid);
640         }
641
642         return ret;
643 }
644
645 static int __vc_auth_stop_cb(rpc_port_stub_vcd_stub_vc_context_h context, int pid, int mgr_pid, void *user_data)
646 {
647         SLOG(LOG_INFO, TAG_VCD, "[TIDL] __vc_auth_stop_cb. Send a request to vc_mgr");
648
649         int ret = VCD_ERROR_OPERATION_FAILED;
650         ret = vcdc_send_request_auth_stop(pid);
651         if (VCD_ERROR_NONE == ret) {
652                 SLOG(LOG_INFO, TAG_VCD, "[SUCCESS] Send request auth stop. pid(%d), mgr_pid(%d)", pid, mgr_pid);
653         } else {
654                 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to send request auth stop. ret(%d), pid(%d), mgr_pid(%d)", ret, pid, mgr_pid);
655         }
656
657         return ret;
658 }
659
660 static int __vc_auth_cancel_cb(rpc_port_stub_vcd_stub_vc_context_h context, int pid, int mgr_pid, void *user_data)
661 {
662         SLOG(LOG_INFO, TAG_VCD, "[TIDL] __vc_auth_cancel_cb. Send a request to vc_mgr");
663
664         int ret = VCD_ERROR_OPERATION_FAILED;
665         ret = vcdc_send_request_auth_cancel(pid);
666         if (VCD_ERROR_NONE == ret) {
667                 SLOG(LOG_INFO, TAG_VCD, "[SUCCESS] Send request auth cancel. pid(%d), mgr_pid(%d)", pid, mgr_pid);
668         } else {
669                 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to send request auth cancel. ret(%d), pid(%d), mgr_pid(%d)", ret, pid, mgr_pid);
670         }
671
672         return ret;
673 }
674
675 static int __vc_request_tts_cb(rpc_port_stub_vcd_stub_vc_context_h context, int pid, const char *text, const char *lang, bool to_vcm, int *utt_id, void *user_data)
676 {
677         SLOG(LOG_INFO, TAG_VCD, "[TIDL] __vc_request_tts_cb");
678
679         int ret = VCD_ERROR_OPERATION_FAILED;
680
681         ret = vcd_server_request_tts(pid, text, lang, to_vcm, utt_id);
682         if (VCD_ERROR_NONE == ret) {
683                 SLOG(LOG_INFO, TAG_VCD, "[IN] vcd request tts : pid(%d), text(%s), language(%s), to_vcm(%d)", pid, text, lang, to_vcm);
684         } else {
685                 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to vcd request tts : pid(%d), text(%s), language(%s), to_vcm(%d), ret(%d)", pid, text, lang, to_vcm, ret);
686         }
687         
688         return ret;
689 }
690
691 static int __vc_cancel_tts_cb(rpc_port_stub_vcd_stub_vc_context_h context, int pid, int utt_id, void *user_data)
692 {
693         SLOG(LOG_INFO, TAG_VCD, "[TIDL] __vc_cancel_tts_cb");
694
695         int ret = VCD_ERROR_OPERATION_FAILED;
696
697         ret = vcd_server_cancel_tts(pid, utt_id);
698         if (VCD_ERROR_NONE == ret) {
699                 SLOG(LOG_INFO, TAG_VCD, "[IN] vcd cancel tts : pid(%d), utt_id(%d)", pid, utt_id);
700         } else {
701                 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to vcd cancel tts : pid(%d), utt_id(%d), ret(%d)", pid, utt_id, ret);
702         }
703         
704         return ret;
705 }
706
707 static int __vc_get_tts_audio_format_cb(rpc_port_stub_vcd_stub_vc_context_h context, int pid, int *rate, int *channel, int *audio_type, void *user_data)
708 {
709         SLOG(LOG_INFO, TAG_VCD, "[TIDL] __vc_get_tts_audio_format_cb");
710
711         int ret = VCD_ERROR_OPERATION_FAILED;
712
713         ret = vcd_server_get_tts_audio_format(pid, rate, channel, audio_type);
714         if (VCD_ERROR_NONE == ret) {
715                 SLOG(LOG_INFO, TAG_VCD, "[IN] vcd get tts audio format : pid(%d), rate(%d), channel(%d), audio_type(%d)", pid, *rate, *channel, *audio_type);
716         } else {
717                 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to vcd get tts audio format : pid(%d) ret(%d)", pid, ret);
718         }
719         
720         return ret;
721 }
722
723 int __client_tidl_open_connection()
724 {
725         SLOG(LOG_INFO, TAG_VCD, "[TIDL] __client_tidl_open_connection");
726
727         g_client_callback.create = __vc_create_cb;
728         g_client_callback.terminate = __vc_terminate_cb;
729         g_client_callback.register_notify_cb = __vc_register_notify_cb_cb;
730         g_client_callback.register_notify_cb_sync = __vc_register_notify_cb_sync_cb;
731         g_client_callback.register_feedback_cb = __vc_register_feedback_cb_cb;
732         g_client_callback.register_feedback_cb_sync = __vc_register_feedback_cb_sync_cb;
733         g_client_callback.initialize = __vc_initialize_cb;
734         g_client_callback.finalize = __vc_finalize_cb;
735         g_client_callback.set_command = __vc_set_command_cb;
736         g_client_callback.unset_command = __vc_unset_command_cb;
737         g_client_callback.set_foreground = __vc_set_foreground_cb;
738         g_client_callback.set_server_dialog = __vc_set_server_dialog_cb;
739         g_client_callback.request_dialog = __vc_request_dialog_cb;
740         g_client_callback.is_system_command_valid = __vc_is_system_command_valid_cb;
741         g_client_callback.auth_enable = __vc_auth_enable_cb;
742         g_client_callback.auth_disable = __vc_auth_disable_cb;
743         g_client_callback.auth_start = __vc_auth_start_cb;
744         g_client_callback.auth_stop = __vc_auth_stop_cb;
745         g_client_callback.auth_cancel = __vc_auth_cancel_cb;
746         g_client_callback.request_tts = __vc_request_tts_cb;
747         g_client_callback.cancel_tts = __vc_cancel_tts_cb;
748         g_client_callback.get_tts_audio_format = __vc_get_tts_audio_format_cb;
749
750         int ret = -1;
751         ret = rpc_port_stub_vcd_stub_vc_register(&g_client_callback, NULL);
752         if (VCD_ERROR_NONE != ret) {
753                 SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to register TIDL callbacks. ret(%d)", ret);
754                 return VCD_ERROR_OPERATION_FAILED;
755         }
756
757         return VCD_ERROR_NONE;
758 }
759
760 int __client_tidl_close_connection()
761 {
762         SLOG(LOG_INFO, TAG_VCD, "[TIDL] __client_tidl_close_connection");
763         rpc_port_stub_vcd_stub_vc_unregister();
764
765         return VCD_ERROR_NONE;
766 }
767
768 /**
769  * TIDL callback functions for VC manager
770  */
771 static void __mgr_on_connected(rpc_port_proxy_vcd_mgr_proxy_vcd_mgr_h h, void *user_data)
772 {
773         manager_tidl_info_s* mgr_tidl_info = vcd_client_manager_get_tidl_info();
774
775         if (NULL == mgr_tidl_info) {
776                 SLOG(LOG_ERROR, TAG_VCD, "[TIDL] tidl proxy info not allocated");
777                 return;
778         }
779
780         mgr_tidl_info->connected = true;
781         mgr_tidl_info->connection_requesting = false;
782
783         SLOG(LOG_INFO, TAG_VCD, "Connected to manager");
784 }
785
786 static void __mgr_on_disconnected(rpc_port_proxy_vcd_mgr_proxy_vcd_mgr_h h, void *user_data)
787 {
788         manager_tidl_info_s* mgr_tidl_info = vcd_client_manager_get_tidl_info();
789
790         if (NULL == mgr_tidl_info) {
791                 SLOG(LOG_ERROR, TAG_VCD, "[TIDL] tidl proxy info not allocated");
792                 return;
793         }
794
795         mgr_tidl_info->connected = false;
796         mgr_tidl_info->connection_requesting = false;
797
798         SLOG(LOG_INFO, TAG_VCD, "Disonnected to manager");
799 }
800
801 static void __mgr_on_rejected(rpc_port_proxy_vcd_mgr_proxy_vcd_mgr_h h, void *user_data)
802 {
803         manager_tidl_info_s* mgr_tidl_info = vcd_client_manager_get_tidl_info();
804
805         if (NULL == mgr_tidl_info) {
806                 SLOG(LOG_ERROR, TAG_VCD, "[TIDL] tidl proxy info not allocated");
807                 return;
808         }
809
810         mgr_tidl_info->connection_requesting = false;
811
812         SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Rejected from manager");
813 }
814
815 static rpc_port_proxy_vcd_mgr_proxy_vcd_mgr_h __mgr_create_rpc_port(const char* engine_app_id)
816 {
817         SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] __mgr_create_rpc_port");
818         rpc_port_proxy_vcd_mgr_proxy_vcd_mgr_callback_s rpc_callback = {
819                 .connected = __mgr_on_connected,
820                 .disconnected = __mgr_on_disconnected,
821                 .rejected = __mgr_on_rejected
822         };
823
824         rpc_port_proxy_vcd_mgr_proxy_vcd_mgr_h handle = NULL;
825         if (0 != rpc_port_proxy_vcd_mgr_proxy_vcd_mgr_create(engine_app_id, &rpc_callback, NULL, &handle)) {
826                 SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to create proxy");
827                 return NULL;
828         }
829
830         return handle;
831 }
832
833 static void __vc_mgr_create_cb(rpc_port_stub_vcd_mgr_stub_vc_mgr_context_h context, void *user_data)
834 {
835         char *sender = NULL;
836
837         rpc_port_stub_vcd_mgr_stub_vc_mgr_context_get_sender(context, &sender);
838         if (!sender){
839                 SLOG(LOG_ERROR, TAG_VCD, "Sender is NULL");
840                 return;
841         }
842
843         SLOG(LOG_DEBUG, TAG_VCD, "@@@ Manager connect. appid(%s)", sender);
844
845         free(sender);
846 }
847
848 static void __vc_mgr_terminate_cb(rpc_port_stub_vcd_mgr_stub_vc_mgr_context_h context, void *user_data)
849 {
850         pthread_mutex_lock(&g_mgr_tidl_info_mutex);
851         manager_tidl_info_s* mgr_tidl_info = vcd_client_manager_get_tidl_info();
852         if (NULL == mgr_tidl_info) {
853                 SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to get manager tidl info.");
854                 pthread_mutex_unlock(&g_mgr_tidl_info_mutex);
855                 return;
856         }
857
858         SLOG(LOG_DEBUG, TAG_VCD, "@@@ VC MANAGER FINALIZE. pid(%u)", mgr_tidl_info->pid);
859
860         if (0 != vcd_client_manager_unset_tidl_notify_cb()) {
861                 SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to unset notify callback");
862         }
863
864         if (0 != vcd_client_manager_unset_tidl_send_buffer_cb()) {
865                 SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to unset send buffer callback");
866         }
867
868         if (0 != vcd_client_manager_delete_tidl_info()) {
869                 SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to delete manager tidl info");
870         }
871         mgr_tidl_info = NULL;
872
873         SLOG(LOG_DEBUG, TAG_VCD, "@@@");
874
875         pthread_mutex_unlock(&g_mgr_tidl_info_mutex);
876
877
878         char *sender = NULL;
879         rpc_port_stub_vcd_mgr_stub_vc_mgr_context_get_sender(context, &sender);
880         if (!sender)
881                 return;
882
883         SLOG(LOG_INFO, TAG_VCD, "@@@ Manager disconnect. appid(%s)", sender);
884
885         free(sender);
886 }
887
888 static void  __vc_mgr_register_cb_cb(rpc_port_stub_vcd_mgr_stub_vc_mgr_context_h context, int pid, rpc_port_stub_vcd_mgr_stub_vc_mgr_notify_cb_h notify_callback, rpc_port_stub_vcd_mgr_stub_vc_mgr_send_buffer_cb_h send_buffer_callback, void *user_data)
889 {
890         pthread_mutex_lock(&g_mgr_tidl_info_mutex);
891         SLOG(LOG_INFO, TAG_VCD, "@@@ VC MANAGER REGISTER CALLBACK");
892
893         int ret = -1;
894         ret = vcd_client_manager_create_tidl_info(pid);
895
896         if (0 != ret) {
897                 SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to create manager tidl info.");
898                 pthread_mutex_unlock(&g_mgr_tidl_info_mutex);
899                 return;
900         }
901
902         manager_tidl_info_s* mgr_tidl_info = vcd_client_manager_get_tidl_info();
903
904         if (NULL == mgr_tidl_info) {
905                 SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to get manager tidl info. pid(%d)", pid);
906                 pthread_mutex_unlock(&g_mgr_tidl_info_mutex);
907                 return;
908         }
909
910         char *sender = NULL;
911         rpc_port_stub_vcd_mgr_stub_vc_mgr_context_get_sender(context, &sender);
912
913         if (!sender){
914                 SLOG(LOG_ERROR, TAG_VCD, "Sender is NULL");
915                 pthread_mutex_unlock(&g_mgr_tidl_info_mutex);
916                 return;
917         }
918
919         mgr_tidl_info->rpc_h = __mgr_create_rpc_port(sender);
920
921         if (NULL == mgr_tidl_info->rpc_h) {
922                 SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to create server proxy");
923         } else {
924                 SLOG(LOG_INFO, TAG_VCD, "[TIDL] rpc_h(%p), engine_app_id(%s)", mgr_tidl_info->rpc_h, sender);
925         }
926
927         free(sender);
928
929         if (0 != vcd_client_manager_set_tidl_notify_cb(notify_callback, user_data)) {
930                 SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to set notify callback");
931         } else {
932                 SLOG(LOG_INFO, TAG_VCD, "[TIDL] Succeed to set notify callback.");
933         }
934
935         if (0 != vcd_client_manager_set_tidl_send_buffer_cb(send_buffer_callback, user_data)) {
936                 SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to set send buffer callback");
937         } else {
938                 SLOG(LOG_INFO, TAG_VCD, "[TIDL] Succeed to set send buffer callback.");
939         }
940
941         pthread_mutex_unlock(&g_mgr_tidl_info_mutex);
942
943         __request_tidl_connect(VCD_CLIENT_TYPE_MANAGER, pid);
944
945         SLOG(LOG_DEBUG, TAG_VCD, "@@@");
946 }
947
948 static int  __vc_mgr_initialize_cb(rpc_port_stub_vcd_mgr_stub_vc_mgr_context_h context, int pid, int audio_streaming_mode, int *service_state, int *foreground, int *daemon_pid, void *user_data)
949 {
950         SLOG(LOG_INFO, TAG_VCD, "@@@ VCD Manager Initialize");
951
952         int ret = -1;
953
954         vcd_config_set_audio_streaming_mode((vcd_audio_streaming_mode_e)audio_streaming_mode);
955         ret = vcd_server_mgr_initialize(pid, audio_streaming_mode);
956         if (0 != ret) {
957                 SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret);
958                 return ret;
959         }
960         *service_state = vcd_server_get_service_state();
961         *foreground = vcd_server_get_foreground();
962         *daemon_pid = getpid();
963
964         SLOG(LOG_INFO, TAG_VCD, "[IN] vcd mgr initialize : pid(%d) service state(%d) foreground(%d) daemon_pid(%d)", pid, *service_state, *foreground, *daemon_pid);
965         SLOG(LOG_DEBUG, TAG_VCD, "@@@");
966         return ret;
967 }
968
969 static int  __vc_mgr_finalize_cb(rpc_port_stub_vcd_mgr_stub_vc_mgr_context_h context, int pid, void *user_data)
970 {
971         SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Manager Finalize");
972         SLOG(LOG_INFO, TAG_VCD, "[IN] vcd mgr finalize : pid(%d)", pid);
973
974         int ret = -1;
975
976         ret = vcd_server_mgr_finalize(pid);
977         if (0 != ret) {
978                 SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret);
979         }
980
981         SLOG(LOG_DEBUG, TAG_VCD, "@@@");
982
983         return ret;
984 }
985
986 static int  __vc_mgr_set_command_cb(rpc_port_stub_vcd_mgr_stub_vc_mgr_context_h context, int pid, void *user_data)
987 {
988         SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Manager Set command");
989         SLOG(LOG_INFO, TAG_VCD, "[IN] vcd mgr set command : pid(%d)", pid);
990
991         int ret = -1;
992
993         ret = vcd_server_mgr_set_command(pid);
994         if (0 != ret) {
995                 SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret);
996                 return ret;
997         }
998
999         SLOG(LOG_DEBUG, TAG_VCD, "@@@");
1000
1001         return ret;
1002 }
1003
1004 static int  __vc_mgr_unset_command_cb(rpc_port_stub_vcd_mgr_stub_vc_mgr_context_h context, int pid, void *user_data)
1005 {
1006         SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Manager unset command");
1007         SLOG(LOG_INFO, TAG_VCD, "[IN] vcd mgr unset command : pid(%d)", pid);
1008
1009         int ret = -1;
1010
1011         ret = vcd_server_mgr_unset_command(pid);
1012         if (0 != ret) {
1013                 SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret);
1014                 return ret;
1015         }
1016
1017         SLOG(LOG_DEBUG, TAG_VCD, "@@@");
1018
1019         return ret;
1020 }
1021
1022 static int  __vc_mgr_set_demandable_client_cb(rpc_port_stub_vcd_mgr_stub_vc_mgr_context_h context, int pid, void *user_data)
1023 {
1024         SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Manager Set demandable client");
1025         SLOG(LOG_INFO, TAG_VCD, "[IN] vcd mgr set demandable client : pid(%d)", pid);
1026
1027         int ret = -1;
1028
1029         ret = vcd_server_mgr_set_demandable_client(pid);
1030         if (0 != ret) {
1031                 SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret);
1032                 return ret;
1033         }
1034
1035         SLOG(LOG_DEBUG, TAG_VCD, "@@@");
1036
1037         return ret;
1038 }
1039
1040 static int  __vc_mgr_set_audio_type_cb(rpc_port_stub_vcd_mgr_stub_vc_mgr_context_h context, int pid, const char *audio_type, void *user_data)
1041 {
1042         SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Manager set audio type");
1043         SLOG(LOG_INFO, TAG_VCD, "[IN] vcd mgr set audio type : pid(%d), audio type(%s)", pid, audio_type);
1044
1045         int ret = -1;
1046
1047         ret = vcd_server_mgr_set_audio_type(pid, audio_type);
1048         if (0 != ret) {
1049                 SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret);
1050                 return ret;
1051         }
1052
1053         SLOG(LOG_DEBUG, TAG_VCD, "@@@");
1054
1055         return ret;
1056 }
1057
1058 static int  __vc_mgr_get_audio_type_cb(rpc_port_stub_vcd_mgr_stub_vc_mgr_context_h context, int pid, char **audio_type, void *user_data)
1059 {
1060         SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Manager get audio type");
1061         SLOG(LOG_INFO, TAG_VCD, "[IN] vcd mgr set audio type : pid(%d)", pid);
1062
1063         int ret = -1;
1064         char* tmp_audio_type = NULL;
1065
1066         ret = vcd_server_mgr_get_audio_type(pid, &tmp_audio_type);
1067         if (0 != ret) {
1068                 SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret);
1069                 free(tmp_audio_type);
1070                 return ret;
1071         }
1072
1073         *audio_type = strdup(tmp_audio_type);
1074         free(tmp_audio_type);
1075
1076         SLOG(LOG_DEBUG, TAG_VCD, "@@@");
1077
1078         return ret;
1079 }
1080
1081 static void  __vc_mgr_set_private_data_cb(rpc_port_stub_vcd_mgr_stub_vc_mgr_context_h context, int pid, const char *key, const char *data, void *user_data)
1082 {
1083         SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Manager set private data");
1084         SLOG(LOG_INFO, TAG_VCD, "[IN] vcd mgr set domain : pid(%d), key(%s), data(%s)", pid, key, data);
1085
1086         int ret = -1;
1087
1088         ret = vcd_server_mgr_set_private_data(pid, key, data);
1089         if (0 != ret) {
1090                 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to set private data");
1091                 SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret);
1092         }
1093
1094         SLOG(LOG_DEBUG, TAG_VCD, "@@@");
1095 }
1096
1097 static int  __vc_mgr_get_private_data_cb(rpc_port_stub_vcd_mgr_stub_vc_mgr_context_h context, int pid, const char *key, char **data, void *user_data)
1098 {
1099         SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Manager get private data");
1100         SLOG(LOG_INFO, TAG_VCD, "[IN] vcd mgr get private data : pid(%d), key(%s)", pid, key);
1101
1102         int ret = -1;
1103         char *temp_data = NULL;
1104
1105         ret = vcd_server_mgr_get_private_data(pid, key, &temp_data);
1106         if (0 != ret) {
1107                 SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret);
1108                 return ret;
1109         }
1110         if (NULL == temp_data) {
1111                 SLOG(LOG_INFO, TAG_VCD, "data parameter is NULL");
1112                 temp_data = strdup("#NULL");
1113         }
1114
1115         *data = strdup(temp_data);
1116         free(temp_data);
1117
1118         SLOG(LOG_DEBUG, TAG_VCD, "@@@");
1119
1120         return ret;
1121 }
1122
1123 static int  __vc_mgr_set_client_info_cb(rpc_port_stub_vcd_mgr_stub_vc_mgr_context_h context, int pid, void *user_data)
1124 {
1125         SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Manager set client info");
1126         SLOG(LOG_INFO, TAG_VCD, "[IN] vcd mgr set client info : pid(%d)", pid);
1127
1128         int ret = -1;
1129
1130         ret = vcd_server_mgr_set_client_info(pid);
1131         if (0 != ret) {
1132                 SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret);
1133                 return ret;
1134         }
1135
1136         SLOG(LOG_DEBUG, TAG_VCD, "@@@");
1137
1138         return ret;
1139 }
1140
1141 static int  __vc_mgr_set_domain_cb(rpc_port_stub_vcd_mgr_stub_vc_mgr_context_h context, int pid, const char *domain, void *user_data)
1142 {
1143         SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Manager set domain type");
1144         SLOG(LOG_INFO, TAG_VCD, "[IN] vcd mgr set domain : pid(%d), domain(%s)", pid, domain);
1145
1146         int ret = -1;
1147
1148         ret = vcd_server_mgr_set_domain(pid, domain);
1149         if (0 != ret) {
1150                 SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret);
1151                 return ret;
1152         }
1153
1154         SLOG(LOG_DEBUG, TAG_VCD, "@@@");
1155
1156         return ret;
1157 }
1158
1159 static void  __vc_mgr_do_action_cb(rpc_port_stub_vcd_mgr_stub_vc_mgr_context_h context, int pid, int type, const char *send_event, void *user_data)
1160 {
1161         SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Manager request to do action");
1162         SLOG(LOG_INFO, TAG_VCD, "[IN] vcd mgr request to do action : pid(%d), type(%d) send_event(%s)", pid, type, send_event);
1163
1164         int ret = -1;
1165
1166         ret = vcd_server_mgr_do_action(pid, type, send_event);
1167         if (0 != ret) {
1168                 SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret);
1169         }
1170
1171         SLOG(LOG_DEBUG, TAG_VCD, "@@@");
1172 }
1173
1174 static int  __vc_mgr_start_cb(rpc_port_stub_vcd_mgr_stub_vc_mgr_context_h context, int pid, int recognition_mode, bool exclusive_command_option, bool start_by_client, int disabled_cmd_type, void *user_data)
1175 {
1176         SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Manager start");
1177         SLOG(LOG_INFO, TAG_VCD, "[IN] vcd check enabled or disabled command types. disabled cmd type(%d)", disabled_cmd_type);
1178
1179         int ret = -1;
1180
1181         vcd_server_mgr_set_disabled_command_type(pid, disabled_cmd_type);
1182
1183         SLOG(LOG_INFO, TAG_VCD, "[IN] vcd mgr start : pid(%d) recognition_mode(%d) exclusive(%d) start by client(%d)", pid, recognition_mode, exclusive_command_option, start_by_client);
1184         ret = vcd_server_mgr_start((vcd_recognition_mode_e)recognition_mode, exclusive_command_option, start_by_client);
1185         if (0 != ret) {
1186                 SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret);
1187                 return ret;
1188         }
1189
1190         SLOG(LOG_DEBUG, TAG_VCD, "@@@");
1191
1192         return ret;
1193 }
1194
1195 static int  __vc_mgr_stop_cb(rpc_port_stub_vcd_mgr_stub_vc_mgr_context_h context, int pid, void *user_data)
1196 {
1197         SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Manager stop");
1198         SLOG(LOG_INFO, TAG_VCD, "[IN] vcd mgr stop : pid(%d)", pid);
1199
1200         int ret = -1;
1201
1202         ret = vcd_server_mgr_stop();
1203
1204         if (0 != ret) {
1205                 SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret);
1206                 return ret;
1207         }
1208
1209         SLOG(LOG_DEBUG, TAG_VCD, "@@@");
1210
1211         return ret;
1212 }
1213
1214 static int  __vc_mgr_cancel_cb(rpc_port_stub_vcd_mgr_stub_vc_mgr_context_h context, int pid, void *user_data)
1215 {
1216         SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Manager cancel");
1217         SLOG(LOG_INFO, TAG_VCD, "[IN] vcd mgr cancel : pid(%d)", pid);
1218
1219         int ret = -1;
1220
1221         ret = vcd_server_mgr_cancel();
1222         if (0 != ret) {
1223                 SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret);
1224                 return ret;
1225         }
1226
1227         SLOG(LOG_DEBUG, TAG_VCD, "@@@");
1228
1229         return ret;
1230 }
1231
1232 static void  __vc_mgr_set_audio_streaming_mode_cb(rpc_port_stub_vcd_mgr_stub_vc_mgr_context_h context, int pid, int mode, void *user_data)
1233 {
1234         SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Manager set audio streaming mode");
1235         SLOG(LOG_INFO, TAG_VCD, "[IN] vcd mgr set audio streaming mode : pid(%d) mode(%d)", pid, mode);
1236
1237         vcd_config_set_audio_streaming_mode((vcd_audio_streaming_mode_e)mode);
1238
1239         SLOG(LOG_DEBUG, TAG_VCD, "@@@");
1240 }
1241
1242 static void  __vc_mgr_send_specific_engine_request_cb(rpc_port_stub_vcd_mgr_stub_vc_mgr_context_h context, int pid, const char *engine_app_id, const char *event, const char *request, void *user_data)
1243 {
1244         SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Manager specific engine request");
1245
1246         int ret = -1;
1247         gsize decodingSize = 0;
1248         gchar *gDecodedRequest = (gchar *)g_base64_decode((const gchar *)request, &decodingSize);
1249
1250         if (gDecodedRequest) {
1251                 ret = vcd_server_mgr_send_specific_engine_request(pid, engine_app_id, event, gDecodedRequest);
1252                 if (0 != ret) {
1253                         SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret);
1254                 }
1255
1256                 SLOG(LOG_INFO, TAG_VCD, "[IN] vcd mgr specific engine request : pid(%d), engine_app_id(%s), event(%s), request(%s), ret(%d)", pid, engine_app_id, event, gDecodedRequest, ret);
1257                 g_free(gDecodedRequest);
1258         }
1259
1260         SLOG(LOG_DEBUG, TAG_VCD, "@@@");
1261 }
1262
1263 static void  __vc_mgr_send_result_selection_cb(rpc_port_stub_vcd_mgr_stub_vc_mgr_context_h context, int pid, void *user_data)
1264 {
1265         SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Manager result selection");
1266         SLOG(LOG_INFO, TAG_VCD, "[IN] vcd mgr result selection : pid(%d)", pid);
1267
1268         vcd_server_mgr_result_select();
1269
1270         SLOG(LOG_DEBUG, TAG_VCD, "@@@");
1271 }
1272
1273 static void  __vc_mgr_send_utterance_status_cb(rpc_port_stub_vcd_mgr_stub_vc_mgr_context_h context, int pid, int utt_id, int utt_status, void *user_data)
1274 {
1275         SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Manager send utterance status");
1276         SLOG(LOG_INFO, TAG_VCD, "[IN] vcd mgr send utterance status : pid(%d), utt_id(%d), utt_status(%d)", pid, utt_id, utt_status);
1277
1278         pthread_mutex_lock(&g_client_tidl_info_mutex);
1279
1280         SLOG(LOG_INFO, TAG_VCD, "[TIDL] message to client");
1281         client_tidl_info_s* client_tidl_info = vcd_client_get_tidl_info(pid);
1282         if (NULL == client_tidl_info) {
1283                 SLOG(LOG_ERROR, TAG_VCD, "[TIDL] tidl proxy info not allocated");
1284                 pthread_mutex_unlock(&g_client_tidl_info_mutex);
1285                 return;
1286         }
1287
1288         rpc_port_stub_vcd_stub_vc_notify_cb_h handle = client_tidl_info->notify_cb;
1289         if (NULL == handle) {
1290                 SLOG(LOG_ERROR, TAG_VCD, "[TIDL] notify callback handle is null");
1291                 pthread_mutex_unlock(&g_client_tidl_info_mutex);
1292                 return;
1293         }
1294
1295         bundle* msg = bundle_create();
1296         if (NULL == msg) {
1297                 SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to create bundle data");
1298                 pthread_mutex_unlock(&g_client_tidl_info_mutex);
1299                 return;
1300         }
1301
1302         char pid_char[10] = {0};
1303         char uttid_char[10] = {0};
1304         char uttstatus_char[10] = {0};
1305         snprintf(pid_char, 10, "%d", pid);
1306         snprintf(uttid_char, 10, "%d", utt_id);
1307         snprintf(uttstatus_char, 10, "%d", utt_status);
1308
1309         bundle_add_str(msg, VC_BUNDLE_METHOD, VC_MANAGER_METHOD_UTTERANCE_STATUS);
1310         bundle_add_str(msg, VC_BUNDLE_PID, pid_char);
1311         bundle_add_str(msg, VC_BUNDLE_REASON, uttid_char);
1312         bundle_add_str(msg, VC_BUNDLE_ERR_MSG, uttstatus_char);
1313
1314         if (0 != rpc_port_stub_vcd_stub_vc_notify_cb_invoke(handle, pid, msg)) {
1315                 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to send msg");
1316                 bundle_free(msg);
1317                 pthread_mutex_unlock(&g_client_tidl_info_mutex);
1318                 return;
1319         }
1320
1321         bundle_free(msg);
1322         pthread_mutex_unlock(&g_client_tidl_info_mutex);
1323
1324         SLOG(LOG_DEBUG, TAG_VCD, "@@@");
1325 }
1326
1327 static void  __vc_mgr_send_audio_streaming_cb(rpc_port_stub_vcd_mgr_stub_vc_mgr_context_h context, int pid, int event, rpc_port_stub_vcd_mgr_stub_array_char_h data, void *user_data)
1328 {
1329         SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Manager send audio streaming");
1330
1331         char* buffer = NULL;
1332         int len = 0;
1333         int ret = -1;
1334         rpc_port_stub_vcd_mgr_stub_array_char_get(data, &buffer, &len);
1335
1336         SLOG(LOG_INFO, TAG_VCD, "[IN] vcd mgr send audio streaming : pid(%d), event(%d), buffer(%p), len(%d)", pid, event, buffer, len);
1337
1338         ret = vcd_server_mgr_send_audio_streaming(pid, event, buffer, (unsigned int)len);
1339         if (0 != ret) {
1340                 SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret);
1341         }
1342
1343         SLOG(LOG_DEBUG, TAG_VCD, "@@@");
1344 }
1345
1346 int __mgr_tidl_open_connection()
1347 {
1348         SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] __mgr_tidl_open_connection");
1349
1350         g_mgr_callback.create = __vc_mgr_create_cb;
1351         g_mgr_callback.terminate = __vc_mgr_terminate_cb;
1352         g_mgr_callback.register_cb = __vc_mgr_register_cb_cb;
1353         g_mgr_callback.initialize = __vc_mgr_initialize_cb;
1354         g_mgr_callback.finalize = __vc_mgr_finalize_cb;
1355         g_mgr_callback.set_command = __vc_mgr_set_command_cb;
1356         g_mgr_callback.unset_command = __vc_mgr_unset_command_cb;
1357         g_mgr_callback.demandable_client = __vc_mgr_set_demandable_client_cb;
1358         g_mgr_callback.set_audio_type = __vc_mgr_set_audio_type_cb;
1359         g_mgr_callback.get_audio_type = __vc_mgr_get_audio_type_cb;
1360         g_mgr_callback.set_private_data = __vc_mgr_set_private_data_cb;
1361         g_mgr_callback.get_private_data = __vc_mgr_get_private_data_cb;
1362         g_mgr_callback.set_client_info = __vc_mgr_set_client_info_cb;
1363         g_mgr_callback.set_domain = __vc_mgr_set_domain_cb;
1364         g_mgr_callback.do_action = __vc_mgr_do_action_cb;
1365         g_mgr_callback.start = __vc_mgr_start_cb;
1366         g_mgr_callback.stop = __vc_mgr_stop_cb;
1367         g_mgr_callback.cancel = __vc_mgr_cancel_cb;
1368         g_mgr_callback.set_audio_streaming_mode = __vc_mgr_set_audio_streaming_mode_cb;
1369         g_mgr_callback.send_specific_engine_request = __vc_mgr_send_specific_engine_request_cb;
1370         g_mgr_callback.send_result_selection = __vc_mgr_send_result_selection_cb;
1371         g_mgr_callback.send_utterance_status = __vc_mgr_send_utterance_status_cb;
1372         g_mgr_callback.send_audio_streaming = __vc_mgr_send_audio_streaming_cb;
1373
1374         int ret = -1;
1375         int count = 0;
1376         while (VC_RETRY_MIN_COUNT >= count) {
1377                 ret = rpc_port_stub_vcd_mgr_stub_vc_mgr_register(&g_mgr_callback, NULL);
1378                 if (0 == ret) {
1379                         SLOG(LOG_DEBUG, TAG_VCD, "register callback");
1380                         return VCD_ERROR_NONE;
1381                 }
1382                 usleep(100000);
1383                 count++;
1384         }
1385
1386         SLOG(LOG_ERROR, TAG_VCD, "Fail to register callback(%d)", ret);
1387         return VCD_ERROR_OPERATION_FAILED;
1388 }
1389
1390 int __mgr_tidl_close_connection()
1391 {
1392         SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Close connection");
1393         rpc_port_stub_vcd_mgr_stub_vc_mgr_unregister();
1394
1395         return VCD_ERROR_NONE;
1396 }
1397
1398 /**
1399  * TIDL callback functions for VC widget
1400  */
1401 static void __widget_on_connected(rpc_port_proxy_vcd_widget_proxy_vcd_widget_h h, void *user_data)
1402 {
1403         widget_tidl_info_s* widget_tidl_info = vcd_client_widget_get_tidl_info((int)user_data);
1404
1405         widget_tidl_info->connected = true;
1406         widget_tidl_info->connection_requesting = false;
1407
1408         SLOG(LOG_INFO, TAG_VCD, "Connected to widget");
1409 }
1410
1411 static void __widget_on_disconnected(rpc_port_proxy_vcd_widget_proxy_vcd_widget_h h, void *user_data)
1412 {
1413         widget_tidl_info_s* widget_tidl_info = vcd_client_widget_get_tidl_info((int)user_data);
1414
1415         widget_tidl_info->connected = false;
1416         widget_tidl_info->connection_requesting = false;
1417
1418         SLOG(LOG_INFO, TAG_VCD, "Disonnected to widget");
1419 }
1420
1421 static void __widget_on_rejected(rpc_port_proxy_vcd_widget_proxy_vcd_widget_h h, void *user_data)
1422 {
1423         widget_tidl_info_s* widget_tidl_info = vcd_client_widget_get_tidl_info((int)user_data);
1424
1425         widget_tidl_info->connection_requesting = false;
1426
1427         SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Rejected from widget");
1428 }
1429
1430 static rpc_port_proxy_vcd_widget_proxy_vcd_widget_h __widget_create_rpc_port(const char* engine_app_id, int pid)
1431 {
1432         SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] __widget_create_rpc_port");
1433         rpc_port_proxy_vcd_widget_proxy_vcd_widget_callback_s rpc_callback = {
1434                 .connected = __widget_on_connected,
1435                 .disconnected = __widget_on_disconnected,
1436                 .rejected = __widget_on_rejected
1437         };
1438
1439         rpc_port_proxy_vcd_widget_proxy_vcd_widget_h handle = NULL;
1440         if (0 != rpc_port_proxy_vcd_widget_proxy_vcd_widget_create(engine_app_id, &rpc_callback, (void *)pid, &handle)) {
1441                 SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to create proxy");
1442                 return NULL;
1443         }
1444
1445         return handle;
1446 }
1447
1448 static void __vc_widget_create_cb(rpc_port_stub_vcd_widget_stub_vc_widget_context_h context, void *user_data)
1449 {
1450         char *sender = NULL;
1451
1452         rpc_port_stub_vcd_widget_stub_vc_widget_context_get_sender(context, &sender);
1453         if (!sender) {
1454                 SLOG(LOG_ERROR, TAG_VCD, "Sender is NULL");
1455                 return;
1456         }
1457
1458         SLOG(LOG_DEBUG, TAG_VCD, "@@@ Widget connect. appid(%s)", sender);
1459         free(sender);
1460 }
1461
1462 static void __vc_widget_terminate_cb(rpc_port_stub_vcd_widget_stub_vc_widget_context_h context, void *user_data)
1463 {
1464         void* tag = NULL;
1465         rpc_port_stub_vcd_widget_stub_vc_widget_context_get_tag(context, &tag);
1466
1467         if (NULL != tag) {
1468                 int pid = (intptr_t)tag;
1469                 SLOG(LOG_DEBUG, TAG_VCD, "@@@ VC WIDGET FINALIZE. pid(%u)", pid);
1470
1471                 pthread_mutex_lock(&g_widget_tidl_info_mutex);
1472                 widget_tidl_info_s* widget_tidl_info = vcd_client_widget_get_tidl_info(pid);
1473                 if (NULL == widget_tidl_info) {
1474                         SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to get widget tidl info.");
1475                         pthread_mutex_unlock(&g_widget_tidl_info_mutex);
1476                         return;
1477                 }
1478
1479                 if (0 != vcd_client_widget_unset_tidl_notify_cb(pid)) {
1480                         SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to unset notify callback");
1481                 }
1482
1483                 if (0 != vcd_client_widget_delete_tidl_info(pid)) {
1484                         SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to delete widget tidl info");
1485                 }
1486                 widget_tidl_info = NULL;
1487
1488                 SLOG(LOG_DEBUG, TAG_VCD, "@@@");
1489
1490                 pthread_mutex_unlock(&g_widget_tidl_info_mutex);
1491
1492                 char *sender = NULL;
1493                 rpc_port_stub_vcd_widget_stub_vc_widget_context_get_sender(context, &sender);
1494                 if (!sender)
1495                         return;
1496
1497                 SLOG(LOG_INFO, TAG_VCD, "@@@ Manager disconnect. appid(%s)", sender);
1498
1499                 free(sender);
1500         }
1501         rpc_port_stub_vcd_widget_stub_vc_widget_context_set_tag(context, NULL);
1502 }
1503
1504 static void  __vc_widget_register_cb_cb(rpc_port_stub_vcd_widget_stub_vc_widget_context_h context, int pid, rpc_port_stub_vcd_widget_stub_vc_widget_notify_cb_h notify_callback, void *user_data)
1505 {
1506         pthread_mutex_lock(&g_widget_tidl_info_mutex);
1507         SLOG(LOG_INFO, TAG_VCD, "@@@ VC WIDGET REGISTER CALLBACK");
1508
1509         int ret = -1;
1510         ret = vcd_client_widget_add_tidl_info(pid);
1511
1512         if (0 != ret) {
1513                 SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to add widget tidl info.");
1514                 pthread_mutex_unlock(&g_widget_tidl_info_mutex);
1515                 return;
1516         }
1517         widget_tidl_info_s* widget_tidl_info = vcd_client_widget_get_tidl_info(pid);
1518
1519         if (NULL == widget_tidl_info) {
1520                 SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to get widget tidl info. pid(%d)", pid);
1521                 pthread_mutex_unlock(&g_widget_tidl_info_mutex);
1522                 return;
1523         }
1524
1525         char *sender = NULL;
1526         rpc_port_stub_vcd_widget_stub_vc_widget_context_get_sender(context, &sender);
1527
1528         if (!sender){
1529                 SLOG(LOG_ERROR, TAG_VCD, "Sender is NULL");
1530                 pthread_mutex_unlock(&g_widget_tidl_info_mutex);
1531                 return;
1532         }
1533
1534         widget_tidl_info->rpc_h = __widget_create_rpc_port(sender, pid);
1535
1536         if (NULL == widget_tidl_info->rpc_h) {
1537                 SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to create server proxy");
1538         } else {
1539                 SLOG(LOG_INFO, TAG_VCD, "[TIDL] rpc_h(%p), engine_app_id(%s)", widget_tidl_info->rpc_h, sender);
1540         }
1541
1542         free(sender);
1543
1544         if (0 != vcd_client_widget_set_tidl_notify_cb(pid, notify_callback, user_data)) {
1545                 SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to set notify callback");
1546         } else {
1547                 SLOG(LOG_INFO, TAG_VCD, "[TIDL] Succeed to set notify callback.");
1548         }
1549
1550         pthread_mutex_unlock(&g_widget_tidl_info_mutex);
1551
1552         __request_tidl_connect(VCD_CLIENT_TYPE_WIDGET, pid);
1553
1554         SLOG(LOG_DEBUG, TAG_VCD, "@@@");
1555 }
1556
1557 static int  __vc_widget_initialize_cb(rpc_port_stub_vcd_widget_stub_vc_widget_context_h context, int pid, int *service_state, int *daemon_pid, void *user_data)
1558 {
1559         SLOG(LOG_INFO, TAG_VCD, "@@@ VCD Widget Initialize");
1560
1561         uintptr_t ptr_pid = pid;
1562         int ret = -1;
1563
1564         rpc_port_stub_vcd_widget_stub_vc_widget_context_set_tag(context, (void*)ptr_pid);
1565
1566         ret = vcd_server_widget_initialize(pid);
1567         if (0 != ret) {
1568                 SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret);
1569                 return ret;
1570         }
1571         *service_state = vcd_server_get_service_state();
1572         *daemon_pid = getpid();
1573
1574         SLOG(LOG_INFO, TAG_VCD, "[IN] vcd widget initialize : pid(%d) service state(%d) daemon_pid(%d)", pid, *service_state, *daemon_pid);
1575         SLOG(LOG_DEBUG, TAG_VCD, "@@@");
1576         return ret;
1577 }
1578
1579 static int  __vc_widget_finalize_cb(rpc_port_stub_vcd_widget_stub_vc_widget_context_h context, int pid, void *user_data)
1580 {
1581         SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Widget Finalize");
1582         SLOG(LOG_INFO, TAG_VCD, "[IN] vcd widget finalize : pid(%d)", pid);
1583
1584         int ret = -1;
1585
1586         ret = vcd_server_widget_finalize(pid);
1587         if (0 != ret) {
1588                 SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret);
1589                 return ret;
1590         }
1591
1592         SLOG(LOG_DEBUG, TAG_VCD, "@@@");
1593
1594         return ret;
1595 }
1596
1597 static int __vc_widget_start_recording_cb(rpc_port_stub_vcd_widget_stub_vc_widget_context_h context, int pid, int command, void *user_data)
1598 {
1599         SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Widget Start Recording");
1600         SLOG(LOG_INFO, TAG_VCD, "[IN] vcd widget start recording : pid(%d) command(%d)", pid, command);
1601
1602         int ret = -1;
1603
1604         ret = vcd_server_widget_start_recording(pid, command);
1605         if (0 != ret) {
1606                 SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret);
1607                 return ret;
1608         }
1609
1610         SLOG(LOG_DEBUG, TAG_VCD, "@@@");
1611
1612         return ret;
1613 }
1614
1615 static int __vc_widget_start_cb(rpc_port_stub_vcd_widget_stub_vc_widget_context_h context, int pid, int silence, void *user_data)
1616 {
1617         SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Widget Start");
1618         SLOG(LOG_INFO, TAG_VCD, "[IN] vcd widget start : pid(%d) silence(%d)", pid, silence);
1619
1620         int ret = -1;
1621
1622         ret = vcd_server_widget_start(pid, (bool)silence);
1623         if (0 != ret) {
1624                 SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret);
1625                 return ret;
1626         }
1627
1628         SLOG(LOG_DEBUG, TAG_VCD, "@@@");
1629
1630         return ret;
1631 }
1632
1633 static int __vc_widget_stop_cb(rpc_port_stub_vcd_widget_stub_vc_widget_context_h context, int pid, void *user_data)
1634 {
1635         SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Widget Stop");
1636         SLOG(LOG_INFO, TAG_VCD, "[IN] vcd widget stop : pid(%d)", pid);
1637
1638         int ret = -1;
1639
1640         ret = vcd_server_widget_stop(pid);
1641         if (0 != ret) {
1642                 SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret);
1643                 return ret;
1644         }
1645
1646         SLOG(LOG_DEBUG, TAG_VCD, "@@@");
1647
1648         return ret;
1649 }
1650
1651 static int __vc_widget_cancel_cb(rpc_port_stub_vcd_widget_stub_vc_widget_context_h context, int pid, void *user_data)
1652 {
1653         SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Widget Cancel");
1654         SLOG(LOG_INFO, TAG_VCD, "[IN] vcd widget cancel : pid(%d)", pid);
1655
1656         int ret = -1;
1657
1658         ret = vcd_server_widget_cancel(pid);
1659         if (0 != ret) {
1660                 SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret);
1661                 return ret;
1662         }
1663
1664         SLOG(LOG_DEBUG, TAG_VCD, "@@@");
1665
1666         return ret;
1667 }
1668
1669 static int __vc_widget_enable_asr_result_cb(rpc_port_stub_vcd_widget_stub_vc_widget_context_h context, int pid, int enable, void *user_data)
1670 {
1671         SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Widget Enable Asr Result");
1672         SLOG(LOG_INFO, TAG_VCD, "[IN] vcd widget enable asr result : pid(%d) enable(%d)", pid, enable);
1673
1674         int ret = -1;
1675
1676         ret = vcd_server_widget_enable_asr_result(pid, enable);
1677         if (0 != ret) {
1678                 SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret);
1679                 return ret;
1680         }
1681
1682         SLOG(LOG_DEBUG, TAG_VCD, "@@@");
1683
1684         return ret;
1685 }
1686
1687 static void __vc_widget_set_foreground_cb(rpc_port_stub_vcd_widget_stub_vc_widget_context_h context, int pid, int value, void *user_data)
1688 {
1689         SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Widget Set Foreground");
1690         SLOG(LOG_INFO, TAG_VCD, "[IN] vcd widget set foreground : pid(%d) value(%d)", pid, value);
1691
1692         int ret = -1;
1693
1694         ret = vcd_server_set_foreground(pid, value);
1695         if (0 != ret) {
1696                 SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret);
1697                 return;
1698         }
1699
1700         SLOG(LOG_DEBUG, TAG_VCD, "@@@ send request set foreground to manager");
1701         vcdc_send_request_set_foreground(pid, value);
1702
1703         SLOG(LOG_DEBUG, TAG_VCD, "@@@");
1704
1705         return;
1706 }
1707
1708 int __widget_tidl_open_connection()
1709 {
1710         SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] __widget_tidl_open_connection");
1711
1712         g_widget_callback.create = __vc_widget_create_cb;
1713         g_widget_callback.terminate = __vc_widget_terminate_cb;
1714         g_widget_callback.register_cb = __vc_widget_register_cb_cb;
1715         g_widget_callback.initialize = __vc_widget_initialize_cb;
1716         g_widget_callback.finalize = __vc_widget_finalize_cb;
1717         g_widget_callback.start_recording = __vc_widget_start_recording_cb;
1718         g_widget_callback.start = __vc_widget_start_cb;
1719         g_widget_callback.stop = __vc_widget_stop_cb;
1720         g_widget_callback.cancel = __vc_widget_cancel_cb;
1721         g_widget_callback.enable_asr_result = __vc_widget_enable_asr_result_cb;
1722         g_widget_callback.set_foreground = __vc_widget_set_foreground_cb;
1723
1724         int ret = -1;
1725         int count = 0;
1726         while (VC_RETRY_MIN_COUNT >= count) {
1727                 ret = rpc_port_stub_vcd_widget_stub_vc_widget_register(&g_widget_callback, NULL);
1728                 if (0 == ret) {
1729                         SLOG(LOG_DEBUG, TAG_VCD, "register callback");
1730                         return VCD_ERROR_NONE;
1731                 }
1732                 usleep(100000);
1733                 count++;
1734         }
1735
1736         SLOG(LOG_ERROR, TAG_VCD, "Fail to register callback(%d)", ret);
1737         return VCD_ERROR_OPERATION_FAILED;
1738 }
1739
1740 int __widget_tidl_close_connection()
1741 {
1742         SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Close connection");
1743         rpc_port_stub_vcd_widget_stub_vc_widget_unregister();
1744
1745         return VCD_ERROR_NONE;
1746 }
1747
1748 /**
1749  * TIDL callback functions for VC setting client
1750  */
1751 static void __vc_setting_create_cb(rpc_port_stub_vcd_setting_stub_vc_setting_context_h context, void *user_data)
1752 {
1753         SLOG(LOG_INFO, TAG_VCD, "[TIDL] __vc_setting_create_cb");
1754
1755         char *sender = NULL;
1756
1757         rpc_port_stub_vcd_setting_stub_vc_setting_context_get_sender(context, &sender);
1758         if (!sender) {
1759                 SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Sender is NULL");
1760                 return;
1761         }
1762
1763         SLOG(LOG_INFO, TAG_VCD, "[TIDL] sender(%s)", sender);           // sender (app_id)
1764         free(sender);
1765 }
1766
1767 static void __vc_setting_terminate_cb(rpc_port_stub_vcd_setting_stub_vc_setting_context_h context, void *user_data)
1768 {
1769         SLOG(LOG_INFO, TAG_VCD, "[TIDL] __vc_setting_terminate_cb");
1770         void* tag = NULL;
1771         rpc_port_stub_vcd_setting_stub_vc_setting_context_get_tag(context, &tag);
1772
1773         if (NULL != tag) {
1774                 int pid = (intptr_t)tag;
1775                 SLOG(LOG_DEBUG, TAG_VCD, "@@@ VC SETTING FINALIZE. pid(%u)", pid);
1776
1777                 pthread_mutex_lock(&g_setting_tidl_info_mutex);
1778                 setting_tidl_info_s* setting_tidl_info = vcd_client_setting_get_tidl_info(pid);
1779                 if (NULL == setting_tidl_info) {
1780                         SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to get setting tidl info.");
1781                         pthread_mutex_unlock(&g_setting_tidl_info_mutex);
1782                         return;
1783                 }
1784
1785                 if (0 != vcd_client_setting_unset_tidl_notify_cb(pid)) {
1786                         SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to unset notify callback");
1787                 }
1788
1789                 if (0 != vcd_client_setting_delete_tidl_info(pid)) {
1790                         SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to delete setting tidl info");
1791                 }
1792                 setting_tidl_info = NULL;
1793
1794                 SLOG(LOG_DEBUG, TAG_VCD, "@@@");
1795
1796                 pthread_mutex_unlock(&g_setting_tidl_info_mutex);
1797         }
1798         rpc_port_stub_vcd_setting_stub_vc_setting_context_set_tag(context, NULL);
1799 }
1800
1801 static void __vc_setting_register_notify_cb_cb(rpc_port_stub_vcd_setting_stub_vc_setting_context_h context, int pid, rpc_port_stub_vcd_setting_stub_vc_setting_notify_cb_h callback, void *user_data)
1802 {
1803         SLOG(LOG_INFO, TAG_VCD, "[TIDL] __vc_setting_register_notify_cb_cb. pid(%d)", pid);
1804
1805         if (NULL == callback) {
1806                 SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] callback is null.");
1807                 return;
1808         }
1809
1810         int ret = -1;
1811         ret = vcd_client_setting_add_tidl_info(pid);
1812         if (0 != ret) {
1813                 SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to add tidl info.");
1814                 return;
1815         }
1816
1817         ret = vcd_client_setting_set_tidl_notify_cb(pid, callback, user_data);
1818         if (0 != ret) {
1819                 SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to set notify callback.");
1820         } else {
1821                 SLOG(LOG_INFO, TAG_VCD, "[TIDL] Succeed to set notify callback.");
1822         }
1823 }
1824
1825 static int __vc_setting_register_notify_cb_sync_cb(rpc_port_stub_vcd_setting_stub_vc_setting_context_h context, int pid, rpc_port_stub_vcd_setting_stub_vc_setting_notify_cb_h callback, void *user_data)
1826 {
1827         SLOG(LOG_INFO, TAG_VCD, "[TIDL] __vc_setting_register_notify_cb_sync_cb. pid(%d)", pid);
1828
1829         if (NULL == callback) {
1830                 SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] callback is null.");
1831                 return VCD_ERROR_INVALID_PARAMETER;
1832         }
1833
1834         int ret = -1;
1835         ret = vcd_client_setting_add_tidl_info(pid);
1836         if (0 != ret) {
1837                 SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to add tidl info.");
1838                 return ret;
1839         }
1840         
1841         ret = vcd_client_setting_set_tidl_notify_cb(pid, callback, user_data);
1842         if (0 != ret) {
1843                 SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to set notify callback.");
1844         } else {
1845                 SLOG(LOG_INFO, TAG_VCD, "[TIDL] Succeed to set notify callback.");
1846         }
1847
1848         return ret;
1849 }
1850
1851 int  __vc_setting_set_language_cb(rpc_port_stub_vcd_setting_stub_vc_setting_context_h context, int pid, const char *language, void *user_data)
1852 {
1853         if (NULL == language) {
1854                 SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Invalid parameter");
1855                 return VCD_ERROR_INVALID_PARAMETER;
1856         }
1857
1858         SLOG(LOG_INFO, TAG_VCD, "[IN] vcd server set language : language(%s)", language);
1859
1860         int ret = vcd_server_set_language(language);
1861         if (0 != ret) {
1862                 SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to set language(%d).", ret);
1863         } else {
1864                 SLOG(LOG_INFO, TAG_VCD, "[TIDL] Succeed to set language.");
1865         }
1866
1867         return ret;
1868 }
1869
1870 int __setting_tidl_open_connection()
1871 {
1872         SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] __setting_tidl_open_connection");
1873
1874         g_setting_callback.create = __vc_setting_create_cb;
1875         g_setting_callback.terminate = __vc_setting_terminate_cb;
1876         g_setting_callback.register_notify_cb = __vc_setting_register_notify_cb_cb;
1877         g_setting_callback.register_notify_cb_sync = __vc_setting_register_notify_cb_sync_cb;
1878         g_setting_callback.set_language = __vc_setting_set_language_cb;
1879
1880         int ret = -1;
1881         int count = 0;
1882         while (VC_RETRY_MIN_COUNT >= count) {
1883                 ret = rpc_port_stub_vcd_setting_stub_vc_setting_register(&g_setting_callback, NULL);
1884                 if (0 == ret) {
1885                         SLOG(LOG_DEBUG, TAG_VCD, "register callback");
1886                         return VCD_ERROR_NONE;
1887                 }
1888                 usleep(100000);
1889                 count++;
1890         }
1891
1892         SLOG(LOG_ERROR, TAG_VCD, "Fail to register callback(%d)", ret);
1893         return VCD_ERROR_OPERATION_FAILED;
1894 }
1895
1896 int __setting_tidl_close_connection()
1897 {
1898         SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Close connection");
1899         rpc_port_stub_vcd_setting_stub_vc_setting_unregister();
1900
1901         return VCD_ERROR_NONE;
1902 }
1903
1904
1905 /**
1906  * Functions for sending the information to client sides
1907  */
1908 int vcdc_send_error_signal_to_app(int pid, int reason, char *err_msg)
1909 {
1910         if (NULL == err_msg) {
1911                 SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Input parameter is NULL");
1912                 return VCD_ERROR_INVALID_PARAMETER;
1913         }
1914
1915         client_tidl_info_s* info = vcd_client_get_tidl_info(pid);
1916         if (NULL == info) {
1917                 SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to get tidl info. pid(%d)", pid);
1918                 return VCD_ERROR_INVALID_PARAMETER;
1919         }
1920
1921         bundle* msg = bundle_create();
1922         if (NULL == msg) {
1923                 SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to create bundle data");
1924                 return VCD_ERROR_OUT_OF_MEMORY;
1925         }
1926
1927         SLOG(LOG_INFO, TAG_VCD, "[TIDL] Send error signal to app(%d)", pid);
1928
1929         char pid_char[10] = {0};
1930         char reason_char[10] = {0};
1931         snprintf(pid_char, 10, "%d", pid);
1932         snprintf(reason_char, 10, "%d", reason);
1933
1934         bundle_add_str(msg, VC_BUNDLE_METHOD, VCD_METHOD_ERROR_TO_APP);
1935         bundle_add_str(msg, VC_BUNDLE_PID, pid_char);
1936         bundle_add_str(msg, VC_BUNDLE_REASON, reason_char);
1937         bundle_add_str(msg, VC_BUNDLE_ERR_MSG, err_msg);
1938
1939         rpc_port_stub_vcd_stub_vc_notify_cb_invoke(info->notify_cb, pid, msg);
1940
1941         return VCD_ERROR_NONE;
1942 }
1943
1944 int vcdc_send_manager_pid(int manager_pid)
1945 {
1946         // send signal to all pid
1947
1948         // get all pids
1949         int* client_list = NULL;
1950         int client_count = 0;
1951         int ret = -1;
1952         ret = vcd_client_get_tidl_list(&client_list, &client_count);
1953         if (0 != ret || 0 == client_count) {
1954                 SLOG(LOG_WARN, TAG_VCD, "[WARNING] There is no client");
1955                 return VCD_ERROR_NONE;
1956         }
1957
1958         client_tidl_info_s* info;
1959         int pid = -1;
1960         bundle* msg;
1961         char pid_char[10] = {0};
1962         char mgrpid_char[10] = {0};
1963         for (int i = 0 ; i < client_count ; i++) {
1964                 pid = client_list[i];
1965
1966                 info = vcd_client_get_tidl_info(pid);
1967                 if (NULL == info) {
1968                         SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to get tidl info. pid(%d)", pid);
1969                         continue;
1970                 }
1971
1972                 msg = bundle_create();
1973                 if (NULL == msg) {
1974                         SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to create bundle data");
1975                         continue;
1976                 }
1977
1978                 SLOG(LOG_INFO, TAG_VCD, "[TIDL] Send manager pid(%d) to app(%d)", manager_pid, pid);
1979
1980                 snprintf(pid_char, 10, "%d", pid);
1981                 snprintf(mgrpid_char, 10, "%d", manager_pid);
1982
1983                 bundle_add_str(msg, VC_BUNDLE_METHOD, VCD_METHOD_SEND_MANAGER_PID);
1984                 bundle_add_str(msg, VC_BUNDLE_PID, pid_char);
1985                 bundle_add_str(msg, VC_BUNDLE_MANAGER_PID, mgrpid_char);
1986
1987                 rpc_port_stub_vcd_stub_vc_notify_cb_invoke(info->notify_cb, pid, msg);
1988
1989                 bundle_free(msg);
1990         }
1991
1992         return VCD_ERROR_NONE;
1993 }
1994
1995 int vcdc_send_feedback_streaming(int pid, int utt_id, vc_feedback_event_e event, char* buffer, int len)
1996 {
1997         if (NULL == buffer || 0 >= len) {
1998                 SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Invalid parameter");
1999                 return VCD_ERROR_INVALID_PARAMETER;
2000         }
2001
2002         client_tidl_info_s* info = vcd_client_get_tidl_info(pid);
2003         if (NULL == info) {
2004                 SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to get tidl info. pid(%d)", pid);
2005                 return VCD_ERROR_NONE;
2006         }
2007
2008         SLOG(LOG_INFO, TAG_VCD, "[TIDL] Send feedback streaming to app(%d), utt_id(%d), event(%d), length(%d)", pid, utt_id, event, len);
2009
2010         rpc_port_stub_vcd_stub_array_char_h arr_char = NULL;
2011         rpc_port_stub_vcd_stub_array_char_create(&arr_char);
2012         rpc_port_stub_vcd_stub_array_char_set(arr_char, buffer, len);
2013
2014         rpc_port_stub_vcd_stub_vc_feedback_cb_invoke(info->feedback_cb, utt_id, event, arr_char, len);
2015
2016         rpc_port_stub_vcd_stub_array_char_destroy(arr_char);
2017
2018
2019         return VCD_ERROR_NONE;
2020 }
2021
2022 int vcdc_send_hello(int pid, vcd_client_type_e type)
2023 {
2024         SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Send hello");
2025
2026         char tmp_pid[10] = {0, };
2027
2028         bundle* msg = bundle_create();
2029         snprintf(tmp_pid, 10, "%d", pid);
2030
2031         if (VCD_CLIENT_TYPE_NORMAL == type) {
2032                 bundle_add_str(msg, VC_BUNDLE_METHOD, VCD_METHOD_HELLO);
2033                 bundle_add_str(msg, VC_BUNDLE_PID, tmp_pid);
2034         } else if (VCD_CLIENT_TYPE_MANAGER == type) {
2035                 bundle_add_str(msg, VC_BUNDLE_METHOD, VCD_MANAGER_METHOD_HELLO);
2036                 bundle_add_str(msg, VC_BUNDLE_PID, tmp_pid);
2037         } else if (VCD_CLIENT_TYPE_WIDGET == type) {
2038                 bundle_add_str(msg, VC_BUNDLE_METHOD, VCD_WIDGET_METHOD_HELLO);
2039                 bundle_add_str(msg, VC_BUNDLE_PID, tmp_pid);
2040         } else {
2041                 SLOG(LOG_ERROR, TAG_VCD, "[Dbus ERROR] Client type is NOT valid");
2042                 bundle_free(msg);
2043                 return VCD_ERROR_INVALID_PARAMETER;
2044         }
2045
2046         SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] VCD SEND MESSAGE");
2047
2048         // TODO: VCD_CLIENT_TYPE_MANAGER?? type??
2049         __send_msg(msg, VCD_CLIENT_TYPE_MANAGER, pid);
2050         bundle_free(msg);
2051
2052         return VCD_ERROR_NONE;
2053 }
2054
2055 int vcd_tidl_open_connection()
2056 {
2057         SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] vcd_tidl_open_connection");
2058
2059         if (0 != __mgr_tidl_open_connection()) {
2060                 SLOG(LOG_ERROR, TAG_VCD, "Fail to open connection to manager");
2061                 return VCD_ERROR_OPERATION_FAILED;
2062         }
2063
2064         if (0 != __client_tidl_open_connection()) {
2065                 SLOG(LOG_ERROR, TAG_VCD, "Fail to open connection to client");
2066                 return VCD_ERROR_OPERATION_FAILED;
2067         }
2068
2069         if (0 != __widget_tidl_open_connection()) {
2070                 SLOG(LOG_ERROR, TAG_VCD, "Fail to open connection to widget");
2071                 return VCD_ERROR_OPERATION_FAILED;
2072         }
2073
2074         if (0 != __setting_tidl_open_connection()) {
2075                 SLOG(LOG_ERROR, TAG_VCD, "Fail to open connection to setting");
2076                 return VCD_ERROR_OPERATION_FAILED;
2077         }
2078
2079         return VCD_ERROR_NONE;
2080 }
2081
2082 int vcd_tidl_close_connection()
2083 {
2084         SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] vcd_tidl_close_connection");
2085
2086         if (0 != __mgr_tidl_close_connection()) {
2087                 SLOG(LOG_ERROR, TAG_VCD, "Fail to close connection to manager");
2088                 return VCD_ERROR_OPERATION_FAILED;
2089         }
2090
2091         if (0 != __client_tidl_close_connection()) {
2092                 SLOG(LOG_ERROR, TAG_VCD, "Fail to close connection to client");
2093                 return VCD_ERROR_OPERATION_FAILED;
2094         }
2095
2096         if (0 != __widget_tidl_close_connection()) {
2097                 SLOG(LOG_ERROR, TAG_VCD, "Fail to close connection to widget");
2098                 return VCD_ERROR_OPERATION_FAILED;
2099         }
2100
2101         if (0 != __setting_tidl_close_connection()) {
2102                 SLOG(LOG_ERROR, TAG_VCD, "Fail to close connection to setting");
2103                 return VCD_ERROR_OPERATION_FAILED;
2104         }
2105
2106         return VCD_ERROR_NONE;
2107 }
2108
2109 int vcdc_send_set_volume(int manager_pid, float volume)
2110 {
2111         SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Set volume");
2112
2113         char tmp_volume[20] = {0, };
2114
2115         bundle* msg = bundle_create();
2116
2117         snprintf(tmp_volume, 20, "%.6f", volume);
2118         bundle_add_str(msg, VC_BUNDLE_METHOD, VCD_MANAGER_METHOD_SET_VOLUME);
2119         bundle_add_str(msg, VC_BUNDLE_VOLUME, tmp_volume);
2120
2121
2122         SLOG(LOG_DEBUG, TAG_VCD, ">>>> VCD SEND MESSAGE");
2123         __send_msg(msg, VCD_CLIENT_TYPE_MANAGER, manager_pid);
2124         if (20 == g_volume_count) {
2125                 SLOG(LOG_INFO, TAG_VCD, "@@ Send set volume : pid(%d), volume(%f)", manager_pid, volume);
2126                 g_volume_count = 0;
2127         }
2128         g_volume_count++;
2129
2130         bundle_free(msg);
2131
2132         return VCD_ERROR_NONE;
2133 }
2134
2135 int vcdc_send_show_tooltip(int pid, bool show)
2136 {
2137         SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Send pre result to manager");
2138
2139         char tmp_pid[10] = {0, };
2140         char tmp_show[10] = {0, };
2141
2142         bundle* msg = bundle_create();
2143
2144         snprintf(tmp_pid, 10, "%d", pid);
2145         snprintf(tmp_show, 10, "%d", (int)show);
2146
2147         bundle_add_str(msg, VC_BUNDLE_METHOD, VCD_WIDGET_METHOD_SHOW_TOOLTIP);
2148         bundle_add_str(msg, VC_BUNDLE_PID, tmp_pid);
2149         bundle_add_str(msg, VC_BUNDLE_SHOW, tmp_show);
2150
2151         SLOG(LOG_DEBUG, TAG_VCD, ">>>> VCD SEND MESSAGE");
2152
2153         __send_msg(msg, VCD_CLIENT_TYPE_WIDGET, pid);
2154         bundle_free(msg);
2155
2156         return VCD_ERROR_NONE;
2157 }
2158
2159 int vcdc_send_result(int pid, int manager_pid, int cmd_type)
2160 {
2161         SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Send result");
2162
2163         vcd_client_type_e type;
2164         bundle* msg = bundle_create();
2165         if (NULL == msg) {
2166                 SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to create bundle data");
2167                 return VCD_ERROR_OUT_OF_MEMORY;
2168         }
2169
2170         SLOG(LOG_INFO, TAG_VCD, "[TIDL] Result command type(%d)", cmd_type);
2171
2172         switch (cmd_type) {
2173         case VC_COMMAND_TYPE_FOREGROUND:
2174         case VC_COMMAND_TYPE_BACKGROUND:
2175                 if (pid == manager_pid) {
2176                         type = VCD_CLIENT_TYPE_MANAGER;
2177                         bundle_add_str(msg, VC_BUNDLE_METHOD, VCD_MANAGER_METHOD_RESULT);
2178                 } else {
2179                         type = VCD_CLIENT_TYPE_NORMAL;
2180                         char pid_char[10] = {0};
2181                         snprintf(pid_char, 10, "%d", pid);
2182                         bundle_add_str(msg, VC_BUNDLE_PID, pid_char);
2183                         bundle_add_str(msg, VC_BUNDLE_METHOD, VCD_METHOD_RESULT);
2184                 }
2185                 break;
2186         case VC_COMMAND_TYPE_WIDGET:
2187                 type = VCD_CLIENT_TYPE_WIDGET;
2188                 bundle_add_str(msg, VC_BUNDLE_METHOD, VCD_WIDGET_METHOD_RESULT);
2189                 break;
2190         case VC_COMMAND_TYPE_SYSTEM:
2191         case VC_COMMAND_TYPE_SYSTEM_BACKGROUND:
2192         case VC_COMMAND_TYPE_EXCLUSIVE:
2193                 type = VCD_CLIENT_TYPE_MANAGER;
2194                 bundle_add_str(msg, VC_BUNDLE_METHOD, VCD_MANAGER_METHOD_RESULT);
2195                 break;
2196
2197         default:
2198                 SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Command type is NOT valid(%d)", cmd_type);
2199                 bundle_free(msg);
2200                 return VCD_ERROR_INVALID_PARAMETER;
2201         }
2202
2203         SLOG(LOG_DEBUG, TAG_VCD, ">>>> VCD SEND MESSAGE");
2204
2205         __send_msg(msg, type, pid);
2206         bundle_free(msg);
2207
2208         return VCD_ERROR_NONE;
2209 }
2210
2211 int vcdc_send_pre_result_to_manager(int manager_pid, int event, const char* pre_result)
2212 {
2213         SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Send pre result to manager");
2214
2215         char tmp_event[10] = {0, };
2216
2217         bundle* msg = bundle_create();
2218         snprintf(tmp_event, 10, "%d", event);
2219
2220         bundle_add_str(msg, VC_BUNDLE_METHOD, VCD_MANAGER_METHOD_PRE_RESULT);
2221         bundle_add_str(msg, VC_BUNDLE_EVENT, tmp_event);
2222         bundle_add_str(msg, VC_BUNDLE_PRE_RESULT, pre_result);
2223
2224         SLOG(LOG_DEBUG, TAG_VCD, ">>>> VCD SEND MESSAGE");
2225
2226         __send_msg(msg, VCD_CLIENT_TYPE_MANAGER, manager_pid);
2227         bundle_free(msg);
2228
2229         return VCD_ERROR_NONE;
2230 }
2231
2232 int vcdc_send_specific_engine_result_to_manager(int manager_pid, const char* engine_app_id, const char* event, const char* result)
2233 {
2234         SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Send specific engine result to manager");
2235
2236         bundle* msg = bundle_create();
2237
2238         gchar *gEncodedResult = g_base64_encode((const guchar*)result, strlen(result));
2239
2240         bundle_add_str(msg, VC_BUNDLE_METHOD, VCD_MANAGER_METHOD_SPECIFIC_ENGINE_RESULT);
2241         bundle_add_str(msg, VC_BUNDLE_ENGINE_APP_ID, engine_app_id);
2242         bundle_add_str(msg, VC_BUNDLE_EVENT, event);
2243         bundle_add_str(msg, VC_BUNDLE_RESULT, gEncodedResult);
2244
2245         SLOG(LOG_DEBUG, TAG_VCD, ">>>> VCD SEND MESSAGE");
2246
2247         __send_msg(msg, VCD_CLIENT_TYPE_MANAGER, manager_pid);
2248         bundle_free(msg);
2249
2250         if (gEncodedResult)
2251                 g_free(gEncodedResult);
2252
2253         return VCD_ERROR_NONE;
2254 }
2255
2256 int vcdc_send_result_to_manager(int manager_pid, int result_type)
2257 {
2258         SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Send result to manager");
2259
2260         char tmp_result[10] = {0, };
2261
2262         bundle* msg = bundle_create();
2263         snprintf(tmp_result, 10, "%d", result_type);
2264
2265         bundle_add_str(msg, VC_BUNDLE_METHOD, VCD_MANAGER_METHOD_ALL_RESULT);
2266         bundle_add_str(msg, VC_BUNDLE_RESULT, tmp_result);
2267
2268
2269         SLOG(LOG_DEBUG, TAG_VCD, ">>>> VCD SEND MESSAGE");
2270
2271         __send_msg(msg, VCD_CLIENT_TYPE_MANAGER, manager_pid);
2272         bundle_free(msg);
2273
2274         return VCD_ERROR_NONE;
2275 }
2276
2277 int vcdc_send_speech_detected(int manager_pid)
2278 {
2279         SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Send speech detected");
2280
2281         bundle* msg = bundle_create();
2282
2283         bundle_add_str(msg, VC_BUNDLE_METHOD, VCD_MANAGER_METHOD_SPEECH_DETECTED);
2284
2285         SLOG(LOG_DEBUG, TAG_VCD, ">>>> VCD SEND MESSAGE");
2286
2287         __send_msg(msg, VCD_CLIENT_TYPE_MANAGER, manager_pid);
2288         bundle_free(msg);
2289
2290         return VCD_ERROR_NONE;
2291 }
2292
2293 int vcdc_send_service_state(vcd_state_e state)
2294 {
2295         SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Send service state");
2296
2297         char tmp_state[10] = {0, };
2298
2299         bundle* msg = bundle_create();
2300         snprintf(tmp_state, 10, "%d", (int)state);
2301
2302         bundle_add_str(msg, VC_BUNDLE_METHOD, VCD_MANAGER_METHOD_SET_SERVICE_STATE);
2303         bundle_add_str(msg, VC_BUNDLE_SERVICE_STATE, tmp_state);
2304         __send_signal(msg, VCD_CLIENT_TYPE_MANAGER);
2305
2306         bundle_add_str(msg, VC_BUNDLE_METHOD, VCD_METHOD_SET_SERVICE_STATE);
2307         bundle_add_str(msg, VC_BUNDLE_SERVICE_STATE, tmp_state);
2308         __send_signal(msg, VCD_CLIENT_TYPE_NORMAL);
2309
2310         bundle_add_str(msg, VC_BUNDLE_METHOD, VCD_WIDGET_METHOD_SET_SERVICE_STATE);
2311         bundle_add_str(msg, VC_BUNDLE_SERVICE_STATE, tmp_state);
2312         __send_signal(msg, VCD_CLIENT_TYPE_WIDGET);
2313
2314         SLOG(LOG_DEBUG, TAG_VCD, ">>>> VCD SEND SIGNAL");
2315         bundle_free(msg);
2316
2317         return VCD_ERROR_NONE;
2318 }
2319
2320 int vcdc_send_dialog(int manager_pid, int pid, const char* disp_text, const char* utt_text, int continuous)
2321 {
2322         SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Send dialog");
2323
2324         char tmp_pid[10] = {0, };
2325         char tmp_continuous[10] = {0, };
2326         char* tmp_disp_text = NULL;
2327         char* tmp_utt_text = NULL;
2328         bundle* msg = bundle_create();
2329         snprintf(tmp_pid, 10, "%d", pid);
2330         snprintf(tmp_continuous, 10, "%d", continuous);
2331
2332         if (NULL == disp_text) {
2333                 tmp_disp_text = strdup("#NULL");
2334         } else {
2335                 tmp_disp_text = strdup(disp_text);
2336         }
2337
2338         if (NULL == utt_text) {
2339                 tmp_utt_text = strdup("#NULL");
2340         } else {
2341                 tmp_utt_text = strdup(utt_text);
2342         }
2343
2344         bundle_add_str(msg, VC_BUNDLE_METHOD, VCD_MANAGER_METHOD_DIALOG);
2345         bundle_add_str(msg, VC_BUNDLE_PID, tmp_pid);
2346         bundle_add_str(msg, VC_BUNDLE_DISP_TEXT, tmp_disp_text);
2347         bundle_add_str(msg, VC_BUNDLE_UTT_TEXT, tmp_utt_text);
2348         bundle_add_str(msg, VC_BUNDLE_CONTINUOUS, tmp_continuous);
2349
2350         SLOG(LOG_DEBUG, TAG_VCD, ">>>> VCD SEND MESSAGE");
2351
2352         __send_msg(msg, VCD_CLIENT_TYPE_MANAGER, manager_pid);
2353         bundle_free(msg);
2354         free(tmp_disp_text);
2355         free(tmp_utt_text);
2356
2357         return VCD_ERROR_NONE;
2358 }
2359
2360 int vcdc_send_error_to_manager(int manager_pid, int reason, char *err_msg)
2361 {
2362         SLOG(LOG_ERROR, TAG_VCD, "[TIDL] Send error signal to manager");
2363
2364         char tmp_reason[10] = {0, };
2365         char tmp_daemon_pid[10] = {0, };
2366         char *temp_msg = NULL;
2367
2368         if (NULL == err_msg) {
2369                 SLOG(LOG_WARN, TAG_VCD, "[TIDL ERROR] Input parameter is NULL");
2370                 temp_msg = strdup("#NULL");
2371         } else {
2372                 temp_msg = strdup(err_msg);
2373         }
2374
2375         bundle* msg = bundle_create();
2376         snprintf(tmp_reason, 10, "%d", reason);
2377         snprintf(tmp_daemon_pid, 10, "%d", getpid());
2378
2379         bundle_add_str(msg, VC_BUNDLE_METHOD, VCD_MANAGER_METHOD_ERROR);
2380         bundle_add_str(msg, VC_BUNDLE_REASON, tmp_reason);
2381         bundle_add_str(msg, VC_BUNDLE_DAEMON_PID, tmp_daemon_pid);
2382         bundle_add_str(msg, VC_BUNDLE_ERR_MSG, temp_msg);
2383
2384         SLOG(LOG_DEBUG, TAG_VCD, ">>>> VCD SEND MESSAGE");
2385
2386         __send_msg(msg, VCD_CLIENT_TYPE_MANAGER, manager_pid);
2387         bundle_free(msg);
2388
2389         free(temp_msg);
2390         temp_msg = NULL;
2391
2392         return VCD_ERROR_NONE;
2393 }
2394
2395 /*
2396 // TODO: remove _tidl after remove dbus
2397 // TODO: make client, widget error signal
2398 // But... it seems there is no call of this function.. Need to check.
2399 int vcdc_tidl_send_error(int reason, char *err_msg)
2400 {
2401         SLOG(LOG_ERROR, TAG_VCD, "[TIDL] Send error signal");
2402
2403         char tmp_reason[10] = {0, };
2404         char tmp_daemon_pid[10] = {0, };
2405         char *temp_msg = NULL;
2406
2407         if (NULL == err_msg) {
2408                 SLOG(LOG_WARN, TAG_VCD, "[TIDL ERROR] Input parameter is NULL");
2409                 temp_msg = strdup("#NULL");
2410         } else {
2411                 temp_msg = strdup(err_msg);
2412         }
2413
2414         bundle* msg = bundle_create();
2415         snprintf(tmp_reason, 10, "%d", reason);
2416         snprintf(tmp_daemon_pid, 10, "%d", getpid());
2417
2418         bundle_add_str(msg, VC_BUNDLE_METHOD, VCD_MANAGER_METHOD_ERROR);
2419         bundle_add_str(msg, VC_BUNDLE_REASON, tmp_reason);
2420         bundle_add_str(msg, VC_BUNDLE_DAEMON_PID, tmp_daemon_pid);
2421         bundle_add_str(msg, VC_BUNDLE_ERR_MSG, temp_msg);
2422
2423         bundle_add_str(msg, VC_BUNDLE_METHOD, VCD_WIDGET_METHOD_ERROR);
2424         bundle_add_str(msg, VC_BUNDLE_REASON, tmp_reason);
2425         bundle_add_str(msg, VC_BUNDLE_DAEMON_PID, tmp_daemon_pid);
2426         bundle_add_str(msg, VC_BUNDLE_ERR_MSG, temp_msg);
2427
2428         SLOG(LOG_DEBUG, TAG_VCD, ">>>> VCD SEND SIGNAL");
2429
2430         __send_signal(msg);
2431
2432         bundle_free(msg);
2433
2434         free(temp_msg);
2435         temp_msg = NULL;
2436
2437         return VCD_ERROR_NONE;
2438 }
2439 */
2440 int vcdc_send_request_set_private_data(int pid, const char* key, const char* data)
2441 {
2442         SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Set private data");
2443
2444         char tmp_pid[10] = { 0, };
2445
2446         bundle* msg = bundle_create();
2447         snprintf(tmp_pid, 10, "%d", pid);
2448
2449         bundle_add_str(msg, VC_BUNDLE_METHOD, VCD_MANAGER_METHOD_SET_PRIVATE_DATA);
2450         bundle_add_str(msg, VC_BUNDLE_PID, tmp_pid);
2451         bundle_add_str(msg, VC_BUNDLE_KEY, key);
2452         bundle_add_str(msg, VC_BUNDLE_PRIVATE_DATA, data);
2453
2454         SLOG(LOG_DEBUG, TAG_VCD, ">>>> VCD SEND MESSAGE");
2455
2456         __send_msg(msg, VCD_CLIENT_TYPE_MANAGER, pid);
2457         bundle_free(msg);
2458
2459         return VCD_ERROR_NONE;
2460 }
2461
2462 int vcdc_send_feedback_audio_format_to_manager(int manager_pid, int rate, vc_audio_channel_e channel, vce_audio_type_e audio_type)
2463 {
2464         SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Send feedback audio format to manager");
2465
2466         char tmp_rate[10] = {0, };
2467         char tmp_channel[10] = {0, };
2468         char tmp_audio_type[10] = {0, };
2469
2470         bundle* msg = bundle_create();
2471         snprintf(tmp_rate, 10, "%d", rate);
2472         snprintf(tmp_channel, 10, "%d", (int)channel);
2473         snprintf(tmp_audio_type, 10, "%d", (int)audio_type);
2474         bundle_add_str(msg, VC_BUNDLE_METHOD, VCD_MANAGER_METHOD_FEEDBACK_AUDIO_FORMAT);
2475         bundle_add_str(msg, VC_BUNDLE_AUDIO_RATE, tmp_rate);
2476         bundle_add_str(msg, VC_BUNDLE_AUDIO_CHANNEL, tmp_channel);
2477         bundle_add_str(msg, VC_BUNDLE_AUDIO_TYPE, tmp_audio_type);
2478
2479         SLOG(LOG_DEBUG, TAG_VCD, ">>>> VCD SEND MESSAGE");
2480
2481         __send_msg(msg, VCD_CLIENT_TYPE_MANAGER, manager_pid);
2482         bundle_free(msg);
2483
2484         return VCD_ERROR_NONE;
2485 }
2486
2487 int vcdc_send_feedback_streaming_to_manager(int manager_pid, int pid, int utt_id, vc_feedback_event_e event, char* buffer, int len)
2488 {
2489         SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Send feedback streaming to manager");
2490
2491         char tmp_pid[10] = {0, };
2492         char tmp_utt_id[10] = {0, };
2493         char tmp_event[10] = {0, };
2494
2495         bundle* msg = bundle_create();
2496         snprintf(tmp_pid, 10, "%d", pid);
2497         snprintf(tmp_utt_id, 10, "%d", utt_id);
2498         snprintf(tmp_event, 10, "%d", (int)event);
2499         bundle_add_str(msg, VC_BUNDLE_METHOD, VCD_MANAGER_METHOD_FEEDBACK_STREAMING);
2500         bundle_add_str(msg, VC_BUNDLE_PID, tmp_pid);
2501         bundle_add_str(msg, VC_BUNDLE_UTT_ID, tmp_utt_id);
2502         bundle_add_str(msg, VC_BUNDLE_EVENT, tmp_event);
2503
2504         rpc_port_stub_vcd_mgr_stub_array_char_h streaming_data = NULL;
2505         rpc_port_stub_vcd_mgr_stub_array_char_create(&streaming_data);
2506         if (NULL == streaming_data) {
2507                 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to create data handle");
2508                 return VCD_ERROR_OUT_OF_MEMORY;
2509         }
2510
2511         if (NULL != buffer && 0 < len) {
2512                 rpc_port_stub_vcd_mgr_stub_array_char_set(streaming_data, (char*)buffer, len);
2513         } else {
2514                 SLOG(LOG_ERROR, TAG_VCD, "[TIDL] buffer is empty");
2515         }
2516
2517         SLOG(LOG_DEBUG, TAG_VCD, ">>>> VCD SEND MESSAGE");
2518
2519         pthread_mutex_lock(&g_mgr_tidl_info_mutex);
2520         SLOG(LOG_INFO, TAG_VCD, "[TIDL] message to manager");
2521         manager_tidl_info_s* mgr_tidl_info = vcd_client_manager_get_tidl_info();
2522
2523         if (NULL == mgr_tidl_info) {
2524                 SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to get manager tidl info. pid(%d)", pid);
2525                 pthread_mutex_unlock(&g_mgr_tidl_info_mutex);
2526                 rpc_port_stub_vcd_mgr_stub_array_char_destroy(streaming_data);
2527                 bundle_free(msg);
2528                 return VCD_ERROR_NONE;
2529         }
2530
2531         rpc_port_stub_vcd_mgr_stub_vc_mgr_send_buffer_cb_h handle = mgr_tidl_info->send_buffer_cb;
2532         if (NULL == handle) {
2533                 SLOG(LOG_ERROR, TAG_VCD, "[TIDL] notify callback handle is null");
2534                 pthread_mutex_unlock(&g_mgr_tidl_info_mutex);
2535                 rpc_port_stub_vcd_mgr_stub_array_char_destroy(streaming_data);
2536                 bundle_free(msg);
2537                 return VCD_ERROR_OPERATION_FAILED;
2538         }
2539
2540         if (0 != rpc_port_stub_vcd_mgr_stub_vc_mgr_send_buffer_cb_invoke(handle, streaming_data, msg)) {
2541                 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to send msg");
2542                 pthread_mutex_unlock(&g_mgr_tidl_info_mutex);
2543                 rpc_port_stub_vcd_mgr_stub_array_char_destroy(streaming_data);
2544                 bundle_free(msg);
2545                 return VCD_ERROR_OPERATION_FAILED;
2546         }
2547         pthread_mutex_unlock(&g_mgr_tidl_info_mutex);
2548         rpc_port_stub_vcd_mgr_stub_array_char_destroy(streaming_data);
2549         bundle_free(msg);
2550
2551         return VCD_ERROR_NONE;
2552 }
2553
2554 void vcdc_send_request_set_foreground(int pid, int value)
2555 {
2556         SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Set foreground");
2557
2558         manager_tidl_info_s* mgr_tidl_info = vcd_client_manager_get_tidl_info();
2559
2560         if (NULL == mgr_tidl_info) {
2561                 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to get tidl info");
2562                 return;
2563         }
2564
2565         if (!mgr_tidl_info->connected) {
2566                 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Not Connected");
2567                 return;
2568         }
2569
2570         rpc_port_proxy_vcd_mgr_proxy_vcd_mgr_invoke_set_foreground(mgr_tidl_info->rpc_h, pid, value);
2571
2572         SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Request set foreground");
2573 }
2574
2575 int vcdc_send_request_get_private_data(int pid, const char* key, char** data)
2576 {
2577         SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Get private data");
2578
2579         manager_tidl_info_s* mgr_tidl_info = vcd_client_manager_get_tidl_info();
2580
2581         if (NULL == mgr_tidl_info) {
2582                 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to get tidl info");
2583                 return VC_ERROR_OPERATION_FAILED;
2584         }
2585
2586         if (!mgr_tidl_info->connected) {
2587                 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Not Connected");
2588                 return VC_ERROR_OPERATION_FAILED;
2589         }
2590
2591         char *tmp = NULL;
2592         int ret = rpc_port_proxy_vcd_mgr_proxy_vcd_mgr_invoke_get_private_data(mgr_tidl_info->rpc_h, pid, key, &tmp);
2593         if (RPC_PORT_ERROR_NONE != ret) {
2594                 SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Request vcd manager get private data : Fail to invoke message, error(%d)", ret);
2595                 return ret;
2596         }
2597         SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Request vcd manager get private data : Success");
2598
2599         *data = tmp;
2600
2601         return VC_ERROR_NONE;
2602 }
2603
2604 int vcdc_send_request_auth_enable(int pid)
2605 {
2606         SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] auth enable");
2607
2608         manager_tidl_info_s* mgr_tidl_info = vcd_client_manager_get_tidl_info();
2609
2610         if (NULL == mgr_tidl_info) {
2611                 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to get tidl info");
2612                 return VC_ERROR_OPERATION_FAILED;
2613         }
2614
2615         if (!mgr_tidl_info->connected) {
2616                 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Not Connected");
2617                 return VC_ERROR_OPERATION_FAILED;
2618         }
2619
2620         int ret = rpc_port_proxy_vcd_mgr_proxy_vcd_mgr_invoke_auth_enable(mgr_tidl_info->rpc_h, pid);
2621         if (RPC_PORT_ERROR_NONE != ret) {
2622                 SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Request auth enable : Fail to invoke message, error(%d)", ret);
2623                 return ret;
2624         }
2625         SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Request auth enable : Success");
2626
2627         return VC_ERROR_NONE;
2628 }
2629
2630 int vcdc_send_request_auth_disable(int pid)
2631 {
2632         SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] auth disable");
2633
2634         manager_tidl_info_s* mgr_tidl_info = vcd_client_manager_get_tidl_info();
2635
2636         if (NULL == mgr_tidl_info) {
2637                 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to get tidl info");
2638                 return VC_ERROR_OPERATION_FAILED;
2639         }
2640
2641         if (!mgr_tidl_info->connected) {
2642                 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Not Connected");
2643                 return VC_ERROR_OPERATION_FAILED;
2644         }
2645
2646         int ret = rpc_port_proxy_vcd_mgr_proxy_vcd_mgr_invoke_auth_disable(mgr_tidl_info->rpc_h, pid);
2647         if (RPC_PORT_ERROR_NONE != ret) {
2648                 SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Request auth disable : Fail to invoke message, error(%d)", ret);
2649                 return ret;
2650         }
2651         SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Request auth disable : Success");
2652
2653         return VC_ERROR_NONE;
2654 }
2655
2656 int vcdc_send_request_auth_start(int pid)
2657 {
2658         SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] auth start");
2659
2660         manager_tidl_info_s* mgr_tidl_info = vcd_client_manager_get_tidl_info();
2661
2662         if (NULL == mgr_tidl_info) {
2663                 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to get tidl info");
2664                 return VC_ERROR_OPERATION_FAILED;
2665         }
2666
2667         if (!mgr_tidl_info->connected) {
2668                 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Not Connected");
2669                 return VC_ERROR_OPERATION_FAILED;
2670         }
2671
2672         int ret = rpc_port_proxy_vcd_mgr_proxy_vcd_mgr_invoke_auth_start(mgr_tidl_info->rpc_h, pid);
2673         if (RPC_PORT_ERROR_NONE != ret) {
2674                 SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Request auth start : Fail to invoke message, error(%d)", ret);
2675                 return ret;
2676         }
2677         SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Request auth start : Success");
2678
2679         return VC_ERROR_NONE;
2680 }
2681
2682 int vcdc_send_request_auth_stop(int pid)
2683 {
2684         SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] auth stop");
2685
2686         manager_tidl_info_s* mgr_tidl_info = vcd_client_manager_get_tidl_info();
2687
2688         if (NULL == mgr_tidl_info) {
2689                 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to get tidl info");
2690                 return VC_ERROR_OPERATION_FAILED;
2691         }
2692
2693         if (!mgr_tidl_info->connected) {
2694                 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Not Connected");
2695                 return VC_ERROR_OPERATION_FAILED;
2696         }
2697
2698         int ret = rpc_port_proxy_vcd_mgr_proxy_vcd_mgr_invoke_auth_stop(mgr_tidl_info->rpc_h, pid);
2699         if (RPC_PORT_ERROR_NONE != ret) {
2700                 SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Request auth stop : Fail to invoke message, error(%d)", ret);
2701                 return ret;
2702         }
2703         SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Request auth stop : Success");
2704
2705         return VC_ERROR_NONE;
2706 }
2707
2708 int vcdc_send_request_auth_cancel(int pid)
2709 {
2710         SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] auth cancel");
2711
2712         manager_tidl_info_s* mgr_tidl_info = vcd_client_manager_get_tidl_info();
2713
2714         if (NULL == mgr_tidl_info) {
2715                 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to get tidl info");
2716                 return VC_ERROR_OPERATION_FAILED;
2717         }
2718
2719         if (!mgr_tidl_info->connected) {
2720                 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Not Connected");
2721                 return VC_ERROR_OPERATION_FAILED;
2722         }
2723
2724         int ret = rpc_port_proxy_vcd_mgr_proxy_vcd_mgr_invoke_auth_cancel(mgr_tidl_info->rpc_h, pid);
2725         if (RPC_PORT_ERROR_NONE != ret) {
2726                 SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Request auth cancel : Fail to invoke message, error(%d)", ret);
2727                 return ret;
2728         }
2729         SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Request auth cancel : Success");
2730
2731         return VC_ERROR_NONE;
2732 }
2733
2734 int vcdc_send_asr_result(int pid, int event, const char* asr_result, int cmd_type, bool* is_consumed)
2735 {
2736         SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Send asr result");
2737
2738         widget_tidl_info_s* widget_tidl_info = vcd_client_widget_get_tidl_info(pid);
2739
2740         if (NULL == widget_tidl_info) {
2741                 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to get tidl info");
2742                 return VC_ERROR_OPERATION_FAILED;
2743         }
2744
2745         if (!widget_tidl_info->connected) {
2746                 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Not Connected");
2747                 return VC_ERROR_OPERATION_FAILED;
2748         }
2749
2750         bool temp;
2751         int ret = rpc_port_proxy_vcd_widget_proxy_vcd_widget_invoke_send_asr_result(widget_tidl_info->rpc_h, pid, event, asr_result, &temp);
2752         if (RPC_PORT_ERROR_NONE != ret) {
2753                 SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Request vcd widget send asr result : Fail to invoke message, error(%d)", ret);
2754                 return ret;
2755         }
2756         SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Request vcd widget send asr result : Success");
2757
2758         *is_consumed = temp;
2759
2760         return VC_ERROR_NONE;
2761 }
2762