2 * Copyright (c) 2022 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include "vcd_client_data.h"
21 #include "vcd_server.h"
22 #include "vcd_config.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"
32 static rpc_port_stub_vcd_mgr_stub_vc_mgr_callback_s g_mgr_callback;
34 static pthread_mutex_t g_mgr_tidl_info_mutex = PTHREAD_MUTEX_INITIALIZER;
36 static rpc_port_stub_vcd_widget_stub_vc_widget_callback_s g_widget_callback;
38 static pthread_mutex_t g_widget_tidl_info_mutex = PTHREAD_MUTEX_INITIALIZER;
40 static rpc_port_stub_vcd_stub_vc_callback_s g_client_callback;
42 static pthread_mutex_t g_client_tidl_info_mutex = PTHREAD_MUTEX_INITIALIZER;
44 static rpc_port_stub_vcd_setting_stub_vc_setting_callback_s g_setting_callback;
46 static pthread_mutex_t g_setting_tidl_info_mutex = PTHREAD_MUTEX_INITIALIZER;
48 static int g_volume_count = 0;
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();
63 static void __request_tidl_connect(vcd_client_type_e type, int pid)
65 char* type_str = NULL;
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");
75 if (mgr_tidl_info->connection_requesting) {
79 ret = rpc_port_proxy_vcd_mgr_proxy_vcd_mgr_connect(mgr_tidl_info->rpc_h);
82 mgr_tidl_info->connection_requesting = true;
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");
93 // if (client_tidl_info->connection_requesting) {
97 // ret = rpc_port_proxy_vcd_client_connect(client_tidl_info->rpc_h);
100 // SLOG(LOG_ERROR, TAG_VCD, "[TIDL] tidl proxy info not allocated");
101 // client_tidl_info->connection_requesting = true;
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");
111 if (widget_tidl_info->connection_requesting) {
115 ret = rpc_port_proxy_vcd_widget_proxy_vcd_widget_connect(widget_tidl_info->rpc_h);
118 SLOG(LOG_ERROR, TAG_VCD, "[TIDL] tidl proxy info not allocated");
119 widget_tidl_info->connection_requesting = true;
123 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] client type is NOT valid(%d)", type);
127 if (RPC_PORT_ERROR_NONE != ret) {
128 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Request connection to %s stub. ret(%d)", type_str, ret);
130 SLOG(LOG_INFO, TAG_VCD, "[INFO] Request connection to %s stub. ret(%d)", type_str, ret);
134 void __send_msg_to_mgr(bundle* msg)
136 pthread_mutex_lock(&g_mgr_tidl_info_mutex);
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);
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);
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);
158 pthread_mutex_unlock(&g_mgr_tidl_info_mutex);
162 void __send_msg(bundle* msg, vcd_client_type_e type, int pid)
164 SLOG(LOG_INFO, TAG_VCD, "[TIDL] send msg start");
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);
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);
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);
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);
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);
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);
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);
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);
215 pthread_mutex_unlock(&g_widget_tidl_info_mutex);
217 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] client type is NOT valid(%d)", type);
222 void __send_signal(bundle* msg, vcd_client_type_e type)
224 SLOG(LOG_INFO, TAG_VCD, "[TIDL] send signal start");
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);
232 int* client_list = NULL;
233 int client_count = 0;
235 ret = vcd_client_get_tidl_list(&client_list, &client_count);
237 client_tidl_info_s* client_tidl_info = NULL;
240 if (0 == ret && 0 < client_count) {
241 for (int i = 0 ; i < client_count ; i++) {
242 pid = client_list[i];
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);
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");
256 pthread_mutex_unlock(&g_client_tidl_info_mutex);
257 } /* signal to clients */
258 else if (VCD_CLIENT_TYPE_WIDGET == type) {
259 pthread_mutex_lock(&g_widget_tidl_info_mutex);
261 GSList* widget_list = vcd_client_widget_get_tidl_info_list();
263 int count = g_slist_length(widget_list);
266 widget_tidl_info_s *widget_tidl_info = NULL;
269 iter = g_slist_nth(widget_list, 0);
270 for (i = 0; i < count; i++) {
272 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] widget list iterator broken");
276 widget_tidl_info = iter->data;
278 if (NULL == widget_tidl_info) {
279 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] widget list data broken");
283 SLOG(LOG_INFO, TAG_VCD, "[TIDL] message to widget");
285 rpc_port_stub_vcd_widget_stub_vc_widget_notify_cb_h handle = widget_tidl_info->notify_cb;
286 if (NULL == handle) {
287 SLOG(LOG_ERROR, TAG_VCD, "[TIDL] notify callback handle is null");
291 if (0 != rpc_port_stub_vcd_widget_stub_vc_widget_notify_cb_invoke(handle, msg)) {
292 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to send msg");
296 iter = g_slist_next(iter);
299 pthread_mutex_unlock(&g_widget_tidl_info_mutex);
300 } /* signal to widgets */
305 * TIDL callback functions for VC client
307 static void __vc_create_cb(rpc_port_stub_vcd_stub_vc_context_h context, void *user_data)
309 SLOG(LOG_INFO, TAG_VCD, "[TIDL] __vc_create_cb");
313 rpc_port_stub_vcd_stub_vc_context_get_sender(context, &sender);
315 SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Sender is NULL");
319 SLOG(LOG_INFO, TAG_VCD, "[TIDL] sender(%s)", sender); // sender (app_id)
323 static void __vc_terminate_cb(rpc_port_stub_vcd_stub_vc_context_h context, void *user_data)
325 SLOG(LOG_INFO, TAG_VCD, "[TIDL] __vc_terminate_cb");
328 rpc_port_stub_vcd_stub_vc_context_get_tag(context, &tag);
331 int pid = (uintptr_t)tag;
332 SLOG(LOG_DEBUG, TAG_VCD, "@@@ VC FINALIZE. pid(%u)", pid);
334 pthread_mutex_lock(&g_client_tidl_info_mutex);
335 client_tidl_info_s* tidl_info = vcd_client_get_tidl_info(pid);
336 if (NULL == tidl_info) {
337 SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to get client tidl info.");
338 pthread_mutex_unlock(&g_client_tidl_info_mutex);
342 if (0 != vcd_client_unset_tidl_notify_cb(pid)) {
343 SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to unset notify callback");
345 if (0 != vcd_client_unset_tidl_feedback_cb(pid)) {
346 SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to unset feedback callback");
349 if (0 != vcd_client_delete_tidl_info(pid)) {
350 SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to delete client tidl info");
354 SLOG(LOG_DEBUG, TAG_VCD, "@@@");
356 pthread_mutex_unlock(&g_client_tidl_info_mutex);
359 rpc_port_stub_vcd_stub_vc_context_set_tag(context, NULL);
362 static void __vc_register_notify_cb_cb(rpc_port_stub_vcd_stub_vc_context_h context, int pid, rpc_port_stub_vcd_stub_vc_notify_cb_h callback, void *user_data)
364 SLOG(LOG_INFO, TAG_VCD, "[TIDL] __vc_register_notify_cb_cb. pid(%d)", pid);
366 if (NULL == callback) {
367 SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] callback is null.");
372 ret = vcd_client_add_tidl_info(pid);
374 SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to add tidl info.");
378 ret = vcd_client_set_tidl_notify_cb(pid, callback, user_data);
380 SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to set notify callback.");
382 SLOG(LOG_INFO, TAG_VCD, "[TIDL] Succeed to set notify callback.");
386 static int __vc_register_notify_cb_sync_cb(rpc_port_stub_vcd_stub_vc_context_h context, int pid, rpc_port_stub_vcd_stub_vc_notify_cb_h callback, void *user_data)
388 SLOG(LOG_INFO, TAG_VCD, "[TIDL] __vc_register_notify_cb_sync_cb. pid(%d)", pid);
390 if (NULL == callback) {
391 SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] callback is null.");
392 return VCD_ERROR_INVALID_PARAMETER;
396 ret = vcd_client_add_tidl_info(pid);
398 SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to add tidl info.");
402 ret = vcd_client_set_tidl_notify_cb(pid, callback, user_data);
404 SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to set notify callback.");
406 SLOG(LOG_INFO, TAG_VCD, "[TIDL] Succeed to set notify callback.");
412 static void __vc_register_feedback_cb_cb(rpc_port_stub_vcd_stub_vc_context_h context, int pid, rpc_port_stub_vcd_stub_vc_feedback_cb_h callback, void *user_data)
414 SLOG(LOG_INFO, TAG_VCD, "[TIDL] __vc_register_feedback_cb_cb. pid(%d)", pid);
416 if (NULL == callback) {
417 SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] callback is null.");
422 ret = vcd_client_add_tidl_info(pid);
424 SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to add tidl info.");
428 ret = vcd_client_set_tidl_feedback_cb(pid, callback, user_data);
430 SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to set feedback callback.");
432 SLOG(LOG_INFO, TAG_VCD, "[TIDL] Succeed to set feedback callback.");
436 static int __vc_register_feedback_cb_sync_cb(rpc_port_stub_vcd_stub_vc_context_h context, int pid, rpc_port_stub_vcd_stub_vc_feedback_cb_h callback, void *user_data)
438 SLOG(LOG_INFO, TAG_VCD, "[TIDL] __vc_register_feedback_cb_sync_cb. pid(%d)", pid);
440 if (NULL == callback) {
441 SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] callback is null.");
442 return VCD_ERROR_INVALID_PARAMETER;
446 ret = vcd_client_add_tidl_info(pid);
448 SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to add tidl info.");
452 ret = vcd_client_set_tidl_feedback_cb(pid, callback, user_data);
454 SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to set feedback callback.");
456 SLOG(LOG_INFO, TAG_VCD, "[TIDL] Succeed to set feedback callback.");
462 static int __vc_initialize_cb(rpc_port_stub_vcd_stub_vc_context_h context, int pid, int *mgr_pid, int *service_state, int *daemon_pid, void *user_data)
464 SLOG(LOG_INFO, TAG_VCD, "[TIDL] __vc_initialize_cb. pid(%d)", pid);
466 int ret = VCD_ERROR_OPERATION_FAILED;
468 uintptr_t ptr_pid = pid;
469 rpc_port_stub_vcd_stub_vc_context_set_tag(context, (void*)ptr_pid);
471 ret = vcd_server_initialize(pid);
472 *service_state = vcd_server_get_service_state();
473 *daemon_pid = getpid();
474 *mgr_pid = vcd_client_manager_get_pid();
476 if (VCD_ERROR_NONE == ret) {
477 SLOG(LOG_INFO, TAG_VCD, "[IN] vcd initialize : pid(%d) daemon_pid(%d)", pid, *daemon_pid);
479 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to vcd initialize : pid(%d) daemon_pid(%d) ret(%d)", pid, *daemon_pid, ret);
485 static int __vc_finalize_cb(rpc_port_stub_vcd_stub_vc_context_h context, int pid, void *user_data)
487 SLOG(LOG_INFO, TAG_VCD, "[TIDL] __vc_finalize_cb");
489 int ret = VCD_ERROR_OPERATION_FAILED;
491 ret = vcd_server_finalize(pid);
492 if (VCD_ERROR_NONE == ret) {
493 SLOG(LOG_INFO, TAG_VCD, "[IN] vcd finalize : pid(%d)", pid);
495 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to vcd finalize : pid(%d) ret(%d)", pid, ret);
501 static int __vc_set_command_cb(rpc_port_stub_vcd_stub_vc_context_h context, int pid, int cmd_type, void *user_data)
503 SLOG(LOG_INFO, TAG_VCD, "[TIDL] __vc_set_command_cb");
505 int ret = VCD_ERROR_OPERATION_FAILED;
507 ret = vcd_server_set_command(pid, (vc_cmd_type_e)cmd_type);
508 if (VCD_ERROR_NONE == ret) {
509 SLOG(LOG_INFO, TAG_VCD, "[IN] vcd set command : pid(%d), cmd_type(%d)", pid, cmd_type);
511 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to vcd set command : pid(%d), cmd_type(%d) ret(%d)", pid, cmd_type, ret);
517 static int __vc_unset_command_cb(rpc_port_stub_vcd_stub_vc_context_h context, int pid, int cmd_type, void *user_data)
519 SLOG(LOG_INFO, TAG_VCD, "[TIDL] __vc_unset_command_cb");
521 int ret = VCD_ERROR_OPERATION_FAILED;
523 ret = vcd_server_unset_command(pid, (vc_cmd_type_e)cmd_type);
524 if (VCD_ERROR_NONE == ret) {
525 SLOG(LOG_INFO, TAG_VCD, "[IN] vcd unset command : pid(%d), cmd_type(%d)", pid, cmd_type);
527 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to vcd unset command : pid(%d), cmd_type(%d) ret(%d)", pid, cmd_type, ret);
533 static int __vc_set_foreground_cb(rpc_port_stub_vcd_stub_vc_context_h context, int pid, bool value, void *user_data)
536 SLOG(LOG_INFO, TAG_VCD, "[TIDL] __vc_set_foreground_cb");
538 int ret = VCD_ERROR_OPERATION_FAILED;
540 ret = vcd_server_set_foreground(pid, value);
541 if (VCD_ERROR_NONE != ret) {
542 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to vcd set foreground : pid(%d) ret(%d)", pid, ret);
546 SLOG(LOG_INFO, TAG_VCD, "[IN] vcd set foreground : pid(%d)", pid);
547 vcdc_send_request_set_foreground(pid, value);
552 static int __vc_set_server_dialog_cb(rpc_port_stub_vcd_stub_vc_context_h context, int pid, const char *app_id, const char *credential, void *user_data)
554 SLOG(LOG_INFO, TAG_VCD, "[TIDL] __vc_set_server_dialog_cb");
556 int ret = VCD_ERROR_OPERATION_FAILED;
558 ret = vcd_server_set_server_dialog(pid, app_id, credential);
559 if (VCD_ERROR_NONE == ret) {
560 SLOG(LOG_INFO, TAG_VCD, "[IN] vcd set server dialog : pid(%d), app_id(%s)", pid, app_id);
562 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to vcd set server dialog : pid(%d), app_id(%s) ret(%d)", pid, app_id, ret);
568 static int __vc_request_dialog_cb(rpc_port_stub_vcd_stub_vc_context_h context, int pid, const char *disp_text, const char *utt_text, bool continuous, void *user_data)
570 SLOG(LOG_INFO, TAG_VCD, "[TIDL] __vc_request_dialog_cb");
572 int ret = VCD_ERROR_OPERATION_FAILED;
574 ret = vcd_server_dialog(pid, disp_text, utt_text, continuous);
575 if (VCD_ERROR_NONE == ret) {
576 SLOG(LOG_INFO, TAG_VCD, "[IN] vcd request dialog : pid(%d), disp_text(%s), utt_text(%s), continuous(%d)", pid, disp_text, utt_text, continuous);
578 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to vcd request dialog : pid(%d), disp_text(%s), utt_text(%s), continuous(%d), ret(%d)", pid, disp_text, utt_text, continuous, ret);
581 return VCD_ERROR_NONE;
584 static int __vc_is_system_command_valid_cb(rpc_port_stub_vcd_stub_vc_context_h context, int pid, bool *is_sys_cmd_valid, void *user_data)
586 SLOG(LOG_INFO, TAG_VCD, "[TIDL] __vc_is_system_command_valid_cb");
588 int ret = VCD_ERROR_OPERATION_FAILED;
590 ret = vcd_server_is_system_command_valid(pid, (int*)is_sys_cmd_valid);
591 if (VCD_ERROR_NONE == ret) {
592 SLOG(LOG_INFO, TAG_VCD, "[IN] vcd check system command is valid : pid(%d), is_sys_cmd_valid(%d)", pid, *is_sys_cmd_valid);
594 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to vcd check system command is valid : pid(%d), ret(%d)", pid, ret);
600 static int __vc_auth_enable_cb(rpc_port_stub_vcd_stub_vc_context_h context, int pid, int mgr_pid, void *user_data)
602 SLOG(LOG_INFO, TAG_VCD, "[TIDL] __vc_auth_enable_cb. Send a request to vc_mgr");
604 int ret = VCD_ERROR_OPERATION_FAILED;
605 ret = vcdc_send_request_auth_enable(pid);
606 if (VCD_ERROR_NONE == ret) {
607 SLOG(LOG_INFO, TAG_VCD, "[SUCCESS] Send request auth enable. pid(%d), mgr_pid(%d)", pid, mgr_pid);
609 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to send request auth enable. ret(%d), pid(%d), mgr_pid(%d)", ret, pid, mgr_pid);
615 static int __vc_auth_disable_cb(rpc_port_stub_vcd_stub_vc_context_h context, int pid, int mgr_pid, void *user_data)
617 SLOG(LOG_INFO, TAG_VCD, "[TIDL] __vc_auth_disable_cb. Send a request to vc_mgr");
619 int ret = VCD_ERROR_OPERATION_FAILED;
620 ret = vcdc_send_request_auth_disable(pid);
621 if (VCD_ERROR_NONE == ret) {
622 SLOG(LOG_INFO, TAG_VCD, "[SUCCESS] Send request auth disable. pid(%d), mgr_pid(%d)", pid, mgr_pid);
624 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to send request auth disable. ret(%d), pid(%d), mgr_pid(%d)", ret, pid, mgr_pid);
630 static int __vc_auth_start_cb(rpc_port_stub_vcd_stub_vc_context_h context, int pid, int mgr_pid, void *user_data)
632 SLOG(LOG_INFO, TAG_VCD, "[TIDL] __vc_auth_start_cb. Send a request to vc_mgr");
634 int ret = VCD_ERROR_OPERATION_FAILED;
635 ret = vcdc_send_request_auth_start(pid);
636 if (VCD_ERROR_NONE == ret) {
637 SLOG(LOG_INFO, TAG_VCD, "[SUCCESS] Send request auth start. pid(%d), mgr_pid(%d)", pid, mgr_pid);
639 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to send request auth start. ret(%d), pid(%d), mgr_pid(%d)", ret, pid, mgr_pid);
645 static int __vc_auth_stop_cb(rpc_port_stub_vcd_stub_vc_context_h context, int pid, int mgr_pid, void *user_data)
647 SLOG(LOG_INFO, TAG_VCD, "[TIDL] __vc_auth_stop_cb. Send a request to vc_mgr");
649 int ret = VCD_ERROR_OPERATION_FAILED;
650 ret = vcdc_send_request_auth_stop(pid);
651 if (VCD_ERROR_NONE == ret) {
652 SLOG(LOG_INFO, TAG_VCD, "[SUCCESS] Send request auth stop. pid(%d), mgr_pid(%d)", pid, mgr_pid);
654 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to send request auth stop. ret(%d), pid(%d), mgr_pid(%d)", ret, pid, mgr_pid);
660 static int __vc_auth_cancel_cb(rpc_port_stub_vcd_stub_vc_context_h context, int pid, int mgr_pid, void *user_data)
662 SLOG(LOG_INFO, TAG_VCD, "[TIDL] __vc_auth_cancel_cb. Send a request to vc_mgr");
664 int ret = VCD_ERROR_OPERATION_FAILED;
665 ret = vcdc_send_request_auth_cancel(pid);
666 if (VCD_ERROR_NONE == ret) {
667 SLOG(LOG_INFO, TAG_VCD, "[SUCCESS] Send request auth cancel. pid(%d), mgr_pid(%d)", pid, mgr_pid);
669 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to send request auth cancel. ret(%d), pid(%d), mgr_pid(%d)", ret, pid, mgr_pid);
675 static int __vc_request_tts_cb(rpc_port_stub_vcd_stub_vc_context_h context, int pid, const char *text, const char *lang, bool to_vcm, int *utt_id, void *user_data)
677 SLOG(LOG_INFO, TAG_VCD, "[TIDL] __vc_request_tts_cb");
679 int ret = VCD_ERROR_OPERATION_FAILED;
681 ret = vcd_server_request_tts(pid, text, lang, to_vcm, utt_id);
682 if (VCD_ERROR_NONE == ret) {
683 SLOG(LOG_INFO, TAG_VCD, "[IN] vcd request tts : pid(%d), text(%s), language(%s), to_vcm(%d)", pid, text, lang, to_vcm);
685 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to vcd request tts : pid(%d), text(%s), language(%s), to_vcm(%d), ret(%d)", pid, text, lang, to_vcm, ret);
691 static int __vc_cancel_tts_cb(rpc_port_stub_vcd_stub_vc_context_h context, int pid, int utt_id, void *user_data)
693 SLOG(LOG_INFO, TAG_VCD, "[TIDL] __vc_cancel_tts_cb");
695 int ret = VCD_ERROR_OPERATION_FAILED;
697 ret = vcd_server_cancel_tts(pid, utt_id);
698 if (VCD_ERROR_NONE == ret) {
699 SLOG(LOG_INFO, TAG_VCD, "[IN] vcd cancel tts : pid(%d), utt_id(%d)", pid, utt_id);
701 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to vcd cancel tts : pid(%d), utt_id(%d), ret(%d)", pid, utt_id, ret);
707 static int __vc_get_tts_audio_format_cb(rpc_port_stub_vcd_stub_vc_context_h context, int pid, int *rate, int *channel, int *audio_type, void *user_data)
709 SLOG(LOG_INFO, TAG_VCD, "[TIDL] __vc_get_tts_audio_format_cb");
711 int ret = VCD_ERROR_OPERATION_FAILED;
713 ret = vcd_server_get_tts_audio_format(pid, rate, channel, audio_type);
714 if (VCD_ERROR_NONE == ret) {
715 SLOG(LOG_INFO, TAG_VCD, "[IN] vcd get tts audio format : pid(%d), rate(%d), channel(%d), audio_type(%d)", pid, *rate, *channel, *audio_type);
717 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to vcd get tts audio format : pid(%d) ret(%d)", pid, ret);
723 int __client_tidl_open_connection()
725 SLOG(LOG_INFO, TAG_VCD, "[TIDL] __client_tidl_open_connection");
727 g_client_callback.create = __vc_create_cb;
728 g_client_callback.terminate = __vc_terminate_cb;
729 g_client_callback.register_notify_cb = __vc_register_notify_cb_cb;
730 g_client_callback.register_notify_cb_sync = __vc_register_notify_cb_sync_cb;
731 g_client_callback.register_feedback_cb = __vc_register_feedback_cb_cb;
732 g_client_callback.register_feedback_cb_sync = __vc_register_feedback_cb_sync_cb;
733 g_client_callback.initialize = __vc_initialize_cb;
734 g_client_callback.finalize = __vc_finalize_cb;
735 g_client_callback.set_command = __vc_set_command_cb;
736 g_client_callback.unset_command = __vc_unset_command_cb;
737 g_client_callback.set_foreground = __vc_set_foreground_cb;
738 g_client_callback.set_server_dialog = __vc_set_server_dialog_cb;
739 g_client_callback.request_dialog = __vc_request_dialog_cb;
740 g_client_callback.is_system_command_valid = __vc_is_system_command_valid_cb;
741 g_client_callback.auth_enable = __vc_auth_enable_cb;
742 g_client_callback.auth_disable = __vc_auth_disable_cb;
743 g_client_callback.auth_start = __vc_auth_start_cb;
744 g_client_callback.auth_stop = __vc_auth_stop_cb;
745 g_client_callback.auth_cancel = __vc_auth_cancel_cb;
746 g_client_callback.request_tts = __vc_request_tts_cb;
747 g_client_callback.cancel_tts = __vc_cancel_tts_cb;
748 g_client_callback.get_tts_audio_format = __vc_get_tts_audio_format_cb;
751 ret = rpc_port_stub_vcd_stub_vc_register(&g_client_callback, NULL);
752 if (VCD_ERROR_NONE != ret) {
753 SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to register TIDL callbacks. ret(%d)", ret);
754 return VCD_ERROR_OPERATION_FAILED;
757 return VCD_ERROR_NONE;
760 int __client_tidl_close_connection()
762 SLOG(LOG_INFO, TAG_VCD, "[TIDL] __client_tidl_close_connection");
763 rpc_port_stub_vcd_stub_vc_unregister();
765 return VCD_ERROR_NONE;
769 * TIDL callback functions for VC manager
771 static void __mgr_on_connected(rpc_port_proxy_vcd_mgr_proxy_vcd_mgr_h h, void *user_data)
773 manager_tidl_info_s* mgr_tidl_info = vcd_client_manager_get_tidl_info();
775 if (NULL == mgr_tidl_info) {
776 SLOG(LOG_ERROR, TAG_VCD, "[TIDL] tidl proxy info not allocated");
780 mgr_tidl_info->connected = true;
781 mgr_tidl_info->connection_requesting = false;
783 SLOG(LOG_INFO, TAG_VCD, "Connected to manager");
786 static void __mgr_on_disconnected(rpc_port_proxy_vcd_mgr_proxy_vcd_mgr_h h, void *user_data)
788 manager_tidl_info_s* mgr_tidl_info = vcd_client_manager_get_tidl_info();
790 if (NULL == mgr_tidl_info) {
791 SLOG(LOG_ERROR, TAG_VCD, "[TIDL] tidl proxy info not allocated");
795 mgr_tidl_info->connected = false;
796 mgr_tidl_info->connection_requesting = false;
798 SLOG(LOG_INFO, TAG_VCD, "Disonnected to manager");
801 static void __mgr_on_rejected(rpc_port_proxy_vcd_mgr_proxy_vcd_mgr_h h, void *user_data)
803 manager_tidl_info_s* mgr_tidl_info = vcd_client_manager_get_tidl_info();
805 if (NULL == mgr_tidl_info) {
806 SLOG(LOG_ERROR, TAG_VCD, "[TIDL] tidl proxy info not allocated");
810 mgr_tidl_info->connection_requesting = false;
812 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Rejected from manager");
815 static rpc_port_proxy_vcd_mgr_proxy_vcd_mgr_h __mgr_create_rpc_port(const char* engine_app_id)
817 SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] __mgr_create_rpc_port");
818 rpc_port_proxy_vcd_mgr_proxy_vcd_mgr_callback_s rpc_callback = {
819 .connected = __mgr_on_connected,
820 .disconnected = __mgr_on_disconnected,
821 .rejected = __mgr_on_rejected
824 rpc_port_proxy_vcd_mgr_proxy_vcd_mgr_h handle = NULL;
825 if (0 != rpc_port_proxy_vcd_mgr_proxy_vcd_mgr_create(engine_app_id, &rpc_callback, NULL, &handle)) {
826 SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to create proxy");
833 static void __vc_mgr_create_cb(rpc_port_stub_vcd_mgr_stub_vc_mgr_context_h context, void *user_data)
837 rpc_port_stub_vcd_mgr_stub_vc_mgr_context_get_sender(context, &sender);
839 SLOG(LOG_ERROR, TAG_VCD, "Sender is NULL");
843 SLOG(LOG_DEBUG, TAG_VCD, "@@@ Manager connect. appid(%s)", sender);
848 static void __vc_mgr_terminate_cb(rpc_port_stub_vcd_mgr_stub_vc_mgr_context_h context, void *user_data)
850 pthread_mutex_lock(&g_mgr_tidl_info_mutex);
851 manager_tidl_info_s* mgr_tidl_info = vcd_client_manager_get_tidl_info();
852 if (NULL == mgr_tidl_info) {
853 SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to get manager tidl info.");
854 pthread_mutex_unlock(&g_mgr_tidl_info_mutex);
858 SLOG(LOG_DEBUG, TAG_VCD, "@@@ VC MANAGER FINALIZE. pid(%u)", mgr_tidl_info->pid);
860 if (0 != vcd_client_manager_unset_tidl_notify_cb()) {
861 SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to unset notify callback");
864 if (0 != vcd_client_manager_unset_tidl_send_buffer_cb()) {
865 SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to unset send buffer callback");
868 if (0 != vcd_client_manager_delete_tidl_info()) {
869 SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to delete manager tidl info");
871 mgr_tidl_info = NULL;
873 SLOG(LOG_DEBUG, TAG_VCD, "@@@");
875 pthread_mutex_unlock(&g_mgr_tidl_info_mutex);
879 rpc_port_stub_vcd_mgr_stub_vc_mgr_context_get_sender(context, &sender);
883 SLOG(LOG_INFO, TAG_VCD, "@@@ Manager disconnect. appid(%s)", sender);
888 static void __vc_mgr_register_cb_cb(rpc_port_stub_vcd_mgr_stub_vc_mgr_context_h context, int pid, rpc_port_stub_vcd_mgr_stub_vc_mgr_notify_cb_h notify_callback, rpc_port_stub_vcd_mgr_stub_vc_mgr_send_buffer_cb_h send_buffer_callback, void *user_data)
890 pthread_mutex_lock(&g_mgr_tidl_info_mutex);
891 SLOG(LOG_INFO, TAG_VCD, "@@@ VC MANAGER REGISTER CALLBACK");
894 ret = vcd_client_manager_create_tidl_info(pid);
897 SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to create manager tidl info.");
898 pthread_mutex_unlock(&g_mgr_tidl_info_mutex);
902 manager_tidl_info_s* mgr_tidl_info = vcd_client_manager_get_tidl_info();
904 if (NULL == mgr_tidl_info) {
905 SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to get manager tidl info. pid(%d)", pid);
906 pthread_mutex_unlock(&g_mgr_tidl_info_mutex);
911 rpc_port_stub_vcd_mgr_stub_vc_mgr_context_get_sender(context, &sender);
914 SLOG(LOG_ERROR, TAG_VCD, "Sender is NULL");
915 pthread_mutex_unlock(&g_mgr_tidl_info_mutex);
919 mgr_tidl_info->rpc_h = __mgr_create_rpc_port(sender);
921 if (NULL == mgr_tidl_info->rpc_h) {
922 SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to create server proxy");
924 SLOG(LOG_INFO, TAG_VCD, "[TIDL] rpc_h(%p), engine_app_id(%s)", mgr_tidl_info->rpc_h, sender);
929 if (0 != vcd_client_manager_set_tidl_notify_cb(notify_callback, user_data)) {
930 SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to set notify callback");
932 SLOG(LOG_INFO, TAG_VCD, "[TIDL] Succeed to set notify callback.");
935 if (0 != vcd_client_manager_set_tidl_send_buffer_cb(send_buffer_callback, user_data)) {
936 SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to set send buffer callback");
938 SLOG(LOG_INFO, TAG_VCD, "[TIDL] Succeed to set send buffer callback.");
941 pthread_mutex_unlock(&g_mgr_tidl_info_mutex);
943 __request_tidl_connect(VCD_CLIENT_TYPE_MANAGER, pid);
945 SLOG(LOG_DEBUG, TAG_VCD, "@@@");
948 static int __vc_mgr_initialize_cb(rpc_port_stub_vcd_mgr_stub_vc_mgr_context_h context, int pid, int audio_streaming_mode, int *service_state, int *foreground, int *daemon_pid, void *user_data)
950 SLOG(LOG_INFO, TAG_VCD, "@@@ VCD Manager Initialize");
954 vcd_config_set_audio_streaming_mode((vcd_audio_streaming_mode_e)audio_streaming_mode);
955 ret = vcd_server_mgr_initialize(pid, audio_streaming_mode);
957 SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret);
960 *service_state = vcd_server_get_service_state();
961 *foreground = vcd_server_get_foreground();
962 *daemon_pid = getpid();
964 SLOG(LOG_INFO, TAG_VCD, "[IN] vcd mgr initialize : pid(%d) service state(%d) foreground(%d) daemon_pid(%d)", pid, *service_state, *foreground, *daemon_pid);
965 SLOG(LOG_DEBUG, TAG_VCD, "@@@");
969 static int __vc_mgr_finalize_cb(rpc_port_stub_vcd_mgr_stub_vc_mgr_context_h context, int pid, void *user_data)
971 SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Manager Finalize");
972 SLOG(LOG_INFO, TAG_VCD, "[IN] vcd mgr finalize : pid(%d)", pid);
976 ret = vcd_server_mgr_finalize(pid);
978 SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret);
981 SLOG(LOG_DEBUG, TAG_VCD, "@@@");
986 static int __vc_mgr_set_command_cb(rpc_port_stub_vcd_mgr_stub_vc_mgr_context_h context, int pid, void *user_data)
988 SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Manager Set command");
989 SLOG(LOG_INFO, TAG_VCD, "[IN] vcd mgr set command : pid(%d)", pid);
993 ret = vcd_server_mgr_set_command(pid);
995 SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret);
999 SLOG(LOG_DEBUG, TAG_VCD, "@@@");
1004 static int __vc_mgr_unset_command_cb(rpc_port_stub_vcd_mgr_stub_vc_mgr_context_h context, int pid, void *user_data)
1006 SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Manager unset command");
1007 SLOG(LOG_INFO, TAG_VCD, "[IN] vcd mgr unset command : pid(%d)", pid);
1011 ret = vcd_server_mgr_unset_command(pid);
1013 SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret);
1017 SLOG(LOG_DEBUG, TAG_VCD, "@@@");
1022 static int __vc_mgr_set_demandable_client_cb(rpc_port_stub_vcd_mgr_stub_vc_mgr_context_h context, int pid, void *user_data)
1024 SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Manager Set demandable client");
1025 SLOG(LOG_INFO, TAG_VCD, "[IN] vcd mgr set demandable client : pid(%d)", pid);
1029 ret = vcd_server_mgr_set_demandable_client(pid);
1031 SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret);
1035 SLOG(LOG_DEBUG, TAG_VCD, "@@@");
1040 static int __vc_mgr_set_audio_type_cb(rpc_port_stub_vcd_mgr_stub_vc_mgr_context_h context, int pid, const char *audio_type, void *user_data)
1042 SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Manager set audio type");
1043 SLOG(LOG_INFO, TAG_VCD, "[IN] vcd mgr set audio type : pid(%d), audio type(%s)", pid, audio_type);
1047 ret = vcd_server_mgr_set_audio_type(pid, audio_type);
1049 SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret);
1053 SLOG(LOG_DEBUG, TAG_VCD, "@@@");
1058 static int __vc_mgr_get_audio_type_cb(rpc_port_stub_vcd_mgr_stub_vc_mgr_context_h context, int pid, char **audio_type, void *user_data)
1060 SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Manager get audio type");
1061 SLOG(LOG_INFO, TAG_VCD, "[IN] vcd mgr set audio type : pid(%d)", pid);
1064 char* tmp_audio_type = NULL;
1066 ret = vcd_server_mgr_get_audio_type(pid, &tmp_audio_type);
1068 SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret);
1069 free(tmp_audio_type);
1073 *audio_type = strdup(tmp_audio_type);
1074 free(tmp_audio_type);
1076 SLOG(LOG_DEBUG, TAG_VCD, "@@@");
1081 static void __vc_mgr_set_private_data_cb(rpc_port_stub_vcd_mgr_stub_vc_mgr_context_h context, int pid, const char *key, const char *data, void *user_data)
1083 SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Manager set private data");
1084 SLOG(LOG_INFO, TAG_VCD, "[IN] vcd mgr set domain : pid(%d), key(%s), data(%s)", pid, key, data);
1088 ret = vcd_server_mgr_set_private_data(pid, key, data);
1090 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to set private data");
1091 SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret);
1094 SLOG(LOG_DEBUG, TAG_VCD, "@@@");
1097 static int __vc_mgr_get_private_data_cb(rpc_port_stub_vcd_mgr_stub_vc_mgr_context_h context, int pid, const char *key, char **data, void *user_data)
1099 SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Manager get private data");
1100 SLOG(LOG_INFO, TAG_VCD, "[IN] vcd mgr get private data : pid(%d), key(%s)", pid, key);
1103 char *temp_data = NULL;
1105 ret = vcd_server_mgr_get_private_data(pid, key, &temp_data);
1107 SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret);
1110 if (NULL == temp_data) {
1111 SLOG(LOG_INFO, TAG_VCD, "data parameter is NULL");
1112 temp_data = strdup("#NULL");
1115 *data = strdup(temp_data);
1118 SLOG(LOG_DEBUG, TAG_VCD, "@@@");
1123 static int __vc_mgr_set_client_info_cb(rpc_port_stub_vcd_mgr_stub_vc_mgr_context_h context, int pid, void *user_data)
1125 SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Manager set client info");
1126 SLOG(LOG_INFO, TAG_VCD, "[IN] vcd mgr set client info : pid(%d)", pid);
1130 ret = vcd_server_mgr_set_client_info(pid);
1132 SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret);
1136 SLOG(LOG_DEBUG, TAG_VCD, "@@@");
1141 static int __vc_mgr_set_domain_cb(rpc_port_stub_vcd_mgr_stub_vc_mgr_context_h context, int pid, const char *domain, void *user_data)
1143 SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Manager set domain type");
1144 SLOG(LOG_INFO, TAG_VCD, "[IN] vcd mgr set domain : pid(%d), domain(%s)", pid, domain);
1148 ret = vcd_server_mgr_set_domain(pid, domain);
1150 SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret);
1154 SLOG(LOG_DEBUG, TAG_VCD, "@@@");
1159 static void __vc_mgr_do_action_cb(rpc_port_stub_vcd_mgr_stub_vc_mgr_context_h context, int pid, int type, const char *send_event, void *user_data)
1161 SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Manager request to do action");
1162 SLOG(LOG_INFO, TAG_VCD, "[IN] vcd mgr request to do action : pid(%d), type(%d) send_event(%s)", pid, type, send_event);
1166 ret = vcd_server_mgr_do_action(pid, type, send_event);
1168 SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret);
1171 SLOG(LOG_DEBUG, TAG_VCD, "@@@");
1174 static int __vc_mgr_start_cb(rpc_port_stub_vcd_mgr_stub_vc_mgr_context_h context, int pid, int recognition_mode, bool exclusive_command_option, bool start_by_client, int disabled_cmd_type, void *user_data)
1176 SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Manager start");
1177 SLOG(LOG_INFO, TAG_VCD, "[IN] vcd check enabled or disabled command types. disabled cmd type(%d)", disabled_cmd_type);
1181 vcd_server_mgr_set_disabled_command_type(pid, disabled_cmd_type);
1183 SLOG(LOG_INFO, TAG_VCD, "[IN] vcd mgr start : pid(%d) recognition_mode(%d) exclusive(%d) start by client(%d)", pid, recognition_mode, exclusive_command_option, start_by_client);
1184 ret = vcd_server_mgr_start((vcd_recognition_mode_e)recognition_mode, exclusive_command_option, start_by_client);
1186 SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret);
1190 SLOG(LOG_DEBUG, TAG_VCD, "@@@");
1195 static int __vc_mgr_stop_cb(rpc_port_stub_vcd_mgr_stub_vc_mgr_context_h context, int pid, void *user_data)
1197 SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Manager stop");
1198 SLOG(LOG_INFO, TAG_VCD, "[IN] vcd mgr stop : pid(%d)", pid);
1202 ret = vcd_server_mgr_stop();
1205 SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret);
1209 SLOG(LOG_DEBUG, TAG_VCD, "@@@");
1214 static int __vc_mgr_cancel_cb(rpc_port_stub_vcd_mgr_stub_vc_mgr_context_h context, int pid, void *user_data)
1216 SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Manager cancel");
1217 SLOG(LOG_INFO, TAG_VCD, "[IN] vcd mgr cancel : pid(%d)", pid);
1221 ret = vcd_server_mgr_cancel();
1223 SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret);
1227 SLOG(LOG_DEBUG, TAG_VCD, "@@@");
1232 static void __vc_mgr_set_audio_streaming_mode_cb(rpc_port_stub_vcd_mgr_stub_vc_mgr_context_h context, int pid, int mode, void *user_data)
1234 SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Manager set audio streaming mode");
1235 SLOG(LOG_INFO, TAG_VCD, "[IN] vcd mgr set audio streaming mode : pid(%d) mode(%d)", pid, mode);
1237 vcd_config_set_audio_streaming_mode((vcd_audio_streaming_mode_e)mode);
1239 SLOG(LOG_DEBUG, TAG_VCD, "@@@");
1242 static void __vc_mgr_send_specific_engine_request_cb(rpc_port_stub_vcd_mgr_stub_vc_mgr_context_h context, int pid, const char *engine_app_id, const char *event, const char *request, void *user_data)
1244 SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Manager specific engine request");
1247 gsize decodingSize = 0;
1248 gchar *gDecodedRequest = (gchar *)g_base64_decode((const gchar *)request, &decodingSize);
1250 if (gDecodedRequest) {
1251 ret = vcd_server_mgr_send_specific_engine_request(pid, engine_app_id, event, gDecodedRequest);
1253 SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret);
1256 SLOG(LOG_INFO, TAG_VCD, "[IN] vcd mgr specific engine request : pid(%d), engine_app_id(%s), event(%s), request(%s), ret(%d)", pid, engine_app_id, event, gDecodedRequest, ret);
1257 g_free(gDecodedRequest);
1260 SLOG(LOG_DEBUG, TAG_VCD, "@@@");
1263 static void __vc_mgr_send_result_selection_cb(rpc_port_stub_vcd_mgr_stub_vc_mgr_context_h context, int pid, void *user_data)
1265 SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Manager result selection");
1266 SLOG(LOG_INFO, TAG_VCD, "[IN] vcd mgr result selection : pid(%d)", pid);
1268 vcd_server_mgr_result_select();
1270 SLOG(LOG_DEBUG, TAG_VCD, "@@@");
1273 static void __vc_mgr_send_utterance_status_cb(rpc_port_stub_vcd_mgr_stub_vc_mgr_context_h context, int pid, int utt_id, int utt_status, void *user_data)
1275 SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Manager send utterance status");
1276 SLOG(LOG_INFO, TAG_VCD, "[IN] vcd mgr send utterance status : pid(%d), utt_id(%d), utt_status(%d)", pid, utt_id, utt_status);
1278 pthread_mutex_lock(&g_client_tidl_info_mutex);
1280 SLOG(LOG_INFO, TAG_VCD, "[TIDL] message to client");
1281 client_tidl_info_s* client_tidl_info = vcd_client_get_tidl_info(pid);
1282 if (NULL == client_tidl_info) {
1283 SLOG(LOG_ERROR, TAG_VCD, "[TIDL] tidl proxy info not allocated");
1284 pthread_mutex_unlock(&g_client_tidl_info_mutex);
1288 rpc_port_stub_vcd_stub_vc_notify_cb_h handle = client_tidl_info->notify_cb;
1289 if (NULL == handle) {
1290 SLOG(LOG_ERROR, TAG_VCD, "[TIDL] notify callback handle is null");
1291 pthread_mutex_unlock(&g_client_tidl_info_mutex);
1295 bundle* msg = bundle_create();
1297 SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to create bundle data");
1298 pthread_mutex_unlock(&g_client_tidl_info_mutex);
1302 char pid_char[10] = {0};
1303 char uttid_char[10] = {0};
1304 char uttstatus_char[10] = {0};
1305 snprintf(pid_char, 10, "%d", pid);
1306 snprintf(uttid_char, 10, "%d", utt_id);
1307 snprintf(uttstatus_char, 10, "%d", utt_status);
1309 bundle_add_str(msg, VC_BUNDLE_METHOD, VC_MANAGER_METHOD_UTTERANCE_STATUS);
1310 bundle_add_str(msg, VC_BUNDLE_PID, pid_char);
1311 bundle_add_str(msg, VC_BUNDLE_REASON, uttid_char);
1312 bundle_add_str(msg, VC_BUNDLE_ERR_MSG, uttstatus_char);
1314 if (0 != rpc_port_stub_vcd_stub_vc_notify_cb_invoke(handle, pid, msg)) {
1315 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to send msg");
1317 pthread_mutex_unlock(&g_client_tidl_info_mutex);
1322 pthread_mutex_unlock(&g_client_tidl_info_mutex);
1324 SLOG(LOG_DEBUG, TAG_VCD, "@@@");
1327 static void __vc_mgr_send_audio_streaming_cb(rpc_port_stub_vcd_mgr_stub_vc_mgr_context_h context, int pid, int event, rpc_port_stub_vcd_mgr_stub_array_char_h data, void *user_data)
1329 SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Manager send audio streaming");
1331 char* buffer = NULL;
1334 rpc_port_stub_vcd_mgr_stub_array_char_get(data, &buffer, &len);
1336 SLOG(LOG_INFO, TAG_VCD, "[IN] vcd mgr send audio streaming : pid(%d), event(%d), buffer(%p), len(%d)", pid, event, buffer, len);
1338 ret = vcd_server_mgr_send_audio_streaming(pid, event, buffer, (unsigned int)len);
1340 SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret);
1343 SLOG(LOG_DEBUG, TAG_VCD, "@@@");
1346 int __mgr_tidl_open_connection()
1348 SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] __mgr_tidl_open_connection");
1350 g_mgr_callback.create = __vc_mgr_create_cb;
1351 g_mgr_callback.terminate = __vc_mgr_terminate_cb;
1352 g_mgr_callback.register_cb = __vc_mgr_register_cb_cb;
1353 g_mgr_callback.initialize = __vc_mgr_initialize_cb;
1354 g_mgr_callback.finalize = __vc_mgr_finalize_cb;
1355 g_mgr_callback.set_command = __vc_mgr_set_command_cb;
1356 g_mgr_callback.unset_command = __vc_mgr_unset_command_cb;
1357 g_mgr_callback.demandable_client = __vc_mgr_set_demandable_client_cb;
1358 g_mgr_callback.set_audio_type = __vc_mgr_set_audio_type_cb;
1359 g_mgr_callback.get_audio_type = __vc_mgr_get_audio_type_cb;
1360 g_mgr_callback.set_private_data = __vc_mgr_set_private_data_cb;
1361 g_mgr_callback.get_private_data = __vc_mgr_get_private_data_cb;
1362 g_mgr_callback.set_client_info = __vc_mgr_set_client_info_cb;
1363 g_mgr_callback.set_domain = __vc_mgr_set_domain_cb;
1364 g_mgr_callback.do_action = __vc_mgr_do_action_cb;
1365 g_mgr_callback.start = __vc_mgr_start_cb;
1366 g_mgr_callback.stop = __vc_mgr_stop_cb;
1367 g_mgr_callback.cancel = __vc_mgr_cancel_cb;
1368 g_mgr_callback.set_audio_streaming_mode = __vc_mgr_set_audio_streaming_mode_cb;
1369 g_mgr_callback.send_specific_engine_request = __vc_mgr_send_specific_engine_request_cb;
1370 g_mgr_callback.send_result_selection = __vc_mgr_send_result_selection_cb;
1371 g_mgr_callback.send_utterance_status = __vc_mgr_send_utterance_status_cb;
1372 g_mgr_callback.send_audio_streaming = __vc_mgr_send_audio_streaming_cb;
1376 while (VC_RETRY_MIN_COUNT >= count) {
1377 ret = rpc_port_stub_vcd_mgr_stub_vc_mgr_register(&g_mgr_callback, NULL);
1379 SLOG(LOG_DEBUG, TAG_VCD, "register callback");
1380 return VCD_ERROR_NONE;
1386 SLOG(LOG_ERROR, TAG_VCD, "Fail to register callback(%d)", ret);
1387 return VCD_ERROR_OPERATION_FAILED;
1390 int __mgr_tidl_close_connection()
1392 SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Close connection");
1393 rpc_port_stub_vcd_mgr_stub_vc_mgr_unregister();
1395 return VCD_ERROR_NONE;
1399 * TIDL callback functions for VC widget
1401 static void __widget_on_connected(rpc_port_proxy_vcd_widget_proxy_vcd_widget_h h, void *user_data)
1403 widget_tidl_info_s* widget_tidl_info = vcd_client_widget_get_tidl_info((int)user_data);
1405 widget_tidl_info->connected = true;
1406 widget_tidl_info->connection_requesting = false;
1408 SLOG(LOG_INFO, TAG_VCD, "Connected to widget");
1411 static void __widget_on_disconnected(rpc_port_proxy_vcd_widget_proxy_vcd_widget_h h, void *user_data)
1413 widget_tidl_info_s* widget_tidl_info = vcd_client_widget_get_tidl_info((int)user_data);
1415 widget_tidl_info->connected = false;
1416 widget_tidl_info->connection_requesting = false;
1418 SLOG(LOG_INFO, TAG_VCD, "Disonnected to widget");
1421 static void __widget_on_rejected(rpc_port_proxy_vcd_widget_proxy_vcd_widget_h h, void *user_data)
1423 widget_tidl_info_s* widget_tidl_info = vcd_client_widget_get_tidl_info((int)user_data);
1425 widget_tidl_info->connection_requesting = false;
1427 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Rejected from widget");
1430 static rpc_port_proxy_vcd_widget_proxy_vcd_widget_h __widget_create_rpc_port(const char* engine_app_id, int pid)
1432 SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] __widget_create_rpc_port");
1433 rpc_port_proxy_vcd_widget_proxy_vcd_widget_callback_s rpc_callback = {
1434 .connected = __widget_on_connected,
1435 .disconnected = __widget_on_disconnected,
1436 .rejected = __widget_on_rejected
1439 rpc_port_proxy_vcd_widget_proxy_vcd_widget_h handle = NULL;
1440 if (0 != rpc_port_proxy_vcd_widget_proxy_vcd_widget_create(engine_app_id, &rpc_callback, (void *)pid, &handle)) {
1441 SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to create proxy");
1448 static void __vc_widget_create_cb(rpc_port_stub_vcd_widget_stub_vc_widget_context_h context, void *user_data)
1450 char *sender = NULL;
1452 rpc_port_stub_vcd_widget_stub_vc_widget_context_get_sender(context, &sender);
1454 SLOG(LOG_ERROR, TAG_VCD, "Sender is NULL");
1458 SLOG(LOG_DEBUG, TAG_VCD, "@@@ Widget connect. appid(%s)", sender);
1462 static void __vc_widget_terminate_cb(rpc_port_stub_vcd_widget_stub_vc_widget_context_h context, void *user_data)
1465 rpc_port_stub_vcd_widget_stub_vc_widget_context_get_tag(context, &tag);
1468 int pid = (intptr_t)tag;
1469 SLOG(LOG_DEBUG, TAG_VCD, "@@@ VC WIDGET FINALIZE. pid(%u)", pid);
1471 pthread_mutex_lock(&g_widget_tidl_info_mutex);
1472 widget_tidl_info_s* widget_tidl_info = vcd_client_widget_get_tidl_info(pid);
1473 if (NULL == widget_tidl_info) {
1474 SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to get widget tidl info.");
1475 pthread_mutex_unlock(&g_widget_tidl_info_mutex);
1479 if (0 != vcd_client_widget_unset_tidl_notify_cb(pid)) {
1480 SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to unset notify callback");
1483 if (0 != vcd_client_widget_delete_tidl_info(pid)) {
1484 SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to delete widget tidl info");
1486 widget_tidl_info = NULL;
1488 SLOG(LOG_DEBUG, TAG_VCD, "@@@");
1490 pthread_mutex_unlock(&g_widget_tidl_info_mutex);
1492 char *sender = NULL;
1493 rpc_port_stub_vcd_widget_stub_vc_widget_context_get_sender(context, &sender);
1497 SLOG(LOG_INFO, TAG_VCD, "@@@ Manager disconnect. appid(%s)", sender);
1501 rpc_port_stub_vcd_widget_stub_vc_widget_context_set_tag(context, NULL);
1504 static void __vc_widget_register_cb_cb(rpc_port_stub_vcd_widget_stub_vc_widget_context_h context, int pid, rpc_port_stub_vcd_widget_stub_vc_widget_notify_cb_h notify_callback, void *user_data)
1506 pthread_mutex_lock(&g_widget_tidl_info_mutex);
1507 SLOG(LOG_INFO, TAG_VCD, "@@@ VC WIDGET REGISTER CALLBACK");
1510 ret = vcd_client_widget_add_tidl_info(pid);
1513 SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to add widget tidl info.");
1514 pthread_mutex_unlock(&g_widget_tidl_info_mutex);
1517 widget_tidl_info_s* widget_tidl_info = vcd_client_widget_get_tidl_info(pid);
1519 if (NULL == widget_tidl_info) {
1520 SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to get widget tidl info. pid(%d)", pid);
1521 pthread_mutex_unlock(&g_widget_tidl_info_mutex);
1525 char *sender = NULL;
1526 rpc_port_stub_vcd_widget_stub_vc_widget_context_get_sender(context, &sender);
1529 SLOG(LOG_ERROR, TAG_VCD, "Sender is NULL");
1530 pthread_mutex_unlock(&g_widget_tidl_info_mutex);
1534 widget_tidl_info->rpc_h = __widget_create_rpc_port(sender, pid);
1536 if (NULL == widget_tidl_info->rpc_h) {
1537 SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to create server proxy");
1539 SLOG(LOG_INFO, TAG_VCD, "[TIDL] rpc_h(%p), engine_app_id(%s)", widget_tidl_info->rpc_h, sender);
1544 if (0 != vcd_client_widget_set_tidl_notify_cb(pid, notify_callback, user_data)) {
1545 SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to set notify callback");
1547 SLOG(LOG_INFO, TAG_VCD, "[TIDL] Succeed to set notify callback.");
1550 pthread_mutex_unlock(&g_widget_tidl_info_mutex);
1552 __request_tidl_connect(VCD_CLIENT_TYPE_WIDGET, pid);
1554 SLOG(LOG_DEBUG, TAG_VCD, "@@@");
1557 static int __vc_widget_initialize_cb(rpc_port_stub_vcd_widget_stub_vc_widget_context_h context, int pid, int *service_state, int *daemon_pid, void *user_data)
1559 SLOG(LOG_INFO, TAG_VCD, "@@@ VCD Widget Initialize");
1561 uintptr_t ptr_pid = pid;
1564 rpc_port_stub_vcd_widget_stub_vc_widget_context_set_tag(context, (void*)ptr_pid);
1566 ret = vcd_server_widget_initialize(pid);
1568 SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret);
1571 *service_state = vcd_server_get_service_state();
1572 *daemon_pid = getpid();
1574 SLOG(LOG_INFO, TAG_VCD, "[IN] vcd widget initialize : pid(%d) service state(%d) daemon_pid(%d)", pid, *service_state, *daemon_pid);
1575 SLOG(LOG_DEBUG, TAG_VCD, "@@@");
1579 static int __vc_widget_finalize_cb(rpc_port_stub_vcd_widget_stub_vc_widget_context_h context, int pid, void *user_data)
1581 SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Widget Finalize");
1582 SLOG(LOG_INFO, TAG_VCD, "[IN] vcd widget finalize : pid(%d)", pid);
1586 ret = vcd_server_widget_finalize(pid);
1588 SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret);
1592 SLOG(LOG_DEBUG, TAG_VCD, "@@@");
1597 static int __vc_widget_start_recording_cb(rpc_port_stub_vcd_widget_stub_vc_widget_context_h context, int pid, int command, void *user_data)
1599 SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Widget Start Recording");
1600 SLOG(LOG_INFO, TAG_VCD, "[IN] vcd widget start recording : pid(%d) command(%d)", pid, command);
1604 ret = vcd_server_widget_start_recording(pid, command);
1606 SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret);
1610 SLOG(LOG_DEBUG, TAG_VCD, "@@@");
1615 static int __vc_widget_start_cb(rpc_port_stub_vcd_widget_stub_vc_widget_context_h context, int pid, int silence, void *user_data)
1617 SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Widget Start");
1618 SLOG(LOG_INFO, TAG_VCD, "[IN] vcd widget start : pid(%d) silence(%d)", pid, silence);
1622 ret = vcd_server_widget_start(pid, (bool)silence);
1624 SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret);
1628 SLOG(LOG_DEBUG, TAG_VCD, "@@@");
1633 static int __vc_widget_stop_cb(rpc_port_stub_vcd_widget_stub_vc_widget_context_h context, int pid, void *user_data)
1635 SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Widget Stop");
1636 SLOG(LOG_INFO, TAG_VCD, "[IN] vcd widget stop : pid(%d)", pid);
1640 ret = vcd_server_widget_stop(pid);
1642 SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret);
1646 SLOG(LOG_DEBUG, TAG_VCD, "@@@");
1651 static int __vc_widget_cancel_cb(rpc_port_stub_vcd_widget_stub_vc_widget_context_h context, int pid, void *user_data)
1653 SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Widget Cancel");
1654 SLOG(LOG_INFO, TAG_VCD, "[IN] vcd widget cancel : pid(%d)", pid);
1658 ret = vcd_server_widget_cancel(pid);
1660 SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret);
1664 SLOG(LOG_DEBUG, TAG_VCD, "@@@");
1669 static int __vc_widget_enable_asr_result_cb(rpc_port_stub_vcd_widget_stub_vc_widget_context_h context, int pid, int enable, void *user_data)
1671 SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Widget Enable Asr Result");
1672 SLOG(LOG_INFO, TAG_VCD, "[IN] vcd widget enable asr result : pid(%d) enable(%d)", pid, enable);
1676 ret = vcd_server_widget_enable_asr_result(pid, enable);
1678 SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret);
1682 SLOG(LOG_DEBUG, TAG_VCD, "@@@");
1687 static void __vc_widget_set_foreground_cb(rpc_port_stub_vcd_widget_stub_vc_widget_context_h context, int pid, int value, void *user_data)
1689 SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Widget Set Foreground");
1690 SLOG(LOG_INFO, TAG_VCD, "[IN] vcd widget set foreground : pid(%d) value(%d)", pid, value);
1694 ret = vcd_server_set_foreground(pid, value);
1696 SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret);
1700 SLOG(LOG_DEBUG, TAG_VCD, "@@@ send request set foreground to manager");
1701 vcdc_send_request_set_foreground(pid, value);
1703 SLOG(LOG_DEBUG, TAG_VCD, "@@@");
1708 int __widget_tidl_open_connection()
1710 SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] __widget_tidl_open_connection");
1712 g_widget_callback.create = __vc_widget_create_cb;
1713 g_widget_callback.terminate = __vc_widget_terminate_cb;
1714 g_widget_callback.register_cb = __vc_widget_register_cb_cb;
1715 g_widget_callback.initialize = __vc_widget_initialize_cb;
1716 g_widget_callback.finalize = __vc_widget_finalize_cb;
1717 g_widget_callback.start_recording = __vc_widget_start_recording_cb;
1718 g_widget_callback.start = __vc_widget_start_cb;
1719 g_widget_callback.stop = __vc_widget_stop_cb;
1720 g_widget_callback.cancel = __vc_widget_cancel_cb;
1721 g_widget_callback.enable_asr_result = __vc_widget_enable_asr_result_cb;
1722 g_widget_callback.set_foreground = __vc_widget_set_foreground_cb;
1726 while (VC_RETRY_MIN_COUNT >= count) {
1727 ret = rpc_port_stub_vcd_widget_stub_vc_widget_register(&g_widget_callback, NULL);
1729 SLOG(LOG_DEBUG, TAG_VCD, "register callback");
1730 return VCD_ERROR_NONE;
1736 SLOG(LOG_ERROR, TAG_VCD, "Fail to register callback(%d)", ret);
1737 return VCD_ERROR_OPERATION_FAILED;
1740 int __widget_tidl_close_connection()
1742 SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Close connection");
1743 rpc_port_stub_vcd_widget_stub_vc_widget_unregister();
1745 return VCD_ERROR_NONE;
1749 * TIDL callback functions for VC setting client
1751 static void __vc_setting_create_cb(rpc_port_stub_vcd_setting_stub_vc_setting_context_h context, void *user_data)
1753 SLOG(LOG_INFO, TAG_VCD, "[TIDL] __vc_setting_create_cb");
1755 char *sender = NULL;
1757 rpc_port_stub_vcd_setting_stub_vc_setting_context_get_sender(context, &sender);
1759 SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Sender is NULL");
1763 SLOG(LOG_INFO, TAG_VCD, "[TIDL] sender(%s)", sender); // sender (app_id)
1767 static void __vc_setting_terminate_cb(rpc_port_stub_vcd_setting_stub_vc_setting_context_h context, void *user_data)
1769 SLOG(LOG_INFO, TAG_VCD, "[TIDL] __vc_setting_terminate_cb");
1771 rpc_port_stub_vcd_setting_stub_vc_setting_context_get_tag(context, &tag);
1774 int pid = (intptr_t)tag;
1775 SLOG(LOG_DEBUG, TAG_VCD, "@@@ VC SETTING FINALIZE. pid(%u)", pid);
1777 pthread_mutex_lock(&g_setting_tidl_info_mutex);
1778 setting_tidl_info_s* setting_tidl_info = vcd_client_setting_get_tidl_info(pid);
1779 if (NULL == setting_tidl_info) {
1780 SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to get setting tidl info.");
1781 pthread_mutex_unlock(&g_setting_tidl_info_mutex);
1785 if (0 != vcd_client_setting_unset_tidl_notify_cb(pid)) {
1786 SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to unset notify callback");
1789 if (0 != vcd_client_setting_delete_tidl_info(pid)) {
1790 SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to delete setting tidl info");
1792 setting_tidl_info = NULL;
1794 SLOG(LOG_DEBUG, TAG_VCD, "@@@");
1796 pthread_mutex_unlock(&g_setting_tidl_info_mutex);
1798 rpc_port_stub_vcd_setting_stub_vc_setting_context_set_tag(context, NULL);
1801 static void __vc_setting_register_notify_cb_cb(rpc_port_stub_vcd_setting_stub_vc_setting_context_h context, int pid, rpc_port_stub_vcd_setting_stub_vc_setting_notify_cb_h callback, void *user_data)
1803 SLOG(LOG_INFO, TAG_VCD, "[TIDL] __vc_setting_register_notify_cb_cb. pid(%d)", pid);
1805 if (NULL == callback) {
1806 SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] callback is null.");
1811 ret = vcd_client_setting_add_tidl_info(pid);
1813 SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to add tidl info.");
1817 ret = vcd_client_setting_set_tidl_notify_cb(pid, callback, user_data);
1819 SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to set notify callback.");
1821 SLOG(LOG_INFO, TAG_VCD, "[TIDL] Succeed to set notify callback.");
1825 static int __vc_setting_register_notify_cb_sync_cb(rpc_port_stub_vcd_setting_stub_vc_setting_context_h context, int pid, rpc_port_stub_vcd_setting_stub_vc_setting_notify_cb_h callback, void *user_data)
1827 SLOG(LOG_INFO, TAG_VCD, "[TIDL] __vc_setting_register_notify_cb_sync_cb. pid(%d)", pid);
1829 if (NULL == callback) {
1830 SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] callback is null.");
1831 return VCD_ERROR_INVALID_PARAMETER;
1835 ret = vcd_client_setting_add_tidl_info(pid);
1837 SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to add tidl info.");
1841 ret = vcd_client_setting_set_tidl_notify_cb(pid, callback, user_data);
1843 SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to set notify callback.");
1845 SLOG(LOG_INFO, TAG_VCD, "[TIDL] Succeed to set notify callback.");
1851 int __vc_setting_set_language_cb(rpc_port_stub_vcd_setting_stub_vc_setting_context_h context, int pid, const char *language, void *user_data)
1853 if (NULL == language) {
1854 SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Invalid parameter");
1855 return VCD_ERROR_INVALID_PARAMETER;
1858 SLOG(LOG_INFO, TAG_VCD, "[IN] vcd server set language : language(%s)", language);
1860 int ret = vcd_server_set_language(language);
1862 SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to set language(%d).", ret);
1864 SLOG(LOG_INFO, TAG_VCD, "[TIDL] Succeed to set language.");
1870 int __setting_tidl_open_connection()
1872 SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] __setting_tidl_open_connection");
1874 g_setting_callback.create = __vc_setting_create_cb;
1875 g_setting_callback.terminate = __vc_setting_terminate_cb;
1876 g_setting_callback.register_notify_cb = __vc_setting_register_notify_cb_cb;
1877 g_setting_callback.register_notify_cb_sync = __vc_setting_register_notify_cb_sync_cb;
1878 g_setting_callback.set_language = __vc_setting_set_language_cb;
1882 while (VC_RETRY_MIN_COUNT >= count) {
1883 ret = rpc_port_stub_vcd_setting_stub_vc_setting_register(&g_setting_callback, NULL);
1885 SLOG(LOG_DEBUG, TAG_VCD, "register callback");
1886 return VCD_ERROR_NONE;
1892 SLOG(LOG_ERROR, TAG_VCD, "Fail to register callback(%d)", ret);
1893 return VCD_ERROR_OPERATION_FAILED;
1896 int __setting_tidl_close_connection()
1898 SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Close connection");
1899 rpc_port_stub_vcd_setting_stub_vc_setting_unregister();
1901 return VCD_ERROR_NONE;
1906 * Functions for sending the information to client sides
1908 int vcdc_send_error_signal_to_app(int pid, int reason, char *err_msg)
1910 if (NULL == err_msg) {
1911 SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Input parameter is NULL");
1912 return VCD_ERROR_INVALID_PARAMETER;
1915 client_tidl_info_s* info = vcd_client_get_tidl_info(pid);
1917 SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to get tidl info. pid(%d)", pid);
1918 return VCD_ERROR_INVALID_PARAMETER;
1921 bundle* msg = bundle_create();
1923 SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to create bundle data");
1924 return VCD_ERROR_OUT_OF_MEMORY;
1927 SLOG(LOG_INFO, TAG_VCD, "[TIDL] Send error signal to app(%d)", pid);
1929 char pid_char[10] = {0};
1930 char reason_char[10] = {0};
1931 snprintf(pid_char, 10, "%d", pid);
1932 snprintf(reason_char, 10, "%d", reason);
1934 bundle_add_str(msg, VC_BUNDLE_METHOD, VCD_METHOD_ERROR_TO_APP);
1935 bundle_add_str(msg, VC_BUNDLE_PID, pid_char);
1936 bundle_add_str(msg, VC_BUNDLE_REASON, reason_char);
1937 bundle_add_str(msg, VC_BUNDLE_ERR_MSG, err_msg);
1939 rpc_port_stub_vcd_stub_vc_notify_cb_invoke(info->notify_cb, pid, msg);
1941 return VCD_ERROR_NONE;
1944 int vcdc_send_manager_pid(int manager_pid)
1946 // send signal to all pid
1949 int* client_list = NULL;
1950 int client_count = 0;
1952 ret = vcd_client_get_tidl_list(&client_list, &client_count);
1953 if (0 != ret || 0 == client_count) {
1954 SLOG(LOG_WARN, TAG_VCD, "[WARNING] There is no client");
1955 return VCD_ERROR_NONE;
1958 client_tidl_info_s* info;
1961 char pid_char[10] = {0};
1962 char mgrpid_char[10] = {0};
1963 for (int i = 0 ; i < client_count ; i++) {
1964 pid = client_list[i];
1966 info = vcd_client_get_tidl_info(pid);
1968 SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to get tidl info. pid(%d)", pid);
1972 msg = bundle_create();
1974 SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to create bundle data");
1978 SLOG(LOG_INFO, TAG_VCD, "[TIDL] Send manager pid(%d) to app(%d)", manager_pid, pid);
1980 snprintf(pid_char, 10, "%d", pid);
1981 snprintf(mgrpid_char, 10, "%d", manager_pid);
1983 bundle_add_str(msg, VC_BUNDLE_METHOD, VCD_METHOD_SEND_MANAGER_PID);
1984 bundle_add_str(msg, VC_BUNDLE_PID, pid_char);
1985 bundle_add_str(msg, VC_BUNDLE_MANAGER_PID, mgrpid_char);
1987 rpc_port_stub_vcd_stub_vc_notify_cb_invoke(info->notify_cb, pid, msg);
1992 return VCD_ERROR_NONE;
1995 int vcdc_send_feedback_streaming(int pid, int utt_id, vc_feedback_event_e event, char* buffer, int len)
1997 if (NULL == buffer || 0 >= len) {
1998 SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Invalid parameter");
1999 return VCD_ERROR_INVALID_PARAMETER;
2002 client_tidl_info_s* info = vcd_client_get_tidl_info(pid);
2004 SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to get tidl info. pid(%d)", pid);
2005 return VCD_ERROR_NONE;
2008 SLOG(LOG_INFO, TAG_VCD, "[TIDL] Send feedback streaming to app(%d), utt_id(%d), event(%d), length(%d)", pid, utt_id, event, len);
2010 rpc_port_stub_vcd_stub_array_char_h arr_char = NULL;
2011 rpc_port_stub_vcd_stub_array_char_create(&arr_char);
2012 rpc_port_stub_vcd_stub_array_char_set(arr_char, buffer, len);
2014 rpc_port_stub_vcd_stub_vc_feedback_cb_invoke(info->feedback_cb, utt_id, event, arr_char, len);
2016 rpc_port_stub_vcd_stub_array_char_destroy(arr_char);
2019 return VCD_ERROR_NONE;
2022 int vcdc_send_hello(int pid, vcd_client_type_e type)
2024 SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Send hello");
2026 char tmp_pid[10] = {0, };
2028 bundle* msg = bundle_create();
2029 snprintf(tmp_pid, 10, "%d", pid);
2031 if (VCD_CLIENT_TYPE_NORMAL == type) {
2032 bundle_add_str(msg, VC_BUNDLE_METHOD, VCD_METHOD_HELLO);
2033 bundle_add_str(msg, VC_BUNDLE_PID, tmp_pid);
2034 } else if (VCD_CLIENT_TYPE_MANAGER == type) {
2035 bundle_add_str(msg, VC_BUNDLE_METHOD, VCD_MANAGER_METHOD_HELLO);
2036 bundle_add_str(msg, VC_BUNDLE_PID, tmp_pid);
2037 } else if (VCD_CLIENT_TYPE_WIDGET == type) {
2038 bundle_add_str(msg, VC_BUNDLE_METHOD, VCD_WIDGET_METHOD_HELLO);
2039 bundle_add_str(msg, VC_BUNDLE_PID, tmp_pid);
2041 SLOG(LOG_ERROR, TAG_VCD, "[Dbus ERROR] Client type is NOT valid");
2043 return VCD_ERROR_INVALID_PARAMETER;
2046 SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] VCD SEND MESSAGE");
2048 // TODO: VCD_CLIENT_TYPE_MANAGER?? type??
2049 __send_msg(msg, VCD_CLIENT_TYPE_MANAGER, pid);
2052 return VCD_ERROR_NONE;
2055 int vcd_tidl_open_connection()
2057 SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] vcd_tidl_open_connection");
2059 if (0 != __mgr_tidl_open_connection()) {
2060 SLOG(LOG_ERROR, TAG_VCD, "Fail to open connection to manager");
2061 return VCD_ERROR_OPERATION_FAILED;
2064 if (0 != __client_tidl_open_connection()) {
2065 SLOG(LOG_ERROR, TAG_VCD, "Fail to open connection to client");
2066 return VCD_ERROR_OPERATION_FAILED;
2069 if (0 != __widget_tidl_open_connection()) {
2070 SLOG(LOG_ERROR, TAG_VCD, "Fail to open connection to widget");
2071 return VCD_ERROR_OPERATION_FAILED;
2074 if (0 != __setting_tidl_open_connection()) {
2075 SLOG(LOG_ERROR, TAG_VCD, "Fail to open connection to setting");
2076 return VCD_ERROR_OPERATION_FAILED;
2079 return VCD_ERROR_NONE;
2082 int vcd_tidl_close_connection()
2084 SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] vcd_tidl_close_connection");
2086 if (0 != __mgr_tidl_close_connection()) {
2087 SLOG(LOG_ERROR, TAG_VCD, "Fail to close connection to manager");
2088 return VCD_ERROR_OPERATION_FAILED;
2091 if (0 != __client_tidl_close_connection()) {
2092 SLOG(LOG_ERROR, TAG_VCD, "Fail to close connection to client");
2093 return VCD_ERROR_OPERATION_FAILED;
2096 if (0 != __widget_tidl_close_connection()) {
2097 SLOG(LOG_ERROR, TAG_VCD, "Fail to close connection to widget");
2098 return VCD_ERROR_OPERATION_FAILED;
2101 if (0 != __setting_tidl_close_connection()) {
2102 SLOG(LOG_ERROR, TAG_VCD, "Fail to close connection to setting");
2103 return VCD_ERROR_OPERATION_FAILED;
2106 return VCD_ERROR_NONE;
2109 int vcdc_send_set_volume(int manager_pid, float volume)
2111 SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Set volume");
2113 char tmp_volume[20] = {0, };
2115 bundle* msg = bundle_create();
2117 snprintf(tmp_volume, 20, "%.6f", volume);
2118 bundle_add_str(msg, VC_BUNDLE_METHOD, VCD_MANAGER_METHOD_SET_VOLUME);
2119 bundle_add_str(msg, VC_BUNDLE_VOLUME, tmp_volume);
2122 SLOG(LOG_DEBUG, TAG_VCD, ">>>> VCD SEND MESSAGE");
2123 __send_msg(msg, VCD_CLIENT_TYPE_MANAGER, manager_pid);
2124 if (20 == g_volume_count) {
2125 SLOG(LOG_INFO, TAG_VCD, "@@ Send set volume : pid(%d), volume(%f)", manager_pid, volume);
2132 return VCD_ERROR_NONE;
2135 int vcdc_send_show_tooltip(int pid, bool show)
2137 SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Send pre result to manager");
2139 char tmp_pid[10] = {0, };
2140 char tmp_show[10] = {0, };
2142 bundle* msg = bundle_create();
2144 snprintf(tmp_pid, 10, "%d", pid);
2145 snprintf(tmp_show, 10, "%d", (int)show);
2147 bundle_add_str(msg, VC_BUNDLE_METHOD, VCD_WIDGET_METHOD_SHOW_TOOLTIP);
2148 bundle_add_str(msg, VC_BUNDLE_PID, tmp_pid);
2149 bundle_add_str(msg, VC_BUNDLE_SHOW, tmp_show);
2151 SLOG(LOG_DEBUG, TAG_VCD, ">>>> VCD SEND MESSAGE");
2153 __send_msg(msg, VCD_CLIENT_TYPE_WIDGET, pid);
2156 return VCD_ERROR_NONE;
2159 int vcdc_send_result(int pid, int manager_pid, int cmd_type)
2161 SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Send result");
2163 vcd_client_type_e type;
2164 bundle* msg = bundle_create();
2166 SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to create bundle data");
2167 return VCD_ERROR_OUT_OF_MEMORY;
2170 SLOG(LOG_INFO, TAG_VCD, "[TIDL] Result command type(%d)", cmd_type);
2173 case VC_COMMAND_TYPE_FOREGROUND:
2174 case VC_COMMAND_TYPE_BACKGROUND:
2175 if (pid == manager_pid) {
2176 type = VCD_CLIENT_TYPE_MANAGER;
2177 bundle_add_str(msg, VC_BUNDLE_METHOD, VCD_MANAGER_METHOD_RESULT);
2179 type = VCD_CLIENT_TYPE_NORMAL;
2180 char pid_char[10] = {0};
2181 snprintf(pid_char, 10, "%d", pid);
2182 bundle_add_str(msg, VC_BUNDLE_PID, pid_char);
2183 bundle_add_str(msg, VC_BUNDLE_METHOD, VCD_METHOD_RESULT);
2186 case VC_COMMAND_TYPE_WIDGET:
2187 type = VCD_CLIENT_TYPE_WIDGET;
2188 bundle_add_str(msg, VC_BUNDLE_METHOD, VCD_WIDGET_METHOD_RESULT);
2190 case VC_COMMAND_TYPE_SYSTEM:
2191 case VC_COMMAND_TYPE_SYSTEM_BACKGROUND:
2192 case VC_COMMAND_TYPE_EXCLUSIVE:
2193 type = VCD_CLIENT_TYPE_MANAGER;
2194 bundle_add_str(msg, VC_BUNDLE_METHOD, VCD_MANAGER_METHOD_RESULT);
2198 SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Command type is NOT valid(%d)", cmd_type);
2200 return VCD_ERROR_INVALID_PARAMETER;
2203 SLOG(LOG_DEBUG, TAG_VCD, ">>>> VCD SEND MESSAGE");
2205 __send_msg(msg, type, pid);
2208 return VCD_ERROR_NONE;
2211 int vcdc_send_pre_result_to_manager(int manager_pid, int event, const char* pre_result)
2213 SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Send pre result to manager");
2215 char tmp_event[10] = {0, };
2217 bundle* msg = bundle_create();
2218 snprintf(tmp_event, 10, "%d", event);
2220 bundle_add_str(msg, VC_BUNDLE_METHOD, VCD_MANAGER_METHOD_PRE_RESULT);
2221 bundle_add_str(msg, VC_BUNDLE_EVENT, tmp_event);
2222 bundle_add_str(msg, VC_BUNDLE_PRE_RESULT, pre_result);
2224 SLOG(LOG_DEBUG, TAG_VCD, ">>>> VCD SEND MESSAGE");
2226 __send_msg(msg, VCD_CLIENT_TYPE_MANAGER, manager_pid);
2229 return VCD_ERROR_NONE;
2232 int vcdc_send_specific_engine_result_to_manager(int manager_pid, const char* engine_app_id, const char* event, const char* result)
2234 SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Send specific engine result to manager");
2236 bundle* msg = bundle_create();
2238 gchar *gEncodedResult = g_base64_encode((const guchar*)result, strlen(result));
2240 bundle_add_str(msg, VC_BUNDLE_METHOD, VCD_MANAGER_METHOD_SPECIFIC_ENGINE_RESULT);
2241 bundle_add_str(msg, VC_BUNDLE_ENGINE_APP_ID, engine_app_id);
2242 bundle_add_str(msg, VC_BUNDLE_EVENT, event);
2243 bundle_add_str(msg, VC_BUNDLE_RESULT, gEncodedResult);
2245 SLOG(LOG_DEBUG, TAG_VCD, ">>>> VCD SEND MESSAGE");
2247 __send_msg(msg, VCD_CLIENT_TYPE_MANAGER, manager_pid);
2251 g_free(gEncodedResult);
2253 return VCD_ERROR_NONE;
2256 int vcdc_send_result_to_manager(int manager_pid, int result_type)
2258 SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Send result to manager");
2260 char tmp_result[10] = {0, };
2262 bundle* msg = bundle_create();
2263 snprintf(tmp_result, 10, "%d", result_type);
2265 bundle_add_str(msg, VC_BUNDLE_METHOD, VCD_MANAGER_METHOD_ALL_RESULT);
2266 bundle_add_str(msg, VC_BUNDLE_RESULT, tmp_result);
2269 SLOG(LOG_DEBUG, TAG_VCD, ">>>> VCD SEND MESSAGE");
2271 __send_msg(msg, VCD_CLIENT_TYPE_MANAGER, manager_pid);
2274 return VCD_ERROR_NONE;
2277 int vcdc_send_speech_detected(int manager_pid)
2279 SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Send speech detected");
2281 bundle* msg = bundle_create();
2283 bundle_add_str(msg, VC_BUNDLE_METHOD, VCD_MANAGER_METHOD_SPEECH_DETECTED);
2285 SLOG(LOG_DEBUG, TAG_VCD, ">>>> VCD SEND MESSAGE");
2287 __send_msg(msg, VCD_CLIENT_TYPE_MANAGER, manager_pid);
2290 return VCD_ERROR_NONE;
2293 int vcdc_send_service_state(vcd_state_e state)
2295 SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Send service state");
2297 char tmp_state[10] = {0, };
2299 bundle* msg = bundle_create();
2300 snprintf(tmp_state, 10, "%d", (int)state);
2302 bundle_add_str(msg, VC_BUNDLE_METHOD, VCD_MANAGER_METHOD_SET_SERVICE_STATE);
2303 bundle_add_str(msg, VC_BUNDLE_SERVICE_STATE, tmp_state);
2304 __send_signal(msg, VCD_CLIENT_TYPE_MANAGER);
2306 bundle_add_str(msg, VC_BUNDLE_METHOD, VCD_METHOD_SET_SERVICE_STATE);
2307 bundle_add_str(msg, VC_BUNDLE_SERVICE_STATE, tmp_state);
2308 __send_signal(msg, VCD_CLIENT_TYPE_NORMAL);
2310 bundle_add_str(msg, VC_BUNDLE_METHOD, VCD_WIDGET_METHOD_SET_SERVICE_STATE);
2311 bundle_add_str(msg, VC_BUNDLE_SERVICE_STATE, tmp_state);
2312 __send_signal(msg, VCD_CLIENT_TYPE_WIDGET);
2314 SLOG(LOG_DEBUG, TAG_VCD, ">>>> VCD SEND SIGNAL");
2317 return VCD_ERROR_NONE;
2320 int vcdc_send_dialog(int manager_pid, int pid, const char* disp_text, const char* utt_text, int continuous)
2322 SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Send dialog");
2324 char tmp_pid[10] = {0, };
2325 char tmp_continuous[10] = {0, };
2326 char* tmp_disp_text = NULL;
2327 char* tmp_utt_text = NULL;
2328 bundle* msg = bundle_create();
2329 snprintf(tmp_pid, 10, "%d", pid);
2330 snprintf(tmp_continuous, 10, "%d", continuous);
2332 if (NULL == disp_text) {
2333 tmp_disp_text = strdup("#NULL");
2335 tmp_disp_text = strdup(disp_text);
2338 if (NULL == utt_text) {
2339 tmp_utt_text = strdup("#NULL");
2341 tmp_utt_text = strdup(utt_text);
2344 bundle_add_str(msg, VC_BUNDLE_METHOD, VCD_MANAGER_METHOD_DIALOG);
2345 bundle_add_str(msg, VC_BUNDLE_PID, tmp_pid);
2346 bundle_add_str(msg, VC_BUNDLE_DISP_TEXT, tmp_disp_text);
2347 bundle_add_str(msg, VC_BUNDLE_UTT_TEXT, tmp_utt_text);
2348 bundle_add_str(msg, VC_BUNDLE_CONTINUOUS, tmp_continuous);
2350 SLOG(LOG_DEBUG, TAG_VCD, ">>>> VCD SEND MESSAGE");
2352 __send_msg(msg, VCD_CLIENT_TYPE_MANAGER, manager_pid);
2354 free(tmp_disp_text);
2357 return VCD_ERROR_NONE;
2360 int vcdc_send_error_to_manager(int manager_pid, int reason, char *err_msg)
2362 SLOG(LOG_ERROR, TAG_VCD, "[TIDL] Send error signal to manager");
2364 char tmp_reason[10] = {0, };
2365 char tmp_daemon_pid[10] = {0, };
2366 char *temp_msg = NULL;
2368 if (NULL == err_msg) {
2369 SLOG(LOG_WARN, TAG_VCD, "[TIDL ERROR] Input parameter is NULL");
2370 temp_msg = strdup("#NULL");
2372 temp_msg = strdup(err_msg);
2375 bundle* msg = bundle_create();
2376 snprintf(tmp_reason, 10, "%d", reason);
2377 snprintf(tmp_daemon_pid, 10, "%d", getpid());
2379 bundle_add_str(msg, VC_BUNDLE_METHOD, VCD_MANAGER_METHOD_ERROR);
2380 bundle_add_str(msg, VC_BUNDLE_REASON, tmp_reason);
2381 bundle_add_str(msg, VC_BUNDLE_DAEMON_PID, tmp_daemon_pid);
2382 bundle_add_str(msg, VC_BUNDLE_ERR_MSG, temp_msg);
2384 SLOG(LOG_DEBUG, TAG_VCD, ">>>> VCD SEND MESSAGE");
2386 __send_msg(msg, VCD_CLIENT_TYPE_MANAGER, manager_pid);
2392 return VCD_ERROR_NONE;
2396 // TODO: remove _tidl after remove dbus
2397 // TODO: make client, widget error signal
2398 // But... it seems there is no call of this function.. Need to check.
2399 int vcdc_tidl_send_error(int reason, char *err_msg)
2401 SLOG(LOG_ERROR, TAG_VCD, "[TIDL] Send error signal");
2403 char tmp_reason[10] = {0, };
2404 char tmp_daemon_pid[10] = {0, };
2405 char *temp_msg = NULL;
2407 if (NULL == err_msg) {
2408 SLOG(LOG_WARN, TAG_VCD, "[TIDL ERROR] Input parameter is NULL");
2409 temp_msg = strdup("#NULL");
2411 temp_msg = strdup(err_msg);
2414 bundle* msg = bundle_create();
2415 snprintf(tmp_reason, 10, "%d", reason);
2416 snprintf(tmp_daemon_pid, 10, "%d", getpid());
2418 bundle_add_str(msg, VC_BUNDLE_METHOD, VCD_MANAGER_METHOD_ERROR);
2419 bundle_add_str(msg, VC_BUNDLE_REASON, tmp_reason);
2420 bundle_add_str(msg, VC_BUNDLE_DAEMON_PID, tmp_daemon_pid);
2421 bundle_add_str(msg, VC_BUNDLE_ERR_MSG, temp_msg);
2423 bundle_add_str(msg, VC_BUNDLE_METHOD, VCD_WIDGET_METHOD_ERROR);
2424 bundle_add_str(msg, VC_BUNDLE_REASON, tmp_reason);
2425 bundle_add_str(msg, VC_BUNDLE_DAEMON_PID, tmp_daemon_pid);
2426 bundle_add_str(msg, VC_BUNDLE_ERR_MSG, temp_msg);
2428 SLOG(LOG_DEBUG, TAG_VCD, ">>>> VCD SEND SIGNAL");
2437 return VCD_ERROR_NONE;
2440 int vcdc_send_request_set_private_data(int pid, const char* key, const char* data)
2442 SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Set private data");
2444 char tmp_pid[10] = { 0, };
2446 bundle* msg = bundle_create();
2447 snprintf(tmp_pid, 10, "%d", pid);
2449 bundle_add_str(msg, VC_BUNDLE_METHOD, VCD_MANAGER_METHOD_SET_PRIVATE_DATA);
2450 bundle_add_str(msg, VC_BUNDLE_PID, tmp_pid);
2451 bundle_add_str(msg, VC_BUNDLE_KEY, key);
2452 bundle_add_str(msg, VC_BUNDLE_PRIVATE_DATA, data);
2454 SLOG(LOG_DEBUG, TAG_VCD, ">>>> VCD SEND MESSAGE");
2456 __send_msg(msg, VCD_CLIENT_TYPE_MANAGER, pid);
2459 return VCD_ERROR_NONE;
2462 int vcdc_send_feedback_audio_format_to_manager(int manager_pid, int rate, vc_audio_channel_e channel, vce_audio_type_e audio_type)
2464 SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Send feedback audio format to manager");
2466 char tmp_rate[10] = {0, };
2467 char tmp_channel[10] = {0, };
2468 char tmp_audio_type[10] = {0, };
2470 bundle* msg = bundle_create();
2471 snprintf(tmp_rate, 10, "%d", rate);
2472 snprintf(tmp_channel, 10, "%d", (int)channel);
2473 snprintf(tmp_audio_type, 10, "%d", (int)audio_type);
2474 bundle_add_str(msg, VC_BUNDLE_METHOD, VCD_MANAGER_METHOD_FEEDBACK_AUDIO_FORMAT);
2475 bundle_add_str(msg, VC_BUNDLE_AUDIO_RATE, tmp_rate);
2476 bundle_add_str(msg, VC_BUNDLE_AUDIO_CHANNEL, tmp_channel);
2477 bundle_add_str(msg, VC_BUNDLE_AUDIO_TYPE, tmp_audio_type);
2479 SLOG(LOG_DEBUG, TAG_VCD, ">>>> VCD SEND MESSAGE");
2481 __send_msg(msg, VCD_CLIENT_TYPE_MANAGER, manager_pid);
2484 return VCD_ERROR_NONE;
2487 int vcdc_send_feedback_streaming_to_manager(int manager_pid, int pid, int utt_id, vc_feedback_event_e event, char* buffer, int len)
2489 SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Send feedback streaming to manager");
2491 char tmp_pid[10] = {0, };
2492 char tmp_utt_id[10] = {0, };
2493 char tmp_event[10] = {0, };
2495 bundle* msg = bundle_create();
2496 snprintf(tmp_pid, 10, "%d", pid);
2497 snprintf(tmp_utt_id, 10, "%d", utt_id);
2498 snprintf(tmp_event, 10, "%d", (int)event);
2499 bundle_add_str(msg, VC_BUNDLE_METHOD, VCD_MANAGER_METHOD_FEEDBACK_STREAMING);
2500 bundle_add_str(msg, VC_BUNDLE_PID, tmp_pid);
2501 bundle_add_str(msg, VC_BUNDLE_UTT_ID, tmp_utt_id);
2502 bundle_add_str(msg, VC_BUNDLE_EVENT, tmp_event);
2504 rpc_port_stub_vcd_mgr_stub_array_char_h streaming_data = NULL;
2505 rpc_port_stub_vcd_mgr_stub_array_char_create(&streaming_data);
2506 if (NULL == streaming_data) {
2507 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to create data handle");
2508 return VCD_ERROR_OUT_OF_MEMORY;
2511 if (NULL != buffer && 0 < len) {
2512 rpc_port_stub_vcd_mgr_stub_array_char_set(streaming_data, (char*)buffer, len);
2514 SLOG(LOG_ERROR, TAG_VCD, "[TIDL] buffer is empty");
2517 SLOG(LOG_DEBUG, TAG_VCD, ">>>> VCD SEND MESSAGE");
2519 pthread_mutex_lock(&g_mgr_tidl_info_mutex);
2520 SLOG(LOG_INFO, TAG_VCD, "[TIDL] message to manager");
2521 manager_tidl_info_s* mgr_tidl_info = vcd_client_manager_get_tidl_info();
2523 if (NULL == mgr_tidl_info) {
2524 SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to get manager tidl info. pid(%d)", pid);
2525 pthread_mutex_unlock(&g_mgr_tidl_info_mutex);
2526 rpc_port_stub_vcd_mgr_stub_array_char_destroy(streaming_data);
2528 return VCD_ERROR_NONE;
2531 rpc_port_stub_vcd_mgr_stub_vc_mgr_send_buffer_cb_h handle = mgr_tidl_info->send_buffer_cb;
2532 if (NULL == handle) {
2533 SLOG(LOG_ERROR, TAG_VCD, "[TIDL] notify callback handle is null");
2534 pthread_mutex_unlock(&g_mgr_tidl_info_mutex);
2535 rpc_port_stub_vcd_mgr_stub_array_char_destroy(streaming_data);
2537 return VCD_ERROR_OPERATION_FAILED;
2540 if (0 != rpc_port_stub_vcd_mgr_stub_vc_mgr_send_buffer_cb_invoke(handle, streaming_data, msg)) {
2541 SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to send msg");
2542 pthread_mutex_unlock(&g_mgr_tidl_info_mutex);
2543 rpc_port_stub_vcd_mgr_stub_array_char_destroy(streaming_data);
2545 return VCD_ERROR_OPERATION_FAILED;
2547 pthread_mutex_unlock(&g_mgr_tidl_info_mutex);
2548 rpc_port_stub_vcd_mgr_stub_array_char_destroy(streaming_data);
2551 return VCD_ERROR_NONE;
2554 void vcdc_send_request_set_foreground(int pid, int value)
2556 SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Set foreground");
2558 manager_tidl_info_s* mgr_tidl_info = vcd_client_manager_get_tidl_info();
2560 if (NULL == mgr_tidl_info) {
2561 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to get tidl info");
2565 if (!mgr_tidl_info->connected) {
2566 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Not Connected");
2570 rpc_port_proxy_vcd_mgr_proxy_vcd_mgr_invoke_set_foreground(mgr_tidl_info->rpc_h, pid, value);
2572 SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Request set foreground");
2575 int vcdc_send_request_get_private_data(int pid, const char* key, char** data)
2577 SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Get private data");
2579 manager_tidl_info_s* mgr_tidl_info = vcd_client_manager_get_tidl_info();
2581 if (NULL == mgr_tidl_info) {
2582 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to get tidl info");
2583 return VC_ERROR_OPERATION_FAILED;
2586 if (!mgr_tidl_info->connected) {
2587 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Not Connected");
2588 return VC_ERROR_OPERATION_FAILED;
2592 int ret = rpc_port_proxy_vcd_mgr_proxy_vcd_mgr_invoke_get_private_data(mgr_tidl_info->rpc_h, pid, key, &tmp);
2593 if (RPC_PORT_ERROR_NONE != ret) {
2594 SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Request vcd manager get private data : Fail to invoke message, error(%d)", ret);
2597 SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Request vcd manager get private data : Success");
2601 return VC_ERROR_NONE;
2604 int vcdc_send_request_auth_enable(int pid)
2606 SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] auth enable");
2608 manager_tidl_info_s* mgr_tidl_info = vcd_client_manager_get_tidl_info();
2610 if (NULL == mgr_tidl_info) {
2611 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to get tidl info");
2612 return VC_ERROR_OPERATION_FAILED;
2615 if (!mgr_tidl_info->connected) {
2616 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Not Connected");
2617 return VC_ERROR_OPERATION_FAILED;
2620 int ret = rpc_port_proxy_vcd_mgr_proxy_vcd_mgr_invoke_auth_enable(mgr_tidl_info->rpc_h, pid);
2621 if (RPC_PORT_ERROR_NONE != ret) {
2622 SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Request auth enable : Fail to invoke message, error(%d)", ret);
2625 SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Request auth enable : Success");
2627 return VC_ERROR_NONE;
2630 int vcdc_send_request_auth_disable(int pid)
2632 SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] auth disable");
2634 manager_tidl_info_s* mgr_tidl_info = vcd_client_manager_get_tidl_info();
2636 if (NULL == mgr_tidl_info) {
2637 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to get tidl info");
2638 return VC_ERROR_OPERATION_FAILED;
2641 if (!mgr_tidl_info->connected) {
2642 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Not Connected");
2643 return VC_ERROR_OPERATION_FAILED;
2646 int ret = rpc_port_proxy_vcd_mgr_proxy_vcd_mgr_invoke_auth_disable(mgr_tidl_info->rpc_h, pid);
2647 if (RPC_PORT_ERROR_NONE != ret) {
2648 SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Request auth disable : Fail to invoke message, error(%d)", ret);
2651 SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Request auth disable : Success");
2653 return VC_ERROR_NONE;
2656 int vcdc_send_request_auth_start(int pid)
2658 SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] auth start");
2660 manager_tidl_info_s* mgr_tidl_info = vcd_client_manager_get_tidl_info();
2662 if (NULL == mgr_tidl_info) {
2663 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to get tidl info");
2664 return VC_ERROR_OPERATION_FAILED;
2667 if (!mgr_tidl_info->connected) {
2668 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Not Connected");
2669 return VC_ERROR_OPERATION_FAILED;
2672 int ret = rpc_port_proxy_vcd_mgr_proxy_vcd_mgr_invoke_auth_start(mgr_tidl_info->rpc_h, pid);
2673 if (RPC_PORT_ERROR_NONE != ret) {
2674 SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Request auth start : Fail to invoke message, error(%d)", ret);
2677 SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Request auth start : Success");
2679 return VC_ERROR_NONE;
2682 int vcdc_send_request_auth_stop(int pid)
2684 SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] auth stop");
2686 manager_tidl_info_s* mgr_tidl_info = vcd_client_manager_get_tidl_info();
2688 if (NULL == mgr_tidl_info) {
2689 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to get tidl info");
2690 return VC_ERROR_OPERATION_FAILED;
2693 if (!mgr_tidl_info->connected) {
2694 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Not Connected");
2695 return VC_ERROR_OPERATION_FAILED;
2698 int ret = rpc_port_proxy_vcd_mgr_proxy_vcd_mgr_invoke_auth_stop(mgr_tidl_info->rpc_h, pid);
2699 if (RPC_PORT_ERROR_NONE != ret) {
2700 SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Request auth stop : Fail to invoke message, error(%d)", ret);
2703 SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Request auth stop : Success");
2705 return VC_ERROR_NONE;
2708 int vcdc_send_request_auth_cancel(int pid)
2710 SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] auth cancel");
2712 manager_tidl_info_s* mgr_tidl_info = vcd_client_manager_get_tidl_info();
2714 if (NULL == mgr_tidl_info) {
2715 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to get tidl info");
2716 return VC_ERROR_OPERATION_FAILED;
2719 if (!mgr_tidl_info->connected) {
2720 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Not Connected");
2721 return VC_ERROR_OPERATION_FAILED;
2724 int ret = rpc_port_proxy_vcd_mgr_proxy_vcd_mgr_invoke_auth_cancel(mgr_tidl_info->rpc_h, pid);
2725 if (RPC_PORT_ERROR_NONE != ret) {
2726 SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Request auth cancel : Fail to invoke message, error(%d)", ret);
2729 SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Request auth cancel : Success");
2731 return VC_ERROR_NONE;
2734 int vcdc_send_asr_result(int pid, int event, const char* asr_result, int cmd_type, bool* is_consumed)
2736 SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Send asr result");
2738 widget_tidl_info_s* widget_tidl_info = vcd_client_widget_get_tidl_info(pid);
2740 if (NULL == widget_tidl_info) {
2741 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to get tidl info");
2742 return VC_ERROR_OPERATION_FAILED;
2745 if (!widget_tidl_info->connected) {
2746 SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Not Connected");
2747 return VC_ERROR_OPERATION_FAILED;
2751 int ret = rpc_port_proxy_vcd_widget_proxy_vcd_widget_invoke_send_asr_result(widget_tidl_info->rpc_h, pid, event, asr_result, &temp);
2752 if (RPC_PORT_ERROR_NONE != ret) {
2753 SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Request vcd widget send asr result : Fail to invoke message, error(%d)", ret);
2756 SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Request vcd widget send asr result : Success");
2758 *is_consumed = temp;
2760 return VC_ERROR_NONE;