From af4b421226b0e7ce7636b5f381dd5ea46b1503b3 Mon Sep 17 00:00:00 2001 From: "wn.jang" Date: Thu, 20 Jan 2022 15:31:25 +0900 Subject: [PATCH 01/16] Coverage support for robot profile Change-Id: Ifc880b594a7183e62603ee6801c5bad6465e985b --- packaging/voice-control.spec | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packaging/voice-control.spec b/packaging/voice-control.spec index b20f88d..0c353c1 100644 --- a/packaging/voice-control.spec +++ b/packaging/voice-control.spec @@ -158,8 +158,8 @@ mv -f org.tizen.voice.vcserver.tv.service org.tizen.voice.vcserver.service %make_install %if 0%{?gcov:1} -mkdir -p %{buildroot}%{_datadir}/gcov/obj -install -m 0644 gcov-obj/* %{buildroot}%{_datadir}/gcov/obj +mkdir -p %{buildroot}%{_datadir}/gcov/obj/%{name} +install -m 0644 gcov-obj/* %{buildroot}%{_datadir}/gcov/obj/%{name} %endif %post -- 2.7.4 From e200b2403672623bd57eeb8942450df548494b16 Mon Sep 17 00:00:00 2001 From: "wn.jang" Date: Thu, 20 Jan 2022 16:33:20 +0900 Subject: [PATCH 02/16] Update version to 1.70.1 Change-Id: I9d3cf3d032bdf59657fbb54729707b5b325f2743 --- CMakeLists.txt | 2 +- packaging/voice-control.spec | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index fe5746f..1c57109 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -26,7 +26,7 @@ PROJECT(vc) SET(PREFIX ${CMAKE_INSTALL_PREFIX}) SET(EXEC_PREFIX "${PREFIX}") -SET(VERSION 1.70.0) +SET(VERSION 1.70.1) FIND_PROGRAM(UNAME NAMES uname) EXEC_PROGRAM("${UNAME}" ARGS "-m" OUTPUT_VARIABLE "ARCH") diff --git a/packaging/voice-control.spec b/packaging/voice-control.spec index 0c353c1..3a6a5f2 100644 --- a/packaging/voice-control.spec +++ b/packaging/voice-control.spec @@ -1,6 +1,6 @@ Name: voice-control Summary: Voice control client library and daemon -Version: 1.70.0 +Version: 1.70.1 Release: 1 Group: Graphics & UI Framework/Voice Framework License: Apache-2.0 -- 2.7.4 From 877a5b40910fa1a85d23585cb3ef87fbfc1e7913 Mon Sep 17 00:00:00 2001 From: Suyeon Hwang Date: Fri, 7 Jan 2022 16:35:08 +0900 Subject: [PATCH 03/16] Call service state changed callback before state changed callback https://review.tizen.org/gerrit/c/platform/core/uifw/voice-control/+/223267 The patch of this link makes that service state changed callback is called asynchronously. This was because prepare process was handled on sub thread. In order to assure the callback calls on main thread, the patch seperated the code for calling service state changed callback and state changed callback. However, this change made client can not assure the value of service state because it was updated unknown timing. To solve this problem, this patch calls the service state changed callback before calling the state changed callback. Current code does not handle the prepare process on sub thread but on main thread. So, by this change, service state would be synchornously updated when the state changed callback is called. Change-Id: I276577fb494a93c8e4f58182c2e16a6ff88b7423 Signed-off-by: Suyeon Hwang --- client/vc_mgr.c | 20 +++++++++++++++++++- server/vcd_server.c | 12 ------------ 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/client/vc_mgr.c b/client/vc_mgr.c index 0c82dc8..9c07f62 100755 --- a/client/vc_mgr.c +++ b/client/vc_mgr.c @@ -457,6 +457,24 @@ static Eina_Bool __request_initialize(void *data) /* Success to connect */ } + /* Set service state */ + vc_service_state_e previous_service_state; + vc_mgr_client_get_service_state(g_vc_m, &previous_service_state); + vc_mgr_client_set_service_state(g_vc_m, (vc_service_state_e)service_state); + + vc_service_state_changed_cb service_changed_callback = NULL; + void* user_data = NULL; + vc_mgr_client_get_service_state_changed_cb(g_vc_m, &service_changed_callback, &user_data); + + if (NULL != service_changed_callback) { + vc_mgr_client_use_callback(g_vc_m); + service_changed_callback(previous_service_state, service_state, user_data); + vc_mgr_client_not_use_callback(g_vc_m); + SLOG(LOG_INFO, TAG_VCM, "Service state changed callback is called"); + } else { + SLOG(LOG_WARN, TAG_VCM, "[WARNING] Service state changed callback is null"); + } + /* Set foreground */ vc_mgr_client_set_foreground(g_vc_m, foreground, true); @@ -466,7 +484,7 @@ static Eina_Bool __request_initialize(void *data) vc_mgr_client_set_client_state(g_vc_m, VC_STATE_READY); vc_state_changed_cb changed_callback = NULL; - void* user_data = NULL; + user_data = NULL; vc_mgr_client_get_state_changed_cb(g_vc_m, &changed_callback, &user_data); vc_state_e current_state; diff --git a/server/vcd_server.c b/server/vcd_server.c index 81cbd50..faf41e5 100644 --- a/server/vcd_server.c +++ b/server/vcd_server.c @@ -1673,16 +1673,6 @@ int vcd_server_get_foreground() return pid; } -static Eina_Bool __vcd_send_service_state(void *data) -{ - vcd_config_set_service_state(VCD_STATE_READY); - vcdc_send_service_state(VCD_STATE_READY); - - SLOG(LOG_INFO, TAG_VCD, "[Server Success] success to send service status for READY"); - - return EINA_FALSE; -} - /* * API for manager */ @@ -1707,8 +1697,6 @@ int vcd_server_mgr_initialize(int pid, vcd_audio_streaming_mode_e mode) vcd_recorder_set_audio_streaming_mode(mode); - ecore_timer_add(0.05, __vcd_send_service_state, NULL); - SLOG(LOG_ERROR, TAG_VCD, "[Server Success] Manager initialize : pid(%d)", pid); return VCD_ERROR_NONE; -- 2.7.4 From 94c46f76d577b416f2351b093e4a26047f45aed7 Mon Sep 17 00:00:00 2001 From: "wn.jang" Date: Tue, 8 Feb 2022 14:24:43 +0900 Subject: [PATCH 04/16] Fix defects from static analysis tool Change-Id: I9cb797a9f2ab1ade83b2e752359fe906ede6c5f5 --- common/vc_cmd_db.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/common/vc_cmd_db.c b/common/vc_cmd_db.c index c5004ef..92df706 100644 --- a/common/vc_cmd_db.c +++ b/common/vc_cmd_db.c @@ -1498,8 +1498,9 @@ int __vc_db_open_db_for_daemon(char** path, sqlite3** db_handle) struct stat stat; int ret = db_util_open(*path, db_handle, DB_UTIL_REGISTER_HOOK_METHOD); if (ret != SQLITE_OK) { - SLOG(LOG_ERROR, vc_db_tag(), "[ERROR] Fail to open db, path = %s, ret %d: %s", *path, ret, sqlite3_errmsg(*db_handle)); + SLOG(LOG_ERROR, vc_db_tag(), "[ERROR] Fail to open db, path = %s, ret(%d)", *path, ret); if (*db_handle) { + SLOG(LOG_ERROR, vc_db_tag(), "[ERROR] Error msg (%s)", sqlite3_errmsg(*db_handle)); db_util_close(*db_handle); *db_handle = NULL; } @@ -1760,8 +1761,9 @@ int __vc_db_open_db(char** path, sqlite3** db_handle) { int ret = db_util_open(*path, db_handle, DB_UTIL_REGISTER_HOOK_METHOD); if (ret != SQLITE_OK) { - SLOG(LOG_ERROR, vc_db_tag(), "[ERROR] Fail to open db for daemon, path = %s, ret %d: %s", *path, ret, sqlite3_errmsg(*db_handle)); + SLOG(LOG_ERROR, vc_db_tag(), "[ERROR] Fail to open db for daemon, path = %s, ret(%d)", *path, ret); if (*db_handle) { + SLOG(LOG_ERROR, vc_db_tag(), "[ERROR] Error msg (%s)", sqlite3_errmsg(*db_handle)); db_util_close(*db_handle); *db_handle = NULL; } -- 2.7.4 From 04a6827ff78dc29bb196df46f7d1fdf706697566 Mon Sep 17 00:00:00 2001 From: "wn.jang" Date: Tue, 8 Feb 2022 14:56:05 +0900 Subject: [PATCH 05/16] Update version to 1.70.2 Change-Id: I6a3f5cd4bf2065da5f832aad153ebf4eb5a7b247 --- CMakeLists.txt | 2 +- packaging/voice-control.spec | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1c57109..def351d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -26,7 +26,7 @@ PROJECT(vc) SET(PREFIX ${CMAKE_INSTALL_PREFIX}) SET(EXEC_PREFIX "${PREFIX}") -SET(VERSION 1.70.1) +SET(VERSION 1.70.2) FIND_PROGRAM(UNAME NAMES uname) EXEC_PROGRAM("${UNAME}" ARGS "-m" OUTPUT_VARIABLE "ARCH") diff --git a/packaging/voice-control.spec b/packaging/voice-control.spec index 3a6a5f2..714e679 100644 --- a/packaging/voice-control.spec +++ b/packaging/voice-control.spec @@ -1,6 +1,6 @@ Name: voice-control Summary: Voice control client library and daemon -Version: 1.70.1 +Version: 1.70.2 Release: 1 Group: Graphics & UI Framework/Voice Framework License: Apache-2.0 -- 2.7.4 From 00abf454fae1e0da4b428537949111c632d755b4 Mon Sep 17 00:00:00 2001 From: sooyeon Date: Thu, 24 Feb 2022 00:19:48 +0900 Subject: [PATCH 06/16] Fix svace issue (PASSED_TO_PROC_AFTER_RELEASE) Change-Id: I5278c5197e3298fb4fdd933eb5972d8c3e6dc5f7 Signed-off-by: sooyeon --- common/vc_cmd_db.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/common/vc_cmd_db.c b/common/vc_cmd_db.c index 92df706..54c1df0 100644 --- a/common/vc_cmd_db.c +++ b/common/vc_cmd_db.c @@ -1499,7 +1499,7 @@ int __vc_db_open_db_for_daemon(char** path, sqlite3** db_handle) int ret = db_util_open(*path, db_handle, DB_UTIL_REGISTER_HOOK_METHOD); if (ret != SQLITE_OK) { SLOG(LOG_ERROR, vc_db_tag(), "[ERROR] Fail to open db, path = %s, ret(%d)", *path, ret); - if (*db_handle) { + if (db_handle && *db_handle) { SLOG(LOG_ERROR, vc_db_tag(), "[ERROR] Error msg (%s)", sqlite3_errmsg(*db_handle)); db_util_close(*db_handle); *db_handle = NULL; @@ -1762,7 +1762,7 @@ int __vc_db_open_db(char** path, sqlite3** db_handle) int ret = db_util_open(*path, db_handle, DB_UTIL_REGISTER_HOOK_METHOD); if (ret != SQLITE_OK) { SLOG(LOG_ERROR, vc_db_tag(), "[ERROR] Fail to open db for daemon, path = %s, ret(%d)", *path, ret); - if (*db_handle) { + if (db_handle && *db_handle) { SLOG(LOG_ERROR, vc_db_tag(), "[ERROR] Error msg (%s)", sqlite3_errmsg(*db_handle)); db_util_close(*db_handle); *db_handle = NULL; -- 2.7.4 From f90031768c89c5511eb437f3e91573a26abc4445 Mon Sep 17 00:00:00 2001 From: sooyeon Date: Thu, 24 Feb 2022 19:10:46 +0900 Subject: [PATCH 07/16] Update version (1.70.3) Change-Id: Ie8ba2b7c8d416de1662759984565737a5541bb9a Signed-off-by: sooyeon --- CMakeLists.txt | 2 +- packaging/voice-control.spec | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index def351d..d72a322 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -26,7 +26,7 @@ PROJECT(vc) SET(PREFIX ${CMAKE_INSTALL_PREFIX}) SET(EXEC_PREFIX "${PREFIX}") -SET(VERSION 1.70.2) +SET(VERSION 1.70.3) FIND_PROGRAM(UNAME NAMES uname) EXEC_PROGRAM("${UNAME}" ARGS "-m" OUTPUT_VARIABLE "ARCH") diff --git a/packaging/voice-control.spec b/packaging/voice-control.spec index 714e679..9c5e914 100644 --- a/packaging/voice-control.spec +++ b/packaging/voice-control.spec @@ -1,6 +1,6 @@ Name: voice-control Summary: Voice control client library and daemon -Version: 1.70.2 +Version: 1.70.3 Release: 1 Group: Graphics & UI Framework/Voice Framework License: Apache-2.0 -- 2.7.4 From 0f45e773e855163998050d3956dcb19903159cab Mon Sep 17 00:00:00 2001 From: "wn.jang" Date: Mon, 7 Mar 2022 12:12:27 +0900 Subject: [PATCH 08/16] Remove unused codes UpdateEvent has never used until now. But this should be supported for notifying update state. Therefore, I leave a TODO comment. Change-Id: I4ef0ea99785b51c23cf9c93363d93a65c67ca0a5 --- server/vce.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/server/vce.c b/server/vce.c index 5d71383..fae0fbb 100644 --- a/server/vce.c +++ b/server/vce.c @@ -384,16 +384,17 @@ int vce_set_private_data(const char* key, const char* data) return VCE_ERROR_INVALID_PARAMETER; } - if (!strncmp(key, "UpdateEventStart", strlen(key))) - ret = vce_send_update_status(VCE_UPDATE_EVENT_START, NULL); - else if (!strncmp(data, "UpdateEventComplete", strlen(key))) - ret = vce_send_update_status(VCE_UPDATE_EVENT_FINISH, NULL); - else if (!strncmp(data, "UpdateEventFail", strlen(key))) - ret = vce_send_update_status(VCE_UPDATE_EVENT_FAIL, data); - if (0 != ret) { - SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to send update status, event(%s), msg(%s): ret(%d)", key, data, ret); - return ret; - } + // TODO: Shoud be added updateEvent to client, need to ACR for update state. + // if (!strncmp(key, "UpdateEventStart", strlen(key))) + // ret = vce_send_update_status(VCE_UPDATE_EVENT_START, NULL); + // else if (!strncmp(key, "UpdateEventComplete", strlen(key))) + // ret = vce_send_update_status(VCE_UPDATE_EVENT_FINISH, NULL); + // else if (!strncmp(key, "UpdateEventFail", strlen(key))) + // ret = vce_send_update_status(VCE_UPDATE_EVENT_FAIL, data); + // if (0 != ret) { + // SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to send update status, event(%s), msg(%s): ret(%d)", key, data, ret); + // return ret; + // } ret = vcd_set_private_data(key, data); if (0 != ret) { -- 2.7.4 From a71829021ac0a28bc51c6ae1d9fbf996d3956c57 Mon Sep 17 00:00:00 2001 From: Suyeon Hwang Date: Mon, 14 Mar 2022 11:25:06 +0900 Subject: [PATCH 09/16] Add error into the description of vce_send_error() Change-Id: I64f455f0433459508d6016f16806fc9b296626ca Signed-off-by: Suyeon Hwang --- include/vce.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/include/vce.h b/include/vce.h index e700059..1b16529 100644 --- a/include/vce.h +++ b/include/vce.h @@ -877,7 +877,8 @@ int vce_send_specific_engine_result(const char* engine_app_id, const char* event * #VCE_ERROR_INVALID_LANGUAGE, \n * #VCE_ERROR_OPERATION_FAILED, \n * #VCE_ERROR_PERMISSION_DENIED, \n - * #VCE_ERROR_NOT_SUPPORTED_FEATURE. + * #VCE_ERROR_NOT_SUPPORTED_FEATURE \n + * #VCE_ERROR_TTS_FAILED. * @since_tizen @if MOBILE 4.0 @elseif WEARABLE 5.0 @endif * @param[in] error Error type * @param[in] msg Error message -- 2.7.4 From 58c72fc9dde94ee12ecae41b579b724c86269eba Mon Sep 17 00:00:00 2001 From: ulgal-park Date: Mon, 14 Feb 2022 19:31:00 +0900 Subject: [PATCH 10/16] Replace IPC between manager and server from dbus to tidl Change-Id: I0495d54c8a3ae5f89b5c38750e80760391a8e4c9 --- CMakeLists.txt | 2 +- client/CMakeLists.txt | 3 + client/vc_mgr.c | 90 +- client/vc_mgr_dbus.c | 1873 +++--------------------------------------- client/vc_mgr_dbus.h | 44 - client/vc_mgr_tidl.c | 1204 +++++++++++++++++++++++++++ client/vc_mgr_tidl.h | 85 ++ common/vc_defs.h | 26 +- packaging/voice-control.spec | 10 + server/CMakeLists.txt | 3 + server/vcd_client_data.c | 138 ++++ server/vcd_client_data.h | 30 + server/vcd_dbus.c | 647 +-------------- server/vcd_dbus.h | 31 +- server/vcd_dbus_server.c | 848 +------------------ server/vcd_dbus_server.h | 39 - server/vcd_engine_agent.c | 3 +- server/vcd_main.h | 6 + server/vcd_recorder.c | 1 + server/vcd_server.c | 33 +- server/vcd_server.h | 2 +- server/vcd_tidl.c | 1204 +++++++++++++++++++++++++++ server/vcd_tidl.h | 72 ++ server/vce.c | 1 + tidl/vc_mgr.tidl | 26 + tidl/vcd_mgr.tidl | 9 + 26 files changed, 3037 insertions(+), 3393 deletions(-) create mode 100755 client/vc_mgr_tidl.c create mode 100644 client/vc_mgr_tidl.h create mode 100644 server/vcd_tidl.c create mode 100644 server/vcd_tidl.h create mode 100644 tidl/vc_mgr.tidl create mode 100644 tidl/vcd_mgr.tidl diff --git a/CMakeLists.txt b/CMakeLists.txt index d72a322..a180809 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -47,7 +47,7 @@ INCLUDE_DIRECTORIES("${CMAKE_SOURCE_DIR}/include") INCLUDE(FindPkgConfig) pkg_check_modules(pkgs REQUIRED aul buxton2 capi-appfw-app-control capi-appfw-app-manager capi-base-common capi-media-audio-io capi-media-sound-manager ecore-wl2 - capi-system-info cynara-client cynara-session dbus-1 db-util dlog ecore glib-2.0 json-glib-1.0 libgum libtzplatform-config libxml-2.0 sqlite3 vconf gmock + capi-system-info cynara-client cynara-session dbus-1 db-util dlog ecore glib-2.0 json-glib-1.0 libgum libtzplatform-config libxml-2.0 sqlite3 vconf gmock bundle rpc-port ) diff --git a/client/CMakeLists.txt b/client/CMakeLists.txt index 29a1049..5815fa0 100644 --- a/client/CMakeLists.txt +++ b/client/CMakeLists.txt @@ -37,6 +37,9 @@ SET(MANAGER_SRCS vc_mgr_client.c vc_mgr_data.cpp vc_mgr_player.c + vc_mgr_tidl.c + vc_mgr_proxy.c + vc_mgr_stub.c vc_mgr_dbus.c ../common/vc_cmd_db.c ../common/vc_command.c diff --git a/client/vc_mgr.c b/client/vc_mgr.c index 9c07f62..c02b61b 100755 --- a/client/vc_mgr.c +++ b/client/vc_mgr.c @@ -31,6 +31,7 @@ #include "vc_json_parser.h" #include "vc_main.h" #include "vc_mgr_client.h" +#include "vc_mgr_tidl.h" #include "vc_mgr_dbus.h" #include "vc_mgr_data.h" #include "vc_mgr_player.h" @@ -46,7 +47,8 @@ static Ecore_Timer* g_send_hello_timer = NULL; static Ecore_Timer* g_request_init_timer = NULL; -static int g_send_hello_count = 0; +static int g_dbus_send_hello_count = 0; +static int g_tidl_send_hello_count = 0; static Ecore_Timer* g_m_set_volume_timer = NULL; @@ -276,8 +278,14 @@ int vc_mgr_initialize(void) return VC_ERROR_NONE; } + // TODO: remove dbus after migrate from dbus to tidl done if (0 != vc_mgr_dbus_open_connection()) { - SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to open connection"); + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to open dbus connection"); + return VC_ERROR_OPERATION_FAILED; + } + + if (0 != vc_mgr_tidl_open_connection()) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to open tidl connection"); return VC_ERROR_OPERATION_FAILED; } @@ -324,11 +332,16 @@ int vc_mgr_initialize(void) static void __vc_mgr_internal_unprepare() { - int ret = vc_mgr_dbus_request_finalize(g_vc_m->handle); + int ret = vc_mgr_tidl_request_finalize(g_vc_m->handle); if (0 != ret) { SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to request finalize : %s", __vc_mgr_get_error_code(ret)); } + ret = vc_mgr_dbus_request_finalize(g_vc_m->handle); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to request dbus finalize : %s", __vc_mgr_get_error_code(ret)); + } + vc_mgr_client_set_internal_state(g_vc_m, VC_INTERNAL_STATE_NONE); return; } @@ -403,10 +416,15 @@ int vc_mgr_deinitialize(void) SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to release VC mgr player(%d)", ret); } */ + // TODO: remove dbus after migrate from dbus to tidl done if (0 != vc_mgr_dbus_close_connection()) { SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to close connection"); } + if (0 != vc_mgr_tidl_close_connection()) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to close connection"); + } + SLOG(LOG_ERROR, TAG_VCM, "@@@"); return VC_ERROR_NONE; @@ -434,7 +452,7 @@ static Eina_Bool __request_initialize(void *data) vc_audio_streaming_mode_e streaming_mode; vc_mgr_client_get_audio_streaming_mode(g_vc_m, &streaming_mode); - ret = vc_mgr_dbus_request_initialize(g_vc_m->handle, (int)streaming_mode, &service_state, &foreground, &g_daemon_pid); + ret = vc_mgr_tidl_request_initialize(g_vc_m->handle, (int)streaming_mode, &service_state, &foreground, &g_daemon_pid); if (VC_ERROR_ENGINE_NOT_FOUND == ret) { SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to initialize : %s", __vc_mgr_get_error_code(ret)); @@ -516,15 +534,30 @@ static Eina_Bool __request_initialize(void *data) static Eina_Bool __send_hello_message(void *data) { /* Send hello */ + // TODO: remove dbus after migrate from dbus to tidl done if (0 != vc_mgr_dbus_request_hello()) { - if (g_send_hello_count == 20) { - g_send_hello_count = 0; + if (g_dbus_send_hello_count == 20) { + g_dbus_send_hello_count = 0; + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to request hello !! send error to manager"); + __vc_mgr_cb_error(VC_ERROR_TIMED_OUT, -1, "voice_framework.error.vcfw.connect_engine_fail"); + g_send_hello_timer = NULL; + return EINA_FALSE; + } else { + g_dbus_send_hello_count++; + return EINA_TRUE; + } + } + + /* Send hello */ + if (0 != vc_mgr_tidl_request_hello()) { + if (g_tidl_send_hello_count == 20) { + g_tidl_send_hello_count = 0; SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to request hello !! send error to manager"); __vc_mgr_cb_error(VC_ERROR_TIMED_OUT, -1, "voice_framework.error.vcfw.connect_engine_fail"); g_send_hello_timer = NULL; return EINA_FALSE; } else { - g_send_hello_count++; + g_tidl_send_hello_count++; return EINA_TRUE; } } @@ -570,7 +603,8 @@ int vc_mgr_prepare(void) } if (NULL == g_send_hello_timer) { - g_send_hello_count = 0; + g_dbus_send_hello_count = 0; + g_tidl_send_hello_count = 0; SLOG(LOG_INFO, TAG_VCM, "[DEBUG] Create a new timer for preparation"); ecore_thread_main_loop_begin(); g_send_hello_timer = ecore_timer_add(0.02, __send_hello_message, NULL); @@ -849,7 +883,7 @@ int vc_mgr_unset_demandable_client_rule(void) int count = 0; int ret = -1; while (0 != ret) { - ret = vc_mgr_dbus_request_demandable_client(g_vc_m->handle); + ret = vc_mgr_tidl_request_demandable_client(g_vc_m->handle); if (0 != ret) { if (VC_ERROR_TIMED_OUT != ret) { SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to request unset client rule to daemon : %s", __vc_mgr_get_error_code(ret)); @@ -1099,7 +1133,7 @@ int vc_mgr_set_command_list(vc_cmd_list_h vc_cmd_list) } else { int count = 0; do { - ret = vc_mgr_dbus_request_set_command(g_vc_m->handle); + ret = vc_mgr_tidl_request_set_command(g_vc_m->handle); if (0 != ret) { if (VC_ERROR_TIMED_OUT != ret) { SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to request set command to daemon : %s", __vc_mgr_get_error_code(ret)); @@ -1150,7 +1184,7 @@ int vc_mgr_unset_command_list(void) int count = 0; int ret = -1; while (0 != ret) { - ret = vc_mgr_dbus_request_unset_command(g_vc_m->handle); + ret = vc_mgr_tidl_request_unset_command(g_vc_m->handle); if (0 != ret) { if (VC_ERROR_TIMED_OUT != ret) { SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to request unset command to daemon : %s", __vc_mgr_get_error_code(ret)); @@ -1236,7 +1270,7 @@ int vc_mgr_set_command_list_from_file(const char* file_path, int type) } else { int count = 0; do { - ret = vc_mgr_dbus_request_set_command(g_vc_m->handle); + ret = vc_mgr_tidl_request_set_command(g_vc_m->handle); if (0 != ret) { if (VC_ERROR_TIMED_OUT != ret) { SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to request set command to daemon : %s", __vc_mgr_get_error_code(ret)); @@ -1354,7 +1388,7 @@ int vc_mgr_set_audio_type(const char* audio_id) /* Request */ while (0 != ret) { - ret = vc_mgr_dbus_request_set_audio_type(g_vc_m->handle, audio_id); + ret = vc_mgr_tidl_request_set_audio_type(g_vc_m->handle, audio_id); if (0 != ret) { if (VC_ERROR_TIMED_OUT != ret) { SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to set audio type : %s", __vc_mgr_get_error_code(ret)); @@ -1430,7 +1464,7 @@ int vc_mgr_get_audio_type(char** audio_id) int ret = -1; int count = 0; while (0 != ret) { - ret = vc_mgr_dbus_request_get_audio_type(g_vc_m->handle, &temp); + ret = vc_mgr_tidl_request_get_audio_type(g_vc_m->handle, &temp); if (0 != ret) { if (VC_ERROR_TIMED_OUT != ret) { SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to get audio type : %s", __vc_mgr_get_error_code(ret)); @@ -1541,7 +1575,7 @@ int vc_mgr_get_current_commands(vc_cmd_list_h* vc_cmd_list) ret = -1; count = 0; while (0 != ret) { - ret = vc_mgr_dbus_request_set_client_info(g_vc_m->handle); + ret = vc_mgr_tidl_request_set_client_info(g_vc_m->handle); if (0 != ret) { if (VC_ERROR_TIMED_OUT != ret) { SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to set client info : %s", __vc_mgr_get_error_code(ret)); @@ -1786,7 +1820,7 @@ int vc_mgr_set_private_data(const char* key, const char* data) } int ret = -1; - ret = vc_mgr_dbus_request_set_private_data(g_vc_m->handle, key, data); + ret = vc_mgr_tidl_request_set_private_data(g_vc_m->handle, key, data); if (0 != ret) { SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to set private data : %s", __vc_mgr_get_error_code(ret)); return ret; @@ -1845,7 +1879,7 @@ int vc_mgr_get_private_data(const char* key, char** data) char* temp = NULL; while (0 != ret) { - ret = vc_mgr_dbus_request_get_private_data(g_vc_m->handle, key, &temp); + ret = vc_mgr_tidl_request_get_private_data(g_vc_m->handle, key, &temp); if (0 != ret) { if (VC_ERROR_TIMED_OUT != ret) { SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to get private data request : %s", __vc_mgr_get_error_code(ret)); @@ -1919,7 +1953,7 @@ int vc_mgr_set_domain(const char* domain) int ret = -1; int count = 0; while (0 != ret) { - ret = vc_mgr_dbus_request_set_domain(g_vc_m->handle, domain); + ret = vc_mgr_tidl_request_set_domain(g_vc_m->handle, domain); if (0 != ret) { if (VC_ERROR_TIMED_OUT != ret) { SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to set domain request : %s", __vc_mgr_get_error_code(ret)); @@ -1989,7 +2023,7 @@ int vc_mgr_do_action(vc_send_event_type_e type, char* send_event) } int ret = -1; - ret = vc_mgr_dbus_request_do_action(g_vc_m->handle, type, send_event); + ret = vc_mgr_tidl_request_do_action(g_vc_m->handle, type, send_event); if (0 != ret) { SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to do action request : %s", __vc_mgr_get_error_code(ret)); return ret; @@ -2049,7 +2083,7 @@ int vc_mgr_send_specific_engine_request(const char* engine_app_id, const char* e } int ret = -1; - ret = vc_mgr_dbus_send_specific_engine_request(g_vc_m->handle, engine_app_id, event, request); + ret = vc_mgr_tidl_send_specific_engine_request(g_vc_m->handle, engine_app_id, event, request); if (0 != ret) { SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to specific engine request : %s", __vc_mgr_get_error_code(ret)); return ret; @@ -2129,7 +2163,7 @@ int vc_mgr_start(bool exclusive_command_option) count = 0; while (0 != ret) { vc_mgr_client_set_internal_state(g_vc_m, VC_INTERNAL_STATE_STARTING); - ret = vc_mgr_dbus_request_start(g_vc_m->handle, (int)recognition_mode, exclusive_command_option, start_by_client, disabled_cmd_type); + ret = vc_mgr_tidl_request_start(g_vc_m->handle, (int)recognition_mode, exclusive_command_option, start_by_client, disabled_cmd_type); if (0 != ret) { if (VC_ERROR_TIMED_OUT != ret) { SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to start request start : %s", __vc_mgr_get_error_code(ret)); @@ -2215,7 +2249,7 @@ int vc_mgr_stop(void) /* do request */ while (0 != ret) { vc_mgr_client_set_internal_state(g_vc_m, VC_INTERNAL_STATE_STOPPING); - ret = vc_mgr_dbus_request_stop(g_vc_m->handle); + ret = vc_mgr_tidl_request_stop(g_vc_m->handle); if (0 != ret) { if (VC_ERROR_TIMED_OUT != ret) { SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to stop request : %s", __vc_mgr_get_error_code(ret)); @@ -2294,7 +2328,7 @@ int vc_mgr_cancel(void) int count = 0; while (0 != ret) { vc_mgr_client_set_internal_state(g_vc_m, VC_INTERNAL_STATE_CANCELING); - ret = vc_mgr_dbus_request_cancel(g_vc_m->handle); + ret = vc_mgr_tidl_request_cancel(g_vc_m->handle); if (0 != ret) { if (VC_ERROR_TIMED_OUT != ret) { SLOG(LOG_DEBUG, TAG_VCM, "[ERROR] Fail to cancel request : %s", __vc_mgr_get_error_code(ret)); @@ -2338,7 +2372,7 @@ static Eina_Bool __vc_mgr_set_volume_timer_cb(void* data) int __vc_mgr_cb_set_volume(float volume) { - // called in vc_mgr_dbus + // called in vc_mgr_tidl g_prev_volume_db = g_volume_db; g_cur_volume_db = volume; @@ -2474,7 +2508,7 @@ int vc_mgr_set_selected_results(vc_cmd_list_h vc_cmd_list) /* Request */ int ret = -1; - ret = vc_mgr_dbus_send_result_selection(g_vc_m->handle); + ret = vc_mgr_tidl_send_result_selection(g_vc_m->handle); if (0 != ret) { SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to send result selection : %s", __vc_mgr_get_error_code(ret)); return ret; @@ -4501,7 +4535,7 @@ int vc_mgr_send_audio_streaming(vc_audio_streaming_event_e event, unsigned char* float volume = __get_volume_decibel((char*)buffer, len); __vc_mgr_set_volume(volume); - ret = vc_mgr_dbus_send_audio_streaming(g_vc_m->handle, event, buffer, len); + ret = vc_mgr_tidl_send_audio_streaming(g_vc_m->handle, event, buffer, len); if (0 != ret) SLOG(LOG_WARN, TAG_VCM, "[WARNING] retry to send audio streaming data"); else @@ -4560,12 +4594,12 @@ int vc_mgr_set_audio_streaming_mode(vc_audio_streaming_mode_e mode) SLOG(LOG_DEBUG, TAG_VCM, "[SUCCESS] Set audio streaming mode in vc mgr client"); } - ret = vc_mgr_dbus_request_set_audio_streaming_mode(g_vc_m->handle, mode); + ret = vc_mgr_tidl_request_set_audio_streaming_mode(g_vc_m->handle, mode); if (VC_ERROR_NONE != ret) { SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to set audio streaming mode : %s", __vc_mgr_get_error_code(ret)); return VC_ERROR_OPERATION_FAILED; } else { - SLOG(LOG_DEBUG, TAG_VCM, "[SUCCESS] Set audio streaming mode in vc mgr dbus"); + SLOG(LOG_DEBUG, TAG_VCM, "[SUCCESS] Set audio streaming mode in vc mgr tidl"); } } else { SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Invalid State: Current state is not 'INITIALIZED', state(%d)", state); diff --git a/client/vc_mgr_dbus.c b/client/vc_mgr_dbus.c index 7e2b875..c59a3d9 100755 --- a/client/vc_mgr_dbus.c +++ b/client/vc_mgr_dbus.c @@ -23,7 +23,6 @@ static pthread_mutex_t g_m_dbus_mutex = PTHREAD_MUTEX_INITIALIZER; -static int g_m_waiting_time = 3000; static int g_m_waiting_short_time = 200; static bool g_is_connection_opened = false; @@ -32,32 +31,13 @@ static Ecore_Fd_Handler* g_m_fd_handler = NULL; static DBusConnection* g_m_conn_sender = NULL; static DBusConnection* g_m_conn_listener = NULL; -static int g_volume_count = 0; - - -extern void __vc_mgr_cb_all_result(vc_result_type_e type); - -extern void __vc_mgr_cb_pre_result(int event, const char* pre_result); - -extern void __vc_mgr_cb_system_result(); - -extern void __vc_mgr_cb_speech_detected(); - extern int __vc_mgr_cb_error(int reason, int daemon_pid, char* msg); -extern int __vc_mgr_cb_set_volume(float volume); - -extern int __vc_mgr_cb_service_state(int state); - extern int __vc_mgr_cb_set_foreground(int pid, bool value); -extern int __vc_mgr_cb_private_data_set(const char* key, const char* data); - extern int __vc_mgr_cb_private_data_requested(const char* key, char** data); /* for TTS feedback */ -extern int __vc_mgr_cb_feedback_audio_format(int rate, vc_audio_channel_e channel, vc_audio_type_e audio_type); - extern int __vc_mgr_cb_feedback_streaming(int pid, int utt_id, vc_feedback_event_e event, char* buffer, int len); /* Authority */ @@ -71,10 +51,7 @@ extern int __vc_mgr_request_auth_stop(int pid); extern int __vc_mgr_request_auth_cancel(int pid); -extern int __vc_mgr_cb_dialog(int pid, const char* disp_text, const char* utt_text, bool continuous); - -extern void __vc_mgr_cb_specific_engine_result(const char* engine_app_id, const char* event, const char* result); - +// TODO: remove listener event callback static Eina_Bool vc_mgr_listener_event_callback(void* data, Ecore_Fd_Handler *fd_handler) { if (NULL == g_m_conn_listener) return ECORE_CALLBACK_RENEW; @@ -98,145 +75,7 @@ static Eina_Bool vc_mgr_listener_event_callback(void* data, Ecore_Fd_Handler *fd char if_name[64] = {0, }; snprintf(if_name, 64, "%s", VC_MANAGER_SERVICE_INTERFACE); - if (dbus_message_is_method_call(msg, if_name, VCD_MANAGER_METHOD_HELLO)) { - SLOG(LOG_INFO, TAG_VCM, "@@@ Get Hello"); - int pid = 0; - int response = -1; - - dbus_message_get_args(msg, &err, DBUS_TYPE_INT32, &pid, DBUS_TYPE_INVALID); - if (dbus_error_is_set(&err)) { - SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Dbus Error (%s)", err.message); - dbus_error_free(&err); - } - - if (pid > 0) { - SLOG(LOG_DEBUG, TAG_VCM, "@@ vc mgr get hello : pid(%d) ", pid); - response = 1; - } else { - SLOG(LOG_ERROR, TAG_VCM, "@@ vc mgr get hello : invalid pid "); - } - - DBusMessage *reply = NULL; - reply = dbus_message_new_method_return(msg); - - if (NULL != reply) { - dbus_message_append_args(reply, DBUS_TYPE_INT32, &response, DBUS_TYPE_INVALID); - - if (!dbus_connection_send(g_m_conn_listener, reply, NULL)) - SLOG(LOG_ERROR, TAG_VCM, "@@ vc get hello : fail to send reply"); - else - SLOG(LOG_INFO, TAG_VCM, "@@ vc get hello : result(%d)", response); - - dbus_connection_flush(g_m_conn_listener); - dbus_message_unref(reply); - } else { - SLOG(LOG_ERROR, TAG_VCM, "@@ vc mgr get hello : fail to create reply message"); - } - - SLOG(LOG_DEBUG, TAG_VCM, "@@@"); - } /* VCD_METHOD_HELLO */ - - else if (dbus_message_is_signal(msg, if_name, VCD_MANAGER_METHOD_SET_VOLUME)) { - float volume = 0; - - dbus_message_get_args(msg, &err, DBUS_TYPE_INT32, &volume, DBUS_TYPE_INVALID); - - if (dbus_error_is_set(&err)) { - SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Get arguments error (%s)", err.message); - dbus_error_free(&err); - } - - if (10 == g_volume_count) { - SLOG(LOG_DEBUG, TAG_VCM, "@@@ Set volume"); - SLOG(LOG_DEBUG, TAG_VCM, "@@ vc mgr set volume : volume(%f)", volume); - g_volume_count = 0; - } - - __vc_mgr_cb_set_volume(volume); - g_volume_count++; - - } /* VCD_MANAGER_METHOD_SET_VOLUME */ - - else if (dbus_message_is_method_call(msg, if_name, VCD_MANAGER_METHOD_SET_SERVICE_STATE)) { - int state = 0; - - dbus_message_get_args(msg, &err, DBUS_TYPE_INT32, &state, DBUS_TYPE_INVALID); - if (dbus_error_is_set(&err)) { - SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Get arguments error (%s)", err.message); - dbus_error_free(&err); - } - - SLOG(LOG_INFO, TAG_VCM, "@@ state changed : %d", state); - - __vc_mgr_cb_service_state(state); - - } /* VCD_MANAGER_METHOD_SET_SERVICE_STATE */ - - else if (dbus_message_is_method_call(msg, if_name, VCD_MANAGER_METHOD_SPEECH_DETECTED)) { - SLOG(LOG_INFO, TAG_VCM, "@@@ Get Speech detected"); - - __vc_mgr_cb_speech_detected(); - - SLOG(LOG_DEBUG, TAG_VCM, "@@@"); - - } /* VCD_MANAGER_METHOD_SPEECH_DETECTED */ - - else if (dbus_message_is_method_call(msg, if_name, VCD_MANAGER_METHOD_ALL_RESULT)) { - SLOG(LOG_INFO, TAG_VCM, "@@@ Get All Result"); - int result_type = 0; - - dbus_message_get_args(msg, &err, DBUS_TYPE_INT32, &result_type, DBUS_TYPE_INVALID); - - __vc_mgr_cb_all_result((vc_result_type_e)result_type); - - SLOG(LOG_DEBUG, TAG_VCM, "@@@"); - - } /* VCD_MANAGER_METHOD_ALL_RESULT */ - - else if (dbus_message_is_method_call(msg, if_name, VCD_MANAGER_METHOD_PRE_RESULT)) { - SLOG(LOG_INFO, TAG_VCM, "@@@ Get Pre Result"); - int event; - char* pre_result = NULL; - - dbus_message_get_args(msg, &err, DBUS_TYPE_INT32, &event, DBUS_TYPE_STRING, &pre_result, DBUS_TYPE_INVALID); - - if (NULL != pre_result) { - __vc_mgr_cb_pre_result((vc_pre_result_event_e)event, pre_result); - } - - SLOG(LOG_DEBUG, TAG_VCM, "@@@"); - } /* VCD_MANAGER_METHOD_PRE_RESULT */ - else if (dbus_message_is_method_call(msg, if_name, VCD_MANAGER_METHOD_SPECIFIC_ENGINE_RESULT)) { - SLOG(LOG_INFO, TAG_VCM, "@@@ Get specific engine result"); - char* engine_app_id = NULL; - char* event = NULL; - char* result = NULL; - - dbus_message_get_args(msg, &err, DBUS_TYPE_STRING, &engine_app_id, DBUS_TYPE_STRING, &event, DBUS_TYPE_STRING, &result, DBUS_TYPE_INVALID); - - if (NULL != result) { - gsize decodingSize=0; - gchar *gDecodedResult = (gchar *)g_base64_decode((const gchar *)result, &decodingSize); - if (gDecodedResult) - { - SLOG(LOG_WARN, TAG_VCM, "@@@ Get specific engine result --> %s", gDecodedResult); - __vc_mgr_cb_specific_engine_result(engine_app_id, event, gDecodedResult); - g_free(gDecodedResult); - } - } - - SLOG(LOG_DEBUG, TAG_VCM, "@@@"); - } /* VCD_MANAGER_METHOD_SPECIFIC_ENGINE_RESULT */ - else if (dbus_message_is_method_call(msg, if_name, VCD_MANAGER_METHOD_RESULT)) { - SLOG(LOG_INFO, TAG_VCM, "@@@ Get System Result"); - - __vc_mgr_cb_system_result(); - - SLOG(LOG_DEBUG, TAG_VCM, "@@@"); - - } /* VCD_MANAGER_METHOD_RESULT */ - - else if (dbus_message_is_signal(msg, if_name, VCC_MANAGER_METHOD_SET_FOREGROUND)) { + if (dbus_message_is_signal(msg, if_name, VCC_MANAGER_METHOD_SET_FOREGROUND)) { SLOG(LOG_INFO, TAG_VCM, "@@@ Set foreground"); int pid = 0; int value = 0; @@ -256,89 +95,6 @@ static Eina_Bool vc_mgr_listener_event_callback(void* data, Ecore_Fd_Handler *fd SLOG(LOG_DEBUG, TAG_VCM, "@@@"); } /* VCC_MANAGER_METHOD_SET_FOREGROUND */ - else if (dbus_message_is_method_call(msg, if_name, VCD_MANAGER_METHOD_DIALOG)) { - SLOG(LOG_INFO, TAG_VCM, "@@@ Request Dialog"); - int pid = -1; - char* disp_text = NULL; - char* utt_text = NULL; - int tmp_continue; - - dbus_message_get_args(msg, &err, - DBUS_TYPE_INT32, &pid, - DBUS_TYPE_STRING, &disp_text, - DBUS_TYPE_STRING, &utt_text, - DBUS_TYPE_INT32, &tmp_continue, - DBUS_TYPE_INVALID); - - if (!strcmp(disp_text, "NNUULLLL")) - disp_text = NULL; - if (!strcmp(utt_text, "NNUULLLL")) - utt_text = NULL; - - __vc_mgr_cb_dialog(pid, disp_text, utt_text, (bool)tmp_continue); - - SLOG(LOG_DEBUG, TAG_VCM, "@@@"); - - } /* VCD_MANAGER_METHOD_DIALOG */ - - else if (dbus_message_is_signal(msg, if_name, VCD_MANAGER_METHOD_ERROR)) { - SLOG(LOG_INFO, TAG_VCM, "@@@ Get Error"); - int reason; - int daemon_pid; - char* err_msg = NULL; - - dbus_message_get_args(msg, &err, - DBUS_TYPE_INT32, &reason, - DBUS_TYPE_INT32, &daemon_pid, - DBUS_TYPE_STRING, &err_msg, - DBUS_TYPE_INVALID); - - if (dbus_error_is_set(&err)) { - SLOG(LOG_ERROR, TAG_VCM, "@@ vc mgr Get Error message : Get arguments error (%s)", err.message); - dbus_error_free(&err); - } else { - char* temp_msg = NULL; - if (NULL != err_msg && strcmp("#NULL", err_msg)) { - temp_msg = strdup(err_msg); - } - SLOG(LOG_ERROR, TAG_VCM, "@@ vc mgr Get Error message : reason(%d), daemon_pid(%d), msg(%s)", reason, daemon_pid, (temp_msg) ? temp_msg : "NULL"); - __vc_mgr_cb_error(reason, daemon_pid, temp_msg); - if (NULL != temp_msg) { - free(temp_msg); - temp_msg = NULL; - } - } - - SLOG(LOG_DEBUG, TAG_VCM, "@@@"); - } /* VCD_MANAGER_METHOD_ERROR */ - - else if (dbus_message_is_method_call(msg, if_name, VCD_MANAGER_METHOD_SET_PRIVATE_DATA)) { - SLOG(LOG_INFO, TAG_VCM, "@@@ Get request set private data"); - int pid = 0; - char* key = NULL; - char* private_data = NULL; - - dbus_message_get_args(msg, &err, - DBUS_TYPE_INT32, &pid, - DBUS_TYPE_STRING, &key, - DBUS_TYPE_STRING, &private_data, - DBUS_TYPE_INVALID); - - if (dbus_error_is_set(&err)) { - SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Dbus Error (%s)", err.message); - dbus_error_free(&err); - } - - if (pid > 0) { - SLOG(LOG_INFO, TAG_VCM, "@@ vc mgr get request set private data : pid(%d) ", pid); - __vc_mgr_cb_private_data_set(key, private_data); - } else { - SLOG(LOG_ERROR, TAG_VCM, "@@ vc mgr get request set private data : invalid pid "); - } - - SLOG(LOG_DEBUG, TAG_VCM, "@@@"); - } /* VCD_MANAGER_METHOD_SET_PRIVATE_DATA */ - else if (dbus_message_is_method_call(msg, if_name, VCD_MANAGER_METHOD_GET_PRIVATE_DATA)) { SLOG(LOG_INFO, TAG_VCM, "@@@ Get request get private data"); int pid = 0; @@ -385,44 +141,6 @@ static Eina_Bool vc_mgr_listener_event_callback(void* data, Ecore_Fd_Handler *fd SLOG(LOG_DEBUG, TAG_VCM, "@@@"); } /* VCD_MANAGER_METHOD_GET_PRIVATE_DATA */ - else if (dbus_message_is_method_call(msg, if_name, VCD_MANAGER_METHOD_FEEDBACK_AUDIO_FORMAT)) { - SLOG(LOG_INFO, TAG_VCM, "@@@ Get TTS feedback audio format"); - int rate; - vc_audio_channel_e channel; - vc_audio_type_e audio_type; - - dbus_message_get_args(msg, &err, - DBUS_TYPE_INT32, &rate, - DBUS_TYPE_INT32, &channel, - DBUS_TYPE_INT32, &audio_type, - DBUS_TYPE_INVALID); - - __vc_mgr_cb_feedback_audio_format(rate, channel, audio_type); - - SLOG(LOG_INFO, TAG_VCM, "@@@"); - } /* VCD_MANAGER_METHOD_FEEDBACK_AUDIO_FORMAT */ - - else if (dbus_message_is_method_call(msg, if_name, VCD_MANAGER_METHOD_FEEDBACK_STREAMING)) { - SLOG(LOG_INFO, TAG_VCM, "@@@ Get TTS feedback streaming"); - int pid = -1; - int utt_id = -1;; - vc_feedback_event_e event; - char* buffer = NULL; - int len; - - dbus_message_get_args(msg, &err, - DBUS_TYPE_INT32, &pid, - DBUS_TYPE_INT32, &utt_id, - DBUS_TYPE_INT32, &event, - DBUS_TYPE_ARRAY, DBUS_TYPE_BYTE, - &buffer, &len, - DBUS_TYPE_INVALID); - - __vc_mgr_cb_feedback_streaming(pid, utt_id, event, buffer, len); - - SLOG(LOG_INFO, TAG_VCM, "@@@"); - } /* VCD_MANAGER_METHOD_FEEDBACK_STREAMING */ - /* Authority */ else if (dbus_message_is_method_call(msg, if_name, VC_METHOD_AUTH_ENABLE)) { SLOG(LOG_INFO, TAG_VCM, "@@@ Get request auth enable"); @@ -859,6 +577,7 @@ static int __dbus_check() int vc_mgr_dbus_request_hello() { + SLOG(LOG_DEBUG, TAG_VCM, "@@ Request vc hello start"); if (0 != __dbus_check()) { return VC_ERROR_OPERATION_FAILED; } @@ -898,6 +617,7 @@ int vc_mgr_dbus_request_hello() result = VC_ERROR_TIMED_OUT; } + SLOG(LOG_DEBUG, TAG_VCM, "@@ Request vc hello end"); return result; } @@ -927,7 +647,7 @@ static int __dbus_restore_daemon() return ret; } -int vc_mgr_dbus_request_initialize(int pid, int audio_streaming_mode, int* service_state, int* foreground, int* daemon_pid) +int vc_mgr_dbus_request_finalize(int pid) { if (0 != __dbus_check()) { return VC_ERROR_OPERATION_FAILED; @@ -952,1526 +672,123 @@ int vc_mgr_dbus_request_initialize(int pid, int audio_streaming_mode, int* servi return VC_ERROR_OPERATION_FAILED; } - DBusMessage* msg; - - msg = dbus_message_new_method_call( - VC_SERVER_SERVICE_NAME, - VC_SERVER_SERVICE_OBJECT_PATH, - VC_SERVER_SERVICE_INTERFACE, - VC_MANAGER_METHOD_INITIALIZE); - - if (NULL == msg) { - SLOG(LOG_ERROR, TAG_VCM, "@@ vc mgr initialize : Fail to make message "); - return VC_ERROR_OPERATION_FAILED; - } else { - SLOG(LOG_INFO, TAG_VCM, "@@ vc mgr initialize : pid(%d)", pid); - } - - dbus_message_append_args(msg, - DBUS_TYPE_INT32, &pid, - DBUS_TYPE_INT32, &audio_streaming_mode, - DBUS_TYPE_INVALID); - - DBusMessage* result_msg; - int result = VC_ERROR_OPERATION_FAILED; - - result_msg = dbus_connection_send_with_reply_and_block(g_m_conn_sender, msg, g_m_waiting_time, &err); - dbus_message_unref(msg); + /* remove a rule for daemon error */ + char rule_err[256] = {0, }; + snprintf(rule_err, 256, "sender='org.freedesktop.DBus',path='/org/freedesktop/DBus',interface='org.freedesktop.DBus',member='NameOwnerChanged',type='signal',arg0='%s'", VC_SERVER_SERVICE_INTERFACE); + dbus_bus_remove_match(g_m_conn_listener, rule_err, &err); + dbus_connection_flush(g_m_conn_listener); if (dbus_error_is_set(&err)) { - SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Dbus Error (%s)", err.message); + SLOG(LOG_ERROR, TAG_VCM, "Match Error (%s)", err.message); dbus_error_free(&err); + return VC_ERROR_OPERATION_FAILED; } - if (NULL != result_msg) { - int tmp_service_state = 0; - int tmp_foreground = 0; - int tmp_daemon_pid = 0; - dbus_message_get_args(result_msg, &err, - DBUS_TYPE_INT32, &result, - DBUS_TYPE_INT32, &tmp_service_state, - DBUS_TYPE_INT32, &tmp_foreground, - DBUS_TYPE_INT32, &tmp_daemon_pid, - DBUS_TYPE_INVALID); - - if (dbus_error_is_set(&err)) { - SLOG(LOG_ERROR, TAG_VCM, "@@ Get arguments error (%s)", err.message); - dbus_error_free(&err); - result = VC_ERROR_OPERATION_FAILED; - } - - dbus_message_unref(result_msg); + return VC_ERROR_NONE; +} - if (0 == result) { - *service_state = tmp_service_state; - *foreground = tmp_foreground; - *daemon_pid = tmp_daemon_pid; +static DBusMessage* __get_message(int pid, const char* method, int type) +{ + char service_name[64]; + char object_path[64]; + char target_if_name[128]; - /* add a rule for daemon error */ - char rule_err[256] = {0, }; - snprintf(rule_err, 256, "sender='org.freedesktop.DBus',path='/org/freedesktop/DBus',interface='org.freedesktop.DBus',member='NameOwnerChanged',type='signal',arg0='%s'", VC_SERVER_SERVICE_INTERFACE); - if (NULL == g_m_conn_listener) { - if (g_is_connection_opened) { - SLOG(LOG_ERROR, TAG_VCM, "[ERROR] g_m_conn_listener is NULL abnormally"); - return VC_ERROR_OPERATION_FAILED; - } else { - SLOG(LOG_INFO, TAG_VCM, "[INFO] g_m_conn_listener is NULL and DBUS connection was closed"); - return VC_ERROR_NONE; - } - } - dbus_bus_add_match(g_m_conn_listener, rule_err, NULL); + memset(service_name, '\0', 64); + memset(object_path, '\0', 64); + memset(target_if_name, '\0', 128); - SLOG(LOG_INFO, TAG_VCM, "@@ vc mgr initialize : result = %d, service state = %d, foreground = %d, daemon_pid = %d", - result, *service_state, *foreground, *daemon_pid); - } else { - SLOG(LOG_ERROR, TAG_VCM, "@@ vc mgr initialize : result = %d", result); - } + if (VC_COMMAND_TYPE_FOREGROUND == type || VC_COMMAND_TYPE_BACKGROUND == type) { + snprintf(service_name, 64, "%s%d", VC_CLIENT_SERVICE_NAME, pid); + snprintf(object_path, 64, "%s", VC_CLIENT_SERVICE_OBJECT_PATH); + snprintf(target_if_name, 128, "%s%d", VC_CLIENT_SERVICE_NAME, pid); + } else if (VC_COMMAND_TYPE_WIDGET == type) { + snprintf(service_name, 64, "%s%d", VC_WIDGET_SERVICE_NAME, pid); + snprintf(object_path, 64, "%s", VC_WIDGET_SERVICE_OBJECT_PATH); + snprintf(target_if_name, 128, "%s%d", VC_WIDGET_SERVICE_INTERFACE, pid); } else { - SLOG(LOG_ERROR, TAG_VCM, "@@ Result message is NULL "); - vc_mgr_dbus_reconnect(); - result = VC_ERROR_TIMED_OUT; + return NULL; } - return result; + SLOG(LOG_INFO, TAG_VCM, "[Dbus] Service(%s) object(%s) if(%s)", service_name, object_path, target_if_name); + + return dbus_message_new_method_call(service_name, object_path, target_if_name, method); } -int vc_mgr_dbus_request_finalize(int pid) +// int vc_mgr_dbus_send_result(int pid, int cmd_type, int result_id) +// { +// if (0 != __dbus_check()) { +// return VC_ERROR_OPERATION_FAILED; +// } + +// DBusMessage* msg = NULL; + +// switch (cmd_type) { +// case VC_COMMAND_TYPE_FOREGROUND: +// case VC_COMMAND_TYPE_BACKGROUND: +// msg = __get_message(pid, VCD_METHOD_RESULT, cmd_type); +// break; +// case VC_COMMAND_TYPE_WIDGET: +// msg = __get_message(pid, VCD_WIDGET_METHOD_RESULT, cmd_type); +// break; +// default: +// SLOG(LOG_ERROR, TAG_VCM, "[Dbus ERROR] Command type is NOT valid(%d)", cmd_type); +// return -1; +// } + +// if (NULL == msg) +// SLOG(LOG_ERROR, TAG_VCM, "[Dbus ERROR] Message is NULL"); + +// dbus_message_append_args(msg, DBUS_TYPE_INT32, &result_id, DBUS_TYPE_INVALID); + +// dbus_message_set_no_reply(msg, TRUE); + +// /* send the message and flush the connection */ +// if (1 != dbus_connection_send(g_m_conn_sender, msg, NULL)) { +// SLOG(LOG_ERROR, TAG_VCM, "[Dbus ERROR] Fail to Send"); +// dbus_message_unref(msg); +// return VC_ERROR_OPERATION_FAILED; +// } else { +// SLOG(LOG_INFO, TAG_VCM, "[Dbus] SUCCESS Send"); +// dbus_connection_flush(g_m_conn_sender); +// } + +// dbus_message_unref(msg); +// return 0; +// } + +int vc_mgr_dbus_send_utterance_status(int pid, int utt_id, vc_tts_utterance_status_e utt_status) { if (0 != __dbus_check()) { return VC_ERROR_OPERATION_FAILED; } - DBusError err; - dbus_error_init(&err); - - bool exist = dbus_bus_name_has_owner(g_m_conn_sender, VC_SERVER_SERVICE_NAME, &err); - if (dbus_error_is_set(&err)) { - SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Dbus Error (%s)", err.message); - dbus_error_free(&err); - } - - int ret; - if (false == exist) { - ret = __dbus_restore_daemon(); - if (VC_ERROR_NONE != ret) { - SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to restore daemon"); - return VC_ERROR_TIMED_OUT; - } - return VC_ERROR_OPERATION_FAILED; - } - - /* remove a rule for daemon error */ - char rule_err[256] = {0, }; - snprintf(rule_err, 256, "sender='org.freedesktop.DBus',path='/org/freedesktop/DBus',interface='org.freedesktop.DBus',member='NameOwnerChanged',type='signal',arg0='%s'", VC_SERVER_SERVICE_INTERFACE); - dbus_bus_remove_match(g_m_conn_listener, rule_err, &err); - dbus_connection_flush(g_m_conn_listener); + DBusMessage* msg; + msg = __get_message(pid, VC_MANAGER_METHOD_UTTERANCE_STATUS, VC_COMMAND_TYPE_FOREGROUND); - if (dbus_error_is_set(&err)) { - SLOG(LOG_ERROR, TAG_VCM, "Match Error (%s)", err.message); - dbus_error_free(&err); + if (NULL == msg) { + SLOG(LOG_ERROR, TAG_VCM, "@@ vc send utterance status : Fail to make message"); return VC_ERROR_OPERATION_FAILED; + } else { + SLOG(LOG_INFO, TAG_VCM, "@@ vc send utterance status : pid(%d), utt_id(%d), utt_status(%d)", pid, utt_id, utt_status); } - DBusMessage* msg; + dbus_message_append_args(msg, + DBUS_TYPE_INT32, &utt_id, + DBUS_TYPE_INT32, &utt_status, + DBUS_TYPE_INVALID); - msg = dbus_message_new_method_call( - VC_SERVER_SERVICE_NAME, - VC_SERVER_SERVICE_OBJECT_PATH, - VC_SERVER_SERVICE_INTERFACE, - VC_MANAGER_METHOD_FINALIZE); + dbus_message_set_no_reply(msg, TRUE); - if (NULL == msg) { - SLOG(LOG_ERROR, TAG_VCM, "@@ vc mgr finalize : Fail to make message "); + /* send the message and flush the connection */ + if (1 != dbus_connection_send(g_m_conn_sender, msg, NULL)) { + SLOG(LOG_ERROR, TAG_VCM, "[Dbus ERROR] Fail to Send"); + dbus_message_unref(msg); return VC_ERROR_OPERATION_FAILED; } else { - SLOG(LOG_INFO, TAG_VCM, "@@ vc mgr finalize : pid(%d)", pid); + SLOG(LOG_INFO, TAG_VCM, "[Dbus] SUCCESS Send"); + dbus_connection_flush(g_m_conn_sender); } - dbus_message_append_args(msg, DBUS_TYPE_INT32, &pid, DBUS_TYPE_INVALID); - - DBusMessage* result_msg; - int result = VC_ERROR_OPERATION_FAILED; - - result_msg = dbus_connection_send_with_reply_and_block(g_m_conn_sender, msg, g_m_waiting_time, &err); dbus_message_unref(msg); - - if (dbus_error_is_set(&err)) { - SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Dbus Error (%s)", err.message); - dbus_error_free(&err); - } - - if (NULL != result_msg) { - dbus_message_get_args(result_msg, &err, - DBUS_TYPE_INT32, &result, - DBUS_TYPE_INVALID); - - if (dbus_error_is_set(&err)) { - SLOG(LOG_ERROR, TAG_VCM, "@@ Get arguments error (%s)", err.message); - dbus_error_free(&err); - result = VC_ERROR_OPERATION_FAILED; - } - - dbus_message_unref(result_msg); - - if (0 == result) { - SLOG(LOG_INFO, TAG_VCM, "@@ vc mgr finalize : result = %d", result); - } else { - SLOG(LOG_ERROR, TAG_VCM, "@@ vc mgr finalize : result = %d", result); - } - } else { - SLOG(LOG_ERROR, TAG_VCM, "@@ Result message is NULL "); - vc_mgr_dbus_reconnect(); - result = VC_ERROR_TIMED_OUT; - } - - return result; -} - -int vc_mgr_dbus_request_set_command(int pid) -{ - if (0 != __dbus_check()) { - return VC_ERROR_OPERATION_FAILED; - } - - DBusError err; - dbus_error_init(&err); - - bool exist = dbus_bus_name_has_owner(g_m_conn_sender, VC_SERVER_SERVICE_NAME, &err); - if (dbus_error_is_set(&err)) { - SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Dbus Error (%s)", err.message); - dbus_error_free(&err); - } - - int ret; - if (false == exist) { - ret = __dbus_restore_daemon(); - if (VC_ERROR_NONE != ret) { - SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to restore daemon"); - return VC_ERROR_TIMED_OUT; - } - return VC_ERROR_OPERATION_FAILED; - } - - DBusMessage* msg; - - msg = dbus_message_new_method_call( - VC_SERVER_SERVICE_NAME, - VC_SERVER_SERVICE_OBJECT_PATH, - VC_SERVER_SERVICE_INTERFACE, - VC_MANAGER_METHOD_SET_COMMAND); - - if (NULL == msg) { - SLOG(LOG_ERROR, TAG_VCM, "@@ vc mgr set command : Fail to make message"); - return VC_ERROR_OPERATION_FAILED; - } else { - SLOG(LOG_INFO, TAG_VCM, "@@ vc mgr set command : pid(%d)", pid); - } - - dbus_message_append_args(msg, - DBUS_TYPE_INT32, &pid, - DBUS_TYPE_INVALID); - - DBusMessage* result_msg; - int result = VC_ERROR_OPERATION_FAILED; - - result_msg = dbus_connection_send_with_reply_and_block(g_m_conn_sender, msg, g_m_waiting_time, &err); - dbus_message_unref(msg); - - if (dbus_error_is_set(&err)) { - SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Dbus Error (%s)", err.message); - dbus_error_free(&err); - } - - if (NULL != result_msg) { - dbus_message_get_args(result_msg, &err, - DBUS_TYPE_INT32, &result, - DBUS_TYPE_INVALID); - - if (dbus_error_is_set(&err)) { - SLOG(LOG_ERROR, TAG_VCM, "@@ Get arguments error (%s)", err.message); - dbus_error_free(&err); - result = VC_ERROR_OPERATION_FAILED; - } - dbus_message_unref(result_msg); - - if (0 == result) { - SLOG(LOG_INFO, TAG_VCM, "@@ vc mgr set command : result = %d", result); - } else { - SLOG(LOG_ERROR, TAG_VCM, "@@ vc mgr set command : result = %d", result); - } - } else { - SLOG(LOG_ERROR, TAG_VCM, "@@ Result message is NULL"); - vc_mgr_dbus_reconnect(); - result = VC_ERROR_TIMED_OUT; - } - - return result; -} - -int vc_mgr_dbus_request_unset_command(int pid) -{ - if (0 != __dbus_check()) { - return VC_ERROR_OPERATION_FAILED; - } - - DBusError err; - dbus_error_init(&err); - - bool exist = dbus_bus_name_has_owner(g_m_conn_sender, VC_SERVER_SERVICE_NAME, &err); - if (dbus_error_is_set(&err)) { - SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Dbus Error (%s)", err.message); - dbus_error_free(&err); - } - - int ret; - if (false == exist) { - ret = __dbus_restore_daemon(); - if (VC_ERROR_NONE != ret) { - SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to restore daemon"); - return VC_ERROR_TIMED_OUT; - } - return VC_ERROR_OPERATION_FAILED; - } - - DBusMessage* msg; - - msg = dbus_message_new_method_call( - VC_SERVER_SERVICE_NAME, - VC_SERVER_SERVICE_OBJECT_PATH, - VC_SERVER_SERVICE_INTERFACE, - VC_MANAGER_METHOD_UNSET_COMMAND); - - if (NULL == msg) { - SLOG(LOG_ERROR, TAG_VCM, "@@ vc mgr unset command : Fail to make message"); - return VC_ERROR_OPERATION_FAILED; - } else { - SLOG(LOG_INFO, TAG_VCM, "@@ vc mgr unset command : pid(%d)", pid); - } - - dbus_message_append_args(msg, - DBUS_TYPE_INT32, &pid, - DBUS_TYPE_INVALID); - - DBusMessage* result_msg; - int result = VC_ERROR_OPERATION_FAILED; - - result_msg = dbus_connection_send_with_reply_and_block(g_m_conn_sender, msg, g_m_waiting_time, &err); - dbus_message_unref(msg); - - if (dbus_error_is_set(&err)) { - SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Dbus Error (%s)", err.message); - dbus_error_free(&err); - } - - if (NULL != result_msg) { - dbus_message_get_args(result_msg, &err, - DBUS_TYPE_INT32, &result, - DBUS_TYPE_INVALID); - - if (dbus_error_is_set(&err)) { - SLOG(LOG_ERROR, TAG_VCM, "@@ Get arguments error (%s)", err.message); - dbus_error_free(&err); - result = VC_ERROR_OPERATION_FAILED; - } - dbus_message_unref(result_msg); - - if (0 == result) { - SLOG(LOG_INFO, TAG_VCM, "@@ vc mgr unset command : result = %d", result); - } else { - SLOG(LOG_ERROR, TAG_VCM, "@@ vc mgr unset command : result = %d", result); - } - } else { - SLOG(LOG_ERROR, TAG_VCM, "@@ Result message is NULL"); - vc_mgr_dbus_reconnect(); - result = VC_ERROR_TIMED_OUT; - } - - return result; -} - -int vc_mgr_dbus_request_demandable_client(int pid) -{ - if (0 != __dbus_check()) { - return VC_ERROR_OPERATION_FAILED; - } - - DBusError err; - dbus_error_init(&err); - - bool exist = dbus_bus_name_has_owner(g_m_conn_sender, VC_SERVER_SERVICE_NAME, &err); - if (dbus_error_is_set(&err)) { - SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Dbus Error (%s)", err.message); - dbus_error_free(&err); - } - - int ret; - if (false == exist) { - ret = __dbus_restore_daemon(); - if (VC_ERROR_NONE != ret) { - SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to restore daemon"); - return VC_ERROR_TIMED_OUT; - } - return VC_ERROR_OPERATION_FAILED; - } - - DBusMessage* msg; - - msg = dbus_message_new_method_call( - VC_SERVER_SERVICE_NAME, - VC_SERVER_SERVICE_OBJECT_PATH, - VC_SERVER_SERVICE_INTERFACE, - VC_MANAGER_METHOD_SET_DEMANDABLE); - - if (NULL == msg) { - SLOG(LOG_ERROR, TAG_VCM, "@@ vc mgr set demandable client : Fail to make message"); - return VC_ERROR_OPERATION_FAILED; - } else { - SLOG(LOG_INFO, TAG_VCM, "@@ vc mgr set demandable client : pid(%d)", pid); - } - - dbus_message_append_args(msg, - DBUS_TYPE_INT32, &pid, - DBUS_TYPE_INVALID); - - DBusMessage* result_msg; - int result = VC_ERROR_OPERATION_FAILED; - - result_msg = dbus_connection_send_with_reply_and_block(g_m_conn_sender, msg, g_m_waiting_time, &err); - dbus_message_unref(msg); - - if (dbus_error_is_set(&err)) { - SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Dbus Error (%s)", err.message); - dbus_error_free(&err); - } - - if (NULL != result_msg) { - dbus_message_get_args(result_msg, &err, - DBUS_TYPE_INT32, &result, - DBUS_TYPE_INVALID); - - if (dbus_error_is_set(&err)) { - SLOG(LOG_ERROR, TAG_VCM, "@@ Get arguments error (%s)", err.message); - dbus_error_free(&err); - result = VC_ERROR_OPERATION_FAILED; - } - dbus_message_unref(result_msg); - - if (0 == result) { - SLOG(LOG_INFO, TAG_VCM, "@@ vc mgr set demandable client : result = %d", result); - } else { - SLOG(LOG_ERROR, TAG_VCM, "@@ vc mgr set demandable client : result = %d", result); - } - } else { - SLOG(LOG_ERROR, TAG_VCM, "@@ Result message is NULL"); - vc_mgr_dbus_reconnect(); - result = VC_ERROR_TIMED_OUT; - } - - return result; -} - -int vc_mgr_dbus_request_set_audio_type(int pid, const char* audio_type) -{ - if (0 != __dbus_check()) { - return VC_ERROR_OPERATION_FAILED; - } - - DBusError err; - dbus_error_init(&err); - - bool exist = dbus_bus_name_has_owner(g_m_conn_sender, VC_SERVER_SERVICE_NAME, &err); - if (dbus_error_is_set(&err)) { - SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Dbus Error (%s)", err.message); - dbus_error_free(&err); - } - - int ret; - if (false == exist) { - ret = __dbus_restore_daemon(); - if (VC_ERROR_NONE != ret) { - SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to restore daemon"); - return VC_ERROR_TIMED_OUT; - } - return VC_ERROR_OPERATION_FAILED; - } - - DBusMessage* msg; - - /* create a signal & check for errors */ - msg = dbus_message_new_method_call( - VC_SERVER_SERVICE_NAME, - VC_SERVER_SERVICE_OBJECT_PATH, - VC_SERVER_SERVICE_INTERFACE, - VC_MANAGER_METHOD_SET_AUDIO_TYPE); - - if (NULL == msg) { - SLOG(LOG_ERROR, TAG_VCM, "@@ vc mgr set audio type : Fail to make message "); - return VC_ERROR_OPERATION_FAILED; - } else { - SLOG(LOG_INFO, TAG_VCM, "@@ vc mgr set audio type : pid(%d), audio type(%s)", pid, audio_type); - } - - dbus_message_append_args(msg, - DBUS_TYPE_INT32, &pid, - DBUS_TYPE_STRING, &(audio_type), - DBUS_TYPE_INVALID); - - DBusMessage* result_msg; - int result = VC_ERROR_OPERATION_FAILED; - - result_msg = dbus_connection_send_with_reply_and_block(g_m_conn_sender, msg, g_m_waiting_time, &err); - dbus_message_unref(msg); - - if (dbus_error_is_set(&err)) { - SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Dbus Error (%s)", err.message); - dbus_error_free(&err); - } - - if (NULL != result_msg) { - dbus_message_get_args(result_msg, &err, - DBUS_TYPE_INT32, &result, - DBUS_TYPE_INVALID); - - if (dbus_error_is_set(&err)) { - SLOG(LOG_ERROR, TAG_VCM, "@@ Get arguments error (%s)", err.message); - dbus_error_free(&err); - result = VC_ERROR_OPERATION_FAILED; - } - dbus_message_unref(result_msg); - - if (0 == result) { - SLOG(LOG_INFO, TAG_VCM, "@@ vc mgr set audio type : result = %d", result); - } else { - SLOG(LOG_ERROR, TAG_VCM, "@@ vc mgr set audio type : result = %d", result); - } - } else { - SLOG(LOG_ERROR, TAG_VCM, "@@ Result Message is NULL"); - vc_mgr_dbus_reconnect(); - result = VC_ERROR_TIMED_OUT; - } - - return result; -} - -int vc_mgr_dbus_request_get_audio_type(int pid, char** audio_type) -{ - if (0 != __dbus_check()) { - return VC_ERROR_OPERATION_FAILED; - } - - DBusError err; - dbus_error_init(&err); - - bool exist = dbus_bus_name_has_owner(g_m_conn_sender, VC_SERVER_SERVICE_NAME, &err); - if (dbus_error_is_set(&err)) { - SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Dbus Error (%s)", err.message); - dbus_error_free(&err); - } - - int ret; - if (false == exist) { - ret = __dbus_restore_daemon(); - if (VC_ERROR_NONE != ret) { - SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to restore daemon"); - return VC_ERROR_TIMED_OUT; - } - return VC_ERROR_OPERATION_FAILED; - } - - DBusMessage* msg; - - /* create a signal & check for errors */ - msg = dbus_message_new_method_call( - VC_SERVER_SERVICE_NAME, - VC_SERVER_SERVICE_OBJECT_PATH, - VC_SERVER_SERVICE_INTERFACE, - VC_MANAGER_METHOD_GET_AUDIO_TYPE); - - if (NULL == msg) { - SLOG(LOG_ERROR, TAG_VCM, "@@ vc mgr get audio type : Fail to make message "); - return VC_ERROR_OPERATION_FAILED; - } else { - SLOG(LOG_INFO, TAG_VCM, "@@ vc mgr get audio type : pid(%d)", pid); - } - - dbus_message_append_args(msg, - DBUS_TYPE_INT32, &pid, - DBUS_TYPE_INVALID); - - - DBusMessage* result_msg; - int result = VC_ERROR_OPERATION_FAILED; - char* temp = NULL; - - result_msg = dbus_connection_send_with_reply_and_block(g_m_conn_sender, msg, g_m_waiting_time, &err); - dbus_message_unref(msg); - - if (dbus_error_is_set(&err)) { - SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Dbus Error (%s)", err.message); - dbus_error_free(&err); - } - - if (NULL != result_msg) { - dbus_message_get_args(result_msg, &err, - DBUS_TYPE_INT32, &result, - DBUS_TYPE_STRING, &temp, - DBUS_TYPE_INVALID); - - if (dbus_error_is_set(&err)) { - SLOG(LOG_ERROR, TAG_VCM, "@@ Get arguments error (%s)", err.message); - dbus_error_free(&err); - result = VC_ERROR_OPERATION_FAILED; - } - dbus_message_unref(result_msg); - - if (0 == result) { - if (NULL != audio_type && NULL != temp) { - *audio_type = strdup(temp); - } - SLOG(LOG_INFO, TAG_VCM, "@@ vc mgr get audio type : result = %d audio type = %s", result, temp); - } else { - SLOG(LOG_ERROR, TAG_VCM, "@@ vc mgr get audio type : result = %d", result); - } - } else { - SLOG(LOG_ERROR, TAG_VCM, "@@ Result Message is NULL"); - vc_mgr_dbus_reconnect(); - result = VC_ERROR_TIMED_OUT; - } - - return result; -} - -int vc_mgr_dbus_request_set_private_data(int pid, const char* key, const char* data) -{ - if (0 != __dbus_check()) { - return VC_ERROR_OPERATION_FAILED; - } - - DBusMessage* msg; - - /* create a signal & check for errors */ - msg = dbus_message_new_method_call( - VC_SERVER_SERVICE_NAME, - VC_SERVER_SERVICE_OBJECT_PATH, /* object name of the signal */ - VC_SERVER_SERVICE_INTERFACE, /* interface name of the signal */ - VC_MANAGER_METHOD_SET_PRIVATE_DATA); /* name of the signal */ - - if (NULL == msg) { - SLOG(LOG_ERROR, TAG_VCM, "@@ vc set private data : Fail to make message "); - return VC_ERROR_OPERATION_FAILED; - } else { - SLOG(LOG_INFO, TAG_VCM, "@@ vc set private data : pid(%d), data(%s)", pid, data); - } - - dbus_message_append_args(msg, - DBUS_TYPE_INT32, &pid, - DBUS_TYPE_STRING, &key, - DBUS_TYPE_STRING, &data, - DBUS_TYPE_INVALID); - - dbus_message_set_no_reply(msg, TRUE); - - /* send the message and flush the connection */ - if (1 != dbus_connection_send(g_m_conn_sender, msg, NULL)) { - SLOG(LOG_ERROR, TAG_VCM, "[Dbus ERROR] Fail to send private data"); - dbus_message_unref(msg); - return VC_ERROR_OPERATION_FAILED; - } else { - SLOG(LOG_ERROR, TAG_VCM, "[Dbus] Success to send private data"); - dbus_connection_flush(g_m_conn_sender); - } - - dbus_message_unref(msg); - - return VC_ERROR_NONE; -} - -int vc_mgr_dbus_request_get_private_data(int pid, const char* key, char** data) -{ - if (0 != __dbus_check()) { - return VC_ERROR_OPERATION_FAILED; - } - - DBusMessage* msg; - - /* create a signal & check for errors */ - msg = dbus_message_new_method_call( - VC_SERVER_SERVICE_NAME, - VC_SERVER_SERVICE_OBJECT_PATH, - VC_SERVER_SERVICE_INTERFACE, - VC_MANAGER_METHOD_GET_PRIVATE_DATA); - - if (NULL == msg) { - SLOG(LOG_ERROR, TAG_VCM, "@@ vc mgr get private data : Fail to make message "); - return VC_ERROR_OPERATION_FAILED; - } else { - SLOG(LOG_INFO, TAG_VCM, "@@ vc mgr get private data : pid(%d), key(%s)", pid, key); - } - - dbus_message_append_args(msg, - DBUS_TYPE_INT32, &pid, - DBUS_TYPE_STRING, &key, - DBUS_TYPE_INVALID); - - DBusError err; - dbus_error_init(&err); - - DBusMessage* result_msg; - int result = VC_ERROR_OPERATION_FAILED; - char* temp = NULL; - - result_msg = dbus_connection_send_with_reply_and_block(g_m_conn_sender, msg, g_m_waiting_time, &err); - dbus_message_unref(msg); - - if (dbus_error_is_set(&err)) { - SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Dbus Error (%s)", err.message); - dbus_error_free(&err); - } - - if (NULL != result_msg) { - dbus_message_get_args(result_msg, &err, - DBUS_TYPE_INT32, &result, - DBUS_TYPE_STRING, &temp, - DBUS_TYPE_INVALID); - - if (dbus_error_is_set(&err)) { - SLOG(LOG_ERROR, TAG_VCM, "@@ Get arguments error (%s)", err.message); - dbus_error_free(&err); - result = VC_ERROR_OPERATION_FAILED; - } - dbus_message_unref(result_msg); - - if (0 == result) { - if (0 == strncmp(temp, "#NULL", 5)) { - *data = NULL; - } else { - *data = strdup(temp); - } - SLOG(LOG_INFO, TAG_VCM, "@@ vc mgr get private data : result = %d private data = %s", result, *data); - } else { - SLOG(LOG_ERROR, TAG_VCM, "@@ vc mgr get private data : result = %d", result); - } - } else { - SLOG(LOG_INFO, TAG_VCM, "@@ Result Message is NULL"); - vc_mgr_dbus_reconnect(); - result = VC_ERROR_TIMED_OUT; - } - - return result; -} - -int vc_mgr_dbus_request_set_client_info(int pid) -{ - if (0 != __dbus_check()) { - return VC_ERROR_OPERATION_FAILED; - } - - DBusError err; - dbus_error_init(&err); - - bool exist = dbus_bus_name_has_owner(g_m_conn_sender, VC_SERVER_SERVICE_NAME, &err); - if (dbus_error_is_set(&err)) { - SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Dbus Error (%s)", err.message); - dbus_error_free(&err); - } - - int ret; - if (false == exist) { - ret = __dbus_restore_daemon(); - if (VC_ERROR_NONE != ret) { - SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to restore daemon"); - return VC_ERROR_TIMED_OUT; - } - return VC_ERROR_OPERATION_FAILED; - } - - DBusMessage* msg; - - /* create a signal & check for errors */ - msg = dbus_message_new_method_call( - VC_SERVER_SERVICE_NAME, - VC_SERVER_SERVICE_OBJECT_PATH, - VC_SERVER_SERVICE_INTERFACE, - VC_MANAGER_METHOD_SET_CLIENT_INFO); - - if (NULL == msg) { - SLOG(LOG_ERROR, TAG_VCM, "@@ vc mgr set client info : Fail to make message "); - return VC_ERROR_OPERATION_FAILED; - } else { - SLOG(LOG_INFO, TAG_VCM, "@@ vc mgr set client info : pid(%d)", pid); - } - - dbus_message_append_args(msg, - DBUS_TYPE_INT32, &pid, - DBUS_TYPE_INVALID); - - DBusMessage* result_msg; - int result = VC_ERROR_OPERATION_FAILED; - - result_msg = dbus_connection_send_with_reply_and_block(g_m_conn_sender, msg, g_m_waiting_time, &err); - dbus_message_unref(msg); - - if (dbus_error_is_set(&err)) { - SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Dbus Error (%s)", err.message); - dbus_error_free(&err); - } - - if (NULL != result_msg) { - dbus_message_get_args(result_msg, &err, - DBUS_TYPE_INT32, &result, - DBUS_TYPE_INVALID); - - if (dbus_error_is_set(&err)) { - SLOG(LOG_ERROR, TAG_VCM, "@@ Get arguments error (%s)", err.message); - dbus_error_free(&err); - result = VC_ERROR_OPERATION_FAILED; - } - dbus_message_unref(result_msg); - - if (0 == result) { - SLOG(LOG_INFO, TAG_VCM, "@@ vc mgr set client info : result = %d", result); - } else { - SLOG(LOG_ERROR, TAG_VCM, "@@ vc mgr set client info : result = %d", result); - } - } else { - SLOG(LOG_ERROR, TAG_VCM, "@@ Result Message is NULL"); - vc_mgr_dbus_reconnect(); - result = VC_ERROR_TIMED_OUT; - } - - return result; -} - -int vc_mgr_dbus_request_set_domain(int pid, const char* domain) -{ - if (0 != __dbus_check()) { - return VC_ERROR_OPERATION_FAILED; - } - - DBusMessage* msg; - - /* create a signal & check for errors */ - msg = dbus_message_new_method_call( - VC_SERVER_SERVICE_NAME, - VC_SERVER_SERVICE_OBJECT_PATH, /* object name of the signal */ - VC_SERVER_SERVICE_INTERFACE, /* interface name of the signal */ - VC_MANAGER_METHOD_SET_DOMAIN); /* name of the signal */ - - if (NULL == msg) { - SLOG(LOG_ERROR, TAG_VCM, "@@ vc set domain : Fail to make message "); - return VC_ERROR_OPERATION_FAILED; - } else { - SLOG(LOG_INFO, TAG_VCM, "@@ vc set domain : pid(%d), domain(%s)", pid, domain); - } - - dbus_message_append_args(msg, - DBUS_TYPE_INT32, &pid, - DBUS_TYPE_STRING, &domain, - DBUS_TYPE_INVALID); - - DBusError err; - dbus_error_init(&err); - - DBusMessage* result_msg; - int result = VC_ERROR_OPERATION_FAILED; - - result_msg = dbus_connection_send_with_reply_and_block(g_m_conn_sender, msg, g_m_waiting_time, &err); - dbus_message_unref(msg); - - if (dbus_error_is_set(&err)) { - SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Dbus Error (%s)", err.message); - dbus_error_free(&err); - } - - if (NULL != result_msg) { - dbus_message_get_args(result_msg, &err, - DBUS_TYPE_INT32, &result, - DBUS_TYPE_INVALID); - - if (dbus_error_is_set(&err)) { - SLOG(LOG_ERROR, TAG_VCM, "@@ Get arguments error (%s)", err.message); - dbus_error_free(&err); - result = VC_ERROR_OPERATION_FAILED; - } - dbus_message_unref(result_msg); - - if (0 == result) { - SLOG(LOG_INFO, TAG_VCM, "@@ vc set domain : result = %d", result); - } else { - SLOG(LOG_ERROR, TAG_VCM, "@@ vc set domain : result = %d", result); - } - } else { - SLOG(LOG_ERROR, TAG_VCM, "@@ Result Message is NULL"); - vc_mgr_dbus_reconnect(); - result = VC_ERROR_TIMED_OUT; - } - - return result; -} - -int vc_mgr_dbus_request_do_action(int pid, vc_send_event_type_e type, char* send_event) -{ - if (0 != __dbus_check()) { - return VC_ERROR_OPERATION_FAILED; - } - - DBusMessage* msg; - - /* create a signal & check for errors */ - msg = dbus_message_new_method_call( - VC_SERVER_SERVICE_NAME, - VC_SERVER_SERVICE_OBJECT_PATH, /* object name of the signal */ - VC_SERVER_SERVICE_INTERFACE, /* interface name of the signal */ - VC_MANAGER_METHOD_DO_ACTION); /* name of the signal */ - - if (NULL == msg) { - SLOG(LOG_ERROR, TAG_VCM, "@@ vc set domain : Fail to make message "); - return VC_ERROR_OPERATION_FAILED; - } else { - SLOG(LOG_INFO, TAG_VCM, "@@ vc set domain : pid(%d), type(%d), send_event(%s)", pid, type, send_event); - } - - dbus_message_append_args(msg, - DBUS_TYPE_INT32, &pid, - DBUS_TYPE_INT32, &type, - DBUS_TYPE_STRING, &send_event, - DBUS_TYPE_INVALID); - - dbus_message_set_no_reply(msg, TRUE); - - /* send the message and flush the connection */ - if (1 != dbus_connection_send(g_m_conn_sender, msg, NULL)) { - SLOG(LOG_ERROR, TAG_VCM, "[Dbus ERROR] Fail to Send"); - dbus_message_unref(msg); - return VC_ERROR_OPERATION_FAILED; - } else { - SLOG(LOG_INFO, TAG_VCM, "[Dbus] SUCCESS Send"); - dbus_connection_flush(g_m_conn_sender); - } - - dbus_message_unref(msg); - return 0; -} - -int vc_mgr_dbus_request_start(int pid, int recognition_mode, bool exclusive_command_option, bool start_by_client, int disabled_cmd_type) -{ - if (0 != __dbus_check()) { - return VC_ERROR_OPERATION_FAILED; - } - - DBusError err; - dbus_error_init(&err); - - bool exist = dbus_bus_name_has_owner(g_m_conn_sender, VC_SERVER_SERVICE_NAME, &err); - if (dbus_error_is_set(&err)) { - SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Dbus Error (%s)", err.message); - dbus_error_free(&err); - } - - int ret; - if (false == exist) { - ret = __dbus_restore_daemon(); - if (VC_ERROR_NONE != ret) { - SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to restore daemon"); - return VC_ERROR_TIMED_OUT; - } - return VC_ERROR_OPERATION_FAILED; - } - - DBusMessage* msg; - - /* create a signal & check for errors */ - msg = dbus_message_new_method_call( - VC_SERVER_SERVICE_NAME, - VC_SERVER_SERVICE_OBJECT_PATH, - VC_SERVER_SERVICE_INTERFACE, - VC_MANAGER_METHOD_START); - - if (NULL == msg) { - SLOG(LOG_ERROR, TAG_VCM, "@@ vc mgr start : Fail to make message "); - return VC_ERROR_OPERATION_FAILED; - } else { - SLOG(LOG_INFO, TAG_VCM, "@@ vc mgr start : pid(%d), recognition_mode(%d) exclusive(%d) start by client(%d) disabled cmd type(%d)", - pid, recognition_mode, exclusive_command_option, start_by_client, disabled_cmd_type); - } - - int exclusive = (int)exclusive_command_option; - int by = (int)start_by_client; - - dbus_message_append_args(msg, - DBUS_TYPE_INT32, &pid, - DBUS_TYPE_INT32, &(recognition_mode), - DBUS_TYPE_INT32, &(exclusive), - DBUS_TYPE_INT32, &(by), - DBUS_TYPE_INT32, &(disabled_cmd_type), - DBUS_TYPE_INVALID); - - DBusMessage* result_msg; - int result = VC_ERROR_OPERATION_FAILED; - - result_msg = dbus_connection_send_with_reply_and_block(g_m_conn_sender, msg, g_m_waiting_time, &err); - dbus_message_unref(msg); - - if (dbus_error_is_set(&err)) { - SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Dbus Error (%s)", err.message); - dbus_error_free(&err); - } - - if (NULL != result_msg) { - dbus_message_get_args(result_msg, &err, - DBUS_TYPE_INT32, &result, - DBUS_TYPE_INVALID); - - if (dbus_error_is_set(&err)) { - SLOG(LOG_ERROR, TAG_VCM, "@@ Get arguments error (%s)", err.message); - dbus_error_free(&err); - result = VC_ERROR_OPERATION_FAILED; - } - dbus_message_unref(result_msg); - - if (0 == result) { - SLOG(LOG_INFO, TAG_VCM, "@@ vc mgr start : result = %d", result); - } else { - SLOG(LOG_ERROR, TAG_VCM, "@@ vc mgr start : result = %d", result); - } - } else { - SLOG(LOG_ERROR, TAG_VCM, "@@ Result Message is NULL"); - vc_mgr_dbus_reconnect(); - result = VC_ERROR_TIMED_OUT; - } - - return result; -} - -int vc_mgr_dbus_request_stop(int pid) -{ - if (0 != __dbus_check()) { - return VC_ERROR_OPERATION_FAILED; - } - - DBusError err; - dbus_error_init(&err); - - bool exist = dbus_bus_name_has_owner(g_m_conn_sender, VC_SERVER_SERVICE_NAME, &err); - if (dbus_error_is_set(&err)) { - SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Dbus Error (%s)", err.message); - dbus_error_free(&err); - } - - int ret; - if (false == exist) { - ret = __dbus_restore_daemon(); - if (VC_ERROR_NONE != ret) { - SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to restore daemon"); - return VC_ERROR_TIMED_OUT; - } - return VC_ERROR_OPERATION_FAILED; - } - - DBusMessage* msg; - - /* create a signal & check for errors */ - msg = dbus_message_new_method_call( - VC_SERVER_SERVICE_NAME, - VC_SERVER_SERVICE_OBJECT_PATH, - VC_SERVER_SERVICE_INTERFACE, - VC_MANAGER_METHOD_STOP); - - if (NULL == msg) { - SLOG(LOG_ERROR, TAG_VCM, "@@ vc mgr stop : Fail to make message "); - return VC_ERROR_OPERATION_FAILED; - } else { - SLOG(LOG_INFO, TAG_VCM, "@@ vc mgr stop : pid(%d)", pid); - } - - dbus_message_append_args(msg, - DBUS_TYPE_INT32, &pid, - DBUS_TYPE_INVALID); - - DBusMessage* result_msg; - int result = VC_ERROR_OPERATION_FAILED; - - result_msg = dbus_connection_send_with_reply_and_block(g_m_conn_sender, msg, g_m_waiting_time, &err); - dbus_message_unref(msg); - - if (dbus_error_is_set(&err)) { - SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Dbus Error (%s)", err.message); - dbus_error_free(&err); - } - - if (NULL != result_msg) { - dbus_message_get_args(result_msg, &err, - DBUS_TYPE_INT32, &result, - DBUS_TYPE_INVALID); - - if (dbus_error_is_set(&err)) { - SLOG(LOG_ERROR, TAG_VCM, "@@ Get arguments error (%s)", err.message); - dbus_error_free(&err); - result = VC_ERROR_OPERATION_FAILED; - } - dbus_message_unref(result_msg); - - if (0 == result) { - SLOG(LOG_INFO, TAG_VCM, "@@ vc mgr stop : result = %d", result); - } else { - SLOG(LOG_ERROR, TAG_VCM, "@@ vc mgr stop : result = %d", result); - } - } else { - SLOG(LOG_ERROR, TAG_VCM, "@@ Result Message is NULL"); - vc_mgr_dbus_reconnect(); - result = VC_ERROR_TIMED_OUT; - } - - return result; -} - -int vc_mgr_dbus_request_cancel(int pid) -{ - if (0 != __dbus_check()) { - return VC_ERROR_OPERATION_FAILED; - } - - DBusError err; - dbus_error_init(&err); - - bool exist = dbus_bus_name_has_owner(g_m_conn_sender, VC_SERVER_SERVICE_NAME, &err); - if (dbus_error_is_set(&err)) { - SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Dbus Error (%s)", err.message); - dbus_error_free(&err); - } - - int ret; - if (false == exist) { - ret = __dbus_restore_daemon(); - if (VC_ERROR_NONE != ret) { - SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to restore daemon"); - return VC_ERROR_TIMED_OUT; - } - return VC_ERROR_OPERATION_FAILED; - } - - DBusMessage* msg; - - /* create a signal & check for errors */ - msg = dbus_message_new_method_call( - VC_SERVER_SERVICE_NAME, - VC_SERVER_SERVICE_OBJECT_PATH, /* object name of the signal */ - VC_SERVER_SERVICE_INTERFACE, /* interface name of the signal */ - VC_MANAGER_METHOD_CANCEL); /* name of the signal */ - - if (NULL == msg) { - SLOG(LOG_ERROR, TAG_VCM, "@@ vc cancel : Fail to make message "); - return VC_ERROR_OPERATION_FAILED; - } else { - SLOG(LOG_INFO, TAG_VCM, "@@ vc cancel : pid(%d)", pid); - } - - dbus_message_append_args(msg, - DBUS_TYPE_INT32, &pid, - DBUS_TYPE_INVALID); - - DBusMessage* result_msg; - int result = VC_ERROR_OPERATION_FAILED; - - result_msg = dbus_connection_send_with_reply_and_block(g_m_conn_sender, msg, g_m_waiting_time, &err); - dbus_message_unref(msg); - - if (dbus_error_is_set(&err)) { - SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Dbus Error (%s)", err.message); - dbus_error_free(&err); - } - - if (NULL != result_msg) { - dbus_message_get_args(result_msg, &err, - DBUS_TYPE_INT32, &result, - DBUS_TYPE_INVALID); - - if (dbus_error_is_set(&err)) { - SLOG(LOG_ERROR, TAG_VCM, "@@ Get arguments error (%s)", err.message); - dbus_error_free(&err); - result = VC_ERROR_OPERATION_FAILED; - } - dbus_message_unref(result_msg); - - if (0 == result) { - SLOG(LOG_INFO, TAG_VCM, "@@ vc cancel : result = %d", result); - } else { - SLOG(LOG_ERROR, TAG_VCM, "@@ vc cancel : result = %d", result); - } - } else { - SLOG(LOG_ERROR, TAG_VCM, "@@ Result Message is NULL"); - vc_mgr_dbus_reconnect(); - result = VC_ERROR_TIMED_OUT; - } - - return result; -} - -int vc_mgr_dbus_request_set_audio_streaming_mode(int pid, vc_audio_streaming_mode_e mode) -{ - if (0 != __dbus_check()) { - return VC_ERROR_OPERATION_FAILED; - } - - DBusMessage* msg; - - /* create a signal & check for errors */ - msg = dbus_message_new_method_call( - VC_SERVER_SERVICE_NAME, - VC_SERVER_SERVICE_OBJECT_PATH, /* object name of the signal */ - VC_SERVER_SERVICE_INTERFACE, /* interface name of the signal */ - VC_MANAGER_METHOD_SET_AUDIO_STREAMING_MODE); /* name of the signal */ - - if (NULL == msg) { - SLOG(LOG_ERROR, TAG_VCM, "@@ vc mgr set audio streaming mode : Fail to make message "); - return VC_ERROR_OPERATION_FAILED; - } else { - SLOG(LOG_INFO, TAG_VCM, "@@ vc mgr set audio streaming mode : pid(%d) mode(%d)", pid, mode); - } - - dbus_message_append_args(msg, - DBUS_TYPE_INT32, &pid, - DBUS_TYPE_INT32, &mode, - DBUS_TYPE_INVALID); - - dbus_message_set_no_reply(msg, TRUE); - - /* send the message and flush the connection */ - if (1 != dbus_connection_send(g_m_conn_sender, msg, NULL)) { - SLOG(LOG_ERROR, TAG_VCM, "[Dbus ERROR] Fail to set audio streaming mode"); - dbus_message_unref(msg); - return VC_ERROR_OPERATION_FAILED; - } else { - SLOG(LOG_INFO, TAG_VCM, "[Dbus] Success to set audio streaming mode"); - dbus_connection_flush(g_m_conn_sender); - } - - dbus_message_unref(msg); - - return VC_ERROR_NONE; -} - -static DBusMessage* __get_message(int pid, const char* method, int type) -{ - char service_name[64]; - char object_path[64]; - char target_if_name[128]; - - memset(service_name, '\0', 64); - memset(object_path, '\0', 64); - memset(target_if_name, '\0', 128); - - if (VC_COMMAND_TYPE_FOREGROUND == type || VC_COMMAND_TYPE_BACKGROUND == type) { - snprintf(service_name, 64, "%s%d", VC_CLIENT_SERVICE_NAME, pid); - snprintf(object_path, 64, "%s", VC_CLIENT_SERVICE_OBJECT_PATH); - snprintf(target_if_name, 128, "%s%d", VC_CLIENT_SERVICE_NAME, pid); - } else if (VC_COMMAND_TYPE_WIDGET == type) { - snprintf(service_name, 64, "%s%d", VC_WIDGET_SERVICE_NAME, pid); - snprintf(object_path, 64, "%s", VC_WIDGET_SERVICE_OBJECT_PATH); - snprintf(target_if_name, 128, "%s%d", VC_WIDGET_SERVICE_INTERFACE, pid); - } else { - return NULL; - } - - SLOG(LOG_INFO, TAG_VCM, "[Dbus] Service(%s) object(%s) if(%s)", service_name, object_path, target_if_name); - - return dbus_message_new_method_call(service_name, object_path, target_if_name, method); -} - -int vc_mgr_dbus_send_result(int pid, int cmd_type, int result_id) -{ - if (0 != __dbus_check()) { - return VC_ERROR_OPERATION_FAILED; - } - - DBusMessage* msg = NULL; - - switch (cmd_type) { - case VC_COMMAND_TYPE_FOREGROUND: - case VC_COMMAND_TYPE_BACKGROUND: - msg = __get_message(pid, VCD_METHOD_RESULT, cmd_type); - break; - case VC_COMMAND_TYPE_WIDGET: - msg = __get_message(pid, VCD_WIDGET_METHOD_RESULT, cmd_type); - break; - default: - SLOG(LOG_ERROR, TAG_VCM, "[Dbus ERROR] Command type is NOT valid(%d)", cmd_type); - return -1; - } - - if (NULL == msg) - SLOG(LOG_ERROR, TAG_VCM, "[Dbus ERROR] Message is NULL"); - - dbus_message_append_args(msg, DBUS_TYPE_INT32, &result_id, DBUS_TYPE_INVALID); - - dbus_message_set_no_reply(msg, TRUE); - - /* send the message and flush the connection */ - if (1 != dbus_connection_send(g_m_conn_sender, msg, NULL)) { - SLOG(LOG_ERROR, TAG_VCM, "[Dbus ERROR] Fail to Send"); - dbus_message_unref(msg); - return VC_ERROR_OPERATION_FAILED; - } else { - SLOG(LOG_INFO, TAG_VCM, "[Dbus] SUCCESS Send"); - dbus_connection_flush(g_m_conn_sender); - } - - dbus_message_unref(msg); - return 0; -} - -int vc_mgr_dbus_send_result_selection(int pid) -{ - if (0 != __dbus_check()) { - return VC_ERROR_OPERATION_FAILED; - } - - DBusMessage* msg; - - /* create a signal & check for errors */ - msg = dbus_message_new_method_call( - VC_SERVER_SERVICE_NAME, - VC_SERVER_SERVICE_OBJECT_PATH, /* object name of the signal */ - VC_SERVER_SERVICE_INTERFACE, /* interface name of the signal */ - VC_MANAGER_METHOD_RESULT_SELECTION); /* name of the signal */ - - if (NULL == msg) { - SLOG(LOG_ERROR, TAG_VCM, "@@ vc result selection : Fail to make message "); - return VC_ERROR_OPERATION_FAILED; - } else { - SLOG(LOG_INFO, TAG_VCM, "@@ vc result selection : pid(%d)", pid); - } - - dbus_message_append_args(msg, - DBUS_TYPE_INT32, &pid, - DBUS_TYPE_INVALID); - - dbus_message_set_no_reply(msg, TRUE); - - /* send the message and flush the connection */ - if (1 != dbus_connection_send(g_m_conn_sender, msg, NULL)) { - SLOG(LOG_ERROR, TAG_VCM, "[Dbus ERROR] Fail to Send"); - dbus_message_unref(msg); - return VC_ERROR_OPERATION_FAILED; - } else { - SLOG(LOG_INFO, TAG_VCM, "[Dbus] SUCCESS Send"); - dbus_connection_flush(g_m_conn_sender); - } - - dbus_message_unref(msg); - return 0; -} - -int vc_mgr_dbus_send_specific_engine_request(int pid, const char* engine_app_id, const char* event, const char* request) -{ - if (0 != __dbus_check()) { - return VC_ERROR_OPERATION_FAILED; - } - - DBusMessage* msg; - - /* create a signal & check for errors */ - msg = dbus_message_new_method_call( - VC_SERVER_SERVICE_NAME, - VC_SERVER_SERVICE_OBJECT_PATH, /* object name of the signal */ - VC_SERVER_SERVICE_INTERFACE, /* interface name of the signal */ - VC_MANAGER_METHOD_SPECIFIC_ENGINE_REQUEST); /* name of the signal */ - - if (NULL == msg) { - SLOG(LOG_ERROR, TAG_VCM, "@@ vc send specific engine : Fail to make message"); - return VC_ERROR_OPERATION_FAILED; - } else { - SLOG(LOG_INFO, TAG_VCM, "@@ vc send specific engine : pid(%d), engine_app_id(%s), event(%s), request(%s)", pid, engine_app_id, event, request); - } - - gchar *gEncodedRequest = g_base64_encode((const guchar*)request, strlen(request)); - - dbus_message_append_args(msg, - DBUS_TYPE_INT32, &pid, - DBUS_TYPE_STRING, &engine_app_id, - DBUS_TYPE_STRING, &event, - DBUS_TYPE_STRING, &gEncodedRequest, - DBUS_TYPE_INVALID); - - dbus_message_set_no_reply(msg, TRUE); - - /* send the message and flush the connection */ - if (1 != dbus_connection_send(g_m_conn_sender, msg, NULL)) { - SLOG(LOG_ERROR, TAG_VCM, "[Dbus ERROR] Fail to Send"); - if (gEncodedRequest) - g_free(gEncodedRequest); - dbus_message_unref(msg); - return VC_ERROR_OPERATION_FAILED; - } else { - SLOG(LOG_INFO, TAG_VCM, "[Dbus] SUCCESS Send"); - dbus_connection_flush(g_m_conn_sender); - } - - if (gEncodedRequest) - g_free(gEncodedRequest); - dbus_message_unref(msg); - return 0; -} - -int vc_mgr_dbus_send_utterance_status(int pid, int utt_id, vc_tts_utterance_status_e utt_status) -{ - if (0 != __dbus_check()) { - return VC_ERROR_OPERATION_FAILED; - } - - DBusMessage* msg; - msg = __get_message(pid, VC_MANAGER_METHOD_UTTERANCE_STATUS, VC_COMMAND_TYPE_FOREGROUND); - - if (NULL == msg) { - SLOG(LOG_ERROR, TAG_VCM, "@@ vc send utterance status : Fail to make message"); - return VC_ERROR_OPERATION_FAILED; - } else { - SLOG(LOG_INFO, TAG_VCM, "@@ vc send utterance status : pid(%d), utt_id(%d), utt_status(%d)", pid, utt_id, utt_status); - } - - dbus_message_append_args(msg, - DBUS_TYPE_INT32, &utt_id, - DBUS_TYPE_INT32, &utt_status, - DBUS_TYPE_INVALID); - - dbus_message_set_no_reply(msg, TRUE); - - /* send the message and flush the connection */ - if (1 != dbus_connection_send(g_m_conn_sender, msg, NULL)) { - SLOG(LOG_ERROR, TAG_VCM, "[Dbus ERROR] Fail to Send"); - dbus_message_unref(msg); - return VC_ERROR_OPERATION_FAILED; - } else { - SLOG(LOG_INFO, TAG_VCM, "[Dbus] SUCCESS Send"); - dbus_connection_flush(g_m_conn_sender); - } - - dbus_message_unref(msg); - return 0; -} - -int vc_mgr_dbus_send_audio_streaming(int pid, vc_audio_streaming_event_e event, unsigned char* buffer, unsigned int len) -{ - if (0 != __dbus_check()) { - return VC_ERROR_OPERATION_FAILED; - } - - DBusMessage* msg; - msg = dbus_message_new_method_call( - VC_SERVER_SERVICE_NAME, - VC_SERVER_SERVICE_OBJECT_PATH, - VC_SERVER_SERVICE_INTERFACE, - VC_MANAGER_METHOD_SEND_AUDIO_STREAMING); - - if (NULL == msg) { - SLOG(LOG_ERROR, TAG_VCM, "@@ vc send audio streaming : Fail to make message"); - return VC_ERROR_OPERATION_FAILED; - } else { - SLOG(LOG_INFO, TAG_VCM, "@@ vc send audio streaming : pid(%d), event(%d), buffer(%p), len(%d)", pid, event, buffer, len); - } - - dbus_message_append_args(msg, - DBUS_TYPE_INT32, &pid, - DBUS_TYPE_INT32, &event, - DBUS_TYPE_ARRAY, DBUS_TYPE_BYTE, - &buffer, len, - DBUS_TYPE_INVALID); - - dbus_message_set_no_reply(msg, TRUE); - - /* send dbus message and flush the connection */ - if (!dbus_connection_send(g_m_conn_sender, msg, NULL)) { - SLOG(LOG_ERROR, TAG_VCM, "[Dbus ERROR] Fail to send audio streaming"); - } else { - SLOG(LOG_INFO, TAG_VCM, "[Dbus DEBUG] Success to send audio streaming"); - dbus_connection_flush(g_m_conn_sender); - } - - dbus_message_unref(msg); - return 0; -} - -int vc_mgr_dbus_change_system_volume(int pid, vc_system_volume_event_e volume_event) -{ - if (0 != __dbus_check()) { - return VC_ERROR_OPERATION_FAILED; - } - - DBusError err; - dbus_error_init(&err); - - bool exist = dbus_bus_name_has_owner(g_m_conn_sender, VC_SERVER_SERVICE_NAME, &err); - if (dbus_error_is_set(&err)) { - SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Dbus Error (%s)", err.message); - dbus_error_free(&err); - } - - int ret; - int temp_event = (int)volume_event; - if (false == exist) { - ret = __dbus_restore_daemon(); - if (VC_ERROR_NONE != ret) { - SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to restore daemon"); - return VC_ERROR_TIMED_OUT; - } - return VC_ERROR_OPERATION_FAILED; - } - - DBusMessage* msg; - - /* create a signal & check for errors */ - msg = dbus_message_new_method_call( - VC_SERVER_SERVICE_NAME, - VC_SERVER_SERVICE_OBJECT_PATH, /* object name of the signal */ - VC_SERVER_SERVICE_INTERFACE, /* interface name of the signal */ - VC_MANAGER_METHOD_CHANGE_SYSTEM_VOLUME); /* name of the signal */ - - if (NULL == msg) { - SLOG(LOG_ERROR, TAG_VCM, "@@ vc change system volume : Fail to make message "); - return VC_ERROR_OPERATION_FAILED; - } else { - SLOG(LOG_INFO, TAG_VCM, "@@ vc change system volume : pid(%d) volume_event(%d)", pid, temp_event); - } - - dbus_message_append_args(msg, - DBUS_TYPE_INT32, &pid, - DBUS_TYPE_INT32, &temp_event, - DBUS_TYPE_INVALID); - - DBusMessage* result_msg; - int result = VC_ERROR_OPERATION_FAILED; - - result_msg = dbus_connection_send_with_reply_and_block(g_m_conn_sender, msg, g_m_waiting_time, &err); - dbus_message_unref(msg); - - if (dbus_error_is_set(&err)) { - SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Dbus Error (%s)", err.message); - dbus_error_free(&err); - } - - if (NULL != result_msg) { - dbus_message_get_args(result_msg, &err, - DBUS_TYPE_INT32, &result, - DBUS_TYPE_INVALID); - - if (dbus_error_is_set(&err)) { - SLOG(LOG_ERROR, TAG_VCM, "@@ Get arguments error (%s)", err.message); - dbus_error_free(&err); - result = VC_ERROR_OPERATION_FAILED; - } - dbus_message_unref(result_msg); - - if (0 == result) { - SLOG(LOG_INFO, TAG_VCM, "@@ vc change system volume : result = %d", result); - } else { - SLOG(LOG_ERROR, TAG_VCM, "@@ vc change system volume : result = %d", result); - } - } else { - SLOG(LOG_ERROR, TAG_VCM, "@@ Result Message is NULL"); - vc_mgr_dbus_reconnect(); - result = VC_ERROR_TIMED_OUT; - } - - return result; -} +} \ No newline at end of file diff --git a/client/vc_mgr_dbus.h b/client/vc_mgr_dbus.h index c144024..4c82e19 100644 --- a/client/vc_mgr_dbus.h +++ b/client/vc_mgr_dbus.h @@ -32,54 +32,10 @@ int vc_mgr_dbus_close_connection(); int vc_mgr_dbus_request_hello(); -int vc_mgr_dbus_request_initialize(int pid, int audio_streaming_mode, int* service_state, int* foreground, int* daemon_pid); - int vc_mgr_dbus_request_finalize(int pid); -int vc_mgr_dbus_request_set_command(int pid); - -int vc_mgr_dbus_request_unset_command(int pid); - -int vc_mgr_dbus_request_demandable_client(int pid); - -int vc_mgr_dbus_request_set_audio_type(int pid, const char* audio_type); - -int vc_mgr_dbus_request_get_audio_type(int pid, char** audio_type); - -int vc_mgr_dbus_request_set_private_data(int pid, const char* key, const char* data); - -int vc_mgr_dbus_request_get_private_data(int pid, const char* key, char** data); - -int vc_mgr_dbus_request_set_client_info(int pid); - -int vc_mgr_dbus_request_set_domain(int pid, const char* domain); - -int vc_mgr_dbus_request_do_action(int pid, vc_send_event_type_e type, char* send_event); - -int vc_mgr_dbus_request_start(int pid, int recognition_mode, bool exclusive_command_option, bool start_by_client, int disabled_cmd_type); - -int vc_mgr_dbus_request_stop(int pid); - -int vc_mgr_dbus_request_cancel(int pid); - -int vc_mgr_dbus_send_result(int pid, int cmd_type, int result_id); - -int vc_mgr_dbus_send_result_selection(int pid); - -int vc_mgr_dbus_send_specific_engine_request(int pid, const char* engine_app_id, const char* event, const char* request); - -int vc_mgr_dbus_request_start_feedback(int pid); - -int vc_mgr_dbus_request_stop_feedback(int pid); - int vc_mgr_dbus_send_utterance_status(int pid, int utt_id, vc_tts_utterance_status_e utt_status); -int vc_mgr_dbus_send_audio_streaming(int pid, vc_audio_streaming_event_e event, unsigned char* buffer, unsigned int len); - -int vc_mgr_dbus_change_system_volume(int pid, vc_system_volume_event_e volume_event); - -int vc_mgr_dbus_request_set_audio_streaming_mode(int pid, vc_audio_streaming_mode_e mode); - #ifdef __cplusplus } #endif diff --git a/client/vc_mgr_tidl.c b/client/vc_mgr_tidl.c new file mode 100755 index 0000000..fc9781f --- /dev/null +++ b/client/vc_mgr_tidl.c @@ -0,0 +1,1204 @@ +/* +* Copyright (c) 2022 Samsung Electronics Co., Ltd All Rights Reserved +* +* Licensed under the Apache License, Version 2.0 (the License); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an AS IS BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#include + +#include + +#include "vc_main.h" +#include "vc_mgr_client.h" +#include "vc_mgr_tidl.h" +#include "vc_mgr_proxy.h" +#include "vc_mgr_stub.h" +#include "vc_command.h" + +typedef struct { + bool connected; + bool connection_requesting; + bool register_callback_invoked; + rpc_port_proxy_vc_mgr_h rpc_h; + rpc_port_proxy_vc_mgr_notify_cb_h notify_cb_h; + rpc_port_proxy_vc_mgr_send_buffer_cb_h send_buffer_cb_h; +} vc_mgr_tidl_info_s; + +typedef struct { + bool connected; + bool register_callback_requesting; +} vcd_mgr_tidl_info_s; + +static vc_mgr_tidl_info_s* g_proxy_tidl_info = NULL; + +static vcd_mgr_tidl_info_s* g_stub_tidl_info = NULL; + +static pthread_mutex_t g_tidl_mutex = PTHREAD_MUTEX_INITIALIZER; + +static rpc_port_stub_vcd_mgr_callback_s g_mgr_callback; + +static int g_volume_count = 0; + + +extern void __vc_mgr_cb_all_result(vc_result_type_e type); + +extern void __vc_mgr_cb_pre_result(int event, const char* pre_result); + +extern void __vc_mgr_cb_system_result(); + +extern void __vc_mgr_cb_speech_detected(); + +extern int __vc_mgr_cb_error(int reason, int daemon_pid, char* msg); + +extern int __vc_mgr_cb_set_volume(float volume); + +extern int __vc_mgr_cb_service_state(int state); + +extern int __vc_mgr_cb_set_foreground(int pid, bool value); + +extern int __vc_mgr_cb_private_data_set(const char* key, const char* data); + +extern int __vc_mgr_cb_private_data_requested(const char* key, char** data); + +/* for TTS feedback */ +extern int __vc_mgr_cb_feedback_audio_format(int rate, vc_audio_channel_e channel, vc_audio_type_e audio_type); + +extern int __vc_mgr_cb_feedback_streaming(int pid, int utt_id, vc_feedback_event_e event, char* buffer, int len); + +/* Authority */ +extern int __vc_mgr_request_auth_enable(int pid); + +extern int __vc_mgr_request_auth_disable(int pid); + +extern int __vc_mgr_request_auth_start(int pid); + +extern int __vc_mgr_request_auth_stop(int pid); + +extern int __vc_mgr_request_auth_cancel(int pid); + +extern int __vc_mgr_cb_dialog(int pid, const char* disp_text, const char* utt_text, bool continuous); + +extern void __vc_mgr_cb_specific_engine_result(const char* engine_app_id, const char* event, const char* result); + +static void __notify_cb(void *user_data, bundle *msg) +{ + char *method = NULL; + char *val = NULL; + + SLOG(LOG_DEBUG, TAG_VCM, "__notify_cb is invoked"); + + bundle_get_str(msg, VC_MANAGER_BUNDLE_METHOD, &method); + + if (0 == strncmp(VCD_MANAGER_METHOD_SET_VOLUME, method, strlen(VCD_MANAGER_METHOD_SET_VOLUME))) { + bundle_get_str(msg, VC_MANAGER_BUNDLE_MESSAGE, &val); + float volume = 0; + + if (val) { + volume = atof(val); + } + if (10 == g_volume_count) { + SLOG(LOG_DEBUG, TAG_VCM, "@@@ Set volume"); + SLOG(LOG_DEBUG, TAG_VCM, "@@ vc mgr set volume : volume(%f)", volume); + g_volume_count = 0; + } + + if (val) { + __vc_mgr_cb_set_volume(volume); + g_volume_count++; + } + } /* VCD_MANAGER_METHOD_SET_VOLUME */ + + else if (0 == strncmp(VCD_MANAGER_METHOD_SET_SERVICE_STATE, method, strlen(VCD_MANAGER_METHOD_SET_SERVICE_STATE))) { + bundle_get_str(msg, VC_MANAGER_BUNDLE_MESSAGE, &val); + int state = 0; + if (val) { + state = atoi(val); + SLOG(LOG_INFO, TAG_VCM, "@@ state changed : %d", state); + __vc_mgr_cb_service_state(state); + } + } /* VCD_MANAGER_METHOD_SET_SERVICE_STATE */ + + else if (0 == strncmp(VCD_MANAGER_METHOD_SPEECH_DETECTED, method, strlen(VCD_MANAGER_METHOD_SPEECH_DETECTED))) { + SLOG(LOG_INFO, TAG_VCM, "@@@ Get Speech detected"); + + __vc_mgr_cb_speech_detected(); + + SLOG(LOG_DEBUG, TAG_VCM, "@@@"); + } /* VCD_MANAGER_METHOD_SPEECH_DETECTED */ + + else if (0 == strncmp(VCD_MANAGER_METHOD_ALL_RESULT, method, strlen(VCD_MANAGER_METHOD_ALL_RESULT))) { + SLOG(LOG_INFO, TAG_VCM, "@@@ Get All Result"); + + bundle_get_str(msg, VC_MANAGER_BUNDLE_MESSAGE, &val); + + if (val) { + __vc_mgr_cb_all_result((vc_result_type_e)atoi(val)); + } + + SLOG(LOG_DEBUG, TAG_VCM, "@@@"); + } /* VCD_MANAGER_METHOD_ALL_RESULT */ + + else if (0 == strncmp(VCD_MANAGER_METHOD_PRE_RESULT, method, strlen(VCD_MANAGER_METHOD_PRE_RESULT))) { + SLOG(LOG_INFO, TAG_VCM, "@@@ Get Pre Result"); + char* event = NULL; + char* pre_result = NULL; + + bundle_get_str(msg, VC_MANAGER_BUNDLE_EVENT, &event); + bundle_get_str(msg, VC_MANAGER_BUNDLE_PRE_RESULT, &pre_result); + + if (NULL != pre_result) { + __vc_mgr_cb_pre_result((vc_pre_result_event_e)atoi(event), pre_result); + } + + SLOG(LOG_DEBUG, TAG_VCM, "@@@"); + } /* VCD_MANAGER_METHOD_PRE_RESULT */ + + else if (0 == strncmp(VCD_MANAGER_METHOD_SPECIFIC_ENGINE_RESULT, method, strlen(VCD_MANAGER_METHOD_SPECIFIC_ENGINE_RESULT))) { + SLOG(LOG_INFO, TAG_VCM, "@@@ Get specific engine result"); + char* engine_app_id = NULL; + char* event = NULL; + char* result = NULL; + + bundle_get_str(msg, VC_MANAGER_BUNDLE_ENGINE_APP_ID, &engine_app_id); + bundle_get_str(msg, VC_MANAGER_BUNDLE_EVENT, &event); + bundle_get_str(msg, VC_MANAGER_BUNDLE_RESULT, &result); + + if (NULL != result) { + gsize decodingSize=0; + gchar *gDecodedResult = (gchar *)g_base64_decode((const gchar *)result, &decodingSize); + if (gDecodedResult) + { + SLOG(LOG_WARN, TAG_VCM, "@@@ Get specific engine result --> %s", gDecodedResult); + __vc_mgr_cb_specific_engine_result(engine_app_id, event, gDecodedResult); + g_free(gDecodedResult); + } + } + } /* VCD_MANAGER_METHOD_SPECIFIC_ENGINE_RESULT */ + + else if (0 == strncmp(VCD_MANAGER_METHOD_RESULT, method, strlen(VCD_MANAGER_METHOD_RESULT))) { + SLOG(LOG_INFO, TAG_VCM, "@@@ Get System Result"); + + __vc_mgr_cb_system_result(); + + SLOG(LOG_DEBUG, TAG_VCM, "@@@"); + + } /* VCD_MANAGER_METHOD_RESULT */ + + else if (0 == strncmp(VCD_MANAGER_METHOD_DIALOG, method, strlen(VCD_MANAGER_METHOD_DIALOG))) { + SLOG(LOG_INFO, TAG_VCM, "@@@ Request Dialog"); + char* pid = NULL; + char* disp_text = NULL; + char* utt_text = NULL; + char* continous = NULL; + + bundle_get_str(msg, VC_MANAGER_BUNDLE_MESSAGE, &pid); + bundle_get_str(msg, VC_MANAGER_BUNDLE_DISP_TEXT, &disp_text); + bundle_get_str(msg, VC_MANAGER_BUNDLE_UTT_TEXT, &utt_text); + bundle_get_str(msg, VC_MANAGER_BUNDLE_CONTINUOUS, &continous); + + if (!strncmp(disp_text, "#NULL", strlen("#NULL") + 1)) + disp_text = NULL; + if (!strncmp(utt_text, "#NULL", strlen("#NULL") + 1)) + utt_text = NULL; + + __vc_mgr_cb_dialog(atoi(pid), disp_text, utt_text, (bool)atoi(continous)); + + SLOG(LOG_DEBUG, TAG_VCM, "@@@"); + } /* VCD_MANAGER_METHOD_DIALOG */ + + else if (0 == strncmp(VCD_MANAGER_METHOD_ERROR, method, strlen(VCD_MANAGER_METHOD_ERROR))) { + SLOG(LOG_INFO, TAG_VCM, "@@@ Get Error"); + char* reason = NULL; + char* daemon_pid = NULL; + char* err_msg = NULL; + + bundle_get_str(msg, VC_MANAGER_BUNDLE_REASON, &reason); + bundle_get_str(msg, VC_MANAGER_BUNDLE_DAEMON_PID, &daemon_pid); + bundle_get_str(msg, VC_MANAGER_BUNDLE_ERROR_MESSAGE, &err_msg); + + char* temp_msg = NULL; + if (NULL != err_msg && strncmp(err_msg, "#NULL", strlen("#NULL") + 1)) { + temp_msg = strdup(err_msg); + } + SLOG(LOG_ERROR, TAG_VCM, "@@ vc mgr Get Error message : reason(%d), daemon_pid(%d), msg(%s)", atoi(reason), atoi(daemon_pid), (temp_msg) ? temp_msg : "NULL"); + __vc_mgr_cb_error(atoi(reason), atoi(daemon_pid), temp_msg); + if (NULL != temp_msg) { + free(temp_msg); + temp_msg = NULL; + } + + SLOG(LOG_DEBUG, TAG_VCM, "@@@"); + } /* VCD_MANAGER_METHOD_ERROR */ + + else if (0 == strncmp(VCD_MANAGER_METHOD_SET_PRIVATE_DATA, method, strlen(VCD_MANAGER_METHOD_SET_PRIVATE_DATA))) { + SLOG(LOG_INFO, TAG_VCM, "@@@ Get request set private data"); + char* pid = NULL; + char* key = NULL; + char* private_data = NULL; + + bundle_get_str(msg, VC_MANAGER_BUNDLE_MESSAGE, &pid); + bundle_get_str(msg, VC_MANAGER_BUNDLE_KEY, &key); + bundle_get_str(msg, VC_MANAGER_BUNDLE_PRIVATE_DATA, &private_data); + + SLOG(LOG_INFO, TAG_VCM, "@@ vc mgr get request set private data : pid(%d) ", atoi(pid)); + if (pid > 0) { + __vc_mgr_cb_private_data_set(key, private_data); + } else { + SLOG(LOG_ERROR, TAG_VCM, "@@ got invalid pid(%d)", atoi(pid)); + } + + SLOG(LOG_DEBUG, TAG_VCM, "@@@"); + } /* VCD_MANAGER_METHOD_SET_PRIVATE_DATA */ + + else if (0 == strncmp(VCD_MANAGER_METHOD_FEEDBACK_AUDIO_FORMAT, method, strlen(VCD_MANAGER_METHOD_FEEDBACK_AUDIO_FORMAT))) { + SLOG(LOG_INFO, TAG_VCM, "@@@ Get request feedback audio format"); + char* channel = NULL; + char* audio_type = NULL; + char* rate = NULL; + + bundle_get_str(msg, VC_MANAGER_BUNDLE_AUDIO_CHANNEL, &channel); + bundle_get_str(msg, VC_MANAGER_BUNDLE_AUDIO_TYPE, &audio_type); + bundle_get_str(msg, VC_MANAGER_BUNDLE_AUDIO_RATE, &rate); + + __vc_mgr_cb_feedback_audio_format(atoi(rate), (vc_audio_channel_e)atoi(channel), (vc_audio_type_e)atoi(audio_type)); + + SLOG(LOG_INFO, TAG_VCM, "@@@"); + } /* VCD_MANAGER_METHOD_FEEDBACK_AUDIO_FORMAT */ + + // TODO: uncomment this line after vcc done + // else if (0 == strncmp(VCC_MANAGER_METHOD_SET_FOREGROUND, method, strlen(VCC_MANAGER_METHOD_SET_FOREGROUND))) { + // SLOG(LOG_INFO, TAG_VCM, "@@@ Set foreground"); + // char* temp_pid = NULL; + // char* temp_value = NULL; + // int pid = 0; + // int value = 0; + + // bundle_get_str(msg, VC_MANAGER_BUNDLE_MESSAGE, &temp_pid); + // bundle_get_str(msg, VC_MANAGER_BUNDLE_VALUE, &temp_value); + // pid = atoi(temp_pid); + // value = atoi(temp_value); + + // SLOG(LOG_INFO, TAG_VCM, "@@ foreground changed : pid(%d) value(%s)", pid, value ? "true" : "false"); + + // __vc_mgr_cb_set_foreground(pid, (bool)value); + // SLOG(LOG_DEBUG, TAG_VCM, "@@@"); + // } /* VCC_MANAGER_METHOD_SET_FOREGROUND */ + + else { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Invalid msg"); + } + +} + +static void __send_buffer_cb(void *user_data, rpc_port_proxy_array_char_h data_in, bundle *msg) +{ + char *method = NULL; + char *val = NULL; + + SLOG(LOG_DEBUG, TAG_VCM, "__send_buffer_cb is invoked"); + + bundle_get_str(msg, VC_MANAGER_BUNDLE_METHOD, &method); + + if (0 == strncmp(VCD_MANAGER_METHOD_FEEDBACK_STREAMING, method, strlen(VCD_MANAGER_METHOD_FEEDBACK_STREAMING))) { + char *utt_id = NULL; + char *event = NULL; + char* buffer = NULL; + int len = 0; + + bundle_get_str(msg, VC_MANAGER_BUNDLE_MESSAGE, &val); + bundle_get_str(msg, VC_MANAGER_BUNDLE_UTTID, &utt_id); + bundle_get_str(msg, VC_MANAGER_BUNDLE_EVENT, &event); + + rpc_port_proxy_array_char_get(data_in, &buffer, &len); + __vc_mgr_cb_feedback_streaming(atoi(val), atoi(utt_id), atoi(event), buffer, len); + free(buffer); + + SLOG(LOG_INFO, TAG_VCM, "@@@"); + } /* VCD_MANAGER_METHOD_FEEDBACK_STREAMING */ + + else { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Invalid msg"); + } + +} + +static void __on_connected(rpc_port_proxy_vc_mgr_h h, void *user_data) +{ + g_proxy_tidl_info->connected = true; + g_proxy_tidl_info->connection_requesting = false; + g_proxy_tidl_info->register_callback_invoked = false; + + SLOG(LOG_INFO, TAG_VCM, "Connected to server"); +} + +static void __on_disconnected(rpc_port_proxy_vc_mgr_h h, void *user_data) +{ + g_proxy_tidl_info->connected = false; + g_proxy_tidl_info->connection_requesting = false; + g_proxy_tidl_info->register_callback_invoked = false; + + SLOG(LOG_INFO, TAG_VCM, "Disonnected to server"); +} + +static void __on_rejected(rpc_port_proxy_vc_mgr_h h, void *user_data) +{ + g_proxy_tidl_info->connection_requesting = false; + g_proxy_tidl_info->register_callback_invoked = false; + + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Rejected from server"); +} + + +static rpc_port_proxy_vc_mgr_h __create_rpc_port(const char* engine_app_id) +{ + SLOG(LOG_DEBUG, TAG_VCM, "[TIDL] __create_rpc_port"); + rpc_port_proxy_vc_mgr_callback_s rpc_callback = { + .connected = __on_connected, + .disconnected = __on_disconnected, + .rejected = __on_rejected + }; + + rpc_port_proxy_vc_mgr_h handle = NULL; + if (0 != rpc_port_proxy_vc_mgr_create(engine_app_id, &rpc_callback, NULL, &handle)) { + SLOG(LOG_ERROR, TAG_VCM, "[TIDL ERROR] Fail to create proxy"); + return NULL; + } + + return handle; +} + +static void __vcd_mgr_create_cb(rpc_port_stub_vcd_mgr_context_h context, void *user_data) +{ + g_stub_tidl_info->connected = true; + g_stub_tidl_info->register_callback_requesting = false; + + SLOG(LOG_DEBUG, TAG_VCM, "Connected to server"); + + char *sender = NULL; + + rpc_port_stub_vcd_mgr_context_get_sender(context, &sender); + if (!sender) { + SLOG(LOG_ERROR, TAG_VCM, "@@@ Sender is NULL"); + return; + } + + SLOG(LOG_DEBUG, TAG_VCM, "@@@ Server connect. appid(%s)", sender); + free(sender); +} + +static void __vcd_mgr_terminate_cb(rpc_port_stub_vcd_mgr_context_h context, void *user_data) +{ + g_stub_tidl_info->connected = false; + g_stub_tidl_info->register_callback_requesting = false; + + rpc_port_stub_vcd_mgr_context_set_tag(context, NULL); + + char *sender = NULL; + rpc_port_stub_vcd_mgr_context_get_sender(context, &sender); + if (!sender) + return; + + SLOG(LOG_INFO, TAG_VCM, "@@@ Server disconnect. appid(%s)", sender); + free(sender); +} + +static void __vcd_mgr_set_foreground_cb(rpc_port_stub_vcd_mgr_context_h context, int pid, int value, void *user_data) +{ + SLOG(LOG_INFO, TAG_VCM, "@@@ Set foreground"); + SLOG(LOG_INFO, TAG_VCM, "@@ foreground changed : pid(%d) value(%s)", pid, value ? "true" : "false"); + + __vc_mgr_cb_set_foreground(pid, (bool)value); + + SLOG(LOG_DEBUG, TAG_VCM, "@@@"); +} + +static int __vcd_mgr_get_private_data_cb(rpc_port_stub_vcd_mgr_context_h context, int pid, const char *key, char **data, void *user_data) +{ + SLOG(LOG_INFO, TAG_VCM, "@@@ Get request get private data"); + SLOG(LOG_INFO, TAG_VCM, "@@ vc mgr get request get private data : pid(%d) ", pid); + + int ret = -1; + char *temp_data = NULL; + + ret = __vc_mgr_cb_private_data_requested(key, &temp_data); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCM, "[OUT ERROR] Result(%d)", ret); + return ret; + } + if (NULL == temp_data) { + SLOG(LOG_INFO, TAG_VCM, "data parameter is NULL"); + temp_data = strdup("#NULL"); + } + *data = temp_data; + SLOG(LOG_DEBUG, TAG_VCM, "@@@"); + + return ret; +} + +static int __vcd_mgr_auth_enable_cb(rpc_port_stub_vcd_mgr_context_h context, int pid, void *user_data) +{ + SLOG(LOG_INFO, TAG_VCM, "@@@ Get request auth enable"); + SLOG(LOG_INFO, TAG_VCM, "@@ vc mgr request auth enable : pid(%d)", pid); + + int ret = -1; + + ret = __vc_mgr_request_auth_enable(pid); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCM, "[OUT ERROR] Result(%d)", ret); + } + + SLOG(LOG_DEBUG, TAG_VCM, "@@@"); + + return ret; +} + +static int __vcd_mgr_auth_disable_cb(rpc_port_stub_vcd_mgr_context_h context, int pid, void *user_data) +{ + SLOG(LOG_INFO, TAG_VCM, "@@@ Get request auth disable"); + SLOG(LOG_INFO, TAG_VCM, "@@ vc mgr request auth disable : pid(%d)", pid); + + int ret = -1; + + ret = __vc_mgr_request_auth_disable(pid); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCM, "[OUT ERROR] Result(%d)", ret); + } + + SLOG(LOG_DEBUG, TAG_VCM, "@@@"); + + return ret; +} + +static int __vcd_mgr_auth_start_cb(rpc_port_stub_vcd_mgr_context_h context, int pid, void *user_data) +{ + SLOG(LOG_INFO, TAG_VCM, "@@@ Get request auth start"); + SLOG(LOG_INFO, TAG_VCM, "@@ vc mgr request auth start : pid(%d)", pid); + + int ret = -1; + + ret = __vc_mgr_request_auth_start(pid); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCM, "[OUT ERROR] Result(%d)", ret); + } + + SLOG(LOG_DEBUG, TAG_VCM, "@@@"); + + return ret; +} + +static int __vcd_mgr_auth_stop_cb(rpc_port_stub_vcd_mgr_context_h context, int pid, void *user_data) +{ + SLOG(LOG_INFO, TAG_VCM, "@@@ Get request auth stop"); + SLOG(LOG_INFO, TAG_VCM, "@@ vc mgr request auth stop : pid(%d)", pid); + + int ret = -1; + + ret = __vc_mgr_request_auth_stop(pid); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCM, "[OUT ERROR] Result(%d)", ret); + } + + SLOG(LOG_DEBUG, TAG_VCM, "@@@"); + + return ret; +} + +static int __vcd_mgr_auth_cancel_cb(rpc_port_stub_vcd_mgr_context_h context, int pid, void *user_data) +{ + SLOG(LOG_INFO, TAG_VCM, "@@@ Get request auth cancel"); + SLOG(LOG_INFO, TAG_VCM, "@@ vc mgr request auth cancel : pid(%d)", pid); + + int ret = -1; + + ret = __vc_mgr_request_auth_cancel(pid); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCM, "[OUT ERROR] Result(%d)", ret); + } + + SLOG(LOG_DEBUG, TAG_VCM, "@@@"); + + return ret; +} + +static void __register_stub_callback() +{ + if (g_stub_tidl_info->register_callback_requesting) { + return; + } + + SLOG(LOG_DEBUG, TAG_VCM, "[TIDL] __register_stub_callback"); + + g_mgr_callback.create = __vcd_mgr_create_cb; + g_mgr_callback.terminate = __vcd_mgr_terminate_cb; + g_mgr_callback.set_foreground = __vcd_mgr_set_foreground_cb; + g_mgr_callback.get_private_data = __vcd_mgr_get_private_data_cb; + g_mgr_callback.auth_enable = __vcd_mgr_auth_enable_cb; + g_mgr_callback.auth_disable = __vcd_mgr_auth_disable_cb; + g_mgr_callback.auth_start = __vcd_mgr_auth_start_cb; + g_mgr_callback.auth_stop = __vcd_mgr_auth_stop_cb; + g_mgr_callback.auth_cancel = __vcd_mgr_auth_cancel_cb; + + int ret = -1; + ret = rpc_port_stub_vcd_mgr_register(&g_mgr_callback, NULL); + if (0 == ret) { + SLOG(LOG_DEBUG, TAG_VCM, "register callback"); + g_stub_tidl_info->register_callback_requesting = true; + return; + } + + SLOG(LOG_ERROR, TAG_VCM, "Fail to rister callback(%d)", ret); + return; +} + +int vc_mgr_tidl_open_connection() +{ + SLOG(LOG_DEBUG, TAG_VCM, "[TIDL] vc_mgr_tidl_open_connection"); + pthread_mutex_lock(&g_tidl_mutex); + + if (NULL != g_proxy_tidl_info) { + SLOG(LOG_ERROR, TAG_VCM, "[TIDL ERROR] g_proxy_tidl_info already created"); + pthread_mutex_unlock(&g_tidl_mutex); + return VC_ERROR_NONE; + } + + g_proxy_tidl_info = (vc_mgr_tidl_info_s*)calloc(1, sizeof(vc_mgr_tidl_info_s)); + + if (NULL == g_proxy_tidl_info) { + SLOG(LOG_ERROR, TAG_VCM, "[TIDL ERROR] Fail to create vc_mgr_tidl_info_s"); + pthread_mutex_unlock(&g_tidl_mutex); + return VC_ERROR_OUT_OF_MEMORY; + } + + char* engine_app_id = vconf_get_str(VC_ENGINE_DB_DEFAULT); + if (NULL == engine_app_id) { + SLOG(LOG_ERROR, TAG_VCM, "[TIDL] vconf not found"); + pthread_mutex_unlock(&g_tidl_mutex); + return VC_ERROR_ENGINE_NOT_FOUND; + } + + g_proxy_tidl_info->rpc_h = __create_rpc_port(engine_app_id); + if (NULL == g_proxy_tidl_info->rpc_h) { + SLOG(LOG_ERROR, TAG_VCM, "[TIDL ERROR] Fail to create proxy"); + free(engine_app_id); + free(g_proxy_tidl_info); + g_proxy_tidl_info = NULL; + pthread_mutex_unlock(&g_tidl_mutex); + return VC_ERROR_OPERATION_FAILED; + } + + SLOG(LOG_INFO, TAG_VCM, "[TIDL] rpc_h(%p), engine_app_id(%s)", g_proxy_tidl_info->rpc_h, engine_app_id); + free(engine_app_id); + + g_stub_tidl_info = (vcd_mgr_tidl_info_s*)calloc(1, sizeof(vcd_mgr_tidl_info_s)); + + if (NULL == g_stub_tidl_info) { + SLOG(LOG_ERROR, TAG_VCM, "[TIDL ERROR] Fail to create vcd_mgr_tidl_info_s"); + pthread_mutex_unlock(&g_tidl_mutex); + return VC_ERROR_OUT_OF_MEMORY; + } + + __register_stub_callback(); + + pthread_mutex_unlock(&g_tidl_mutex); + + return VC_ERROR_NONE; +} + +int vc_mgr_tidl_close_connection() +{ + SLOG(LOG_DEBUG, TAG_VCM, "[TIDL] vc_mgr_tidl_close_connection"); + pthread_mutex_lock(&g_tidl_mutex); + + if (NULL == g_proxy_tidl_info) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to get tidl info"); + pthread_mutex_unlock(&g_tidl_mutex); + return VC_ERROR_OPERATION_FAILED; + } + + if (0 != rpc_port_proxy_vc_mgr_destroy(g_proxy_tidl_info->rpc_h)) { + SLOG(LOG_ERROR, TAG_VCM, "[TIDL ERROR] Fail to destroy tidl handle"); + pthread_mutex_unlock(&g_tidl_mutex); + return VC_ERROR_OPERATION_FAILED; + } + + g_proxy_tidl_info->rpc_h = NULL; + g_proxy_tidl_info->notify_cb_h = NULL; + g_proxy_tidl_info->send_buffer_cb_h = NULL; + + free(g_proxy_tidl_info); + g_proxy_tidl_info = NULL; + + free(g_stub_tidl_info); + g_stub_tidl_info = NULL; + + pthread_mutex_unlock(&g_tidl_mutex); + + return VC_ERROR_NONE; +} + +static void __request_tidl_connect() +{ + if (g_proxy_tidl_info->connection_requesting) { + return; + } + + int ret = rpc_port_proxy_vc_mgr_connect(g_proxy_tidl_info->rpc_h); + SLOG(LOG_INFO, TAG_VCM, "[INFO] Request connection to stub. ret(%d)", ret); + + if (0 == ret) { + g_proxy_tidl_info->connection_requesting = true; + } +} + +static int __create_callback_handles() +{ + if (NULL != g_proxy_tidl_info->notify_cb_h) { + rpc_port_proxy_vc_mgr_notify_cb_dispose(g_proxy_tidl_info->rpc_h, g_proxy_tidl_info->notify_cb_h); + g_proxy_tidl_info->notify_cb_h = NULL; + } + + if (RPC_PORT_ERROR_NONE != rpc_port_proxy_vc_mgr_notify_cb_create(&g_proxy_tidl_info->notify_cb_h)) { + return VC_ERROR_OUT_OF_MEMORY; + } + + rpc_port_proxy_vc_mgr_notify_cb_set_callback(g_proxy_tidl_info->notify_cb_h, __notify_cb, NULL); + + rpc_port_proxy_vc_mgr_notify_cb_set_once(g_proxy_tidl_info->notify_cb_h, false); + + if (NULL != g_proxy_tidl_info->send_buffer_cb_h) { + rpc_port_proxy_vc_mgr_send_buffer_cb_dispose(g_proxy_tidl_info->rpc_h, g_proxy_tidl_info->send_buffer_cb_h); + g_proxy_tidl_info->send_buffer_cb_h = NULL; + } + + if (RPC_PORT_ERROR_NONE != rpc_port_proxy_vc_mgr_send_buffer_cb_create(&g_proxy_tidl_info->send_buffer_cb_h)) { + return VC_ERROR_OUT_OF_MEMORY; + } + + rpc_port_proxy_vc_mgr_send_buffer_cb_set_callback(g_proxy_tidl_info->send_buffer_cb_h, __send_buffer_cb, NULL); + + rpc_port_proxy_vc_mgr_send_buffer_cb_set_once(g_proxy_tidl_info->send_buffer_cb_h, false); + + return VC_ERROR_NONE; +} + +static int __invoke_register_callback() +{ + if (g_proxy_tidl_info->register_callback_invoked) { + SLOG(LOG_ERROR, TAG_VCM, "[INFO] Already register callback is invoked"); + return VC_ERROR_NONE; + } + + int ret = __create_callback_handles(g_proxy_tidl_info); + if (VC_ERROR_NONE != ret) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to create callback handle. ret(%d)", ret); + return VC_ERROR_OPERATION_FAILED; + } + + rpc_port_proxy_vc_mgr_invoke_register_cb(g_proxy_tidl_info->rpc_h, getpid(), g_proxy_tidl_info->notify_cb_h, g_proxy_tidl_info->send_buffer_cb_h); + g_proxy_tidl_info->register_callback_invoked = true; + return VC_ERROR_NONE; +} + +int vc_mgr_tidl_request_hello() +{ + SLOG(LOG_DEBUG, TAG_VCM, "[TIDL] vc_mgr_tidl_request_hello"); + + if (NULL == g_proxy_tidl_info) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to get proxy tidl info"); + return VC_ERROR_OPERATION_FAILED; + } + + if (!g_proxy_tidl_info->connected) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Proxy Not Connected"); + __request_tidl_connect(); + return VC_ERROR_OPERATION_FAILED; + } + + if (VC_ERROR_NONE != __invoke_register_callback()) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to invoke register callback"); + return VC_ERROR_OPERATION_FAILED; + } + + if (NULL == g_stub_tidl_info) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to get stub tidl info"); + return VC_ERROR_OPERATION_FAILED; + } + + if (!g_stub_tidl_info->connected) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Stub Not Connected"); + __register_stub_callback(); + return VC_ERROR_OPERATION_FAILED; + } + + SLOG(LOG_DEBUG, TAG_VCM, ">>>>> VCM Hello"); + + SLOG(LOG_DEBUG, TAG_VCM, "<<<<"); + + return VC_ERROR_NONE; +} + +int vc_mgr_tidl_request_initialize(int pid, int audio_streaming_mode, int* service_state, int* foreground, int* daemon_pid) +{ + SLOG(LOG_DEBUG, TAG_VCM, "[TIDL] vc_mgr_tidl_request_initialize"); + + if (NULL == g_proxy_tidl_info) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to get tidl info"); + return VC_ERROR_OPERATION_FAILED; + } + + int tmp_service_state = 0; + int tmp_forground = 0; + int tmp_daemon_pid = 0; + + if (!g_proxy_tidl_info->connected) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Not Connected"); + return VC_ERROR_OPERATION_FAILED; + } + + if (0 != rpc_port_proxy_vc_mgr_invoke_initialize(g_proxy_tidl_info->rpc_h, pid, audio_streaming_mode, &tmp_service_state, &tmp_forground, &tmp_daemon_pid)) { + SLOG(LOG_ERROR, TAG_VCM, "[TIDL ERROR] Request vc manager initialize : Fail to invoke message"); + return VC_ERROR_OPERATION_FAILED; + } + + *service_state = tmp_service_state; + *foreground = tmp_forground; + *daemon_pid = tmp_daemon_pid; + + SLOG(LOG_DEBUG, TAG_VCM, "[TIDL] vc manager initialize: service_state(%d), foreground(%d), daemon_pid(%d)", *service_state, *foreground, *daemon_pid); + + return VC_ERROR_NONE; +} + +int vc_mgr_tidl_request_finalize(int pid) +{ + SLOG(LOG_DEBUG, TAG_VCM, "[TIDL] vc_mgr_tidl_request_finalize"); + + if (NULL == g_proxy_tidl_info) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to get tidl info"); + return VC_ERROR_OPERATION_FAILED; + } + + if (!g_proxy_tidl_info->connected) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Not Connected"); + return VC_ERROR_OPERATION_FAILED; + } + + if (0 != rpc_port_proxy_vc_mgr_invoke_finalize(g_proxy_tidl_info->rpc_h, pid)) { + SLOG(LOG_ERROR, TAG_VCM, "[TIDL ERROR] Request vc manager finalize : Fail to invoke message"); + return VC_ERROR_OPERATION_FAILED; + } + + return VC_ERROR_NONE; +} + +int vc_mgr_tidl_request_set_command(int pid) +{ + SLOG(LOG_DEBUG, TAG_VCM, "[TIDL] vc_mgr_tidl_request_set_command"); + + if (NULL == g_proxy_tidl_info) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to get tidl info"); + return VC_ERROR_OPERATION_FAILED; + } + + if (!g_proxy_tidl_info->connected) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Not Connected"); + return VC_ERROR_OPERATION_FAILED; + } + + if (0 != rpc_port_proxy_vc_mgr_invoke_set_command(g_proxy_tidl_info->rpc_h, pid)) { + SLOG(LOG_ERROR, TAG_VCM, "[TIDL ERROR] Request vc manager set command : Fail to invoke message"); + return VC_ERROR_OPERATION_FAILED; + } + + return VC_ERROR_NONE; +} + +int vc_mgr_tidl_request_unset_command(int pid) +{ + SLOG(LOG_DEBUG, TAG_VCM, "[TIDL] vc_mgr_tidl_request_unset_command"); + + if (NULL == g_proxy_tidl_info) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to get tidl info"); + return VC_ERROR_OPERATION_FAILED; + } + + if (!g_proxy_tidl_info->connected) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Not Connected"); + return VC_ERROR_OPERATION_FAILED; + } + + if (0 != rpc_port_proxy_vc_mgr_invoke_unset_command(g_proxy_tidl_info->rpc_h, pid)) { + SLOG(LOG_ERROR, TAG_VCM, "[TIDL ERROR] Request vc manager unset command : Fail to invoke message"); + return VC_ERROR_OPERATION_FAILED; + } + + return VC_ERROR_NONE; +} + +int vc_mgr_tidl_request_demandable_client(int pid) +{ + SLOG(LOG_DEBUG, TAG_VCM, "[TIDL] vc_mgr_tidl_request_demandable_client"); + + if (NULL == g_proxy_tidl_info) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to get tidl info"); + return VC_ERROR_OPERATION_FAILED; + } + + if (!g_proxy_tidl_info->connected) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Not Connected"); + return VC_ERROR_OPERATION_FAILED; + } + + if (0 != rpc_port_proxy_vc_mgr_invoke_demandable_client(g_proxy_tidl_info->rpc_h, pid)) { + SLOG(LOG_ERROR, TAG_VCM, "[TIDL ERROR] Request vc manager demandable client : Fail to invoke message"); + return VC_ERROR_OPERATION_FAILED; + } + + return VC_ERROR_NONE; +} + +int vc_mgr_tidl_request_set_audio_type(int pid, const char* audio_type) +{ + SLOG(LOG_DEBUG, TAG_VCM, "[TIDL] vc_mgr_tidl_request_set_audio_type"); + + if (NULL == g_proxy_tidl_info) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to get tidl info"); + return VC_ERROR_OPERATION_FAILED; + } + + if (!g_proxy_tidl_info->connected) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Not Connected"); + return VC_ERROR_OPERATION_FAILED; + } + + if (0 != rpc_port_proxy_vc_mgr_invoke_set_audio_type(g_proxy_tidl_info->rpc_h, pid, audio_type)) { + SLOG(LOG_ERROR, TAG_VCM, "[TIDL ERROR] Request vc manager set audio type : Fail to invoke message"); + return VC_ERROR_OPERATION_FAILED; + } + + return VC_ERROR_NONE; +} + +int vc_mgr_tidl_request_get_audio_type(int pid, char** audio_type) +{ + SLOG(LOG_DEBUG, TAG_VCM, "[TIDL] vc_mgr_tidl_request_get_audio_type"); + + if (NULL == g_proxy_tidl_info) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to get tidl info"); + return VC_ERROR_OPERATION_FAILED; + } + + if (!g_proxy_tidl_info->connected) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Not Connected"); + return VC_ERROR_OPERATION_FAILED; + } + + char *tmp = NULL; + if (0 != rpc_port_proxy_vc_mgr_invoke_get_audio_type(g_proxy_tidl_info->rpc_h, pid, &tmp)) { + SLOG(LOG_ERROR, TAG_VCM, "[TIDL ERROR] Request vc manager get audio type : Fail to invoke message"); + return VC_ERROR_OPERATION_FAILED; + } + SLOG(LOG_DEBUG, TAG_VCM, "[TIDL] Request vc manager get audio type : Success"); + + *audio_type = tmp; + + return VC_ERROR_NONE; +} + +int vc_mgr_tidl_request_set_private_data(int pid, const char* key, const char* data) +{ + SLOG(LOG_DEBUG, TAG_VCM, "[TIDL] vc_mgr_tidl_request_set_private_data"); + + if (NULL == g_proxy_tidl_info) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to get tidl info"); + return VC_ERROR_OPERATION_FAILED; + } + + if (!g_proxy_tidl_info->connected) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Not Connected"); + return VC_ERROR_OPERATION_FAILED; + } + + rpc_port_proxy_vc_mgr_invoke_set_private_data(g_proxy_tidl_info->rpc_h, pid, key, data); + + return VC_ERROR_NONE; +} + +int vc_mgr_tidl_request_get_private_data(int pid, const char* key, char** data) +{ + SLOG(LOG_DEBUG, TAG_VCM, "[TIDL] vc_mgr_tidl_request_get_private_data"); + + if (NULL == g_proxy_tidl_info) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to get tidl info"); + return VC_ERROR_OPERATION_FAILED; + } + + if (!g_proxy_tidl_info->connected) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Not Connected"); + return VC_ERROR_OPERATION_FAILED; + } + + char *tmp = NULL; + if (0 != rpc_port_proxy_vc_mgr_invoke_get_private_data(g_proxy_tidl_info->rpc_h, pid, key, &tmp)) { + SLOG(LOG_ERROR, TAG_VCM, "[TIDL ERROR] Request vc manager get private data : Fail to invoke message"); + return VC_ERROR_OPERATION_FAILED; + } + SLOG(LOG_DEBUG, TAG_VCM, "[TIDL] Request vc manager get private data : Success"); + + *data = tmp; + + return VC_ERROR_NONE; +} + +int vc_mgr_tidl_request_set_client_info(int pid) +{ + SLOG(LOG_DEBUG, TAG_VCM, "[TIDL] vc_mgr_tidl_request_set_client_info"); + + if (NULL == g_proxy_tidl_info) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to get tidl info"); + return VC_ERROR_OPERATION_FAILED; + } + + if (!g_proxy_tidl_info->connected) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Not Connected"); + return VC_ERROR_OPERATION_FAILED; + } + + if (0 != rpc_port_proxy_vc_mgr_invoke_set_client_info(g_proxy_tidl_info->rpc_h, pid)) { + SLOG(LOG_ERROR, TAG_VCM, "[TIDL ERROR] Request vc manager set client info : Fail to invoke message"); + return VC_ERROR_OPERATION_FAILED; + } + + return VC_ERROR_NONE; +} + +int vc_mgr_tidl_request_set_domain(int pid, const char* domain) +{ + SLOG(LOG_DEBUG, TAG_VCM, "[TIDL] vc_mgr_tidl_request_set_domain"); + + if (NULL == g_proxy_tidl_info) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to get tidl info"); + return VC_ERROR_OPERATION_FAILED; + } + + if (!g_proxy_tidl_info->connected) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Not Connected"); + return VC_ERROR_OPERATION_FAILED; + } + + if (0 != rpc_port_proxy_vc_mgr_invoke_set_domain(g_proxy_tidl_info->rpc_h, pid, domain)) { + SLOG(LOG_ERROR, TAG_VCM, "[TIDL ERROR] Request vc manager set domain : Fail to invoke message"); + return VC_ERROR_OPERATION_FAILED; + } + + return VC_ERROR_NONE; +} + +int vc_mgr_tidl_request_do_action(int pid, vc_send_event_type_e type, char* send_event) +{ + SLOG(LOG_DEBUG, TAG_VCM, "[TIDL] vc_mgr_tidl_request_do_action"); + + if (NULL == g_proxy_tidl_info) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to get tidl info"); + return VC_ERROR_OPERATION_FAILED; + } + + if (!g_proxy_tidl_info->connected) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Not Connected"); + return VC_ERROR_OPERATION_FAILED; + } + + rpc_port_proxy_vc_mgr_invoke_do_action(g_proxy_tidl_info->rpc_h, pid, type, send_event); + + return VC_ERROR_NONE; +} + +int vc_mgr_tidl_request_start(int pid, int recognition_mode, bool exclusive_command_option, bool start_by_client, int disabled_cmd_type) +{ + SLOG(LOG_DEBUG, TAG_VCM, "[TIDL] vc_mgr_tidl_request_start"); + + if (NULL == g_proxy_tidl_info) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to get tidl info"); + return VC_ERROR_OPERATION_FAILED; + } + + if (!g_proxy_tidl_info->connected) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Not Connected"); + return VC_ERROR_OPERATION_FAILED; + } + + if (0 != rpc_port_proxy_vc_mgr_invoke_start(g_proxy_tidl_info->rpc_h, pid, recognition_mode, exclusive_command_option, start_by_client, disabled_cmd_type)) { + SLOG(LOG_ERROR, TAG_VCM, "[TIDL ERROR] Request vc manager start : Fail to invoke message"); + return VC_ERROR_OPERATION_FAILED; + } + + return VC_ERROR_NONE; +} + +int vc_mgr_tidl_request_stop(int pid) +{ + SLOG(LOG_DEBUG, TAG_VCM, "[TIDL] vc_mgr_tidl_request_stop"); + + if (NULL == g_proxy_tidl_info) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to get tidl info"); + return VC_ERROR_OPERATION_FAILED; + } + + if (!g_proxy_tidl_info->connected) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Not Connected"); + return VC_ERROR_OPERATION_FAILED; + } + + if (0 != rpc_port_proxy_vc_mgr_invoke_stop(g_proxy_tidl_info->rpc_h, pid)) { + SLOG(LOG_ERROR, TAG_VCM, "[TIDL ERROR] Request vc manager stop : Fail to invoke message"); + return VC_ERROR_OPERATION_FAILED; + } + + return VC_ERROR_NONE; +} + +int vc_mgr_tidl_request_cancel(int pid) +{ + SLOG(LOG_DEBUG, TAG_VCM, "[TIDL] vc_mgr_tidl_request_cancel"); + + if (NULL == g_proxy_tidl_info) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to get tidl info"); + return VC_ERROR_OPERATION_FAILED; + } + + if (!g_proxy_tidl_info->connected) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Not Connected"); + return VC_ERROR_OPERATION_FAILED; + } + + if (0 != rpc_port_proxy_vc_mgr_invoke_cancel(g_proxy_tidl_info->rpc_h, pid)) { + SLOG(LOG_ERROR, TAG_VCM, "[TIDL ERROR] Request vc manager cancel : Fail to invoke message"); + return VC_ERROR_OPERATION_FAILED; + } + + return VC_ERROR_NONE; +} + +int vc_mgr_tidl_request_set_audio_streaming_mode(int pid, vc_audio_streaming_mode_e mode) +{ + SLOG(LOG_DEBUG, TAG_VCM, "[TIDL] vc_mgr_tidl_request_set_audio_streaming_mode"); + + if (NULL == g_proxy_tidl_info) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to get tidl info"); + return VC_ERROR_OPERATION_FAILED; + } + + if (!g_proxy_tidl_info->connected) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Not Connected"); + return VC_ERROR_OPERATION_FAILED; + } + + rpc_port_proxy_vc_mgr_invoke_set_audio_streaming_mode(g_proxy_tidl_info->rpc_h, pid, mode); + + return VC_ERROR_NONE; +} + +int vc_mgr_tidl_send_result_selection(int pid) +{ + SLOG(LOG_DEBUG, TAG_VCM, "[TIDL] vc_mgr_tidl_send_result_selection"); + + if (NULL == g_proxy_tidl_info) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to get tidl info"); + return VC_ERROR_OPERATION_FAILED; + } + + if (!g_proxy_tidl_info->connected) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Not Connected"); + return VC_ERROR_OPERATION_FAILED; + } + + rpc_port_proxy_vc_mgr_invoke_send_result_selection(g_proxy_tidl_info->rpc_h, pid); + + return VC_ERROR_NONE; +} + +int vc_mgr_tidl_send_specific_engine_request(int pid, const char* engine_app_id, const char* event, const char* request) +{ + SLOG(LOG_DEBUG, TAG_VCM, "[TIDL] vc_mgr_tidl_send_result_selection"); + + if (NULL == g_proxy_tidl_info) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to get tidl info"); + return VC_ERROR_OPERATION_FAILED; + } + + if (!g_proxy_tidl_info->connected) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Not Connected"); + return VC_ERROR_OPERATION_FAILED; + } + + gchar *gEncodedRequest = g_base64_encode((const guchar*)request, strlen(request)); + + rpc_port_proxy_vc_mgr_invoke_send_specific_engine_request(g_proxy_tidl_info->rpc_h, pid, engine_app_id, event, gEncodedRequest); + + if (gEncodedRequest) + g_free(gEncodedRequest); + + return VC_ERROR_NONE; +} + +int vc_mgr_tidl_send_utterance_status(int pid, int utt_id, vc_tts_utterance_status_e utt_status) +{ + SLOG(LOG_DEBUG, TAG_VCM, "[TIDL] vc_mgr_tidl_send_utterance_status"); + + if (NULL == g_proxy_tidl_info) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to get tidl info"); + return VC_ERROR_OPERATION_FAILED; + } + + if (!g_proxy_tidl_info->connected) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Not Connected"); + return VC_ERROR_OPERATION_FAILED; + } + + rpc_port_proxy_vc_mgr_invoke_send_utterance_status(g_proxy_tidl_info->rpc_h, utt_id, utt_status); + + return VC_ERROR_NONE; +} + +int vc_mgr_tidl_send_audio_streaming(int pid, vc_audio_streaming_event_e event, unsigned char* buffer, unsigned int len) +{ + SLOG(LOG_DEBUG, TAG_VCM, "[TIDL] vc_mgr_tidl_send_audio_streaming"); + + if (NULL == g_proxy_tidl_info) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to get tidl info"); + return VC_ERROR_OPERATION_FAILED; + } + + if (!g_proxy_tidl_info->connected) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Not Connected"); + return VC_ERROR_OPERATION_FAILED; + } + + rpc_port_proxy_array_char_h data = NULL; + rpc_port_proxy_array_char_create(&data); + if (NULL == data) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to create data handle"); + return VC_ERROR_OUT_OF_MEMORY; + } + + if (NULL != buffer && 0 < len) { + rpc_port_proxy_array_char_set(data, (char*)buffer, len); + } else { + SLOG(LOG_ERROR, TAG_VCM, "[TIDL] buffer is empty"); + } + + rpc_port_proxy_vc_mgr_invoke_send_audio_streaming(g_proxy_tidl_info->rpc_h, pid, event, data); + rpc_port_proxy_array_char_destroy(data); + + return VC_ERROR_NONE; +} diff --git a/client/vc_mgr_tidl.h b/client/vc_mgr_tidl.h new file mode 100644 index 0000000..fd91d7f --- /dev/null +++ b/client/vc_mgr_tidl.h @@ -0,0 +1,85 @@ +/* +* Copyright (c) 2022 Samsung Electronics Co., Ltd All Rights Reserved +* +* Licensed under the Apache License, Version 2.0 (the License); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an AS IS BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + + +#ifndef __VC_TIDL_H_ +#define __VC_TIDL_H_ + +#include "voice_control_manager_internal.h" + + +#ifdef __cplusplus +extern "C" { +#endif + +int vc_mgr_tidl_open_connection(); + +int vc_mgr_tidl_close_connection(); + + +int vc_mgr_tidl_request_hello(); + +int vc_mgr_tidl_request_initialize(int pid, int audio_streaming_mode, int* service_state, int* foreground, int* daemon_pid); + +int vc_mgr_tidl_request_finalize(int pid); + +int vc_mgr_tidl_request_set_command(int pid); + +int vc_mgr_tidl_request_unset_command(int pid); + +int vc_mgr_tidl_request_demandable_client(int pid); + +int vc_mgr_tidl_request_set_audio_type(int pid, const char* audio_type); + +int vc_mgr_tidl_request_get_audio_type(int pid, char** audio_type); + +int vc_mgr_tidl_request_set_private_data(int pid, const char* key, const char* data); + +int vc_mgr_tidl_request_get_private_data(int pid, const char* key, char** data); + +int vc_mgr_tidl_request_set_client_info(int pid); + +int vc_mgr_tidl_request_set_domain(int pid, const char* domain); + +int vc_mgr_tidl_request_do_action(int pid, vc_send_event_type_e type, char* send_event); + +int vc_mgr_tidl_request_start(int pid, int recognition_mode, bool exclusive_command_option, bool start_by_client, int disabled_cmd_type); + +int vc_mgr_tidl_request_stop(int pid); + +int vc_mgr_tidl_request_cancel(int pid); + +int vc_mgr_tidl_send_result(int pid, int cmd_type, int result_id); + +int vc_mgr_tidl_send_result_selection(int pid); + +int vc_mgr_tidl_send_specific_engine_request(int pid, const char* engine_app_id, const char* event, const char* request); + +int vc_mgr_tidl_request_start_feedback(int pid); + +int vc_mgr_tidl_request_stop_feedback(int pid); + +int vc_mgr_tidl_send_utterance_status(int pid, int utt_id, vc_tts_utterance_status_e utt_status); + +int vc_mgr_tidl_send_audio_streaming(int pid, vc_audio_streaming_event_e event, unsigned char* buffer, unsigned int len); + +int vc_mgr_tidl_request_set_audio_streaming_mode(int pid, vc_audio_streaming_mode_e mode); + +#ifdef __cplusplus +} +#endif + +#endif /* __VC_TIDL_H_ */ diff --git a/common/vc_defs.h b/common/vc_defs.h index 4570918..0f906d6 100644 --- a/common/vc_defs.h +++ b/common/vc_defs.h @@ -19,6 +19,7 @@ #define __VC_DEFS_H__ #include +#include #ifdef __cplusplus extern "C" { @@ -26,7 +27,7 @@ extern "C" { /****************************************************************************************** -* Definitions for Dbus +* Definitions for IPC *******************************************************************************************/ #define VC_CLIENT_SERVICE_NAME "org.tizen.voice.vcclient" @@ -49,6 +50,8 @@ extern "C" { #define VC_SETTING_SERVICE_OBJECT_PATH "/org/tize/voice/vcsetting" #define VC_SETTING_SERVICE_INTERFACE "org.tizen.voice.vcsetting" +#define VC_SERVER_ENGINE_DEFAULT "org.tizen.vc-engine-default" + /****************************************************************************************** * Definitions for Vconf Keys *******************************************************************************************/ @@ -162,6 +165,26 @@ extern "C" { #define VC_MANAGER_METHOD_SEND_AUDIO_STREAMING "vc_manager_method_send_audio_streaming" #define VC_MANAGER_METHOD_CHANGE_SYSTEM_VOLUME "vc_manager_method_change_system_volume" +#define VC_MANAGER_BUNDLE_METHOD "vc_manager_bundle_method" +#define VC_MANAGER_BUNDLE_MESSAGE "vc_manager_bundle_message" +#define VC_MANAGER_BUNDLE_EVENT "vc_manager_bundle_event" +#define VC_MANAGER_BUNDLE_PRE_RESULT "vc_manager_bundle_pre_result" +#define VC_MANAGER_BUNDLE_ENGINE_APP_ID "vc_manager_bundle_engine_app_id" +#define VC_MANAGER_BUNDLE_RESULT "vc_manager_bundle_result" +#define VC_MANAGER_BUNDLE_DISP_TEXT "vc_manager_bundle_disp_text" +#define VC_MANAGER_BUNDLE_UTT_TEXT "vc_manager_bundle_utt_text" +#define VC_MANAGER_BUNDLE_CONTINUOUS "vc_manager_bundle_continuous" +#define VC_MANAGER_BUNDLE_REASON "vc_manager_bundle_reason" +#define VC_MANAGER_BUNDLE_DAEMON_PID "vc_manager_bundle_daemon_pid" +#define VC_MANAGER_BUNDLE_ERROR_MESSAGE "vc_manager_bundle_error_message" +#define VC_MANAGER_BUNDLE_KEY "vc_manager_bundle_key" +#define VC_MANAGER_BUNDLE_PRIVATE_DATA "vc_manager_bundle_private_data" +#define VC_MANAGER_BUNDLE_AUDIO_CHANNEL "vc_manager_bundle_audio_channel" +#define VC_MANAGER_BUNDLE_AUDIO_TYPE "vc_manager_bundle_audio_type" +#define VC_MANAGER_BUNDLE_AUDIO_RATE "vc_manager_bundle_audio_rate" +#define VC_MANAGER_BUNDLE_UTTID "vc_manager_bundle_uttid" +#define VC_MANAGER_BUNDLE_BUFFER "vc_manager_bundle_buffer" + #define VCD_MANAGER_METHOD_HELLO "vcd_manager_method_hello" #define VCD_MANAGER_METHOD_SPEECH_DETECTED "vcd_manager_method_speech_detected" #define VCD_MANAGER_METHOD_ALL_RESULT "vcd_manager_method_all_result" @@ -231,6 +254,7 @@ extern "C" { #define VC_NO_FOREGROUND_PID -1 #define VC_BASE_LANGUAGE "en_US" #define VC_RETRY_COUNT 5 +#define VC_RETRY_MIN_COUNT 2 #define VC_RUNTIME_INFO_NO_FOREGROUND -1 #define VC_CONNECTION_RETRY_COUNT 10 #define VC_INVALID_TTS_UID 0 diff --git a/packaging/voice-control.spec b/packaging/voice-control.spec index 9c5e914..d776104 100644 --- a/packaging/voice-control.spec +++ b/packaging/voice-control.spec @@ -36,6 +36,9 @@ BuildRequires: pkgconfig(pkgmgr-installer) BuildRequires: pkgconfig(vconf) BuildRequires: cmake BuildRequires: pkgconfig(gmock) +BuildRequires: tidl +BuildRequires: pkgconfig(rpc-port) +BuildRequires: pkgconfig(bundle) %if 0%{?gcov:1} BuildRequires: lcov @@ -111,6 +114,13 @@ GTest for Voice Control %setup -q -n %{name}-%{version} cp %{SOURCE1001} %{SOURCE1002} . +tidlc -p -l C -i tidl/vc_mgr.tidl -o vc_mgr_proxy +tidlc -s -l C -i tidl/vc_mgr.tidl -o vcd_mgr_stub +tidlc -s -l C -i tidl/vcd_mgr.tidl -o vc_mgr_stub +tidlc -p -l C -i tidl/vcd_mgr.tidl -o vcd_mgr_proxy + +mv vc_* client +mv vcd_* server %build %if 0%{?gcov:1} diff --git a/server/CMakeLists.txt b/server/CMakeLists.txt index b5e14ce..c557c71 100644 --- a/server/CMakeLists.txt +++ b/server/CMakeLists.txt @@ -11,6 +11,9 @@ SET(SRCS vcd_config.c vcd_dbus_server.c vcd_dbus.c + vcd_tidl.c + vcd_mgr_stub.c + vcd_mgr_proxy.c vcd_engine_agent.c # vcd_main.c vcd_recorder.c diff --git a/server/vcd_client_data.c b/server/vcd_client_data.c index 202c2e0..ddb298b 100644 --- a/server/vcd_client_data.c +++ b/server/vcd_client_data.c @@ -31,6 +31,9 @@ static GSList* g_widget_list = NULL; static manager_info_s g_manager; +/* Manager IPC info */ +static manager_tidl_info_s* g_mgr_tidl_info = NULL; + /* Command list */ static current_commands_list_s g_cur_cmd_list; @@ -253,6 +256,141 @@ char* vcd_client_manager_get_result_text() return g_result_text; } +int vcd_client_manger_create_tidl_info(int pid) +{ + /*Check already created*/ + if (NULL != g_mgr_tidl_info) { + SLOG(LOG_WARN, TAG_VCD, "[Client Data] Manager tidl info pid is already registered"); + if (pid != g_mgr_tidl_info->pid) { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Manager pid is different"); + return VCD_ERROR_OPERATION_FAILED; + } + return VCD_ERROR_NONE; + } + + SLOG(LOG_INFO, TAG_VCD, "[Client Data] There is no manager tidl info. Create new one."); + g_mgr_tidl_info = (manager_tidl_info_s*)calloc(1, sizeof(manager_tidl_info_s)); + if (NULL == g_mgr_tidl_info) { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to allocate memory"); + return VCD_ERROR_OUT_OF_MEMORY; + } + + g_mgr_tidl_info->pid = pid; + g_mgr_tidl_info->notify_cb = NULL; + g_mgr_tidl_info->notify_cb_user_data = NULL; + g_mgr_tidl_info->send_buffer_cb = NULL; + g_mgr_tidl_info->send_buffer_cb_user_data = NULL; + + g_mgr_tidl_info->connected = false; + g_mgr_tidl_info->connection_requesting = false; + g_mgr_tidl_info->rpc_h = NULL; + + SLOG(LOG_INFO, TAG_VCD, "[Client Data SUCCESS] Add new manager tidl info. pid(%d)", pid); + + return VCD_ERROR_NONE; +} + +int vcd_client_manager_set_tidl_notify_cb(rpc_port_stub_vc_mgr_notify_cb_h callback, void* user_data) +{ + if (NULL == g_mgr_tidl_info) { + SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] There is no manager tidl info"); + return VCD_ERROR_INVALID_PARAMETER; + } + + int ret = -1; + ret = rpc_port_stub_vc_mgr_notify_cb_clone(callback, &(g_mgr_tidl_info->notify_cb)); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] Fail to clone notify callback. ret(%d)", ret); + } else { + SLOG(LOG_INFO, TAG_VCD, "[Client Data] Succeed to clone notify callback. ret(%d)", ret); + } + g_mgr_tidl_info->notify_cb_user_data = user_data; + + return VCD_ERROR_NONE; +} + +int vcd_client_manager_unset_tidl_notify_cb() +{ + if (NULL == g_mgr_tidl_info) { + SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] There is no manager tidl info"); + return VCD_ERROR_INVALID_PARAMETER; + } + + int ret = -1; + ret = rpc_port_stub_vc_mgr_notify_cb_destroy(g_mgr_tidl_info->notify_cb); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] Fail to destroy notify callback. ret(%d)", ret); + } else { + SLOG(LOG_INFO, TAG_VCD, "[Client Data] Succeed to destroy notify callback. ret(%d)", ret); + } + g_mgr_tidl_info->notify_cb = NULL; + g_mgr_tidl_info->notify_cb_user_data = NULL; + + return VCD_ERROR_NONE; +} + +int vcd_client_manager_set_tidl_send_buffer_cb(rpc_port_stub_vc_mgr_send_buffer_cb_h callback, void* user_data) +{ + if (NULL == g_mgr_tidl_info) { + SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] There is no manager tidl info"); + return VCD_ERROR_INVALID_PARAMETER; + } + + int ret = -1; + ret = rpc_port_stub_vc_mgr_send_buffer_cb_clone(callback, &(g_mgr_tidl_info->send_buffer_cb)); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] Fail to clone feedback callback. ret(%d)", ret); + } else { + SLOG(LOG_INFO, TAG_VCD, "[Client Data] Succeed to clone feedback callback. ret(%d)", ret); + } + g_mgr_tidl_info->send_buffer_cb_user_data = user_data; + + return VCD_ERROR_NONE; +} + +int vcd_client_manager_unset_tidl_send_buffer_cb() +{ + if (NULL == g_mgr_tidl_info) { + SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] There is no manager tidl info"); + return VCD_ERROR_INVALID_PARAMETER; + } + + int ret = -1; + ret = rpc_port_stub_vc_mgr_send_buffer_cb_destroy(g_mgr_tidl_info->send_buffer_cb); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] Fail to destroy feedback callback. ret(%d)", ret); + } else { + SLOG(LOG_INFO, TAG_VCD, "[Client Data] Succeed to destroy feedback callback. ret(%d)", ret); + } + g_mgr_tidl_info->send_buffer_cb = NULL; + g_mgr_tidl_info->send_buffer_cb_user_data = NULL; + + return VCD_ERROR_NONE; +} + +int vcd_client_manager_delete_tidl_info() +{ + if (NULL == g_mgr_tidl_info) { + SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] There is no manager tidl info"); + return VCD_ERROR_INVALID_PARAMETER; + } + + if (0 != rpc_port_proxy_vcd_mgr_destroy(g_mgr_tidl_info->rpc_h)) { + SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to destroy tidl handle"); + } + + g_mgr_tidl_info->rpc_h = NULL; + free(g_mgr_tidl_info); + g_mgr_tidl_info = NULL; + + return 0; +} + +manager_tidl_info_s* vcd_client_manager_get_tidl_info() +{ + return g_mgr_tidl_info; +} + static void __vcd_client_release_each_commands(GSList** cmds) { GSList *iter = NULL; diff --git a/server/vcd_client_data.h b/server/vcd_client_data.h index 6060c81..260c984 100644 --- a/server/vcd_client_data.h +++ b/server/vcd_client_data.h @@ -21,6 +21,8 @@ #include #include "vc_command.h" #include "vc_info_parser.h" +#include "vcd_mgr_stub.h" +#include "vcd_mgr_proxy.h" #ifdef __cplusplus extern "C" { @@ -65,6 +67,20 @@ typedef struct { bool asr_result_enabled; } widget_info_s; +typedef struct { + int pid; + + rpc_port_stub_vc_mgr_notify_cb_h notify_cb; + void* notify_cb_user_data; + rpc_port_stub_vc_mgr_send_buffer_cb_h send_buffer_cb; + void* send_buffer_cb_user_data; + + bool connected; + bool connection_requesting; + + rpc_port_proxy_vcd_mgr_h rpc_h; +} manager_tidl_info_s; + typedef enum { VCD_RECOGNITION_MODE_STOP_BY_SILENCE, /**< Default mode */ VCD_RECOGNITION_MODE_RESTART_AFTER_REJECT, /**< Restart recognition after rejected result */ @@ -131,6 +147,20 @@ char* vcd_client_manager_get_result_text(); bool vcd_client_manager_is_system_command_valid(int pid); +int vcd_client_manger_create_tidl_info(int pid); + +int vcd_client_manager_set_tidl_notify_cb(rpc_port_stub_vc_mgr_notify_cb_h callback, void* user_data); + +int vcd_client_manager_unset_tidl_notify_cb(); + +int vcd_client_manager_set_tidl_send_buffer_cb(rpc_port_stub_vc_mgr_send_buffer_cb_h callback, void* user_data); + +int vcd_client_manager_unset_tidl_send_buffer_cb(); + +int vcd_client_manager_delete_tidl_info(); + +manager_tidl_info_s* vcd_client_manager_get_tidl_info(); + /* * client API */ diff --git a/server/vcd_dbus.c b/server/vcd_dbus.c index 9ac4f0c..b37e486 100755 --- a/server/vcd_dbus.c +++ b/server/vcd_dbus.c @@ -18,6 +18,7 @@ #include "vcd_client_data.h" #include "vcd_dbus.h" #include "vcd_dbus_server.h" +#include "vcd_tidl.h" #include "vcd_main.h" @@ -28,7 +29,7 @@ static Ecore_Fd_Handler* g_dbus_fd_handler = NULL; static int g_waiting_time = 3000; -static int g_volume_count = 0; +// static int g_volume_count = 0; static DBusMessage* __get_message(int pid, const char* method, vcd_client_type_e type) @@ -120,7 +121,8 @@ int vcdc_send_hello(int pid, vcd_client_type_e type) } else if (VCD_CLIENT_TYPE_WIDGET == type) { msg = __get_message(pid, VCD_WIDGET_METHOD_HELLO, VCD_CLIENT_TYPE_WIDGET); } else if (VCD_CLIENT_TYPE_MANAGER == type) { - msg = __get_message(pid, VCD_MANAGER_METHOD_HELLO, VCD_CLIENT_TYPE_MANAGER); + vcdc_tidl_send_hello(pid, type); + return VCD_ERROR_NONE; } else { SLOG(LOG_ERROR, TAG_VCD, "[Dbus ERROR] Client type is NOT valid"); return -1; @@ -228,48 +230,6 @@ int vcdc_send_show_tooltip(int pid, bool show) return 0; } -int vcdc_send_set_volume(int manger_pid, float volume) -{ - if (0 != __dbus_check()) { - return VCD_ERROR_OPERATION_FAILED; - } - - DBusMessage* msg = NULL; - - /* SLOG(LOG_DEBUG, TAG_VCD, "[Dbus] Set volume (%f)", volume); */ - - msg = dbus_message_new_signal( - VC_MANAGER_SERVICE_OBJECT_PATH, - VC_MANAGER_SERVICE_INTERFACE, - VCD_MANAGER_METHOD_SET_VOLUME); - - if (NULL == msg) { - SLOG(LOG_ERROR, TAG_VCD, "[Dbus ERROR] Message is NULL"); - return VCD_ERROR_OUT_OF_MEMORY; - } - - dbus_message_append_args(msg, DBUS_TYPE_INT32, &volume, DBUS_TYPE_INVALID); - - if (1 != dbus_connection_send(g_conn_sender, msg, NULL)) { - SLOG(LOG_ERROR, TAG_VCD, "[Dbus ERROR] Fail to Send"); - dbus_message_unref(msg); - return -1; - } else { - if (20 == g_volume_count) { - SLOG(LOG_INFO, TAG_VCD, "@@ Send set volume : pid(%d), volume(%f)", manger_pid, volume); - g_volume_count = 0; - } - - dbus_connection_flush(g_conn_sender); - - g_volume_count++; - } - - dbus_message_unref(msg); - - return 0; -} - int vcdc_send_result(int pid, int manager_pid, int cmd_type) { if (0 != __dbus_check()) { @@ -284,7 +244,9 @@ int vcdc_send_result(int pid, int manager_pid, int cmd_type) case VC_COMMAND_TYPE_FOREGROUND: case VC_COMMAND_TYPE_BACKGROUND: if (pid == manager_pid) { - msg = __get_message(pid, VCD_MANAGER_METHOD_RESULT, VCD_CLIENT_TYPE_MANAGER); + // msg = __get_message(pid, VCD_MANAGER_METHOD_RESULT, VCD_CLIENT_TYPE_MANAGER); + vcdc_tidl_send_result(pid, manager_pid, cmd_type); + return 0; } else { msg = __get_message(pid, VCD_METHOD_RESULT, VCD_CLIENT_TYPE_NORMAL); } @@ -295,8 +257,10 @@ int vcdc_send_result(int pid, int manager_pid, int cmd_type) case VC_COMMAND_TYPE_SYSTEM: case VC_COMMAND_TYPE_SYSTEM_BACKGROUND: case VC_COMMAND_TYPE_EXCLUSIVE: - msg = __get_message(pid, VCD_MANAGER_METHOD_RESULT, VCD_CLIENT_TYPE_MANAGER); - break; + // msg = __get_message(pid, VCD_MANAGER_METHOD_RESULT, VCD_CLIENT_TYPE_MANAGER); + // break; + vcdc_tidl_send_result(pid, manager_pid, cmd_type); + return 0; default: SLOG(LOG_ERROR, TAG_VCD, "[Dbus ERROR] Command type is NOT valid(%d)", cmd_type); @@ -384,241 +348,6 @@ int vcdc_send_asr_result(int pid, int event, const char* asr_result, int cmd_typ } } -int vcdc_send_pre_result_to_manager(int manager_pid, int event, const char* pre_result) -{ - if (0 != __dbus_check()) { - return VCD_ERROR_OPERATION_FAILED; - } - - DBusError err; - dbus_error_init(&err); - - DBusMessage* msg = NULL; - - msg = __get_message(manager_pid, VCD_MANAGER_METHOD_PRE_RESULT, VCD_CLIENT_TYPE_MANAGER); - - if (NULL == msg) { - SLOG(LOG_ERROR, TAG_VCD, "[Dbus ERROR] Message is NULL"); - return VCD_ERROR_OUT_OF_MEMORY; - } - - dbus_message_append_args(msg, DBUS_TYPE_INT32, &event, DBUS_TYPE_STRING, &pre_result, DBUS_TYPE_INVALID); - - dbus_message_set_no_reply(msg, TRUE); - - if (1 != dbus_connection_send(g_conn_sender, msg, NULL)) { - SLOG(LOG_ERROR, TAG_VCD, "[Dbus ERROR] Fail to Send"); - return VCD_ERROR_OPERATION_FAILED; - } else { - SLOG(LOG_INFO, TAG_VCD, "[Dbus] SUCCESS Send"); - dbus_connection_flush(g_conn_sender); - } - - return 0; -} - -int vcdc_send_specific_engine_result_to_manager(int manager_pid, const char* engine_app_id, const char* event, const char* result) -{ - SLOG(LOG_INFO, TAG_VCD, "[VCDC] send specific engine result to manager, mgr pid(%d), engine app id(%s), event(%s), result(%s),", - manager_pid, engine_app_id, event, result); - - if (0 != __dbus_check()) { - return VCD_ERROR_OPERATION_FAILED; - } - - DBusError err; - dbus_error_init(&err); - - DBusMessage* msg = NULL; - - msg = __get_message(manager_pid, VCD_MANAGER_METHOD_SPECIFIC_ENGINE_RESULT, VCD_CLIENT_TYPE_MANAGER); - - if (NULL == msg) { - SLOG(LOG_ERROR, TAG_VCD, "[Dbus ERROR] Message is NULL"); - return VCD_ERROR_OUT_OF_MEMORY; - } - - gchar *gEncodedResult = g_base64_encode((const guchar*)result, strlen(result)); - - dbus_message_append_args(msg, DBUS_TYPE_STRING, &engine_app_id, DBUS_TYPE_STRING, &event, DBUS_TYPE_STRING, &gEncodedResult, DBUS_TYPE_INVALID); - - dbus_message_set_no_reply(msg, TRUE); - - if (1 != dbus_connection_send(g_conn_sender, msg, NULL)) { - SLOG(LOG_ERROR, TAG_VCD, "[Dbus ERROR] Fail to Send"); - if (gEncodedResult) - g_free(gEncodedResult); - dbus_message_unref(msg); - return VCD_ERROR_OPERATION_FAILED; - } else { - SLOG(LOG_INFO, TAG_VCD, "[Dbus] SUCCESS Send"); - dbus_connection_flush(g_conn_sender); - } - - if (gEncodedResult) - g_free(gEncodedResult); - - dbus_message_unref(msg); - - return 0; -} - -int vcdc_send_result_to_manager(int manger_pid, int result_type) -{ - if (0 != __dbus_check()) { - return VCD_ERROR_OPERATION_FAILED; - } - - DBusError err; - dbus_error_init(&err); - - DBusMessage* msg = NULL; - - msg = __get_message(manger_pid, VCD_MANAGER_METHOD_ALL_RESULT, VCD_CLIENT_TYPE_MANAGER); - - if (NULL == msg) { - SLOG(LOG_ERROR, TAG_VCD, "[Dbus ERROR] Message is NULL"); - return VCD_ERROR_OUT_OF_MEMORY; - } - - SLOG(LOG_INFO, TAG_VCD, "[Dbus] send result : result type(%d)", result_type); - - dbus_message_append_args(msg, DBUS_TYPE_INT32, &result_type, DBUS_TYPE_INVALID); - - dbus_message_set_no_reply(msg, TRUE); - - if (1 != dbus_connection_send(g_conn_sender, msg, NULL)) { - SLOG(LOG_ERROR, TAG_VCD, "[Dbus ERROR] Fail to Send"); - return VCD_ERROR_OPERATION_FAILED; - } else { - SLOG(LOG_INFO, TAG_VCD, "[Dbus] SUCCESS Send"); - dbus_connection_flush(g_conn_sender); - } - - dbus_message_unref(msg); - - return 0; -} - -int vcdc_send_speech_detected(int manger_pid) -{ - if (0 != __dbus_check()) { - return VCD_ERROR_OPERATION_FAILED; - } - - DBusError err; - dbus_error_init(&err); - - /* Send to manager */ - DBusMessage* msg = NULL; - - msg = __get_message(manger_pid, VCD_MANAGER_METHOD_SPEECH_DETECTED, VCD_CLIENT_TYPE_MANAGER); - - if (NULL == msg) { - SLOG(LOG_ERROR, TAG_VCD, "[Dbus ERROR] Message is NULL"); - return VCD_ERROR_OUT_OF_MEMORY; - } - - dbus_message_set_no_reply(msg, TRUE); - - if (1 != dbus_connection_send(g_conn_sender, msg, NULL)) { - SLOG(LOG_ERROR, TAG_VCD, "[Dbus ERROR] Fail to Send"); - return VCD_ERROR_OPERATION_FAILED; - } else { - SLOG(LOG_INFO, TAG_VCD, "[Dbus] SUCCESS Send"); - dbus_connection_flush(g_conn_sender); - } - - dbus_message_unref(msg); - - return 0; -} - -int vcdc_send_service_state(vcd_state_e state) -{ - if (0 != __dbus_check()) { - return VCD_ERROR_OPERATION_FAILED; - } - - DBusError err; - dbus_error_init(&err); - - DBusMessage* msg = NULL; - - msg = __get_message(vcd_client_manager_get_pid(), VCD_MANAGER_METHOD_SET_SERVICE_STATE, VCD_CLIENT_TYPE_MANAGER); - - if (NULL == msg) { - SLOG(LOG_ERROR, TAG_VCD, "[Dbus ERROR] Message is NULL"); - return VCD_ERROR_OUT_OF_MEMORY; - } - - dbus_message_append_args(msg, DBUS_TYPE_INT32, &state, DBUS_TYPE_INVALID); - - dbus_message_set_no_reply(msg, TRUE); - - if (1 != dbus_connection_send(g_conn_sender, msg, NULL)) { - SLOG(LOG_ERROR, TAG_VCD, "[Dbus ERROR] Fail to Send"); - return VCD_ERROR_OPERATION_FAILED; - } else { - SLOG(LOG_INFO, TAG_VCD, "@@ Send service state message to manager : state(%d)", state); - dbus_connection_flush(g_conn_sender); - } - - dbus_message_unref(msg); - - /* Send to client */ - msg = NULL; - - msg = dbus_message_new_signal( - VC_CLIENT_SERVICE_OBJECT_PATH, - VC_CLIENT_SERVICE_INTERFACE, - VCD_METHOD_SET_SERVICE_STATE); - - if (NULL == msg) { - SLOG(LOG_ERROR, TAG_VCD, "[Dbus ERROR] Message is NULL"); - return VCD_ERROR_OUT_OF_MEMORY; - } - - dbus_message_append_args(msg, DBUS_TYPE_INT32, &state, DBUS_TYPE_INVALID); - - if (1 != dbus_connection_send(g_conn_sender, msg, NULL)) { - SLOG(LOG_ERROR, TAG_VCD, "[Dbus ERROR] Fail to Send"); - return VCD_ERROR_OPERATION_FAILED; - } else { - SLOG(LOG_INFO, TAG_VCD, "@@ Send service state message to client : state(%d)", state); - dbus_connection_flush(g_conn_sender); - } - - dbus_message_unref(msg); - - msg = NULL; - - /* Send to widget client */ - msg = dbus_message_new_signal( - VC_WIDGET_SERVICE_OBJECT_PATH, - VC_WIDGET_SERVICE_INTERFACE, - VCD_WIDGET_METHOD_SET_SERVICE_STATE); - - if (NULL == msg) { - SLOG(LOG_ERROR, TAG_VCD, "[Dbus ERROR] Message is NULL"); - return VCD_ERROR_OUT_OF_MEMORY; - } - - dbus_message_append_args(msg, DBUS_TYPE_INT32, &state, DBUS_TYPE_INVALID); - - if (1 != dbus_connection_send(g_conn_sender, msg, NULL)) { - SLOG(LOG_ERROR, TAG_VCD, "[Dbus ERROR] Fail to Send"); - return VCD_ERROR_OPERATION_FAILED; - } else { - SLOG(LOG_INFO, TAG_VCD, "@@ Send service state message to widget client : state(%d)", state); - dbus_connection_flush(g_conn_sender); - } - - dbus_message_unref(msg); - - return 0; -} - int vcdc_send_manager_pid(int manager_pid) { DBusError err; @@ -652,71 +381,6 @@ int vcdc_send_manager_pid(int manager_pid) return 0; } -int vcdc_send_dialog(int manger_pid, int pid, const char* disp_text, const char* utt_text, int continuous) -{ - if (0 != __dbus_check()) { - return VCD_ERROR_OPERATION_FAILED; - } - - DBusError err; - dbus_error_init(&err); - - DBusMessage* msg = NULL; - - msg = __get_message(manger_pid, VCD_MANAGER_METHOD_DIALOG, VCD_CLIENT_TYPE_MANAGER); - - if (NULL == msg) { - SLOG(LOG_ERROR, TAG_VCD, "[Dbus ERROR] Message is NULL"); - return VCD_ERROR_OUT_OF_MEMORY; - } - - SLOG(LOG_INFO, TAG_VCD, "[Dbus] send dialog : pid(%d), disp_text(%s), utt_text(%s), continue(%d)", pid, disp_text, utt_text, continuous); - - char* disp_null = NULL; - char* utt_null = NULL; - int ret = VCD_ERROR_NONE; - if (NULL == disp_text) { - disp_null = strdup("NNUULLLL"); - disp_text = disp_null; - } - - if (NULL == utt_text) { - utt_null = strdup("NNUULLLL"); - utt_text = utt_null; - } - - dbus_message_append_args(msg, - DBUS_TYPE_INT32, &pid, - DBUS_TYPE_STRING, &disp_text, - DBUS_TYPE_STRING, &utt_text, - DBUS_TYPE_INT32, &continuous, - DBUS_TYPE_INVALID); - - dbus_message_set_no_reply(msg, TRUE); - - if (1 != dbus_connection_send(g_conn_sender, msg, NULL)) { - SLOG(LOG_ERROR, TAG_VCD, "[Dbus ERROR] Fail to Send"); - ret = VCD_ERROR_OPERATION_FAILED; - } else { - SLOG(LOG_INFO, TAG_VCD, "[Dbus] SUCCESS Send"); - dbus_connection_flush(g_conn_sender); - } - - dbus_message_unref(msg); - - if (NULL != disp_null) { - free(disp_null); - disp_null = NULL; - } - - if (NULL != utt_null) { - free(utt_null); - utt_null = NULL; - } - - return ret; -} - int vcdc_send_error_signal_to_manager(int manager_pid, int reason, char *err_msg) { SLOG(LOG_ERROR, TAG_VCD, "@@ Send error signal to manager"); @@ -792,30 +456,32 @@ int vcdc_send_error_signal(int reason, char *err_msg) DBusMessage* msg = NULL; - msg = dbus_message_new_signal( - VC_MANAGER_SERVICE_OBJECT_PATH, - VC_MANAGER_SERVICE_INTERFACE, - VCD_MANAGER_METHOD_ERROR); + // msg = dbus_message_new_signal( + // VC_MANAGER_SERVICE_OBJECT_PATH, + // VC_MANAGER_SERVICE_INTERFACE, + // VCD_MANAGER_METHOD_ERROR); - if (NULL == msg) { - SLOG(LOG_ERROR, TAG_VCD, "[Dbus ERROR] Message is NULL"); - return VCD_ERROR_OUT_OF_MEMORY; - } + // if (NULL == msg) { + // SLOG(LOG_ERROR, TAG_VCD, "[Dbus ERROR] Message is NULL"); + // return VCD_ERROR_OUT_OF_MEMORY; + // } - daemon_pid = getpid(); - dbus_message_append_args(msg, DBUS_TYPE_INT32, &reason, DBUS_TYPE_INT32, &daemon_pid, DBUS_TYPE_STRING, &err_msg, DBUS_TYPE_INVALID); + // daemon_pid = getpid(); + // dbus_message_append_args(msg, DBUS_TYPE_INT32, &reason, DBUS_TYPE_INT32, &daemon_pid, DBUS_TYPE_STRING, &err_msg, DBUS_TYPE_INVALID); - if (1 != dbus_connection_send(g_conn_sender, msg, NULL)) { - SLOG(LOG_ERROR, TAG_VCD, "[Dbus ERROR] Fail to Send"); - return VCD_ERROR_OPERATION_FAILED; - } else { - SLOG(LOG_INFO, TAG_VCD, "@@ Send error signal to manager: reason(%d), daemon_pid(%d), Error Msg(%s)", reason, daemon_pid, err_msg); - dbus_connection_flush(g_conn_sender); - } + // if (1 != dbus_connection_send(g_conn_sender, msg, NULL)) { + // SLOG(LOG_ERROR, TAG_VCD, "[Dbus ERROR] Fail to Send"); + // return VCD_ERROR_OPERATION_FAILED; + // } else { + // SLOG(LOG_INFO, TAG_VCD, "@@ Send error signal to manager: reason(%d), daemon_pid(%d), Error Msg(%s)", reason, daemon_pid, err_msg); + // dbus_connection_flush(g_conn_sender); + // } - dbus_message_unref(msg); + // dbus_message_unref(msg); - msg = NULL; + // msg = NULL; + + vcdc_tidl_send_error(reason, err_msg); msg = dbus_message_new_signal( VC_CLIENT_SERVICE_OBJECT_PATH, VC_CLIENT_SERVICE_INTERFACE, @@ -904,188 +570,6 @@ int vcdc_send_error_signal_to_app(int pid, int reason, char *err_msg) return VCD_ERROR_NONE; } -int vcdc_send_request_set_private_data(int pid, const char* key, const char* data) -{ - if (0 != __dbus_check()) { - return VCD_ERROR_OPERATION_FAILED; - } - - DBusMessage* msg = NULL; - msg = __get_message(pid, VCD_MANAGER_METHOD_SET_PRIVATE_DATA, VCD_CLIENT_TYPE_MANAGER); - if (NULL == msg) { - SLOG(LOG_ERROR, TAG_VCD, "[Dbus ERROR] Fail to create message"); - return VCD_ERROR_OUT_OF_MEMORY; - } - - dbus_message_append_args(msg, - DBUS_TYPE_INT32, &pid, - DBUS_TYPE_STRING, &key, - DBUS_TYPE_STRING, &data, - DBUS_TYPE_INVALID); - - dbus_message_set_no_reply(msg, TRUE); - - if (1 != dbus_connection_send(g_conn_sender, msg, NULL)) { - SLOG(LOG_ERROR, TAG_VCD, "[Dbus ERROR] Fail to Send request set private data"); - dbus_message_unref(msg); - return VCD_ERROR_OPERATION_FAILED; - } else { - SLOG(LOG_INFO, TAG_VCD, "[Dbus] SUCCESS Send request set private data"); - dbus_connection_flush(g_conn_sender); - } - - dbus_message_unref(msg); - - return VCD_ERROR_NONE; -} - -int vcdc_send_request_get_private_data(int pid, const char* key, char** data) -{ - if (0 != __dbus_check()) { - return VCD_ERROR_OPERATION_FAILED; - } - - DBusMessage* msg = NULL; - msg = __get_message(pid, VCD_MANAGER_METHOD_GET_PRIVATE_DATA, VCD_CLIENT_TYPE_MANAGER); - if (NULL == msg) { - SLOG(LOG_ERROR, TAG_VCD, "[Dbus ERROR] Fail to create message"); - return VCD_ERROR_OUT_OF_MEMORY; - } - - dbus_message_append_args(msg, - DBUS_TYPE_INT32, &pid, - DBUS_TYPE_STRING, &key, - DBUS_TYPE_INVALID); - - DBusError err; - dbus_error_init(&err); - - DBusMessage* result_msg; - int result = -1; - char* temp = NULL; - - result_msg = dbus_connection_send_with_reply_and_block(g_conn_sender, msg, g_waiting_time, &err); - dbus_message_unref(msg); - - if (dbus_error_is_set(&err)) { - SLOG(LOG_ERROR, TAG_VCD, "[Dbus ERROR] %s", err.message); - if (NULL != err.name) { - if (!strcmp(err.name, DBUS_ERROR_SERVICE_UNKNOWN)) { - SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Unknown service. Client is not available"); - dbus_error_free(&err); - return VCD_ERROR_NONE; - } - } - dbus_error_free(&err); - } - - if (NULL != result_msg) { - dbus_message_get_args(result_msg, &err, DBUS_TYPE_INT32, &result, DBUS_TYPE_STRING, &temp, DBUS_TYPE_INVALID); - - if (dbus_error_is_set(&err)) { - SLOG(LOG_ERROR, TAG_VCD, "[Dbus] Get arguments error (%s)", err.message); - dbus_error_free(&err); - result = VCD_ERROR_OPERATION_FAILED; - } - - dbus_message_unref(result_msg); - } else { - SLOG(LOG_INFO, TAG_VCD, "[Dbus] Result message is NULL. Client is not available"); - } - - if (NULL != data && NULL != temp) { - *data = strdup(temp); - } - - return result; -} - -int vcdc_send_feedback_audio_format_to_manager(int manager_pid, int rate, vc_audio_channel_e channel, vce_audio_type_e audio_type) -{ - SLOG(LOG_INFO, TAG_VCD, "[Dbus] Send TTS feedback audio format : manager_pid(%d), rate(%d), audio channel(%d), audio type(%d)", manager_pid, rate, channel, audio_type); - - if (0 != __dbus_check()) { - return VCD_ERROR_OPERATION_FAILED; - } - - DBusError err; - dbus_error_init(&err); - - /* make dbus message */ - DBusMessage* msg = NULL; - msg = __get_message(manager_pid, VCD_MANAGER_METHOD_FEEDBACK_AUDIO_FORMAT, VCD_CLIENT_TYPE_MANAGER); - if (NULL == msg) { - SLOG(LOG_ERROR, TAG_VCD, "[Dbus ERROR] Message is NULL"); - return VCD_ERROR_OUT_OF_MEMORY; - } - - dbus_message_append_args(msg, - DBUS_TYPE_INT32, &rate, - DBUS_TYPE_INT32, &channel, - DBUS_TYPE_INT32, &audio_type, - DBUS_TYPE_INVALID); - - dbus_message_set_no_reply(msg, TRUE); - - int ret = VCD_ERROR_NONE; - - if (1 != dbus_connection_send(g_conn_sender, msg, NULL)) { - SLOG(LOG_ERROR, TAG_VCD, "[Dbus ERROR] Fail to Send"); - ret = VCD_ERROR_OPERATION_FAILED; - } else { - SLOG(LOG_INFO, TAG_VCD, "[Dbus] SUCCESS Send"); - dbus_connection_flush(g_conn_sender); - } - - dbus_message_unref(msg); - - return ret; -} - -int vcdc_send_feedback_streaming_to_manager(int manager_pid, int pid, int utt_id, vc_feedback_event_e event, char* buffer, int len) -{ - SLOG(LOG_INFO, TAG_VCD, "[Dbus] Send TTS feedback streaming : manager_pid(%d), pid(%d), utt_id(%d) feedback event(%d), buffer(%p), length(%d)", manager_pid, pid, utt_id, event, buffer, len); - - if (0 != __dbus_check()) { - return VCD_ERROR_OPERATION_FAILED; - } - - DBusError err; - dbus_error_init(&err); - - /* make dbus message */ - DBusMessage* msg = NULL; - msg = __get_message(manager_pid, VCD_MANAGER_METHOD_FEEDBACK_STREAMING, VCD_CLIENT_TYPE_MANAGER); - if (NULL == msg) { - SLOG(LOG_ERROR, TAG_VCD, "[Dbus ERROR] Message is NULL"); - return VCD_ERROR_OUT_OF_MEMORY; - } - - dbus_message_append_args(msg, - DBUS_TYPE_INT32, &pid, - DBUS_TYPE_INT32, &utt_id, - DBUS_TYPE_INT32, &event, - DBUS_TYPE_ARRAY, DBUS_TYPE_BYTE, - &buffer, len, - DBUS_TYPE_INVALID); - - dbus_message_set_no_reply(msg, TRUE); - - int ret = VCD_ERROR_NONE; - - if (1 != dbus_connection_send(g_conn_sender, msg, NULL)) { - SLOG(LOG_ERROR, TAG_VCD, "[Dbus ERROR] Fail to Send"); - ret = VCD_ERROR_OPERATION_FAILED; - } else { - SLOG(LOG_INFO, TAG_VCD, "[Dbus] SUCCESS Send"); - dbus_connection_flush(g_conn_sender); - } - - dbus_message_unref(msg); - - return ret; -} - int vcdc_send_feedback_streaming(int pid, int utt_id, vc_feedback_event_e event, char* buffer, int len) { SLOG(LOG_INFO, TAG_VCD, "[Dbus] Send TTS feedback streaming : pid(%d), utt_id(%d), feedback event(%d), buffer(%p), length(%d)", pid, utt_id, event, buffer, len); @@ -1149,73 +633,6 @@ static Eina_Bool listener_event_callback(void* data, Ecore_Fd_Handler *fd_handle if (dbus_message_is_method_call(msg, VC_SERVER_SERVICE_INTERFACE, VC_METHOD_HELLO)) vcd_dbus_server_hello(g_conn_listener, msg); - /* manager event */ - else if (dbus_message_is_method_call(msg, VC_SERVER_SERVICE_INTERFACE, VC_MANAGER_METHOD_INITIALIZE)) - vcd_dbus_server_mgr_initialize(g_conn_listener, msg); - - else if (dbus_message_is_method_call(msg, VC_SERVER_SERVICE_INTERFACE, VC_MANAGER_METHOD_FINALIZE)) - vcd_dbus_server_mgr_finalize(g_conn_listener, msg); - - else if (dbus_message_is_method_call(msg, VC_SERVER_SERVICE_INTERFACE, VC_MANAGER_METHOD_SET_COMMAND)) - vcd_dbus_server_mgr_set_command(g_conn_listener, msg); - - else if (dbus_message_is_method_call(msg, VC_SERVER_SERVICE_INTERFACE, VC_MANAGER_METHOD_UNSET_COMMAND)) - vcd_dbus_server_mgr_unset_command(g_conn_listener, msg); - - else if (dbus_message_is_method_call(msg, VC_SERVER_SERVICE_INTERFACE, VC_MANAGER_METHOD_SET_DEMANDABLE)) - vcd_dbus_server_mgr_set_demandable_client(g_conn_listener, msg); - - else if (dbus_message_is_method_call(msg, VC_SERVER_SERVICE_INTERFACE, VC_MANAGER_METHOD_SET_AUDIO_TYPE)) - vcd_dbus_server_mgr_set_audio_type(g_conn_listener, msg); - - else if (dbus_message_is_method_call(msg, VC_SERVER_SERVICE_INTERFACE, VC_MANAGER_METHOD_GET_AUDIO_TYPE)) - vcd_dbus_server_mgr_get_audio_type(g_conn_listener, msg); - - else if (dbus_message_is_method_call(msg, VC_SERVER_SERVICE_INTERFACE, VC_MANAGER_METHOD_SET_CLIENT_INFO)) - vcd_dbus_server_mgr_set_client_info(g_conn_listener, msg); - - else if (dbus_message_is_method_call(msg, VC_SERVER_SERVICE_INTERFACE, VC_MANAGER_METHOD_SET_PRIVATE_DATA)) - vcd_dbus_server_mgr_set_private_data(g_conn_listener, msg); - - else if (dbus_message_is_method_call(msg, VC_SERVER_SERVICE_INTERFACE, VC_MANAGER_METHOD_GET_PRIVATE_DATA)) - vcd_dbus_server_mgr_get_private_data(g_conn_listener, msg); - - else if (dbus_message_is_method_call(msg, VC_SERVER_SERVICE_INTERFACE, VC_MANAGER_METHOD_START)) - vcd_dbus_server_mgr_start(g_conn_listener, msg); - - else if (dbus_message_is_method_call(msg, VC_SERVER_SERVICE_INTERFACE, VC_MANAGER_METHOD_STOP)) - vcd_dbus_server_mgr_stop(g_conn_listener, msg); - - else if (dbus_message_is_method_call(msg, VC_SERVER_SERVICE_INTERFACE, VC_MANAGER_METHOD_CANCEL)) - vcd_dbus_server_mgr_cancel(g_conn_listener, msg); - - else if (dbus_message_is_method_call(msg, VC_SERVER_SERVICE_INTERFACE, VC_MANAGER_METHOD_RESULT_SELECTION)) - vcd_dbus_server_mgr_result_selection(g_conn_listener, msg); - - else if (dbus_message_is_method_call(msg, VC_SERVER_SERVICE_INTERFACE, VC_MANAGER_METHOD_SET_DOMAIN)) - vcd_dbus_server_mgr_set_domain(g_conn_listener, msg); - - else if (dbus_message_is_method_call(msg, VC_SERVER_SERVICE_INTERFACE, VC_MANAGER_METHOD_DO_ACTION)) - vcd_dbus_server_mgr_do_action(g_conn_listener, msg); - - else if (dbus_message_is_method_call(msg, VC_SERVER_SERVICE_INTERFACE, VC_MANAGER_METHOD_SPECIFIC_ENGINE_REQUEST)) - vcd_dbus_server_mgr_send_specific_engine_request(g_conn_listener, msg); - - else if (dbus_message_is_method_call(msg, VC_SERVER_SERVICE_INTERFACE, VC_MANAGER_METHOD_START_FEEDBACK)) - vcd_dbus_server_mgr_start_feedback(g_conn_listener, msg); - - else if (dbus_message_is_method_call(msg, VC_SERVER_SERVICE_INTERFACE, VC_MANAGER_METHOD_STOP_FEEDBACK)) - vcd_dbus_server_mgr_stop_feedback(g_conn_listener, msg); - - else if (dbus_message_is_method_call(msg, VC_SERVER_SERVICE_INTERFACE, VC_MANAGER_METHOD_SEND_AUDIO_STREAMING)) - vcd_dbus_server_mgr_send_audio_streaming(g_conn_listener, msg); - - else if (dbus_message_is_method_call(msg, VC_SERVER_SERVICE_INTERFACE, VC_MANAGER_METHOD_CHANGE_SYSTEM_VOLUME)) - vcd_dbus_server_mgr_change_system_volume(g_conn_listener, msg); - - else if (dbus_message_is_method_call(msg, VC_SERVER_SERVICE_INTERFACE, VC_MANAGER_METHOD_SET_AUDIO_STREAMING_MODE)) - vcd_dbus_server_mgr_set_audio_streaming_mode(g_conn_listener, msg); - /* client event */ else if (dbus_message_is_method_call(msg, VC_SERVER_SERVICE_INTERFACE, VC_METHOD_INITIALIZE)) vcd_dbus_server_initialize(g_conn_listener, msg); diff --git a/server/vcd_dbus.h b/server/vcd_dbus.h index 5fd1b7b..7f07726 100644 --- a/server/vcd_dbus.h +++ b/server/vcd_dbus.h @@ -24,12 +24,6 @@ extern "C" { #endif -typedef enum { - VCD_CLIENT_TYPE_NORMAL, - VCD_CLIENT_TYPE_WIDGET, - VCD_CLIENT_TYPE_MANAGER -} vcd_client_type_e; - int vcd_dbus_open_connection(); int vcd_dbus_close_connection(); @@ -40,43 +34,22 @@ int vcdc_send_hello(int pid, vcd_client_type_e type); int vcdc_send_show_tooltip(int pid, bool show); -int vcdc_send_set_volume(int manger_pid, float volume); - int vcdc_send_result(int pid, int manager_pid, int cmd_type); int vcdc_send_asr_result(int pid, int event, const char* asr_result, int cmd_type, bool* is_consumed); -int vcdc_send_pre_result_to_manager(int manager_pid, int event, const char* pre_result); - -int vcdc_send_specific_engine_result_to_manager(int manager_pid, const char* engine_app_id, const char* event, const char* result); - -int vcdc_send_result_to_manager(int manger_pid, int result_type); - -int vcdc_send_speech_detected(int manger_pid); - int vcdc_send_error_signal(int reason, char *err_msg); -int vcdc_send_error_signal_to_manager(int manager_pid, int reason, char *err_msg); - int vcdc_send_error_signal_to_app(int pid, int reason, char *err_msg); -int vcdc_send_service_state(vcd_state_e state); - -int vcdc_send_dialog(int manger_pid, int pid, const char* disp_text, const char* utt_text, int continuous); - int vcdc_send_manager_pid(int manager_pid); -int vcdc_send_request_set_private_data(int pid, const char* key, const char* data); - -int vcdc_send_request_get_private_data(int pid, const char* key, char** data); +// int vcdc_send_request_get_private_data(int pid, const char* key, char** data); /* for TTS feedback */ -int vcdc_send_feedback_audio_format_to_manager(int manager_pid, int rate, vc_audio_channel_e channel, vce_audio_type_e audio_type); - -int vcdc_send_feedback_streaming_to_manager(int manager_pid, int pid, int utt_id, vc_feedback_event_e event, char* buffer, int len); - int vcdc_send_feedback_streaming(int pid, int utt_id, vc_feedback_event_e event, char* buffer, int len); +// int vcdc_send_feedback_streaming_to_manager(int manager_pid, int pid, int utt_id, vc_feedback_event_e event, char* buffer, int len); #ifdef __cplusplus } diff --git a/server/vcd_dbus_server.c b/server/vcd_dbus_server.c index d30dd2b..d5d4ac1 100755 --- a/server/vcd_dbus_server.c +++ b/server/vcd_dbus_server.c @@ -17,6 +17,7 @@ #include "vcd_client_data.h" #include "vcd_dbus.h" +#include "vcd_tidl.h" #include "vcd_dbus_server.h" #include "vcd_main.h" #include "vcd_server.h" @@ -85,853 +86,6 @@ int vcd_dbus_server_hello(DBusConnection* conn, DBusMessage* msg) return 0; } -/* -* Dbus Server functions for manager -*/ - -int vcd_dbus_server_mgr_initialize(DBusConnection* conn, DBusMessage* msg) -{ - DBusError err; - dbus_error_init(&err); - - int pid; - int streaming_mode; - int service_state; - int foreground; - int daemon_pid; - int ret = VCD_ERROR_OPERATION_FAILED; - - dbus_message_get_args(msg, &err, - DBUS_TYPE_INT32, &pid, - DBUS_TYPE_INT32, &streaming_mode, - DBUS_TYPE_INVALID); - - SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Manager Initialize"); - - if (dbus_error_is_set(&err)) { - SLOG(LOG_ERROR, TAG_VCD, "[IN ERROR] vcd mgr initialize : get arguments error (%s)", err.message); - dbus_error_free(&err); - ret = VCD_ERROR_OPERATION_FAILED; - } else { - vcd_config_set_audio_streaming_mode((vcd_audio_streaming_mode_e)streaming_mode); - ret = vcd_server_mgr_initialize(pid, streaming_mode); - service_state = vcd_server_get_service_state(); - foreground = vcd_server_get_foreground(); - daemon_pid = getpid(); - - 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); - } - - DBusMessage* reply; - reply = dbus_message_new_method_return(msg); - - if (NULL != reply) { - dbus_message_append_args(reply, - DBUS_TYPE_INT32, &ret, - DBUS_TYPE_INT32, &service_state, - DBUS_TYPE_INT32, &foreground, - DBUS_TYPE_INT32, &daemon_pid, - DBUS_TYPE_INVALID); - - if (0 == ret) { - SLOG(LOG_INFO, TAG_VCD, "[OUT SUCCESS] Result(%d)", ret); - } else { - SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret); - } - - if (!dbus_connection_send(conn, reply, NULL)) { - SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Out Of Memory!"); - } - - dbus_connection_flush(conn); - dbus_message_unref(reply); - } else { - SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Fail to create reply message!!"); - } - - SLOG(LOG_DEBUG, TAG_VCD, "@@@"); - - return 0; -} - -int vcd_dbus_server_mgr_finalize(DBusConnection* conn, DBusMessage* msg) -{ - DBusError err; - dbus_error_init(&err); - - int pid; - int ret = VCD_ERROR_OPERATION_FAILED; - dbus_message_get_args(msg, &err, DBUS_TYPE_INT32, &pid, DBUS_TYPE_INVALID); - - SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Manager Finalize"); - - if (dbus_error_is_set(&err)) { - SLOG(LOG_ERROR, TAG_VCD, "[IN ERROR] vcd mgr finalize : get arguments error (%s)", err.message); - dbus_error_free(&err); - ret = VCD_ERROR_OPERATION_FAILED; - } else { - SLOG(LOG_INFO, TAG_VCD, "[IN] vcd mgr finalize : pid(%d)", pid); - ret = vcd_server_mgr_finalize(pid); - } - - DBusMessage* reply; - - reply = dbus_message_new_method_return(msg); - - if (NULL != reply) { - dbus_message_append_args(reply, DBUS_TYPE_INT32, &ret, DBUS_TYPE_INVALID); - - if (0 == ret) { - SLOG(LOG_INFO, TAG_VCD, "[OUT SUCCESS] Result(%d)", ret); - } else { - SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret); - } - - if (!dbus_connection_send(conn, reply, NULL)) { - SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Out Of Memory!"); - } - - dbus_connection_flush(conn); - dbus_message_unref(reply); - } else { - SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Fail to create reply message!!"); - } - - SLOG(LOG_DEBUG, TAG_VCD, "@@@"); - - return 0; -} - -int vcd_dbus_server_mgr_set_command(DBusConnection* conn, DBusMessage* msg) -{ - DBusError err; - dbus_error_init(&err); - - int pid; - int ret = VCD_ERROR_OPERATION_FAILED; - - dbus_message_get_args(msg, &err, DBUS_TYPE_INT32, &pid, DBUS_TYPE_INVALID); - - SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Manager Set command"); - - if (dbus_error_is_set(&err)) { - SLOG(LOG_ERROR, TAG_VCD, "[IN ERROR] vcd mgr set command : get arguments error (%s)", err.message); - dbus_error_free(&err); - ret = VCD_ERROR_OPERATION_FAILED; - } else { - SLOG(LOG_INFO, TAG_VCD, "[IN] vcd mgr set command : pid(%d)", pid); - ret = vcd_server_mgr_set_command(pid); - } - - DBusMessage* reply; - reply = dbus_message_new_method_return(msg); - - if (NULL != reply) { - if (0 == ret) { - /* Append result and language */ - dbus_message_append_args(reply, DBUS_TYPE_INT32, &ret, DBUS_TYPE_INVALID); - - SLOG(LOG_INFO, TAG_VCD, "[OUT SUCCESS] Result(%d)", ret); - } else { - dbus_message_append_args(reply, DBUS_TYPE_INT32, &ret, DBUS_TYPE_INVALID); - - SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret); - } - - if (!dbus_connection_send(conn, reply, NULL)) { - SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Out Of Memory!"); - } - - dbus_connection_flush(conn); - dbus_message_unref(reply); - } else { - SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Fail to create reply message!!"); - } - - SLOG(LOG_DEBUG, TAG_VCD, "@@@"); - - return 0; -} - -int vcd_dbus_server_mgr_unset_command(DBusConnection* conn, DBusMessage* msg) -{ - DBusError err; - dbus_error_init(&err); - - int pid; - int ret = VCD_ERROR_OPERATION_FAILED; - - dbus_message_get_args(msg, &err, DBUS_TYPE_INT32, &pid, DBUS_TYPE_INVALID); - - SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD manager unset command"); - - if (dbus_error_is_set(&err)) { - SLOG(LOG_ERROR, TAG_VCD, "[IN ERROR] vcd mgr unset command : get arguments error (%s)", err.message); - dbus_error_free(&err); - ret = VCD_ERROR_OPERATION_FAILED; - } else { - SLOG(LOG_INFO, TAG_VCD, "[IN] vcd mgr unset command : pid(%d)", pid); - ret = vcd_server_mgr_unset_command(pid); - } - - DBusMessage* reply; - reply = dbus_message_new_method_return(msg); - - if (NULL != reply) { - if (0 == ret) { - /* Append result and language */ - dbus_message_append_args(reply, DBUS_TYPE_INT32, &ret, DBUS_TYPE_INVALID); - - SLOG(LOG_INFO, TAG_VCD, "[OUT SUCCESS] Result(%d)", ret); - } else { - dbus_message_append_args(reply, DBUS_TYPE_INT32, &ret, DBUS_TYPE_INVALID); - - SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret); - } - - if (!dbus_connection_send(conn, reply, NULL)) { - SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Out Of Memory!"); - } - - dbus_connection_flush(conn); - dbus_message_unref(reply); - } else { - SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Fail to create reply message!!"); - } - - SLOG(LOG_DEBUG, TAG_VCD, "@@@"); - - return 0; -} - -int vcd_dbus_server_mgr_set_demandable_client(DBusConnection* conn, DBusMessage* msg) -{ - DBusError err; - dbus_error_init(&err); - - int pid; - int ret = VCD_ERROR_OPERATION_FAILED; - - dbus_message_get_args(msg, &err, DBUS_TYPE_INT32, &pid, DBUS_TYPE_INVALID); - - SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Manager Set demandable client"); - - if (dbus_error_is_set(&err)) { - SLOG(LOG_ERROR, TAG_VCD, "[IN ERROR] vcd mgr set demandable client : get arguments error (%s)", err.message); - dbus_error_free(&err); - ret = VCD_ERROR_OPERATION_FAILED; - } else { - SLOG(LOG_INFO, TAG_VCD, "[IN] vcd mgr set demandable client : pid(%d)", pid); - ret = vcd_server_mgr_set_demandable_client(pid); - } - - DBusMessage* reply; - reply = dbus_message_new_method_return(msg); - - if (NULL != reply) { - if (0 == ret) { - /* Append result and language */ - dbus_message_append_args(reply, DBUS_TYPE_INT32, &ret, DBUS_TYPE_INVALID); - - SLOG(LOG_INFO, TAG_VCD, "[OUT SUCCESS] Result(%d)", ret); - } else { - dbus_message_append_args(reply, DBUS_TYPE_INT32, &ret, DBUS_TYPE_INVALID); - - SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret); - } - - if (!dbus_connection_send(conn, reply, NULL)) { - SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Out Of Memory!"); - } - - dbus_connection_flush(conn); - dbus_message_unref(reply); - } else { - SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Fail to create reply message!!"); - } - - SLOG(LOG_DEBUG, TAG_VCD, "@@@"); - - return 0; -} - -int vcd_dbus_server_mgr_set_audio_type(DBusConnection* conn, DBusMessage* msg) -{ - DBusError err; - dbus_error_init(&err); - - int pid = 0; - char* audio_type = NULL; - - int ret = VCD_ERROR_OPERATION_FAILED; - - SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Manager set audio type"); - - dbus_message_get_args(msg, &err, - DBUS_TYPE_INT32, &pid, - DBUS_TYPE_STRING, &audio_type, - DBUS_TYPE_INVALID); - - if (dbus_error_is_set(&err)) { - SLOG(LOG_ERROR, TAG_VCD, "[IN ERROR] vcd mgr set audio type : get arguments error (%s)", err.message); - dbus_error_free(&err); - ret = VCD_ERROR_OPERATION_FAILED; - } else { - SLOG(LOG_INFO, TAG_VCD, "[IN] vcd mgr set audio type : pid(%d), audio type(%s)", pid, audio_type); - ret = vcd_server_mgr_set_audio_type(pid, audio_type); - } - - DBusMessage* reply; - reply = dbus_message_new_method_return(msg); - - if (NULL != reply) { - dbus_message_append_args(reply, DBUS_TYPE_INT32, &ret, DBUS_TYPE_INVALID); - - if (0 == ret) { - SLOG(LOG_INFO, TAG_VCD, "[OUT SUCCESS] Result(%d)", ret); - } else { - SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret); - } - - if (!dbus_connection_send(conn, reply, NULL)) { - SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Out Of Memory!"); - } - - dbus_connection_flush(conn); - dbus_message_unref(reply); - } else { - SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Fail to create reply message!!"); - } - - SLOG(LOG_DEBUG, TAG_VCD, "@@@"); - - return 0; -} - -int vcd_dbus_server_mgr_get_audio_type(DBusConnection* conn, DBusMessage* msg) -{ - DBusError err; - dbus_error_init(&err); - - int pid = 0; - char* audio_type = NULL; - - int ret = VCD_ERROR_OPERATION_FAILED; - - SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Manager get audio type"); - - dbus_message_get_args(msg, &err, - DBUS_TYPE_INT32, &pid, - DBUS_TYPE_INVALID); - - if (dbus_error_is_set(&err)) { - SLOG(LOG_ERROR, TAG_VCD, "[IN ERROR] vcd mgr set audio type : get arguments error (%s)", err.message); - dbus_error_free(&err); - ret = VCD_ERROR_OPERATION_FAILED; - } else { - SLOG(LOG_INFO, TAG_VCD, "[IN] vcd mgr set audio type : pid(%d)", pid); - ret = vcd_server_mgr_get_audio_type(pid, &audio_type); - } - - DBusMessage* reply; - reply = dbus_message_new_method_return(msg); - - if (NULL != reply) { - dbus_message_append_args(reply, - DBUS_TYPE_INT32, &ret, - DBUS_TYPE_STRING, &audio_type, - DBUS_TYPE_INVALID); - - if (0 == ret) { - SLOG(LOG_INFO, TAG_VCD, "[OUT SUCCESS] Result(%d), audio type(%s)", ret, audio_type); - } else { - SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret); - } - - if (!dbus_connection_send(conn, reply, NULL)) { - SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Out Of Memory!"); - } - - dbus_connection_flush(conn); - dbus_message_unref(reply); - } else { - SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Fail to create reply message!!"); - } - - SLOG(LOG_DEBUG, TAG_VCD, "@@@"); - - if (NULL != audio_type) free(audio_type); - - return 0; -} - -int vcd_dbus_server_mgr_set_client_info(DBusConnection* conn, DBusMessage* msg) -{ - DBusError err; - dbus_error_init(&err); - - int pid = 0; - - int ret = VCD_ERROR_OPERATION_FAILED; - - SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Manager set client info"); - - dbus_message_get_args(msg, &err, - DBUS_TYPE_INT32, &pid, - DBUS_TYPE_INVALID); - - if (dbus_error_is_set(&err)) { - SLOG(LOG_ERROR, TAG_VCD, "[IN ERROR] vcd mgr set client info : get arguments error (%s)", err.message); - dbus_error_free(&err); - ret = VCD_ERROR_OPERATION_FAILED; - } else { - SLOG(LOG_INFO, TAG_VCD, "[IN] vcd mgr set client info : pid(%d)", pid); - ret = vcd_server_mgr_set_client_info(pid); - } - - DBusMessage* reply; - reply = dbus_message_new_method_return(msg); - - if (NULL != reply) { - dbus_message_append_args(reply, - DBUS_TYPE_INT32, &ret, - DBUS_TYPE_INVALID); - - if (0 == ret) { - SLOG(LOG_INFO, TAG_VCD, "[OUT SUCCESS] Result(%d)", ret); - } else { - SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret); - } - - if (!dbus_connection_send(conn, reply, NULL)) { - SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Out Of Memory!"); - } - - dbus_connection_flush(conn); - dbus_message_unref(reply); - } else { - SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Fail to create reply message!!"); - } - - SLOG(LOG_DEBUG, TAG_VCD, "@@@"); - - return 0; -} - -int vcd_dbus_server_mgr_set_private_data(DBusConnection* conn, DBusMessage* msg) -{ - DBusError err; - dbus_error_init(&err); - - int pid = 0; - char* key = NULL; - char* data = NULL; - - int ret = VCD_ERROR_OPERATION_FAILED; - - SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Manager set private data"); - - dbus_message_get_args(msg, &err, - DBUS_TYPE_INT32, &pid, - DBUS_TYPE_STRING, &key, - DBUS_TYPE_STRING, &data, - DBUS_TYPE_INVALID); - - if (dbus_error_is_set(&err)) { - SLOG(LOG_ERROR, TAG_VCD, "[IN ERROR] vcd mgr set private data : get arguments error (%s)", err.message); - dbus_error_free(&err); - ret = VCD_ERROR_OPERATION_FAILED; - } else { - SLOG(LOG_INFO, TAG_VCD, "[IN] vcd mgr set domain : pid(%d), key(%s), data(%s)", pid, key, data); - ret = vcd_server_mgr_set_private_data(pid, key, data); - if (0 != ret) { - SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to set private data"); - } - } - - SLOG(LOG_DEBUG, TAG_VCD, "@@@"); - - return 0; -} - -int vcd_dbus_server_mgr_get_private_data(DBusConnection* conn, DBusMessage* msg) -{ - DBusError err; - dbus_error_init(&err); - - int pid = 0; - char* key = NULL; - char* data = NULL; - - int ret = VCD_ERROR_OPERATION_FAILED; - - SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Manager get private data"); - - dbus_message_get_args(msg, &err, - DBUS_TYPE_INT32, &pid, - DBUS_TYPE_STRING, &key, - DBUS_TYPE_INVALID); - - if (dbus_error_is_set(&err)) { - SLOG(LOG_ERROR, TAG_VCD, "[IN ERROR] vcd mgr set audio type : get arguments error (%s)", err.message); - dbus_error_free(&err); - ret = VCD_ERROR_OPERATION_FAILED; - } else { - SLOG(LOG_INFO, TAG_VCD, "[IN] vcd mgr get private data : pid(%d), key(%s)", pid, key); - ret = vcd_server_mgr_get_private_data(pid, key, &data); - } - - char *temp_data = NULL; - if (NULL == data) { - SLOG(LOG_INFO, TAG_VCD, "[Dbus INFO] data parameter is NULL"); - temp_data = strdup("#NULL"); - } else { - temp_data = strdup(data); - } - - DBusMessage* reply; - reply = dbus_message_new_method_return(msg); - - if (NULL != reply) { - dbus_message_append_args(reply, - DBUS_TYPE_INT32, &ret, - DBUS_TYPE_STRING, &temp_data, - DBUS_TYPE_INVALID); - - if (0 == ret) { - SLOG(LOG_INFO, TAG_VCD, "[OUT SUCCESS] Result(%d), private data(%s)", ret, temp_data); - } else { - SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret); - } - - if (!dbus_connection_send(conn, reply, NULL)) { - SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Out Of Memory!"); - } - - dbus_connection_flush(conn); - dbus_message_unref(reply); - } else { - SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Fail to create reply message!!"); - } - - SLOG(LOG_DEBUG, TAG_VCD, "@@@"); - - if (NULL != data) { - free(data); - data = NULL; - } - if (NULL != temp_data) { - free(temp_data); - temp_data = NULL; - } - - return 0; -} - -int vcd_dbus_server_mgr_send_specific_engine_request(DBusConnection* conn, DBusMessage* msg) -{ - DBusError err; - dbus_error_init(&err); - - int pid = 0; - char* engine_app_id = NULL; - char* event = NULL; - char* request = NULL; - - int ret = VCD_ERROR_OPERATION_FAILED; - - SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Manager specific engine request"); - - dbus_message_get_args(msg, &err, - DBUS_TYPE_INT32, &pid, - DBUS_TYPE_STRING, &engine_app_id, - DBUS_TYPE_STRING, &event, - DBUS_TYPE_STRING, &request, - DBUS_TYPE_INVALID); - - if (dbus_error_is_set(&err)) { - SLOG(LOG_ERROR, TAG_VCD, "[IN ERROR] vcd mgr specific engine request : get arguments error (%s)", err.message); - dbus_error_free(&err); - ret = VCD_ERROR_OPERATION_FAILED; - } else { - gsize decodingSize=0; - gchar *gDecodedRequest = (gchar *)g_base64_decode((const gchar *)request, &decodingSize); - if (gDecodedRequest) - { - ret = vcd_server_mgr_send_specific_engine_request(pid, engine_app_id, event, gDecodedRequest); - 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); - g_free(gDecodedRequest); - } - } - - return 0; -} - -int vcd_dbus_server_mgr_set_domain(DBusConnection* conn, DBusMessage* msg) -{ - DBusError err; - dbus_error_init(&err); - - int pid = 0; - char* domain = NULL; - - int ret = VCD_ERROR_OPERATION_FAILED; - - SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Manager set domain type"); - - dbus_message_get_args(msg, &err, - DBUS_TYPE_INT32, &pid, - DBUS_TYPE_STRING, &domain, - DBUS_TYPE_INVALID); - - if (dbus_error_is_set(&err)) { - SLOG(LOG_ERROR, TAG_VCD, "[IN ERROR] vcd mgr set domain : get arguments error (%s)", err.message); - dbus_error_free(&err); - ret = VCD_ERROR_OPERATION_FAILED; - } else { - SLOG(LOG_INFO, TAG_VCD, "[IN] vcd mgr set domain : pid(%d), domain(%s)", pid, domain); - ret = vcd_server_mgr_set_domain(pid, domain); - } - - DBusMessage* reply; - reply = dbus_message_new_method_return(msg); - - if (NULL != reply) { - dbus_message_append_args(reply, DBUS_TYPE_INT32, &ret, DBUS_TYPE_INVALID); - - if (0 == ret) { - SLOG(LOG_INFO, TAG_VCD, "[OUT SUCCESS] Result(%d)", ret); - } else { - SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret); - } - - if (!dbus_connection_send(conn, reply, NULL)) { - SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Out Of Memory!"); - } - - dbus_connection_flush(conn); - dbus_message_unref(reply); - } else { - SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Fail to create reply message!!"); - } - - SLOG(LOG_DEBUG, TAG_VCD, "@@@"); - - return 0; -} - -int vcd_dbus_server_mgr_do_action(DBusConnection* conn, DBusMessage* msg) -{ - DBusError err; - dbus_error_init(&err); - - int pid = 0; - int type = 0; - char* send_event = NULL; - - int ret = VCD_ERROR_OPERATION_FAILED; - - SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Manager request to do action"); - - dbus_message_get_args(msg, &err, - DBUS_TYPE_INT32, &pid, - DBUS_TYPE_INT32, &type, - DBUS_TYPE_STRING, &send_event, - DBUS_TYPE_INVALID); - - if (dbus_error_is_set(&err)) { - SLOG(LOG_ERROR, TAG_VCD, "[IN ERROR] vcd mgr request to do action : get arguments error (%s)", err.message); - dbus_error_free(&err); - ret = VCD_ERROR_OPERATION_FAILED; - } else { - SLOG(LOG_INFO, TAG_VCD, "[IN] vcd mgr request to do action : pid(%d), type(%d) send_event(%s)", pid, type, send_event); - ret = vcd_server_mgr_do_action(pid, type, send_event); - if (0 != ret) { - SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to do action"); - } - } - - SLOG(LOG_DEBUG, TAG_VCD, "@@@"); - - return 0; -} - -int vcd_dbus_server_mgr_start(DBusConnection* conn, DBusMessage* msg) -{ - DBusError err; - dbus_error_init(&err); - - int pid = 0; - int recognition_mode = 0; - int exclusive = 0; - int start_by_client = 0; - int disabled_cmd_type = 0; - - int ret = VCD_ERROR_OPERATION_FAILED; - - SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Manager start"); - - dbus_message_get_args(msg, &err, - DBUS_TYPE_INT32, &pid, - DBUS_TYPE_INT32, &recognition_mode, - DBUS_TYPE_INT32, &exclusive, - DBUS_TYPE_INT32, &start_by_client, - DBUS_TYPE_INT32, &disabled_cmd_type, - DBUS_TYPE_INVALID); - - if (dbus_error_is_set(&err)) { - SLOG(LOG_ERROR, TAG_VCD, "[IN ERROR] vcd mgr start : get arguments error (%s)", err.message); - dbus_error_free(&err); - ret = VCD_ERROR_OPERATION_FAILED; - } else { - SLOG(LOG_INFO, TAG_VCD, "[IN] vcd check enabled or disabled command types. disabled cmd type(%d)", disabled_cmd_type); - vcd_server_mgr_set_disabled_command_type(pid, disabled_cmd_type); - - SLOG(LOG_INFO, TAG_VCD, "[IN] vcd mgr start : pid(%d) recognition_mode(%d) exclusive(%d) start by client(%d)", pid, recognition_mode, exclusive, start_by_client); - ret = vcd_server_mgr_start((vcd_recognition_mode_e)recognition_mode, (bool)exclusive, (bool)start_by_client); - } - - DBusMessage* reply; - reply = dbus_message_new_method_return(msg); - - if (NULL != reply) { - dbus_message_append_args(reply, DBUS_TYPE_INT32, &ret, DBUS_TYPE_INVALID); - - if (0 == ret) { - SLOG(LOG_INFO, TAG_VCD, "[OUT SUCCESS] Result(%d)", ret); - } else { - SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret); - } - - if (!dbus_connection_send(conn, reply, NULL)) { - SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Out Of Memory!"); - } - - dbus_connection_flush(conn); - dbus_message_unref(reply); - } else { - SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Fail to create reply message!!"); - } - - SLOG(LOG_DEBUG, TAG_VCD, "@@@"); - - return 0; -} - -int vcd_dbus_server_mgr_stop(DBusConnection* conn, DBusMessage* msg) -{ - DBusError err; - dbus_error_init(&err); - - int pid; - int ret = VCD_ERROR_OPERATION_FAILED; - dbus_message_get_args(msg, &err, DBUS_TYPE_INT32, &pid, DBUS_TYPE_INVALID); - - SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Manager stop"); - - if (dbus_error_is_set(&err)) { - SLOG(LOG_ERROR, TAG_VCD, "[IN ERROR] vcd mgr stop : get arguments error (%s)", err.message); - dbus_error_free(&err); - ret = VCD_ERROR_OPERATION_FAILED; - } else { - SLOG(LOG_INFO, TAG_VCD, "[IN] vcd mgr stop : pid(%d)", pid); - ret = vcd_server_mgr_stop(); - } - - DBusMessage* reply; - reply = dbus_message_new_method_return(msg); - - if (NULL != reply) { - dbus_message_append_args(reply, DBUS_TYPE_INT32, &ret, DBUS_TYPE_INVALID); - - if (0 == ret) { - SLOG(LOG_INFO, TAG_VCD, "[OUT SUCCESS] Result(%d)", ret); - } else { - SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret); - } - - if (!dbus_connection_send(conn, reply, NULL)) { - SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Out Of Memory!"); - } - - dbus_connection_flush(conn); - dbus_message_unref(reply); - } else { - SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Fail to create reply message!!"); - } - - SLOG(LOG_DEBUG, TAG_VCD, "@@@"); - - return 0; -} - -int vcd_dbus_server_mgr_cancel(DBusConnection* conn, DBusMessage* msg) -{ - DBusError err; - dbus_error_init(&err); - - int pid; - int ret = VCD_ERROR_OPERATION_FAILED; - dbus_message_get_args(msg, &err, DBUS_TYPE_INT32, &pid, DBUS_TYPE_INVALID); - - SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Manager cancel"); - - if (dbus_error_is_set(&err)) { - SLOG(LOG_ERROR, TAG_VCD, "[IN ERROR] vcd mgr cancel : get arguments error (%s)", err.message); - dbus_error_free(&err); - ret = VCD_ERROR_OPERATION_FAILED; - } else { - SLOG(LOG_INFO, TAG_VCD, "[IN] vcd mgr cancel : pid(%d)", pid); - ret = vcd_server_mgr_cancel(); - } - - DBusMessage* reply; - reply = dbus_message_new_method_return(msg); - - if (NULL != reply) { - dbus_message_append_args(reply, DBUS_TYPE_INT32, &ret, DBUS_TYPE_INVALID); - - if (0 == ret) { - SLOG(LOG_INFO, TAG_VCD, "[OUT SUCCESS] Result(%d)", ret); - } else { - SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret); - } - - if (!dbus_connection_send(conn, reply, NULL)) { - SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Out Of Memory!"); - } - - dbus_connection_flush(conn); - dbus_message_unref(reply); - } else { - SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Fail to create reply message!!"); - } - - SLOG(LOG_DEBUG, TAG_VCD, "@@@"); - - return 0; -} - -int vcd_dbus_server_mgr_result_selection(DBusConnection* conn, DBusMessage* msg) -{ - DBusError err; - dbus_error_init(&err); - - int pid; - dbus_message_get_args(msg, &err, DBUS_TYPE_INT32, &pid, DBUS_TYPE_INVALID); - - SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Manager result selection"); - - if (dbus_error_is_set(&err)) { - SLOG(LOG_ERROR, TAG_VCD, "[IN ERROR] vcd mgr result selection : get arguments error (%s)", err.message); - dbus_error_free(&err); - } else { - SLOG(LOG_INFO, TAG_VCD, "[IN] vcd mgr result selection : pid(%d)", pid); - vcd_server_mgr_result_select(); - } - return 0; -} - /* for TTS feedback */ int vcd_dbus_server_mgr_start_feedback(DBusConnection* conn, DBusMessage* msg) { diff --git a/server/vcd_dbus_server.h b/server/vcd_dbus_server.h index dca8add..0d0ec0a 100644 --- a/server/vcd_dbus_server.h +++ b/server/vcd_dbus_server.h @@ -30,45 +30,6 @@ int vcd_dbus_server_hello(DBusConnection* conn, DBusMessage* msg); /* * Dbus Server functions for manager */ - -int vcd_dbus_server_mgr_initialize(DBusConnection* conn, DBusMessage* msg); - -int vcd_dbus_server_mgr_finalize(DBusConnection* conn, DBusMessage* msg); - -int vcd_dbus_server_mgr_set_command(DBusConnection* conn, DBusMessage* msg); - -int vcd_dbus_server_mgr_unset_command(DBusConnection* conn, DBusMessage* msg); - -int vcd_dbus_server_mgr_set_demandable_client(DBusConnection* conn, DBusMessage* msg); - -int vcd_dbus_server_mgr_set_audio_type(DBusConnection* conn, DBusMessage* msg); - -int vcd_dbus_server_mgr_get_audio_type(DBusConnection* conn, DBusMessage* msg); - -int vcd_dbus_server_mgr_set_client_info(DBusConnection* conn, DBusMessage* msg); - -int vcd_dbus_server_mgr_set_private_data(DBusConnection* conn, DBusMessage* msg); - -int vcd_dbus_server_mgr_get_private_data(DBusConnection* conn, DBusMessage* msg); - -int vcd_dbus_server_mgr_set_domain(DBusConnection* conn, DBusMessage* msg); - -int vcd_dbus_server_mgr_do_action(DBusConnection* conn, DBusMessage* msg); - -int vcd_dbus_server_mgr_start(DBusConnection* conn, DBusMessage* msg); - -int vcd_dbus_server_mgr_stop(DBusConnection* conn, DBusMessage* msg); - -int vcd_dbus_server_mgr_cancel(DBusConnection* conn, DBusMessage* msg); - -int vcd_dbus_server_mgr_result_selection(DBusConnection* conn, DBusMessage* msg); - -int vcd_dbus_server_mgr_send_specific_engine_request(DBusConnection* conn, DBusMessage* msg); - -int vcd_dbus_server_mgr_change_system_volume(DBusConnection* conn, DBusMessage* msg); - -int vcd_dbus_server_mgr_set_audio_streaming_mode(DBusConnection* conn, DBusMessage* msg); - /* for TTS feedback */ int vcd_dbus_server_mgr_start_feedback(DBusConnection* conn, DBusMessage* msg); diff --git a/server/vcd_engine_agent.c b/server/vcd_engine_agent.c index 531dbdf..6e45a4d 100644 --- a/server/vcd_engine_agent.c +++ b/server/vcd_engine_agent.c @@ -24,6 +24,7 @@ #include "vcd_main.h" #include "vcd_recorder.h" #include "vcd_dbus.h" +#include "vcd_tidl.h" #include "vce_internal.h" /* @@ -922,7 +923,7 @@ int vcd_engine_agent_start_recording() SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to start recorder : result(%d)", ret); vcd_engine_recognize_cancel(); /* Send error cb to manager */ - vcdc_send_error_signal_to_manager(vcd_client_manager_get_pid(), VCD_ERROR_OPERATION_FAILED, "voice_framework.error.vcfw.send_rc_fail"); + vcdc_tidl_send_error_to_manager(vcd_client_manager_get_pid(), VCD_ERROR_OPERATION_FAILED, "voice_framework.error.vcfw.send_rc_fail"); return ret; } diff --git a/server/vcd_main.h b/server/vcd_main.h index 70bcd18..7636495 100644 --- a/server/vcd_main.h +++ b/server/vcd_main.h @@ -98,6 +98,12 @@ struct vce_cmd_s { int index; }; +// TODO: move vcd_client_type_e to vcd_tidl.h after migrate from dbus to tidl done +typedef enum { + VCD_CLIENT_TYPE_NORMAL, + VCD_CLIENT_TYPE_WIDGET, + VCD_CLIENT_TYPE_MANAGER +} vcd_client_type_e; #ifdef __cplusplus } diff --git a/server/vcd_recorder.c b/server/vcd_recorder.c index cadb81d..9c4845f 100644 --- a/server/vcd_recorder.c +++ b/server/vcd_recorder.c @@ -22,6 +22,7 @@ #include "vcd_client_data.h" #include "vcd_config.h" #include "vcd_dbus.h" +#include "vcd_tidl.h" #include "vcd_engine_agent.h" #include "vcd_recorder.h" #include "dependency_audio_manager.h" diff --git a/server/vcd_server.c b/server/vcd_server.c index faf41e5..7f0d713 100644 --- a/server/vcd_server.c +++ b/server/vcd_server.c @@ -29,6 +29,7 @@ #include "vcd_config.h" #include "vcd_recorder.h" #include "vcd_dbus.h" +#include "vcd_tidl.h" #include "vce_internal.h" #include "voice_control_command_expand.h" @@ -145,9 +146,9 @@ static int __server_recorder_callback(const void* data, const unsigned int lengt ecore_timer_add(0, __cancel_by_interrupt, NULL); /* Send error cb to manager */ if (VCE_ERROR_OUT_OF_NETWORK == ret) { - vcdc_send_error_signal_to_manager(vcd_client_manager_get_pid(), VCD_ERROR_TIMED_OUT, "voice_framework.error.engine.set_recording_fail"); + vcdc_tidl_send_error_to_manager(vcd_client_manager_get_pid(), VCD_ERROR_TIMED_OUT, "voice_framework.error.engine.set_recording_fail"); } else { - vcdc_send_error_signal_to_manager(vcd_client_manager_get_pid(), ret, "voice_framework.error.engine.set_recording_fail"); + vcdc_tidl_send_error_to_manager(vcd_client_manager_get_pid(), ret, "voice_framework.error.engine.set_recording_fail"); } return 0; } @@ -1123,7 +1124,7 @@ int vcd_send_error(vce_error_e error, const char* msg, void *user_data) int pid = __get_tts_played_pid(); ret = vcdc_send_error_signal_to_app(pid, error, error_msg); } else { - ret = vcdc_send_error_signal_to_manager(vcd_client_manager_get_pid(), error, error_msg); + ret = vcdc_tidl_send_error_to_manager(vcd_client_manager_get_pid(), error, error_msg); ecore_main_loop_thread_safe_call_async(__cancel_by_error, NULL); } @@ -1347,6 +1348,15 @@ int vcd_initialize(vce_request_callback_s *callback) } return VCD_ERROR_OPERATION_FAILED; } + + /* Open tidl connection */ + if (0 != vcd_mgr_tidl_open_connection()) { + SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to open tidl connection"); + if (TRUE != vcd_finalize()) { + SLOG(LOG_ERROR, TAG_VCD, "[Server Error] Fail to finalize"); + } + return VCD_ERROR_OPERATION_FAILED; + } // } vcd_config_set_service_state(VCD_STATE_READY); @@ -1426,11 +1436,16 @@ bool vcd_finalize() vcdc_send_service_state(VCD_STATE_NONE); } - /* Open dbus connection */ + /* Close dbus connection */ if (0 != vcd_dbus_close_connection()) { SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to close connection"); } + /* Close tidl connection */ + if (0 != vcd_mgr_tidl_close_connection()) { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to close connection"); + } + SLOG(LOG_ERROR, TAG_VCD, "[Server] mode finalize"); return true; @@ -1898,7 +1913,7 @@ static int __start_internal_recognition() /* Send error cb to manager */ int pid = vcd_client_widget_get_foreground_pid(); if (-1 != pid) - vcdc_send_error_signal_to_manager(vcd_client_manager_get_pid(), VCD_ERROR_OPERATION_FAILED, "voice_framework.error.vcfw.collect_command_fail"); + vcdc_tidl_send_error_to_manager(vcd_client_manager_get_pid(), VCD_ERROR_OPERATION_FAILED, "voice_framework.error.vcfw.collect_command_fail"); return VCD_ERROR_OPERATION_FAILED; } @@ -1909,7 +1924,7 @@ static int __start_internal_recognition() /* Send error cb to manager */ int pid = vcd_client_widget_get_foreground_pid(); if (-1 != pid) - vcdc_send_error_signal_to_manager(vcd_client_manager_get_pid(), VCD_ERROR_OPERATION_FAILED, "voice_framework.error.engine.set_commands_fail"); + vcdc_tidl_send_error_to_manager(vcd_client_manager_get_pid(), VCD_ERROR_OPERATION_FAILED, "voice_framework.error.engine.set_commands_fail"); return VCD_ERROR_OPERATION_FAILED; } @@ -1929,7 +1944,7 @@ static int __start_internal_recognition() /* Send error cb to manager */ int pid = vcd_client_widget_get_foreground_pid(); if (-1 != pid) - vcdc_send_error_signal_to_manager(vcd_client_manager_get_pid(), ret, "voice_framework.error.engine.start_fail"); + vcdc_tidl_send_error_to_manager(vcd_client_manager_get_pid(), ret, "voice_framework.error.engine.start_fail"); return ret; } @@ -1944,7 +1959,7 @@ static int __start_internal_recognition() /* Send error cb to manager */ int pid = vcd_client_widget_get_foreground_pid(); if (-1 != pid) - vcdc_send_error_signal_to_manager(vcd_client_manager_get_pid(), VCD_ERROR_OPERATION_FAILED, "voice_framework.error.vcfw.send_rc_fail"); + vcdc_tidl_send_error_to_manager(vcd_client_manager_get_pid(), VCD_ERROR_OPERATION_FAILED, "voice_framework.error.vcfw.send_rc_fail"); return ret; } #endif @@ -2330,7 +2345,7 @@ int vcd_server_mgr_stop_feedback(void) return VCD_ERROR_NONE; } -int vcd_server_mgr_send_audio_streaming(int pid, int event, char* buffer, unsigned int len) +int vcd_server_mgr_send_audio_streaming(int pid, int event, const char* buffer, unsigned int len) { SLOG(LOG_INFO, TAG_VCD, "[DEBUG] Send Audio Streaming from Multi-assistant. event(%d), buffer(%p), len(%d)", event, &buffer, len); diff --git a/server/vcd_server.h b/server/vcd_server.h index 7597b3d..4f1286d 100644 --- a/server/vcd_server.h +++ b/server/vcd_server.h @@ -87,7 +87,7 @@ int vcd_server_mgr_start_feedback(void); int vcd_server_mgr_stop_feedback(void); /* for Multi-assistant */ -int vcd_server_mgr_send_audio_streaming(int pid, int event, char* buffer, unsigned int len); +int vcd_server_mgr_send_audio_streaming(int pid, int event, const char* buffer, unsigned int len); /* diff --git a/server/vcd_tidl.c b/server/vcd_tidl.c new file mode 100644 index 0000000..d5917a5 --- /dev/null +++ b/server/vcd_tidl.c @@ -0,0 +1,1204 @@ +/* +* Copyright (c) 2022 Samsung Electronics Co., Ltd All Rights Reserved +* +* Licensed under the Apache License, Version 2.0 (the License); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an AS IS BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#include "vcd_client_data.h" +#include "vcd_main.h" +#include "vcd_server.h" +#include "vcd_config.h" + +#include "vcd_tidl.h" +#include "vcd_mgr_stub.h" +#include "vcd_mgr_proxy.h" + +static rpc_port_stub_vc_mgr_callback_s g_mgr_callback; + +static pthread_mutex_t g_mgr_tidl_info_mutex = PTHREAD_MUTEX_INITIALIZER; + +static int g_volume_count = 0; + +static void __on_connected(rpc_port_proxy_vcd_mgr_h h, void *user_data) +{ + manager_tidl_info_s* mgr_tidl_info = vcd_client_manager_get_tidl_info(); + + if (NULL == mgr_tidl_info) { + SLOG(LOG_ERROR, TAG_VCD, "[TIDL] tidl proxy info not allocated"); + return; + } + + mgr_tidl_info->connected = true; + mgr_tidl_info->connection_requesting = false; + + SLOG(LOG_INFO, TAG_VCD, "Connected to manager"); +} + +static void __on_disconnected(rpc_port_proxy_vcd_mgr_h h, void *user_data) +{ + manager_tidl_info_s* mgr_tidl_info = vcd_client_manager_get_tidl_info(); + + if (NULL == mgr_tidl_info) { + SLOG(LOG_ERROR, TAG_VCD, "[TIDL] tidl proxy info not allocated"); + return; + } + + mgr_tidl_info->connected = false; + mgr_tidl_info->connection_requesting = false; + + SLOG(LOG_INFO, TAG_VCD, "Disonnected to manager"); +} + +static void __on_rejected(rpc_port_proxy_vcd_mgr_h h, void *user_data) +{ + manager_tidl_info_s* mgr_tidl_info = vcd_client_manager_get_tidl_info(); + + if (NULL == mgr_tidl_info) { + SLOG(LOG_ERROR, TAG_VCD, "[TIDL] tidl proxy info not allocated"); + return; + } + + mgr_tidl_info->connection_requesting = false; + + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Rejected from manager"); +} + +static rpc_port_proxy_vcd_mgr_h __create_rpc_port(const char* engine_app_id, manager_tidl_info_s* mgr_tidl_info) +{ + SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] __create_rpc_port"); + rpc_port_proxy_vcd_mgr_callback_s rpc_callback = { + .connected = __on_connected, + .disconnected = __on_disconnected, + .rejected = __on_rejected + }; + + rpc_port_proxy_vcd_mgr_h handle = NULL; + if (0 != rpc_port_proxy_vcd_mgr_create(engine_app_id, &rpc_callback, NULL, &handle)) { + SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to create proxy"); + return NULL; + } + + return handle; +} + +static void __request_tidl_connect_sync(manager_tidl_info_s* mgr_tidl_info) +{ + if (NULL == mgr_tidl_info) { + SLOG(LOG_ERROR, TAG_VCD, "[TIDL] tidl proxy info not allocated"); + return; + } + + if (mgr_tidl_info->connection_requesting) { + return; + } + + int ret = rpc_port_proxy_vcd_mgr_connect_sync(mgr_tidl_info->rpc_h); + SLOG(LOG_INFO, TAG_VCD, "[INFO] Request connection to stub. ret(%d)", ret); + + if (0 == ret) { + mgr_tidl_info->connection_requesting = true; + } +} + +void __send_msg(bundle* msg, vcd_client_type_e type) +{ + SLOG(LOG_INFO, TAG_VCD, "[TIDL] send msg start"); + + if (VCD_CLIENT_TYPE_MANAGER == type) { + pthread_mutex_lock(&g_mgr_tidl_info_mutex); + + SLOG(LOG_INFO, TAG_VCD, "[TIDL] message to manager"); + manager_tidl_info_s* mgr_tidl_info = vcd_client_manager_get_tidl_info(); + if (NULL == mgr_tidl_info) { + SLOG(LOG_ERROR, TAG_VCD, "[TIDL] tidl proxy info not allocated"); + pthread_mutex_unlock(&g_mgr_tidl_info_mutex); + return; + } + + rpc_port_stub_vc_mgr_notify_cb_h handle = mgr_tidl_info->notify_cb; + if (NULL == handle) { + SLOG(LOG_ERROR, TAG_VCD, "[TIDL] notify callback handle is null"); + pthread_mutex_unlock(&g_mgr_tidl_info_mutex); + return; + } + + if (0 != rpc_port_stub_vc_mgr_notify_cb_invoke(handle, msg)) { + SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to send msg"); + pthread_mutex_unlock(&g_mgr_tidl_info_mutex); + return; + } + pthread_mutex_unlock(&g_mgr_tidl_info_mutex); + } + + SLOG(LOG_INFO, TAG_VCD, "[TIDL] send msg end"); +} + +static void __vc_mgr_create_cb(rpc_port_stub_vc_mgr_context_h context, void *user_data) +{ + char *sender = NULL; + + rpc_port_stub_vc_mgr_context_get_sender(context, &sender); + if (!sender){ + SLOG(LOG_ERROR, TAG_VCD, "Sender is NULL"); + return; + } + + SLOG(LOG_DEBUG, TAG_VCD, "@@@ Manager connect. appid(%s)", sender); + + free(sender); +} + +static void __vc_mgr_terminate_cb(rpc_port_stub_vc_mgr_context_h context, void *user_data) +{ + pthread_mutex_lock(&g_mgr_tidl_info_mutex); + manager_tidl_info_s* mgr_tidl_info = vcd_client_manager_get_tidl_info(); + if (NULL == mgr_tidl_info) { + SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to get manager tidl info."); + pthread_mutex_unlock(&g_mgr_tidl_info_mutex); + return; + } + + SLOG(LOG_DEBUG, TAG_VCD, "@@@ VC MANAGER FINALIZE. pid(%u)", mgr_tidl_info->pid); + + if (0 != vcd_client_manager_unset_tidl_notify_cb()) { + SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to unset notify callback"); + } + + if (0 != vcd_client_manager_unset_tidl_send_buffer_cb()) { + SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to unset send buffer callback"); + } + + if (0 != vcd_client_manager_delete_tidl_info()) { + SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to delete manager tidl info"); + } + mgr_tidl_info = NULL; + + SLOG(LOG_DEBUG, TAG_VCD, "@@@"); + + pthread_mutex_unlock(&g_mgr_tidl_info_mutex); + + + char *sender = NULL; + rpc_port_stub_vc_mgr_context_get_sender(context, &sender); + if (!sender) + return; + + SLOG(LOG_INFO, TAG_VCD, "@@@ Manager disconnect. appid(%s)", sender); + + free(sender); +} + +static void __vc_mgr_register_cb_cb(rpc_port_stub_vc_mgr_context_h context, int pid, rpc_port_stub_vc_mgr_notify_cb_h notify_callback, rpc_port_stub_vc_mgr_send_buffer_cb_h send_buffer_callback, void *user_data) +{ + pthread_mutex_lock(&g_mgr_tidl_info_mutex); + SLOG(LOG_INFO, TAG_VCD, "@@@ VC MANAGER REGISTER CALLBACK"); + + int ret = -1; + ret = vcd_client_manger_create_tidl_info(pid); + + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to create manager tidl info."); + pthread_mutex_unlock(&g_mgr_tidl_info_mutex); + return; + } + + manager_tidl_info_s* mgr_tidl_info = vcd_client_manager_get_tidl_info(); + + if (NULL == mgr_tidl_info) { + SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to get manager tidl info. pid(%d)", pid); + pthread_mutex_unlock(&g_mgr_tidl_info_mutex); + return; + } + + char *sender = NULL; + rpc_port_stub_vc_mgr_context_get_sender(context, &sender); + + if (!sender){ + SLOG(LOG_ERROR, TAG_VCD, "Sender is NULL"); + pthread_mutex_unlock(&g_mgr_tidl_info_mutex); + return; + } + + mgr_tidl_info->rpc_h = __create_rpc_port(sender, mgr_tidl_info); + + if (NULL == mgr_tidl_info->rpc_h) { + SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to create server proxy"); + } else { + SLOG(LOG_INFO, TAG_VCD, "[TIDL] rpc_h(%p), engine_app_id(%s)", mgr_tidl_info->rpc_h, sender); + } + + free(sender); + + if (0 != vcd_client_manager_set_tidl_notify_cb(notify_callback, user_data)) { + SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to set notify callback"); + } else { + SLOG(LOG_INFO, TAG_VCD, "[TIDL] Succeed to set notify callback."); + } + + if (0 != vcd_client_manager_set_tidl_send_buffer_cb(send_buffer_callback, user_data)) { + SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to set send buffer callback"); + } else { + SLOG(LOG_INFO, TAG_VCD, "[TIDL] Succeed to set send buffer callback."); + } + + pthread_mutex_unlock(&g_mgr_tidl_info_mutex); + + __request_tidl_connect_sync(mgr_tidl_info); + + SLOG(LOG_DEBUG, TAG_VCD, "@@@"); +} + +static int __vc_mgr_initialize_cb(rpc_port_stub_vc_mgr_context_h context, int pid, int audio_streaming_mode, int *service_state, int *foreground, int *daemon_pid, void *user_data) +{ + SLOG(LOG_INFO, TAG_VCD, "@@@ VCD Manager Initialize"); + + int ret = -1; + + vcd_config_set_audio_streaming_mode((vcd_audio_streaming_mode_e)audio_streaming_mode); + ret = vcd_server_mgr_initialize(pid, audio_streaming_mode); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret); + return ret; + } + *service_state = vcd_server_get_service_state(); + *foreground = vcd_server_get_foreground(); + *daemon_pid = getpid(); + + 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); + SLOG(LOG_DEBUG, TAG_VCD, "@@@"); + return ret; +} + +static int __vc_mgr_finalize_cb(rpc_port_stub_vc_mgr_context_h context, int pid, void *user_data) +{ + SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Manager Finalize"); + SLOG(LOG_INFO, TAG_VCD, "[IN] vcd mgr finalize : pid(%d)", pid); + + int ret = -1; + + ret = vcd_server_mgr_finalize(pid); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret); + } + + SLOG(LOG_DEBUG, TAG_VCD, "@@@"); + + return ret; +} + +static int __vc_mgr_set_command_cb(rpc_port_stub_vc_mgr_context_h context, int pid, void *user_data) +{ + SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Manager Set command"); + SLOG(LOG_INFO, TAG_VCD, "[IN] vcd mgr set command : pid(%d)", pid); + + int ret = -1; + + ret = vcd_server_mgr_set_command(pid); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret); + return ret; + } + + SLOG(LOG_DEBUG, TAG_VCD, "@@@"); + + return ret; +} + +static int __vc_mgr_unset_command_cb(rpc_port_stub_vc_mgr_context_h context, int pid, void *user_data) +{ + SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Manager unset command"); + SLOG(LOG_INFO, TAG_VCD, "[IN] vcd mgr unset command : pid(%d)", pid); + + int ret = -1; + + ret = vcd_server_mgr_unset_command(pid); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret); + return ret; + } + + SLOG(LOG_DEBUG, TAG_VCD, "@@@"); + + return ret; +} + +static int __vc_mgr_set_demandable_client_cb(rpc_port_stub_vc_mgr_context_h context, int pid, void *user_data) +{ + SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Manager Set demandable client"); + SLOG(LOG_INFO, TAG_VCD, "[IN] vcd mgr set demandable client : pid(%d)", pid); + + int ret = -1; + + ret = vcd_server_mgr_set_demandable_client(pid); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret); + return ret; + } + + SLOG(LOG_DEBUG, TAG_VCD, "@@@"); + + return ret; +} + +static int __vc_mgr_set_audio_type_cb(rpc_port_stub_vc_mgr_context_h context, int pid, const char *audio_type, void *user_data) +{ + SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Manager set audio type"); + SLOG(LOG_INFO, TAG_VCD, "[IN] vcd mgr set audio type : pid(%d), audio type(%s)", pid, audio_type); + + int ret = -1; + + ret = vcd_server_mgr_set_audio_type(pid, audio_type); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret); + return ret; + } + + SLOG(LOG_DEBUG, TAG_VCD, "@@@"); + + return ret; +} + +static int __vc_mgr_get_audio_type_cb(rpc_port_stub_vc_mgr_context_h context, int pid, char **audio_type, void *user_data) +{ + SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Manager get audio type"); + SLOG(LOG_INFO, TAG_VCD, "[IN] vcd mgr set audio type : pid(%d)", pid); + + int ret = -1; + char* tmp_audio_type = NULL; + + ret = vcd_server_mgr_get_audio_type(pid, &tmp_audio_type); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret); + free(tmp_audio_type); + return ret; + } + + *audio_type = strdup(tmp_audio_type); + free(tmp_audio_type); + + SLOG(LOG_DEBUG, TAG_VCD, "@@@"); + + return ret; +} + +static void __vc_mgr_set_private_data_cb(rpc_port_stub_vc_mgr_context_h context, int pid, const char *key, const char *data, void *user_data) +{ + SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Manager set private data"); + SLOG(LOG_INFO, TAG_VCD, "[IN] vcd mgr set domain : pid(%d), key(%s), data(%s)", pid, key, data); + + int ret = -1; + + ret = vcd_server_mgr_set_private_data(pid, key, data); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to set private data"); + SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret); + } + + SLOG(LOG_DEBUG, TAG_VCD, "@@@"); +} + +static int __vc_mgr_get_private_data_cb(rpc_port_stub_vc_mgr_context_h context, int pid, const char *key, char **data, void *user_data) +{ + SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Manager get private data"); + SLOG(LOG_INFO, TAG_VCD, "[IN] vcd mgr get private data : pid(%d), key(%s)", pid, key); + + int ret = -1; + char *temp_data = NULL; + + ret = vcd_server_mgr_get_private_data(pid, key, &temp_data); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret); + return ret; + } + if (NULL == temp_data) { + SLOG(LOG_INFO, TAG_VCD, "data parameter is NULL"); + temp_data = strdup("#NULL"); + } + + *data = strdup(temp_data); + free(temp_data); + + SLOG(LOG_DEBUG, TAG_VCD, "@@@"); + + return ret; +} + +static int __vc_mgr_set_client_info_cb(rpc_port_stub_vc_mgr_context_h context, int pid, void *user_data) +{ + SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Manager set client info"); + SLOG(LOG_INFO, TAG_VCD, "[IN] vcd mgr set client info : pid(%d)", pid); + + int ret = -1; + + ret = vcd_server_mgr_set_client_info(pid); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret); + return ret; + } + + SLOG(LOG_DEBUG, TAG_VCD, "@@@"); + + return ret; +} + +static int __vc_mgr_set_domain_cb(rpc_port_stub_vc_mgr_context_h context, int pid, const char *domain, void *user_data) +{ + SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Manager set domain type"); + SLOG(LOG_INFO, TAG_VCD, "[IN] vcd mgr set domain : pid(%d), domain(%s)", pid, domain); + + int ret = -1; + + ret = vcd_server_mgr_set_domain(pid, domain); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret); + return ret; + } + + SLOG(LOG_DEBUG, TAG_VCD, "@@@"); + + return ret; +} + +static void __vc_mgr_do_action_cb(rpc_port_stub_vc_mgr_context_h context, int pid, int type, const char *send_event, void *user_data) +{ + SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Manager request to do action"); + SLOG(LOG_INFO, TAG_VCD, "[IN] vcd mgr request to do action : pid(%d), type(%d) send_event(%s)", pid, type, send_event); + + int ret = -1; + + ret = vcd_server_mgr_do_action(pid, type, send_event); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret); + } + + SLOG(LOG_DEBUG, TAG_VCD, "@@@"); +} + +static int __vc_mgr_start_cb(rpc_port_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) +{ + SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Manager start"); + SLOG(LOG_INFO, TAG_VCD, "[IN] vcd check enabled or disabled command types. disabled cmd type(%d)", disabled_cmd_type); + + int ret = -1; + + vcd_server_mgr_set_disabled_command_type(pid, disabled_cmd_type); + + 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); + ret = vcd_server_mgr_start((vcd_recognition_mode_e)recognition_mode, exclusive_command_option, start_by_client); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret); + return ret; + } + + SLOG(LOG_DEBUG, TAG_VCD, "@@@"); + + return ret; +} + +static int __vc_mgr_stop_cb(rpc_port_stub_vc_mgr_context_h context, int pid, void *user_data) +{ + SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Manager stop"); + SLOG(LOG_INFO, TAG_VCD, "[IN] vcd mgr stop : pid(%d)", pid); + + int ret = -1; + + ret = vcd_server_mgr_stop(); + + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret); + return ret; + } + + SLOG(LOG_DEBUG, TAG_VCD, "@@@"); + + return ret; +} + +static int __vc_mgr_cancel_cb(rpc_port_stub_vc_mgr_context_h context, int pid, void *user_data) +{ + SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Manager cancel"); + SLOG(LOG_INFO, TAG_VCD, "[IN] vcd mgr cancel : pid(%d)", pid); + + int ret = -1; + + ret = vcd_server_mgr_cancel(); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret); + return ret; + } + + SLOG(LOG_DEBUG, TAG_VCD, "@@@"); + + return ret; +} + +static void __vc_mgr_set_audio_streaming_mode_cb(rpc_port_stub_vc_mgr_context_h context, int pid, int mode, void *user_data) +{ + SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Manager set audio streaming mode"); + SLOG(LOG_INFO, TAG_VCD, "[IN] vcd mgr set audio streaming mode : pid(%d) mode(%d)", pid, mode); + + vcd_config_set_audio_streaming_mode((vcd_audio_streaming_mode_e)mode); + + SLOG(LOG_DEBUG, TAG_VCD, "@@@"); +} + +static void __vc_mgr_send_specific_engine_request_cb(rpc_port_stub_vc_mgr_context_h context, int pid, const char *engine_app_id, const char *event, const char *request, void *user_data) +{ + SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Manager specific engine request"); + + int ret = -1; + gsize decodingSize = 0; + gchar *gDecodedRequest = (gchar *)g_base64_decode((const gchar *)request, &decodingSize); + + if (gDecodedRequest) { + ret = vcd_server_mgr_send_specific_engine_request(pid, engine_app_id, event, gDecodedRequest); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret); + } + + 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); + g_free(gDecodedRequest); + } + + SLOG(LOG_DEBUG, TAG_VCD, "@@@"); +} + +static void __vc_mgr_send_result_selection_cb(rpc_port_stub_vc_mgr_context_h context, int pid, void *user_data) +{ + SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Manager result selection"); + SLOG(LOG_INFO, TAG_VCD, "[IN] vcd mgr result selection : pid(%d)", pid); + + vcd_server_mgr_result_select(); + + SLOG(LOG_DEBUG, TAG_VCD, "@@@"); +} + +static void __vc_mgr_send_utterance_status_cb(rpc_port_stub_vc_mgr_context_h context, int utt_id, int utt_status, void *user_data) +{ + SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Manager send utterance status"); + SLOG(LOG_INFO, TAG_VCD, "[IN] vcd mgr send utterance status : utt_id(%d), utt_status(%d)", utt_id, utt_status); + // TODO: send parameter to client + + SLOG(LOG_DEBUG, TAG_VCD, "@@@"); +} + +static void __vc_mgr_send_audio_streaming_cb(rpc_port_stub_vc_mgr_context_h context, int pid, int event, rpc_port_stub_array_char_h data, void *user_data) +{ + SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Manager send audio streaming"); + + char* buffer = NULL; + int len = 0; + int ret = -1; + rpc_port_stub_array_char_get(data, &buffer, &len); + + SLOG(LOG_INFO, TAG_VCD, "[IN] vcd mgr send audio streaming : pid(%d), event(%d), buffer(%p), len(%d)", pid, event, buffer, len); + + ret = vcd_server_mgr_send_audio_streaming(pid, event, buffer, (unsigned int)len); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret); + } + + SLOG(LOG_DEBUG, TAG_VCD, "@@@"); +} + +int vcd_mgr_tidl_open_connection() +{ + SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] vcd_tidl_open_connection"); + + g_mgr_callback.create = __vc_mgr_create_cb; + g_mgr_callback.terminate = __vc_mgr_terminate_cb; + g_mgr_callback.register_cb = __vc_mgr_register_cb_cb; + g_mgr_callback.initialize = __vc_mgr_initialize_cb; + g_mgr_callback.finalize = __vc_mgr_finalize_cb; + g_mgr_callback.set_command = __vc_mgr_set_command_cb; + g_mgr_callback.unset_command = __vc_mgr_unset_command_cb; + g_mgr_callback.demandable_client = __vc_mgr_set_demandable_client_cb; + g_mgr_callback.set_audio_type = __vc_mgr_set_audio_type_cb; + g_mgr_callback.get_audio_type = __vc_mgr_get_audio_type_cb; + g_mgr_callback.set_private_data = __vc_mgr_set_private_data_cb; + g_mgr_callback.get_private_data = __vc_mgr_get_private_data_cb; + g_mgr_callback.set_client_info = __vc_mgr_set_client_info_cb; + g_mgr_callback.set_domain = __vc_mgr_set_domain_cb; + g_mgr_callback.do_action = __vc_mgr_do_action_cb; + g_mgr_callback.start = __vc_mgr_start_cb; + g_mgr_callback.stop = __vc_mgr_stop_cb; + g_mgr_callback.cancel = __vc_mgr_cancel_cb; + g_mgr_callback.set_audio_streaming_mode = __vc_mgr_set_audio_streaming_mode_cb; + g_mgr_callback.send_specific_engine_request = __vc_mgr_send_specific_engine_request_cb; + g_mgr_callback.send_result_selection = __vc_mgr_send_result_selection_cb; + g_mgr_callback.send_utterance_status = __vc_mgr_send_utterance_status_cb; + g_mgr_callback.send_audio_streaming = __vc_mgr_send_audio_streaming_cb; + + int ret = -1; + int count = 0; + while (VC_RETRY_MIN_COUNT >= count) { + ret = rpc_port_stub_vc_mgr_register(&g_mgr_callback, NULL); + if (0 == ret) { + SLOG(LOG_DEBUG, TAG_VCD, "register callback"); + return VCD_ERROR_NONE; + } + usleep(100000); + count++; + } + + SLOG(LOG_ERROR, TAG_VCD, "Fail to register callback(%d)", ret); + return VCD_ERROR_OPERATION_FAILED; +} + +int vcd_mgr_tidl_close_connection() +{ + SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Close connection"); + rpc_port_stub_vc_mgr_unregister(); + + return VCD_ERROR_NONE; +} + +// TODO: remove _tidl after all dbus removed +int vcdc_tidl_send_hello(int pid, vcd_client_type_e type) +{ + SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Send hello"); + + char tmp_pid[10] = {0, }; + + bundle* msg = bundle_create(); + snprintf(tmp_pid, 10, "%d", pid); + + bundle_add_str(msg, VC_MANAGER_BUNDLE_METHOD, VCD_MANAGER_METHOD_HELLO); + bundle_add_str(msg, VC_MANAGER_BUNDLE_MESSAGE, tmp_pid); + + SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] VCD SEND MESSAGE"); + + __send_msg(msg, VCD_CLIENT_TYPE_MANAGER); + bundle_free(msg); + + return VCD_ERROR_NONE; +} + +int vcdc_send_set_volume(int manager_pid, float volume) +{ + SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Set volume"); + + char tmp_volume[20] = {0, }; + + bundle* msg = bundle_create(); + + snprintf(tmp_volume, 20, "%.6f", volume); + bundle_add_str(msg, VC_MANAGER_BUNDLE_METHOD, VCD_MANAGER_METHOD_SET_VOLUME); + bundle_add_str(msg, VC_MANAGER_BUNDLE_MESSAGE, tmp_volume); + + + SLOG(LOG_DEBUG, TAG_VCD, ">>>> VCD SEND MESSAGE"); + __send_msg(msg, VCD_CLIENT_TYPE_MANAGER); + if (20 == g_volume_count) { + SLOG(LOG_INFO, TAG_VCD, "@@ Send set volume : pid(%d), volume(%f)", manager_pid, volume); + g_volume_count = 0; + } + g_volume_count++; + + bundle_free(msg); + + return VCD_ERROR_NONE; +} +// TODO: remove tidl after all dbus migrate to tidl +int vcdc_tidl_send_result(int pid, int manager_pid, int cmd_type) +{ + SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Send result"); + + bundle* msg = bundle_create(); + + bundle_add_str(msg, VC_MANAGER_BUNDLE_METHOD, VCD_MANAGER_METHOD_RESULT); + + SLOG(LOG_DEBUG, TAG_VCD, ">>>> VCD SEND MESSAGE"); + + __send_msg(msg, VCD_CLIENT_TYPE_MANAGER); + bundle_free(msg); + + return VCD_ERROR_NONE; +} + +int vcdc_send_pre_result_to_manager(int manager_pid, int event, const char* pre_result) +{ + SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Send pre result to manager"); + + char tmp_event[10] = {0, }; + + bundle* msg = bundle_create(); + snprintf(tmp_event, 10, "%d", event); + + bundle_add_str(msg, VC_MANAGER_BUNDLE_METHOD, VCD_MANAGER_METHOD_PRE_RESULT); + bundle_add_str(msg, VC_MANAGER_BUNDLE_EVENT, tmp_event); + bundle_add_str(msg, VC_MANAGER_BUNDLE_PRE_RESULT, pre_result); + + SLOG(LOG_DEBUG, TAG_VCD, ">>>> VCD SEND MESSAGE"); + + __send_msg(msg, VCD_CLIENT_TYPE_MANAGER); + bundle_free(msg); + + return VCD_ERROR_NONE; +} + +int vcdc_send_specific_engine_result_to_manager(int manager_pid, const char* engine_app_id, const char* event, const char* result) +{ + SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Send specific engine result to manager"); + + bundle* msg = bundle_create(); + + gchar *gEncodedResult = g_base64_encode((const guchar*)result, strlen(result)); + + bundle_add_str(msg, VC_MANAGER_BUNDLE_METHOD, VCD_MANAGER_METHOD_SPECIFIC_ENGINE_RESULT); + bundle_add_str(msg, VC_MANAGER_BUNDLE_ENGINE_APP_ID, engine_app_id); + bundle_add_str(msg, VC_MANAGER_BUNDLE_EVENT, event); + bundle_add_str(msg, VC_MANAGER_BUNDLE_RESULT, gEncodedResult); + + SLOG(LOG_DEBUG, TAG_VCD, ">>>> VCD SEND MESSAGE"); + + __send_msg(msg, VCD_CLIENT_TYPE_MANAGER); + bundle_free(msg); + + if (gEncodedResult) + g_free(gEncodedResult); + + return VCD_ERROR_NONE; +} + +int vcdc_send_result_to_manager(int manager_pid, int result_type) +{ + SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Send result to manager"); + + char tmp_result[10] = {0, }; + + bundle* msg = bundle_create(); + snprintf(tmp_result, 10, "%d", result_type); + + bundle_add_str(msg, VC_MANAGER_BUNDLE_METHOD, VCD_MANAGER_METHOD_ALL_RESULT); + bundle_add_str(msg, VC_MANAGER_BUNDLE_MESSAGE, tmp_result); + + + SLOG(LOG_DEBUG, TAG_VCD, ">>>> VCD SEND MESSAGE"); + + __send_msg(msg, VCD_CLIENT_TYPE_MANAGER); + bundle_free(msg); + + return VCD_ERROR_NONE; +} + +int vcdc_send_speech_detected(int manager_pid) +{ + SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Send speech detected"); + + bundle* msg = bundle_create(); + + bundle_add_str(msg, VC_MANAGER_BUNDLE_METHOD, VCD_MANAGER_METHOD_SPEECH_DETECTED); + + SLOG(LOG_DEBUG, TAG_VCD, ">>>> VCD SEND MESSAGE"); + + __send_msg(msg, VCD_CLIENT_TYPE_MANAGER); + bundle_free(msg); + + return VCD_ERROR_NONE; +} + +int vcdc_send_service_state(vcd_state_e state) +{ + SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Send service state"); + + char tmp_state[10] = {0, }; + + bundle* msg = bundle_create(); + snprintf(tmp_state, 10, "%d", (int)state); + + bundle_add_str(msg, VC_MANAGER_BUNDLE_METHOD, VCD_MANAGER_METHOD_SET_SERVICE_STATE); + bundle_add_str(msg, VC_MANAGER_BUNDLE_MESSAGE, tmp_state); + + SLOG(LOG_DEBUG, TAG_VCD, ">>>> VCD SEND MESSAGE"); + + __send_msg(msg, VCD_CLIENT_TYPE_MANAGER); + bundle_free(msg); + + return VCD_ERROR_NONE; +} + +int vcdc_send_dialog(int manager_pid, int pid, const char* disp_text, const char* utt_text, int continuous) +{ + SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Send dialog"); + + char tmp_pid[10] = {0, }; + char tmp_continuous[10] = {0, }; + char* tmp_disp_text = NULL; + char* tmp_utt_text = NULL; + bundle* msg = bundle_create(); + snprintf(tmp_pid, 10, "%d", pid); + snprintf(tmp_continuous, 10, "%d", continuous); + + if (NULL == disp_text) { + tmp_disp_text = strdup("#NULL"); + } else { + tmp_disp_text = strdup(disp_text); + } + + if (NULL == utt_text) { + tmp_utt_text = strdup("#NULL"); + } else { + tmp_utt_text = strdup(utt_text); + } + + bundle_add_str(msg, VC_MANAGER_BUNDLE_METHOD, VCD_MANAGER_METHOD_DIALOG); + bundle_add_str(msg, VC_MANAGER_BUNDLE_MESSAGE, tmp_pid); + bundle_add_str(msg, VC_MANAGER_BUNDLE_DISP_TEXT, tmp_disp_text); + bundle_add_str(msg, VC_MANAGER_BUNDLE_UTT_TEXT, tmp_utt_text); + bundle_add_str(msg, VC_MANAGER_BUNDLE_CONTINUOUS, tmp_continuous); + + SLOG(LOG_DEBUG, TAG_VCD, ">>>> VCD SEND MESSAGE"); + + __send_msg(msg, VCD_CLIENT_TYPE_MANAGER); + bundle_free(msg); + free(tmp_disp_text); + free(tmp_utt_text); + + return VCD_ERROR_NONE; +} + +int vcdc_tidl_send_error_to_manager(int manager_pid, int reason, char *err_msg) +{ + SLOG(LOG_ERROR, TAG_VCD, "[TIDL] Send error signal to manager"); + + char tmp_reason[10] = {0, }; + char tmp_daemon_pid[10] = {0, }; + char *temp_msg = NULL; + + if (NULL == err_msg) { + SLOG(LOG_WARN, TAG_VCD, "[TIDL ERROR] Input parameter is NULL"); + temp_msg = strdup("#NULL"); + } else { + temp_msg = strdup(err_msg); + } + + bundle* msg = bundle_create(); + snprintf(tmp_reason, 10, "%d", reason); + snprintf(tmp_daemon_pid, 10, "%d", getpid()); + + bundle_add_str(msg, VC_MANAGER_BUNDLE_METHOD, VCD_MANAGER_METHOD_ERROR); + bundle_add_str(msg, VC_MANAGER_BUNDLE_REASON, tmp_reason); + bundle_add_str(msg, VC_MANAGER_BUNDLE_DAEMON_PID, tmp_daemon_pid); + bundle_add_str(msg, VC_MANAGER_BUNDLE_ERROR_MESSAGE, temp_msg); + + SLOG(LOG_DEBUG, TAG_VCD, ">>>> VCD SEND MESSAGE"); + + __send_msg(msg, VCD_CLIENT_TYPE_MANAGER); + bundle_free(msg); + + free(temp_msg); + temp_msg = NULL; + + return VCD_ERROR_NONE; +} + +// TODO: remove _tidl after remove dbus +// TODO: make client, widget error signal +int vcdc_tidl_send_error(int reason, char *err_msg) +{ + SLOG(LOG_ERROR, TAG_VCD, "[TIDL] Send error signal"); + + vcdc_tidl_send_error_to_manager(vcd_client_manager_get_pid(), reason, err_msg); + + return VCD_ERROR_NONE; +} + +int vcdc_send_request_set_private_data(int pid, const char* key, const char* data) +{ + SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Set private data"); + + char tmp_pid[10] = { 0, }; + + bundle* msg = bundle_create(); + snprintf(tmp_pid, 10, "%d", pid); + + bundle_add_str(msg, VC_MANAGER_BUNDLE_METHOD, VCD_MANAGER_METHOD_SET_PRIVATE_DATA); + bundle_add_str(msg, VC_MANAGER_BUNDLE_MESSAGE, tmp_pid); + bundle_add_str(msg, VC_MANAGER_BUNDLE_KEY, key); + bundle_add_str(msg, VC_MANAGER_BUNDLE_PRIVATE_DATA, data); + + + SLOG(LOG_DEBUG, TAG_VCD, ">>>> VCD SEND MESSAGE"); + + __send_msg(msg, VCD_CLIENT_TYPE_MANAGER); + bundle_free(msg); + + return VCD_ERROR_NONE; +} + +int vcdc_send_feedback_audio_format_to_manager(int manager_pid, int rate, vc_audio_channel_e channel, vce_audio_type_e audio_type) +{ + SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Send feedback audio format to manager"); + + char tmp_rate[10] = {0, }; + char tmp_channel[10] = {0, }; + char tmp_audio_type[10] = {0, }; + + bundle* msg = bundle_create(); + snprintf(tmp_rate, 10, "%d", rate); + snprintf(tmp_channel, 10, "%d", (int)channel); + snprintf(tmp_audio_type, 10, "%d", (int)audio_type); + bundle_add_str(msg, VC_MANAGER_BUNDLE_METHOD, VCD_MANAGER_METHOD_FEEDBACK_AUDIO_FORMAT); + bundle_add_str(msg, VC_MANAGER_BUNDLE_AUDIO_RATE, tmp_rate); + bundle_add_str(msg, VC_MANAGER_BUNDLE_AUDIO_CHANNEL, tmp_channel); + bundle_add_str(msg, VC_MANAGER_BUNDLE_AUDIO_TYPE, tmp_audio_type); + + SLOG(LOG_DEBUG, TAG_VCD, ">>>> VCD SEND MESSAGE"); + + __send_msg(msg, VCD_CLIENT_TYPE_MANAGER); + bundle_free(msg); + + return VCD_ERROR_NONE; +} + +int vcdc_send_feedback_streaming_to_manager(int manager_pid, int pid, int utt_id, vc_feedback_event_e event, char* buffer, int len) +{ + SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Send feedback streaming to manager"); + + char tmp_pid[10] = {0, }; + char tmp_utt_id[10] = {0, }; + char tmp_event[10] = {0, }; + + bundle* msg = bundle_create(); + snprintf(tmp_pid, 10, "%d", pid); + snprintf(tmp_utt_id, 10, "%d", utt_id); + snprintf(tmp_event, 10, "%d", (int)event); + bundle_add_str(msg, VC_MANAGER_BUNDLE_METHOD, VCD_MANAGER_METHOD_FEEDBACK_STREAMING); + bundle_add_str(msg, VC_MANAGER_BUNDLE_MESSAGE, tmp_pid); + bundle_add_str(msg, VC_MANAGER_BUNDLE_UTTID, tmp_utt_id); + bundle_add_str(msg, VC_MANAGER_BUNDLE_EVENT, tmp_event); + + rpc_port_stub_array_char_h streaming_data = NULL; + rpc_port_stub_array_char_create(&streaming_data); + if (NULL == streaming_data) { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to create data handle"); + return VCD_ERROR_OUT_OF_MEMORY; + } + + if (NULL != buffer && 0 < len) { + rpc_port_stub_array_char_set(streaming_data, (char*)buffer, len); + } else { + SLOG(LOG_ERROR, TAG_VCD, "[TIDL] buffer is empty"); + } + + SLOG(LOG_DEBUG, TAG_VCD, ">>>> VCD SEND MESSAGE"); + + pthread_mutex_lock(&g_mgr_tidl_info_mutex); + SLOG(LOG_INFO, TAG_VCD, "[TIDL] message to manager"); + manager_tidl_info_s* mgr_tidl_info = vcd_client_manager_get_tidl_info(); + + if (NULL == mgr_tidl_info) { + SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to get manager tidl info. pid(%d)", pid); + pthread_mutex_unlock(&g_mgr_tidl_info_mutex); + rpc_port_stub_array_char_destroy(streaming_data); + bundle_free(msg); + return VCD_ERROR_OPERATION_FAILED; + } + + rpc_port_stub_vc_mgr_send_buffer_cb_h handle = mgr_tidl_info->send_buffer_cb; + if (NULL == handle) { + SLOG(LOG_ERROR, TAG_VCD, "[TIDL] notify callback handle is null"); + pthread_mutex_unlock(&g_mgr_tidl_info_mutex); + rpc_port_stub_array_char_destroy(streaming_data); + bundle_free(msg); + return VCD_ERROR_OPERATION_FAILED; + } + + if (0 != rpc_port_stub_vc_mgr_send_buffer_cb_invoke(handle, streaming_data, msg)) { + SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to send msg"); + pthread_mutex_unlock(&g_mgr_tidl_info_mutex); + rpc_port_stub_array_char_destroy(streaming_data); + bundle_free(msg); + return VCD_ERROR_OPERATION_FAILED; + } + pthread_mutex_unlock(&g_mgr_tidl_info_mutex); + rpc_port_stub_array_char_destroy(streaming_data); + bundle_free(msg); + + return VCD_ERROR_NONE; +} + +void vcdc_send_request_set_foreground(int pid, int value) +{ + SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Set foreground"); + + manager_tidl_info_s* mgr_tidl_info = vcd_client_manager_get_tidl_info(); + + if (NULL == mgr_tidl_info) { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to get tidl info"); + return; + } + + if (!mgr_tidl_info->connected) { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Not Connected"); + return; + } + + rpc_port_proxy_vcd_mgr_invoke_set_foreground(mgr_tidl_info->rpc_h, pid, value); + + SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Request set foreground"); +} + +int vcdc_send_request_get_private_data(int pid, const char* key, char** data) +{ + SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Get private data"); + + manager_tidl_info_s* mgr_tidl_info = vcd_client_manager_get_tidl_info(); + + if (NULL == mgr_tidl_info) { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to get tidl info"); + return VC_ERROR_OPERATION_FAILED; + } + + if (!mgr_tidl_info->connected) { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Not Connected"); + return VC_ERROR_OPERATION_FAILED; + } + + char *tmp = NULL; + if (0 != rpc_port_proxy_vcd_mgr_invoke_get_private_data(mgr_tidl_info->rpc_h, pid, key, &tmp)) { + SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Request vcd manager get private data : Fail to invoke message"); + return VC_ERROR_OPERATION_FAILED; + } + SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Request vcd manager get private data : Success"); + + *data = tmp; + + return VC_ERROR_NONE; +} + +int vcdc_send_request_auth_enable(int pid) +{ + SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] auth enable"); + + manager_tidl_info_s* mgr_tidl_info = vcd_client_manager_get_tidl_info(); + + if (NULL == mgr_tidl_info) { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to get tidl info"); + return VC_ERROR_OPERATION_FAILED; + } + + if (!mgr_tidl_info->connected) { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Not Connected"); + return VC_ERROR_OPERATION_FAILED; + } + + if (0 != rpc_port_proxy_vcd_mgr_invoke_auth_enable(mgr_tidl_info->rpc_h, pid)) { + SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Request auth enable : Fail to invoke message"); + return VC_ERROR_OPERATION_FAILED; + } + SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Request auth enable : Success"); + + return VC_ERROR_NONE; +} + +int vcdc_send_request_auth_disable(int pid) +{ + SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] auth disable"); + + manager_tidl_info_s* mgr_tidl_info = vcd_client_manager_get_tidl_info(); + + if (NULL == mgr_tidl_info) { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to get tidl info"); + return VC_ERROR_OPERATION_FAILED; + } + + if (!mgr_tidl_info->connected) { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Not Connected"); + return VC_ERROR_OPERATION_FAILED; + } + + if (0 != rpc_port_proxy_vcd_mgr_invoke_auth_disable(mgr_tidl_info->rpc_h, pid)) { + SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Request auth disable : Fail to invoke message"); + return VC_ERROR_OPERATION_FAILED; + } + SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Request auth disable : Success"); + + return VC_ERROR_NONE; +} + +int vcdc_send_request_auth_start(int pid) +{ + SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] auth start"); + + manager_tidl_info_s* mgr_tidl_info = vcd_client_manager_get_tidl_info(); + + if (NULL == mgr_tidl_info) { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to get tidl info"); + return VC_ERROR_OPERATION_FAILED; + } + + if (!mgr_tidl_info->connected) { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Not Connected"); + return VC_ERROR_OPERATION_FAILED; + } + + if (0 != rpc_port_proxy_vcd_mgr_invoke_auth_start(mgr_tidl_info->rpc_h, pid)) { + SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Request auth start : Fail to invoke message"); + return VC_ERROR_OPERATION_FAILED; + } + SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Request auth start : Success"); + + return VC_ERROR_NONE; +} + +int vcdc_send_request_auth_stop(int pid) +{ + SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] auth stop"); + + manager_tidl_info_s* mgr_tidl_info = vcd_client_manager_get_tidl_info(); + + if (NULL == mgr_tidl_info) { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to get tidl info"); + return VC_ERROR_OPERATION_FAILED; + } + + if (!mgr_tidl_info->connected) { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Not Connected"); + return VC_ERROR_OPERATION_FAILED; + } + + if (0 != rpc_port_proxy_vcd_mgr_invoke_auth_stop(mgr_tidl_info->rpc_h, pid)) { + SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Request auth stop : Fail to invoke message"); + return VC_ERROR_OPERATION_FAILED; + } + SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Request auth stop : Success"); + + return VC_ERROR_NONE; +} + +int vcdc_send_request_auth_cancel(int pid) +{ + SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] auth cancel"); + + manager_tidl_info_s* mgr_tidl_info = vcd_client_manager_get_tidl_info(); + + if (NULL == mgr_tidl_info) { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to get tidl info"); + return VC_ERROR_OPERATION_FAILED; + } + + if (!mgr_tidl_info->connected) { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Not Connected"); + return VC_ERROR_OPERATION_FAILED; + } + + if (0 != rpc_port_proxy_vcd_mgr_invoke_auth_cancel(mgr_tidl_info->rpc_h, pid)) { + SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Request auth cancel : Fail to invoke message"); + return VC_ERROR_OPERATION_FAILED; + } + SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Request auth cancel : Success"); + + return VC_ERROR_NONE; +} diff --git a/server/vcd_tidl.h b/server/vcd_tidl.h new file mode 100644 index 0000000..6f339dc --- /dev/null +++ b/server/vcd_tidl.h @@ -0,0 +1,72 @@ +/* +* Copyright (c) 2022 Samsung Electronics Co., Ltd All Rights Reserved +* +* Licensed under the Apache License, Version 2.0 (the License); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an AS IS BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + + +#ifndef __VCD_TIDL_h__ +#define __VCD_TIDL_h__ + +#include "vcd_main.h" + +#ifdef __cplusplus +extern "C" { +#endif + +// typedef enum { +// VCD_CLIENT_TYPE_NORMAL, +// VCD_CLIENT_TYPE_WIDGET, +// VCD_CLIENT_TYPE_MANAGER +// } vcd_client_type_e; + +int vcd_mgr_tidl_open_connection(); + +int vcd_mgr_tidl_close_connection(); + +int vcdc_tidl_send_hello(int pid, vcd_client_type_e type); + +int vcdc_send_set_volume(int manager_pid, float volume); + +int vcdc_tidl_send_result(int pid, int manager_pid, int cmd_type); + +int vcdc_send_pre_result_to_manager(int manager_pid, int event, const char* pre_result); + +int vcdc_send_specific_engine_result_to_manager(int manager_pid, const char* engine_app_id, const char* event, const char* result); + +int vcdc_send_result_to_manager(int manager_pid, int result_type); + +int vcdc_send_speech_detected(int manager_pid); + +int vcdc_tidl_send_error(int reason, char *err_msg); + +int vcdc_tidl_send_error_to_manager(int manager_pid, int reason, char *err_msg); + +int vcdc_send_service_state(vcd_state_e state); + +int vcdc_send_dialog(int manager_pid, int pid, const char* disp_text, const char* utt_text, int continuous); + +int vcdc_send_request_set_private_data(int pid, const char* key, const char* data); + +int vcdc_send_request_get_private_data(int pid, const char* key, char** data); + +/* for TTS feedback */ +int vcdc_send_feedback_audio_format_to_manager(int manager_pid, int rate, vc_audio_channel_e channel, vce_audio_type_e audio_type); + +int vcdc_send_feedback_streaming_to_manager(int manager_pid, int pid, int utt_id, vc_feedback_event_e event, char* buffer, int len); + +#ifdef __cplusplus +} +#endif + +#endif /* __VCD_TIDL_h__ */ diff --git a/server/vce.c b/server/vce.c index fae0fbb..5353ea0 100644 --- a/server/vce.c +++ b/server/vce.c @@ -20,6 +20,7 @@ #include #include #include "vcd_dbus.h" +#include "vcd_tidl.h" #include "vcd_main.h" #include "vcd_server.h" diff --git a/tidl/vc_mgr.tidl b/tidl/vc_mgr.tidl new file mode 100644 index 0000000..f790247 --- /dev/null +++ b/tidl/vc_mgr.tidl @@ -0,0 +1,26 @@ +interface vc_mgr { + void notify_cb(bundle msg) delegate; + void send_buffer_cb(array data_in, bundle msg) delegate; + void register_cb(int pid, notify_cb notify_callback, send_buffer_cb send_buffer_callback) async; + + int initialize(in int pid, in int audio_streaming_mode, out int service_state, out int foreground, out int daemon_pid); + int finalize(in int pid); + int set_command(in int pid); + int unset_command(in int pid); + int demandable_client(in int pid); + int set_audio_type(in int pid, string audio_type); + int get_audio_type(in int pid, out string audio_type); + void set_private_data(in int pid, string key, string data) async; + int get_private_data(in int pid, string key, out string data); + int set_client_info(in int pid); + int set_domain(in int pid, string domain); + void do_action(in int pid, int type, string send_event) async; + int start(in int pid, in int recognition_mode, bool exclusive_command_option, bool start_by_client, int disabled_cmd_type); + int stop(in int pid); + int cancel(in int pid); + void set_audio_streaming_mode(in int pid, in int mode) async; + void send_specific_engine_request(in int pid, in string engine_app_id, in string event, in string request) async; + void send_result_selection(in int pid) async; + void send_audio_streaming(in int pid, in int event, array data_in) async; + void send_utterance_status(in int utt_id, in int utt_status) async; +} \ No newline at end of file diff --git a/tidl/vcd_mgr.tidl b/tidl/vcd_mgr.tidl new file mode 100644 index 0000000..57557f8 --- /dev/null +++ b/tidl/vcd_mgr.tidl @@ -0,0 +1,9 @@ +interface vcd_mgr { + void set_foreground(in int pid, in int value) async; + int get_private_data(in int pid, in string key, out string data); + int auth_enable(in int pid); + int auth_disable(in int pid); + int auth_start(in int pid); + int auth_stop(in int pid); + int auth_cancel(in int pid); +} \ No newline at end of file -- 2.7.4 From c6f99860c7b8de38a4942f45aec4b6b5efe755d7 Mon Sep 17 00:00:00 2001 From: "wn.jang" Date: Wed, 13 Apr 2022 19:38:09 +0900 Subject: [PATCH 11/16] Add metadata profile xml file Change-Id: I34c62f51fef48d29ce505c5ba010f72d7b4194ba --- packaging/metadata-profile.xml | 74 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 packaging/metadata-profile.xml diff --git a/packaging/metadata-profile.xml b/packaging/metadata-profile.xml new file mode 100644 index 0000000..6149419 --- /dev/null +++ b/packaging/metadata-profile.xml @@ -0,0 +1,74 @@ + + + + + Y + 1.0 + + Write a VC engine name. + + + It does not work if there is no value. + + + + + + + + Y + 1.0 + + Write supported langueges. + + + Language specified as an ISO 3166 alpha-2 two-letter country code followed by ISO 639-1 for the two-letter language code (for example, "ko_KR" for Korean, "en_US" for American English) + + + + + + + + Y + 1.0 + + false - the credential key is not necessary. + true - the credential key is necessary. + + + Default value is false. + + + + + + + + Y + 1.0 + + Write a setting app name for vc engine. + + + The setting app does not launch if there is no value. + + + + + + + + Y + 1.0 + + Write whether to support non-fixed type command + + + Default value is false. + + + + + + \ No newline at end of file -- 2.7.4 From a88b50ad66a722e2b44735155623da2b8d2a75e0 Mon Sep 17 00:00:00 2001 From: ulgal-park Date: Tue, 15 Mar 2022 12:04:27 +0900 Subject: [PATCH 12/16] Replace IPC between widget and server from dbus to tidl Change-Id: I08d104ed3511cfb0b251062e5521664105ae2cb3 --- client/CMakeLists.txt | 4 +- client/vc_mgr.c | 1 + client/vc_mgr_tidl.c | 2 + client/vc_widget.c | 34 +- client/vc_widget_dbus.c | 1126 --------------------- client/vc_widget_dbus.h | 54 - client/vc_widget_tidl.c | 621 ++++++++++++ client/vc_widget_tidl.h | 54 + common/vc_defs.h | 8 + packaging/voice-control.spec | 5 + server/CMakeLists.txt | 2 + server/vcd_client_data.c | 183 +++- server/vcd_client_data.h | 27 +- server/vcd_dbus.c | 190 +--- server/vcd_dbus.h | 8 - server/vcd_server.c | 4 +- server/vcd_tidl.c | 2256 ++++++++++++++++++++++++++++-------------- server/vcd_tidl.h | 19 +- tidl/vc_widget.tidl | 14 + tidl/vcd_widget.tidl | 3 + 20 files changed, 2479 insertions(+), 2136 deletions(-) delete mode 100644 client/vc_widget_dbus.c delete mode 100644 client/vc_widget_dbus.h create mode 100644 client/vc_widget_tidl.c create mode 100644 client/vc_widget_tidl.h create mode 100644 tidl/vc_widget.tidl create mode 100644 tidl/vcd_widget.tidl diff --git a/client/CMakeLists.txt b/client/CMakeLists.txt index 5815fa0..ab5f35f 100644 --- a/client/CMakeLists.txt +++ b/client/CMakeLists.txt @@ -22,7 +22,9 @@ SET(SETTING_SRCS SET(WIDGET_SRCS vc_widget.c vc_widget_client.c - vc_widget_dbus.c + vc_widget_tidl.c + vc_widget_proxy.c + vc_widget_stub.c ../common/vc_cmd_db.c ../common/vc_command.c ../common/vc_command_util.c diff --git a/client/vc_mgr.c b/client/vc_mgr.c index c02b61b..9fd7862 100755 --- a/client/vc_mgr.c +++ b/client/vc_mgr.c @@ -557,6 +557,7 @@ static Eina_Bool __send_hello_message(void *data) g_send_hello_timer = NULL; return EINA_FALSE; } else { + // TODO: discuss when updating connect/reconnect g_tidl_send_hello_count++; return EINA_TRUE; } diff --git a/client/vc_mgr_tidl.c b/client/vc_mgr_tidl.c index fc9781f..27154fc 100755 --- a/client/vc_mgr_tidl.c +++ b/client/vc_mgr_tidl.c @@ -582,6 +582,8 @@ int vc_mgr_tidl_open_connection() char* engine_app_id = vconf_get_str(VC_ENGINE_DB_DEFAULT); if (NULL == engine_app_id) { SLOG(LOG_ERROR, TAG_VCM, "[TIDL] vconf not found"); + free(g_proxy_tidl_info); + g_proxy_tidl_info = NULL; pthread_mutex_unlock(&g_tidl_mutex); return VC_ERROR_ENGINE_NOT_FOUND; } diff --git a/client/vc_widget.c b/client/vc_widget.c index 92e0951..c0d1b1e 100644 --- a/client/vc_widget.c +++ b/client/vc_widget.c @@ -23,7 +23,7 @@ #include "vc_info_parser.h" #include "vc_main.h" #include "vc_widget_client.h" -#include "vc_widget_dbus.h" +#include "vc_widget_tidl.h" #include "voice_control_command.h" #include "voice_control_command_expand.h" #include "voice_control_internal.h" @@ -174,7 +174,7 @@ int vc_widget_initialize(vc_h* vc_w) } if (0 == vc_widget_client_get_count()) { - if (0 != vc_widget_dbus_open_connection()) { + if (0 != vc_widget_tidl_open_connection()) { SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to open connection"); return VC_ERROR_OPERATION_FAILED; } @@ -216,7 +216,7 @@ int vc_widget_initialize(vc_h* vc_w) static void __vc_widget_internal_unprepare(vc_h vc_w) { - int ret = vc_widget_dbus_request_finalize(getpid()); + int ret = vc_widget_tidl_request_finalize(getpid()); if (0 != ret) { SLOG(LOG_WARN, TAG_VCW, "[ERROR] Fail to request finalize : %s", __vc_widget_get_error_code(ret)); } @@ -333,8 +333,7 @@ int vc_widget_deinitialize(vc_h vc_w) if (0 != ret) { SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to finalize DB, ret(%d)", ret); } - - if (0 != vc_widget_dbus_close_connection()) { + if (0 != vc_widget_tidl_close_connection()) { SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to close connection"); } } @@ -352,13 +351,13 @@ static Eina_Bool __focus_changed_cb(void *data, int type, void *event) int ret; if (ECORE_WL2_EVENT_FOCUS_IN == type) { SLOG(LOG_DEBUG, TAG_VCW, "@@@ Set foreground"); - ret = vc_widget_dbus_set_foreground(getpid(), true); + ret = vc_widget_tidl_set_foreground(getpid(), true); if (0 != ret) { SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to set foreground (true) : %d", ret); } } else if (ECORE_WL2_EVENT_FOCUS_OUT == type) { SLOG(LOG_DEBUG, TAG_VCW, "@@@ Set background"); - ret = vc_widget_dbus_set_foreground(getpid(), false); + ret = vc_widget_tidl_set_foreground(getpid(), false); if (0 != ret) { SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to set foreground (false) : %d", ret); } @@ -421,7 +420,7 @@ static Eina_Bool __vc_widget_connect_daemon(void *data) /* request initialization */ int service_state = 0; - ret = vc_widget_dbus_request_initialize(getpid(), &service_state, &g_daemon_pid); + ret = vc_widget_tidl_request_initialize(getpid(), &service_state, &g_daemon_pid); if (VC_ERROR_ENGINE_NOT_FOUND == ret) { SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to initialize : %s", __vc_widget_get_error_code(ret)); @@ -481,7 +480,7 @@ static Eina_Bool __vc_widget_connect_daemon(void *data) int status = aul_app_get_status(appid); if (status == STATUS_FOCUS) { SLOG(LOG_DEBUG, TAG_VCW, "@@@ Set foreground"); - ret = vc_widget_dbus_set_foreground(getpid(), true); + ret = vc_widget_tidl_set_foreground(getpid(), true); if (0 != ret) { SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to set foreground (true) : %d", ret); } @@ -535,12 +534,15 @@ static void __start_prepare_thread(void *data, Ecore_Thread *thread) return; } - ret = vc_widget_dbus_request_hello(); + ret = vc_widget_tidl_request_hello(); if (ret == 0) { SLOG(LOG_DEBUG, TAG_VCW, "Success to request hello. retry count(%d)", retry_count); break; } else { retry_count++; + // TODO: discuss when updating connect/reconnect + SLOG(LOG_DEBUG, TAG_VCW, "Fail to request TIDL hello. failed(%d)", retry_count); + usleep(200000); } } @@ -703,7 +705,7 @@ int vc_widget_enable_asr_result(vc_h vc_w, bool enable) int ret = -1; do { - ret = vc_widget_dbus_request_enable_asr_result(getpid(), enable); + ret = vc_widget_tidl_request_enable_asr_result(getpid(), enable); if (0 != ret) { if (VC_ERROR_TIMED_OUT != ret) { SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to enable asr result : %s", __vc_widget_get_error_code(ret)); @@ -903,7 +905,7 @@ int vc_widget_set_foreground(vc_h vc_w, bool value) } SLOG(LOG_DEBUG, TAG_VCW, "Set foreground : pid(%d) value(%s)", getpid(), value ? "true" : "false"); - int ret = vc_widget_dbus_set_foreground(getpid(), value); + int ret = vc_widget_tidl_set_foreground(getpid(), value); if (0 != ret) { ret = vc_config_convert_error_code((vc_config_error_e)ret); SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to set foreground : %s", __vc_widget_get_error_code(ret)); @@ -1013,7 +1015,7 @@ int vc_widget_start(bool stop_by_silence, vc_cmd_group_h vc_group) } else { int count = 0; do { - ret = vc_widget_dbus_request_start(getpid(), stop_by_silence); + ret = vc_widget_tidl_request_start(getpid(), stop_by_silence); if (0 != ret) { if (VC_ERROR_TIMED_OUT != ret) { SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to request start : %s", __vc_widget_get_error_code(ret)); @@ -1095,7 +1097,7 @@ int vc_widget_stop() int count = 0; do { - ret = vc_widget_dbus_request_stop(getpid()); + ret = vc_widget_tidl_request_stop(getpid()); if (0 != ret) { if (VC_ERROR_TIMED_OUT != ret) { SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to request stop : %s", __vc_widget_get_error_code(ret)); @@ -1152,7 +1154,7 @@ int vc_widget_cancel(vc_h vc_w) int ret = -1; do { - ret = vc_widget_dbus_request_cancel(getpid()); + ret = vc_widget_tidl_request_cancel(getpid()); if (0 != ret) { if (VC_ERROR_TIMED_OUT != ret) { SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to request cancel : %s", __vc_widget_get_error_code(ret)); @@ -1311,7 +1313,7 @@ static Eina_Bool __vc_widget_start_recording(void *data) ret = -1; count = 0; while (0 != ret) { - ret = vc_widget_dbus_request_start_recording(getpid(), widget_command); + ret = vc_widget_tidl_request_start_recording(getpid(), widget_command); if (0 != ret) { if (VC_ERROR_TIMED_OUT != ret) { SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to request start recording to daemon : %s", __vc_widget_get_error_code(ret)); diff --git a/client/vc_widget_dbus.c b/client/vc_widget_dbus.c deleted file mode 100644 index a6f2769..0000000 --- a/client/vc_widget_dbus.c +++ /dev/null @@ -1,1126 +0,0 @@ -/* -* Copyright (c) 2011-2015 Samsung Electronics Co., Ltd All Rights Reserved -* -* Licensed under the Apache License, Version 2.0 (the License); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an AS IS BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - - -#include - -#include "vc_main.h" -#include "vc_widget_client.h" -#include "vc_widget_dbus.h" - - -static pthread_mutex_t g_w_dbus_mutex = PTHREAD_MUTEX_INITIALIZER; -static pthread_mutex_t g_w_init_mutex = PTHREAD_MUTEX_INITIALIZER; - -static int g_w_waiting_time = 3000; -static int g_w_waiting_short_time = 200; -static bool g_is_connection_opened = false; - -static Ecore_Fd_Handler* g_w_fd_handler = NULL; - -static DBusConnection* g_w_conn_sender = NULL; -static DBusConnection* g_w_conn_listener = NULL; - -extern int __vc_widget_cb_error(int reason, int daemon_pid, char* msg); - -extern void __vc_widget_cb_show_tooltip(int pid, bool show); - -extern void __vc_widget_cb_result(); - -extern bool __vc_widget_cb_asr_result(int event, const char* asr_result); - -extern int __vc_widget_cb_service_state(int state); - - -static Eina_Bool widget_listener_event_callback(void* data, Ecore_Fd_Handler *fd_handler) -{ - if (NULL == g_w_conn_listener) return ECORE_CALLBACK_RENEW; - - dbus_connection_read_write_dispatch(g_w_conn_listener, 50); - - while (1) { - DBusMessage* msg = NULL; - msg = dbus_connection_pop_message(g_w_conn_listener); - - /* loop again if we haven't read a message */ - if (NULL == msg) { - break; - } - - SLOG(LOG_DEBUG, TAG_VCW, "[DEBUG] Message is arrived"); - - DBusError err; - dbus_error_init(&err); - - char if_name[64] = {0, }; - snprintf(if_name, 64, "%s", VC_WIDGET_SERVICE_INTERFACE); - - if (dbus_message_is_method_call(msg, if_name, VCD_WIDGET_METHOD_HELLO)) { - SLOG(LOG_DEBUG, TAG_VCW, "@@@ Get widget hello"); - int pid = 0; - int response = -1; - - dbus_message_get_args(msg, &err, DBUS_TYPE_INT32, &pid, DBUS_TYPE_INVALID); - - if (dbus_error_is_set(&err)) { - SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Dbus Error (%s)", err.message); - dbus_error_free(&err); - } - - if (pid > 0) { - SLOG(LOG_DEBUG, TAG_VCW, "@@ vc widget get hello : pid(%d) ", pid); - response = 1; - } else { - SLOG(LOG_ERROR, TAG_VCW, "@@ vc widget get hello : invalid pid "); - } - - DBusMessage* reply = NULL; - reply = dbus_message_new_method_return(msg); - - if (NULL != reply) { - dbus_message_append_args(reply, DBUS_TYPE_INT32, &response, DBUS_TYPE_INVALID); - - if (!dbus_connection_send(g_w_conn_listener, reply, NULL)) - SLOG(LOG_ERROR, TAG_VCW, "@@ vc widget get hello : fail to send reply"); - else - SLOG(LOG_DEBUG, TAG_VCW, "@@ vc widget get hello : result(%d)", response); - - dbus_connection_flush(g_w_conn_listener); - dbus_message_unref(reply); - } else { - SLOG(LOG_ERROR, TAG_VCW, "@@ vc widget get hello : fail to create reply message"); - } - - SLOG(LOG_DEBUG, TAG_VCW, "@@@"); - } /* VCD_WIDGET_METHOD_HELLO */ - - else if (dbus_message_is_signal(msg, if_name, VCD_WIDGET_METHOD_SET_SERVICE_STATE)) { - int state = 0; - - dbus_message_get_args(msg, &err, DBUS_TYPE_INT32, &state, DBUS_TYPE_INVALID); - if (dbus_error_is_set(&err)) { - SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Get arguments error (%s)", err.message); - dbus_error_free(&err); - } - - SLOG(LOG_DEBUG, TAG_VCW, "@@ service state changed : %d", state); - - __vc_widget_cb_service_state(state); - - } /* VCD_WIDGET_METHOD_SET_SERVICE_STATE */ - - else if (dbus_message_is_method_call(msg, if_name, VCD_WIDGET_METHOD_SHOW_TOOLTIP)) { - SLOG(LOG_DEBUG, TAG_VCW, "@@@ Show / Hide tooltip"); - int pid = 0; - int show = 0; - - dbus_message_get_args(msg, &err, - DBUS_TYPE_INT32, &pid, - DBUS_TYPE_INT32, &show, - DBUS_TYPE_INVALID); - - if (dbus_error_is_set(&err)) { - SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Dbus Error (%s)", err.message); - dbus_error_free(&err); - } - - if (pid > 0) { - SLOG(LOG_DEBUG, TAG_VCW, "@@ vc widget show tooltip : pid(%d), show(%d)", pid, show); - __vc_widget_cb_show_tooltip(pid, (bool)show); - } else { - SLOG(LOG_ERROR, TAG_VCW, "@@ vc widget show tooltip : invalid pid"); - } - - SLOG(LOG_DEBUG, TAG_VCW, "@@@"); - } /* VCD_WIDGET_METHOD_SHOW_TOOLTIP */ - - else if (dbus_message_is_method_call(msg, if_name, VCD_WIDGET_METHOD_RESULT)) { - SLOG(LOG_DEBUG, TAG_VCW, "@@@ Get widget result"); - - __vc_widget_cb_result(); - - SLOG(LOG_DEBUG, TAG_VCW, "@@@"); - - } /* VCD_WIDGET_METHOD_RESULT */ - - else if (dbus_message_is_method_call(msg, if_name, VCD_WIDGET_METHOD_ASR_RESULT)) { - SLOG(LOG_DEBUG, TAG_VCW, "@@@ Get widget asr result"); - int ret = 0; - int event = -1; - char* asr_result = NULL; - - dbus_message_get_args(msg, &err, - DBUS_TYPE_INT32, &event, - DBUS_TYPE_STRING, &asr_result, - DBUS_TYPE_INVALID); - - if (false == __vc_widget_cb_asr_result(event, asr_result)) - ret = 0; - else - ret = 1; - - DBusMessage* reply = dbus_message_new_method_return(msg); - if (NULL != reply) { - dbus_message_append_args(reply, DBUS_TYPE_INT32, &ret, DBUS_TYPE_INVALID); - if (!dbus_connection_send(g_w_conn_listener, reply, NULL)) - SLOG(LOG_ERROR, TAG_VCW, "@@ vc widget get asr result : fail to send reply"); - else - SLOG(LOG_DEBUG, TAG_VCW, "@@ vc widget get asr result, event(%d), asr_result(%s), consumed(%d)", event, asr_result, ret); - - dbus_connection_flush(g_w_conn_listener); - dbus_message_unref(reply); - } else { - SLOG(LOG_ERROR, TAG_VCW, "@@ vc widget asr get result : fail to create reply message"); - } - - SLOG(LOG_DEBUG, TAG_VCW, "@@@"); - - } /* VCD_WIDGET_METHOD_ASR_RESULT */ - - else if (dbus_message_is_signal(msg, if_name, VCD_WIDGET_METHOD_ERROR)) { - SLOG(LOG_DEBUG, TAG_VCW, "@@@ Get widget error"); - int reason; - int daemon_pid; - char* err_msg; - - dbus_message_get_args(msg, &err, - DBUS_TYPE_INT32, &reason, - DBUS_TYPE_INT32, &daemon_pid, - DBUS_TYPE_STRING, &err_msg, - DBUS_TYPE_INVALID); - - if (dbus_error_is_set(&err)) { - SLOG(LOG_ERROR, TAG_VCW, "@@ vc widget get error message : Get arguments error (%s)", err.message); - dbus_error_free(&err); - } else { - SLOG(LOG_DEBUG, TAG_VCW, "@@ vc widget get error message : reason(%d), daemon_pid(%d), msg(%s)", reason, daemon_pid, err_msg); - __vc_widget_cb_error(reason, daemon_pid, err_msg); - } - - /* - reply = dbus_message_new_method_return(msg); - - if (NULL != reply) { - if (!dbus_connection_send(g_w_conn_listener, reply, NULL)) - SLOG(LOG_ERROR, TAG_VCW, "@@ vc widget error message : fail to send reply"); - else - SLOG(LOG_DEBUG, TAG_VCW, "@@ vc widget error message"); - - dbus_connection_flush(g_w_conn_listener); - dbus_message_unref(reply); - } else { - SLOG(LOG_ERROR, TAG_VCW, "@@ vc widget error message : fail to create reply message"); - } - */ - - SLOG(LOG_DEBUG, TAG_VCW, "@@@"); - } /* VCD_WIDGET_METHOD_ERROR */ - - else if (dbus_message_is_signal(msg, "org.freedesktop.DBus", "NameOwnerChanged")) { - SLOG(LOG_DEBUG, TAG_VCW, "@@@ Owner Changed"); - DBusError err; - dbus_error_init(&err); - - /* remove a rule for daemon error */ - char rule_err[256] = {0, }; - snprintf(rule_err, 256, "sender='org.freedesktop.DBus',path='/org/freedesktop/DBus',interface='org.freedesktop.DBus',member='NameOwnerChanged',type='signal',arg0='%s'", VC_SERVER_SERVICE_INTERFACE); - dbus_bus_remove_match(g_w_conn_listener, rule_err, &err); - dbus_connection_flush(g_w_conn_listener); - - if (dbus_error_is_set(&err)) { - SLOG(LOG_ERROR, TAG_VCW, "Match Error (%s)", err.message); - dbus_error_free(&err); - } - __vc_widget_cb_error(VC_ERROR_SERVICE_RESET, -1, "Daemon Reset"); - SLOG(LOG_DEBUG, TAG_VCW, "@@@"); - } /* NameOwnerChanged */ - - else { - const char* sender = dbus_message_get_sender(msg); - const char* destination = dbus_message_get_destination(msg); - const char* path = dbus_message_get_path(msg); - const char* interf = dbus_message_get_interface(msg); - const char* member = dbus_message_get_member(msg); - int type = dbus_message_get_type(msg); - SLOG(LOG_ERROR, TAG_VCW, "[INFO] Message is NOT valid, sender(%s), destination(%s), path(%s), interface(%s), member(%s), type(%d)", sender, destination, path, interf, member, type); - dbus_message_unref(msg); - break; - } - - /* free the message */ - dbus_message_unref(msg); - } /* while(1) */ - - return ECORE_CALLBACK_PASS_ON; -} - -static void __vc_widget_dbus_connection_free() -{ - if (NULL != g_w_conn_listener) { - dbus_connection_close(g_w_conn_listener); - dbus_connection_unref(g_w_conn_listener); - g_w_conn_listener = NULL; - } - if (NULL != g_w_conn_sender) { - dbus_connection_close(g_w_conn_sender); - dbus_connection_unref(g_w_conn_sender); - g_w_conn_sender = NULL; - } -} - -int vc_widget_dbus_open_connection() -{ - pthread_mutex_lock(&g_w_dbus_mutex); - - if (NULL != g_w_conn_sender && NULL != g_w_conn_listener) { - SLOG(LOG_WARN, TAG_VCW, "Already existed connection "); - pthread_mutex_unlock(&g_w_dbus_mutex); - return VC_ERROR_NONE; - } - - DBusError err; - int ret; - - /* initialize the error value */ - dbus_error_init(&err); - - /* connect to the DBUS system bus, and check for errors */ - g_w_conn_sender = dbus_bus_get_private(DBUS_BUS_SESSION, &err); - - if (dbus_error_is_set(&err)) { - SLOG(LOG_ERROR, TAG_VCW, "Dbus Connection Error (%s)", err.message); - dbus_error_free(&err); - } - - if (NULL == g_w_conn_sender) { - SLOG(LOG_ERROR, TAG_VCW, "Fail to get dbus connection "); - pthread_mutex_unlock(&g_w_dbus_mutex); - return VC_ERROR_OPERATION_FAILED; - } - - dbus_connection_set_exit_on_disconnect(g_w_conn_sender, false); - - g_w_conn_listener = dbus_bus_get_private(DBUS_BUS_SESSION, &err); - - if (dbus_error_is_set(&err)) { - SLOG(LOG_ERROR, TAG_VCW, "Dbus Connection Error (%s)", err.message); - dbus_error_free(&err); - } - - if (NULL == g_w_conn_listener) { - SLOG(LOG_ERROR, TAG_VCW, "Fail to get dbus connection "); - __vc_widget_dbus_connection_free(); - pthread_mutex_unlock(&g_w_dbus_mutex); - return VC_ERROR_OPERATION_FAILED; - } - - dbus_connection_set_exit_on_disconnect(g_w_conn_listener, false); - - int pid = getpid(); - - char service_name[64]; - memset(service_name, '\0', 64); - snprintf(service_name, 64, "%s%d", VC_WIDGET_SERVICE_NAME, pid); - - SLOG(LOG_DEBUG, TAG_VCW, "service name is %s", service_name); - - /* register our name on the bus, and check for errors */ - ret = dbus_bus_request_name(g_w_conn_listener, service_name, DBUS_NAME_FLAG_REPLACE_EXISTING , &err); - - if (dbus_error_is_set(&err)) { - SLOG(LOG_ERROR, TAG_VCW, "Name Error (%s)", err.message); - dbus_error_free(&err); - } - - if (DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER != ret) { - SLOG(LOG_ERROR, TAG_VCW, "fail dbus_bus_request_name()"); - __vc_widget_dbus_connection_free(); - pthread_mutex_unlock(&g_w_dbus_mutex); - return -2; - } - - if (NULL != g_w_fd_handler) { - SLOG(LOG_WARN, TAG_VCW, "The handler already exists."); - __vc_widget_dbus_connection_free(); - pthread_mutex_unlock(&g_w_dbus_mutex); - return 0; - } - - char rule[128] = {0, }; - snprintf(rule, 128, "type='signal',interface='%s'", VC_WIDGET_SERVICE_INTERFACE); - - /* add a rule for which messages we want to see */ - dbus_bus_add_match(g_w_conn_listener, rule, &err); - - if (dbus_error_is_set(&err)) { - SLOG(LOG_ERROR, TAG_VCW, "Match Error (%s)", err.message); - dbus_error_free(&err); - __vc_widget_dbus_connection_free(); - pthread_mutex_unlock(&g_w_dbus_mutex); - return VC_ERROR_OPERATION_FAILED; - } - - int fd = 0; - if (1 != dbus_connection_get_unix_fd(g_w_conn_listener, &fd)) { - SLOG(LOG_ERROR, TAG_VCW, "fail to get fd from dbus "); - __vc_widget_dbus_connection_free(); - pthread_mutex_unlock(&g_w_dbus_mutex); - return VC_ERROR_OPERATION_FAILED; - } else { - SLOG(LOG_DEBUG, TAG_VCW, "Get fd from dbus : %d", fd); - } - - g_w_fd_handler = ecore_main_fd_handler_add(fd, ECORE_FD_READ, (Ecore_Fd_Cb)widget_listener_event_callback, g_w_conn_listener, NULL, NULL); - - if (NULL == g_w_fd_handler) { - SLOG(LOG_ERROR, TAG_VCW, "fail to get fd handler from ecore "); - __vc_widget_dbus_connection_free(); - pthread_mutex_unlock(&g_w_dbus_mutex); - return VC_ERROR_OPERATION_FAILED; - } - - g_is_connection_opened = true; - - pthread_mutex_unlock(&g_w_dbus_mutex); - - SLOG(LOG_INFO, TAG_VCW, "[INFO] widget dbus connection is opened"); - - return 0; -} - -int vc_widget_dbus_close_connection() -{ - pthread_mutex_lock(&g_w_dbus_mutex); - - DBusError err; - dbus_error_init(&err); - - if (NULL != g_w_fd_handler) { - ecore_main_fd_handler_del(g_w_fd_handler); - g_w_fd_handler = NULL; - } - - if (NULL != g_w_conn_listener) { - int pid = getpid(); - - char service_name[64]; - memset(service_name, '\0', 64); - snprintf(service_name, 64, "%s%d", VC_WIDGET_SERVICE_NAME, pid); - - dbus_bus_release_name(g_w_conn_listener, service_name, &err); - - if (dbus_error_is_set(&err)) { - SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Dbus Error (%s)", err.message); - dbus_error_free(&err); - } - } - - __vc_widget_dbus_connection_free(); - - g_is_connection_opened = false; - - pthread_mutex_unlock(&g_w_dbus_mutex); - - SLOG(LOG_INFO, TAG_VCW, "[INFO] widget dbus connection is closed"); - - return 0; -} - -int vc_widget_dbus_reconnect() -{ - if (!g_w_conn_sender || !g_w_conn_listener) { - vc_widget_dbus_close_connection(); - - if (0 != vc_widget_dbus_open_connection()) { - SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to reconnect"); - return -1; - } - - SLOG(LOG_DEBUG, TAG_VCW, "[DBUS] Reconnect"); - return 0; - } - - bool sender_connected = dbus_connection_get_is_connected(g_w_conn_sender); - bool listener_connected = dbus_connection_get_is_connected(g_w_conn_listener); - SLOG(LOG_DEBUG, TAG_VCW, "[DBUS] Sender(%s) Listener(%s)", - sender_connected ? "Connected" : "Not connected", listener_connected ? "Connected" : "Not connected"); - - if (false == sender_connected || false == listener_connected) { - vc_widget_dbus_close_connection(); - - if (0 != vc_widget_dbus_open_connection()) { - SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to reconnect"); - return -1; - } - - SLOG(LOG_DEBUG, TAG_VCW, "[DBUS] Reconnect"); - } - - return 0; -} - -static int __dbus_check() -{ - if (NULL == g_w_conn_sender || NULL == g_w_conn_listener) { - SLOG(LOG_ERROR, TAG_VCW, "[ERROR] NULL connection"); - return vc_widget_dbus_reconnect(); - } - return 0; -} - -int vc_widget_dbus_request_hello() -{ - if (0 != __dbus_check()) { - return VC_ERROR_OPERATION_FAILED; - } - - DBusMessage* msg; - - msg = dbus_message_new_method_call( - VC_SERVER_SERVICE_NAME, - VC_SERVER_SERVICE_OBJECT_PATH, - VC_SERVER_SERVICE_INTERFACE, - VC_METHOD_HELLO); - - if (NULL == msg) { - SLOG(LOG_ERROR, TAG_VCW, "@@ Request vc hello : Fail to make message"); - return VC_ERROR_OPERATION_FAILED; - } - - DBusError err; - dbus_error_init(&err); - - DBusMessage* result_msg = NULL; - int result = 0; - - result_msg = dbus_connection_send_with_reply_and_block(g_w_conn_sender, msg, g_w_waiting_short_time, &err); - - if (dbus_error_is_set(&err)) { - if (!strncmp(err.name, DBUS_ERROR_SERVICE_UNKNOWN, strlen(err.name))) - usleep(500000); - dbus_error_free(&err); - } - - dbus_message_unref(msg); - - if (NULL != result_msg) { - dbus_message_unref(result_msg); - result = 0; - } else { - result = VC_ERROR_TIMED_OUT; - } - - return result; -} - - -int vc_widget_dbus_request_initialize(int pid, int* service_state, int* daemon_pid) -{ - pthread_mutex_lock(&g_w_init_mutex); - if (0 != __dbus_check()) { - pthread_mutex_unlock(&g_w_init_mutex); - return VC_ERROR_OPERATION_FAILED; - } - - DBusMessage* msg; - - msg = dbus_message_new_method_call( - VC_SERVER_SERVICE_NAME, - VC_SERVER_SERVICE_OBJECT_PATH, - VC_SERVER_SERVICE_INTERFACE, - VC_WIDGET_METHOD_INITIALIZE); - - if (NULL == msg) { - SLOG(LOG_ERROR, TAG_VCW, "@@ vc widget initialize : Fail to make message "); - pthread_mutex_unlock(&g_w_init_mutex); - return VC_ERROR_OPERATION_FAILED; - } else { - SLOG(LOG_DEBUG, TAG_VCW, "@@ vc widget initialize : pid(%d)", pid); - } - - dbus_message_append_args(msg, - DBUS_TYPE_INT32, &pid, - DBUS_TYPE_INVALID); - - DBusError err; - dbus_error_init(&err); - - DBusMessage* result_msg; - int result = VC_ERROR_OPERATION_FAILED; - - result_msg = dbus_connection_send_with_reply_and_block(g_w_conn_sender, msg, g_w_waiting_time, &err); - dbus_message_unref(msg); - - if (dbus_error_is_set(&err)) { - SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Dbus Error (%s)", err.message); - dbus_error_free(&err); - } - - if (NULL != result_msg) { - int tmp_service_state = 0; - int tmp_daemon_pid = 0; - dbus_message_get_args(result_msg, &err, - DBUS_TYPE_INT32, &result, - DBUS_TYPE_INT32, &tmp_service_state, - DBUS_TYPE_INT32, &tmp_daemon_pid, - DBUS_TYPE_INVALID); - - if (dbus_error_is_set(&err)) { - SLOG(LOG_ERROR, TAG_VCW, "@@ Get arguments error (%s)", err.message); - dbus_error_free(&err); - result = VC_ERROR_OPERATION_FAILED; - } - - dbus_message_unref(result_msg); - - if (0 == result) { - *service_state = tmp_service_state; - *daemon_pid = tmp_daemon_pid; - - /* add a rule for daemon error */ - char rule_err[256] = {0, }; - snprintf(rule_err, 256, "sender='org.freedesktop.DBus',path='/org/freedesktop/DBus',interface='org.freedesktop.DBus',member='NameOwnerChanged',type='signal',arg0='%s'", VC_SERVER_SERVICE_INTERFACE); - if (NULL == g_w_conn_listener) { - if (g_is_connection_opened) { - SLOG(LOG_ERROR, TAG_VCW, "[ERROR] g_w_conn_listener is NULL abnormally"); - pthread_mutex_unlock(&g_w_init_mutex); - return VC_ERROR_OPERATION_FAILED; - } else { - SLOG(LOG_INFO, TAG_VCW, "[INFO] g_w_conn_listener is NULL and DBUS connection was closed"); - pthread_mutex_unlock(&g_w_init_mutex); - return VC_ERROR_NONE; - } - } - - dbus_bus_add_match(g_w_conn_listener, rule_err, NULL); - - SLOG(LOG_DEBUG, TAG_VCW, "@@ vc widget initialize : result = %d service = %d daemon_pid = %d", result, *service_state, *daemon_pid); - } else { - SLOG(LOG_ERROR, TAG_VCW, "@@ vc widget initialize : result = %d", result); - } - } else { - SLOG(LOG_ERROR, TAG_VCW, "@@ Result message is NULL "); - vc_widget_dbus_reconnect(); - result = VC_ERROR_TIMED_OUT; - } - - pthread_mutex_unlock(&g_w_init_mutex); - return result; -} - -int vc_widget_dbus_request_finalize(int pid) -{ - pthread_mutex_lock(&g_w_init_mutex); - if (0 != __dbus_check()) { - pthread_mutex_unlock(&g_w_init_mutex); - return VC_ERROR_OPERATION_FAILED; - } - - if (NULL == g_w_conn_listener) { - if (g_is_connection_opened) { - SLOG(LOG_ERROR, TAG_VCW, "[ERROR] g_w_conn_listener is NULL abnormally"); - pthread_mutex_unlock(&g_w_init_mutex); - return VC_ERROR_OPERATION_FAILED; - } else { - SLOG(LOG_INFO, TAG_VCW, "[INFO] g_w_conn_listener is NULL and DBUS connection was closed"); - pthread_mutex_unlock(&g_w_init_mutex); - return VC_ERROR_NONE; - } - } - - DBusError err; - dbus_error_init(&err); - - /* remove a rule for daemon error */ - char rule_err[256] = {0, }; - snprintf(rule_err, 256, "sender='org.freedesktop.DBus',path='/org/freedesktop/DBus',interface='org.freedesktop.DBus',member='NameOwnerChanged',type='signal',arg0='%s'", VC_SERVER_SERVICE_INTERFACE); - dbus_bus_remove_match(g_w_conn_listener, rule_err, &err); - dbus_connection_flush(g_w_conn_listener); - - if (dbus_error_is_set(&err)) { - SLOG(LOG_ERROR, TAG_VCW, "Match Error (%s)", err.message); - dbus_error_free(&err); - pthread_mutex_unlock(&g_w_init_mutex); - return VC_ERROR_OPERATION_FAILED; - } - - DBusMessage* msg; - - msg = dbus_message_new_method_call( - VC_SERVER_SERVICE_NAME, - VC_SERVER_SERVICE_OBJECT_PATH, - VC_SERVER_SERVICE_INTERFACE, - VC_WIDGET_METHOD_FINALIZE); - - if (NULL == msg) { - SLOG(LOG_ERROR, TAG_VCW, "@@ vc widget finalize : Fail to make message "); - pthread_mutex_unlock(&g_w_init_mutex); - return VC_ERROR_OPERATION_FAILED; - } else { - SLOG(LOG_DEBUG, TAG_VCW, "@@ vc widget finalize : pid(%d)", pid); - } - - dbus_message_append_args(msg, DBUS_TYPE_INT32, &pid, DBUS_TYPE_INVALID); - - DBusMessage* result_msg; - int result = VC_ERROR_OPERATION_FAILED; - - result_msg = dbus_connection_send_with_reply_and_block(g_w_conn_sender, msg, g_w_waiting_time, &err); - dbus_message_unref(msg); - - if (dbus_error_is_set(&err)) { - SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Dbus Error (%s)", err.message); - dbus_error_free(&err); - } - - if (NULL != result_msg) { - dbus_message_get_args(result_msg, &err, - DBUS_TYPE_INT32, &result, - DBUS_TYPE_INVALID); - - if (dbus_error_is_set(&err)) { - SLOG(LOG_ERROR, TAG_VCW, "@@ Get arguments error (%s)", err.message); - dbus_error_free(&err); - result = VC_ERROR_OPERATION_FAILED; - } - - dbus_message_unref(result_msg); - - if (0 == result) { - SLOG(LOG_DEBUG, TAG_VCW, "@@ vc widget finalize : result = %d", result); - } else { - SLOG(LOG_ERROR, TAG_VCW, "@@ vc widget finalize : result = %d", result); - } - } else { - SLOG(LOG_ERROR, TAG_VCW, "@@ Result message is NULL "); - vc_widget_dbus_reconnect(); - result = VC_ERROR_TIMED_OUT; - } - - pthread_mutex_unlock(&g_w_init_mutex); - return result; -} - -int vc_widget_dbus_request_start_recording(int pid, bool command) -{ - if (0 != __dbus_check()) { - return VC_ERROR_OPERATION_FAILED; - } - - DBusMessage* msg; - - msg = dbus_message_new_method_call( - VC_SERVER_SERVICE_NAME, - VC_SERVER_SERVICE_OBJECT_PATH, - VC_SERVER_SERVICE_INTERFACE, - VC_WIDGET_METHOD_START_RECORDING); - - if (NULL == msg) { - SLOG(LOG_ERROR, TAG_VCW, "@@ vc widget start recording : Fail to make message"); - return VC_ERROR_OPERATION_FAILED; - } else { - SLOG(LOG_DEBUG, TAG_VCW, "@@ vc widget start recording : pid(%d)", pid); - } - - int temp = (int)command; - - dbus_message_append_args(msg, - DBUS_TYPE_INT32, &pid, - DBUS_TYPE_INT32, &temp, - DBUS_TYPE_INVALID); - - DBusError err; - dbus_error_init(&err); - - DBusMessage* result_msg; - int result = VC_ERROR_OPERATION_FAILED; - - result_msg = dbus_connection_send_with_reply_and_block(g_w_conn_sender, msg, g_w_waiting_time, &err); - dbus_message_unref(msg); - - if (dbus_error_is_set(&err)) { - SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Dbus Error (%s)", err.message); - dbus_error_free(&err); - } - - if (NULL != result_msg) { - dbus_message_get_args(result_msg, &err, DBUS_TYPE_INT32, &result, DBUS_TYPE_INVALID); - - if (dbus_error_is_set(&err)) { - SLOG(LOG_ERROR, TAG_VCW, "@@ Get arguments error (%s)", err.message); - dbus_error_free(&err); - result = VC_ERROR_OPERATION_FAILED; - } - dbus_message_unref(result_msg); - - if (0 == result) { - SLOG(LOG_DEBUG, TAG_VCW, "@@ vc widget start recording : result = %d", result); - } else { - SLOG(LOG_ERROR, TAG_VCW, "@@ vc widget start recording : result = %d", result); - } - } else { - SLOG(LOG_ERROR, TAG_VCW, "@@ Result message is NULL"); - vc_widget_dbus_reconnect(); - result = VC_ERROR_TIMED_OUT; - } - - return result; -} - -int vc_widget_dbus_set_foreground(int pid, bool value) -{ - if (0 != __dbus_check()) { - return VC_ERROR_OPERATION_FAILED; - } - - DBusMessage* msg = NULL; - int tmp_value = 0; - - tmp_value = (int)value; - - msg = dbus_message_new_signal( - VC_MANAGER_SERVICE_OBJECT_PATH, - VC_MANAGER_SERVICE_INTERFACE, - VCC_MANAGER_METHOD_SET_FOREGROUND); - - if (NULL == msg) { - SLOG(LOG_ERROR, TAG_VCW, "@@ vc widget set foreground to manager : Fail to make message"); - return VC_ERROR_OPERATION_FAILED; - } else { - SLOG(LOG_DEBUG, TAG_VCW, "@@ vc widget set foreground to manager : client pid(%d), value(%s)", pid, tmp_value ? "true" : "false"); - } - - dbus_message_append_args(msg, - DBUS_TYPE_INT32, &pid, - DBUS_TYPE_INT32, &tmp_value, - DBUS_TYPE_INVALID); - - if (1 != dbus_connection_send(g_w_conn_sender, msg, NULL)) { - SLOG(LOG_ERROR, TAG_VCW, "[Dbus ERROR] Fail to Send"); - dbus_message_unref(msg); - return VC_ERROR_OPERATION_FAILED; - } - - dbus_message_unref(msg); - - msg = NULL; - msg = dbus_message_new_method_call( - VC_SERVER_SERVICE_NAME, - VC_SERVER_SERVICE_OBJECT_PATH, - VC_SERVER_SERVICE_INTERFACE, - VC_METHOD_SET_FOREGROUND); - - if (NULL == msg) { - SLOG(LOG_ERROR, TAG_VCW, "@@ vc widget set foreground to daemon : Fail to make message"); - return VC_ERROR_OPERATION_FAILED; - } else { - SLOG(LOG_DEBUG, TAG_VCW, "@@ vc widget set foreground to daemon : client pid(%d), value(%s)", pid, tmp_value ? "true" : "false"); - } - - dbus_message_append_args(msg, - DBUS_TYPE_INT32, &pid, - DBUS_TYPE_INT32, &tmp_value, - DBUS_TYPE_INVALID); - - dbus_message_set_no_reply(msg, TRUE); - - /* send the message and flush the connection */ - if (1 != dbus_connection_send(g_w_conn_sender, msg, NULL)) { - SLOG(LOG_ERROR, TAG_VCW, "[Dbus ERROR] Fail to Send"); - dbus_message_unref(msg); - return VC_ERROR_OPERATION_FAILED; - } else { - SLOG(LOG_INFO, TAG_VCW, "[Dbus] SUCCESS Send"); - dbus_connection_flush(g_w_conn_sender); - } - - dbus_message_unref(msg); - - return 0; -} - -int vc_widget_dbus_request_enable_asr_result(int pid, bool enable) -{ - if (0 != __dbus_check()) { - return VC_ERROR_OPERATION_FAILED; - } - - DBusMessage* msg; - - /* create a signal & check for errors */ - msg = dbus_message_new_method_call( - VC_SERVER_SERVICE_NAME, - VC_SERVER_SERVICE_OBJECT_PATH, - VC_SERVER_SERVICE_INTERFACE, - VC_WIDGET_METHOD_ENABLE_ASR_RESULT); - - if (NULL == msg) { - SLOG(LOG_ERROR, TAG_VCW, "@@ vc widget enable asr result : Fail to make message "); - return VC_ERROR_OPERATION_FAILED; - } else { - SLOG(LOG_DEBUG, TAG_VCW, "@@ vc widget enable asr result : pid(%d), enable(%d)", pid, enable); - } - - DBusMessageIter args; - dbus_message_iter_init_append(msg, &args); - - /* Append result*/ - int temp; - if (false == enable) temp = 0; - else temp = 1; - dbus_message_iter_append_basic(&args, DBUS_TYPE_INT32, &(pid)); - dbus_message_iter_append_basic(&args, DBUS_TYPE_INT32, &(temp)); - - DBusError err; - dbus_error_init(&err); - - DBusMessage* result_msg; - int result = VC_ERROR_OPERATION_FAILED; - - result_msg = dbus_connection_send_with_reply_and_block(g_w_conn_sender, msg, g_w_waiting_time, &err); - dbus_message_unref(msg); - - if (dbus_error_is_set(&err)) { - SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Dbus Error (%s)", err.message); - dbus_error_free(&err); - } - - if (NULL != result_msg) { - dbus_message_get_args(result_msg, &err, - DBUS_TYPE_INT32, &result, - DBUS_TYPE_INVALID); - - if (dbus_error_is_set(&err)) { - SLOG(LOG_ERROR, TAG_VCW, "@@ Get arguments error (%s)", err.message); - dbus_error_free(&err); - result = VC_ERROR_OPERATION_FAILED; - } - dbus_message_unref(result_msg); - - if (0 == result) { - SLOG(LOG_DEBUG, TAG_VCW, "@@ vc widget enable asr result : result = %d", result); - } else { - SLOG(LOG_ERROR, TAG_VCW, "@@ vc widget enable asr result : result = %d", result); - } - } else { - SLOG(LOG_DEBUG, TAG_VCW, "@@ Result Message is NULL"); - vc_widget_dbus_reconnect(); - result = VC_ERROR_TIMED_OUT; - } - - return result; -} - -int vc_widget_dbus_request_start(int pid, int silence) -{ - if (0 != __dbus_check()) { - return VC_ERROR_OPERATION_FAILED; - } - - DBusMessage* msg; - - /* create a signal & check for errors */ - msg = dbus_message_new_method_call( - VC_SERVER_SERVICE_NAME, - VC_SERVER_SERVICE_OBJECT_PATH, - VC_SERVER_SERVICE_INTERFACE, - VC_WIDGET_METHOD_START); - - if (NULL == msg) { - SLOG(LOG_ERROR, TAG_VCW, "@@ vc widget start : Fail to make message "); - return VC_ERROR_OPERATION_FAILED; - } else { - SLOG(LOG_DEBUG, TAG_VCW, "@@ vc widget start : pid(%d), silence(%d)", pid, silence); - } - - DBusMessageIter args; - dbus_message_iter_init_append(msg, &args); - - /* Append result*/ - dbus_message_iter_append_basic(&args, DBUS_TYPE_INT32, &(pid)); - dbus_message_iter_append_basic(&args, DBUS_TYPE_INT32, &(silence)); - - DBusError err; - dbus_error_init(&err); - - DBusMessage* result_msg; - int result = VC_ERROR_OPERATION_FAILED; - - result_msg = dbus_connection_send_with_reply_and_block(g_w_conn_sender, msg, g_w_waiting_time, &err); - dbus_message_unref(msg); - - if (dbus_error_is_set(&err)) { - SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Dbus Error (%s)", err.message); - dbus_error_free(&err); - } - - if (NULL != result_msg) { - dbus_message_get_args(result_msg, &err, - DBUS_TYPE_INT32, &result, - DBUS_TYPE_INVALID); - - if (dbus_error_is_set(&err)) { - SLOG(LOG_ERROR, TAG_VCW, "@@ Get arguments error (%s)", err.message); - dbus_error_free(&err); - result = VC_ERROR_OPERATION_FAILED; - } - dbus_message_unref(result_msg); - - if (0 == result) { - SLOG(LOG_DEBUG, TAG_VCW, "@@ vc widget start : result = %d", result); - } else { - SLOG(LOG_ERROR, TAG_VCW, "@@ vc widget start : result = %d", result); - } - } else { - SLOG(LOG_DEBUG, TAG_VCW, "@@ Result Message is NULL"); - vc_widget_dbus_reconnect(); - result = VC_ERROR_TIMED_OUT; - } - - return result; -} - -int vc_widget_dbus_request_stop(int pid) -{ - if (0 != __dbus_check()) { - return VC_ERROR_OPERATION_FAILED; - } - - DBusMessage* msg; - - /* create a signal & check for errors */ - msg = dbus_message_new_method_call( - VC_SERVER_SERVICE_NAME, - VC_SERVER_SERVICE_OBJECT_PATH, - VC_SERVER_SERVICE_INTERFACE, - VC_WIDGET_METHOD_STOP); - - if (NULL == msg) { - SLOG(LOG_ERROR, TAG_VCW, "@@ vc widget stop : Fail to make message "); - return VC_ERROR_OPERATION_FAILED; - } else { - SLOG(LOG_DEBUG, TAG_VCW, "@@ vc widget stop : pid(%d)", pid); - } - - dbus_message_append_args(msg, - DBUS_TYPE_INT32, &pid, - DBUS_TYPE_INVALID); - - DBusError err; - dbus_error_init(&err); - - DBusMessage* result_msg; - int result = VC_ERROR_OPERATION_FAILED; - - result_msg = dbus_connection_send_with_reply_and_block(g_w_conn_sender, msg, g_w_waiting_time, &err); - dbus_message_unref(msg); - - if (dbus_error_is_set(&err)) { - SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Dbus Error (%s)", err.message); - dbus_error_free(&err); - } - - if (NULL != result_msg) { - dbus_message_get_args(result_msg, &err, - DBUS_TYPE_INT32, &result, - DBUS_TYPE_INVALID); - - if (dbus_error_is_set(&err)) { - SLOG(LOG_ERROR, TAG_VCW, "@@ Get arguments error (%s)", err.message); - dbus_error_free(&err); - result = VC_ERROR_OPERATION_FAILED; - } - dbus_message_unref(result_msg); - - if (0 == result) { - SLOG(LOG_DEBUG, TAG_VCW, "@@ vc widget stop : result = %d", result); - } else { - SLOG(LOG_ERROR, TAG_VCW, "@@ vc widget stop : result = %d", result); - } - } else { - SLOG(LOG_DEBUG, TAG_VCW, "@@ Result Message is NULL"); - vc_widget_dbus_reconnect(); - result = VC_ERROR_TIMED_OUT; - } - - return result; -} - -int vc_widget_dbus_request_cancel(int pid) -{ - if (0 != __dbus_check()) { - return VC_ERROR_OPERATION_FAILED; - } - - DBusMessage* msg; - - /* create a signal & check for errors */ - msg = dbus_message_new_method_call( - VC_SERVER_SERVICE_NAME, - VC_SERVER_SERVICE_OBJECT_PATH, /* object name of the signal */ - VC_SERVER_SERVICE_INTERFACE, /* interface name of the signal */ - VC_WIDGET_METHOD_CANCEL); /* name of the signal */ - - if (NULL == msg) { - SLOG(LOG_ERROR, TAG_VCW, "@@ vc widget cancel : Fail to make message "); - return VC_ERROR_OPERATION_FAILED; - } else { - SLOG(LOG_DEBUG, TAG_VCW, "@@ vc widget cancel : pid(%d)", pid); - } - - dbus_message_append_args(msg, - DBUS_TYPE_INT32, &pid, - DBUS_TYPE_INVALID); - - DBusError err; - dbus_error_init(&err); - - DBusMessage* result_msg; - int result = VC_ERROR_OPERATION_FAILED; - - result_msg = dbus_connection_send_with_reply_and_block(g_w_conn_sender, msg, g_w_waiting_time, &err); - dbus_message_unref(msg); - - if (dbus_error_is_set(&err)) { - SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Dbus Error (%s)", err.message); - dbus_error_free(&err); - } - - if (NULL != result_msg) { - dbus_message_get_args(result_msg, &err, - DBUS_TYPE_INT32, &result, - DBUS_TYPE_INVALID); - - if (dbus_error_is_set(&err)) { - SLOG(LOG_ERROR, TAG_VCW, "@@ Get arguments error (%s)", err.message); - dbus_error_free(&err); - result = VC_ERROR_OPERATION_FAILED; - } - dbus_message_unref(result_msg); - - if (0 == result) { - SLOG(LOG_DEBUG, TAG_VCW, "@@ vc widget cancel : result = %d", result); - } else { - SLOG(LOG_ERROR, TAG_VCW, "@@ vc widget cancel : result = %d", result); - } - } else { - SLOG(LOG_DEBUG, TAG_VCW, "@@ Result Message is NULL"); - vc_widget_dbus_reconnect(); - result = VC_ERROR_TIMED_OUT; - } - - return result; -} diff --git a/client/vc_widget_dbus.h b/client/vc_widget_dbus.h deleted file mode 100644 index 01fba7a..0000000 --- a/client/vc_widget_dbus.h +++ /dev/null @@ -1,54 +0,0 @@ -/* -* Copyright (c) 2011-2015 Samsung Electronics Co., Ltd All Rights Reserved -* -* Licensed under the Apache License, Version 2.0 (the License); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an AS IS BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - - -#ifndef __VC_WIDGET_DBUS_H_ -#define __VC_WIDGET_DBUS_H_ - - -#ifdef __cplusplus -extern "C" { -#endif - -int vc_widget_dbus_open_connection(); - -int vc_widget_dbus_close_connection(); - - -int vc_widget_dbus_request_hello(); - -int vc_widget_dbus_request_initialize(int pid, int* service_state, int* daemon_pid); - -int vc_widget_dbus_request_finalize(int pid); - -int vc_widget_dbus_request_start_recording(int pid, bool command); - -int vc_widget_dbus_set_foreground(int pid, bool value); - -int vc_widget_dbus_request_enable_asr_result(int pid, bool enable); - -int vc_widget_dbus_request_start(int pid, int silence); - -int vc_widget_dbus_request_stop(int pid); - -int vc_widget_dbus_request_cancel(int pid); - - -#ifdef __cplusplus -} -#endif - -#endif /* __VC_WIDGET_DBUS_H_ */ diff --git a/client/vc_widget_tidl.c b/client/vc_widget_tidl.c new file mode 100644 index 0000000..3002bf5 --- /dev/null +++ b/client/vc_widget_tidl.c @@ -0,0 +1,621 @@ +/* +* Copyright (c) 2022 Samsung Electronics Co., Ltd All Rights Reserved +* +* Licensed under the Apache License, Version 2.0 (the License); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an AS IS BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#include +#include + +#include "vc_main.h" +#include "vc_widget_client.h" +#include "vc_widget_tidl.h" +#include "vc_widget_proxy.h" +#include "vc_widget_stub.h" + +typedef struct { + bool connected; + bool connection_requesting; + bool register_callback_invoked; + rpc_port_proxy_vc_widget_h rpc_h; + rpc_port_proxy_vc_widget_notify_cb_h notify_cb_h; +} vc_widget_tidl_info_s; + +typedef struct { + bool connected; + bool register_callback_requesting; +} vcd_widget_tidl_info_s; + +static vc_widget_tidl_info_s* g_proxy_tidl_info = NULL; + +static vcd_widget_tidl_info_s* g_stub_tidl_info = NULL; + +static pthread_mutex_t g_w_tidl_mutex = PTHREAD_MUTEX_INITIALIZER; +static pthread_mutex_t g_w_init_mutex = PTHREAD_MUTEX_INITIALIZER; + +static rpc_port_stub_vcd_widget_callback_s g_widget_callback; + +extern int __vc_widget_cb_error(int reason, int daemon_pid, char* msg); + +extern void __vc_widget_cb_show_tooltip(int pid, bool show); + +extern void __vc_widget_cb_result(); + +extern bool __vc_widget_cb_asr_result(int event, const char* asr_result); + +extern int __vc_widget_cb_service_state(int state); + +static void __notify_cb(void *user_data, bundle *msg) +{ + char* method = NULL; + char* val = NULL; + SLOG(LOG_DEBUG, TAG_VCW, "__notify_cb is invoked"); + + bundle_get_str(msg, VC_WIDGET_BUNDLE_METHOD, &method); + + if (0 == strncmp(VCD_WIDGET_METHOD_HELLO, method, strlen(VCD_WIDGET_METHOD_HELLO))) { + SLOG(LOG_INFO, TAG_VCW, "@@@ Get widget hello"); + bundle_get_str(msg, VC_WIDGET_BUNDLE_MESSAGE, &val); + if (val) { + SLOG(LOG_DEBUG, TAG_VCW, "@@ vc widget get hello : pid(%d) ", atoi(val)); + } else { + SLOG(LOG_ERROR, TAG_VCW, "@@ vc widget get hello : invalid pid "); + } + SLOG(LOG_DEBUG, TAG_VCW, "@@@"); + } /* VCD_METHOD_HELLO */ + + else if (0 == strncmp(VCD_WIDGET_METHOD_SET_SERVICE_STATE, method, strlen(VCD_WIDGET_METHOD_SET_SERVICE_STATE))) { + bundle_get_str(msg, VC_WIDGET_BUNDLE_MESSAGE, &val); + int state = 0; + if (val) { + state = atoi(val); + SLOG(LOG_INFO, TAG_VCW, "@@ service state changed : %d", state); + __vc_widget_cb_service_state(state); + } + } /* VCD_WIDGET_METHOD_SET_SERVICE_STATE */ + + else if (0 == strncmp(VCD_WIDGET_METHOD_SHOW_TOOLTIP, method, strlen(VCD_WIDGET_METHOD_SHOW_TOOLTIP))) { + SLOG(LOG_DEBUG, TAG_VCW, "@@@ Show / Hide tooltip"); + char* temp_show = NULL; + bundle_get_str(msg, VC_WIDGET_BUNDLE_MESSAGE, &val); + bundle_get_str(msg, VC_WIDGET_BUNDLE_SHOW, &temp_show); + int pid = 0; + int show = 0; + + if (val) { + pid = atoi(val); + } + if (temp_show) { + show = atoi(temp_show); + } + + if(pid > 0){ + SLOG(LOG_DEBUG, TAG_VCW, "@@ vc widget show tooltip : pid(%d), show(%d)", pid, show); + __vc_widget_cb_show_tooltip(pid, (bool)show); + } else { + SLOG(LOG_ERROR, TAG_VCW, "@@ vc widget show tooltip : invalid pid"); + } + SLOG(LOG_DEBUG, TAG_VCW, "@@@"); + } /* VCD_WIDGET_METHOD_SHOW_TOOLTIP */ + + else if (0 == strncmp(VCD_WIDGET_METHOD_RESULT, method, strlen(VCD_WIDGET_METHOD_RESULT))) { + SLOG(LOG_DEBUG, TAG_VCW, "@@@ Get widget result"); + + __vc_widget_cb_result(); + + SLOG(LOG_DEBUG, TAG_VCW, "@@@"); + } /* VCD_WIDGET_METHOD_RESULT */ + + else if (0 == strncmp(VCD_WIDGET_METHOD_ERROR, method, strlen(VCD_WIDGET_METHOD_ERROR))) { + SLOG(LOG_INFO, TAG_VCW, "@@@ Get Pre Result"); + char* temp_reason = NULL; + char* temp_daemon_pid = NULL; + char* err_msg = NULL; + + bundle_get_str(msg, VC_WIDGET_BUNDLE_REASON, &temp_reason); + bundle_get_str(msg, VC_WIDGET_BUNDLE_DAEMON_PID, &temp_daemon_pid); + bundle_get_str(msg, VC_WIDGET_BUNDLE_ERROR_MESSAGE, &err_msg); + int reason = 0; + int daemon_pid = 0; + + if (NULL != temp_reason) { + reason = atoi(temp_reason); + } + if (NULL != temp_daemon_pid) { + daemon_pid = atoi(temp_daemon_pid); + } + + SLOG(LOG_DEBUG, TAG_VCW, "@@ vc widget get error message : reason(%d), daemon_pid(%d), msg(%s)", reason, daemon_pid, err_msg); + __vc_widget_cb_error(reason, daemon_pid, err_msg); + + SLOG(LOG_DEBUG, TAG_VCW, "@@@"); + } /* VCD_WIDGET_METHOD_ERROR */ + + else { + SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Invalid msg"); + } +} + +static void __on_connected(rpc_port_proxy_vc_widget_h h, void *user_data) +{ + g_proxy_tidl_info->connected = true; + g_proxy_tidl_info->connection_requesting = false; + g_proxy_tidl_info->register_callback_invoked = false; + + SLOG(LOG_INFO, TAG_VCW, "Connected to server"); +} + +static void __on_disconnected(rpc_port_proxy_vc_widget_h h, void *user_data) +{ + g_proxy_tidl_info->connected = false; + g_proxy_tidl_info->connection_requesting = false; + g_proxy_tidl_info->register_callback_invoked = false; + + SLOG(LOG_INFO, TAG_VCW, "Disonnected to server"); +} + +static void __on_rejected(rpc_port_proxy_vc_widget_h h, void *user_data) +{ + g_proxy_tidl_info->connection_requesting = false; + g_proxy_tidl_info->register_callback_invoked = false; + + SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Rejected from server"); +} + + +static rpc_port_proxy_vc_widget_h __create_rpc_port(const char* engine_app_id) +{ + SLOG(LOG_DEBUG, TAG_VCW, "[TIDL] __create_rpc_port"); + rpc_port_proxy_vc_widget_callback_s rpc_callback = { + .connected = __on_connected, + .disconnected = __on_disconnected, + .rejected = __on_rejected + }; + + rpc_port_proxy_vc_widget_h handle = NULL; + if (0 != rpc_port_proxy_vc_widget_create(engine_app_id, &rpc_callback, NULL, &handle)) { + SLOG(LOG_ERROR, TAG_VCW, "[TIDL ERROR] Fail to create proxy"); + return NULL; + } + + return handle; +} + +static void __vcd_widget_create_cb(rpc_port_stub_vcd_widget_context_h context, void *user_data) +{ + g_stub_tidl_info->connected = true; + g_stub_tidl_info->register_callback_requesting = false; + + SLOG(LOG_DEBUG, TAG_VCW, "Connected to server"); + + char *sender = NULL; + + rpc_port_stub_vcd_widget_context_get_sender(context, &sender); + if (!sender) { + SLOG(LOG_ERROR, TAG_VCW, "@@@ Sender is NULL"); + return; + } + + SLOG(LOG_DEBUG, TAG_VCW, "@@@ Server connect. appid(%s)", sender); + free(sender); +} + +static void __vcd_widget_terminate_cb(rpc_port_stub_vcd_widget_context_h context, void *user_data) +{ + g_stub_tidl_info->connected = false; + g_stub_tidl_info->register_callback_requesting = false; + + rpc_port_stub_vcd_widget_context_set_tag(context, NULL); + + char *sender = NULL; + rpc_port_stub_vcd_widget_context_get_sender(context, &sender); + if (!sender) + return; + + SLOG(LOG_INFO, TAG_VCW, "@@@ Server disconnect. appid(%s)", sender); + free(sender); +} + +static int __vcd_widget_asr_result_cb(rpc_port_stub_vcd_widget_context_h context, int pid, int event, const char *asr_result, bool *is_consumed, void *user_data) +{ + SLOG(LOG_DEBUG, TAG_VCW, "@@@ Get widget asr result"); + + bool result = false; + result = __vc_widget_cb_asr_result(event, asr_result); + *is_consumed = result; + + return VC_ERROR_NONE; +} + +static void __register_stub_callback() +{ + if (g_stub_tidl_info->register_callback_requesting) { + return; + } + + SLOG(LOG_DEBUG, TAG_VCW, "[TIDL] __register_stub_callback"); + + g_widget_callback.create = __vcd_widget_create_cb; + g_widget_callback.terminate = __vcd_widget_terminate_cb; + g_widget_callback.send_asr_result = __vcd_widget_asr_result_cb; + + int ret = -1; + ret = rpc_port_stub_vcd_widget_register(&g_widget_callback, NULL); + if (0 == ret) { + SLOG(LOG_DEBUG, TAG_VCW, "register callback"); + g_stub_tidl_info->register_callback_requesting = true; + return; + } + + SLOG(LOG_ERROR, TAG_VCW, "Fail to rister callback(%d)", ret); + return; +} + +int vc_widget_tidl_open_connection() +{ + SLOG(LOG_DEBUG, TAG_VCW, "[TIDL] vc_widget_tidl_open_connection"); + pthread_mutex_lock(&g_w_tidl_mutex); + + if (NULL != g_proxy_tidl_info) { + SLOG(LOG_ERROR, TAG_VCW, "[TIDL ERROR] g_proxy_tidl_info already created"); + pthread_mutex_unlock(&g_w_tidl_mutex); + return VC_ERROR_NONE; + } + + g_proxy_tidl_info = (vc_widget_tidl_info_s*)calloc(1, sizeof(vc_widget_tidl_info_s)); + + if (NULL == g_proxy_tidl_info) { + SLOG(LOG_ERROR, TAG_VCW, "[TIDL ERROR] Fail to create vc_widget_tidl_info_s"); + pthread_mutex_unlock(&g_w_tidl_mutex); + return VC_ERROR_OUT_OF_MEMORY; + } + + char* engine_app_id = vconf_get_str(VC_ENGINE_DB_DEFAULT); + if (NULL == engine_app_id) { + SLOG(LOG_ERROR, TAG_VCW, "[TIDL] vconf not found"); + free(g_proxy_tidl_info); + g_proxy_tidl_info = NULL; + pthread_mutex_unlock(&g_w_tidl_mutex); + return VC_ERROR_ENGINE_NOT_FOUND; + } + + g_proxy_tidl_info->rpc_h = __create_rpc_port(engine_app_id); + if (NULL == g_proxy_tidl_info->rpc_h) { + SLOG(LOG_ERROR, TAG_VCW, "[TIDL ERROR] Fail to create proxy"); + free(engine_app_id); + free(g_proxy_tidl_info); + g_proxy_tidl_info = NULL; + pthread_mutex_unlock(&g_w_tidl_mutex); + return VC_ERROR_OPERATION_FAILED; + } + + SLOG(LOG_INFO, TAG_VCW, "[TIDL] rpc_h(%p), engine_app_id(%s)", g_proxy_tidl_info->rpc_h, engine_app_id); + free(engine_app_id); + + g_stub_tidl_info = (vcd_widget_tidl_info_s*)calloc(1, sizeof(vcd_widget_tidl_info_s)); + + if (NULL == g_stub_tidl_info) { + SLOG(LOG_ERROR, TAG_VCW, "[TIDL ERROR] Fail to create vcd_widget_tidl_info_s"); + pthread_mutex_unlock(&g_w_tidl_mutex); + return VC_ERROR_OUT_OF_MEMORY; + } + + __register_stub_callback(); + + pthread_mutex_unlock(&g_w_tidl_mutex); + + return VC_ERROR_NONE; +} + +int vc_widget_tidl_close_connection() +{ + SLOG(LOG_DEBUG, TAG_VCW, "[TIDL] vc_widget_tidl_close_connection"); + pthread_mutex_lock(&g_w_tidl_mutex); + + if (NULL == g_proxy_tidl_info) { + SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to get tidl info"); + pthread_mutex_unlock(&g_w_tidl_mutex); + return VC_ERROR_OPERATION_FAILED; + } + + if (0 != rpc_port_proxy_vc_widget_destroy(g_proxy_tidl_info->rpc_h)) { + SLOG(LOG_ERROR, TAG_VCW, "[TIDL ERROR] Fail to destroy tidl handle"); + pthread_mutex_unlock(&g_w_tidl_mutex); + return VC_ERROR_OPERATION_FAILED; + } + + g_proxy_tidl_info->rpc_h = NULL; + g_proxy_tidl_info->notify_cb_h = NULL; + + free(g_proxy_tidl_info); + g_proxy_tidl_info = NULL; + + free(g_stub_tidl_info); + g_stub_tidl_info = NULL; + + pthread_mutex_unlock(&g_w_tidl_mutex); + + return VC_ERROR_NONE; +} + +static void __request_tidl_connect() +{ + if (g_proxy_tidl_info->connection_requesting) { + return; + } + + int ret = rpc_port_proxy_vc_widget_connect(g_proxy_tidl_info->rpc_h); + SLOG(LOG_INFO, TAG_VCW, "[INFO] Request connection to stub. ret(%d)", ret); + + if (0 == ret) { + g_proxy_tidl_info->connection_requesting = true; + } +} + +static int __create_callback_handles() +{ + if (NULL != g_proxy_tidl_info->notify_cb_h) { + rpc_port_proxy_vc_widget_notify_cb_dispose(g_proxy_tidl_info->rpc_h, g_proxy_tidl_info->notify_cb_h); + g_proxy_tidl_info->notify_cb_h = NULL; + } + + if (RPC_PORT_ERROR_NONE != rpc_port_proxy_vc_widget_notify_cb_create(&g_proxy_tidl_info->notify_cb_h)) { + return VC_ERROR_OUT_OF_MEMORY; + } + + rpc_port_proxy_vc_widget_notify_cb_set_callback(g_proxy_tidl_info->notify_cb_h, __notify_cb, NULL); + + rpc_port_proxy_vc_widget_notify_cb_set_once(g_proxy_tidl_info->notify_cb_h, false); + + return VC_ERROR_NONE; +} + +static int __invoke_register_callback() +{ + if (g_proxy_tidl_info->register_callback_invoked) { + SLOG(LOG_ERROR, TAG_VCW, "[INFO] Already register callback is invoked"); + return VC_ERROR_NONE; + } + + int ret = __create_callback_handles(g_proxy_tidl_info); + if (VC_ERROR_NONE != ret) { + SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to create callback handle. ret(%d)", ret); + return VC_ERROR_OPERATION_FAILED; + } + + rpc_port_proxy_vc_widget_invoke_register_cb(g_proxy_tidl_info->rpc_h, getpid(), g_proxy_tidl_info->notify_cb_h); + g_proxy_tidl_info->register_callback_invoked = true; + return VC_ERROR_NONE; +} + +int vc_widget_tidl_request_hello() +{ + SLOG(LOG_DEBUG, TAG_VCW, "[TIDL] vc_widget_tidl_request_hello"); + + if (NULL == g_proxy_tidl_info) { + SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to get proxy tidl info"); + return VC_ERROR_OPERATION_FAILED; + } + + if (!g_proxy_tidl_info->connected) { + SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Proxy Not Connected"); + __request_tidl_connect(); + return VC_ERROR_OPERATION_FAILED; + } + + if (VC_ERROR_NONE != __invoke_register_callback()) { + SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to invoke register callback"); + return VC_ERROR_OPERATION_FAILED; + } + + if (NULL == g_stub_tidl_info) { + SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to get stub tidl info"); + return VC_ERROR_OPERATION_FAILED; + } + + if (!g_stub_tidl_info->connected) { + SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Stub Not Connected"); + __register_stub_callback(); + return VC_ERROR_OPERATION_FAILED; + } + + SLOG(LOG_DEBUG, TAG_VCW, ">>>>> VCW Hello"); + + SLOG(LOG_DEBUG, TAG_VCW, "<<<<"); + + return VC_ERROR_NONE; +} + +int vc_widget_tidl_request_initialize(int pid, int* service_state, int* daemon_pid) +{ + pthread_mutex_lock(&g_w_init_mutex); + SLOG(LOG_DEBUG, TAG_VCW, "[TIDL] vc_widget_tidl_request_initialize"); + + if (NULL == g_proxy_tidl_info) { + SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to get tidl info"); + pthread_mutex_unlock(&g_w_init_mutex); + return VC_ERROR_OPERATION_FAILED; + } + + int temp_service_state = 0; + int temp_daemon_pid = 0; + if (0 != rpc_port_proxy_vc_widget_invoke_initialize(g_proxy_tidl_info->rpc_h, pid, &temp_service_state, &temp_daemon_pid)) { + SLOG(LOG_ERROR, TAG_VCW, "[TIDL ERROR] Request vc widget initialize : Fail to invoke message"); + pthread_mutex_unlock(&g_w_init_mutex); + return VC_ERROR_OPERATION_FAILED; + } + + *service_state = temp_service_state; + *daemon_pid = temp_daemon_pid; + + pthread_mutex_unlock(&g_w_init_mutex); + SLOG(LOG_DEBUG, TAG_VCW, "[TIDL] vc widget initialize: service_state(%d), daemon_pid(%d)", *service_state, *daemon_pid); + + return VC_ERROR_NONE; +} + +int vc_widget_tidl_request_finalize(int pid) +{ + pthread_mutex_lock(&g_w_init_mutex); + SLOG(LOG_DEBUG, TAG_VCW, "[TIDL] vc_widget_tidl_request_finalize"); + + if (NULL == g_proxy_tidl_info) { + SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to get tidl info"); + pthread_mutex_unlock(&g_w_init_mutex); + return VC_ERROR_OPERATION_FAILED; + } + + if (!g_proxy_tidl_info->connected) { + SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Not Connected"); + pthread_mutex_unlock(&g_w_init_mutex); + return VC_ERROR_OPERATION_FAILED; + } + + if (0 != rpc_port_proxy_vc_widget_invoke_finalize(g_proxy_tidl_info->rpc_h, pid)) { + SLOG(LOG_ERROR, TAG_VCW, "[TIDL ERROR] Request vc widget finalize : Fail to invoke message"); + pthread_mutex_unlock(&g_w_init_mutex); + return VC_ERROR_OPERATION_FAILED; + } + + pthread_mutex_unlock(&g_w_init_mutex); + return VC_ERROR_NONE; +} + +int vc_widget_tidl_request_start_recording(int pid, bool command) +{ + SLOG(LOG_DEBUG, TAG_VCW, "[TIDL] vc_widget_tidl_request_start_recording"); + + if (NULL == g_proxy_tidl_info) { + SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to get tidl info"); + return VC_ERROR_OPERATION_FAILED; + } + + if (!g_proxy_tidl_info->connected) { + SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Not Connected"); + return VC_ERROR_OPERATION_FAILED; + } + + if (0 != rpc_port_proxy_vc_widget_invoke_start_recording(g_proxy_tidl_info->rpc_h, pid, (int)command)) { + SLOG(LOG_ERROR, TAG_VCW, "[TIDL ERROR] Request vc widget start recording : Fail to invoke message"); + return VC_ERROR_OPERATION_FAILED; + } + + return VC_ERROR_NONE; +} + +int vc_widget_tidl_set_foreground(int pid, bool value) +{ + SLOG(LOG_DEBUG, TAG_VCW, "[TIDL] vc_widget_tidl_set_foreground"); + + if (NULL == g_proxy_tidl_info) { + SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to get tidl info"); + return VC_ERROR_OPERATION_FAILED; + } + + if (!g_proxy_tidl_info->connected) { + SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Not Connected"); + return VC_ERROR_OPERATION_FAILED; + } + + rpc_port_proxy_vc_widget_invoke_set_foreground(g_proxy_tidl_info->rpc_h, pid, (int)value); + + return VC_ERROR_NONE; +} + +int vc_widget_tidl_request_enable_asr_result(int pid, bool enable) +{ + SLOG(LOG_DEBUG, TAG_VCW, "[TIDL] vc_widget_tidl_request_enable_asr_result"); + + if (NULL == g_proxy_tidl_info) { + SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to get tidl info"); + return VC_ERROR_OPERATION_FAILED; + } + + if (!g_proxy_tidl_info->connected) { + SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Not Connected"); + return VC_ERROR_OPERATION_FAILED; + } + + if (0 != rpc_port_proxy_vc_widget_invoke_enable_asr_result(g_proxy_tidl_info->rpc_h, pid, (int)enable)) { + SLOG(LOG_ERROR, TAG_VCW, "[TIDL ERROR] Request vc widget enable asr result : Fail to invoke message"); + return VC_ERROR_OPERATION_FAILED; + } + + return VC_ERROR_NONE; +} + +int vc_widget_tidl_request_start(int pid, int silence) +{ + SLOG(LOG_DEBUG, TAG_VCW, "[TIDL] vc_widget_tidl_request_start"); + + if (NULL == g_proxy_tidl_info) { + SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to get tidl info"); + return VC_ERROR_OPERATION_FAILED; + } + + if (!g_proxy_tidl_info->connected) { + SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Not Connected"); + return VC_ERROR_OPERATION_FAILED; + } + + if (0 != rpc_port_proxy_vc_widget_invoke_start(g_proxy_tidl_info->rpc_h, pid, silence)) { + SLOG(LOG_ERROR, TAG_VCW, "[TIDL ERROR] Request vc widget start : Fail to invoke message"); + return VC_ERROR_OPERATION_FAILED; + } + + return VC_ERROR_NONE; +} + +int vc_widget_tidl_request_stop(int pid) +{ + SLOG(LOG_DEBUG, TAG_VCW, "[TIDL] vc_widget_tidl_request_stop"); + + if (NULL == g_proxy_tidl_info) { + SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to get tidl info"); + return VC_ERROR_OPERATION_FAILED; + } + + if (!g_proxy_tidl_info->connected) { + SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Not Connected"); + return VC_ERROR_OPERATION_FAILED; + } + + if (0 != rpc_port_proxy_vc_widget_invoke_stop(g_proxy_tidl_info->rpc_h, pid)) { + SLOG(LOG_ERROR, TAG_VCW, "[TIDL ERROR] Request vc widget stop : Fail to invoke message"); + return VC_ERROR_OPERATION_FAILED; + } + + return VC_ERROR_NONE; +} + +int vc_widget_tidl_request_cancel(int pid) +{ + SLOG(LOG_DEBUG, TAG_VCW, "[TIDL] vc_widget_tidl_request_cancel"); + + if (NULL == g_proxy_tidl_info) { + SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to get tidl info"); + return VC_ERROR_OPERATION_FAILED; + } + + if (!g_proxy_tidl_info->connected) { + SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Not Connected"); + return VC_ERROR_OPERATION_FAILED; + } + + if (0 != rpc_port_proxy_vc_widget_invoke_cancel(g_proxy_tidl_info->rpc_h, pid)) { + SLOG(LOG_ERROR, TAG_VCW, "[TIDL ERROR] Request vc widget cancel : Fail to invoke message"); + return VC_ERROR_OPERATION_FAILED; + } + + return VC_ERROR_NONE; +} diff --git a/client/vc_widget_tidl.h b/client/vc_widget_tidl.h new file mode 100644 index 0000000..7b00320 --- /dev/null +++ b/client/vc_widget_tidl.h @@ -0,0 +1,54 @@ +/* +* Copyright (c) 2022 Samsung Electronics Co., Ltd All Rights Reserved +* +* Licensed under the Apache License, Version 2.0 (the License); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an AS IS BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + + +#ifndef __VC_WIDGET_TIDL_H_ +#define __VC_WIDGET_TIDL_H_ + + +#ifdef __cplusplus +extern "C" { +#endif + +int vc_widget_tidl_open_connection(); + +int vc_widget_tidl_close_connection(); + + +int vc_widget_tidl_request_hello(); + +int vc_widget_tidl_request_initialize(int pid, int* service_state, int* daemon_pid); + +int vc_widget_tidl_request_finalize(int pid); + +int vc_widget_tidl_request_start_recording(int pid, bool command); + +int vc_widget_tidl_set_foreground(int pid, bool value); + +int vc_widget_tidl_request_enable_asr_result(int pid, bool enable); + +int vc_widget_tidl_request_start(int pid, int silence); + +int vc_widget_tidl_request_stop(int pid); + +int vc_widget_tidl_request_cancel(int pid); + + +#ifdef __cplusplus +} +#endif + +#endif /* __VC_WIDGET_TIDL_H_ */ \ No newline at end of file diff --git a/common/vc_defs.h b/common/vc_defs.h index 0f906d6..3ba15c5 100644 --- a/common/vc_defs.h +++ b/common/vc_defs.h @@ -130,6 +130,14 @@ extern "C" { #define VCD_WIDGET_METHOD_SHOW_TOOLTIP "vcd_widget_method_show_tooltip" #define VCD_WIDGET_METHOD_SET_SERVICE_STATE "vcd_widget_method_set_service_state" +#define VC_WIDGET_BUNDLE_METHOD "vc_widget_bundle_method" +#define VC_WIDGET_BUNDLE_MESSAGE "vc_widget_bundle_message" +#define VC_WIDGET_BUNDLE_SERVICE_STATE "vc_widget_bundle_service_state" +#define VC_WIDGET_BUNDLE_DAEMON_PID "vc_widget_bundle_daemon_pid" +#define VC_WIDGET_BUNDLE_SHOW "vc_widget_bundle_show" +#define VC_WIDGET_BUNDLE_REASON "vc_widget_bundle_reason" +#define VC_WIDGET_BUNDLE_ERROR_MESSAGE "vc_widget_bundle_error_message" + /****************************************************************************************** * Message Definitions for manager diff --git a/packaging/voice-control.spec b/packaging/voice-control.spec index d776104..63b9aa4 100644 --- a/packaging/voice-control.spec +++ b/packaging/voice-control.spec @@ -119,6 +119,11 @@ tidlc -s -l C -i tidl/vc_mgr.tidl -o vcd_mgr_stub tidlc -s -l C -i tidl/vcd_mgr.tidl -o vc_mgr_stub tidlc -p -l C -i tidl/vcd_mgr.tidl -o vcd_mgr_proxy +tidlc -p -l C -i tidl/vc_widget.tidl -o vc_widget_proxy +tidlc -s -l C -i tidl/vc_widget.tidl -o vcd_widget_stub +tidlc -s -l C -i tidl/vcd_widget.tidl -o vc_widget_stub +tidlc -p -l C -i tidl/vcd_widget.tidl -o vcd_widget_proxy + mv vc_* client mv vcd_* server diff --git a/server/CMakeLists.txt b/server/CMakeLists.txt index c557c71..5fe0268 100644 --- a/server/CMakeLists.txt +++ b/server/CMakeLists.txt @@ -14,6 +14,8 @@ SET(SRCS vcd_tidl.c vcd_mgr_stub.c vcd_mgr_proxy.c + vcd_widget_stub.c + vcd_widget_proxy.c vcd_engine_agent.c # vcd_main.c vcd_recorder.c diff --git a/server/vcd_client_data.c b/server/vcd_client_data.c index ddb298b..f9bdec8 100644 --- a/server/vcd_client_data.c +++ b/server/vcd_client_data.c @@ -34,6 +34,9 @@ static manager_info_s g_manager; /* Manager IPC info */ static manager_tidl_info_s* g_mgr_tidl_info = NULL; +/* Widget IPC info */ +static GSList* g_widget_tidl_info_list = NULL; + /* Command list */ static current_commands_list_s g_cur_cmd_list; @@ -256,7 +259,7 @@ char* vcd_client_manager_get_result_text() return g_result_text; } -int vcd_client_manger_create_tidl_info(int pid) +int vcd_client_manager_create_tidl_info(int pid) { /*Check already created*/ if (NULL != g_mgr_tidl_info) { @@ -1664,6 +1667,184 @@ int vcd_client_widget_get_waiting_for_recording(int pid, bool* waiting) return 0; } +GSList* __get_widget_tidl_info_item(const int pid) +{ + GSList *iter = NULL; + widget_tidl_info_s *data = NULL; + + int count = g_slist_length(g_widget_tidl_info_list); + int i; + + if (0 < count) { + iter = g_slist_nth(g_widget_tidl_info_list, 0); + for (i = 0; i < count; i++) { + if (NULL == iter) + break; + + data = iter->data; + if (NULL != data) { + if (pid == data->pid) + return iter; + } + + iter = g_slist_next(iter); + } + } + + return NULL; +} + +widget_tidl_info_s* __get_widget_tidl_info_element(int pid) +{ + GSList *iter = NULL; + widget_tidl_info_s *data = NULL; + + int count = g_slist_length(g_widget_tidl_info_list); + int i; + + if (0 < count) { + iter = g_slist_nth(g_widget_tidl_info_list, 0); + for (i = 0; i < count; i++) { + if (NULL == iter) + break; + + data = iter->data; + + if (NULL != data) { + if (pid == data->pid) + return data; + } + + iter = g_slist_next(iter); + } + } + + return NULL; +} + +int vcd_client_widget_add_tidl_info(int pid) +{ + /*Check pid is duplicated*/ + widget_tidl_info_s* info = NULL; + info = __get_widget_tidl_info_element(pid); + + if (NULL != info) { + SLOG(LOG_WARN, TAG_VCD, "[Client Data] Widget tidl info pid is already registered"); + return VCD_ERROR_NONE; + } + + SLOG(LOG_INFO, TAG_VCD, "[Client Data] There is no tidl info of pid(%d). Create new one.", pid); + info = (widget_tidl_info_s*)calloc(1, sizeof(widget_tidl_info_s)); + if (NULL == info) { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to allocate memory"); + return VCD_ERROR_OUT_OF_MEMORY; + } + + info->pid = pid; + info->notify_cb = NULL; + info->notify_cb_user_data = NULL; + + info->connected = false; + info->connection_requesting = false; + info->rpc_h = NULL; + + g_widget_tidl_info_list = g_slist_append(g_widget_tidl_info_list, info); + if (NULL == g_widget_tidl_info_list) { + SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] Fail to add new widget tidl info"); + + free(info); + info = NULL; + + return -1; + } else { + SLOG(LOG_INFO, TAG_VCD, "[Client Data SUCCESS] Add new widget tidl info. pid(%d)", pid); + } + + return VCD_ERROR_NONE; +} + +int vcd_client_widget_set_tidl_notify_cb(int pid, rpc_port_stub_vc_widget_notify_cb_h callback, void* user_data) +{ + /*Check pid*/ + widget_tidl_info_s* info = NULL; + info = __get_widget_tidl_info_element(pid); + + if (NULL == info) { + SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] There is no tidl info in the list. pid(%d)", pid); + return VCD_ERROR_INVALID_PARAMETER; + } + + int ret = -1; + ret = rpc_port_stub_vc_widget_notify_cb_clone(callback, &(info->notify_cb)); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] Fail to clone notify callback. ret(%d)", ret); + } else { + SLOG(LOG_INFO, TAG_VCD, "[Client Data] Succeed to clone notify callback. ret(%d)", ret); + } + info->notify_cb_user_data = user_data; + + return VCD_ERROR_NONE; +} + +int vcd_client_widget_unset_tidl_notify_cb(int pid) +{ + /*Check pid*/ + widget_tidl_info_s* info = NULL; + info = __get_widget_tidl_info_element(pid); + + if (NULL == info) { + SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] There is no tidl info in the list. pid(%d)", pid); + return VCD_ERROR_INVALID_PARAMETER; + } + + int ret = -1; + ret = rpc_port_stub_vc_widget_notify_cb_destroy(info->notify_cb); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] Fail to destroy notify callback. ret(%d)", ret); + } else { + SLOG(LOG_INFO, TAG_VCD, "[Client Data] Succeed to destroy notify callback. ret(%d)", ret); + } + info->notify_cb = NULL; + info->notify_cb_user_data = NULL; + + return VCD_ERROR_NONE; +} + +int vcd_client_widget_delete_tidl_info(int pid) +{ + GSList *tmp = NULL; + widget_tidl_info_s* widget_tidl_info = NULL; + + /*Get handle*/ + tmp = __get_widget_tidl_info_item(pid); + if (NULL == tmp) { + SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] pid(%d) is NOT valid", pid); + return VCD_ERROR_INVALID_PARAMETER; + } + + /*Free widget structure*/ + widget_tidl_info = tmp->data; + if (NULL != widget_tidl_info) { + free(widget_tidl_info); + } + + /*Remove handle from list*/ + g_widget_tidl_info_list = g_slist_remove_link(g_widget_tidl_info_list, tmp); + + return 0; +} + +widget_tidl_info_s* vcd_client_widget_get_tidl_info(int pid) +{ + return __get_widget_tidl_info_element(pid); +} + +GSList* vcd_client_widget_get_tidl_info_list() +{ + return g_widget_tidl_info_list; +} + + void vcd_client_update_foreground_pid() { int tmp_pid = VC_RUNTIME_INFO_NO_FOREGROUND; diff --git a/server/vcd_client_data.h b/server/vcd_client_data.h index 260c984..317e1d5 100644 --- a/server/vcd_client_data.h +++ b/server/vcd_client_data.h @@ -23,6 +23,8 @@ #include "vc_info_parser.h" #include "vcd_mgr_stub.h" #include "vcd_mgr_proxy.h" +#include "vcd_widget_stub.h" +#include "vcd_widget_proxy.h" #ifdef __cplusplus extern "C" { @@ -81,6 +83,18 @@ typedef struct { rpc_port_proxy_vcd_mgr_h rpc_h; } manager_tidl_info_s; +typedef struct { + int pid; + + rpc_port_stub_vc_widget_notify_cb_h notify_cb; + void* notify_cb_user_data; + + bool connected; + bool connection_requesting; + + rpc_port_proxy_vcd_widget_h rpc_h; +} widget_tidl_info_s; + typedef enum { VCD_RECOGNITION_MODE_STOP_BY_SILENCE, /**< Default mode */ VCD_RECOGNITION_MODE_RESTART_AFTER_REJECT, /**< Restart recognition after rejected result */ @@ -147,7 +161,7 @@ char* vcd_client_manager_get_result_text(); bool vcd_client_manager_is_system_command_valid(int pid); -int vcd_client_manger_create_tidl_info(int pid); +int vcd_client_manager_create_tidl_info(int pid); int vcd_client_manager_set_tidl_notify_cb(rpc_port_stub_vc_mgr_notify_cb_h callback, void* user_data); @@ -215,6 +229,17 @@ int vcd_client_widget_set_waiting_for_recording(int pid, bool waiting); int vcd_client_widget_get_waiting_for_recording(int pid, bool* waiting); +int vcd_client_widget_add_tidl_info(int pid); + +int vcd_client_widget_set_tidl_notify_cb(int pid, rpc_port_stub_vc_widget_notify_cb_h callback, void* user_data); + +int vcd_client_widget_unset_tidl_notify_cb(int pid); + +int vcd_client_widget_delete_tidl_info(int pid); + +widget_tidl_info_s* vcd_client_widget_get_tidl_info(int pid); + +GSList* vcd_client_widget_get_tidl_info_list(); #ifdef __cplusplus } diff --git a/server/vcd_dbus.c b/server/vcd_dbus.c index b37e486..54bf596 100755 --- a/server/vcd_dbus.c +++ b/server/vcd_dbus.c @@ -119,7 +119,9 @@ int vcdc_send_hello(int pid, vcd_client_type_e type) if (VCD_CLIENT_TYPE_NORMAL == type) { msg = __get_message(pid, VCD_METHOD_HELLO, VCD_CLIENT_TYPE_NORMAL); } else if (VCD_CLIENT_TYPE_WIDGET == type) { - msg = __get_message(pid, VCD_WIDGET_METHOD_HELLO, VCD_CLIENT_TYPE_WIDGET); + // msg = __get_message(pid, VCD_WIDGET_METHOD_HELLO, VCD_CLIENT_TYPE_WIDGET); + vcdc_tidl_send_hello(pid, type); + return VCD_ERROR_NONE; } else if (VCD_CLIENT_TYPE_MANAGER == type) { vcdc_tidl_send_hello(pid, type); return VCD_ERROR_NONE; @@ -173,63 +175,6 @@ int vcdc_send_hello(int pid, vcd_client_type_e type) return result; } -int vcdc_send_show_tooltip(int pid, bool show) -{ - if (0 != __dbus_check()) { - return VCD_ERROR_OPERATION_FAILED; - } - - if (0 > pid) { - SLOG(LOG_ERROR, TAG_VCD, "[Dbus ERROR] widget pid is NOT valid"); - return -1; - } - - char service_name[64] = {0, }; - memset(service_name, 0, 64); - snprintf(service_name, 64, "%s%d", VC_WIDGET_SERVICE_NAME, pid); - - char target_if_name[128] = {0, }; - snprintf(target_if_name, sizeof(target_if_name), "%s", VC_WIDGET_SERVICE_INTERFACE); - - DBusMessage* msg; - - SLOG(LOG_INFO, TAG_VCD, "[Dbus] send widget show tooltip signal : pid(%d) show(%d)", pid, show); - - msg = dbus_message_new_method_call( - service_name, - VC_WIDGET_SERVICE_OBJECT_PATH, - target_if_name, - VCD_WIDGET_METHOD_SHOW_TOOLTIP); - - if (NULL == msg) { - SLOG(LOG_ERROR, TAG_VCD, "[Dbus ERROR] Fail to create message"); - return VCD_ERROR_OUT_OF_MEMORY; - } - - int temp = (int)show; - - DBusMessageIter args; - dbus_message_iter_init_append(msg, &args); - - /* Append pid & type */ - dbus_message_iter_append_basic(&args, DBUS_TYPE_INT32, &pid); - dbus_message_iter_append_basic(&args, DBUS_TYPE_INT32, &(temp)); - - dbus_message_set_no_reply(msg, TRUE); - - if (1 != dbus_connection_send(g_conn_sender, msg, NULL)) { - SLOG(LOG_ERROR, TAG_VCD, "[Dbus ERROR] Fail to Send"); - return VCD_ERROR_OPERATION_FAILED; - } else { - SLOG(LOG_INFO, TAG_VCD, "[Dbus] SUCCESS Send"); - dbus_connection_flush(g_conn_sender); - } - - dbus_message_unref(msg); - - return 0; -} - int vcdc_send_result(int pid, int manager_pid, int cmd_type) { if (0 != __dbus_check()) { @@ -245,21 +190,23 @@ int vcdc_send_result(int pid, int manager_pid, int cmd_type) case VC_COMMAND_TYPE_BACKGROUND: if (pid == manager_pid) { // msg = __get_message(pid, VCD_MANAGER_METHOD_RESULT, VCD_CLIENT_TYPE_MANAGER); - vcdc_tidl_send_result(pid, manager_pid, cmd_type); + vcdc_tidl_send_result(pid, manager_pid, VCD_CLIENT_TYPE_MANAGER); return 0; } else { msg = __get_message(pid, VCD_METHOD_RESULT, VCD_CLIENT_TYPE_NORMAL); } break; case VC_COMMAND_TYPE_WIDGET: - msg = __get_message(pid, VCD_WIDGET_METHOD_RESULT, VCD_CLIENT_TYPE_WIDGET); - break; + // msg = __get_message(pid, VCD_WIDGET_METHOD_RESULT, VCD_CLIENT_TYPE_WIDGET); + // break; + vcdc_tidl_send_result(pid, manager_pid, VCD_CLIENT_TYPE_WIDGET); + return 0; case VC_COMMAND_TYPE_SYSTEM: case VC_COMMAND_TYPE_SYSTEM_BACKGROUND: case VC_COMMAND_TYPE_EXCLUSIVE: // msg = __get_message(pid, VCD_MANAGER_METHOD_RESULT, VCD_CLIENT_TYPE_MANAGER); // break; - vcdc_tidl_send_result(pid, manager_pid, cmd_type); + vcdc_tidl_send_result(pid, manager_pid, VCD_CLIENT_TYPE_MANAGER); return 0; default: @@ -287,67 +234,6 @@ int vcdc_send_result(int pid, int manager_pid, int cmd_type) return 0; } -int vcdc_send_asr_result(int pid, int event, const char* asr_result, int cmd_type, bool* is_consumed) -{ - if (0 != __dbus_check()) { - return VCD_ERROR_OPERATION_FAILED; - } - - DBusMessage* msg = NULL; - - SLOG(LOG_INFO, TAG_VCD, "[Dbus] Result command type(%d)", cmd_type); - - switch (cmd_type) { - case VC_COMMAND_TYPE_WIDGET: - msg = __get_message(pid, VCD_WIDGET_METHOD_ASR_RESULT, VCD_CLIENT_TYPE_WIDGET); - break; - default: - SLOG(LOG_ERROR, TAG_VCD, "[Dbus ERROR] Command type is NOT valid(%d)", cmd_type); - return VCD_ERROR_INVALID_PARAMETER; - } - - if (NULL == msg) { - SLOG(LOG_ERROR, TAG_VCD, "[Dbus ERROR] Message is NULL"); - return VCD_ERROR_OUT_OF_MEMORY; - } - - dbus_message_append_args(msg, DBUS_TYPE_INT32, &event, DBUS_TYPE_STRING, &asr_result, DBUS_TYPE_INVALID); - - DBusError err; - dbus_error_init(&err); - - DBusMessage* result_msg; - - int result = 0; - result_msg = dbus_connection_send_with_reply_and_block(g_conn_sender, msg, 5000, &err); - dbus_message_unref(msg); - - if (dbus_error_is_set(&err)) { - SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Dbus Error (%s)", err.message); - dbus_error_free(&err); - } - - if (NULL != result_msg) { - dbus_message_get_args(result_msg, &err, - DBUS_TYPE_INT32, &result, - DBUS_TYPE_INVALID); - - if (dbus_error_is_set(&err)) { - SLOG(LOG_ERROR, TAG_VCD, "@@ Get arguments error (%s)", err.message); - dbus_error_free(&err); - result = VCD_ERROR_OPERATION_FAILED; - } - - dbus_message_unref(result_msg); - SLOG(LOG_INFO, TAG_VCD, "@@ vc send asr result : result = %d", result); - *is_consumed = result; - return VCD_ERROR_NONE; - } else { - SLOG(LOG_ERROR, TAG_VCD, "@@ Result message is NULL "); - return VCD_ERROR_OPERATION_FAILED; - } -} - int vcdc_send_manager_pid(int manager_pid) { DBusError err; @@ -482,6 +368,7 @@ int vcdc_send_error_signal(int reason, char *err_msg) // msg = NULL; vcdc_tidl_send_error(reason, err_msg); + msg = dbus_message_new_signal( VC_CLIENT_SERVICE_OBJECT_PATH, VC_CLIENT_SERVICE_INTERFACE, @@ -504,28 +391,28 @@ int vcdc_send_error_signal(int reason, char *err_msg) dbus_message_unref(msg); - msg = NULL; - msg = dbus_message_new_signal( - VC_WIDGET_SERVICE_OBJECT_PATH, - VC_WIDGET_SERVICE_INTERFACE, - VCD_WIDGET_METHOD_ERROR); + // msg = NULL; + // msg = dbus_message_new_signal( + // VC_WIDGET_SERVICE_OBJECT_PATH, + // VC_WIDGET_SERVICE_INTERFACE, + // VCD_WIDGET_METHOD_ERROR); - if (NULL == msg) { - SLOG(LOG_ERROR, TAG_VCD, "[Dbus ERROR] Message is NULL"); - return VCD_ERROR_OUT_OF_MEMORY; - } + // if (NULL == msg) { + // SLOG(LOG_ERROR, TAG_VCD, "[Dbus ERROR] Message is NULL"); + // return VCD_ERROR_OUT_OF_MEMORY; + // } - dbus_message_append_args(msg, DBUS_TYPE_INT32, &reason, DBUS_TYPE_INT32, &daemon_pid, DBUS_TYPE_STRING, &err_msg, DBUS_TYPE_INVALID); + // dbus_message_append_args(msg, DBUS_TYPE_INT32, &reason, DBUS_TYPE_INT32, &daemon_pid, DBUS_TYPE_STRING, &err_msg, DBUS_TYPE_INVALID); - if (1 != dbus_connection_send(g_conn_sender, msg, NULL)) { - SLOG(LOG_ERROR, TAG_VCD, "[Dbus ERROR] Fail to Send"); - return VCD_ERROR_OPERATION_FAILED; - } else { - SLOG(LOG_INFO, TAG_VCD, "@@ Send error signal to widget : reason(%d), daemon_pid(%d), Error Msg(%s)", reason, daemon_pid, err_msg); - dbus_connection_flush(g_conn_sender); - } + // if (1 != dbus_connection_send(g_conn_sender, msg, NULL)) { + // SLOG(LOG_ERROR, TAG_VCD, "[Dbus ERROR] Fail to Send"); + // return VCD_ERROR_OPERATION_FAILED; + // } else { + // SLOG(LOG_INFO, TAG_VCD, "@@ Send error signal to widget : reason(%d), daemon_pid(%d), Error Msg(%s)", reason, daemon_pid, err_msg); + // dbus_connection_flush(g_conn_sender); + // } - dbus_message_unref(msg); + // dbus_message_unref(msg); return 0; } @@ -671,27 +558,6 @@ static Eina_Bool listener_event_callback(void* data, Ecore_Fd_Handler *fd_handle else if (dbus_message_is_method_call(msg, VC_SERVER_SERVICE_INTERFACE, VC_METHOD_REQUEST_CANCEL)) vcd_dbus_server_cancel_request(g_conn_listener, msg); #endif - /* widget event */ - else if (dbus_message_is_method_call(msg, VC_SERVER_SERVICE_INTERFACE, VC_WIDGET_METHOD_INITIALIZE)) - vcd_dbus_server_widget_initialize(g_conn_listener, msg); - - else if (dbus_message_is_method_call(msg, VC_SERVER_SERVICE_INTERFACE, VC_WIDGET_METHOD_FINALIZE)) - vcd_dbus_server_widget_finalize(g_conn_listener, msg); - - else if (dbus_message_is_method_call(msg, VC_SERVER_SERVICE_INTERFACE, VC_WIDGET_METHOD_START_RECORDING)) - vcd_dbus_server_widget_start_recording(g_conn_listener, msg); - - else if (dbus_message_is_method_call(msg, VC_SERVER_SERVICE_INTERFACE, VC_WIDGET_METHOD_START)) - vcd_dbus_server_widget_start(g_conn_listener, msg); - - else if (dbus_message_is_method_call(msg, VC_SERVER_SERVICE_INTERFACE, VC_WIDGET_METHOD_STOP)) - vcd_dbus_server_widget_stop(g_conn_listener, msg); - - else if (dbus_message_is_method_call(msg, VC_SERVER_SERVICE_INTERFACE, VC_WIDGET_METHOD_CANCEL)) - vcd_dbus_server_widget_cancel(g_conn_listener, msg); - - else if (dbus_message_is_method_call(msg, VC_SERVER_SERVICE_INTERFACE, VC_WIDGET_METHOD_ENABLE_ASR_RESULT)) - vcd_dbus_server_widget_enable_asr_result(g_conn_listener, msg); else if (dbus_message_is_method_call(msg, VC_SERVER_SERVICE_INTERFACE, VC_SETTING_METHOD_SET_LANGUAGE)) vcd_dbus_server_set_language(g_conn_listener, msg); diff --git a/server/vcd_dbus.h b/server/vcd_dbus.h index 7f07726..fcfaad3 100644 --- a/server/vcd_dbus.h +++ b/server/vcd_dbus.h @@ -32,25 +32,17 @@ int vcd_check_dbus_connection(); int vcdc_send_hello(int pid, vcd_client_type_e type); -int vcdc_send_show_tooltip(int pid, bool show); - int vcdc_send_result(int pid, int manager_pid, int cmd_type); -int vcdc_send_asr_result(int pid, int event, const char* asr_result, int cmd_type, bool* is_consumed); - int vcdc_send_error_signal(int reason, char *err_msg); int vcdc_send_error_signal_to_app(int pid, int reason, char *err_msg); int vcdc_send_manager_pid(int manager_pid); -// int vcdc_send_request_get_private_data(int pid, const char* key, char** data); - /* for TTS feedback */ int vcdc_send_feedback_streaming(int pid, int utt_id, vc_feedback_event_e event, char* buffer, int len); -// int vcdc_send_feedback_streaming_to_manager(int manager_pid, int pid, int utt_id, vc_feedback_event_e event, char* buffer, int len); - #ifdef __cplusplus } #endif diff --git a/server/vcd_server.c b/server/vcd_server.c index 7f0d713..ae36531 100644 --- a/server/vcd_server.c +++ b/server/vcd_server.c @@ -1350,7 +1350,7 @@ int vcd_initialize(vce_request_callback_s *callback) } /* Open tidl connection */ - if (0 != vcd_mgr_tidl_open_connection()) { + if (0 != vcd_tidl_open_connection()) { SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to open tidl connection"); if (TRUE != vcd_finalize()) { SLOG(LOG_ERROR, TAG_VCD, "[Server Error] Fail to finalize"); @@ -1442,7 +1442,7 @@ bool vcd_finalize() } /* Close tidl connection */ - if (0 != vcd_mgr_tidl_close_connection()) { + if (0 != vcd_tidl_close_connection()) { SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to close connection"); } diff --git a/server/vcd_tidl.c b/server/vcd_tidl.c index d5917a5..3ed737c 100644 --- a/server/vcd_tidl.c +++ b/server/vcd_tidl.c @@ -22,95 +22,97 @@ #include "vcd_tidl.h" #include "vcd_mgr_stub.h" #include "vcd_mgr_proxy.h" +#include "vcd_widget_stub.h" +#include "vcd_widget_proxy.h" static rpc_port_stub_vc_mgr_callback_s g_mgr_callback; static pthread_mutex_t g_mgr_tidl_info_mutex = PTHREAD_MUTEX_INITIALIZER; -static int g_volume_count = 0; - -static void __on_connected(rpc_port_proxy_vcd_mgr_h h, void *user_data) -{ - manager_tidl_info_s* mgr_tidl_info = vcd_client_manager_get_tidl_info(); - - if (NULL == mgr_tidl_info) { - SLOG(LOG_ERROR, TAG_VCD, "[TIDL] tidl proxy info not allocated"); - return; - } - - mgr_tidl_info->connected = true; - mgr_tidl_info->connection_requesting = false; - - SLOG(LOG_INFO, TAG_VCD, "Connected to manager"); -} - -static void __on_disconnected(rpc_port_proxy_vcd_mgr_h h, void *user_data) -{ - manager_tidl_info_s* mgr_tidl_info = vcd_client_manager_get_tidl_info(); +static rpc_port_stub_vc_widget_callback_s g_widget_callback; - if (NULL == mgr_tidl_info) { - SLOG(LOG_ERROR, TAG_VCD, "[TIDL] tidl proxy info not allocated"); - return; - } +static pthread_mutex_t g_widget_tidl_info_mutex = PTHREAD_MUTEX_INITIALIZER; - mgr_tidl_info->connected = false; - mgr_tidl_info->connection_requesting = false; +static int g_volume_count = 0; - SLOG(LOG_INFO, TAG_VCD, "Disonnected to manager"); -} +int vcd_mgr_tidl_open_connection(); +int vcd_mgr_tidl_close_connection(); +int vcd_widget_tidl_open_connection(); +int vcd_widget_tidl_close_connection(); -static void __on_rejected(rpc_port_proxy_vcd_mgr_h h, void *user_data) +/* for common request */ +static void __request_tidl_connect(vcd_client_type_e type, int pid) { - manager_tidl_info_s* mgr_tidl_info = vcd_client_manager_get_tidl_info(); + char* type_str = NULL; + int ret = -1; - if (NULL == mgr_tidl_info) { - SLOG(LOG_ERROR, TAG_VCD, "[TIDL] tidl proxy info not allocated"); - return; - } + if (VCD_CLIENT_TYPE_MANAGER == type) { + manager_tidl_info_s* mgr_tidl_info = vcd_client_manager_get_tidl_info(); + if (NULL == mgr_tidl_info) { + SLOG(LOG_ERROR, TAG_VCD, "[TIDL] manager tidl info not allocated"); + return; + } - mgr_tidl_info->connection_requesting = false; + if (mgr_tidl_info->connection_requesting) { + return; + } - SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Rejected from manager"); -} + ret = rpc_port_proxy_vcd_mgr_connect(mgr_tidl_info->rpc_h); -static rpc_port_proxy_vcd_mgr_h __create_rpc_port(const char* engine_app_id, manager_tidl_info_s* mgr_tidl_info) -{ - SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] __create_rpc_port"); - rpc_port_proxy_vcd_mgr_callback_s rpc_callback = { - .connected = __on_connected, - .disconnected = __on_disconnected, - .rejected = __on_rejected - }; + if (0 == ret) { + mgr_tidl_info->connection_requesting = true; + } + type_str = "manager"; + // TODO: uncomment after client done + // } else if (VCD_CLIENT_TYPE_NORMAL == type) { + // client_tidl_info_s* client_tidl_info = vcd_client_client_get_tidl_info(pid); + // if (NULL == client_tidl_info) { + // SLOG(LOG_ERROR, TAG_VCD, "[TIDL] client tidl info not allocated"); + // return; + // } + + // if (client_tidl_info->connection_requesting) { + // return; + // } + + // ret = rpc_port_proxy_vcd_client_connect(client_tidl_info->rpc_h); + + // if (0 == ret) { + // SLOG(LOG_ERROR, TAG_VCD, "[TIDL] tidl proxy info not allocated"); + // client_tidl_info->connection_requesting = true; + // } + // type_str = "client"; + } else if (VCD_CLIENT_TYPE_WIDGET == type) { + widget_tidl_info_s* widget_tidl_info = vcd_client_widget_get_tidl_info(pid); + if (NULL == widget_tidl_info) { + SLOG(LOG_ERROR, TAG_VCD, "[TIDL] widget tidl info not allocated"); + return; + } - rpc_port_proxy_vcd_mgr_h handle = NULL; - if (0 != rpc_port_proxy_vcd_mgr_create(engine_app_id, &rpc_callback, NULL, &handle)) { - SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to create proxy"); - return NULL; - } + if (widget_tidl_info->connection_requesting) { + return; + } - return handle; -} + ret = rpc_port_proxy_vcd_widget_connect(widget_tidl_info->rpc_h); -static void __request_tidl_connect_sync(manager_tidl_info_s* mgr_tidl_info) -{ - if (NULL == mgr_tidl_info) { + if (0 == ret) { SLOG(LOG_ERROR, TAG_VCD, "[TIDL] tidl proxy info not allocated"); + widget_tidl_info->connection_requesting = true; + } + type_str = "widget"; + } else { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] client type is NOT valid(%d)", type); return; } - if (mgr_tidl_info->connection_requesting) { - return; - } - - int ret = rpc_port_proxy_vcd_mgr_connect_sync(mgr_tidl_info->rpc_h); - SLOG(LOG_INFO, TAG_VCD, "[INFO] Request connection to stub. ret(%d)", ret); - - if (0 == ret) { - mgr_tidl_info->connection_requesting = true; + if (RPC_PORT_ERROR_NONE != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Request connection to %s stub. ret(%d)", type_str, ret); + } else { + SLOG(LOG_INFO, TAG_VCD, "[INFO] Request connection to %s stub. ret(%d)", type_str, ret); } } -void __send_msg(bundle* msg, vcd_client_type_e type) +void __send_msg(bundle* msg, vcd_client_type_e type, int pid) { SLOG(LOG_INFO, TAG_VCD, "[TIDL] send msg start"); @@ -138,1067 +140,1805 @@ void __send_msg(bundle* msg, vcd_client_type_e type) return; } pthread_mutex_unlock(&g_mgr_tidl_info_mutex); - } - - SLOG(LOG_INFO, TAG_VCD, "[TIDL] send msg end"); -} + // TODO: uncomment after client done + // } else if (VCD_CLIENT_TYPE_NORMAL == type) { + // pthread_mutex_lock(&g_client_tidl_info_mutex); + + // SLOG(LOG_INFO, TAG_VCD, "[TIDL] message to client"); + // client_tidl_info_s* client_tidl_info = vcd_client_client_get_tidl_info(pid); + // if (NULL == client_tidl_info) { + // SLOG(LOG_ERROR, TAG_VCD, "[TIDL] tidl proxy info not allocated"); + // pthread_mutex_unlock(&g_client_tidl_info_mutex); + // return; + // } + + // rpc_port_stub_vc_client_notify_cb_h handle = client_tidl_info->notify_cb; + // if (NULL == handle) { + // SLOG(LOG_ERROR, TAG_VCD, "[TIDL] notify callback handle is null"); + // pthread_mutex_unlock(&g_client_tidl_info_mutex); + // return; + // } + + // if (0 != rpc_port_stub_vc_client_notify_cb_invoke(handle, msg)) { + // SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to send msg"); + // pthread_mutex_unlock(&g_client_tidl_info_mutex); + // return; + // } + // pthread_mutex_unlock(&g_client_tidl_info_mutex); + } else if (VCD_CLIENT_TYPE_WIDGET == type) { + pthread_mutex_lock(&g_widget_tidl_info_mutex); + + SLOG(LOG_INFO, TAG_VCD, "[TIDL] message to widget"); + widget_tidl_info_s* widget_tidl_info = vcd_client_widget_get_tidl_info(pid); + if (NULL == widget_tidl_info) { + SLOG(LOG_ERROR, TAG_VCD, "[TIDL] tidl proxy info not allocated"); + pthread_mutex_unlock(&g_widget_tidl_info_mutex); + return; + } -static void __vc_mgr_create_cb(rpc_port_stub_vc_mgr_context_h context, void *user_data) -{ - char *sender = NULL; + rpc_port_stub_vc_widget_notify_cb_h handle = widget_tidl_info->notify_cb; + if (NULL == handle) { + SLOG(LOG_ERROR, TAG_VCD, "[TIDL] notify callback handle is null"); + pthread_mutex_unlock(&g_widget_tidl_info_mutex); + return; + } - rpc_port_stub_vc_mgr_context_get_sender(context, &sender); - if (!sender){ - SLOG(LOG_ERROR, TAG_VCD, "Sender is NULL"); + if (0 != rpc_port_stub_vc_widget_notify_cb_invoke(handle, msg)) { + SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to send msg"); + pthread_mutex_unlock(&g_widget_tidl_info_mutex); + return; + } + pthread_mutex_unlock(&g_widget_tidl_info_mutex); + } else { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] client type is NOT valid(%d)", type); return; } - - SLOG(LOG_DEBUG, TAG_VCD, "@@@ Manager connect. appid(%s)", sender); - - free(sender); } -static void __vc_mgr_terminate_cb(rpc_port_stub_vc_mgr_context_h context, void *user_data) +void __send_signal(bundle* msg) { + SLOG(LOG_INFO, TAG_VCD, "[TIDL] send signal start"); + pthread_mutex_lock(&g_mgr_tidl_info_mutex); + + SLOG(LOG_INFO, TAG_VCD, "[TIDL] message to manager"); manager_tidl_info_s* mgr_tidl_info = vcd_client_manager_get_tidl_info(); if (NULL == mgr_tidl_info) { - SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to get manager tidl info."); + SLOG(LOG_ERROR, TAG_VCD, "[TIDL] tidl proxy info not allocated"); pthread_mutex_unlock(&g_mgr_tidl_info_mutex); return; } - SLOG(LOG_DEBUG, TAG_VCD, "@@@ VC MANAGER FINALIZE. pid(%u)", mgr_tidl_info->pid); - - if (0 != vcd_client_manager_unset_tidl_notify_cb()) { - SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to unset notify callback"); + rpc_port_stub_vc_mgr_notify_cb_h handle = mgr_tidl_info->notify_cb; + if (NULL == handle) { + SLOG(LOG_ERROR, TAG_VCD, "[TIDL] notify callback handle is null"); + pthread_mutex_unlock(&g_mgr_tidl_info_mutex); + return; } - if (0 != vcd_client_manager_unset_tidl_send_buffer_cb()) { - SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to unset send buffer callback"); + if (0 != rpc_port_stub_vc_mgr_notify_cb_invoke(handle, msg)) { + SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to send msg"); + pthread_mutex_unlock(&g_mgr_tidl_info_mutex); + return; } + pthread_mutex_unlock(&g_mgr_tidl_info_mutex); - if (0 != vcd_client_manager_delete_tidl_info()) { - SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to delete manager tidl info"); - } - mgr_tidl_info = NULL; + GSList *iter = NULL; - SLOG(LOG_DEBUG, TAG_VCD, "@@@"); + // TODO: uncomment after client done + // pthread_mutex_lock(&g_client_tidl_info_mutex); + // GSList* client_list = vcd_client_client_get_tidl_info_list(); - pthread_mutex_unlock(&g_mgr_tidl_info_mutex); + // int count = g_slist_length(g_client_ipc_info_list); + // int i; + // client_tidl_info_s *client_tidl_info = NULL; - char *sender = NULL; - rpc_port_stub_vc_mgr_context_get_sender(context, &sender); - if (!sender) - return; + // if (0 < count) { + // iter = g_slist_nth(client_list, 0); + // for (i = 0; i < count; i++) { + // if (NULL == iter) { + // SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] client list iterator broken"); + // break; + // } - SLOG(LOG_INFO, TAG_VCD, "@@@ Manager disconnect. appid(%s)", sender); + // client_tidl_info = iter->data; - free(sender); -} + // if (NULL == client_tidl_info) { + // SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] client list data broken"); + // break; + // } -static void __vc_mgr_register_cb_cb(rpc_port_stub_vc_mgr_context_h context, int pid, rpc_port_stub_vc_mgr_notify_cb_h notify_callback, rpc_port_stub_vc_mgr_send_buffer_cb_h send_buffer_callback, void *user_data) -{ - pthread_mutex_lock(&g_mgr_tidl_info_mutex); - SLOG(LOG_INFO, TAG_VCD, "@@@ VC MANAGER REGISTER CALLBACK"); + // SLOG(LOG_INFO, TAG_VCD, "[TIDL] message to client"); - int ret = -1; - ret = vcd_client_manger_create_tidl_info(pid); + // rpc_port_stub_vc_client_notify_cb_h handle = client_tidl_info->notify_cb; + // if (NULL == handle) { + // SLOG(LOG_ERROR, TAG_VCD, "[TIDL] notify callback handle is null"); + // break; + // } - if (0 != ret) { - SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to create manager tidl info."); - pthread_mutex_unlock(&g_mgr_tidl_info_mutex); - return; - } + // if (0 != rpc_port_stub_vc_client_notify_cb_invoke(handle, msg)) { + // SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to send msg"); + // break; + // } - manager_tidl_info_s* mgr_tidl_info = vcd_client_manager_get_tidl_info(); + // iter = g_slist_next(iter); + // } + // } + // pthread_mutex_unlock(&g_client_tidl_info_mutex); + + pthread_mutex_lock(&g_widget_tidl_info_mutex); + GSList* widget_list = vcd_client_widget_get_tidl_info_list(); - if (NULL == mgr_tidl_info) { - SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to get manager tidl info. pid(%d)", pid); - pthread_mutex_unlock(&g_mgr_tidl_info_mutex); - return; - } + int count = g_slist_length(widget_list); + int i; - char *sender = NULL; - rpc_port_stub_vc_mgr_context_get_sender(context, &sender); + widget_tidl_info_s *widget_tidl_info = NULL; - if (!sender){ - SLOG(LOG_ERROR, TAG_VCD, "Sender is NULL"); - pthread_mutex_unlock(&g_mgr_tidl_info_mutex); - return; - } + if (0 < count) { + iter = g_slist_nth(widget_list, 0); + for (i = 0; i < count; i++) { + if (NULL == iter) { + SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] widget list iterator broken"); + break; + } - mgr_tidl_info->rpc_h = __create_rpc_port(sender, mgr_tidl_info); + widget_tidl_info = iter->data; - if (NULL == mgr_tidl_info->rpc_h) { - SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to create server proxy"); - } else { - SLOG(LOG_INFO, TAG_VCD, "[TIDL] rpc_h(%p), engine_app_id(%s)", mgr_tidl_info->rpc_h, sender); - } + if (NULL == widget_tidl_info) { + SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] widget list data broken"); + break; + } - free(sender); + SLOG(LOG_INFO, TAG_VCD, "[TIDL] message to widget"); - if (0 != vcd_client_manager_set_tidl_notify_cb(notify_callback, user_data)) { - SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to set notify callback"); - } else { - SLOG(LOG_INFO, TAG_VCD, "[TIDL] Succeed to set notify callback."); - } + rpc_port_stub_vc_widget_notify_cb_h handle = widget_tidl_info->notify_cb; + if (NULL == handle) { + SLOG(LOG_ERROR, TAG_VCD, "[TIDL] notify callback handle is null"); + break; + } - if (0 != vcd_client_manager_set_tidl_send_buffer_cb(send_buffer_callback, user_data)) { - SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to set send buffer callback"); + if (0 != rpc_port_stub_vc_widget_notify_cb_invoke(handle, msg)) { + SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to send msg"); + break; + } + + iter = g_slist_next(iter); + } + } + pthread_mutex_unlock(&g_widget_tidl_info_mutex); +} + +// TODO: remove _tidl after all dbus removed +int vcdc_tidl_send_hello(int pid, vcd_client_type_e type) +{ + SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Send hello"); + + char tmp_pid[10] = {0, }; + + bundle* msg = bundle_create(); + snprintf(tmp_pid, 10, "%d", pid); + + if (VCD_CLIENT_TYPE_NORMAL == type) { + // bundle_add_str(msg, VC_CLIENT_BUNDLE_METHOD, VCD_CLIENT_METHOD_HELLO); + // bundle_add_str(msg, VC_CLIENT_BUNDLE_MESSAGE, tmp_pid); + } else if (VCD_CLIENT_TYPE_MANAGER == type) { + bundle_add_str(msg, VC_MANAGER_BUNDLE_METHOD, VCD_MANAGER_METHOD_HELLO); + bundle_add_str(msg, VC_MANAGER_BUNDLE_MESSAGE, tmp_pid); + } else if (VCD_CLIENT_TYPE_WIDGET == type) { + bundle_add_str(msg, VC_WIDGET_BUNDLE_METHOD, VCD_WIDGET_METHOD_HELLO); + bundle_add_str(msg, VC_WIDGET_BUNDLE_MESSAGE, tmp_pid); } else { - SLOG(LOG_INFO, TAG_VCD, "[TIDL] Succeed to set send buffer callback."); + SLOG(LOG_ERROR, TAG_VCD, "[Dbus ERROR] Client type is NOT valid"); + bundle_free(msg); + return VCD_ERROR_INVALID_PARAMETER; } - pthread_mutex_unlock(&g_mgr_tidl_info_mutex); + SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] VCD SEND MESSAGE"); - __request_tidl_connect_sync(mgr_tidl_info); + __send_msg(msg, VCD_CLIENT_TYPE_MANAGER, pid); + bundle_free(msg); - SLOG(LOG_DEBUG, TAG_VCD, "@@@"); + return VCD_ERROR_NONE; } -static int __vc_mgr_initialize_cb(rpc_port_stub_vc_mgr_context_h context, int pid, int audio_streaming_mode, int *service_state, int *foreground, int *daemon_pid, void *user_data) +int vcd_tidl_open_connection() { - SLOG(LOG_INFO, TAG_VCD, "@@@ VCD Manager Initialize"); + SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] vcd_tidl_open_connection"); - int ret = -1; + if (0 != vcd_mgr_tidl_open_connection()) { + SLOG(LOG_ERROR, TAG_VCD, "Fail to open connection to manager"); + return VCD_ERROR_OPERATION_FAILED; + } - vcd_config_set_audio_streaming_mode((vcd_audio_streaming_mode_e)audio_streaming_mode); - ret = vcd_server_mgr_initialize(pid, audio_streaming_mode); - if (0 != ret) { - SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret); - return ret; + // TODO: uncomment after client done + // if (0 != vcd_client_tidl_open_connection()) { + // SLOG(LOG_ERROR, TAG_VCD, "Fail to open connection to client"); + // return VCD_ERROR_OPERATION_FAILED; + // } + + if (0 != vcd_widget_tidl_open_connection()) { + SLOG(LOG_ERROR, TAG_VCD, "Fail to open connection to widget"); + return VCD_ERROR_OPERATION_FAILED; } - *service_state = vcd_server_get_service_state(); - *foreground = vcd_server_get_foreground(); - *daemon_pid = getpid(); - 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); - SLOG(LOG_DEBUG, TAG_VCD, "@@@"); - return ret; + return VCD_ERROR_NONE; } -static int __vc_mgr_finalize_cb(rpc_port_stub_vc_mgr_context_h context, int pid, void *user_data) +int vcd_tidl_close_connection() { - SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Manager Finalize"); - SLOG(LOG_INFO, TAG_VCD, "[IN] vcd mgr finalize : pid(%d)", pid); - - int ret = -1; + SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] vcd_tidl_close_connection"); - ret = vcd_server_mgr_finalize(pid); - if (0 != ret) { - SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret); + if (0 != vcd_mgr_tidl_close_connection()) { + SLOG(LOG_ERROR, TAG_VCD, "Fail to close connection to manager"); + return VCD_ERROR_OPERATION_FAILED; } - SLOG(LOG_DEBUG, TAG_VCD, "@@@"); + // TODO: uncomment after client done + // if (0 != vcd_client_tidl_close_connection()) { + // SLOG(LOG_ERROR, TAG_VCD, "Fail to close connection to client"); + // return VCD_ERROR_OPERATION_FAILED; + // } - return ret; + if (0 != vcd_widget_tidl_close_connection()) { + SLOG(LOG_ERROR, TAG_VCD, "Fail to close connection to widget"); + return VCD_ERROR_OPERATION_FAILED; + } + + return VCD_ERROR_NONE; } -static int __vc_mgr_set_command_cb(rpc_port_stub_vc_mgr_context_h context, int pid, void *user_data) +int vcdc_send_set_volume(int manager_pid, float volume) { - SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Manager Set command"); - SLOG(LOG_INFO, TAG_VCD, "[IN] vcd mgr set command : pid(%d)", pid); + SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Set volume"); - int ret = -1; + char tmp_volume[20] = {0, }; - ret = vcd_server_mgr_set_command(pid); - if (0 != ret) { - SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret); - return ret; + bundle* msg = bundle_create(); + + snprintf(tmp_volume, 20, "%.6f", volume); + bundle_add_str(msg, VC_MANAGER_BUNDLE_METHOD, VCD_MANAGER_METHOD_SET_VOLUME); + bundle_add_str(msg, VC_MANAGER_BUNDLE_MESSAGE, tmp_volume); + + + SLOG(LOG_DEBUG, TAG_VCD, ">>>> VCD SEND MESSAGE"); + __send_msg(msg, VCD_CLIENT_TYPE_MANAGER, manager_pid); + if (20 == g_volume_count) { + SLOG(LOG_INFO, TAG_VCD, "@@ Send set volume : pid(%d), volume(%f)", manager_pid, volume); + g_volume_count = 0; } + g_volume_count++; - SLOG(LOG_DEBUG, TAG_VCD, "@@@"); + bundle_free(msg); - return ret; + return VCD_ERROR_NONE; } -static int __vc_mgr_unset_command_cb(rpc_port_stub_vc_mgr_context_h context, int pid, void *user_data) +int vcdc_send_show_tooltip(int pid, bool show) { - SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Manager unset command"); - SLOG(LOG_INFO, TAG_VCD, "[IN] vcd mgr unset command : pid(%d)", pid); + SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Send pre result to manager"); - int ret = -1; + char tmp_pid[10] = {0, }; + char tmp_show[10] = {0, }; - ret = vcd_server_mgr_unset_command(pid); - if (0 != ret) { - SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret); - return ret; - } - - SLOG(LOG_DEBUG, TAG_VCD, "@@@"); - - return ret; -} + bundle* msg = bundle_create(); -static int __vc_mgr_set_demandable_client_cb(rpc_port_stub_vc_mgr_context_h context, int pid, void *user_data) -{ - SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Manager Set demandable client"); - SLOG(LOG_INFO, TAG_VCD, "[IN] vcd mgr set demandable client : pid(%d)", pid); + snprintf(tmp_pid, 10, "%d", pid); + snprintf(tmp_show, 10, "%d", (int)show); - int ret = -1; + bundle_add_str(msg, VC_WIDGET_BUNDLE_METHOD, VCD_WIDGET_METHOD_SHOW_TOOLTIP); + bundle_add_str(msg, VC_WIDGET_BUNDLE_MESSAGE, tmp_pid); + bundle_add_str(msg, VC_WIDGET_BUNDLE_SHOW, tmp_show); - ret = vcd_server_mgr_set_demandable_client(pid); - if (0 != ret) { - SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret); - return ret; - } + SLOG(LOG_DEBUG, TAG_VCD, ">>>> VCD SEND MESSAGE"); - SLOG(LOG_DEBUG, TAG_VCD, "@@@"); + __send_msg(msg, VCD_CLIENT_TYPE_WIDGET, pid); + bundle_free(msg); - return ret; + return VCD_ERROR_NONE; } -static int __vc_mgr_set_audio_type_cb(rpc_port_stub_vc_mgr_context_h context, int pid, const char *audio_type, void *user_data) +// TODO: remove tidl after all dbus migrate to tidl +int vcdc_tidl_send_result(int pid, int manager_pid, vcd_client_type_e type) { - SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Manager set audio type"); - SLOG(LOG_INFO, TAG_VCD, "[IN] vcd mgr set audio type : pid(%d), audio type(%s)", pid, audio_type); + SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Send result"); - int ret = -1; + bundle* msg = bundle_create(); - ret = vcd_server_mgr_set_audio_type(pid, audio_type); - if (0 != ret) { - SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret); - return ret; + if (VCD_CLIENT_TYPE_MANAGER == type) { + bundle_add_str(msg, VC_MANAGER_BUNDLE_METHOD, VCD_MANAGER_METHOD_RESULT); + // TODO: uncomment after client done + // } else if (VCD_CLIENT_TYPE_NORMAL == type) { + // // bundle_add_str(msg, VC_CLIENT_BUNDLE_METHOD, VCD_METHOD_RESULT); + } else if (VCD_CLIENT_TYPE_WIDGET == type) { + bundle_add_str(msg, VC_WIDGET_BUNDLE_METHOD, VCD_WIDGET_METHOD_RESULT); + } else { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] client type is NOT valid(%d)", type); + bundle_free(msg); + return VCD_ERROR_INVALID_PARAMETER; } - SLOG(LOG_DEBUG, TAG_VCD, "@@@"); + SLOG(LOG_DEBUG, TAG_VCD, ">>>> VCD SEND MESSAGE"); - return ret; + __send_msg(msg, type, pid); + bundle_free(msg); + + return VCD_ERROR_NONE; } -static int __vc_mgr_get_audio_type_cb(rpc_port_stub_vc_mgr_context_h context, int pid, char **audio_type, void *user_data) +int vcdc_send_pre_result_to_manager(int manager_pid, int event, const char* pre_result) { - SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Manager get audio type"); - SLOG(LOG_INFO, TAG_VCD, "[IN] vcd mgr set audio type : pid(%d)", pid); - - int ret = -1; - char* tmp_audio_type = NULL; - - ret = vcd_server_mgr_get_audio_type(pid, &tmp_audio_type); - if (0 != ret) { - SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret); - free(tmp_audio_type); - return ret; - } - - *audio_type = strdup(tmp_audio_type); - free(tmp_audio_type); + SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Send pre result to manager"); - SLOG(LOG_DEBUG, TAG_VCD, "@@@"); + char tmp_event[10] = {0, }; - return ret; -} + bundle* msg = bundle_create(); + snprintf(tmp_event, 10, "%d", event); -static void __vc_mgr_set_private_data_cb(rpc_port_stub_vc_mgr_context_h context, int pid, const char *key, const char *data, void *user_data) -{ - SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Manager set private data"); - SLOG(LOG_INFO, TAG_VCD, "[IN] vcd mgr set domain : pid(%d), key(%s), data(%s)", pid, key, data); + bundle_add_str(msg, VC_MANAGER_BUNDLE_METHOD, VCD_MANAGER_METHOD_PRE_RESULT); + bundle_add_str(msg, VC_MANAGER_BUNDLE_EVENT, tmp_event); + bundle_add_str(msg, VC_MANAGER_BUNDLE_PRE_RESULT, pre_result); - int ret = -1; + SLOG(LOG_DEBUG, TAG_VCD, ">>>> VCD SEND MESSAGE"); - ret = vcd_server_mgr_set_private_data(pid, key, data); - if (0 != ret) { - SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to set private data"); - SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret); - } + __send_msg(msg, VCD_CLIENT_TYPE_MANAGER, manager_pid); + bundle_free(msg); - SLOG(LOG_DEBUG, TAG_VCD, "@@@"); + return VCD_ERROR_NONE; } -static int __vc_mgr_get_private_data_cb(rpc_port_stub_vc_mgr_context_h context, int pid, const char *key, char **data, void *user_data) +int vcdc_send_specific_engine_result_to_manager(int manager_pid, const char* engine_app_id, const char* event, const char* result) { - SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Manager get private data"); - SLOG(LOG_INFO, TAG_VCD, "[IN] vcd mgr get private data : pid(%d), key(%s)", pid, key); - - int ret = -1; - char *temp_data = NULL; - - ret = vcd_server_mgr_get_private_data(pid, key, &temp_data); - if (0 != ret) { - SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret); - return ret; - } - if (NULL == temp_data) { - SLOG(LOG_INFO, TAG_VCD, "data parameter is NULL"); - temp_data = strdup("#NULL"); - } - - *data = strdup(temp_data); - free(temp_data); + SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Send specific engine result to manager"); - SLOG(LOG_DEBUG, TAG_VCD, "@@@"); + bundle* msg = bundle_create(); - return ret; -} + gchar *gEncodedResult = g_base64_encode((const guchar*)result, strlen(result)); -static int __vc_mgr_set_client_info_cb(rpc_port_stub_vc_mgr_context_h context, int pid, void *user_data) -{ - SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Manager set client info"); - SLOG(LOG_INFO, TAG_VCD, "[IN] vcd mgr set client info : pid(%d)", pid); + bundle_add_str(msg, VC_MANAGER_BUNDLE_METHOD, VCD_MANAGER_METHOD_SPECIFIC_ENGINE_RESULT); + bundle_add_str(msg, VC_MANAGER_BUNDLE_ENGINE_APP_ID, engine_app_id); + bundle_add_str(msg, VC_MANAGER_BUNDLE_EVENT, event); + bundle_add_str(msg, VC_MANAGER_BUNDLE_RESULT, gEncodedResult); - int ret = -1; + SLOG(LOG_DEBUG, TAG_VCD, ">>>> VCD SEND MESSAGE"); - ret = vcd_server_mgr_set_client_info(pid); - if (0 != ret) { - SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret); - return ret; - } + __send_msg(msg, VCD_CLIENT_TYPE_MANAGER, manager_pid); + bundle_free(msg); - SLOG(LOG_DEBUG, TAG_VCD, "@@@"); + if (gEncodedResult) + g_free(gEncodedResult); - return ret; + return VCD_ERROR_NONE; } -static int __vc_mgr_set_domain_cb(rpc_port_stub_vc_mgr_context_h context, int pid, const char *domain, void *user_data) +int vcdc_send_result_to_manager(int manager_pid, int result_type) { - SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Manager set domain type"); - SLOG(LOG_INFO, TAG_VCD, "[IN] vcd mgr set domain : pid(%d), domain(%s)", pid, domain); - - int ret = -1; + SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Send result to manager"); - ret = vcd_server_mgr_set_domain(pid, domain); - if (0 != ret) { - SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret); - return ret; - } + char tmp_result[10] = {0, }; - SLOG(LOG_DEBUG, TAG_VCD, "@@@"); + bundle* msg = bundle_create(); + snprintf(tmp_result, 10, "%d", result_type); - return ret; -} + bundle_add_str(msg, VC_MANAGER_BUNDLE_METHOD, VCD_MANAGER_METHOD_ALL_RESULT); + bundle_add_str(msg, VC_MANAGER_BUNDLE_MESSAGE, tmp_result); -static void __vc_mgr_do_action_cb(rpc_port_stub_vc_mgr_context_h context, int pid, int type, const char *send_event, void *user_data) -{ - SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Manager request to do action"); - SLOG(LOG_INFO, TAG_VCD, "[IN] vcd mgr request to do action : pid(%d), type(%d) send_event(%s)", pid, type, send_event); - int ret = -1; + SLOG(LOG_DEBUG, TAG_VCD, ">>>> VCD SEND MESSAGE"); - ret = vcd_server_mgr_do_action(pid, type, send_event); - if (0 != ret) { - SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret); - } + __send_msg(msg, VCD_CLIENT_TYPE_MANAGER, manager_pid); + bundle_free(msg); - SLOG(LOG_DEBUG, TAG_VCD, "@@@"); + return VCD_ERROR_NONE; } -static int __vc_mgr_start_cb(rpc_port_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) +int vcdc_send_speech_detected(int manager_pid) { - SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Manager start"); - SLOG(LOG_INFO, TAG_VCD, "[IN] vcd check enabled or disabled command types. disabled cmd type(%d)", disabled_cmd_type); + SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Send speech detected"); - int ret = -1; + bundle* msg = bundle_create(); - vcd_server_mgr_set_disabled_command_type(pid, disabled_cmd_type); + bundle_add_str(msg, VC_MANAGER_BUNDLE_METHOD, VCD_MANAGER_METHOD_SPEECH_DETECTED); - 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); - ret = vcd_server_mgr_start((vcd_recognition_mode_e)recognition_mode, exclusive_command_option, start_by_client); - if (0 != ret) { - SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret); - return ret; - } + SLOG(LOG_DEBUG, TAG_VCD, ">>>> VCD SEND MESSAGE"); - SLOG(LOG_DEBUG, TAG_VCD, "@@@"); + __send_msg(msg, VCD_CLIENT_TYPE_MANAGER, manager_pid); + bundle_free(msg); - return ret; + return VCD_ERROR_NONE; } -static int __vc_mgr_stop_cb(rpc_port_stub_vc_mgr_context_h context, int pid, void *user_data) +int vcdc_send_service_state(vcd_state_e state) { - SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Manager stop"); - SLOG(LOG_INFO, TAG_VCD, "[IN] vcd mgr stop : pid(%d)", pid); + SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Send service state"); - int ret = -1; + char tmp_state[10] = {0, }; - ret = vcd_server_mgr_stop(); + bundle* msg = bundle_create(); + snprintf(tmp_state, 10, "%d", (int)state); - if (0 != ret) { - SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret); - return ret; - } + bundle_add_str(msg, VC_MANAGER_BUNDLE_METHOD, VCD_MANAGER_METHOD_SET_SERVICE_STATE); + bundle_add_str(msg, VC_MANAGER_BUNDLE_MESSAGE, tmp_state); - SLOG(LOG_DEBUG, TAG_VCD, "@@@"); + // TODO: uncomment after client done + // bundle_add_str(msg, VC_CLIENT_BUNDLE_METHOD, VCD_METHOD_SET_SERVICE_STATE); + // bundle_add_str(msg, VC_CLIENT_BUNDLE_MESSAGE, tmp_state); - return ret; + bundle_add_str(msg, VC_WIDGET_BUNDLE_METHOD, VCD_WIDGET_METHOD_SET_SERVICE_STATE); + bundle_add_str(msg, VC_WIDGET_BUNDLE_MESSAGE, tmp_state); + + SLOG(LOG_DEBUG, TAG_VCD, ">>>> VCD SEND SIGNAL"); + __send_signal(msg); + bundle_free(msg); + + return VCD_ERROR_NONE; } -static int __vc_mgr_cancel_cb(rpc_port_stub_vc_mgr_context_h context, int pid, void *user_data) +int vcdc_send_dialog(int manager_pid, int pid, const char* disp_text, const char* utt_text, int continuous) { - SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Manager cancel"); - SLOG(LOG_INFO, TAG_VCD, "[IN] vcd mgr cancel : pid(%d)", pid); + SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Send dialog"); - int ret = -1; + char tmp_pid[10] = {0, }; + char tmp_continuous[10] = {0, }; + char* tmp_disp_text = NULL; + char* tmp_utt_text = NULL; + bundle* msg = bundle_create(); + snprintf(tmp_pid, 10, "%d", pid); + snprintf(tmp_continuous, 10, "%d", continuous); - ret = vcd_server_mgr_cancel(); - if (0 != ret) { - SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret); - return ret; + if (NULL == disp_text) { + tmp_disp_text = strdup("#NULL"); + } else { + tmp_disp_text = strdup(disp_text); } - SLOG(LOG_DEBUG, TAG_VCD, "@@@"); + if (NULL == utt_text) { + tmp_utt_text = strdup("#NULL"); + } else { + tmp_utt_text = strdup(utt_text); + } - return ret; -} + bundle_add_str(msg, VC_MANAGER_BUNDLE_METHOD, VCD_MANAGER_METHOD_DIALOG); + bundle_add_str(msg, VC_MANAGER_BUNDLE_MESSAGE, tmp_pid); + bundle_add_str(msg, VC_MANAGER_BUNDLE_DISP_TEXT, tmp_disp_text); + bundle_add_str(msg, VC_MANAGER_BUNDLE_UTT_TEXT, tmp_utt_text); + bundle_add_str(msg, VC_MANAGER_BUNDLE_CONTINUOUS, tmp_continuous); -static void __vc_mgr_set_audio_streaming_mode_cb(rpc_port_stub_vc_mgr_context_h context, int pid, int mode, void *user_data) -{ - SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Manager set audio streaming mode"); - SLOG(LOG_INFO, TAG_VCD, "[IN] vcd mgr set audio streaming mode : pid(%d) mode(%d)", pid, mode); + SLOG(LOG_DEBUG, TAG_VCD, ">>>> VCD SEND MESSAGE"); - vcd_config_set_audio_streaming_mode((vcd_audio_streaming_mode_e)mode); + __send_msg(msg, VCD_CLIENT_TYPE_MANAGER, manager_pid); + bundle_free(msg); + free(tmp_disp_text); + free(tmp_utt_text); - SLOG(LOG_DEBUG, TAG_VCD, "@@@"); + return VCD_ERROR_NONE; } -static void __vc_mgr_send_specific_engine_request_cb(rpc_port_stub_vc_mgr_context_h context, int pid, const char *engine_app_id, const char *event, const char *request, void *user_data) +int vcdc_tidl_send_error_to_manager(int manager_pid, int reason, char *err_msg) { - SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Manager specific engine request"); + SLOG(LOG_ERROR, TAG_VCD, "[TIDL] Send error signal to manager"); - int ret = -1; - gsize decodingSize = 0; - gchar *gDecodedRequest = (gchar *)g_base64_decode((const gchar *)request, &decodingSize); - - if (gDecodedRequest) { - ret = vcd_server_mgr_send_specific_engine_request(pid, engine_app_id, event, gDecodedRequest); - if (0 != ret) { - SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret); - } + char tmp_reason[10] = {0, }; + char tmp_daemon_pid[10] = {0, }; + char *temp_msg = NULL; - 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); - g_free(gDecodedRequest); + if (NULL == err_msg) { + SLOG(LOG_WARN, TAG_VCD, "[TIDL ERROR] Input parameter is NULL"); + temp_msg = strdup("#NULL"); + } else { + temp_msg = strdup(err_msg); } - SLOG(LOG_DEBUG, TAG_VCD, "@@@"); -} + bundle* msg = bundle_create(); + snprintf(tmp_reason, 10, "%d", reason); + snprintf(tmp_daemon_pid, 10, "%d", getpid()); -static void __vc_mgr_send_result_selection_cb(rpc_port_stub_vc_mgr_context_h context, int pid, void *user_data) -{ - SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Manager result selection"); - SLOG(LOG_INFO, TAG_VCD, "[IN] vcd mgr result selection : pid(%d)", pid); + bundle_add_str(msg, VC_MANAGER_BUNDLE_METHOD, VCD_MANAGER_METHOD_ERROR); + bundle_add_str(msg, VC_MANAGER_BUNDLE_REASON, tmp_reason); + bundle_add_str(msg, VC_MANAGER_BUNDLE_DAEMON_PID, tmp_daemon_pid); + bundle_add_str(msg, VC_MANAGER_BUNDLE_ERROR_MESSAGE, temp_msg); - vcd_server_mgr_result_select(); + SLOG(LOG_DEBUG, TAG_VCD, ">>>> VCD SEND MESSAGE"); - SLOG(LOG_DEBUG, TAG_VCD, "@@@"); -} + __send_msg(msg, VCD_CLIENT_TYPE_MANAGER, manager_pid); + bundle_free(msg); -static void __vc_mgr_send_utterance_status_cb(rpc_port_stub_vc_mgr_context_h context, int utt_id, int utt_status, void *user_data) -{ - SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Manager send utterance status"); - SLOG(LOG_INFO, TAG_VCD, "[IN] vcd mgr send utterance status : utt_id(%d), utt_status(%d)", utt_id, utt_status); - // TODO: send parameter to client + free(temp_msg); + temp_msg = NULL; - SLOG(LOG_DEBUG, TAG_VCD, "@@@"); + return VCD_ERROR_NONE; } -static void __vc_mgr_send_audio_streaming_cb(rpc_port_stub_vc_mgr_context_h context, int pid, int event, rpc_port_stub_array_char_h data, void *user_data) +// TODO: remove _tidl after remove dbus +// TODO: make client, widget error signal +int vcdc_tidl_send_error(int reason, char *err_msg) { - SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Manager send audio streaming"); - - char* buffer = NULL; - int len = 0; - int ret = -1; - rpc_port_stub_array_char_get(data, &buffer, &len); + SLOG(LOG_ERROR, TAG_VCD, "[TIDL] Send error signal"); - SLOG(LOG_INFO, TAG_VCD, "[IN] vcd mgr send audio streaming : pid(%d), event(%d), buffer(%p), len(%d)", pid, event, buffer, len); + char tmp_reason[10] = {0, }; + char tmp_daemon_pid[10] = {0, }; + char *temp_msg = NULL; - ret = vcd_server_mgr_send_audio_streaming(pid, event, buffer, (unsigned int)len); - if (0 != ret) { - SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret); + if (NULL == err_msg) { + SLOG(LOG_WARN, TAG_VCD, "[TIDL ERROR] Input parameter is NULL"); + temp_msg = strdup("#NULL"); + } else { + temp_msg = strdup(err_msg); } - SLOG(LOG_DEBUG, TAG_VCD, "@@@"); -} + bundle* msg = bundle_create(); + snprintf(tmp_reason, 10, "%d", reason); + snprintf(tmp_daemon_pid, 10, "%d", getpid()); -int vcd_mgr_tidl_open_connection() -{ - SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] vcd_tidl_open_connection"); + bundle_add_str(msg, VC_MANAGER_BUNDLE_METHOD, VCD_MANAGER_METHOD_ERROR); + bundle_add_str(msg, VC_MANAGER_BUNDLE_REASON, tmp_reason); + bundle_add_str(msg, VC_MANAGER_BUNDLE_DAEMON_PID, tmp_daemon_pid); + bundle_add_str(msg, VC_MANAGER_BUNDLE_ERROR_MESSAGE, temp_msg); + + bundle_add_str(msg, VC_WIDGET_BUNDLE_METHOD, VCD_MANAGER_METHOD_ERROR); + bundle_add_str(msg, VC_WIDGET_BUNDLE_REASON, tmp_reason); + bundle_add_str(msg, VC_WIDGET_BUNDLE_DAEMON_PID, tmp_daemon_pid); + bundle_add_str(msg, VC_WIDGET_BUNDLE_ERROR_MESSAGE, temp_msg); - g_mgr_callback.create = __vc_mgr_create_cb; - g_mgr_callback.terminate = __vc_mgr_terminate_cb; - g_mgr_callback.register_cb = __vc_mgr_register_cb_cb; - g_mgr_callback.initialize = __vc_mgr_initialize_cb; - g_mgr_callback.finalize = __vc_mgr_finalize_cb; - g_mgr_callback.set_command = __vc_mgr_set_command_cb; - g_mgr_callback.unset_command = __vc_mgr_unset_command_cb; - g_mgr_callback.demandable_client = __vc_mgr_set_demandable_client_cb; - g_mgr_callback.set_audio_type = __vc_mgr_set_audio_type_cb; - g_mgr_callback.get_audio_type = __vc_mgr_get_audio_type_cb; - g_mgr_callback.set_private_data = __vc_mgr_set_private_data_cb; - g_mgr_callback.get_private_data = __vc_mgr_get_private_data_cb; - g_mgr_callback.set_client_info = __vc_mgr_set_client_info_cb; - g_mgr_callback.set_domain = __vc_mgr_set_domain_cb; - g_mgr_callback.do_action = __vc_mgr_do_action_cb; - g_mgr_callback.start = __vc_mgr_start_cb; - g_mgr_callback.stop = __vc_mgr_stop_cb; - g_mgr_callback.cancel = __vc_mgr_cancel_cb; - g_mgr_callback.set_audio_streaming_mode = __vc_mgr_set_audio_streaming_mode_cb; - g_mgr_callback.send_specific_engine_request = __vc_mgr_send_specific_engine_request_cb; - g_mgr_callback.send_result_selection = __vc_mgr_send_result_selection_cb; - g_mgr_callback.send_utterance_status = __vc_mgr_send_utterance_status_cb; - g_mgr_callback.send_audio_streaming = __vc_mgr_send_audio_streaming_cb; + SLOG(LOG_DEBUG, TAG_VCD, ">>>> VCD SEND SIGNAL"); - int ret = -1; - int count = 0; - while (VC_RETRY_MIN_COUNT >= count) { - ret = rpc_port_stub_vc_mgr_register(&g_mgr_callback, NULL); - if (0 == ret) { - SLOG(LOG_DEBUG, TAG_VCD, "register callback"); - return VCD_ERROR_NONE; - } - usleep(100000); - count++; - } + __send_signal(msg); - SLOG(LOG_ERROR, TAG_VCD, "Fail to register callback(%d)", ret); - return VCD_ERROR_OPERATION_FAILED; -} + bundle_free(msg); -int vcd_mgr_tidl_close_connection() -{ - SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Close connection"); - rpc_port_stub_vc_mgr_unregister(); + free(temp_msg); + temp_msg = NULL; return VCD_ERROR_NONE; } -// TODO: remove _tidl after all dbus removed -int vcdc_tidl_send_hello(int pid, vcd_client_type_e type) +int vcdc_send_request_set_private_data(int pid, const char* key, const char* data) { - SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Send hello"); + SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Set private data"); - char tmp_pid[10] = {0, }; + char tmp_pid[10] = { 0, }; bundle* msg = bundle_create(); snprintf(tmp_pid, 10, "%d", pid); - bundle_add_str(msg, VC_MANAGER_BUNDLE_METHOD, VCD_MANAGER_METHOD_HELLO); + bundle_add_str(msg, VC_MANAGER_BUNDLE_METHOD, VCD_MANAGER_METHOD_SET_PRIVATE_DATA); bundle_add_str(msg, VC_MANAGER_BUNDLE_MESSAGE, tmp_pid); + bundle_add_str(msg, VC_MANAGER_BUNDLE_KEY, key); + bundle_add_str(msg, VC_MANAGER_BUNDLE_PRIVATE_DATA, data); - SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] VCD SEND MESSAGE"); + SLOG(LOG_DEBUG, TAG_VCD, ">>>> VCD SEND MESSAGE"); - __send_msg(msg, VCD_CLIENT_TYPE_MANAGER); + __send_msg(msg, VCD_CLIENT_TYPE_MANAGER, pid); bundle_free(msg); return VCD_ERROR_NONE; } -int vcdc_send_set_volume(int manager_pid, float volume) +int vcdc_send_feedback_audio_format_to_manager(int manager_pid, int rate, vc_audio_channel_e channel, vce_audio_type_e audio_type) { - SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Set volume"); + SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Send feedback audio format to manager"); - char tmp_volume[20] = {0, }; + char tmp_rate[10] = {0, }; + char tmp_channel[10] = {0, }; + char tmp_audio_type[10] = {0, }; bundle* msg = bundle_create(); - - snprintf(tmp_volume, 20, "%.6f", volume); - bundle_add_str(msg, VC_MANAGER_BUNDLE_METHOD, VCD_MANAGER_METHOD_SET_VOLUME); - bundle_add_str(msg, VC_MANAGER_BUNDLE_MESSAGE, tmp_volume); - + snprintf(tmp_rate, 10, "%d", rate); + snprintf(tmp_channel, 10, "%d", (int)channel); + snprintf(tmp_audio_type, 10, "%d", (int)audio_type); + bundle_add_str(msg, VC_MANAGER_BUNDLE_METHOD, VCD_MANAGER_METHOD_FEEDBACK_AUDIO_FORMAT); + bundle_add_str(msg, VC_MANAGER_BUNDLE_AUDIO_RATE, tmp_rate); + bundle_add_str(msg, VC_MANAGER_BUNDLE_AUDIO_CHANNEL, tmp_channel); + bundle_add_str(msg, VC_MANAGER_BUNDLE_AUDIO_TYPE, tmp_audio_type); SLOG(LOG_DEBUG, TAG_VCD, ">>>> VCD SEND MESSAGE"); - __send_msg(msg, VCD_CLIENT_TYPE_MANAGER); - if (20 == g_volume_count) { - SLOG(LOG_INFO, TAG_VCD, "@@ Send set volume : pid(%d), volume(%f)", manager_pid, volume); - g_volume_count = 0; - } - g_volume_count++; + __send_msg(msg, VCD_CLIENT_TYPE_MANAGER, manager_pid); bundle_free(msg); return VCD_ERROR_NONE; } -// TODO: remove tidl after all dbus migrate to tidl -int vcdc_tidl_send_result(int pid, int manager_pid, int cmd_type) + +int vcdc_send_feedback_streaming_to_manager(int manager_pid, int pid, int utt_id, vc_feedback_event_e event, char* buffer, int len) { - SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Send result"); + SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Send feedback streaming to manager"); + + char tmp_pid[10] = {0, }; + char tmp_utt_id[10] = {0, }; + char tmp_event[10] = {0, }; bundle* msg = bundle_create(); + snprintf(tmp_pid, 10, "%d", pid); + snprintf(tmp_utt_id, 10, "%d", utt_id); + snprintf(tmp_event, 10, "%d", (int)event); + bundle_add_str(msg, VC_MANAGER_BUNDLE_METHOD, VCD_MANAGER_METHOD_FEEDBACK_STREAMING); + bundle_add_str(msg, VC_MANAGER_BUNDLE_MESSAGE, tmp_pid); + bundle_add_str(msg, VC_MANAGER_BUNDLE_UTTID, tmp_utt_id); + bundle_add_str(msg, VC_MANAGER_BUNDLE_EVENT, tmp_event); - bundle_add_str(msg, VC_MANAGER_BUNDLE_METHOD, VCD_MANAGER_METHOD_RESULT); + rpc_port_stub_array_char_h streaming_data = NULL; + rpc_port_stub_array_char_create(&streaming_data); + if (NULL == streaming_data) { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to create data handle"); + return VCD_ERROR_OUT_OF_MEMORY; + } + + if (NULL != buffer && 0 < len) { + rpc_port_stub_array_char_set(streaming_data, (char*)buffer, len); + } else { + SLOG(LOG_ERROR, TAG_VCD, "[TIDL] buffer is empty"); + } SLOG(LOG_DEBUG, TAG_VCD, ">>>> VCD SEND MESSAGE"); - __send_msg(msg, VCD_CLIENT_TYPE_MANAGER); + pthread_mutex_lock(&g_mgr_tidl_info_mutex); + SLOG(LOG_INFO, TAG_VCD, "[TIDL] message to manager"); + manager_tidl_info_s* mgr_tidl_info = vcd_client_manager_get_tidl_info(); + + if (NULL == mgr_tidl_info) { + SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to get manager tidl info. pid(%d)", pid); + pthread_mutex_unlock(&g_mgr_tidl_info_mutex); + rpc_port_stub_array_char_destroy(streaming_data); + bundle_free(msg); + return VCD_ERROR_OPERATION_FAILED; + } + + rpc_port_stub_vc_mgr_send_buffer_cb_h handle = mgr_tidl_info->send_buffer_cb; + if (NULL == handle) { + SLOG(LOG_ERROR, TAG_VCD, "[TIDL] notify callback handle is null"); + pthread_mutex_unlock(&g_mgr_tidl_info_mutex); + rpc_port_stub_array_char_destroy(streaming_data); + bundle_free(msg); + return VCD_ERROR_OPERATION_FAILED; + } + + if (0 != rpc_port_stub_vc_mgr_send_buffer_cb_invoke(handle, streaming_data, msg)) { + SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to send msg"); + pthread_mutex_unlock(&g_mgr_tidl_info_mutex); + rpc_port_stub_array_char_destroy(streaming_data); + bundle_free(msg); + return VCD_ERROR_OPERATION_FAILED; + } + pthread_mutex_unlock(&g_mgr_tidl_info_mutex); + rpc_port_stub_array_char_destroy(streaming_data); bundle_free(msg); return VCD_ERROR_NONE; } -int vcdc_send_pre_result_to_manager(int manager_pid, int event, const char* pre_result) +void vcdc_send_request_set_foreground(int pid, int value) { - SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Send pre result to manager"); - - char tmp_event[10] = {0, }; + SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Set foreground"); - bundle* msg = bundle_create(); - snprintf(tmp_event, 10, "%d", event); + manager_tidl_info_s* mgr_tidl_info = vcd_client_manager_get_tidl_info(); - bundle_add_str(msg, VC_MANAGER_BUNDLE_METHOD, VCD_MANAGER_METHOD_PRE_RESULT); - bundle_add_str(msg, VC_MANAGER_BUNDLE_EVENT, tmp_event); - bundle_add_str(msg, VC_MANAGER_BUNDLE_PRE_RESULT, pre_result); + if (NULL == mgr_tidl_info) { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to get tidl info"); + return; + } - SLOG(LOG_DEBUG, TAG_VCD, ">>>> VCD SEND MESSAGE"); + if (!mgr_tidl_info->connected) { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Not Connected"); + return; + } - __send_msg(msg, VCD_CLIENT_TYPE_MANAGER); - bundle_free(msg); + rpc_port_proxy_vcd_mgr_invoke_set_foreground(mgr_tidl_info->rpc_h, pid, value); - return VCD_ERROR_NONE; + SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Request set foreground"); } -int vcdc_send_specific_engine_result_to_manager(int manager_pid, const char* engine_app_id, const char* event, const char* result) +int vcdc_send_request_get_private_data(int pid, const char* key, char** data) { - SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Send specific engine result to manager"); + SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Get private data"); - bundle* msg = bundle_create(); + manager_tidl_info_s* mgr_tidl_info = vcd_client_manager_get_tidl_info(); - gchar *gEncodedResult = g_base64_encode((const guchar*)result, strlen(result)); + if (NULL == mgr_tidl_info) { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to get tidl info"); + return VC_ERROR_OPERATION_FAILED; + } - bundle_add_str(msg, VC_MANAGER_BUNDLE_METHOD, VCD_MANAGER_METHOD_SPECIFIC_ENGINE_RESULT); - bundle_add_str(msg, VC_MANAGER_BUNDLE_ENGINE_APP_ID, engine_app_id); - bundle_add_str(msg, VC_MANAGER_BUNDLE_EVENT, event); - bundle_add_str(msg, VC_MANAGER_BUNDLE_RESULT, gEncodedResult); + if (!mgr_tidl_info->connected) { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Not Connected"); + return VC_ERROR_OPERATION_FAILED; + } + + char *tmp = NULL; + if (0 != rpc_port_proxy_vcd_mgr_invoke_get_private_data(mgr_tidl_info->rpc_h, pid, key, &tmp)) { + SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Request vcd manager get private data : Fail to invoke message"); + return VC_ERROR_OPERATION_FAILED; + } + SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Request vcd manager get private data : Success"); + + *data = tmp; + + return VC_ERROR_NONE; +} + +int vcdc_send_request_auth_enable(int pid) +{ + SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] auth enable"); + + manager_tidl_info_s* mgr_tidl_info = vcd_client_manager_get_tidl_info(); + + if (NULL == mgr_tidl_info) { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to get tidl info"); + return VC_ERROR_OPERATION_FAILED; + } + + if (!mgr_tidl_info->connected) { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Not Connected"); + return VC_ERROR_OPERATION_FAILED; + } + + if (0 != rpc_port_proxy_vcd_mgr_invoke_auth_enable(mgr_tidl_info->rpc_h, pid)) { + SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Request auth enable : Fail to invoke message"); + return VC_ERROR_OPERATION_FAILED; + } + SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Request auth enable : Success"); + + return VC_ERROR_NONE; +} + +int vcdc_send_request_auth_disable(int pid) +{ + SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] auth disable"); + + manager_tidl_info_s* mgr_tidl_info = vcd_client_manager_get_tidl_info(); + + if (NULL == mgr_tidl_info) { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to get tidl info"); + return VC_ERROR_OPERATION_FAILED; + } + + if (!mgr_tidl_info->connected) { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Not Connected"); + return VC_ERROR_OPERATION_FAILED; + } + + if (0 != rpc_port_proxy_vcd_mgr_invoke_auth_disable(mgr_tidl_info->rpc_h, pid)) { + SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Request auth disable : Fail to invoke message"); + return VC_ERROR_OPERATION_FAILED; + } + SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Request auth disable : Success"); + + return VC_ERROR_NONE; +} + +int vcdc_send_request_auth_start(int pid) +{ + SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] auth start"); + + manager_tidl_info_s* mgr_tidl_info = vcd_client_manager_get_tidl_info(); + + if (NULL == mgr_tidl_info) { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to get tidl info"); + return VC_ERROR_OPERATION_FAILED; + } + + if (!mgr_tidl_info->connected) { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Not Connected"); + return VC_ERROR_OPERATION_FAILED; + } + + if (0 != rpc_port_proxy_vcd_mgr_invoke_auth_start(mgr_tidl_info->rpc_h, pid)) { + SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Request auth start : Fail to invoke message"); + return VC_ERROR_OPERATION_FAILED; + } + SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Request auth start : Success"); + + return VC_ERROR_NONE; +} + +int vcdc_send_request_auth_stop(int pid) +{ + SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] auth stop"); + + manager_tidl_info_s* mgr_tidl_info = vcd_client_manager_get_tidl_info(); + + if (NULL == mgr_tidl_info) { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to get tidl info"); + return VC_ERROR_OPERATION_FAILED; + } + + if (!mgr_tidl_info->connected) { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Not Connected"); + return VC_ERROR_OPERATION_FAILED; + } + + if (0 != rpc_port_proxy_vcd_mgr_invoke_auth_stop(mgr_tidl_info->rpc_h, pid)) { + SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Request auth stop : Fail to invoke message"); + return VC_ERROR_OPERATION_FAILED; + } + SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Request auth stop : Success"); + + return VC_ERROR_NONE; +} + +int vcdc_send_request_auth_cancel(int pid) +{ + SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] auth cancel"); + + manager_tidl_info_s* mgr_tidl_info = vcd_client_manager_get_tidl_info(); + + if (NULL == mgr_tidl_info) { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to get tidl info"); + return VC_ERROR_OPERATION_FAILED; + } + + if (!mgr_tidl_info->connected) { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Not Connected"); + return VC_ERROR_OPERATION_FAILED; + } + + if (0 != rpc_port_proxy_vcd_mgr_invoke_auth_cancel(mgr_tidl_info->rpc_h, pid)) { + SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Request auth cancel : Fail to invoke message"); + return VC_ERROR_OPERATION_FAILED; + } + SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Request auth cancel : Success"); + + return VC_ERROR_NONE; +} + +int vcdc_send_asr_result(int pid, int event, const char* asr_result, int cmd_type, bool* is_consumed) +{ + SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Send asr result"); + + widget_tidl_info_s* widget_tidl_info = vcd_client_widget_get_tidl_info(pid); + + if (NULL == widget_tidl_info) { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to get tidl info"); + return VC_ERROR_OPERATION_FAILED; + } + + if (!widget_tidl_info->connected) { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Not Connected"); + return VC_ERROR_OPERATION_FAILED; + } + + bool temp; + if (0 != rpc_port_proxy_vcd_widget_invoke_send_asr_result(widget_tidl_info->rpc_h, pid, event, asr_result, &temp)) { + SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Request vcd widget send asr result : Fail to invoke message"); + return VC_ERROR_OPERATION_FAILED; + } + SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Request vcd widget send asr result : Success"); + + *is_consumed = temp; + + return VC_ERROR_NONE; +} + +/* +* Tidl for manager +*/ +static void __mgr_on_connected(rpc_port_proxy_vcd_mgr_h h, void *user_data) +{ + manager_tidl_info_s* mgr_tidl_info = vcd_client_manager_get_tidl_info(); + + if (NULL == mgr_tidl_info) { + SLOG(LOG_ERROR, TAG_VCD, "[TIDL] tidl proxy info not allocated"); + return; + } + + mgr_tidl_info->connected = true; + mgr_tidl_info->connection_requesting = false; + + SLOG(LOG_INFO, TAG_VCD, "Connected to manager"); +} + +static void __mgr_on_disconnected(rpc_port_proxy_vcd_mgr_h h, void *user_data) +{ + manager_tidl_info_s* mgr_tidl_info = vcd_client_manager_get_tidl_info(); + + if (NULL == mgr_tidl_info) { + SLOG(LOG_ERROR, TAG_VCD, "[TIDL] tidl proxy info not allocated"); + return; + } + + mgr_tidl_info->connected = false; + mgr_tidl_info->connection_requesting = false; + + SLOG(LOG_INFO, TAG_VCD, "Disonnected to manager"); +} + +static void __mgr_on_rejected(rpc_port_proxy_vcd_mgr_h h, void *user_data) +{ + manager_tidl_info_s* mgr_tidl_info = vcd_client_manager_get_tidl_info(); + + if (NULL == mgr_tidl_info) { + SLOG(LOG_ERROR, TAG_VCD, "[TIDL] tidl proxy info not allocated"); + return; + } + + mgr_tidl_info->connection_requesting = false; + + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Rejected from manager"); +} + +static rpc_port_proxy_vcd_mgr_h __mgr_create_rpc_port(const char* engine_app_id) +{ + SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] __mgr_create_rpc_port"); + rpc_port_proxy_vcd_mgr_callback_s rpc_callback = { + .connected = __mgr_on_connected, + .disconnected = __mgr_on_disconnected, + .rejected = __mgr_on_rejected + }; + + rpc_port_proxy_vcd_mgr_h handle = NULL; + if (0 != rpc_port_proxy_vcd_mgr_create(engine_app_id, &rpc_callback, NULL, &handle)) { + SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to create proxy"); + return NULL; + } + + return handle; +} + +static void __vc_mgr_create_cb(rpc_port_stub_vc_mgr_context_h context, void *user_data) +{ + char *sender = NULL; + + rpc_port_stub_vc_mgr_context_get_sender(context, &sender); + if (!sender){ + SLOG(LOG_ERROR, TAG_VCD, "Sender is NULL"); + return; + } + + SLOG(LOG_DEBUG, TAG_VCD, "@@@ Manager connect. appid(%s)", sender); + + free(sender); +} + +static void __vc_mgr_terminate_cb(rpc_port_stub_vc_mgr_context_h context, void *user_data) +{ + pthread_mutex_lock(&g_mgr_tidl_info_mutex); + manager_tidl_info_s* mgr_tidl_info = vcd_client_manager_get_tidl_info(); + if (NULL == mgr_tidl_info) { + SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to get manager tidl info."); + pthread_mutex_unlock(&g_mgr_tidl_info_mutex); + return; + } + + SLOG(LOG_DEBUG, TAG_VCD, "@@@ VC MANAGER FINALIZE. pid(%u)", mgr_tidl_info->pid); + + if (0 != vcd_client_manager_unset_tidl_notify_cb()) { + SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to unset notify callback"); + } + + if (0 != vcd_client_manager_unset_tidl_send_buffer_cb()) { + SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to unset send buffer callback"); + } + + if (0 != vcd_client_manager_delete_tidl_info()) { + SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to delete manager tidl info"); + } + mgr_tidl_info = NULL; + + SLOG(LOG_DEBUG, TAG_VCD, "@@@"); + + pthread_mutex_unlock(&g_mgr_tidl_info_mutex); + + + char *sender = NULL; + rpc_port_stub_vc_mgr_context_get_sender(context, &sender); + if (!sender) + return; + + SLOG(LOG_INFO, TAG_VCD, "@@@ Manager disconnect. appid(%s)", sender); + + free(sender); +} + +static void __vc_mgr_register_cb_cb(rpc_port_stub_vc_mgr_context_h context, int pid, rpc_port_stub_vc_mgr_notify_cb_h notify_callback, rpc_port_stub_vc_mgr_send_buffer_cb_h send_buffer_callback, void *user_data) +{ + pthread_mutex_lock(&g_mgr_tidl_info_mutex); + SLOG(LOG_INFO, TAG_VCD, "@@@ VC MANAGER REGISTER CALLBACK"); + + int ret = -1; + ret = vcd_client_manager_create_tidl_info(pid); + + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to create manager tidl info."); + pthread_mutex_unlock(&g_mgr_tidl_info_mutex); + return; + } + + manager_tidl_info_s* mgr_tidl_info = vcd_client_manager_get_tidl_info(); + + if (NULL == mgr_tidl_info) { + SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to get manager tidl info. pid(%d)", pid); + pthread_mutex_unlock(&g_mgr_tidl_info_mutex); + return; + } + + char *sender = NULL; + rpc_port_stub_vc_mgr_context_get_sender(context, &sender); + + if (!sender){ + SLOG(LOG_ERROR, TAG_VCD, "Sender is NULL"); + pthread_mutex_unlock(&g_mgr_tidl_info_mutex); + return; + } + + mgr_tidl_info->rpc_h = __mgr_create_rpc_port(sender); + + if (NULL == mgr_tidl_info->rpc_h) { + SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to create server proxy"); + } else { + SLOG(LOG_INFO, TAG_VCD, "[TIDL] rpc_h(%p), engine_app_id(%s)", mgr_tidl_info->rpc_h, sender); + } - SLOG(LOG_DEBUG, TAG_VCD, ">>>> VCD SEND MESSAGE"); + free(sender); - __send_msg(msg, VCD_CLIENT_TYPE_MANAGER); - bundle_free(msg); + if (0 != vcd_client_manager_set_tidl_notify_cb(notify_callback, user_data)) { + SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to set notify callback"); + } else { + SLOG(LOG_INFO, TAG_VCD, "[TIDL] Succeed to set notify callback."); + } - if (gEncodedResult) - g_free(gEncodedResult); + if (0 != vcd_client_manager_set_tidl_send_buffer_cb(send_buffer_callback, user_data)) { + SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to set send buffer callback"); + } else { + SLOG(LOG_INFO, TAG_VCD, "[TIDL] Succeed to set send buffer callback."); + } - return VCD_ERROR_NONE; + pthread_mutex_unlock(&g_mgr_tidl_info_mutex); + + __request_tidl_connect(VCD_CLIENT_TYPE_MANAGER, pid); + + SLOG(LOG_DEBUG, TAG_VCD, "@@@"); } -int vcdc_send_result_to_manager(int manager_pid, int result_type) +static int __vc_mgr_initialize_cb(rpc_port_stub_vc_mgr_context_h context, int pid, int audio_streaming_mode, int *service_state, int *foreground, int *daemon_pid, void *user_data) { - SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Send result to manager"); + SLOG(LOG_INFO, TAG_VCD, "@@@ VCD Manager Initialize"); - char tmp_result[10] = {0, }; + int ret = -1; - bundle* msg = bundle_create(); - snprintf(tmp_result, 10, "%d", result_type); + vcd_config_set_audio_streaming_mode((vcd_audio_streaming_mode_e)audio_streaming_mode); + ret = vcd_server_mgr_initialize(pid, audio_streaming_mode); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret); + return ret; + } + *service_state = vcd_server_get_service_state(); + *foreground = vcd_server_get_foreground(); + *daemon_pid = getpid(); - bundle_add_str(msg, VC_MANAGER_BUNDLE_METHOD, VCD_MANAGER_METHOD_ALL_RESULT); - bundle_add_str(msg, VC_MANAGER_BUNDLE_MESSAGE, tmp_result); + 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); + SLOG(LOG_DEBUG, TAG_VCD, "@@@"); + return ret; +} + +static int __vc_mgr_finalize_cb(rpc_port_stub_vc_mgr_context_h context, int pid, void *user_data) +{ + SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Manager Finalize"); + SLOG(LOG_INFO, TAG_VCD, "[IN] vcd mgr finalize : pid(%d)", pid); + + int ret = -1; + + ret = vcd_server_mgr_finalize(pid); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret); + } + + SLOG(LOG_DEBUG, TAG_VCD, "@@@"); + + return ret; +} + +static int __vc_mgr_set_command_cb(rpc_port_stub_vc_mgr_context_h context, int pid, void *user_data) +{ + SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Manager Set command"); + SLOG(LOG_INFO, TAG_VCD, "[IN] vcd mgr set command : pid(%d)", pid); + + int ret = -1; + + ret = vcd_server_mgr_set_command(pid); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret); + return ret; + } + + SLOG(LOG_DEBUG, TAG_VCD, "@@@"); + + return ret; +} + +static int __vc_mgr_unset_command_cb(rpc_port_stub_vc_mgr_context_h context, int pid, void *user_data) +{ + SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Manager unset command"); + SLOG(LOG_INFO, TAG_VCD, "[IN] vcd mgr unset command : pid(%d)", pid); + + int ret = -1; + + ret = vcd_server_mgr_unset_command(pid); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret); + return ret; + } + + SLOG(LOG_DEBUG, TAG_VCD, "@@@"); + + return ret; +} + +static int __vc_mgr_set_demandable_client_cb(rpc_port_stub_vc_mgr_context_h context, int pid, void *user_data) +{ + SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Manager Set demandable client"); + SLOG(LOG_INFO, TAG_VCD, "[IN] vcd mgr set demandable client : pid(%d)", pid); + + int ret = -1; + + ret = vcd_server_mgr_set_demandable_client(pid); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret); + return ret; + } + + SLOG(LOG_DEBUG, TAG_VCD, "@@@"); + + return ret; +} + +static int __vc_mgr_set_audio_type_cb(rpc_port_stub_vc_mgr_context_h context, int pid, const char *audio_type, void *user_data) +{ + SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Manager set audio type"); + SLOG(LOG_INFO, TAG_VCD, "[IN] vcd mgr set audio type : pid(%d), audio type(%s)", pid, audio_type); + + int ret = -1; + + ret = vcd_server_mgr_set_audio_type(pid, audio_type); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret); + return ret; + } + + SLOG(LOG_DEBUG, TAG_VCD, "@@@"); + + return ret; +} + +static int __vc_mgr_get_audio_type_cb(rpc_port_stub_vc_mgr_context_h context, int pid, char **audio_type, void *user_data) +{ + SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Manager get audio type"); + SLOG(LOG_INFO, TAG_VCD, "[IN] vcd mgr set audio type : pid(%d)", pid); + + int ret = -1; + char* tmp_audio_type = NULL; + + ret = vcd_server_mgr_get_audio_type(pid, &tmp_audio_type); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret); + free(tmp_audio_type); + return ret; + } + + *audio_type = strdup(tmp_audio_type); + free(tmp_audio_type); + + SLOG(LOG_DEBUG, TAG_VCD, "@@@"); + + return ret; +} + +static void __vc_mgr_set_private_data_cb(rpc_port_stub_vc_mgr_context_h context, int pid, const char *key, const char *data, void *user_data) +{ + SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Manager set private data"); + SLOG(LOG_INFO, TAG_VCD, "[IN] vcd mgr set domain : pid(%d), key(%s), data(%s)", pid, key, data); + + int ret = -1; + + ret = vcd_server_mgr_set_private_data(pid, key, data); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to set private data"); + SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret); + } + + SLOG(LOG_DEBUG, TAG_VCD, "@@@"); +} + +static int __vc_mgr_get_private_data_cb(rpc_port_stub_vc_mgr_context_h context, int pid, const char *key, char **data, void *user_data) +{ + SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Manager get private data"); + SLOG(LOG_INFO, TAG_VCD, "[IN] vcd mgr get private data : pid(%d), key(%s)", pid, key); + + int ret = -1; + char *temp_data = NULL; + + ret = vcd_server_mgr_get_private_data(pid, key, &temp_data); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret); + return ret; + } + if (NULL == temp_data) { + SLOG(LOG_INFO, TAG_VCD, "data parameter is NULL"); + temp_data = strdup("#NULL"); + } + + *data = strdup(temp_data); + free(temp_data); + SLOG(LOG_DEBUG, TAG_VCD, "@@@"); + + return ret; +} + +static int __vc_mgr_set_client_info_cb(rpc_port_stub_vc_mgr_context_h context, int pid, void *user_data) +{ + SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Manager set client info"); + SLOG(LOG_INFO, TAG_VCD, "[IN] vcd mgr set client info : pid(%d)", pid); + + int ret = -1; + + ret = vcd_server_mgr_set_client_info(pid); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret); + return ret; + } + + SLOG(LOG_DEBUG, TAG_VCD, "@@@"); + + return ret; +} + +static int __vc_mgr_set_domain_cb(rpc_port_stub_vc_mgr_context_h context, int pid, const char *domain, void *user_data) +{ + SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Manager set domain type"); + SLOG(LOG_INFO, TAG_VCD, "[IN] vcd mgr set domain : pid(%d), domain(%s)", pid, domain); + + int ret = -1; + + ret = vcd_server_mgr_set_domain(pid, domain); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret); + return ret; + } + + SLOG(LOG_DEBUG, TAG_VCD, "@@@"); + + return ret; +} + +static void __vc_mgr_do_action_cb(rpc_port_stub_vc_mgr_context_h context, int pid, int type, const char *send_event, void *user_data) +{ + SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Manager request to do action"); + SLOG(LOG_INFO, TAG_VCD, "[IN] vcd mgr request to do action : pid(%d), type(%d) send_event(%s)", pid, type, send_event); + + int ret = -1; + + ret = vcd_server_mgr_do_action(pid, type, send_event); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret); + } + + SLOG(LOG_DEBUG, TAG_VCD, "@@@"); +} + +static int __vc_mgr_start_cb(rpc_port_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) +{ + SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Manager start"); + SLOG(LOG_INFO, TAG_VCD, "[IN] vcd check enabled or disabled command types. disabled cmd type(%d)", disabled_cmd_type); + + int ret = -1; + + vcd_server_mgr_set_disabled_command_type(pid, disabled_cmd_type); - SLOG(LOG_DEBUG, TAG_VCD, ">>>> VCD SEND MESSAGE"); + 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); + ret = vcd_server_mgr_start((vcd_recognition_mode_e)recognition_mode, exclusive_command_option, start_by_client); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret); + return ret; + } - __send_msg(msg, VCD_CLIENT_TYPE_MANAGER); - bundle_free(msg); + SLOG(LOG_DEBUG, TAG_VCD, "@@@"); - return VCD_ERROR_NONE; + return ret; } -int vcdc_send_speech_detected(int manager_pid) +static int __vc_mgr_stop_cb(rpc_port_stub_vc_mgr_context_h context, int pid, void *user_data) { - SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Send speech detected"); + SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Manager stop"); + SLOG(LOG_INFO, TAG_VCD, "[IN] vcd mgr stop : pid(%d)", pid); - bundle* msg = bundle_create(); + int ret = -1; - bundle_add_str(msg, VC_MANAGER_BUNDLE_METHOD, VCD_MANAGER_METHOD_SPEECH_DETECTED); + ret = vcd_server_mgr_stop(); - SLOG(LOG_DEBUG, TAG_VCD, ">>>> VCD SEND MESSAGE"); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret); + return ret; + } - __send_msg(msg, VCD_CLIENT_TYPE_MANAGER); - bundle_free(msg); + SLOG(LOG_DEBUG, TAG_VCD, "@@@"); - return VCD_ERROR_NONE; + return ret; } -int vcdc_send_service_state(vcd_state_e state) +static int __vc_mgr_cancel_cb(rpc_port_stub_vc_mgr_context_h context, int pid, void *user_data) { - SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Send service state"); + SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Manager cancel"); + SLOG(LOG_INFO, TAG_VCD, "[IN] vcd mgr cancel : pid(%d)", pid); - char tmp_state[10] = {0, }; + int ret = -1; - bundle* msg = bundle_create(); - snprintf(tmp_state, 10, "%d", (int)state); + ret = vcd_server_mgr_cancel(); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret); + return ret; + } - bundle_add_str(msg, VC_MANAGER_BUNDLE_METHOD, VCD_MANAGER_METHOD_SET_SERVICE_STATE); - bundle_add_str(msg, VC_MANAGER_BUNDLE_MESSAGE, tmp_state); + SLOG(LOG_DEBUG, TAG_VCD, "@@@"); - SLOG(LOG_DEBUG, TAG_VCD, ">>>> VCD SEND MESSAGE"); + return ret; +} - __send_msg(msg, VCD_CLIENT_TYPE_MANAGER); - bundle_free(msg); +static void __vc_mgr_set_audio_streaming_mode_cb(rpc_port_stub_vc_mgr_context_h context, int pid, int mode, void *user_data) +{ + SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Manager set audio streaming mode"); + SLOG(LOG_INFO, TAG_VCD, "[IN] vcd mgr set audio streaming mode : pid(%d) mode(%d)", pid, mode); - return VCD_ERROR_NONE; + vcd_config_set_audio_streaming_mode((vcd_audio_streaming_mode_e)mode); + + SLOG(LOG_DEBUG, TAG_VCD, "@@@"); } -int vcdc_send_dialog(int manager_pid, int pid, const char* disp_text, const char* utt_text, int continuous) +static void __vc_mgr_send_specific_engine_request_cb(rpc_port_stub_vc_mgr_context_h context, int pid, const char *engine_app_id, const char *event, const char *request, void *user_data) { - SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Send dialog"); + SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Manager specific engine request"); - char tmp_pid[10] = {0, }; - char tmp_continuous[10] = {0, }; - char* tmp_disp_text = NULL; - char* tmp_utt_text = NULL; - bundle* msg = bundle_create(); - snprintf(tmp_pid, 10, "%d", pid); - snprintf(tmp_continuous, 10, "%d", continuous); + int ret = -1; + gsize decodingSize = 0; + gchar *gDecodedRequest = (gchar *)g_base64_decode((const gchar *)request, &decodingSize); - if (NULL == disp_text) { - tmp_disp_text = strdup("#NULL"); - } else { - tmp_disp_text = strdup(disp_text); - } + if (gDecodedRequest) { + ret = vcd_server_mgr_send_specific_engine_request(pid, engine_app_id, event, gDecodedRequest); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret); + } - if (NULL == utt_text) { - tmp_utt_text = strdup("#NULL"); - } else { - tmp_utt_text = strdup(utt_text); + 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); + g_free(gDecodedRequest); } - bundle_add_str(msg, VC_MANAGER_BUNDLE_METHOD, VCD_MANAGER_METHOD_DIALOG); - bundle_add_str(msg, VC_MANAGER_BUNDLE_MESSAGE, tmp_pid); - bundle_add_str(msg, VC_MANAGER_BUNDLE_DISP_TEXT, tmp_disp_text); - bundle_add_str(msg, VC_MANAGER_BUNDLE_UTT_TEXT, tmp_utt_text); - bundle_add_str(msg, VC_MANAGER_BUNDLE_CONTINUOUS, tmp_continuous); + SLOG(LOG_DEBUG, TAG_VCD, "@@@"); +} - SLOG(LOG_DEBUG, TAG_VCD, ">>>> VCD SEND MESSAGE"); +static void __vc_mgr_send_result_selection_cb(rpc_port_stub_vc_mgr_context_h context, int pid, void *user_data) +{ + SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Manager result selection"); + SLOG(LOG_INFO, TAG_VCD, "[IN] vcd mgr result selection : pid(%d)", pid); - __send_msg(msg, VCD_CLIENT_TYPE_MANAGER); - bundle_free(msg); - free(tmp_disp_text); - free(tmp_utt_text); + vcd_server_mgr_result_select(); - return VCD_ERROR_NONE; + SLOG(LOG_DEBUG, TAG_VCD, "@@@"); } -int vcdc_tidl_send_error_to_manager(int manager_pid, int reason, char *err_msg) +static void __vc_mgr_send_utterance_status_cb(rpc_port_stub_vc_mgr_context_h context, int utt_id, int utt_status, void *user_data) { - SLOG(LOG_ERROR, TAG_VCD, "[TIDL] Send error signal to manager"); + SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Manager send utterance status"); + SLOG(LOG_INFO, TAG_VCD, "[IN] vcd mgr send utterance status : utt_id(%d), utt_status(%d)", utt_id, utt_status); + // TODO: send parameter to client - char tmp_reason[10] = {0, }; - char tmp_daemon_pid[10] = {0, }; - char *temp_msg = NULL; + SLOG(LOG_DEBUG, TAG_VCD, "@@@"); +} - if (NULL == err_msg) { - SLOG(LOG_WARN, TAG_VCD, "[TIDL ERROR] Input parameter is NULL"); - temp_msg = strdup("#NULL"); - } else { - temp_msg = strdup(err_msg); - } +static void __vc_mgr_send_audio_streaming_cb(rpc_port_stub_vc_mgr_context_h context, int pid, int event, rpc_port_stub_array_char_h data, void *user_data) +{ + SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Manager send audio streaming"); - bundle* msg = bundle_create(); - snprintf(tmp_reason, 10, "%d", reason); - snprintf(tmp_daemon_pid, 10, "%d", getpid()); + char* buffer = NULL; + int len = 0; + int ret = -1; + rpc_port_stub_array_char_get(data, &buffer, &len); - bundle_add_str(msg, VC_MANAGER_BUNDLE_METHOD, VCD_MANAGER_METHOD_ERROR); - bundle_add_str(msg, VC_MANAGER_BUNDLE_REASON, tmp_reason); - bundle_add_str(msg, VC_MANAGER_BUNDLE_DAEMON_PID, tmp_daemon_pid); - bundle_add_str(msg, VC_MANAGER_BUNDLE_ERROR_MESSAGE, temp_msg); + SLOG(LOG_INFO, TAG_VCD, "[IN] vcd mgr send audio streaming : pid(%d), event(%d), buffer(%p), len(%d)", pid, event, buffer, len); - SLOG(LOG_DEBUG, TAG_VCD, ">>>> VCD SEND MESSAGE"); + ret = vcd_server_mgr_send_audio_streaming(pid, event, buffer, (unsigned int)len); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret); + } - __send_msg(msg, VCD_CLIENT_TYPE_MANAGER); - bundle_free(msg); + SLOG(LOG_DEBUG, TAG_VCD, "@@@"); +} - free(temp_msg); - temp_msg = NULL; +int vcd_mgr_tidl_open_connection() +{ + SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] vcd_mgr_tidl_open_connection"); - return VCD_ERROR_NONE; + g_mgr_callback.create = __vc_mgr_create_cb; + g_mgr_callback.terminate = __vc_mgr_terminate_cb; + g_mgr_callback.register_cb = __vc_mgr_register_cb_cb; + g_mgr_callback.initialize = __vc_mgr_initialize_cb; + g_mgr_callback.finalize = __vc_mgr_finalize_cb; + g_mgr_callback.set_command = __vc_mgr_set_command_cb; + g_mgr_callback.unset_command = __vc_mgr_unset_command_cb; + g_mgr_callback.demandable_client = __vc_mgr_set_demandable_client_cb; + g_mgr_callback.set_audio_type = __vc_mgr_set_audio_type_cb; + g_mgr_callback.get_audio_type = __vc_mgr_get_audio_type_cb; + g_mgr_callback.set_private_data = __vc_mgr_set_private_data_cb; + g_mgr_callback.get_private_data = __vc_mgr_get_private_data_cb; + g_mgr_callback.set_client_info = __vc_mgr_set_client_info_cb; + g_mgr_callback.set_domain = __vc_mgr_set_domain_cb; + g_mgr_callback.do_action = __vc_mgr_do_action_cb; + g_mgr_callback.start = __vc_mgr_start_cb; + g_mgr_callback.stop = __vc_mgr_stop_cb; + g_mgr_callback.cancel = __vc_mgr_cancel_cb; + g_mgr_callback.set_audio_streaming_mode = __vc_mgr_set_audio_streaming_mode_cb; + g_mgr_callback.send_specific_engine_request = __vc_mgr_send_specific_engine_request_cb; + g_mgr_callback.send_result_selection = __vc_mgr_send_result_selection_cb; + g_mgr_callback.send_utterance_status = __vc_mgr_send_utterance_status_cb; + g_mgr_callback.send_audio_streaming = __vc_mgr_send_audio_streaming_cb; + + int ret = -1; + int count = 0; + while (VC_RETRY_MIN_COUNT >= count) { + ret = rpc_port_stub_vc_mgr_register(&g_mgr_callback, NULL); + if (0 == ret) { + SLOG(LOG_DEBUG, TAG_VCD, "register callback"); + return VCD_ERROR_NONE; + } + usleep(100000); + count++; + } + + SLOG(LOG_ERROR, TAG_VCD, "Fail to register callback(%d)", ret); + return VCD_ERROR_OPERATION_FAILED; } -// TODO: remove _tidl after remove dbus -// TODO: make client, widget error signal -int vcdc_tidl_send_error(int reason, char *err_msg) +int vcd_mgr_tidl_close_connection() { - SLOG(LOG_ERROR, TAG_VCD, "[TIDL] Send error signal"); - - vcdc_tidl_send_error_to_manager(vcd_client_manager_get_pid(), reason, err_msg); + SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Close connection"); + rpc_port_stub_vc_mgr_unregister(); return VCD_ERROR_NONE; } -int vcdc_send_request_set_private_data(int pid, const char* key, const char* data) +/* +* Tidl for widget +*/ +static void __widget_on_connected(rpc_port_proxy_vcd_widget_h h, void *user_data) { - SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Set private data"); + widget_tidl_info_s* widget_tidl_info = vcd_client_widget_get_tidl_info((int)user_data); + + widget_tidl_info->connected = true; + widget_tidl_info->connection_requesting = false; - char tmp_pid[10] = { 0, }; + SLOG(LOG_INFO, TAG_VCD, "Connected to widget"); +} - bundle* msg = bundle_create(); - snprintf(tmp_pid, 10, "%d", pid); +static void __widget_on_disconnected(rpc_port_proxy_vcd_widget_h h, void *user_data) +{ + widget_tidl_info_s* widget_tidl_info = vcd_client_widget_get_tidl_info((int)user_data); - bundle_add_str(msg, VC_MANAGER_BUNDLE_METHOD, VCD_MANAGER_METHOD_SET_PRIVATE_DATA); - bundle_add_str(msg, VC_MANAGER_BUNDLE_MESSAGE, tmp_pid); - bundle_add_str(msg, VC_MANAGER_BUNDLE_KEY, key); - bundle_add_str(msg, VC_MANAGER_BUNDLE_PRIVATE_DATA, data); + widget_tidl_info->connected = false; + widget_tidl_info->connection_requesting = false; + SLOG(LOG_INFO, TAG_VCD, "Disonnected to widget"); +} - SLOG(LOG_DEBUG, TAG_VCD, ">>>> VCD SEND MESSAGE"); +static void __widget_on_rejected(rpc_port_proxy_vcd_widget_h h, void *user_data) +{ + widget_tidl_info_s* widget_tidl_info = vcd_client_widget_get_tidl_info((int)user_data); - __send_msg(msg, VCD_CLIENT_TYPE_MANAGER); - bundle_free(msg); + widget_tidl_info->connection_requesting = false; - return VCD_ERROR_NONE; + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Rejected from widget"); } -int vcdc_send_feedback_audio_format_to_manager(int manager_pid, int rate, vc_audio_channel_e channel, vce_audio_type_e audio_type) +static rpc_port_proxy_vcd_widget_h __widget_create_rpc_port(const char* engine_app_id, int pid) { - SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Send feedback audio format to manager"); + SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] __widget_create_rpc_port"); + rpc_port_proxy_vcd_widget_callback_s rpc_callback = { + .connected = __widget_on_connected, + .disconnected = __widget_on_disconnected, + .rejected = __widget_on_rejected + }; - char tmp_rate[10] = {0, }; - char tmp_channel[10] = {0, }; - char tmp_audio_type[10] = {0, }; + rpc_port_proxy_vcd_widget_h handle = NULL; + if (0 != rpc_port_proxy_vcd_widget_create(engine_app_id, &rpc_callback, (void *)pid, &handle)) { + SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to create proxy"); + return NULL; + } - bundle* msg = bundle_create(); - snprintf(tmp_rate, 10, "%d", rate); - snprintf(tmp_channel, 10, "%d", (int)channel); - snprintf(tmp_audio_type, 10, "%d", (int)audio_type); - bundle_add_str(msg, VC_MANAGER_BUNDLE_METHOD, VCD_MANAGER_METHOD_FEEDBACK_AUDIO_FORMAT); - bundle_add_str(msg, VC_MANAGER_BUNDLE_AUDIO_RATE, tmp_rate); - bundle_add_str(msg, VC_MANAGER_BUNDLE_AUDIO_CHANNEL, tmp_channel); - bundle_add_str(msg, VC_MANAGER_BUNDLE_AUDIO_TYPE, tmp_audio_type); + return handle; +} - SLOG(LOG_DEBUG, TAG_VCD, ">>>> VCD SEND MESSAGE"); +static void __vc_widget_create_cb(rpc_port_stub_vc_widget_context_h context, void *user_data) +{ + char *sender = NULL; - __send_msg(msg, VCD_CLIENT_TYPE_MANAGER); - bundle_free(msg); + rpc_port_stub_vc_widget_context_get_sender(context, &sender); + if (!sender) { + SLOG(LOG_ERROR, TAG_VCD, "Sender is NULL"); + return; + } - return VCD_ERROR_NONE; + SLOG(LOG_DEBUG, TAG_VCD, "@@@ Widget connect. appid(%s)", sender); + free(sender); } -int vcdc_send_feedback_streaming_to_manager(int manager_pid, int pid, int utt_id, vc_feedback_event_e event, char* buffer, int len) +static void __vc_widget_terminate_cb(rpc_port_stub_vc_widget_context_h context, void *user_data) { - SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Send feedback streaming to manager"); + void* tag = NULL; + rpc_port_stub_vc_widget_context_get_tag(context, &tag); + + if (NULL != tag) { + int pid = (intptr_t)tag; + SLOG(LOG_DEBUG, TAG_VCD, "@@@ VC WIDGET FINALIZE. pid(%u)", pid); + + pthread_mutex_lock(&g_widget_tidl_info_mutex); + widget_tidl_info_s* widget_tidl_info = vcd_client_widget_get_tidl_info(pid); + if (NULL == widget_tidl_info) { + SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to get widget tidl info."); + pthread_mutex_unlock(&g_widget_tidl_info_mutex); + return; + } - char tmp_pid[10] = {0, }; - char tmp_utt_id[10] = {0, }; - char tmp_event[10] = {0, }; + if (0 != vcd_client_widget_unset_tidl_notify_cb(pid)) { + SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to unset notify callback"); + } + + if (0 != vcd_client_widget_delete_tidl_info(pid)) { + SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to delete widget tidl info"); + } + widget_tidl_info = NULL; + + SLOG(LOG_DEBUG, TAG_VCD, "@@@"); + + pthread_mutex_unlock(&g_widget_tidl_info_mutex); + + char *sender = NULL; + rpc_port_stub_vc_widget_context_get_sender(context, &sender); + if (!sender) + return; - bundle* msg = bundle_create(); - snprintf(tmp_pid, 10, "%d", pid); - snprintf(tmp_utt_id, 10, "%d", utt_id); - snprintf(tmp_event, 10, "%d", (int)event); - bundle_add_str(msg, VC_MANAGER_BUNDLE_METHOD, VCD_MANAGER_METHOD_FEEDBACK_STREAMING); - bundle_add_str(msg, VC_MANAGER_BUNDLE_MESSAGE, tmp_pid); - bundle_add_str(msg, VC_MANAGER_BUNDLE_UTTID, tmp_utt_id); - bundle_add_str(msg, VC_MANAGER_BUNDLE_EVENT, tmp_event); + SLOG(LOG_INFO, TAG_VCD, "@@@ Manager disconnect. appid(%s)", sender); - rpc_port_stub_array_char_h streaming_data = NULL; - rpc_port_stub_array_char_create(&streaming_data); - if (NULL == streaming_data) { - SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to create data handle"); - return VCD_ERROR_OUT_OF_MEMORY; + free(sender); } + rpc_port_stub_vc_widget_context_set_tag(context, NULL); +} - if (NULL != buffer && 0 < len) { - rpc_port_stub_array_char_set(streaming_data, (char*)buffer, len); - } else { - SLOG(LOG_ERROR, TAG_VCD, "[TIDL] buffer is empty"); +static void __vc_widget_register_cb_cb(rpc_port_stub_vc_widget_context_h context, int pid, rpc_port_stub_vc_widget_notify_cb_h notify_callback, void *user_data) +{ + pthread_mutex_lock(&g_widget_tidl_info_mutex); + SLOG(LOG_INFO, TAG_VCD, "@@@ VC WIDGET REGISTER CALLBACK"); + + int ret = -1; + ret = vcd_client_widget_add_tidl_info(pid); + + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to add widget tidl info."); + pthread_mutex_unlock(&g_widget_tidl_info_mutex); + return; } + widget_tidl_info_s* widget_tidl_info = vcd_client_widget_get_tidl_info(pid); - SLOG(LOG_DEBUG, TAG_VCD, ">>>> VCD SEND MESSAGE"); + if (NULL == widget_tidl_info) { + SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to get widget tidl info. pid(%d)", pid); + pthread_mutex_unlock(&g_widget_tidl_info_mutex); + return; + } - pthread_mutex_lock(&g_mgr_tidl_info_mutex); - SLOG(LOG_INFO, TAG_VCD, "[TIDL] message to manager"); - manager_tidl_info_s* mgr_tidl_info = vcd_client_manager_get_tidl_info(); + char *sender = NULL; + rpc_port_stub_vc_widget_context_get_sender(context, &sender); - if (NULL == mgr_tidl_info) { - SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to get manager tidl info. pid(%d)", pid); - pthread_mutex_unlock(&g_mgr_tidl_info_mutex); - rpc_port_stub_array_char_destroy(streaming_data); - bundle_free(msg); - return VCD_ERROR_OPERATION_FAILED; + if (!sender){ + SLOG(LOG_ERROR, TAG_VCD, "Sender is NULL"); + pthread_mutex_unlock(&g_widget_tidl_info_mutex); + return; } - rpc_port_stub_vc_mgr_send_buffer_cb_h handle = mgr_tidl_info->send_buffer_cb; - if (NULL == handle) { - SLOG(LOG_ERROR, TAG_VCD, "[TIDL] notify callback handle is null"); - pthread_mutex_unlock(&g_mgr_tidl_info_mutex); - rpc_port_stub_array_char_destroy(streaming_data); - bundle_free(msg); - return VCD_ERROR_OPERATION_FAILED; + widget_tidl_info->rpc_h = __widget_create_rpc_port(sender, pid); + + if (NULL == widget_tidl_info->rpc_h) { + SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to create server proxy"); + } else { + SLOG(LOG_INFO, TAG_VCD, "[TIDL] rpc_h(%p), engine_app_id(%s)", widget_tidl_info->rpc_h, sender); } - if (0 != rpc_port_stub_vc_mgr_send_buffer_cb_invoke(handle, streaming_data, msg)) { - SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to send msg"); - pthread_mutex_unlock(&g_mgr_tidl_info_mutex); - rpc_port_stub_array_char_destroy(streaming_data); - bundle_free(msg); - return VCD_ERROR_OPERATION_FAILED; + free(sender); + + if (0 != vcd_client_widget_set_tidl_notify_cb(pid, notify_callback, user_data)) { + SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to set notify callback"); + } else { + SLOG(LOG_INFO, TAG_VCD, "[TIDL] Succeed to set notify callback."); } - pthread_mutex_unlock(&g_mgr_tidl_info_mutex); - rpc_port_stub_array_char_destroy(streaming_data); - bundle_free(msg); - return VCD_ERROR_NONE; + pthread_mutex_unlock(&g_widget_tidl_info_mutex); + + __request_tidl_connect(VCD_CLIENT_TYPE_WIDGET, pid); + + SLOG(LOG_DEBUG, TAG_VCD, "@@@"); } -void vcdc_send_request_set_foreground(int pid, int value) +static int __vc_widget_initialize_cb(rpc_port_stub_vc_widget_context_h context, int pid, int *service_state, int *daemon_pid, void *user_data) { - SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Set foreground"); + SLOG(LOG_INFO, TAG_VCD, "@@@ VCD Widget Initialize"); - manager_tidl_info_s* mgr_tidl_info = vcd_client_manager_get_tidl_info(); + uintptr_t ptr_pid = pid; + int ret = -1; - if (NULL == mgr_tidl_info) { - SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to get tidl info"); - return; - } + rpc_port_stub_vc_widget_context_set_tag(context, (void*)ptr_pid); - if (!mgr_tidl_info->connected) { - SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Not Connected"); - return; + ret = vcd_server_widget_initialize(pid); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret); + return ret; } + *service_state = vcd_server_get_service_state(); + *daemon_pid = getpid(); - rpc_port_proxy_vcd_mgr_invoke_set_foreground(mgr_tidl_info->rpc_h, pid, value); - - SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Request set foreground"); + SLOG(LOG_INFO, TAG_VCD, "[IN] vcd widget initialize : pid(%d) service state(%d) daemon_pid(%d)", pid, *service_state, *daemon_pid); + SLOG(LOG_DEBUG, TAG_VCD, "@@@"); + return ret; } -int vcdc_send_request_get_private_data(int pid, const char* key, char** data) +static int __vc_widget_finalize_cb(rpc_port_stub_vc_widget_context_h context, int pid, void *user_data) { - SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Get private data"); + SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Widget Finalize"); + SLOG(LOG_INFO, TAG_VCD, "[IN] vcd widget finalize : pid(%d)", pid); - manager_tidl_info_s* mgr_tidl_info = vcd_client_manager_get_tidl_info(); + int ret = -1; - if (NULL == mgr_tidl_info) { - SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to get tidl info"); - return VC_ERROR_OPERATION_FAILED; + ret = vcd_server_widget_finalize(pid); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret); + return ret; } - if (!mgr_tidl_info->connected) { - SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Not Connected"); - return VC_ERROR_OPERATION_FAILED; - } + SLOG(LOG_DEBUG, TAG_VCD, "@@@"); - char *tmp = NULL; - if (0 != rpc_port_proxy_vcd_mgr_invoke_get_private_data(mgr_tidl_info->rpc_h, pid, key, &tmp)) { - SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Request vcd manager get private data : Fail to invoke message"); - return VC_ERROR_OPERATION_FAILED; + return ret; +} + +static int __vc_widget_start_recording_cb(rpc_port_stub_vc_widget_context_h context, int pid, int command, void *user_data) +{ + SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Widget Start Recording"); + SLOG(LOG_INFO, TAG_VCD, "[IN] vcd widget start recording : pid(%d) command(%d)", pid, command); + + int ret = -1; + + ret = vcd_server_widget_start_recording(pid, command); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret); + return ret; } - SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Request vcd manager get private data : Success"); - *data = tmp; + SLOG(LOG_DEBUG, TAG_VCD, "@@@"); - return VC_ERROR_NONE; + return ret; } -int vcdc_send_request_auth_enable(int pid) +static int __vc_widget_start_cb(rpc_port_stub_vc_widget_context_h context, int pid, int silence, void *user_data) { - SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] auth enable"); - - manager_tidl_info_s* mgr_tidl_info = vcd_client_manager_get_tidl_info(); + SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Widget Start"); + SLOG(LOG_INFO, TAG_VCD, "[IN] vcd widget start : pid(%d) silence(%d)", pid, silence); - if (NULL == mgr_tidl_info) { - SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to get tidl info"); - return VC_ERROR_OPERATION_FAILED; - } + int ret = -1; - if (!mgr_tidl_info->connected) { - SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Not Connected"); - return VC_ERROR_OPERATION_FAILED; + ret = vcd_server_widget_start(pid, (bool)silence); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret); + return ret; } - if (0 != rpc_port_proxy_vcd_mgr_invoke_auth_enable(mgr_tidl_info->rpc_h, pid)) { - SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Request auth enable : Fail to invoke message"); - return VC_ERROR_OPERATION_FAILED; - } - SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Request auth enable : Success"); + SLOG(LOG_DEBUG, TAG_VCD, "@@@"); - return VC_ERROR_NONE; + return ret; } -int vcdc_send_request_auth_disable(int pid) +static int __vc_widget_stop_cb(rpc_port_stub_vc_widget_context_h context, int pid, void *user_data) { - SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] auth disable"); - - manager_tidl_info_s* mgr_tidl_info = vcd_client_manager_get_tidl_info(); + SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Widget Stop"); + SLOG(LOG_INFO, TAG_VCD, "[IN] vcd widget stop : pid(%d)", pid); - if (NULL == mgr_tidl_info) { - SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to get tidl info"); - return VC_ERROR_OPERATION_FAILED; - } + int ret = -1; - if (!mgr_tidl_info->connected) { - SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Not Connected"); - return VC_ERROR_OPERATION_FAILED; + ret = vcd_server_widget_stop(pid); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret); + return ret; } - if (0 != rpc_port_proxy_vcd_mgr_invoke_auth_disable(mgr_tidl_info->rpc_h, pid)) { - SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Request auth disable : Fail to invoke message"); - return VC_ERROR_OPERATION_FAILED; - } - SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Request auth disable : Success"); + SLOG(LOG_DEBUG, TAG_VCD, "@@@"); - return VC_ERROR_NONE; + return ret; } -int vcdc_send_request_auth_start(int pid) +static int __vc_widget_cancel_cb(rpc_port_stub_vc_widget_context_h context, int pid, void *user_data) { - SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] auth start"); + SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Widget Cancel"); + SLOG(LOG_INFO, TAG_VCD, "[IN] vcd widget cancel : pid(%d)", pid); - manager_tidl_info_s* mgr_tidl_info = vcd_client_manager_get_tidl_info(); + int ret = -1; - if (NULL == mgr_tidl_info) { - SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to get tidl info"); - return VC_ERROR_OPERATION_FAILED; + ret = vcd_server_widget_cancel(pid); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret); + return ret; } - if (!mgr_tidl_info->connected) { - SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Not Connected"); - return VC_ERROR_OPERATION_FAILED; - } + SLOG(LOG_DEBUG, TAG_VCD, "@@@"); - if (0 != rpc_port_proxy_vcd_mgr_invoke_auth_start(mgr_tidl_info->rpc_h, pid)) { - SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Request auth start : Fail to invoke message"); - return VC_ERROR_OPERATION_FAILED; + return ret; +} + +static int __vc_widget_enable_asr_result_cb(rpc_port_stub_vc_widget_context_h context, int pid, int enable, void *user_data) +{ + SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Widget Enable Asr Result"); + SLOG(LOG_INFO, TAG_VCD, "[IN] vcd widget enable asr result : pid(%d) enable(%d)", pid, enable); + + int ret = -1; + + ret = vcd_server_widget_enable_asr_result(pid, enable); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret); + return ret; } - SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Request auth start : Success"); - return VC_ERROR_NONE; + SLOG(LOG_DEBUG, TAG_VCD, "@@@"); + + return ret; } -int vcdc_send_request_auth_stop(int pid) +static void __vc_widget_set_foreground_cb(rpc_port_stub_vc_widget_context_h context, int pid, int value, void *user_data) { - SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] auth stop"); + SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Widget Set Foreground"); + SLOG(LOG_INFO, TAG_VCD, "[IN] vcd widget set foreground : pid(%d) value(%d)", pid, value); - manager_tidl_info_s* mgr_tidl_info = vcd_client_manager_get_tidl_info(); + int ret = -1; - if (NULL == mgr_tidl_info) { - SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to get tidl info"); - return VC_ERROR_OPERATION_FAILED; + ret = vcd_server_set_foreground(pid, value); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret); + return; } - if (!mgr_tidl_info->connected) { - SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Not Connected"); - return VC_ERROR_OPERATION_FAILED; - } + SLOG(LOG_DEBUG, TAG_VCD, "@@@ send request set foreground to manager"); + vcdc_send_request_set_foreground(pid, value); - if (0 != rpc_port_proxy_vcd_mgr_invoke_auth_stop(mgr_tidl_info->rpc_h, pid)) { - SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Request auth stop : Fail to invoke message"); - return VC_ERROR_OPERATION_FAILED; - } - SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Request auth stop : Success"); + SLOG(LOG_DEBUG, TAG_VCD, "@@@"); - return VC_ERROR_NONE; + return; } -int vcdc_send_request_auth_cancel(int pid) +int vcd_widget_tidl_open_connection() { - SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] auth cancel"); - - manager_tidl_info_s* mgr_tidl_info = vcd_client_manager_get_tidl_info(); + SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] vcd_widget_tidl_open_connection"); + + g_widget_callback.create = __vc_widget_create_cb; + g_widget_callback.terminate = __vc_widget_terminate_cb; + g_widget_callback.register_cb = __vc_widget_register_cb_cb; + g_widget_callback.initialize = __vc_widget_initialize_cb; + g_widget_callback.finalize = __vc_widget_finalize_cb; + g_widget_callback.start_recording = __vc_widget_start_recording_cb; + g_widget_callback.start = __vc_widget_start_cb; + g_widget_callback.stop = __vc_widget_stop_cb; + g_widget_callback.cancel = __vc_widget_cancel_cb; + g_widget_callback.enable_asr_result = __vc_widget_enable_asr_result_cb; + g_widget_callback.set_foreground = __vc_widget_set_foreground_cb; - if (NULL == mgr_tidl_info) { - SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to get tidl info"); - return VC_ERROR_OPERATION_FAILED; + int ret = -1; + int count = 0; + while (VC_RETRY_MIN_COUNT >= count) { + ret = rpc_port_stub_vc_widget_register(&g_widget_callback, NULL); + if (0 == ret) { + SLOG(LOG_DEBUG, TAG_VCD, "register callback"); + return VCD_ERROR_NONE; + } + usleep(100000); + count++; } - if (!mgr_tidl_info->connected) { - SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Not Connected"); - return VC_ERROR_OPERATION_FAILED; - } + SLOG(LOG_ERROR, TAG_VCD, "Fail to register callback(%d)", ret); + return VCD_ERROR_OPERATION_FAILED; +} - if (0 != rpc_port_proxy_vcd_mgr_invoke_auth_cancel(mgr_tidl_info->rpc_h, pid)) { - SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Request auth cancel : Fail to invoke message"); - return VC_ERROR_OPERATION_FAILED; - } - SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Request auth cancel : Success"); +int vcd_widget_tidl_close_connection() +{ + SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Close connection"); + rpc_port_stub_vc_widget_unregister(); - return VC_ERROR_NONE; + return VCD_ERROR_NONE; } diff --git a/server/vcd_tidl.h b/server/vcd_tidl.h index 6f339dc..84e61f8 100644 --- a/server/vcd_tidl.h +++ b/server/vcd_tidl.h @@ -30,23 +30,25 @@ extern "C" { // VCD_CLIENT_TYPE_MANAGER // } vcd_client_type_e; -int vcd_mgr_tidl_open_connection(); +int vcd_tidl_open_connection(); -int vcd_mgr_tidl_close_connection(); +int vcd_tidl_close_connection(); int vcdc_tidl_send_hello(int pid, vcd_client_type_e type); -int vcdc_send_set_volume(int manager_pid, float volume); +int vcdc_send_set_volume(int manger_pid, float volume); -int vcdc_tidl_send_result(int pid, int manager_pid, int cmd_type); +int vcdc_send_show_tooltip(int pid, bool show); + +int vcdc_tidl_send_result(int pid, int manager_pid, vcd_client_type_e type); int vcdc_send_pre_result_to_manager(int manager_pid, int event, const char* pre_result); int vcdc_send_specific_engine_result_to_manager(int manager_pid, const char* engine_app_id, const char* event, const char* result); -int vcdc_send_result_to_manager(int manager_pid, int result_type); +int vcdc_send_result_to_manager(int manger_pid, int result_type); -int vcdc_send_speech_detected(int manager_pid); +int vcdc_send_speech_detected(int manger_pid); int vcdc_tidl_send_error(int reason, char *err_msg); @@ -54,17 +56,20 @@ int vcdc_tidl_send_error_to_manager(int manager_pid, int reason, char *err_msg); int vcdc_send_service_state(vcd_state_e state); -int vcdc_send_dialog(int manager_pid, int pid, const char* disp_text, const char* utt_text, int continuous); +int vcdc_send_dialog(int manger_pid, int pid, const char* disp_text, const char* utt_text, int continuous); int vcdc_send_request_set_private_data(int pid, const char* key, const char* data); int vcdc_send_request_get_private_data(int pid, const char* key, char** data); +int vcdc_send_asr_result(int pid, int event, const char* asr_result, int cmd_type, bool* is_consumed); + /* for TTS feedback */ int vcdc_send_feedback_audio_format_to_manager(int manager_pid, int rate, vc_audio_channel_e channel, vce_audio_type_e audio_type); int vcdc_send_feedback_streaming_to_manager(int manager_pid, int pid, int utt_id, vc_feedback_event_e event, char* buffer, int len); + #ifdef __cplusplus } #endif diff --git a/tidl/vc_widget.tidl b/tidl/vc_widget.tidl new file mode 100644 index 0000000..662afc5 --- /dev/null +++ b/tidl/vc_widget.tidl @@ -0,0 +1,14 @@ +interface vc_widget { + void notify_cb(bundle msg) delegate; + void register_cb(int pid, notify_cb notify_callback) async; + + int initialize(in int pid, out int service_state, out int daemon_pid); + int finalize(in int pid); + int start_recording(in int pid, in int command); + int start(in int pid, in int silence); + int stop(in int pid); + int cancel(in int pid); + int enable_asr_result(in int pid, in int enable); + + void set_foreground(in int pid, in int value) async; +} \ No newline at end of file diff --git a/tidl/vcd_widget.tidl b/tidl/vcd_widget.tidl new file mode 100644 index 0000000..9dfcefa --- /dev/null +++ b/tidl/vcd_widget.tidl @@ -0,0 +1,3 @@ +interface vcd_widget { + int send_asr_result(in int pid, in int event, string asr_result, out bool is_consumed); +} \ No newline at end of file -- 2.7.4 From 7845abdaa3246b36550de0c7fc0c65582728e392 Mon Sep 17 00:00:00 2001 From: Seongmin Park Date: Fri, 29 Apr 2022 02:57:40 +0000 Subject: [PATCH 13/16] Revert "Replace IPC between widget and server from dbus to tidl" This reverts commit a88b50ad66a722e2b44735155623da2b8d2a75e0. Reason for revert: Change-Id: I1e670df9d691736100f61edb16bf54fa349e6090 --- client/CMakeLists.txt | 4 +- client/vc_mgr.c | 1 - client/vc_mgr_tidl.c | 2 - client/vc_widget.c | 34 +- client/vc_widget_dbus.c | 1126 ++++++++++++++++++++++++ client/vc_widget_dbus.h | 54 ++ client/vc_widget_tidl.c | 621 -------------- client/vc_widget_tidl.h | 54 -- common/vc_defs.h | 8 - packaging/voice-control.spec | 5 - server/CMakeLists.txt | 2 - server/vcd_client_data.c | 183 +--- server/vcd_client_data.h | 27 +- server/vcd_dbus.c | 190 ++++- server/vcd_dbus.h | 8 + server/vcd_server.c | 4 +- server/vcd_tidl.c | 1934 +++++++++++++----------------------------- server/vcd_tidl.h | 19 +- tidl/vc_widget.tidl | 14 - tidl/vcd_widget.tidl | 3 - 20 files changed, 1975 insertions(+), 2318 deletions(-) create mode 100644 client/vc_widget_dbus.c create mode 100644 client/vc_widget_dbus.h delete mode 100644 client/vc_widget_tidl.c delete mode 100644 client/vc_widget_tidl.h delete mode 100644 tidl/vc_widget.tidl delete mode 100644 tidl/vcd_widget.tidl diff --git a/client/CMakeLists.txt b/client/CMakeLists.txt index ab5f35f..5815fa0 100644 --- a/client/CMakeLists.txt +++ b/client/CMakeLists.txt @@ -22,9 +22,7 @@ SET(SETTING_SRCS SET(WIDGET_SRCS vc_widget.c vc_widget_client.c - vc_widget_tidl.c - vc_widget_proxy.c - vc_widget_stub.c + vc_widget_dbus.c ../common/vc_cmd_db.c ../common/vc_command.c ../common/vc_command_util.c diff --git a/client/vc_mgr.c b/client/vc_mgr.c index 9fd7862..c02b61b 100755 --- a/client/vc_mgr.c +++ b/client/vc_mgr.c @@ -557,7 +557,6 @@ static Eina_Bool __send_hello_message(void *data) g_send_hello_timer = NULL; return EINA_FALSE; } else { - // TODO: discuss when updating connect/reconnect g_tidl_send_hello_count++; return EINA_TRUE; } diff --git a/client/vc_mgr_tidl.c b/client/vc_mgr_tidl.c index 27154fc..fc9781f 100755 --- a/client/vc_mgr_tidl.c +++ b/client/vc_mgr_tidl.c @@ -582,8 +582,6 @@ int vc_mgr_tidl_open_connection() char* engine_app_id = vconf_get_str(VC_ENGINE_DB_DEFAULT); if (NULL == engine_app_id) { SLOG(LOG_ERROR, TAG_VCM, "[TIDL] vconf not found"); - free(g_proxy_tidl_info); - g_proxy_tidl_info = NULL; pthread_mutex_unlock(&g_tidl_mutex); return VC_ERROR_ENGINE_NOT_FOUND; } diff --git a/client/vc_widget.c b/client/vc_widget.c index c0d1b1e..92e0951 100644 --- a/client/vc_widget.c +++ b/client/vc_widget.c @@ -23,7 +23,7 @@ #include "vc_info_parser.h" #include "vc_main.h" #include "vc_widget_client.h" -#include "vc_widget_tidl.h" +#include "vc_widget_dbus.h" #include "voice_control_command.h" #include "voice_control_command_expand.h" #include "voice_control_internal.h" @@ -174,7 +174,7 @@ int vc_widget_initialize(vc_h* vc_w) } if (0 == vc_widget_client_get_count()) { - if (0 != vc_widget_tidl_open_connection()) { + if (0 != vc_widget_dbus_open_connection()) { SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to open connection"); return VC_ERROR_OPERATION_FAILED; } @@ -216,7 +216,7 @@ int vc_widget_initialize(vc_h* vc_w) static void __vc_widget_internal_unprepare(vc_h vc_w) { - int ret = vc_widget_tidl_request_finalize(getpid()); + int ret = vc_widget_dbus_request_finalize(getpid()); if (0 != ret) { SLOG(LOG_WARN, TAG_VCW, "[ERROR] Fail to request finalize : %s", __vc_widget_get_error_code(ret)); } @@ -333,7 +333,8 @@ int vc_widget_deinitialize(vc_h vc_w) if (0 != ret) { SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to finalize DB, ret(%d)", ret); } - if (0 != vc_widget_tidl_close_connection()) { + + if (0 != vc_widget_dbus_close_connection()) { SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to close connection"); } } @@ -351,13 +352,13 @@ static Eina_Bool __focus_changed_cb(void *data, int type, void *event) int ret; if (ECORE_WL2_EVENT_FOCUS_IN == type) { SLOG(LOG_DEBUG, TAG_VCW, "@@@ Set foreground"); - ret = vc_widget_tidl_set_foreground(getpid(), true); + ret = vc_widget_dbus_set_foreground(getpid(), true); if (0 != ret) { SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to set foreground (true) : %d", ret); } } else if (ECORE_WL2_EVENT_FOCUS_OUT == type) { SLOG(LOG_DEBUG, TAG_VCW, "@@@ Set background"); - ret = vc_widget_tidl_set_foreground(getpid(), false); + ret = vc_widget_dbus_set_foreground(getpid(), false); if (0 != ret) { SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to set foreground (false) : %d", ret); } @@ -420,7 +421,7 @@ static Eina_Bool __vc_widget_connect_daemon(void *data) /* request initialization */ int service_state = 0; - ret = vc_widget_tidl_request_initialize(getpid(), &service_state, &g_daemon_pid); + ret = vc_widget_dbus_request_initialize(getpid(), &service_state, &g_daemon_pid); if (VC_ERROR_ENGINE_NOT_FOUND == ret) { SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to initialize : %s", __vc_widget_get_error_code(ret)); @@ -480,7 +481,7 @@ static Eina_Bool __vc_widget_connect_daemon(void *data) int status = aul_app_get_status(appid); if (status == STATUS_FOCUS) { SLOG(LOG_DEBUG, TAG_VCW, "@@@ Set foreground"); - ret = vc_widget_tidl_set_foreground(getpid(), true); + ret = vc_widget_dbus_set_foreground(getpid(), true); if (0 != ret) { SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to set foreground (true) : %d", ret); } @@ -534,15 +535,12 @@ static void __start_prepare_thread(void *data, Ecore_Thread *thread) return; } - ret = vc_widget_tidl_request_hello(); + ret = vc_widget_dbus_request_hello(); if (ret == 0) { SLOG(LOG_DEBUG, TAG_VCW, "Success to request hello. retry count(%d)", retry_count); break; } else { retry_count++; - // TODO: discuss when updating connect/reconnect - SLOG(LOG_DEBUG, TAG_VCW, "Fail to request TIDL hello. failed(%d)", retry_count); - usleep(200000); } } @@ -705,7 +703,7 @@ int vc_widget_enable_asr_result(vc_h vc_w, bool enable) int ret = -1; do { - ret = vc_widget_tidl_request_enable_asr_result(getpid(), enable); + ret = vc_widget_dbus_request_enable_asr_result(getpid(), enable); if (0 != ret) { if (VC_ERROR_TIMED_OUT != ret) { SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to enable asr result : %s", __vc_widget_get_error_code(ret)); @@ -905,7 +903,7 @@ int vc_widget_set_foreground(vc_h vc_w, bool value) } SLOG(LOG_DEBUG, TAG_VCW, "Set foreground : pid(%d) value(%s)", getpid(), value ? "true" : "false"); - int ret = vc_widget_tidl_set_foreground(getpid(), value); + int ret = vc_widget_dbus_set_foreground(getpid(), value); if (0 != ret) { ret = vc_config_convert_error_code((vc_config_error_e)ret); SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to set foreground : %s", __vc_widget_get_error_code(ret)); @@ -1015,7 +1013,7 @@ int vc_widget_start(bool stop_by_silence, vc_cmd_group_h vc_group) } else { int count = 0; do { - ret = vc_widget_tidl_request_start(getpid(), stop_by_silence); + ret = vc_widget_dbus_request_start(getpid(), stop_by_silence); if (0 != ret) { if (VC_ERROR_TIMED_OUT != ret) { SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to request start : %s", __vc_widget_get_error_code(ret)); @@ -1097,7 +1095,7 @@ int vc_widget_stop() int count = 0; do { - ret = vc_widget_tidl_request_stop(getpid()); + ret = vc_widget_dbus_request_stop(getpid()); if (0 != ret) { if (VC_ERROR_TIMED_OUT != ret) { SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to request stop : %s", __vc_widget_get_error_code(ret)); @@ -1154,7 +1152,7 @@ int vc_widget_cancel(vc_h vc_w) int ret = -1; do { - ret = vc_widget_tidl_request_cancel(getpid()); + ret = vc_widget_dbus_request_cancel(getpid()); if (0 != ret) { if (VC_ERROR_TIMED_OUT != ret) { SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to request cancel : %s", __vc_widget_get_error_code(ret)); @@ -1313,7 +1311,7 @@ static Eina_Bool __vc_widget_start_recording(void *data) ret = -1; count = 0; while (0 != ret) { - ret = vc_widget_tidl_request_start_recording(getpid(), widget_command); + ret = vc_widget_dbus_request_start_recording(getpid(), widget_command); if (0 != ret) { if (VC_ERROR_TIMED_OUT != ret) { SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to request start recording to daemon : %s", __vc_widget_get_error_code(ret)); diff --git a/client/vc_widget_dbus.c b/client/vc_widget_dbus.c new file mode 100644 index 0000000..a6f2769 --- /dev/null +++ b/client/vc_widget_dbus.c @@ -0,0 +1,1126 @@ +/* +* Copyright (c) 2011-2015 Samsung Electronics Co., Ltd All Rights Reserved +* +* Licensed under the Apache License, Version 2.0 (the License); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an AS IS BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + + +#include + +#include "vc_main.h" +#include "vc_widget_client.h" +#include "vc_widget_dbus.h" + + +static pthread_mutex_t g_w_dbus_mutex = PTHREAD_MUTEX_INITIALIZER; +static pthread_mutex_t g_w_init_mutex = PTHREAD_MUTEX_INITIALIZER; + +static int g_w_waiting_time = 3000; +static int g_w_waiting_short_time = 200; +static bool g_is_connection_opened = false; + +static Ecore_Fd_Handler* g_w_fd_handler = NULL; + +static DBusConnection* g_w_conn_sender = NULL; +static DBusConnection* g_w_conn_listener = NULL; + +extern int __vc_widget_cb_error(int reason, int daemon_pid, char* msg); + +extern void __vc_widget_cb_show_tooltip(int pid, bool show); + +extern void __vc_widget_cb_result(); + +extern bool __vc_widget_cb_asr_result(int event, const char* asr_result); + +extern int __vc_widget_cb_service_state(int state); + + +static Eina_Bool widget_listener_event_callback(void* data, Ecore_Fd_Handler *fd_handler) +{ + if (NULL == g_w_conn_listener) return ECORE_CALLBACK_RENEW; + + dbus_connection_read_write_dispatch(g_w_conn_listener, 50); + + while (1) { + DBusMessage* msg = NULL; + msg = dbus_connection_pop_message(g_w_conn_listener); + + /* loop again if we haven't read a message */ + if (NULL == msg) { + break; + } + + SLOG(LOG_DEBUG, TAG_VCW, "[DEBUG] Message is arrived"); + + DBusError err; + dbus_error_init(&err); + + char if_name[64] = {0, }; + snprintf(if_name, 64, "%s", VC_WIDGET_SERVICE_INTERFACE); + + if (dbus_message_is_method_call(msg, if_name, VCD_WIDGET_METHOD_HELLO)) { + SLOG(LOG_DEBUG, TAG_VCW, "@@@ Get widget hello"); + int pid = 0; + int response = -1; + + dbus_message_get_args(msg, &err, DBUS_TYPE_INT32, &pid, DBUS_TYPE_INVALID); + + if (dbus_error_is_set(&err)) { + SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Dbus Error (%s)", err.message); + dbus_error_free(&err); + } + + if (pid > 0) { + SLOG(LOG_DEBUG, TAG_VCW, "@@ vc widget get hello : pid(%d) ", pid); + response = 1; + } else { + SLOG(LOG_ERROR, TAG_VCW, "@@ vc widget get hello : invalid pid "); + } + + DBusMessage* reply = NULL; + reply = dbus_message_new_method_return(msg); + + if (NULL != reply) { + dbus_message_append_args(reply, DBUS_TYPE_INT32, &response, DBUS_TYPE_INVALID); + + if (!dbus_connection_send(g_w_conn_listener, reply, NULL)) + SLOG(LOG_ERROR, TAG_VCW, "@@ vc widget get hello : fail to send reply"); + else + SLOG(LOG_DEBUG, TAG_VCW, "@@ vc widget get hello : result(%d)", response); + + dbus_connection_flush(g_w_conn_listener); + dbus_message_unref(reply); + } else { + SLOG(LOG_ERROR, TAG_VCW, "@@ vc widget get hello : fail to create reply message"); + } + + SLOG(LOG_DEBUG, TAG_VCW, "@@@"); + } /* VCD_WIDGET_METHOD_HELLO */ + + else if (dbus_message_is_signal(msg, if_name, VCD_WIDGET_METHOD_SET_SERVICE_STATE)) { + int state = 0; + + dbus_message_get_args(msg, &err, DBUS_TYPE_INT32, &state, DBUS_TYPE_INVALID); + if (dbus_error_is_set(&err)) { + SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Get arguments error (%s)", err.message); + dbus_error_free(&err); + } + + SLOG(LOG_DEBUG, TAG_VCW, "@@ service state changed : %d", state); + + __vc_widget_cb_service_state(state); + + } /* VCD_WIDGET_METHOD_SET_SERVICE_STATE */ + + else if (dbus_message_is_method_call(msg, if_name, VCD_WIDGET_METHOD_SHOW_TOOLTIP)) { + SLOG(LOG_DEBUG, TAG_VCW, "@@@ Show / Hide tooltip"); + int pid = 0; + int show = 0; + + dbus_message_get_args(msg, &err, + DBUS_TYPE_INT32, &pid, + DBUS_TYPE_INT32, &show, + DBUS_TYPE_INVALID); + + if (dbus_error_is_set(&err)) { + SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Dbus Error (%s)", err.message); + dbus_error_free(&err); + } + + if (pid > 0) { + SLOG(LOG_DEBUG, TAG_VCW, "@@ vc widget show tooltip : pid(%d), show(%d)", pid, show); + __vc_widget_cb_show_tooltip(pid, (bool)show); + } else { + SLOG(LOG_ERROR, TAG_VCW, "@@ vc widget show tooltip : invalid pid"); + } + + SLOG(LOG_DEBUG, TAG_VCW, "@@@"); + } /* VCD_WIDGET_METHOD_SHOW_TOOLTIP */ + + else if (dbus_message_is_method_call(msg, if_name, VCD_WIDGET_METHOD_RESULT)) { + SLOG(LOG_DEBUG, TAG_VCW, "@@@ Get widget result"); + + __vc_widget_cb_result(); + + SLOG(LOG_DEBUG, TAG_VCW, "@@@"); + + } /* VCD_WIDGET_METHOD_RESULT */ + + else if (dbus_message_is_method_call(msg, if_name, VCD_WIDGET_METHOD_ASR_RESULT)) { + SLOG(LOG_DEBUG, TAG_VCW, "@@@ Get widget asr result"); + int ret = 0; + int event = -1; + char* asr_result = NULL; + + dbus_message_get_args(msg, &err, + DBUS_TYPE_INT32, &event, + DBUS_TYPE_STRING, &asr_result, + DBUS_TYPE_INVALID); + + if (false == __vc_widget_cb_asr_result(event, asr_result)) + ret = 0; + else + ret = 1; + + DBusMessage* reply = dbus_message_new_method_return(msg); + if (NULL != reply) { + dbus_message_append_args(reply, DBUS_TYPE_INT32, &ret, DBUS_TYPE_INVALID); + if (!dbus_connection_send(g_w_conn_listener, reply, NULL)) + SLOG(LOG_ERROR, TAG_VCW, "@@ vc widget get asr result : fail to send reply"); + else + SLOG(LOG_DEBUG, TAG_VCW, "@@ vc widget get asr result, event(%d), asr_result(%s), consumed(%d)", event, asr_result, ret); + + dbus_connection_flush(g_w_conn_listener); + dbus_message_unref(reply); + } else { + SLOG(LOG_ERROR, TAG_VCW, "@@ vc widget asr get result : fail to create reply message"); + } + + SLOG(LOG_DEBUG, TAG_VCW, "@@@"); + + } /* VCD_WIDGET_METHOD_ASR_RESULT */ + + else if (dbus_message_is_signal(msg, if_name, VCD_WIDGET_METHOD_ERROR)) { + SLOG(LOG_DEBUG, TAG_VCW, "@@@ Get widget error"); + int reason; + int daemon_pid; + char* err_msg; + + dbus_message_get_args(msg, &err, + DBUS_TYPE_INT32, &reason, + DBUS_TYPE_INT32, &daemon_pid, + DBUS_TYPE_STRING, &err_msg, + DBUS_TYPE_INVALID); + + if (dbus_error_is_set(&err)) { + SLOG(LOG_ERROR, TAG_VCW, "@@ vc widget get error message : Get arguments error (%s)", err.message); + dbus_error_free(&err); + } else { + SLOG(LOG_DEBUG, TAG_VCW, "@@ vc widget get error message : reason(%d), daemon_pid(%d), msg(%s)", reason, daemon_pid, err_msg); + __vc_widget_cb_error(reason, daemon_pid, err_msg); + } + + /* + reply = dbus_message_new_method_return(msg); + + if (NULL != reply) { + if (!dbus_connection_send(g_w_conn_listener, reply, NULL)) + SLOG(LOG_ERROR, TAG_VCW, "@@ vc widget error message : fail to send reply"); + else + SLOG(LOG_DEBUG, TAG_VCW, "@@ vc widget error message"); + + dbus_connection_flush(g_w_conn_listener); + dbus_message_unref(reply); + } else { + SLOG(LOG_ERROR, TAG_VCW, "@@ vc widget error message : fail to create reply message"); + } + */ + + SLOG(LOG_DEBUG, TAG_VCW, "@@@"); + } /* VCD_WIDGET_METHOD_ERROR */ + + else if (dbus_message_is_signal(msg, "org.freedesktop.DBus", "NameOwnerChanged")) { + SLOG(LOG_DEBUG, TAG_VCW, "@@@ Owner Changed"); + DBusError err; + dbus_error_init(&err); + + /* remove a rule for daemon error */ + char rule_err[256] = {0, }; + snprintf(rule_err, 256, "sender='org.freedesktop.DBus',path='/org/freedesktop/DBus',interface='org.freedesktop.DBus',member='NameOwnerChanged',type='signal',arg0='%s'", VC_SERVER_SERVICE_INTERFACE); + dbus_bus_remove_match(g_w_conn_listener, rule_err, &err); + dbus_connection_flush(g_w_conn_listener); + + if (dbus_error_is_set(&err)) { + SLOG(LOG_ERROR, TAG_VCW, "Match Error (%s)", err.message); + dbus_error_free(&err); + } + __vc_widget_cb_error(VC_ERROR_SERVICE_RESET, -1, "Daemon Reset"); + SLOG(LOG_DEBUG, TAG_VCW, "@@@"); + } /* NameOwnerChanged */ + + else { + const char* sender = dbus_message_get_sender(msg); + const char* destination = dbus_message_get_destination(msg); + const char* path = dbus_message_get_path(msg); + const char* interf = dbus_message_get_interface(msg); + const char* member = dbus_message_get_member(msg); + int type = dbus_message_get_type(msg); + SLOG(LOG_ERROR, TAG_VCW, "[INFO] Message is NOT valid, sender(%s), destination(%s), path(%s), interface(%s), member(%s), type(%d)", sender, destination, path, interf, member, type); + dbus_message_unref(msg); + break; + } + + /* free the message */ + dbus_message_unref(msg); + } /* while(1) */ + + return ECORE_CALLBACK_PASS_ON; +} + +static void __vc_widget_dbus_connection_free() +{ + if (NULL != g_w_conn_listener) { + dbus_connection_close(g_w_conn_listener); + dbus_connection_unref(g_w_conn_listener); + g_w_conn_listener = NULL; + } + if (NULL != g_w_conn_sender) { + dbus_connection_close(g_w_conn_sender); + dbus_connection_unref(g_w_conn_sender); + g_w_conn_sender = NULL; + } +} + +int vc_widget_dbus_open_connection() +{ + pthread_mutex_lock(&g_w_dbus_mutex); + + if (NULL != g_w_conn_sender && NULL != g_w_conn_listener) { + SLOG(LOG_WARN, TAG_VCW, "Already existed connection "); + pthread_mutex_unlock(&g_w_dbus_mutex); + return VC_ERROR_NONE; + } + + DBusError err; + int ret; + + /* initialize the error value */ + dbus_error_init(&err); + + /* connect to the DBUS system bus, and check for errors */ + g_w_conn_sender = dbus_bus_get_private(DBUS_BUS_SESSION, &err); + + if (dbus_error_is_set(&err)) { + SLOG(LOG_ERROR, TAG_VCW, "Dbus Connection Error (%s)", err.message); + dbus_error_free(&err); + } + + if (NULL == g_w_conn_sender) { + SLOG(LOG_ERROR, TAG_VCW, "Fail to get dbus connection "); + pthread_mutex_unlock(&g_w_dbus_mutex); + return VC_ERROR_OPERATION_FAILED; + } + + dbus_connection_set_exit_on_disconnect(g_w_conn_sender, false); + + g_w_conn_listener = dbus_bus_get_private(DBUS_BUS_SESSION, &err); + + if (dbus_error_is_set(&err)) { + SLOG(LOG_ERROR, TAG_VCW, "Dbus Connection Error (%s)", err.message); + dbus_error_free(&err); + } + + if (NULL == g_w_conn_listener) { + SLOG(LOG_ERROR, TAG_VCW, "Fail to get dbus connection "); + __vc_widget_dbus_connection_free(); + pthread_mutex_unlock(&g_w_dbus_mutex); + return VC_ERROR_OPERATION_FAILED; + } + + dbus_connection_set_exit_on_disconnect(g_w_conn_listener, false); + + int pid = getpid(); + + char service_name[64]; + memset(service_name, '\0', 64); + snprintf(service_name, 64, "%s%d", VC_WIDGET_SERVICE_NAME, pid); + + SLOG(LOG_DEBUG, TAG_VCW, "service name is %s", service_name); + + /* register our name on the bus, and check for errors */ + ret = dbus_bus_request_name(g_w_conn_listener, service_name, DBUS_NAME_FLAG_REPLACE_EXISTING , &err); + + if (dbus_error_is_set(&err)) { + SLOG(LOG_ERROR, TAG_VCW, "Name Error (%s)", err.message); + dbus_error_free(&err); + } + + if (DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER != ret) { + SLOG(LOG_ERROR, TAG_VCW, "fail dbus_bus_request_name()"); + __vc_widget_dbus_connection_free(); + pthread_mutex_unlock(&g_w_dbus_mutex); + return -2; + } + + if (NULL != g_w_fd_handler) { + SLOG(LOG_WARN, TAG_VCW, "The handler already exists."); + __vc_widget_dbus_connection_free(); + pthread_mutex_unlock(&g_w_dbus_mutex); + return 0; + } + + char rule[128] = {0, }; + snprintf(rule, 128, "type='signal',interface='%s'", VC_WIDGET_SERVICE_INTERFACE); + + /* add a rule for which messages we want to see */ + dbus_bus_add_match(g_w_conn_listener, rule, &err); + + if (dbus_error_is_set(&err)) { + SLOG(LOG_ERROR, TAG_VCW, "Match Error (%s)", err.message); + dbus_error_free(&err); + __vc_widget_dbus_connection_free(); + pthread_mutex_unlock(&g_w_dbus_mutex); + return VC_ERROR_OPERATION_FAILED; + } + + int fd = 0; + if (1 != dbus_connection_get_unix_fd(g_w_conn_listener, &fd)) { + SLOG(LOG_ERROR, TAG_VCW, "fail to get fd from dbus "); + __vc_widget_dbus_connection_free(); + pthread_mutex_unlock(&g_w_dbus_mutex); + return VC_ERROR_OPERATION_FAILED; + } else { + SLOG(LOG_DEBUG, TAG_VCW, "Get fd from dbus : %d", fd); + } + + g_w_fd_handler = ecore_main_fd_handler_add(fd, ECORE_FD_READ, (Ecore_Fd_Cb)widget_listener_event_callback, g_w_conn_listener, NULL, NULL); + + if (NULL == g_w_fd_handler) { + SLOG(LOG_ERROR, TAG_VCW, "fail to get fd handler from ecore "); + __vc_widget_dbus_connection_free(); + pthread_mutex_unlock(&g_w_dbus_mutex); + return VC_ERROR_OPERATION_FAILED; + } + + g_is_connection_opened = true; + + pthread_mutex_unlock(&g_w_dbus_mutex); + + SLOG(LOG_INFO, TAG_VCW, "[INFO] widget dbus connection is opened"); + + return 0; +} + +int vc_widget_dbus_close_connection() +{ + pthread_mutex_lock(&g_w_dbus_mutex); + + DBusError err; + dbus_error_init(&err); + + if (NULL != g_w_fd_handler) { + ecore_main_fd_handler_del(g_w_fd_handler); + g_w_fd_handler = NULL; + } + + if (NULL != g_w_conn_listener) { + int pid = getpid(); + + char service_name[64]; + memset(service_name, '\0', 64); + snprintf(service_name, 64, "%s%d", VC_WIDGET_SERVICE_NAME, pid); + + dbus_bus_release_name(g_w_conn_listener, service_name, &err); + + if (dbus_error_is_set(&err)) { + SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Dbus Error (%s)", err.message); + dbus_error_free(&err); + } + } + + __vc_widget_dbus_connection_free(); + + g_is_connection_opened = false; + + pthread_mutex_unlock(&g_w_dbus_mutex); + + SLOG(LOG_INFO, TAG_VCW, "[INFO] widget dbus connection is closed"); + + return 0; +} + +int vc_widget_dbus_reconnect() +{ + if (!g_w_conn_sender || !g_w_conn_listener) { + vc_widget_dbus_close_connection(); + + if (0 != vc_widget_dbus_open_connection()) { + SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to reconnect"); + return -1; + } + + SLOG(LOG_DEBUG, TAG_VCW, "[DBUS] Reconnect"); + return 0; + } + + bool sender_connected = dbus_connection_get_is_connected(g_w_conn_sender); + bool listener_connected = dbus_connection_get_is_connected(g_w_conn_listener); + SLOG(LOG_DEBUG, TAG_VCW, "[DBUS] Sender(%s) Listener(%s)", + sender_connected ? "Connected" : "Not connected", listener_connected ? "Connected" : "Not connected"); + + if (false == sender_connected || false == listener_connected) { + vc_widget_dbus_close_connection(); + + if (0 != vc_widget_dbus_open_connection()) { + SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to reconnect"); + return -1; + } + + SLOG(LOG_DEBUG, TAG_VCW, "[DBUS] Reconnect"); + } + + return 0; +} + +static int __dbus_check() +{ + if (NULL == g_w_conn_sender || NULL == g_w_conn_listener) { + SLOG(LOG_ERROR, TAG_VCW, "[ERROR] NULL connection"); + return vc_widget_dbus_reconnect(); + } + return 0; +} + +int vc_widget_dbus_request_hello() +{ + if (0 != __dbus_check()) { + return VC_ERROR_OPERATION_FAILED; + } + + DBusMessage* msg; + + msg = dbus_message_new_method_call( + VC_SERVER_SERVICE_NAME, + VC_SERVER_SERVICE_OBJECT_PATH, + VC_SERVER_SERVICE_INTERFACE, + VC_METHOD_HELLO); + + if (NULL == msg) { + SLOG(LOG_ERROR, TAG_VCW, "@@ Request vc hello : Fail to make message"); + return VC_ERROR_OPERATION_FAILED; + } + + DBusError err; + dbus_error_init(&err); + + DBusMessage* result_msg = NULL; + int result = 0; + + result_msg = dbus_connection_send_with_reply_and_block(g_w_conn_sender, msg, g_w_waiting_short_time, &err); + + if (dbus_error_is_set(&err)) { + if (!strncmp(err.name, DBUS_ERROR_SERVICE_UNKNOWN, strlen(err.name))) + usleep(500000); + dbus_error_free(&err); + } + + dbus_message_unref(msg); + + if (NULL != result_msg) { + dbus_message_unref(result_msg); + result = 0; + } else { + result = VC_ERROR_TIMED_OUT; + } + + return result; +} + + +int vc_widget_dbus_request_initialize(int pid, int* service_state, int* daemon_pid) +{ + pthread_mutex_lock(&g_w_init_mutex); + if (0 != __dbus_check()) { + pthread_mutex_unlock(&g_w_init_mutex); + return VC_ERROR_OPERATION_FAILED; + } + + DBusMessage* msg; + + msg = dbus_message_new_method_call( + VC_SERVER_SERVICE_NAME, + VC_SERVER_SERVICE_OBJECT_PATH, + VC_SERVER_SERVICE_INTERFACE, + VC_WIDGET_METHOD_INITIALIZE); + + if (NULL == msg) { + SLOG(LOG_ERROR, TAG_VCW, "@@ vc widget initialize : Fail to make message "); + pthread_mutex_unlock(&g_w_init_mutex); + return VC_ERROR_OPERATION_FAILED; + } else { + SLOG(LOG_DEBUG, TAG_VCW, "@@ vc widget initialize : pid(%d)", pid); + } + + dbus_message_append_args(msg, + DBUS_TYPE_INT32, &pid, + DBUS_TYPE_INVALID); + + DBusError err; + dbus_error_init(&err); + + DBusMessage* result_msg; + int result = VC_ERROR_OPERATION_FAILED; + + result_msg = dbus_connection_send_with_reply_and_block(g_w_conn_sender, msg, g_w_waiting_time, &err); + dbus_message_unref(msg); + + if (dbus_error_is_set(&err)) { + SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Dbus Error (%s)", err.message); + dbus_error_free(&err); + } + + if (NULL != result_msg) { + int tmp_service_state = 0; + int tmp_daemon_pid = 0; + dbus_message_get_args(result_msg, &err, + DBUS_TYPE_INT32, &result, + DBUS_TYPE_INT32, &tmp_service_state, + DBUS_TYPE_INT32, &tmp_daemon_pid, + DBUS_TYPE_INVALID); + + if (dbus_error_is_set(&err)) { + SLOG(LOG_ERROR, TAG_VCW, "@@ Get arguments error (%s)", err.message); + dbus_error_free(&err); + result = VC_ERROR_OPERATION_FAILED; + } + + dbus_message_unref(result_msg); + + if (0 == result) { + *service_state = tmp_service_state; + *daemon_pid = tmp_daemon_pid; + + /* add a rule for daemon error */ + char rule_err[256] = {0, }; + snprintf(rule_err, 256, "sender='org.freedesktop.DBus',path='/org/freedesktop/DBus',interface='org.freedesktop.DBus',member='NameOwnerChanged',type='signal',arg0='%s'", VC_SERVER_SERVICE_INTERFACE); + if (NULL == g_w_conn_listener) { + if (g_is_connection_opened) { + SLOG(LOG_ERROR, TAG_VCW, "[ERROR] g_w_conn_listener is NULL abnormally"); + pthread_mutex_unlock(&g_w_init_mutex); + return VC_ERROR_OPERATION_FAILED; + } else { + SLOG(LOG_INFO, TAG_VCW, "[INFO] g_w_conn_listener is NULL and DBUS connection was closed"); + pthread_mutex_unlock(&g_w_init_mutex); + return VC_ERROR_NONE; + } + } + + dbus_bus_add_match(g_w_conn_listener, rule_err, NULL); + + SLOG(LOG_DEBUG, TAG_VCW, "@@ vc widget initialize : result = %d service = %d daemon_pid = %d", result, *service_state, *daemon_pid); + } else { + SLOG(LOG_ERROR, TAG_VCW, "@@ vc widget initialize : result = %d", result); + } + } else { + SLOG(LOG_ERROR, TAG_VCW, "@@ Result message is NULL "); + vc_widget_dbus_reconnect(); + result = VC_ERROR_TIMED_OUT; + } + + pthread_mutex_unlock(&g_w_init_mutex); + return result; +} + +int vc_widget_dbus_request_finalize(int pid) +{ + pthread_mutex_lock(&g_w_init_mutex); + if (0 != __dbus_check()) { + pthread_mutex_unlock(&g_w_init_mutex); + return VC_ERROR_OPERATION_FAILED; + } + + if (NULL == g_w_conn_listener) { + if (g_is_connection_opened) { + SLOG(LOG_ERROR, TAG_VCW, "[ERROR] g_w_conn_listener is NULL abnormally"); + pthread_mutex_unlock(&g_w_init_mutex); + return VC_ERROR_OPERATION_FAILED; + } else { + SLOG(LOG_INFO, TAG_VCW, "[INFO] g_w_conn_listener is NULL and DBUS connection was closed"); + pthread_mutex_unlock(&g_w_init_mutex); + return VC_ERROR_NONE; + } + } + + DBusError err; + dbus_error_init(&err); + + /* remove a rule for daemon error */ + char rule_err[256] = {0, }; + snprintf(rule_err, 256, "sender='org.freedesktop.DBus',path='/org/freedesktop/DBus',interface='org.freedesktop.DBus',member='NameOwnerChanged',type='signal',arg0='%s'", VC_SERVER_SERVICE_INTERFACE); + dbus_bus_remove_match(g_w_conn_listener, rule_err, &err); + dbus_connection_flush(g_w_conn_listener); + + if (dbus_error_is_set(&err)) { + SLOG(LOG_ERROR, TAG_VCW, "Match Error (%s)", err.message); + dbus_error_free(&err); + pthread_mutex_unlock(&g_w_init_mutex); + return VC_ERROR_OPERATION_FAILED; + } + + DBusMessage* msg; + + msg = dbus_message_new_method_call( + VC_SERVER_SERVICE_NAME, + VC_SERVER_SERVICE_OBJECT_PATH, + VC_SERVER_SERVICE_INTERFACE, + VC_WIDGET_METHOD_FINALIZE); + + if (NULL == msg) { + SLOG(LOG_ERROR, TAG_VCW, "@@ vc widget finalize : Fail to make message "); + pthread_mutex_unlock(&g_w_init_mutex); + return VC_ERROR_OPERATION_FAILED; + } else { + SLOG(LOG_DEBUG, TAG_VCW, "@@ vc widget finalize : pid(%d)", pid); + } + + dbus_message_append_args(msg, DBUS_TYPE_INT32, &pid, DBUS_TYPE_INVALID); + + DBusMessage* result_msg; + int result = VC_ERROR_OPERATION_FAILED; + + result_msg = dbus_connection_send_with_reply_and_block(g_w_conn_sender, msg, g_w_waiting_time, &err); + dbus_message_unref(msg); + + if (dbus_error_is_set(&err)) { + SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Dbus Error (%s)", err.message); + dbus_error_free(&err); + } + + if (NULL != result_msg) { + dbus_message_get_args(result_msg, &err, + DBUS_TYPE_INT32, &result, + DBUS_TYPE_INVALID); + + if (dbus_error_is_set(&err)) { + SLOG(LOG_ERROR, TAG_VCW, "@@ Get arguments error (%s)", err.message); + dbus_error_free(&err); + result = VC_ERROR_OPERATION_FAILED; + } + + dbus_message_unref(result_msg); + + if (0 == result) { + SLOG(LOG_DEBUG, TAG_VCW, "@@ vc widget finalize : result = %d", result); + } else { + SLOG(LOG_ERROR, TAG_VCW, "@@ vc widget finalize : result = %d", result); + } + } else { + SLOG(LOG_ERROR, TAG_VCW, "@@ Result message is NULL "); + vc_widget_dbus_reconnect(); + result = VC_ERROR_TIMED_OUT; + } + + pthread_mutex_unlock(&g_w_init_mutex); + return result; +} + +int vc_widget_dbus_request_start_recording(int pid, bool command) +{ + if (0 != __dbus_check()) { + return VC_ERROR_OPERATION_FAILED; + } + + DBusMessage* msg; + + msg = dbus_message_new_method_call( + VC_SERVER_SERVICE_NAME, + VC_SERVER_SERVICE_OBJECT_PATH, + VC_SERVER_SERVICE_INTERFACE, + VC_WIDGET_METHOD_START_RECORDING); + + if (NULL == msg) { + SLOG(LOG_ERROR, TAG_VCW, "@@ vc widget start recording : Fail to make message"); + return VC_ERROR_OPERATION_FAILED; + } else { + SLOG(LOG_DEBUG, TAG_VCW, "@@ vc widget start recording : pid(%d)", pid); + } + + int temp = (int)command; + + dbus_message_append_args(msg, + DBUS_TYPE_INT32, &pid, + DBUS_TYPE_INT32, &temp, + DBUS_TYPE_INVALID); + + DBusError err; + dbus_error_init(&err); + + DBusMessage* result_msg; + int result = VC_ERROR_OPERATION_FAILED; + + result_msg = dbus_connection_send_with_reply_and_block(g_w_conn_sender, msg, g_w_waiting_time, &err); + dbus_message_unref(msg); + + if (dbus_error_is_set(&err)) { + SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Dbus Error (%s)", err.message); + dbus_error_free(&err); + } + + if (NULL != result_msg) { + dbus_message_get_args(result_msg, &err, DBUS_TYPE_INT32, &result, DBUS_TYPE_INVALID); + + if (dbus_error_is_set(&err)) { + SLOG(LOG_ERROR, TAG_VCW, "@@ Get arguments error (%s)", err.message); + dbus_error_free(&err); + result = VC_ERROR_OPERATION_FAILED; + } + dbus_message_unref(result_msg); + + if (0 == result) { + SLOG(LOG_DEBUG, TAG_VCW, "@@ vc widget start recording : result = %d", result); + } else { + SLOG(LOG_ERROR, TAG_VCW, "@@ vc widget start recording : result = %d", result); + } + } else { + SLOG(LOG_ERROR, TAG_VCW, "@@ Result message is NULL"); + vc_widget_dbus_reconnect(); + result = VC_ERROR_TIMED_OUT; + } + + return result; +} + +int vc_widget_dbus_set_foreground(int pid, bool value) +{ + if (0 != __dbus_check()) { + return VC_ERROR_OPERATION_FAILED; + } + + DBusMessage* msg = NULL; + int tmp_value = 0; + + tmp_value = (int)value; + + msg = dbus_message_new_signal( + VC_MANAGER_SERVICE_OBJECT_PATH, + VC_MANAGER_SERVICE_INTERFACE, + VCC_MANAGER_METHOD_SET_FOREGROUND); + + if (NULL == msg) { + SLOG(LOG_ERROR, TAG_VCW, "@@ vc widget set foreground to manager : Fail to make message"); + return VC_ERROR_OPERATION_FAILED; + } else { + SLOG(LOG_DEBUG, TAG_VCW, "@@ vc widget set foreground to manager : client pid(%d), value(%s)", pid, tmp_value ? "true" : "false"); + } + + dbus_message_append_args(msg, + DBUS_TYPE_INT32, &pid, + DBUS_TYPE_INT32, &tmp_value, + DBUS_TYPE_INVALID); + + if (1 != dbus_connection_send(g_w_conn_sender, msg, NULL)) { + SLOG(LOG_ERROR, TAG_VCW, "[Dbus ERROR] Fail to Send"); + dbus_message_unref(msg); + return VC_ERROR_OPERATION_FAILED; + } + + dbus_message_unref(msg); + + msg = NULL; + msg = dbus_message_new_method_call( + VC_SERVER_SERVICE_NAME, + VC_SERVER_SERVICE_OBJECT_PATH, + VC_SERVER_SERVICE_INTERFACE, + VC_METHOD_SET_FOREGROUND); + + if (NULL == msg) { + SLOG(LOG_ERROR, TAG_VCW, "@@ vc widget set foreground to daemon : Fail to make message"); + return VC_ERROR_OPERATION_FAILED; + } else { + SLOG(LOG_DEBUG, TAG_VCW, "@@ vc widget set foreground to daemon : client pid(%d), value(%s)", pid, tmp_value ? "true" : "false"); + } + + dbus_message_append_args(msg, + DBUS_TYPE_INT32, &pid, + DBUS_TYPE_INT32, &tmp_value, + DBUS_TYPE_INVALID); + + dbus_message_set_no_reply(msg, TRUE); + + /* send the message and flush the connection */ + if (1 != dbus_connection_send(g_w_conn_sender, msg, NULL)) { + SLOG(LOG_ERROR, TAG_VCW, "[Dbus ERROR] Fail to Send"); + dbus_message_unref(msg); + return VC_ERROR_OPERATION_FAILED; + } else { + SLOG(LOG_INFO, TAG_VCW, "[Dbus] SUCCESS Send"); + dbus_connection_flush(g_w_conn_sender); + } + + dbus_message_unref(msg); + + return 0; +} + +int vc_widget_dbus_request_enable_asr_result(int pid, bool enable) +{ + if (0 != __dbus_check()) { + return VC_ERROR_OPERATION_FAILED; + } + + DBusMessage* msg; + + /* create a signal & check for errors */ + msg = dbus_message_new_method_call( + VC_SERVER_SERVICE_NAME, + VC_SERVER_SERVICE_OBJECT_PATH, + VC_SERVER_SERVICE_INTERFACE, + VC_WIDGET_METHOD_ENABLE_ASR_RESULT); + + if (NULL == msg) { + SLOG(LOG_ERROR, TAG_VCW, "@@ vc widget enable asr result : Fail to make message "); + return VC_ERROR_OPERATION_FAILED; + } else { + SLOG(LOG_DEBUG, TAG_VCW, "@@ vc widget enable asr result : pid(%d), enable(%d)", pid, enable); + } + + DBusMessageIter args; + dbus_message_iter_init_append(msg, &args); + + /* Append result*/ + int temp; + if (false == enable) temp = 0; + else temp = 1; + dbus_message_iter_append_basic(&args, DBUS_TYPE_INT32, &(pid)); + dbus_message_iter_append_basic(&args, DBUS_TYPE_INT32, &(temp)); + + DBusError err; + dbus_error_init(&err); + + DBusMessage* result_msg; + int result = VC_ERROR_OPERATION_FAILED; + + result_msg = dbus_connection_send_with_reply_and_block(g_w_conn_sender, msg, g_w_waiting_time, &err); + dbus_message_unref(msg); + + if (dbus_error_is_set(&err)) { + SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Dbus Error (%s)", err.message); + dbus_error_free(&err); + } + + if (NULL != result_msg) { + dbus_message_get_args(result_msg, &err, + DBUS_TYPE_INT32, &result, + DBUS_TYPE_INVALID); + + if (dbus_error_is_set(&err)) { + SLOG(LOG_ERROR, TAG_VCW, "@@ Get arguments error (%s)", err.message); + dbus_error_free(&err); + result = VC_ERROR_OPERATION_FAILED; + } + dbus_message_unref(result_msg); + + if (0 == result) { + SLOG(LOG_DEBUG, TAG_VCW, "@@ vc widget enable asr result : result = %d", result); + } else { + SLOG(LOG_ERROR, TAG_VCW, "@@ vc widget enable asr result : result = %d", result); + } + } else { + SLOG(LOG_DEBUG, TAG_VCW, "@@ Result Message is NULL"); + vc_widget_dbus_reconnect(); + result = VC_ERROR_TIMED_OUT; + } + + return result; +} + +int vc_widget_dbus_request_start(int pid, int silence) +{ + if (0 != __dbus_check()) { + return VC_ERROR_OPERATION_FAILED; + } + + DBusMessage* msg; + + /* create a signal & check for errors */ + msg = dbus_message_new_method_call( + VC_SERVER_SERVICE_NAME, + VC_SERVER_SERVICE_OBJECT_PATH, + VC_SERVER_SERVICE_INTERFACE, + VC_WIDGET_METHOD_START); + + if (NULL == msg) { + SLOG(LOG_ERROR, TAG_VCW, "@@ vc widget start : Fail to make message "); + return VC_ERROR_OPERATION_FAILED; + } else { + SLOG(LOG_DEBUG, TAG_VCW, "@@ vc widget start : pid(%d), silence(%d)", pid, silence); + } + + DBusMessageIter args; + dbus_message_iter_init_append(msg, &args); + + /* Append result*/ + dbus_message_iter_append_basic(&args, DBUS_TYPE_INT32, &(pid)); + dbus_message_iter_append_basic(&args, DBUS_TYPE_INT32, &(silence)); + + DBusError err; + dbus_error_init(&err); + + DBusMessage* result_msg; + int result = VC_ERROR_OPERATION_FAILED; + + result_msg = dbus_connection_send_with_reply_and_block(g_w_conn_sender, msg, g_w_waiting_time, &err); + dbus_message_unref(msg); + + if (dbus_error_is_set(&err)) { + SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Dbus Error (%s)", err.message); + dbus_error_free(&err); + } + + if (NULL != result_msg) { + dbus_message_get_args(result_msg, &err, + DBUS_TYPE_INT32, &result, + DBUS_TYPE_INVALID); + + if (dbus_error_is_set(&err)) { + SLOG(LOG_ERROR, TAG_VCW, "@@ Get arguments error (%s)", err.message); + dbus_error_free(&err); + result = VC_ERROR_OPERATION_FAILED; + } + dbus_message_unref(result_msg); + + if (0 == result) { + SLOG(LOG_DEBUG, TAG_VCW, "@@ vc widget start : result = %d", result); + } else { + SLOG(LOG_ERROR, TAG_VCW, "@@ vc widget start : result = %d", result); + } + } else { + SLOG(LOG_DEBUG, TAG_VCW, "@@ Result Message is NULL"); + vc_widget_dbus_reconnect(); + result = VC_ERROR_TIMED_OUT; + } + + return result; +} + +int vc_widget_dbus_request_stop(int pid) +{ + if (0 != __dbus_check()) { + return VC_ERROR_OPERATION_FAILED; + } + + DBusMessage* msg; + + /* create a signal & check for errors */ + msg = dbus_message_new_method_call( + VC_SERVER_SERVICE_NAME, + VC_SERVER_SERVICE_OBJECT_PATH, + VC_SERVER_SERVICE_INTERFACE, + VC_WIDGET_METHOD_STOP); + + if (NULL == msg) { + SLOG(LOG_ERROR, TAG_VCW, "@@ vc widget stop : Fail to make message "); + return VC_ERROR_OPERATION_FAILED; + } else { + SLOG(LOG_DEBUG, TAG_VCW, "@@ vc widget stop : pid(%d)", pid); + } + + dbus_message_append_args(msg, + DBUS_TYPE_INT32, &pid, + DBUS_TYPE_INVALID); + + DBusError err; + dbus_error_init(&err); + + DBusMessage* result_msg; + int result = VC_ERROR_OPERATION_FAILED; + + result_msg = dbus_connection_send_with_reply_and_block(g_w_conn_sender, msg, g_w_waiting_time, &err); + dbus_message_unref(msg); + + if (dbus_error_is_set(&err)) { + SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Dbus Error (%s)", err.message); + dbus_error_free(&err); + } + + if (NULL != result_msg) { + dbus_message_get_args(result_msg, &err, + DBUS_TYPE_INT32, &result, + DBUS_TYPE_INVALID); + + if (dbus_error_is_set(&err)) { + SLOG(LOG_ERROR, TAG_VCW, "@@ Get arguments error (%s)", err.message); + dbus_error_free(&err); + result = VC_ERROR_OPERATION_FAILED; + } + dbus_message_unref(result_msg); + + if (0 == result) { + SLOG(LOG_DEBUG, TAG_VCW, "@@ vc widget stop : result = %d", result); + } else { + SLOG(LOG_ERROR, TAG_VCW, "@@ vc widget stop : result = %d", result); + } + } else { + SLOG(LOG_DEBUG, TAG_VCW, "@@ Result Message is NULL"); + vc_widget_dbus_reconnect(); + result = VC_ERROR_TIMED_OUT; + } + + return result; +} + +int vc_widget_dbus_request_cancel(int pid) +{ + if (0 != __dbus_check()) { + return VC_ERROR_OPERATION_FAILED; + } + + DBusMessage* msg; + + /* create a signal & check for errors */ + msg = dbus_message_new_method_call( + VC_SERVER_SERVICE_NAME, + VC_SERVER_SERVICE_OBJECT_PATH, /* object name of the signal */ + VC_SERVER_SERVICE_INTERFACE, /* interface name of the signal */ + VC_WIDGET_METHOD_CANCEL); /* name of the signal */ + + if (NULL == msg) { + SLOG(LOG_ERROR, TAG_VCW, "@@ vc widget cancel : Fail to make message "); + return VC_ERROR_OPERATION_FAILED; + } else { + SLOG(LOG_DEBUG, TAG_VCW, "@@ vc widget cancel : pid(%d)", pid); + } + + dbus_message_append_args(msg, + DBUS_TYPE_INT32, &pid, + DBUS_TYPE_INVALID); + + DBusError err; + dbus_error_init(&err); + + DBusMessage* result_msg; + int result = VC_ERROR_OPERATION_FAILED; + + result_msg = dbus_connection_send_with_reply_and_block(g_w_conn_sender, msg, g_w_waiting_time, &err); + dbus_message_unref(msg); + + if (dbus_error_is_set(&err)) { + SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Dbus Error (%s)", err.message); + dbus_error_free(&err); + } + + if (NULL != result_msg) { + dbus_message_get_args(result_msg, &err, + DBUS_TYPE_INT32, &result, + DBUS_TYPE_INVALID); + + if (dbus_error_is_set(&err)) { + SLOG(LOG_ERROR, TAG_VCW, "@@ Get arguments error (%s)", err.message); + dbus_error_free(&err); + result = VC_ERROR_OPERATION_FAILED; + } + dbus_message_unref(result_msg); + + if (0 == result) { + SLOG(LOG_DEBUG, TAG_VCW, "@@ vc widget cancel : result = %d", result); + } else { + SLOG(LOG_ERROR, TAG_VCW, "@@ vc widget cancel : result = %d", result); + } + } else { + SLOG(LOG_DEBUG, TAG_VCW, "@@ Result Message is NULL"); + vc_widget_dbus_reconnect(); + result = VC_ERROR_TIMED_OUT; + } + + return result; +} diff --git a/client/vc_widget_dbus.h b/client/vc_widget_dbus.h new file mode 100644 index 0000000..01fba7a --- /dev/null +++ b/client/vc_widget_dbus.h @@ -0,0 +1,54 @@ +/* +* Copyright (c) 2011-2015 Samsung Electronics Co., Ltd All Rights Reserved +* +* Licensed under the Apache License, Version 2.0 (the License); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an AS IS BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + + +#ifndef __VC_WIDGET_DBUS_H_ +#define __VC_WIDGET_DBUS_H_ + + +#ifdef __cplusplus +extern "C" { +#endif + +int vc_widget_dbus_open_connection(); + +int vc_widget_dbus_close_connection(); + + +int vc_widget_dbus_request_hello(); + +int vc_widget_dbus_request_initialize(int pid, int* service_state, int* daemon_pid); + +int vc_widget_dbus_request_finalize(int pid); + +int vc_widget_dbus_request_start_recording(int pid, bool command); + +int vc_widget_dbus_set_foreground(int pid, bool value); + +int vc_widget_dbus_request_enable_asr_result(int pid, bool enable); + +int vc_widget_dbus_request_start(int pid, int silence); + +int vc_widget_dbus_request_stop(int pid); + +int vc_widget_dbus_request_cancel(int pid); + + +#ifdef __cplusplus +} +#endif + +#endif /* __VC_WIDGET_DBUS_H_ */ diff --git a/client/vc_widget_tidl.c b/client/vc_widget_tidl.c deleted file mode 100644 index 3002bf5..0000000 --- a/client/vc_widget_tidl.c +++ /dev/null @@ -1,621 +0,0 @@ -/* -* Copyright (c) 2022 Samsung Electronics Co., Ltd All Rights Reserved -* -* Licensed under the Apache License, Version 2.0 (the License); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an AS IS BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include -#include - -#include "vc_main.h" -#include "vc_widget_client.h" -#include "vc_widget_tidl.h" -#include "vc_widget_proxy.h" -#include "vc_widget_stub.h" - -typedef struct { - bool connected; - bool connection_requesting; - bool register_callback_invoked; - rpc_port_proxy_vc_widget_h rpc_h; - rpc_port_proxy_vc_widget_notify_cb_h notify_cb_h; -} vc_widget_tidl_info_s; - -typedef struct { - bool connected; - bool register_callback_requesting; -} vcd_widget_tidl_info_s; - -static vc_widget_tidl_info_s* g_proxy_tidl_info = NULL; - -static vcd_widget_tidl_info_s* g_stub_tidl_info = NULL; - -static pthread_mutex_t g_w_tidl_mutex = PTHREAD_MUTEX_INITIALIZER; -static pthread_mutex_t g_w_init_mutex = PTHREAD_MUTEX_INITIALIZER; - -static rpc_port_stub_vcd_widget_callback_s g_widget_callback; - -extern int __vc_widget_cb_error(int reason, int daemon_pid, char* msg); - -extern void __vc_widget_cb_show_tooltip(int pid, bool show); - -extern void __vc_widget_cb_result(); - -extern bool __vc_widget_cb_asr_result(int event, const char* asr_result); - -extern int __vc_widget_cb_service_state(int state); - -static void __notify_cb(void *user_data, bundle *msg) -{ - char* method = NULL; - char* val = NULL; - SLOG(LOG_DEBUG, TAG_VCW, "__notify_cb is invoked"); - - bundle_get_str(msg, VC_WIDGET_BUNDLE_METHOD, &method); - - if (0 == strncmp(VCD_WIDGET_METHOD_HELLO, method, strlen(VCD_WIDGET_METHOD_HELLO))) { - SLOG(LOG_INFO, TAG_VCW, "@@@ Get widget hello"); - bundle_get_str(msg, VC_WIDGET_BUNDLE_MESSAGE, &val); - if (val) { - SLOG(LOG_DEBUG, TAG_VCW, "@@ vc widget get hello : pid(%d) ", atoi(val)); - } else { - SLOG(LOG_ERROR, TAG_VCW, "@@ vc widget get hello : invalid pid "); - } - SLOG(LOG_DEBUG, TAG_VCW, "@@@"); - } /* VCD_METHOD_HELLO */ - - else if (0 == strncmp(VCD_WIDGET_METHOD_SET_SERVICE_STATE, method, strlen(VCD_WIDGET_METHOD_SET_SERVICE_STATE))) { - bundle_get_str(msg, VC_WIDGET_BUNDLE_MESSAGE, &val); - int state = 0; - if (val) { - state = atoi(val); - SLOG(LOG_INFO, TAG_VCW, "@@ service state changed : %d", state); - __vc_widget_cb_service_state(state); - } - } /* VCD_WIDGET_METHOD_SET_SERVICE_STATE */ - - else if (0 == strncmp(VCD_WIDGET_METHOD_SHOW_TOOLTIP, method, strlen(VCD_WIDGET_METHOD_SHOW_TOOLTIP))) { - SLOG(LOG_DEBUG, TAG_VCW, "@@@ Show / Hide tooltip"); - char* temp_show = NULL; - bundle_get_str(msg, VC_WIDGET_BUNDLE_MESSAGE, &val); - bundle_get_str(msg, VC_WIDGET_BUNDLE_SHOW, &temp_show); - int pid = 0; - int show = 0; - - if (val) { - pid = atoi(val); - } - if (temp_show) { - show = atoi(temp_show); - } - - if(pid > 0){ - SLOG(LOG_DEBUG, TAG_VCW, "@@ vc widget show tooltip : pid(%d), show(%d)", pid, show); - __vc_widget_cb_show_tooltip(pid, (bool)show); - } else { - SLOG(LOG_ERROR, TAG_VCW, "@@ vc widget show tooltip : invalid pid"); - } - SLOG(LOG_DEBUG, TAG_VCW, "@@@"); - } /* VCD_WIDGET_METHOD_SHOW_TOOLTIP */ - - else if (0 == strncmp(VCD_WIDGET_METHOD_RESULT, method, strlen(VCD_WIDGET_METHOD_RESULT))) { - SLOG(LOG_DEBUG, TAG_VCW, "@@@ Get widget result"); - - __vc_widget_cb_result(); - - SLOG(LOG_DEBUG, TAG_VCW, "@@@"); - } /* VCD_WIDGET_METHOD_RESULT */ - - else if (0 == strncmp(VCD_WIDGET_METHOD_ERROR, method, strlen(VCD_WIDGET_METHOD_ERROR))) { - SLOG(LOG_INFO, TAG_VCW, "@@@ Get Pre Result"); - char* temp_reason = NULL; - char* temp_daemon_pid = NULL; - char* err_msg = NULL; - - bundle_get_str(msg, VC_WIDGET_BUNDLE_REASON, &temp_reason); - bundle_get_str(msg, VC_WIDGET_BUNDLE_DAEMON_PID, &temp_daemon_pid); - bundle_get_str(msg, VC_WIDGET_BUNDLE_ERROR_MESSAGE, &err_msg); - int reason = 0; - int daemon_pid = 0; - - if (NULL != temp_reason) { - reason = atoi(temp_reason); - } - if (NULL != temp_daemon_pid) { - daemon_pid = atoi(temp_daemon_pid); - } - - SLOG(LOG_DEBUG, TAG_VCW, "@@ vc widget get error message : reason(%d), daemon_pid(%d), msg(%s)", reason, daemon_pid, err_msg); - __vc_widget_cb_error(reason, daemon_pid, err_msg); - - SLOG(LOG_DEBUG, TAG_VCW, "@@@"); - } /* VCD_WIDGET_METHOD_ERROR */ - - else { - SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Invalid msg"); - } -} - -static void __on_connected(rpc_port_proxy_vc_widget_h h, void *user_data) -{ - g_proxy_tidl_info->connected = true; - g_proxy_tidl_info->connection_requesting = false; - g_proxy_tidl_info->register_callback_invoked = false; - - SLOG(LOG_INFO, TAG_VCW, "Connected to server"); -} - -static void __on_disconnected(rpc_port_proxy_vc_widget_h h, void *user_data) -{ - g_proxy_tidl_info->connected = false; - g_proxy_tidl_info->connection_requesting = false; - g_proxy_tidl_info->register_callback_invoked = false; - - SLOG(LOG_INFO, TAG_VCW, "Disonnected to server"); -} - -static void __on_rejected(rpc_port_proxy_vc_widget_h h, void *user_data) -{ - g_proxy_tidl_info->connection_requesting = false; - g_proxy_tidl_info->register_callback_invoked = false; - - SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Rejected from server"); -} - - -static rpc_port_proxy_vc_widget_h __create_rpc_port(const char* engine_app_id) -{ - SLOG(LOG_DEBUG, TAG_VCW, "[TIDL] __create_rpc_port"); - rpc_port_proxy_vc_widget_callback_s rpc_callback = { - .connected = __on_connected, - .disconnected = __on_disconnected, - .rejected = __on_rejected - }; - - rpc_port_proxy_vc_widget_h handle = NULL; - if (0 != rpc_port_proxy_vc_widget_create(engine_app_id, &rpc_callback, NULL, &handle)) { - SLOG(LOG_ERROR, TAG_VCW, "[TIDL ERROR] Fail to create proxy"); - return NULL; - } - - return handle; -} - -static void __vcd_widget_create_cb(rpc_port_stub_vcd_widget_context_h context, void *user_data) -{ - g_stub_tidl_info->connected = true; - g_stub_tidl_info->register_callback_requesting = false; - - SLOG(LOG_DEBUG, TAG_VCW, "Connected to server"); - - char *sender = NULL; - - rpc_port_stub_vcd_widget_context_get_sender(context, &sender); - if (!sender) { - SLOG(LOG_ERROR, TAG_VCW, "@@@ Sender is NULL"); - return; - } - - SLOG(LOG_DEBUG, TAG_VCW, "@@@ Server connect. appid(%s)", sender); - free(sender); -} - -static void __vcd_widget_terminate_cb(rpc_port_stub_vcd_widget_context_h context, void *user_data) -{ - g_stub_tidl_info->connected = false; - g_stub_tidl_info->register_callback_requesting = false; - - rpc_port_stub_vcd_widget_context_set_tag(context, NULL); - - char *sender = NULL; - rpc_port_stub_vcd_widget_context_get_sender(context, &sender); - if (!sender) - return; - - SLOG(LOG_INFO, TAG_VCW, "@@@ Server disconnect. appid(%s)", sender); - free(sender); -} - -static int __vcd_widget_asr_result_cb(rpc_port_stub_vcd_widget_context_h context, int pid, int event, const char *asr_result, bool *is_consumed, void *user_data) -{ - SLOG(LOG_DEBUG, TAG_VCW, "@@@ Get widget asr result"); - - bool result = false; - result = __vc_widget_cb_asr_result(event, asr_result); - *is_consumed = result; - - return VC_ERROR_NONE; -} - -static void __register_stub_callback() -{ - if (g_stub_tidl_info->register_callback_requesting) { - return; - } - - SLOG(LOG_DEBUG, TAG_VCW, "[TIDL] __register_stub_callback"); - - g_widget_callback.create = __vcd_widget_create_cb; - g_widget_callback.terminate = __vcd_widget_terminate_cb; - g_widget_callback.send_asr_result = __vcd_widget_asr_result_cb; - - int ret = -1; - ret = rpc_port_stub_vcd_widget_register(&g_widget_callback, NULL); - if (0 == ret) { - SLOG(LOG_DEBUG, TAG_VCW, "register callback"); - g_stub_tidl_info->register_callback_requesting = true; - return; - } - - SLOG(LOG_ERROR, TAG_VCW, "Fail to rister callback(%d)", ret); - return; -} - -int vc_widget_tidl_open_connection() -{ - SLOG(LOG_DEBUG, TAG_VCW, "[TIDL] vc_widget_tidl_open_connection"); - pthread_mutex_lock(&g_w_tidl_mutex); - - if (NULL != g_proxy_tidl_info) { - SLOG(LOG_ERROR, TAG_VCW, "[TIDL ERROR] g_proxy_tidl_info already created"); - pthread_mutex_unlock(&g_w_tidl_mutex); - return VC_ERROR_NONE; - } - - g_proxy_tidl_info = (vc_widget_tidl_info_s*)calloc(1, sizeof(vc_widget_tidl_info_s)); - - if (NULL == g_proxy_tidl_info) { - SLOG(LOG_ERROR, TAG_VCW, "[TIDL ERROR] Fail to create vc_widget_tidl_info_s"); - pthread_mutex_unlock(&g_w_tidl_mutex); - return VC_ERROR_OUT_OF_MEMORY; - } - - char* engine_app_id = vconf_get_str(VC_ENGINE_DB_DEFAULT); - if (NULL == engine_app_id) { - SLOG(LOG_ERROR, TAG_VCW, "[TIDL] vconf not found"); - free(g_proxy_tidl_info); - g_proxy_tidl_info = NULL; - pthread_mutex_unlock(&g_w_tidl_mutex); - return VC_ERROR_ENGINE_NOT_FOUND; - } - - g_proxy_tidl_info->rpc_h = __create_rpc_port(engine_app_id); - if (NULL == g_proxy_tidl_info->rpc_h) { - SLOG(LOG_ERROR, TAG_VCW, "[TIDL ERROR] Fail to create proxy"); - free(engine_app_id); - free(g_proxy_tidl_info); - g_proxy_tidl_info = NULL; - pthread_mutex_unlock(&g_w_tidl_mutex); - return VC_ERROR_OPERATION_FAILED; - } - - SLOG(LOG_INFO, TAG_VCW, "[TIDL] rpc_h(%p), engine_app_id(%s)", g_proxy_tidl_info->rpc_h, engine_app_id); - free(engine_app_id); - - g_stub_tidl_info = (vcd_widget_tidl_info_s*)calloc(1, sizeof(vcd_widget_tidl_info_s)); - - if (NULL == g_stub_tidl_info) { - SLOG(LOG_ERROR, TAG_VCW, "[TIDL ERROR] Fail to create vcd_widget_tidl_info_s"); - pthread_mutex_unlock(&g_w_tidl_mutex); - return VC_ERROR_OUT_OF_MEMORY; - } - - __register_stub_callback(); - - pthread_mutex_unlock(&g_w_tidl_mutex); - - return VC_ERROR_NONE; -} - -int vc_widget_tidl_close_connection() -{ - SLOG(LOG_DEBUG, TAG_VCW, "[TIDL] vc_widget_tidl_close_connection"); - pthread_mutex_lock(&g_w_tidl_mutex); - - if (NULL == g_proxy_tidl_info) { - SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to get tidl info"); - pthread_mutex_unlock(&g_w_tidl_mutex); - return VC_ERROR_OPERATION_FAILED; - } - - if (0 != rpc_port_proxy_vc_widget_destroy(g_proxy_tidl_info->rpc_h)) { - SLOG(LOG_ERROR, TAG_VCW, "[TIDL ERROR] Fail to destroy tidl handle"); - pthread_mutex_unlock(&g_w_tidl_mutex); - return VC_ERROR_OPERATION_FAILED; - } - - g_proxy_tidl_info->rpc_h = NULL; - g_proxy_tidl_info->notify_cb_h = NULL; - - free(g_proxy_tidl_info); - g_proxy_tidl_info = NULL; - - free(g_stub_tidl_info); - g_stub_tidl_info = NULL; - - pthread_mutex_unlock(&g_w_tidl_mutex); - - return VC_ERROR_NONE; -} - -static void __request_tidl_connect() -{ - if (g_proxy_tidl_info->connection_requesting) { - return; - } - - int ret = rpc_port_proxy_vc_widget_connect(g_proxy_tidl_info->rpc_h); - SLOG(LOG_INFO, TAG_VCW, "[INFO] Request connection to stub. ret(%d)", ret); - - if (0 == ret) { - g_proxy_tidl_info->connection_requesting = true; - } -} - -static int __create_callback_handles() -{ - if (NULL != g_proxy_tidl_info->notify_cb_h) { - rpc_port_proxy_vc_widget_notify_cb_dispose(g_proxy_tidl_info->rpc_h, g_proxy_tidl_info->notify_cb_h); - g_proxy_tidl_info->notify_cb_h = NULL; - } - - if (RPC_PORT_ERROR_NONE != rpc_port_proxy_vc_widget_notify_cb_create(&g_proxy_tidl_info->notify_cb_h)) { - return VC_ERROR_OUT_OF_MEMORY; - } - - rpc_port_proxy_vc_widget_notify_cb_set_callback(g_proxy_tidl_info->notify_cb_h, __notify_cb, NULL); - - rpc_port_proxy_vc_widget_notify_cb_set_once(g_proxy_tidl_info->notify_cb_h, false); - - return VC_ERROR_NONE; -} - -static int __invoke_register_callback() -{ - if (g_proxy_tidl_info->register_callback_invoked) { - SLOG(LOG_ERROR, TAG_VCW, "[INFO] Already register callback is invoked"); - return VC_ERROR_NONE; - } - - int ret = __create_callback_handles(g_proxy_tidl_info); - if (VC_ERROR_NONE != ret) { - SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to create callback handle. ret(%d)", ret); - return VC_ERROR_OPERATION_FAILED; - } - - rpc_port_proxy_vc_widget_invoke_register_cb(g_proxy_tidl_info->rpc_h, getpid(), g_proxy_tidl_info->notify_cb_h); - g_proxy_tidl_info->register_callback_invoked = true; - return VC_ERROR_NONE; -} - -int vc_widget_tidl_request_hello() -{ - SLOG(LOG_DEBUG, TAG_VCW, "[TIDL] vc_widget_tidl_request_hello"); - - if (NULL == g_proxy_tidl_info) { - SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to get proxy tidl info"); - return VC_ERROR_OPERATION_FAILED; - } - - if (!g_proxy_tidl_info->connected) { - SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Proxy Not Connected"); - __request_tidl_connect(); - return VC_ERROR_OPERATION_FAILED; - } - - if (VC_ERROR_NONE != __invoke_register_callback()) { - SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to invoke register callback"); - return VC_ERROR_OPERATION_FAILED; - } - - if (NULL == g_stub_tidl_info) { - SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to get stub tidl info"); - return VC_ERROR_OPERATION_FAILED; - } - - if (!g_stub_tidl_info->connected) { - SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Stub Not Connected"); - __register_stub_callback(); - return VC_ERROR_OPERATION_FAILED; - } - - SLOG(LOG_DEBUG, TAG_VCW, ">>>>> VCW Hello"); - - SLOG(LOG_DEBUG, TAG_VCW, "<<<<"); - - return VC_ERROR_NONE; -} - -int vc_widget_tidl_request_initialize(int pid, int* service_state, int* daemon_pid) -{ - pthread_mutex_lock(&g_w_init_mutex); - SLOG(LOG_DEBUG, TAG_VCW, "[TIDL] vc_widget_tidl_request_initialize"); - - if (NULL == g_proxy_tidl_info) { - SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to get tidl info"); - pthread_mutex_unlock(&g_w_init_mutex); - return VC_ERROR_OPERATION_FAILED; - } - - int temp_service_state = 0; - int temp_daemon_pid = 0; - if (0 != rpc_port_proxy_vc_widget_invoke_initialize(g_proxy_tidl_info->rpc_h, pid, &temp_service_state, &temp_daemon_pid)) { - SLOG(LOG_ERROR, TAG_VCW, "[TIDL ERROR] Request vc widget initialize : Fail to invoke message"); - pthread_mutex_unlock(&g_w_init_mutex); - return VC_ERROR_OPERATION_FAILED; - } - - *service_state = temp_service_state; - *daemon_pid = temp_daemon_pid; - - pthread_mutex_unlock(&g_w_init_mutex); - SLOG(LOG_DEBUG, TAG_VCW, "[TIDL] vc widget initialize: service_state(%d), daemon_pid(%d)", *service_state, *daemon_pid); - - return VC_ERROR_NONE; -} - -int vc_widget_tidl_request_finalize(int pid) -{ - pthread_mutex_lock(&g_w_init_mutex); - SLOG(LOG_DEBUG, TAG_VCW, "[TIDL] vc_widget_tidl_request_finalize"); - - if (NULL == g_proxy_tidl_info) { - SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to get tidl info"); - pthread_mutex_unlock(&g_w_init_mutex); - return VC_ERROR_OPERATION_FAILED; - } - - if (!g_proxy_tidl_info->connected) { - SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Not Connected"); - pthread_mutex_unlock(&g_w_init_mutex); - return VC_ERROR_OPERATION_FAILED; - } - - if (0 != rpc_port_proxy_vc_widget_invoke_finalize(g_proxy_tidl_info->rpc_h, pid)) { - SLOG(LOG_ERROR, TAG_VCW, "[TIDL ERROR] Request vc widget finalize : Fail to invoke message"); - pthread_mutex_unlock(&g_w_init_mutex); - return VC_ERROR_OPERATION_FAILED; - } - - pthread_mutex_unlock(&g_w_init_mutex); - return VC_ERROR_NONE; -} - -int vc_widget_tidl_request_start_recording(int pid, bool command) -{ - SLOG(LOG_DEBUG, TAG_VCW, "[TIDL] vc_widget_tidl_request_start_recording"); - - if (NULL == g_proxy_tidl_info) { - SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to get tidl info"); - return VC_ERROR_OPERATION_FAILED; - } - - if (!g_proxy_tidl_info->connected) { - SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Not Connected"); - return VC_ERROR_OPERATION_FAILED; - } - - if (0 != rpc_port_proxy_vc_widget_invoke_start_recording(g_proxy_tidl_info->rpc_h, pid, (int)command)) { - SLOG(LOG_ERROR, TAG_VCW, "[TIDL ERROR] Request vc widget start recording : Fail to invoke message"); - return VC_ERROR_OPERATION_FAILED; - } - - return VC_ERROR_NONE; -} - -int vc_widget_tidl_set_foreground(int pid, bool value) -{ - SLOG(LOG_DEBUG, TAG_VCW, "[TIDL] vc_widget_tidl_set_foreground"); - - if (NULL == g_proxy_tidl_info) { - SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to get tidl info"); - return VC_ERROR_OPERATION_FAILED; - } - - if (!g_proxy_tidl_info->connected) { - SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Not Connected"); - return VC_ERROR_OPERATION_FAILED; - } - - rpc_port_proxy_vc_widget_invoke_set_foreground(g_proxy_tidl_info->rpc_h, pid, (int)value); - - return VC_ERROR_NONE; -} - -int vc_widget_tidl_request_enable_asr_result(int pid, bool enable) -{ - SLOG(LOG_DEBUG, TAG_VCW, "[TIDL] vc_widget_tidl_request_enable_asr_result"); - - if (NULL == g_proxy_tidl_info) { - SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to get tidl info"); - return VC_ERROR_OPERATION_FAILED; - } - - if (!g_proxy_tidl_info->connected) { - SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Not Connected"); - return VC_ERROR_OPERATION_FAILED; - } - - if (0 != rpc_port_proxy_vc_widget_invoke_enable_asr_result(g_proxy_tidl_info->rpc_h, pid, (int)enable)) { - SLOG(LOG_ERROR, TAG_VCW, "[TIDL ERROR] Request vc widget enable asr result : Fail to invoke message"); - return VC_ERROR_OPERATION_FAILED; - } - - return VC_ERROR_NONE; -} - -int vc_widget_tidl_request_start(int pid, int silence) -{ - SLOG(LOG_DEBUG, TAG_VCW, "[TIDL] vc_widget_tidl_request_start"); - - if (NULL == g_proxy_tidl_info) { - SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to get tidl info"); - return VC_ERROR_OPERATION_FAILED; - } - - if (!g_proxy_tidl_info->connected) { - SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Not Connected"); - return VC_ERROR_OPERATION_FAILED; - } - - if (0 != rpc_port_proxy_vc_widget_invoke_start(g_proxy_tidl_info->rpc_h, pid, silence)) { - SLOG(LOG_ERROR, TAG_VCW, "[TIDL ERROR] Request vc widget start : Fail to invoke message"); - return VC_ERROR_OPERATION_FAILED; - } - - return VC_ERROR_NONE; -} - -int vc_widget_tidl_request_stop(int pid) -{ - SLOG(LOG_DEBUG, TAG_VCW, "[TIDL] vc_widget_tidl_request_stop"); - - if (NULL == g_proxy_tidl_info) { - SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to get tidl info"); - return VC_ERROR_OPERATION_FAILED; - } - - if (!g_proxy_tidl_info->connected) { - SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Not Connected"); - return VC_ERROR_OPERATION_FAILED; - } - - if (0 != rpc_port_proxy_vc_widget_invoke_stop(g_proxy_tidl_info->rpc_h, pid)) { - SLOG(LOG_ERROR, TAG_VCW, "[TIDL ERROR] Request vc widget stop : Fail to invoke message"); - return VC_ERROR_OPERATION_FAILED; - } - - return VC_ERROR_NONE; -} - -int vc_widget_tidl_request_cancel(int pid) -{ - SLOG(LOG_DEBUG, TAG_VCW, "[TIDL] vc_widget_tidl_request_cancel"); - - if (NULL == g_proxy_tidl_info) { - SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to get tidl info"); - return VC_ERROR_OPERATION_FAILED; - } - - if (!g_proxy_tidl_info->connected) { - SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Not Connected"); - return VC_ERROR_OPERATION_FAILED; - } - - if (0 != rpc_port_proxy_vc_widget_invoke_cancel(g_proxy_tidl_info->rpc_h, pid)) { - SLOG(LOG_ERROR, TAG_VCW, "[TIDL ERROR] Request vc widget cancel : Fail to invoke message"); - return VC_ERROR_OPERATION_FAILED; - } - - return VC_ERROR_NONE; -} diff --git a/client/vc_widget_tidl.h b/client/vc_widget_tidl.h deleted file mode 100644 index 7b00320..0000000 --- a/client/vc_widget_tidl.h +++ /dev/null @@ -1,54 +0,0 @@ -/* -* Copyright (c) 2022 Samsung Electronics Co., Ltd All Rights Reserved -* -* Licensed under the Apache License, Version 2.0 (the License); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an AS IS BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - - -#ifndef __VC_WIDGET_TIDL_H_ -#define __VC_WIDGET_TIDL_H_ - - -#ifdef __cplusplus -extern "C" { -#endif - -int vc_widget_tidl_open_connection(); - -int vc_widget_tidl_close_connection(); - - -int vc_widget_tidl_request_hello(); - -int vc_widget_tidl_request_initialize(int pid, int* service_state, int* daemon_pid); - -int vc_widget_tidl_request_finalize(int pid); - -int vc_widget_tidl_request_start_recording(int pid, bool command); - -int vc_widget_tidl_set_foreground(int pid, bool value); - -int vc_widget_tidl_request_enable_asr_result(int pid, bool enable); - -int vc_widget_tidl_request_start(int pid, int silence); - -int vc_widget_tidl_request_stop(int pid); - -int vc_widget_tidl_request_cancel(int pid); - - -#ifdef __cplusplus -} -#endif - -#endif /* __VC_WIDGET_TIDL_H_ */ \ No newline at end of file diff --git a/common/vc_defs.h b/common/vc_defs.h index 3ba15c5..0f906d6 100644 --- a/common/vc_defs.h +++ b/common/vc_defs.h @@ -130,14 +130,6 @@ extern "C" { #define VCD_WIDGET_METHOD_SHOW_TOOLTIP "vcd_widget_method_show_tooltip" #define VCD_WIDGET_METHOD_SET_SERVICE_STATE "vcd_widget_method_set_service_state" -#define VC_WIDGET_BUNDLE_METHOD "vc_widget_bundle_method" -#define VC_WIDGET_BUNDLE_MESSAGE "vc_widget_bundle_message" -#define VC_WIDGET_BUNDLE_SERVICE_STATE "vc_widget_bundle_service_state" -#define VC_WIDGET_BUNDLE_DAEMON_PID "vc_widget_bundle_daemon_pid" -#define VC_WIDGET_BUNDLE_SHOW "vc_widget_bundle_show" -#define VC_WIDGET_BUNDLE_REASON "vc_widget_bundle_reason" -#define VC_WIDGET_BUNDLE_ERROR_MESSAGE "vc_widget_bundle_error_message" - /****************************************************************************************** * Message Definitions for manager diff --git a/packaging/voice-control.spec b/packaging/voice-control.spec index 63b9aa4..d776104 100644 --- a/packaging/voice-control.spec +++ b/packaging/voice-control.spec @@ -119,11 +119,6 @@ tidlc -s -l C -i tidl/vc_mgr.tidl -o vcd_mgr_stub tidlc -s -l C -i tidl/vcd_mgr.tidl -o vc_mgr_stub tidlc -p -l C -i tidl/vcd_mgr.tidl -o vcd_mgr_proxy -tidlc -p -l C -i tidl/vc_widget.tidl -o vc_widget_proxy -tidlc -s -l C -i tidl/vc_widget.tidl -o vcd_widget_stub -tidlc -s -l C -i tidl/vcd_widget.tidl -o vc_widget_stub -tidlc -p -l C -i tidl/vcd_widget.tidl -o vcd_widget_proxy - mv vc_* client mv vcd_* server diff --git a/server/CMakeLists.txt b/server/CMakeLists.txt index 5fe0268..c557c71 100644 --- a/server/CMakeLists.txt +++ b/server/CMakeLists.txt @@ -14,8 +14,6 @@ SET(SRCS vcd_tidl.c vcd_mgr_stub.c vcd_mgr_proxy.c - vcd_widget_stub.c - vcd_widget_proxy.c vcd_engine_agent.c # vcd_main.c vcd_recorder.c diff --git a/server/vcd_client_data.c b/server/vcd_client_data.c index f9bdec8..ddb298b 100644 --- a/server/vcd_client_data.c +++ b/server/vcd_client_data.c @@ -34,9 +34,6 @@ static manager_info_s g_manager; /* Manager IPC info */ static manager_tidl_info_s* g_mgr_tidl_info = NULL; -/* Widget IPC info */ -static GSList* g_widget_tidl_info_list = NULL; - /* Command list */ static current_commands_list_s g_cur_cmd_list; @@ -259,7 +256,7 @@ char* vcd_client_manager_get_result_text() return g_result_text; } -int vcd_client_manager_create_tidl_info(int pid) +int vcd_client_manger_create_tidl_info(int pid) { /*Check already created*/ if (NULL != g_mgr_tidl_info) { @@ -1667,184 +1664,6 @@ int vcd_client_widget_get_waiting_for_recording(int pid, bool* waiting) return 0; } -GSList* __get_widget_tidl_info_item(const int pid) -{ - GSList *iter = NULL; - widget_tidl_info_s *data = NULL; - - int count = g_slist_length(g_widget_tidl_info_list); - int i; - - if (0 < count) { - iter = g_slist_nth(g_widget_tidl_info_list, 0); - for (i = 0; i < count; i++) { - if (NULL == iter) - break; - - data = iter->data; - if (NULL != data) { - if (pid == data->pid) - return iter; - } - - iter = g_slist_next(iter); - } - } - - return NULL; -} - -widget_tidl_info_s* __get_widget_tidl_info_element(int pid) -{ - GSList *iter = NULL; - widget_tidl_info_s *data = NULL; - - int count = g_slist_length(g_widget_tidl_info_list); - int i; - - if (0 < count) { - iter = g_slist_nth(g_widget_tidl_info_list, 0); - for (i = 0; i < count; i++) { - if (NULL == iter) - break; - - data = iter->data; - - if (NULL != data) { - if (pid == data->pid) - return data; - } - - iter = g_slist_next(iter); - } - } - - return NULL; -} - -int vcd_client_widget_add_tidl_info(int pid) -{ - /*Check pid is duplicated*/ - widget_tidl_info_s* info = NULL; - info = __get_widget_tidl_info_element(pid); - - if (NULL != info) { - SLOG(LOG_WARN, TAG_VCD, "[Client Data] Widget tidl info pid is already registered"); - return VCD_ERROR_NONE; - } - - SLOG(LOG_INFO, TAG_VCD, "[Client Data] There is no tidl info of pid(%d). Create new one.", pid); - info = (widget_tidl_info_s*)calloc(1, sizeof(widget_tidl_info_s)); - if (NULL == info) { - SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to allocate memory"); - return VCD_ERROR_OUT_OF_MEMORY; - } - - info->pid = pid; - info->notify_cb = NULL; - info->notify_cb_user_data = NULL; - - info->connected = false; - info->connection_requesting = false; - info->rpc_h = NULL; - - g_widget_tidl_info_list = g_slist_append(g_widget_tidl_info_list, info); - if (NULL == g_widget_tidl_info_list) { - SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] Fail to add new widget tidl info"); - - free(info); - info = NULL; - - return -1; - } else { - SLOG(LOG_INFO, TAG_VCD, "[Client Data SUCCESS] Add new widget tidl info. pid(%d)", pid); - } - - return VCD_ERROR_NONE; -} - -int vcd_client_widget_set_tidl_notify_cb(int pid, rpc_port_stub_vc_widget_notify_cb_h callback, void* user_data) -{ - /*Check pid*/ - widget_tidl_info_s* info = NULL; - info = __get_widget_tidl_info_element(pid); - - if (NULL == info) { - SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] There is no tidl info in the list. pid(%d)", pid); - return VCD_ERROR_INVALID_PARAMETER; - } - - int ret = -1; - ret = rpc_port_stub_vc_widget_notify_cb_clone(callback, &(info->notify_cb)); - if (0 != ret) { - SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] Fail to clone notify callback. ret(%d)", ret); - } else { - SLOG(LOG_INFO, TAG_VCD, "[Client Data] Succeed to clone notify callback. ret(%d)", ret); - } - info->notify_cb_user_data = user_data; - - return VCD_ERROR_NONE; -} - -int vcd_client_widget_unset_tidl_notify_cb(int pid) -{ - /*Check pid*/ - widget_tidl_info_s* info = NULL; - info = __get_widget_tidl_info_element(pid); - - if (NULL == info) { - SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] There is no tidl info in the list. pid(%d)", pid); - return VCD_ERROR_INVALID_PARAMETER; - } - - int ret = -1; - ret = rpc_port_stub_vc_widget_notify_cb_destroy(info->notify_cb); - if (0 != ret) { - SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] Fail to destroy notify callback. ret(%d)", ret); - } else { - SLOG(LOG_INFO, TAG_VCD, "[Client Data] Succeed to destroy notify callback. ret(%d)", ret); - } - info->notify_cb = NULL; - info->notify_cb_user_data = NULL; - - return VCD_ERROR_NONE; -} - -int vcd_client_widget_delete_tidl_info(int pid) -{ - GSList *tmp = NULL; - widget_tidl_info_s* widget_tidl_info = NULL; - - /*Get handle*/ - tmp = __get_widget_tidl_info_item(pid); - if (NULL == tmp) { - SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] pid(%d) is NOT valid", pid); - return VCD_ERROR_INVALID_PARAMETER; - } - - /*Free widget structure*/ - widget_tidl_info = tmp->data; - if (NULL != widget_tidl_info) { - free(widget_tidl_info); - } - - /*Remove handle from list*/ - g_widget_tidl_info_list = g_slist_remove_link(g_widget_tidl_info_list, tmp); - - return 0; -} - -widget_tidl_info_s* vcd_client_widget_get_tidl_info(int pid) -{ - return __get_widget_tidl_info_element(pid); -} - -GSList* vcd_client_widget_get_tidl_info_list() -{ - return g_widget_tidl_info_list; -} - - void vcd_client_update_foreground_pid() { int tmp_pid = VC_RUNTIME_INFO_NO_FOREGROUND; diff --git a/server/vcd_client_data.h b/server/vcd_client_data.h index 317e1d5..260c984 100644 --- a/server/vcd_client_data.h +++ b/server/vcd_client_data.h @@ -23,8 +23,6 @@ #include "vc_info_parser.h" #include "vcd_mgr_stub.h" #include "vcd_mgr_proxy.h" -#include "vcd_widget_stub.h" -#include "vcd_widget_proxy.h" #ifdef __cplusplus extern "C" { @@ -83,18 +81,6 @@ typedef struct { rpc_port_proxy_vcd_mgr_h rpc_h; } manager_tidl_info_s; -typedef struct { - int pid; - - rpc_port_stub_vc_widget_notify_cb_h notify_cb; - void* notify_cb_user_data; - - bool connected; - bool connection_requesting; - - rpc_port_proxy_vcd_widget_h rpc_h; -} widget_tidl_info_s; - typedef enum { VCD_RECOGNITION_MODE_STOP_BY_SILENCE, /**< Default mode */ VCD_RECOGNITION_MODE_RESTART_AFTER_REJECT, /**< Restart recognition after rejected result */ @@ -161,7 +147,7 @@ char* vcd_client_manager_get_result_text(); bool vcd_client_manager_is_system_command_valid(int pid); -int vcd_client_manager_create_tidl_info(int pid); +int vcd_client_manger_create_tidl_info(int pid); int vcd_client_manager_set_tidl_notify_cb(rpc_port_stub_vc_mgr_notify_cb_h callback, void* user_data); @@ -229,17 +215,6 @@ int vcd_client_widget_set_waiting_for_recording(int pid, bool waiting); int vcd_client_widget_get_waiting_for_recording(int pid, bool* waiting); -int vcd_client_widget_add_tidl_info(int pid); - -int vcd_client_widget_set_tidl_notify_cb(int pid, rpc_port_stub_vc_widget_notify_cb_h callback, void* user_data); - -int vcd_client_widget_unset_tidl_notify_cb(int pid); - -int vcd_client_widget_delete_tidl_info(int pid); - -widget_tidl_info_s* vcd_client_widget_get_tidl_info(int pid); - -GSList* vcd_client_widget_get_tidl_info_list(); #ifdef __cplusplus } diff --git a/server/vcd_dbus.c b/server/vcd_dbus.c index 54bf596..b37e486 100755 --- a/server/vcd_dbus.c +++ b/server/vcd_dbus.c @@ -119,9 +119,7 @@ int vcdc_send_hello(int pid, vcd_client_type_e type) if (VCD_CLIENT_TYPE_NORMAL == type) { msg = __get_message(pid, VCD_METHOD_HELLO, VCD_CLIENT_TYPE_NORMAL); } else if (VCD_CLIENT_TYPE_WIDGET == type) { - // msg = __get_message(pid, VCD_WIDGET_METHOD_HELLO, VCD_CLIENT_TYPE_WIDGET); - vcdc_tidl_send_hello(pid, type); - return VCD_ERROR_NONE; + msg = __get_message(pid, VCD_WIDGET_METHOD_HELLO, VCD_CLIENT_TYPE_WIDGET); } else if (VCD_CLIENT_TYPE_MANAGER == type) { vcdc_tidl_send_hello(pid, type); return VCD_ERROR_NONE; @@ -175,6 +173,63 @@ int vcdc_send_hello(int pid, vcd_client_type_e type) return result; } +int vcdc_send_show_tooltip(int pid, bool show) +{ + if (0 != __dbus_check()) { + return VCD_ERROR_OPERATION_FAILED; + } + + if (0 > pid) { + SLOG(LOG_ERROR, TAG_VCD, "[Dbus ERROR] widget pid is NOT valid"); + return -1; + } + + char service_name[64] = {0, }; + memset(service_name, 0, 64); + snprintf(service_name, 64, "%s%d", VC_WIDGET_SERVICE_NAME, pid); + + char target_if_name[128] = {0, }; + snprintf(target_if_name, sizeof(target_if_name), "%s", VC_WIDGET_SERVICE_INTERFACE); + + DBusMessage* msg; + + SLOG(LOG_INFO, TAG_VCD, "[Dbus] send widget show tooltip signal : pid(%d) show(%d)", pid, show); + + msg = dbus_message_new_method_call( + service_name, + VC_WIDGET_SERVICE_OBJECT_PATH, + target_if_name, + VCD_WIDGET_METHOD_SHOW_TOOLTIP); + + if (NULL == msg) { + SLOG(LOG_ERROR, TAG_VCD, "[Dbus ERROR] Fail to create message"); + return VCD_ERROR_OUT_OF_MEMORY; + } + + int temp = (int)show; + + DBusMessageIter args; + dbus_message_iter_init_append(msg, &args); + + /* Append pid & type */ + dbus_message_iter_append_basic(&args, DBUS_TYPE_INT32, &pid); + dbus_message_iter_append_basic(&args, DBUS_TYPE_INT32, &(temp)); + + dbus_message_set_no_reply(msg, TRUE); + + if (1 != dbus_connection_send(g_conn_sender, msg, NULL)) { + SLOG(LOG_ERROR, TAG_VCD, "[Dbus ERROR] Fail to Send"); + return VCD_ERROR_OPERATION_FAILED; + } else { + SLOG(LOG_INFO, TAG_VCD, "[Dbus] SUCCESS Send"); + dbus_connection_flush(g_conn_sender); + } + + dbus_message_unref(msg); + + return 0; +} + int vcdc_send_result(int pid, int manager_pid, int cmd_type) { if (0 != __dbus_check()) { @@ -190,23 +245,21 @@ int vcdc_send_result(int pid, int manager_pid, int cmd_type) case VC_COMMAND_TYPE_BACKGROUND: if (pid == manager_pid) { // msg = __get_message(pid, VCD_MANAGER_METHOD_RESULT, VCD_CLIENT_TYPE_MANAGER); - vcdc_tidl_send_result(pid, manager_pid, VCD_CLIENT_TYPE_MANAGER); + vcdc_tidl_send_result(pid, manager_pid, cmd_type); return 0; } else { msg = __get_message(pid, VCD_METHOD_RESULT, VCD_CLIENT_TYPE_NORMAL); } break; case VC_COMMAND_TYPE_WIDGET: - // msg = __get_message(pid, VCD_WIDGET_METHOD_RESULT, VCD_CLIENT_TYPE_WIDGET); - // break; - vcdc_tidl_send_result(pid, manager_pid, VCD_CLIENT_TYPE_WIDGET); - return 0; + msg = __get_message(pid, VCD_WIDGET_METHOD_RESULT, VCD_CLIENT_TYPE_WIDGET); + break; case VC_COMMAND_TYPE_SYSTEM: case VC_COMMAND_TYPE_SYSTEM_BACKGROUND: case VC_COMMAND_TYPE_EXCLUSIVE: // msg = __get_message(pid, VCD_MANAGER_METHOD_RESULT, VCD_CLIENT_TYPE_MANAGER); // break; - vcdc_tidl_send_result(pid, manager_pid, VCD_CLIENT_TYPE_MANAGER); + vcdc_tidl_send_result(pid, manager_pid, cmd_type); return 0; default: @@ -234,6 +287,67 @@ int vcdc_send_result(int pid, int manager_pid, int cmd_type) return 0; } +int vcdc_send_asr_result(int pid, int event, const char* asr_result, int cmd_type, bool* is_consumed) +{ + if (0 != __dbus_check()) { + return VCD_ERROR_OPERATION_FAILED; + } + + DBusMessage* msg = NULL; + + SLOG(LOG_INFO, TAG_VCD, "[Dbus] Result command type(%d)", cmd_type); + + switch (cmd_type) { + case VC_COMMAND_TYPE_WIDGET: + msg = __get_message(pid, VCD_WIDGET_METHOD_ASR_RESULT, VCD_CLIENT_TYPE_WIDGET); + break; + default: + SLOG(LOG_ERROR, TAG_VCD, "[Dbus ERROR] Command type is NOT valid(%d)", cmd_type); + return VCD_ERROR_INVALID_PARAMETER; + } + + if (NULL == msg) { + SLOG(LOG_ERROR, TAG_VCD, "[Dbus ERROR] Message is NULL"); + return VCD_ERROR_OUT_OF_MEMORY; + } + + dbus_message_append_args(msg, DBUS_TYPE_INT32, &event, DBUS_TYPE_STRING, &asr_result, DBUS_TYPE_INVALID); + + DBusError err; + dbus_error_init(&err); + + DBusMessage* result_msg; + + int result = 0; + result_msg = dbus_connection_send_with_reply_and_block(g_conn_sender, msg, 5000, &err); + dbus_message_unref(msg); + + if (dbus_error_is_set(&err)) { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Dbus Error (%s)", err.message); + dbus_error_free(&err); + } + + if (NULL != result_msg) { + dbus_message_get_args(result_msg, &err, + DBUS_TYPE_INT32, &result, + DBUS_TYPE_INVALID); + + if (dbus_error_is_set(&err)) { + SLOG(LOG_ERROR, TAG_VCD, "@@ Get arguments error (%s)", err.message); + dbus_error_free(&err); + result = VCD_ERROR_OPERATION_FAILED; + } + + dbus_message_unref(result_msg); + SLOG(LOG_INFO, TAG_VCD, "@@ vc send asr result : result = %d", result); + *is_consumed = result; + return VCD_ERROR_NONE; + } else { + SLOG(LOG_ERROR, TAG_VCD, "@@ Result message is NULL "); + return VCD_ERROR_OPERATION_FAILED; + } +} + int vcdc_send_manager_pid(int manager_pid) { DBusError err; @@ -368,7 +482,6 @@ int vcdc_send_error_signal(int reason, char *err_msg) // msg = NULL; vcdc_tidl_send_error(reason, err_msg); - msg = dbus_message_new_signal( VC_CLIENT_SERVICE_OBJECT_PATH, VC_CLIENT_SERVICE_INTERFACE, @@ -391,28 +504,28 @@ int vcdc_send_error_signal(int reason, char *err_msg) dbus_message_unref(msg); - // msg = NULL; - // msg = dbus_message_new_signal( - // VC_WIDGET_SERVICE_OBJECT_PATH, - // VC_WIDGET_SERVICE_INTERFACE, - // VCD_WIDGET_METHOD_ERROR); + msg = NULL; + msg = dbus_message_new_signal( + VC_WIDGET_SERVICE_OBJECT_PATH, + VC_WIDGET_SERVICE_INTERFACE, + VCD_WIDGET_METHOD_ERROR); - // if (NULL == msg) { - // SLOG(LOG_ERROR, TAG_VCD, "[Dbus ERROR] Message is NULL"); - // return VCD_ERROR_OUT_OF_MEMORY; - // } + if (NULL == msg) { + SLOG(LOG_ERROR, TAG_VCD, "[Dbus ERROR] Message is NULL"); + return VCD_ERROR_OUT_OF_MEMORY; + } - // dbus_message_append_args(msg, DBUS_TYPE_INT32, &reason, DBUS_TYPE_INT32, &daemon_pid, DBUS_TYPE_STRING, &err_msg, DBUS_TYPE_INVALID); + dbus_message_append_args(msg, DBUS_TYPE_INT32, &reason, DBUS_TYPE_INT32, &daemon_pid, DBUS_TYPE_STRING, &err_msg, DBUS_TYPE_INVALID); - // if (1 != dbus_connection_send(g_conn_sender, msg, NULL)) { - // SLOG(LOG_ERROR, TAG_VCD, "[Dbus ERROR] Fail to Send"); - // return VCD_ERROR_OPERATION_FAILED; - // } else { - // SLOG(LOG_INFO, TAG_VCD, "@@ Send error signal to widget : reason(%d), daemon_pid(%d), Error Msg(%s)", reason, daemon_pid, err_msg); - // dbus_connection_flush(g_conn_sender); - // } + if (1 != dbus_connection_send(g_conn_sender, msg, NULL)) { + SLOG(LOG_ERROR, TAG_VCD, "[Dbus ERROR] Fail to Send"); + return VCD_ERROR_OPERATION_FAILED; + } else { + SLOG(LOG_INFO, TAG_VCD, "@@ Send error signal to widget : reason(%d), daemon_pid(%d), Error Msg(%s)", reason, daemon_pid, err_msg); + dbus_connection_flush(g_conn_sender); + } - // dbus_message_unref(msg); + dbus_message_unref(msg); return 0; } @@ -558,6 +671,27 @@ static Eina_Bool listener_event_callback(void* data, Ecore_Fd_Handler *fd_handle else if (dbus_message_is_method_call(msg, VC_SERVER_SERVICE_INTERFACE, VC_METHOD_REQUEST_CANCEL)) vcd_dbus_server_cancel_request(g_conn_listener, msg); #endif + /* widget event */ + else if (dbus_message_is_method_call(msg, VC_SERVER_SERVICE_INTERFACE, VC_WIDGET_METHOD_INITIALIZE)) + vcd_dbus_server_widget_initialize(g_conn_listener, msg); + + else if (dbus_message_is_method_call(msg, VC_SERVER_SERVICE_INTERFACE, VC_WIDGET_METHOD_FINALIZE)) + vcd_dbus_server_widget_finalize(g_conn_listener, msg); + + else if (dbus_message_is_method_call(msg, VC_SERVER_SERVICE_INTERFACE, VC_WIDGET_METHOD_START_RECORDING)) + vcd_dbus_server_widget_start_recording(g_conn_listener, msg); + + else if (dbus_message_is_method_call(msg, VC_SERVER_SERVICE_INTERFACE, VC_WIDGET_METHOD_START)) + vcd_dbus_server_widget_start(g_conn_listener, msg); + + else if (dbus_message_is_method_call(msg, VC_SERVER_SERVICE_INTERFACE, VC_WIDGET_METHOD_STOP)) + vcd_dbus_server_widget_stop(g_conn_listener, msg); + + else if (dbus_message_is_method_call(msg, VC_SERVER_SERVICE_INTERFACE, VC_WIDGET_METHOD_CANCEL)) + vcd_dbus_server_widget_cancel(g_conn_listener, msg); + + else if (dbus_message_is_method_call(msg, VC_SERVER_SERVICE_INTERFACE, VC_WIDGET_METHOD_ENABLE_ASR_RESULT)) + vcd_dbus_server_widget_enable_asr_result(g_conn_listener, msg); else if (dbus_message_is_method_call(msg, VC_SERVER_SERVICE_INTERFACE, VC_SETTING_METHOD_SET_LANGUAGE)) vcd_dbus_server_set_language(g_conn_listener, msg); diff --git a/server/vcd_dbus.h b/server/vcd_dbus.h index fcfaad3..7f07726 100644 --- a/server/vcd_dbus.h +++ b/server/vcd_dbus.h @@ -32,17 +32,25 @@ int vcd_check_dbus_connection(); int vcdc_send_hello(int pid, vcd_client_type_e type); +int vcdc_send_show_tooltip(int pid, bool show); + int vcdc_send_result(int pid, int manager_pid, int cmd_type); +int vcdc_send_asr_result(int pid, int event, const char* asr_result, int cmd_type, bool* is_consumed); + int vcdc_send_error_signal(int reason, char *err_msg); int vcdc_send_error_signal_to_app(int pid, int reason, char *err_msg); int vcdc_send_manager_pid(int manager_pid); +// int vcdc_send_request_get_private_data(int pid, const char* key, char** data); + /* for TTS feedback */ int vcdc_send_feedback_streaming(int pid, int utt_id, vc_feedback_event_e event, char* buffer, int len); +// int vcdc_send_feedback_streaming_to_manager(int manager_pid, int pid, int utt_id, vc_feedback_event_e event, char* buffer, int len); + #ifdef __cplusplus } #endif diff --git a/server/vcd_server.c b/server/vcd_server.c index ae36531..7f0d713 100644 --- a/server/vcd_server.c +++ b/server/vcd_server.c @@ -1350,7 +1350,7 @@ int vcd_initialize(vce_request_callback_s *callback) } /* Open tidl connection */ - if (0 != vcd_tidl_open_connection()) { + if (0 != vcd_mgr_tidl_open_connection()) { SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to open tidl connection"); if (TRUE != vcd_finalize()) { SLOG(LOG_ERROR, TAG_VCD, "[Server Error] Fail to finalize"); @@ -1442,7 +1442,7 @@ bool vcd_finalize() } /* Close tidl connection */ - if (0 != vcd_tidl_close_connection()) { + if (0 != vcd_mgr_tidl_close_connection()) { SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to close connection"); } diff --git a/server/vcd_tidl.c b/server/vcd_tidl.c index 3ed737c..d5917a5 100644 --- a/server/vcd_tidl.c +++ b/server/vcd_tidl.c @@ -22,97 +22,95 @@ #include "vcd_tidl.h" #include "vcd_mgr_stub.h" #include "vcd_mgr_proxy.h" -#include "vcd_widget_stub.h" -#include "vcd_widget_proxy.h" static rpc_port_stub_vc_mgr_callback_s g_mgr_callback; static pthread_mutex_t g_mgr_tidl_info_mutex = PTHREAD_MUTEX_INITIALIZER; -static rpc_port_stub_vc_widget_callback_s g_widget_callback; +static int g_volume_count = 0; -static pthread_mutex_t g_widget_tidl_info_mutex = PTHREAD_MUTEX_INITIALIZER; +static void __on_connected(rpc_port_proxy_vcd_mgr_h h, void *user_data) +{ + manager_tidl_info_s* mgr_tidl_info = vcd_client_manager_get_tidl_info(); -static int g_volume_count = 0; + if (NULL == mgr_tidl_info) { + SLOG(LOG_ERROR, TAG_VCD, "[TIDL] tidl proxy info not allocated"); + return; + } -int vcd_mgr_tidl_open_connection(); -int vcd_mgr_tidl_close_connection(); -int vcd_widget_tidl_open_connection(); -int vcd_widget_tidl_close_connection(); + mgr_tidl_info->connected = true; + mgr_tidl_info->connection_requesting = false; + + SLOG(LOG_INFO, TAG_VCD, "Connected to manager"); +} -/* for common request */ -static void __request_tidl_connect(vcd_client_type_e type, int pid) +static void __on_disconnected(rpc_port_proxy_vcd_mgr_h h, void *user_data) { - char* type_str = NULL; - int ret = -1; + manager_tidl_info_s* mgr_tidl_info = vcd_client_manager_get_tidl_info(); - if (VCD_CLIENT_TYPE_MANAGER == type) { - manager_tidl_info_s* mgr_tidl_info = vcd_client_manager_get_tidl_info(); - if (NULL == mgr_tidl_info) { - SLOG(LOG_ERROR, TAG_VCD, "[TIDL] manager tidl info not allocated"); - return; - } + if (NULL == mgr_tidl_info) { + SLOG(LOG_ERROR, TAG_VCD, "[TIDL] tidl proxy info not allocated"); + return; + } - if (mgr_tidl_info->connection_requesting) { - return; - } + mgr_tidl_info->connected = false; + mgr_tidl_info->connection_requesting = false; - ret = rpc_port_proxy_vcd_mgr_connect(mgr_tidl_info->rpc_h); + SLOG(LOG_INFO, TAG_VCD, "Disonnected to manager"); +} - if (0 == ret) { - mgr_tidl_info->connection_requesting = true; - } - type_str = "manager"; - // TODO: uncomment after client done - // } else if (VCD_CLIENT_TYPE_NORMAL == type) { - // client_tidl_info_s* client_tidl_info = vcd_client_client_get_tidl_info(pid); - // if (NULL == client_tidl_info) { - // SLOG(LOG_ERROR, TAG_VCD, "[TIDL] client tidl info not allocated"); - // return; - // } - - // if (client_tidl_info->connection_requesting) { - // return; - // } - - // ret = rpc_port_proxy_vcd_client_connect(client_tidl_info->rpc_h); - - // if (0 == ret) { - // SLOG(LOG_ERROR, TAG_VCD, "[TIDL] tidl proxy info not allocated"); - // client_tidl_info->connection_requesting = true; - // } - // type_str = "client"; - } else if (VCD_CLIENT_TYPE_WIDGET == type) { - widget_tidl_info_s* widget_tidl_info = vcd_client_widget_get_tidl_info(pid); - if (NULL == widget_tidl_info) { - SLOG(LOG_ERROR, TAG_VCD, "[TIDL] widget tidl info not allocated"); - return; - } +static void __on_rejected(rpc_port_proxy_vcd_mgr_h h, void *user_data) +{ + manager_tidl_info_s* mgr_tidl_info = vcd_client_manager_get_tidl_info(); - if (widget_tidl_info->connection_requesting) { - return; - } + if (NULL == mgr_tidl_info) { + SLOG(LOG_ERROR, TAG_VCD, "[TIDL] tidl proxy info not allocated"); + return; + } - ret = rpc_port_proxy_vcd_widget_connect(widget_tidl_info->rpc_h); + mgr_tidl_info->connection_requesting = false; - if (0 == ret) { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Rejected from manager"); +} + +static rpc_port_proxy_vcd_mgr_h __create_rpc_port(const char* engine_app_id, manager_tidl_info_s* mgr_tidl_info) +{ + SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] __create_rpc_port"); + rpc_port_proxy_vcd_mgr_callback_s rpc_callback = { + .connected = __on_connected, + .disconnected = __on_disconnected, + .rejected = __on_rejected + }; + + rpc_port_proxy_vcd_mgr_h handle = NULL; + if (0 != rpc_port_proxy_vcd_mgr_create(engine_app_id, &rpc_callback, NULL, &handle)) { + SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to create proxy"); + return NULL; + } + + return handle; +} + +static void __request_tidl_connect_sync(manager_tidl_info_s* mgr_tidl_info) +{ + if (NULL == mgr_tidl_info) { SLOG(LOG_ERROR, TAG_VCD, "[TIDL] tidl proxy info not allocated"); - widget_tidl_info->connection_requesting = true; - } - type_str = "widget"; - } else { - SLOG(LOG_ERROR, TAG_VCD, "[ERROR] client type is NOT valid(%d)", type); return; } - if (RPC_PORT_ERROR_NONE != ret) { - SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Request connection to %s stub. ret(%d)", type_str, ret); - } else { - SLOG(LOG_INFO, TAG_VCD, "[INFO] Request connection to %s stub. ret(%d)", type_str, ret); + if (mgr_tidl_info->connection_requesting) { + return; + } + + int ret = rpc_port_proxy_vcd_mgr_connect_sync(mgr_tidl_info->rpc_h); + SLOG(LOG_INFO, TAG_VCD, "[INFO] Request connection to stub. ret(%d)", ret); + + if (0 == ret) { + mgr_tidl_info->connection_requesting = true; } } -void __send_msg(bundle* msg, vcd_client_type_e type, int pid) +void __send_msg(bundle* msg, vcd_client_type_e type) { SLOG(LOG_INFO, TAG_VCD, "[TIDL] send msg start"); @@ -140,1116 +138,188 @@ void __send_msg(bundle* msg, vcd_client_type_e type, int pid) return; } pthread_mutex_unlock(&g_mgr_tidl_info_mutex); - // TODO: uncomment after client done - // } else if (VCD_CLIENT_TYPE_NORMAL == type) { - // pthread_mutex_lock(&g_client_tidl_info_mutex); - - // SLOG(LOG_INFO, TAG_VCD, "[TIDL] message to client"); - // client_tidl_info_s* client_tidl_info = vcd_client_client_get_tidl_info(pid); - // if (NULL == client_tidl_info) { - // SLOG(LOG_ERROR, TAG_VCD, "[TIDL] tidl proxy info not allocated"); - // pthread_mutex_unlock(&g_client_tidl_info_mutex); - // return; - // } - - // rpc_port_stub_vc_client_notify_cb_h handle = client_tidl_info->notify_cb; - // if (NULL == handle) { - // SLOG(LOG_ERROR, TAG_VCD, "[TIDL] notify callback handle is null"); - // pthread_mutex_unlock(&g_client_tidl_info_mutex); - // return; - // } - - // if (0 != rpc_port_stub_vc_client_notify_cb_invoke(handle, msg)) { - // SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to send msg"); - // pthread_mutex_unlock(&g_client_tidl_info_mutex); - // return; - // } - // pthread_mutex_unlock(&g_client_tidl_info_mutex); - } else if (VCD_CLIENT_TYPE_WIDGET == type) { - pthread_mutex_lock(&g_widget_tidl_info_mutex); - - SLOG(LOG_INFO, TAG_VCD, "[TIDL] message to widget"); - widget_tidl_info_s* widget_tidl_info = vcd_client_widget_get_tidl_info(pid); - if (NULL == widget_tidl_info) { - SLOG(LOG_ERROR, TAG_VCD, "[TIDL] tidl proxy info not allocated"); - pthread_mutex_unlock(&g_widget_tidl_info_mutex); - return; - } + } - rpc_port_stub_vc_widget_notify_cb_h handle = widget_tidl_info->notify_cb; - if (NULL == handle) { - SLOG(LOG_ERROR, TAG_VCD, "[TIDL] notify callback handle is null"); - pthread_mutex_unlock(&g_widget_tidl_info_mutex); - return; - } + SLOG(LOG_INFO, TAG_VCD, "[TIDL] send msg end"); +} - if (0 != rpc_port_stub_vc_widget_notify_cb_invoke(handle, msg)) { - SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to send msg"); - pthread_mutex_unlock(&g_widget_tidl_info_mutex); - return; - } - pthread_mutex_unlock(&g_widget_tidl_info_mutex); - } else { - SLOG(LOG_ERROR, TAG_VCD, "[ERROR] client type is NOT valid(%d)", type); +static void __vc_mgr_create_cb(rpc_port_stub_vc_mgr_context_h context, void *user_data) +{ + char *sender = NULL; + + rpc_port_stub_vc_mgr_context_get_sender(context, &sender); + if (!sender){ + SLOG(LOG_ERROR, TAG_VCD, "Sender is NULL"); return; } + + SLOG(LOG_DEBUG, TAG_VCD, "@@@ Manager connect. appid(%s)", sender); + + free(sender); } -void __send_signal(bundle* msg) +static void __vc_mgr_terminate_cb(rpc_port_stub_vc_mgr_context_h context, void *user_data) { - SLOG(LOG_INFO, TAG_VCD, "[TIDL] send signal start"); - pthread_mutex_lock(&g_mgr_tidl_info_mutex); - - SLOG(LOG_INFO, TAG_VCD, "[TIDL] message to manager"); manager_tidl_info_s* mgr_tidl_info = vcd_client_manager_get_tidl_info(); if (NULL == mgr_tidl_info) { - SLOG(LOG_ERROR, TAG_VCD, "[TIDL] tidl proxy info not allocated"); + SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to get manager tidl info."); pthread_mutex_unlock(&g_mgr_tidl_info_mutex); return; } - rpc_port_stub_vc_mgr_notify_cb_h handle = mgr_tidl_info->notify_cb; - if (NULL == handle) { - SLOG(LOG_ERROR, TAG_VCD, "[TIDL] notify callback handle is null"); - pthread_mutex_unlock(&g_mgr_tidl_info_mutex); - return; - } + SLOG(LOG_DEBUG, TAG_VCD, "@@@ VC MANAGER FINALIZE. pid(%u)", mgr_tidl_info->pid); - if (0 != rpc_port_stub_vc_mgr_notify_cb_invoke(handle, msg)) { - SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to send msg"); - pthread_mutex_unlock(&g_mgr_tidl_info_mutex); - return; + if (0 != vcd_client_manager_unset_tidl_notify_cb()) { + SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to unset notify callback"); } - pthread_mutex_unlock(&g_mgr_tidl_info_mutex); - - GSList *iter = NULL; - // TODO: uncomment after client done - // pthread_mutex_lock(&g_client_tidl_info_mutex); - // GSList* client_list = vcd_client_client_get_tidl_info_list(); - - // int count = g_slist_length(g_client_ipc_info_list); - // int i; - - // client_tidl_info_s *client_tidl_info = NULL; - - // if (0 < count) { - // iter = g_slist_nth(client_list, 0); - // for (i = 0; i < count; i++) { - // if (NULL == iter) { - // SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] client list iterator broken"); - // break; - // } + if (0 != vcd_client_manager_unset_tidl_send_buffer_cb()) { + SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to unset send buffer callback"); + } - // client_tidl_info = iter->data; + if (0 != vcd_client_manager_delete_tidl_info()) { + SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to delete manager tidl info"); + } + mgr_tidl_info = NULL; - // if (NULL == client_tidl_info) { - // SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] client list data broken"); - // break; - // } + SLOG(LOG_DEBUG, TAG_VCD, "@@@"); - // SLOG(LOG_INFO, TAG_VCD, "[TIDL] message to client"); + pthread_mutex_unlock(&g_mgr_tidl_info_mutex); - // rpc_port_stub_vc_client_notify_cb_h handle = client_tidl_info->notify_cb; - // if (NULL == handle) { - // SLOG(LOG_ERROR, TAG_VCD, "[TIDL] notify callback handle is null"); - // break; - // } - // if (0 != rpc_port_stub_vc_client_notify_cb_invoke(handle, msg)) { - // SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to send msg"); - // break; - // } + char *sender = NULL; + rpc_port_stub_vc_mgr_context_get_sender(context, &sender); + if (!sender) + return; - // iter = g_slist_next(iter); - // } - // } - // pthread_mutex_unlock(&g_client_tidl_info_mutex); - - pthread_mutex_lock(&g_widget_tidl_info_mutex); - GSList* widget_list = vcd_client_widget_get_tidl_info_list(); + SLOG(LOG_INFO, TAG_VCD, "@@@ Manager disconnect. appid(%s)", sender); - int count = g_slist_length(widget_list); - int i; + free(sender); +} - widget_tidl_info_s *widget_tidl_info = NULL; +static void __vc_mgr_register_cb_cb(rpc_port_stub_vc_mgr_context_h context, int pid, rpc_port_stub_vc_mgr_notify_cb_h notify_callback, rpc_port_stub_vc_mgr_send_buffer_cb_h send_buffer_callback, void *user_data) +{ + pthread_mutex_lock(&g_mgr_tidl_info_mutex); + SLOG(LOG_INFO, TAG_VCD, "@@@ VC MANAGER REGISTER CALLBACK"); - if (0 < count) { - iter = g_slist_nth(widget_list, 0); - for (i = 0; i < count; i++) { - if (NULL == iter) { - SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] widget list iterator broken"); - break; - } + int ret = -1; + ret = vcd_client_manger_create_tidl_info(pid); - widget_tidl_info = iter->data; + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to create manager tidl info."); + pthread_mutex_unlock(&g_mgr_tidl_info_mutex); + return; + } - if (NULL == widget_tidl_info) { - SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] widget list data broken"); - break; - } + manager_tidl_info_s* mgr_tidl_info = vcd_client_manager_get_tidl_info(); - SLOG(LOG_INFO, TAG_VCD, "[TIDL] message to widget"); + if (NULL == mgr_tidl_info) { + SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to get manager tidl info. pid(%d)", pid); + pthread_mutex_unlock(&g_mgr_tidl_info_mutex); + return; + } - rpc_port_stub_vc_widget_notify_cb_h handle = widget_tidl_info->notify_cb; - if (NULL == handle) { - SLOG(LOG_ERROR, TAG_VCD, "[TIDL] notify callback handle is null"); - break; - } + char *sender = NULL; + rpc_port_stub_vc_mgr_context_get_sender(context, &sender); - if (0 != rpc_port_stub_vc_widget_notify_cb_invoke(handle, msg)) { - SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to send msg"); - break; - } + if (!sender){ + SLOG(LOG_ERROR, TAG_VCD, "Sender is NULL"); + pthread_mutex_unlock(&g_mgr_tidl_info_mutex); + return; + } - iter = g_slist_next(iter); - } - } - pthread_mutex_unlock(&g_widget_tidl_info_mutex); -} + mgr_tidl_info->rpc_h = __create_rpc_port(sender, mgr_tidl_info); -// TODO: remove _tidl after all dbus removed -int vcdc_tidl_send_hello(int pid, vcd_client_type_e type) -{ - SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Send hello"); + if (NULL == mgr_tidl_info->rpc_h) { + SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to create server proxy"); + } else { + SLOG(LOG_INFO, TAG_VCD, "[TIDL] rpc_h(%p), engine_app_id(%s)", mgr_tidl_info->rpc_h, sender); + } - char tmp_pid[10] = {0, }; + free(sender); - bundle* msg = bundle_create(); - snprintf(tmp_pid, 10, "%d", pid); + if (0 != vcd_client_manager_set_tidl_notify_cb(notify_callback, user_data)) { + SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to set notify callback"); + } else { + SLOG(LOG_INFO, TAG_VCD, "[TIDL] Succeed to set notify callback."); + } - if (VCD_CLIENT_TYPE_NORMAL == type) { - // bundle_add_str(msg, VC_CLIENT_BUNDLE_METHOD, VCD_CLIENT_METHOD_HELLO); - // bundle_add_str(msg, VC_CLIENT_BUNDLE_MESSAGE, tmp_pid); - } else if (VCD_CLIENT_TYPE_MANAGER == type) { - bundle_add_str(msg, VC_MANAGER_BUNDLE_METHOD, VCD_MANAGER_METHOD_HELLO); - bundle_add_str(msg, VC_MANAGER_BUNDLE_MESSAGE, tmp_pid); - } else if (VCD_CLIENT_TYPE_WIDGET == type) { - bundle_add_str(msg, VC_WIDGET_BUNDLE_METHOD, VCD_WIDGET_METHOD_HELLO); - bundle_add_str(msg, VC_WIDGET_BUNDLE_MESSAGE, tmp_pid); + if (0 != vcd_client_manager_set_tidl_send_buffer_cb(send_buffer_callback, user_data)) { + SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to set send buffer callback"); } else { - SLOG(LOG_ERROR, TAG_VCD, "[Dbus ERROR] Client type is NOT valid"); - bundle_free(msg); - return VCD_ERROR_INVALID_PARAMETER; + SLOG(LOG_INFO, TAG_VCD, "[TIDL] Succeed to set send buffer callback."); } - SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] VCD SEND MESSAGE"); + pthread_mutex_unlock(&g_mgr_tidl_info_mutex); - __send_msg(msg, VCD_CLIENT_TYPE_MANAGER, pid); - bundle_free(msg); + __request_tidl_connect_sync(mgr_tidl_info); - return VCD_ERROR_NONE; + SLOG(LOG_DEBUG, TAG_VCD, "@@@"); } -int vcd_tidl_open_connection() +static int __vc_mgr_initialize_cb(rpc_port_stub_vc_mgr_context_h context, int pid, int audio_streaming_mode, int *service_state, int *foreground, int *daemon_pid, void *user_data) { - SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] vcd_tidl_open_connection"); - - if (0 != vcd_mgr_tidl_open_connection()) { - SLOG(LOG_ERROR, TAG_VCD, "Fail to open connection to manager"); - return VCD_ERROR_OPERATION_FAILED; - } + SLOG(LOG_INFO, TAG_VCD, "@@@ VCD Manager Initialize"); - // TODO: uncomment after client done - // if (0 != vcd_client_tidl_open_connection()) { - // SLOG(LOG_ERROR, TAG_VCD, "Fail to open connection to client"); - // return VCD_ERROR_OPERATION_FAILED; - // } + int ret = -1; - if (0 != vcd_widget_tidl_open_connection()) { - SLOG(LOG_ERROR, TAG_VCD, "Fail to open connection to widget"); - return VCD_ERROR_OPERATION_FAILED; + vcd_config_set_audio_streaming_mode((vcd_audio_streaming_mode_e)audio_streaming_mode); + ret = vcd_server_mgr_initialize(pid, audio_streaming_mode); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret); + return ret; } + *service_state = vcd_server_get_service_state(); + *foreground = vcd_server_get_foreground(); + *daemon_pid = getpid(); - return VCD_ERROR_NONE; + 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); + SLOG(LOG_DEBUG, TAG_VCD, "@@@"); + return ret; } -int vcd_tidl_close_connection() +static int __vc_mgr_finalize_cb(rpc_port_stub_vc_mgr_context_h context, int pid, void *user_data) { - SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] vcd_tidl_close_connection"); - - if (0 != vcd_mgr_tidl_close_connection()) { - SLOG(LOG_ERROR, TAG_VCD, "Fail to close connection to manager"); - return VCD_ERROR_OPERATION_FAILED; - } + SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Manager Finalize"); + SLOG(LOG_INFO, TAG_VCD, "[IN] vcd mgr finalize : pid(%d)", pid); - // TODO: uncomment after client done - // if (0 != vcd_client_tidl_close_connection()) { - // SLOG(LOG_ERROR, TAG_VCD, "Fail to close connection to client"); - // return VCD_ERROR_OPERATION_FAILED; - // } + int ret = -1; - if (0 != vcd_widget_tidl_close_connection()) { - SLOG(LOG_ERROR, TAG_VCD, "Fail to close connection to widget"); - return VCD_ERROR_OPERATION_FAILED; + ret = vcd_server_mgr_finalize(pid); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret); } - return VCD_ERROR_NONE; + SLOG(LOG_DEBUG, TAG_VCD, "@@@"); + + return ret; } -int vcdc_send_set_volume(int manager_pid, float volume) +static int __vc_mgr_set_command_cb(rpc_port_stub_vc_mgr_context_h context, int pid, void *user_data) { - SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Set volume"); - - char tmp_volume[20] = {0, }; - - bundle* msg = bundle_create(); - - snprintf(tmp_volume, 20, "%.6f", volume); - bundle_add_str(msg, VC_MANAGER_BUNDLE_METHOD, VCD_MANAGER_METHOD_SET_VOLUME); - bundle_add_str(msg, VC_MANAGER_BUNDLE_MESSAGE, tmp_volume); + SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Manager Set command"); + SLOG(LOG_INFO, TAG_VCD, "[IN] vcd mgr set command : pid(%d)", pid); + int ret = -1; - SLOG(LOG_DEBUG, TAG_VCD, ">>>> VCD SEND MESSAGE"); - __send_msg(msg, VCD_CLIENT_TYPE_MANAGER, manager_pid); - if (20 == g_volume_count) { - SLOG(LOG_INFO, TAG_VCD, "@@ Send set volume : pid(%d), volume(%f)", manager_pid, volume); - g_volume_count = 0; + ret = vcd_server_mgr_set_command(pid); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret); + return ret; } - g_volume_count++; - bundle_free(msg); + SLOG(LOG_DEBUG, TAG_VCD, "@@@"); - return VCD_ERROR_NONE; + return ret; } -int vcdc_send_show_tooltip(int pid, bool show) +static int __vc_mgr_unset_command_cb(rpc_port_stub_vc_mgr_context_h context, int pid, void *user_data) { - SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Send pre result to manager"); - - char tmp_pid[10] = {0, }; - char tmp_show[10] = {0, }; - - bundle* msg = bundle_create(); - - snprintf(tmp_pid, 10, "%d", pid); - snprintf(tmp_show, 10, "%d", (int)show); + SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Manager unset command"); + SLOG(LOG_INFO, TAG_VCD, "[IN] vcd mgr unset command : pid(%d)", pid); - bundle_add_str(msg, VC_WIDGET_BUNDLE_METHOD, VCD_WIDGET_METHOD_SHOW_TOOLTIP); - bundle_add_str(msg, VC_WIDGET_BUNDLE_MESSAGE, tmp_pid); - bundle_add_str(msg, VC_WIDGET_BUNDLE_SHOW, tmp_show); - - SLOG(LOG_DEBUG, TAG_VCD, ">>>> VCD SEND MESSAGE"); - - __send_msg(msg, VCD_CLIENT_TYPE_WIDGET, pid); - bundle_free(msg); - - return VCD_ERROR_NONE; -} - -// TODO: remove tidl after all dbus migrate to tidl -int vcdc_tidl_send_result(int pid, int manager_pid, vcd_client_type_e type) -{ - SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Send result"); - - bundle* msg = bundle_create(); - - if (VCD_CLIENT_TYPE_MANAGER == type) { - bundle_add_str(msg, VC_MANAGER_BUNDLE_METHOD, VCD_MANAGER_METHOD_RESULT); - // TODO: uncomment after client done - // } else if (VCD_CLIENT_TYPE_NORMAL == type) { - // // bundle_add_str(msg, VC_CLIENT_BUNDLE_METHOD, VCD_METHOD_RESULT); - } else if (VCD_CLIENT_TYPE_WIDGET == type) { - bundle_add_str(msg, VC_WIDGET_BUNDLE_METHOD, VCD_WIDGET_METHOD_RESULT); - } else { - SLOG(LOG_ERROR, TAG_VCD, "[ERROR] client type is NOT valid(%d)", type); - bundle_free(msg); - return VCD_ERROR_INVALID_PARAMETER; - } - - SLOG(LOG_DEBUG, TAG_VCD, ">>>> VCD SEND MESSAGE"); - - __send_msg(msg, type, pid); - bundle_free(msg); - - return VCD_ERROR_NONE; -} - -int vcdc_send_pre_result_to_manager(int manager_pid, int event, const char* pre_result) -{ - SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Send pre result to manager"); - - char tmp_event[10] = {0, }; - - bundle* msg = bundle_create(); - snprintf(tmp_event, 10, "%d", event); - - bundle_add_str(msg, VC_MANAGER_BUNDLE_METHOD, VCD_MANAGER_METHOD_PRE_RESULT); - bundle_add_str(msg, VC_MANAGER_BUNDLE_EVENT, tmp_event); - bundle_add_str(msg, VC_MANAGER_BUNDLE_PRE_RESULT, pre_result); - - SLOG(LOG_DEBUG, TAG_VCD, ">>>> VCD SEND MESSAGE"); - - __send_msg(msg, VCD_CLIENT_TYPE_MANAGER, manager_pid); - bundle_free(msg); - - return VCD_ERROR_NONE; -} - -int vcdc_send_specific_engine_result_to_manager(int manager_pid, const char* engine_app_id, const char* event, const char* result) -{ - SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Send specific engine result to manager"); - - bundle* msg = bundle_create(); - - gchar *gEncodedResult = g_base64_encode((const guchar*)result, strlen(result)); - - bundle_add_str(msg, VC_MANAGER_BUNDLE_METHOD, VCD_MANAGER_METHOD_SPECIFIC_ENGINE_RESULT); - bundle_add_str(msg, VC_MANAGER_BUNDLE_ENGINE_APP_ID, engine_app_id); - bundle_add_str(msg, VC_MANAGER_BUNDLE_EVENT, event); - bundle_add_str(msg, VC_MANAGER_BUNDLE_RESULT, gEncodedResult); - - SLOG(LOG_DEBUG, TAG_VCD, ">>>> VCD SEND MESSAGE"); - - __send_msg(msg, VCD_CLIENT_TYPE_MANAGER, manager_pid); - bundle_free(msg); - - if (gEncodedResult) - g_free(gEncodedResult); - - return VCD_ERROR_NONE; -} - -int vcdc_send_result_to_manager(int manager_pid, int result_type) -{ - SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Send result to manager"); - - char tmp_result[10] = {0, }; - - bundle* msg = bundle_create(); - snprintf(tmp_result, 10, "%d", result_type); - - bundle_add_str(msg, VC_MANAGER_BUNDLE_METHOD, VCD_MANAGER_METHOD_ALL_RESULT); - bundle_add_str(msg, VC_MANAGER_BUNDLE_MESSAGE, tmp_result); - - - SLOG(LOG_DEBUG, TAG_VCD, ">>>> VCD SEND MESSAGE"); - - __send_msg(msg, VCD_CLIENT_TYPE_MANAGER, manager_pid); - bundle_free(msg); - - return VCD_ERROR_NONE; -} - -int vcdc_send_speech_detected(int manager_pid) -{ - SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Send speech detected"); - - bundle* msg = bundle_create(); - - bundle_add_str(msg, VC_MANAGER_BUNDLE_METHOD, VCD_MANAGER_METHOD_SPEECH_DETECTED); - - SLOG(LOG_DEBUG, TAG_VCD, ">>>> VCD SEND MESSAGE"); - - __send_msg(msg, VCD_CLIENT_TYPE_MANAGER, manager_pid); - bundle_free(msg); - - return VCD_ERROR_NONE; -} - -int vcdc_send_service_state(vcd_state_e state) -{ - SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Send service state"); - - char tmp_state[10] = {0, }; - - bundle* msg = bundle_create(); - snprintf(tmp_state, 10, "%d", (int)state); - - bundle_add_str(msg, VC_MANAGER_BUNDLE_METHOD, VCD_MANAGER_METHOD_SET_SERVICE_STATE); - bundle_add_str(msg, VC_MANAGER_BUNDLE_MESSAGE, tmp_state); - - // TODO: uncomment after client done - // bundle_add_str(msg, VC_CLIENT_BUNDLE_METHOD, VCD_METHOD_SET_SERVICE_STATE); - // bundle_add_str(msg, VC_CLIENT_BUNDLE_MESSAGE, tmp_state); - - bundle_add_str(msg, VC_WIDGET_BUNDLE_METHOD, VCD_WIDGET_METHOD_SET_SERVICE_STATE); - bundle_add_str(msg, VC_WIDGET_BUNDLE_MESSAGE, tmp_state); - - SLOG(LOG_DEBUG, TAG_VCD, ">>>> VCD SEND SIGNAL"); - __send_signal(msg); - bundle_free(msg); - - return VCD_ERROR_NONE; -} - -int vcdc_send_dialog(int manager_pid, int pid, const char* disp_text, const char* utt_text, int continuous) -{ - SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Send dialog"); - - char tmp_pid[10] = {0, }; - char tmp_continuous[10] = {0, }; - char* tmp_disp_text = NULL; - char* tmp_utt_text = NULL; - bundle* msg = bundle_create(); - snprintf(tmp_pid, 10, "%d", pid); - snprintf(tmp_continuous, 10, "%d", continuous); - - if (NULL == disp_text) { - tmp_disp_text = strdup("#NULL"); - } else { - tmp_disp_text = strdup(disp_text); - } - - if (NULL == utt_text) { - tmp_utt_text = strdup("#NULL"); - } else { - tmp_utt_text = strdup(utt_text); - } - - bundle_add_str(msg, VC_MANAGER_BUNDLE_METHOD, VCD_MANAGER_METHOD_DIALOG); - bundle_add_str(msg, VC_MANAGER_BUNDLE_MESSAGE, tmp_pid); - bundle_add_str(msg, VC_MANAGER_BUNDLE_DISP_TEXT, tmp_disp_text); - bundle_add_str(msg, VC_MANAGER_BUNDLE_UTT_TEXT, tmp_utt_text); - bundle_add_str(msg, VC_MANAGER_BUNDLE_CONTINUOUS, tmp_continuous); - - SLOG(LOG_DEBUG, TAG_VCD, ">>>> VCD SEND MESSAGE"); - - __send_msg(msg, VCD_CLIENT_TYPE_MANAGER, manager_pid); - bundle_free(msg); - free(tmp_disp_text); - free(tmp_utt_text); - - return VCD_ERROR_NONE; -} - -int vcdc_tidl_send_error_to_manager(int manager_pid, int reason, char *err_msg) -{ - SLOG(LOG_ERROR, TAG_VCD, "[TIDL] Send error signal to manager"); - - char tmp_reason[10] = {0, }; - char tmp_daemon_pid[10] = {0, }; - char *temp_msg = NULL; - - if (NULL == err_msg) { - SLOG(LOG_WARN, TAG_VCD, "[TIDL ERROR] Input parameter is NULL"); - temp_msg = strdup("#NULL"); - } else { - temp_msg = strdup(err_msg); - } - - bundle* msg = bundle_create(); - snprintf(tmp_reason, 10, "%d", reason); - snprintf(tmp_daemon_pid, 10, "%d", getpid()); - - bundle_add_str(msg, VC_MANAGER_BUNDLE_METHOD, VCD_MANAGER_METHOD_ERROR); - bundle_add_str(msg, VC_MANAGER_BUNDLE_REASON, tmp_reason); - bundle_add_str(msg, VC_MANAGER_BUNDLE_DAEMON_PID, tmp_daemon_pid); - bundle_add_str(msg, VC_MANAGER_BUNDLE_ERROR_MESSAGE, temp_msg); - - SLOG(LOG_DEBUG, TAG_VCD, ">>>> VCD SEND MESSAGE"); - - __send_msg(msg, VCD_CLIENT_TYPE_MANAGER, manager_pid); - bundle_free(msg); - - free(temp_msg); - temp_msg = NULL; - - return VCD_ERROR_NONE; -} - -// TODO: remove _tidl after remove dbus -// TODO: make client, widget error signal -int vcdc_tidl_send_error(int reason, char *err_msg) -{ - SLOG(LOG_ERROR, TAG_VCD, "[TIDL] Send error signal"); - - char tmp_reason[10] = {0, }; - char tmp_daemon_pid[10] = {0, }; - char *temp_msg = NULL; - - if (NULL == err_msg) { - SLOG(LOG_WARN, TAG_VCD, "[TIDL ERROR] Input parameter is NULL"); - temp_msg = strdup("#NULL"); - } else { - temp_msg = strdup(err_msg); - } - - bundle* msg = bundle_create(); - snprintf(tmp_reason, 10, "%d", reason); - snprintf(tmp_daemon_pid, 10, "%d", getpid()); - - bundle_add_str(msg, VC_MANAGER_BUNDLE_METHOD, VCD_MANAGER_METHOD_ERROR); - bundle_add_str(msg, VC_MANAGER_BUNDLE_REASON, tmp_reason); - bundle_add_str(msg, VC_MANAGER_BUNDLE_DAEMON_PID, tmp_daemon_pid); - bundle_add_str(msg, VC_MANAGER_BUNDLE_ERROR_MESSAGE, temp_msg); - - bundle_add_str(msg, VC_WIDGET_BUNDLE_METHOD, VCD_MANAGER_METHOD_ERROR); - bundle_add_str(msg, VC_WIDGET_BUNDLE_REASON, tmp_reason); - bundle_add_str(msg, VC_WIDGET_BUNDLE_DAEMON_PID, tmp_daemon_pid); - bundle_add_str(msg, VC_WIDGET_BUNDLE_ERROR_MESSAGE, temp_msg); - - SLOG(LOG_DEBUG, TAG_VCD, ">>>> VCD SEND SIGNAL"); - - __send_signal(msg); - - bundle_free(msg); - - free(temp_msg); - temp_msg = NULL; - - return VCD_ERROR_NONE; -} - -int vcdc_send_request_set_private_data(int pid, const char* key, const char* data) -{ - SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Set private data"); - - char tmp_pid[10] = { 0, }; - - bundle* msg = bundle_create(); - snprintf(tmp_pid, 10, "%d", pid); - - bundle_add_str(msg, VC_MANAGER_BUNDLE_METHOD, VCD_MANAGER_METHOD_SET_PRIVATE_DATA); - bundle_add_str(msg, VC_MANAGER_BUNDLE_MESSAGE, tmp_pid); - bundle_add_str(msg, VC_MANAGER_BUNDLE_KEY, key); - bundle_add_str(msg, VC_MANAGER_BUNDLE_PRIVATE_DATA, data); - - SLOG(LOG_DEBUG, TAG_VCD, ">>>> VCD SEND MESSAGE"); - - __send_msg(msg, VCD_CLIENT_TYPE_MANAGER, pid); - bundle_free(msg); - - return VCD_ERROR_NONE; -} - -int vcdc_send_feedback_audio_format_to_manager(int manager_pid, int rate, vc_audio_channel_e channel, vce_audio_type_e audio_type) -{ - SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Send feedback audio format to manager"); - - char tmp_rate[10] = {0, }; - char tmp_channel[10] = {0, }; - char tmp_audio_type[10] = {0, }; - - bundle* msg = bundle_create(); - snprintf(tmp_rate, 10, "%d", rate); - snprintf(tmp_channel, 10, "%d", (int)channel); - snprintf(tmp_audio_type, 10, "%d", (int)audio_type); - bundle_add_str(msg, VC_MANAGER_BUNDLE_METHOD, VCD_MANAGER_METHOD_FEEDBACK_AUDIO_FORMAT); - bundle_add_str(msg, VC_MANAGER_BUNDLE_AUDIO_RATE, tmp_rate); - bundle_add_str(msg, VC_MANAGER_BUNDLE_AUDIO_CHANNEL, tmp_channel); - bundle_add_str(msg, VC_MANAGER_BUNDLE_AUDIO_TYPE, tmp_audio_type); - - SLOG(LOG_DEBUG, TAG_VCD, ">>>> VCD SEND MESSAGE"); - - __send_msg(msg, VCD_CLIENT_TYPE_MANAGER, manager_pid); - bundle_free(msg); - - return VCD_ERROR_NONE; -} - -int vcdc_send_feedback_streaming_to_manager(int manager_pid, int pid, int utt_id, vc_feedback_event_e event, char* buffer, int len) -{ - SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Send feedback streaming to manager"); - - char tmp_pid[10] = {0, }; - char tmp_utt_id[10] = {0, }; - char tmp_event[10] = {0, }; - - bundle* msg = bundle_create(); - snprintf(tmp_pid, 10, "%d", pid); - snprintf(tmp_utt_id, 10, "%d", utt_id); - snprintf(tmp_event, 10, "%d", (int)event); - bundle_add_str(msg, VC_MANAGER_BUNDLE_METHOD, VCD_MANAGER_METHOD_FEEDBACK_STREAMING); - bundle_add_str(msg, VC_MANAGER_BUNDLE_MESSAGE, tmp_pid); - bundle_add_str(msg, VC_MANAGER_BUNDLE_UTTID, tmp_utt_id); - bundle_add_str(msg, VC_MANAGER_BUNDLE_EVENT, tmp_event); - - rpc_port_stub_array_char_h streaming_data = NULL; - rpc_port_stub_array_char_create(&streaming_data); - if (NULL == streaming_data) { - SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to create data handle"); - return VCD_ERROR_OUT_OF_MEMORY; - } - - if (NULL != buffer && 0 < len) { - rpc_port_stub_array_char_set(streaming_data, (char*)buffer, len); - } else { - SLOG(LOG_ERROR, TAG_VCD, "[TIDL] buffer is empty"); - } - - SLOG(LOG_DEBUG, TAG_VCD, ">>>> VCD SEND MESSAGE"); - - pthread_mutex_lock(&g_mgr_tidl_info_mutex); - SLOG(LOG_INFO, TAG_VCD, "[TIDL] message to manager"); - manager_tidl_info_s* mgr_tidl_info = vcd_client_manager_get_tidl_info(); - - if (NULL == mgr_tidl_info) { - SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to get manager tidl info. pid(%d)", pid); - pthread_mutex_unlock(&g_mgr_tidl_info_mutex); - rpc_port_stub_array_char_destroy(streaming_data); - bundle_free(msg); - return VCD_ERROR_OPERATION_FAILED; - } - - rpc_port_stub_vc_mgr_send_buffer_cb_h handle = mgr_tidl_info->send_buffer_cb; - if (NULL == handle) { - SLOG(LOG_ERROR, TAG_VCD, "[TIDL] notify callback handle is null"); - pthread_mutex_unlock(&g_mgr_tidl_info_mutex); - rpc_port_stub_array_char_destroy(streaming_data); - bundle_free(msg); - return VCD_ERROR_OPERATION_FAILED; - } - - if (0 != rpc_port_stub_vc_mgr_send_buffer_cb_invoke(handle, streaming_data, msg)) { - SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to send msg"); - pthread_mutex_unlock(&g_mgr_tidl_info_mutex); - rpc_port_stub_array_char_destroy(streaming_data); - bundle_free(msg); - return VCD_ERROR_OPERATION_FAILED; - } - pthread_mutex_unlock(&g_mgr_tidl_info_mutex); - rpc_port_stub_array_char_destroy(streaming_data); - bundle_free(msg); - - return VCD_ERROR_NONE; -} - -void vcdc_send_request_set_foreground(int pid, int value) -{ - SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Set foreground"); - - manager_tidl_info_s* mgr_tidl_info = vcd_client_manager_get_tidl_info(); - - if (NULL == mgr_tidl_info) { - SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to get tidl info"); - return; - } - - if (!mgr_tidl_info->connected) { - SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Not Connected"); - return; - } - - rpc_port_proxy_vcd_mgr_invoke_set_foreground(mgr_tidl_info->rpc_h, pid, value); - - SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Request set foreground"); -} - -int vcdc_send_request_get_private_data(int pid, const char* key, char** data) -{ - SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Get private data"); - - manager_tidl_info_s* mgr_tidl_info = vcd_client_manager_get_tidl_info(); - - if (NULL == mgr_tidl_info) { - SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to get tidl info"); - return VC_ERROR_OPERATION_FAILED; - } - - if (!mgr_tidl_info->connected) { - SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Not Connected"); - return VC_ERROR_OPERATION_FAILED; - } - - char *tmp = NULL; - if (0 != rpc_port_proxy_vcd_mgr_invoke_get_private_data(mgr_tidl_info->rpc_h, pid, key, &tmp)) { - SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Request vcd manager get private data : Fail to invoke message"); - return VC_ERROR_OPERATION_FAILED; - } - SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Request vcd manager get private data : Success"); - - *data = tmp; - - return VC_ERROR_NONE; -} - -int vcdc_send_request_auth_enable(int pid) -{ - SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] auth enable"); - - manager_tidl_info_s* mgr_tidl_info = vcd_client_manager_get_tidl_info(); - - if (NULL == mgr_tidl_info) { - SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to get tidl info"); - return VC_ERROR_OPERATION_FAILED; - } - - if (!mgr_tidl_info->connected) { - SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Not Connected"); - return VC_ERROR_OPERATION_FAILED; - } - - if (0 != rpc_port_proxy_vcd_mgr_invoke_auth_enable(mgr_tidl_info->rpc_h, pid)) { - SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Request auth enable : Fail to invoke message"); - return VC_ERROR_OPERATION_FAILED; - } - SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Request auth enable : Success"); - - return VC_ERROR_NONE; -} - -int vcdc_send_request_auth_disable(int pid) -{ - SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] auth disable"); - - manager_tidl_info_s* mgr_tidl_info = vcd_client_manager_get_tidl_info(); - - if (NULL == mgr_tidl_info) { - SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to get tidl info"); - return VC_ERROR_OPERATION_FAILED; - } - - if (!mgr_tidl_info->connected) { - SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Not Connected"); - return VC_ERROR_OPERATION_FAILED; - } - - if (0 != rpc_port_proxy_vcd_mgr_invoke_auth_disable(mgr_tidl_info->rpc_h, pid)) { - SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Request auth disable : Fail to invoke message"); - return VC_ERROR_OPERATION_FAILED; - } - SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Request auth disable : Success"); - - return VC_ERROR_NONE; -} - -int vcdc_send_request_auth_start(int pid) -{ - SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] auth start"); - - manager_tidl_info_s* mgr_tidl_info = vcd_client_manager_get_tidl_info(); - - if (NULL == mgr_tidl_info) { - SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to get tidl info"); - return VC_ERROR_OPERATION_FAILED; - } - - if (!mgr_tidl_info->connected) { - SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Not Connected"); - return VC_ERROR_OPERATION_FAILED; - } - - if (0 != rpc_port_proxy_vcd_mgr_invoke_auth_start(mgr_tidl_info->rpc_h, pid)) { - SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Request auth start : Fail to invoke message"); - return VC_ERROR_OPERATION_FAILED; - } - SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Request auth start : Success"); - - return VC_ERROR_NONE; -} - -int vcdc_send_request_auth_stop(int pid) -{ - SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] auth stop"); - - manager_tidl_info_s* mgr_tidl_info = vcd_client_manager_get_tidl_info(); - - if (NULL == mgr_tidl_info) { - SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to get tidl info"); - return VC_ERROR_OPERATION_FAILED; - } - - if (!mgr_tidl_info->connected) { - SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Not Connected"); - return VC_ERROR_OPERATION_FAILED; - } - - if (0 != rpc_port_proxy_vcd_mgr_invoke_auth_stop(mgr_tidl_info->rpc_h, pid)) { - SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Request auth stop : Fail to invoke message"); - return VC_ERROR_OPERATION_FAILED; - } - SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Request auth stop : Success"); - - return VC_ERROR_NONE; -} - -int vcdc_send_request_auth_cancel(int pid) -{ - SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] auth cancel"); - - manager_tidl_info_s* mgr_tidl_info = vcd_client_manager_get_tidl_info(); - - if (NULL == mgr_tidl_info) { - SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to get tidl info"); - return VC_ERROR_OPERATION_FAILED; - } - - if (!mgr_tidl_info->connected) { - SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Not Connected"); - return VC_ERROR_OPERATION_FAILED; - } - - if (0 != rpc_port_proxy_vcd_mgr_invoke_auth_cancel(mgr_tidl_info->rpc_h, pid)) { - SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Request auth cancel : Fail to invoke message"); - return VC_ERROR_OPERATION_FAILED; - } - SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Request auth cancel : Success"); - - return VC_ERROR_NONE; -} - -int vcdc_send_asr_result(int pid, int event, const char* asr_result, int cmd_type, bool* is_consumed) -{ - SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Send asr result"); - - widget_tidl_info_s* widget_tidl_info = vcd_client_widget_get_tidl_info(pid); - - if (NULL == widget_tidl_info) { - SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to get tidl info"); - return VC_ERROR_OPERATION_FAILED; - } - - if (!widget_tidl_info->connected) { - SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Not Connected"); - return VC_ERROR_OPERATION_FAILED; - } - - bool temp; - if (0 != rpc_port_proxy_vcd_widget_invoke_send_asr_result(widget_tidl_info->rpc_h, pid, event, asr_result, &temp)) { - SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Request vcd widget send asr result : Fail to invoke message"); - return VC_ERROR_OPERATION_FAILED; - } - SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Request vcd widget send asr result : Success"); - - *is_consumed = temp; - - return VC_ERROR_NONE; -} - -/* -* Tidl for manager -*/ -static void __mgr_on_connected(rpc_port_proxy_vcd_mgr_h h, void *user_data) -{ - manager_tidl_info_s* mgr_tidl_info = vcd_client_manager_get_tidl_info(); - - if (NULL == mgr_tidl_info) { - SLOG(LOG_ERROR, TAG_VCD, "[TIDL] tidl proxy info not allocated"); - return; - } - - mgr_tidl_info->connected = true; - mgr_tidl_info->connection_requesting = false; - - SLOG(LOG_INFO, TAG_VCD, "Connected to manager"); -} - -static void __mgr_on_disconnected(rpc_port_proxy_vcd_mgr_h h, void *user_data) -{ - manager_tidl_info_s* mgr_tidl_info = vcd_client_manager_get_tidl_info(); - - if (NULL == mgr_tidl_info) { - SLOG(LOG_ERROR, TAG_VCD, "[TIDL] tidl proxy info not allocated"); - return; - } - - mgr_tidl_info->connected = false; - mgr_tidl_info->connection_requesting = false; - - SLOG(LOG_INFO, TAG_VCD, "Disonnected to manager"); -} - -static void __mgr_on_rejected(rpc_port_proxy_vcd_mgr_h h, void *user_data) -{ - manager_tidl_info_s* mgr_tidl_info = vcd_client_manager_get_tidl_info(); - - if (NULL == mgr_tidl_info) { - SLOG(LOG_ERROR, TAG_VCD, "[TIDL] tidl proxy info not allocated"); - return; - } - - mgr_tidl_info->connection_requesting = false; - - SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Rejected from manager"); -} - -static rpc_port_proxy_vcd_mgr_h __mgr_create_rpc_port(const char* engine_app_id) -{ - SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] __mgr_create_rpc_port"); - rpc_port_proxy_vcd_mgr_callback_s rpc_callback = { - .connected = __mgr_on_connected, - .disconnected = __mgr_on_disconnected, - .rejected = __mgr_on_rejected - }; - - rpc_port_proxy_vcd_mgr_h handle = NULL; - if (0 != rpc_port_proxy_vcd_mgr_create(engine_app_id, &rpc_callback, NULL, &handle)) { - SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to create proxy"); - return NULL; - } - - return handle; -} - -static void __vc_mgr_create_cb(rpc_port_stub_vc_mgr_context_h context, void *user_data) -{ - char *sender = NULL; - - rpc_port_stub_vc_mgr_context_get_sender(context, &sender); - if (!sender){ - SLOG(LOG_ERROR, TAG_VCD, "Sender is NULL"); - return; - } - - SLOG(LOG_DEBUG, TAG_VCD, "@@@ Manager connect. appid(%s)", sender); - - free(sender); -} - -static void __vc_mgr_terminate_cb(rpc_port_stub_vc_mgr_context_h context, void *user_data) -{ - pthread_mutex_lock(&g_mgr_tidl_info_mutex); - manager_tidl_info_s* mgr_tidl_info = vcd_client_manager_get_tidl_info(); - if (NULL == mgr_tidl_info) { - SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to get manager tidl info."); - pthread_mutex_unlock(&g_mgr_tidl_info_mutex); - return; - } - - SLOG(LOG_DEBUG, TAG_VCD, "@@@ VC MANAGER FINALIZE. pid(%u)", mgr_tidl_info->pid); - - if (0 != vcd_client_manager_unset_tidl_notify_cb()) { - SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to unset notify callback"); - } - - if (0 != vcd_client_manager_unset_tidl_send_buffer_cb()) { - SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to unset send buffer callback"); - } - - if (0 != vcd_client_manager_delete_tidl_info()) { - SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to delete manager tidl info"); - } - mgr_tidl_info = NULL; - - SLOG(LOG_DEBUG, TAG_VCD, "@@@"); - - pthread_mutex_unlock(&g_mgr_tidl_info_mutex); - - - char *sender = NULL; - rpc_port_stub_vc_mgr_context_get_sender(context, &sender); - if (!sender) - return; - - SLOG(LOG_INFO, TAG_VCD, "@@@ Manager disconnect. appid(%s)", sender); - - free(sender); -} - -static void __vc_mgr_register_cb_cb(rpc_port_stub_vc_mgr_context_h context, int pid, rpc_port_stub_vc_mgr_notify_cb_h notify_callback, rpc_port_stub_vc_mgr_send_buffer_cb_h send_buffer_callback, void *user_data) -{ - pthread_mutex_lock(&g_mgr_tidl_info_mutex); - SLOG(LOG_INFO, TAG_VCD, "@@@ VC MANAGER REGISTER CALLBACK"); - - int ret = -1; - ret = vcd_client_manager_create_tidl_info(pid); - - if (0 != ret) { - SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to create manager tidl info."); - pthread_mutex_unlock(&g_mgr_tidl_info_mutex); - return; - } - - manager_tidl_info_s* mgr_tidl_info = vcd_client_manager_get_tidl_info(); - - if (NULL == mgr_tidl_info) { - SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to get manager tidl info. pid(%d)", pid); - pthread_mutex_unlock(&g_mgr_tidl_info_mutex); - return; - } - - char *sender = NULL; - rpc_port_stub_vc_mgr_context_get_sender(context, &sender); - - if (!sender){ - SLOG(LOG_ERROR, TAG_VCD, "Sender is NULL"); - pthread_mutex_unlock(&g_mgr_tidl_info_mutex); - return; - } - - mgr_tidl_info->rpc_h = __mgr_create_rpc_port(sender); - - if (NULL == mgr_tidl_info->rpc_h) { - SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to create server proxy"); - } else { - SLOG(LOG_INFO, TAG_VCD, "[TIDL] rpc_h(%p), engine_app_id(%s)", mgr_tidl_info->rpc_h, sender); - } - - free(sender); - - if (0 != vcd_client_manager_set_tidl_notify_cb(notify_callback, user_data)) { - SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to set notify callback"); - } else { - SLOG(LOG_INFO, TAG_VCD, "[TIDL] Succeed to set notify callback."); - } - - if (0 != vcd_client_manager_set_tidl_send_buffer_cb(send_buffer_callback, user_data)) { - SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to set send buffer callback"); - } else { - SLOG(LOG_INFO, TAG_VCD, "[TIDL] Succeed to set send buffer callback."); - } - - pthread_mutex_unlock(&g_mgr_tidl_info_mutex); - - __request_tidl_connect(VCD_CLIENT_TYPE_MANAGER, pid); - - SLOG(LOG_DEBUG, TAG_VCD, "@@@"); -} - -static int __vc_mgr_initialize_cb(rpc_port_stub_vc_mgr_context_h context, int pid, int audio_streaming_mode, int *service_state, int *foreground, int *daemon_pid, void *user_data) -{ - SLOG(LOG_INFO, TAG_VCD, "@@@ VCD Manager Initialize"); - - int ret = -1; - - vcd_config_set_audio_streaming_mode((vcd_audio_streaming_mode_e)audio_streaming_mode); - ret = vcd_server_mgr_initialize(pid, audio_streaming_mode); - if (0 != ret) { - SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret); - return ret; - } - *service_state = vcd_server_get_service_state(); - *foreground = vcd_server_get_foreground(); - *daemon_pid = getpid(); - - 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); - SLOG(LOG_DEBUG, TAG_VCD, "@@@"); - return ret; -} - -static int __vc_mgr_finalize_cb(rpc_port_stub_vc_mgr_context_h context, int pid, void *user_data) -{ - SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Manager Finalize"); - SLOG(LOG_INFO, TAG_VCD, "[IN] vcd mgr finalize : pid(%d)", pid); - - int ret = -1; - - ret = vcd_server_mgr_finalize(pid); - if (0 != ret) { - SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret); - } - - SLOG(LOG_DEBUG, TAG_VCD, "@@@"); - - return ret; -} - -static int __vc_mgr_set_command_cb(rpc_port_stub_vc_mgr_context_h context, int pid, void *user_data) -{ - SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Manager Set command"); - SLOG(LOG_INFO, TAG_VCD, "[IN] vcd mgr set command : pid(%d)", pid); - - int ret = -1; - - ret = vcd_server_mgr_set_command(pid); - if (0 != ret) { - SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret); - return ret; - } - - SLOG(LOG_DEBUG, TAG_VCD, "@@@"); - - return ret; -} - -static int __vc_mgr_unset_command_cb(rpc_port_stub_vc_mgr_context_h context, int pid, void *user_data) -{ - SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Manager unset command"); - SLOG(LOG_INFO, TAG_VCD, "[IN] vcd mgr unset command : pid(%d)", pid); - - int ret = -1; + int ret = -1; ret = vcd_server_mgr_unset_command(pid); if (0 != ret) { @@ -1543,7 +613,7 @@ static void __vc_mgr_send_audio_streaming_cb(rpc_port_stub_vc_mgr_context_h con int vcd_mgr_tidl_open_connection() { - SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] vcd_mgr_tidl_open_connection"); + SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] vcd_tidl_open_connection"); g_mgr_callback.create = __vc_mgr_create_cb; g_mgr_callback.terminate = __vc_mgr_terminate_cb; @@ -1593,352 +663,542 @@ int vcd_mgr_tidl_close_connection() return VCD_ERROR_NONE; } -/* -* Tidl for widget -*/ -static void __widget_on_connected(rpc_port_proxy_vcd_widget_h h, void *user_data) +// TODO: remove _tidl after all dbus removed +int vcdc_tidl_send_hello(int pid, vcd_client_type_e type) { - widget_tidl_info_s* widget_tidl_info = vcd_client_widget_get_tidl_info((int)user_data); - - widget_tidl_info->connected = true; - widget_tidl_info->connection_requesting = false; + SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Send hello"); + + char tmp_pid[10] = {0, }; + + bundle* msg = bundle_create(); + snprintf(tmp_pid, 10, "%d", pid); + + bundle_add_str(msg, VC_MANAGER_BUNDLE_METHOD, VCD_MANAGER_METHOD_HELLO); + bundle_add_str(msg, VC_MANAGER_BUNDLE_MESSAGE, tmp_pid); - SLOG(LOG_INFO, TAG_VCD, "Connected to widget"); + SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] VCD SEND MESSAGE"); + + __send_msg(msg, VCD_CLIENT_TYPE_MANAGER); + bundle_free(msg); + + return VCD_ERROR_NONE; } -static void __widget_on_disconnected(rpc_port_proxy_vcd_widget_h h, void *user_data) +int vcdc_send_set_volume(int manager_pid, float volume) +{ + SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Set volume"); + + char tmp_volume[20] = {0, }; + + bundle* msg = bundle_create(); + + snprintf(tmp_volume, 20, "%.6f", volume); + bundle_add_str(msg, VC_MANAGER_BUNDLE_METHOD, VCD_MANAGER_METHOD_SET_VOLUME); + bundle_add_str(msg, VC_MANAGER_BUNDLE_MESSAGE, tmp_volume); + + + SLOG(LOG_DEBUG, TAG_VCD, ">>>> VCD SEND MESSAGE"); + __send_msg(msg, VCD_CLIENT_TYPE_MANAGER); + if (20 == g_volume_count) { + SLOG(LOG_INFO, TAG_VCD, "@@ Send set volume : pid(%d), volume(%f)", manager_pid, volume); + g_volume_count = 0; + } + g_volume_count++; + + bundle_free(msg); + + return VCD_ERROR_NONE; +} +// TODO: remove tidl after all dbus migrate to tidl +int vcdc_tidl_send_result(int pid, int manager_pid, int cmd_type) { - widget_tidl_info_s* widget_tidl_info = vcd_client_widget_get_tidl_info((int)user_data); + SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Send result"); + + bundle* msg = bundle_create(); + + bundle_add_str(msg, VC_MANAGER_BUNDLE_METHOD, VCD_MANAGER_METHOD_RESULT); + + SLOG(LOG_DEBUG, TAG_VCD, ">>>> VCD SEND MESSAGE"); - widget_tidl_info->connected = false; - widget_tidl_info->connection_requesting = false; + __send_msg(msg, VCD_CLIENT_TYPE_MANAGER); + bundle_free(msg); - SLOG(LOG_INFO, TAG_VCD, "Disonnected to widget"); + return VCD_ERROR_NONE; } -static void __widget_on_rejected(rpc_port_proxy_vcd_widget_h h, void *user_data) +int vcdc_send_pre_result_to_manager(int manager_pid, int event, const char* pre_result) { - widget_tidl_info_s* widget_tidl_info = vcd_client_widget_get_tidl_info((int)user_data); + SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Send pre result to manager"); - widget_tidl_info->connection_requesting = false; + char tmp_event[10] = {0, }; + + bundle* msg = bundle_create(); + snprintf(tmp_event, 10, "%d", event); + + bundle_add_str(msg, VC_MANAGER_BUNDLE_METHOD, VCD_MANAGER_METHOD_PRE_RESULT); + bundle_add_str(msg, VC_MANAGER_BUNDLE_EVENT, tmp_event); + bundle_add_str(msg, VC_MANAGER_BUNDLE_PRE_RESULT, pre_result); - SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Rejected from widget"); + SLOG(LOG_DEBUG, TAG_VCD, ">>>> VCD SEND MESSAGE"); + + __send_msg(msg, VCD_CLIENT_TYPE_MANAGER); + bundle_free(msg); + + return VCD_ERROR_NONE; } -static rpc_port_proxy_vcd_widget_h __widget_create_rpc_port(const char* engine_app_id, int pid) +int vcdc_send_specific_engine_result_to_manager(int manager_pid, const char* engine_app_id, const char* event, const char* result) { - SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] __widget_create_rpc_port"); - rpc_port_proxy_vcd_widget_callback_s rpc_callback = { - .connected = __widget_on_connected, - .disconnected = __widget_on_disconnected, - .rejected = __widget_on_rejected - }; + SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Send specific engine result to manager"); - rpc_port_proxy_vcd_widget_h handle = NULL; - if (0 != rpc_port_proxy_vcd_widget_create(engine_app_id, &rpc_callback, (void *)pid, &handle)) { - SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to create proxy"); - return NULL; - } + bundle* msg = bundle_create(); - return handle; + gchar *gEncodedResult = g_base64_encode((const guchar*)result, strlen(result)); + + bundle_add_str(msg, VC_MANAGER_BUNDLE_METHOD, VCD_MANAGER_METHOD_SPECIFIC_ENGINE_RESULT); + bundle_add_str(msg, VC_MANAGER_BUNDLE_ENGINE_APP_ID, engine_app_id); + bundle_add_str(msg, VC_MANAGER_BUNDLE_EVENT, event); + bundle_add_str(msg, VC_MANAGER_BUNDLE_RESULT, gEncodedResult); + + SLOG(LOG_DEBUG, TAG_VCD, ">>>> VCD SEND MESSAGE"); + + __send_msg(msg, VCD_CLIENT_TYPE_MANAGER); + bundle_free(msg); + + if (gEncodedResult) + g_free(gEncodedResult); + + return VCD_ERROR_NONE; } -static void __vc_widget_create_cb(rpc_port_stub_vc_widget_context_h context, void *user_data) +int vcdc_send_result_to_manager(int manager_pid, int result_type) { - char *sender = NULL; + SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Send result to manager"); - rpc_port_stub_vc_widget_context_get_sender(context, &sender); - if (!sender) { - SLOG(LOG_ERROR, TAG_VCD, "Sender is NULL"); - return; - } + char tmp_result[10] = {0, }; - SLOG(LOG_DEBUG, TAG_VCD, "@@@ Widget connect. appid(%s)", sender); - free(sender); + bundle* msg = bundle_create(); + snprintf(tmp_result, 10, "%d", result_type); + + bundle_add_str(msg, VC_MANAGER_BUNDLE_METHOD, VCD_MANAGER_METHOD_ALL_RESULT); + bundle_add_str(msg, VC_MANAGER_BUNDLE_MESSAGE, tmp_result); + + + SLOG(LOG_DEBUG, TAG_VCD, ">>>> VCD SEND MESSAGE"); + + __send_msg(msg, VCD_CLIENT_TYPE_MANAGER); + bundle_free(msg); + + return VCD_ERROR_NONE; } -static void __vc_widget_terminate_cb(rpc_port_stub_vc_widget_context_h context, void *user_data) +int vcdc_send_speech_detected(int manager_pid) { - void* tag = NULL; - rpc_port_stub_vc_widget_context_get_tag(context, &tag); - - if (NULL != tag) { - int pid = (intptr_t)tag; - SLOG(LOG_DEBUG, TAG_VCD, "@@@ VC WIDGET FINALIZE. pid(%u)", pid); - - pthread_mutex_lock(&g_widget_tidl_info_mutex); - widget_tidl_info_s* widget_tidl_info = vcd_client_widget_get_tidl_info(pid); - if (NULL == widget_tidl_info) { - SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to get widget tidl info."); - pthread_mutex_unlock(&g_widget_tidl_info_mutex); - return; - } + SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Send speech detected"); - if (0 != vcd_client_widget_unset_tidl_notify_cb(pid)) { - SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to unset notify callback"); - } + bundle* msg = bundle_create(); - if (0 != vcd_client_widget_delete_tidl_info(pid)) { - SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to delete widget tidl info"); - } - widget_tidl_info = NULL; + bundle_add_str(msg, VC_MANAGER_BUNDLE_METHOD, VCD_MANAGER_METHOD_SPEECH_DETECTED); - SLOG(LOG_DEBUG, TAG_VCD, "@@@"); + SLOG(LOG_DEBUG, TAG_VCD, ">>>> VCD SEND MESSAGE"); - pthread_mutex_unlock(&g_widget_tidl_info_mutex); + __send_msg(msg, VCD_CLIENT_TYPE_MANAGER); + bundle_free(msg); - char *sender = NULL; - rpc_port_stub_vc_widget_context_get_sender(context, &sender); - if (!sender) - return; + return VCD_ERROR_NONE; +} + +int vcdc_send_service_state(vcd_state_e state) +{ + SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Send service state"); - SLOG(LOG_INFO, TAG_VCD, "@@@ Manager disconnect. appid(%s)", sender); + char tmp_state[10] = {0, }; - free(sender); - } - rpc_port_stub_vc_widget_context_set_tag(context, NULL); + bundle* msg = bundle_create(); + snprintf(tmp_state, 10, "%d", (int)state); + + bundle_add_str(msg, VC_MANAGER_BUNDLE_METHOD, VCD_MANAGER_METHOD_SET_SERVICE_STATE); + bundle_add_str(msg, VC_MANAGER_BUNDLE_MESSAGE, tmp_state); + + SLOG(LOG_DEBUG, TAG_VCD, ">>>> VCD SEND MESSAGE"); + + __send_msg(msg, VCD_CLIENT_TYPE_MANAGER); + bundle_free(msg); + + return VCD_ERROR_NONE; } -static void __vc_widget_register_cb_cb(rpc_port_stub_vc_widget_context_h context, int pid, rpc_port_stub_vc_widget_notify_cb_h notify_callback, void *user_data) +int vcdc_send_dialog(int manager_pid, int pid, const char* disp_text, const char* utt_text, int continuous) { - pthread_mutex_lock(&g_widget_tidl_info_mutex); - SLOG(LOG_INFO, TAG_VCD, "@@@ VC WIDGET REGISTER CALLBACK"); + SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Send dialog"); - int ret = -1; - ret = vcd_client_widget_add_tidl_info(pid); + char tmp_pid[10] = {0, }; + char tmp_continuous[10] = {0, }; + char* tmp_disp_text = NULL; + char* tmp_utt_text = NULL; + bundle* msg = bundle_create(); + snprintf(tmp_pid, 10, "%d", pid); + snprintf(tmp_continuous, 10, "%d", continuous); - if (0 != ret) { - SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to add widget tidl info."); - pthread_mutex_unlock(&g_widget_tidl_info_mutex); - return; + if (NULL == disp_text) { + tmp_disp_text = strdup("#NULL"); + } else { + tmp_disp_text = strdup(disp_text); } - widget_tidl_info_s* widget_tidl_info = vcd_client_widget_get_tidl_info(pid); - if (NULL == widget_tidl_info) { - SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to get widget tidl info. pid(%d)", pid); - pthread_mutex_unlock(&g_widget_tidl_info_mutex); - return; + if (NULL == utt_text) { + tmp_utt_text = strdup("#NULL"); + } else { + tmp_utt_text = strdup(utt_text); } - char *sender = NULL; - rpc_port_stub_vc_widget_context_get_sender(context, &sender); + bundle_add_str(msg, VC_MANAGER_BUNDLE_METHOD, VCD_MANAGER_METHOD_DIALOG); + bundle_add_str(msg, VC_MANAGER_BUNDLE_MESSAGE, tmp_pid); + bundle_add_str(msg, VC_MANAGER_BUNDLE_DISP_TEXT, tmp_disp_text); + bundle_add_str(msg, VC_MANAGER_BUNDLE_UTT_TEXT, tmp_utt_text); + bundle_add_str(msg, VC_MANAGER_BUNDLE_CONTINUOUS, tmp_continuous); - if (!sender){ - SLOG(LOG_ERROR, TAG_VCD, "Sender is NULL"); - pthread_mutex_unlock(&g_widget_tidl_info_mutex); - return; - } + SLOG(LOG_DEBUG, TAG_VCD, ">>>> VCD SEND MESSAGE"); + + __send_msg(msg, VCD_CLIENT_TYPE_MANAGER); + bundle_free(msg); + free(tmp_disp_text); + free(tmp_utt_text); - widget_tidl_info->rpc_h = __widget_create_rpc_port(sender, pid); + return VCD_ERROR_NONE; +} - if (NULL == widget_tidl_info->rpc_h) { - SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to create server proxy"); +int vcdc_tidl_send_error_to_manager(int manager_pid, int reason, char *err_msg) +{ + SLOG(LOG_ERROR, TAG_VCD, "[TIDL] Send error signal to manager"); + + char tmp_reason[10] = {0, }; + char tmp_daemon_pid[10] = {0, }; + char *temp_msg = NULL; + + if (NULL == err_msg) { + SLOG(LOG_WARN, TAG_VCD, "[TIDL ERROR] Input parameter is NULL"); + temp_msg = strdup("#NULL"); } else { - SLOG(LOG_INFO, TAG_VCD, "[TIDL] rpc_h(%p), engine_app_id(%s)", widget_tidl_info->rpc_h, sender); + temp_msg = strdup(err_msg); } - free(sender); + bundle* msg = bundle_create(); + snprintf(tmp_reason, 10, "%d", reason); + snprintf(tmp_daemon_pid, 10, "%d", getpid()); + + bundle_add_str(msg, VC_MANAGER_BUNDLE_METHOD, VCD_MANAGER_METHOD_ERROR); + bundle_add_str(msg, VC_MANAGER_BUNDLE_REASON, tmp_reason); + bundle_add_str(msg, VC_MANAGER_BUNDLE_DAEMON_PID, tmp_daemon_pid); + bundle_add_str(msg, VC_MANAGER_BUNDLE_ERROR_MESSAGE, temp_msg); + + SLOG(LOG_DEBUG, TAG_VCD, ">>>> VCD SEND MESSAGE"); + + __send_msg(msg, VCD_CLIENT_TYPE_MANAGER); + bundle_free(msg); + + free(temp_msg); + temp_msg = NULL; + + return VCD_ERROR_NONE; +} + +// TODO: remove _tidl after remove dbus +// TODO: make client, widget error signal +int vcdc_tidl_send_error(int reason, char *err_msg) +{ + SLOG(LOG_ERROR, TAG_VCD, "[TIDL] Send error signal"); + + vcdc_tidl_send_error_to_manager(vcd_client_manager_get_pid(), reason, err_msg); + + return VCD_ERROR_NONE; +} + +int vcdc_send_request_set_private_data(int pid, const char* key, const char* data) +{ + SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Set private data"); + + char tmp_pid[10] = { 0, }; + + bundle* msg = bundle_create(); + snprintf(tmp_pid, 10, "%d", pid); + + bundle_add_str(msg, VC_MANAGER_BUNDLE_METHOD, VCD_MANAGER_METHOD_SET_PRIVATE_DATA); + bundle_add_str(msg, VC_MANAGER_BUNDLE_MESSAGE, tmp_pid); + bundle_add_str(msg, VC_MANAGER_BUNDLE_KEY, key); + bundle_add_str(msg, VC_MANAGER_BUNDLE_PRIVATE_DATA, data); + + + SLOG(LOG_DEBUG, TAG_VCD, ">>>> VCD SEND MESSAGE"); + + __send_msg(msg, VCD_CLIENT_TYPE_MANAGER); + bundle_free(msg); + + return VCD_ERROR_NONE; +} + +int vcdc_send_feedback_audio_format_to_manager(int manager_pid, int rate, vc_audio_channel_e channel, vce_audio_type_e audio_type) +{ + SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Send feedback audio format to manager"); + + char tmp_rate[10] = {0, }; + char tmp_channel[10] = {0, }; + char tmp_audio_type[10] = {0, }; - if (0 != vcd_client_widget_set_tidl_notify_cb(pid, notify_callback, user_data)) { - SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to set notify callback"); - } else { - SLOG(LOG_INFO, TAG_VCD, "[TIDL] Succeed to set notify callback."); - } + bundle* msg = bundle_create(); + snprintf(tmp_rate, 10, "%d", rate); + snprintf(tmp_channel, 10, "%d", (int)channel); + snprintf(tmp_audio_type, 10, "%d", (int)audio_type); + bundle_add_str(msg, VC_MANAGER_BUNDLE_METHOD, VCD_MANAGER_METHOD_FEEDBACK_AUDIO_FORMAT); + bundle_add_str(msg, VC_MANAGER_BUNDLE_AUDIO_RATE, tmp_rate); + bundle_add_str(msg, VC_MANAGER_BUNDLE_AUDIO_CHANNEL, tmp_channel); + bundle_add_str(msg, VC_MANAGER_BUNDLE_AUDIO_TYPE, tmp_audio_type); - pthread_mutex_unlock(&g_widget_tidl_info_mutex); + SLOG(LOG_DEBUG, TAG_VCD, ">>>> VCD SEND MESSAGE"); - __request_tidl_connect(VCD_CLIENT_TYPE_WIDGET, pid); + __send_msg(msg, VCD_CLIENT_TYPE_MANAGER); + bundle_free(msg); - SLOG(LOG_DEBUG, TAG_VCD, "@@@"); + return VCD_ERROR_NONE; } -static int __vc_widget_initialize_cb(rpc_port_stub_vc_widget_context_h context, int pid, int *service_state, int *daemon_pid, void *user_data) +int vcdc_send_feedback_streaming_to_manager(int manager_pid, int pid, int utt_id, vc_feedback_event_e event, char* buffer, int len) { - SLOG(LOG_INFO, TAG_VCD, "@@@ VCD Widget Initialize"); + SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Send feedback streaming to manager"); - uintptr_t ptr_pid = pid; - int ret = -1; + char tmp_pid[10] = {0, }; + char tmp_utt_id[10] = {0, }; + char tmp_event[10] = {0, }; - rpc_port_stub_vc_widget_context_set_tag(context, (void*)ptr_pid); + bundle* msg = bundle_create(); + snprintf(tmp_pid, 10, "%d", pid); + snprintf(tmp_utt_id, 10, "%d", utt_id); + snprintf(tmp_event, 10, "%d", (int)event); + bundle_add_str(msg, VC_MANAGER_BUNDLE_METHOD, VCD_MANAGER_METHOD_FEEDBACK_STREAMING); + bundle_add_str(msg, VC_MANAGER_BUNDLE_MESSAGE, tmp_pid); + bundle_add_str(msg, VC_MANAGER_BUNDLE_UTTID, tmp_utt_id); + bundle_add_str(msg, VC_MANAGER_BUNDLE_EVENT, tmp_event); - ret = vcd_server_widget_initialize(pid); - if (0 != ret) { - SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret); - return ret; + rpc_port_stub_array_char_h streaming_data = NULL; + rpc_port_stub_array_char_create(&streaming_data); + if (NULL == streaming_data) { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to create data handle"); + return VCD_ERROR_OUT_OF_MEMORY; } - *service_state = vcd_server_get_service_state(); - *daemon_pid = getpid(); - SLOG(LOG_INFO, TAG_VCD, "[IN] vcd widget initialize : pid(%d) service state(%d) daemon_pid(%d)", pid, *service_state, *daemon_pid); - SLOG(LOG_DEBUG, TAG_VCD, "@@@"); - return ret; -} + if (NULL != buffer && 0 < len) { + rpc_port_stub_array_char_set(streaming_data, (char*)buffer, len); + } else { + SLOG(LOG_ERROR, TAG_VCD, "[TIDL] buffer is empty"); + } -static int __vc_widget_finalize_cb(rpc_port_stub_vc_widget_context_h context, int pid, void *user_data) -{ - SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Widget Finalize"); - SLOG(LOG_INFO, TAG_VCD, "[IN] vcd widget finalize : pid(%d)", pid); + SLOG(LOG_DEBUG, TAG_VCD, ">>>> VCD SEND MESSAGE"); - int ret = -1; + pthread_mutex_lock(&g_mgr_tidl_info_mutex); + SLOG(LOG_INFO, TAG_VCD, "[TIDL] message to manager"); + manager_tidl_info_s* mgr_tidl_info = vcd_client_manager_get_tidl_info(); - ret = vcd_server_widget_finalize(pid); - if (0 != ret) { - SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret); - return ret; + if (NULL == mgr_tidl_info) { + SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to get manager tidl info. pid(%d)", pid); + pthread_mutex_unlock(&g_mgr_tidl_info_mutex); + rpc_port_stub_array_char_destroy(streaming_data); + bundle_free(msg); + return VCD_ERROR_OPERATION_FAILED; } - SLOG(LOG_DEBUG, TAG_VCD, "@@@"); + rpc_port_stub_vc_mgr_send_buffer_cb_h handle = mgr_tidl_info->send_buffer_cb; + if (NULL == handle) { + SLOG(LOG_ERROR, TAG_VCD, "[TIDL] notify callback handle is null"); + pthread_mutex_unlock(&g_mgr_tidl_info_mutex); + rpc_port_stub_array_char_destroy(streaming_data); + bundle_free(msg); + return VCD_ERROR_OPERATION_FAILED; + } - return ret; + if (0 != rpc_port_stub_vc_mgr_send_buffer_cb_invoke(handle, streaming_data, msg)) { + SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to send msg"); + pthread_mutex_unlock(&g_mgr_tidl_info_mutex); + rpc_port_stub_array_char_destroy(streaming_data); + bundle_free(msg); + return VCD_ERROR_OPERATION_FAILED; + } + pthread_mutex_unlock(&g_mgr_tidl_info_mutex); + rpc_port_stub_array_char_destroy(streaming_data); + bundle_free(msg); + + return VCD_ERROR_NONE; } -static int __vc_widget_start_recording_cb(rpc_port_stub_vc_widget_context_h context, int pid, int command, void *user_data) +void vcdc_send_request_set_foreground(int pid, int value) { - SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Widget Start Recording"); - SLOG(LOG_INFO, TAG_VCD, "[IN] vcd widget start recording : pid(%d) command(%d)", pid, command); + SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Set foreground"); - int ret = -1; + manager_tidl_info_s* mgr_tidl_info = vcd_client_manager_get_tidl_info(); - ret = vcd_server_widget_start_recording(pid, command); - if (0 != ret) { - SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret); - return ret; + if (NULL == mgr_tidl_info) { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to get tidl info"); + return; } - SLOG(LOG_DEBUG, TAG_VCD, "@@@"); + if (!mgr_tidl_info->connected) { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Not Connected"); + return; + } - return ret; + rpc_port_proxy_vcd_mgr_invoke_set_foreground(mgr_tidl_info->rpc_h, pid, value); + + SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Request set foreground"); } -static int __vc_widget_start_cb(rpc_port_stub_vc_widget_context_h context, int pid, int silence, void *user_data) +int vcdc_send_request_get_private_data(int pid, const char* key, char** data) { - SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Widget Start"); - SLOG(LOG_INFO, TAG_VCD, "[IN] vcd widget start : pid(%d) silence(%d)", pid, silence); + SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Get private data"); - int ret = -1; + manager_tidl_info_s* mgr_tidl_info = vcd_client_manager_get_tidl_info(); - ret = vcd_server_widget_start(pid, (bool)silence); - if (0 != ret) { - SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret); - return ret; + if (NULL == mgr_tidl_info) { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to get tidl info"); + return VC_ERROR_OPERATION_FAILED; } - SLOG(LOG_DEBUG, TAG_VCD, "@@@"); + if (!mgr_tidl_info->connected) { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Not Connected"); + return VC_ERROR_OPERATION_FAILED; + } - return ret; + char *tmp = NULL; + if (0 != rpc_port_proxy_vcd_mgr_invoke_get_private_data(mgr_tidl_info->rpc_h, pid, key, &tmp)) { + SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Request vcd manager get private data : Fail to invoke message"); + return VC_ERROR_OPERATION_FAILED; + } + SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Request vcd manager get private data : Success"); + + *data = tmp; + + return VC_ERROR_NONE; } -static int __vc_widget_stop_cb(rpc_port_stub_vc_widget_context_h context, int pid, void *user_data) +int vcdc_send_request_auth_enable(int pid) { - SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Widget Stop"); - SLOG(LOG_INFO, TAG_VCD, "[IN] vcd widget stop : pid(%d)", pid); + SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] auth enable"); - int ret = -1; + manager_tidl_info_s* mgr_tidl_info = vcd_client_manager_get_tidl_info(); - ret = vcd_server_widget_stop(pid); - if (0 != ret) { - SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret); - return ret; + if (NULL == mgr_tidl_info) { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to get tidl info"); + return VC_ERROR_OPERATION_FAILED; } - SLOG(LOG_DEBUG, TAG_VCD, "@@@"); + if (!mgr_tidl_info->connected) { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Not Connected"); + return VC_ERROR_OPERATION_FAILED; + } - return ret; + if (0 != rpc_port_proxy_vcd_mgr_invoke_auth_enable(mgr_tidl_info->rpc_h, pid)) { + SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Request auth enable : Fail to invoke message"); + return VC_ERROR_OPERATION_FAILED; + } + SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Request auth enable : Success"); + + return VC_ERROR_NONE; } -static int __vc_widget_cancel_cb(rpc_port_stub_vc_widget_context_h context, int pid, void *user_data) +int vcdc_send_request_auth_disable(int pid) { - SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Widget Cancel"); - SLOG(LOG_INFO, TAG_VCD, "[IN] vcd widget cancel : pid(%d)", pid); + SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] auth disable"); - int ret = -1; + manager_tidl_info_s* mgr_tidl_info = vcd_client_manager_get_tidl_info(); - ret = vcd_server_widget_cancel(pid); - if (0 != ret) { - SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret); - return ret; + if (NULL == mgr_tidl_info) { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to get tidl info"); + return VC_ERROR_OPERATION_FAILED; } - SLOG(LOG_DEBUG, TAG_VCD, "@@@"); + if (!mgr_tidl_info->connected) { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Not Connected"); + return VC_ERROR_OPERATION_FAILED; + } - return ret; + if (0 != rpc_port_proxy_vcd_mgr_invoke_auth_disable(mgr_tidl_info->rpc_h, pid)) { + SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Request auth disable : Fail to invoke message"); + return VC_ERROR_OPERATION_FAILED; + } + SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Request auth disable : Success"); + + return VC_ERROR_NONE; } -static int __vc_widget_enable_asr_result_cb(rpc_port_stub_vc_widget_context_h context, int pid, int enable, void *user_data) +int vcdc_send_request_auth_start(int pid) { - SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Widget Enable Asr Result"); - SLOG(LOG_INFO, TAG_VCD, "[IN] vcd widget enable asr result : pid(%d) enable(%d)", pid, enable); + SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] auth start"); - int ret = -1; + manager_tidl_info_s* mgr_tidl_info = vcd_client_manager_get_tidl_info(); - ret = vcd_server_widget_enable_asr_result(pid, enable); - if (0 != ret) { - SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret); - return ret; + if (NULL == mgr_tidl_info) { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to get tidl info"); + return VC_ERROR_OPERATION_FAILED; } - SLOG(LOG_DEBUG, TAG_VCD, "@@@"); + if (!mgr_tidl_info->connected) { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Not Connected"); + return VC_ERROR_OPERATION_FAILED; + } - return ret; + if (0 != rpc_port_proxy_vcd_mgr_invoke_auth_start(mgr_tidl_info->rpc_h, pid)) { + SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Request auth start : Fail to invoke message"); + return VC_ERROR_OPERATION_FAILED; + } + SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Request auth start : Success"); + + return VC_ERROR_NONE; } -static void __vc_widget_set_foreground_cb(rpc_port_stub_vc_widget_context_h context, int pid, int value, void *user_data) +int vcdc_send_request_auth_stop(int pid) { - SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Widget Set Foreground"); - SLOG(LOG_INFO, TAG_VCD, "[IN] vcd widget set foreground : pid(%d) value(%d)", pid, value); + SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] auth stop"); - int ret = -1; + manager_tidl_info_s* mgr_tidl_info = vcd_client_manager_get_tidl_info(); - ret = vcd_server_set_foreground(pid, value); - if (0 != ret) { - SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret); - return; + if (NULL == mgr_tidl_info) { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to get tidl info"); + return VC_ERROR_OPERATION_FAILED; } - SLOG(LOG_DEBUG, TAG_VCD, "@@@ send request set foreground to manager"); - vcdc_send_request_set_foreground(pid, value); + if (!mgr_tidl_info->connected) { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Not Connected"); + return VC_ERROR_OPERATION_FAILED; + } - SLOG(LOG_DEBUG, TAG_VCD, "@@@"); + if (0 != rpc_port_proxy_vcd_mgr_invoke_auth_stop(mgr_tidl_info->rpc_h, pid)) { + SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Request auth stop : Fail to invoke message"); + return VC_ERROR_OPERATION_FAILED; + } + SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Request auth stop : Success"); - return; + return VC_ERROR_NONE; } -int vcd_widget_tidl_open_connection() +int vcdc_send_request_auth_cancel(int pid) { - SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] vcd_widget_tidl_open_connection"); - - g_widget_callback.create = __vc_widget_create_cb; - g_widget_callback.terminate = __vc_widget_terminate_cb; - g_widget_callback.register_cb = __vc_widget_register_cb_cb; - g_widget_callback.initialize = __vc_widget_initialize_cb; - g_widget_callback.finalize = __vc_widget_finalize_cb; - g_widget_callback.start_recording = __vc_widget_start_recording_cb; - g_widget_callback.start = __vc_widget_start_cb; - g_widget_callback.stop = __vc_widget_stop_cb; - g_widget_callback.cancel = __vc_widget_cancel_cb; - g_widget_callback.enable_asr_result = __vc_widget_enable_asr_result_cb; - g_widget_callback.set_foreground = __vc_widget_set_foreground_cb; + SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] auth cancel"); - int ret = -1; - int count = 0; - while (VC_RETRY_MIN_COUNT >= count) { - ret = rpc_port_stub_vc_widget_register(&g_widget_callback, NULL); - if (0 == ret) { - SLOG(LOG_DEBUG, TAG_VCD, "register callback"); - return VCD_ERROR_NONE; - } - usleep(100000); - count++; + manager_tidl_info_s* mgr_tidl_info = vcd_client_manager_get_tidl_info(); + + if (NULL == mgr_tidl_info) { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to get tidl info"); + return VC_ERROR_OPERATION_FAILED; } - SLOG(LOG_ERROR, TAG_VCD, "Fail to register callback(%d)", ret); - return VCD_ERROR_OPERATION_FAILED; -} + if (!mgr_tidl_info->connected) { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Not Connected"); + return VC_ERROR_OPERATION_FAILED; + } -int vcd_widget_tidl_close_connection() -{ - SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Close connection"); - rpc_port_stub_vc_widget_unregister(); + if (0 != rpc_port_proxy_vcd_mgr_invoke_auth_cancel(mgr_tidl_info->rpc_h, pid)) { + SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Request auth cancel : Fail to invoke message"); + return VC_ERROR_OPERATION_FAILED; + } + SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Request auth cancel : Success"); - return VCD_ERROR_NONE; + return VC_ERROR_NONE; } diff --git a/server/vcd_tidl.h b/server/vcd_tidl.h index 84e61f8..6f339dc 100644 --- a/server/vcd_tidl.h +++ b/server/vcd_tidl.h @@ -30,25 +30,23 @@ extern "C" { // VCD_CLIENT_TYPE_MANAGER // } vcd_client_type_e; -int vcd_tidl_open_connection(); +int vcd_mgr_tidl_open_connection(); -int vcd_tidl_close_connection(); +int vcd_mgr_tidl_close_connection(); int vcdc_tidl_send_hello(int pid, vcd_client_type_e type); -int vcdc_send_set_volume(int manger_pid, float volume); +int vcdc_send_set_volume(int manager_pid, float volume); -int vcdc_send_show_tooltip(int pid, bool show); - -int vcdc_tidl_send_result(int pid, int manager_pid, vcd_client_type_e type); +int vcdc_tidl_send_result(int pid, int manager_pid, int cmd_type); int vcdc_send_pre_result_to_manager(int manager_pid, int event, const char* pre_result); int vcdc_send_specific_engine_result_to_manager(int manager_pid, const char* engine_app_id, const char* event, const char* result); -int vcdc_send_result_to_manager(int manger_pid, int result_type); +int vcdc_send_result_to_manager(int manager_pid, int result_type); -int vcdc_send_speech_detected(int manger_pid); +int vcdc_send_speech_detected(int manager_pid); int vcdc_tidl_send_error(int reason, char *err_msg); @@ -56,20 +54,17 @@ int vcdc_tidl_send_error_to_manager(int manager_pid, int reason, char *err_msg); int vcdc_send_service_state(vcd_state_e state); -int vcdc_send_dialog(int manger_pid, int pid, const char* disp_text, const char* utt_text, int continuous); +int vcdc_send_dialog(int manager_pid, int pid, const char* disp_text, const char* utt_text, int continuous); int vcdc_send_request_set_private_data(int pid, const char* key, const char* data); int vcdc_send_request_get_private_data(int pid, const char* key, char** data); -int vcdc_send_asr_result(int pid, int event, const char* asr_result, int cmd_type, bool* is_consumed); - /* for TTS feedback */ int vcdc_send_feedback_audio_format_to_manager(int manager_pid, int rate, vc_audio_channel_e channel, vce_audio_type_e audio_type); int vcdc_send_feedback_streaming_to_manager(int manager_pid, int pid, int utt_id, vc_feedback_event_e event, char* buffer, int len); - #ifdef __cplusplus } #endif diff --git a/tidl/vc_widget.tidl b/tidl/vc_widget.tidl deleted file mode 100644 index 662afc5..0000000 --- a/tidl/vc_widget.tidl +++ /dev/null @@ -1,14 +0,0 @@ -interface vc_widget { - void notify_cb(bundle msg) delegate; - void register_cb(int pid, notify_cb notify_callback) async; - - int initialize(in int pid, out int service_state, out int daemon_pid); - int finalize(in int pid); - int start_recording(in int pid, in int command); - int start(in int pid, in int silence); - int stop(in int pid); - int cancel(in int pid); - int enable_asr_result(in int pid, in int enable); - - void set_foreground(in int pid, in int value) async; -} \ No newline at end of file diff --git a/tidl/vcd_widget.tidl b/tidl/vcd_widget.tidl deleted file mode 100644 index 9dfcefa..0000000 --- a/tidl/vcd_widget.tidl +++ /dev/null @@ -1,3 +0,0 @@ -interface vcd_widget { - int send_asr_result(in int pid, in int event, string asr_result, out bool is_consumed); -} \ No newline at end of file -- 2.7.4 From ef8eb09a20af1a7cb4da76c8528cfc93c3a6b460 Mon Sep 17 00:00:00 2001 From: Seongmin Park Date: Fri, 29 Apr 2022 05:14:03 +0000 Subject: [PATCH 14/16] Revert "Replace IPC between manager and server from dbus to tidl" This reverts commit 58c72fc9dde94ee12ecae41b579b724c86269eba. Reason for revert: this commit will be re-merged when all dbus replaced to tidl Change-Id: Ic50ef53ff4b1e455464e587a9282f0b1989f5414 --- CMakeLists.txt | 2 +- client/CMakeLists.txt | 3 - client/vc_mgr.c | 90 +- client/vc_mgr_dbus.c | 1875 +++++++++++++++++++++++++++++++++++++++--- client/vc_mgr_dbus.h | 44 + client/vc_mgr_tidl.c | 1204 --------------------------- client/vc_mgr_tidl.h | 85 -- common/vc_defs.h | 26 +- packaging/voice-control.spec | 10 - server/CMakeLists.txt | 3 - server/vcd_client_data.c | 138 ---- server/vcd_client_data.h | 30 - server/vcd_dbus.c | 647 ++++++++++++++- server/vcd_dbus.h | 31 +- server/vcd_dbus_server.c | 848 ++++++++++++++++++- server/vcd_dbus_server.h | 39 + server/vcd_engine_agent.c | 3 +- server/vcd_main.h | 6 - server/vcd_recorder.c | 1 - server/vcd_server.c | 33 +- server/vcd_server.h | 2 +- server/vcd_tidl.c | 1204 --------------------------- server/vcd_tidl.h | 72 -- server/vce.c | 1 - tidl/vc_mgr.tidl | 26 - tidl/vcd_mgr.tidl | 9 - 26 files changed, 3394 insertions(+), 3038 deletions(-) delete mode 100755 client/vc_mgr_tidl.c delete mode 100644 client/vc_mgr_tidl.h delete mode 100644 server/vcd_tidl.c delete mode 100644 server/vcd_tidl.h delete mode 100644 tidl/vc_mgr.tidl delete mode 100644 tidl/vcd_mgr.tidl diff --git a/CMakeLists.txt b/CMakeLists.txt index a180809..d72a322 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -47,7 +47,7 @@ INCLUDE_DIRECTORIES("${CMAKE_SOURCE_DIR}/include") INCLUDE(FindPkgConfig) pkg_check_modules(pkgs REQUIRED aul buxton2 capi-appfw-app-control capi-appfw-app-manager capi-base-common capi-media-audio-io capi-media-sound-manager ecore-wl2 - capi-system-info cynara-client cynara-session dbus-1 db-util dlog ecore glib-2.0 json-glib-1.0 libgum libtzplatform-config libxml-2.0 sqlite3 vconf gmock bundle rpc-port + capi-system-info cynara-client cynara-session dbus-1 db-util dlog ecore glib-2.0 json-glib-1.0 libgum libtzplatform-config libxml-2.0 sqlite3 vconf gmock ) diff --git a/client/CMakeLists.txt b/client/CMakeLists.txt index 5815fa0..29a1049 100644 --- a/client/CMakeLists.txt +++ b/client/CMakeLists.txt @@ -37,9 +37,6 @@ SET(MANAGER_SRCS vc_mgr_client.c vc_mgr_data.cpp vc_mgr_player.c - vc_mgr_tidl.c - vc_mgr_proxy.c - vc_mgr_stub.c vc_mgr_dbus.c ../common/vc_cmd_db.c ../common/vc_command.c diff --git a/client/vc_mgr.c b/client/vc_mgr.c index c02b61b..9c07f62 100755 --- a/client/vc_mgr.c +++ b/client/vc_mgr.c @@ -31,7 +31,6 @@ #include "vc_json_parser.h" #include "vc_main.h" #include "vc_mgr_client.h" -#include "vc_mgr_tidl.h" #include "vc_mgr_dbus.h" #include "vc_mgr_data.h" #include "vc_mgr_player.h" @@ -47,8 +46,7 @@ static Ecore_Timer* g_send_hello_timer = NULL; static Ecore_Timer* g_request_init_timer = NULL; -static int g_dbus_send_hello_count = 0; -static int g_tidl_send_hello_count = 0; +static int g_send_hello_count = 0; static Ecore_Timer* g_m_set_volume_timer = NULL; @@ -278,14 +276,8 @@ int vc_mgr_initialize(void) return VC_ERROR_NONE; } - // TODO: remove dbus after migrate from dbus to tidl done if (0 != vc_mgr_dbus_open_connection()) { - SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to open dbus connection"); - return VC_ERROR_OPERATION_FAILED; - } - - if (0 != vc_mgr_tidl_open_connection()) { - SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to open tidl connection"); + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to open connection"); return VC_ERROR_OPERATION_FAILED; } @@ -332,16 +324,11 @@ int vc_mgr_initialize(void) static void __vc_mgr_internal_unprepare() { - int ret = vc_mgr_tidl_request_finalize(g_vc_m->handle); + int ret = vc_mgr_dbus_request_finalize(g_vc_m->handle); if (0 != ret) { SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to request finalize : %s", __vc_mgr_get_error_code(ret)); } - ret = vc_mgr_dbus_request_finalize(g_vc_m->handle); - if (0 != ret) { - SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to request dbus finalize : %s", __vc_mgr_get_error_code(ret)); - } - vc_mgr_client_set_internal_state(g_vc_m, VC_INTERNAL_STATE_NONE); return; } @@ -416,15 +403,10 @@ int vc_mgr_deinitialize(void) SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to release VC mgr player(%d)", ret); } */ - // TODO: remove dbus after migrate from dbus to tidl done if (0 != vc_mgr_dbus_close_connection()) { SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to close connection"); } - if (0 != vc_mgr_tidl_close_connection()) { - SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to close connection"); - } - SLOG(LOG_ERROR, TAG_VCM, "@@@"); return VC_ERROR_NONE; @@ -452,7 +434,7 @@ static Eina_Bool __request_initialize(void *data) vc_audio_streaming_mode_e streaming_mode; vc_mgr_client_get_audio_streaming_mode(g_vc_m, &streaming_mode); - ret = vc_mgr_tidl_request_initialize(g_vc_m->handle, (int)streaming_mode, &service_state, &foreground, &g_daemon_pid); + ret = vc_mgr_dbus_request_initialize(g_vc_m->handle, (int)streaming_mode, &service_state, &foreground, &g_daemon_pid); if (VC_ERROR_ENGINE_NOT_FOUND == ret) { SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to initialize : %s", __vc_mgr_get_error_code(ret)); @@ -534,30 +516,15 @@ static Eina_Bool __request_initialize(void *data) static Eina_Bool __send_hello_message(void *data) { /* Send hello */ - // TODO: remove dbus after migrate from dbus to tidl done if (0 != vc_mgr_dbus_request_hello()) { - if (g_dbus_send_hello_count == 20) { - g_dbus_send_hello_count = 0; - SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to request hello !! send error to manager"); - __vc_mgr_cb_error(VC_ERROR_TIMED_OUT, -1, "voice_framework.error.vcfw.connect_engine_fail"); - g_send_hello_timer = NULL; - return EINA_FALSE; - } else { - g_dbus_send_hello_count++; - return EINA_TRUE; - } - } - - /* Send hello */ - if (0 != vc_mgr_tidl_request_hello()) { - if (g_tidl_send_hello_count == 20) { - g_tidl_send_hello_count = 0; + if (g_send_hello_count == 20) { + g_send_hello_count = 0; SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to request hello !! send error to manager"); __vc_mgr_cb_error(VC_ERROR_TIMED_OUT, -1, "voice_framework.error.vcfw.connect_engine_fail"); g_send_hello_timer = NULL; return EINA_FALSE; } else { - g_tidl_send_hello_count++; + g_send_hello_count++; return EINA_TRUE; } } @@ -603,8 +570,7 @@ int vc_mgr_prepare(void) } if (NULL == g_send_hello_timer) { - g_dbus_send_hello_count = 0; - g_tidl_send_hello_count = 0; + g_send_hello_count = 0; SLOG(LOG_INFO, TAG_VCM, "[DEBUG] Create a new timer for preparation"); ecore_thread_main_loop_begin(); g_send_hello_timer = ecore_timer_add(0.02, __send_hello_message, NULL); @@ -883,7 +849,7 @@ int vc_mgr_unset_demandable_client_rule(void) int count = 0; int ret = -1; while (0 != ret) { - ret = vc_mgr_tidl_request_demandable_client(g_vc_m->handle); + ret = vc_mgr_dbus_request_demandable_client(g_vc_m->handle); if (0 != ret) { if (VC_ERROR_TIMED_OUT != ret) { SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to request unset client rule to daemon : %s", __vc_mgr_get_error_code(ret)); @@ -1133,7 +1099,7 @@ int vc_mgr_set_command_list(vc_cmd_list_h vc_cmd_list) } else { int count = 0; do { - ret = vc_mgr_tidl_request_set_command(g_vc_m->handle); + ret = vc_mgr_dbus_request_set_command(g_vc_m->handle); if (0 != ret) { if (VC_ERROR_TIMED_OUT != ret) { SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to request set command to daemon : %s", __vc_mgr_get_error_code(ret)); @@ -1184,7 +1150,7 @@ int vc_mgr_unset_command_list(void) int count = 0; int ret = -1; while (0 != ret) { - ret = vc_mgr_tidl_request_unset_command(g_vc_m->handle); + ret = vc_mgr_dbus_request_unset_command(g_vc_m->handle); if (0 != ret) { if (VC_ERROR_TIMED_OUT != ret) { SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to request unset command to daemon : %s", __vc_mgr_get_error_code(ret)); @@ -1270,7 +1236,7 @@ int vc_mgr_set_command_list_from_file(const char* file_path, int type) } else { int count = 0; do { - ret = vc_mgr_tidl_request_set_command(g_vc_m->handle); + ret = vc_mgr_dbus_request_set_command(g_vc_m->handle); if (0 != ret) { if (VC_ERROR_TIMED_OUT != ret) { SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to request set command to daemon : %s", __vc_mgr_get_error_code(ret)); @@ -1388,7 +1354,7 @@ int vc_mgr_set_audio_type(const char* audio_id) /* Request */ while (0 != ret) { - ret = vc_mgr_tidl_request_set_audio_type(g_vc_m->handle, audio_id); + ret = vc_mgr_dbus_request_set_audio_type(g_vc_m->handle, audio_id); if (0 != ret) { if (VC_ERROR_TIMED_OUT != ret) { SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to set audio type : %s", __vc_mgr_get_error_code(ret)); @@ -1464,7 +1430,7 @@ int vc_mgr_get_audio_type(char** audio_id) int ret = -1; int count = 0; while (0 != ret) { - ret = vc_mgr_tidl_request_get_audio_type(g_vc_m->handle, &temp); + ret = vc_mgr_dbus_request_get_audio_type(g_vc_m->handle, &temp); if (0 != ret) { if (VC_ERROR_TIMED_OUT != ret) { SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to get audio type : %s", __vc_mgr_get_error_code(ret)); @@ -1575,7 +1541,7 @@ int vc_mgr_get_current_commands(vc_cmd_list_h* vc_cmd_list) ret = -1; count = 0; while (0 != ret) { - ret = vc_mgr_tidl_request_set_client_info(g_vc_m->handle); + ret = vc_mgr_dbus_request_set_client_info(g_vc_m->handle); if (0 != ret) { if (VC_ERROR_TIMED_OUT != ret) { SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to set client info : %s", __vc_mgr_get_error_code(ret)); @@ -1820,7 +1786,7 @@ int vc_mgr_set_private_data(const char* key, const char* data) } int ret = -1; - ret = vc_mgr_tidl_request_set_private_data(g_vc_m->handle, key, data); + ret = vc_mgr_dbus_request_set_private_data(g_vc_m->handle, key, data); if (0 != ret) { SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to set private data : %s", __vc_mgr_get_error_code(ret)); return ret; @@ -1879,7 +1845,7 @@ int vc_mgr_get_private_data(const char* key, char** data) char* temp = NULL; while (0 != ret) { - ret = vc_mgr_tidl_request_get_private_data(g_vc_m->handle, key, &temp); + ret = vc_mgr_dbus_request_get_private_data(g_vc_m->handle, key, &temp); if (0 != ret) { if (VC_ERROR_TIMED_OUT != ret) { SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to get private data request : %s", __vc_mgr_get_error_code(ret)); @@ -1953,7 +1919,7 @@ int vc_mgr_set_domain(const char* domain) int ret = -1; int count = 0; while (0 != ret) { - ret = vc_mgr_tidl_request_set_domain(g_vc_m->handle, domain); + ret = vc_mgr_dbus_request_set_domain(g_vc_m->handle, domain); if (0 != ret) { if (VC_ERROR_TIMED_OUT != ret) { SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to set domain request : %s", __vc_mgr_get_error_code(ret)); @@ -2023,7 +1989,7 @@ int vc_mgr_do_action(vc_send_event_type_e type, char* send_event) } int ret = -1; - ret = vc_mgr_tidl_request_do_action(g_vc_m->handle, type, send_event); + ret = vc_mgr_dbus_request_do_action(g_vc_m->handle, type, send_event); if (0 != ret) { SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to do action request : %s", __vc_mgr_get_error_code(ret)); return ret; @@ -2083,7 +2049,7 @@ int vc_mgr_send_specific_engine_request(const char* engine_app_id, const char* e } int ret = -1; - ret = vc_mgr_tidl_send_specific_engine_request(g_vc_m->handle, engine_app_id, event, request); + ret = vc_mgr_dbus_send_specific_engine_request(g_vc_m->handle, engine_app_id, event, request); if (0 != ret) { SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to specific engine request : %s", __vc_mgr_get_error_code(ret)); return ret; @@ -2163,7 +2129,7 @@ int vc_mgr_start(bool exclusive_command_option) count = 0; while (0 != ret) { vc_mgr_client_set_internal_state(g_vc_m, VC_INTERNAL_STATE_STARTING); - ret = vc_mgr_tidl_request_start(g_vc_m->handle, (int)recognition_mode, exclusive_command_option, start_by_client, disabled_cmd_type); + ret = vc_mgr_dbus_request_start(g_vc_m->handle, (int)recognition_mode, exclusive_command_option, start_by_client, disabled_cmd_type); if (0 != ret) { if (VC_ERROR_TIMED_OUT != ret) { SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to start request start : %s", __vc_mgr_get_error_code(ret)); @@ -2249,7 +2215,7 @@ int vc_mgr_stop(void) /* do request */ while (0 != ret) { vc_mgr_client_set_internal_state(g_vc_m, VC_INTERNAL_STATE_STOPPING); - ret = vc_mgr_tidl_request_stop(g_vc_m->handle); + ret = vc_mgr_dbus_request_stop(g_vc_m->handle); if (0 != ret) { if (VC_ERROR_TIMED_OUT != ret) { SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to stop request : %s", __vc_mgr_get_error_code(ret)); @@ -2328,7 +2294,7 @@ int vc_mgr_cancel(void) int count = 0; while (0 != ret) { vc_mgr_client_set_internal_state(g_vc_m, VC_INTERNAL_STATE_CANCELING); - ret = vc_mgr_tidl_request_cancel(g_vc_m->handle); + ret = vc_mgr_dbus_request_cancel(g_vc_m->handle); if (0 != ret) { if (VC_ERROR_TIMED_OUT != ret) { SLOG(LOG_DEBUG, TAG_VCM, "[ERROR] Fail to cancel request : %s", __vc_mgr_get_error_code(ret)); @@ -2372,7 +2338,7 @@ static Eina_Bool __vc_mgr_set_volume_timer_cb(void* data) int __vc_mgr_cb_set_volume(float volume) { - // called in vc_mgr_tidl + // called in vc_mgr_dbus g_prev_volume_db = g_volume_db; g_cur_volume_db = volume; @@ -2508,7 +2474,7 @@ int vc_mgr_set_selected_results(vc_cmd_list_h vc_cmd_list) /* Request */ int ret = -1; - ret = vc_mgr_tidl_send_result_selection(g_vc_m->handle); + ret = vc_mgr_dbus_send_result_selection(g_vc_m->handle); if (0 != ret) { SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to send result selection : %s", __vc_mgr_get_error_code(ret)); return ret; @@ -4535,7 +4501,7 @@ int vc_mgr_send_audio_streaming(vc_audio_streaming_event_e event, unsigned char* float volume = __get_volume_decibel((char*)buffer, len); __vc_mgr_set_volume(volume); - ret = vc_mgr_tidl_send_audio_streaming(g_vc_m->handle, event, buffer, len); + ret = vc_mgr_dbus_send_audio_streaming(g_vc_m->handle, event, buffer, len); if (0 != ret) SLOG(LOG_WARN, TAG_VCM, "[WARNING] retry to send audio streaming data"); else @@ -4594,12 +4560,12 @@ int vc_mgr_set_audio_streaming_mode(vc_audio_streaming_mode_e mode) SLOG(LOG_DEBUG, TAG_VCM, "[SUCCESS] Set audio streaming mode in vc mgr client"); } - ret = vc_mgr_tidl_request_set_audio_streaming_mode(g_vc_m->handle, mode); + ret = vc_mgr_dbus_request_set_audio_streaming_mode(g_vc_m->handle, mode); if (VC_ERROR_NONE != ret) { SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to set audio streaming mode : %s", __vc_mgr_get_error_code(ret)); return VC_ERROR_OPERATION_FAILED; } else { - SLOG(LOG_DEBUG, TAG_VCM, "[SUCCESS] Set audio streaming mode in vc mgr tidl"); + SLOG(LOG_DEBUG, TAG_VCM, "[SUCCESS] Set audio streaming mode in vc mgr dbus"); } } else { SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Invalid State: Current state is not 'INITIALIZED', state(%d)", state); diff --git a/client/vc_mgr_dbus.c b/client/vc_mgr_dbus.c index c59a3d9..7e2b875 100755 --- a/client/vc_mgr_dbus.c +++ b/client/vc_mgr_dbus.c @@ -23,6 +23,7 @@ static pthread_mutex_t g_m_dbus_mutex = PTHREAD_MUTEX_INITIALIZER; +static int g_m_waiting_time = 3000; static int g_m_waiting_short_time = 200; static bool g_is_connection_opened = false; @@ -31,13 +32,32 @@ static Ecore_Fd_Handler* g_m_fd_handler = NULL; static DBusConnection* g_m_conn_sender = NULL; static DBusConnection* g_m_conn_listener = NULL; +static int g_volume_count = 0; + + +extern void __vc_mgr_cb_all_result(vc_result_type_e type); + +extern void __vc_mgr_cb_pre_result(int event, const char* pre_result); + +extern void __vc_mgr_cb_system_result(); + +extern void __vc_mgr_cb_speech_detected(); + extern int __vc_mgr_cb_error(int reason, int daemon_pid, char* msg); +extern int __vc_mgr_cb_set_volume(float volume); + +extern int __vc_mgr_cb_service_state(int state); + extern int __vc_mgr_cb_set_foreground(int pid, bool value); +extern int __vc_mgr_cb_private_data_set(const char* key, const char* data); + extern int __vc_mgr_cb_private_data_requested(const char* key, char** data); /* for TTS feedback */ +extern int __vc_mgr_cb_feedback_audio_format(int rate, vc_audio_channel_e channel, vc_audio_type_e audio_type); + extern int __vc_mgr_cb_feedback_streaming(int pid, int utt_id, vc_feedback_event_e event, char* buffer, int len); /* Authority */ @@ -51,7 +71,10 @@ extern int __vc_mgr_request_auth_stop(int pid); extern int __vc_mgr_request_auth_cancel(int pid); -// TODO: remove listener event callback +extern int __vc_mgr_cb_dialog(int pid, const char* disp_text, const char* utt_text, bool continuous); + +extern void __vc_mgr_cb_specific_engine_result(const char* engine_app_id, const char* event, const char* result); + static Eina_Bool vc_mgr_listener_event_callback(void* data, Ecore_Fd_Handler *fd_handler) { if (NULL == g_m_conn_listener) return ECORE_CALLBACK_RENEW; @@ -75,7 +98,145 @@ static Eina_Bool vc_mgr_listener_event_callback(void* data, Ecore_Fd_Handler *fd char if_name[64] = {0, }; snprintf(if_name, 64, "%s", VC_MANAGER_SERVICE_INTERFACE); - if (dbus_message_is_signal(msg, if_name, VCC_MANAGER_METHOD_SET_FOREGROUND)) { + if (dbus_message_is_method_call(msg, if_name, VCD_MANAGER_METHOD_HELLO)) { + SLOG(LOG_INFO, TAG_VCM, "@@@ Get Hello"); + int pid = 0; + int response = -1; + + dbus_message_get_args(msg, &err, DBUS_TYPE_INT32, &pid, DBUS_TYPE_INVALID); + if (dbus_error_is_set(&err)) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Dbus Error (%s)", err.message); + dbus_error_free(&err); + } + + if (pid > 0) { + SLOG(LOG_DEBUG, TAG_VCM, "@@ vc mgr get hello : pid(%d) ", pid); + response = 1; + } else { + SLOG(LOG_ERROR, TAG_VCM, "@@ vc mgr get hello : invalid pid "); + } + + DBusMessage *reply = NULL; + reply = dbus_message_new_method_return(msg); + + if (NULL != reply) { + dbus_message_append_args(reply, DBUS_TYPE_INT32, &response, DBUS_TYPE_INVALID); + + if (!dbus_connection_send(g_m_conn_listener, reply, NULL)) + SLOG(LOG_ERROR, TAG_VCM, "@@ vc get hello : fail to send reply"); + else + SLOG(LOG_INFO, TAG_VCM, "@@ vc get hello : result(%d)", response); + + dbus_connection_flush(g_m_conn_listener); + dbus_message_unref(reply); + } else { + SLOG(LOG_ERROR, TAG_VCM, "@@ vc mgr get hello : fail to create reply message"); + } + + SLOG(LOG_DEBUG, TAG_VCM, "@@@"); + } /* VCD_METHOD_HELLO */ + + else if (dbus_message_is_signal(msg, if_name, VCD_MANAGER_METHOD_SET_VOLUME)) { + float volume = 0; + + dbus_message_get_args(msg, &err, DBUS_TYPE_INT32, &volume, DBUS_TYPE_INVALID); + + if (dbus_error_is_set(&err)) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Get arguments error (%s)", err.message); + dbus_error_free(&err); + } + + if (10 == g_volume_count) { + SLOG(LOG_DEBUG, TAG_VCM, "@@@ Set volume"); + SLOG(LOG_DEBUG, TAG_VCM, "@@ vc mgr set volume : volume(%f)", volume); + g_volume_count = 0; + } + + __vc_mgr_cb_set_volume(volume); + g_volume_count++; + + } /* VCD_MANAGER_METHOD_SET_VOLUME */ + + else if (dbus_message_is_method_call(msg, if_name, VCD_MANAGER_METHOD_SET_SERVICE_STATE)) { + int state = 0; + + dbus_message_get_args(msg, &err, DBUS_TYPE_INT32, &state, DBUS_TYPE_INVALID); + if (dbus_error_is_set(&err)) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Get arguments error (%s)", err.message); + dbus_error_free(&err); + } + + SLOG(LOG_INFO, TAG_VCM, "@@ state changed : %d", state); + + __vc_mgr_cb_service_state(state); + + } /* VCD_MANAGER_METHOD_SET_SERVICE_STATE */ + + else if (dbus_message_is_method_call(msg, if_name, VCD_MANAGER_METHOD_SPEECH_DETECTED)) { + SLOG(LOG_INFO, TAG_VCM, "@@@ Get Speech detected"); + + __vc_mgr_cb_speech_detected(); + + SLOG(LOG_DEBUG, TAG_VCM, "@@@"); + + } /* VCD_MANAGER_METHOD_SPEECH_DETECTED */ + + else if (dbus_message_is_method_call(msg, if_name, VCD_MANAGER_METHOD_ALL_RESULT)) { + SLOG(LOG_INFO, TAG_VCM, "@@@ Get All Result"); + int result_type = 0; + + dbus_message_get_args(msg, &err, DBUS_TYPE_INT32, &result_type, DBUS_TYPE_INVALID); + + __vc_mgr_cb_all_result((vc_result_type_e)result_type); + + SLOG(LOG_DEBUG, TAG_VCM, "@@@"); + + } /* VCD_MANAGER_METHOD_ALL_RESULT */ + + else if (dbus_message_is_method_call(msg, if_name, VCD_MANAGER_METHOD_PRE_RESULT)) { + SLOG(LOG_INFO, TAG_VCM, "@@@ Get Pre Result"); + int event; + char* pre_result = NULL; + + dbus_message_get_args(msg, &err, DBUS_TYPE_INT32, &event, DBUS_TYPE_STRING, &pre_result, DBUS_TYPE_INVALID); + + if (NULL != pre_result) { + __vc_mgr_cb_pre_result((vc_pre_result_event_e)event, pre_result); + } + + SLOG(LOG_DEBUG, TAG_VCM, "@@@"); + } /* VCD_MANAGER_METHOD_PRE_RESULT */ + else if (dbus_message_is_method_call(msg, if_name, VCD_MANAGER_METHOD_SPECIFIC_ENGINE_RESULT)) { + SLOG(LOG_INFO, TAG_VCM, "@@@ Get specific engine result"); + char* engine_app_id = NULL; + char* event = NULL; + char* result = NULL; + + dbus_message_get_args(msg, &err, DBUS_TYPE_STRING, &engine_app_id, DBUS_TYPE_STRING, &event, DBUS_TYPE_STRING, &result, DBUS_TYPE_INVALID); + + if (NULL != result) { + gsize decodingSize=0; + gchar *gDecodedResult = (gchar *)g_base64_decode((const gchar *)result, &decodingSize); + if (gDecodedResult) + { + SLOG(LOG_WARN, TAG_VCM, "@@@ Get specific engine result --> %s", gDecodedResult); + __vc_mgr_cb_specific_engine_result(engine_app_id, event, gDecodedResult); + g_free(gDecodedResult); + } + } + + SLOG(LOG_DEBUG, TAG_VCM, "@@@"); + } /* VCD_MANAGER_METHOD_SPECIFIC_ENGINE_RESULT */ + else if (dbus_message_is_method_call(msg, if_name, VCD_MANAGER_METHOD_RESULT)) { + SLOG(LOG_INFO, TAG_VCM, "@@@ Get System Result"); + + __vc_mgr_cb_system_result(); + + SLOG(LOG_DEBUG, TAG_VCM, "@@@"); + + } /* VCD_MANAGER_METHOD_RESULT */ + + else if (dbus_message_is_signal(msg, if_name, VCC_MANAGER_METHOD_SET_FOREGROUND)) { SLOG(LOG_INFO, TAG_VCM, "@@@ Set foreground"); int pid = 0; int value = 0; @@ -95,6 +256,89 @@ static Eina_Bool vc_mgr_listener_event_callback(void* data, Ecore_Fd_Handler *fd SLOG(LOG_DEBUG, TAG_VCM, "@@@"); } /* VCC_MANAGER_METHOD_SET_FOREGROUND */ + else if (dbus_message_is_method_call(msg, if_name, VCD_MANAGER_METHOD_DIALOG)) { + SLOG(LOG_INFO, TAG_VCM, "@@@ Request Dialog"); + int pid = -1; + char* disp_text = NULL; + char* utt_text = NULL; + int tmp_continue; + + dbus_message_get_args(msg, &err, + DBUS_TYPE_INT32, &pid, + DBUS_TYPE_STRING, &disp_text, + DBUS_TYPE_STRING, &utt_text, + DBUS_TYPE_INT32, &tmp_continue, + DBUS_TYPE_INVALID); + + if (!strcmp(disp_text, "NNUULLLL")) + disp_text = NULL; + if (!strcmp(utt_text, "NNUULLLL")) + utt_text = NULL; + + __vc_mgr_cb_dialog(pid, disp_text, utt_text, (bool)tmp_continue); + + SLOG(LOG_DEBUG, TAG_VCM, "@@@"); + + } /* VCD_MANAGER_METHOD_DIALOG */ + + else if (dbus_message_is_signal(msg, if_name, VCD_MANAGER_METHOD_ERROR)) { + SLOG(LOG_INFO, TAG_VCM, "@@@ Get Error"); + int reason; + int daemon_pid; + char* err_msg = NULL; + + dbus_message_get_args(msg, &err, + DBUS_TYPE_INT32, &reason, + DBUS_TYPE_INT32, &daemon_pid, + DBUS_TYPE_STRING, &err_msg, + DBUS_TYPE_INVALID); + + if (dbus_error_is_set(&err)) { + SLOG(LOG_ERROR, TAG_VCM, "@@ vc mgr Get Error message : Get arguments error (%s)", err.message); + dbus_error_free(&err); + } else { + char* temp_msg = NULL; + if (NULL != err_msg && strcmp("#NULL", err_msg)) { + temp_msg = strdup(err_msg); + } + SLOG(LOG_ERROR, TAG_VCM, "@@ vc mgr Get Error message : reason(%d), daemon_pid(%d), msg(%s)", reason, daemon_pid, (temp_msg) ? temp_msg : "NULL"); + __vc_mgr_cb_error(reason, daemon_pid, temp_msg); + if (NULL != temp_msg) { + free(temp_msg); + temp_msg = NULL; + } + } + + SLOG(LOG_DEBUG, TAG_VCM, "@@@"); + } /* VCD_MANAGER_METHOD_ERROR */ + + else if (dbus_message_is_method_call(msg, if_name, VCD_MANAGER_METHOD_SET_PRIVATE_DATA)) { + SLOG(LOG_INFO, TAG_VCM, "@@@ Get request set private data"); + int pid = 0; + char* key = NULL; + char* private_data = NULL; + + dbus_message_get_args(msg, &err, + DBUS_TYPE_INT32, &pid, + DBUS_TYPE_STRING, &key, + DBUS_TYPE_STRING, &private_data, + DBUS_TYPE_INVALID); + + if (dbus_error_is_set(&err)) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Dbus Error (%s)", err.message); + dbus_error_free(&err); + } + + if (pid > 0) { + SLOG(LOG_INFO, TAG_VCM, "@@ vc mgr get request set private data : pid(%d) ", pid); + __vc_mgr_cb_private_data_set(key, private_data); + } else { + SLOG(LOG_ERROR, TAG_VCM, "@@ vc mgr get request set private data : invalid pid "); + } + + SLOG(LOG_DEBUG, TAG_VCM, "@@@"); + } /* VCD_MANAGER_METHOD_SET_PRIVATE_DATA */ + else if (dbus_message_is_method_call(msg, if_name, VCD_MANAGER_METHOD_GET_PRIVATE_DATA)) { SLOG(LOG_INFO, TAG_VCM, "@@@ Get request get private data"); int pid = 0; @@ -141,6 +385,44 @@ static Eina_Bool vc_mgr_listener_event_callback(void* data, Ecore_Fd_Handler *fd SLOG(LOG_DEBUG, TAG_VCM, "@@@"); } /* VCD_MANAGER_METHOD_GET_PRIVATE_DATA */ + else if (dbus_message_is_method_call(msg, if_name, VCD_MANAGER_METHOD_FEEDBACK_AUDIO_FORMAT)) { + SLOG(LOG_INFO, TAG_VCM, "@@@ Get TTS feedback audio format"); + int rate; + vc_audio_channel_e channel; + vc_audio_type_e audio_type; + + dbus_message_get_args(msg, &err, + DBUS_TYPE_INT32, &rate, + DBUS_TYPE_INT32, &channel, + DBUS_TYPE_INT32, &audio_type, + DBUS_TYPE_INVALID); + + __vc_mgr_cb_feedback_audio_format(rate, channel, audio_type); + + SLOG(LOG_INFO, TAG_VCM, "@@@"); + } /* VCD_MANAGER_METHOD_FEEDBACK_AUDIO_FORMAT */ + + else if (dbus_message_is_method_call(msg, if_name, VCD_MANAGER_METHOD_FEEDBACK_STREAMING)) { + SLOG(LOG_INFO, TAG_VCM, "@@@ Get TTS feedback streaming"); + int pid = -1; + int utt_id = -1;; + vc_feedback_event_e event; + char* buffer = NULL; + int len; + + dbus_message_get_args(msg, &err, + DBUS_TYPE_INT32, &pid, + DBUS_TYPE_INT32, &utt_id, + DBUS_TYPE_INT32, &event, + DBUS_TYPE_ARRAY, DBUS_TYPE_BYTE, + &buffer, &len, + DBUS_TYPE_INVALID); + + __vc_mgr_cb_feedback_streaming(pid, utt_id, event, buffer, len); + + SLOG(LOG_INFO, TAG_VCM, "@@@"); + } /* VCD_MANAGER_METHOD_FEEDBACK_STREAMING */ + /* Authority */ else if (dbus_message_is_method_call(msg, if_name, VC_METHOD_AUTH_ENABLE)) { SLOG(LOG_INFO, TAG_VCM, "@@@ Get request auth enable"); @@ -577,7 +859,6 @@ static int __dbus_check() int vc_mgr_dbus_request_hello() { - SLOG(LOG_DEBUG, TAG_VCM, "@@ Request vc hello start"); if (0 != __dbus_check()) { return VC_ERROR_OPERATION_FAILED; } @@ -617,7 +898,6 @@ int vc_mgr_dbus_request_hello() result = VC_ERROR_TIMED_OUT; } - SLOG(LOG_DEBUG, TAG_VCM, "@@ Request vc hello end"); return result; } @@ -647,7 +927,7 @@ static int __dbus_restore_daemon() return ret; } -int vc_mgr_dbus_request_finalize(int pid) +int vc_mgr_dbus_request_initialize(int pid, int audio_streaming_mode, int* service_state, int* foreground, int* daemon_pid) { if (0 != __dbus_check()) { return VC_ERROR_OPERATION_FAILED; @@ -672,123 +952,1526 @@ int vc_mgr_dbus_request_finalize(int pid) return VC_ERROR_OPERATION_FAILED; } - /* remove a rule for daemon error */ - char rule_err[256] = {0, }; - snprintf(rule_err, 256, "sender='org.freedesktop.DBus',path='/org/freedesktop/DBus',interface='org.freedesktop.DBus',member='NameOwnerChanged',type='signal',arg0='%s'", VC_SERVER_SERVICE_INTERFACE); - dbus_bus_remove_match(g_m_conn_listener, rule_err, &err); - dbus_connection_flush(g_m_conn_listener); + DBusMessage* msg; + + msg = dbus_message_new_method_call( + VC_SERVER_SERVICE_NAME, + VC_SERVER_SERVICE_OBJECT_PATH, + VC_SERVER_SERVICE_INTERFACE, + VC_MANAGER_METHOD_INITIALIZE); + + if (NULL == msg) { + SLOG(LOG_ERROR, TAG_VCM, "@@ vc mgr initialize : Fail to make message "); + return VC_ERROR_OPERATION_FAILED; + } else { + SLOG(LOG_INFO, TAG_VCM, "@@ vc mgr initialize : pid(%d)", pid); + } + + dbus_message_append_args(msg, + DBUS_TYPE_INT32, &pid, + DBUS_TYPE_INT32, &audio_streaming_mode, + DBUS_TYPE_INVALID); + + DBusMessage* result_msg; + int result = VC_ERROR_OPERATION_FAILED; + + result_msg = dbus_connection_send_with_reply_and_block(g_m_conn_sender, msg, g_m_waiting_time, &err); + dbus_message_unref(msg); if (dbus_error_is_set(&err)) { - SLOG(LOG_ERROR, TAG_VCM, "Match Error (%s)", err.message); + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Dbus Error (%s)", err.message); dbus_error_free(&err); - return VC_ERROR_OPERATION_FAILED; } - return VC_ERROR_NONE; -} + if (NULL != result_msg) { + int tmp_service_state = 0; + int tmp_foreground = 0; + int tmp_daemon_pid = 0; + dbus_message_get_args(result_msg, &err, + DBUS_TYPE_INT32, &result, + DBUS_TYPE_INT32, &tmp_service_state, + DBUS_TYPE_INT32, &tmp_foreground, + DBUS_TYPE_INT32, &tmp_daemon_pid, + DBUS_TYPE_INVALID); -static DBusMessage* __get_message(int pid, const char* method, int type) -{ - char service_name[64]; - char object_path[64]; - char target_if_name[128]; + if (dbus_error_is_set(&err)) { + SLOG(LOG_ERROR, TAG_VCM, "@@ Get arguments error (%s)", err.message); + dbus_error_free(&err); + result = VC_ERROR_OPERATION_FAILED; + } - memset(service_name, '\0', 64); - memset(object_path, '\0', 64); - memset(target_if_name, '\0', 128); + dbus_message_unref(result_msg); - if (VC_COMMAND_TYPE_FOREGROUND == type || VC_COMMAND_TYPE_BACKGROUND == type) { - snprintf(service_name, 64, "%s%d", VC_CLIENT_SERVICE_NAME, pid); - snprintf(object_path, 64, "%s", VC_CLIENT_SERVICE_OBJECT_PATH); - snprintf(target_if_name, 128, "%s%d", VC_CLIENT_SERVICE_NAME, pid); - } else if (VC_COMMAND_TYPE_WIDGET == type) { - snprintf(service_name, 64, "%s%d", VC_WIDGET_SERVICE_NAME, pid); - snprintf(object_path, 64, "%s", VC_WIDGET_SERVICE_OBJECT_PATH); - snprintf(target_if_name, 128, "%s%d", VC_WIDGET_SERVICE_INTERFACE, pid); + if (0 == result) { + *service_state = tmp_service_state; + *foreground = tmp_foreground; + *daemon_pid = tmp_daemon_pid; + + /* add a rule for daemon error */ + char rule_err[256] = {0, }; + snprintf(rule_err, 256, "sender='org.freedesktop.DBus',path='/org/freedesktop/DBus',interface='org.freedesktop.DBus',member='NameOwnerChanged',type='signal',arg0='%s'", VC_SERVER_SERVICE_INTERFACE); + if (NULL == g_m_conn_listener) { + if (g_is_connection_opened) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] g_m_conn_listener is NULL abnormally"); + return VC_ERROR_OPERATION_FAILED; + } else { + SLOG(LOG_INFO, TAG_VCM, "[INFO] g_m_conn_listener is NULL and DBUS connection was closed"); + return VC_ERROR_NONE; + } + } + dbus_bus_add_match(g_m_conn_listener, rule_err, NULL); + + SLOG(LOG_INFO, TAG_VCM, "@@ vc mgr initialize : result = %d, service state = %d, foreground = %d, daemon_pid = %d", + result, *service_state, *foreground, *daemon_pid); + } else { + SLOG(LOG_ERROR, TAG_VCM, "@@ vc mgr initialize : result = %d", result); + } } else { - return NULL; + SLOG(LOG_ERROR, TAG_VCM, "@@ Result message is NULL "); + vc_mgr_dbus_reconnect(); + result = VC_ERROR_TIMED_OUT; } - SLOG(LOG_INFO, TAG_VCM, "[Dbus] Service(%s) object(%s) if(%s)", service_name, object_path, target_if_name); - - return dbus_message_new_method_call(service_name, object_path, target_if_name, method); + return result; } -// int vc_mgr_dbus_send_result(int pid, int cmd_type, int result_id) -// { -// if (0 != __dbus_check()) { -// return VC_ERROR_OPERATION_FAILED; -// } - -// DBusMessage* msg = NULL; - -// switch (cmd_type) { -// case VC_COMMAND_TYPE_FOREGROUND: -// case VC_COMMAND_TYPE_BACKGROUND: -// msg = __get_message(pid, VCD_METHOD_RESULT, cmd_type); -// break; -// case VC_COMMAND_TYPE_WIDGET: -// msg = __get_message(pid, VCD_WIDGET_METHOD_RESULT, cmd_type); -// break; -// default: -// SLOG(LOG_ERROR, TAG_VCM, "[Dbus ERROR] Command type is NOT valid(%d)", cmd_type); -// return -1; -// } - -// if (NULL == msg) -// SLOG(LOG_ERROR, TAG_VCM, "[Dbus ERROR] Message is NULL"); - -// dbus_message_append_args(msg, DBUS_TYPE_INT32, &result_id, DBUS_TYPE_INVALID); - -// dbus_message_set_no_reply(msg, TRUE); - -// /* send the message and flush the connection */ -// if (1 != dbus_connection_send(g_m_conn_sender, msg, NULL)) { -// SLOG(LOG_ERROR, TAG_VCM, "[Dbus ERROR] Fail to Send"); -// dbus_message_unref(msg); -// return VC_ERROR_OPERATION_FAILED; -// } else { -// SLOG(LOG_INFO, TAG_VCM, "[Dbus] SUCCESS Send"); -// dbus_connection_flush(g_m_conn_sender); -// } - -// dbus_message_unref(msg); -// return 0; -// } - -int vc_mgr_dbus_send_utterance_status(int pid, int utt_id, vc_tts_utterance_status_e utt_status) +int vc_mgr_dbus_request_finalize(int pid) { if (0 != __dbus_check()) { return VC_ERROR_OPERATION_FAILED; } - DBusMessage* msg; - msg = __get_message(pid, VC_MANAGER_METHOD_UTTERANCE_STATUS, VC_COMMAND_TYPE_FOREGROUND); + DBusError err; + dbus_error_init(&err); - if (NULL == msg) { - SLOG(LOG_ERROR, TAG_VCM, "@@ vc send utterance status : Fail to make message"); + bool exist = dbus_bus_name_has_owner(g_m_conn_sender, VC_SERVER_SERVICE_NAME, &err); + if (dbus_error_is_set(&err)) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Dbus Error (%s)", err.message); + dbus_error_free(&err); + } + + int ret; + if (false == exist) { + ret = __dbus_restore_daemon(); + if (VC_ERROR_NONE != ret) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to restore daemon"); + return VC_ERROR_TIMED_OUT; + } return VC_ERROR_OPERATION_FAILED; - } else { - SLOG(LOG_INFO, TAG_VCM, "@@ vc send utterance status : pid(%d), utt_id(%d), utt_status(%d)", pid, utt_id, utt_status); } - dbus_message_append_args(msg, - DBUS_TYPE_INT32, &utt_id, - DBUS_TYPE_INT32, &utt_status, - DBUS_TYPE_INVALID); + /* remove a rule for daemon error */ + char rule_err[256] = {0, }; + snprintf(rule_err, 256, "sender='org.freedesktop.DBus',path='/org/freedesktop/DBus',interface='org.freedesktop.DBus',member='NameOwnerChanged',type='signal',arg0='%s'", VC_SERVER_SERVICE_INTERFACE); + dbus_bus_remove_match(g_m_conn_listener, rule_err, &err); + dbus_connection_flush(g_m_conn_listener); - dbus_message_set_no_reply(msg, TRUE); + if (dbus_error_is_set(&err)) { + SLOG(LOG_ERROR, TAG_VCM, "Match Error (%s)", err.message); + dbus_error_free(&err); + return VC_ERROR_OPERATION_FAILED; + } - /* send the message and flush the connection */ - if (1 != dbus_connection_send(g_m_conn_sender, msg, NULL)) { - SLOG(LOG_ERROR, TAG_VCM, "[Dbus ERROR] Fail to Send"); - dbus_message_unref(msg); + DBusMessage* msg; + + msg = dbus_message_new_method_call( + VC_SERVER_SERVICE_NAME, + VC_SERVER_SERVICE_OBJECT_PATH, + VC_SERVER_SERVICE_INTERFACE, + VC_MANAGER_METHOD_FINALIZE); + + if (NULL == msg) { + SLOG(LOG_ERROR, TAG_VCM, "@@ vc mgr finalize : Fail to make message "); return VC_ERROR_OPERATION_FAILED; } else { - SLOG(LOG_INFO, TAG_VCM, "[Dbus] SUCCESS Send"); - dbus_connection_flush(g_m_conn_sender); + SLOG(LOG_INFO, TAG_VCM, "@@ vc mgr finalize : pid(%d)", pid); } + dbus_message_append_args(msg, DBUS_TYPE_INT32, &pid, DBUS_TYPE_INVALID); + + DBusMessage* result_msg; + int result = VC_ERROR_OPERATION_FAILED; + + result_msg = dbus_connection_send_with_reply_and_block(g_m_conn_sender, msg, g_m_waiting_time, &err); dbus_message_unref(msg); - return 0; -} \ No newline at end of file + + if (dbus_error_is_set(&err)) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Dbus Error (%s)", err.message); + dbus_error_free(&err); + } + + if (NULL != result_msg) { + dbus_message_get_args(result_msg, &err, + DBUS_TYPE_INT32, &result, + DBUS_TYPE_INVALID); + + if (dbus_error_is_set(&err)) { + SLOG(LOG_ERROR, TAG_VCM, "@@ Get arguments error (%s)", err.message); + dbus_error_free(&err); + result = VC_ERROR_OPERATION_FAILED; + } + + dbus_message_unref(result_msg); + + if (0 == result) { + SLOG(LOG_INFO, TAG_VCM, "@@ vc mgr finalize : result = %d", result); + } else { + SLOG(LOG_ERROR, TAG_VCM, "@@ vc mgr finalize : result = %d", result); + } + } else { + SLOG(LOG_ERROR, TAG_VCM, "@@ Result message is NULL "); + vc_mgr_dbus_reconnect(); + result = VC_ERROR_TIMED_OUT; + } + + return result; +} + +int vc_mgr_dbus_request_set_command(int pid) +{ + if (0 != __dbus_check()) { + return VC_ERROR_OPERATION_FAILED; + } + + DBusError err; + dbus_error_init(&err); + + bool exist = dbus_bus_name_has_owner(g_m_conn_sender, VC_SERVER_SERVICE_NAME, &err); + if (dbus_error_is_set(&err)) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Dbus Error (%s)", err.message); + dbus_error_free(&err); + } + + int ret; + if (false == exist) { + ret = __dbus_restore_daemon(); + if (VC_ERROR_NONE != ret) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to restore daemon"); + return VC_ERROR_TIMED_OUT; + } + return VC_ERROR_OPERATION_FAILED; + } + + DBusMessage* msg; + + msg = dbus_message_new_method_call( + VC_SERVER_SERVICE_NAME, + VC_SERVER_SERVICE_OBJECT_PATH, + VC_SERVER_SERVICE_INTERFACE, + VC_MANAGER_METHOD_SET_COMMAND); + + if (NULL == msg) { + SLOG(LOG_ERROR, TAG_VCM, "@@ vc mgr set command : Fail to make message"); + return VC_ERROR_OPERATION_FAILED; + } else { + SLOG(LOG_INFO, TAG_VCM, "@@ vc mgr set command : pid(%d)", pid); + } + + dbus_message_append_args(msg, + DBUS_TYPE_INT32, &pid, + DBUS_TYPE_INVALID); + + DBusMessage* result_msg; + int result = VC_ERROR_OPERATION_FAILED; + + result_msg = dbus_connection_send_with_reply_and_block(g_m_conn_sender, msg, g_m_waiting_time, &err); + dbus_message_unref(msg); + + if (dbus_error_is_set(&err)) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Dbus Error (%s)", err.message); + dbus_error_free(&err); + } + + if (NULL != result_msg) { + dbus_message_get_args(result_msg, &err, + DBUS_TYPE_INT32, &result, + DBUS_TYPE_INVALID); + + if (dbus_error_is_set(&err)) { + SLOG(LOG_ERROR, TAG_VCM, "@@ Get arguments error (%s)", err.message); + dbus_error_free(&err); + result = VC_ERROR_OPERATION_FAILED; + } + dbus_message_unref(result_msg); + + if (0 == result) { + SLOG(LOG_INFO, TAG_VCM, "@@ vc mgr set command : result = %d", result); + } else { + SLOG(LOG_ERROR, TAG_VCM, "@@ vc mgr set command : result = %d", result); + } + } else { + SLOG(LOG_ERROR, TAG_VCM, "@@ Result message is NULL"); + vc_mgr_dbus_reconnect(); + result = VC_ERROR_TIMED_OUT; + } + + return result; +} + +int vc_mgr_dbus_request_unset_command(int pid) +{ + if (0 != __dbus_check()) { + return VC_ERROR_OPERATION_FAILED; + } + + DBusError err; + dbus_error_init(&err); + + bool exist = dbus_bus_name_has_owner(g_m_conn_sender, VC_SERVER_SERVICE_NAME, &err); + if (dbus_error_is_set(&err)) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Dbus Error (%s)", err.message); + dbus_error_free(&err); + } + + int ret; + if (false == exist) { + ret = __dbus_restore_daemon(); + if (VC_ERROR_NONE != ret) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to restore daemon"); + return VC_ERROR_TIMED_OUT; + } + return VC_ERROR_OPERATION_FAILED; + } + + DBusMessage* msg; + + msg = dbus_message_new_method_call( + VC_SERVER_SERVICE_NAME, + VC_SERVER_SERVICE_OBJECT_PATH, + VC_SERVER_SERVICE_INTERFACE, + VC_MANAGER_METHOD_UNSET_COMMAND); + + if (NULL == msg) { + SLOG(LOG_ERROR, TAG_VCM, "@@ vc mgr unset command : Fail to make message"); + return VC_ERROR_OPERATION_FAILED; + } else { + SLOG(LOG_INFO, TAG_VCM, "@@ vc mgr unset command : pid(%d)", pid); + } + + dbus_message_append_args(msg, + DBUS_TYPE_INT32, &pid, + DBUS_TYPE_INVALID); + + DBusMessage* result_msg; + int result = VC_ERROR_OPERATION_FAILED; + + result_msg = dbus_connection_send_with_reply_and_block(g_m_conn_sender, msg, g_m_waiting_time, &err); + dbus_message_unref(msg); + + if (dbus_error_is_set(&err)) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Dbus Error (%s)", err.message); + dbus_error_free(&err); + } + + if (NULL != result_msg) { + dbus_message_get_args(result_msg, &err, + DBUS_TYPE_INT32, &result, + DBUS_TYPE_INVALID); + + if (dbus_error_is_set(&err)) { + SLOG(LOG_ERROR, TAG_VCM, "@@ Get arguments error (%s)", err.message); + dbus_error_free(&err); + result = VC_ERROR_OPERATION_FAILED; + } + dbus_message_unref(result_msg); + + if (0 == result) { + SLOG(LOG_INFO, TAG_VCM, "@@ vc mgr unset command : result = %d", result); + } else { + SLOG(LOG_ERROR, TAG_VCM, "@@ vc mgr unset command : result = %d", result); + } + } else { + SLOG(LOG_ERROR, TAG_VCM, "@@ Result message is NULL"); + vc_mgr_dbus_reconnect(); + result = VC_ERROR_TIMED_OUT; + } + + return result; +} + +int vc_mgr_dbus_request_demandable_client(int pid) +{ + if (0 != __dbus_check()) { + return VC_ERROR_OPERATION_FAILED; + } + + DBusError err; + dbus_error_init(&err); + + bool exist = dbus_bus_name_has_owner(g_m_conn_sender, VC_SERVER_SERVICE_NAME, &err); + if (dbus_error_is_set(&err)) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Dbus Error (%s)", err.message); + dbus_error_free(&err); + } + + int ret; + if (false == exist) { + ret = __dbus_restore_daemon(); + if (VC_ERROR_NONE != ret) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to restore daemon"); + return VC_ERROR_TIMED_OUT; + } + return VC_ERROR_OPERATION_FAILED; + } + + DBusMessage* msg; + + msg = dbus_message_new_method_call( + VC_SERVER_SERVICE_NAME, + VC_SERVER_SERVICE_OBJECT_PATH, + VC_SERVER_SERVICE_INTERFACE, + VC_MANAGER_METHOD_SET_DEMANDABLE); + + if (NULL == msg) { + SLOG(LOG_ERROR, TAG_VCM, "@@ vc mgr set demandable client : Fail to make message"); + return VC_ERROR_OPERATION_FAILED; + } else { + SLOG(LOG_INFO, TAG_VCM, "@@ vc mgr set demandable client : pid(%d)", pid); + } + + dbus_message_append_args(msg, + DBUS_TYPE_INT32, &pid, + DBUS_TYPE_INVALID); + + DBusMessage* result_msg; + int result = VC_ERROR_OPERATION_FAILED; + + result_msg = dbus_connection_send_with_reply_and_block(g_m_conn_sender, msg, g_m_waiting_time, &err); + dbus_message_unref(msg); + + if (dbus_error_is_set(&err)) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Dbus Error (%s)", err.message); + dbus_error_free(&err); + } + + if (NULL != result_msg) { + dbus_message_get_args(result_msg, &err, + DBUS_TYPE_INT32, &result, + DBUS_TYPE_INVALID); + + if (dbus_error_is_set(&err)) { + SLOG(LOG_ERROR, TAG_VCM, "@@ Get arguments error (%s)", err.message); + dbus_error_free(&err); + result = VC_ERROR_OPERATION_FAILED; + } + dbus_message_unref(result_msg); + + if (0 == result) { + SLOG(LOG_INFO, TAG_VCM, "@@ vc mgr set demandable client : result = %d", result); + } else { + SLOG(LOG_ERROR, TAG_VCM, "@@ vc mgr set demandable client : result = %d", result); + } + } else { + SLOG(LOG_ERROR, TAG_VCM, "@@ Result message is NULL"); + vc_mgr_dbus_reconnect(); + result = VC_ERROR_TIMED_OUT; + } + + return result; +} + +int vc_mgr_dbus_request_set_audio_type(int pid, const char* audio_type) +{ + if (0 != __dbus_check()) { + return VC_ERROR_OPERATION_FAILED; + } + + DBusError err; + dbus_error_init(&err); + + bool exist = dbus_bus_name_has_owner(g_m_conn_sender, VC_SERVER_SERVICE_NAME, &err); + if (dbus_error_is_set(&err)) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Dbus Error (%s)", err.message); + dbus_error_free(&err); + } + + int ret; + if (false == exist) { + ret = __dbus_restore_daemon(); + if (VC_ERROR_NONE != ret) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to restore daemon"); + return VC_ERROR_TIMED_OUT; + } + return VC_ERROR_OPERATION_FAILED; + } + + DBusMessage* msg; + + /* create a signal & check for errors */ + msg = dbus_message_new_method_call( + VC_SERVER_SERVICE_NAME, + VC_SERVER_SERVICE_OBJECT_PATH, + VC_SERVER_SERVICE_INTERFACE, + VC_MANAGER_METHOD_SET_AUDIO_TYPE); + + if (NULL == msg) { + SLOG(LOG_ERROR, TAG_VCM, "@@ vc mgr set audio type : Fail to make message "); + return VC_ERROR_OPERATION_FAILED; + } else { + SLOG(LOG_INFO, TAG_VCM, "@@ vc mgr set audio type : pid(%d), audio type(%s)", pid, audio_type); + } + + dbus_message_append_args(msg, + DBUS_TYPE_INT32, &pid, + DBUS_TYPE_STRING, &(audio_type), + DBUS_TYPE_INVALID); + + DBusMessage* result_msg; + int result = VC_ERROR_OPERATION_FAILED; + + result_msg = dbus_connection_send_with_reply_and_block(g_m_conn_sender, msg, g_m_waiting_time, &err); + dbus_message_unref(msg); + + if (dbus_error_is_set(&err)) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Dbus Error (%s)", err.message); + dbus_error_free(&err); + } + + if (NULL != result_msg) { + dbus_message_get_args(result_msg, &err, + DBUS_TYPE_INT32, &result, + DBUS_TYPE_INVALID); + + if (dbus_error_is_set(&err)) { + SLOG(LOG_ERROR, TAG_VCM, "@@ Get arguments error (%s)", err.message); + dbus_error_free(&err); + result = VC_ERROR_OPERATION_FAILED; + } + dbus_message_unref(result_msg); + + if (0 == result) { + SLOG(LOG_INFO, TAG_VCM, "@@ vc mgr set audio type : result = %d", result); + } else { + SLOG(LOG_ERROR, TAG_VCM, "@@ vc mgr set audio type : result = %d", result); + } + } else { + SLOG(LOG_ERROR, TAG_VCM, "@@ Result Message is NULL"); + vc_mgr_dbus_reconnect(); + result = VC_ERROR_TIMED_OUT; + } + + return result; +} + +int vc_mgr_dbus_request_get_audio_type(int pid, char** audio_type) +{ + if (0 != __dbus_check()) { + return VC_ERROR_OPERATION_FAILED; + } + + DBusError err; + dbus_error_init(&err); + + bool exist = dbus_bus_name_has_owner(g_m_conn_sender, VC_SERVER_SERVICE_NAME, &err); + if (dbus_error_is_set(&err)) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Dbus Error (%s)", err.message); + dbus_error_free(&err); + } + + int ret; + if (false == exist) { + ret = __dbus_restore_daemon(); + if (VC_ERROR_NONE != ret) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to restore daemon"); + return VC_ERROR_TIMED_OUT; + } + return VC_ERROR_OPERATION_FAILED; + } + + DBusMessage* msg; + + /* create a signal & check for errors */ + msg = dbus_message_new_method_call( + VC_SERVER_SERVICE_NAME, + VC_SERVER_SERVICE_OBJECT_PATH, + VC_SERVER_SERVICE_INTERFACE, + VC_MANAGER_METHOD_GET_AUDIO_TYPE); + + if (NULL == msg) { + SLOG(LOG_ERROR, TAG_VCM, "@@ vc mgr get audio type : Fail to make message "); + return VC_ERROR_OPERATION_FAILED; + } else { + SLOG(LOG_INFO, TAG_VCM, "@@ vc mgr get audio type : pid(%d)", pid); + } + + dbus_message_append_args(msg, + DBUS_TYPE_INT32, &pid, + DBUS_TYPE_INVALID); + + + DBusMessage* result_msg; + int result = VC_ERROR_OPERATION_FAILED; + char* temp = NULL; + + result_msg = dbus_connection_send_with_reply_and_block(g_m_conn_sender, msg, g_m_waiting_time, &err); + dbus_message_unref(msg); + + if (dbus_error_is_set(&err)) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Dbus Error (%s)", err.message); + dbus_error_free(&err); + } + + if (NULL != result_msg) { + dbus_message_get_args(result_msg, &err, + DBUS_TYPE_INT32, &result, + DBUS_TYPE_STRING, &temp, + DBUS_TYPE_INVALID); + + if (dbus_error_is_set(&err)) { + SLOG(LOG_ERROR, TAG_VCM, "@@ Get arguments error (%s)", err.message); + dbus_error_free(&err); + result = VC_ERROR_OPERATION_FAILED; + } + dbus_message_unref(result_msg); + + if (0 == result) { + if (NULL != audio_type && NULL != temp) { + *audio_type = strdup(temp); + } + SLOG(LOG_INFO, TAG_VCM, "@@ vc mgr get audio type : result = %d audio type = %s", result, temp); + } else { + SLOG(LOG_ERROR, TAG_VCM, "@@ vc mgr get audio type : result = %d", result); + } + } else { + SLOG(LOG_ERROR, TAG_VCM, "@@ Result Message is NULL"); + vc_mgr_dbus_reconnect(); + result = VC_ERROR_TIMED_OUT; + } + + return result; +} + +int vc_mgr_dbus_request_set_private_data(int pid, const char* key, const char* data) +{ + if (0 != __dbus_check()) { + return VC_ERROR_OPERATION_FAILED; + } + + DBusMessage* msg; + + /* create a signal & check for errors */ + msg = dbus_message_new_method_call( + VC_SERVER_SERVICE_NAME, + VC_SERVER_SERVICE_OBJECT_PATH, /* object name of the signal */ + VC_SERVER_SERVICE_INTERFACE, /* interface name of the signal */ + VC_MANAGER_METHOD_SET_PRIVATE_DATA); /* name of the signal */ + + if (NULL == msg) { + SLOG(LOG_ERROR, TAG_VCM, "@@ vc set private data : Fail to make message "); + return VC_ERROR_OPERATION_FAILED; + } else { + SLOG(LOG_INFO, TAG_VCM, "@@ vc set private data : pid(%d), data(%s)", pid, data); + } + + dbus_message_append_args(msg, + DBUS_TYPE_INT32, &pid, + DBUS_TYPE_STRING, &key, + DBUS_TYPE_STRING, &data, + DBUS_TYPE_INVALID); + + dbus_message_set_no_reply(msg, TRUE); + + /* send the message and flush the connection */ + if (1 != dbus_connection_send(g_m_conn_sender, msg, NULL)) { + SLOG(LOG_ERROR, TAG_VCM, "[Dbus ERROR] Fail to send private data"); + dbus_message_unref(msg); + return VC_ERROR_OPERATION_FAILED; + } else { + SLOG(LOG_ERROR, TAG_VCM, "[Dbus] Success to send private data"); + dbus_connection_flush(g_m_conn_sender); + } + + dbus_message_unref(msg); + + return VC_ERROR_NONE; +} + +int vc_mgr_dbus_request_get_private_data(int pid, const char* key, char** data) +{ + if (0 != __dbus_check()) { + return VC_ERROR_OPERATION_FAILED; + } + + DBusMessage* msg; + + /* create a signal & check for errors */ + msg = dbus_message_new_method_call( + VC_SERVER_SERVICE_NAME, + VC_SERVER_SERVICE_OBJECT_PATH, + VC_SERVER_SERVICE_INTERFACE, + VC_MANAGER_METHOD_GET_PRIVATE_DATA); + + if (NULL == msg) { + SLOG(LOG_ERROR, TAG_VCM, "@@ vc mgr get private data : Fail to make message "); + return VC_ERROR_OPERATION_FAILED; + } else { + SLOG(LOG_INFO, TAG_VCM, "@@ vc mgr get private data : pid(%d), key(%s)", pid, key); + } + + dbus_message_append_args(msg, + DBUS_TYPE_INT32, &pid, + DBUS_TYPE_STRING, &key, + DBUS_TYPE_INVALID); + + DBusError err; + dbus_error_init(&err); + + DBusMessage* result_msg; + int result = VC_ERROR_OPERATION_FAILED; + char* temp = NULL; + + result_msg = dbus_connection_send_with_reply_and_block(g_m_conn_sender, msg, g_m_waiting_time, &err); + dbus_message_unref(msg); + + if (dbus_error_is_set(&err)) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Dbus Error (%s)", err.message); + dbus_error_free(&err); + } + + if (NULL != result_msg) { + dbus_message_get_args(result_msg, &err, + DBUS_TYPE_INT32, &result, + DBUS_TYPE_STRING, &temp, + DBUS_TYPE_INVALID); + + if (dbus_error_is_set(&err)) { + SLOG(LOG_ERROR, TAG_VCM, "@@ Get arguments error (%s)", err.message); + dbus_error_free(&err); + result = VC_ERROR_OPERATION_FAILED; + } + dbus_message_unref(result_msg); + + if (0 == result) { + if (0 == strncmp(temp, "#NULL", 5)) { + *data = NULL; + } else { + *data = strdup(temp); + } + SLOG(LOG_INFO, TAG_VCM, "@@ vc mgr get private data : result = %d private data = %s", result, *data); + } else { + SLOG(LOG_ERROR, TAG_VCM, "@@ vc mgr get private data : result = %d", result); + } + } else { + SLOG(LOG_INFO, TAG_VCM, "@@ Result Message is NULL"); + vc_mgr_dbus_reconnect(); + result = VC_ERROR_TIMED_OUT; + } + + return result; +} + +int vc_mgr_dbus_request_set_client_info(int pid) +{ + if (0 != __dbus_check()) { + return VC_ERROR_OPERATION_FAILED; + } + + DBusError err; + dbus_error_init(&err); + + bool exist = dbus_bus_name_has_owner(g_m_conn_sender, VC_SERVER_SERVICE_NAME, &err); + if (dbus_error_is_set(&err)) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Dbus Error (%s)", err.message); + dbus_error_free(&err); + } + + int ret; + if (false == exist) { + ret = __dbus_restore_daemon(); + if (VC_ERROR_NONE != ret) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to restore daemon"); + return VC_ERROR_TIMED_OUT; + } + return VC_ERROR_OPERATION_FAILED; + } + + DBusMessage* msg; + + /* create a signal & check for errors */ + msg = dbus_message_new_method_call( + VC_SERVER_SERVICE_NAME, + VC_SERVER_SERVICE_OBJECT_PATH, + VC_SERVER_SERVICE_INTERFACE, + VC_MANAGER_METHOD_SET_CLIENT_INFO); + + if (NULL == msg) { + SLOG(LOG_ERROR, TAG_VCM, "@@ vc mgr set client info : Fail to make message "); + return VC_ERROR_OPERATION_FAILED; + } else { + SLOG(LOG_INFO, TAG_VCM, "@@ vc mgr set client info : pid(%d)", pid); + } + + dbus_message_append_args(msg, + DBUS_TYPE_INT32, &pid, + DBUS_TYPE_INVALID); + + DBusMessage* result_msg; + int result = VC_ERROR_OPERATION_FAILED; + + result_msg = dbus_connection_send_with_reply_and_block(g_m_conn_sender, msg, g_m_waiting_time, &err); + dbus_message_unref(msg); + + if (dbus_error_is_set(&err)) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Dbus Error (%s)", err.message); + dbus_error_free(&err); + } + + if (NULL != result_msg) { + dbus_message_get_args(result_msg, &err, + DBUS_TYPE_INT32, &result, + DBUS_TYPE_INVALID); + + if (dbus_error_is_set(&err)) { + SLOG(LOG_ERROR, TAG_VCM, "@@ Get arguments error (%s)", err.message); + dbus_error_free(&err); + result = VC_ERROR_OPERATION_FAILED; + } + dbus_message_unref(result_msg); + + if (0 == result) { + SLOG(LOG_INFO, TAG_VCM, "@@ vc mgr set client info : result = %d", result); + } else { + SLOG(LOG_ERROR, TAG_VCM, "@@ vc mgr set client info : result = %d", result); + } + } else { + SLOG(LOG_ERROR, TAG_VCM, "@@ Result Message is NULL"); + vc_mgr_dbus_reconnect(); + result = VC_ERROR_TIMED_OUT; + } + + return result; +} + +int vc_mgr_dbus_request_set_domain(int pid, const char* domain) +{ + if (0 != __dbus_check()) { + return VC_ERROR_OPERATION_FAILED; + } + + DBusMessage* msg; + + /* create a signal & check for errors */ + msg = dbus_message_new_method_call( + VC_SERVER_SERVICE_NAME, + VC_SERVER_SERVICE_OBJECT_PATH, /* object name of the signal */ + VC_SERVER_SERVICE_INTERFACE, /* interface name of the signal */ + VC_MANAGER_METHOD_SET_DOMAIN); /* name of the signal */ + + if (NULL == msg) { + SLOG(LOG_ERROR, TAG_VCM, "@@ vc set domain : Fail to make message "); + return VC_ERROR_OPERATION_FAILED; + } else { + SLOG(LOG_INFO, TAG_VCM, "@@ vc set domain : pid(%d), domain(%s)", pid, domain); + } + + dbus_message_append_args(msg, + DBUS_TYPE_INT32, &pid, + DBUS_TYPE_STRING, &domain, + DBUS_TYPE_INVALID); + + DBusError err; + dbus_error_init(&err); + + DBusMessage* result_msg; + int result = VC_ERROR_OPERATION_FAILED; + + result_msg = dbus_connection_send_with_reply_and_block(g_m_conn_sender, msg, g_m_waiting_time, &err); + dbus_message_unref(msg); + + if (dbus_error_is_set(&err)) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Dbus Error (%s)", err.message); + dbus_error_free(&err); + } + + if (NULL != result_msg) { + dbus_message_get_args(result_msg, &err, + DBUS_TYPE_INT32, &result, + DBUS_TYPE_INVALID); + + if (dbus_error_is_set(&err)) { + SLOG(LOG_ERROR, TAG_VCM, "@@ Get arguments error (%s)", err.message); + dbus_error_free(&err); + result = VC_ERROR_OPERATION_FAILED; + } + dbus_message_unref(result_msg); + + if (0 == result) { + SLOG(LOG_INFO, TAG_VCM, "@@ vc set domain : result = %d", result); + } else { + SLOG(LOG_ERROR, TAG_VCM, "@@ vc set domain : result = %d", result); + } + } else { + SLOG(LOG_ERROR, TAG_VCM, "@@ Result Message is NULL"); + vc_mgr_dbus_reconnect(); + result = VC_ERROR_TIMED_OUT; + } + + return result; +} + +int vc_mgr_dbus_request_do_action(int pid, vc_send_event_type_e type, char* send_event) +{ + if (0 != __dbus_check()) { + return VC_ERROR_OPERATION_FAILED; + } + + DBusMessage* msg; + + /* create a signal & check for errors */ + msg = dbus_message_new_method_call( + VC_SERVER_SERVICE_NAME, + VC_SERVER_SERVICE_OBJECT_PATH, /* object name of the signal */ + VC_SERVER_SERVICE_INTERFACE, /* interface name of the signal */ + VC_MANAGER_METHOD_DO_ACTION); /* name of the signal */ + + if (NULL == msg) { + SLOG(LOG_ERROR, TAG_VCM, "@@ vc set domain : Fail to make message "); + return VC_ERROR_OPERATION_FAILED; + } else { + SLOG(LOG_INFO, TAG_VCM, "@@ vc set domain : pid(%d), type(%d), send_event(%s)", pid, type, send_event); + } + + dbus_message_append_args(msg, + DBUS_TYPE_INT32, &pid, + DBUS_TYPE_INT32, &type, + DBUS_TYPE_STRING, &send_event, + DBUS_TYPE_INVALID); + + dbus_message_set_no_reply(msg, TRUE); + + /* send the message and flush the connection */ + if (1 != dbus_connection_send(g_m_conn_sender, msg, NULL)) { + SLOG(LOG_ERROR, TAG_VCM, "[Dbus ERROR] Fail to Send"); + dbus_message_unref(msg); + return VC_ERROR_OPERATION_FAILED; + } else { + SLOG(LOG_INFO, TAG_VCM, "[Dbus] SUCCESS Send"); + dbus_connection_flush(g_m_conn_sender); + } + + dbus_message_unref(msg); + return 0; +} + +int vc_mgr_dbus_request_start(int pid, int recognition_mode, bool exclusive_command_option, bool start_by_client, int disabled_cmd_type) +{ + if (0 != __dbus_check()) { + return VC_ERROR_OPERATION_FAILED; + } + + DBusError err; + dbus_error_init(&err); + + bool exist = dbus_bus_name_has_owner(g_m_conn_sender, VC_SERVER_SERVICE_NAME, &err); + if (dbus_error_is_set(&err)) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Dbus Error (%s)", err.message); + dbus_error_free(&err); + } + + int ret; + if (false == exist) { + ret = __dbus_restore_daemon(); + if (VC_ERROR_NONE != ret) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to restore daemon"); + return VC_ERROR_TIMED_OUT; + } + return VC_ERROR_OPERATION_FAILED; + } + + DBusMessage* msg; + + /* create a signal & check for errors */ + msg = dbus_message_new_method_call( + VC_SERVER_SERVICE_NAME, + VC_SERVER_SERVICE_OBJECT_PATH, + VC_SERVER_SERVICE_INTERFACE, + VC_MANAGER_METHOD_START); + + if (NULL == msg) { + SLOG(LOG_ERROR, TAG_VCM, "@@ vc mgr start : Fail to make message "); + return VC_ERROR_OPERATION_FAILED; + } else { + SLOG(LOG_INFO, TAG_VCM, "@@ vc mgr start : pid(%d), recognition_mode(%d) exclusive(%d) start by client(%d) disabled cmd type(%d)", + pid, recognition_mode, exclusive_command_option, start_by_client, disabled_cmd_type); + } + + int exclusive = (int)exclusive_command_option; + int by = (int)start_by_client; + + dbus_message_append_args(msg, + DBUS_TYPE_INT32, &pid, + DBUS_TYPE_INT32, &(recognition_mode), + DBUS_TYPE_INT32, &(exclusive), + DBUS_TYPE_INT32, &(by), + DBUS_TYPE_INT32, &(disabled_cmd_type), + DBUS_TYPE_INVALID); + + DBusMessage* result_msg; + int result = VC_ERROR_OPERATION_FAILED; + + result_msg = dbus_connection_send_with_reply_and_block(g_m_conn_sender, msg, g_m_waiting_time, &err); + dbus_message_unref(msg); + + if (dbus_error_is_set(&err)) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Dbus Error (%s)", err.message); + dbus_error_free(&err); + } + + if (NULL != result_msg) { + dbus_message_get_args(result_msg, &err, + DBUS_TYPE_INT32, &result, + DBUS_TYPE_INVALID); + + if (dbus_error_is_set(&err)) { + SLOG(LOG_ERROR, TAG_VCM, "@@ Get arguments error (%s)", err.message); + dbus_error_free(&err); + result = VC_ERROR_OPERATION_FAILED; + } + dbus_message_unref(result_msg); + + if (0 == result) { + SLOG(LOG_INFO, TAG_VCM, "@@ vc mgr start : result = %d", result); + } else { + SLOG(LOG_ERROR, TAG_VCM, "@@ vc mgr start : result = %d", result); + } + } else { + SLOG(LOG_ERROR, TAG_VCM, "@@ Result Message is NULL"); + vc_mgr_dbus_reconnect(); + result = VC_ERROR_TIMED_OUT; + } + + return result; +} + +int vc_mgr_dbus_request_stop(int pid) +{ + if (0 != __dbus_check()) { + return VC_ERROR_OPERATION_FAILED; + } + + DBusError err; + dbus_error_init(&err); + + bool exist = dbus_bus_name_has_owner(g_m_conn_sender, VC_SERVER_SERVICE_NAME, &err); + if (dbus_error_is_set(&err)) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Dbus Error (%s)", err.message); + dbus_error_free(&err); + } + + int ret; + if (false == exist) { + ret = __dbus_restore_daemon(); + if (VC_ERROR_NONE != ret) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to restore daemon"); + return VC_ERROR_TIMED_OUT; + } + return VC_ERROR_OPERATION_FAILED; + } + + DBusMessage* msg; + + /* create a signal & check for errors */ + msg = dbus_message_new_method_call( + VC_SERVER_SERVICE_NAME, + VC_SERVER_SERVICE_OBJECT_PATH, + VC_SERVER_SERVICE_INTERFACE, + VC_MANAGER_METHOD_STOP); + + if (NULL == msg) { + SLOG(LOG_ERROR, TAG_VCM, "@@ vc mgr stop : Fail to make message "); + return VC_ERROR_OPERATION_FAILED; + } else { + SLOG(LOG_INFO, TAG_VCM, "@@ vc mgr stop : pid(%d)", pid); + } + + dbus_message_append_args(msg, + DBUS_TYPE_INT32, &pid, + DBUS_TYPE_INVALID); + + DBusMessage* result_msg; + int result = VC_ERROR_OPERATION_FAILED; + + result_msg = dbus_connection_send_with_reply_and_block(g_m_conn_sender, msg, g_m_waiting_time, &err); + dbus_message_unref(msg); + + if (dbus_error_is_set(&err)) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Dbus Error (%s)", err.message); + dbus_error_free(&err); + } + + if (NULL != result_msg) { + dbus_message_get_args(result_msg, &err, + DBUS_TYPE_INT32, &result, + DBUS_TYPE_INVALID); + + if (dbus_error_is_set(&err)) { + SLOG(LOG_ERROR, TAG_VCM, "@@ Get arguments error (%s)", err.message); + dbus_error_free(&err); + result = VC_ERROR_OPERATION_FAILED; + } + dbus_message_unref(result_msg); + + if (0 == result) { + SLOG(LOG_INFO, TAG_VCM, "@@ vc mgr stop : result = %d", result); + } else { + SLOG(LOG_ERROR, TAG_VCM, "@@ vc mgr stop : result = %d", result); + } + } else { + SLOG(LOG_ERROR, TAG_VCM, "@@ Result Message is NULL"); + vc_mgr_dbus_reconnect(); + result = VC_ERROR_TIMED_OUT; + } + + return result; +} + +int vc_mgr_dbus_request_cancel(int pid) +{ + if (0 != __dbus_check()) { + return VC_ERROR_OPERATION_FAILED; + } + + DBusError err; + dbus_error_init(&err); + + bool exist = dbus_bus_name_has_owner(g_m_conn_sender, VC_SERVER_SERVICE_NAME, &err); + if (dbus_error_is_set(&err)) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Dbus Error (%s)", err.message); + dbus_error_free(&err); + } + + int ret; + if (false == exist) { + ret = __dbus_restore_daemon(); + if (VC_ERROR_NONE != ret) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to restore daemon"); + return VC_ERROR_TIMED_OUT; + } + return VC_ERROR_OPERATION_FAILED; + } + + DBusMessage* msg; + + /* create a signal & check for errors */ + msg = dbus_message_new_method_call( + VC_SERVER_SERVICE_NAME, + VC_SERVER_SERVICE_OBJECT_PATH, /* object name of the signal */ + VC_SERVER_SERVICE_INTERFACE, /* interface name of the signal */ + VC_MANAGER_METHOD_CANCEL); /* name of the signal */ + + if (NULL == msg) { + SLOG(LOG_ERROR, TAG_VCM, "@@ vc cancel : Fail to make message "); + return VC_ERROR_OPERATION_FAILED; + } else { + SLOG(LOG_INFO, TAG_VCM, "@@ vc cancel : pid(%d)", pid); + } + + dbus_message_append_args(msg, + DBUS_TYPE_INT32, &pid, + DBUS_TYPE_INVALID); + + DBusMessage* result_msg; + int result = VC_ERROR_OPERATION_FAILED; + + result_msg = dbus_connection_send_with_reply_and_block(g_m_conn_sender, msg, g_m_waiting_time, &err); + dbus_message_unref(msg); + + if (dbus_error_is_set(&err)) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Dbus Error (%s)", err.message); + dbus_error_free(&err); + } + + if (NULL != result_msg) { + dbus_message_get_args(result_msg, &err, + DBUS_TYPE_INT32, &result, + DBUS_TYPE_INVALID); + + if (dbus_error_is_set(&err)) { + SLOG(LOG_ERROR, TAG_VCM, "@@ Get arguments error (%s)", err.message); + dbus_error_free(&err); + result = VC_ERROR_OPERATION_FAILED; + } + dbus_message_unref(result_msg); + + if (0 == result) { + SLOG(LOG_INFO, TAG_VCM, "@@ vc cancel : result = %d", result); + } else { + SLOG(LOG_ERROR, TAG_VCM, "@@ vc cancel : result = %d", result); + } + } else { + SLOG(LOG_ERROR, TAG_VCM, "@@ Result Message is NULL"); + vc_mgr_dbus_reconnect(); + result = VC_ERROR_TIMED_OUT; + } + + return result; +} + +int vc_mgr_dbus_request_set_audio_streaming_mode(int pid, vc_audio_streaming_mode_e mode) +{ + if (0 != __dbus_check()) { + return VC_ERROR_OPERATION_FAILED; + } + + DBusMessage* msg; + + /* create a signal & check for errors */ + msg = dbus_message_new_method_call( + VC_SERVER_SERVICE_NAME, + VC_SERVER_SERVICE_OBJECT_PATH, /* object name of the signal */ + VC_SERVER_SERVICE_INTERFACE, /* interface name of the signal */ + VC_MANAGER_METHOD_SET_AUDIO_STREAMING_MODE); /* name of the signal */ + + if (NULL == msg) { + SLOG(LOG_ERROR, TAG_VCM, "@@ vc mgr set audio streaming mode : Fail to make message "); + return VC_ERROR_OPERATION_FAILED; + } else { + SLOG(LOG_INFO, TAG_VCM, "@@ vc mgr set audio streaming mode : pid(%d) mode(%d)", pid, mode); + } + + dbus_message_append_args(msg, + DBUS_TYPE_INT32, &pid, + DBUS_TYPE_INT32, &mode, + DBUS_TYPE_INVALID); + + dbus_message_set_no_reply(msg, TRUE); + + /* send the message and flush the connection */ + if (1 != dbus_connection_send(g_m_conn_sender, msg, NULL)) { + SLOG(LOG_ERROR, TAG_VCM, "[Dbus ERROR] Fail to set audio streaming mode"); + dbus_message_unref(msg); + return VC_ERROR_OPERATION_FAILED; + } else { + SLOG(LOG_INFO, TAG_VCM, "[Dbus] Success to set audio streaming mode"); + dbus_connection_flush(g_m_conn_sender); + } + + dbus_message_unref(msg); + + return VC_ERROR_NONE; +} + +static DBusMessage* __get_message(int pid, const char* method, int type) +{ + char service_name[64]; + char object_path[64]; + char target_if_name[128]; + + memset(service_name, '\0', 64); + memset(object_path, '\0', 64); + memset(target_if_name, '\0', 128); + + if (VC_COMMAND_TYPE_FOREGROUND == type || VC_COMMAND_TYPE_BACKGROUND == type) { + snprintf(service_name, 64, "%s%d", VC_CLIENT_SERVICE_NAME, pid); + snprintf(object_path, 64, "%s", VC_CLIENT_SERVICE_OBJECT_PATH); + snprintf(target_if_name, 128, "%s%d", VC_CLIENT_SERVICE_NAME, pid); + } else if (VC_COMMAND_TYPE_WIDGET == type) { + snprintf(service_name, 64, "%s%d", VC_WIDGET_SERVICE_NAME, pid); + snprintf(object_path, 64, "%s", VC_WIDGET_SERVICE_OBJECT_PATH); + snprintf(target_if_name, 128, "%s%d", VC_WIDGET_SERVICE_INTERFACE, pid); + } else { + return NULL; + } + + SLOG(LOG_INFO, TAG_VCM, "[Dbus] Service(%s) object(%s) if(%s)", service_name, object_path, target_if_name); + + return dbus_message_new_method_call(service_name, object_path, target_if_name, method); +} + +int vc_mgr_dbus_send_result(int pid, int cmd_type, int result_id) +{ + if (0 != __dbus_check()) { + return VC_ERROR_OPERATION_FAILED; + } + + DBusMessage* msg = NULL; + + switch (cmd_type) { + case VC_COMMAND_TYPE_FOREGROUND: + case VC_COMMAND_TYPE_BACKGROUND: + msg = __get_message(pid, VCD_METHOD_RESULT, cmd_type); + break; + case VC_COMMAND_TYPE_WIDGET: + msg = __get_message(pid, VCD_WIDGET_METHOD_RESULT, cmd_type); + break; + default: + SLOG(LOG_ERROR, TAG_VCM, "[Dbus ERROR] Command type is NOT valid(%d)", cmd_type); + return -1; + } + + if (NULL == msg) + SLOG(LOG_ERROR, TAG_VCM, "[Dbus ERROR] Message is NULL"); + + dbus_message_append_args(msg, DBUS_TYPE_INT32, &result_id, DBUS_TYPE_INVALID); + + dbus_message_set_no_reply(msg, TRUE); + + /* send the message and flush the connection */ + if (1 != dbus_connection_send(g_m_conn_sender, msg, NULL)) { + SLOG(LOG_ERROR, TAG_VCM, "[Dbus ERROR] Fail to Send"); + dbus_message_unref(msg); + return VC_ERROR_OPERATION_FAILED; + } else { + SLOG(LOG_INFO, TAG_VCM, "[Dbus] SUCCESS Send"); + dbus_connection_flush(g_m_conn_sender); + } + + dbus_message_unref(msg); + return 0; +} + +int vc_mgr_dbus_send_result_selection(int pid) +{ + if (0 != __dbus_check()) { + return VC_ERROR_OPERATION_FAILED; + } + + DBusMessage* msg; + + /* create a signal & check for errors */ + msg = dbus_message_new_method_call( + VC_SERVER_SERVICE_NAME, + VC_SERVER_SERVICE_OBJECT_PATH, /* object name of the signal */ + VC_SERVER_SERVICE_INTERFACE, /* interface name of the signal */ + VC_MANAGER_METHOD_RESULT_SELECTION); /* name of the signal */ + + if (NULL == msg) { + SLOG(LOG_ERROR, TAG_VCM, "@@ vc result selection : Fail to make message "); + return VC_ERROR_OPERATION_FAILED; + } else { + SLOG(LOG_INFO, TAG_VCM, "@@ vc result selection : pid(%d)", pid); + } + + dbus_message_append_args(msg, + DBUS_TYPE_INT32, &pid, + DBUS_TYPE_INVALID); + + dbus_message_set_no_reply(msg, TRUE); + + /* send the message and flush the connection */ + if (1 != dbus_connection_send(g_m_conn_sender, msg, NULL)) { + SLOG(LOG_ERROR, TAG_VCM, "[Dbus ERROR] Fail to Send"); + dbus_message_unref(msg); + return VC_ERROR_OPERATION_FAILED; + } else { + SLOG(LOG_INFO, TAG_VCM, "[Dbus] SUCCESS Send"); + dbus_connection_flush(g_m_conn_sender); + } + + dbus_message_unref(msg); + return 0; +} + +int vc_mgr_dbus_send_specific_engine_request(int pid, const char* engine_app_id, const char* event, const char* request) +{ + if (0 != __dbus_check()) { + return VC_ERROR_OPERATION_FAILED; + } + + DBusMessage* msg; + + /* create a signal & check for errors */ + msg = dbus_message_new_method_call( + VC_SERVER_SERVICE_NAME, + VC_SERVER_SERVICE_OBJECT_PATH, /* object name of the signal */ + VC_SERVER_SERVICE_INTERFACE, /* interface name of the signal */ + VC_MANAGER_METHOD_SPECIFIC_ENGINE_REQUEST); /* name of the signal */ + + if (NULL == msg) { + SLOG(LOG_ERROR, TAG_VCM, "@@ vc send specific engine : Fail to make message"); + return VC_ERROR_OPERATION_FAILED; + } else { + SLOG(LOG_INFO, TAG_VCM, "@@ vc send specific engine : pid(%d), engine_app_id(%s), event(%s), request(%s)", pid, engine_app_id, event, request); + } + + gchar *gEncodedRequest = g_base64_encode((const guchar*)request, strlen(request)); + + dbus_message_append_args(msg, + DBUS_TYPE_INT32, &pid, + DBUS_TYPE_STRING, &engine_app_id, + DBUS_TYPE_STRING, &event, + DBUS_TYPE_STRING, &gEncodedRequest, + DBUS_TYPE_INVALID); + + dbus_message_set_no_reply(msg, TRUE); + + /* send the message and flush the connection */ + if (1 != dbus_connection_send(g_m_conn_sender, msg, NULL)) { + SLOG(LOG_ERROR, TAG_VCM, "[Dbus ERROR] Fail to Send"); + if (gEncodedRequest) + g_free(gEncodedRequest); + dbus_message_unref(msg); + return VC_ERROR_OPERATION_FAILED; + } else { + SLOG(LOG_INFO, TAG_VCM, "[Dbus] SUCCESS Send"); + dbus_connection_flush(g_m_conn_sender); + } + + if (gEncodedRequest) + g_free(gEncodedRequest); + dbus_message_unref(msg); + return 0; +} + +int vc_mgr_dbus_send_utterance_status(int pid, int utt_id, vc_tts_utterance_status_e utt_status) +{ + if (0 != __dbus_check()) { + return VC_ERROR_OPERATION_FAILED; + } + + DBusMessage* msg; + msg = __get_message(pid, VC_MANAGER_METHOD_UTTERANCE_STATUS, VC_COMMAND_TYPE_FOREGROUND); + + if (NULL == msg) { + SLOG(LOG_ERROR, TAG_VCM, "@@ vc send utterance status : Fail to make message"); + return VC_ERROR_OPERATION_FAILED; + } else { + SLOG(LOG_INFO, TAG_VCM, "@@ vc send utterance status : pid(%d), utt_id(%d), utt_status(%d)", pid, utt_id, utt_status); + } + + dbus_message_append_args(msg, + DBUS_TYPE_INT32, &utt_id, + DBUS_TYPE_INT32, &utt_status, + DBUS_TYPE_INVALID); + + dbus_message_set_no_reply(msg, TRUE); + + /* send the message and flush the connection */ + if (1 != dbus_connection_send(g_m_conn_sender, msg, NULL)) { + SLOG(LOG_ERROR, TAG_VCM, "[Dbus ERROR] Fail to Send"); + dbus_message_unref(msg); + return VC_ERROR_OPERATION_FAILED; + } else { + SLOG(LOG_INFO, TAG_VCM, "[Dbus] SUCCESS Send"); + dbus_connection_flush(g_m_conn_sender); + } + + dbus_message_unref(msg); + return 0; +} + +int vc_mgr_dbus_send_audio_streaming(int pid, vc_audio_streaming_event_e event, unsigned char* buffer, unsigned int len) +{ + if (0 != __dbus_check()) { + return VC_ERROR_OPERATION_FAILED; + } + + DBusMessage* msg; + msg = dbus_message_new_method_call( + VC_SERVER_SERVICE_NAME, + VC_SERVER_SERVICE_OBJECT_PATH, + VC_SERVER_SERVICE_INTERFACE, + VC_MANAGER_METHOD_SEND_AUDIO_STREAMING); + + if (NULL == msg) { + SLOG(LOG_ERROR, TAG_VCM, "@@ vc send audio streaming : Fail to make message"); + return VC_ERROR_OPERATION_FAILED; + } else { + SLOG(LOG_INFO, TAG_VCM, "@@ vc send audio streaming : pid(%d), event(%d), buffer(%p), len(%d)", pid, event, buffer, len); + } + + dbus_message_append_args(msg, + DBUS_TYPE_INT32, &pid, + DBUS_TYPE_INT32, &event, + DBUS_TYPE_ARRAY, DBUS_TYPE_BYTE, + &buffer, len, + DBUS_TYPE_INVALID); + + dbus_message_set_no_reply(msg, TRUE); + + /* send dbus message and flush the connection */ + if (!dbus_connection_send(g_m_conn_sender, msg, NULL)) { + SLOG(LOG_ERROR, TAG_VCM, "[Dbus ERROR] Fail to send audio streaming"); + } else { + SLOG(LOG_INFO, TAG_VCM, "[Dbus DEBUG] Success to send audio streaming"); + dbus_connection_flush(g_m_conn_sender); + } + + dbus_message_unref(msg); + + return 0; +} + +int vc_mgr_dbus_change_system_volume(int pid, vc_system_volume_event_e volume_event) +{ + if (0 != __dbus_check()) { + return VC_ERROR_OPERATION_FAILED; + } + + DBusError err; + dbus_error_init(&err); + + bool exist = dbus_bus_name_has_owner(g_m_conn_sender, VC_SERVER_SERVICE_NAME, &err); + if (dbus_error_is_set(&err)) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Dbus Error (%s)", err.message); + dbus_error_free(&err); + } + + int ret; + int temp_event = (int)volume_event; + if (false == exist) { + ret = __dbus_restore_daemon(); + if (VC_ERROR_NONE != ret) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to restore daemon"); + return VC_ERROR_TIMED_OUT; + } + return VC_ERROR_OPERATION_FAILED; + } + + DBusMessage* msg; + + /* create a signal & check for errors */ + msg = dbus_message_new_method_call( + VC_SERVER_SERVICE_NAME, + VC_SERVER_SERVICE_OBJECT_PATH, /* object name of the signal */ + VC_SERVER_SERVICE_INTERFACE, /* interface name of the signal */ + VC_MANAGER_METHOD_CHANGE_SYSTEM_VOLUME); /* name of the signal */ + + if (NULL == msg) { + SLOG(LOG_ERROR, TAG_VCM, "@@ vc change system volume : Fail to make message "); + return VC_ERROR_OPERATION_FAILED; + } else { + SLOG(LOG_INFO, TAG_VCM, "@@ vc change system volume : pid(%d) volume_event(%d)", pid, temp_event); + } + + dbus_message_append_args(msg, + DBUS_TYPE_INT32, &pid, + DBUS_TYPE_INT32, &temp_event, + DBUS_TYPE_INVALID); + + DBusMessage* result_msg; + int result = VC_ERROR_OPERATION_FAILED; + + result_msg = dbus_connection_send_with_reply_and_block(g_m_conn_sender, msg, g_m_waiting_time, &err); + dbus_message_unref(msg); + + if (dbus_error_is_set(&err)) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Dbus Error (%s)", err.message); + dbus_error_free(&err); + } + + if (NULL != result_msg) { + dbus_message_get_args(result_msg, &err, + DBUS_TYPE_INT32, &result, + DBUS_TYPE_INVALID); + + if (dbus_error_is_set(&err)) { + SLOG(LOG_ERROR, TAG_VCM, "@@ Get arguments error (%s)", err.message); + dbus_error_free(&err); + result = VC_ERROR_OPERATION_FAILED; + } + dbus_message_unref(result_msg); + + if (0 == result) { + SLOG(LOG_INFO, TAG_VCM, "@@ vc change system volume : result = %d", result); + } else { + SLOG(LOG_ERROR, TAG_VCM, "@@ vc change system volume : result = %d", result); + } + } else { + SLOG(LOG_ERROR, TAG_VCM, "@@ Result Message is NULL"); + vc_mgr_dbus_reconnect(); + result = VC_ERROR_TIMED_OUT; + } + + return result; +} diff --git a/client/vc_mgr_dbus.h b/client/vc_mgr_dbus.h index 4c82e19..c144024 100644 --- a/client/vc_mgr_dbus.h +++ b/client/vc_mgr_dbus.h @@ -32,10 +32,54 @@ int vc_mgr_dbus_close_connection(); int vc_mgr_dbus_request_hello(); +int vc_mgr_dbus_request_initialize(int pid, int audio_streaming_mode, int* service_state, int* foreground, int* daemon_pid); + int vc_mgr_dbus_request_finalize(int pid); +int vc_mgr_dbus_request_set_command(int pid); + +int vc_mgr_dbus_request_unset_command(int pid); + +int vc_mgr_dbus_request_demandable_client(int pid); + +int vc_mgr_dbus_request_set_audio_type(int pid, const char* audio_type); + +int vc_mgr_dbus_request_get_audio_type(int pid, char** audio_type); + +int vc_mgr_dbus_request_set_private_data(int pid, const char* key, const char* data); + +int vc_mgr_dbus_request_get_private_data(int pid, const char* key, char** data); + +int vc_mgr_dbus_request_set_client_info(int pid); + +int vc_mgr_dbus_request_set_domain(int pid, const char* domain); + +int vc_mgr_dbus_request_do_action(int pid, vc_send_event_type_e type, char* send_event); + +int vc_mgr_dbus_request_start(int pid, int recognition_mode, bool exclusive_command_option, bool start_by_client, int disabled_cmd_type); + +int vc_mgr_dbus_request_stop(int pid); + +int vc_mgr_dbus_request_cancel(int pid); + +int vc_mgr_dbus_send_result(int pid, int cmd_type, int result_id); + +int vc_mgr_dbus_send_result_selection(int pid); + +int vc_mgr_dbus_send_specific_engine_request(int pid, const char* engine_app_id, const char* event, const char* request); + +int vc_mgr_dbus_request_start_feedback(int pid); + +int vc_mgr_dbus_request_stop_feedback(int pid); + int vc_mgr_dbus_send_utterance_status(int pid, int utt_id, vc_tts_utterance_status_e utt_status); +int vc_mgr_dbus_send_audio_streaming(int pid, vc_audio_streaming_event_e event, unsigned char* buffer, unsigned int len); + +int vc_mgr_dbus_change_system_volume(int pid, vc_system_volume_event_e volume_event); + +int vc_mgr_dbus_request_set_audio_streaming_mode(int pid, vc_audio_streaming_mode_e mode); + #ifdef __cplusplus } #endif diff --git a/client/vc_mgr_tidl.c b/client/vc_mgr_tidl.c deleted file mode 100755 index fc9781f..0000000 --- a/client/vc_mgr_tidl.c +++ /dev/null @@ -1,1204 +0,0 @@ -/* -* Copyright (c) 2022 Samsung Electronics Co., Ltd All Rights Reserved -* -* Licensed under the Apache License, Version 2.0 (the License); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an AS IS BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include - -#include - -#include "vc_main.h" -#include "vc_mgr_client.h" -#include "vc_mgr_tidl.h" -#include "vc_mgr_proxy.h" -#include "vc_mgr_stub.h" -#include "vc_command.h" - -typedef struct { - bool connected; - bool connection_requesting; - bool register_callback_invoked; - rpc_port_proxy_vc_mgr_h rpc_h; - rpc_port_proxy_vc_mgr_notify_cb_h notify_cb_h; - rpc_port_proxy_vc_mgr_send_buffer_cb_h send_buffer_cb_h; -} vc_mgr_tidl_info_s; - -typedef struct { - bool connected; - bool register_callback_requesting; -} vcd_mgr_tidl_info_s; - -static vc_mgr_tidl_info_s* g_proxy_tidl_info = NULL; - -static vcd_mgr_tidl_info_s* g_stub_tidl_info = NULL; - -static pthread_mutex_t g_tidl_mutex = PTHREAD_MUTEX_INITIALIZER; - -static rpc_port_stub_vcd_mgr_callback_s g_mgr_callback; - -static int g_volume_count = 0; - - -extern void __vc_mgr_cb_all_result(vc_result_type_e type); - -extern void __vc_mgr_cb_pre_result(int event, const char* pre_result); - -extern void __vc_mgr_cb_system_result(); - -extern void __vc_mgr_cb_speech_detected(); - -extern int __vc_mgr_cb_error(int reason, int daemon_pid, char* msg); - -extern int __vc_mgr_cb_set_volume(float volume); - -extern int __vc_mgr_cb_service_state(int state); - -extern int __vc_mgr_cb_set_foreground(int pid, bool value); - -extern int __vc_mgr_cb_private_data_set(const char* key, const char* data); - -extern int __vc_mgr_cb_private_data_requested(const char* key, char** data); - -/* for TTS feedback */ -extern int __vc_mgr_cb_feedback_audio_format(int rate, vc_audio_channel_e channel, vc_audio_type_e audio_type); - -extern int __vc_mgr_cb_feedback_streaming(int pid, int utt_id, vc_feedback_event_e event, char* buffer, int len); - -/* Authority */ -extern int __vc_mgr_request_auth_enable(int pid); - -extern int __vc_mgr_request_auth_disable(int pid); - -extern int __vc_mgr_request_auth_start(int pid); - -extern int __vc_mgr_request_auth_stop(int pid); - -extern int __vc_mgr_request_auth_cancel(int pid); - -extern int __vc_mgr_cb_dialog(int pid, const char* disp_text, const char* utt_text, bool continuous); - -extern void __vc_mgr_cb_specific_engine_result(const char* engine_app_id, const char* event, const char* result); - -static void __notify_cb(void *user_data, bundle *msg) -{ - char *method = NULL; - char *val = NULL; - - SLOG(LOG_DEBUG, TAG_VCM, "__notify_cb is invoked"); - - bundle_get_str(msg, VC_MANAGER_BUNDLE_METHOD, &method); - - if (0 == strncmp(VCD_MANAGER_METHOD_SET_VOLUME, method, strlen(VCD_MANAGER_METHOD_SET_VOLUME))) { - bundle_get_str(msg, VC_MANAGER_BUNDLE_MESSAGE, &val); - float volume = 0; - - if (val) { - volume = atof(val); - } - if (10 == g_volume_count) { - SLOG(LOG_DEBUG, TAG_VCM, "@@@ Set volume"); - SLOG(LOG_DEBUG, TAG_VCM, "@@ vc mgr set volume : volume(%f)", volume); - g_volume_count = 0; - } - - if (val) { - __vc_mgr_cb_set_volume(volume); - g_volume_count++; - } - } /* VCD_MANAGER_METHOD_SET_VOLUME */ - - else if (0 == strncmp(VCD_MANAGER_METHOD_SET_SERVICE_STATE, method, strlen(VCD_MANAGER_METHOD_SET_SERVICE_STATE))) { - bundle_get_str(msg, VC_MANAGER_BUNDLE_MESSAGE, &val); - int state = 0; - if (val) { - state = atoi(val); - SLOG(LOG_INFO, TAG_VCM, "@@ state changed : %d", state); - __vc_mgr_cb_service_state(state); - } - } /* VCD_MANAGER_METHOD_SET_SERVICE_STATE */ - - else if (0 == strncmp(VCD_MANAGER_METHOD_SPEECH_DETECTED, method, strlen(VCD_MANAGER_METHOD_SPEECH_DETECTED))) { - SLOG(LOG_INFO, TAG_VCM, "@@@ Get Speech detected"); - - __vc_mgr_cb_speech_detected(); - - SLOG(LOG_DEBUG, TAG_VCM, "@@@"); - } /* VCD_MANAGER_METHOD_SPEECH_DETECTED */ - - else if (0 == strncmp(VCD_MANAGER_METHOD_ALL_RESULT, method, strlen(VCD_MANAGER_METHOD_ALL_RESULT))) { - SLOG(LOG_INFO, TAG_VCM, "@@@ Get All Result"); - - bundle_get_str(msg, VC_MANAGER_BUNDLE_MESSAGE, &val); - - if (val) { - __vc_mgr_cb_all_result((vc_result_type_e)atoi(val)); - } - - SLOG(LOG_DEBUG, TAG_VCM, "@@@"); - } /* VCD_MANAGER_METHOD_ALL_RESULT */ - - else if (0 == strncmp(VCD_MANAGER_METHOD_PRE_RESULT, method, strlen(VCD_MANAGER_METHOD_PRE_RESULT))) { - SLOG(LOG_INFO, TAG_VCM, "@@@ Get Pre Result"); - char* event = NULL; - char* pre_result = NULL; - - bundle_get_str(msg, VC_MANAGER_BUNDLE_EVENT, &event); - bundle_get_str(msg, VC_MANAGER_BUNDLE_PRE_RESULT, &pre_result); - - if (NULL != pre_result) { - __vc_mgr_cb_pre_result((vc_pre_result_event_e)atoi(event), pre_result); - } - - SLOG(LOG_DEBUG, TAG_VCM, "@@@"); - } /* VCD_MANAGER_METHOD_PRE_RESULT */ - - else if (0 == strncmp(VCD_MANAGER_METHOD_SPECIFIC_ENGINE_RESULT, method, strlen(VCD_MANAGER_METHOD_SPECIFIC_ENGINE_RESULT))) { - SLOG(LOG_INFO, TAG_VCM, "@@@ Get specific engine result"); - char* engine_app_id = NULL; - char* event = NULL; - char* result = NULL; - - bundle_get_str(msg, VC_MANAGER_BUNDLE_ENGINE_APP_ID, &engine_app_id); - bundle_get_str(msg, VC_MANAGER_BUNDLE_EVENT, &event); - bundle_get_str(msg, VC_MANAGER_BUNDLE_RESULT, &result); - - if (NULL != result) { - gsize decodingSize=0; - gchar *gDecodedResult = (gchar *)g_base64_decode((const gchar *)result, &decodingSize); - if (gDecodedResult) - { - SLOG(LOG_WARN, TAG_VCM, "@@@ Get specific engine result --> %s", gDecodedResult); - __vc_mgr_cb_specific_engine_result(engine_app_id, event, gDecodedResult); - g_free(gDecodedResult); - } - } - } /* VCD_MANAGER_METHOD_SPECIFIC_ENGINE_RESULT */ - - else if (0 == strncmp(VCD_MANAGER_METHOD_RESULT, method, strlen(VCD_MANAGER_METHOD_RESULT))) { - SLOG(LOG_INFO, TAG_VCM, "@@@ Get System Result"); - - __vc_mgr_cb_system_result(); - - SLOG(LOG_DEBUG, TAG_VCM, "@@@"); - - } /* VCD_MANAGER_METHOD_RESULT */ - - else if (0 == strncmp(VCD_MANAGER_METHOD_DIALOG, method, strlen(VCD_MANAGER_METHOD_DIALOG))) { - SLOG(LOG_INFO, TAG_VCM, "@@@ Request Dialog"); - char* pid = NULL; - char* disp_text = NULL; - char* utt_text = NULL; - char* continous = NULL; - - bundle_get_str(msg, VC_MANAGER_BUNDLE_MESSAGE, &pid); - bundle_get_str(msg, VC_MANAGER_BUNDLE_DISP_TEXT, &disp_text); - bundle_get_str(msg, VC_MANAGER_BUNDLE_UTT_TEXT, &utt_text); - bundle_get_str(msg, VC_MANAGER_BUNDLE_CONTINUOUS, &continous); - - if (!strncmp(disp_text, "#NULL", strlen("#NULL") + 1)) - disp_text = NULL; - if (!strncmp(utt_text, "#NULL", strlen("#NULL") + 1)) - utt_text = NULL; - - __vc_mgr_cb_dialog(atoi(pid), disp_text, utt_text, (bool)atoi(continous)); - - SLOG(LOG_DEBUG, TAG_VCM, "@@@"); - } /* VCD_MANAGER_METHOD_DIALOG */ - - else if (0 == strncmp(VCD_MANAGER_METHOD_ERROR, method, strlen(VCD_MANAGER_METHOD_ERROR))) { - SLOG(LOG_INFO, TAG_VCM, "@@@ Get Error"); - char* reason = NULL; - char* daemon_pid = NULL; - char* err_msg = NULL; - - bundle_get_str(msg, VC_MANAGER_BUNDLE_REASON, &reason); - bundle_get_str(msg, VC_MANAGER_BUNDLE_DAEMON_PID, &daemon_pid); - bundle_get_str(msg, VC_MANAGER_BUNDLE_ERROR_MESSAGE, &err_msg); - - char* temp_msg = NULL; - if (NULL != err_msg && strncmp(err_msg, "#NULL", strlen("#NULL") + 1)) { - temp_msg = strdup(err_msg); - } - SLOG(LOG_ERROR, TAG_VCM, "@@ vc mgr Get Error message : reason(%d), daemon_pid(%d), msg(%s)", atoi(reason), atoi(daemon_pid), (temp_msg) ? temp_msg : "NULL"); - __vc_mgr_cb_error(atoi(reason), atoi(daemon_pid), temp_msg); - if (NULL != temp_msg) { - free(temp_msg); - temp_msg = NULL; - } - - SLOG(LOG_DEBUG, TAG_VCM, "@@@"); - } /* VCD_MANAGER_METHOD_ERROR */ - - else if (0 == strncmp(VCD_MANAGER_METHOD_SET_PRIVATE_DATA, method, strlen(VCD_MANAGER_METHOD_SET_PRIVATE_DATA))) { - SLOG(LOG_INFO, TAG_VCM, "@@@ Get request set private data"); - char* pid = NULL; - char* key = NULL; - char* private_data = NULL; - - bundle_get_str(msg, VC_MANAGER_BUNDLE_MESSAGE, &pid); - bundle_get_str(msg, VC_MANAGER_BUNDLE_KEY, &key); - bundle_get_str(msg, VC_MANAGER_BUNDLE_PRIVATE_DATA, &private_data); - - SLOG(LOG_INFO, TAG_VCM, "@@ vc mgr get request set private data : pid(%d) ", atoi(pid)); - if (pid > 0) { - __vc_mgr_cb_private_data_set(key, private_data); - } else { - SLOG(LOG_ERROR, TAG_VCM, "@@ got invalid pid(%d)", atoi(pid)); - } - - SLOG(LOG_DEBUG, TAG_VCM, "@@@"); - } /* VCD_MANAGER_METHOD_SET_PRIVATE_DATA */ - - else if (0 == strncmp(VCD_MANAGER_METHOD_FEEDBACK_AUDIO_FORMAT, method, strlen(VCD_MANAGER_METHOD_FEEDBACK_AUDIO_FORMAT))) { - SLOG(LOG_INFO, TAG_VCM, "@@@ Get request feedback audio format"); - char* channel = NULL; - char* audio_type = NULL; - char* rate = NULL; - - bundle_get_str(msg, VC_MANAGER_BUNDLE_AUDIO_CHANNEL, &channel); - bundle_get_str(msg, VC_MANAGER_BUNDLE_AUDIO_TYPE, &audio_type); - bundle_get_str(msg, VC_MANAGER_BUNDLE_AUDIO_RATE, &rate); - - __vc_mgr_cb_feedback_audio_format(atoi(rate), (vc_audio_channel_e)atoi(channel), (vc_audio_type_e)atoi(audio_type)); - - SLOG(LOG_INFO, TAG_VCM, "@@@"); - } /* VCD_MANAGER_METHOD_FEEDBACK_AUDIO_FORMAT */ - - // TODO: uncomment this line after vcc done - // else if (0 == strncmp(VCC_MANAGER_METHOD_SET_FOREGROUND, method, strlen(VCC_MANAGER_METHOD_SET_FOREGROUND))) { - // SLOG(LOG_INFO, TAG_VCM, "@@@ Set foreground"); - // char* temp_pid = NULL; - // char* temp_value = NULL; - // int pid = 0; - // int value = 0; - - // bundle_get_str(msg, VC_MANAGER_BUNDLE_MESSAGE, &temp_pid); - // bundle_get_str(msg, VC_MANAGER_BUNDLE_VALUE, &temp_value); - // pid = atoi(temp_pid); - // value = atoi(temp_value); - - // SLOG(LOG_INFO, TAG_VCM, "@@ foreground changed : pid(%d) value(%s)", pid, value ? "true" : "false"); - - // __vc_mgr_cb_set_foreground(pid, (bool)value); - // SLOG(LOG_DEBUG, TAG_VCM, "@@@"); - // } /* VCC_MANAGER_METHOD_SET_FOREGROUND */ - - else { - SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Invalid msg"); - } - -} - -static void __send_buffer_cb(void *user_data, rpc_port_proxy_array_char_h data_in, bundle *msg) -{ - char *method = NULL; - char *val = NULL; - - SLOG(LOG_DEBUG, TAG_VCM, "__send_buffer_cb is invoked"); - - bundle_get_str(msg, VC_MANAGER_BUNDLE_METHOD, &method); - - if (0 == strncmp(VCD_MANAGER_METHOD_FEEDBACK_STREAMING, method, strlen(VCD_MANAGER_METHOD_FEEDBACK_STREAMING))) { - char *utt_id = NULL; - char *event = NULL; - char* buffer = NULL; - int len = 0; - - bundle_get_str(msg, VC_MANAGER_BUNDLE_MESSAGE, &val); - bundle_get_str(msg, VC_MANAGER_BUNDLE_UTTID, &utt_id); - bundle_get_str(msg, VC_MANAGER_BUNDLE_EVENT, &event); - - rpc_port_proxy_array_char_get(data_in, &buffer, &len); - __vc_mgr_cb_feedback_streaming(atoi(val), atoi(utt_id), atoi(event), buffer, len); - free(buffer); - - SLOG(LOG_INFO, TAG_VCM, "@@@"); - } /* VCD_MANAGER_METHOD_FEEDBACK_STREAMING */ - - else { - SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Invalid msg"); - } - -} - -static void __on_connected(rpc_port_proxy_vc_mgr_h h, void *user_data) -{ - g_proxy_tidl_info->connected = true; - g_proxy_tidl_info->connection_requesting = false; - g_proxy_tidl_info->register_callback_invoked = false; - - SLOG(LOG_INFO, TAG_VCM, "Connected to server"); -} - -static void __on_disconnected(rpc_port_proxy_vc_mgr_h h, void *user_data) -{ - g_proxy_tidl_info->connected = false; - g_proxy_tidl_info->connection_requesting = false; - g_proxy_tidl_info->register_callback_invoked = false; - - SLOG(LOG_INFO, TAG_VCM, "Disonnected to server"); -} - -static void __on_rejected(rpc_port_proxy_vc_mgr_h h, void *user_data) -{ - g_proxy_tidl_info->connection_requesting = false; - g_proxy_tidl_info->register_callback_invoked = false; - - SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Rejected from server"); -} - - -static rpc_port_proxy_vc_mgr_h __create_rpc_port(const char* engine_app_id) -{ - SLOG(LOG_DEBUG, TAG_VCM, "[TIDL] __create_rpc_port"); - rpc_port_proxy_vc_mgr_callback_s rpc_callback = { - .connected = __on_connected, - .disconnected = __on_disconnected, - .rejected = __on_rejected - }; - - rpc_port_proxy_vc_mgr_h handle = NULL; - if (0 != rpc_port_proxy_vc_mgr_create(engine_app_id, &rpc_callback, NULL, &handle)) { - SLOG(LOG_ERROR, TAG_VCM, "[TIDL ERROR] Fail to create proxy"); - return NULL; - } - - return handle; -} - -static void __vcd_mgr_create_cb(rpc_port_stub_vcd_mgr_context_h context, void *user_data) -{ - g_stub_tidl_info->connected = true; - g_stub_tidl_info->register_callback_requesting = false; - - SLOG(LOG_DEBUG, TAG_VCM, "Connected to server"); - - char *sender = NULL; - - rpc_port_stub_vcd_mgr_context_get_sender(context, &sender); - if (!sender) { - SLOG(LOG_ERROR, TAG_VCM, "@@@ Sender is NULL"); - return; - } - - SLOG(LOG_DEBUG, TAG_VCM, "@@@ Server connect. appid(%s)", sender); - free(sender); -} - -static void __vcd_mgr_terminate_cb(rpc_port_stub_vcd_mgr_context_h context, void *user_data) -{ - g_stub_tidl_info->connected = false; - g_stub_tidl_info->register_callback_requesting = false; - - rpc_port_stub_vcd_mgr_context_set_tag(context, NULL); - - char *sender = NULL; - rpc_port_stub_vcd_mgr_context_get_sender(context, &sender); - if (!sender) - return; - - SLOG(LOG_INFO, TAG_VCM, "@@@ Server disconnect. appid(%s)", sender); - free(sender); -} - -static void __vcd_mgr_set_foreground_cb(rpc_port_stub_vcd_mgr_context_h context, int pid, int value, void *user_data) -{ - SLOG(LOG_INFO, TAG_VCM, "@@@ Set foreground"); - SLOG(LOG_INFO, TAG_VCM, "@@ foreground changed : pid(%d) value(%s)", pid, value ? "true" : "false"); - - __vc_mgr_cb_set_foreground(pid, (bool)value); - - SLOG(LOG_DEBUG, TAG_VCM, "@@@"); -} - -static int __vcd_mgr_get_private_data_cb(rpc_port_stub_vcd_mgr_context_h context, int pid, const char *key, char **data, void *user_data) -{ - SLOG(LOG_INFO, TAG_VCM, "@@@ Get request get private data"); - SLOG(LOG_INFO, TAG_VCM, "@@ vc mgr get request get private data : pid(%d) ", pid); - - int ret = -1; - char *temp_data = NULL; - - ret = __vc_mgr_cb_private_data_requested(key, &temp_data); - if (0 != ret) { - SLOG(LOG_ERROR, TAG_VCM, "[OUT ERROR] Result(%d)", ret); - return ret; - } - if (NULL == temp_data) { - SLOG(LOG_INFO, TAG_VCM, "data parameter is NULL"); - temp_data = strdup("#NULL"); - } - *data = temp_data; - SLOG(LOG_DEBUG, TAG_VCM, "@@@"); - - return ret; -} - -static int __vcd_mgr_auth_enable_cb(rpc_port_stub_vcd_mgr_context_h context, int pid, void *user_data) -{ - SLOG(LOG_INFO, TAG_VCM, "@@@ Get request auth enable"); - SLOG(LOG_INFO, TAG_VCM, "@@ vc mgr request auth enable : pid(%d)", pid); - - int ret = -1; - - ret = __vc_mgr_request_auth_enable(pid); - if (0 != ret) { - SLOG(LOG_ERROR, TAG_VCM, "[OUT ERROR] Result(%d)", ret); - } - - SLOG(LOG_DEBUG, TAG_VCM, "@@@"); - - return ret; -} - -static int __vcd_mgr_auth_disable_cb(rpc_port_stub_vcd_mgr_context_h context, int pid, void *user_data) -{ - SLOG(LOG_INFO, TAG_VCM, "@@@ Get request auth disable"); - SLOG(LOG_INFO, TAG_VCM, "@@ vc mgr request auth disable : pid(%d)", pid); - - int ret = -1; - - ret = __vc_mgr_request_auth_disable(pid); - if (0 != ret) { - SLOG(LOG_ERROR, TAG_VCM, "[OUT ERROR] Result(%d)", ret); - } - - SLOG(LOG_DEBUG, TAG_VCM, "@@@"); - - return ret; -} - -static int __vcd_mgr_auth_start_cb(rpc_port_stub_vcd_mgr_context_h context, int pid, void *user_data) -{ - SLOG(LOG_INFO, TAG_VCM, "@@@ Get request auth start"); - SLOG(LOG_INFO, TAG_VCM, "@@ vc mgr request auth start : pid(%d)", pid); - - int ret = -1; - - ret = __vc_mgr_request_auth_start(pid); - if (0 != ret) { - SLOG(LOG_ERROR, TAG_VCM, "[OUT ERROR] Result(%d)", ret); - } - - SLOG(LOG_DEBUG, TAG_VCM, "@@@"); - - return ret; -} - -static int __vcd_mgr_auth_stop_cb(rpc_port_stub_vcd_mgr_context_h context, int pid, void *user_data) -{ - SLOG(LOG_INFO, TAG_VCM, "@@@ Get request auth stop"); - SLOG(LOG_INFO, TAG_VCM, "@@ vc mgr request auth stop : pid(%d)", pid); - - int ret = -1; - - ret = __vc_mgr_request_auth_stop(pid); - if (0 != ret) { - SLOG(LOG_ERROR, TAG_VCM, "[OUT ERROR] Result(%d)", ret); - } - - SLOG(LOG_DEBUG, TAG_VCM, "@@@"); - - return ret; -} - -static int __vcd_mgr_auth_cancel_cb(rpc_port_stub_vcd_mgr_context_h context, int pid, void *user_data) -{ - SLOG(LOG_INFO, TAG_VCM, "@@@ Get request auth cancel"); - SLOG(LOG_INFO, TAG_VCM, "@@ vc mgr request auth cancel : pid(%d)", pid); - - int ret = -1; - - ret = __vc_mgr_request_auth_cancel(pid); - if (0 != ret) { - SLOG(LOG_ERROR, TAG_VCM, "[OUT ERROR] Result(%d)", ret); - } - - SLOG(LOG_DEBUG, TAG_VCM, "@@@"); - - return ret; -} - -static void __register_stub_callback() -{ - if (g_stub_tidl_info->register_callback_requesting) { - return; - } - - SLOG(LOG_DEBUG, TAG_VCM, "[TIDL] __register_stub_callback"); - - g_mgr_callback.create = __vcd_mgr_create_cb; - g_mgr_callback.terminate = __vcd_mgr_terminate_cb; - g_mgr_callback.set_foreground = __vcd_mgr_set_foreground_cb; - g_mgr_callback.get_private_data = __vcd_mgr_get_private_data_cb; - g_mgr_callback.auth_enable = __vcd_mgr_auth_enable_cb; - g_mgr_callback.auth_disable = __vcd_mgr_auth_disable_cb; - g_mgr_callback.auth_start = __vcd_mgr_auth_start_cb; - g_mgr_callback.auth_stop = __vcd_mgr_auth_stop_cb; - g_mgr_callback.auth_cancel = __vcd_mgr_auth_cancel_cb; - - int ret = -1; - ret = rpc_port_stub_vcd_mgr_register(&g_mgr_callback, NULL); - if (0 == ret) { - SLOG(LOG_DEBUG, TAG_VCM, "register callback"); - g_stub_tidl_info->register_callback_requesting = true; - return; - } - - SLOG(LOG_ERROR, TAG_VCM, "Fail to rister callback(%d)", ret); - return; -} - -int vc_mgr_tidl_open_connection() -{ - SLOG(LOG_DEBUG, TAG_VCM, "[TIDL] vc_mgr_tidl_open_connection"); - pthread_mutex_lock(&g_tidl_mutex); - - if (NULL != g_proxy_tidl_info) { - SLOG(LOG_ERROR, TAG_VCM, "[TIDL ERROR] g_proxy_tidl_info already created"); - pthread_mutex_unlock(&g_tidl_mutex); - return VC_ERROR_NONE; - } - - g_proxy_tidl_info = (vc_mgr_tidl_info_s*)calloc(1, sizeof(vc_mgr_tidl_info_s)); - - if (NULL == g_proxy_tidl_info) { - SLOG(LOG_ERROR, TAG_VCM, "[TIDL ERROR] Fail to create vc_mgr_tidl_info_s"); - pthread_mutex_unlock(&g_tidl_mutex); - return VC_ERROR_OUT_OF_MEMORY; - } - - char* engine_app_id = vconf_get_str(VC_ENGINE_DB_DEFAULT); - if (NULL == engine_app_id) { - SLOG(LOG_ERROR, TAG_VCM, "[TIDL] vconf not found"); - pthread_mutex_unlock(&g_tidl_mutex); - return VC_ERROR_ENGINE_NOT_FOUND; - } - - g_proxy_tidl_info->rpc_h = __create_rpc_port(engine_app_id); - if (NULL == g_proxy_tidl_info->rpc_h) { - SLOG(LOG_ERROR, TAG_VCM, "[TIDL ERROR] Fail to create proxy"); - free(engine_app_id); - free(g_proxy_tidl_info); - g_proxy_tidl_info = NULL; - pthread_mutex_unlock(&g_tidl_mutex); - return VC_ERROR_OPERATION_FAILED; - } - - SLOG(LOG_INFO, TAG_VCM, "[TIDL] rpc_h(%p), engine_app_id(%s)", g_proxy_tidl_info->rpc_h, engine_app_id); - free(engine_app_id); - - g_stub_tidl_info = (vcd_mgr_tidl_info_s*)calloc(1, sizeof(vcd_mgr_tidl_info_s)); - - if (NULL == g_stub_tidl_info) { - SLOG(LOG_ERROR, TAG_VCM, "[TIDL ERROR] Fail to create vcd_mgr_tidl_info_s"); - pthread_mutex_unlock(&g_tidl_mutex); - return VC_ERROR_OUT_OF_MEMORY; - } - - __register_stub_callback(); - - pthread_mutex_unlock(&g_tidl_mutex); - - return VC_ERROR_NONE; -} - -int vc_mgr_tidl_close_connection() -{ - SLOG(LOG_DEBUG, TAG_VCM, "[TIDL] vc_mgr_tidl_close_connection"); - pthread_mutex_lock(&g_tidl_mutex); - - if (NULL == g_proxy_tidl_info) { - SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to get tidl info"); - pthread_mutex_unlock(&g_tidl_mutex); - return VC_ERROR_OPERATION_FAILED; - } - - if (0 != rpc_port_proxy_vc_mgr_destroy(g_proxy_tidl_info->rpc_h)) { - SLOG(LOG_ERROR, TAG_VCM, "[TIDL ERROR] Fail to destroy tidl handle"); - pthread_mutex_unlock(&g_tidl_mutex); - return VC_ERROR_OPERATION_FAILED; - } - - g_proxy_tidl_info->rpc_h = NULL; - g_proxy_tidl_info->notify_cb_h = NULL; - g_proxy_tidl_info->send_buffer_cb_h = NULL; - - free(g_proxy_tidl_info); - g_proxy_tidl_info = NULL; - - free(g_stub_tidl_info); - g_stub_tidl_info = NULL; - - pthread_mutex_unlock(&g_tidl_mutex); - - return VC_ERROR_NONE; -} - -static void __request_tidl_connect() -{ - if (g_proxy_tidl_info->connection_requesting) { - return; - } - - int ret = rpc_port_proxy_vc_mgr_connect(g_proxy_tidl_info->rpc_h); - SLOG(LOG_INFO, TAG_VCM, "[INFO] Request connection to stub. ret(%d)", ret); - - if (0 == ret) { - g_proxy_tidl_info->connection_requesting = true; - } -} - -static int __create_callback_handles() -{ - if (NULL != g_proxy_tidl_info->notify_cb_h) { - rpc_port_proxy_vc_mgr_notify_cb_dispose(g_proxy_tidl_info->rpc_h, g_proxy_tidl_info->notify_cb_h); - g_proxy_tidl_info->notify_cb_h = NULL; - } - - if (RPC_PORT_ERROR_NONE != rpc_port_proxy_vc_mgr_notify_cb_create(&g_proxy_tidl_info->notify_cb_h)) { - return VC_ERROR_OUT_OF_MEMORY; - } - - rpc_port_proxy_vc_mgr_notify_cb_set_callback(g_proxy_tidl_info->notify_cb_h, __notify_cb, NULL); - - rpc_port_proxy_vc_mgr_notify_cb_set_once(g_proxy_tidl_info->notify_cb_h, false); - - if (NULL != g_proxy_tidl_info->send_buffer_cb_h) { - rpc_port_proxy_vc_mgr_send_buffer_cb_dispose(g_proxy_tidl_info->rpc_h, g_proxy_tidl_info->send_buffer_cb_h); - g_proxy_tidl_info->send_buffer_cb_h = NULL; - } - - if (RPC_PORT_ERROR_NONE != rpc_port_proxy_vc_mgr_send_buffer_cb_create(&g_proxy_tidl_info->send_buffer_cb_h)) { - return VC_ERROR_OUT_OF_MEMORY; - } - - rpc_port_proxy_vc_mgr_send_buffer_cb_set_callback(g_proxy_tidl_info->send_buffer_cb_h, __send_buffer_cb, NULL); - - rpc_port_proxy_vc_mgr_send_buffer_cb_set_once(g_proxy_tidl_info->send_buffer_cb_h, false); - - return VC_ERROR_NONE; -} - -static int __invoke_register_callback() -{ - if (g_proxy_tidl_info->register_callback_invoked) { - SLOG(LOG_ERROR, TAG_VCM, "[INFO] Already register callback is invoked"); - return VC_ERROR_NONE; - } - - int ret = __create_callback_handles(g_proxy_tidl_info); - if (VC_ERROR_NONE != ret) { - SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to create callback handle. ret(%d)", ret); - return VC_ERROR_OPERATION_FAILED; - } - - rpc_port_proxy_vc_mgr_invoke_register_cb(g_proxy_tidl_info->rpc_h, getpid(), g_proxy_tidl_info->notify_cb_h, g_proxy_tidl_info->send_buffer_cb_h); - g_proxy_tidl_info->register_callback_invoked = true; - return VC_ERROR_NONE; -} - -int vc_mgr_tidl_request_hello() -{ - SLOG(LOG_DEBUG, TAG_VCM, "[TIDL] vc_mgr_tidl_request_hello"); - - if (NULL == g_proxy_tidl_info) { - SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to get proxy tidl info"); - return VC_ERROR_OPERATION_FAILED; - } - - if (!g_proxy_tidl_info->connected) { - SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Proxy Not Connected"); - __request_tidl_connect(); - return VC_ERROR_OPERATION_FAILED; - } - - if (VC_ERROR_NONE != __invoke_register_callback()) { - SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to invoke register callback"); - return VC_ERROR_OPERATION_FAILED; - } - - if (NULL == g_stub_tidl_info) { - SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to get stub tidl info"); - return VC_ERROR_OPERATION_FAILED; - } - - if (!g_stub_tidl_info->connected) { - SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Stub Not Connected"); - __register_stub_callback(); - return VC_ERROR_OPERATION_FAILED; - } - - SLOG(LOG_DEBUG, TAG_VCM, ">>>>> VCM Hello"); - - SLOG(LOG_DEBUG, TAG_VCM, "<<<<"); - - return VC_ERROR_NONE; -} - -int vc_mgr_tidl_request_initialize(int pid, int audio_streaming_mode, int* service_state, int* foreground, int* daemon_pid) -{ - SLOG(LOG_DEBUG, TAG_VCM, "[TIDL] vc_mgr_tidl_request_initialize"); - - if (NULL == g_proxy_tidl_info) { - SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to get tidl info"); - return VC_ERROR_OPERATION_FAILED; - } - - int tmp_service_state = 0; - int tmp_forground = 0; - int tmp_daemon_pid = 0; - - if (!g_proxy_tidl_info->connected) { - SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Not Connected"); - return VC_ERROR_OPERATION_FAILED; - } - - if (0 != rpc_port_proxy_vc_mgr_invoke_initialize(g_proxy_tidl_info->rpc_h, pid, audio_streaming_mode, &tmp_service_state, &tmp_forground, &tmp_daemon_pid)) { - SLOG(LOG_ERROR, TAG_VCM, "[TIDL ERROR] Request vc manager initialize : Fail to invoke message"); - return VC_ERROR_OPERATION_FAILED; - } - - *service_state = tmp_service_state; - *foreground = tmp_forground; - *daemon_pid = tmp_daemon_pid; - - SLOG(LOG_DEBUG, TAG_VCM, "[TIDL] vc manager initialize: service_state(%d), foreground(%d), daemon_pid(%d)", *service_state, *foreground, *daemon_pid); - - return VC_ERROR_NONE; -} - -int vc_mgr_tidl_request_finalize(int pid) -{ - SLOG(LOG_DEBUG, TAG_VCM, "[TIDL] vc_mgr_tidl_request_finalize"); - - if (NULL == g_proxy_tidl_info) { - SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to get tidl info"); - return VC_ERROR_OPERATION_FAILED; - } - - if (!g_proxy_tidl_info->connected) { - SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Not Connected"); - return VC_ERROR_OPERATION_FAILED; - } - - if (0 != rpc_port_proxy_vc_mgr_invoke_finalize(g_proxy_tidl_info->rpc_h, pid)) { - SLOG(LOG_ERROR, TAG_VCM, "[TIDL ERROR] Request vc manager finalize : Fail to invoke message"); - return VC_ERROR_OPERATION_FAILED; - } - - return VC_ERROR_NONE; -} - -int vc_mgr_tidl_request_set_command(int pid) -{ - SLOG(LOG_DEBUG, TAG_VCM, "[TIDL] vc_mgr_tidl_request_set_command"); - - if (NULL == g_proxy_tidl_info) { - SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to get tidl info"); - return VC_ERROR_OPERATION_FAILED; - } - - if (!g_proxy_tidl_info->connected) { - SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Not Connected"); - return VC_ERROR_OPERATION_FAILED; - } - - if (0 != rpc_port_proxy_vc_mgr_invoke_set_command(g_proxy_tidl_info->rpc_h, pid)) { - SLOG(LOG_ERROR, TAG_VCM, "[TIDL ERROR] Request vc manager set command : Fail to invoke message"); - return VC_ERROR_OPERATION_FAILED; - } - - return VC_ERROR_NONE; -} - -int vc_mgr_tidl_request_unset_command(int pid) -{ - SLOG(LOG_DEBUG, TAG_VCM, "[TIDL] vc_mgr_tidl_request_unset_command"); - - if (NULL == g_proxy_tidl_info) { - SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to get tidl info"); - return VC_ERROR_OPERATION_FAILED; - } - - if (!g_proxy_tidl_info->connected) { - SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Not Connected"); - return VC_ERROR_OPERATION_FAILED; - } - - if (0 != rpc_port_proxy_vc_mgr_invoke_unset_command(g_proxy_tidl_info->rpc_h, pid)) { - SLOG(LOG_ERROR, TAG_VCM, "[TIDL ERROR] Request vc manager unset command : Fail to invoke message"); - return VC_ERROR_OPERATION_FAILED; - } - - return VC_ERROR_NONE; -} - -int vc_mgr_tidl_request_demandable_client(int pid) -{ - SLOG(LOG_DEBUG, TAG_VCM, "[TIDL] vc_mgr_tidl_request_demandable_client"); - - if (NULL == g_proxy_tidl_info) { - SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to get tidl info"); - return VC_ERROR_OPERATION_FAILED; - } - - if (!g_proxy_tidl_info->connected) { - SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Not Connected"); - return VC_ERROR_OPERATION_FAILED; - } - - if (0 != rpc_port_proxy_vc_mgr_invoke_demandable_client(g_proxy_tidl_info->rpc_h, pid)) { - SLOG(LOG_ERROR, TAG_VCM, "[TIDL ERROR] Request vc manager demandable client : Fail to invoke message"); - return VC_ERROR_OPERATION_FAILED; - } - - return VC_ERROR_NONE; -} - -int vc_mgr_tidl_request_set_audio_type(int pid, const char* audio_type) -{ - SLOG(LOG_DEBUG, TAG_VCM, "[TIDL] vc_mgr_tidl_request_set_audio_type"); - - if (NULL == g_proxy_tidl_info) { - SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to get tidl info"); - return VC_ERROR_OPERATION_FAILED; - } - - if (!g_proxy_tidl_info->connected) { - SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Not Connected"); - return VC_ERROR_OPERATION_FAILED; - } - - if (0 != rpc_port_proxy_vc_mgr_invoke_set_audio_type(g_proxy_tidl_info->rpc_h, pid, audio_type)) { - SLOG(LOG_ERROR, TAG_VCM, "[TIDL ERROR] Request vc manager set audio type : Fail to invoke message"); - return VC_ERROR_OPERATION_FAILED; - } - - return VC_ERROR_NONE; -} - -int vc_mgr_tidl_request_get_audio_type(int pid, char** audio_type) -{ - SLOG(LOG_DEBUG, TAG_VCM, "[TIDL] vc_mgr_tidl_request_get_audio_type"); - - if (NULL == g_proxy_tidl_info) { - SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to get tidl info"); - return VC_ERROR_OPERATION_FAILED; - } - - if (!g_proxy_tidl_info->connected) { - SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Not Connected"); - return VC_ERROR_OPERATION_FAILED; - } - - char *tmp = NULL; - if (0 != rpc_port_proxy_vc_mgr_invoke_get_audio_type(g_proxy_tidl_info->rpc_h, pid, &tmp)) { - SLOG(LOG_ERROR, TAG_VCM, "[TIDL ERROR] Request vc manager get audio type : Fail to invoke message"); - return VC_ERROR_OPERATION_FAILED; - } - SLOG(LOG_DEBUG, TAG_VCM, "[TIDL] Request vc manager get audio type : Success"); - - *audio_type = tmp; - - return VC_ERROR_NONE; -} - -int vc_mgr_tidl_request_set_private_data(int pid, const char* key, const char* data) -{ - SLOG(LOG_DEBUG, TAG_VCM, "[TIDL] vc_mgr_tidl_request_set_private_data"); - - if (NULL == g_proxy_tidl_info) { - SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to get tidl info"); - return VC_ERROR_OPERATION_FAILED; - } - - if (!g_proxy_tidl_info->connected) { - SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Not Connected"); - return VC_ERROR_OPERATION_FAILED; - } - - rpc_port_proxy_vc_mgr_invoke_set_private_data(g_proxy_tidl_info->rpc_h, pid, key, data); - - return VC_ERROR_NONE; -} - -int vc_mgr_tidl_request_get_private_data(int pid, const char* key, char** data) -{ - SLOG(LOG_DEBUG, TAG_VCM, "[TIDL] vc_mgr_tidl_request_get_private_data"); - - if (NULL == g_proxy_tidl_info) { - SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to get tidl info"); - return VC_ERROR_OPERATION_FAILED; - } - - if (!g_proxy_tidl_info->connected) { - SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Not Connected"); - return VC_ERROR_OPERATION_FAILED; - } - - char *tmp = NULL; - if (0 != rpc_port_proxy_vc_mgr_invoke_get_private_data(g_proxy_tidl_info->rpc_h, pid, key, &tmp)) { - SLOG(LOG_ERROR, TAG_VCM, "[TIDL ERROR] Request vc manager get private data : Fail to invoke message"); - return VC_ERROR_OPERATION_FAILED; - } - SLOG(LOG_DEBUG, TAG_VCM, "[TIDL] Request vc manager get private data : Success"); - - *data = tmp; - - return VC_ERROR_NONE; -} - -int vc_mgr_tidl_request_set_client_info(int pid) -{ - SLOG(LOG_DEBUG, TAG_VCM, "[TIDL] vc_mgr_tidl_request_set_client_info"); - - if (NULL == g_proxy_tidl_info) { - SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to get tidl info"); - return VC_ERROR_OPERATION_FAILED; - } - - if (!g_proxy_tidl_info->connected) { - SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Not Connected"); - return VC_ERROR_OPERATION_FAILED; - } - - if (0 != rpc_port_proxy_vc_mgr_invoke_set_client_info(g_proxy_tidl_info->rpc_h, pid)) { - SLOG(LOG_ERROR, TAG_VCM, "[TIDL ERROR] Request vc manager set client info : Fail to invoke message"); - return VC_ERROR_OPERATION_FAILED; - } - - return VC_ERROR_NONE; -} - -int vc_mgr_tidl_request_set_domain(int pid, const char* domain) -{ - SLOG(LOG_DEBUG, TAG_VCM, "[TIDL] vc_mgr_tidl_request_set_domain"); - - if (NULL == g_proxy_tidl_info) { - SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to get tidl info"); - return VC_ERROR_OPERATION_FAILED; - } - - if (!g_proxy_tidl_info->connected) { - SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Not Connected"); - return VC_ERROR_OPERATION_FAILED; - } - - if (0 != rpc_port_proxy_vc_mgr_invoke_set_domain(g_proxy_tidl_info->rpc_h, pid, domain)) { - SLOG(LOG_ERROR, TAG_VCM, "[TIDL ERROR] Request vc manager set domain : Fail to invoke message"); - return VC_ERROR_OPERATION_FAILED; - } - - return VC_ERROR_NONE; -} - -int vc_mgr_tidl_request_do_action(int pid, vc_send_event_type_e type, char* send_event) -{ - SLOG(LOG_DEBUG, TAG_VCM, "[TIDL] vc_mgr_tidl_request_do_action"); - - if (NULL == g_proxy_tidl_info) { - SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to get tidl info"); - return VC_ERROR_OPERATION_FAILED; - } - - if (!g_proxy_tidl_info->connected) { - SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Not Connected"); - return VC_ERROR_OPERATION_FAILED; - } - - rpc_port_proxy_vc_mgr_invoke_do_action(g_proxy_tidl_info->rpc_h, pid, type, send_event); - - return VC_ERROR_NONE; -} - -int vc_mgr_tidl_request_start(int pid, int recognition_mode, bool exclusive_command_option, bool start_by_client, int disabled_cmd_type) -{ - SLOG(LOG_DEBUG, TAG_VCM, "[TIDL] vc_mgr_tidl_request_start"); - - if (NULL == g_proxy_tidl_info) { - SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to get tidl info"); - return VC_ERROR_OPERATION_FAILED; - } - - if (!g_proxy_tidl_info->connected) { - SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Not Connected"); - return VC_ERROR_OPERATION_FAILED; - } - - if (0 != rpc_port_proxy_vc_mgr_invoke_start(g_proxy_tidl_info->rpc_h, pid, recognition_mode, exclusive_command_option, start_by_client, disabled_cmd_type)) { - SLOG(LOG_ERROR, TAG_VCM, "[TIDL ERROR] Request vc manager start : Fail to invoke message"); - return VC_ERROR_OPERATION_FAILED; - } - - return VC_ERROR_NONE; -} - -int vc_mgr_tidl_request_stop(int pid) -{ - SLOG(LOG_DEBUG, TAG_VCM, "[TIDL] vc_mgr_tidl_request_stop"); - - if (NULL == g_proxy_tidl_info) { - SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to get tidl info"); - return VC_ERROR_OPERATION_FAILED; - } - - if (!g_proxy_tidl_info->connected) { - SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Not Connected"); - return VC_ERROR_OPERATION_FAILED; - } - - if (0 != rpc_port_proxy_vc_mgr_invoke_stop(g_proxy_tidl_info->rpc_h, pid)) { - SLOG(LOG_ERROR, TAG_VCM, "[TIDL ERROR] Request vc manager stop : Fail to invoke message"); - return VC_ERROR_OPERATION_FAILED; - } - - return VC_ERROR_NONE; -} - -int vc_mgr_tidl_request_cancel(int pid) -{ - SLOG(LOG_DEBUG, TAG_VCM, "[TIDL] vc_mgr_tidl_request_cancel"); - - if (NULL == g_proxy_tidl_info) { - SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to get tidl info"); - return VC_ERROR_OPERATION_FAILED; - } - - if (!g_proxy_tidl_info->connected) { - SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Not Connected"); - return VC_ERROR_OPERATION_FAILED; - } - - if (0 != rpc_port_proxy_vc_mgr_invoke_cancel(g_proxy_tidl_info->rpc_h, pid)) { - SLOG(LOG_ERROR, TAG_VCM, "[TIDL ERROR] Request vc manager cancel : Fail to invoke message"); - return VC_ERROR_OPERATION_FAILED; - } - - return VC_ERROR_NONE; -} - -int vc_mgr_tidl_request_set_audio_streaming_mode(int pid, vc_audio_streaming_mode_e mode) -{ - SLOG(LOG_DEBUG, TAG_VCM, "[TIDL] vc_mgr_tidl_request_set_audio_streaming_mode"); - - if (NULL == g_proxy_tidl_info) { - SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to get tidl info"); - return VC_ERROR_OPERATION_FAILED; - } - - if (!g_proxy_tidl_info->connected) { - SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Not Connected"); - return VC_ERROR_OPERATION_FAILED; - } - - rpc_port_proxy_vc_mgr_invoke_set_audio_streaming_mode(g_proxy_tidl_info->rpc_h, pid, mode); - - return VC_ERROR_NONE; -} - -int vc_mgr_tidl_send_result_selection(int pid) -{ - SLOG(LOG_DEBUG, TAG_VCM, "[TIDL] vc_mgr_tidl_send_result_selection"); - - if (NULL == g_proxy_tidl_info) { - SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to get tidl info"); - return VC_ERROR_OPERATION_FAILED; - } - - if (!g_proxy_tidl_info->connected) { - SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Not Connected"); - return VC_ERROR_OPERATION_FAILED; - } - - rpc_port_proxy_vc_mgr_invoke_send_result_selection(g_proxy_tidl_info->rpc_h, pid); - - return VC_ERROR_NONE; -} - -int vc_mgr_tidl_send_specific_engine_request(int pid, const char* engine_app_id, const char* event, const char* request) -{ - SLOG(LOG_DEBUG, TAG_VCM, "[TIDL] vc_mgr_tidl_send_result_selection"); - - if (NULL == g_proxy_tidl_info) { - SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to get tidl info"); - return VC_ERROR_OPERATION_FAILED; - } - - if (!g_proxy_tidl_info->connected) { - SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Not Connected"); - return VC_ERROR_OPERATION_FAILED; - } - - gchar *gEncodedRequest = g_base64_encode((const guchar*)request, strlen(request)); - - rpc_port_proxy_vc_mgr_invoke_send_specific_engine_request(g_proxy_tidl_info->rpc_h, pid, engine_app_id, event, gEncodedRequest); - - if (gEncodedRequest) - g_free(gEncodedRequest); - - return VC_ERROR_NONE; -} - -int vc_mgr_tidl_send_utterance_status(int pid, int utt_id, vc_tts_utterance_status_e utt_status) -{ - SLOG(LOG_DEBUG, TAG_VCM, "[TIDL] vc_mgr_tidl_send_utterance_status"); - - if (NULL == g_proxy_tidl_info) { - SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to get tidl info"); - return VC_ERROR_OPERATION_FAILED; - } - - if (!g_proxy_tidl_info->connected) { - SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Not Connected"); - return VC_ERROR_OPERATION_FAILED; - } - - rpc_port_proxy_vc_mgr_invoke_send_utterance_status(g_proxy_tidl_info->rpc_h, utt_id, utt_status); - - return VC_ERROR_NONE; -} - -int vc_mgr_tidl_send_audio_streaming(int pid, vc_audio_streaming_event_e event, unsigned char* buffer, unsigned int len) -{ - SLOG(LOG_DEBUG, TAG_VCM, "[TIDL] vc_mgr_tidl_send_audio_streaming"); - - if (NULL == g_proxy_tidl_info) { - SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to get tidl info"); - return VC_ERROR_OPERATION_FAILED; - } - - if (!g_proxy_tidl_info->connected) { - SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Not Connected"); - return VC_ERROR_OPERATION_FAILED; - } - - rpc_port_proxy_array_char_h data = NULL; - rpc_port_proxy_array_char_create(&data); - if (NULL == data) { - SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to create data handle"); - return VC_ERROR_OUT_OF_MEMORY; - } - - if (NULL != buffer && 0 < len) { - rpc_port_proxy_array_char_set(data, (char*)buffer, len); - } else { - SLOG(LOG_ERROR, TAG_VCM, "[TIDL] buffer is empty"); - } - - rpc_port_proxy_vc_mgr_invoke_send_audio_streaming(g_proxy_tidl_info->rpc_h, pid, event, data); - rpc_port_proxy_array_char_destroy(data); - - return VC_ERROR_NONE; -} diff --git a/client/vc_mgr_tidl.h b/client/vc_mgr_tidl.h deleted file mode 100644 index fd91d7f..0000000 --- a/client/vc_mgr_tidl.h +++ /dev/null @@ -1,85 +0,0 @@ -/* -* Copyright (c) 2022 Samsung Electronics Co., Ltd All Rights Reserved -* -* Licensed under the Apache License, Version 2.0 (the License); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an AS IS BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - - -#ifndef __VC_TIDL_H_ -#define __VC_TIDL_H_ - -#include "voice_control_manager_internal.h" - - -#ifdef __cplusplus -extern "C" { -#endif - -int vc_mgr_tidl_open_connection(); - -int vc_mgr_tidl_close_connection(); - - -int vc_mgr_tidl_request_hello(); - -int vc_mgr_tidl_request_initialize(int pid, int audio_streaming_mode, int* service_state, int* foreground, int* daemon_pid); - -int vc_mgr_tidl_request_finalize(int pid); - -int vc_mgr_tidl_request_set_command(int pid); - -int vc_mgr_tidl_request_unset_command(int pid); - -int vc_mgr_tidl_request_demandable_client(int pid); - -int vc_mgr_tidl_request_set_audio_type(int pid, const char* audio_type); - -int vc_mgr_tidl_request_get_audio_type(int pid, char** audio_type); - -int vc_mgr_tidl_request_set_private_data(int pid, const char* key, const char* data); - -int vc_mgr_tidl_request_get_private_data(int pid, const char* key, char** data); - -int vc_mgr_tidl_request_set_client_info(int pid); - -int vc_mgr_tidl_request_set_domain(int pid, const char* domain); - -int vc_mgr_tidl_request_do_action(int pid, vc_send_event_type_e type, char* send_event); - -int vc_mgr_tidl_request_start(int pid, int recognition_mode, bool exclusive_command_option, bool start_by_client, int disabled_cmd_type); - -int vc_mgr_tidl_request_stop(int pid); - -int vc_mgr_tidl_request_cancel(int pid); - -int vc_mgr_tidl_send_result(int pid, int cmd_type, int result_id); - -int vc_mgr_tidl_send_result_selection(int pid); - -int vc_mgr_tidl_send_specific_engine_request(int pid, const char* engine_app_id, const char* event, const char* request); - -int vc_mgr_tidl_request_start_feedback(int pid); - -int vc_mgr_tidl_request_stop_feedback(int pid); - -int vc_mgr_tidl_send_utterance_status(int pid, int utt_id, vc_tts_utterance_status_e utt_status); - -int vc_mgr_tidl_send_audio_streaming(int pid, vc_audio_streaming_event_e event, unsigned char* buffer, unsigned int len); - -int vc_mgr_tidl_request_set_audio_streaming_mode(int pid, vc_audio_streaming_mode_e mode); - -#ifdef __cplusplus -} -#endif - -#endif /* __VC_TIDL_H_ */ diff --git a/common/vc_defs.h b/common/vc_defs.h index 0f906d6..4570918 100644 --- a/common/vc_defs.h +++ b/common/vc_defs.h @@ -19,7 +19,6 @@ #define __VC_DEFS_H__ #include -#include #ifdef __cplusplus extern "C" { @@ -27,7 +26,7 @@ extern "C" { /****************************************************************************************** -* Definitions for IPC +* Definitions for Dbus *******************************************************************************************/ #define VC_CLIENT_SERVICE_NAME "org.tizen.voice.vcclient" @@ -50,8 +49,6 @@ extern "C" { #define VC_SETTING_SERVICE_OBJECT_PATH "/org/tize/voice/vcsetting" #define VC_SETTING_SERVICE_INTERFACE "org.tizen.voice.vcsetting" -#define VC_SERVER_ENGINE_DEFAULT "org.tizen.vc-engine-default" - /****************************************************************************************** * Definitions for Vconf Keys *******************************************************************************************/ @@ -165,26 +162,6 @@ extern "C" { #define VC_MANAGER_METHOD_SEND_AUDIO_STREAMING "vc_manager_method_send_audio_streaming" #define VC_MANAGER_METHOD_CHANGE_SYSTEM_VOLUME "vc_manager_method_change_system_volume" -#define VC_MANAGER_BUNDLE_METHOD "vc_manager_bundle_method" -#define VC_MANAGER_BUNDLE_MESSAGE "vc_manager_bundle_message" -#define VC_MANAGER_BUNDLE_EVENT "vc_manager_bundle_event" -#define VC_MANAGER_BUNDLE_PRE_RESULT "vc_manager_bundle_pre_result" -#define VC_MANAGER_BUNDLE_ENGINE_APP_ID "vc_manager_bundle_engine_app_id" -#define VC_MANAGER_BUNDLE_RESULT "vc_manager_bundle_result" -#define VC_MANAGER_BUNDLE_DISP_TEXT "vc_manager_bundle_disp_text" -#define VC_MANAGER_BUNDLE_UTT_TEXT "vc_manager_bundle_utt_text" -#define VC_MANAGER_BUNDLE_CONTINUOUS "vc_manager_bundle_continuous" -#define VC_MANAGER_BUNDLE_REASON "vc_manager_bundle_reason" -#define VC_MANAGER_BUNDLE_DAEMON_PID "vc_manager_bundle_daemon_pid" -#define VC_MANAGER_BUNDLE_ERROR_MESSAGE "vc_manager_bundle_error_message" -#define VC_MANAGER_BUNDLE_KEY "vc_manager_bundle_key" -#define VC_MANAGER_BUNDLE_PRIVATE_DATA "vc_manager_bundle_private_data" -#define VC_MANAGER_BUNDLE_AUDIO_CHANNEL "vc_manager_bundle_audio_channel" -#define VC_MANAGER_BUNDLE_AUDIO_TYPE "vc_manager_bundle_audio_type" -#define VC_MANAGER_BUNDLE_AUDIO_RATE "vc_manager_bundle_audio_rate" -#define VC_MANAGER_BUNDLE_UTTID "vc_manager_bundle_uttid" -#define VC_MANAGER_BUNDLE_BUFFER "vc_manager_bundle_buffer" - #define VCD_MANAGER_METHOD_HELLO "vcd_manager_method_hello" #define VCD_MANAGER_METHOD_SPEECH_DETECTED "vcd_manager_method_speech_detected" #define VCD_MANAGER_METHOD_ALL_RESULT "vcd_manager_method_all_result" @@ -254,7 +231,6 @@ extern "C" { #define VC_NO_FOREGROUND_PID -1 #define VC_BASE_LANGUAGE "en_US" #define VC_RETRY_COUNT 5 -#define VC_RETRY_MIN_COUNT 2 #define VC_RUNTIME_INFO_NO_FOREGROUND -1 #define VC_CONNECTION_RETRY_COUNT 10 #define VC_INVALID_TTS_UID 0 diff --git a/packaging/voice-control.spec b/packaging/voice-control.spec index d776104..9c5e914 100644 --- a/packaging/voice-control.spec +++ b/packaging/voice-control.spec @@ -36,9 +36,6 @@ BuildRequires: pkgconfig(pkgmgr-installer) BuildRequires: pkgconfig(vconf) BuildRequires: cmake BuildRequires: pkgconfig(gmock) -BuildRequires: tidl -BuildRequires: pkgconfig(rpc-port) -BuildRequires: pkgconfig(bundle) %if 0%{?gcov:1} BuildRequires: lcov @@ -114,13 +111,6 @@ GTest for Voice Control %setup -q -n %{name}-%{version} cp %{SOURCE1001} %{SOURCE1002} . -tidlc -p -l C -i tidl/vc_mgr.tidl -o vc_mgr_proxy -tidlc -s -l C -i tidl/vc_mgr.tidl -o vcd_mgr_stub -tidlc -s -l C -i tidl/vcd_mgr.tidl -o vc_mgr_stub -tidlc -p -l C -i tidl/vcd_mgr.tidl -o vcd_mgr_proxy - -mv vc_* client -mv vcd_* server %build %if 0%{?gcov:1} diff --git a/server/CMakeLists.txt b/server/CMakeLists.txt index c557c71..b5e14ce 100644 --- a/server/CMakeLists.txt +++ b/server/CMakeLists.txt @@ -11,9 +11,6 @@ SET(SRCS vcd_config.c vcd_dbus_server.c vcd_dbus.c - vcd_tidl.c - vcd_mgr_stub.c - vcd_mgr_proxy.c vcd_engine_agent.c # vcd_main.c vcd_recorder.c diff --git a/server/vcd_client_data.c b/server/vcd_client_data.c index ddb298b..202c2e0 100644 --- a/server/vcd_client_data.c +++ b/server/vcd_client_data.c @@ -31,9 +31,6 @@ static GSList* g_widget_list = NULL; static manager_info_s g_manager; -/* Manager IPC info */ -static manager_tidl_info_s* g_mgr_tidl_info = NULL; - /* Command list */ static current_commands_list_s g_cur_cmd_list; @@ -256,141 +253,6 @@ char* vcd_client_manager_get_result_text() return g_result_text; } -int vcd_client_manger_create_tidl_info(int pid) -{ - /*Check already created*/ - if (NULL != g_mgr_tidl_info) { - SLOG(LOG_WARN, TAG_VCD, "[Client Data] Manager tidl info pid is already registered"); - if (pid != g_mgr_tidl_info->pid) { - SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Manager pid is different"); - return VCD_ERROR_OPERATION_FAILED; - } - return VCD_ERROR_NONE; - } - - SLOG(LOG_INFO, TAG_VCD, "[Client Data] There is no manager tidl info. Create new one."); - g_mgr_tidl_info = (manager_tidl_info_s*)calloc(1, sizeof(manager_tidl_info_s)); - if (NULL == g_mgr_tidl_info) { - SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to allocate memory"); - return VCD_ERROR_OUT_OF_MEMORY; - } - - g_mgr_tidl_info->pid = pid; - g_mgr_tidl_info->notify_cb = NULL; - g_mgr_tidl_info->notify_cb_user_data = NULL; - g_mgr_tidl_info->send_buffer_cb = NULL; - g_mgr_tidl_info->send_buffer_cb_user_data = NULL; - - g_mgr_tidl_info->connected = false; - g_mgr_tidl_info->connection_requesting = false; - g_mgr_tidl_info->rpc_h = NULL; - - SLOG(LOG_INFO, TAG_VCD, "[Client Data SUCCESS] Add new manager tidl info. pid(%d)", pid); - - return VCD_ERROR_NONE; -} - -int vcd_client_manager_set_tidl_notify_cb(rpc_port_stub_vc_mgr_notify_cb_h callback, void* user_data) -{ - if (NULL == g_mgr_tidl_info) { - SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] There is no manager tidl info"); - return VCD_ERROR_INVALID_PARAMETER; - } - - int ret = -1; - ret = rpc_port_stub_vc_mgr_notify_cb_clone(callback, &(g_mgr_tidl_info->notify_cb)); - if (0 != ret) { - SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] Fail to clone notify callback. ret(%d)", ret); - } else { - SLOG(LOG_INFO, TAG_VCD, "[Client Data] Succeed to clone notify callback. ret(%d)", ret); - } - g_mgr_tidl_info->notify_cb_user_data = user_data; - - return VCD_ERROR_NONE; -} - -int vcd_client_manager_unset_tidl_notify_cb() -{ - if (NULL == g_mgr_tidl_info) { - SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] There is no manager tidl info"); - return VCD_ERROR_INVALID_PARAMETER; - } - - int ret = -1; - ret = rpc_port_stub_vc_mgr_notify_cb_destroy(g_mgr_tidl_info->notify_cb); - if (0 != ret) { - SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] Fail to destroy notify callback. ret(%d)", ret); - } else { - SLOG(LOG_INFO, TAG_VCD, "[Client Data] Succeed to destroy notify callback. ret(%d)", ret); - } - g_mgr_tidl_info->notify_cb = NULL; - g_mgr_tidl_info->notify_cb_user_data = NULL; - - return VCD_ERROR_NONE; -} - -int vcd_client_manager_set_tidl_send_buffer_cb(rpc_port_stub_vc_mgr_send_buffer_cb_h callback, void* user_data) -{ - if (NULL == g_mgr_tidl_info) { - SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] There is no manager tidl info"); - return VCD_ERROR_INVALID_PARAMETER; - } - - int ret = -1; - ret = rpc_port_stub_vc_mgr_send_buffer_cb_clone(callback, &(g_mgr_tidl_info->send_buffer_cb)); - if (0 != ret) { - SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] Fail to clone feedback callback. ret(%d)", ret); - } else { - SLOG(LOG_INFO, TAG_VCD, "[Client Data] Succeed to clone feedback callback. ret(%d)", ret); - } - g_mgr_tidl_info->send_buffer_cb_user_data = user_data; - - return VCD_ERROR_NONE; -} - -int vcd_client_manager_unset_tidl_send_buffer_cb() -{ - if (NULL == g_mgr_tidl_info) { - SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] There is no manager tidl info"); - return VCD_ERROR_INVALID_PARAMETER; - } - - int ret = -1; - ret = rpc_port_stub_vc_mgr_send_buffer_cb_destroy(g_mgr_tidl_info->send_buffer_cb); - if (0 != ret) { - SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] Fail to destroy feedback callback. ret(%d)", ret); - } else { - SLOG(LOG_INFO, TAG_VCD, "[Client Data] Succeed to destroy feedback callback. ret(%d)", ret); - } - g_mgr_tidl_info->send_buffer_cb = NULL; - g_mgr_tidl_info->send_buffer_cb_user_data = NULL; - - return VCD_ERROR_NONE; -} - -int vcd_client_manager_delete_tidl_info() -{ - if (NULL == g_mgr_tidl_info) { - SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] There is no manager tidl info"); - return VCD_ERROR_INVALID_PARAMETER; - } - - if (0 != rpc_port_proxy_vcd_mgr_destroy(g_mgr_tidl_info->rpc_h)) { - SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to destroy tidl handle"); - } - - g_mgr_tidl_info->rpc_h = NULL; - free(g_mgr_tidl_info); - g_mgr_tidl_info = NULL; - - return 0; -} - -manager_tidl_info_s* vcd_client_manager_get_tidl_info() -{ - return g_mgr_tidl_info; -} - static void __vcd_client_release_each_commands(GSList** cmds) { GSList *iter = NULL; diff --git a/server/vcd_client_data.h b/server/vcd_client_data.h index 260c984..6060c81 100644 --- a/server/vcd_client_data.h +++ b/server/vcd_client_data.h @@ -21,8 +21,6 @@ #include #include "vc_command.h" #include "vc_info_parser.h" -#include "vcd_mgr_stub.h" -#include "vcd_mgr_proxy.h" #ifdef __cplusplus extern "C" { @@ -67,20 +65,6 @@ typedef struct { bool asr_result_enabled; } widget_info_s; -typedef struct { - int pid; - - rpc_port_stub_vc_mgr_notify_cb_h notify_cb; - void* notify_cb_user_data; - rpc_port_stub_vc_mgr_send_buffer_cb_h send_buffer_cb; - void* send_buffer_cb_user_data; - - bool connected; - bool connection_requesting; - - rpc_port_proxy_vcd_mgr_h rpc_h; -} manager_tidl_info_s; - typedef enum { VCD_RECOGNITION_MODE_STOP_BY_SILENCE, /**< Default mode */ VCD_RECOGNITION_MODE_RESTART_AFTER_REJECT, /**< Restart recognition after rejected result */ @@ -147,20 +131,6 @@ char* vcd_client_manager_get_result_text(); bool vcd_client_manager_is_system_command_valid(int pid); -int vcd_client_manger_create_tidl_info(int pid); - -int vcd_client_manager_set_tidl_notify_cb(rpc_port_stub_vc_mgr_notify_cb_h callback, void* user_data); - -int vcd_client_manager_unset_tidl_notify_cb(); - -int vcd_client_manager_set_tidl_send_buffer_cb(rpc_port_stub_vc_mgr_send_buffer_cb_h callback, void* user_data); - -int vcd_client_manager_unset_tidl_send_buffer_cb(); - -int vcd_client_manager_delete_tidl_info(); - -manager_tidl_info_s* vcd_client_manager_get_tidl_info(); - /* * client API */ diff --git a/server/vcd_dbus.c b/server/vcd_dbus.c index b37e486..9ac4f0c 100755 --- a/server/vcd_dbus.c +++ b/server/vcd_dbus.c @@ -18,7 +18,6 @@ #include "vcd_client_data.h" #include "vcd_dbus.h" #include "vcd_dbus_server.h" -#include "vcd_tidl.h" #include "vcd_main.h" @@ -29,7 +28,7 @@ static Ecore_Fd_Handler* g_dbus_fd_handler = NULL; static int g_waiting_time = 3000; -// static int g_volume_count = 0; +static int g_volume_count = 0; static DBusMessage* __get_message(int pid, const char* method, vcd_client_type_e type) @@ -121,8 +120,7 @@ int vcdc_send_hello(int pid, vcd_client_type_e type) } else if (VCD_CLIENT_TYPE_WIDGET == type) { msg = __get_message(pid, VCD_WIDGET_METHOD_HELLO, VCD_CLIENT_TYPE_WIDGET); } else if (VCD_CLIENT_TYPE_MANAGER == type) { - vcdc_tidl_send_hello(pid, type); - return VCD_ERROR_NONE; + msg = __get_message(pid, VCD_MANAGER_METHOD_HELLO, VCD_CLIENT_TYPE_MANAGER); } else { SLOG(LOG_ERROR, TAG_VCD, "[Dbus ERROR] Client type is NOT valid"); return -1; @@ -230,6 +228,48 @@ int vcdc_send_show_tooltip(int pid, bool show) return 0; } +int vcdc_send_set_volume(int manger_pid, float volume) +{ + if (0 != __dbus_check()) { + return VCD_ERROR_OPERATION_FAILED; + } + + DBusMessage* msg = NULL; + + /* SLOG(LOG_DEBUG, TAG_VCD, "[Dbus] Set volume (%f)", volume); */ + + msg = dbus_message_new_signal( + VC_MANAGER_SERVICE_OBJECT_PATH, + VC_MANAGER_SERVICE_INTERFACE, + VCD_MANAGER_METHOD_SET_VOLUME); + + if (NULL == msg) { + SLOG(LOG_ERROR, TAG_VCD, "[Dbus ERROR] Message is NULL"); + return VCD_ERROR_OUT_OF_MEMORY; + } + + dbus_message_append_args(msg, DBUS_TYPE_INT32, &volume, DBUS_TYPE_INVALID); + + if (1 != dbus_connection_send(g_conn_sender, msg, NULL)) { + SLOG(LOG_ERROR, TAG_VCD, "[Dbus ERROR] Fail to Send"); + dbus_message_unref(msg); + return -1; + } else { + if (20 == g_volume_count) { + SLOG(LOG_INFO, TAG_VCD, "@@ Send set volume : pid(%d), volume(%f)", manger_pid, volume); + g_volume_count = 0; + } + + dbus_connection_flush(g_conn_sender); + + g_volume_count++; + } + + dbus_message_unref(msg); + + return 0; +} + int vcdc_send_result(int pid, int manager_pid, int cmd_type) { if (0 != __dbus_check()) { @@ -244,9 +284,7 @@ int vcdc_send_result(int pid, int manager_pid, int cmd_type) case VC_COMMAND_TYPE_FOREGROUND: case VC_COMMAND_TYPE_BACKGROUND: if (pid == manager_pid) { - // msg = __get_message(pid, VCD_MANAGER_METHOD_RESULT, VCD_CLIENT_TYPE_MANAGER); - vcdc_tidl_send_result(pid, manager_pid, cmd_type); - return 0; + msg = __get_message(pid, VCD_MANAGER_METHOD_RESULT, VCD_CLIENT_TYPE_MANAGER); } else { msg = __get_message(pid, VCD_METHOD_RESULT, VCD_CLIENT_TYPE_NORMAL); } @@ -257,10 +295,8 @@ int vcdc_send_result(int pid, int manager_pid, int cmd_type) case VC_COMMAND_TYPE_SYSTEM: case VC_COMMAND_TYPE_SYSTEM_BACKGROUND: case VC_COMMAND_TYPE_EXCLUSIVE: - // msg = __get_message(pid, VCD_MANAGER_METHOD_RESULT, VCD_CLIENT_TYPE_MANAGER); - // break; - vcdc_tidl_send_result(pid, manager_pid, cmd_type); - return 0; + msg = __get_message(pid, VCD_MANAGER_METHOD_RESULT, VCD_CLIENT_TYPE_MANAGER); + break; default: SLOG(LOG_ERROR, TAG_VCD, "[Dbus ERROR] Command type is NOT valid(%d)", cmd_type); @@ -348,6 +384,241 @@ int vcdc_send_asr_result(int pid, int event, const char* asr_result, int cmd_typ } } +int vcdc_send_pre_result_to_manager(int manager_pid, int event, const char* pre_result) +{ + if (0 != __dbus_check()) { + return VCD_ERROR_OPERATION_FAILED; + } + + DBusError err; + dbus_error_init(&err); + + DBusMessage* msg = NULL; + + msg = __get_message(manager_pid, VCD_MANAGER_METHOD_PRE_RESULT, VCD_CLIENT_TYPE_MANAGER); + + if (NULL == msg) { + SLOG(LOG_ERROR, TAG_VCD, "[Dbus ERROR] Message is NULL"); + return VCD_ERROR_OUT_OF_MEMORY; + } + + dbus_message_append_args(msg, DBUS_TYPE_INT32, &event, DBUS_TYPE_STRING, &pre_result, DBUS_TYPE_INVALID); + + dbus_message_set_no_reply(msg, TRUE); + + if (1 != dbus_connection_send(g_conn_sender, msg, NULL)) { + SLOG(LOG_ERROR, TAG_VCD, "[Dbus ERROR] Fail to Send"); + return VCD_ERROR_OPERATION_FAILED; + } else { + SLOG(LOG_INFO, TAG_VCD, "[Dbus] SUCCESS Send"); + dbus_connection_flush(g_conn_sender); + } + + return 0; +} + +int vcdc_send_specific_engine_result_to_manager(int manager_pid, const char* engine_app_id, const char* event, const char* result) +{ + SLOG(LOG_INFO, TAG_VCD, "[VCDC] send specific engine result to manager, mgr pid(%d), engine app id(%s), event(%s), result(%s),", + manager_pid, engine_app_id, event, result); + + if (0 != __dbus_check()) { + return VCD_ERROR_OPERATION_FAILED; + } + + DBusError err; + dbus_error_init(&err); + + DBusMessage* msg = NULL; + + msg = __get_message(manager_pid, VCD_MANAGER_METHOD_SPECIFIC_ENGINE_RESULT, VCD_CLIENT_TYPE_MANAGER); + + if (NULL == msg) { + SLOG(LOG_ERROR, TAG_VCD, "[Dbus ERROR] Message is NULL"); + return VCD_ERROR_OUT_OF_MEMORY; + } + + gchar *gEncodedResult = g_base64_encode((const guchar*)result, strlen(result)); + + dbus_message_append_args(msg, DBUS_TYPE_STRING, &engine_app_id, DBUS_TYPE_STRING, &event, DBUS_TYPE_STRING, &gEncodedResult, DBUS_TYPE_INVALID); + + dbus_message_set_no_reply(msg, TRUE); + + if (1 != dbus_connection_send(g_conn_sender, msg, NULL)) { + SLOG(LOG_ERROR, TAG_VCD, "[Dbus ERROR] Fail to Send"); + if (gEncodedResult) + g_free(gEncodedResult); + dbus_message_unref(msg); + return VCD_ERROR_OPERATION_FAILED; + } else { + SLOG(LOG_INFO, TAG_VCD, "[Dbus] SUCCESS Send"); + dbus_connection_flush(g_conn_sender); + } + + if (gEncodedResult) + g_free(gEncodedResult); + + dbus_message_unref(msg); + + return 0; +} + +int vcdc_send_result_to_manager(int manger_pid, int result_type) +{ + if (0 != __dbus_check()) { + return VCD_ERROR_OPERATION_FAILED; + } + + DBusError err; + dbus_error_init(&err); + + DBusMessage* msg = NULL; + + msg = __get_message(manger_pid, VCD_MANAGER_METHOD_ALL_RESULT, VCD_CLIENT_TYPE_MANAGER); + + if (NULL == msg) { + SLOG(LOG_ERROR, TAG_VCD, "[Dbus ERROR] Message is NULL"); + return VCD_ERROR_OUT_OF_MEMORY; + } + + SLOG(LOG_INFO, TAG_VCD, "[Dbus] send result : result type(%d)", result_type); + + dbus_message_append_args(msg, DBUS_TYPE_INT32, &result_type, DBUS_TYPE_INVALID); + + dbus_message_set_no_reply(msg, TRUE); + + if (1 != dbus_connection_send(g_conn_sender, msg, NULL)) { + SLOG(LOG_ERROR, TAG_VCD, "[Dbus ERROR] Fail to Send"); + return VCD_ERROR_OPERATION_FAILED; + } else { + SLOG(LOG_INFO, TAG_VCD, "[Dbus] SUCCESS Send"); + dbus_connection_flush(g_conn_sender); + } + + dbus_message_unref(msg); + + return 0; +} + +int vcdc_send_speech_detected(int manger_pid) +{ + if (0 != __dbus_check()) { + return VCD_ERROR_OPERATION_FAILED; + } + + DBusError err; + dbus_error_init(&err); + + /* Send to manager */ + DBusMessage* msg = NULL; + + msg = __get_message(manger_pid, VCD_MANAGER_METHOD_SPEECH_DETECTED, VCD_CLIENT_TYPE_MANAGER); + + if (NULL == msg) { + SLOG(LOG_ERROR, TAG_VCD, "[Dbus ERROR] Message is NULL"); + return VCD_ERROR_OUT_OF_MEMORY; + } + + dbus_message_set_no_reply(msg, TRUE); + + if (1 != dbus_connection_send(g_conn_sender, msg, NULL)) { + SLOG(LOG_ERROR, TAG_VCD, "[Dbus ERROR] Fail to Send"); + return VCD_ERROR_OPERATION_FAILED; + } else { + SLOG(LOG_INFO, TAG_VCD, "[Dbus] SUCCESS Send"); + dbus_connection_flush(g_conn_sender); + } + + dbus_message_unref(msg); + + return 0; +} + +int vcdc_send_service_state(vcd_state_e state) +{ + if (0 != __dbus_check()) { + return VCD_ERROR_OPERATION_FAILED; + } + + DBusError err; + dbus_error_init(&err); + + DBusMessage* msg = NULL; + + msg = __get_message(vcd_client_manager_get_pid(), VCD_MANAGER_METHOD_SET_SERVICE_STATE, VCD_CLIENT_TYPE_MANAGER); + + if (NULL == msg) { + SLOG(LOG_ERROR, TAG_VCD, "[Dbus ERROR] Message is NULL"); + return VCD_ERROR_OUT_OF_MEMORY; + } + + dbus_message_append_args(msg, DBUS_TYPE_INT32, &state, DBUS_TYPE_INVALID); + + dbus_message_set_no_reply(msg, TRUE); + + if (1 != dbus_connection_send(g_conn_sender, msg, NULL)) { + SLOG(LOG_ERROR, TAG_VCD, "[Dbus ERROR] Fail to Send"); + return VCD_ERROR_OPERATION_FAILED; + } else { + SLOG(LOG_INFO, TAG_VCD, "@@ Send service state message to manager : state(%d)", state); + dbus_connection_flush(g_conn_sender); + } + + dbus_message_unref(msg); + + /* Send to client */ + msg = NULL; + + msg = dbus_message_new_signal( + VC_CLIENT_SERVICE_OBJECT_PATH, + VC_CLIENT_SERVICE_INTERFACE, + VCD_METHOD_SET_SERVICE_STATE); + + if (NULL == msg) { + SLOG(LOG_ERROR, TAG_VCD, "[Dbus ERROR] Message is NULL"); + return VCD_ERROR_OUT_OF_MEMORY; + } + + dbus_message_append_args(msg, DBUS_TYPE_INT32, &state, DBUS_TYPE_INVALID); + + if (1 != dbus_connection_send(g_conn_sender, msg, NULL)) { + SLOG(LOG_ERROR, TAG_VCD, "[Dbus ERROR] Fail to Send"); + return VCD_ERROR_OPERATION_FAILED; + } else { + SLOG(LOG_INFO, TAG_VCD, "@@ Send service state message to client : state(%d)", state); + dbus_connection_flush(g_conn_sender); + } + + dbus_message_unref(msg); + + msg = NULL; + + /* Send to widget client */ + msg = dbus_message_new_signal( + VC_WIDGET_SERVICE_OBJECT_PATH, + VC_WIDGET_SERVICE_INTERFACE, + VCD_WIDGET_METHOD_SET_SERVICE_STATE); + + if (NULL == msg) { + SLOG(LOG_ERROR, TAG_VCD, "[Dbus ERROR] Message is NULL"); + return VCD_ERROR_OUT_OF_MEMORY; + } + + dbus_message_append_args(msg, DBUS_TYPE_INT32, &state, DBUS_TYPE_INVALID); + + if (1 != dbus_connection_send(g_conn_sender, msg, NULL)) { + SLOG(LOG_ERROR, TAG_VCD, "[Dbus ERROR] Fail to Send"); + return VCD_ERROR_OPERATION_FAILED; + } else { + SLOG(LOG_INFO, TAG_VCD, "@@ Send service state message to widget client : state(%d)", state); + dbus_connection_flush(g_conn_sender); + } + + dbus_message_unref(msg); + + return 0; +} + int vcdc_send_manager_pid(int manager_pid) { DBusError err; @@ -381,6 +652,71 @@ int vcdc_send_manager_pid(int manager_pid) return 0; } +int vcdc_send_dialog(int manger_pid, int pid, const char* disp_text, const char* utt_text, int continuous) +{ + if (0 != __dbus_check()) { + return VCD_ERROR_OPERATION_FAILED; + } + + DBusError err; + dbus_error_init(&err); + + DBusMessage* msg = NULL; + + msg = __get_message(manger_pid, VCD_MANAGER_METHOD_DIALOG, VCD_CLIENT_TYPE_MANAGER); + + if (NULL == msg) { + SLOG(LOG_ERROR, TAG_VCD, "[Dbus ERROR] Message is NULL"); + return VCD_ERROR_OUT_OF_MEMORY; + } + + SLOG(LOG_INFO, TAG_VCD, "[Dbus] send dialog : pid(%d), disp_text(%s), utt_text(%s), continue(%d)", pid, disp_text, utt_text, continuous); + + char* disp_null = NULL; + char* utt_null = NULL; + int ret = VCD_ERROR_NONE; + if (NULL == disp_text) { + disp_null = strdup("NNUULLLL"); + disp_text = disp_null; + } + + if (NULL == utt_text) { + utt_null = strdup("NNUULLLL"); + utt_text = utt_null; + } + + dbus_message_append_args(msg, + DBUS_TYPE_INT32, &pid, + DBUS_TYPE_STRING, &disp_text, + DBUS_TYPE_STRING, &utt_text, + DBUS_TYPE_INT32, &continuous, + DBUS_TYPE_INVALID); + + dbus_message_set_no_reply(msg, TRUE); + + if (1 != dbus_connection_send(g_conn_sender, msg, NULL)) { + SLOG(LOG_ERROR, TAG_VCD, "[Dbus ERROR] Fail to Send"); + ret = VCD_ERROR_OPERATION_FAILED; + } else { + SLOG(LOG_INFO, TAG_VCD, "[Dbus] SUCCESS Send"); + dbus_connection_flush(g_conn_sender); + } + + dbus_message_unref(msg); + + if (NULL != disp_null) { + free(disp_null); + disp_null = NULL; + } + + if (NULL != utt_null) { + free(utt_null); + utt_null = NULL; + } + + return ret; +} + int vcdc_send_error_signal_to_manager(int manager_pid, int reason, char *err_msg) { SLOG(LOG_ERROR, TAG_VCD, "@@ Send error signal to manager"); @@ -456,32 +792,30 @@ int vcdc_send_error_signal(int reason, char *err_msg) DBusMessage* msg = NULL; - // msg = dbus_message_new_signal( - // VC_MANAGER_SERVICE_OBJECT_PATH, - // VC_MANAGER_SERVICE_INTERFACE, - // VCD_MANAGER_METHOD_ERROR); - - // if (NULL == msg) { - // SLOG(LOG_ERROR, TAG_VCD, "[Dbus ERROR] Message is NULL"); - // return VCD_ERROR_OUT_OF_MEMORY; - // } + msg = dbus_message_new_signal( + VC_MANAGER_SERVICE_OBJECT_PATH, + VC_MANAGER_SERVICE_INTERFACE, + VCD_MANAGER_METHOD_ERROR); - // daemon_pid = getpid(); - // dbus_message_append_args(msg, DBUS_TYPE_INT32, &reason, DBUS_TYPE_INT32, &daemon_pid, DBUS_TYPE_STRING, &err_msg, DBUS_TYPE_INVALID); + if (NULL == msg) { + SLOG(LOG_ERROR, TAG_VCD, "[Dbus ERROR] Message is NULL"); + return VCD_ERROR_OUT_OF_MEMORY; + } - // if (1 != dbus_connection_send(g_conn_sender, msg, NULL)) { - // SLOG(LOG_ERROR, TAG_VCD, "[Dbus ERROR] Fail to Send"); - // return VCD_ERROR_OPERATION_FAILED; - // } else { - // SLOG(LOG_INFO, TAG_VCD, "@@ Send error signal to manager: reason(%d), daemon_pid(%d), Error Msg(%s)", reason, daemon_pid, err_msg); - // dbus_connection_flush(g_conn_sender); - // } + daemon_pid = getpid(); + dbus_message_append_args(msg, DBUS_TYPE_INT32, &reason, DBUS_TYPE_INT32, &daemon_pid, DBUS_TYPE_STRING, &err_msg, DBUS_TYPE_INVALID); - // dbus_message_unref(msg); + if (1 != dbus_connection_send(g_conn_sender, msg, NULL)) { + SLOG(LOG_ERROR, TAG_VCD, "[Dbus ERROR] Fail to Send"); + return VCD_ERROR_OPERATION_FAILED; + } else { + SLOG(LOG_INFO, TAG_VCD, "@@ Send error signal to manager: reason(%d), daemon_pid(%d), Error Msg(%s)", reason, daemon_pid, err_msg); + dbus_connection_flush(g_conn_sender); + } - // msg = NULL; + dbus_message_unref(msg); - vcdc_tidl_send_error(reason, err_msg); + msg = NULL; msg = dbus_message_new_signal( VC_CLIENT_SERVICE_OBJECT_PATH, VC_CLIENT_SERVICE_INTERFACE, @@ -570,6 +904,188 @@ int vcdc_send_error_signal_to_app(int pid, int reason, char *err_msg) return VCD_ERROR_NONE; } +int vcdc_send_request_set_private_data(int pid, const char* key, const char* data) +{ + if (0 != __dbus_check()) { + return VCD_ERROR_OPERATION_FAILED; + } + + DBusMessage* msg = NULL; + msg = __get_message(pid, VCD_MANAGER_METHOD_SET_PRIVATE_DATA, VCD_CLIENT_TYPE_MANAGER); + if (NULL == msg) { + SLOG(LOG_ERROR, TAG_VCD, "[Dbus ERROR] Fail to create message"); + return VCD_ERROR_OUT_OF_MEMORY; + } + + dbus_message_append_args(msg, + DBUS_TYPE_INT32, &pid, + DBUS_TYPE_STRING, &key, + DBUS_TYPE_STRING, &data, + DBUS_TYPE_INVALID); + + dbus_message_set_no_reply(msg, TRUE); + + if (1 != dbus_connection_send(g_conn_sender, msg, NULL)) { + SLOG(LOG_ERROR, TAG_VCD, "[Dbus ERROR] Fail to Send request set private data"); + dbus_message_unref(msg); + return VCD_ERROR_OPERATION_FAILED; + } else { + SLOG(LOG_INFO, TAG_VCD, "[Dbus] SUCCESS Send request set private data"); + dbus_connection_flush(g_conn_sender); + } + + dbus_message_unref(msg); + + return VCD_ERROR_NONE; +} + +int vcdc_send_request_get_private_data(int pid, const char* key, char** data) +{ + if (0 != __dbus_check()) { + return VCD_ERROR_OPERATION_FAILED; + } + + DBusMessage* msg = NULL; + msg = __get_message(pid, VCD_MANAGER_METHOD_GET_PRIVATE_DATA, VCD_CLIENT_TYPE_MANAGER); + if (NULL == msg) { + SLOG(LOG_ERROR, TAG_VCD, "[Dbus ERROR] Fail to create message"); + return VCD_ERROR_OUT_OF_MEMORY; + } + + dbus_message_append_args(msg, + DBUS_TYPE_INT32, &pid, + DBUS_TYPE_STRING, &key, + DBUS_TYPE_INVALID); + + DBusError err; + dbus_error_init(&err); + + DBusMessage* result_msg; + int result = -1; + char* temp = NULL; + + result_msg = dbus_connection_send_with_reply_and_block(g_conn_sender, msg, g_waiting_time, &err); + dbus_message_unref(msg); + + if (dbus_error_is_set(&err)) { + SLOG(LOG_ERROR, TAG_VCD, "[Dbus ERROR] %s", err.message); + if (NULL != err.name) { + if (!strcmp(err.name, DBUS_ERROR_SERVICE_UNKNOWN)) { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Unknown service. Client is not available"); + dbus_error_free(&err); + return VCD_ERROR_NONE; + } + } + dbus_error_free(&err); + } + + if (NULL != result_msg) { + dbus_message_get_args(result_msg, &err, DBUS_TYPE_INT32, &result, DBUS_TYPE_STRING, &temp, DBUS_TYPE_INVALID); + + if (dbus_error_is_set(&err)) { + SLOG(LOG_ERROR, TAG_VCD, "[Dbus] Get arguments error (%s)", err.message); + dbus_error_free(&err); + result = VCD_ERROR_OPERATION_FAILED; + } + + dbus_message_unref(result_msg); + } else { + SLOG(LOG_INFO, TAG_VCD, "[Dbus] Result message is NULL. Client is not available"); + } + + if (NULL != data && NULL != temp) { + *data = strdup(temp); + } + + return result; +} + +int vcdc_send_feedback_audio_format_to_manager(int manager_pid, int rate, vc_audio_channel_e channel, vce_audio_type_e audio_type) +{ + SLOG(LOG_INFO, TAG_VCD, "[Dbus] Send TTS feedback audio format : manager_pid(%d), rate(%d), audio channel(%d), audio type(%d)", manager_pid, rate, channel, audio_type); + + if (0 != __dbus_check()) { + return VCD_ERROR_OPERATION_FAILED; + } + + DBusError err; + dbus_error_init(&err); + + /* make dbus message */ + DBusMessage* msg = NULL; + msg = __get_message(manager_pid, VCD_MANAGER_METHOD_FEEDBACK_AUDIO_FORMAT, VCD_CLIENT_TYPE_MANAGER); + if (NULL == msg) { + SLOG(LOG_ERROR, TAG_VCD, "[Dbus ERROR] Message is NULL"); + return VCD_ERROR_OUT_OF_MEMORY; + } + + dbus_message_append_args(msg, + DBUS_TYPE_INT32, &rate, + DBUS_TYPE_INT32, &channel, + DBUS_TYPE_INT32, &audio_type, + DBUS_TYPE_INVALID); + + dbus_message_set_no_reply(msg, TRUE); + + int ret = VCD_ERROR_NONE; + + if (1 != dbus_connection_send(g_conn_sender, msg, NULL)) { + SLOG(LOG_ERROR, TAG_VCD, "[Dbus ERROR] Fail to Send"); + ret = VCD_ERROR_OPERATION_FAILED; + } else { + SLOG(LOG_INFO, TAG_VCD, "[Dbus] SUCCESS Send"); + dbus_connection_flush(g_conn_sender); + } + + dbus_message_unref(msg); + + return ret; +} + +int vcdc_send_feedback_streaming_to_manager(int manager_pid, int pid, int utt_id, vc_feedback_event_e event, char* buffer, int len) +{ + SLOG(LOG_INFO, TAG_VCD, "[Dbus] Send TTS feedback streaming : manager_pid(%d), pid(%d), utt_id(%d) feedback event(%d), buffer(%p), length(%d)", manager_pid, pid, utt_id, event, buffer, len); + + if (0 != __dbus_check()) { + return VCD_ERROR_OPERATION_FAILED; + } + + DBusError err; + dbus_error_init(&err); + + /* make dbus message */ + DBusMessage* msg = NULL; + msg = __get_message(manager_pid, VCD_MANAGER_METHOD_FEEDBACK_STREAMING, VCD_CLIENT_TYPE_MANAGER); + if (NULL == msg) { + SLOG(LOG_ERROR, TAG_VCD, "[Dbus ERROR] Message is NULL"); + return VCD_ERROR_OUT_OF_MEMORY; + } + + dbus_message_append_args(msg, + DBUS_TYPE_INT32, &pid, + DBUS_TYPE_INT32, &utt_id, + DBUS_TYPE_INT32, &event, + DBUS_TYPE_ARRAY, DBUS_TYPE_BYTE, + &buffer, len, + DBUS_TYPE_INVALID); + + dbus_message_set_no_reply(msg, TRUE); + + int ret = VCD_ERROR_NONE; + + if (1 != dbus_connection_send(g_conn_sender, msg, NULL)) { + SLOG(LOG_ERROR, TAG_VCD, "[Dbus ERROR] Fail to Send"); + ret = VCD_ERROR_OPERATION_FAILED; + } else { + SLOG(LOG_INFO, TAG_VCD, "[Dbus] SUCCESS Send"); + dbus_connection_flush(g_conn_sender); + } + + dbus_message_unref(msg); + + return ret; +} + int vcdc_send_feedback_streaming(int pid, int utt_id, vc_feedback_event_e event, char* buffer, int len) { SLOG(LOG_INFO, TAG_VCD, "[Dbus] Send TTS feedback streaming : pid(%d), utt_id(%d), feedback event(%d), buffer(%p), length(%d)", pid, utt_id, event, buffer, len); @@ -633,6 +1149,73 @@ static Eina_Bool listener_event_callback(void* data, Ecore_Fd_Handler *fd_handle if (dbus_message_is_method_call(msg, VC_SERVER_SERVICE_INTERFACE, VC_METHOD_HELLO)) vcd_dbus_server_hello(g_conn_listener, msg); + /* manager event */ + else if (dbus_message_is_method_call(msg, VC_SERVER_SERVICE_INTERFACE, VC_MANAGER_METHOD_INITIALIZE)) + vcd_dbus_server_mgr_initialize(g_conn_listener, msg); + + else if (dbus_message_is_method_call(msg, VC_SERVER_SERVICE_INTERFACE, VC_MANAGER_METHOD_FINALIZE)) + vcd_dbus_server_mgr_finalize(g_conn_listener, msg); + + else if (dbus_message_is_method_call(msg, VC_SERVER_SERVICE_INTERFACE, VC_MANAGER_METHOD_SET_COMMAND)) + vcd_dbus_server_mgr_set_command(g_conn_listener, msg); + + else if (dbus_message_is_method_call(msg, VC_SERVER_SERVICE_INTERFACE, VC_MANAGER_METHOD_UNSET_COMMAND)) + vcd_dbus_server_mgr_unset_command(g_conn_listener, msg); + + else if (dbus_message_is_method_call(msg, VC_SERVER_SERVICE_INTERFACE, VC_MANAGER_METHOD_SET_DEMANDABLE)) + vcd_dbus_server_mgr_set_demandable_client(g_conn_listener, msg); + + else if (dbus_message_is_method_call(msg, VC_SERVER_SERVICE_INTERFACE, VC_MANAGER_METHOD_SET_AUDIO_TYPE)) + vcd_dbus_server_mgr_set_audio_type(g_conn_listener, msg); + + else if (dbus_message_is_method_call(msg, VC_SERVER_SERVICE_INTERFACE, VC_MANAGER_METHOD_GET_AUDIO_TYPE)) + vcd_dbus_server_mgr_get_audio_type(g_conn_listener, msg); + + else if (dbus_message_is_method_call(msg, VC_SERVER_SERVICE_INTERFACE, VC_MANAGER_METHOD_SET_CLIENT_INFO)) + vcd_dbus_server_mgr_set_client_info(g_conn_listener, msg); + + else if (dbus_message_is_method_call(msg, VC_SERVER_SERVICE_INTERFACE, VC_MANAGER_METHOD_SET_PRIVATE_DATA)) + vcd_dbus_server_mgr_set_private_data(g_conn_listener, msg); + + else if (dbus_message_is_method_call(msg, VC_SERVER_SERVICE_INTERFACE, VC_MANAGER_METHOD_GET_PRIVATE_DATA)) + vcd_dbus_server_mgr_get_private_data(g_conn_listener, msg); + + else if (dbus_message_is_method_call(msg, VC_SERVER_SERVICE_INTERFACE, VC_MANAGER_METHOD_START)) + vcd_dbus_server_mgr_start(g_conn_listener, msg); + + else if (dbus_message_is_method_call(msg, VC_SERVER_SERVICE_INTERFACE, VC_MANAGER_METHOD_STOP)) + vcd_dbus_server_mgr_stop(g_conn_listener, msg); + + else if (dbus_message_is_method_call(msg, VC_SERVER_SERVICE_INTERFACE, VC_MANAGER_METHOD_CANCEL)) + vcd_dbus_server_mgr_cancel(g_conn_listener, msg); + + else if (dbus_message_is_method_call(msg, VC_SERVER_SERVICE_INTERFACE, VC_MANAGER_METHOD_RESULT_SELECTION)) + vcd_dbus_server_mgr_result_selection(g_conn_listener, msg); + + else if (dbus_message_is_method_call(msg, VC_SERVER_SERVICE_INTERFACE, VC_MANAGER_METHOD_SET_DOMAIN)) + vcd_dbus_server_mgr_set_domain(g_conn_listener, msg); + + else if (dbus_message_is_method_call(msg, VC_SERVER_SERVICE_INTERFACE, VC_MANAGER_METHOD_DO_ACTION)) + vcd_dbus_server_mgr_do_action(g_conn_listener, msg); + + else if (dbus_message_is_method_call(msg, VC_SERVER_SERVICE_INTERFACE, VC_MANAGER_METHOD_SPECIFIC_ENGINE_REQUEST)) + vcd_dbus_server_mgr_send_specific_engine_request(g_conn_listener, msg); + + else if (dbus_message_is_method_call(msg, VC_SERVER_SERVICE_INTERFACE, VC_MANAGER_METHOD_START_FEEDBACK)) + vcd_dbus_server_mgr_start_feedback(g_conn_listener, msg); + + else if (dbus_message_is_method_call(msg, VC_SERVER_SERVICE_INTERFACE, VC_MANAGER_METHOD_STOP_FEEDBACK)) + vcd_dbus_server_mgr_stop_feedback(g_conn_listener, msg); + + else if (dbus_message_is_method_call(msg, VC_SERVER_SERVICE_INTERFACE, VC_MANAGER_METHOD_SEND_AUDIO_STREAMING)) + vcd_dbus_server_mgr_send_audio_streaming(g_conn_listener, msg); + + else if (dbus_message_is_method_call(msg, VC_SERVER_SERVICE_INTERFACE, VC_MANAGER_METHOD_CHANGE_SYSTEM_VOLUME)) + vcd_dbus_server_mgr_change_system_volume(g_conn_listener, msg); + + else if (dbus_message_is_method_call(msg, VC_SERVER_SERVICE_INTERFACE, VC_MANAGER_METHOD_SET_AUDIO_STREAMING_MODE)) + vcd_dbus_server_mgr_set_audio_streaming_mode(g_conn_listener, msg); + /* client event */ else if (dbus_message_is_method_call(msg, VC_SERVER_SERVICE_INTERFACE, VC_METHOD_INITIALIZE)) vcd_dbus_server_initialize(g_conn_listener, msg); diff --git a/server/vcd_dbus.h b/server/vcd_dbus.h index 7f07726..5fd1b7b 100644 --- a/server/vcd_dbus.h +++ b/server/vcd_dbus.h @@ -24,6 +24,12 @@ extern "C" { #endif +typedef enum { + VCD_CLIENT_TYPE_NORMAL, + VCD_CLIENT_TYPE_WIDGET, + VCD_CLIENT_TYPE_MANAGER +} vcd_client_type_e; + int vcd_dbus_open_connection(); int vcd_dbus_close_connection(); @@ -34,22 +40,43 @@ int vcdc_send_hello(int pid, vcd_client_type_e type); int vcdc_send_show_tooltip(int pid, bool show); +int vcdc_send_set_volume(int manger_pid, float volume); + int vcdc_send_result(int pid, int manager_pid, int cmd_type); int vcdc_send_asr_result(int pid, int event, const char* asr_result, int cmd_type, bool* is_consumed); +int vcdc_send_pre_result_to_manager(int manager_pid, int event, const char* pre_result); + +int vcdc_send_specific_engine_result_to_manager(int manager_pid, const char* engine_app_id, const char* event, const char* result); + +int vcdc_send_result_to_manager(int manger_pid, int result_type); + +int vcdc_send_speech_detected(int manger_pid); + int vcdc_send_error_signal(int reason, char *err_msg); +int vcdc_send_error_signal_to_manager(int manager_pid, int reason, char *err_msg); + int vcdc_send_error_signal_to_app(int pid, int reason, char *err_msg); +int vcdc_send_service_state(vcd_state_e state); + +int vcdc_send_dialog(int manger_pid, int pid, const char* disp_text, const char* utt_text, int continuous); + int vcdc_send_manager_pid(int manager_pid); -// int vcdc_send_request_get_private_data(int pid, const char* key, char** data); +int vcdc_send_request_set_private_data(int pid, const char* key, const char* data); + +int vcdc_send_request_get_private_data(int pid, const char* key, char** data); /* for TTS feedback */ +int vcdc_send_feedback_audio_format_to_manager(int manager_pid, int rate, vc_audio_channel_e channel, vce_audio_type_e audio_type); + +int vcdc_send_feedback_streaming_to_manager(int manager_pid, int pid, int utt_id, vc_feedback_event_e event, char* buffer, int len); + int vcdc_send_feedback_streaming(int pid, int utt_id, vc_feedback_event_e event, char* buffer, int len); -// int vcdc_send_feedback_streaming_to_manager(int manager_pid, int pid, int utt_id, vc_feedback_event_e event, char* buffer, int len); #ifdef __cplusplus } diff --git a/server/vcd_dbus_server.c b/server/vcd_dbus_server.c index d5d4ac1..d30dd2b 100755 --- a/server/vcd_dbus_server.c +++ b/server/vcd_dbus_server.c @@ -17,7 +17,6 @@ #include "vcd_client_data.h" #include "vcd_dbus.h" -#include "vcd_tidl.h" #include "vcd_dbus_server.h" #include "vcd_main.h" #include "vcd_server.h" @@ -86,6 +85,853 @@ int vcd_dbus_server_hello(DBusConnection* conn, DBusMessage* msg) return 0; } +/* +* Dbus Server functions for manager +*/ + +int vcd_dbus_server_mgr_initialize(DBusConnection* conn, DBusMessage* msg) +{ + DBusError err; + dbus_error_init(&err); + + int pid; + int streaming_mode; + int service_state; + int foreground; + int daemon_pid; + int ret = VCD_ERROR_OPERATION_FAILED; + + dbus_message_get_args(msg, &err, + DBUS_TYPE_INT32, &pid, + DBUS_TYPE_INT32, &streaming_mode, + DBUS_TYPE_INVALID); + + SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Manager Initialize"); + + if (dbus_error_is_set(&err)) { + SLOG(LOG_ERROR, TAG_VCD, "[IN ERROR] vcd mgr initialize : get arguments error (%s)", err.message); + dbus_error_free(&err); + ret = VCD_ERROR_OPERATION_FAILED; + } else { + vcd_config_set_audio_streaming_mode((vcd_audio_streaming_mode_e)streaming_mode); + ret = vcd_server_mgr_initialize(pid, streaming_mode); + service_state = vcd_server_get_service_state(); + foreground = vcd_server_get_foreground(); + daemon_pid = getpid(); + + 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); + } + + DBusMessage* reply; + reply = dbus_message_new_method_return(msg); + + if (NULL != reply) { + dbus_message_append_args(reply, + DBUS_TYPE_INT32, &ret, + DBUS_TYPE_INT32, &service_state, + DBUS_TYPE_INT32, &foreground, + DBUS_TYPE_INT32, &daemon_pid, + DBUS_TYPE_INVALID); + + if (0 == ret) { + SLOG(LOG_INFO, TAG_VCD, "[OUT SUCCESS] Result(%d)", ret); + } else { + SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret); + } + + if (!dbus_connection_send(conn, reply, NULL)) { + SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Out Of Memory!"); + } + + dbus_connection_flush(conn); + dbus_message_unref(reply); + } else { + SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Fail to create reply message!!"); + } + + SLOG(LOG_DEBUG, TAG_VCD, "@@@"); + + return 0; +} + +int vcd_dbus_server_mgr_finalize(DBusConnection* conn, DBusMessage* msg) +{ + DBusError err; + dbus_error_init(&err); + + int pid; + int ret = VCD_ERROR_OPERATION_FAILED; + dbus_message_get_args(msg, &err, DBUS_TYPE_INT32, &pid, DBUS_TYPE_INVALID); + + SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Manager Finalize"); + + if (dbus_error_is_set(&err)) { + SLOG(LOG_ERROR, TAG_VCD, "[IN ERROR] vcd mgr finalize : get arguments error (%s)", err.message); + dbus_error_free(&err); + ret = VCD_ERROR_OPERATION_FAILED; + } else { + SLOG(LOG_INFO, TAG_VCD, "[IN] vcd mgr finalize : pid(%d)", pid); + ret = vcd_server_mgr_finalize(pid); + } + + DBusMessage* reply; + + reply = dbus_message_new_method_return(msg); + + if (NULL != reply) { + dbus_message_append_args(reply, DBUS_TYPE_INT32, &ret, DBUS_TYPE_INVALID); + + if (0 == ret) { + SLOG(LOG_INFO, TAG_VCD, "[OUT SUCCESS] Result(%d)", ret); + } else { + SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret); + } + + if (!dbus_connection_send(conn, reply, NULL)) { + SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Out Of Memory!"); + } + + dbus_connection_flush(conn); + dbus_message_unref(reply); + } else { + SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Fail to create reply message!!"); + } + + SLOG(LOG_DEBUG, TAG_VCD, "@@@"); + + return 0; +} + +int vcd_dbus_server_mgr_set_command(DBusConnection* conn, DBusMessage* msg) +{ + DBusError err; + dbus_error_init(&err); + + int pid; + int ret = VCD_ERROR_OPERATION_FAILED; + + dbus_message_get_args(msg, &err, DBUS_TYPE_INT32, &pid, DBUS_TYPE_INVALID); + + SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Manager Set command"); + + if (dbus_error_is_set(&err)) { + SLOG(LOG_ERROR, TAG_VCD, "[IN ERROR] vcd mgr set command : get arguments error (%s)", err.message); + dbus_error_free(&err); + ret = VCD_ERROR_OPERATION_FAILED; + } else { + SLOG(LOG_INFO, TAG_VCD, "[IN] vcd mgr set command : pid(%d)", pid); + ret = vcd_server_mgr_set_command(pid); + } + + DBusMessage* reply; + reply = dbus_message_new_method_return(msg); + + if (NULL != reply) { + if (0 == ret) { + /* Append result and language */ + dbus_message_append_args(reply, DBUS_TYPE_INT32, &ret, DBUS_TYPE_INVALID); + + SLOG(LOG_INFO, TAG_VCD, "[OUT SUCCESS] Result(%d)", ret); + } else { + dbus_message_append_args(reply, DBUS_TYPE_INT32, &ret, DBUS_TYPE_INVALID); + + SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret); + } + + if (!dbus_connection_send(conn, reply, NULL)) { + SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Out Of Memory!"); + } + + dbus_connection_flush(conn); + dbus_message_unref(reply); + } else { + SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Fail to create reply message!!"); + } + + SLOG(LOG_DEBUG, TAG_VCD, "@@@"); + + return 0; +} + +int vcd_dbus_server_mgr_unset_command(DBusConnection* conn, DBusMessage* msg) +{ + DBusError err; + dbus_error_init(&err); + + int pid; + int ret = VCD_ERROR_OPERATION_FAILED; + + dbus_message_get_args(msg, &err, DBUS_TYPE_INT32, &pid, DBUS_TYPE_INVALID); + + SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD manager unset command"); + + if (dbus_error_is_set(&err)) { + SLOG(LOG_ERROR, TAG_VCD, "[IN ERROR] vcd mgr unset command : get arguments error (%s)", err.message); + dbus_error_free(&err); + ret = VCD_ERROR_OPERATION_FAILED; + } else { + SLOG(LOG_INFO, TAG_VCD, "[IN] vcd mgr unset command : pid(%d)", pid); + ret = vcd_server_mgr_unset_command(pid); + } + + DBusMessage* reply; + reply = dbus_message_new_method_return(msg); + + if (NULL != reply) { + if (0 == ret) { + /* Append result and language */ + dbus_message_append_args(reply, DBUS_TYPE_INT32, &ret, DBUS_TYPE_INVALID); + + SLOG(LOG_INFO, TAG_VCD, "[OUT SUCCESS] Result(%d)", ret); + } else { + dbus_message_append_args(reply, DBUS_TYPE_INT32, &ret, DBUS_TYPE_INVALID); + + SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret); + } + + if (!dbus_connection_send(conn, reply, NULL)) { + SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Out Of Memory!"); + } + + dbus_connection_flush(conn); + dbus_message_unref(reply); + } else { + SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Fail to create reply message!!"); + } + + SLOG(LOG_DEBUG, TAG_VCD, "@@@"); + + return 0; +} + +int vcd_dbus_server_mgr_set_demandable_client(DBusConnection* conn, DBusMessage* msg) +{ + DBusError err; + dbus_error_init(&err); + + int pid; + int ret = VCD_ERROR_OPERATION_FAILED; + + dbus_message_get_args(msg, &err, DBUS_TYPE_INT32, &pid, DBUS_TYPE_INVALID); + + SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Manager Set demandable client"); + + if (dbus_error_is_set(&err)) { + SLOG(LOG_ERROR, TAG_VCD, "[IN ERROR] vcd mgr set demandable client : get arguments error (%s)", err.message); + dbus_error_free(&err); + ret = VCD_ERROR_OPERATION_FAILED; + } else { + SLOG(LOG_INFO, TAG_VCD, "[IN] vcd mgr set demandable client : pid(%d)", pid); + ret = vcd_server_mgr_set_demandable_client(pid); + } + + DBusMessage* reply; + reply = dbus_message_new_method_return(msg); + + if (NULL != reply) { + if (0 == ret) { + /* Append result and language */ + dbus_message_append_args(reply, DBUS_TYPE_INT32, &ret, DBUS_TYPE_INVALID); + + SLOG(LOG_INFO, TAG_VCD, "[OUT SUCCESS] Result(%d)", ret); + } else { + dbus_message_append_args(reply, DBUS_TYPE_INT32, &ret, DBUS_TYPE_INVALID); + + SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret); + } + + if (!dbus_connection_send(conn, reply, NULL)) { + SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Out Of Memory!"); + } + + dbus_connection_flush(conn); + dbus_message_unref(reply); + } else { + SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Fail to create reply message!!"); + } + + SLOG(LOG_DEBUG, TAG_VCD, "@@@"); + + return 0; +} + +int vcd_dbus_server_mgr_set_audio_type(DBusConnection* conn, DBusMessage* msg) +{ + DBusError err; + dbus_error_init(&err); + + int pid = 0; + char* audio_type = NULL; + + int ret = VCD_ERROR_OPERATION_FAILED; + + SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Manager set audio type"); + + dbus_message_get_args(msg, &err, + DBUS_TYPE_INT32, &pid, + DBUS_TYPE_STRING, &audio_type, + DBUS_TYPE_INVALID); + + if (dbus_error_is_set(&err)) { + SLOG(LOG_ERROR, TAG_VCD, "[IN ERROR] vcd mgr set audio type : get arguments error (%s)", err.message); + dbus_error_free(&err); + ret = VCD_ERROR_OPERATION_FAILED; + } else { + SLOG(LOG_INFO, TAG_VCD, "[IN] vcd mgr set audio type : pid(%d), audio type(%s)", pid, audio_type); + ret = vcd_server_mgr_set_audio_type(pid, audio_type); + } + + DBusMessage* reply; + reply = dbus_message_new_method_return(msg); + + if (NULL != reply) { + dbus_message_append_args(reply, DBUS_TYPE_INT32, &ret, DBUS_TYPE_INVALID); + + if (0 == ret) { + SLOG(LOG_INFO, TAG_VCD, "[OUT SUCCESS] Result(%d)", ret); + } else { + SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret); + } + + if (!dbus_connection_send(conn, reply, NULL)) { + SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Out Of Memory!"); + } + + dbus_connection_flush(conn); + dbus_message_unref(reply); + } else { + SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Fail to create reply message!!"); + } + + SLOG(LOG_DEBUG, TAG_VCD, "@@@"); + + return 0; +} + +int vcd_dbus_server_mgr_get_audio_type(DBusConnection* conn, DBusMessage* msg) +{ + DBusError err; + dbus_error_init(&err); + + int pid = 0; + char* audio_type = NULL; + + int ret = VCD_ERROR_OPERATION_FAILED; + + SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Manager get audio type"); + + dbus_message_get_args(msg, &err, + DBUS_TYPE_INT32, &pid, + DBUS_TYPE_INVALID); + + if (dbus_error_is_set(&err)) { + SLOG(LOG_ERROR, TAG_VCD, "[IN ERROR] vcd mgr set audio type : get arguments error (%s)", err.message); + dbus_error_free(&err); + ret = VCD_ERROR_OPERATION_FAILED; + } else { + SLOG(LOG_INFO, TAG_VCD, "[IN] vcd mgr set audio type : pid(%d)", pid); + ret = vcd_server_mgr_get_audio_type(pid, &audio_type); + } + + DBusMessage* reply; + reply = dbus_message_new_method_return(msg); + + if (NULL != reply) { + dbus_message_append_args(reply, + DBUS_TYPE_INT32, &ret, + DBUS_TYPE_STRING, &audio_type, + DBUS_TYPE_INVALID); + + if (0 == ret) { + SLOG(LOG_INFO, TAG_VCD, "[OUT SUCCESS] Result(%d), audio type(%s)", ret, audio_type); + } else { + SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret); + } + + if (!dbus_connection_send(conn, reply, NULL)) { + SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Out Of Memory!"); + } + + dbus_connection_flush(conn); + dbus_message_unref(reply); + } else { + SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Fail to create reply message!!"); + } + + SLOG(LOG_DEBUG, TAG_VCD, "@@@"); + + if (NULL != audio_type) free(audio_type); + + return 0; +} + +int vcd_dbus_server_mgr_set_client_info(DBusConnection* conn, DBusMessage* msg) +{ + DBusError err; + dbus_error_init(&err); + + int pid = 0; + + int ret = VCD_ERROR_OPERATION_FAILED; + + SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Manager set client info"); + + dbus_message_get_args(msg, &err, + DBUS_TYPE_INT32, &pid, + DBUS_TYPE_INVALID); + + if (dbus_error_is_set(&err)) { + SLOG(LOG_ERROR, TAG_VCD, "[IN ERROR] vcd mgr set client info : get arguments error (%s)", err.message); + dbus_error_free(&err); + ret = VCD_ERROR_OPERATION_FAILED; + } else { + SLOG(LOG_INFO, TAG_VCD, "[IN] vcd mgr set client info : pid(%d)", pid); + ret = vcd_server_mgr_set_client_info(pid); + } + + DBusMessage* reply; + reply = dbus_message_new_method_return(msg); + + if (NULL != reply) { + dbus_message_append_args(reply, + DBUS_TYPE_INT32, &ret, + DBUS_TYPE_INVALID); + + if (0 == ret) { + SLOG(LOG_INFO, TAG_VCD, "[OUT SUCCESS] Result(%d)", ret); + } else { + SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret); + } + + if (!dbus_connection_send(conn, reply, NULL)) { + SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Out Of Memory!"); + } + + dbus_connection_flush(conn); + dbus_message_unref(reply); + } else { + SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Fail to create reply message!!"); + } + + SLOG(LOG_DEBUG, TAG_VCD, "@@@"); + + return 0; +} + +int vcd_dbus_server_mgr_set_private_data(DBusConnection* conn, DBusMessage* msg) +{ + DBusError err; + dbus_error_init(&err); + + int pid = 0; + char* key = NULL; + char* data = NULL; + + int ret = VCD_ERROR_OPERATION_FAILED; + + SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Manager set private data"); + + dbus_message_get_args(msg, &err, + DBUS_TYPE_INT32, &pid, + DBUS_TYPE_STRING, &key, + DBUS_TYPE_STRING, &data, + DBUS_TYPE_INVALID); + + if (dbus_error_is_set(&err)) { + SLOG(LOG_ERROR, TAG_VCD, "[IN ERROR] vcd mgr set private data : get arguments error (%s)", err.message); + dbus_error_free(&err); + ret = VCD_ERROR_OPERATION_FAILED; + } else { + SLOG(LOG_INFO, TAG_VCD, "[IN] vcd mgr set domain : pid(%d), key(%s), data(%s)", pid, key, data); + ret = vcd_server_mgr_set_private_data(pid, key, data); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to set private data"); + } + } + + SLOG(LOG_DEBUG, TAG_VCD, "@@@"); + + return 0; +} + +int vcd_dbus_server_mgr_get_private_data(DBusConnection* conn, DBusMessage* msg) +{ + DBusError err; + dbus_error_init(&err); + + int pid = 0; + char* key = NULL; + char* data = NULL; + + int ret = VCD_ERROR_OPERATION_FAILED; + + SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Manager get private data"); + + dbus_message_get_args(msg, &err, + DBUS_TYPE_INT32, &pid, + DBUS_TYPE_STRING, &key, + DBUS_TYPE_INVALID); + + if (dbus_error_is_set(&err)) { + SLOG(LOG_ERROR, TAG_VCD, "[IN ERROR] vcd mgr set audio type : get arguments error (%s)", err.message); + dbus_error_free(&err); + ret = VCD_ERROR_OPERATION_FAILED; + } else { + SLOG(LOG_INFO, TAG_VCD, "[IN] vcd mgr get private data : pid(%d), key(%s)", pid, key); + ret = vcd_server_mgr_get_private_data(pid, key, &data); + } + + char *temp_data = NULL; + if (NULL == data) { + SLOG(LOG_INFO, TAG_VCD, "[Dbus INFO] data parameter is NULL"); + temp_data = strdup("#NULL"); + } else { + temp_data = strdup(data); + } + + DBusMessage* reply; + reply = dbus_message_new_method_return(msg); + + if (NULL != reply) { + dbus_message_append_args(reply, + DBUS_TYPE_INT32, &ret, + DBUS_TYPE_STRING, &temp_data, + DBUS_TYPE_INVALID); + + if (0 == ret) { + SLOG(LOG_INFO, TAG_VCD, "[OUT SUCCESS] Result(%d), private data(%s)", ret, temp_data); + } else { + SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret); + } + + if (!dbus_connection_send(conn, reply, NULL)) { + SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Out Of Memory!"); + } + + dbus_connection_flush(conn); + dbus_message_unref(reply); + } else { + SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Fail to create reply message!!"); + } + + SLOG(LOG_DEBUG, TAG_VCD, "@@@"); + + if (NULL != data) { + free(data); + data = NULL; + } + if (NULL != temp_data) { + free(temp_data); + temp_data = NULL; + } + + return 0; +} + +int vcd_dbus_server_mgr_send_specific_engine_request(DBusConnection* conn, DBusMessage* msg) +{ + DBusError err; + dbus_error_init(&err); + + int pid = 0; + char* engine_app_id = NULL; + char* event = NULL; + char* request = NULL; + + int ret = VCD_ERROR_OPERATION_FAILED; + + SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Manager specific engine request"); + + dbus_message_get_args(msg, &err, + DBUS_TYPE_INT32, &pid, + DBUS_TYPE_STRING, &engine_app_id, + DBUS_TYPE_STRING, &event, + DBUS_TYPE_STRING, &request, + DBUS_TYPE_INVALID); + + if (dbus_error_is_set(&err)) { + SLOG(LOG_ERROR, TAG_VCD, "[IN ERROR] vcd mgr specific engine request : get arguments error (%s)", err.message); + dbus_error_free(&err); + ret = VCD_ERROR_OPERATION_FAILED; + } else { + gsize decodingSize=0; + gchar *gDecodedRequest = (gchar *)g_base64_decode((const gchar *)request, &decodingSize); + if (gDecodedRequest) + { + ret = vcd_server_mgr_send_specific_engine_request(pid, engine_app_id, event, gDecodedRequest); + 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); + g_free(gDecodedRequest); + } + } + + return 0; +} + +int vcd_dbus_server_mgr_set_domain(DBusConnection* conn, DBusMessage* msg) +{ + DBusError err; + dbus_error_init(&err); + + int pid = 0; + char* domain = NULL; + + int ret = VCD_ERROR_OPERATION_FAILED; + + SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Manager set domain type"); + + dbus_message_get_args(msg, &err, + DBUS_TYPE_INT32, &pid, + DBUS_TYPE_STRING, &domain, + DBUS_TYPE_INVALID); + + if (dbus_error_is_set(&err)) { + SLOG(LOG_ERROR, TAG_VCD, "[IN ERROR] vcd mgr set domain : get arguments error (%s)", err.message); + dbus_error_free(&err); + ret = VCD_ERROR_OPERATION_FAILED; + } else { + SLOG(LOG_INFO, TAG_VCD, "[IN] vcd mgr set domain : pid(%d), domain(%s)", pid, domain); + ret = vcd_server_mgr_set_domain(pid, domain); + } + + DBusMessage* reply; + reply = dbus_message_new_method_return(msg); + + if (NULL != reply) { + dbus_message_append_args(reply, DBUS_TYPE_INT32, &ret, DBUS_TYPE_INVALID); + + if (0 == ret) { + SLOG(LOG_INFO, TAG_VCD, "[OUT SUCCESS] Result(%d)", ret); + } else { + SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret); + } + + if (!dbus_connection_send(conn, reply, NULL)) { + SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Out Of Memory!"); + } + + dbus_connection_flush(conn); + dbus_message_unref(reply); + } else { + SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Fail to create reply message!!"); + } + + SLOG(LOG_DEBUG, TAG_VCD, "@@@"); + + return 0; +} + +int vcd_dbus_server_mgr_do_action(DBusConnection* conn, DBusMessage* msg) +{ + DBusError err; + dbus_error_init(&err); + + int pid = 0; + int type = 0; + char* send_event = NULL; + + int ret = VCD_ERROR_OPERATION_FAILED; + + SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Manager request to do action"); + + dbus_message_get_args(msg, &err, + DBUS_TYPE_INT32, &pid, + DBUS_TYPE_INT32, &type, + DBUS_TYPE_STRING, &send_event, + DBUS_TYPE_INVALID); + + if (dbus_error_is_set(&err)) { + SLOG(LOG_ERROR, TAG_VCD, "[IN ERROR] vcd mgr request to do action : get arguments error (%s)", err.message); + dbus_error_free(&err); + ret = VCD_ERROR_OPERATION_FAILED; + } else { + SLOG(LOG_INFO, TAG_VCD, "[IN] vcd mgr request to do action : pid(%d), type(%d) send_event(%s)", pid, type, send_event); + ret = vcd_server_mgr_do_action(pid, type, send_event); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to do action"); + } + } + + SLOG(LOG_DEBUG, TAG_VCD, "@@@"); + + return 0; +} + +int vcd_dbus_server_mgr_start(DBusConnection* conn, DBusMessage* msg) +{ + DBusError err; + dbus_error_init(&err); + + int pid = 0; + int recognition_mode = 0; + int exclusive = 0; + int start_by_client = 0; + int disabled_cmd_type = 0; + + int ret = VCD_ERROR_OPERATION_FAILED; + + SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Manager start"); + + dbus_message_get_args(msg, &err, + DBUS_TYPE_INT32, &pid, + DBUS_TYPE_INT32, &recognition_mode, + DBUS_TYPE_INT32, &exclusive, + DBUS_TYPE_INT32, &start_by_client, + DBUS_TYPE_INT32, &disabled_cmd_type, + DBUS_TYPE_INVALID); + + if (dbus_error_is_set(&err)) { + SLOG(LOG_ERROR, TAG_VCD, "[IN ERROR] vcd mgr start : get arguments error (%s)", err.message); + dbus_error_free(&err); + ret = VCD_ERROR_OPERATION_FAILED; + } else { + SLOG(LOG_INFO, TAG_VCD, "[IN] vcd check enabled or disabled command types. disabled cmd type(%d)", disabled_cmd_type); + vcd_server_mgr_set_disabled_command_type(pid, disabled_cmd_type); + + SLOG(LOG_INFO, TAG_VCD, "[IN] vcd mgr start : pid(%d) recognition_mode(%d) exclusive(%d) start by client(%d)", pid, recognition_mode, exclusive, start_by_client); + ret = vcd_server_mgr_start((vcd_recognition_mode_e)recognition_mode, (bool)exclusive, (bool)start_by_client); + } + + DBusMessage* reply; + reply = dbus_message_new_method_return(msg); + + if (NULL != reply) { + dbus_message_append_args(reply, DBUS_TYPE_INT32, &ret, DBUS_TYPE_INVALID); + + if (0 == ret) { + SLOG(LOG_INFO, TAG_VCD, "[OUT SUCCESS] Result(%d)", ret); + } else { + SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret); + } + + if (!dbus_connection_send(conn, reply, NULL)) { + SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Out Of Memory!"); + } + + dbus_connection_flush(conn); + dbus_message_unref(reply); + } else { + SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Fail to create reply message!!"); + } + + SLOG(LOG_DEBUG, TAG_VCD, "@@@"); + + return 0; +} + +int vcd_dbus_server_mgr_stop(DBusConnection* conn, DBusMessage* msg) +{ + DBusError err; + dbus_error_init(&err); + + int pid; + int ret = VCD_ERROR_OPERATION_FAILED; + dbus_message_get_args(msg, &err, DBUS_TYPE_INT32, &pid, DBUS_TYPE_INVALID); + + SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Manager stop"); + + if (dbus_error_is_set(&err)) { + SLOG(LOG_ERROR, TAG_VCD, "[IN ERROR] vcd mgr stop : get arguments error (%s)", err.message); + dbus_error_free(&err); + ret = VCD_ERROR_OPERATION_FAILED; + } else { + SLOG(LOG_INFO, TAG_VCD, "[IN] vcd mgr stop : pid(%d)", pid); + ret = vcd_server_mgr_stop(); + } + + DBusMessage* reply; + reply = dbus_message_new_method_return(msg); + + if (NULL != reply) { + dbus_message_append_args(reply, DBUS_TYPE_INT32, &ret, DBUS_TYPE_INVALID); + + if (0 == ret) { + SLOG(LOG_INFO, TAG_VCD, "[OUT SUCCESS] Result(%d)", ret); + } else { + SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret); + } + + if (!dbus_connection_send(conn, reply, NULL)) { + SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Out Of Memory!"); + } + + dbus_connection_flush(conn); + dbus_message_unref(reply); + } else { + SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Fail to create reply message!!"); + } + + SLOG(LOG_DEBUG, TAG_VCD, "@@@"); + + return 0; +} + +int vcd_dbus_server_mgr_cancel(DBusConnection* conn, DBusMessage* msg) +{ + DBusError err; + dbus_error_init(&err); + + int pid; + int ret = VCD_ERROR_OPERATION_FAILED; + dbus_message_get_args(msg, &err, DBUS_TYPE_INT32, &pid, DBUS_TYPE_INVALID); + + SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Manager cancel"); + + if (dbus_error_is_set(&err)) { + SLOG(LOG_ERROR, TAG_VCD, "[IN ERROR] vcd mgr cancel : get arguments error (%s)", err.message); + dbus_error_free(&err); + ret = VCD_ERROR_OPERATION_FAILED; + } else { + SLOG(LOG_INFO, TAG_VCD, "[IN] vcd mgr cancel : pid(%d)", pid); + ret = vcd_server_mgr_cancel(); + } + + DBusMessage* reply; + reply = dbus_message_new_method_return(msg); + + if (NULL != reply) { + dbus_message_append_args(reply, DBUS_TYPE_INT32, &ret, DBUS_TYPE_INVALID); + + if (0 == ret) { + SLOG(LOG_INFO, TAG_VCD, "[OUT SUCCESS] Result(%d)", ret); + } else { + SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret); + } + + if (!dbus_connection_send(conn, reply, NULL)) { + SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Out Of Memory!"); + } + + dbus_connection_flush(conn); + dbus_message_unref(reply); + } else { + SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Fail to create reply message!!"); + } + + SLOG(LOG_DEBUG, TAG_VCD, "@@@"); + + return 0; +} + +int vcd_dbus_server_mgr_result_selection(DBusConnection* conn, DBusMessage* msg) +{ + DBusError err; + dbus_error_init(&err); + + int pid; + dbus_message_get_args(msg, &err, DBUS_TYPE_INT32, &pid, DBUS_TYPE_INVALID); + + SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Manager result selection"); + + if (dbus_error_is_set(&err)) { + SLOG(LOG_ERROR, TAG_VCD, "[IN ERROR] vcd mgr result selection : get arguments error (%s)", err.message); + dbus_error_free(&err); + } else { + SLOG(LOG_INFO, TAG_VCD, "[IN] vcd mgr result selection : pid(%d)", pid); + vcd_server_mgr_result_select(); + } + return 0; +} + /* for TTS feedback */ int vcd_dbus_server_mgr_start_feedback(DBusConnection* conn, DBusMessage* msg) { diff --git a/server/vcd_dbus_server.h b/server/vcd_dbus_server.h index 0d0ec0a..dca8add 100644 --- a/server/vcd_dbus_server.h +++ b/server/vcd_dbus_server.h @@ -30,6 +30,45 @@ int vcd_dbus_server_hello(DBusConnection* conn, DBusMessage* msg); /* * Dbus Server functions for manager */ + +int vcd_dbus_server_mgr_initialize(DBusConnection* conn, DBusMessage* msg); + +int vcd_dbus_server_mgr_finalize(DBusConnection* conn, DBusMessage* msg); + +int vcd_dbus_server_mgr_set_command(DBusConnection* conn, DBusMessage* msg); + +int vcd_dbus_server_mgr_unset_command(DBusConnection* conn, DBusMessage* msg); + +int vcd_dbus_server_mgr_set_demandable_client(DBusConnection* conn, DBusMessage* msg); + +int vcd_dbus_server_mgr_set_audio_type(DBusConnection* conn, DBusMessage* msg); + +int vcd_dbus_server_mgr_get_audio_type(DBusConnection* conn, DBusMessage* msg); + +int vcd_dbus_server_mgr_set_client_info(DBusConnection* conn, DBusMessage* msg); + +int vcd_dbus_server_mgr_set_private_data(DBusConnection* conn, DBusMessage* msg); + +int vcd_dbus_server_mgr_get_private_data(DBusConnection* conn, DBusMessage* msg); + +int vcd_dbus_server_mgr_set_domain(DBusConnection* conn, DBusMessage* msg); + +int vcd_dbus_server_mgr_do_action(DBusConnection* conn, DBusMessage* msg); + +int vcd_dbus_server_mgr_start(DBusConnection* conn, DBusMessage* msg); + +int vcd_dbus_server_mgr_stop(DBusConnection* conn, DBusMessage* msg); + +int vcd_dbus_server_mgr_cancel(DBusConnection* conn, DBusMessage* msg); + +int vcd_dbus_server_mgr_result_selection(DBusConnection* conn, DBusMessage* msg); + +int vcd_dbus_server_mgr_send_specific_engine_request(DBusConnection* conn, DBusMessage* msg); + +int vcd_dbus_server_mgr_change_system_volume(DBusConnection* conn, DBusMessage* msg); + +int vcd_dbus_server_mgr_set_audio_streaming_mode(DBusConnection* conn, DBusMessage* msg); + /* for TTS feedback */ int vcd_dbus_server_mgr_start_feedback(DBusConnection* conn, DBusMessage* msg); diff --git a/server/vcd_engine_agent.c b/server/vcd_engine_agent.c index 6e45a4d..531dbdf 100644 --- a/server/vcd_engine_agent.c +++ b/server/vcd_engine_agent.c @@ -24,7 +24,6 @@ #include "vcd_main.h" #include "vcd_recorder.h" #include "vcd_dbus.h" -#include "vcd_tidl.h" #include "vce_internal.h" /* @@ -923,7 +922,7 @@ int vcd_engine_agent_start_recording() SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to start recorder : result(%d)", ret); vcd_engine_recognize_cancel(); /* Send error cb to manager */ - vcdc_tidl_send_error_to_manager(vcd_client_manager_get_pid(), VCD_ERROR_OPERATION_FAILED, "voice_framework.error.vcfw.send_rc_fail"); + vcdc_send_error_signal_to_manager(vcd_client_manager_get_pid(), VCD_ERROR_OPERATION_FAILED, "voice_framework.error.vcfw.send_rc_fail"); return ret; } diff --git a/server/vcd_main.h b/server/vcd_main.h index 7636495..70bcd18 100644 --- a/server/vcd_main.h +++ b/server/vcd_main.h @@ -98,12 +98,6 @@ struct vce_cmd_s { int index; }; -// TODO: move vcd_client_type_e to vcd_tidl.h after migrate from dbus to tidl done -typedef enum { - VCD_CLIENT_TYPE_NORMAL, - VCD_CLIENT_TYPE_WIDGET, - VCD_CLIENT_TYPE_MANAGER -} vcd_client_type_e; #ifdef __cplusplus } diff --git a/server/vcd_recorder.c b/server/vcd_recorder.c index 9c4845f..cadb81d 100644 --- a/server/vcd_recorder.c +++ b/server/vcd_recorder.c @@ -22,7 +22,6 @@ #include "vcd_client_data.h" #include "vcd_config.h" #include "vcd_dbus.h" -#include "vcd_tidl.h" #include "vcd_engine_agent.h" #include "vcd_recorder.h" #include "dependency_audio_manager.h" diff --git a/server/vcd_server.c b/server/vcd_server.c index 7f0d713..faf41e5 100644 --- a/server/vcd_server.c +++ b/server/vcd_server.c @@ -29,7 +29,6 @@ #include "vcd_config.h" #include "vcd_recorder.h" #include "vcd_dbus.h" -#include "vcd_tidl.h" #include "vce_internal.h" #include "voice_control_command_expand.h" @@ -146,9 +145,9 @@ static int __server_recorder_callback(const void* data, const unsigned int lengt ecore_timer_add(0, __cancel_by_interrupt, NULL); /* Send error cb to manager */ if (VCE_ERROR_OUT_OF_NETWORK == ret) { - vcdc_tidl_send_error_to_manager(vcd_client_manager_get_pid(), VCD_ERROR_TIMED_OUT, "voice_framework.error.engine.set_recording_fail"); + vcdc_send_error_signal_to_manager(vcd_client_manager_get_pid(), VCD_ERROR_TIMED_OUT, "voice_framework.error.engine.set_recording_fail"); } else { - vcdc_tidl_send_error_to_manager(vcd_client_manager_get_pid(), ret, "voice_framework.error.engine.set_recording_fail"); + vcdc_send_error_signal_to_manager(vcd_client_manager_get_pid(), ret, "voice_framework.error.engine.set_recording_fail"); } return 0; } @@ -1124,7 +1123,7 @@ int vcd_send_error(vce_error_e error, const char* msg, void *user_data) int pid = __get_tts_played_pid(); ret = vcdc_send_error_signal_to_app(pid, error, error_msg); } else { - ret = vcdc_tidl_send_error_to_manager(vcd_client_manager_get_pid(), error, error_msg); + ret = vcdc_send_error_signal_to_manager(vcd_client_manager_get_pid(), error, error_msg); ecore_main_loop_thread_safe_call_async(__cancel_by_error, NULL); } @@ -1348,15 +1347,6 @@ int vcd_initialize(vce_request_callback_s *callback) } return VCD_ERROR_OPERATION_FAILED; } - - /* Open tidl connection */ - if (0 != vcd_mgr_tidl_open_connection()) { - SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to open tidl connection"); - if (TRUE != vcd_finalize()) { - SLOG(LOG_ERROR, TAG_VCD, "[Server Error] Fail to finalize"); - } - return VCD_ERROR_OPERATION_FAILED; - } // } vcd_config_set_service_state(VCD_STATE_READY); @@ -1436,16 +1426,11 @@ bool vcd_finalize() vcdc_send_service_state(VCD_STATE_NONE); } - /* Close dbus connection */ + /* Open dbus connection */ if (0 != vcd_dbus_close_connection()) { SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to close connection"); } - /* Close tidl connection */ - if (0 != vcd_mgr_tidl_close_connection()) { - SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to close connection"); - } - SLOG(LOG_ERROR, TAG_VCD, "[Server] mode finalize"); return true; @@ -1913,7 +1898,7 @@ static int __start_internal_recognition() /* Send error cb to manager */ int pid = vcd_client_widget_get_foreground_pid(); if (-1 != pid) - vcdc_tidl_send_error_to_manager(vcd_client_manager_get_pid(), VCD_ERROR_OPERATION_FAILED, "voice_framework.error.vcfw.collect_command_fail"); + vcdc_send_error_signal_to_manager(vcd_client_manager_get_pid(), VCD_ERROR_OPERATION_FAILED, "voice_framework.error.vcfw.collect_command_fail"); return VCD_ERROR_OPERATION_FAILED; } @@ -1924,7 +1909,7 @@ static int __start_internal_recognition() /* Send error cb to manager */ int pid = vcd_client_widget_get_foreground_pid(); if (-1 != pid) - vcdc_tidl_send_error_to_manager(vcd_client_manager_get_pid(), VCD_ERROR_OPERATION_FAILED, "voice_framework.error.engine.set_commands_fail"); + vcdc_send_error_signal_to_manager(vcd_client_manager_get_pid(), VCD_ERROR_OPERATION_FAILED, "voice_framework.error.engine.set_commands_fail"); return VCD_ERROR_OPERATION_FAILED; } @@ -1944,7 +1929,7 @@ static int __start_internal_recognition() /* Send error cb to manager */ int pid = vcd_client_widget_get_foreground_pid(); if (-1 != pid) - vcdc_tidl_send_error_to_manager(vcd_client_manager_get_pid(), ret, "voice_framework.error.engine.start_fail"); + vcdc_send_error_signal_to_manager(vcd_client_manager_get_pid(), ret, "voice_framework.error.engine.start_fail"); return ret; } @@ -1959,7 +1944,7 @@ static int __start_internal_recognition() /* Send error cb to manager */ int pid = vcd_client_widget_get_foreground_pid(); if (-1 != pid) - vcdc_tidl_send_error_to_manager(vcd_client_manager_get_pid(), VCD_ERROR_OPERATION_FAILED, "voice_framework.error.vcfw.send_rc_fail"); + vcdc_send_error_signal_to_manager(vcd_client_manager_get_pid(), VCD_ERROR_OPERATION_FAILED, "voice_framework.error.vcfw.send_rc_fail"); return ret; } #endif @@ -2345,7 +2330,7 @@ int vcd_server_mgr_stop_feedback(void) return VCD_ERROR_NONE; } -int vcd_server_mgr_send_audio_streaming(int pid, int event, const char* buffer, unsigned int len) +int vcd_server_mgr_send_audio_streaming(int pid, int event, char* buffer, unsigned int len) { SLOG(LOG_INFO, TAG_VCD, "[DEBUG] Send Audio Streaming from Multi-assistant. event(%d), buffer(%p), len(%d)", event, &buffer, len); diff --git a/server/vcd_server.h b/server/vcd_server.h index 4f1286d..7597b3d 100644 --- a/server/vcd_server.h +++ b/server/vcd_server.h @@ -87,7 +87,7 @@ int vcd_server_mgr_start_feedback(void); int vcd_server_mgr_stop_feedback(void); /* for Multi-assistant */ -int vcd_server_mgr_send_audio_streaming(int pid, int event, const char* buffer, unsigned int len); +int vcd_server_mgr_send_audio_streaming(int pid, int event, char* buffer, unsigned int len); /* diff --git a/server/vcd_tidl.c b/server/vcd_tidl.c deleted file mode 100644 index d5917a5..0000000 --- a/server/vcd_tidl.c +++ /dev/null @@ -1,1204 +0,0 @@ -/* -* Copyright (c) 2022 Samsung Electronics Co., Ltd All Rights Reserved -* -* Licensed under the Apache License, Version 2.0 (the License); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an AS IS BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include "vcd_client_data.h" -#include "vcd_main.h" -#include "vcd_server.h" -#include "vcd_config.h" - -#include "vcd_tidl.h" -#include "vcd_mgr_stub.h" -#include "vcd_mgr_proxy.h" - -static rpc_port_stub_vc_mgr_callback_s g_mgr_callback; - -static pthread_mutex_t g_mgr_tidl_info_mutex = PTHREAD_MUTEX_INITIALIZER; - -static int g_volume_count = 0; - -static void __on_connected(rpc_port_proxy_vcd_mgr_h h, void *user_data) -{ - manager_tidl_info_s* mgr_tidl_info = vcd_client_manager_get_tidl_info(); - - if (NULL == mgr_tidl_info) { - SLOG(LOG_ERROR, TAG_VCD, "[TIDL] tidl proxy info not allocated"); - return; - } - - mgr_tidl_info->connected = true; - mgr_tidl_info->connection_requesting = false; - - SLOG(LOG_INFO, TAG_VCD, "Connected to manager"); -} - -static void __on_disconnected(rpc_port_proxy_vcd_mgr_h h, void *user_data) -{ - manager_tidl_info_s* mgr_tidl_info = vcd_client_manager_get_tidl_info(); - - if (NULL == mgr_tidl_info) { - SLOG(LOG_ERROR, TAG_VCD, "[TIDL] tidl proxy info not allocated"); - return; - } - - mgr_tidl_info->connected = false; - mgr_tidl_info->connection_requesting = false; - - SLOG(LOG_INFO, TAG_VCD, "Disonnected to manager"); -} - -static void __on_rejected(rpc_port_proxy_vcd_mgr_h h, void *user_data) -{ - manager_tidl_info_s* mgr_tidl_info = vcd_client_manager_get_tidl_info(); - - if (NULL == mgr_tidl_info) { - SLOG(LOG_ERROR, TAG_VCD, "[TIDL] tidl proxy info not allocated"); - return; - } - - mgr_tidl_info->connection_requesting = false; - - SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Rejected from manager"); -} - -static rpc_port_proxy_vcd_mgr_h __create_rpc_port(const char* engine_app_id, manager_tidl_info_s* mgr_tidl_info) -{ - SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] __create_rpc_port"); - rpc_port_proxy_vcd_mgr_callback_s rpc_callback = { - .connected = __on_connected, - .disconnected = __on_disconnected, - .rejected = __on_rejected - }; - - rpc_port_proxy_vcd_mgr_h handle = NULL; - if (0 != rpc_port_proxy_vcd_mgr_create(engine_app_id, &rpc_callback, NULL, &handle)) { - SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to create proxy"); - return NULL; - } - - return handle; -} - -static void __request_tidl_connect_sync(manager_tidl_info_s* mgr_tidl_info) -{ - if (NULL == mgr_tidl_info) { - SLOG(LOG_ERROR, TAG_VCD, "[TIDL] tidl proxy info not allocated"); - return; - } - - if (mgr_tidl_info->connection_requesting) { - return; - } - - int ret = rpc_port_proxy_vcd_mgr_connect_sync(mgr_tidl_info->rpc_h); - SLOG(LOG_INFO, TAG_VCD, "[INFO] Request connection to stub. ret(%d)", ret); - - if (0 == ret) { - mgr_tidl_info->connection_requesting = true; - } -} - -void __send_msg(bundle* msg, vcd_client_type_e type) -{ - SLOG(LOG_INFO, TAG_VCD, "[TIDL] send msg start"); - - if (VCD_CLIENT_TYPE_MANAGER == type) { - pthread_mutex_lock(&g_mgr_tidl_info_mutex); - - SLOG(LOG_INFO, TAG_VCD, "[TIDL] message to manager"); - manager_tidl_info_s* mgr_tidl_info = vcd_client_manager_get_tidl_info(); - if (NULL == mgr_tidl_info) { - SLOG(LOG_ERROR, TAG_VCD, "[TIDL] tidl proxy info not allocated"); - pthread_mutex_unlock(&g_mgr_tidl_info_mutex); - return; - } - - rpc_port_stub_vc_mgr_notify_cb_h handle = mgr_tidl_info->notify_cb; - if (NULL == handle) { - SLOG(LOG_ERROR, TAG_VCD, "[TIDL] notify callback handle is null"); - pthread_mutex_unlock(&g_mgr_tidl_info_mutex); - return; - } - - if (0 != rpc_port_stub_vc_mgr_notify_cb_invoke(handle, msg)) { - SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to send msg"); - pthread_mutex_unlock(&g_mgr_tidl_info_mutex); - return; - } - pthread_mutex_unlock(&g_mgr_tidl_info_mutex); - } - - SLOG(LOG_INFO, TAG_VCD, "[TIDL] send msg end"); -} - -static void __vc_mgr_create_cb(rpc_port_stub_vc_mgr_context_h context, void *user_data) -{ - char *sender = NULL; - - rpc_port_stub_vc_mgr_context_get_sender(context, &sender); - if (!sender){ - SLOG(LOG_ERROR, TAG_VCD, "Sender is NULL"); - return; - } - - SLOG(LOG_DEBUG, TAG_VCD, "@@@ Manager connect. appid(%s)", sender); - - free(sender); -} - -static void __vc_mgr_terminate_cb(rpc_port_stub_vc_mgr_context_h context, void *user_data) -{ - pthread_mutex_lock(&g_mgr_tidl_info_mutex); - manager_tidl_info_s* mgr_tidl_info = vcd_client_manager_get_tidl_info(); - if (NULL == mgr_tidl_info) { - SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to get manager tidl info."); - pthread_mutex_unlock(&g_mgr_tidl_info_mutex); - return; - } - - SLOG(LOG_DEBUG, TAG_VCD, "@@@ VC MANAGER FINALIZE. pid(%u)", mgr_tidl_info->pid); - - if (0 != vcd_client_manager_unset_tidl_notify_cb()) { - SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to unset notify callback"); - } - - if (0 != vcd_client_manager_unset_tidl_send_buffer_cb()) { - SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to unset send buffer callback"); - } - - if (0 != vcd_client_manager_delete_tidl_info()) { - SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to delete manager tidl info"); - } - mgr_tidl_info = NULL; - - SLOG(LOG_DEBUG, TAG_VCD, "@@@"); - - pthread_mutex_unlock(&g_mgr_tidl_info_mutex); - - - char *sender = NULL; - rpc_port_stub_vc_mgr_context_get_sender(context, &sender); - if (!sender) - return; - - SLOG(LOG_INFO, TAG_VCD, "@@@ Manager disconnect. appid(%s)", sender); - - free(sender); -} - -static void __vc_mgr_register_cb_cb(rpc_port_stub_vc_mgr_context_h context, int pid, rpc_port_stub_vc_mgr_notify_cb_h notify_callback, rpc_port_stub_vc_mgr_send_buffer_cb_h send_buffer_callback, void *user_data) -{ - pthread_mutex_lock(&g_mgr_tidl_info_mutex); - SLOG(LOG_INFO, TAG_VCD, "@@@ VC MANAGER REGISTER CALLBACK"); - - int ret = -1; - ret = vcd_client_manger_create_tidl_info(pid); - - if (0 != ret) { - SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to create manager tidl info."); - pthread_mutex_unlock(&g_mgr_tidl_info_mutex); - return; - } - - manager_tidl_info_s* mgr_tidl_info = vcd_client_manager_get_tidl_info(); - - if (NULL == mgr_tidl_info) { - SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to get manager tidl info. pid(%d)", pid); - pthread_mutex_unlock(&g_mgr_tidl_info_mutex); - return; - } - - char *sender = NULL; - rpc_port_stub_vc_mgr_context_get_sender(context, &sender); - - if (!sender){ - SLOG(LOG_ERROR, TAG_VCD, "Sender is NULL"); - pthread_mutex_unlock(&g_mgr_tidl_info_mutex); - return; - } - - mgr_tidl_info->rpc_h = __create_rpc_port(sender, mgr_tidl_info); - - if (NULL == mgr_tidl_info->rpc_h) { - SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to create server proxy"); - } else { - SLOG(LOG_INFO, TAG_VCD, "[TIDL] rpc_h(%p), engine_app_id(%s)", mgr_tidl_info->rpc_h, sender); - } - - free(sender); - - if (0 != vcd_client_manager_set_tidl_notify_cb(notify_callback, user_data)) { - SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to set notify callback"); - } else { - SLOG(LOG_INFO, TAG_VCD, "[TIDL] Succeed to set notify callback."); - } - - if (0 != vcd_client_manager_set_tidl_send_buffer_cb(send_buffer_callback, user_data)) { - SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to set send buffer callback"); - } else { - SLOG(LOG_INFO, TAG_VCD, "[TIDL] Succeed to set send buffer callback."); - } - - pthread_mutex_unlock(&g_mgr_tidl_info_mutex); - - __request_tidl_connect_sync(mgr_tidl_info); - - SLOG(LOG_DEBUG, TAG_VCD, "@@@"); -} - -static int __vc_mgr_initialize_cb(rpc_port_stub_vc_mgr_context_h context, int pid, int audio_streaming_mode, int *service_state, int *foreground, int *daemon_pid, void *user_data) -{ - SLOG(LOG_INFO, TAG_VCD, "@@@ VCD Manager Initialize"); - - int ret = -1; - - vcd_config_set_audio_streaming_mode((vcd_audio_streaming_mode_e)audio_streaming_mode); - ret = vcd_server_mgr_initialize(pid, audio_streaming_mode); - if (0 != ret) { - SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret); - return ret; - } - *service_state = vcd_server_get_service_state(); - *foreground = vcd_server_get_foreground(); - *daemon_pid = getpid(); - - 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); - SLOG(LOG_DEBUG, TAG_VCD, "@@@"); - return ret; -} - -static int __vc_mgr_finalize_cb(rpc_port_stub_vc_mgr_context_h context, int pid, void *user_data) -{ - SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Manager Finalize"); - SLOG(LOG_INFO, TAG_VCD, "[IN] vcd mgr finalize : pid(%d)", pid); - - int ret = -1; - - ret = vcd_server_mgr_finalize(pid); - if (0 != ret) { - SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret); - } - - SLOG(LOG_DEBUG, TAG_VCD, "@@@"); - - return ret; -} - -static int __vc_mgr_set_command_cb(rpc_port_stub_vc_mgr_context_h context, int pid, void *user_data) -{ - SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Manager Set command"); - SLOG(LOG_INFO, TAG_VCD, "[IN] vcd mgr set command : pid(%d)", pid); - - int ret = -1; - - ret = vcd_server_mgr_set_command(pid); - if (0 != ret) { - SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret); - return ret; - } - - SLOG(LOG_DEBUG, TAG_VCD, "@@@"); - - return ret; -} - -static int __vc_mgr_unset_command_cb(rpc_port_stub_vc_mgr_context_h context, int pid, void *user_data) -{ - SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Manager unset command"); - SLOG(LOG_INFO, TAG_VCD, "[IN] vcd mgr unset command : pid(%d)", pid); - - int ret = -1; - - ret = vcd_server_mgr_unset_command(pid); - if (0 != ret) { - SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret); - return ret; - } - - SLOG(LOG_DEBUG, TAG_VCD, "@@@"); - - return ret; -} - -static int __vc_mgr_set_demandable_client_cb(rpc_port_stub_vc_mgr_context_h context, int pid, void *user_data) -{ - SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Manager Set demandable client"); - SLOG(LOG_INFO, TAG_VCD, "[IN] vcd mgr set demandable client : pid(%d)", pid); - - int ret = -1; - - ret = vcd_server_mgr_set_demandable_client(pid); - if (0 != ret) { - SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret); - return ret; - } - - SLOG(LOG_DEBUG, TAG_VCD, "@@@"); - - return ret; -} - -static int __vc_mgr_set_audio_type_cb(rpc_port_stub_vc_mgr_context_h context, int pid, const char *audio_type, void *user_data) -{ - SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Manager set audio type"); - SLOG(LOG_INFO, TAG_VCD, "[IN] vcd mgr set audio type : pid(%d), audio type(%s)", pid, audio_type); - - int ret = -1; - - ret = vcd_server_mgr_set_audio_type(pid, audio_type); - if (0 != ret) { - SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret); - return ret; - } - - SLOG(LOG_DEBUG, TAG_VCD, "@@@"); - - return ret; -} - -static int __vc_mgr_get_audio_type_cb(rpc_port_stub_vc_mgr_context_h context, int pid, char **audio_type, void *user_data) -{ - SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Manager get audio type"); - SLOG(LOG_INFO, TAG_VCD, "[IN] vcd mgr set audio type : pid(%d)", pid); - - int ret = -1; - char* tmp_audio_type = NULL; - - ret = vcd_server_mgr_get_audio_type(pid, &tmp_audio_type); - if (0 != ret) { - SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret); - free(tmp_audio_type); - return ret; - } - - *audio_type = strdup(tmp_audio_type); - free(tmp_audio_type); - - SLOG(LOG_DEBUG, TAG_VCD, "@@@"); - - return ret; -} - -static void __vc_mgr_set_private_data_cb(rpc_port_stub_vc_mgr_context_h context, int pid, const char *key, const char *data, void *user_data) -{ - SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Manager set private data"); - SLOG(LOG_INFO, TAG_VCD, "[IN] vcd mgr set domain : pid(%d), key(%s), data(%s)", pid, key, data); - - int ret = -1; - - ret = vcd_server_mgr_set_private_data(pid, key, data); - if (0 != ret) { - SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to set private data"); - SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret); - } - - SLOG(LOG_DEBUG, TAG_VCD, "@@@"); -} - -static int __vc_mgr_get_private_data_cb(rpc_port_stub_vc_mgr_context_h context, int pid, const char *key, char **data, void *user_data) -{ - SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Manager get private data"); - SLOG(LOG_INFO, TAG_VCD, "[IN] vcd mgr get private data : pid(%d), key(%s)", pid, key); - - int ret = -1; - char *temp_data = NULL; - - ret = vcd_server_mgr_get_private_data(pid, key, &temp_data); - if (0 != ret) { - SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret); - return ret; - } - if (NULL == temp_data) { - SLOG(LOG_INFO, TAG_VCD, "data parameter is NULL"); - temp_data = strdup("#NULL"); - } - - *data = strdup(temp_data); - free(temp_data); - - SLOG(LOG_DEBUG, TAG_VCD, "@@@"); - - return ret; -} - -static int __vc_mgr_set_client_info_cb(rpc_port_stub_vc_mgr_context_h context, int pid, void *user_data) -{ - SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Manager set client info"); - SLOG(LOG_INFO, TAG_VCD, "[IN] vcd mgr set client info : pid(%d)", pid); - - int ret = -1; - - ret = vcd_server_mgr_set_client_info(pid); - if (0 != ret) { - SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret); - return ret; - } - - SLOG(LOG_DEBUG, TAG_VCD, "@@@"); - - return ret; -} - -static int __vc_mgr_set_domain_cb(rpc_port_stub_vc_mgr_context_h context, int pid, const char *domain, void *user_data) -{ - SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Manager set domain type"); - SLOG(LOG_INFO, TAG_VCD, "[IN] vcd mgr set domain : pid(%d), domain(%s)", pid, domain); - - int ret = -1; - - ret = vcd_server_mgr_set_domain(pid, domain); - if (0 != ret) { - SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret); - return ret; - } - - SLOG(LOG_DEBUG, TAG_VCD, "@@@"); - - return ret; -} - -static void __vc_mgr_do_action_cb(rpc_port_stub_vc_mgr_context_h context, int pid, int type, const char *send_event, void *user_data) -{ - SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Manager request to do action"); - SLOG(LOG_INFO, TAG_VCD, "[IN] vcd mgr request to do action : pid(%d), type(%d) send_event(%s)", pid, type, send_event); - - int ret = -1; - - ret = vcd_server_mgr_do_action(pid, type, send_event); - if (0 != ret) { - SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret); - } - - SLOG(LOG_DEBUG, TAG_VCD, "@@@"); -} - -static int __vc_mgr_start_cb(rpc_port_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) -{ - SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Manager start"); - SLOG(LOG_INFO, TAG_VCD, "[IN] vcd check enabled or disabled command types. disabled cmd type(%d)", disabled_cmd_type); - - int ret = -1; - - vcd_server_mgr_set_disabled_command_type(pid, disabled_cmd_type); - - 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); - ret = vcd_server_mgr_start((vcd_recognition_mode_e)recognition_mode, exclusive_command_option, start_by_client); - if (0 != ret) { - SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret); - return ret; - } - - SLOG(LOG_DEBUG, TAG_VCD, "@@@"); - - return ret; -} - -static int __vc_mgr_stop_cb(rpc_port_stub_vc_mgr_context_h context, int pid, void *user_data) -{ - SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Manager stop"); - SLOG(LOG_INFO, TAG_VCD, "[IN] vcd mgr stop : pid(%d)", pid); - - int ret = -1; - - ret = vcd_server_mgr_stop(); - - if (0 != ret) { - SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret); - return ret; - } - - SLOG(LOG_DEBUG, TAG_VCD, "@@@"); - - return ret; -} - -static int __vc_mgr_cancel_cb(rpc_port_stub_vc_mgr_context_h context, int pid, void *user_data) -{ - SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Manager cancel"); - SLOG(LOG_INFO, TAG_VCD, "[IN] vcd mgr cancel : pid(%d)", pid); - - int ret = -1; - - ret = vcd_server_mgr_cancel(); - if (0 != ret) { - SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret); - return ret; - } - - SLOG(LOG_DEBUG, TAG_VCD, "@@@"); - - return ret; -} - -static void __vc_mgr_set_audio_streaming_mode_cb(rpc_port_stub_vc_mgr_context_h context, int pid, int mode, void *user_data) -{ - SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Manager set audio streaming mode"); - SLOG(LOG_INFO, TAG_VCD, "[IN] vcd mgr set audio streaming mode : pid(%d) mode(%d)", pid, mode); - - vcd_config_set_audio_streaming_mode((vcd_audio_streaming_mode_e)mode); - - SLOG(LOG_DEBUG, TAG_VCD, "@@@"); -} - -static void __vc_mgr_send_specific_engine_request_cb(rpc_port_stub_vc_mgr_context_h context, int pid, const char *engine_app_id, const char *event, const char *request, void *user_data) -{ - SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Manager specific engine request"); - - int ret = -1; - gsize decodingSize = 0; - gchar *gDecodedRequest = (gchar *)g_base64_decode((const gchar *)request, &decodingSize); - - if (gDecodedRequest) { - ret = vcd_server_mgr_send_specific_engine_request(pid, engine_app_id, event, gDecodedRequest); - if (0 != ret) { - SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret); - } - - 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); - g_free(gDecodedRequest); - } - - SLOG(LOG_DEBUG, TAG_VCD, "@@@"); -} - -static void __vc_mgr_send_result_selection_cb(rpc_port_stub_vc_mgr_context_h context, int pid, void *user_data) -{ - SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Manager result selection"); - SLOG(LOG_INFO, TAG_VCD, "[IN] vcd mgr result selection : pid(%d)", pid); - - vcd_server_mgr_result_select(); - - SLOG(LOG_DEBUG, TAG_VCD, "@@@"); -} - -static void __vc_mgr_send_utterance_status_cb(rpc_port_stub_vc_mgr_context_h context, int utt_id, int utt_status, void *user_data) -{ - SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Manager send utterance status"); - SLOG(LOG_INFO, TAG_VCD, "[IN] vcd mgr send utterance status : utt_id(%d), utt_status(%d)", utt_id, utt_status); - // TODO: send parameter to client - - SLOG(LOG_DEBUG, TAG_VCD, "@@@"); -} - -static void __vc_mgr_send_audio_streaming_cb(rpc_port_stub_vc_mgr_context_h context, int pid, int event, rpc_port_stub_array_char_h data, void *user_data) -{ - SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Manager send audio streaming"); - - char* buffer = NULL; - int len = 0; - int ret = -1; - rpc_port_stub_array_char_get(data, &buffer, &len); - - SLOG(LOG_INFO, TAG_VCD, "[IN] vcd mgr send audio streaming : pid(%d), event(%d), buffer(%p), len(%d)", pid, event, buffer, len); - - ret = vcd_server_mgr_send_audio_streaming(pid, event, buffer, (unsigned int)len); - if (0 != ret) { - SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret); - } - - SLOG(LOG_DEBUG, TAG_VCD, "@@@"); -} - -int vcd_mgr_tidl_open_connection() -{ - SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] vcd_tidl_open_connection"); - - g_mgr_callback.create = __vc_mgr_create_cb; - g_mgr_callback.terminate = __vc_mgr_terminate_cb; - g_mgr_callback.register_cb = __vc_mgr_register_cb_cb; - g_mgr_callback.initialize = __vc_mgr_initialize_cb; - g_mgr_callback.finalize = __vc_mgr_finalize_cb; - g_mgr_callback.set_command = __vc_mgr_set_command_cb; - g_mgr_callback.unset_command = __vc_mgr_unset_command_cb; - g_mgr_callback.demandable_client = __vc_mgr_set_demandable_client_cb; - g_mgr_callback.set_audio_type = __vc_mgr_set_audio_type_cb; - g_mgr_callback.get_audio_type = __vc_mgr_get_audio_type_cb; - g_mgr_callback.set_private_data = __vc_mgr_set_private_data_cb; - g_mgr_callback.get_private_data = __vc_mgr_get_private_data_cb; - g_mgr_callback.set_client_info = __vc_mgr_set_client_info_cb; - g_mgr_callback.set_domain = __vc_mgr_set_domain_cb; - g_mgr_callback.do_action = __vc_mgr_do_action_cb; - g_mgr_callback.start = __vc_mgr_start_cb; - g_mgr_callback.stop = __vc_mgr_stop_cb; - g_mgr_callback.cancel = __vc_mgr_cancel_cb; - g_mgr_callback.set_audio_streaming_mode = __vc_mgr_set_audio_streaming_mode_cb; - g_mgr_callback.send_specific_engine_request = __vc_mgr_send_specific_engine_request_cb; - g_mgr_callback.send_result_selection = __vc_mgr_send_result_selection_cb; - g_mgr_callback.send_utterance_status = __vc_mgr_send_utterance_status_cb; - g_mgr_callback.send_audio_streaming = __vc_mgr_send_audio_streaming_cb; - - int ret = -1; - int count = 0; - while (VC_RETRY_MIN_COUNT >= count) { - ret = rpc_port_stub_vc_mgr_register(&g_mgr_callback, NULL); - if (0 == ret) { - SLOG(LOG_DEBUG, TAG_VCD, "register callback"); - return VCD_ERROR_NONE; - } - usleep(100000); - count++; - } - - SLOG(LOG_ERROR, TAG_VCD, "Fail to register callback(%d)", ret); - return VCD_ERROR_OPERATION_FAILED; -} - -int vcd_mgr_tidl_close_connection() -{ - SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Close connection"); - rpc_port_stub_vc_mgr_unregister(); - - return VCD_ERROR_NONE; -} - -// TODO: remove _tidl after all dbus removed -int vcdc_tidl_send_hello(int pid, vcd_client_type_e type) -{ - SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Send hello"); - - char tmp_pid[10] = {0, }; - - bundle* msg = bundle_create(); - snprintf(tmp_pid, 10, "%d", pid); - - bundle_add_str(msg, VC_MANAGER_BUNDLE_METHOD, VCD_MANAGER_METHOD_HELLO); - bundle_add_str(msg, VC_MANAGER_BUNDLE_MESSAGE, tmp_pid); - - SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] VCD SEND MESSAGE"); - - __send_msg(msg, VCD_CLIENT_TYPE_MANAGER); - bundle_free(msg); - - return VCD_ERROR_NONE; -} - -int vcdc_send_set_volume(int manager_pid, float volume) -{ - SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Set volume"); - - char tmp_volume[20] = {0, }; - - bundle* msg = bundle_create(); - - snprintf(tmp_volume, 20, "%.6f", volume); - bundle_add_str(msg, VC_MANAGER_BUNDLE_METHOD, VCD_MANAGER_METHOD_SET_VOLUME); - bundle_add_str(msg, VC_MANAGER_BUNDLE_MESSAGE, tmp_volume); - - - SLOG(LOG_DEBUG, TAG_VCD, ">>>> VCD SEND MESSAGE"); - __send_msg(msg, VCD_CLIENT_TYPE_MANAGER); - if (20 == g_volume_count) { - SLOG(LOG_INFO, TAG_VCD, "@@ Send set volume : pid(%d), volume(%f)", manager_pid, volume); - g_volume_count = 0; - } - g_volume_count++; - - bundle_free(msg); - - return VCD_ERROR_NONE; -} -// TODO: remove tidl after all dbus migrate to tidl -int vcdc_tidl_send_result(int pid, int manager_pid, int cmd_type) -{ - SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Send result"); - - bundle* msg = bundle_create(); - - bundle_add_str(msg, VC_MANAGER_BUNDLE_METHOD, VCD_MANAGER_METHOD_RESULT); - - SLOG(LOG_DEBUG, TAG_VCD, ">>>> VCD SEND MESSAGE"); - - __send_msg(msg, VCD_CLIENT_TYPE_MANAGER); - bundle_free(msg); - - return VCD_ERROR_NONE; -} - -int vcdc_send_pre_result_to_manager(int manager_pid, int event, const char* pre_result) -{ - SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Send pre result to manager"); - - char tmp_event[10] = {0, }; - - bundle* msg = bundle_create(); - snprintf(tmp_event, 10, "%d", event); - - bundle_add_str(msg, VC_MANAGER_BUNDLE_METHOD, VCD_MANAGER_METHOD_PRE_RESULT); - bundle_add_str(msg, VC_MANAGER_BUNDLE_EVENT, tmp_event); - bundle_add_str(msg, VC_MANAGER_BUNDLE_PRE_RESULT, pre_result); - - SLOG(LOG_DEBUG, TAG_VCD, ">>>> VCD SEND MESSAGE"); - - __send_msg(msg, VCD_CLIENT_TYPE_MANAGER); - bundle_free(msg); - - return VCD_ERROR_NONE; -} - -int vcdc_send_specific_engine_result_to_manager(int manager_pid, const char* engine_app_id, const char* event, const char* result) -{ - SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Send specific engine result to manager"); - - bundle* msg = bundle_create(); - - gchar *gEncodedResult = g_base64_encode((const guchar*)result, strlen(result)); - - bundle_add_str(msg, VC_MANAGER_BUNDLE_METHOD, VCD_MANAGER_METHOD_SPECIFIC_ENGINE_RESULT); - bundle_add_str(msg, VC_MANAGER_BUNDLE_ENGINE_APP_ID, engine_app_id); - bundle_add_str(msg, VC_MANAGER_BUNDLE_EVENT, event); - bundle_add_str(msg, VC_MANAGER_BUNDLE_RESULT, gEncodedResult); - - SLOG(LOG_DEBUG, TAG_VCD, ">>>> VCD SEND MESSAGE"); - - __send_msg(msg, VCD_CLIENT_TYPE_MANAGER); - bundle_free(msg); - - if (gEncodedResult) - g_free(gEncodedResult); - - return VCD_ERROR_NONE; -} - -int vcdc_send_result_to_manager(int manager_pid, int result_type) -{ - SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Send result to manager"); - - char tmp_result[10] = {0, }; - - bundle* msg = bundle_create(); - snprintf(tmp_result, 10, "%d", result_type); - - bundle_add_str(msg, VC_MANAGER_BUNDLE_METHOD, VCD_MANAGER_METHOD_ALL_RESULT); - bundle_add_str(msg, VC_MANAGER_BUNDLE_MESSAGE, tmp_result); - - - SLOG(LOG_DEBUG, TAG_VCD, ">>>> VCD SEND MESSAGE"); - - __send_msg(msg, VCD_CLIENT_TYPE_MANAGER); - bundle_free(msg); - - return VCD_ERROR_NONE; -} - -int vcdc_send_speech_detected(int manager_pid) -{ - SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Send speech detected"); - - bundle* msg = bundle_create(); - - bundle_add_str(msg, VC_MANAGER_BUNDLE_METHOD, VCD_MANAGER_METHOD_SPEECH_DETECTED); - - SLOG(LOG_DEBUG, TAG_VCD, ">>>> VCD SEND MESSAGE"); - - __send_msg(msg, VCD_CLIENT_TYPE_MANAGER); - bundle_free(msg); - - return VCD_ERROR_NONE; -} - -int vcdc_send_service_state(vcd_state_e state) -{ - SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Send service state"); - - char tmp_state[10] = {0, }; - - bundle* msg = bundle_create(); - snprintf(tmp_state, 10, "%d", (int)state); - - bundle_add_str(msg, VC_MANAGER_BUNDLE_METHOD, VCD_MANAGER_METHOD_SET_SERVICE_STATE); - bundle_add_str(msg, VC_MANAGER_BUNDLE_MESSAGE, tmp_state); - - SLOG(LOG_DEBUG, TAG_VCD, ">>>> VCD SEND MESSAGE"); - - __send_msg(msg, VCD_CLIENT_TYPE_MANAGER); - bundle_free(msg); - - return VCD_ERROR_NONE; -} - -int vcdc_send_dialog(int manager_pid, int pid, const char* disp_text, const char* utt_text, int continuous) -{ - SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Send dialog"); - - char tmp_pid[10] = {0, }; - char tmp_continuous[10] = {0, }; - char* tmp_disp_text = NULL; - char* tmp_utt_text = NULL; - bundle* msg = bundle_create(); - snprintf(tmp_pid, 10, "%d", pid); - snprintf(tmp_continuous, 10, "%d", continuous); - - if (NULL == disp_text) { - tmp_disp_text = strdup("#NULL"); - } else { - tmp_disp_text = strdup(disp_text); - } - - if (NULL == utt_text) { - tmp_utt_text = strdup("#NULL"); - } else { - tmp_utt_text = strdup(utt_text); - } - - bundle_add_str(msg, VC_MANAGER_BUNDLE_METHOD, VCD_MANAGER_METHOD_DIALOG); - bundle_add_str(msg, VC_MANAGER_BUNDLE_MESSAGE, tmp_pid); - bundle_add_str(msg, VC_MANAGER_BUNDLE_DISP_TEXT, tmp_disp_text); - bundle_add_str(msg, VC_MANAGER_BUNDLE_UTT_TEXT, tmp_utt_text); - bundle_add_str(msg, VC_MANAGER_BUNDLE_CONTINUOUS, tmp_continuous); - - SLOG(LOG_DEBUG, TAG_VCD, ">>>> VCD SEND MESSAGE"); - - __send_msg(msg, VCD_CLIENT_TYPE_MANAGER); - bundle_free(msg); - free(tmp_disp_text); - free(tmp_utt_text); - - return VCD_ERROR_NONE; -} - -int vcdc_tidl_send_error_to_manager(int manager_pid, int reason, char *err_msg) -{ - SLOG(LOG_ERROR, TAG_VCD, "[TIDL] Send error signal to manager"); - - char tmp_reason[10] = {0, }; - char tmp_daemon_pid[10] = {0, }; - char *temp_msg = NULL; - - if (NULL == err_msg) { - SLOG(LOG_WARN, TAG_VCD, "[TIDL ERROR] Input parameter is NULL"); - temp_msg = strdup("#NULL"); - } else { - temp_msg = strdup(err_msg); - } - - bundle* msg = bundle_create(); - snprintf(tmp_reason, 10, "%d", reason); - snprintf(tmp_daemon_pid, 10, "%d", getpid()); - - bundle_add_str(msg, VC_MANAGER_BUNDLE_METHOD, VCD_MANAGER_METHOD_ERROR); - bundle_add_str(msg, VC_MANAGER_BUNDLE_REASON, tmp_reason); - bundle_add_str(msg, VC_MANAGER_BUNDLE_DAEMON_PID, tmp_daemon_pid); - bundle_add_str(msg, VC_MANAGER_BUNDLE_ERROR_MESSAGE, temp_msg); - - SLOG(LOG_DEBUG, TAG_VCD, ">>>> VCD SEND MESSAGE"); - - __send_msg(msg, VCD_CLIENT_TYPE_MANAGER); - bundle_free(msg); - - free(temp_msg); - temp_msg = NULL; - - return VCD_ERROR_NONE; -} - -// TODO: remove _tidl after remove dbus -// TODO: make client, widget error signal -int vcdc_tidl_send_error(int reason, char *err_msg) -{ - SLOG(LOG_ERROR, TAG_VCD, "[TIDL] Send error signal"); - - vcdc_tidl_send_error_to_manager(vcd_client_manager_get_pid(), reason, err_msg); - - return VCD_ERROR_NONE; -} - -int vcdc_send_request_set_private_data(int pid, const char* key, const char* data) -{ - SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Set private data"); - - char tmp_pid[10] = { 0, }; - - bundle* msg = bundle_create(); - snprintf(tmp_pid, 10, "%d", pid); - - bundle_add_str(msg, VC_MANAGER_BUNDLE_METHOD, VCD_MANAGER_METHOD_SET_PRIVATE_DATA); - bundle_add_str(msg, VC_MANAGER_BUNDLE_MESSAGE, tmp_pid); - bundle_add_str(msg, VC_MANAGER_BUNDLE_KEY, key); - bundle_add_str(msg, VC_MANAGER_BUNDLE_PRIVATE_DATA, data); - - - SLOG(LOG_DEBUG, TAG_VCD, ">>>> VCD SEND MESSAGE"); - - __send_msg(msg, VCD_CLIENT_TYPE_MANAGER); - bundle_free(msg); - - return VCD_ERROR_NONE; -} - -int vcdc_send_feedback_audio_format_to_manager(int manager_pid, int rate, vc_audio_channel_e channel, vce_audio_type_e audio_type) -{ - SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Send feedback audio format to manager"); - - char tmp_rate[10] = {0, }; - char tmp_channel[10] = {0, }; - char tmp_audio_type[10] = {0, }; - - bundle* msg = bundle_create(); - snprintf(tmp_rate, 10, "%d", rate); - snprintf(tmp_channel, 10, "%d", (int)channel); - snprintf(tmp_audio_type, 10, "%d", (int)audio_type); - bundle_add_str(msg, VC_MANAGER_BUNDLE_METHOD, VCD_MANAGER_METHOD_FEEDBACK_AUDIO_FORMAT); - bundle_add_str(msg, VC_MANAGER_BUNDLE_AUDIO_RATE, tmp_rate); - bundle_add_str(msg, VC_MANAGER_BUNDLE_AUDIO_CHANNEL, tmp_channel); - bundle_add_str(msg, VC_MANAGER_BUNDLE_AUDIO_TYPE, tmp_audio_type); - - SLOG(LOG_DEBUG, TAG_VCD, ">>>> VCD SEND MESSAGE"); - - __send_msg(msg, VCD_CLIENT_TYPE_MANAGER); - bundle_free(msg); - - return VCD_ERROR_NONE; -} - -int vcdc_send_feedback_streaming_to_manager(int manager_pid, int pid, int utt_id, vc_feedback_event_e event, char* buffer, int len) -{ - SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Send feedback streaming to manager"); - - char tmp_pid[10] = {0, }; - char tmp_utt_id[10] = {0, }; - char tmp_event[10] = {0, }; - - bundle* msg = bundle_create(); - snprintf(tmp_pid, 10, "%d", pid); - snprintf(tmp_utt_id, 10, "%d", utt_id); - snprintf(tmp_event, 10, "%d", (int)event); - bundle_add_str(msg, VC_MANAGER_BUNDLE_METHOD, VCD_MANAGER_METHOD_FEEDBACK_STREAMING); - bundle_add_str(msg, VC_MANAGER_BUNDLE_MESSAGE, tmp_pid); - bundle_add_str(msg, VC_MANAGER_BUNDLE_UTTID, tmp_utt_id); - bundle_add_str(msg, VC_MANAGER_BUNDLE_EVENT, tmp_event); - - rpc_port_stub_array_char_h streaming_data = NULL; - rpc_port_stub_array_char_create(&streaming_data); - if (NULL == streaming_data) { - SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to create data handle"); - return VCD_ERROR_OUT_OF_MEMORY; - } - - if (NULL != buffer && 0 < len) { - rpc_port_stub_array_char_set(streaming_data, (char*)buffer, len); - } else { - SLOG(LOG_ERROR, TAG_VCD, "[TIDL] buffer is empty"); - } - - SLOG(LOG_DEBUG, TAG_VCD, ">>>> VCD SEND MESSAGE"); - - pthread_mutex_lock(&g_mgr_tidl_info_mutex); - SLOG(LOG_INFO, TAG_VCD, "[TIDL] message to manager"); - manager_tidl_info_s* mgr_tidl_info = vcd_client_manager_get_tidl_info(); - - if (NULL == mgr_tidl_info) { - SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to get manager tidl info. pid(%d)", pid); - pthread_mutex_unlock(&g_mgr_tidl_info_mutex); - rpc_port_stub_array_char_destroy(streaming_data); - bundle_free(msg); - return VCD_ERROR_OPERATION_FAILED; - } - - rpc_port_stub_vc_mgr_send_buffer_cb_h handle = mgr_tidl_info->send_buffer_cb; - if (NULL == handle) { - SLOG(LOG_ERROR, TAG_VCD, "[TIDL] notify callback handle is null"); - pthread_mutex_unlock(&g_mgr_tidl_info_mutex); - rpc_port_stub_array_char_destroy(streaming_data); - bundle_free(msg); - return VCD_ERROR_OPERATION_FAILED; - } - - if (0 != rpc_port_stub_vc_mgr_send_buffer_cb_invoke(handle, streaming_data, msg)) { - SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to send msg"); - pthread_mutex_unlock(&g_mgr_tidl_info_mutex); - rpc_port_stub_array_char_destroy(streaming_data); - bundle_free(msg); - return VCD_ERROR_OPERATION_FAILED; - } - pthread_mutex_unlock(&g_mgr_tidl_info_mutex); - rpc_port_stub_array_char_destroy(streaming_data); - bundle_free(msg); - - return VCD_ERROR_NONE; -} - -void vcdc_send_request_set_foreground(int pid, int value) -{ - SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Set foreground"); - - manager_tidl_info_s* mgr_tidl_info = vcd_client_manager_get_tidl_info(); - - if (NULL == mgr_tidl_info) { - SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to get tidl info"); - return; - } - - if (!mgr_tidl_info->connected) { - SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Not Connected"); - return; - } - - rpc_port_proxy_vcd_mgr_invoke_set_foreground(mgr_tidl_info->rpc_h, pid, value); - - SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Request set foreground"); -} - -int vcdc_send_request_get_private_data(int pid, const char* key, char** data) -{ - SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Get private data"); - - manager_tidl_info_s* mgr_tidl_info = vcd_client_manager_get_tidl_info(); - - if (NULL == mgr_tidl_info) { - SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to get tidl info"); - return VC_ERROR_OPERATION_FAILED; - } - - if (!mgr_tidl_info->connected) { - SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Not Connected"); - return VC_ERROR_OPERATION_FAILED; - } - - char *tmp = NULL; - if (0 != rpc_port_proxy_vcd_mgr_invoke_get_private_data(mgr_tidl_info->rpc_h, pid, key, &tmp)) { - SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Request vcd manager get private data : Fail to invoke message"); - return VC_ERROR_OPERATION_FAILED; - } - SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Request vcd manager get private data : Success"); - - *data = tmp; - - return VC_ERROR_NONE; -} - -int vcdc_send_request_auth_enable(int pid) -{ - SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] auth enable"); - - manager_tidl_info_s* mgr_tidl_info = vcd_client_manager_get_tidl_info(); - - if (NULL == mgr_tidl_info) { - SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to get tidl info"); - return VC_ERROR_OPERATION_FAILED; - } - - if (!mgr_tidl_info->connected) { - SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Not Connected"); - return VC_ERROR_OPERATION_FAILED; - } - - if (0 != rpc_port_proxy_vcd_mgr_invoke_auth_enable(mgr_tidl_info->rpc_h, pid)) { - SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Request auth enable : Fail to invoke message"); - return VC_ERROR_OPERATION_FAILED; - } - SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Request auth enable : Success"); - - return VC_ERROR_NONE; -} - -int vcdc_send_request_auth_disable(int pid) -{ - SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] auth disable"); - - manager_tidl_info_s* mgr_tidl_info = vcd_client_manager_get_tidl_info(); - - if (NULL == mgr_tidl_info) { - SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to get tidl info"); - return VC_ERROR_OPERATION_FAILED; - } - - if (!mgr_tidl_info->connected) { - SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Not Connected"); - return VC_ERROR_OPERATION_FAILED; - } - - if (0 != rpc_port_proxy_vcd_mgr_invoke_auth_disable(mgr_tidl_info->rpc_h, pid)) { - SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Request auth disable : Fail to invoke message"); - return VC_ERROR_OPERATION_FAILED; - } - SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Request auth disable : Success"); - - return VC_ERROR_NONE; -} - -int vcdc_send_request_auth_start(int pid) -{ - SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] auth start"); - - manager_tidl_info_s* mgr_tidl_info = vcd_client_manager_get_tidl_info(); - - if (NULL == mgr_tidl_info) { - SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to get tidl info"); - return VC_ERROR_OPERATION_FAILED; - } - - if (!mgr_tidl_info->connected) { - SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Not Connected"); - return VC_ERROR_OPERATION_FAILED; - } - - if (0 != rpc_port_proxy_vcd_mgr_invoke_auth_start(mgr_tidl_info->rpc_h, pid)) { - SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Request auth start : Fail to invoke message"); - return VC_ERROR_OPERATION_FAILED; - } - SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Request auth start : Success"); - - return VC_ERROR_NONE; -} - -int vcdc_send_request_auth_stop(int pid) -{ - SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] auth stop"); - - manager_tidl_info_s* mgr_tidl_info = vcd_client_manager_get_tidl_info(); - - if (NULL == mgr_tidl_info) { - SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to get tidl info"); - return VC_ERROR_OPERATION_FAILED; - } - - if (!mgr_tidl_info->connected) { - SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Not Connected"); - return VC_ERROR_OPERATION_FAILED; - } - - if (0 != rpc_port_proxy_vcd_mgr_invoke_auth_stop(mgr_tidl_info->rpc_h, pid)) { - SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Request auth stop : Fail to invoke message"); - return VC_ERROR_OPERATION_FAILED; - } - SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Request auth stop : Success"); - - return VC_ERROR_NONE; -} - -int vcdc_send_request_auth_cancel(int pid) -{ - SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] auth cancel"); - - manager_tidl_info_s* mgr_tidl_info = vcd_client_manager_get_tidl_info(); - - if (NULL == mgr_tidl_info) { - SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to get tidl info"); - return VC_ERROR_OPERATION_FAILED; - } - - if (!mgr_tidl_info->connected) { - SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Not Connected"); - return VC_ERROR_OPERATION_FAILED; - } - - if (0 != rpc_port_proxy_vcd_mgr_invoke_auth_cancel(mgr_tidl_info->rpc_h, pid)) { - SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Request auth cancel : Fail to invoke message"); - return VC_ERROR_OPERATION_FAILED; - } - SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Request auth cancel : Success"); - - return VC_ERROR_NONE; -} diff --git a/server/vcd_tidl.h b/server/vcd_tidl.h deleted file mode 100644 index 6f339dc..0000000 --- a/server/vcd_tidl.h +++ /dev/null @@ -1,72 +0,0 @@ -/* -* Copyright (c) 2022 Samsung Electronics Co., Ltd All Rights Reserved -* -* Licensed under the Apache License, Version 2.0 (the License); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an AS IS BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - - -#ifndef __VCD_TIDL_h__ -#define __VCD_TIDL_h__ - -#include "vcd_main.h" - -#ifdef __cplusplus -extern "C" { -#endif - -// typedef enum { -// VCD_CLIENT_TYPE_NORMAL, -// VCD_CLIENT_TYPE_WIDGET, -// VCD_CLIENT_TYPE_MANAGER -// } vcd_client_type_e; - -int vcd_mgr_tidl_open_connection(); - -int vcd_mgr_tidl_close_connection(); - -int vcdc_tidl_send_hello(int pid, vcd_client_type_e type); - -int vcdc_send_set_volume(int manager_pid, float volume); - -int vcdc_tidl_send_result(int pid, int manager_pid, int cmd_type); - -int vcdc_send_pre_result_to_manager(int manager_pid, int event, const char* pre_result); - -int vcdc_send_specific_engine_result_to_manager(int manager_pid, const char* engine_app_id, const char* event, const char* result); - -int vcdc_send_result_to_manager(int manager_pid, int result_type); - -int vcdc_send_speech_detected(int manager_pid); - -int vcdc_tidl_send_error(int reason, char *err_msg); - -int vcdc_tidl_send_error_to_manager(int manager_pid, int reason, char *err_msg); - -int vcdc_send_service_state(vcd_state_e state); - -int vcdc_send_dialog(int manager_pid, int pid, const char* disp_text, const char* utt_text, int continuous); - -int vcdc_send_request_set_private_data(int pid, const char* key, const char* data); - -int vcdc_send_request_get_private_data(int pid, const char* key, char** data); - -/* for TTS feedback */ -int vcdc_send_feedback_audio_format_to_manager(int manager_pid, int rate, vc_audio_channel_e channel, vce_audio_type_e audio_type); - -int vcdc_send_feedback_streaming_to_manager(int manager_pid, int pid, int utt_id, vc_feedback_event_e event, char* buffer, int len); - -#ifdef __cplusplus -} -#endif - -#endif /* __VCD_TIDL_h__ */ diff --git a/server/vce.c b/server/vce.c index 5353ea0..fae0fbb 100644 --- a/server/vce.c +++ b/server/vce.c @@ -20,7 +20,6 @@ #include #include #include "vcd_dbus.h" -#include "vcd_tidl.h" #include "vcd_main.h" #include "vcd_server.h" diff --git a/tidl/vc_mgr.tidl b/tidl/vc_mgr.tidl deleted file mode 100644 index f790247..0000000 --- a/tidl/vc_mgr.tidl +++ /dev/null @@ -1,26 +0,0 @@ -interface vc_mgr { - void notify_cb(bundle msg) delegate; - void send_buffer_cb(array data_in, bundle msg) delegate; - void register_cb(int pid, notify_cb notify_callback, send_buffer_cb send_buffer_callback) async; - - int initialize(in int pid, in int audio_streaming_mode, out int service_state, out int foreground, out int daemon_pid); - int finalize(in int pid); - int set_command(in int pid); - int unset_command(in int pid); - int demandable_client(in int pid); - int set_audio_type(in int pid, string audio_type); - int get_audio_type(in int pid, out string audio_type); - void set_private_data(in int pid, string key, string data) async; - int get_private_data(in int pid, string key, out string data); - int set_client_info(in int pid); - int set_domain(in int pid, string domain); - void do_action(in int pid, int type, string send_event) async; - int start(in int pid, in int recognition_mode, bool exclusive_command_option, bool start_by_client, int disabled_cmd_type); - int stop(in int pid); - int cancel(in int pid); - void set_audio_streaming_mode(in int pid, in int mode) async; - void send_specific_engine_request(in int pid, in string engine_app_id, in string event, in string request) async; - void send_result_selection(in int pid) async; - void send_audio_streaming(in int pid, in int event, array data_in) async; - void send_utterance_status(in int utt_id, in int utt_status) async; -} \ No newline at end of file diff --git a/tidl/vcd_mgr.tidl b/tidl/vcd_mgr.tidl deleted file mode 100644 index 57557f8..0000000 --- a/tidl/vcd_mgr.tidl +++ /dev/null @@ -1,9 +0,0 @@ -interface vcd_mgr { - void set_foreground(in int pid, in int value) async; - int get_private_data(in int pid, in string key, out string data); - int auth_enable(in int pid); - int auth_disable(in int pid); - int auth_start(in int pid); - int auth_stop(in int pid); - int auth_cancel(in int pid); -} \ No newline at end of file -- 2.7.4 From 1f5f0ff5c4efdabf39cc94dc6e93473b68a79225 Mon Sep 17 00:00:00 2001 From: Suyeon Hwang Date: Thu, 9 Jun 2022 11:47:08 +0900 Subject: [PATCH 15/16] Fix gcov package contents for automation Change-Id: Ia9f42f9670c8c44d0cbfcfcffbed2d9751628829 Signed-off-by: Suyeon Hwang --- packaging/voice-control.spec | 24 ++++-------------------- 1 file changed, 4 insertions(+), 20 deletions(-) diff --git a/packaging/voice-control.spec b/packaging/voice-control.spec index 9c5e914..519e741 100644 --- a/packaging/voice-control.spec +++ b/packaging/voice-control.spec @@ -130,24 +130,6 @@ cmake . -DCMAKE_INSTALL_PREFIX=/usr -DLIBDIR=%{_libdir} -DBINDIR=%{_bindir} -DIN make %{?jobs:-j%jobs} %endif -%if 0%{?gcov:1} -mkdir -p gcov-obj -find . -name 'vc-engine-parser.c.gcno' -exec rm {} \; -find . -name '*_client.c.gcno' -exec rm {} \; -find . -name '*_cmd_db.c.gcno' -exec rm {} \; -find . -name '*_command*.gcno' -exec rm {} \; -find . -name '*_config_*.gcno' -exec rm {} \; -find . -name '*_data*.gcno' -exec rm {} \; -find . -name '*_dbus.c.gcno' -exec rm {} \; -find . -name '*_parser.c.gcno' -exec rm {} \; -find . -name 'vc_mgr*.gcno' -exec rm {} \; -find . -name 'vc_setting*.gcno' -exec rm {} \; -find . -name 'vc_widget*.gcno' -exec rm {} \; -find . -name 'vcd_*.gcno' -exec rm {} \; -find . -name 'vce.c.gcno' -exec rm {} \; -find . -name '*.gcno' -exec cp '{}' gcov-obj ';' -%endif - %install rm -rf %{buildroot} @@ -158,8 +140,10 @@ mv -f org.tizen.voice.vcserver.tv.service org.tizen.voice.vcserver.service %make_install %if 0%{?gcov:1} -mkdir -p %{buildroot}%{_datadir}/gcov/obj/%{name} -install -m 0644 gcov-obj/* %{buildroot}%{_datadir}/gcov/obj/%{name} +builddir=$(basename $PWD) +gcno_obj_dir=%{buildroot}%{_datadir}/gcov/obj/%{name}/"$builddir" +mkdir -p "$gcno_obj_dir" +find . -name '*.gcno' -exec cp --parents '{}' "$gcno_obj_dir" ';' %endif %post -- 2.7.4 From 2afcd62ad5328a217c5d781b2cdd90b7f5595091 Mon Sep 17 00:00:00 2001 From: Suyeon Hwang Date: Fri, 10 Jun 2022 19:20:26 +0900 Subject: [PATCH 16/16] Fix unittest for line coverage automation Change-Id: I81ba58b22167ee07f155fc0fc0c468a4095b1989 Signed-off-by: Suyeon Hwang --- packaging/voice-control.spec | 35 ++++++++++++++++++++++++++++-- tests/CMakeLists.txt | 7 +++--- tests/src/main.cpp | 17 ++++++++++++++- tests/src/vc_denied_unittests.cpp | 45 --------------------------------------- 4 files changed, 52 insertions(+), 52 deletions(-) delete mode 100644 tests/src/vc_denied_unittests.cpp diff --git a/packaging/voice-control.spec b/packaging/voice-control.spec index 519e741..e05edb8 100644 --- a/packaging/voice-control.spec +++ b/packaging/voice-control.spec @@ -114,8 +114,8 @@ cp %{SOURCE1001} %{SOURCE1002} . %build %if 0%{?gcov:1} -export CFLAGS="$CFLAGS -fprofile-arcs -ftest-coverage" -export CXXFLAGS="$CXXFLAGS -fprofile-arcs -ftest-coverage" +export CFLAGS="$CFLAGS -fprofile-arcs -ftest-coverage -DTIZEN_TEST_GCOV" +export CXXFLAGS="$CXXFLAGS -fprofile-arcs -ftest-coverage -DTIZEN_TEST_GCOV" export FFLAGS="$FFLAGS -fprofile-arcs -ftest-coverage" export LDFLAGS="$LDFLAGS -lgcov" %endif @@ -146,6 +146,36 @@ mkdir -p "$gcno_obj_dir" find . -name '*.gcno' -exec cp --parents '{}' "$gcno_obj_dir" ';' %endif +cat << EOF > run-unittest.sh +#!/bin/sh +setup() { + echo "setup start" + touch /opt/share/askuser_disable + mount -o remount,rw / + tpk-backend --preload -y org.tizen.vc-unittests +} + +test_main() { + echo "test_main start" + launch_app org.tizen.vc-unittests +} + +teardown() { + echo "teardown start" +} + +main() { + setup + test_main + teardown +} + +main "\$*" +EOF + +mkdir -p %{buildroot}%{_bindir}/tizen-unittests/%{name} +install -m 0755 run-unittest.sh %{buildroot}%{_bindir}/tizen-unittests/%{name} + %post /sbin/ldconfig @@ -223,3 +253,4 @@ mkdir -p %{_libdir}/voice/vc %defattr(-,root,root,-) %{TZ_SYS_RO_PACKAGES}/org.tizen.vc-unittests.xml %{TZ_SYS_RO_APP}/org.tizen.vc-unittests/bin/vc-unittests +%{_bindir}/tizen-unittests/%{name}/run-unittest.sh diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index ec00560..ac6ae41 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -21,16 +21,15 @@ SET(SOURCES "") INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../include) AUX_SOURCE_DIRECTORY(src SOURCES) -AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/../client VC_CLIENT_SOURCES) -AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/../common VC_COMMON_SOURCES) ADD_DEFINITIONS("-DFULLVER=\"${FULLVER}\"") ADD_EXECUTABLE(${UNITTEST_VC} - ${VC_COMMON_SOURCES} - ${VC_CLIENT_SOURCES} ${SOURCES} ) + +TARGET_LINK_LIBRARIES(${UNITTEST_VC} vc -ldl ${pkgs_LDFLAGS}) +TARGET_LINK_LIBRARIES(${UNITTEST_VC} vc_manager -ldl ${pkgs_LDFLAGS}) TARGET_LINK_LIBRARIES(${UNITTEST_VC} ${GTEST_LIBRARIES} ${pkgs_LDFLAGS} ${EXTRA_LDFLAGS}) SET_TARGET_PROPERTIES(${UNITTEST_VC} PROPERTIES COMPILE_FLAGS "-fPIE" diff --git a/tests/src/main.cpp b/tests/src/main.cpp index a37d671..450edea 100644 --- a/tests/src/main.cpp +++ b/tests/src/main.cpp @@ -1,7 +1,22 @@ #include #include + +#ifdef TIZEN_TEST_GCOV +extern "C" void __gcov_flush(void); +#endif + int main(int argc, char** argv) { +#ifdef TIZEN_TEST_GCOV + setenv("GCOV_PREFIX", "/tmp", 1); +#endif + testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); + auto testResults = RUN_ALL_TESTS(); + +#ifdef TIZEN_TEST_GCOV + __gcov_flush(); +#endif + + return testResults; } diff --git a/tests/src/vc_denied_unittests.cpp b/tests/src/vc_denied_unittests.cpp deleted file mode 100644 index c133af6..0000000 --- a/tests/src/vc_denied_unittests.cpp +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright (c) 2020 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include - -#include "cynara_mock.h" -#include "system_info_mock.h" - -namespace { - -class VCDeniedTest : public testing::Test { - public: - virtual void SetUp() { - /* start of TC */ - cynara_check_set_result(CYNARA_API_ACCESS_DENIED); - } - virtual void TearDown() { - /* end of TC */ - cynara_check_set_result(CYNARA_API_ACCESS_ALLOWED); - } -}; - -TEST_F(VCDeniedTest, utc_stt_create_denied) -{ - int ret = VC_ERROR_NONE; - - ret = vc_initialize(); - EXPECT_EQ(ret, VC_ERROR_PERMISSION_DENIED); -} - -} // namespace -- 2.7.4