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