From 58c72fc9dde94ee12ecae41b579b724c86269eba Mon Sep 17 00:00:00 2001 From: ulgal-park Date: Mon, 14 Feb 2022 19:31:00 +0900 Subject: [PATCH 01/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 02/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 03/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 04/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 05/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 06/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 07/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 From c2bb94f4b437770c511efd3013f5cc5b48dc6371 Mon Sep 17 00:00:00 2001 From: Suyeon Hwang Date: Mon, 13 Jun 2022 17:14:53 +0900 Subject: [PATCH 08/16] Update version (1.70.4) Change-Id: I481f920d4592c0e7b1acfa02e40406c15f7305c8 Signed-off-by: Suyeon Hwang --- CMakeLists.txt | 2 +- packaging/voice-control.spec | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d72a322..e468ea9 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.3) +SET(VERSION 1.70.4) 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 e05edb8..80a4e61 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.3 +Version: 1.70.4 Release: 1 Group: Graphics & UI Framework/Voice Framework License: Apache-2.0 -- 2.7.4 From e74391e7b119bce4572bd1fa2ffa1313a9877140 Mon Sep 17 00:00:00 2001 From: "wn.jang" Date: Wed, 29 Jun 2022 14:52:08 +0900 Subject: [PATCH 09/16] Check whether symbolic link or real file If open a file in write mode and do not check whether the file is a symbolic link or not, the file can be overwritten unintentionally. So, this commit will check whether the file is symbolic link or real file. Change-Id: I9db8c0287b479ef7474a2525fc1de3bd39e47e22 --- common/vc_info_parser.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/common/vc_info_parser.c b/common/vc_info_parser.c index d4b48ac..56ce84b 100644 --- a/common/vc_info_parser.c +++ b/common/vc_info_parser.c @@ -364,6 +364,45 @@ int vc_info_parser_unset_result(bool exclusive) return ret; } +static int __is_symbolic_link(const char* path, bool* is_symbolic) +{ + extern int errno; + int ret = VC_ERROR_NONE; + *is_symbolic = true; + char real_path[PATH_MAX]; + SLOG(LOG_DEBUG, vc_info_tag(), "[DEBUG] path: %s ", path); + if (realpath(path, real_path) != NULL) { + if (strncmp(path, real_path, strlen(path) + 1) == 0) { + SLOG(LOG_DEBUG, vc_info_tag(), "[DEBUG] %s is real file, not symbolic link", path); + *is_symbolic = false; + } else { + char temp_path[PATH_MAX]; + if (getcwd(temp_path, PATH_MAX)) { + strncat(temp_path, "/", sizeof(temp_path) - strlen(temp_path) - 1); + strncat(temp_path, path, sizeof(temp_path) - strlen(temp_path) - 1); + if (strncmp(temp_path, real_path, strlen(temp_path) + 1) == 0) { + SLOG(LOG_DEBUG, vc_info_tag(), "[DEBUG] %s is real file, not symbolic link", path); + *is_symbolic = false; + } + } + } + + if (*is_symbolic == true) + SLOG(LOG_ERROR, vc_info_tag(), "[INFO] %s is symbolic link", path); + return VC_ERROR_NONE; + } else { + *is_symbolic = false; + if (errno == ENOENT) { + SLOG(LOG_DEBUG, vc_info_tag(), "[DEBUG] No such file or directory: %s", path); + return VC_ERROR_OPERATION_REJECTED; + } else { + SLOG(LOG_ERROR, vc_info_tag(), "[ERROR] error is %d", errno); + return VC_ERROR_OPERATION_FAILED; + } + } + return ret; +} + int vc_info_parser_set_nlu_result(const char* nlu_result) { if (NULL == nlu_result) { @@ -380,6 +419,13 @@ int vc_info_parser_set_nlu_result(const char* nlu_result) FILE* fp = NULL; int write_size = -1; + bool is_symbolic = true; + int ret = __is_symbolic_link(VC_RUNTIME_INFO_NLU_RESULT, &is_symbolic); + if (is_symbolic || VC_ERROR_OPERATION_FAILED == ret) { + SLOG(LOG_ERROR, vc_info_tag(), "[ERROR] Fail to open file, it is symbolic link : %s", VC_RUNTIME_INFO_NLU_RESULT); + return -1; + } + fp = fopen(VC_RUNTIME_INFO_NLU_RESULT, "w+"); if (NULL == fp) { SLOG(LOG_ERROR, vc_info_tag(), "[ERROR] Fail to open file %s", VC_RUNTIME_INFO_NLU_RESULT); -- 2.7.4 From e504b434e6eaca61fe07c949d26fef687439076b Mon Sep 17 00:00:00 2001 From: Suyeon Hwang Date: Mon, 25 Jul 2022 11:47:25 +0900 Subject: [PATCH 10/16] Fix line coverage scope and test option This patch reduces the scope for checking line coverage. The line coverage is for checking client API, so other files in this repo is not target of the line coverage test. Change-Id: I677a34eb9a682a7cfd0c3d7e061fda1b7554cf17 Signed-off-by: Suyeon Hwang --- packaging/voice-control.spec | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/packaging/voice-control.spec b/packaging/voice-control.spec index 80a4e61..cae9684 100644 --- a/packaging/voice-control.spec +++ b/packaging/voice-control.spec @@ -143,6 +143,20 @@ mv -f org.tizen.voice.vcserver.tv.service org.tizen.voice.vcserver.service builddir=$(basename $PWD) gcno_obj_dir=%{buildroot}%{_datadir}/gcov/obj/%{name}/"$builddir" mkdir -p "$gcno_obj_dir" +find ./server/ -name '*.gcno' -exec rm {} \; +find ./audio-manager/ -name '*.gcno' -exec rm {} \; +find ./tests/ -name '*.gcno' -exec rm {} \; +find ./engine-parser/ -name '*.gcno' -exec rm {} \; +find . -name '*_client.c.gcno' -exec rm {} \; +find . -name '*_dbus.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 '*_parser.c.gcno' -exec rm {} \; +find . -name '*_data*.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 '*.gcno' -exec cp --parents '{}' "$gcno_obj_dir" ';' %endif @@ -157,7 +171,7 @@ setup() { test_main() { echo "test_main start" - launch_app org.tizen.vc-unittests + launch_app org.tizen.vc-unittests __AUL_SDK__ UNIT_TEST __LAUNCH_APP_MODE__ SYNC } teardown() { -- 2.7.4 From ba7df579e55a1bdfc2fc4de69fd9f7b46f5793ef Mon Sep 17 00:00:00 2001 From: ulgal-park Date: Mon, 25 Jul 2022 17:44:05 +0900 Subject: [PATCH 11/16] Add metadata key Change-Id: I898af8cff671a6b591360b86607c21831485d3e7 --- packaging/metadata-profile.xml | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/packaging/metadata-profile.xml b/packaging/metadata-profile.xml index 6149419..3b3bbed 100644 --- a/packaging/metadata-profile.xml +++ b/packaging/metadata-profile.xml @@ -71,4 +71,32 @@ + + + Y + 1.0 + + Write whether to support silent detection such as EPD(End Point Detection) of speech. + + + Default value is false. + + + + + + + + Y + 1.0 + + Write a VC engine uuid. + + + It does not work if there is no value. + + + + + \ No newline at end of file -- 2.7.4 From ba9f171e10be744350cb3029cc0e9c8159d8ed6e Mon Sep 17 00:00:00 2001 From: ulgal-park Date: Fri, 13 May 2022 15:32:04 +0900 Subject: [PATCH 12/16] Replace IPC between manager and server from dbus to tidl Change-Id: I76e2c9aeef41f3d166fbe19feca62d3364f875bd --- 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 e468ea9..aca3b41 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 cae9684..3e183d3 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 05ae1df9be7eb0164997ba69c0a55fecf0938a3a Mon Sep 17 00:00:00 2001 From: ulgal-park Date: Thu, 19 May 2022 18:53:58 +0900 Subject: [PATCH 13/16] Replace IPC between widget and server from dbus to tidl Change-Id: I82d73ad71b794ab13f7bfd1a6298c531cf4805b4 --- 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 | 2272 ++++++++++++++++++++++++++++-------------- server/vcd_tidl.h | 19 +- tidl/vc_widget.tidl | 14 + tidl/vcd_widget.tidl | 3 + 20 files changed, 2487 insertions(+), 2144 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 3e183d3..2498f9c 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..1d87f70 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); - 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; - } + pthread_mutex_lock(&g_widget_tidl_info_mutex); + GSList* widget_list = vcd_client_widget_get_tidl_info_list(); - char *sender = NULL; - rpc_port_stub_vc_mgr_context_get_sender(context, &sender); + int count = g_slist_length(widget_list); + int i; - if (!sender){ - SLOG(LOG_ERROR, TAG_VCD, "Sender is NULL"); - pthread_mutex_unlock(&g_mgr_tidl_info_mutex); - return; - } + widget_tidl_info_s *widget_tidl_info = NULL; - mgr_tidl_info->rpc_h = __create_rpc_port(sender, mgr_tidl_info); + 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; + } - 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); - } + widget_tidl_info = iter->data; - free(sender); + if (NULL == widget_tidl_info) { + SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] widget list data broken"); + break; + } - 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."); + SLOG(LOG_INFO, TAG_VCD, "[TIDL] message to widget"); + + 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 != 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); +} - 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"); +// 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); - 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; + 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); - 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_DEBUG, TAG_VCD, ">>>> VCD SEND SIGNAL"); - SLOG(LOG_ERROR, TAG_VCD, "Fail to register callback(%d)", ret); - return VCD_ERROR_OPERATION_FAILED; -} + __send_signal(msg); -int vcd_mgr_tidl_close_connection() -{ - SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Close connection"); - rpc_port_stub_vc_mgr_unregister(); + bundle_free(msg); + + 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); + + 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; + } - bundle_add_str(msg, VC_MANAGER_BUNDLE_METHOD, VCD_MANAGER_METHOD_RESULT); + 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); + } + + 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, "@@@"); +} - SLOG(LOG_DEBUG, TAG_VCD, ">>>> VCD SEND MESSAGE"); +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(); - __send_msg(msg, VCD_CLIENT_TYPE_MANAGER); - bundle_free(msg); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret); + return ret; + } - if (gEncodedResult) - g_free(gEncodedResult); + SLOG(LOG_DEBUG, TAG_VCD, "@@@"); - return VCD_ERROR_NONE; + return ret; } -int vcdc_send_result_to_manager(int manager_pid, int result_type) +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 result to manager"); + SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Manager cancel"); + SLOG(LOG_INFO, TAG_VCD, "[IN] vcd mgr cancel : pid(%d)", pid); - char tmp_result[10] = {0, }; + int ret = -1; - bundle* msg = bundle_create(); - snprintf(tmp_result, 10, "%d", result_type); + 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_ALL_RESULT); - bundle_add_str(msg, VC_MANAGER_BUNDLE_MESSAGE, tmp_result); + SLOG(LOG_DEBUG, TAG_VCD, "@@@"); + return ret; +} - SLOG(LOG_DEBUG, TAG_VCD, ">>>> VCD SEND MESSAGE"); +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); - __send_msg(msg, VCD_CLIENT_TYPE_MANAGER); - bundle_free(msg); + vcd_config_set_audio_streaming_mode((vcd_audio_streaming_mode_e)mode); - return VCD_ERROR_NONE; + SLOG(LOG_DEBUG, TAG_VCD, "@@@"); } -int vcdc_send_speech_detected(int manager_pid) +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 speech detected"); - - bundle* msg = bundle_create(); + SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Manager specific engine request"); - bundle_add_str(msg, VC_MANAGER_BUNDLE_METHOD, VCD_MANAGER_METHOD_SPEECH_DETECTED); + int ret = -1; + gsize decodingSize = 0; + gchar *gDecodedRequest = (gchar *)g_base64_decode((const gchar *)request, &decodingSize); - SLOG(LOG_DEBUG, TAG_VCD, ">>>> VCD SEND MESSAGE"); + 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); + } - __send_msg(msg, VCD_CLIENT_TYPE_MANAGER); - bundle_free(msg); + 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 VCD_ERROR_NONE; + SLOG(LOG_DEBUG, TAG_VCD, "@@@"); } -int vcdc_send_service_state(vcd_state_e state) +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, "[TIDL] Send service state"); - - char tmp_state[10] = {0, }; - - bundle* msg = bundle_create(); - snprintf(tmp_state, 10, "%d", (int)state); + 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_SET_SERVICE_STATE); - bundle_add_str(msg, VC_MANAGER_BUNDLE_MESSAGE, tmp_state); + 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); - 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 - return VCD_ERROR_NONE; + 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_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, "[TIDL] Send dialog"); + SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Manager send audio streaming"); - 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); + char* buffer = NULL; + int len = 0; + int ret = -1; + rpc_port_stub_array_char_get(data, &buffer, &len); - if (NULL == disp_text) { - tmp_disp_text = strdup("#NULL"); - } else { - tmp_disp_text = strdup(disp_text); - } + SLOG(LOG_INFO, TAG_VCD, "[IN] vcd mgr send audio streaming : pid(%d), event(%d), buffer(%p), len(%d)", pid, event, buffer, len); - if (NULL == utt_text) { - tmp_utt_text = strdup("#NULL"); - } else { - tmp_utt_text = strdup(utt_text); + 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); } - 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; + SLOG(LOG_DEBUG, TAG_VCD, "@@@"); } -int vcdc_tidl_send_error_to_manager(int manager_pid, int reason, char *err_msg) +int vcd_mgr_tidl_open_connection() { - SLOG(LOG_ERROR, TAG_VCD, "[TIDL] Send error signal to manager"); + SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] vcd_mgr_tidl_open_connection"); - char tmp_reason[10] = {0, }; - char tmp_daemon_pid[10] = {0, }; - char *temp_msg = NULL; + 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; - 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); + 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++; } - 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); + SLOG(LOG_ERROR, TAG_VCD, "Fail to register callback(%d)", ret); + return VCD_ERROR_OPERATION_FAILED; +} - free(temp_msg); - temp_msg = NULL; +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 remove dbus -// TODO: make client, widget error signal -int vcdc_tidl_send_error(int reason, char *err_msg) +/* +* Tidl for widget +*/ +static void __widget_on_connected(rpc_port_proxy_vcd_widget_h h, void *user_data) { - SLOG(LOG_ERROR, TAG_VCD, "[TIDL] Send error signal"); + widget_tidl_info_s* widget_tidl_info = vcd_client_widget_get_tidl_info((int)user_data); - vcdc_tidl_send_error_to_manager(vcd_client_manager_get_pid(), reason, err_msg); + widget_tidl_info->connected = true; + widget_tidl_info->connection_requesting = false; - return VCD_ERROR_NONE; + SLOG(LOG_INFO, TAG_VCD, "Connected to widget"); } -int vcdc_send_request_set_private_data(int pid, const char* key, const char* data) +static void __widget_on_disconnected(rpc_port_proxy_vcd_widget_h h, void *user_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); + 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 7b8d84ed2dac202a8a0390fe1eced48bfb4bf124 Mon Sep 17 00:00:00 2001 From: ulgal-park Date: Thu, 19 May 2022 19:39:01 +0900 Subject: [PATCH 14/16] Fix ipc sync function's return value Change-Id: Ideac4cd335daf2de50153f96443af85bde0a0f49 --- client/vc_mgr_tidl.c | 91 ++++++++++++++++++++++++++++--------------------- client/vc_widget_tidl.c | 50 +++++++++++++++------------ server/vcd_tidl.c | 49 ++++++++++++++------------ 3 files changed, 109 insertions(+), 81 deletions(-) diff --git a/client/vc_mgr_tidl.c b/client/vc_mgr_tidl.c index 27154fc..a351965 100755 --- a/client/vc_mgr_tidl.c +++ b/client/vc_mgr_tidl.c @@ -767,9 +767,10 @@ int vc_mgr_tidl_request_initialize(int pid, int audio_streaming_mode, int* servi 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; + int ret = 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); + if (RPC_PORT_ERROR_NONE != ret) { + SLOG(LOG_ERROR, TAG_VCM, "[TIDL ERROR] Request vc manager initialize : Fail to invoke message, error(%d)", ret); + return ret; } *service_state = tmp_service_state; @@ -795,9 +796,10 @@ int vc_mgr_tidl_request_finalize(int pid) 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; + int ret = rpc_port_proxy_vc_mgr_invoke_finalize(g_proxy_tidl_info->rpc_h, pid); + if (RPC_PORT_ERROR_NONE != ret) { + SLOG(LOG_ERROR, TAG_VCM, "[TIDL ERROR] Request vc manager finalize : Fail to invoke message, error(%d)", ret); + return ret; } return VC_ERROR_NONE; @@ -817,9 +819,10 @@ int vc_mgr_tidl_request_set_command(int pid) 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; + int ret = rpc_port_proxy_vc_mgr_invoke_set_command(g_proxy_tidl_info->rpc_h, pid); + if (RPC_PORT_ERROR_NONE != ret) { + SLOG(LOG_ERROR, TAG_VCM, "[TIDL ERROR] Request vc manager set command : Fail to invoke message, error(%d)", ret); + return ret; } return VC_ERROR_NONE; @@ -839,9 +842,10 @@ int vc_mgr_tidl_request_unset_command(int pid) 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; + int ret = rpc_port_proxy_vc_mgr_invoke_unset_command(g_proxy_tidl_info->rpc_h, pid); + if (RPC_PORT_ERROR_NONE != ret) { + SLOG(LOG_ERROR, TAG_VCM, "[TIDL ERROR] Request vc manager unset command : Fail to invoke message, error(%d)", ret); + return ret; } return VC_ERROR_NONE; @@ -861,9 +865,10 @@ int vc_mgr_tidl_request_demandable_client(int pid) 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; + int ret = rpc_port_proxy_vc_mgr_invoke_demandable_client(g_proxy_tidl_info->rpc_h, pid); + if (RPC_PORT_ERROR_NONE != ret) { + SLOG(LOG_ERROR, TAG_VCM, "[TIDL ERROR] Request vc manager demandable client : Fail to invoke message, error(%d)", ret); + return ret; } return VC_ERROR_NONE; @@ -883,9 +888,10 @@ int vc_mgr_tidl_request_set_audio_type(int pid, const char* audio_type) 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; + int ret = rpc_port_proxy_vc_mgr_invoke_set_audio_type(g_proxy_tidl_info->rpc_h, pid, audio_type); + if (RPC_PORT_ERROR_NONE != ret) { + SLOG(LOG_ERROR, TAG_VCM, "[TIDL ERROR] Request vc manager set audio type : Fail to invoke message, error(%d)", ret); + return ret; } return VC_ERROR_NONE; @@ -906,9 +912,10 @@ int vc_mgr_tidl_request_get_audio_type(int pid, char** audio_type) } 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; + int ret = rpc_port_proxy_vc_mgr_invoke_get_audio_type(g_proxy_tidl_info->rpc_h, pid, &tmp); + if (RPC_PORT_ERROR_NONE != ret) { + SLOG(LOG_ERROR, TAG_VCM, "[TIDL ERROR] Request vc manager get audio type : Fail to invoke message, error(%d)", ret); + return ret; } SLOG(LOG_DEBUG, TAG_VCM, "[TIDL] Request vc manager get audio type : Success"); @@ -951,9 +958,10 @@ int vc_mgr_tidl_request_get_private_data(int pid, const char* key, char** data) } 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; + int ret = rpc_port_proxy_vc_mgr_invoke_get_private_data(g_proxy_tidl_info->rpc_h, pid, key, &tmp); + if (RPC_PORT_ERROR_NONE != ret) { + SLOG(LOG_ERROR, TAG_VCM, "[TIDL ERROR] Request vc manager get private data : Fail to invoke message, error(%d)", ret); + return ret; } SLOG(LOG_DEBUG, TAG_VCM, "[TIDL] Request vc manager get private data : Success"); @@ -976,9 +984,10 @@ int vc_mgr_tidl_request_set_client_info(int pid) 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; + int ret = rpc_port_proxy_vc_mgr_invoke_set_client_info(g_proxy_tidl_info->rpc_h, pid); + if (RPC_PORT_ERROR_NONE != ret) { + SLOG(LOG_ERROR, TAG_VCM, "[TIDL ERROR] Request vc manager set client info : Fail to invoke message, error(%d)", ret); + return ret; } return VC_ERROR_NONE; @@ -998,9 +1007,10 @@ int vc_mgr_tidl_request_set_domain(int pid, const char* domain) 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; + int ret = rpc_port_proxy_vc_mgr_invoke_set_domain(g_proxy_tidl_info->rpc_h, pid, domain); + if (RPC_PORT_ERROR_NONE != ret) { + SLOG(LOG_ERROR, TAG_VCM, "[TIDL ERROR] Request vc manager set domain : Fail to invoke message, error(%d)", ret); + return ret; } return VC_ERROR_NONE; @@ -1039,9 +1049,10 @@ int vc_mgr_tidl_request_start(int pid, int recognition_mode, bool exclusive_comm 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; + int ret = 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); + if (RPC_PORT_ERROR_NONE != ret) { + SLOG(LOG_ERROR, TAG_VCM, "[TIDL ERROR] Request vc manager start : Fail to invoke message, error(%d)", ret); + return ret; } return VC_ERROR_NONE; @@ -1061,9 +1072,10 @@ int vc_mgr_tidl_request_stop(int pid) 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; + int ret = rpc_port_proxy_vc_mgr_invoke_stop(g_proxy_tidl_info->rpc_h, pid); + if (RPC_PORT_ERROR_NONE != ret) { + SLOG(LOG_ERROR, TAG_VCM, "[TIDL ERROR] Request vc manager stop : Fail to invoke message, error(%d)", ret); + return ret; } return VC_ERROR_NONE; @@ -1083,9 +1095,10 @@ int vc_mgr_tidl_request_cancel(int pid) 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; + int ret = rpc_port_proxy_vc_mgr_invoke_cancel(g_proxy_tidl_info->rpc_h, pid); + if (RPC_PORT_ERROR_NONE != ret) { + SLOG(LOG_ERROR, TAG_VCM, "[TIDL ERROR] Request vc manager cancel : Fail to invoke message, error(%d)", ret); + return ret; } return VC_ERROR_NONE; diff --git a/client/vc_widget_tidl.c b/client/vc_widget_tidl.c index 3002bf5..da50b61 100644 --- a/client/vc_widget_tidl.c +++ b/client/vc_widget_tidl.c @@ -449,10 +449,11 @@ int vc_widget_tidl_request_initialize(int pid, int* service_state, int* daemon_p 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"); + int ret = rpc_port_proxy_vc_widget_invoke_initialize(g_proxy_tidl_info->rpc_h, pid, &temp_service_state, &temp_daemon_pid); + if (RPC_PORT_ERROR_NONE != ret) { + SLOG(LOG_ERROR, TAG_VCW, "[TIDL ERROR] Request vc widget initialize : Fail to invoke message, error(%d)", ret); pthread_mutex_unlock(&g_w_init_mutex); - return VC_ERROR_OPERATION_FAILED; + return ret; } *service_state = temp_service_state; @@ -481,10 +482,11 @@ int vc_widget_tidl_request_finalize(int pid) 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"); + int ret = rpc_port_proxy_vc_widget_invoke_finalize(g_proxy_tidl_info->rpc_h, pid); + if (RPC_PORT_ERROR_NONE != ret) { + SLOG(LOG_ERROR, TAG_VCW, "[TIDL ERROR] Request vc widget finalize : Fail to invoke message, error(%d)", ret); pthread_mutex_unlock(&g_w_init_mutex); - return VC_ERROR_OPERATION_FAILED; + return ret; } pthread_mutex_unlock(&g_w_init_mutex); @@ -505,9 +507,10 @@ int vc_widget_tidl_request_start_recording(int pid, bool command) 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; + int ret = rpc_port_proxy_vc_widget_invoke_start_recording(g_proxy_tidl_info->rpc_h, pid, (int)command); + if (RPC_PORT_ERROR_NONE != ret) { + SLOG(LOG_ERROR, TAG_VCW, "[TIDL ERROR] Request vc widget start recording : Fail to invoke message, error(%d)", ret); + return ret; } return VC_ERROR_NONE; @@ -527,6 +530,7 @@ int vc_widget_tidl_set_foreground(int pid, bool value) return VC_ERROR_OPERATION_FAILED; } + // TODO: Error tolerance cannot be applied because this function is asynchronous. rpc_port_proxy_vc_widget_invoke_set_foreground(g_proxy_tidl_info->rpc_h, pid, (int)value); return VC_ERROR_NONE; @@ -546,9 +550,10 @@ int vc_widget_tidl_request_enable_asr_result(int pid, bool enable) 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; + int ret = rpc_port_proxy_vc_widget_invoke_enable_asr_result(g_proxy_tidl_info->rpc_h, pid, (int)enable); + if (RPC_PORT_ERROR_NONE != ret) { + SLOG(LOG_ERROR, TAG_VCW, "[TIDL ERROR] Request vc widget enable asr result : Fail to invoke message, error(%d)", ret); + return ret; } return VC_ERROR_NONE; @@ -568,9 +573,10 @@ int vc_widget_tidl_request_start(int pid, int silence) 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; + int ret = rpc_port_proxy_vc_widget_invoke_start(g_proxy_tidl_info->rpc_h, pid, silence); + if (RPC_PORT_ERROR_NONE != ret) { + SLOG(LOG_ERROR, TAG_VCW, "[TIDL ERROR] Request vc widget start : Fail to invoke message, error(%d)", ret); + return ret; } return VC_ERROR_NONE; @@ -590,9 +596,10 @@ int vc_widget_tidl_request_stop(int pid) 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; + int ret = rpc_port_proxy_vc_widget_invoke_stop(g_proxy_tidl_info->rpc_h, pid); + if (RPC_PORT_ERROR_NONE != ret) { + SLOG(LOG_ERROR, TAG_VCW, "[TIDL ERROR] Request vc widget stop : Fail to invoke message, error(%d)", ret); + return ret; } return VC_ERROR_NONE; @@ -612,9 +619,10 @@ int vc_widget_tidl_request_cancel(int pid) 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; + int ret = rpc_port_proxy_vc_widget_invoke_cancel(g_proxy_tidl_info->rpc_h, pid); + if (RPC_PORT_ERROR_NONE != ret) { + SLOG(LOG_ERROR, TAG_VCW, "[TIDL ERROR] Request vc widget cancel : Fail to invoke message, error(%d)", ret); + return ret; } return VC_ERROR_NONE; diff --git a/server/vcd_tidl.c b/server/vcd_tidl.c index 1d87f70..784f9c0 100644 --- a/server/vcd_tidl.c +++ b/server/vcd_tidl.c @@ -844,9 +844,10 @@ int vcdc_send_request_get_private_data(int pid, const char* key, char** data) } 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; + int ret = rpc_port_proxy_vcd_mgr_invoke_get_private_data(mgr_tidl_info->rpc_h, pid, key, &tmp); + if (RPC_PORT_ERROR_NONE != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Request vcd manager get private data : Fail to invoke message, error(%d)", ret); + return ret; } SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Request vcd manager get private data : Success"); @@ -871,9 +872,10 @@ int vcdc_send_request_auth_enable(int pid) 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; + int ret = rpc_port_proxy_vcd_mgr_invoke_auth_enable(mgr_tidl_info->rpc_h, pid); + if (RPC_PORT_ERROR_NONE != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Request auth enable : Fail to invoke message, error(%d)", ret); + return ret; } SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Request auth enable : Success"); @@ -896,9 +898,10 @@ int vcdc_send_request_auth_disable(int pid) 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; + int ret = rpc_port_proxy_vcd_mgr_invoke_auth_disable(mgr_tidl_info->rpc_h, pid); + if (RPC_PORT_ERROR_NONE != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Request auth disable : Fail to invoke message, error(%d)", ret); + return ret; } SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Request auth disable : Success"); @@ -921,9 +924,10 @@ int vcdc_send_request_auth_start(int pid) 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; + int ret = rpc_port_proxy_vcd_mgr_invoke_auth_start(mgr_tidl_info->rpc_h, pid); + if (RPC_PORT_ERROR_NONE != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Request auth start : Fail to invoke message, error(%d)", ret); + return ret; } SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Request auth start : Success"); @@ -946,9 +950,10 @@ int vcdc_send_request_auth_stop(int pid) 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; + int ret = rpc_port_proxy_vcd_mgr_invoke_auth_stop(mgr_tidl_info->rpc_h, pid); + if (RPC_PORT_ERROR_NONE != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Request auth stop : Fail to invoke message, error(%d)", ret); + return ret; } SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Request auth stop : Success"); @@ -971,9 +976,10 @@ int vcdc_send_request_auth_cancel(int pid) 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; + int ret = rpc_port_proxy_vcd_mgr_invoke_auth_cancel(mgr_tidl_info->rpc_h, pid); + if (RPC_PORT_ERROR_NONE != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Request auth cancel : Fail to invoke message, error(%d)", ret); + return ret; } SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Request auth cancel : Success"); @@ -997,9 +1003,10 @@ int vcdc_send_asr_result(int pid, int event, const char* asr_result, int cmd_typ } 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; + int ret = rpc_port_proxy_vcd_widget_invoke_send_asr_result(widget_tidl_info->rpc_h, pid, event, asr_result, &temp); + if (RPC_PORT_ERROR_NONE != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Request vcd widget send asr result : Fail to invoke message, error(%d)", ret); + return ret; } SLOG(LOG_DEBUG, TAG_VCD, "[TIDL] Request vcd widget send asr result : Success"); -- 2.7.4 From 0ac5da7b4acc098c2fa8fc68fd34dd07d9738478 Mon Sep 17 00:00:00 2001 From: ulgal-park Date: Thu, 19 May 2022 19:39:58 +0900 Subject: [PATCH 15/16] Change retry logic to match TIDL Change-Id: I50b7ca2aa38904ebbc92bcdf6ba2b3390995ea69 --- client/vc_mgr.c | 323 ++++++++++++------------------------------------ client/vc_mgr_tidl.c | 3 + client/vc_widget.c | 68 +++------- client/vc_widget_tidl.c | 3 + common/vc_defs.h | 1 + 5 files changed, 100 insertions(+), 298 deletions(-) diff --git a/client/vc_mgr.c b/client/vc_mgr.c index 9fd7862..6769fa1 100755 --- a/client/vc_mgr.c +++ b/client/vc_mgr.c @@ -534,31 +534,31 @@ 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; + if (0 != vc_mgr_tidl_request_hello()) { + if (g_tidl_send_hello_count == VC_TIDL_RETRY_COUNT) { + 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_dbus_send_hello_count++; + // TODO: discuss when updating connect/reconnect + g_tidl_send_hello_count++; + usleep(200000); 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; + // 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 { - // TODO: discuss when updating connect/reconnect - g_tidl_send_hello_count++; + g_dbus_send_hello_count++; return EINA_TRUE; } } @@ -881,26 +881,12 @@ int vc_mgr_unset_demandable_client_rule(void) vc_info_parser_set_demandable_client(NULL); - int count = 0; - int ret = -1; - while (0 != ret) { - 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)); - break; - } else { - SLOG(LOG_WARN, TAG_VCM, "[WARNING] retry request unset client rule : %s", __vc_mgr_get_error_code(ret)); - usleep(10000); - count++; - if (VC_RETRY_COUNT == count) { - SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to request"); - break; - } - } - } + int ret = vc_mgr_tidl_request_demandable_client(g_vc_m->handle); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to request unset client rule to daemon : %s", __vc_mgr_get_error_code(ret)); } + // TODO: check return value correct or not return 0; } @@ -1132,24 +1118,10 @@ int vc_mgr_set_command_list(vc_cmd_list_h vc_cmd_list) ret = VC_ERROR_INVALID_PARAMETER; SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to save command group : %s", __vc_mgr_get_error_code(ret)); } else { - int count = 0; - do { - 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)); - break; - } else { - SLOG(LOG_WARN, TAG_VCM, "[WARNING] retry request set command : %s", __vc_mgr_get_error_code(ret)); - usleep(10000); - count++; - if (VC_RETRY_COUNT == count) { - SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to request"); - break; - } - } - } - } while (0 != ret); + ret = vc_mgr_tidl_request_set_command(g_vc_m->handle); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to request set command to daemon : %s", __vc_mgr_get_error_code(ret)); + } } SLOG(LOG_ERROR, TAG_VCM, "@@@, ret(%d)", ret); @@ -1182,24 +1154,11 @@ int vc_mgr_unset_command_list(void) return VC_ERROR_INVALID_STATE; } - int count = 0; + int ret = -1; - while (0 != ret) { - 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)); - break; - } else { - SLOG(LOG_WARN, TAG_VCM, "[WARNING] retry request unset command : %s", __vc_mgr_get_error_code(ret)); - usleep(10000); - count++; - if (VC_RETRY_COUNT == count) { - SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to request"); - break; - } - } - } + ret = vc_mgr_tidl_request_unset_command(g_vc_m->handle); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to request unset command to daemon : %s", __vc_mgr_get_error_code(ret)); } int i; @@ -1211,6 +1170,7 @@ int vc_mgr_unset_command_list(void) SLOG(LOG_ERROR, TAG_VCM, "@@@"); + // TODO: check return value correct or not return 0; } @@ -1269,24 +1229,10 @@ int vc_mgr_set_command_list_from_file(const char* file_path, int type) ret = VC_ERROR_INVALID_PARAMETER; SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to save command list (%d)", ret); } else { - int count = 0; - do { - 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)); - break; - } else { - SLOG(LOG_WARN, TAG_VCM, "[WARNING] retry request set command : %s", __vc_mgr_get_error_code(ret)); - usleep(10000); - count++; - if (VC_RETRY_COUNT == count) { - SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to request"); - break; - } - } - } - } while (0 != ret); + ret = vc_mgr_tidl_request_set_command(g_vc_m->handle); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to request set command to daemon : %s", __vc_mgr_get_error_code(ret)); + } } SLOG(LOG_ERROR, TAG_VCM, "@@@, ret(%d)", ret); @@ -1385,29 +1331,14 @@ int vc_mgr_set_audio_type(const char* audio_id) } int ret = -1; - int count = 0; - /* Request */ - while (0 != ret) { - 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)); - break; - } else { - SLOG(LOG_WARN, TAG_VCM, "[WARNING] retry to set audio type : %s", __vc_mgr_get_error_code(ret)); - usleep(10000); - count++; - if (VC_RETRY_COUNT == count) { - SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to request"); - break; - } - } - } else { - SLOG(LOG_INFO, TAG_VCM, "[SUCCESS] Set audio type"); - /* Save */ - vc_mgr_client_set_audio_type(g_vc_m, audio_id); - } + ret = vc_mgr_tidl_request_set_audio_type(g_vc_m->handle, audio_id); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to set audio type : %s", __vc_mgr_get_error_code(ret)); + } else { + SLOG(LOG_INFO, TAG_VCM, "[SUCCESS] Set audio type"); + /* Save */ + vc_mgr_client_set_audio_type(g_vc_m, audio_id); } SLOG(LOG_ERROR, TAG_VCM, "@@@, ret(%d)", ret); @@ -1463,22 +1394,10 @@ int vc_mgr_get_audio_type(char** audio_id) if (NULL == temp) { /* Not initiallized */ int ret = -1; - int count = 0; while (0 != ret) { 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)); - break; - } else { - SLOG(LOG_WARN, TAG_VCM, "[WARNING] retry to get audio type : %s", __vc_mgr_get_error_code(ret)); - usleep(10000); - count++; - if (VC_RETRY_COUNT == count) { - SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to request"); - break; - } - } + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to get audio type : %s", __vc_mgr_get_error_code(ret)); } else { SLOG(LOG_ERROR, TAG_VCM, "[SUCCESS] Get audio type : %s", temp); /* Save */ @@ -1493,6 +1412,7 @@ int vc_mgr_get_audio_type(char** audio_id) temp = NULL; } + // TODO: check return value correct or not return 0; } @@ -1548,7 +1468,6 @@ int vc_mgr_get_current_commands(vc_cmd_list_h* vc_cmd_list) int fg_pid = 0; int mgr_pid = 0; - int count = 0; int ret = -1; /* Get foreground pid */ @@ -1573,26 +1492,11 @@ int vc_mgr_get_current_commands(vc_cmd_list_h* vc_cmd_list) } /* Request */ - ret = -1; - count = 0; - while (0 != ret) { - 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)); - break; - } else { - SLOG(LOG_WARN, TAG_VCM, "[WARNING] retry to set client info : %s", __vc_mgr_get_error_code(ret)); - usleep(10000); - count++; - if (VC_RETRY_COUNT == count) { - SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to request"); - break; - } - } - } else { - SLOG(LOG_INFO, TAG_VCM, "[SUCCESS] Set client info"); - } + ret = vc_mgr_tidl_request_set_client_info(g_vc_m->handle); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to set client info : %s", __vc_mgr_get_error_code(ret)); + } else { + SLOG(LOG_INFO, TAG_VCM, "[SUCCESS] Set client info"); } GSList *iter = NULL; @@ -1695,6 +1599,7 @@ int vc_mgr_get_current_commands(vc_cmd_list_h* vc_cmd_list) SLOG(LOG_ERROR, TAG_VCM, "@@@"); + // TODO: check return value correct or not return 0; } @@ -1876,29 +1781,17 @@ int vc_mgr_get_private_data(const char* key, char** data) } int ret = -1; - int count = 0; char* temp = NULL; - while (0 != ret) { - 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)); - break; - } else { - SLOG(LOG_WARN, TAG_VCM, "[WARNING] retry get private data request : %s", __vc_mgr_get_error_code(ret)); - usleep(10000); - count++; - if (VC_RETRY_COUNT == count) { - SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to request"); - break; - } - } - } else { - SLOG(LOG_INFO, TAG_VCM, "[SUCCESS] Get private data, key(%s), data(%s)", key, temp); - } + + ret = vc_mgr_tidl_request_get_private_data(g_vc_m->handle, key, &temp); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to get private data request : %s", __vc_mgr_get_error_code(ret)); + } else { + SLOG(LOG_INFO, TAG_VCM, "[SUCCESS] Get private data, key(%s), data(%s)", key, temp); } + if (NULL != temp) { *data = strdup(temp); free(temp); @@ -1907,6 +1800,7 @@ int vc_mgr_get_private_data(const char* key, char** data) SLOG(LOG_DEBUG, TAG_VCM, "@@@"); + // TODO: check return value correct or not return 0; } @@ -1952,26 +1846,14 @@ 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); - 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)); - break; - } else { - SLOG(LOG_WARN, TAG_VCM, "[WARNING] retry set domain request : %s", __vc_mgr_get_error_code(ret)); - usleep(10000); - count++; - if (VC_RETRY_COUNT == count) { - SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to request"); - break; - } - } - } else { - SLOG(LOG_INFO, TAG_VCM, "[SUCCESS] Set domain"); - } + + ret = vc_mgr_tidl_request_set_domain(g_vc_m->handle, domain); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to set domain request : %s", __vc_mgr_get_error_code(ret)); + } else { + SLOG(LOG_INFO, TAG_VCM, "[SUCCESS] Set domain"); } + SLOG(LOG_DEBUG, TAG_VCM, "@@@"); return 0; @@ -2153,7 +2035,6 @@ int vc_mgr_start(bool exclusive_command_option) } int ret; - int count = 0; vc_recognition_mode_e recognition_mode = VC_RECOGNITION_MODE_STOP_BY_SILENCE; if (0 != vc_mgr_get_recognition_mode(&recognition_mode)) { SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to get recognition mode"); @@ -2161,29 +2042,13 @@ int vc_mgr_start(bool exclusive_command_option) /* Request */ ret = -1; - 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); - 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)); - vc_mgr_client_set_internal_state(g_vc_m, VC_INTERNAL_STATE_NONE); - break; - } else { - SLOG(LOG_WARN, TAG_VCM, "[WARNING] retry start request start : %s", __vc_mgr_get_error_code(ret)); - usleep(10000); - count++; - if (VC_RETRY_COUNT == count) { - SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to request"); - vc_mgr_client_set_exclusive_command(g_vc_m, false); - vc_mgr_client_set_internal_state(g_vc_m, VC_INTERNAL_STATE_NONE); - break; - } - } - } else { - SLOG(LOG_INFO, TAG_VCM, "[SUCCESS] start recognition"); - } + 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); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to start request start : %s", __vc_mgr_get_error_code(ret)); + vc_mgr_client_set_internal_state(g_vc_m, VC_INTERNAL_STATE_NONE); + } else { + SLOG(LOG_INFO, TAG_VCM, "[SUCCESS] start recognition"); } g_volume_db = 0; @@ -2246,29 +2111,14 @@ int vc_mgr_stop(void) } int ret = -1; - int count = 0; /* 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); - 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)); - vc_mgr_client_set_internal_state(g_vc_m, VC_INTERNAL_STATE_NONE); - break; - } else { - SLOG(LOG_WARN, TAG_VCM, "[WARNING] retry stop request : %s", __vc_mgr_get_error_code(ret)); - usleep(10000); - count++; - if (VC_RETRY_COUNT == count) { - SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to request"); - vc_mgr_client_set_internal_state(g_vc_m, VC_INTERNAL_STATE_NONE); - break; - } - } - } else { - SLOG(LOG_INFO, TAG_VCM, "[SUCCESS] Stop recognition"); - } + vc_mgr_client_set_internal_state(g_vc_m, VC_INTERNAL_STATE_STOPPING); + ret = vc_mgr_tidl_request_stop(g_vc_m->handle); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to stop request : %s", __vc_mgr_get_error_code(ret)); + vc_mgr_client_set_internal_state(g_vc_m, VC_INTERNAL_STATE_NONE); + } else { + SLOG(LOG_INFO, TAG_VCM, "[SUCCESS] Stop recognition"); } SLOG(LOG_DEBUG, TAG_VCM, "@@@"); @@ -2326,28 +2176,13 @@ int vc_mgr_cancel(void) } int ret = -1; - 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); - 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)); - vc_mgr_client_set_internal_state(g_vc_m, VC_INTERNAL_STATE_NONE); - break; - } else { - SLOG(LOG_WARN, TAG_VCM, "[WARNING] retry cancel request : %s", __vc_mgr_get_error_code(ret)); - usleep(10000); - count++; - if (VC_RETRY_COUNT == count) { - SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to request"); - vc_mgr_client_set_internal_state(g_vc_m, VC_INTERNAL_STATE_NONE); - break; - } - } - } else { - SLOG(LOG_INFO, TAG_VCM, "[SUCCESS] Cancel recognition"); - } + vc_mgr_client_set_internal_state(g_vc_m, VC_INTERNAL_STATE_CANCELING); + ret = vc_mgr_tidl_request_cancel(g_vc_m->handle); + if (0 != ret) { + SLOG(LOG_DEBUG, TAG_VCM, "[ERROR] Fail to cancel request : %s", __vc_mgr_get_error_code(ret)); + vc_mgr_client_set_internal_state(g_vc_m, VC_INTERNAL_STATE_NONE); + } else { + SLOG(LOG_INFO, TAG_VCM, "[SUCCESS] Cancel recognition"); } vc_mgr_client_set_exclusive_command(g_vc_m, false); diff --git a/client/vc_mgr_tidl.c b/client/vc_mgr_tidl.c index a351965..daf53a1 100755 --- a/client/vc_mgr_tidl.c +++ b/client/vc_mgr_tidl.c @@ -348,6 +348,9 @@ static void __on_disconnected(rpc_port_proxy_vc_mgr_h h, void *user_data) g_proxy_tidl_info->register_callback_invoked = false; SLOG(LOG_INFO, TAG_VCM, "Disonnected to server"); + + SLOG(LOG_INFO, TAG_VCM, "Re-connection start"); + __vc_mgr_cb_error(VC_ERROR_SERVICE_RESET, -1, "Server Disconnected, re-launch"); } static void __on_rejected(rpc_port_proxy_vc_mgr_h h, void *user_data) diff --git a/client/vc_widget.c b/client/vc_widget.c index c0d1b1e..f0e3b01 100644 --- a/client/vc_widget.c +++ b/client/vc_widget.c @@ -527,7 +527,7 @@ static void __start_prepare_thread(void *data, Ecore_Thread *thread) return; } - if (retry_count == 30) { + if (retry_count == VC_TIDL_RETRY_COUNT) { SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to request hello !!"); ecore_main_loop_thread_safe_call_async(__vc_widget_delete_focus_event_handler, NULL); g_w_prepare_thread = NULL; @@ -701,26 +701,13 @@ int vc_widget_enable_asr_result(vc_h vc_w, bool enable) return VC_ERROR_INVALID_STATE; } - int count = 0; int ret = -1; - do { - 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)); - break; - } else { - SLOG(LOG_WARN, TAG_VCW, "[WARNING] retry to enable asr result : %s", __vc_widget_get_error_code(ret)); - usleep(10000); - count++; - if (VC_RETRY_COUNT == count) { - SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to request"); - break; - } - } - } - } while (0 != ret); + ret = vc_widget_tidl_request_enable_asr_result(getpid(), enable); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to enable asr result : %s", __vc_widget_get_error_code(ret)); + return ret; + } vc_widget_client_set_asr_result_enabled(vc_w, enable); @@ -1150,29 +1137,16 @@ int vc_widget_cancel(vc_h vc_w) return VC_ERROR_INVALID_STATE; } - int count = 0; int ret = -1; - do { - 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)); - break; - } else { - SLOG(LOG_WARN, TAG_VCW, "[WARNING] retry request cancel : %s", __vc_widget_get_error_code(ret)); - usleep(10000); - count++; - if (VC_RETRY_COUNT == count) { - SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to request"); - break; - } - } - } - } while (0 != ret); + ret = vc_widget_tidl_request_cancel(getpid()); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to request cancel : %s", __vc_widget_get_error_code(ret)); + } SLOG(LOG_DEBUG, TAG_VCW, "@@@"); + // TODO: check return value correct or not return 0; } @@ -1311,23 +1285,9 @@ 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); - 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)); - return EINA_FALSE; - } else { - SLOG(LOG_WARN, TAG_VCW, "[WARNING] retry start recording : %s", __vc_widget_get_error_code(ret)); - usleep(10000); - count++; - if (VC_RETRY_COUNT == count) { - SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to request"); - return EINA_FALSE; - } - } - } + ret = vc_widget_tidl_request_start_recording(getpid(), widget_command); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to request start recording to daemon : %s", __vc_widget_get_error_code(ret)); } return EINA_FALSE; diff --git a/client/vc_widget_tidl.c b/client/vc_widget_tidl.c index da50b61..1210668 100644 --- a/client/vc_widget_tidl.c +++ b/client/vc_widget_tidl.c @@ -162,6 +162,9 @@ static void __on_disconnected(rpc_port_proxy_vc_widget_h h, void *user_data) g_proxy_tidl_info->register_callback_invoked = false; SLOG(LOG_INFO, TAG_VCW, "Disonnected to server"); + + SLOG(LOG_INFO, TAG_VCW, "Re-connection start"); + __vc_widget_cb_error(VC_ERROR_SERVICE_RESET, -1, "Server Disconnected, re-launch"); } static void __on_rejected(rpc_port_proxy_vc_widget_h h, void *user_data) diff --git a/common/vc_defs.h b/common/vc_defs.h index 3ba15c5..81226ca 100644 --- a/common/vc_defs.h +++ b/common/vc_defs.h @@ -266,6 +266,7 @@ extern "C" { #define VC_RUNTIME_INFO_NO_FOREGROUND -1 #define VC_CONNECTION_RETRY_COUNT 10 #define VC_INVALID_TTS_UID 0 +#define VC_TIDL_RETRY_COUNT 100 #define VC_FEATURE_PATH "tizen.org/feature/speech.control" #define VC_MGR_FEATURE_PATH "tizen.org/feature/speech.control_manager" -- 2.7.4 From 90411c6dcdc96e08459f628b88439a4188cd85da Mon Sep 17 00:00:00 2001 From: sooyeon Date: Fri, 3 Jun 2022 18:10:20 +0900 Subject: [PATCH 16/16] Replace IPC (VCC) from dbus to tidl Change-Id: Ief592a9240490c404b756b37cb7b887c3a974321 Signed-off-by: sooyeon --- client/CMakeLists.txt | 3 +- client/vc.c | 51 +- client/vc_proxy.c | 2869 ++++++++++++++++++++++++++++++++++++++++++ client/vc_proxy.h | 819 ++++++++++++ client/vc_tidl.c | 708 +++++++++++ client/vc_tidl.h | 83 ++ common/vc_defs.h | 16 + common/vc_main.h | 28 + packaging/voice-control.spec | 8 +- server/vcd_client_data.c | 220 ++++ server/vcd_client_data.h | 22 + server/vcd_dbus.c | 145 ++- server/vcd_dbus.h | 8 +- server/vcd_stub.c | 2422 +++++++++++++++++++++++++++++++++++ server/vcd_stub.h | 680 ++++++++++ server/vcd_tidl.c | 495 ++++++++ server/vcd_tidl.h | 10 + tidl/vc.tidl | 28 + 18 files changed, 8509 insertions(+), 106 deletions(-) create mode 100755 client/vc_proxy.c create mode 100755 client/vc_proxy.h create mode 100755 client/vc_tidl.c create mode 100755 client/vc_tidl.h create mode 100755 server/vcd_stub.c create mode 100755 server/vcd_stub.h create mode 100755 tidl/vc.tidl diff --git a/client/CMakeLists.txt b/client/CMakeLists.txt index ab5f35f..0001ef9 100644 --- a/client/CMakeLists.txt +++ b/client/CMakeLists.txt @@ -2,7 +2,8 @@ SET(SRCS vc.c vc_data.cpp vc_client.c - vc_dbus.c +# vc_dbus.c + vc_tidl.c ../common/vc_cmd_db.c ../common/vc_command.c ../common/vc_command_util.c diff --git a/client/vc.c b/client/vc.c index f42cc66..0688716 100644 --- a/client/vc.c +++ b/client/vc.c @@ -30,7 +30,8 @@ #include "vc_command.h" #include "vc_config_mgr.h" #include "vc_data.h" -#include "vc_dbus.h" +// #include "vc_dbus.h" +#include "vc_tidl.h" #include "vc_info_parser.h" #include "vc_json_parser.h" #include "vc_main.h" @@ -268,7 +269,7 @@ 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_VCC, "@@@ Set foreground"); - ret = vc_dbus_set_foreground(getpid(), true); + ret = vc_tidl_request_set_foreground(getpid(), true); if (0 != ret) { SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Fail to set foreground (true) : %d", ret); } @@ -291,7 +292,7 @@ static Eina_Bool __focus_changed_cb(void *data, int type, void *event) } } else if (ECORE_WL2_EVENT_FOCUS_OUT == type) { SLOG(LOG_DEBUG, TAG_VCW, "@@@ Set background"); - ret = vc_dbus_set_foreground(getpid(), false); + ret = vc_tidl_request_set_foreground(getpid(), false); if (0 != ret) { SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Fail to set foreground (false) : %d", ret); } @@ -344,7 +345,7 @@ int vc_initialize(void) return VC_ERROR_NONE; //LCOV_EXCL_LINE } - if (0 != vc_dbus_open_connection()) { + if (0 != vc_tidl_open_connection()) { SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Fail to open connection"); //LCOV_EXCL_LINE return VC_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE } @@ -391,7 +392,7 @@ static void __vc_internal_unprepare(void) } } - int ret = vc_dbus_request_finalize(g_vc->handle); + int ret = vc_tidl_request_finalize(g_vc->handle); if (0 != ret) { SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Fail to request finalize : %s", __vc_get_error_code(ret)); //LCOV_EXCL_LINE } @@ -471,7 +472,7 @@ int vc_deinitialize(void) SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Fail to finalize DB, ret(%d)", ret); //LCOV_EXCL_LINE } - if (0 != vc_dbus_close_connection()) { + if (0 != vc_tidl_close_connection()) { SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Fail to close connection"); //LCOV_EXCL_LINE } @@ -506,7 +507,7 @@ static Eina_Bool __vc_connect_daemon(void *data) if (0 != ret) SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Fail to delete file, type(%d), ret(%d)", VC_COMMAND_TYPE_FOREGROUND, ret); //LCOV_EXCL_LINE - ret = vc_dbus_request_initialize(g_vc->handle, &mgr_pid, &service_state, &g_daemon_pid); + ret = vc_tidl_request_initialize(g_vc->handle, &mgr_pid, &service_state, &g_daemon_pid); //LCOV_EXCL_START if (VC_ERROR_ENGINE_NOT_FOUND == ret) { SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Fail to initialize : %s", __vc_get_error_code(ret)); @@ -565,7 +566,7 @@ static Eina_Bool __vc_connect_daemon(void *data) int status = aul_app_get_status(appid); if (STATUS_FOCUS == status) { SLOG(LOG_DEBUG, TAG_VCC, "@@@ Set foreground"); //LCOV_EXCL_LINE - ret = vc_dbus_set_foreground(getpid(), true); + ret = vc_tidl_request_set_foreground(getpid(), true); if (0 != ret) { SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Fail to set foreground (true) : %d", ret); //LCOV_EXCL_LINE } @@ -614,7 +615,7 @@ static void __start_prepare_thread(void *data, Ecore_Thread *thread) return; } - ret = vc_dbus_request_hello(); + ret = vc_tidl_request_hello(); if (ret == 0) { SLOG(LOG_DEBUG, TAG_VCC, "Success to request hello. retry count(%d)", retry_count); break; @@ -964,7 +965,7 @@ int vc_get_system_command_list(vc_cmd_list_h* vc_sys_cmd_list) int ret = -1; bool is_prepared = false; do { - ret = vc_dbus_request_is_system_command_valid(g_vc->handle, &is_sys_cmd_valid); + ret = vc_tidl_request_is_system_command_valid(g_vc->handle, &is_sys_cmd_valid); if (0 != ret) { //LCOV_EXCL_START if (VC_ERROR_INVALID_PARAMETER == ret && false == is_prepared) { @@ -1211,7 +1212,7 @@ int vc_set_command_list(vc_cmd_list_h vc_cmd_list, int type) int count = 0; bool is_prepared = false; do { - ret = vc_dbus_request_set_command(g_vc->handle, (vc_cmd_type_e)type); + ret = vc_tidl_request_set_command(g_vc->handle, (vc_cmd_type_e)type); if (0 != ret) { //LCOV_EXCL_START if (VC_ERROR_INVALID_PARAMETER == ret && false == is_prepared) { @@ -1276,7 +1277,7 @@ int vc_unset_command_list(int type) int ret = -1; bool is_prepared = false; while (0 != ret) { - ret = vc_dbus_request_unset_command(g_vc->handle, (vc_cmd_type_e)type); + ret = vc_tidl_request_unset_command(g_vc->handle, (vc_cmd_type_e)type); if (0 != ret) { //LCOV_EXCL_START if (VC_ERROR_INVALID_PARAMETER == ret && false == is_prepared) { @@ -1366,7 +1367,7 @@ int vc_set_command_list_from_file(const char* file_path, int type) int count = 0; bool is_prepared = false; do { - ret = vc_dbus_request_set_command(g_vc->handle, (vc_cmd_type_e)type); + ret = vc_tidl_request_set_command(g_vc->handle, (vc_cmd_type_e)type); if (0 != ret) { if (VC_ERROR_INVALID_PARAMETER == ret && false == is_prepared) { vc_client_set_client_state(g_vc, VC_STATE_INITIALIZED); @@ -2280,7 +2281,7 @@ int vc_set_server_dialog(const char* app_id, const char* credential) int count = 0; bool is_prepared = false; do { - ret = vc_dbus_set_server_dialog(pid, tmp_appid, credential); + ret = vc_tidl_request_set_server_dialog(pid, tmp_appid, credential); if (0 != ret) { if (VC_ERROR_INVALID_PARAMETER == ret && false == is_prepared) { vc_client_set_client_state(g_vc, VC_STATE_INITIALIZED); @@ -2364,7 +2365,7 @@ int vc_unset_server_dialog(const char* app_id) bool is_prepared = false; char* credential = strdup("#NULL"); do { - ret = vc_dbus_set_server_dialog(pid, tmp_appid, credential); + ret = vc_tidl_request_set_server_dialog(pid, tmp_appid, credential); if (0 != ret) { if (VC_ERROR_INVALID_PARAMETER == ret && false == is_prepared) { vc_client_set_client_state(g_vc, VC_STATE_INITIALIZED); @@ -2431,7 +2432,7 @@ int vc_request_dialog(const char* disp_text, const char* utt_text, bool auto_sta } SLOG(LOG_DEBUG, TAG_VCC, "Request dialog : pid(%d) disp_text(%s), utt_text(%s), auto_start(%d)", getpid(), disp_text, utt_text, auto_start); - int ret = vc_dbus_request_dialog(getpid(), disp_text, utt_text, auto_start); + int ret = vc_tidl_request_request_dialog(getpid(), disp_text, utt_text, auto_start); if (0 != ret) { SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Fail to request dialog, ret(%d)", ret); return VC_ERROR_OPERATION_FAILED; @@ -2477,7 +2478,7 @@ int vc_auth_enable(void) return VC_ERROR_OPERATION_FAILED; } - if (0 != vc_dbus_request_auth_enable(g_vc->handle, mgr_pid)) { + if (0 != vc_tidl_request_auth_enable(g_vc->handle, mgr_pid)) { SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Fail to authority enabled"); return VC_ERROR_OPERATION_FAILED; } @@ -2537,14 +2538,14 @@ int vc_auth_disable(void) SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Fail to unset state changed cb"); } - /* request return authority by dbus */ + /* request return authority by tidl */ int mgr_pid = -1; if (0 != vc_client_get_mgr_pid(g_vc, &mgr_pid)) { SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Fail to get mgr info"); return VC_ERROR_OPERATION_FAILED; } - if (0 != vc_dbus_request_auth_disable(g_vc->handle, mgr_pid)) { + if (0 != vc_tidl_request_auth_disable(g_vc->handle, mgr_pid)) { SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Fail to authority disable"); return VC_ERROR_OPERATION_FAILED; } @@ -2697,7 +2698,7 @@ int vc_auth_start(void) bool is_prepared = false; /* Request */ while (0 != ret) { - ret = vc_dbus_request_auth_start(g_vc->handle, mgr_pid); + ret = vc_tidl_request_auth_start(g_vc->handle, mgr_pid); if (0 != ret) { if (VC_ERROR_INVALID_PARAMETER == ret && false == is_prepared) { vc_client_set_client_state(g_vc, VC_STATE_INITIALIZED); @@ -2778,7 +2779,7 @@ int vc_auth_stop(void) bool is_prepared = false; /* do request */ while (0 != ret) { - ret = vc_dbus_request_auth_stop(g_vc->handle, mgr_pid); + ret = vc_tidl_request_auth_stop(g_vc->handle, mgr_pid); if (0 != ret) { if (VC_ERROR_INVALID_PARAMETER == ret && false == is_prepared) { vc_client_set_client_state(g_vc, VC_STATE_INITIALIZED); @@ -2858,7 +2859,7 @@ int vc_auth_cancel(void) int count = 0; bool is_prepared = false; while (0 != ret) { - ret = vc_dbus_request_auth_cancel(g_vc->handle, mgr_pid); + ret = vc_tidl_request_auth_cancel(g_vc->handle, mgr_pid); if (0 != ret) { if (VC_ERROR_INVALID_PARAMETER == ret && false == is_prepared) { vc_client_set_client_state(g_vc, VC_STATE_INITIALIZED); @@ -3044,7 +3045,7 @@ int vc_tts_request(const char* text, const char* language, bool to_vc_manager, i int count = 0; bool is_prepared = false; do { - ret = vc_dbus_request_tts(pid, text, language, to_vc_manager, utt_id); + ret = vc_tidl_request_request_tts(pid, text, language, to_vc_manager, utt_id); if (0 != ret) { if (VC_ERROR_INVALID_PARAMETER == ret && false == is_prepared) { vc_client_set_client_state(g_vc, VC_STATE_INITIALIZED); @@ -3119,7 +3120,7 @@ int vc_tts_cancel(int utt_id) int count = 0; bool is_prepared = false; do { - ret = vc_dbus_cancel_tts(pid, utt_id); + ret = vc_tidl_request_cancel_tts(pid, utt_id); if (0 != ret) { if (VC_ERROR_INVALID_PARAMETER == ret && false == is_prepared) { vc_client_set_client_state(g_vc, VC_STATE_INITIALIZED); @@ -3189,7 +3190,7 @@ int vc_tts_get_synthesized_audio_details(int* rate, vc_audio_channel_e* channel, int count = 0; bool is_prepared = false; do { - ret = vc_dbus_get_tts_audio_format(pid, rate, channel, audio_type); + ret = vc_tidl_request_get_tts_audio_format(pid, rate, channel, audio_type); if (0 != ret) { if (VC_ERROR_INVALID_PARAMETER == ret && false == is_prepared) { vc_client_set_client_state(g_vc, VC_STATE_INITIALIZED); diff --git a/client/vc_proxy.c b/client/vc_proxy.c new file mode 100755 index 0000000..d55b82d --- /dev/null +++ b/client/vc_proxy.c @@ -0,0 +1,2869 @@ +/* + * Generated by tidlc 1.8.1. + */ + +#ifndef _GNU_SOURCE +#define _GNU_SOURCE +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "vc_proxy.h" + +#undef LOG_TAG +#define LOG_TAG "RPC_PORT_PROXY" + +#undef _E +#define _E(fmt, ...) dlog_print(DLOG_ERROR, LOG_TAG, "%s: %s(%d) > "fmt, basename(__FILE__), __FUNCTION__, __LINE__, ##__VA_ARGS__) + +#undef _W +#define _W(fmt, ...) dlog_print(DLOG_WARN, LOG_TAG, "%s: %s(%d) > "fmt, basename(__FILE__), __FUNCTION__, __LINE__, ##__VA_ARGS__) + +#undef _I +#define _I(fmt, ...) dlog_print(DLOG_INFO, LOG_TAG, "%s: %s(%d) > "fmt, basename(__FILE__), __FUNCTION__, __LINE__, ##__VA_ARGS__) + +#undef _D +#define _D(fmt, ...) dlog_print(DLOG_DEBUG, LOG_TAG, "%s: %s(%d) > "fmt, basename(__FILE__), __FUNCTION__, __LINE__, ##__VA_ARGS__) + +#ifndef TIDL_VERSION +#define TIDL_VERSION "1.8.1" +#endif + +#ifndef nullptr +#define nullptr NULL +#endif + +#ifndef ARRAY_SIZE +#define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0])) +#endif + +#ifndef STRING_GET +#define STRING_GET(x) ((x) ? x : "") +#endif + +typedef void (*rpc_port_proxy_delegate_cb)(GList **delegates, rpc_port_parcel_h parcel, int id, int seq_id); + +typedef struct rpc_port_proxy_array_char_s { + rpc_port_parcelable_t parcelable; + char *value; + int size; +} rpc_port_proxy_array_char_t; + +typedef struct rpc_port_proxy_vc_notify_cb_s { + rpc_port_parcelable_t parcelable; + int id; + int seq_id; + bool once; + rpc_port_proxy_vc_notify_cb_cb callback; + void *user_data; +} rpc_port_proxy_vc_notify_cb_t; + +typedef struct rpc_port_proxy_vc_feedback_cb_s { + rpc_port_parcelable_t parcelable; + int id; + int seq_id; + bool once; + rpc_port_proxy_vc_feedback_cb_cb callback; + void *user_data; +} rpc_port_proxy_vc_feedback_cb_t; + +typedef struct rpc_port_proxy_vc_s { + char *stub_appid; + rpc_port_proxy_h proxy; + rpc_port_h port; + rpc_port_h callback_port; + rpc_port_proxy_vc_callback_s callback; + void *user_data; + GList *delegates; + GRecMutex mutex; +} rpc_port_proxy_vc_t; + +static void __rpc_port_proxy_array_char_to(rpc_port_parcel_h parcel, void *data) +{ + rpc_port_proxy_array_char_h h = data; + int i; + + if (parcel == nullptr || h == nullptr) { + _E("Invalid parameter"); + return; + } + + rpc_port_parcel_write_array_count(parcel, h->size); + + for (i = 0; i < h->size; ++i) + rpc_port_parcel_write_byte(parcel, h->value[i]); +} + +static void __rpc_port_proxy_array_char_from(rpc_port_parcel_h parcel, void *data) +{ + rpc_port_proxy_array_char_h h = data; + char value; + int ret; + int i; + + if (parcel == nullptr || h == nullptr) { + _E("Invalid parameter"); + set_last_result(RPC_PORT_ERROR_INVALID_PARAMETER); + return; + } + + ret = rpc_port_parcel_read_array_count(parcel, &h->size); + if (ret != RPC_PORT_ERROR_NONE) { + _E("Failed to read array count. error(%d)", ret); + set_last_result(ret); + return; + } + + h->value = calloc(h->size, sizeof(char)); + if (h->value == nullptr) { + _E("Out of memory"); + set_last_result(RPC_PORT_ERROR_OUT_OF_MEMORY); + return; + } + + for (i = 0; i < h->size; ++i) { + rpc_port_parcel_read_byte(parcel, &value); + h->value[i] = value; + } + + set_last_result(RPC_PORT_ERROR_NONE); +} + +int rpc_port_proxy_array_char_create(rpc_port_proxy_array_char_h *h) +{ + rpc_port_proxy_array_char_t *handle; + + if (h == nullptr) { + _E("Invalid parameter"); + return RPC_PORT_ERROR_INVALID_PARAMETER; + } + + handle = calloc(1, sizeof(rpc_port_proxy_array_char_t)); + if (handle == nullptr) { + _E("Out of memory"); + return RPC_PORT_ERROR_OUT_OF_MEMORY; + } + + handle->parcelable.to = __rpc_port_proxy_array_char_to; + handle->parcelable.from = __rpc_port_proxy_array_char_from; + + *h = handle; + + return RPC_PORT_ERROR_NONE; +} + +int rpc_port_proxy_array_char_destroy(rpc_port_proxy_array_char_h h) +{ + if (h == nullptr) { + _E("Invalid parameter"); + return RPC_PORT_ERROR_INVALID_PARAMETER; + } + + if (h->value) + free(h->value); + + free(h); + + return RPC_PORT_ERROR_NONE; +} + +int rpc_port_proxy_array_char_clone(rpc_port_proxy_array_char_h h, rpc_port_proxy_array_char_h *clone) +{ + rpc_port_proxy_array_char_h handle; + rpc_port_parcel_h parcel; + int ret; + + if (h == nullptr || clone == nullptr) { + _E("Invalid parameter"); + return RPC_PORT_ERROR_INVALID_PARAMETER; + } + + ret = rpc_port_proxy_array_char_create(&handle); + if (ret != RPC_PORT_ERROR_NONE) { + _E("Failed to create handle. error(%d)", ret); + return ret; + } + + ret = rpc_port_parcel_create(&parcel); + if (ret != RPC_PORT_ERROR_NONE) { + _E("Failed to create parcel handle. error(%d)", ret); + rpc_port_proxy_array_char_destroy(handle); + return ret; + } + + rpc_port_parcel_write(parcel, &h->parcelable, h); + rpc_port_parcel_read(parcel, &handle->parcelable, handle); + ret = get_last_result(); + rpc_port_parcel_destroy(parcel); + + if (ret != RPC_PORT_ERROR_NONE) { + _E("Failed to read data. error(%d)", ret); + rpc_port_proxy_array_char_destroy(handle); + return ret; + } + + *clone = handle; + + return RPC_PORT_ERROR_NONE; +} + +int rpc_port_proxy_array_char_set(rpc_port_proxy_array_char_h h, char *value, int size) +{ + rpc_port_proxy_array_char_h handle; + rpc_port_proxy_array_char_h clone; + int ret; + + if (h == nullptr || value == nullptr || size <= 0) { + _E("Invalid parameter"); + return RPC_PORT_ERROR_INVALID_PARAMETER; + } + + ret = rpc_port_proxy_array_char_create(&handle); + if (ret != RPC_PORT_ERROR_NONE) { + _E("Failed to create handle. error(%d)", ret); + return ret; + } + + handle->value = (char *)value; + handle->size = size; + + ret = rpc_port_proxy_array_char_clone(handle, &clone); + if (ret != RPC_PORT_ERROR_NONE) { + _E("Failed to clone handle. error(%d)", ret); + handle->value = nullptr; + handle->size = 0; + rpc_port_proxy_array_char_destroy(handle); + return ret; + } + + handle->value = h->value; + handle->size = h->size; + rpc_port_proxy_array_char_destroy(handle); + + h->value = clone->value; + h->size = clone->size; + + clone->value = nullptr; + clone->size = 0; + rpc_port_proxy_array_char_destroy(clone); + + return RPC_PORT_ERROR_NONE; +} + +int rpc_port_proxy_array_char_get(rpc_port_proxy_array_char_h h, char **value, int *size) +{ + rpc_port_proxy_array_char_h handle; + int ret; + + if (h == nullptr || value == nullptr || size == nullptr) { + _E("Invalid parameter"); + return RPC_PORT_ERROR_INVALID_PARAMETER; + } + + ret = rpc_port_proxy_array_char_clone(h, &handle); + if (ret != RPC_PORT_ERROR_NONE) { + _E("Failed to clone handle. error(%d)", ret); + return ret; + } + + *value = handle->value; + *size = handle->size; + + handle->value = nullptr; + handle->size = 0; + rpc_port_proxy_array_char_destroy(handle); + + return RPC_PORT_ERROR_NONE; +} + +typedef enum { + RPC_PORT_PROXY_VC_DELEGATE_NOTIFY_CB = 1, + RPC_PORT_PROXY_VC_DELEGATE_FEEDBACK_CB = 2, +} rpc_port_proxy_vc_delegate_e; + +static void __rpc_port_proxy_vc_notify_cb_to(rpc_port_parcel_h parcel, void *data) +{ + rpc_port_proxy_vc_notify_cb_h h = data; + + if (parcel == nullptr || h == nullptr) { + _E("Invalid parameter"); + return; + } + + rpc_port_parcel_write_int32(parcel, h->id); + + rpc_port_parcel_write_int32(parcel, h->seq_id); + + rpc_port_parcel_write_bool(parcel, h->once); + + _I("id(%d), seq_id(%d), once(%s)", h->id, h->seq_id, h->once ? "true" : "false"); +} + +static void __rpc_port_proxy_vc_notify_cb_from(rpc_port_parcel_h parcel, void *data) +{ + rpc_port_proxy_vc_notify_cb_h h = data; + + if (parcel == nullptr || h == nullptr) { + _E("Invalid parameter"); + set_last_result(RPC_PORT_ERROR_INVALID_PARAMETER); + return; + } + + rpc_port_parcel_read_int32(parcel, &h->id); + + rpc_port_parcel_read_int32(parcel, &h->seq_id); + + rpc_port_parcel_read_bool(parcel, &h->once); + + _I("id(%d), seq_id(%d), once(%s)", h->id, h->seq_id, h->once ? "true" : "false"); + set_last_result(RPC_PORT_ERROR_NONE); +} + +int rpc_port_proxy_vc_notify_cb_create(rpc_port_proxy_vc_notify_cb_h *h) +{ + rpc_port_proxy_vc_notify_cb_t *handle; + static int seq_num; + + if (h == nullptr) { + _E("Invalid parameter"); + return RPC_PORT_ERROR_INVALID_PARAMETER; + } + + handle = calloc(1, sizeof(rpc_port_proxy_vc_notify_cb_t)); + if (handle == nullptr) { + _E("Out of memory"); + return RPC_PORT_ERROR_OUT_OF_MEMORY; + } + + handle->parcelable.to = __rpc_port_proxy_vc_notify_cb_to; + handle->parcelable.from = __rpc_port_proxy_vc_notify_cb_from; + handle->id = RPC_PORT_PROXY_VC_DELEGATE_NOTIFY_CB; + handle->seq_id = g_atomic_int_add(&seq_num, 1) + 1; + _I("id(%d), seq_id(%d)", handle->id, handle->seq_id); + + *h = handle; + + return RPC_PORT_ERROR_NONE; +} + +int rpc_port_proxy_vc_notify_cb_destroy(rpc_port_proxy_vc_notify_cb_h h) +{ + if (h == nullptr) { + _E("Invalid parameter"); + return RPC_PORT_ERROR_INVALID_PARAMETER; + } + + _W("id(%d), seq_id(%d), once(%s)", h->id, h->seq_id, h->once ? "true" : "false"); + + free(h); + + return RPC_PORT_ERROR_NONE; +} + +int rpc_port_proxy_vc_notify_cb_clone(rpc_port_proxy_vc_notify_cb_h h, rpc_port_proxy_vc_notify_cb_h *clone) +{ + rpc_port_proxy_vc_notify_cb_h handle; + rpc_port_parcel_h parcel; + int ret; + + if (h == nullptr || clone == nullptr) { + _E("Invalid parameter"); + return RPC_PORT_ERROR_INVALID_PARAMETER; + } + + ret = rpc_port_proxy_vc_notify_cb_create(&handle); + if (ret != RPC_PORT_ERROR_NONE) { + _E("Failed to create handle. error(%d)", ret); + return ret; + } + + ret = rpc_port_parcel_create(&parcel); + if (ret != RPC_PORT_ERROR_NONE) { + _E("Failed to create parcel handle. error(%d)", ret); + rpc_port_proxy_vc_notify_cb_destroy(handle); + return ret; + } + + rpc_port_parcel_write(parcel, &h->parcelable, h); + rpc_port_parcel_read(parcel, &handle->parcelable, handle); + ret = get_last_result(); + rpc_port_parcel_destroy(parcel); + + if (ret != RPC_PORT_ERROR_NONE) { + _E("Failed to read data. error(%d)", ret); + rpc_port_proxy_vc_notify_cb_destroy(handle); + return ret; + } + + handle->callback = h->callback; + handle->user_data = h->user_data; + + *clone = handle; + + return RPC_PORT_ERROR_NONE; +} + +int rpc_port_proxy_vc_notify_cb_set_callback(rpc_port_proxy_vc_notify_cb_h h, rpc_port_proxy_vc_notify_cb_cb callback, void *user_data) +{ + if (h == nullptr || callback == nullptr) { + _E("Invalid parameter"); + return RPC_PORT_ERROR_INVALID_PARAMETER; + } + + h->callback = callback; + h->user_data = user_data; + + return RPC_PORT_ERROR_NONE; +} + +int rpc_port_proxy_vc_notify_cb_set_once(rpc_port_proxy_vc_notify_cb_h h, bool once) +{ + if (h == nullptr) { + _E("Invalid parameter"); + return RPC_PORT_ERROR_INVALID_PARAMETER; + } + + h->once = once; + + return RPC_PORT_ERROR_NONE; +} + +int rpc_port_proxy_vc_notify_cb_get_id(rpc_port_proxy_vc_notify_cb_h h, int *id) +{ + if (h == nullptr || id == nullptr) { + _E("Invalid parameter"); + return RPC_PORT_ERROR_INVALID_PARAMETER; + } + + *id = h->id; + + return RPC_PORT_ERROR_NONE; +} + +int rpc_port_proxy_vc_notify_cb_get_seq_id(rpc_port_proxy_vc_notify_cb_h h, int *seq_id) +{ + if (h == nullptr || seq_id == nullptr) { + _E("Invalid parameter"); + return RPC_PORT_ERROR_INVALID_PARAMETER; + } + + *seq_id = h->seq_id; + + return RPC_PORT_ERROR_NONE; +} + +int rpc_port_proxy_vc_notify_cb_is_once(rpc_port_proxy_vc_notify_cb_h h, bool *once) +{ + if (h == nullptr || once == nullptr) { + _E("Invalid parameter"); + return RPC_PORT_ERROR_INVALID_PARAMETER; + } + + *once = h->once; + + return RPC_PORT_ERROR_NONE; +} + +int rpc_port_proxy_vc_notify_cb_get_tag(rpc_port_proxy_vc_notify_cb_h h, char **tag) +{ + char *new_tag; + char buf[128]; + + if (h == nullptr || tag == nullptr) { + _E("Invalid parameter"); + return RPC_PORT_ERROR_INVALID_PARAMETER; + } + + snprintf(buf, sizeof(buf), "%d::%d", h->id, h->seq_id); + new_tag = strdup(buf); + if (new_tag == nullptr) { + _E("Out of memory"); + return RPC_PORT_ERROR_OUT_OF_MEMORY; + } + + *tag = new_tag; + + return RPC_PORT_ERROR_NONE; +} + +int rpc_port_proxy_vc_notify_cb_dispose(rpc_port_proxy_vc_h proxy, rpc_port_proxy_vc_notify_cb_h h) +{ + GList *found; + + if (proxy == nullptr || h == nullptr) { + _E("Invalid parameter"); + return RPC_PORT_ERROR_INVALID_PARAMETER; + } + + found = g_list_find(proxy->delegates, h); + if (found == nullptr) { + _E("Invalid parameter"); + return RPC_PORT_ERROR_INVALID_PARAMETER; + } + + proxy->delegates = g_list_remove_link(proxy->delegates, found); + rpc_port_proxy_vc_notify_cb_destroy(h); + g_list_free(found); + + return RPC_PORT_ERROR_NONE; +} + +static void __rpc_port_proxy_vc_notify_cb_delegate_handler(GList **delegates, rpc_port_parcel_h parcel, int id, int seq_id) +{ + rpc_port_proxy_vc_notify_cb_h handle; + GList *iter; + bool once; + int pid = -1; + bundle *msg = nullptr; + + rpc_port_parcel_read_int32(parcel, &pid); + + rpc_port_parcel_read_bundle(parcel, &msg); + if (msg == nullptr) { + _E("Failed to read data"); + goto out; + } + + iter = *delegates; + while (iter) { + handle = iter->data; + iter = g_list_next(iter); + if (handle->id == id && handle->seq_id == seq_id) { + once = handle->once; + _W("Invoke id(%d), seq_id(%d)", id, seq_id); + if (handle->callback) + handle->callback(handle->user_data, pid, msg); + else + _W("The callback function is nullptr"); + + if (once) { + *delegates = g_list_remove(*delegates, handle); + rpc_port_proxy_vc_notify_cb_destroy(handle); + } + + break; + } + } + +out: + + if (msg) + bundle_free(msg); +} + +static void __rpc_port_proxy_vc_feedback_cb_to(rpc_port_parcel_h parcel, void *data) +{ + rpc_port_proxy_vc_feedback_cb_h h = data; + + if (parcel == nullptr || h == nullptr) { + _E("Invalid parameter"); + return; + } + + rpc_port_parcel_write_int32(parcel, h->id); + + rpc_port_parcel_write_int32(parcel, h->seq_id); + + rpc_port_parcel_write_bool(parcel, h->once); + + _I("id(%d), seq_id(%d), once(%s)", h->id, h->seq_id, h->once ? "true" : "false"); +} + +static void __rpc_port_proxy_vc_feedback_cb_from(rpc_port_parcel_h parcel, void *data) +{ + rpc_port_proxy_vc_feedback_cb_h h = data; + + if (parcel == nullptr || h == nullptr) { + _E("Invalid parameter"); + set_last_result(RPC_PORT_ERROR_INVALID_PARAMETER); + return; + } + + rpc_port_parcel_read_int32(parcel, &h->id); + + rpc_port_parcel_read_int32(parcel, &h->seq_id); + + rpc_port_parcel_read_bool(parcel, &h->once); + + _I("id(%d), seq_id(%d), once(%s)", h->id, h->seq_id, h->once ? "true" : "false"); + set_last_result(RPC_PORT_ERROR_NONE); +} + +int rpc_port_proxy_vc_feedback_cb_create(rpc_port_proxy_vc_feedback_cb_h *h) +{ + rpc_port_proxy_vc_feedback_cb_t *handle; + static int seq_num; + + if (h == nullptr) { + _E("Invalid parameter"); + return RPC_PORT_ERROR_INVALID_PARAMETER; + } + + handle = calloc(1, sizeof(rpc_port_proxy_vc_feedback_cb_t)); + if (handle == nullptr) { + _E("Out of memory"); + return RPC_PORT_ERROR_OUT_OF_MEMORY; + } + + handle->parcelable.to = __rpc_port_proxy_vc_feedback_cb_to; + handle->parcelable.from = __rpc_port_proxy_vc_feedback_cb_from; + handle->id = RPC_PORT_PROXY_VC_DELEGATE_FEEDBACK_CB; + handle->seq_id = g_atomic_int_add(&seq_num, 1) + 1; + _I("id(%d), seq_id(%d)", handle->id, handle->seq_id); + + *h = handle; + + return RPC_PORT_ERROR_NONE; +} + +int rpc_port_proxy_vc_feedback_cb_destroy(rpc_port_proxy_vc_feedback_cb_h h) +{ + if (h == nullptr) { + _E("Invalid parameter"); + return RPC_PORT_ERROR_INVALID_PARAMETER; + } + + _W("id(%d), seq_id(%d), once(%s)", h->id, h->seq_id, h->once ? "true" : "false"); + + free(h); + + return RPC_PORT_ERROR_NONE; +} + +int rpc_port_proxy_vc_feedback_cb_clone(rpc_port_proxy_vc_feedback_cb_h h, rpc_port_proxy_vc_feedback_cb_h *clone) +{ + rpc_port_proxy_vc_feedback_cb_h handle; + rpc_port_parcel_h parcel; + int ret; + + if (h == nullptr || clone == nullptr) { + _E("Invalid parameter"); + return RPC_PORT_ERROR_INVALID_PARAMETER; + } + + ret = rpc_port_proxy_vc_feedback_cb_create(&handle); + if (ret != RPC_PORT_ERROR_NONE) { + _E("Failed to create handle. error(%d)", ret); + return ret; + } + + ret = rpc_port_parcel_create(&parcel); + if (ret != RPC_PORT_ERROR_NONE) { + _E("Failed to create parcel handle. error(%d)", ret); + rpc_port_proxy_vc_feedback_cb_destroy(handle); + return ret; + } + + rpc_port_parcel_write(parcel, &h->parcelable, h); + rpc_port_parcel_read(parcel, &handle->parcelable, handle); + ret = get_last_result(); + rpc_port_parcel_destroy(parcel); + + if (ret != RPC_PORT_ERROR_NONE) { + _E("Failed to read data. error(%d)", ret); + rpc_port_proxy_vc_feedback_cb_destroy(handle); + return ret; + } + + handle->callback = h->callback; + handle->user_data = h->user_data; + + *clone = handle; + + return RPC_PORT_ERROR_NONE; +} + +int rpc_port_proxy_vc_feedback_cb_set_callback(rpc_port_proxy_vc_feedback_cb_h h, rpc_port_proxy_vc_feedback_cb_cb callback, void *user_data) +{ + if (h == nullptr || callback == nullptr) { + _E("Invalid parameter"); + return RPC_PORT_ERROR_INVALID_PARAMETER; + } + + h->callback = callback; + h->user_data = user_data; + + return RPC_PORT_ERROR_NONE; +} + +int rpc_port_proxy_vc_feedback_cb_set_once(rpc_port_proxy_vc_feedback_cb_h h, bool once) +{ + if (h == nullptr) { + _E("Invalid parameter"); + return RPC_PORT_ERROR_INVALID_PARAMETER; + } + + h->once = once; + + return RPC_PORT_ERROR_NONE; +} + +int rpc_port_proxy_vc_feedback_cb_get_id(rpc_port_proxy_vc_feedback_cb_h h, int *id) +{ + if (h == nullptr || id == nullptr) { + _E("Invalid parameter"); + return RPC_PORT_ERROR_INVALID_PARAMETER; + } + + *id = h->id; + + return RPC_PORT_ERROR_NONE; +} + +int rpc_port_proxy_vc_feedback_cb_get_seq_id(rpc_port_proxy_vc_feedback_cb_h h, int *seq_id) +{ + if (h == nullptr || seq_id == nullptr) { + _E("Invalid parameter"); + return RPC_PORT_ERROR_INVALID_PARAMETER; + } + + *seq_id = h->seq_id; + + return RPC_PORT_ERROR_NONE; +} + +int rpc_port_proxy_vc_feedback_cb_is_once(rpc_port_proxy_vc_feedback_cb_h h, bool *once) +{ + if (h == nullptr || once == nullptr) { + _E("Invalid parameter"); + return RPC_PORT_ERROR_INVALID_PARAMETER; + } + + *once = h->once; + + return RPC_PORT_ERROR_NONE; +} + +int rpc_port_proxy_vc_feedback_cb_get_tag(rpc_port_proxy_vc_feedback_cb_h h, char **tag) +{ + char *new_tag; + char buf[128]; + + if (h == nullptr || tag == nullptr) { + _E("Invalid parameter"); + return RPC_PORT_ERROR_INVALID_PARAMETER; + } + + snprintf(buf, sizeof(buf), "%d::%d", h->id, h->seq_id); + new_tag = strdup(buf); + if (new_tag == nullptr) { + _E("Out of memory"); + return RPC_PORT_ERROR_OUT_OF_MEMORY; + } + + *tag = new_tag; + + return RPC_PORT_ERROR_NONE; +} + +int rpc_port_proxy_vc_feedback_cb_dispose(rpc_port_proxy_vc_h proxy, rpc_port_proxy_vc_feedback_cb_h h) +{ + GList *found; + + if (proxy == nullptr || h == nullptr) { + _E("Invalid parameter"); + return RPC_PORT_ERROR_INVALID_PARAMETER; + } + + found = g_list_find(proxy->delegates, h); + if (found == nullptr) { + _E("Invalid parameter"); + return RPC_PORT_ERROR_INVALID_PARAMETER; + } + + proxy->delegates = g_list_remove_link(proxy->delegates, found); + rpc_port_proxy_vc_feedback_cb_destroy(h); + g_list_free(found); + + return RPC_PORT_ERROR_NONE; +} + +static void __rpc_port_proxy_vc_feedback_cb_delegate_handler(GList **delegates, rpc_port_parcel_h parcel, int id, int seq_id) +{ + rpc_port_proxy_vc_feedback_cb_h handle; + GList *iter; + bool once; + int utt_id = -1; + int event = -1; + rpc_port_proxy_array_char_h pcm_data = nullptr; + int len = -1; + + rpc_port_parcel_read_int32(parcel, &utt_id); + + rpc_port_parcel_read_int32(parcel, &event); + + rpc_port_proxy_array_char_create(&pcm_data); + if (pcm_data == nullptr) { + _E("Failed to create handle"); + goto out; + } + + rpc_port_parcel_read(parcel, &pcm_data->parcelable, pcm_data); + if (get_last_result() != RPC_PORT_ERROR_NONE) { + _E("Failed to read data"); + goto out; + } + + rpc_port_parcel_read_int32(parcel, &len); + + iter = *delegates; + while (iter) { + handle = iter->data; + iter = g_list_next(iter); + if (handle->id == id && handle->seq_id == seq_id) { + once = handle->once; + _W("Invoke id(%d), seq_id(%d)", id, seq_id); + if (handle->callback) + handle->callback(handle->user_data, utt_id, event, pcm_data, len); + else + _W("The callback function is nullptr"); + + if (once) { + *delegates = g_list_remove(*delegates, handle); + rpc_port_proxy_vc_feedback_cb_destroy(handle); + } + + break; + } + } + +out: + + if (pcm_data) + rpc_port_proxy_array_char_destroy(pcm_data); +} + +static rpc_port_proxy_delegate_cb __rpc_port_proxy_vc_delegate_table[] = { + [RPC_PORT_PROXY_VC_DELEGATE_NOTIFY_CB] = __rpc_port_proxy_vc_notify_cb_delegate_handler, + [RPC_PORT_PROXY_VC_DELEGATE_FEEDBACK_CB] = __rpc_port_proxy_vc_feedback_cb_delegate_handler, +}; + +typedef enum { + RPC_PORT_PROXY_VC_METHOD_RESULT_, + RPC_PORT_PROXY_VC_METHOD_CALLBACK_, + RPC_PORT_PROXY_VC_METHOD_REGISTER_NOTIFY_CB, + RPC_PORT_PROXY_VC_METHOD_REGISTER_NOTIFY_CB_SYNC, + RPC_PORT_PROXY_VC_METHOD_REGISTER_FEEDBACK_CB, + RPC_PORT_PROXY_VC_METHOD_REGISTER_FEEDBACK_CB_SYNC, + RPC_PORT_PROXY_VC_METHOD_INITIALIZE, + RPC_PORT_PROXY_VC_METHOD_FINALIZE, + RPC_PORT_PROXY_VC_METHOD_SET_COMMAND, + RPC_PORT_PROXY_VC_METHOD_UNSET_COMMAND, + RPC_PORT_PROXY_VC_METHOD_SET_FOREGROUND, + RPC_PORT_PROXY_VC_METHOD_SET_SERVER_DIALOG, + RPC_PORT_PROXY_VC_METHOD_REQUEST_DIALOG, + RPC_PORT_PROXY_VC_METHOD_IS_SYSTEM_COMMAND_VALID, + RPC_PORT_PROXY_VC_METHOD_AUTH_ENABLE, + RPC_PORT_PROXY_VC_METHOD_AUTH_DISABLE, + RPC_PORT_PROXY_VC_METHOD_AUTH_START, + RPC_PORT_PROXY_VC_METHOD_AUTH_STOP, + RPC_PORT_PROXY_VC_METHOD_AUTH_CANCEL, + RPC_PORT_PROXY_VC_METHOD_REQUEST_TTS, + RPC_PORT_PROXY_VC_METHOD_CANCEL_TTS, + RPC_PORT_PROXY_VC_METHOD_GET_TTS_AUDIO_FORMAT, +} rpc_port_proxy_vc_method_e; + +static void __rpc_port_proxy_vc_process_received_event(GList **delegates, rpc_port_parcel_h parcel) +{ + int id = 0; + int seq_id = 0; + bool once = false; + + rpc_port_parcel_read_int32(parcel, &id); + rpc_port_parcel_read_int32(parcel, &seq_id); + rpc_port_parcel_read_bool(parcel, &once); + _W("id(%d), seq_id(%d)", id, seq_id); + + if (id > 0 && id < ARRAY_SIZE(__rpc_port_proxy_vc_delegate_table)) { + if (__rpc_port_proxy_vc_delegate_table[id]) + __rpc_port_proxy_vc_delegate_table[id](delegates, parcel, id, seq_id); + } else { + _W("Unknown ID(%d)", id); + } +} + +static void __rpc_port_proxy_vc_consume_command(rpc_port_h port, rpc_port_parcel_h *p) +{ + rpc_port_parcel_h parcel; + int cmd = -1; + int ret; + + do { + ret = rpc_port_parcel_create_from_port(&parcel, port); + if (ret != RPC_PORT_ERROR_NONE) + break; + + rpc_port_parcel_read_int32(parcel, &cmd); + if (cmd == RPC_PORT_PROXY_VC_METHOD_RESULT_) { + *p = parcel; + return; + } + + rpc_port_parcel_destroy(parcel); + } while (true); + + *p = nullptr; +} + +static void __rpc_port_proxy_vc_connected(const char *endpoint, const char *port_name, rpc_port_h port, void *data) +{ + rpc_port_proxy_vc_h h = data; + + _I("endpoint(%s), port_name(%s)", endpoint, port_name); + h->port = port; + rpc_port_proxy_get_port(h->proxy, RPC_PORT_PORT_CALLBACK, &h->callback_port); + h->callback.connected(h, h->user_data); +} + +static void __rpc_port_proxy_vc_disconnected(const char *endpoint, const char *port_name, void *data) +{ + rpc_port_proxy_vc_h h = data; + + _W("endpoint(%s), port_name(%s)", endpoint, port_name); + h->port = nullptr; + h->callback.disconnected(h, h->user_data); +} + +static void __rpc_port_proxy_vc_rejected(const char *endpoint, const char *port_name, void *data) +{ + rpc_port_proxy_vc_h h = data; + + _W("endpoint(%s), port_name(%s)", endpoint, port_name); + h->port = nullptr; + h->callback.rejected(h, h->user_data); +} + +static void __rpc_port_proxy_vc_received(const char *endpoint, const char *port_name, void *data) +{ + rpc_port_proxy_vc_h h = data; + rpc_port_parcel_h parcel; + int cmd = -1; + int ret; + + _W("endpoint(%s), port_name(%s)", endpoint, port_name); + ret = rpc_port_parcel_create_from_port(&parcel, h->callback_port); + if (ret != RPC_PORT_ERROR_NONE) { + _E("Failed to create parcel handle from port. error(%d)", ret); + return; + } + + rpc_port_parcel_read_int32(parcel, &cmd); + if (cmd != RPC_PORT_PROXY_VC_METHOD_CALLBACK_) { + _E("Invalid protocol"); + rpc_port_parcel_destroy(parcel); + return; + } + + __rpc_port_proxy_vc_process_received_event(&h->delegates, parcel); + rpc_port_parcel_destroy(parcel); +} + +int rpc_port_proxy_vc_create(const char *stub_appid, rpc_port_proxy_vc_callback_s *callback, void *user_data, rpc_port_proxy_vc_h *h) +{ + rpc_port_proxy_vc_t *handle; + int ret; + + if (stub_appid == nullptr || callback == nullptr || h == nullptr) { + _E("Invalid parameter"); + return RPC_PORT_ERROR_INVALID_PARAMETER; + } + + if (callback->connected == nullptr || callback->disconnected == nullptr || callback->rejected == nullptr) { + _E("Invalid parameter"); + return RPC_PORT_ERROR_INVALID_PARAMETER; + } + + handle = calloc(1, sizeof(rpc_port_proxy_vc_t)); + if (handle == nullptr) { + _E("Out of memory"); + return RPC_PORT_ERROR_OUT_OF_MEMORY; + } + + g_rec_mutex_init(&handle->mutex); + + handle->stub_appid = strdup(stub_appid); + if (handle->stub_appid == nullptr) { + _E("Failed to duplicate stub appid"); + rpc_port_proxy_vc_destroy(handle); + return RPC_PORT_ERROR_OUT_OF_MEMORY; + } + + ret = rpc_port_proxy_create(&handle->proxy); + if (ret != RPC_PORT_ERROR_NONE) { + _E("Failed to create proxy handle. error(%d)", ret); + rpc_port_proxy_vc_destroy(handle); + return ret; + } + + handle->callback = *callback; + handle->user_data = user_data; + + ret = rpc_port_proxy_add_connected_event_cb(handle->proxy, __rpc_port_proxy_vc_connected, handle); + if (ret != RPC_PORT_ERROR_NONE) { + _E("Failed to add connected event cb. error(%d)", ret); + rpc_port_proxy_vc_destroy(handle); + return ret; + } + + ret = rpc_port_proxy_add_disconnected_event_cb(handle->proxy, __rpc_port_proxy_vc_disconnected, handle); + if (ret != RPC_PORT_ERROR_NONE) { + _E("Failed to add disconnected event cb. error(%d)", ret); + rpc_port_proxy_vc_destroy(handle); + return ret; + } + + ret = rpc_port_proxy_add_rejected_event_cb(handle->proxy, __rpc_port_proxy_vc_rejected, handle); + if (ret != RPC_PORT_ERROR_NONE) { + _E("Failed to add rejected event cb. error(%d)", ret); + rpc_port_proxy_vc_destroy(handle); + return ret; + } + + ret = rpc_port_proxy_add_received_event_cb(handle->proxy, __rpc_port_proxy_vc_received, handle); + if (ret != RPC_PORT_ERROR_NONE) { + _E("Failed to add received event cb. error(%d)", ret); + rpc_port_proxy_vc_destroy(handle); + return ret; + } + + *h = handle; + + return RPC_PORT_ERROR_NONE; +} + +int rpc_port_proxy_vc_destroy(rpc_port_proxy_vc_h h) +{ + if (h == nullptr) { + _E("Invalid parameter"); + return RPC_PORT_ERROR_INVALID_PARAMETER; + } + + g_rec_mutex_lock(&h->mutex); + g_rec_mutex_unlock(&h->mutex); + g_rec_mutex_clear(&h->mutex); + + if (h->delegates) + g_list_free_full(h->delegates, free); + + if (h->proxy) + rpc_port_proxy_destroy(h->proxy); + + if (h->stub_appid) + free(h->stub_appid); + + free(h); + + return RPC_PORT_ERROR_NONE; +} + +int rpc_port_proxy_vc_connect(rpc_port_proxy_vc_h h) +{ + int ret; + + if (h == nullptr || h->proxy == nullptr) { + _E("Invalid parameter"); + return RPC_PORT_ERROR_INVALID_PARAMETER; + } + + ret = rpc_port_proxy_connect(h->proxy, h->stub_appid, "vc"); + if (ret != RPC_PORT_ERROR_NONE) { + _E("Failed to connect to stub. error(%d)", ret); + return ret; + } + + return RPC_PORT_ERROR_NONE; +} + +int rpc_port_proxy_vc_connect_sync(rpc_port_proxy_vc_h h) +{ + int ret; + + if (h == nullptr || h->proxy == nullptr) { + _E("Invalid parameter"); + return RPC_PORT_ERROR_INVALID_PARAMETER; + } + + ret = rpc_port_proxy_connect_sync(h->proxy, h->stub_appid, "vc"); + if (ret != RPC_PORT_ERROR_NONE) { + _E("Failed to connect to stub. error(%d)", ret); + return ret; + } + + return RPC_PORT_ERROR_NONE; +} + +int rpc_port_proxy_vc_disconnect(rpc_port_proxy_vc_h h) +{ + int ret; + + if (h == nullptr || h->proxy == nullptr) { + _E("Invalid parameter"); + return RPC_PORT_ERROR_INVALID_PARAMETER; + } + + ret = rpc_port_disconnect(h->port); + if (ret != RPC_PORT_ERROR_NONE) { + _E("Failed to disconnect from stub. error(%d)", ret); + return ret; + } + + return RPC_PORT_ERROR_NONE; +} + +void rpc_port_proxy_vc_invoke_register_notify_cb(rpc_port_proxy_vc_h h, int pid, rpc_port_proxy_vc_notify_cb_h callback) +{ + rpc_port_parcel_h parcel_; + rpc_port_parcel_header_h header_; + int seq_num_ = -1; + int res_; + + if (h == nullptr || callback == nullptr) { + _E("Invalid parameter"); + set_last_result(RPC_PORT_ERROR_INVALID_PARAMETER); + return; + } + + g_rec_mutex_lock(&h->mutex); + if (h->port == nullptr) { + _E("Not connected"); + g_rec_mutex_unlock(&h->mutex); + set_last_result(RPC_PORT_ERROR_INVALID_PARAMETER); + return; + } + + res_ = rpc_port_parcel_create(&parcel_); + if (res_ != RPC_PORT_ERROR_NONE) { + _E("Failed to create parcel handle. error(%d)", res_); + g_rec_mutex_unlock(&h->mutex); + set_last_result(res_); + return; + } + + rpc_port_parcel_get_header(parcel_, &header_); + rpc_port_parcel_header_set_tag(header_, TIDL_VERSION); + rpc_port_parcel_header_get_seq_num(header_, &seq_num_); + _W("[Version] \"%s\", [Sequence] %d", TIDL_VERSION, seq_num_); + + rpc_port_parcel_write_int32(parcel_, RPC_PORT_PROXY_VC_METHOD_REGISTER_NOTIFY_CB); + + rpc_port_parcel_write_int32(parcel_, pid); + + rpc_port_parcel_write(parcel_, &callback->parcelable, callback); + + h->delegates = g_list_append(h->delegates, callback); + + res_ = rpc_port_parcel_send(parcel_, h->port); + rpc_port_parcel_destroy(parcel_); + if (res_ != RPC_PORT_ERROR_NONE) + _E("Failed to send parcel. error(%d)", res_); + + g_rec_mutex_unlock(&h->mutex); + set_last_result(res_); +} + +int rpc_port_proxy_vc_invoke_register_notify_cb_sync(rpc_port_proxy_vc_h h, int pid, rpc_port_proxy_vc_notify_cb_h callback) +{ + rpc_port_parcel_h parcel_; + rpc_port_parcel_header_h header_; + int seq_num_ = -1; + int recv_seq_num_ = -1; + char *tag_ = nullptr; + bool done_ = false; + int res_; + int ret_ = -1; + + if (h == nullptr || callback == nullptr) { + _E("Invalid parameter"); + set_last_result(RPC_PORT_ERROR_INVALID_PARAMETER); + return ret_; + } + + g_rec_mutex_lock(&h->mutex); + if (h->port == nullptr) { + _E("Not connected"); + set_last_result(RPC_PORT_ERROR_INVALID_PARAMETER); + g_rec_mutex_unlock(&h->mutex); + return ret_; + } + + res_ = rpc_port_parcel_create(&parcel_); + if (res_ != RPC_PORT_ERROR_NONE) { + _E("Failed to create parcel handle. error(%d)", res_); + set_last_result(res_); + g_rec_mutex_unlock(&h->mutex); + return ret_; + } + + rpc_port_parcel_get_header(parcel_, &header_); + rpc_port_parcel_header_set_tag(header_, TIDL_VERSION); + rpc_port_parcel_header_get_seq_num(header_, &seq_num_); + _W("[Version] \"%s\", [Sequence] %d", TIDL_VERSION, seq_num_); + + rpc_port_parcel_write_int32(parcel_, RPC_PORT_PROXY_VC_METHOD_REGISTER_NOTIFY_CB_SYNC); + + rpc_port_parcel_write_int32(parcel_, pid); + + rpc_port_parcel_write(parcel_, &callback->parcelable, callback); + + h->delegates = g_list_append(h->delegates, callback); + + res_ = rpc_port_parcel_send(parcel_, h->port); + rpc_port_parcel_destroy(parcel_); + if (res_ != RPC_PORT_ERROR_NONE) { + _E("Failed to send parcel. error(%d)", res_); + set_last_result(res_); + g_rec_mutex_unlock(&h->mutex); + return ret_; + } + + do { + parcel_ = nullptr; + __rpc_port_proxy_vc_consume_command(h->port, &parcel_); + if (parcel_ == nullptr) { + _E("Invalid protocol"); + res_ = RPC_PORT_ERROR_IO_ERROR; + break; + } + + header_ = nullptr; + rpc_port_parcel_get_header(parcel_, &header_); + tag_ = nullptr; + rpc_port_parcel_header_get_tag(header_, &tag_); + if (tag_ && tag_[0] != '\0') { + _W("[Version] %s", tag_); + rpc_port_parcel_header_get_seq_num(header_, &recv_seq_num_); + if (recv_seq_num_ != seq_num_) { + _E("Invalid protocol. %d", recv_seq_num_); + free(tag_); + rpc_port_parcel_destroy(parcel_); + continue; + } + } + done_ = true; + free(tag_); + + rpc_port_parcel_read_int32(parcel_, &ret_); + + rpc_port_parcel_destroy(parcel_); + } while (!done_); + g_rec_mutex_unlock(&h->mutex); + set_last_result(res_); + + return ret_; +} + +void rpc_port_proxy_vc_invoke_register_feedback_cb(rpc_port_proxy_vc_h h, int pid, rpc_port_proxy_vc_feedback_cb_h callback) +{ + rpc_port_parcel_h parcel_; + rpc_port_parcel_header_h header_; + int seq_num_ = -1; + int res_; + + if (h == nullptr || callback == nullptr) { + _E("Invalid parameter"); + set_last_result(RPC_PORT_ERROR_INVALID_PARAMETER); + return; + } + + g_rec_mutex_lock(&h->mutex); + if (h->port == nullptr) { + _E("Not connected"); + g_rec_mutex_unlock(&h->mutex); + set_last_result(RPC_PORT_ERROR_INVALID_PARAMETER); + return; + } + + res_ = rpc_port_parcel_create(&parcel_); + if (res_ != RPC_PORT_ERROR_NONE) { + _E("Failed to create parcel handle. error(%d)", res_); + g_rec_mutex_unlock(&h->mutex); + set_last_result(res_); + return; + } + + rpc_port_parcel_get_header(parcel_, &header_); + rpc_port_parcel_header_set_tag(header_, TIDL_VERSION); + rpc_port_parcel_header_get_seq_num(header_, &seq_num_); + _W("[Version] \"%s\", [Sequence] %d", TIDL_VERSION, seq_num_); + + rpc_port_parcel_write_int32(parcel_, RPC_PORT_PROXY_VC_METHOD_REGISTER_FEEDBACK_CB); + + rpc_port_parcel_write_int32(parcel_, pid); + + rpc_port_parcel_write(parcel_, &callback->parcelable, callback); + + h->delegates = g_list_append(h->delegates, callback); + + res_ = rpc_port_parcel_send(parcel_, h->port); + rpc_port_parcel_destroy(parcel_); + if (res_ != RPC_PORT_ERROR_NONE) + _E("Failed to send parcel. error(%d)", res_); + + g_rec_mutex_unlock(&h->mutex); + set_last_result(res_); +} + +int rpc_port_proxy_vc_invoke_register_feedback_cb_sync(rpc_port_proxy_vc_h h, int pid, rpc_port_proxy_vc_feedback_cb_h callback) +{ + rpc_port_parcel_h parcel_; + rpc_port_parcel_header_h header_; + int seq_num_ = -1; + int recv_seq_num_ = -1; + char *tag_ = nullptr; + bool done_ = false; + int res_; + int ret_ = -1; + + if (h == nullptr || callback == nullptr) { + _E("Invalid parameter"); + set_last_result(RPC_PORT_ERROR_INVALID_PARAMETER); + return ret_; + } + + g_rec_mutex_lock(&h->mutex); + if (h->port == nullptr) { + _E("Not connected"); + set_last_result(RPC_PORT_ERROR_INVALID_PARAMETER); + g_rec_mutex_unlock(&h->mutex); + return ret_; + } + + res_ = rpc_port_parcel_create(&parcel_); + if (res_ != RPC_PORT_ERROR_NONE) { + _E("Failed to create parcel handle. error(%d)", res_); + set_last_result(res_); + g_rec_mutex_unlock(&h->mutex); + return ret_; + } + + rpc_port_parcel_get_header(parcel_, &header_); + rpc_port_parcel_header_set_tag(header_, TIDL_VERSION); + rpc_port_parcel_header_get_seq_num(header_, &seq_num_); + _W("[Version] \"%s\", [Sequence] %d", TIDL_VERSION, seq_num_); + + rpc_port_parcel_write_int32(parcel_, RPC_PORT_PROXY_VC_METHOD_REGISTER_FEEDBACK_CB_SYNC); + + rpc_port_parcel_write_int32(parcel_, pid); + + rpc_port_parcel_write(parcel_, &callback->parcelable, callback); + + h->delegates = g_list_append(h->delegates, callback); + + res_ = rpc_port_parcel_send(parcel_, h->port); + rpc_port_parcel_destroy(parcel_); + if (res_ != RPC_PORT_ERROR_NONE) { + _E("Failed to send parcel. error(%d)", res_); + set_last_result(res_); + g_rec_mutex_unlock(&h->mutex); + return ret_; + } + + do { + parcel_ = nullptr; + __rpc_port_proxy_vc_consume_command(h->port, &parcel_); + if (parcel_ == nullptr) { + _E("Invalid protocol"); + res_ = RPC_PORT_ERROR_IO_ERROR; + break; + } + + header_ = nullptr; + rpc_port_parcel_get_header(parcel_, &header_); + tag_ = nullptr; + rpc_port_parcel_header_get_tag(header_, &tag_); + if (tag_ && tag_[0] != '\0') { + _W("[Version] %s", tag_); + rpc_port_parcel_header_get_seq_num(header_, &recv_seq_num_); + if (recv_seq_num_ != seq_num_) { + _E("Invalid protocol. %d", recv_seq_num_); + free(tag_); + rpc_port_parcel_destroy(parcel_); + continue; + } + } + done_ = true; + free(tag_); + + rpc_port_parcel_read_int32(parcel_, &ret_); + + rpc_port_parcel_destroy(parcel_); + } while (!done_); + g_rec_mutex_unlock(&h->mutex); + set_last_result(res_); + + return ret_; +} + +int rpc_port_proxy_vc_invoke_initialize(rpc_port_proxy_vc_h h, int pid, int *mgr_pid, int *service_state, int *daemon_pid) +{ + rpc_port_parcel_h parcel_; + rpc_port_parcel_header_h header_; + int seq_num_ = -1; + int recv_seq_num_ = -1; + char *tag_ = nullptr; + bool done_ = false; + int res_; + int ret_ = -1; + int new_mgr_pid; + int new_service_state; + int new_daemon_pid; + + if (h == nullptr) { + _E("Invalid parameter"); + set_last_result(RPC_PORT_ERROR_INVALID_PARAMETER); + return ret_; + } + + g_rec_mutex_lock(&h->mutex); + if (h->port == nullptr) { + _E("Not connected"); + set_last_result(RPC_PORT_ERROR_INVALID_PARAMETER); + g_rec_mutex_unlock(&h->mutex); + return ret_; + } + + res_ = rpc_port_parcel_create(&parcel_); + if (res_ != RPC_PORT_ERROR_NONE) { + _E("Failed to create parcel handle. error(%d)", res_); + set_last_result(res_); + g_rec_mutex_unlock(&h->mutex); + return ret_; + } + + rpc_port_parcel_get_header(parcel_, &header_); + rpc_port_parcel_header_set_tag(header_, TIDL_VERSION); + rpc_port_parcel_header_get_seq_num(header_, &seq_num_); + _W("[Version] \"%s\", [Sequence] %d", TIDL_VERSION, seq_num_); + + rpc_port_parcel_write_int32(parcel_, RPC_PORT_PROXY_VC_METHOD_INITIALIZE); + + rpc_port_parcel_write_int32(parcel_, pid); + + res_ = rpc_port_parcel_send(parcel_, h->port); + rpc_port_parcel_destroy(parcel_); + if (res_ != RPC_PORT_ERROR_NONE) { + _E("Failed to send parcel. error(%d)", res_); + set_last_result(res_); + g_rec_mutex_unlock(&h->mutex); + return ret_; + } + + do { + parcel_ = nullptr; + __rpc_port_proxy_vc_consume_command(h->port, &parcel_); + if (parcel_ == nullptr) { + _E("Invalid protocol"); + res_ = RPC_PORT_ERROR_IO_ERROR; + break; + } + + header_ = nullptr; + rpc_port_parcel_get_header(parcel_, &header_); + tag_ = nullptr; + rpc_port_parcel_header_get_tag(header_, &tag_); + if (tag_ && tag_[0] != '\0') { + _W("[Version] %s", tag_); + rpc_port_parcel_header_get_seq_num(header_, &recv_seq_num_); + if (recv_seq_num_ != seq_num_) { + _E("Invalid protocol. %d", recv_seq_num_); + free(tag_); + rpc_port_parcel_destroy(parcel_); + continue; + } + } + done_ = true; + free(tag_); + + rpc_port_parcel_read_int32(parcel_, &new_mgr_pid); + + *mgr_pid = new_mgr_pid; + + rpc_port_parcel_read_int32(parcel_, &new_service_state); + + *service_state = new_service_state; + + rpc_port_parcel_read_int32(parcel_, &new_daemon_pid); + + *daemon_pid = new_daemon_pid; + + rpc_port_parcel_read_int32(parcel_, &ret_); + + rpc_port_parcel_destroy(parcel_); + } while (!done_); + g_rec_mutex_unlock(&h->mutex); + set_last_result(res_); + + return ret_; +} + +int rpc_port_proxy_vc_invoke_finalize(rpc_port_proxy_vc_h h, int pid) +{ + rpc_port_parcel_h parcel_; + rpc_port_parcel_header_h header_; + int seq_num_ = -1; + int recv_seq_num_ = -1; + char *tag_ = nullptr; + bool done_ = false; + int res_; + int ret_ = -1; + + if (h == nullptr) { + _E("Invalid parameter"); + set_last_result(RPC_PORT_ERROR_INVALID_PARAMETER); + return ret_; + } + + g_rec_mutex_lock(&h->mutex); + if (h->port == nullptr) { + _E("Not connected"); + set_last_result(RPC_PORT_ERROR_INVALID_PARAMETER); + g_rec_mutex_unlock(&h->mutex); + return ret_; + } + + res_ = rpc_port_parcel_create(&parcel_); + if (res_ != RPC_PORT_ERROR_NONE) { + _E("Failed to create parcel handle. error(%d)", res_); + set_last_result(res_); + g_rec_mutex_unlock(&h->mutex); + return ret_; + } + + rpc_port_parcel_get_header(parcel_, &header_); + rpc_port_parcel_header_set_tag(header_, TIDL_VERSION); + rpc_port_parcel_header_get_seq_num(header_, &seq_num_); + _W("[Version] \"%s\", [Sequence] %d", TIDL_VERSION, seq_num_); + + rpc_port_parcel_write_int32(parcel_, RPC_PORT_PROXY_VC_METHOD_FINALIZE); + + rpc_port_parcel_write_int32(parcel_, pid); + + res_ = rpc_port_parcel_send(parcel_, h->port); + rpc_port_parcel_destroy(parcel_); + if (res_ != RPC_PORT_ERROR_NONE) { + _E("Failed to send parcel. error(%d)", res_); + set_last_result(res_); + g_rec_mutex_unlock(&h->mutex); + return ret_; + } + + do { + parcel_ = nullptr; + __rpc_port_proxy_vc_consume_command(h->port, &parcel_); + if (parcel_ == nullptr) { + _E("Invalid protocol"); + res_ = RPC_PORT_ERROR_IO_ERROR; + break; + } + + header_ = nullptr; + rpc_port_parcel_get_header(parcel_, &header_); + tag_ = nullptr; + rpc_port_parcel_header_get_tag(header_, &tag_); + if (tag_ && tag_[0] != '\0') { + _W("[Version] %s", tag_); + rpc_port_parcel_header_get_seq_num(header_, &recv_seq_num_); + if (recv_seq_num_ != seq_num_) { + _E("Invalid protocol. %d", recv_seq_num_); + free(tag_); + rpc_port_parcel_destroy(parcel_); + continue; + } + } + done_ = true; + free(tag_); + + rpc_port_parcel_read_int32(parcel_, &ret_); + + rpc_port_parcel_destroy(parcel_); + } while (!done_); + g_rec_mutex_unlock(&h->mutex); + set_last_result(res_); + + return ret_; +} + +int rpc_port_proxy_vc_invoke_set_command(rpc_port_proxy_vc_h h, int pid, int cmd_type) +{ + rpc_port_parcel_h parcel_; + rpc_port_parcel_header_h header_; + int seq_num_ = -1; + int recv_seq_num_ = -1; + char *tag_ = nullptr; + bool done_ = false; + int res_; + int ret_ = -1; + + if (h == nullptr) { + _E("Invalid parameter"); + set_last_result(RPC_PORT_ERROR_INVALID_PARAMETER); + return ret_; + } + + g_rec_mutex_lock(&h->mutex); + if (h->port == nullptr) { + _E("Not connected"); + set_last_result(RPC_PORT_ERROR_INVALID_PARAMETER); + g_rec_mutex_unlock(&h->mutex); + return ret_; + } + + res_ = rpc_port_parcel_create(&parcel_); + if (res_ != RPC_PORT_ERROR_NONE) { + _E("Failed to create parcel handle. error(%d)", res_); + set_last_result(res_); + g_rec_mutex_unlock(&h->mutex); + return ret_; + } + + rpc_port_parcel_get_header(parcel_, &header_); + rpc_port_parcel_header_set_tag(header_, TIDL_VERSION); + rpc_port_parcel_header_get_seq_num(header_, &seq_num_); + _W("[Version] \"%s\", [Sequence] %d", TIDL_VERSION, seq_num_); + + rpc_port_parcel_write_int32(parcel_, RPC_PORT_PROXY_VC_METHOD_SET_COMMAND); + + rpc_port_parcel_write_int32(parcel_, pid); + + rpc_port_parcel_write_int32(parcel_, cmd_type); + + res_ = rpc_port_parcel_send(parcel_, h->port); + rpc_port_parcel_destroy(parcel_); + if (res_ != RPC_PORT_ERROR_NONE) { + _E("Failed to send parcel. error(%d)", res_); + set_last_result(res_); + g_rec_mutex_unlock(&h->mutex); + return ret_; + } + + do { + parcel_ = nullptr; + __rpc_port_proxy_vc_consume_command(h->port, &parcel_); + if (parcel_ == nullptr) { + _E("Invalid protocol"); + res_ = RPC_PORT_ERROR_IO_ERROR; + break; + } + + header_ = nullptr; + rpc_port_parcel_get_header(parcel_, &header_); + tag_ = nullptr; + rpc_port_parcel_header_get_tag(header_, &tag_); + if (tag_ && tag_[0] != '\0') { + _W("[Version] %s", tag_); + rpc_port_parcel_header_get_seq_num(header_, &recv_seq_num_); + if (recv_seq_num_ != seq_num_) { + _E("Invalid protocol. %d", recv_seq_num_); + free(tag_); + rpc_port_parcel_destroy(parcel_); + continue; + } + } + done_ = true; + free(tag_); + + rpc_port_parcel_read_int32(parcel_, &ret_); + + rpc_port_parcel_destroy(parcel_); + } while (!done_); + g_rec_mutex_unlock(&h->mutex); + set_last_result(res_); + + return ret_; +} + +int rpc_port_proxy_vc_invoke_unset_command(rpc_port_proxy_vc_h h, int pid, int cmd_type) +{ + rpc_port_parcel_h parcel_; + rpc_port_parcel_header_h header_; + int seq_num_ = -1; + int recv_seq_num_ = -1; + char *tag_ = nullptr; + bool done_ = false; + int res_; + int ret_ = -1; + + if (h == nullptr) { + _E("Invalid parameter"); + set_last_result(RPC_PORT_ERROR_INVALID_PARAMETER); + return ret_; + } + + g_rec_mutex_lock(&h->mutex); + if (h->port == nullptr) { + _E("Not connected"); + set_last_result(RPC_PORT_ERROR_INVALID_PARAMETER); + g_rec_mutex_unlock(&h->mutex); + return ret_; + } + + res_ = rpc_port_parcel_create(&parcel_); + if (res_ != RPC_PORT_ERROR_NONE) { + _E("Failed to create parcel handle. error(%d)", res_); + set_last_result(res_); + g_rec_mutex_unlock(&h->mutex); + return ret_; + } + + rpc_port_parcel_get_header(parcel_, &header_); + rpc_port_parcel_header_set_tag(header_, TIDL_VERSION); + rpc_port_parcel_header_get_seq_num(header_, &seq_num_); + _W("[Version] \"%s\", [Sequence] %d", TIDL_VERSION, seq_num_); + + rpc_port_parcel_write_int32(parcel_, RPC_PORT_PROXY_VC_METHOD_UNSET_COMMAND); + + rpc_port_parcel_write_int32(parcel_, pid); + + rpc_port_parcel_write_int32(parcel_, cmd_type); + + res_ = rpc_port_parcel_send(parcel_, h->port); + rpc_port_parcel_destroy(parcel_); + if (res_ != RPC_PORT_ERROR_NONE) { + _E("Failed to send parcel. error(%d)", res_); + set_last_result(res_); + g_rec_mutex_unlock(&h->mutex); + return ret_; + } + + do { + parcel_ = nullptr; + __rpc_port_proxy_vc_consume_command(h->port, &parcel_); + if (parcel_ == nullptr) { + _E("Invalid protocol"); + res_ = RPC_PORT_ERROR_IO_ERROR; + break; + } + + header_ = nullptr; + rpc_port_parcel_get_header(parcel_, &header_); + tag_ = nullptr; + rpc_port_parcel_header_get_tag(header_, &tag_); + if (tag_ && tag_[0] != '\0') { + _W("[Version] %s", tag_); + rpc_port_parcel_header_get_seq_num(header_, &recv_seq_num_); + if (recv_seq_num_ != seq_num_) { + _E("Invalid protocol. %d", recv_seq_num_); + free(tag_); + rpc_port_parcel_destroy(parcel_); + continue; + } + } + done_ = true; + free(tag_); + + rpc_port_parcel_read_int32(parcel_, &ret_); + + rpc_port_parcel_destroy(parcel_); + } while (!done_); + g_rec_mutex_unlock(&h->mutex); + set_last_result(res_); + + return ret_; +} + +int rpc_port_proxy_vc_invoke_set_foreground(rpc_port_proxy_vc_h h, int pid, bool value) +{ + rpc_port_parcel_h parcel_; + rpc_port_parcel_header_h header_; + int seq_num_ = -1; + int recv_seq_num_ = -1; + char *tag_ = nullptr; + bool done_ = false; + int res_; + int ret_ = -1; + + if (h == nullptr) { + _E("Invalid parameter"); + set_last_result(RPC_PORT_ERROR_INVALID_PARAMETER); + return ret_; + } + + g_rec_mutex_lock(&h->mutex); + if (h->port == nullptr) { + _E("Not connected"); + set_last_result(RPC_PORT_ERROR_INVALID_PARAMETER); + g_rec_mutex_unlock(&h->mutex); + return ret_; + } + + res_ = rpc_port_parcel_create(&parcel_); + if (res_ != RPC_PORT_ERROR_NONE) { + _E("Failed to create parcel handle. error(%d)", res_); + set_last_result(res_); + g_rec_mutex_unlock(&h->mutex); + return ret_; + } + + rpc_port_parcel_get_header(parcel_, &header_); + rpc_port_parcel_header_set_tag(header_, TIDL_VERSION); + rpc_port_parcel_header_get_seq_num(header_, &seq_num_); + _W("[Version] \"%s\", [Sequence] %d", TIDL_VERSION, seq_num_); + + rpc_port_parcel_write_int32(parcel_, RPC_PORT_PROXY_VC_METHOD_SET_FOREGROUND); + + rpc_port_parcel_write_int32(parcel_, pid); + + rpc_port_parcel_write_bool(parcel_, value); + + res_ = rpc_port_parcel_send(parcel_, h->port); + rpc_port_parcel_destroy(parcel_); + if (res_ != RPC_PORT_ERROR_NONE) { + _E("Failed to send parcel. error(%d)", res_); + set_last_result(res_); + g_rec_mutex_unlock(&h->mutex); + return ret_; + } + + do { + parcel_ = nullptr; + __rpc_port_proxy_vc_consume_command(h->port, &parcel_); + if (parcel_ == nullptr) { + _E("Invalid protocol"); + res_ = RPC_PORT_ERROR_IO_ERROR; + break; + } + + header_ = nullptr; + rpc_port_parcel_get_header(parcel_, &header_); + tag_ = nullptr; + rpc_port_parcel_header_get_tag(header_, &tag_); + if (tag_ && tag_[0] != '\0') { + _W("[Version] %s", tag_); + rpc_port_parcel_header_get_seq_num(header_, &recv_seq_num_); + if (recv_seq_num_ != seq_num_) { + _E("Invalid protocol. %d", recv_seq_num_); + free(tag_); + rpc_port_parcel_destroy(parcel_); + continue; + } + } + done_ = true; + free(tag_); + + rpc_port_parcel_read_int32(parcel_, &ret_); + + rpc_port_parcel_destroy(parcel_); + } while (!done_); + g_rec_mutex_unlock(&h->mutex); + set_last_result(res_); + + return ret_; +} + +int rpc_port_proxy_vc_invoke_set_server_dialog(rpc_port_proxy_vc_h h, int pid, const char *app_id, const char *credential) +{ + rpc_port_parcel_h parcel_; + rpc_port_parcel_header_h header_; + int seq_num_ = -1; + int recv_seq_num_ = -1; + char *tag_ = nullptr; + bool done_ = false; + int res_; + int ret_ = -1; + + if (h == nullptr || app_id == nullptr || credential == nullptr) { + _E("Invalid parameter"); + set_last_result(RPC_PORT_ERROR_INVALID_PARAMETER); + return ret_; + } + + g_rec_mutex_lock(&h->mutex); + if (h->port == nullptr) { + _E("Not connected"); + set_last_result(RPC_PORT_ERROR_INVALID_PARAMETER); + g_rec_mutex_unlock(&h->mutex); + return ret_; + } + + res_ = rpc_port_parcel_create(&parcel_); + if (res_ != RPC_PORT_ERROR_NONE) { + _E("Failed to create parcel handle. error(%d)", res_); + set_last_result(res_); + g_rec_mutex_unlock(&h->mutex); + return ret_; + } + + rpc_port_parcel_get_header(parcel_, &header_); + rpc_port_parcel_header_set_tag(header_, TIDL_VERSION); + rpc_port_parcel_header_get_seq_num(header_, &seq_num_); + _W("[Version] \"%s\", [Sequence] %d", TIDL_VERSION, seq_num_); + + rpc_port_parcel_write_int32(parcel_, RPC_PORT_PROXY_VC_METHOD_SET_SERVER_DIALOG); + + rpc_port_parcel_write_int32(parcel_, pid); + + rpc_port_parcel_write_string(parcel_, app_id); + + rpc_port_parcel_write_string(parcel_, credential); + + res_ = rpc_port_parcel_send(parcel_, h->port); + rpc_port_parcel_destroy(parcel_); + if (res_ != RPC_PORT_ERROR_NONE) { + _E("Failed to send parcel. error(%d)", res_); + set_last_result(res_); + g_rec_mutex_unlock(&h->mutex); + return ret_; + } + + do { + parcel_ = nullptr; + __rpc_port_proxy_vc_consume_command(h->port, &parcel_); + if (parcel_ == nullptr) { + _E("Invalid protocol"); + res_ = RPC_PORT_ERROR_IO_ERROR; + break; + } + + header_ = nullptr; + rpc_port_parcel_get_header(parcel_, &header_); + tag_ = nullptr; + rpc_port_parcel_header_get_tag(header_, &tag_); + if (tag_ && tag_[0] != '\0') { + _W("[Version] %s", tag_); + rpc_port_parcel_header_get_seq_num(header_, &recv_seq_num_); + if (recv_seq_num_ != seq_num_) { + _E("Invalid protocol. %d", recv_seq_num_); + free(tag_); + rpc_port_parcel_destroy(parcel_); + continue; + } + } + done_ = true; + free(tag_); + + rpc_port_parcel_read_int32(parcel_, &ret_); + + rpc_port_parcel_destroy(parcel_); + } while (!done_); + g_rec_mutex_unlock(&h->mutex); + set_last_result(res_); + + return ret_; +} + +int rpc_port_proxy_vc_invoke_request_dialog(rpc_port_proxy_vc_h h, int pid, const char *disp_text, const char *utt_text, bool continuous) +{ + rpc_port_parcel_h parcel_; + rpc_port_parcel_header_h header_; + int seq_num_ = -1; + int recv_seq_num_ = -1; + char *tag_ = nullptr; + bool done_ = false; + int res_; + int ret_ = -1; + + if (h == nullptr || disp_text == nullptr || utt_text == nullptr) { + _E("Invalid parameter"); + set_last_result(RPC_PORT_ERROR_INVALID_PARAMETER); + return ret_; + } + + g_rec_mutex_lock(&h->mutex); + if (h->port == nullptr) { + _E("Not connected"); + set_last_result(RPC_PORT_ERROR_INVALID_PARAMETER); + g_rec_mutex_unlock(&h->mutex); + return ret_; + } + + res_ = rpc_port_parcel_create(&parcel_); + if (res_ != RPC_PORT_ERROR_NONE) { + _E("Failed to create parcel handle. error(%d)", res_); + set_last_result(res_); + g_rec_mutex_unlock(&h->mutex); + return ret_; + } + + rpc_port_parcel_get_header(parcel_, &header_); + rpc_port_parcel_header_set_tag(header_, TIDL_VERSION); + rpc_port_parcel_header_get_seq_num(header_, &seq_num_); + _W("[Version] \"%s\", [Sequence] %d", TIDL_VERSION, seq_num_); + + rpc_port_parcel_write_int32(parcel_, RPC_PORT_PROXY_VC_METHOD_REQUEST_DIALOG); + + rpc_port_parcel_write_int32(parcel_, pid); + + rpc_port_parcel_write_string(parcel_, disp_text); + + rpc_port_parcel_write_string(parcel_, utt_text); + + rpc_port_parcel_write_bool(parcel_, continuous); + + res_ = rpc_port_parcel_send(parcel_, h->port); + rpc_port_parcel_destroy(parcel_); + if (res_ != RPC_PORT_ERROR_NONE) { + _E("Failed to send parcel. error(%d)", res_); + set_last_result(res_); + g_rec_mutex_unlock(&h->mutex); + return ret_; + } + + do { + parcel_ = nullptr; + __rpc_port_proxy_vc_consume_command(h->port, &parcel_); + if (parcel_ == nullptr) { + _E("Invalid protocol"); + res_ = RPC_PORT_ERROR_IO_ERROR; + break; + } + + header_ = nullptr; + rpc_port_parcel_get_header(parcel_, &header_); + tag_ = nullptr; + rpc_port_parcel_header_get_tag(header_, &tag_); + if (tag_ && tag_[0] != '\0') { + _W("[Version] %s", tag_); + rpc_port_parcel_header_get_seq_num(header_, &recv_seq_num_); + if (recv_seq_num_ != seq_num_) { + _E("Invalid protocol. %d", recv_seq_num_); + free(tag_); + rpc_port_parcel_destroy(parcel_); + continue; + } + } + done_ = true; + free(tag_); + + rpc_port_parcel_read_int32(parcel_, &ret_); + + rpc_port_parcel_destroy(parcel_); + } while (!done_); + g_rec_mutex_unlock(&h->mutex); + set_last_result(res_); + + return ret_; +} + +int rpc_port_proxy_vc_invoke_is_system_command_valid(rpc_port_proxy_vc_h h, int pid, bool *is_sys_cmd_valid) +{ + rpc_port_parcel_h parcel_; + rpc_port_parcel_header_h header_; + int seq_num_ = -1; + int recv_seq_num_ = -1; + char *tag_ = nullptr; + bool done_ = false; + int res_; + int ret_ = -1; + bool new_is_sys_cmd_valid; + + if (h == nullptr) { + _E("Invalid parameter"); + set_last_result(RPC_PORT_ERROR_INVALID_PARAMETER); + return ret_; + } + + g_rec_mutex_lock(&h->mutex); + if (h->port == nullptr) { + _E("Not connected"); + set_last_result(RPC_PORT_ERROR_INVALID_PARAMETER); + g_rec_mutex_unlock(&h->mutex); + return ret_; + } + + res_ = rpc_port_parcel_create(&parcel_); + if (res_ != RPC_PORT_ERROR_NONE) { + _E("Failed to create parcel handle. error(%d)", res_); + set_last_result(res_); + g_rec_mutex_unlock(&h->mutex); + return ret_; + } + + rpc_port_parcel_get_header(parcel_, &header_); + rpc_port_parcel_header_set_tag(header_, TIDL_VERSION); + rpc_port_parcel_header_get_seq_num(header_, &seq_num_); + _W("[Version] \"%s\", [Sequence] %d", TIDL_VERSION, seq_num_); + + rpc_port_parcel_write_int32(parcel_, RPC_PORT_PROXY_VC_METHOD_IS_SYSTEM_COMMAND_VALID); + + rpc_port_parcel_write_int32(parcel_, pid); + + res_ = rpc_port_parcel_send(parcel_, h->port); + rpc_port_parcel_destroy(parcel_); + if (res_ != RPC_PORT_ERROR_NONE) { + _E("Failed to send parcel. error(%d)", res_); + set_last_result(res_); + g_rec_mutex_unlock(&h->mutex); + return ret_; + } + + do { + parcel_ = nullptr; + __rpc_port_proxy_vc_consume_command(h->port, &parcel_); + if (parcel_ == nullptr) { + _E("Invalid protocol"); + res_ = RPC_PORT_ERROR_IO_ERROR; + break; + } + + header_ = nullptr; + rpc_port_parcel_get_header(parcel_, &header_); + tag_ = nullptr; + rpc_port_parcel_header_get_tag(header_, &tag_); + if (tag_ && tag_[0] != '\0') { + _W("[Version] %s", tag_); + rpc_port_parcel_header_get_seq_num(header_, &recv_seq_num_); + if (recv_seq_num_ != seq_num_) { + _E("Invalid protocol. %d", recv_seq_num_); + free(tag_); + rpc_port_parcel_destroy(parcel_); + continue; + } + } + done_ = true; + free(tag_); + + rpc_port_parcel_read_bool(parcel_, &new_is_sys_cmd_valid); + + *is_sys_cmd_valid = new_is_sys_cmd_valid; + + rpc_port_parcel_read_int32(parcel_, &ret_); + + rpc_port_parcel_destroy(parcel_); + } while (!done_); + g_rec_mutex_unlock(&h->mutex); + set_last_result(res_); + + return ret_; +} + +int rpc_port_proxy_vc_invoke_auth_enable(rpc_port_proxy_vc_h h, int pid, int mgr_pid) +{ + rpc_port_parcel_h parcel_; + rpc_port_parcel_header_h header_; + int seq_num_ = -1; + int recv_seq_num_ = -1; + char *tag_ = nullptr; + bool done_ = false; + int res_; + int ret_ = -1; + + if (h == nullptr) { + _E("Invalid parameter"); + set_last_result(RPC_PORT_ERROR_INVALID_PARAMETER); + return ret_; + } + + g_rec_mutex_lock(&h->mutex); + if (h->port == nullptr) { + _E("Not connected"); + set_last_result(RPC_PORT_ERROR_INVALID_PARAMETER); + g_rec_mutex_unlock(&h->mutex); + return ret_; + } + + res_ = rpc_port_parcel_create(&parcel_); + if (res_ != RPC_PORT_ERROR_NONE) { + _E("Failed to create parcel handle. error(%d)", res_); + set_last_result(res_); + g_rec_mutex_unlock(&h->mutex); + return ret_; + } + + rpc_port_parcel_get_header(parcel_, &header_); + rpc_port_parcel_header_set_tag(header_, TIDL_VERSION); + rpc_port_parcel_header_get_seq_num(header_, &seq_num_); + _W("[Version] \"%s\", [Sequence] %d", TIDL_VERSION, seq_num_); + + rpc_port_parcel_write_int32(parcel_, RPC_PORT_PROXY_VC_METHOD_AUTH_ENABLE); + + rpc_port_parcel_write_int32(parcel_, pid); + + rpc_port_parcel_write_int32(parcel_, mgr_pid); + + res_ = rpc_port_parcel_send(parcel_, h->port); + rpc_port_parcel_destroy(parcel_); + if (res_ != RPC_PORT_ERROR_NONE) { + _E("Failed to send parcel. error(%d)", res_); + set_last_result(res_); + g_rec_mutex_unlock(&h->mutex); + return ret_; + } + + do { + parcel_ = nullptr; + __rpc_port_proxy_vc_consume_command(h->port, &parcel_); + if (parcel_ == nullptr) { + _E("Invalid protocol"); + res_ = RPC_PORT_ERROR_IO_ERROR; + break; + } + + header_ = nullptr; + rpc_port_parcel_get_header(parcel_, &header_); + tag_ = nullptr; + rpc_port_parcel_header_get_tag(header_, &tag_); + if (tag_ && tag_[0] != '\0') { + _W("[Version] %s", tag_); + rpc_port_parcel_header_get_seq_num(header_, &recv_seq_num_); + if (recv_seq_num_ != seq_num_) { + _E("Invalid protocol. %d", recv_seq_num_); + free(tag_); + rpc_port_parcel_destroy(parcel_); + continue; + } + } + done_ = true; + free(tag_); + + rpc_port_parcel_read_int32(parcel_, &ret_); + + rpc_port_parcel_destroy(parcel_); + } while (!done_); + g_rec_mutex_unlock(&h->mutex); + set_last_result(res_); + + return ret_; +} + +int rpc_port_proxy_vc_invoke_auth_disable(rpc_port_proxy_vc_h h, int pid, int mgr_pid) +{ + rpc_port_parcel_h parcel_; + rpc_port_parcel_header_h header_; + int seq_num_ = -1; + int recv_seq_num_ = -1; + char *tag_ = nullptr; + bool done_ = false; + int res_; + int ret_ = -1; + + if (h == nullptr) { + _E("Invalid parameter"); + set_last_result(RPC_PORT_ERROR_INVALID_PARAMETER); + return ret_; + } + + g_rec_mutex_lock(&h->mutex); + if (h->port == nullptr) { + _E("Not connected"); + set_last_result(RPC_PORT_ERROR_INVALID_PARAMETER); + g_rec_mutex_unlock(&h->mutex); + return ret_; + } + + res_ = rpc_port_parcel_create(&parcel_); + if (res_ != RPC_PORT_ERROR_NONE) { + _E("Failed to create parcel handle. error(%d)", res_); + set_last_result(res_); + g_rec_mutex_unlock(&h->mutex); + return ret_; + } + + rpc_port_parcel_get_header(parcel_, &header_); + rpc_port_parcel_header_set_tag(header_, TIDL_VERSION); + rpc_port_parcel_header_get_seq_num(header_, &seq_num_); + _W("[Version] \"%s\", [Sequence] %d", TIDL_VERSION, seq_num_); + + rpc_port_parcel_write_int32(parcel_, RPC_PORT_PROXY_VC_METHOD_AUTH_DISABLE); + + rpc_port_parcel_write_int32(parcel_, pid); + + rpc_port_parcel_write_int32(parcel_, mgr_pid); + + res_ = rpc_port_parcel_send(parcel_, h->port); + rpc_port_parcel_destroy(parcel_); + if (res_ != RPC_PORT_ERROR_NONE) { + _E("Failed to send parcel. error(%d)", res_); + set_last_result(res_); + g_rec_mutex_unlock(&h->mutex); + return ret_; + } + + do { + parcel_ = nullptr; + __rpc_port_proxy_vc_consume_command(h->port, &parcel_); + if (parcel_ == nullptr) { + _E("Invalid protocol"); + res_ = RPC_PORT_ERROR_IO_ERROR; + break; + } + + header_ = nullptr; + rpc_port_parcel_get_header(parcel_, &header_); + tag_ = nullptr; + rpc_port_parcel_header_get_tag(header_, &tag_); + if (tag_ && tag_[0] != '\0') { + _W("[Version] %s", tag_); + rpc_port_parcel_header_get_seq_num(header_, &recv_seq_num_); + if (recv_seq_num_ != seq_num_) { + _E("Invalid protocol. %d", recv_seq_num_); + free(tag_); + rpc_port_parcel_destroy(parcel_); + continue; + } + } + done_ = true; + free(tag_); + + rpc_port_parcel_read_int32(parcel_, &ret_); + + rpc_port_parcel_destroy(parcel_); + } while (!done_); + g_rec_mutex_unlock(&h->mutex); + set_last_result(res_); + + return ret_; +} + +int rpc_port_proxy_vc_invoke_auth_start(rpc_port_proxy_vc_h h, int pid, int mgr_pid) +{ + rpc_port_parcel_h parcel_; + rpc_port_parcel_header_h header_; + int seq_num_ = -1; + int recv_seq_num_ = -1; + char *tag_ = nullptr; + bool done_ = false; + int res_; + int ret_ = -1; + + if (h == nullptr) { + _E("Invalid parameter"); + set_last_result(RPC_PORT_ERROR_INVALID_PARAMETER); + return ret_; + } + + g_rec_mutex_lock(&h->mutex); + if (h->port == nullptr) { + _E("Not connected"); + set_last_result(RPC_PORT_ERROR_INVALID_PARAMETER); + g_rec_mutex_unlock(&h->mutex); + return ret_; + } + + res_ = rpc_port_parcel_create(&parcel_); + if (res_ != RPC_PORT_ERROR_NONE) { + _E("Failed to create parcel handle. error(%d)", res_); + set_last_result(res_); + g_rec_mutex_unlock(&h->mutex); + return ret_; + } + + rpc_port_parcel_get_header(parcel_, &header_); + rpc_port_parcel_header_set_tag(header_, TIDL_VERSION); + rpc_port_parcel_header_get_seq_num(header_, &seq_num_); + _W("[Version] \"%s\", [Sequence] %d", TIDL_VERSION, seq_num_); + + rpc_port_parcel_write_int32(parcel_, RPC_PORT_PROXY_VC_METHOD_AUTH_START); + + rpc_port_parcel_write_int32(parcel_, pid); + + rpc_port_parcel_write_int32(parcel_, mgr_pid); + + res_ = rpc_port_parcel_send(parcel_, h->port); + rpc_port_parcel_destroy(parcel_); + if (res_ != RPC_PORT_ERROR_NONE) { + _E("Failed to send parcel. error(%d)", res_); + set_last_result(res_); + g_rec_mutex_unlock(&h->mutex); + return ret_; + } + + do { + parcel_ = nullptr; + __rpc_port_proxy_vc_consume_command(h->port, &parcel_); + if (parcel_ == nullptr) { + _E("Invalid protocol"); + res_ = RPC_PORT_ERROR_IO_ERROR; + break; + } + + header_ = nullptr; + rpc_port_parcel_get_header(parcel_, &header_); + tag_ = nullptr; + rpc_port_parcel_header_get_tag(header_, &tag_); + if (tag_ && tag_[0] != '\0') { + _W("[Version] %s", tag_); + rpc_port_parcel_header_get_seq_num(header_, &recv_seq_num_); + if (recv_seq_num_ != seq_num_) { + _E("Invalid protocol. %d", recv_seq_num_); + free(tag_); + rpc_port_parcel_destroy(parcel_); + continue; + } + } + done_ = true; + free(tag_); + + rpc_port_parcel_read_int32(parcel_, &ret_); + + rpc_port_parcel_destroy(parcel_); + } while (!done_); + g_rec_mutex_unlock(&h->mutex); + set_last_result(res_); + + return ret_; +} + +int rpc_port_proxy_vc_invoke_auth_stop(rpc_port_proxy_vc_h h, int pid, int mgr_pid) +{ + rpc_port_parcel_h parcel_; + rpc_port_parcel_header_h header_; + int seq_num_ = -1; + int recv_seq_num_ = -1; + char *tag_ = nullptr; + bool done_ = false; + int res_; + int ret_ = -1; + + if (h == nullptr) { + _E("Invalid parameter"); + set_last_result(RPC_PORT_ERROR_INVALID_PARAMETER); + return ret_; + } + + g_rec_mutex_lock(&h->mutex); + if (h->port == nullptr) { + _E("Not connected"); + set_last_result(RPC_PORT_ERROR_INVALID_PARAMETER); + g_rec_mutex_unlock(&h->mutex); + return ret_; + } + + res_ = rpc_port_parcel_create(&parcel_); + if (res_ != RPC_PORT_ERROR_NONE) { + _E("Failed to create parcel handle. error(%d)", res_); + set_last_result(res_); + g_rec_mutex_unlock(&h->mutex); + return ret_; + } + + rpc_port_parcel_get_header(parcel_, &header_); + rpc_port_parcel_header_set_tag(header_, TIDL_VERSION); + rpc_port_parcel_header_get_seq_num(header_, &seq_num_); + _W("[Version] \"%s\", [Sequence] %d", TIDL_VERSION, seq_num_); + + rpc_port_parcel_write_int32(parcel_, RPC_PORT_PROXY_VC_METHOD_AUTH_STOP); + + rpc_port_parcel_write_int32(parcel_, pid); + + rpc_port_parcel_write_int32(parcel_, mgr_pid); + + res_ = rpc_port_parcel_send(parcel_, h->port); + rpc_port_parcel_destroy(parcel_); + if (res_ != RPC_PORT_ERROR_NONE) { + _E("Failed to send parcel. error(%d)", res_); + set_last_result(res_); + g_rec_mutex_unlock(&h->mutex); + return ret_; + } + + do { + parcel_ = nullptr; + __rpc_port_proxy_vc_consume_command(h->port, &parcel_); + if (parcel_ == nullptr) { + _E("Invalid protocol"); + res_ = RPC_PORT_ERROR_IO_ERROR; + break; + } + + header_ = nullptr; + rpc_port_parcel_get_header(parcel_, &header_); + tag_ = nullptr; + rpc_port_parcel_header_get_tag(header_, &tag_); + if (tag_ && tag_[0] != '\0') { + _W("[Version] %s", tag_); + rpc_port_parcel_header_get_seq_num(header_, &recv_seq_num_); + if (recv_seq_num_ != seq_num_) { + _E("Invalid protocol. %d", recv_seq_num_); + free(tag_); + rpc_port_parcel_destroy(parcel_); + continue; + } + } + done_ = true; + free(tag_); + + rpc_port_parcel_read_int32(parcel_, &ret_); + + rpc_port_parcel_destroy(parcel_); + } while (!done_); + g_rec_mutex_unlock(&h->mutex); + set_last_result(res_); + + return ret_; +} + +int rpc_port_proxy_vc_invoke_auth_cancel(rpc_port_proxy_vc_h h, int pid, int mgr_pid) +{ + rpc_port_parcel_h parcel_; + rpc_port_parcel_header_h header_; + int seq_num_ = -1; + int recv_seq_num_ = -1; + char *tag_ = nullptr; + bool done_ = false; + int res_; + int ret_ = -1; + + if (h == nullptr) { + _E("Invalid parameter"); + set_last_result(RPC_PORT_ERROR_INVALID_PARAMETER); + return ret_; + } + + g_rec_mutex_lock(&h->mutex); + if (h->port == nullptr) { + _E("Not connected"); + set_last_result(RPC_PORT_ERROR_INVALID_PARAMETER); + g_rec_mutex_unlock(&h->mutex); + return ret_; + } + + res_ = rpc_port_parcel_create(&parcel_); + if (res_ != RPC_PORT_ERROR_NONE) { + _E("Failed to create parcel handle. error(%d)", res_); + set_last_result(res_); + g_rec_mutex_unlock(&h->mutex); + return ret_; + } + + rpc_port_parcel_get_header(parcel_, &header_); + rpc_port_parcel_header_set_tag(header_, TIDL_VERSION); + rpc_port_parcel_header_get_seq_num(header_, &seq_num_); + _W("[Version] \"%s\", [Sequence] %d", TIDL_VERSION, seq_num_); + + rpc_port_parcel_write_int32(parcel_, RPC_PORT_PROXY_VC_METHOD_AUTH_CANCEL); + + rpc_port_parcel_write_int32(parcel_, pid); + + rpc_port_parcel_write_int32(parcel_, mgr_pid); + + res_ = rpc_port_parcel_send(parcel_, h->port); + rpc_port_parcel_destroy(parcel_); + if (res_ != RPC_PORT_ERROR_NONE) { + _E("Failed to send parcel. error(%d)", res_); + set_last_result(res_); + g_rec_mutex_unlock(&h->mutex); + return ret_; + } + + do { + parcel_ = nullptr; + __rpc_port_proxy_vc_consume_command(h->port, &parcel_); + if (parcel_ == nullptr) { + _E("Invalid protocol"); + res_ = RPC_PORT_ERROR_IO_ERROR; + break; + } + + header_ = nullptr; + rpc_port_parcel_get_header(parcel_, &header_); + tag_ = nullptr; + rpc_port_parcel_header_get_tag(header_, &tag_); + if (tag_ && tag_[0] != '\0') { + _W("[Version] %s", tag_); + rpc_port_parcel_header_get_seq_num(header_, &recv_seq_num_); + if (recv_seq_num_ != seq_num_) { + _E("Invalid protocol. %d", recv_seq_num_); + free(tag_); + rpc_port_parcel_destroy(parcel_); + continue; + } + } + done_ = true; + free(tag_); + + rpc_port_parcel_read_int32(parcel_, &ret_); + + rpc_port_parcel_destroy(parcel_); + } while (!done_); + g_rec_mutex_unlock(&h->mutex); + set_last_result(res_); + + return ret_; +} + +int rpc_port_proxy_vc_invoke_request_tts(rpc_port_proxy_vc_h h, int pid, const char *text, const char *lang, bool to_vcm, int *utt_id) +{ + rpc_port_parcel_h parcel_; + rpc_port_parcel_header_h header_; + int seq_num_ = -1; + int recv_seq_num_ = -1; + char *tag_ = nullptr; + bool done_ = false; + int res_; + int ret_ = -1; + int new_utt_id; + + if (h == nullptr || text == nullptr || lang == nullptr) { + _E("Invalid parameter"); + set_last_result(RPC_PORT_ERROR_INVALID_PARAMETER); + return ret_; + } + + g_rec_mutex_lock(&h->mutex); + if (h->port == nullptr) { + _E("Not connected"); + set_last_result(RPC_PORT_ERROR_INVALID_PARAMETER); + g_rec_mutex_unlock(&h->mutex); + return ret_; + } + + res_ = rpc_port_parcel_create(&parcel_); + if (res_ != RPC_PORT_ERROR_NONE) { + _E("Failed to create parcel handle. error(%d)", res_); + set_last_result(res_); + g_rec_mutex_unlock(&h->mutex); + return ret_; + } + + rpc_port_parcel_get_header(parcel_, &header_); + rpc_port_parcel_header_set_tag(header_, TIDL_VERSION); + rpc_port_parcel_header_get_seq_num(header_, &seq_num_); + _W("[Version] \"%s\", [Sequence] %d", TIDL_VERSION, seq_num_); + + rpc_port_parcel_write_int32(parcel_, RPC_PORT_PROXY_VC_METHOD_REQUEST_TTS); + + rpc_port_parcel_write_int32(parcel_, pid); + + rpc_port_parcel_write_string(parcel_, text); + + rpc_port_parcel_write_string(parcel_, lang); + + rpc_port_parcel_write_bool(parcel_, to_vcm); + + res_ = rpc_port_parcel_send(parcel_, h->port); + rpc_port_parcel_destroy(parcel_); + if (res_ != RPC_PORT_ERROR_NONE) { + _E("Failed to send parcel. error(%d)", res_); + set_last_result(res_); + g_rec_mutex_unlock(&h->mutex); + return ret_; + } + + do { + parcel_ = nullptr; + __rpc_port_proxy_vc_consume_command(h->port, &parcel_); + if (parcel_ == nullptr) { + _E("Invalid protocol"); + res_ = RPC_PORT_ERROR_IO_ERROR; + break; + } + + header_ = nullptr; + rpc_port_parcel_get_header(parcel_, &header_); + tag_ = nullptr; + rpc_port_parcel_header_get_tag(header_, &tag_); + if (tag_ && tag_[0] != '\0') { + _W("[Version] %s", tag_); + rpc_port_parcel_header_get_seq_num(header_, &recv_seq_num_); + if (recv_seq_num_ != seq_num_) { + _E("Invalid protocol. %d", recv_seq_num_); + free(tag_); + rpc_port_parcel_destroy(parcel_); + continue; + } + } + done_ = true; + free(tag_); + + rpc_port_parcel_read_int32(parcel_, &new_utt_id); + + *utt_id = new_utt_id; + + rpc_port_parcel_read_int32(parcel_, &ret_); + + rpc_port_parcel_destroy(parcel_); + } while (!done_); + g_rec_mutex_unlock(&h->mutex); + set_last_result(res_); + + return ret_; +} + +int rpc_port_proxy_vc_invoke_cancel_tts(rpc_port_proxy_vc_h h, int pid, int utt_id) +{ + rpc_port_parcel_h parcel_; + rpc_port_parcel_header_h header_; + int seq_num_ = -1; + int recv_seq_num_ = -1; + char *tag_ = nullptr; + bool done_ = false; + int res_; + int ret_ = -1; + + if (h == nullptr) { + _E("Invalid parameter"); + set_last_result(RPC_PORT_ERROR_INVALID_PARAMETER); + return ret_; + } + + g_rec_mutex_lock(&h->mutex); + if (h->port == nullptr) { + _E("Not connected"); + set_last_result(RPC_PORT_ERROR_INVALID_PARAMETER); + g_rec_mutex_unlock(&h->mutex); + return ret_; + } + + res_ = rpc_port_parcel_create(&parcel_); + if (res_ != RPC_PORT_ERROR_NONE) { + _E("Failed to create parcel handle. error(%d)", res_); + set_last_result(res_); + g_rec_mutex_unlock(&h->mutex); + return ret_; + } + + rpc_port_parcel_get_header(parcel_, &header_); + rpc_port_parcel_header_set_tag(header_, TIDL_VERSION); + rpc_port_parcel_header_get_seq_num(header_, &seq_num_); + _W("[Version] \"%s\", [Sequence] %d", TIDL_VERSION, seq_num_); + + rpc_port_parcel_write_int32(parcel_, RPC_PORT_PROXY_VC_METHOD_CANCEL_TTS); + + rpc_port_parcel_write_int32(parcel_, pid); + + rpc_port_parcel_write_int32(parcel_, utt_id); + + res_ = rpc_port_parcel_send(parcel_, h->port); + rpc_port_parcel_destroy(parcel_); + if (res_ != RPC_PORT_ERROR_NONE) { + _E("Failed to send parcel. error(%d)", res_); + set_last_result(res_); + g_rec_mutex_unlock(&h->mutex); + return ret_; + } + + do { + parcel_ = nullptr; + __rpc_port_proxy_vc_consume_command(h->port, &parcel_); + if (parcel_ == nullptr) { + _E("Invalid protocol"); + res_ = RPC_PORT_ERROR_IO_ERROR; + break; + } + + header_ = nullptr; + rpc_port_parcel_get_header(parcel_, &header_); + tag_ = nullptr; + rpc_port_parcel_header_get_tag(header_, &tag_); + if (tag_ && tag_[0] != '\0') { + _W("[Version] %s", tag_); + rpc_port_parcel_header_get_seq_num(header_, &recv_seq_num_); + if (recv_seq_num_ != seq_num_) { + _E("Invalid protocol. %d", recv_seq_num_); + free(tag_); + rpc_port_parcel_destroy(parcel_); + continue; + } + } + done_ = true; + free(tag_); + + rpc_port_parcel_read_int32(parcel_, &ret_); + + rpc_port_parcel_destroy(parcel_); + } while (!done_); + g_rec_mutex_unlock(&h->mutex); + set_last_result(res_); + + return ret_; +} + +int rpc_port_proxy_vc_invoke_get_tts_audio_format(rpc_port_proxy_vc_h h, int pid, int *rate, int *channel, int *audio_type) +{ + rpc_port_parcel_h parcel_; + rpc_port_parcel_header_h header_; + int seq_num_ = -1; + int recv_seq_num_ = -1; + char *tag_ = nullptr; + bool done_ = false; + int res_; + int ret_ = -1; + int new_rate; + int new_channel; + int new_audio_type; + + if (h == nullptr) { + _E("Invalid parameter"); + set_last_result(RPC_PORT_ERROR_INVALID_PARAMETER); + return ret_; + } + + g_rec_mutex_lock(&h->mutex); + if (h->port == nullptr) { + _E("Not connected"); + set_last_result(RPC_PORT_ERROR_INVALID_PARAMETER); + g_rec_mutex_unlock(&h->mutex); + return ret_; + } + + res_ = rpc_port_parcel_create(&parcel_); + if (res_ != RPC_PORT_ERROR_NONE) { + _E("Failed to create parcel handle. error(%d)", res_); + set_last_result(res_); + g_rec_mutex_unlock(&h->mutex); + return ret_; + } + + rpc_port_parcel_get_header(parcel_, &header_); + rpc_port_parcel_header_set_tag(header_, TIDL_VERSION); + rpc_port_parcel_header_get_seq_num(header_, &seq_num_); + _W("[Version] \"%s\", [Sequence] %d", TIDL_VERSION, seq_num_); + + rpc_port_parcel_write_int32(parcel_, RPC_PORT_PROXY_VC_METHOD_GET_TTS_AUDIO_FORMAT); + + rpc_port_parcel_write_int32(parcel_, pid); + + res_ = rpc_port_parcel_send(parcel_, h->port); + rpc_port_parcel_destroy(parcel_); + if (res_ != RPC_PORT_ERROR_NONE) { + _E("Failed to send parcel. error(%d)", res_); + set_last_result(res_); + g_rec_mutex_unlock(&h->mutex); + return ret_; + } + + do { + parcel_ = nullptr; + __rpc_port_proxy_vc_consume_command(h->port, &parcel_); + if (parcel_ == nullptr) { + _E("Invalid protocol"); + res_ = RPC_PORT_ERROR_IO_ERROR; + break; + } + + header_ = nullptr; + rpc_port_parcel_get_header(parcel_, &header_); + tag_ = nullptr; + rpc_port_parcel_header_get_tag(header_, &tag_); + if (tag_ && tag_[0] != '\0') { + _W("[Version] %s", tag_); + rpc_port_parcel_header_get_seq_num(header_, &recv_seq_num_); + if (recv_seq_num_ != seq_num_) { + _E("Invalid protocol. %d", recv_seq_num_); + free(tag_); + rpc_port_parcel_destroy(parcel_); + continue; + } + } + done_ = true; + free(tag_); + + rpc_port_parcel_read_int32(parcel_, &new_rate); + + *rate = new_rate; + + rpc_port_parcel_read_int32(parcel_, &new_channel); + + *channel = new_channel; + + rpc_port_parcel_read_int32(parcel_, &new_audio_type); + + *audio_type = new_audio_type; + + rpc_port_parcel_read_int32(parcel_, &ret_); + + rpc_port_parcel_destroy(parcel_); + } while (!done_); + g_rec_mutex_unlock(&h->mutex); + set_last_result(res_); + + return ret_; +} diff --git a/client/vc_proxy.h b/client/vc_proxy.h new file mode 100755 index 0000000..5b2fa31 --- /dev/null +++ b/client/vc_proxy.h @@ -0,0 +1,819 @@ +/* + * Generated by tidlc 1.8.1. + */ + +#pragma once + +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief The rpc_port_proxy_array_char handle. + */ +typedef struct rpc_port_proxy_array_char_s *rpc_port_proxy_array_char_h; + +/** + * @brief The rpc_port_proxy_vc handle. + */ +typedef struct rpc_port_proxy_vc_s *rpc_port_proxy_vc_h; + +/** + * @brief The rpc_port_proxy_vc_notify_cb handle. + */ +typedef struct rpc_port_proxy_vc_notify_cb_s *rpc_port_proxy_vc_notify_cb_h; + +/** + * @brief The rpc_port_proxy_vc_feedback_cb handle. + */ +typedef struct rpc_port_proxy_vc_feedback_cb_s *rpc_port_proxy_vc_feedback_cb_h; + +/** + * @briefs Creates a rpc_port_proxy_array_char handle. + * + * @remarks The @a h should be released using the rpc_port_proxy_array_char_destroy() + * if it's no longer needed. + * @param[out] h The rpc_port_proxy_array_char handle that is newly created + * @return @c 0 on success, + * otherwise a negative error value + * @retval #RPC_PORT_ERROR_NONE Successful + * @retval #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #RPC_PORT_ERROR_OUT_OF_MEMORY Out of memory + * @see rpc_port_proxy_array_char_destroy() + */ +int rpc_port_proxy_array_char_create(rpc_port_proxy_array_char_h *h); + +/** + * @brief Destroys the rpc_port_proxy_array_char handle. + * + * @param[in] h The rpc_port_proxy_array_char handle + * @return @c 0 on success, + * otherwise a negative error value + * @retval #RPC_PORT_ERROR_NONE Successful + * @retval #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter + * @see rpc_port_proxy_array_char_create() + */ +int rpc_port_proxy_array_char_destroy(rpc_port_proxy_array_char_h h); + +/** + * @brief Creates and returns a copy of the given rpc_port_proxy_array_char handle. + * + * @remarks A new created rpc_port_proxy_array_char should be released using + * the rpc_port_proxy_array_char_destroy() if it's no longer needed. + * @param[in] h The rpc_port_proxy_array_char handle + * @param[out] clone If successful, a new created rpc_port_proxy_array_char handle will be returned + * @return @c 0 on success, + * otherwise a negative error value + * @retval #RPC_PORT_ERROR_NONE Successful + * @retval #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #RPC_PORT_ERROR_OUT_OF_MEMORY Out of memory + * @see rpc_port_proxy_array_char_destroy() + */ +int rpc_port_proxy_array_char_clone(rpc_port_proxy_array_char_h h, rpc_port_proxy_array_char_h *clone); + +/** + * @brief Sets the value to the rpc_port_proxy_array_char handle. + * + * @remarks The value is internally copied and stored. + * You should release it if it's allocaed when it's no longer needed, + * @param[in] h The rpc_port_proxy_array_char handle + * @param[in] value The array value + * @param[in] size The size of the array + * @return @c 0 on success, + * otherwise a negative error value + * @retval #RPC_PORT_ERROR_NONE Successful + * @retval #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #RPC_PORT_ERROR_OUT_OF_MEMORY Out of memory + * @see rpc_port_proxy_array_char_get() + */ +int rpc_port_proxy_array_char_set(rpc_port_proxy_array_char_h h, char *value, int size); + +/** + * @brief Gets the value from the rpc_port_proxy_array_char handle. + * + * @remarks A new created value should be released if it's no longer needed. + * @param[in] h The rpc_port_proxy_array_char handle + * @param[out] value The array value + * @param[out] size The size of the array + * @return @c 0 on success, + * otherwise a negative error value + * @retval #RPC_PORT_ERROR_NONE Successful + * @retval #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #RPC_PORT_ERROR_OUT_OF_MEMORY Out of memory + * @see rpc_port_proxy_array_char_set() + */ +int rpc_port_proxy_array_char_get(rpc_port_proxy_array_char_h h, char **value, int *size); + +/** + * @brief Called when the event is received. + * + * @param[in] user_data The user data passed from the callback registration function + * @param[in] ... + * + * @see rpc_port_proxy_vc_notify_cb_create() + */ +typedef void (*rpc_port_proxy_vc_notify_cb_cb)(void *user_data, int pid, bundle *msg); + +/** + * @brief Creates a rpc_port_proxy_vc_notify_cb handle. + * + * @param[out] h The rpc_port_proxy_vc_notify_cb handle + * @return @c 0 on success, + * otherwise a negative error value + * @retval #RPC_PORT_ERROR_NONE Successful + * @retval #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #RPC_PORT_ERROR_OUT_OF_MEMORY Out of memorya + * @see rpc_port_proxy_vc_notify_cb_destroy() + * @see rpc_port_proxy_vc_notify_cb_dispose() + * @see rpc_port_proxy_vc_notify_cb_set_callback() + * @see rpc_port_proxy_vc_notify_cb_set_once() + */ +int rpc_port_proxy_vc_notify_cb_create(rpc_port_proxy_vc_notify_cb_h *h); + +/** + * @brief Destroys the rpc_port_proxy_vc_notify_cb handle. + * + * @param[in] h The rpc_port_proxy_vc_notify_cb handle + * @return @c 0 on success, + * otherwise a negative error value + * @retval #RPC_PORT_ERROR_NONE Successful + * @retval #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter + * @see rpc_port_proxy_vc_notify_cb_create() + */ +int rpc_port_proxy_vc_notify_cb_destroy(rpc_port_proxy_vc_notify_cb_h h); + +/** + * @brief Creates and returns a copy of the given rpc_port_proxy_vc_notify_cb handle. + * + * @remarks A new created rpc_port_proxy_vc_notify_cb should be released using + * the rpc_port_proxy_vc_notify_cb_destroy() if it's no longer needed. + * @param[in] h The rpc_port_proxy_vc_notify_cb handle + * @param[out] clone If successful, a new created rpc_port_proxy_vc_notify_cb handle will be returned + * @return @c 0 on success, + * otherwise a negative error value + * @retval #RPC_PORT_ERROR_NONE Successful + * @retval #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #RPC_PORT_ERROR_OUT_OF_MEMORY Out of memory + * @see rpc_port_proxy_vc_notify_cb_destroy() + */ +int rpc_port_proxy_vc_notify_cb_clone(rpc_port_proxy_vc_notify_cb_h h, rpc_port_proxy_vc_notify_cb_h *clone); + +/** + * @brief Sets the callback function to the rpc_port_proxy_vc_notify_cb handle. + * + * @param[in] h The rpc_port_proxy_vc_notify_cb handle + * @param[in] callback The callback function + * @param[in] user_data The user data to be passed to the callback function + * @return @c 0 on success, + * otherwise a negative error value + * @retval #RPC_PORT_ERROR_NONE Successful + * @retval #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter + */ +int rpc_port_proxy_vc_notify_cb_set_callback(rpc_port_proxy_vc_notify_cb_h h, rpc_port_proxy_vc_notify_cb_cb callback, void *user_data); + +/** + * @brief Set the once flag to the rpc_port_proxy_vc_notify_cb handle. + * @details If the once flag is 'true', the delegate handle will be deleted after invocation. + * If the @a h handle is not used using the method, the handle should be released using + * the rpc_port_proxy_vc_notify_cb_destroy() when it's no longer needed. + * If you don't want the delegate callback function to be called after it's used using the method, + * you should release the handle using the rpc_port_proxy_vc_notify_cb_dispose(). + * + * @param[in] h The rpc_port_proxy_vc_notify_cb handle + * @param[in] once The flag if it's true, the delegate will be deleted after invocation + * @return @c 0 on success, + * otherwise a negative error value + * @retval #RPC_PORT_ERROR_NONE Successful + * @retval #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter + */ +int rpc_port_proxy_vc_notify_cb_set_once(rpc_port_proxy_vc_notify_cb_h h, bool once); + +/** + * @brief Gets the ID of the rpc_port_proxy_vc_notify_cb handle. + * + * @param[in] h The rpc_port_proxy_vc_notify_cb handle + * @param[out] id The ID + * @return @c 0 on success, + * otherwise a negative error value + * @retval #RPC_PORT_ERROR_NONE Successful + * @retval #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter + */ +int rpc_port_proxy_vc_notify_cb_get_id(rpc_port_proxy_vc_notify_cb_h h, int *id); + +/** + * @brief Gets the sequence ID of the rpc_port_proxy_vc_notify_cb handle. + * + * @param[in] h The rpc_port_proxy_vc_notify_cb handle + * @param[out] seq_id The Sequence ID + * @return @c 0 on success, + * otherwise a negative error value + * @retval #RPC_PORT_ERROR_NONE Successful + * @retval #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter + */ +int rpc_port_proxy_vc_notify_cb_get_seq_id(rpc_port_proxy_vc_notify_cb_h h, int *seq_id); + +/** + * @brief Checks whether the delegate is for one-time or not. + * + * @param[in] h The rpc_port_proxy_vc_notify_cb handle + * @param[out] once The flag, it's true, the handle is for one-time + * @return @c 0 on success, + * otherwise a negative error value + * @retval #RPC_PORT_ERROR_NONE Successful + * @retval #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter + */ +int rpc_port_proxy_vc_notify_cb_is_once(rpc_port_proxy_vc_notify_cb_h h, bool *once); + +/** + * @brief Gets the tag from the rpc_port_proxy_vc_notify_cb handle. + * + * @remarks The @a tag should be released using free(). + * @param[in] h The rpc_port_proxy_vc_notify_cb handle + * @param[out] tag The tag + * @return @c 0 on success, + * otherwise a negative error value + * @retval #RPC_PORT_ERROR_NONE Successful + * @retval #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #RPC_PORT_ERROR_OUT_OF_MEMORY Out of memory + */ +int rpc_port_proxy_vc_notify_cb_get_tag(rpc_port_proxy_vc_notify_cb_h h, char **tag); + +/** + * @brief Disposes the rpc_port_proxy_vc_notify_cb handle from the rpc_port_proxy_vc handle. + * + * @param[in] proxy The rpc_port_proxy_vc handle + * @param[in] h The rpc_port_proxy_vc_notify_cb handle + * @return @c 0 on success, + * otherwise a negative error value + * @retval #RPC_PORT_ERROR_NONE Successful + * @retval #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter + * @see rpc_port_proxy_vc_notify_cb_create() + */ +int rpc_port_proxy_vc_notify_cb_dispose(rpc_port_proxy_vc_h proxy, rpc_port_proxy_vc_notify_cb_h h); + +/** + * @brief Called when the event is received. + * + * @param[in] user_data The user data passed from the callback registration function + * @param[in] ... + * + * @see rpc_port_proxy_vc_feedback_cb_create() + */ +typedef void (*rpc_port_proxy_vc_feedback_cb_cb)(void *user_data, int utt_id, int event, rpc_port_proxy_array_char_h pcm_data, int len); + +/** + * @brief Creates a rpc_port_proxy_vc_feedback_cb handle. + * + * @param[out] h The rpc_port_proxy_vc_feedback_cb handle + * @return @c 0 on success, + * otherwise a negative error value + * @retval #RPC_PORT_ERROR_NONE Successful + * @retval #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #RPC_PORT_ERROR_OUT_OF_MEMORY Out of memorya + * @see rpc_port_proxy_vc_feedback_cb_destroy() + * @see rpc_port_proxy_vc_feedback_cb_dispose() + * @see rpc_port_proxy_vc_feedback_cb_set_callback() + * @see rpc_port_proxy_vc_feedback_cb_set_once() + */ +int rpc_port_proxy_vc_feedback_cb_create(rpc_port_proxy_vc_feedback_cb_h *h); + +/** + * @brief Destroys the rpc_port_proxy_vc_feedback_cb handle. + * + * @param[in] h The rpc_port_proxy_vc_feedback_cb handle + * @return @c 0 on success, + * otherwise a negative error value + * @retval #RPC_PORT_ERROR_NONE Successful + * @retval #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter + * @see rpc_port_proxy_vc_feedback_cb_create() + */ +int rpc_port_proxy_vc_feedback_cb_destroy(rpc_port_proxy_vc_feedback_cb_h h); + +/** + * @brief Creates and returns a copy of the given rpc_port_proxy_vc_feedback_cb handle. + * + * @remarks A new created rpc_port_proxy_vc_feedback_cb should be released using + * the rpc_port_proxy_vc_feedback_cb_destroy() if it's no longer needed. + * @param[in] h The rpc_port_proxy_vc_feedback_cb handle + * @param[out] clone If successful, a new created rpc_port_proxy_vc_feedback_cb handle will be returned + * @return @c 0 on success, + * otherwise a negative error value + * @retval #RPC_PORT_ERROR_NONE Successful + * @retval #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #RPC_PORT_ERROR_OUT_OF_MEMORY Out of memory + * @see rpc_port_proxy_vc_feedback_cb_destroy() + */ +int rpc_port_proxy_vc_feedback_cb_clone(rpc_port_proxy_vc_feedback_cb_h h, rpc_port_proxy_vc_feedback_cb_h *clone); + +/** + * @brief Sets the callback function to the rpc_port_proxy_vc_feedback_cb handle. + * + * @param[in] h The rpc_port_proxy_vc_feedback_cb handle + * @param[in] callback The callback function + * @param[in] user_data The user data to be passed to the callback function + * @return @c 0 on success, + * otherwise a negative error value + * @retval #RPC_PORT_ERROR_NONE Successful + * @retval #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter + */ +int rpc_port_proxy_vc_feedback_cb_set_callback(rpc_port_proxy_vc_feedback_cb_h h, rpc_port_proxy_vc_feedback_cb_cb callback, void *user_data); + +/** + * @brief Set the once flag to the rpc_port_proxy_vc_feedback_cb handle. + * @details If the once flag is 'true', the delegate handle will be deleted after invocation. + * If the @a h handle is not used using the method, the handle should be released using + * the rpc_port_proxy_vc_feedback_cb_destroy() when it's no longer needed. + * If you don't want the delegate callback function to be called after it's used using the method, + * you should release the handle using the rpc_port_proxy_vc_feedback_cb_dispose(). + * + * @param[in] h The rpc_port_proxy_vc_feedback_cb handle + * @param[in] once The flag if it's true, the delegate will be deleted after invocation + * @return @c 0 on success, + * otherwise a negative error value + * @retval #RPC_PORT_ERROR_NONE Successful + * @retval #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter + */ +int rpc_port_proxy_vc_feedback_cb_set_once(rpc_port_proxy_vc_feedback_cb_h h, bool once); + +/** + * @brief Gets the ID of the rpc_port_proxy_vc_feedback_cb handle. + * + * @param[in] h The rpc_port_proxy_vc_feedback_cb handle + * @param[out] id The ID + * @return @c 0 on success, + * otherwise a negative error value + * @retval #RPC_PORT_ERROR_NONE Successful + * @retval #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter + */ +int rpc_port_proxy_vc_feedback_cb_get_id(rpc_port_proxy_vc_feedback_cb_h h, int *id); + +/** + * @brief Gets the sequence ID of the rpc_port_proxy_vc_feedback_cb handle. + * + * @param[in] h The rpc_port_proxy_vc_feedback_cb handle + * @param[out] seq_id The Sequence ID + * @return @c 0 on success, + * otherwise a negative error value + * @retval #RPC_PORT_ERROR_NONE Successful + * @retval #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter + */ +int rpc_port_proxy_vc_feedback_cb_get_seq_id(rpc_port_proxy_vc_feedback_cb_h h, int *seq_id); + +/** + * @brief Checks whether the delegate is for one-time or not. + * + * @param[in] h The rpc_port_proxy_vc_feedback_cb handle + * @param[out] once The flag, it's true, the handle is for one-time + * @return @c 0 on success, + * otherwise a negative error value + * @retval #RPC_PORT_ERROR_NONE Successful + * @retval #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter + */ +int rpc_port_proxy_vc_feedback_cb_is_once(rpc_port_proxy_vc_feedback_cb_h h, bool *once); + +/** + * @brief Gets the tag from the rpc_port_proxy_vc_feedback_cb handle. + * + * @remarks The @a tag should be released using free(). + * @param[in] h The rpc_port_proxy_vc_feedback_cb handle + * @param[out] tag The tag + * @return @c 0 on success, + * otherwise a negative error value + * @retval #RPC_PORT_ERROR_NONE Successful + * @retval #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #RPC_PORT_ERROR_OUT_OF_MEMORY Out of memory + */ +int rpc_port_proxy_vc_feedback_cb_get_tag(rpc_port_proxy_vc_feedback_cb_h h, char **tag); + +/** + * @brief Disposes the rpc_port_proxy_vc_feedback_cb handle from the rpc_port_proxy_vc handle. + * + * @param[in] proxy The rpc_port_proxy_vc handle + * @param[in] h The rpc_port_proxy_vc_feedback_cb handle + * @return @c 0 on success, + * otherwise a negative error value + * @retval #RPC_PORT_ERROR_NONE Successful + * @retval #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter + * @see rpc_port_proxy_vc_feedback_cb_create() + */ +int rpc_port_proxy_vc_feedback_cb_dispose(rpc_port_proxy_vc_h proxy, rpc_port_proxy_vc_feedback_cb_h h); + +/** + * @brief Called when the proxy is connected. + * @details The callback function is called when the proxy is connected to the stub. + * + * @param[in] h The rpc_port_proxy_vc handle + * @param[in] user_data The user data passed from the registeration function + * @see #rpc_port_proxy_vc_callback_s + */ +typedef void (*rpc_port_proxy_vc_connected_cb)(rpc_port_proxy_vc_h h, void *user_data); + +/** + * @brief Called when the proxy is disconnected. + * @details The callback function is called when the proxy is disconnected from the stub. + * + * @param[in] h The rpc_port_proxy_vc handle + * @param[in] user_data The user data passed from the registeration function + * @see #rpc_port_proxy_vc_callback_s + */ +typedef void (*rpc_port_proxy_vc_disconnected_cb)(rpc_port_proxy_vc_h h, void *user_data); + +/** + * @brief Called when the proxy is rejected. + * @details The callback function is called when the proxy is rejected to connect to the stub. + * + * @param[in] h The rpc_port_proxy_vc handle + * @param[in] user_data The user data passed from the registeration function + * @see #rpc_port_proxy_vc_callback_s + */ +typedef void (*rpc_port_proxy_vc_rejected_cb)(rpc_port_proxy_vc_h h, void *user_data); + +/** + * @brief The structure type containing the set of callback functions for handling proxy events. + * @details It is one of the input parameters of the rpc_port_proxy_vc_create() function. + * + * @see rpc_port_proxy_vc_connected_cb + * @see rpc_port_proxy_vc_disconnected_cb + * @see rpc_port_proxy_vc_rejected_cb + */ +typedef struct { + rpc_port_proxy_vc_connected_cb connected; /**< This callback function is called when the proxy is connected to the stub. */ + rpc_port_proxy_vc_disconnected_cb disconnected; /**< This callback function is called when the proxy is disconnected from the stub. */ + rpc_port_proxy_vc_rejected_cb rejected; /**< This callback function is called when the proxy is rejected to connect to the stub. */ +} rpc_port_proxy_vc_callback_s; + +/** + * @brief Creates a rpc_port_proxy_vc handle. + * @remarks The @a h handle should be released using + * the rpc_port_proxy_vc_destroy() if it's no longer needed. + * + * @param[in] stub_appid The application ID of the stub + * @param[in] callback The set of callback functions to handle proxy events + * @param[in] user_data The user data to be passed to the callback function + * @param[out] h The rpc_port_proxy_vc handle + * @return @c 0 on success, + * otherwise a negative error value + * @retval #RPC_PORT_ERROR_NONE Successful + * @retval #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #RPC_PORT_ERROR_OUT_OF_MEMORY Out of memory + * @see rpc_port_proxy_vc_destroy() + * @see #rpc_port_proxy_vc_callback_s + */ +int rpc_port_proxy_vc_create(const char *stub_appid, rpc_port_proxy_vc_callback_s *callback, void *user_data, rpc_port_proxy_vc_h *h); + +/** + * @brief Destroys the rpc_port_proxy_vc handle. + * + * @param[in] h The rpc_port_proxy_vc handle + * @return @c 0 on success, + * otherwise a negative error value + * @retval #RPC_PORT_ERROR_NONE Successful + * @retval #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter + * @see rpc_port_proxy_vc_create() + */ +int rpc_port_proxy_vc_destroy(rpc_port_proxy_vc_h h); + +/** + * @brief Connects to the stub. + * + * @param[in] h The rpc_port_proxy_vc handle + * @return @c 0 on success, + * otherwise a negative error value + * @retval #RPC_PORT_ERROR_NONE Successful + * @retval #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #RPC_PORT_ERROR_IO_ERROR I/O error + * @retval #RPC_PORT_ERROR_PERMISSION_DENIED Permission denied + */ +int rpc_port_proxy_vc_connect(rpc_port_proxy_vc_h h); + +/** + * @brief Connects to the stub synchronously. + * + * @param[in] h The rpc_port_proxy_vc handle + * @return @c 0 on success, + * otherwise a negative error value + * @retval #RPC_PORT_ERROR_NONE Successful + * @retval #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #RPC_PORT_ERROR_IO_ERROR I/O error + * @retval #RPC_PORT_ERROR_PERMISSION_DENIED Permission denied + */ +int rpc_port_proxy_vc_connect_sync(rpc_port_proxy_vc_h h); + +/** + * @brief Disconnects from the stub. + * + * @param[in] h The rpc_port_proxy_vc handle + * @return @c 0 on success, + * otherwise a negative error value + * @retval #RPC_PORT_ERROR_NONE Successful + * @retval #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter + */ +int rpc_port_proxy_vc_disconnect(rpc_port_proxy_vc_h h); + +/** + * @brief Calls the register_notify_cb() method. + * @details The return value and args are decided by the interface declaration. + * You can get the result using get_last_result(). + * Before returning the function, the function sets the result using set_last_result(). + * @remarks The specific error code can be obtained using the get_last_result() function. Error codes are described in Exception section. + * @param[in] h The rpc_port_proxy_vc handle + * @param[in] ... + * @exception #RPC_PORT_ERROR_NONE Successful + * @exception #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter + * @exception #RPC_PORT_ERROR_OUT_OF_MEMORY Out of memory + * @exception #RPC_PORT_ERROR_IO_ERROR I/O error + */ +void rpc_port_proxy_vc_invoke_register_notify_cb(rpc_port_proxy_vc_h h, int pid, rpc_port_proxy_vc_notify_cb_h callback); + +/** + * @brief Calls the register_notify_cb_sync() method. + * @details The return value and args are decided by the interface declaration. + * You can get the result using get_last_result(). + * Before returning the function, the function sets the result using set_last_result(). + * @remarks The specific error code can be obtained using the get_last_result() function. Error codes are described in Exception section. + * @param[in] h The rpc_port_proxy_vc handle + * @param[in] ... + * @exception #RPC_PORT_ERROR_NONE Successful + * @exception #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter + * @exception #RPC_PORT_ERROR_OUT_OF_MEMORY Out of memory + * @exception #RPC_PORT_ERROR_IO_ERROR I/O error + */ +int rpc_port_proxy_vc_invoke_register_notify_cb_sync(rpc_port_proxy_vc_h h, int pid, rpc_port_proxy_vc_notify_cb_h callback); + +/** + * @brief Calls the register_feedback_cb() method. + * @details The return value and args are decided by the interface declaration. + * You can get the result using get_last_result(). + * Before returning the function, the function sets the result using set_last_result(). + * @remarks The specific error code can be obtained using the get_last_result() function. Error codes are described in Exception section. + * @param[in] h The rpc_port_proxy_vc handle + * @param[in] ... + * @exception #RPC_PORT_ERROR_NONE Successful + * @exception #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter + * @exception #RPC_PORT_ERROR_OUT_OF_MEMORY Out of memory + * @exception #RPC_PORT_ERROR_IO_ERROR I/O error + */ +void rpc_port_proxy_vc_invoke_register_feedback_cb(rpc_port_proxy_vc_h h, int pid, rpc_port_proxy_vc_feedback_cb_h callback); + +/** + * @brief Calls the register_feedback_cb_sync() method. + * @details The return value and args are decided by the interface declaration. + * You can get the result using get_last_result(). + * Before returning the function, the function sets the result using set_last_result(). + * @remarks The specific error code can be obtained using the get_last_result() function. Error codes are described in Exception section. + * @param[in] h The rpc_port_proxy_vc handle + * @param[in] ... + * @exception #RPC_PORT_ERROR_NONE Successful + * @exception #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter + * @exception #RPC_PORT_ERROR_OUT_OF_MEMORY Out of memory + * @exception #RPC_PORT_ERROR_IO_ERROR I/O error + */ +int rpc_port_proxy_vc_invoke_register_feedback_cb_sync(rpc_port_proxy_vc_h h, int pid, rpc_port_proxy_vc_feedback_cb_h callback); + +/** + * @brief Calls the initialize() method. + * @details The return value and args are decided by the interface declaration. + * You can get the result using get_last_result(). + * Before returning the function, the function sets the result using set_last_result(). + * @remarks The specific error code can be obtained using the get_last_result() function. Error codes are described in Exception section. + * @param[in] h The rpc_port_proxy_vc handle + * @param[in] ... + * @exception #RPC_PORT_ERROR_NONE Successful + * @exception #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter + * @exception #RPC_PORT_ERROR_OUT_OF_MEMORY Out of memory + * @exception #RPC_PORT_ERROR_IO_ERROR I/O error + */ +int rpc_port_proxy_vc_invoke_initialize(rpc_port_proxy_vc_h h, int pid, int *mgr_pid, int *service_state, int *daemon_pid); + +/** + * @brief Calls the finalize() method. + * @details The return value and args are decided by the interface declaration. + * You can get the result using get_last_result(). + * Before returning the function, the function sets the result using set_last_result(). + * @remarks The specific error code can be obtained using the get_last_result() function. Error codes are described in Exception section. + * @param[in] h The rpc_port_proxy_vc handle + * @param[in] ... + * @exception #RPC_PORT_ERROR_NONE Successful + * @exception #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter + * @exception #RPC_PORT_ERROR_OUT_OF_MEMORY Out of memory + * @exception #RPC_PORT_ERROR_IO_ERROR I/O error + */ +int rpc_port_proxy_vc_invoke_finalize(rpc_port_proxy_vc_h h, int pid); + +/** + * @brief Calls the set_command() method. + * @details The return value and args are decided by the interface declaration. + * You can get the result using get_last_result(). + * Before returning the function, the function sets the result using set_last_result(). + * @remarks The specific error code can be obtained using the get_last_result() function. Error codes are described in Exception section. + * @param[in] h The rpc_port_proxy_vc handle + * @param[in] ... + * @exception #RPC_PORT_ERROR_NONE Successful + * @exception #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter + * @exception #RPC_PORT_ERROR_OUT_OF_MEMORY Out of memory + * @exception #RPC_PORT_ERROR_IO_ERROR I/O error + */ +int rpc_port_proxy_vc_invoke_set_command(rpc_port_proxy_vc_h h, int pid, int cmd_type); + +/** + * @brief Calls the unset_command() method. + * @details The return value and args are decided by the interface declaration. + * You can get the result using get_last_result(). + * Before returning the function, the function sets the result using set_last_result(). + * @remarks The specific error code can be obtained using the get_last_result() function. Error codes are described in Exception section. + * @param[in] h The rpc_port_proxy_vc handle + * @param[in] ... + * @exception #RPC_PORT_ERROR_NONE Successful + * @exception #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter + * @exception #RPC_PORT_ERROR_OUT_OF_MEMORY Out of memory + * @exception #RPC_PORT_ERROR_IO_ERROR I/O error + */ +int rpc_port_proxy_vc_invoke_unset_command(rpc_port_proxy_vc_h h, int pid, int cmd_type); + +/** + * @brief Calls the set_foreground() method. + * @details The return value and args are decided by the interface declaration. + * You can get the result using get_last_result(). + * Before returning the function, the function sets the result using set_last_result(). + * @remarks The specific error code can be obtained using the get_last_result() function. Error codes are described in Exception section. + * @param[in] h The rpc_port_proxy_vc handle + * @param[in] ... + * @exception #RPC_PORT_ERROR_NONE Successful + * @exception #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter + * @exception #RPC_PORT_ERROR_OUT_OF_MEMORY Out of memory + * @exception #RPC_PORT_ERROR_IO_ERROR I/O error + */ +int rpc_port_proxy_vc_invoke_set_foreground(rpc_port_proxy_vc_h h, int pid, bool value); + +/** + * @brief Calls the set_server_dialog() method. + * @details The return value and args are decided by the interface declaration. + * You can get the result using get_last_result(). + * Before returning the function, the function sets the result using set_last_result(). + * @remarks The specific error code can be obtained using the get_last_result() function. Error codes are described in Exception section. + * @param[in] h The rpc_port_proxy_vc handle + * @param[in] ... + * @exception #RPC_PORT_ERROR_NONE Successful + * @exception #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter + * @exception #RPC_PORT_ERROR_OUT_OF_MEMORY Out of memory + * @exception #RPC_PORT_ERROR_IO_ERROR I/O error + */ +int rpc_port_proxy_vc_invoke_set_server_dialog(rpc_port_proxy_vc_h h, int pid, const char *app_id, const char *credential); + +/** + * @brief Calls the request_dialog() method. + * @details The return value and args are decided by the interface declaration. + * You can get the result using get_last_result(). + * Before returning the function, the function sets the result using set_last_result(). + * @remarks The specific error code can be obtained using the get_last_result() function. Error codes are described in Exception section. + * @param[in] h The rpc_port_proxy_vc handle + * @param[in] ... + * @exception #RPC_PORT_ERROR_NONE Successful + * @exception #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter + * @exception #RPC_PORT_ERROR_OUT_OF_MEMORY Out of memory + * @exception #RPC_PORT_ERROR_IO_ERROR I/O error + */ +int rpc_port_proxy_vc_invoke_request_dialog(rpc_port_proxy_vc_h h, int pid, const char *disp_text, const char *utt_text, bool continuous); + +/** + * @brief Calls the is_system_command_valid() method. + * @details The return value and args are decided by the interface declaration. + * You can get the result using get_last_result(). + * Before returning the function, the function sets the result using set_last_result(). + * @remarks The specific error code can be obtained using the get_last_result() function. Error codes are described in Exception section. + * @param[in] h The rpc_port_proxy_vc handle + * @param[in] ... + * @exception #RPC_PORT_ERROR_NONE Successful + * @exception #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter + * @exception #RPC_PORT_ERROR_OUT_OF_MEMORY Out of memory + * @exception #RPC_PORT_ERROR_IO_ERROR I/O error + */ +int rpc_port_proxy_vc_invoke_is_system_command_valid(rpc_port_proxy_vc_h h, int pid, bool *is_sys_cmd_valid); + +/** + * @brief Calls the auth_enable() method. + * @details The return value and args are decided by the interface declaration. + * You can get the result using get_last_result(). + * Before returning the function, the function sets the result using set_last_result(). + * @remarks The specific error code can be obtained using the get_last_result() function. Error codes are described in Exception section. + * @param[in] h The rpc_port_proxy_vc handle + * @param[in] ... + * @exception #RPC_PORT_ERROR_NONE Successful + * @exception #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter + * @exception #RPC_PORT_ERROR_OUT_OF_MEMORY Out of memory + * @exception #RPC_PORT_ERROR_IO_ERROR I/O error + */ +int rpc_port_proxy_vc_invoke_auth_enable(rpc_port_proxy_vc_h h, int pid, int mgr_pid); + +/** + * @brief Calls the auth_disable() method. + * @details The return value and args are decided by the interface declaration. + * You can get the result using get_last_result(). + * Before returning the function, the function sets the result using set_last_result(). + * @remarks The specific error code can be obtained using the get_last_result() function. Error codes are described in Exception section. + * @param[in] h The rpc_port_proxy_vc handle + * @param[in] ... + * @exception #RPC_PORT_ERROR_NONE Successful + * @exception #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter + * @exception #RPC_PORT_ERROR_OUT_OF_MEMORY Out of memory + * @exception #RPC_PORT_ERROR_IO_ERROR I/O error + */ +int rpc_port_proxy_vc_invoke_auth_disable(rpc_port_proxy_vc_h h, int pid, int mgr_pid); + +/** + * @brief Calls the auth_start() method. + * @details The return value and args are decided by the interface declaration. + * You can get the result using get_last_result(). + * Before returning the function, the function sets the result using set_last_result(). + * @remarks The specific error code can be obtained using the get_last_result() function. Error codes are described in Exception section. + * @param[in] h The rpc_port_proxy_vc handle + * @param[in] ... + * @exception #RPC_PORT_ERROR_NONE Successful + * @exception #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter + * @exception #RPC_PORT_ERROR_OUT_OF_MEMORY Out of memory + * @exception #RPC_PORT_ERROR_IO_ERROR I/O error + */ +int rpc_port_proxy_vc_invoke_auth_start(rpc_port_proxy_vc_h h, int pid, int mgr_pid); + +/** + * @brief Calls the auth_stop() method. + * @details The return value and args are decided by the interface declaration. + * You can get the result using get_last_result(). + * Before returning the function, the function sets the result using set_last_result(). + * @remarks The specific error code can be obtained using the get_last_result() function. Error codes are described in Exception section. + * @param[in] h The rpc_port_proxy_vc handle + * @param[in] ... + * @exception #RPC_PORT_ERROR_NONE Successful + * @exception #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter + * @exception #RPC_PORT_ERROR_OUT_OF_MEMORY Out of memory + * @exception #RPC_PORT_ERROR_IO_ERROR I/O error + */ +int rpc_port_proxy_vc_invoke_auth_stop(rpc_port_proxy_vc_h h, int pid, int mgr_pid); + +/** + * @brief Calls the auth_cancel() method. + * @details The return value and args are decided by the interface declaration. + * You can get the result using get_last_result(). + * Before returning the function, the function sets the result using set_last_result(). + * @remarks The specific error code can be obtained using the get_last_result() function. Error codes are described in Exception section. + * @param[in] h The rpc_port_proxy_vc handle + * @param[in] ... + * @exception #RPC_PORT_ERROR_NONE Successful + * @exception #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter + * @exception #RPC_PORT_ERROR_OUT_OF_MEMORY Out of memory + * @exception #RPC_PORT_ERROR_IO_ERROR I/O error + */ +int rpc_port_proxy_vc_invoke_auth_cancel(rpc_port_proxy_vc_h h, int pid, int mgr_pid); + +/** + * @brief Calls the request_tts() method. + * @details The return value and args are decided by the interface declaration. + * You can get the result using get_last_result(). + * Before returning the function, the function sets the result using set_last_result(). + * @remarks The specific error code can be obtained using the get_last_result() function. Error codes are described in Exception section. + * @param[in] h The rpc_port_proxy_vc handle + * @param[in] ... + * @exception #RPC_PORT_ERROR_NONE Successful + * @exception #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter + * @exception #RPC_PORT_ERROR_OUT_OF_MEMORY Out of memory + * @exception #RPC_PORT_ERROR_IO_ERROR I/O error + */ +int rpc_port_proxy_vc_invoke_request_tts(rpc_port_proxy_vc_h h, int pid, const char *text, const char *lang, bool to_vcm, int *utt_id); + +/** + * @brief Calls the cancel_tts() method. + * @details The return value and args are decided by the interface declaration. + * You can get the result using get_last_result(). + * Before returning the function, the function sets the result using set_last_result(). + * @remarks The specific error code can be obtained using the get_last_result() function. Error codes are described in Exception section. + * @param[in] h The rpc_port_proxy_vc handle + * @param[in] ... + * @exception #RPC_PORT_ERROR_NONE Successful + * @exception #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter + * @exception #RPC_PORT_ERROR_OUT_OF_MEMORY Out of memory + * @exception #RPC_PORT_ERROR_IO_ERROR I/O error + */ +int rpc_port_proxy_vc_invoke_cancel_tts(rpc_port_proxy_vc_h h, int pid, int utt_id); + +/** + * @brief Calls the get_tts_audio_format() method. + * @details The return value and args are decided by the interface declaration. + * You can get the result using get_last_result(). + * Before returning the function, the function sets the result using set_last_result(). + * @remarks The specific error code can be obtained using the get_last_result() function. Error codes are described in Exception section. + * @param[in] h The rpc_port_proxy_vc handle + * @param[in] ... + * @exception #RPC_PORT_ERROR_NONE Successful + * @exception #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter + * @exception #RPC_PORT_ERROR_OUT_OF_MEMORY Out of memory + * @exception #RPC_PORT_ERROR_IO_ERROR I/O error + */ +int rpc_port_proxy_vc_invoke_get_tts_audio_format(rpc_port_proxy_vc_h h, int pid, int *rate, int *channel, int *audio_type); + +#ifdef __cplusplus +} +#endif diff --git a/client/vc_tidl.c b/client/vc_tidl.c new file mode 100755 index 0000000..e937f0f --- /dev/null +++ b/client/vc_tidl.c @@ -0,0 +1,708 @@ +/* +* 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 "vc_command.h" +#include "vc_tidl.h" +#include "vc_proxy.h" +#include "vc_main.h" + +#include + +typedef struct { + int pid; + bool connected; + bool connection_requesting; + bool register_notify_callback_invoked; + bool register_feedback_callback_invoked; + + rpc_port_proxy_vc_h rpc_h; + rpc_port_proxy_vc_notify_cb_h notify_cb_h; + rpc_port_proxy_vc_feedback_cb_h feedback_cb_h; + + char* engine_appid; +} vc_tidl_info_s; + +static GList* g_tidl_infos = NULL; + +extern int __vc_cb_error(int reason, int daemon_pid, char* msg); +extern int __vc_cb_error_to_app(int pid, int reason, char* msg); +extern void __vc_cb_result(); +extern int __vc_cb_service_state(int state); +extern int __vc_cb_manager_pid(int manager_pid); +extern int __vc_cb_tts_streaming(int utt_id, vc_feedback_event_e event, char* buffer, int len); +extern int __vc_cb_utterance_status(int utt_id, int utt_status); + + +static vc_tidl_info_s* __get_tidl_info_s(int pid) +{ + GList* iter = NULL; + vc_tidl_info_s* info = NULL; + + if (g_list_length(g_tidl_infos) > 0) { + /* Get a first item */ + iter = g_list_first(g_tidl_infos); + + while (NULL != iter) { + info = iter->data; + + if (info->pid == pid) { + return info; + } + + /* Next item */ + iter = g_list_next(iter); + } + } + + return NULL; +} + +static char* __get_engine_appid(void) +{ + char* engine_name = vconf_get_str(VC_ENGINE_DB_DEFAULT); + if (NULL == engine_name) { + SLOG(LOG_WARN, TAG_VCC, "[WARNING] Fail to get engine name. Please use default engine name."); + engine_name = strdup("org.tizen.vc-engine-default"); + } + + char* appid = strdup(engine_name); + + return appid; +} + +static void __on_connected(rpc_port_proxy_vc_h h, void* user_data) +{ + unsigned int pid = (uintptr_t)user_data; + + vc_tidl_info_s* info = __get_tidl_info_s(pid); + RETM_IF(NULL == info, "[ERROR] Fail to get tidl info"); + + info->connected = true; + info->connection_requesting = false; + info->register_notify_callback_invoked = false; + + SLOG(LOG_INFO, TAG_VCC, "[INFO] Connected to server"); +} + +static void __on_disconnected(rpc_port_proxy_vc_h h, void* user_data) +{ + unsigned int pid = (uintptr_t)user_data; + + vc_tidl_info_s* info = __get_tidl_info_s(pid); + RETM_IF(NULL == info, "[ERROR] Fail to get tidl info"); + + info->connected = false; + info->connection_requesting = false; + info->register_notify_callback_invoked = false; + + /* retry to connect */ + SLOG(LOG_INFO, TAG_VCC, "[INFO] Disconnected to server"); +} + +static void __on_rejected(rpc_port_proxy_vc_h h, void* user_data) +{ + unsigned int pid = (uintptr_t)user_data; + + vc_tidl_info_s* info = __get_tidl_info_s(pid); + RETM_IF(NULL == info, "[ERROR] Fail to get tidl info"); + + info->connection_requesting = false; + info->register_notify_callback_invoked = false; + + SLOG(LOG_INFO, TAG_VCC, "[INFO] Rejected from server(%d)", pid); +} + + +static rpc_port_proxy_vc_h __create_rpc_port(int pid, const char* engine_app_id) +{ + rpc_port_proxy_vc_callback_s rpc_callback = { + .connected = __on_connected, + .disconnected = __on_disconnected, + .rejected = __on_rejected + }; + + rpc_port_proxy_vc_h handle = NULL; + uintptr_t ptr_pid = pid; + if (0 != rpc_port_proxy_vc_create(engine_app_id, &rpc_callback, (void*)ptr_pid, &handle)) { + return NULL; + } + + return handle; +} + +static void __request_tidl_connect(vc_tidl_info_s* info) +{ + if (info->connection_requesting) { + SLOG(LOG_INFO, TAG_VCC, "[TIDL] Already connection is requested. Skip to call rpc_port_proxy_vc_connect()."); + return ; + } + + int ret = rpc_port_proxy_vc_connect(info->rpc_h); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Fail to request connection to stub. ret(%d)", ret); + return ; + } + + SLOG(LOG_INFO, TAG_VCC, "[INFO] Request connection to stub. ret(%d)", ret); + info->connection_requesting = true; +} + +static void __notify_cb(void* user_data, int pid, bundle* msg) +{ + // corresponding to listener_event_callback + char* method = NULL; + + SLOG(LOG_DEBUG, TAG_VCC, "__notify_cb is invoked pid(%d)", pid); + + bundle_get_str(msg, VC_BUNDLE_METHOD, &method); + + if (0 == strncmp(VCD_METHOD_HELLO, method, strlen(VCD_METHOD_HELLO))) { + } /* VCD_METHOD_HELLO */ + else if (0 == strncmp(VCD_METHOD_SET_SERVICE_STATE, method, strlen(VCD_METHOD_SET_SERVICE_STATE))) { + /* signal!!! */ + char* state = NULL; + bundle_get_str(msg, VC_BUNDLE_SERVICE_STATE, &state); + if (state) { + __vc_cb_service_state(atoi(state)); + } + } /* VCD_METHOD_SET_SERVICE_STATE */ + else if (0 == strncmp(VCD_METHOD_RESULT, method, strlen(VCD_METHOD_RESULT))) { + SLOG(LOG_DEBUG, TAG_VCC, "@@@ Get Client Result"); + + __vc_cb_result(); + } /* VCD_METHOD_RESULT */ + else if (0 == strncmp(VCD_METHOD_SEND_MANAGER_PID, method, strlen(VCD_METHOD_SEND_MANAGER_PID))) { + /* signal!!! */ + char* manager_pid = NULL; + bundle_get_str(msg, VC_BUNDLE_MANAGER_PID, &manager_pid); + if (manager_pid) { + SLOG(LOG_DEBUG, TAG_VCC, "@@ manager pid is changed : %d", atoi(manager_pid)); + __vc_cb_manager_pid(atoi(manager_pid)); + } + } /* VCD_METHOD_SEND_MANAGER_PID */ + else if (0 == strncmp(VCD_METHOD_ERROR, method, strlen(VCD_METHOD_ERROR))) { + /* signal!!! */ + char* reason; + char* daemon_pid; + char* err_msg = NULL; + + bundle_get_str(msg, VC_BUNDLE_REASON, &reason); + bundle_get_str(msg, VC_BUNDLE_DAEMON_PID, &daemon_pid); + bundle_get_str(msg, VC_BUNDLE_ERR_MSG, &err_msg); + + SLOG(LOG_DEBUG, TAG_VCC, "@@ vc Get Error message : reason(%d), daemon_pid(%d), msg(%s)", atoi(reason), atoi(daemon_pid), err_msg); + __vc_cb_error(atoi(reason), atoi(daemon_pid), err_msg); + } /* VCD_METHOD_ERROR */ + else if (0 == strncmp(VCD_METHOD_ERROR_TO_APP, method, strlen(VCD_METHOD_ERROR_TO_APP))) { + /* signal!!! */ + char* pid; + char* reason; + char* err_msg = NULL; + + bundle_get_str(msg, VC_BUNDLE_PID, &pid); + bundle_get_str(msg, VC_BUNDLE_REASON, &reason); + bundle_get_str(msg, VC_BUNDLE_ERR_MSG, &err_msg); + + SLOG(LOG_DEBUG, TAG_VCC, "@@ vc Get Error message : reason(%d), pid(%d), msg(%s)", atoi(reason), atoi(pid), err_msg); + __vc_cb_error_to_app(atoi(pid), atoi(reason), err_msg); + } /* VCD_METHOD_ERROR_TO_APP */ + else if (0 == strncmp(VC_MANAGER_METHOD_UTTERANCE_STATUS, method, strlen(VC_MANAGER_METHOD_UTTERANCE_STATUS))) { + } /* VC_MANAGER_METHOD_UTTERANCE_STATUS */ + else { + SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Invalid msg"); + } +} + +void __feedback_cb(void *user_data, int utt_id, int event, rpc_port_proxy_array_char_h pcm_data, int len) +{ + // corresponding to listener_event_callback (only for tts_streaming) + SLOG(LOG_DEBUG, TAG_VCC, "__feedback_cb is invoked utt_id(%d) event(%d)", utt_id, event); + + // char* utt_id; + // char* event; + + // bundle_get_str(msg, VC_BUNDLE_UTTID, &utt_id); + // bundle_get_str(msg, VC_BUNDLE_FEEDBACK_EVENT, &event); + // __vc_cb_tts_streaming(utt_id, event, buffer, len); + /* VCD_METHOD_FEEDBACK_STREAMING */ +} + +static int __create_notify_callback_handle(vc_tidl_info_s* info) +{ + if (NULL != info->notify_cb_h) { + rpc_port_proxy_vc_notify_cb_dispose(info->rpc_h, info->notify_cb_h); + info->notify_cb_h = NULL; + } + + if (RPC_PORT_ERROR_NONE != rpc_port_proxy_vc_notify_cb_create(&info->notify_cb_h)) { + return VC_ERROR_OUT_OF_MEMORY; + } + + rpc_port_proxy_vc_notify_cb_set_callback(info->notify_cb_h, __notify_cb, NULL); + rpc_port_proxy_vc_notify_cb_set_once(info->notify_cb_h, false); + + return VC_ERROR_NONE; +} + +static int __create_feedback_callback_handle(vc_tidl_info_s* info) +{ + if (NULL != info) { + rpc_port_proxy_vc_feedback_cb_dispose(info->rpc_h, info->feedback_cb_h); + info->feedback_cb_h = NULL; + } + + if (RPC_PORT_ERROR_NONE != rpc_port_proxy_vc_feedback_cb_create(&info->feedback_cb_h)) { + return VC_ERROR_OUT_OF_MEMORY; + } + + rpc_port_proxy_vc_feedback_cb_set_callback(info->feedback_cb_h, __feedback_cb, NULL); + rpc_port_proxy_vc_feedback_cb_set_once(info->feedback_cb_h, false); + + return VC_ERROR_NONE; +} + +static int __invoke_register_notify_callback(int pid, vc_tidl_info_s* info) +{ + if (info->register_notify_callback_invoked) { + SLOG(LOG_ERROR, TAG_VCC, "[INFO] Already register callback is invoked"); + return VC_ERROR_NONE; + } + + int ret = __create_notify_callback_handle(info); + if (VC_ERROR_NONE != ret) { + SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Fail to create callback handle. ret(%d)", ret); + return VC_ERROR_OPERATION_FAILED; + } + + rpc_port_proxy_vc_invoke_register_notify_cb(info->rpc_h, pid, info->notify_cb_h); + info->register_notify_callback_invoked = true; + return VC_ERROR_NONE; +} + +static int __invoke_register_feedback_callback(int pid, vc_tidl_info_s* info) +{ + if (info->register_feedback_callback_invoked) { + SLOG(LOG_ERROR, TAG_VCC, "[INFO] Already register callback is invoked"); + return VC_ERROR_NONE; + } + + int ret = __create_feedback_callback_handle(info); + if (VC_ERROR_NONE != ret) { + SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Fail to create callback handle. ret(%d)", ret); + return VC_ERROR_OPERATION_FAILED; + } + + rpc_port_proxy_vc_invoke_register_feedback_cb(info->rpc_h, pid, info->feedback_cb_h); + info->register_feedback_callback_invoked = true; + return VC_ERROR_NONE; +} + +int vc_tidl_open_connection() +{ + SLOG(LOG_INFO, TAG_VCC, "[TIDL] vc_tidl_open_connection"); + + vc_tidl_info_s* info = (vc_tidl_info_s*)calloc(1, sizeof(vc_tidl_info_s)); + if (NULL == info) { + SLOG(LOG_ERROR, TAG_VCC, "[TIDL ERROR] Fail to create tidl_info_s"); + return VC_ERROR_OUT_OF_MEMORY; + } + + int pid = getpid(); + char* engine_appid = __get_engine_appid(); + + info->rpc_h = __create_rpc_port(pid, engine_appid); + if (NULL == info->rpc_h) { + SLOG(LOG_ERROR, TAG_VCC, "[TIDL ERROR] Fail to create proxy"); + free(info); + return VC_ERROR_OPERATION_FAILED; + } + + info->pid = pid; + g_tidl_infos = g_list_append(g_tidl_infos, info); + + SLOG(LOG_ERROR, TAG_VCC, "[TIDL] pid(%d) rpc_h(%p), engine_appid(%s)", pid, info->rpc_h, info->engine_appid); + return VC_ERROR_NONE; + +} + +int vc_tidl_close_connection() +{ + SLOG(LOG_INFO, TAG_VCC, "[TIDL] vc_tidl_close_connection"); + + int pid = getpid(); + vc_tidl_info_s* info = __get_tidl_info_s(pid); + RETVM_IF(NULL == info, VC_ERROR_INVALID_PARAMETER, "[ERROR] Fail to get tidl info"); + + if (0 != rpc_port_proxy_vc_destroy(info->rpc_h)) { + SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Fail to disconnect"); + return VC_ERROR_OPERATION_FAILED; + } + + info->rpc_h = NULL; + info->notify_cb_h = NULL; + + g_tidl_infos = g_list_remove(g_tidl_infos, info); + free(info); + + return VC_ERROR_NONE; +} + +int vc_tidl_request_hello() +{ + SLOG(LOG_INFO, TAG_VCC, "[TIDL] vc_tidl_request_hello"); + + int pid = getpid(); + vc_tidl_info_s* info = __get_tidl_info_s(pid); + RETVM_IF(NULL == info, VC_ERROR_INVALID_PARAMETER, "[ERROR] Fail to get tidl info"); + + if (!info->connected) { + SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Not Connected. Call __request_tidl_connect()"); + __request_tidl_connect(info); + return VC_ERROR_OPERATION_FAILED; + } + + SLOG(LOG_DEBUG, TAG_VCC, ">>>>> VCC Hello"); + if (VC_ERROR_NONE != __invoke_register_notify_callback(pid, info)) { + SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Fail to invoke register callback"); + return VC_ERROR_OPERATION_FAILED; + } + + SLOG(LOG_DEBUG, TAG_VCC, "<<<<"); + return VC_ERROR_NONE; + +} + +static int __covert_unhandled_error(int ret) +{ + if (RPC_PORT_ERROR_IO_ERROR == ret || RPC_PORT_ERROR_OUT_OF_MEMORY == ret) { + return VC_ERROR_OPERATION_FAILED; + } + + return ret; +} + +int vc_tidl_request_initialize(int pid, int* mgr_pid, int* service_state, int* daemon_pid) +{ + SLOG(LOG_INFO, TAG_VCC, "[TIDL] vc_tidl_request_initialize"); + + vc_tidl_info_s* info = __get_tidl_info_s(pid); + RETVM_IF(NULL == info, VC_ERROR_INVALID_PARAMETER, "[ERROR] Fail to get tidl info"); + RETVM_IF(false == info->connected, VC_ERROR_OPERATION_FAILED, "[ERROR] Not Connected"); + + int ret = rpc_port_proxy_vc_invoke_initialize(info->rpc_h, pid, mgr_pid, service_state, daemon_pid); + if (RPC_PORT_ERROR_NONE != ret) { + SLOG(LOG_ERROR, TAG_VCC, ">>>> Request vc initialize : Fail to invoke message"); + return __covert_unhandled_error(ret); + } + + SLOG(LOG_DEBUG, TAG_VCC, "@@ vc initialize : mgr = %d service = %d daemon_pid = %d", *mgr_pid, *service_state, *daemon_pid); //LCOV_EXCL_LINE + + return VC_ERROR_NONE; +} + +int vc_tidl_request_finalize(int pid) +{ + SLOG(LOG_INFO, TAG_VCC, "[TIDL] vc_tidl_request_finalize"); + + vc_tidl_info_s* info = __get_tidl_info_s(pid); + RETVM_IF(NULL == info, VC_ERROR_INVALID_PARAMETER, "[ERROR] Fail to get tidl info"); + RETVM_IF(false == info->connected, VC_ERROR_OPERATION_FAILED, "[ERROR] Not Connected"); + + int ret = rpc_port_proxy_vc_invoke_finalize(info->rpc_h, pid); + if (RPC_PORT_ERROR_NONE != ret) { + SLOG(LOG_ERROR, TAG_VCC, ">>>> Request vc finalize : Fail to invoke message"); + return __covert_unhandled_error(ret); + } + + SLOG(LOG_DEBUG, TAG_VCC, "@@ vc finalize : result = %d", ret); + + return VC_ERROR_NONE; +} + +int vc_tidl_request_set_command(int pid, vc_cmd_type_e cmd_type) +{ + SLOG(LOG_INFO, TAG_VCC, "[TIDL] vc_tidl_request_set_command"); + + vc_tidl_info_s* info = __get_tidl_info_s(pid); + RETVM_IF(NULL == info, VC_ERROR_INVALID_PARAMETER, "[ERROR] Fail to get tidl info"); + RETVM_IF(false == info->connected, VC_ERROR_OPERATION_FAILED, "[ERROR] Not Connected"); + + int ret = rpc_port_proxy_vc_invoke_set_command(info->rpc_h, pid, cmd_type); + if (RPC_PORT_ERROR_NONE != ret) { + SLOG(LOG_ERROR, TAG_VCC, ">>>> Request vc set command : Fail to invoke message"); + return __covert_unhandled_error(ret); + } + + SLOG(LOG_DEBUG, TAG_VCC, "@@ vc set command : pid(%d), cmd_type(%d)", pid, cmd_type); + + return VC_ERROR_NONE; +} + +int vc_tidl_request_unset_command(int pid, vc_cmd_type_e cmd_type) +{ + SLOG(LOG_INFO, TAG_VCC, "[TIDL] vc_tidl_request_unset_command"); + + vc_tidl_info_s* info = __get_tidl_info_s(pid); + RETVM_IF(NULL == info, VC_ERROR_INVALID_PARAMETER, "[ERROR] Fail to get tidl info"); + RETVM_IF(false == info->connected, VC_ERROR_OPERATION_FAILED, "[ERROR] Not Connected"); + + int ret = rpc_port_proxy_vc_invoke_unset_command(info->rpc_h, pid, cmd_type); + if (RPC_PORT_ERROR_NONE != ret) { + SLOG(LOG_ERROR, TAG_VCC, ">>>> Request vc unset command : Fail to invoke message"); + return __covert_unhandled_error(ret); + } + + SLOG(LOG_DEBUG, TAG_VCC, "@@ vc unset command : pid(%d), cmd_type(%d)", pid, cmd_type); + + return VC_ERROR_NONE; +} + +int vc_tidl_request_set_foreground(int pid, bool value) +{ + // method no reply --> async + SLOG(LOG_INFO, TAG_VCC, "[TIDL] vc_tidl_request_set_foreground"); + + vc_tidl_info_s* info = __get_tidl_info_s(pid); + RETVM_IF(NULL == info, VC_ERROR_INVALID_PARAMETER, "[ERROR] Fail to get tidl info"); + RETVM_IF(false == info->connected, VC_ERROR_OPERATION_FAILED, "[ERROR] Not Connected"); + + int ret = rpc_port_proxy_vc_invoke_set_foreground(info->rpc_h, pid, value); + if (RPC_PORT_ERROR_NONE != ret) { + SLOG(LOG_ERROR, TAG_VCC, ">>>> Request vc set foreground : Fail to invoke message"); + return __covert_unhandled_error(ret); + } + + SLOG(LOG_DEBUG, TAG_VCC, "@@ vc set foreground : pid(%d), value(%d)", pid, value); + + return VC_ERROR_NONE; +} + +int vc_tidl_request_set_server_dialog(int pid, const char* app_id, const char* credential) +{ + SLOG(LOG_INFO, TAG_VCC, "[TIDL] vc_tidl_request_set_server_dialog"); + + vc_tidl_info_s* info = __get_tidl_info_s(pid); + RETVM_IF(NULL == info, VC_ERROR_INVALID_PARAMETER, "[ERROR] Fail to get tidl info"); + RETVM_IF(false == info->connected, VC_ERROR_OPERATION_FAILED, "[ERROR] Not Connected"); + + int ret = rpc_port_proxy_vc_invoke_set_server_dialog(info->rpc_h, pid, app_id, credential); + if (RPC_PORT_ERROR_NONE != ret) { + SLOG(LOG_ERROR, TAG_VCC, ">>>> Request vc set server dialog : Fail to invoke message"); + return __covert_unhandled_error(ret); + } + + SLOG(LOG_DEBUG, TAG_VCC, "@@ vc set server dialog : pid(%d), app_id(%s), credential(%s)", pid, app_id, credential); + + return VC_ERROR_NONE; +} + +int vc_tidl_request_request_dialog(int pid, const char* disp_text, const char* utt_text, bool continuous) +{ + // method no reply --> async + SLOG(LOG_INFO, TAG_VCC, "[TIDL] vc_tidl_request_request_dialog"); + + vc_tidl_info_s* info = __get_tidl_info_s(pid); + RETVM_IF(NULL == info, VC_ERROR_INVALID_PARAMETER, "[ERROR] Fail to get tidl info"); + RETVM_IF(false == info->connected, VC_ERROR_OPERATION_FAILED, "[ERROR] Not Connected"); + + int ret = rpc_port_proxy_vc_invoke_request_dialog(info->rpc_h, pid, disp_text, utt_text, continuous); + if (RPC_PORT_ERROR_NONE != ret) { + SLOG(LOG_ERROR, TAG_VCC, ">>>> Request vc request dialog : Fail to invoke message"); + return __covert_unhandled_error(ret); + } + + SLOG(LOG_DEBUG, TAG_VCC, "@@ vc request dialog : pid(%d), disp_text(%s), utt_text(%s), continuous(%d)", pid, disp_text, utt_text, continuous); + + return VC_ERROR_NONE; +} + +int vc_tidl_request_is_system_command_valid(int pid, bool* is_sys_cmd_valid) +{ + SLOG(LOG_INFO, TAG_VCC, "[TIDL] vc_tidl_request_is_system_command_valid"); + + vc_tidl_info_s* info = __get_tidl_info_s(pid); + RETVM_IF(NULL == info, VC_ERROR_INVALID_PARAMETER, "[ERROR] Fail to get tidl info"); + RETVM_IF(false == info->connected, VC_ERROR_OPERATION_FAILED, "[ERROR] Not Connected"); + + int ret = rpc_port_proxy_vc_invoke_is_system_command_valid(info->rpc_h, pid, is_sys_cmd_valid); + if (RPC_PORT_ERROR_NONE != ret) { + SLOG(LOG_ERROR, TAG_VCC, ">>>> Request vc is system command valid : Fail to invoke message"); + return __covert_unhandled_error(ret); + } + + SLOG(LOG_DEBUG, TAG_VCC, "@@ vc is system command valid : pid(%d), is_sys_cmd_valid(%d)", pid, *is_sys_cmd_valid); + + return VC_ERROR_NONE; +} + +/* Authority */ +int vc_tidl_request_auth_enable(int pid, int mgr_pid) +{ + SLOG(LOG_INFO, TAG_VCC, "[TIDL] vc_tidl_request_auth_enable"); + + vc_tidl_info_s* info = __get_tidl_info_s(pid); + RETVM_IF(NULL == info, VC_ERROR_INVALID_PARAMETER, "[ERROR] Fail to get tidl info"); + RETVM_IF(false == info->connected, VC_ERROR_OPERATION_FAILED, "[ERROR] Not Connected"); + + int ret = rpc_port_proxy_vc_invoke_auth_enable(info->rpc_h, pid, mgr_pid); + if (RPC_PORT_ERROR_NONE != ret) { + SLOG(LOG_ERROR, TAG_VCC, ">>>> Request vc auth enable : Fail to invoke message"); + return __covert_unhandled_error(ret); + } + + SLOG(LOG_DEBUG, TAG_VCC, "@@ vc auth enable : pid(%d), mgr_pid(%d)", pid, mgr_pid); + + return VC_ERROR_NONE; +} + +int vc_tidl_request_auth_disable(int pid, int mgr_pid) +{ + SLOG(LOG_INFO, TAG_VCC, "[TIDL] vc_tidl_request_auth_disable"); + + vc_tidl_info_s* info = __get_tidl_info_s(pid); + RETVM_IF(NULL == info, VC_ERROR_INVALID_PARAMETER, "[ERROR] Fail to get tidl info"); + RETVM_IF(false == info->connected, VC_ERROR_OPERATION_FAILED, "[ERROR] Not Connected"); + + int ret = rpc_port_proxy_vc_invoke_auth_disable(info->rpc_h, pid, mgr_pid); + if (RPC_PORT_ERROR_NONE != ret) { + SLOG(LOG_ERROR, TAG_VCC, ">>>> Request vc auth disable : Fail to invoke message"); + return __covert_unhandled_error(ret); + } + + SLOG(LOG_DEBUG, TAG_VCC, "@@ vc auth disable : pid(%d), mgr_pid(%d)", pid, mgr_pid); + + return VC_ERROR_NONE; +} + +int vc_tidl_request_auth_start(int pid, int mgr_pid) +{ + SLOG(LOG_INFO, TAG_VCC, "[TIDL] vc_tidl_request_auth_start"); + + vc_tidl_info_s* info = __get_tidl_info_s(pid); + RETVM_IF(NULL == info, VC_ERROR_INVALID_PARAMETER, "[ERROR] Fail to get tidl info"); + RETVM_IF(false == info->connected, VC_ERROR_OPERATION_FAILED, "[ERROR] Not Connected"); + + int ret = rpc_port_proxy_vc_invoke_auth_start(info->rpc_h, pid, mgr_pid); + if (RPC_PORT_ERROR_NONE != ret) { + SLOG(LOG_ERROR, TAG_VCC, ">>>> Request vc auth start : Fail to invoke message"); + return __covert_unhandled_error(ret); + } + + SLOG(LOG_DEBUG, TAG_VCC, "@@ vc auth start : pid(%d), mgr_pid(%d)", pid, mgr_pid); + + return VC_ERROR_NONE; +} + +int vc_tidl_request_auth_stop(int pid, int mgr_pid) +{ + SLOG(LOG_INFO, TAG_VCC, "[TIDL] vc_tidl_request_auth_stop"); + + vc_tidl_info_s* info = __get_tidl_info_s(pid); + RETVM_IF(NULL == info, VC_ERROR_INVALID_PARAMETER, "[ERROR] Fail to get tidl info"); + RETVM_IF(false == info->connected, VC_ERROR_OPERATION_FAILED, "[ERROR] Not Connected"); + + int ret = rpc_port_proxy_vc_invoke_auth_stop(info->rpc_h, pid, mgr_pid); + if (RPC_PORT_ERROR_NONE != ret) { + SLOG(LOG_ERROR, TAG_VCC, ">>>> Request vc auth stop : Fail to invoke message"); + return __covert_unhandled_error(ret); + } + + SLOG(LOG_DEBUG, TAG_VCC, "@@ vc auth stop : pid(%d), mgr_pid(%d)", pid, mgr_pid); + + return VC_ERROR_NONE; +} + +int vc_tidl_request_auth_cancel(int pid, int mgr_pid) +{ + SLOG(LOG_INFO, TAG_VCC, "[TIDL] vc_tidl_request_auth_cancel"); + + vc_tidl_info_s* info = __get_tidl_info_s(pid); + RETVM_IF(NULL == info, VC_ERROR_INVALID_PARAMETER, "[ERROR] Fail to get tidl info"); + RETVM_IF(false == info->connected, VC_ERROR_OPERATION_FAILED, "[ERROR] Not Connected"); + + int ret = rpc_port_proxy_vc_invoke_auth_cancel(info->rpc_h, pid, mgr_pid); + if (RPC_PORT_ERROR_NONE != ret) { + SLOG(LOG_ERROR, TAG_VCC, ">>>> Request vc auth cancel : Fail to invoke message"); + return __covert_unhandled_error(ret); + } + + SLOG(LOG_DEBUG, TAG_VCC, "@@ vc auth cancel : pid(%d), mgr_pid(%d)", pid, mgr_pid); + + return VC_ERROR_NONE; +} + +/* tts feedback */ +int vc_tidl_request_request_tts(int pid, const char* text, const char* language, bool to_vcm, int* utt_id) +{ + SLOG(LOG_INFO, TAG_VCC, "[TIDL] vc_tidl_request_request_tts"); + + vc_tidl_info_s* info = __get_tidl_info_s(pid); + RETVM_IF(NULL == info, VC_ERROR_INVALID_PARAMETER, "[ERROR] Fail to get tidl info"); + RETVM_IF(false == info->connected, VC_ERROR_OPERATION_FAILED, "[ERROR] Not Connected"); + + if (VC_ERROR_NONE != __invoke_register_feedback_callback(pid, info)) { + SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Fail to invoke register feedback callback"); + return VC_ERROR_OPERATION_FAILED; + } + + int ret = rpc_port_proxy_vc_invoke_request_tts(info->rpc_h, pid, text, language, to_vcm, utt_id); + if (RPC_PORT_ERROR_NONE != ret) { + SLOG(LOG_ERROR, TAG_VCC, ">>>> Request vc request tts : Fail to invoke message"); + return __covert_unhandled_error(ret); + } + + SLOG(LOG_DEBUG, TAG_VCC, "@@ vc request tts : pid(%d)", pid); + + return VC_ERROR_NONE; +} + +int vc_tidl_request_cancel_tts(int pid, int utt_id) +{ + SLOG(LOG_INFO, TAG_VCC, "[TIDL] vc_tidl_request_cancel_tts"); + + vc_tidl_info_s* info = __get_tidl_info_s(pid); + RETVM_IF(NULL == info, VC_ERROR_INVALID_PARAMETER, "[ERROR] Fail to get tidl info"); + RETVM_IF(false == info->connected, VC_ERROR_OPERATION_FAILED, "[ERROR] Not Connected"); + + int ret = rpc_port_proxy_vc_invoke_cancel_tts(info->rpc_h, pid, utt_id); + if (RPC_PORT_ERROR_NONE != ret) { + SLOG(LOG_ERROR, TAG_VCC, ">>>> Request vc cancel tts : Fail to invoke message"); + return __covert_unhandled_error(ret); + } + + SLOG(LOG_DEBUG, TAG_VCC, "@@ vc cancel tts : pid(%d), utt_id(%d)", pid, utt_id); + + return VC_ERROR_NONE; +} + +int vc_tidl_request_get_tts_audio_format(int pid, int* rate, vc_audio_channel_e* channel, vc_audio_type_e* audio_type) +{ + SLOG(LOG_INFO, TAG_VCC, "[TIDL] vc_tidl_request_get_tts_audio_format"); + + vc_tidl_info_s* info = __get_tidl_info_s(pid); + RETVM_IF(NULL == info, VC_ERROR_INVALID_PARAMETER, "[ERROR] Fail to get tidl info"); + RETVM_IF(false == info->connected, VC_ERROR_OPERATION_FAILED, "[ERROR] Not Connected"); + + int ret = rpc_port_proxy_vc_invoke_get_tts_audio_format(info->rpc_h, pid, rate, (int*)channel, (int*)audio_type); + if (RPC_PORT_ERROR_NONE != ret) { + SLOG(LOG_ERROR, TAG_VCC, ">>>> Request vc get tts audio format: Fail to invoke message"); + return __covert_unhandled_error(ret); + } + + SLOG(LOG_DEBUG, TAG_VCC, "@@ vc get tts audio format : pid(%d), rate(%d), channel(%d), audio_type(%d)", pid, *rate, *channel, *audio_type); + + return VC_ERROR_NONE; +} diff --git a/client/vc_tidl.h b/client/vc_tidl.h new file mode 100755 index 0000000..7b84703 --- /dev/null +++ b/client/vc_tidl.h @@ -0,0 +1,83 @@ +/* +* 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_TIDL_H_ +#define __VC_TIDL_H_ + +#include "voice_control_common.h" + +#ifdef __cplusplus +extern "C" { +#endif + +int vc_tidl_open_connection(); + +int vc_tidl_close_connection(); + + +int vc_tidl_request_hello(); + +int vc_tidl_request_initialize(int pid, int* mgr_pid, int* service_state, int* daemon_pid); + +int vc_tidl_request_finalize(int pid); + +int vc_tidl_request_set_command(int pid, vc_cmd_type_e cmd_type); + +int vc_tidl_request_unset_command(int pid, vc_cmd_type_e cmd_type); + +int vc_tidl_request_set_foreground(int pid, bool value); + +int vc_tidl_request_set_server_dialog(int pid, const char* app_id, const char* credential); + +int vc_tidl_request_request_dialog(int pid, const char* disp_text, const char* utt_text, bool continuous); + +int vc_tidl_request_is_system_command_valid(int pid, bool* is_sys_cmd_valid); + +#if 0 +int vc_tidl_request_start(int pid, int silence); + +int vc_tidl_request_stop(int pid); + +int vc_tidl_request_cancel(int pid); + +int vc_tidl_request_set_exclusive_command(int pid, bool value); +#endif + +/* Authority */ +int vc_tidl_request_auth_enable(int pid, int mgr_pid); + +int vc_tidl_request_auth_disable(int pid, int mgr_pid); + +int vc_tidl_request_auth_start(int pid, int mgr_pid); + +int vc_tidl_request_auth_stop(int pid, int mgr_pid); + +int vc_tidl_request_auth_cancel(int pid, int mgr_pid); + +/* tts feedback */ + +int vc_tidl_request_request_tts(int pid, const char* text, const char* language, bool to_vcm, int* utt_id); + +int vc_tidl_request_cancel_tts(int pid, int utt_id); + +int vc_tidl_request_get_tts_audio_format(int pid, int* rate, vc_audio_channel_e* channel, vc_audio_type_e* audio_type); + +#ifdef __cplusplus +} +#endif + +#endif /* __VC_TIDL_H_ */ diff --git a/common/vc_defs.h b/common/vc_defs.h index 81226ca..cbe89eb 100644 --- a/common/vc_defs.h +++ b/common/vc_defs.h @@ -59,6 +59,21 @@ extern "C" { #define VC_ENGINE_DB_DEFAULT "db/voice/vc/engine/default" /****************************************************************************************** +* Message Definitions for Bundle +*******************************************************************************************/ +#define VC_BUNDLE_METHOD "method" +#define VC_BUNDLE_SERVICE_STATE "service_state" +#define VC_BUNDLE_MANAGER_PID "manager_pid" +#define VC_BUNDLE_REASON "reason" +#define VC_BUNDLE_DAEMON_PID "daemon_pid" +#define VC_BUNDLE_ERR_MSG "err_msg" +#define VC_BUNDLE_PID "pid" +#define VC_BUNDLE_UTTID "uttid" +#define VC_BUNDLE_UTTSTATUS "uttstatus" +#define VC_BUNDLE_FEEDBACK_EVENT "feedback_event" +#define VC_BUNDLE_LENGTH "length" + +/****************************************************************************************** * Message Definition for all *******************************************************************************************/ @@ -267,6 +282,7 @@ extern "C" { #define VC_CONNECTION_RETRY_COUNT 10 #define VC_INVALID_TTS_UID 0 #define VC_TIDL_RETRY_COUNT 100 +#define VC_ENGINE_APPID_LEN 256 #define VC_FEATURE_PATH "tizen.org/feature/speech.control" #define VC_MGR_FEATURE_PATH "tizen.org/feature/speech.control_manager" diff --git a/common/vc_main.h b/common/vc_main.h index 15e94f9..00e079a 100644 --- a/common/vc_main.h +++ b/common/vc_main.h @@ -57,6 +57,34 @@ typedef struct vc_s *vc_h; #define FREE(x) { if (NULL != x) { free(x); x = NULL; } } #define G_FREE(x) { if (NULL != x) { g_free(x); x = NULL; } } +#define COLOR_RED "\033[0;31m" +#define COLOR_GREEN "\033[0;32m" +#define COLOR_BROWN "\033[0;33m" +#define COLOR_BLUE "\033[0;34m" +#define COLOR_PURPLE "\033[0;35m" +#define COLOR_CYAN "\033[0;36m" +#define COLOR_LIGHTBLUE "\033[0;37m" +#define COLOR_END "\033[0;m" + +#define PERR(fmt, args...) LOGE(COLOR_RED "* Critical * " fmt COLOR_END, ##args) + +#define RETM_IF(expr, fmt, arg...) \ +do { \ + if (expr) { \ + PERR(fmt, ##arg); \ + return; \ + } \ +} while (0) + +#define RETVM_IF(expr, val, fmt, arg...) \ +do { \ + if (expr) { \ + PERR(fmt, ##arg); \ + return (val); \ + } \ +} while (0) + + #ifdef __cplusplus } #endif diff --git a/packaging/voice-control.spec b/packaging/voice-control.spec index 2498f9c..bbe1861 100644 --- a/packaging/voice-control.spec +++ b/packaging/voice-control.spec @@ -34,12 +34,13 @@ BuildRequires: pkgconfig(sqlite3) BuildRequires: pkgconfig(pkgmgr-info) BuildRequires: pkgconfig(pkgmgr-installer) BuildRequires: pkgconfig(vconf) -BuildRequires: cmake BuildRequires: pkgconfig(gmock) -BuildRequires: tidl BuildRequires: pkgconfig(rpc-port) BuildRequires: pkgconfig(bundle) +BuildRequires: cmake +BuildRequires: tidl + %if 0%{?gcov:1} BuildRequires: lcov BuildRequires: zip @@ -114,6 +115,9 @@ GTest for Voice Control %setup -q -n %{name}-%{version} cp %{SOURCE1001} %{SOURCE1002} . +tidlc -p -l C -i tidl/vc.tidl -o vc_proxy +tidlc -s -l C -i tidl/vc.tidl -o vcd_stub + 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 diff --git a/server/vcd_client_data.c b/server/vcd_client_data.c index f9bdec8..8d5136d 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; +/* Client IPC info list */ +static GSList* g_client_ipc_info_list = NULL; + /* Manager IPC info */ static manager_tidl_info_s* g_mgr_tidl_info = NULL; @@ -1226,6 +1229,223 @@ int vcd_client_delete(int pid) return 0; } +GSList* __get_client_ipc_info_item(const int pid) +{ + GSList *iter = NULL; + client_ipc_info_s *data = NULL; + + int count = g_slist_length(g_client_ipc_info_list); + int i; + + if (0 < count) { + iter = g_slist_nth(g_client_ipc_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; +} + +client_ipc_info_s* __get_client_ipc_info_element(int pid) +{ + GSList *iter = NULL; + client_ipc_info_s *data = NULL; + + int count = g_slist_length(g_client_ipc_info_list); + int i; + + if (0 < count) { + iter = g_slist_nth(g_client_ipc_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_add_ipc_info(int pid) +{ + /*Check pid is duplicated*/ + client_ipc_info_s* info = NULL; + info = __get_client_ipc_info_element(pid); + + if (NULL != info) { + SLOG(LOG_WARN, TAG_VCD, "[Client Data] Client ipc info pid is already registered"); + return VCD_ERROR_NONE; + } + + SLOG(LOG_INFO, TAG_VCD, "[Client Data] There is no ipc info of pid(%d). Create new one.", pid); + info = (client_ipc_info_s*)calloc(1, sizeof(client_ipc_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->feedback_cb = NULL; + info->feedback_cb_user_data = NULL; + + g_client_ipc_info_list = g_slist_append(g_client_ipc_info_list, info); + if (NULL == g_client_ipc_info_list) { + SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] Fail to add new client ipc info"); + + free(info); + info = NULL; + + return -1; + } else { + SLOG(LOG_INFO, TAG_VCD, "[Client Data SUCCESS] Add new client ipc info. pid(%d)", pid); + } + + return VCD_ERROR_NONE; +} + +int vcd_client_set_ipc_notify_cb(int pid, rpc_port_stub_vc_notify_cb_h callback, void* user_data) +{ + /*Check pid*/ + client_ipc_info_s* info = NULL; + info = __get_client_ipc_info_element(pid); + + if (NULL == info) { + SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] There is no ipc info in the list. pid(%d)", pid); + return VCD_ERROR_INVALID_PARAMETER; + } + + int ret = -1; + ret = rpc_port_stub_vc_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_unset_ipc_notify_cb(int pid) +{ + /*Check pid*/ + client_ipc_info_s* info = NULL; + info = __get_client_ipc_info_element(pid); + + if (NULL == info) { + SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] There is no ipc info in the list. pid(%d)", pid); + return VCD_ERROR_INVALID_PARAMETER; + } + + int ret = -1; + ret = rpc_port_stub_vc_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_set_ipc_feedback_cb(int pid, rpc_port_stub_vc_feedback_cb_h callback, void* user_data) +{ + /*Check pid*/ + client_ipc_info_s* info = NULL; + info = __get_client_ipc_info_element(pid); + + if (NULL == info) { + SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] There is no ipc info in the list. pid(%d)", pid); + return VCD_ERROR_INVALID_PARAMETER; + } + + int ret = -1; + ret = rpc_port_stub_vc_feedback_cb_clone(callback, &(info->feedback_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); + } + info->feedback_cb_user_data = user_data; + + return VCD_ERROR_NONE; +} + +int vcd_client_unset_ipc_feedback_cb(int pid) +{ + /*Check pid*/ + client_ipc_info_s* info = NULL; + info = __get_client_ipc_info_element(pid); + + if (NULL == info) { + SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] There is no ipc info in the list. pid(%d)", pid); + return VCD_ERROR_INVALID_PARAMETER; + } + + int ret = -1; + ret = rpc_port_stub_vc_feedback_cb_destroy(info->feedback_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); + } + info->feedback_cb = NULL; + info->feedback_cb_user_data = NULL; + + return VCD_ERROR_NONE; +} + +int vcd_client_delete_ipc_info(int pid) +{ + GSList *tmp = NULL; + client_ipc_info_s* client_ipc_info = NULL; + + /*Get handle*/ + tmp = __get_client_ipc_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 client structure*/ + client_ipc_info = tmp->data; + if (NULL != client_ipc_info) { + free(client_ipc_info); + } + + /*Remove handle from list*/ + g_client_ipc_info_list = g_slist_remove_link(g_client_ipc_info_list, tmp); + + return 0; +} + +client_ipc_info_s* vcd_client_get_ipc_info(int pid) +{ + return __get_client_ipc_info_element(pid); +} + bool vcd_client_is_available(int pid) { vc_client_info_s* client_info = NULL; diff --git a/server/vcd_client_data.h b/server/vcd_client_data.h index 317e1d5..0620b19 100644 --- a/server/vcd_client_data.h +++ b/server/vcd_client_data.h @@ -21,6 +21,7 @@ #include #include "vc_command.h" #include "vc_info_parser.h" +#include "vcd_stub.h" #include "vcd_mgr_stub.h" #include "vcd_mgr_proxy.h" #include "vcd_widget_stub.h" @@ -71,7 +72,14 @@ typedef struct { typedef struct { int pid; + rpc_port_stub_vc_notify_cb_h notify_cb; + void* notify_cb_user_data; + rpc_port_stub_vc_feedback_cb_h feedback_cb; + void* feedback_cb_user_data; +} client_ipc_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; @@ -182,6 +190,20 @@ int vcd_client_add(int pid); int vcd_client_delete(int pid); +int vcd_client_add_ipc_info(int pid); + +int vcd_client_set_ipc_notify_cb(int pid, rpc_port_stub_vc_notify_cb_h callback, void* user_data); + +int vcd_client_unset_ipc_notify_cb(int pid); + +int vcd_client_set_ipc_feedback_cb(int pid, rpc_port_stub_vc_feedback_cb_h callback, void* user_data); + +int vcd_client_unset_ipc_feedback_cb(int pid); + +int vcd_client_delete_ipc_info(int pid); + +client_ipc_info_s* vcd_client_get_ipc_info(int pid); + bool vcd_client_is_available(int pid); int vcd_client_get_ref_count(); diff --git a/server/vcd_dbus.c b/server/vcd_dbus.c index 54bf596..f7cfc10 100755 --- a/server/vcd_dbus.c +++ b/server/vcd_dbus.c @@ -108,73 +108,71 @@ int vcd_check_dbus_connection() return 0; } -int vcdc_send_hello(int pid, vcd_client_type_e type) -{ - if (0 != __dbus_check()) { - return VCD_ERROR_OPERATION_FAILED; - } - - DBusMessage* msg = NULL; - - 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; - } else if (VCD_CLIENT_TYPE_MANAGER == type) { - 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; - } - - 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_INVALID); - - DBusError err; - dbus_error_init(&err); - - DBusMessage* result_msg; - int result = -1; - - 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 0; - } - } - 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, "[Dbus] Get arguments error (%s)", err.message); - dbus_error_free(&err); - result = VCD_ERROR_OPERATION_FAILED; - } - - dbus_message_unref(result_msg); - } else { - SLOG(LOG_WARN, TAG_VCD, "[Dbus] Result message is NULL. Client is not available"); - } - - return result; -} +// int vcdc_send_hello(int pid, vcd_client_type_e type) +// { +// if (0 != __dbus_check()) { +// return VCD_ERROR_OPERATION_FAILED; +// } + +// DBusMessage* msg = NULL; + +// 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); +// } else if (VCD_CLIENT_TYPE_MANAGER == type) { +// 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; +// } + +// 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_INVALID); + +// DBusError err; +// dbus_error_init(&err); + +// DBusMessage* result_msg; +// int result = -1; + +// 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 0; +// } +// } +// 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, "[Dbus] Get arguments error (%s)", err.message); +// dbus_error_free(&err); +// result = VCD_ERROR_OPERATION_FAILED; +// } + +// dbus_message_unref(result_msg); +// } else { +// SLOG(LOG_WARN, TAG_VCD, "[Dbus] Result message is NULL. Client is not available"); +// } + +// return result; +// } +/* int vcdc_send_result(int pid, int manager_pid, int cmd_type) { if (0 != __dbus_check()) { @@ -204,10 +202,6 @@ 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, VCD_CLIENT_TYPE_MANAGER); - return 0; default: SLOG(LOG_ERROR, TAG_VCD, "[Dbus ERROR] Command type is NOT valid(%d)", cmd_type); @@ -233,7 +227,7 @@ int vcdc_send_result(int pid, int manager_pid, int cmd_type) return 0; } - +*/ int vcdc_send_manager_pid(int manager_pid) { DBusError err; @@ -416,7 +410,7 @@ int vcdc_send_error_signal(int reason, char *err_msg) return 0; } - +/* int vcdc_send_error_signal_to_app(int pid, int reason, char *err_msg) { if (NULL == err_msg) { @@ -456,7 +450,10 @@ int vcdc_send_error_signal_to_app(int pid, int reason, char *err_msg) return VCD_ERROR_NONE; } +*/ +/* +>>>>>>> Replace IPC (VCC) from dbus to tidl 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); @@ -468,7 +465,7 @@ int vcdc_send_feedback_streaming(int pid, int utt_id, vc_feedback_event_e event, DBusError err; dbus_error_init(&err); - /* make dbus message */ + // make dbus message DBusMessage* msg = NULL; msg = __get_message(pid, VCD_METHOD_FEEDBACK_STREAMING, VCD_CLIENT_TYPE_NORMAL); if (NULL == msg) { @@ -499,7 +496,7 @@ int vcdc_send_feedback_streaming(int pid, int utt_id, vc_feedback_event_e event, return ret; } - +*/ static Eina_Bool listener_event_callback(void* data, Ecore_Fd_Handler *fd_handler) { if (NULL == g_conn_listener) return ECORE_CALLBACK_RENEW; diff --git a/server/vcd_dbus.h b/server/vcd_dbus.h index fcfaad3..d6ae86c 100644 --- a/server/vcd_dbus.h +++ b/server/vcd_dbus.h @@ -30,18 +30,18 @@ int vcd_dbus_close_connection(); int vcd_check_dbus_connection(); -int vcdc_send_hello(int pid, vcd_client_type_e type); +// int vcdc_send_hello(int pid, vcd_client_type_e type); -int vcdc_send_result(int pid, int manager_pid, int cmd_type); +//int vcdc_send_result(int pid, int manager_pid, int cmd_type); 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_error_signal_to_app(int pid, int reason, char *err_msg); int vcdc_send_manager_pid(int manager_pid); /* 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(int pid, int utt_id, vc_feedback_event_e event, char* buffer, int len); #ifdef __cplusplus } diff --git a/server/vcd_stub.c b/server/vcd_stub.c new file mode 100755 index 0000000..e84a2e3 --- /dev/null +++ b/server/vcd_stub.c @@ -0,0 +1,2422 @@ +/* + * Generated by tidlc 1.8.1. + */ + +#ifndef _GNU_SOURCE +#define _GNU_SOURCE +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "vcd_stub.h" + +#undef LOG_TAG +#define LOG_TAG "RPC_PORT_STUB" + +#undef _E +#define _E(fmt, ...) dlog_print(DLOG_ERROR, LOG_TAG, "%s: %s(%d) > "fmt, basename(__FILE__), __FUNCTION__, __LINE__, ##__VA_ARGS__) + +#undef _W +#define _W(fmt, ...) dlog_print(DLOG_WARN, LOG_TAG, "%s: %s(%d) > "fmt, basename(__FILE__), __FUNCTION__, __LINE__, ##__VA_ARGS__) + +#undef _I +#define _I(fmt, ...) dlog_print(DLOG_INFO, LOG_TAG, "%s: %s(%d) > "fmt, basename(__FILE__), __FUNCTION__, __LINE__, ##__VA_ARGS__) + +#undef _D +#define _D(fmt, ...) dlog_print(DLOG_DEBUG, LOG_TAG, "%s: %s(%d) > "fmt, basename(__FILE__), __FUNCTION__, __LINE__, ##__VA_ARGS__) + +#ifndef TIDL_VERSION +#define TIDL_VERSION "1.8.1" +#endif + +#ifndef nullptr +#define nullptr NULL +#endif + +#ifndef ARRAY_SIZE +#define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0])) +#endif + +#ifndef STRING_GET +#define STRING_GET(x) ((x) ? x : "") +#endif + +typedef int (*rpc_port_stub_method_handler)(rpc_port_h port, rpc_port_parcel_h parcel, void *data); + +typedef enum { + RPC_PORT_STUB_VC_METHOD_RESULT_, + RPC_PORT_STUB_VC_METHOD_CALLBACK_, + RPC_PORT_STUB_VC_METHOD_REGISTER_NOTIFY_CB, + RPC_PORT_STUB_VC_METHOD_REGISTER_NOTIFY_CB_SYNC, + RPC_PORT_STUB_VC_METHOD_REGISTER_FEEDBACK_CB, + RPC_PORT_STUB_VC_METHOD_REGISTER_FEEDBACK_CB_SYNC, + RPC_PORT_STUB_VC_METHOD_INITIALIZE, + RPC_PORT_STUB_VC_METHOD_FINALIZE, + RPC_PORT_STUB_VC_METHOD_SET_COMMAND, + RPC_PORT_STUB_VC_METHOD_UNSET_COMMAND, + RPC_PORT_STUB_VC_METHOD_SET_FOREGROUND, + RPC_PORT_STUB_VC_METHOD_SET_SERVER_DIALOG, + RPC_PORT_STUB_VC_METHOD_REQUEST_DIALOG, + RPC_PORT_STUB_VC_METHOD_IS_SYSTEM_COMMAND_VALID, + RPC_PORT_STUB_VC_METHOD_AUTH_ENABLE, + RPC_PORT_STUB_VC_METHOD_AUTH_DISABLE, + RPC_PORT_STUB_VC_METHOD_AUTH_START, + RPC_PORT_STUB_VC_METHOD_AUTH_STOP, + RPC_PORT_STUB_VC_METHOD_AUTH_CANCEL, + RPC_PORT_STUB_VC_METHOD_REQUEST_TTS, + RPC_PORT_STUB_VC_METHOD_CANCEL_TTS, + RPC_PORT_STUB_VC_METHOD_GET_TTS_AUDIO_FORMAT, +} rpc_port_stub_vc_method_e; + +typedef enum { + RPC_PORT_STUB_VC_DELEGATE_NOTIFY_CB = 1, + RPC_PORT_STUB_VC_DELEGATE_FEEDBACK_CB = 2, +} rpc_port_stub_vc_delegate_e; + +typedef struct rpc_port_stub_array_char_s { + rpc_port_parcelable_t parcelable; + char *value; + int size; +} rpc_port_stub_array_char_t; + +typedef struct rpc_port_stub_vc_notify_cb_s { + rpc_port_parcelable_t parcelable; + rpc_port_h port; + int id; + int seq_id; + bool once; + bool valid; +} rpc_port_stub_vc_notify_cb_t; + +typedef struct rpc_port_stub_vc_feedback_cb_s { + rpc_port_parcelable_t parcelable; + rpc_port_h port; + int id; + int seq_id; + bool once; + bool valid; +} rpc_port_stub_vc_feedback_cb_t; + +static bool __rpc_port_stub_vc_exist_callback_port(rpc_port_h callback_port); + +typedef struct rpc_port_stub_vc_context_s { + char *sender; + char *instance; + rpc_port_h port; + rpc_port_h callback_port; + void *tag; + rpc_port_stub_vc_callback_s callback; + void *user_data; +#ifdef TIDL_THREAD_ENABLE + GThread *thread; + GQueue *queue; + GMutex mutex; + GCond cond; + bool done; +#endif /* TIDL_THREAD_ENABLE */ +} rpc_port_stub_vc_context_t; + +typedef struct rpc_port_stub_vc_s { + rpc_port_stub_h stub; + rpc_port_stub_vc_callback_s callback; + void *user_data; + GList* contexts; + GList* callback_ports; + GRecMutex mutex; +} rpc_port_stub_vc_t; + +static rpc_port_stub_vc_t __vc; + +static void __rpc_port_stub_array_char_to(rpc_port_parcel_h parcel, void *data) +{ + rpc_port_stub_array_char_h h = data; + int i; + + if (parcel == nullptr || h == nullptr) { + _E("Invalid parameter"); + return; + } + + rpc_port_parcel_write_array_count(parcel, h->size); + + for (i = 0; i < h->size; ++i) + rpc_port_parcel_write_byte(parcel, h->value[i]); +} + +static void __rpc_port_stub_array_char_from(rpc_port_parcel_h parcel, void *data) +{ + rpc_port_stub_array_char_h h = data; + char value; + int ret; + int i; + + if (parcel == nullptr || h == nullptr) { + _E("Invalid parameter"); + set_last_result(RPC_PORT_ERROR_INVALID_PARAMETER); + return; + } + + ret = rpc_port_parcel_read_array_count(parcel, &h->size); + if (ret != RPC_PORT_ERROR_NONE) { + _E("Failed to read array count. error(%d)", ret); + set_last_result(ret); + return; + } + + h->value = calloc(h->size, sizeof(char)); + if (h->value == nullptr) { + _E("Out of memory"); + set_last_result(RPC_PORT_ERROR_OUT_OF_MEMORY); + return; + } + + for (i = 0; i < h->size; ++i) { + rpc_port_parcel_read_byte(parcel, &value); + h->value[i] = value; + } + + set_last_result(RPC_PORT_ERROR_NONE); +} + +int rpc_port_stub_array_char_create(rpc_port_stub_array_char_h *h) +{ + rpc_port_stub_array_char_t *handle; + + if (h == nullptr) { + _E("Invalid parameter"); + return RPC_PORT_ERROR_INVALID_PARAMETER; + } + + handle = calloc(1, sizeof(rpc_port_stub_array_char_t)); + if (handle == nullptr) { + _E("Out of memory"); + return RPC_PORT_ERROR_OUT_OF_MEMORY; + } + + handle->parcelable.to = __rpc_port_stub_array_char_to; + handle->parcelable.from = __rpc_port_stub_array_char_from; + + *h = handle; + + return RPC_PORT_ERROR_NONE; +} + +int rpc_port_stub_array_char_destroy(rpc_port_stub_array_char_h h) +{ + if (h == nullptr) { + _E("Invalid parameter"); + return RPC_PORT_ERROR_INVALID_PARAMETER; + } + + if (h->value) + free(h->value); + + free(h); + + return RPC_PORT_ERROR_NONE; +} + +int rpc_port_stub_array_char_clone(rpc_port_stub_array_char_h h, rpc_port_stub_array_char_h *clone) +{ + rpc_port_stub_array_char_h handle; + rpc_port_parcel_h parcel; + int ret; + + if (h == nullptr || clone == nullptr) { + _E("Invalid parameter"); + return RPC_PORT_ERROR_INVALID_PARAMETER; + } + + ret = rpc_port_stub_array_char_create(&handle); + if (ret != RPC_PORT_ERROR_NONE) { + _E("Failed to create handle. error(%d)", ret); + return ret; + } + + ret = rpc_port_parcel_create(&parcel); + if (ret != RPC_PORT_ERROR_NONE) { + _E("Failed to create parcel handle. error(%d)", ret); + rpc_port_stub_array_char_destroy(handle); + return ret; + } + + rpc_port_parcel_write(parcel, &h->parcelable, h); + rpc_port_parcel_read(parcel, &handle->parcelable, handle); + ret = get_last_result(); + rpc_port_parcel_destroy(parcel); + + if (ret != RPC_PORT_ERROR_NONE) { + _E("Failed to read data. error(%d)", ret); + rpc_port_stub_array_char_destroy(handle); + return ret; + } + + *clone = handle; + + return RPC_PORT_ERROR_NONE; +} + +int rpc_port_stub_array_char_set(rpc_port_stub_array_char_h h, char *value, int size) +{ + rpc_port_stub_array_char_h handle; + rpc_port_stub_array_char_h clone; + int ret; + + if (h == nullptr || value == nullptr || size <= 0) { + _E("Invalid parameter"); + return RPC_PORT_ERROR_INVALID_PARAMETER; + } + + ret = rpc_port_stub_array_char_create(&handle); + if (ret != RPC_PORT_ERROR_NONE) { + _E("Failed to create handle. error(%d)", ret); + return ret; + } + + handle->value = (char *)value; + handle->size = size; + + ret = rpc_port_stub_array_char_clone(handle, &clone); + if (ret != RPC_PORT_ERROR_NONE) { + _E("Failed to clone handle. error(%d)", ret); + handle->value = nullptr; + handle->size = 0; + rpc_port_stub_array_char_destroy(handle); + return ret; + } + + handle->value = h->value; + handle->size = h->size; + rpc_port_stub_array_char_destroy(handle); + + h->value = clone->value; + h->size = clone->size; + + clone->value = nullptr; + clone->size = 0; + rpc_port_stub_array_char_destroy(clone); + + return RPC_PORT_ERROR_NONE; +} + +int rpc_port_stub_array_char_get(rpc_port_stub_array_char_h h, char **value, int *size) +{ + rpc_port_stub_array_char_h handle; + int ret; + + if (h == nullptr || value == nullptr || size == nullptr) { + _E("Invalid parameter"); + return RPC_PORT_ERROR_INVALID_PARAMETER; + } + + ret = rpc_port_stub_array_char_clone(h, &handle); + if (ret != RPC_PORT_ERROR_NONE) { + _E("Failed to clone handle. error(%d)", ret); + return ret; + } + + *value = handle->value; + *size = handle->size; + + handle->value = nullptr; + handle->size = 0; + rpc_port_stub_array_char_destroy(handle); + + return RPC_PORT_ERROR_NONE; +} + +static void __rpc_port_stub_vc_notify_cb_to(rpc_port_parcel_h parcel, void *user_data) +{ + rpc_port_stub_vc_notify_cb_h h = user_data; + + if (parcel == nullptr || h == nullptr) { + _E("Invalid parameter"); + return; + } + + rpc_port_parcel_write_int32(parcel, h->id); + + rpc_port_parcel_write_int32(parcel, h->seq_id); + + rpc_port_parcel_write_bool(parcel, h->once); + + _I("id(%d), seq_id(%d), once(%s)", h->id, h->seq_id, h->once ? "true" : "false"); +} + +static void __rpc_port_stub_vc_notify_cb_from(rpc_port_parcel_h parcel, void *user_data) +{ + rpc_port_stub_vc_notify_cb_h h = user_data; + + if (parcel == nullptr || h == nullptr) { + _E("Invalid parameter"); + set_last_result(RPC_PORT_ERROR_INVALID_PARAMETER); + return; + } + + rpc_port_parcel_read_int32(parcel, &h->id); + + rpc_port_parcel_read_int32(parcel, &h->seq_id); + + rpc_port_parcel_read_bool(parcel, &h->once); + + _I("id(%d), seq_id(%d), once(%s)", h->id, h->seq_id, h->once ? "true" : "false"); + set_last_result(RPC_PORT_ERROR_NONE); +} + +int rpc_port_stub_vc_notify_cb_create(rpc_port_stub_vc_notify_cb_h *h) +{ + rpc_port_stub_vc_notify_cb_t *handle; + static int seq_num; + + if (h == nullptr) { + _E("Invalid parameter"); + return RPC_PORT_ERROR_INVALID_PARAMETER; + } + + handle = calloc(1, sizeof(rpc_port_stub_vc_notify_cb_t)); + if (handle == nullptr) { + _E("Out of memory"); + return RPC_PORT_ERROR_OUT_OF_MEMORY; + } + + handle->parcelable.to = __rpc_port_stub_vc_notify_cb_to; + handle->parcelable.from = __rpc_port_stub_vc_notify_cb_from; + handle->id = RPC_PORT_STUB_VC_DELEGATE_NOTIFY_CB; + handle->seq_id = g_atomic_int_add(&seq_num, 1) + 1; + handle->once = false; + handle->valid = true; + _I("id(%d), seq_id(%d)", handle->id, handle->seq_id); + + *h = handle; + + return RPC_PORT_ERROR_NONE; +} + +int rpc_port_stub_vc_notify_cb_destroy(rpc_port_stub_vc_notify_cb_h h) +{ + if (h == nullptr) { + _E("Invalid parameter"); + return RPC_PORT_ERROR_INVALID_PARAMETER; + } + + _W("id(%d), seq_id(%d), once(%s)", h->id, h->seq_id, h->once ? "true" : "false"); + + free(h); + + return RPC_PORT_ERROR_NONE; +} + +int rpc_port_stub_vc_notify_cb_clone(rpc_port_stub_vc_notify_cb_h h, rpc_port_stub_vc_notify_cb_h *clone) +{ + rpc_port_stub_vc_notify_cb_h handle; + int ret; + + if (h == nullptr || clone == nullptr) { + _E("Invalid parameter"); + return RPC_PORT_ERROR_INVALID_PARAMETER; + } + + ret = rpc_port_stub_vc_notify_cb_create(&handle); + if (ret != RPC_PORT_ERROR_NONE) { + _E("Failed to create handle. error(%d)", ret); + return ret; + } + + handle->port = h->port; + handle->seq_id = h->seq_id; + handle->once = h->once; + handle->valid = h->valid; + + *clone = handle; + + return RPC_PORT_ERROR_NONE; +} + +int rpc_port_stub_vc_notify_cb_get_id(rpc_port_stub_vc_notify_cb_h h, int *id) +{ + if (h == nullptr || id == nullptr) { + _E("Invalid parameter"); + return RPC_PORT_ERROR_INVALID_PARAMETER; + } + + *id = h->id; + + return RPC_PORT_ERROR_NONE; +} + +int rpc_port_stub_vc_notify_cb_get_seq_id(rpc_port_stub_vc_notify_cb_h h, int *seq_id) +{ + if (h == nullptr || seq_id == nullptr) { + _E("Invalid parameter"); + return RPC_PORT_ERROR_INVALID_PARAMETER; + } + + *seq_id = h->seq_id; + + return RPC_PORT_ERROR_NONE; +} + +int rpc_port_stub_vc_notify_cb_is_once(rpc_port_stub_vc_notify_cb_h h, bool *once) +{ + if (h == nullptr || once == nullptr) { + _E("Invalid parameter"); + return RPC_PORT_ERROR_INVALID_PARAMETER; + } + + *once = h->once; + + return RPC_PORT_ERROR_NONE; +} + +int rpc_port_stub_vc_notify_cb_get_tag(rpc_port_stub_vc_notify_cb_h h, char **tag) +{ + char *value; + char buf[128]; + + if (h == nullptr || tag == nullptr) { + _E("Invalid parameter"); + return RPC_PORT_ERROR_INVALID_PARAMETER; + } + + snprintf(buf, sizeof(buf), "%d::%d", h->id, h->seq_id); + value = strdup(buf); + if (value == nullptr) { + _E("Out of memory"); + return RPC_PORT_ERROR_OUT_OF_MEMORY; + } + + *tag = value; + + return RPC_PORT_ERROR_NONE; +} + +int rpc_port_stub_vc_notify_cb_set_port(rpc_port_stub_vc_notify_cb_h h, rpc_port_h port) +{ + if (h == nullptr || port == nullptr) { + _E("Invalid parameter"); + return RPC_PORT_ERROR_INVALID_PARAMETER; + } + + h->port = port; + + return RPC_PORT_ERROR_NONE; +} + +int rpc_port_stub_vc_notify_cb_invoke(rpc_port_stub_vc_notify_cb_h h, int pid, bundle *msg) +{ + rpc_port_parcel_h parcel_; + int ret_; + + if (h == nullptr || h->port == nullptr || msg == nullptr) { + _E("Invalid parameter"); + return RPC_PORT_ERROR_INVALID_PARAMETER; + } + + if (!__rpc_port_stub_vc_exist_callback_port(h->port)) { + _E("Not connected"); + return RPC_PORT_ERROR_INVALID_PARAMETER; + } + + if (h->once && !h->valid) { + _E("The delegate handle is already used"); + return RPC_PORT_ERROR_INVALID_PARAMETER; + } + + ret_ = rpc_port_parcel_create(&parcel_); + if (ret_ != RPC_PORT_ERROR_NONE) { + _E("Failed to create parcel handle. error(%d)", ret_); + return ret_; + } + + rpc_port_parcel_write_int32(parcel_, RPC_PORT_STUB_VC_METHOD_CALLBACK_); + + rpc_port_parcel_write(parcel_, &h->parcelable, h); + + rpc_port_parcel_write_int32(parcel_, pid); + + rpc_port_parcel_write_bundle(parcel_, msg); + + ret_ = rpc_port_parcel_send(parcel_, h->port); + rpc_port_parcel_destroy(parcel_); + h->valid = false; + + return ret_; +} + +static void __rpc_port_stub_vc_feedback_cb_to(rpc_port_parcel_h parcel, void *user_data) +{ + rpc_port_stub_vc_feedback_cb_h h = user_data; + + if (parcel == nullptr || h == nullptr) { + _E("Invalid parameter"); + return; + } + + rpc_port_parcel_write_int32(parcel, h->id); + + rpc_port_parcel_write_int32(parcel, h->seq_id); + + rpc_port_parcel_write_bool(parcel, h->once); + + _I("id(%d), seq_id(%d), once(%s)", h->id, h->seq_id, h->once ? "true" : "false"); +} + +static void __rpc_port_stub_vc_feedback_cb_from(rpc_port_parcel_h parcel, void *user_data) +{ + rpc_port_stub_vc_feedback_cb_h h = user_data; + + if (parcel == nullptr || h == nullptr) { + _E("Invalid parameter"); + set_last_result(RPC_PORT_ERROR_INVALID_PARAMETER); + return; + } + + rpc_port_parcel_read_int32(parcel, &h->id); + + rpc_port_parcel_read_int32(parcel, &h->seq_id); + + rpc_port_parcel_read_bool(parcel, &h->once); + + _I("id(%d), seq_id(%d), once(%s)", h->id, h->seq_id, h->once ? "true" : "false"); + set_last_result(RPC_PORT_ERROR_NONE); +} + +int rpc_port_stub_vc_feedback_cb_create(rpc_port_stub_vc_feedback_cb_h *h) +{ + rpc_port_stub_vc_feedback_cb_t *handle; + static int seq_num; + + if (h == nullptr) { + _E("Invalid parameter"); + return RPC_PORT_ERROR_INVALID_PARAMETER; + } + + handle = calloc(1, sizeof(rpc_port_stub_vc_feedback_cb_t)); + if (handle == nullptr) { + _E("Out of memory"); + return RPC_PORT_ERROR_OUT_OF_MEMORY; + } + + handle->parcelable.to = __rpc_port_stub_vc_feedback_cb_to; + handle->parcelable.from = __rpc_port_stub_vc_feedback_cb_from; + handle->id = RPC_PORT_STUB_VC_DELEGATE_FEEDBACK_CB; + handle->seq_id = g_atomic_int_add(&seq_num, 1) + 1; + handle->once = false; + handle->valid = true; + _I("id(%d), seq_id(%d)", handle->id, handle->seq_id); + + *h = handle; + + return RPC_PORT_ERROR_NONE; +} + +int rpc_port_stub_vc_feedback_cb_destroy(rpc_port_stub_vc_feedback_cb_h h) +{ + if (h == nullptr) { + _E("Invalid parameter"); + return RPC_PORT_ERROR_INVALID_PARAMETER; + } + + _W("id(%d), seq_id(%d), once(%s)", h->id, h->seq_id, h->once ? "true" : "false"); + + free(h); + + return RPC_PORT_ERROR_NONE; +} + +int rpc_port_stub_vc_feedback_cb_clone(rpc_port_stub_vc_feedback_cb_h h, rpc_port_stub_vc_feedback_cb_h *clone) +{ + rpc_port_stub_vc_feedback_cb_h handle; + int ret; + + if (h == nullptr || clone == nullptr) { + _E("Invalid parameter"); + return RPC_PORT_ERROR_INVALID_PARAMETER; + } + + ret = rpc_port_stub_vc_feedback_cb_create(&handle); + if (ret != RPC_PORT_ERROR_NONE) { + _E("Failed to create handle. error(%d)", ret); + return ret; + } + + handle->port = h->port; + handle->seq_id = h->seq_id; + handle->once = h->once; + handle->valid = h->valid; + + *clone = handle; + + return RPC_PORT_ERROR_NONE; +} + +int rpc_port_stub_vc_feedback_cb_get_id(rpc_port_stub_vc_feedback_cb_h h, int *id) +{ + if (h == nullptr || id == nullptr) { + _E("Invalid parameter"); + return RPC_PORT_ERROR_INVALID_PARAMETER; + } + + *id = h->id; + + return RPC_PORT_ERROR_NONE; +} + +int rpc_port_stub_vc_feedback_cb_get_seq_id(rpc_port_stub_vc_feedback_cb_h h, int *seq_id) +{ + if (h == nullptr || seq_id == nullptr) { + _E("Invalid parameter"); + return RPC_PORT_ERROR_INVALID_PARAMETER; + } + + *seq_id = h->seq_id; + + return RPC_PORT_ERROR_NONE; +} + +int rpc_port_stub_vc_feedback_cb_is_once(rpc_port_stub_vc_feedback_cb_h h, bool *once) +{ + if (h == nullptr || once == nullptr) { + _E("Invalid parameter"); + return RPC_PORT_ERROR_INVALID_PARAMETER; + } + + *once = h->once; + + return RPC_PORT_ERROR_NONE; +} + +int rpc_port_stub_vc_feedback_cb_get_tag(rpc_port_stub_vc_feedback_cb_h h, char **tag) +{ + char *value; + char buf[128]; + + if (h == nullptr || tag == nullptr) { + _E("Invalid parameter"); + return RPC_PORT_ERROR_INVALID_PARAMETER; + } + + snprintf(buf, sizeof(buf), "%d::%d", h->id, h->seq_id); + value = strdup(buf); + if (value == nullptr) { + _E("Out of memory"); + return RPC_PORT_ERROR_OUT_OF_MEMORY; + } + + *tag = value; + + return RPC_PORT_ERROR_NONE; +} + +int rpc_port_stub_vc_feedback_cb_set_port(rpc_port_stub_vc_feedback_cb_h h, rpc_port_h port) +{ + if (h == nullptr || port == nullptr) { + _E("Invalid parameter"); + return RPC_PORT_ERROR_INVALID_PARAMETER; + } + + h->port = port; + + return RPC_PORT_ERROR_NONE; +} + +int rpc_port_stub_vc_feedback_cb_invoke(rpc_port_stub_vc_feedback_cb_h h, int utt_id, int event, rpc_port_stub_array_char_h pcm_data, int len) +{ + rpc_port_parcel_h parcel_; + int ret_; + + if (h == nullptr || h->port == nullptr || pcm_data == nullptr) { + _E("Invalid parameter"); + return RPC_PORT_ERROR_INVALID_PARAMETER; + } + + if (!__rpc_port_stub_vc_exist_callback_port(h->port)) { + _E("Not connected"); + return RPC_PORT_ERROR_INVALID_PARAMETER; + } + + if (h->once && !h->valid) { + _E("The delegate handle is already used"); + return RPC_PORT_ERROR_INVALID_PARAMETER; + } + + ret_ = rpc_port_parcel_create(&parcel_); + if (ret_ != RPC_PORT_ERROR_NONE) { + _E("Failed to create parcel handle. error(%d)", ret_); + return ret_; + } + + rpc_port_parcel_write_int32(parcel_, RPC_PORT_STUB_VC_METHOD_CALLBACK_); + + rpc_port_parcel_write(parcel_, &h->parcelable, h); + + rpc_port_parcel_write_int32(parcel_, utt_id); + + rpc_port_parcel_write_int32(parcel_, event); + + rpc_port_parcel_write(parcel_, &pcm_data->parcelable, pcm_data); + + rpc_port_parcel_write_int32(parcel_, len); + + ret_ = rpc_port_parcel_send(parcel_, h->port); + rpc_port_parcel_destroy(parcel_); + h->valid = false; + + return ret_; +} + +static int __rpc_port_stub_vc_method_register_notify_cb_handler(rpc_port_h port, rpc_port_parcel_h parcel, void *user_data) +{ + rpc_port_stub_vc_context_h context_ = user_data; + rpc_port_parcel_header_h header_; + int seq_num_ = -1; + rpc_port_h callback_port_; + int ret_; + int pid = -1; + rpc_port_stub_vc_notify_cb_h callback = nullptr; + + ret_ = rpc_port_stub_get_port(__vc.stub, RPC_PORT_PORT_CALLBACK, context_->instance, &callback_port_); + if (ret_ != RPC_PORT_ERROR_NONE) { + _E("Failed to get callback port. error(%d)", ret_); + goto out; + } + + rpc_port_parcel_get_header(parcel, &header_); + rpc_port_parcel_header_get_seq_num(header_, &seq_num_); + _W("[Sequence] %d", seq_num_); + + rpc_port_parcel_read_int32(parcel, &pid); + + ret_ = rpc_port_stub_vc_notify_cb_create(&callback); + if (ret_ != RPC_PORT_ERROR_NONE) { + _E("Failed to create handle. error(%d)", ret_); + goto out; + } + + rpc_port_stub_vc_notify_cb_set_port(callback, callback_port_); + rpc_port_parcel_read(parcel, &callback->parcelable, callback); + ret_ = get_last_result(); + if (ret_ != RPC_PORT_ERROR_NONE) { + _E("Failed to read data. error(%d)", ret_); + goto out; + } + + if (context_->callback.register_notify_cb) + context_->callback.register_notify_cb(context_, pid, callback, context_->user_data); + +out: + if (callback) + rpc_port_stub_vc_notify_cb_destroy(callback); + + return ret_; +} + +static int __rpc_port_stub_vc_method_register_notify_cb_sync_handler(rpc_port_h port, rpc_port_parcel_h parcel, void *user_data) +{ + rpc_port_stub_vc_context_h context_ = user_data; + rpc_port_parcel_header_h header_; + int seq_num_ = -1; + rpc_port_h callback_port_; + int ret_; + int pid = -1; + rpc_port_stub_vc_notify_cb_h callback = nullptr; + rpc_port_parcel_h parcel_; + int res_ = -1; + + ret_ = rpc_port_stub_get_port(__vc.stub, RPC_PORT_PORT_CALLBACK, context_->instance, &callback_port_); + if (ret_ != RPC_PORT_ERROR_NONE) { + _E("Failed to get callback port. error(%d)", ret_); + goto out; + } + + rpc_port_parcel_get_header(parcel, &header_); + rpc_port_parcel_header_get_seq_num(header_, &seq_num_); + _W("[Sequence] %d", seq_num_); + + rpc_port_parcel_read_int32(parcel, &pid); + + ret_ = rpc_port_stub_vc_notify_cb_create(&callback); + if (ret_ != RPC_PORT_ERROR_NONE) { + _E("Failed to create handle. error(%d)", ret_); + goto out; + } + + rpc_port_stub_vc_notify_cb_set_port(callback, callback_port_); + rpc_port_parcel_read(parcel, &callback->parcelable, callback); + ret_ = get_last_result(); + if (ret_ != RPC_PORT_ERROR_NONE) { + _E("Failed to read data. error(%d)", ret_); + goto out; + } + + if (context_->callback.register_notify_cb_sync) + res_ = context_->callback.register_notify_cb_sync(context_, pid, callback, context_->user_data); + + ret_ = rpc_port_parcel_create(&parcel_); + if (ret_ != RPC_PORT_ERROR_NONE) { + _E("Failed to create parcel handle. error(%d)", ret_); + goto out; + } + + rpc_port_parcel_get_header(parcel_, &header_); + rpc_port_parcel_header_set_tag(header_, TIDL_VERSION); + rpc_port_parcel_header_set_seq_num(header_, seq_num_); + + rpc_port_parcel_write_int32(parcel_, RPC_PORT_STUB_VC_METHOD_RESULT_); + + rpc_port_parcel_write_int32(parcel_, res_); + + ret_ = rpc_port_parcel_send(parcel_, port); + rpc_port_parcel_destroy(parcel_); + +out: + if (callback) + rpc_port_stub_vc_notify_cb_destroy(callback); + + return ret_; +} + +static int __rpc_port_stub_vc_method_register_feedback_cb_handler(rpc_port_h port, rpc_port_parcel_h parcel, void *user_data) +{ + rpc_port_stub_vc_context_h context_ = user_data; + rpc_port_parcel_header_h header_; + int seq_num_ = -1; + rpc_port_h callback_port_; + int ret_; + int pid = -1; + rpc_port_stub_vc_feedback_cb_h callback = nullptr; + + ret_ = rpc_port_stub_get_port(__vc.stub, RPC_PORT_PORT_CALLBACK, context_->instance, &callback_port_); + if (ret_ != RPC_PORT_ERROR_NONE) { + _E("Failed to get callback port. error(%d)", ret_); + goto out; + } + + rpc_port_parcel_get_header(parcel, &header_); + rpc_port_parcel_header_get_seq_num(header_, &seq_num_); + _W("[Sequence] %d", seq_num_); + + rpc_port_parcel_read_int32(parcel, &pid); + + ret_ = rpc_port_stub_vc_feedback_cb_create(&callback); + if (ret_ != RPC_PORT_ERROR_NONE) { + _E("Failed to create handle. error(%d)", ret_); + goto out; + } + + rpc_port_stub_vc_feedback_cb_set_port(callback, callback_port_); + rpc_port_parcel_read(parcel, &callback->parcelable, callback); + ret_ = get_last_result(); + if (ret_ != RPC_PORT_ERROR_NONE) { + _E("Failed to read data. error(%d)", ret_); + goto out; + } + + if (context_->callback.register_feedback_cb) + context_->callback.register_feedback_cb(context_, pid, callback, context_->user_data); + +out: + if (callback) + rpc_port_stub_vc_feedback_cb_destroy(callback); + + return ret_; +} + +static int __rpc_port_stub_vc_method_register_feedback_cb_sync_handler(rpc_port_h port, rpc_port_parcel_h parcel, void *user_data) +{ + rpc_port_stub_vc_context_h context_ = user_data; + rpc_port_parcel_header_h header_; + int seq_num_ = -1; + rpc_port_h callback_port_; + int ret_; + int pid = -1; + rpc_port_stub_vc_feedback_cb_h callback = nullptr; + rpc_port_parcel_h parcel_; + int res_ = -1; + + ret_ = rpc_port_stub_get_port(__vc.stub, RPC_PORT_PORT_CALLBACK, context_->instance, &callback_port_); + if (ret_ != RPC_PORT_ERROR_NONE) { + _E("Failed to get callback port. error(%d)", ret_); + goto out; + } + + rpc_port_parcel_get_header(parcel, &header_); + rpc_port_parcel_header_get_seq_num(header_, &seq_num_); + _W("[Sequence] %d", seq_num_); + + rpc_port_parcel_read_int32(parcel, &pid); + + ret_ = rpc_port_stub_vc_feedback_cb_create(&callback); + if (ret_ != RPC_PORT_ERROR_NONE) { + _E("Failed to create handle. error(%d)", ret_); + goto out; + } + + rpc_port_stub_vc_feedback_cb_set_port(callback, callback_port_); + rpc_port_parcel_read(parcel, &callback->parcelable, callback); + ret_ = get_last_result(); + if (ret_ != RPC_PORT_ERROR_NONE) { + _E("Failed to read data. error(%d)", ret_); + goto out; + } + + if (context_->callback.register_feedback_cb_sync) + res_ = context_->callback.register_feedback_cb_sync(context_, pid, callback, context_->user_data); + + ret_ = rpc_port_parcel_create(&parcel_); + if (ret_ != RPC_PORT_ERROR_NONE) { + _E("Failed to create parcel handle. error(%d)", ret_); + goto out; + } + + rpc_port_parcel_get_header(parcel_, &header_); + rpc_port_parcel_header_set_tag(header_, TIDL_VERSION); + rpc_port_parcel_header_set_seq_num(header_, seq_num_); + + rpc_port_parcel_write_int32(parcel_, RPC_PORT_STUB_VC_METHOD_RESULT_); + + rpc_port_parcel_write_int32(parcel_, res_); + + ret_ = rpc_port_parcel_send(parcel_, port); + rpc_port_parcel_destroy(parcel_); + +out: + if (callback) + rpc_port_stub_vc_feedback_cb_destroy(callback); + + return ret_; +} + +static int __rpc_port_stub_vc_method_initialize_handler(rpc_port_h port, rpc_port_parcel_h parcel, void *user_data) +{ + rpc_port_stub_vc_context_h context_ = user_data; + rpc_port_parcel_header_h header_; + int seq_num_ = -1; + rpc_port_h callback_port_; + int ret_; + int pid = -1; + int mgr_pid = -1; + int service_state = -1; + int daemon_pid = -1; + rpc_port_parcel_h parcel_; + int res_ = -1; + + ret_ = rpc_port_stub_get_port(__vc.stub, RPC_PORT_PORT_CALLBACK, context_->instance, &callback_port_); + if (ret_ != RPC_PORT_ERROR_NONE) { + _E("Failed to get callback port. error(%d)", ret_); + goto out; + } + + rpc_port_parcel_get_header(parcel, &header_); + rpc_port_parcel_header_get_seq_num(header_, &seq_num_); + _W("[Sequence] %d", seq_num_); + + rpc_port_parcel_read_int32(parcel, &pid); + + if (context_->callback.initialize) + res_ = context_->callback.initialize(context_, pid, &mgr_pid, &service_state, &daemon_pid, context_->user_data); + + ret_ = rpc_port_parcel_create(&parcel_); + if (ret_ != RPC_PORT_ERROR_NONE) { + _E("Failed to create parcel handle. error(%d)", ret_); + goto out; + } + + rpc_port_parcel_get_header(parcel_, &header_); + rpc_port_parcel_header_set_tag(header_, TIDL_VERSION); + rpc_port_parcel_header_set_seq_num(header_, seq_num_); + + rpc_port_parcel_write_int32(parcel_, RPC_PORT_STUB_VC_METHOD_RESULT_); + + rpc_port_parcel_write_int32(parcel_, mgr_pid); + + rpc_port_parcel_write_int32(parcel_, service_state); + + rpc_port_parcel_write_int32(parcel_, daemon_pid); + + rpc_port_parcel_write_int32(parcel_, res_); + + ret_ = rpc_port_parcel_send(parcel_, port); + rpc_port_parcel_destroy(parcel_); + +out: + + return ret_; +} + +static int __rpc_port_stub_vc_method_finalize_handler(rpc_port_h port, rpc_port_parcel_h parcel, void *user_data) +{ + rpc_port_stub_vc_context_h context_ = user_data; + rpc_port_parcel_header_h header_; + int seq_num_ = -1; + rpc_port_h callback_port_; + int ret_; + int pid = -1; + rpc_port_parcel_h parcel_; + int res_ = -1; + + ret_ = rpc_port_stub_get_port(__vc.stub, RPC_PORT_PORT_CALLBACK, context_->instance, &callback_port_); + if (ret_ != RPC_PORT_ERROR_NONE) { + _E("Failed to get callback port. error(%d)", ret_); + goto out; + } + + rpc_port_parcel_get_header(parcel, &header_); + rpc_port_parcel_header_get_seq_num(header_, &seq_num_); + _W("[Sequence] %d", seq_num_); + + rpc_port_parcel_read_int32(parcel, &pid); + + if (context_->callback.finalize) + res_ = context_->callback.finalize(context_, pid, context_->user_data); + + ret_ = rpc_port_parcel_create(&parcel_); + if (ret_ != RPC_PORT_ERROR_NONE) { + _E("Failed to create parcel handle. error(%d)", ret_); + goto out; + } + + rpc_port_parcel_get_header(parcel_, &header_); + rpc_port_parcel_header_set_tag(header_, TIDL_VERSION); + rpc_port_parcel_header_set_seq_num(header_, seq_num_); + + rpc_port_parcel_write_int32(parcel_, RPC_PORT_STUB_VC_METHOD_RESULT_); + + rpc_port_parcel_write_int32(parcel_, res_); + + ret_ = rpc_port_parcel_send(parcel_, port); + rpc_port_parcel_destroy(parcel_); + +out: + + return ret_; +} + +static int __rpc_port_stub_vc_method_set_command_handler(rpc_port_h port, rpc_port_parcel_h parcel, void *user_data) +{ + rpc_port_stub_vc_context_h context_ = user_data; + rpc_port_parcel_header_h header_; + int seq_num_ = -1; + rpc_port_h callback_port_; + int ret_; + int pid = -1; + int cmd_type = -1; + rpc_port_parcel_h parcel_; + int res_ = -1; + + ret_ = rpc_port_stub_get_port(__vc.stub, RPC_PORT_PORT_CALLBACK, context_->instance, &callback_port_); + if (ret_ != RPC_PORT_ERROR_NONE) { + _E("Failed to get callback port. error(%d)", ret_); + goto out; + } + + rpc_port_parcel_get_header(parcel, &header_); + rpc_port_parcel_header_get_seq_num(header_, &seq_num_); + _W("[Sequence] %d", seq_num_); + + rpc_port_parcel_read_int32(parcel, &pid); + + rpc_port_parcel_read_int32(parcel, &cmd_type); + + if (context_->callback.set_command) + res_ = context_->callback.set_command(context_, pid, cmd_type, context_->user_data); + + ret_ = rpc_port_parcel_create(&parcel_); + if (ret_ != RPC_PORT_ERROR_NONE) { + _E("Failed to create parcel handle. error(%d)", ret_); + goto out; + } + + rpc_port_parcel_get_header(parcel_, &header_); + rpc_port_parcel_header_set_tag(header_, TIDL_VERSION); + rpc_port_parcel_header_set_seq_num(header_, seq_num_); + + rpc_port_parcel_write_int32(parcel_, RPC_PORT_STUB_VC_METHOD_RESULT_); + + rpc_port_parcel_write_int32(parcel_, res_); + + ret_ = rpc_port_parcel_send(parcel_, port); + rpc_port_parcel_destroy(parcel_); + +out: + + return ret_; +} + +static int __rpc_port_stub_vc_method_unset_command_handler(rpc_port_h port, rpc_port_parcel_h parcel, void *user_data) +{ + rpc_port_stub_vc_context_h context_ = user_data; + rpc_port_parcel_header_h header_; + int seq_num_ = -1; + rpc_port_h callback_port_; + int ret_; + int pid = -1; + int cmd_type = -1; + rpc_port_parcel_h parcel_; + int res_ = -1; + + ret_ = rpc_port_stub_get_port(__vc.stub, RPC_PORT_PORT_CALLBACK, context_->instance, &callback_port_); + if (ret_ != RPC_PORT_ERROR_NONE) { + _E("Failed to get callback port. error(%d)", ret_); + goto out; + } + + rpc_port_parcel_get_header(parcel, &header_); + rpc_port_parcel_header_get_seq_num(header_, &seq_num_); + _W("[Sequence] %d", seq_num_); + + rpc_port_parcel_read_int32(parcel, &pid); + + rpc_port_parcel_read_int32(parcel, &cmd_type); + + if (context_->callback.unset_command) + res_ = context_->callback.unset_command(context_, pid, cmd_type, context_->user_data); + + ret_ = rpc_port_parcel_create(&parcel_); + if (ret_ != RPC_PORT_ERROR_NONE) { + _E("Failed to create parcel handle. error(%d)", ret_); + goto out; + } + + rpc_port_parcel_get_header(parcel_, &header_); + rpc_port_parcel_header_set_tag(header_, TIDL_VERSION); + rpc_port_parcel_header_set_seq_num(header_, seq_num_); + + rpc_port_parcel_write_int32(parcel_, RPC_PORT_STUB_VC_METHOD_RESULT_); + + rpc_port_parcel_write_int32(parcel_, res_); + + ret_ = rpc_port_parcel_send(parcel_, port); + rpc_port_parcel_destroy(parcel_); + +out: + + return ret_; +} + +static int __rpc_port_stub_vc_method_set_foreground_handler(rpc_port_h port, rpc_port_parcel_h parcel, void *user_data) +{ + rpc_port_stub_vc_context_h context_ = user_data; + rpc_port_parcel_header_h header_; + int seq_num_ = -1; + rpc_port_h callback_port_; + int ret_; + int pid = -1; + bool value = false; + rpc_port_parcel_h parcel_; + int res_ = -1; + + ret_ = rpc_port_stub_get_port(__vc.stub, RPC_PORT_PORT_CALLBACK, context_->instance, &callback_port_); + if (ret_ != RPC_PORT_ERROR_NONE) { + _E("Failed to get callback port. error(%d)", ret_); + goto out; + } + + rpc_port_parcel_get_header(parcel, &header_); + rpc_port_parcel_header_get_seq_num(header_, &seq_num_); + _W("[Sequence] %d", seq_num_); + + rpc_port_parcel_read_int32(parcel, &pid); + + rpc_port_parcel_read_bool(parcel, &value); + + if (context_->callback.set_foreground) + res_ = context_->callback.set_foreground(context_, pid, value, context_->user_data); + + ret_ = rpc_port_parcel_create(&parcel_); + if (ret_ != RPC_PORT_ERROR_NONE) { + _E("Failed to create parcel handle. error(%d)", ret_); + goto out; + } + + rpc_port_parcel_get_header(parcel_, &header_); + rpc_port_parcel_header_set_tag(header_, TIDL_VERSION); + rpc_port_parcel_header_set_seq_num(header_, seq_num_); + + rpc_port_parcel_write_int32(parcel_, RPC_PORT_STUB_VC_METHOD_RESULT_); + + rpc_port_parcel_write_int32(parcel_, res_); + + ret_ = rpc_port_parcel_send(parcel_, port); + rpc_port_parcel_destroy(parcel_); + +out: + + return ret_; +} + +static int __rpc_port_stub_vc_method_set_server_dialog_handler(rpc_port_h port, rpc_port_parcel_h parcel, void *user_data) +{ + rpc_port_stub_vc_context_h context_ = user_data; + rpc_port_parcel_header_h header_; + int seq_num_ = -1; + rpc_port_h callback_port_; + int ret_; + int pid = -1; + char *app_id = nullptr; + char *credential = nullptr; + rpc_port_parcel_h parcel_; + int res_ = -1; + + ret_ = rpc_port_stub_get_port(__vc.stub, RPC_PORT_PORT_CALLBACK, context_->instance, &callback_port_); + if (ret_ != RPC_PORT_ERROR_NONE) { + _E("Failed to get callback port. error(%d)", ret_); + goto out; + } + + rpc_port_parcel_get_header(parcel, &header_); + rpc_port_parcel_header_get_seq_num(header_, &seq_num_); + _W("[Sequence] %d", seq_num_); + + rpc_port_parcel_read_int32(parcel, &pid); + + rpc_port_parcel_read_string(parcel, &app_id); + if (app_id == nullptr) { + _E("Failed to read data"); + ret_ = RPC_PORT_ERROR_OUT_OF_MEMORY; + goto out; + } + + rpc_port_parcel_read_string(parcel, &credential); + if (credential == nullptr) { + _E("Failed to read data"); + ret_ = RPC_PORT_ERROR_OUT_OF_MEMORY; + goto out; + } + + if (context_->callback.set_server_dialog) + res_ = context_->callback.set_server_dialog(context_, pid, app_id, credential, context_->user_data); + + ret_ = rpc_port_parcel_create(&parcel_); + if (ret_ != RPC_PORT_ERROR_NONE) { + _E("Failed to create parcel handle. error(%d)", ret_); + goto out; + } + + rpc_port_parcel_get_header(parcel_, &header_); + rpc_port_parcel_header_set_tag(header_, TIDL_VERSION); + rpc_port_parcel_header_set_seq_num(header_, seq_num_); + + rpc_port_parcel_write_int32(parcel_, RPC_PORT_STUB_VC_METHOD_RESULT_); + + rpc_port_parcel_write_int32(parcel_, res_); + + ret_ = rpc_port_parcel_send(parcel_, port); + rpc_port_parcel_destroy(parcel_); + +out: + if (app_id) + free(app_id); + + if (credential) + free(credential); + + return ret_; +} + +static int __rpc_port_stub_vc_method_request_dialog_handler(rpc_port_h port, rpc_port_parcel_h parcel, void *user_data) +{ + rpc_port_stub_vc_context_h context_ = user_data; + rpc_port_parcel_header_h header_; + int seq_num_ = -1; + rpc_port_h callback_port_; + int ret_; + int pid = -1; + char *disp_text = nullptr; + char *utt_text = nullptr; + bool continuous = false; + rpc_port_parcel_h parcel_; + int res_ = -1; + + ret_ = rpc_port_stub_get_port(__vc.stub, RPC_PORT_PORT_CALLBACK, context_->instance, &callback_port_); + if (ret_ != RPC_PORT_ERROR_NONE) { + _E("Failed to get callback port. error(%d)", ret_); + goto out; + } + + rpc_port_parcel_get_header(parcel, &header_); + rpc_port_parcel_header_get_seq_num(header_, &seq_num_); + _W("[Sequence] %d", seq_num_); + + rpc_port_parcel_read_int32(parcel, &pid); + + rpc_port_parcel_read_string(parcel, &disp_text); + if (disp_text == nullptr) { + _E("Failed to read data"); + ret_ = RPC_PORT_ERROR_OUT_OF_MEMORY; + goto out; + } + + rpc_port_parcel_read_string(parcel, &utt_text); + if (utt_text == nullptr) { + _E("Failed to read data"); + ret_ = RPC_PORT_ERROR_OUT_OF_MEMORY; + goto out; + } + + rpc_port_parcel_read_bool(parcel, &continuous); + + if (context_->callback.request_dialog) + res_ = context_->callback.request_dialog(context_, pid, disp_text, utt_text, continuous, context_->user_data); + + ret_ = rpc_port_parcel_create(&parcel_); + if (ret_ != RPC_PORT_ERROR_NONE) { + _E("Failed to create parcel handle. error(%d)", ret_); + goto out; + } + + rpc_port_parcel_get_header(parcel_, &header_); + rpc_port_parcel_header_set_tag(header_, TIDL_VERSION); + rpc_port_parcel_header_set_seq_num(header_, seq_num_); + + rpc_port_parcel_write_int32(parcel_, RPC_PORT_STUB_VC_METHOD_RESULT_); + + rpc_port_parcel_write_int32(parcel_, res_); + + ret_ = rpc_port_parcel_send(parcel_, port); + rpc_port_parcel_destroy(parcel_); + +out: + if (disp_text) + free(disp_text); + + if (utt_text) + free(utt_text); + + return ret_; +} + +static int __rpc_port_stub_vc_method_is_system_command_valid_handler(rpc_port_h port, rpc_port_parcel_h parcel, void *user_data) +{ + rpc_port_stub_vc_context_h context_ = user_data; + rpc_port_parcel_header_h header_; + int seq_num_ = -1; + rpc_port_h callback_port_; + int ret_; + int pid = -1; + bool is_sys_cmd_valid = false; + rpc_port_parcel_h parcel_; + int res_ = -1; + + ret_ = rpc_port_stub_get_port(__vc.stub, RPC_PORT_PORT_CALLBACK, context_->instance, &callback_port_); + if (ret_ != RPC_PORT_ERROR_NONE) { + _E("Failed to get callback port. error(%d)", ret_); + goto out; + } + + rpc_port_parcel_get_header(parcel, &header_); + rpc_port_parcel_header_get_seq_num(header_, &seq_num_); + _W("[Sequence] %d", seq_num_); + + rpc_port_parcel_read_int32(parcel, &pid); + + if (context_->callback.is_system_command_valid) + res_ = context_->callback.is_system_command_valid(context_, pid, &is_sys_cmd_valid, context_->user_data); + + ret_ = rpc_port_parcel_create(&parcel_); + if (ret_ != RPC_PORT_ERROR_NONE) { + _E("Failed to create parcel handle. error(%d)", ret_); + goto out; + } + + rpc_port_parcel_get_header(parcel_, &header_); + rpc_port_parcel_header_set_tag(header_, TIDL_VERSION); + rpc_port_parcel_header_set_seq_num(header_, seq_num_); + + rpc_port_parcel_write_int32(parcel_, RPC_PORT_STUB_VC_METHOD_RESULT_); + + rpc_port_parcel_write_bool(parcel_, is_sys_cmd_valid); + + rpc_port_parcel_write_int32(parcel_, res_); + + ret_ = rpc_port_parcel_send(parcel_, port); + rpc_port_parcel_destroy(parcel_); + +out: + + return ret_; +} + +static int __rpc_port_stub_vc_method_auth_enable_handler(rpc_port_h port, rpc_port_parcel_h parcel, void *user_data) +{ + rpc_port_stub_vc_context_h context_ = user_data; + rpc_port_parcel_header_h header_; + int seq_num_ = -1; + rpc_port_h callback_port_; + int ret_; + int pid = -1; + int mgr_pid = -1; + rpc_port_parcel_h parcel_; + int res_ = -1; + + ret_ = rpc_port_stub_get_port(__vc.stub, RPC_PORT_PORT_CALLBACK, context_->instance, &callback_port_); + if (ret_ != RPC_PORT_ERROR_NONE) { + _E("Failed to get callback port. error(%d)", ret_); + goto out; + } + + rpc_port_parcel_get_header(parcel, &header_); + rpc_port_parcel_header_get_seq_num(header_, &seq_num_); + _W("[Sequence] %d", seq_num_); + + rpc_port_parcel_read_int32(parcel, &pid); + + rpc_port_parcel_read_int32(parcel, &mgr_pid); + + if (context_->callback.auth_enable) + res_ = context_->callback.auth_enable(context_, pid, mgr_pid, context_->user_data); + + ret_ = rpc_port_parcel_create(&parcel_); + if (ret_ != RPC_PORT_ERROR_NONE) { + _E("Failed to create parcel handle. error(%d)", ret_); + goto out; + } + + rpc_port_parcel_get_header(parcel_, &header_); + rpc_port_parcel_header_set_tag(header_, TIDL_VERSION); + rpc_port_parcel_header_set_seq_num(header_, seq_num_); + + rpc_port_parcel_write_int32(parcel_, RPC_PORT_STUB_VC_METHOD_RESULT_); + + rpc_port_parcel_write_int32(parcel_, res_); + + ret_ = rpc_port_parcel_send(parcel_, port); + rpc_port_parcel_destroy(parcel_); + +out: + + return ret_; +} + +static int __rpc_port_stub_vc_method_auth_disable_handler(rpc_port_h port, rpc_port_parcel_h parcel, void *user_data) +{ + rpc_port_stub_vc_context_h context_ = user_data; + rpc_port_parcel_header_h header_; + int seq_num_ = -1; + rpc_port_h callback_port_; + int ret_; + int pid = -1; + int mgr_pid = -1; + rpc_port_parcel_h parcel_; + int res_ = -1; + + ret_ = rpc_port_stub_get_port(__vc.stub, RPC_PORT_PORT_CALLBACK, context_->instance, &callback_port_); + if (ret_ != RPC_PORT_ERROR_NONE) { + _E("Failed to get callback port. error(%d)", ret_); + goto out; + } + + rpc_port_parcel_get_header(parcel, &header_); + rpc_port_parcel_header_get_seq_num(header_, &seq_num_); + _W("[Sequence] %d", seq_num_); + + rpc_port_parcel_read_int32(parcel, &pid); + + rpc_port_parcel_read_int32(parcel, &mgr_pid); + + if (context_->callback.auth_disable) + res_ = context_->callback.auth_disable(context_, pid, mgr_pid, context_->user_data); + + ret_ = rpc_port_parcel_create(&parcel_); + if (ret_ != RPC_PORT_ERROR_NONE) { + _E("Failed to create parcel handle. error(%d)", ret_); + goto out; + } + + rpc_port_parcel_get_header(parcel_, &header_); + rpc_port_parcel_header_set_tag(header_, TIDL_VERSION); + rpc_port_parcel_header_set_seq_num(header_, seq_num_); + + rpc_port_parcel_write_int32(parcel_, RPC_PORT_STUB_VC_METHOD_RESULT_); + + rpc_port_parcel_write_int32(parcel_, res_); + + ret_ = rpc_port_parcel_send(parcel_, port); + rpc_port_parcel_destroy(parcel_); + +out: + + return ret_; +} + +static int __rpc_port_stub_vc_method_auth_start_handler(rpc_port_h port, rpc_port_parcel_h parcel, void *user_data) +{ + rpc_port_stub_vc_context_h context_ = user_data; + rpc_port_parcel_header_h header_; + int seq_num_ = -1; + rpc_port_h callback_port_; + int ret_; + int pid = -1; + int mgr_pid = -1; + rpc_port_parcel_h parcel_; + int res_ = -1; + + ret_ = rpc_port_stub_get_port(__vc.stub, RPC_PORT_PORT_CALLBACK, context_->instance, &callback_port_); + if (ret_ != RPC_PORT_ERROR_NONE) { + _E("Failed to get callback port. error(%d)", ret_); + goto out; + } + + rpc_port_parcel_get_header(parcel, &header_); + rpc_port_parcel_header_get_seq_num(header_, &seq_num_); + _W("[Sequence] %d", seq_num_); + + rpc_port_parcel_read_int32(parcel, &pid); + + rpc_port_parcel_read_int32(parcel, &mgr_pid); + + if (context_->callback.auth_start) + res_ = context_->callback.auth_start(context_, pid, mgr_pid, context_->user_data); + + ret_ = rpc_port_parcel_create(&parcel_); + if (ret_ != RPC_PORT_ERROR_NONE) { + _E("Failed to create parcel handle. error(%d)", ret_); + goto out; + } + + rpc_port_parcel_get_header(parcel_, &header_); + rpc_port_parcel_header_set_tag(header_, TIDL_VERSION); + rpc_port_parcel_header_set_seq_num(header_, seq_num_); + + rpc_port_parcel_write_int32(parcel_, RPC_PORT_STUB_VC_METHOD_RESULT_); + + rpc_port_parcel_write_int32(parcel_, res_); + + ret_ = rpc_port_parcel_send(parcel_, port); + rpc_port_parcel_destroy(parcel_); + +out: + + return ret_; +} + +static int __rpc_port_stub_vc_method_auth_stop_handler(rpc_port_h port, rpc_port_parcel_h parcel, void *user_data) +{ + rpc_port_stub_vc_context_h context_ = user_data; + rpc_port_parcel_header_h header_; + int seq_num_ = -1; + rpc_port_h callback_port_; + int ret_; + int pid = -1; + int mgr_pid = -1; + rpc_port_parcel_h parcel_; + int res_ = -1; + + ret_ = rpc_port_stub_get_port(__vc.stub, RPC_PORT_PORT_CALLBACK, context_->instance, &callback_port_); + if (ret_ != RPC_PORT_ERROR_NONE) { + _E("Failed to get callback port. error(%d)", ret_); + goto out; + } + + rpc_port_parcel_get_header(parcel, &header_); + rpc_port_parcel_header_get_seq_num(header_, &seq_num_); + _W("[Sequence] %d", seq_num_); + + rpc_port_parcel_read_int32(parcel, &pid); + + rpc_port_parcel_read_int32(parcel, &mgr_pid); + + if (context_->callback.auth_stop) + res_ = context_->callback.auth_stop(context_, pid, mgr_pid, context_->user_data); + + ret_ = rpc_port_parcel_create(&parcel_); + if (ret_ != RPC_PORT_ERROR_NONE) { + _E("Failed to create parcel handle. error(%d)", ret_); + goto out; + } + + rpc_port_parcel_get_header(parcel_, &header_); + rpc_port_parcel_header_set_tag(header_, TIDL_VERSION); + rpc_port_parcel_header_set_seq_num(header_, seq_num_); + + rpc_port_parcel_write_int32(parcel_, RPC_PORT_STUB_VC_METHOD_RESULT_); + + rpc_port_parcel_write_int32(parcel_, res_); + + ret_ = rpc_port_parcel_send(parcel_, port); + rpc_port_parcel_destroy(parcel_); + +out: + + return ret_; +} + +static int __rpc_port_stub_vc_method_auth_cancel_handler(rpc_port_h port, rpc_port_parcel_h parcel, void *user_data) +{ + rpc_port_stub_vc_context_h context_ = user_data; + rpc_port_parcel_header_h header_; + int seq_num_ = -1; + rpc_port_h callback_port_; + int ret_; + int pid = -1; + int mgr_pid = -1; + rpc_port_parcel_h parcel_; + int res_ = -1; + + ret_ = rpc_port_stub_get_port(__vc.stub, RPC_PORT_PORT_CALLBACK, context_->instance, &callback_port_); + if (ret_ != RPC_PORT_ERROR_NONE) { + _E("Failed to get callback port. error(%d)", ret_); + goto out; + } + + rpc_port_parcel_get_header(parcel, &header_); + rpc_port_parcel_header_get_seq_num(header_, &seq_num_); + _W("[Sequence] %d", seq_num_); + + rpc_port_parcel_read_int32(parcel, &pid); + + rpc_port_parcel_read_int32(parcel, &mgr_pid); + + if (context_->callback.auth_cancel) + res_ = context_->callback.auth_cancel(context_, pid, mgr_pid, context_->user_data); + + ret_ = rpc_port_parcel_create(&parcel_); + if (ret_ != RPC_PORT_ERROR_NONE) { + _E("Failed to create parcel handle. error(%d)", ret_); + goto out; + } + + rpc_port_parcel_get_header(parcel_, &header_); + rpc_port_parcel_header_set_tag(header_, TIDL_VERSION); + rpc_port_parcel_header_set_seq_num(header_, seq_num_); + + rpc_port_parcel_write_int32(parcel_, RPC_PORT_STUB_VC_METHOD_RESULT_); + + rpc_port_parcel_write_int32(parcel_, res_); + + ret_ = rpc_port_parcel_send(parcel_, port); + rpc_port_parcel_destroy(parcel_); + +out: + + return ret_; +} + +static int __rpc_port_stub_vc_method_request_tts_handler(rpc_port_h port, rpc_port_parcel_h parcel, void *user_data) +{ + rpc_port_stub_vc_context_h context_ = user_data; + rpc_port_parcel_header_h header_; + int seq_num_ = -1; + rpc_port_h callback_port_; + int ret_; + int pid = -1; + char *text = nullptr; + char *lang = nullptr; + bool to_vcm = false; + int utt_id = -1; + rpc_port_parcel_h parcel_; + int res_ = -1; + + ret_ = rpc_port_stub_get_port(__vc.stub, RPC_PORT_PORT_CALLBACK, context_->instance, &callback_port_); + if (ret_ != RPC_PORT_ERROR_NONE) { + _E("Failed to get callback port. error(%d)", ret_); + goto out; + } + + rpc_port_parcel_get_header(parcel, &header_); + rpc_port_parcel_header_get_seq_num(header_, &seq_num_); + _W("[Sequence] %d", seq_num_); + + rpc_port_parcel_read_int32(parcel, &pid); + + rpc_port_parcel_read_string(parcel, &text); + if (text == nullptr) { + _E("Failed to read data"); + ret_ = RPC_PORT_ERROR_OUT_OF_MEMORY; + goto out; + } + + rpc_port_parcel_read_string(parcel, &lang); + if (lang == nullptr) { + _E("Failed to read data"); + ret_ = RPC_PORT_ERROR_OUT_OF_MEMORY; + goto out; + } + + rpc_port_parcel_read_bool(parcel, &to_vcm); + + if (context_->callback.request_tts) + res_ = context_->callback.request_tts(context_, pid, text, lang, to_vcm, &utt_id, context_->user_data); + + ret_ = rpc_port_parcel_create(&parcel_); + if (ret_ != RPC_PORT_ERROR_NONE) { + _E("Failed to create parcel handle. error(%d)", ret_); + goto out; + } + + rpc_port_parcel_get_header(parcel_, &header_); + rpc_port_parcel_header_set_tag(header_, TIDL_VERSION); + rpc_port_parcel_header_set_seq_num(header_, seq_num_); + + rpc_port_parcel_write_int32(parcel_, RPC_PORT_STUB_VC_METHOD_RESULT_); + + rpc_port_parcel_write_int32(parcel_, utt_id); + + rpc_port_parcel_write_int32(parcel_, res_); + + ret_ = rpc_port_parcel_send(parcel_, port); + rpc_port_parcel_destroy(parcel_); + +out: + if (text) + free(text); + + if (lang) + free(lang); + + return ret_; +} + +static int __rpc_port_stub_vc_method_cancel_tts_handler(rpc_port_h port, rpc_port_parcel_h parcel, void *user_data) +{ + rpc_port_stub_vc_context_h context_ = user_data; + rpc_port_parcel_header_h header_; + int seq_num_ = -1; + rpc_port_h callback_port_; + int ret_; + int pid = -1; + int utt_id = -1; + rpc_port_parcel_h parcel_; + int res_ = -1; + + ret_ = rpc_port_stub_get_port(__vc.stub, RPC_PORT_PORT_CALLBACK, context_->instance, &callback_port_); + if (ret_ != RPC_PORT_ERROR_NONE) { + _E("Failed to get callback port. error(%d)", ret_); + goto out; + } + + rpc_port_parcel_get_header(parcel, &header_); + rpc_port_parcel_header_get_seq_num(header_, &seq_num_); + _W("[Sequence] %d", seq_num_); + + rpc_port_parcel_read_int32(parcel, &pid); + + rpc_port_parcel_read_int32(parcel, &utt_id); + + if (context_->callback.cancel_tts) + res_ = context_->callback.cancel_tts(context_, pid, utt_id, context_->user_data); + + ret_ = rpc_port_parcel_create(&parcel_); + if (ret_ != RPC_PORT_ERROR_NONE) { + _E("Failed to create parcel handle. error(%d)", ret_); + goto out; + } + + rpc_port_parcel_get_header(parcel_, &header_); + rpc_port_parcel_header_set_tag(header_, TIDL_VERSION); + rpc_port_parcel_header_set_seq_num(header_, seq_num_); + + rpc_port_parcel_write_int32(parcel_, RPC_PORT_STUB_VC_METHOD_RESULT_); + + rpc_port_parcel_write_int32(parcel_, res_); + + ret_ = rpc_port_parcel_send(parcel_, port); + rpc_port_parcel_destroy(parcel_); + +out: + + return ret_; +} + +static int __rpc_port_stub_vc_method_get_tts_audio_format_handler(rpc_port_h port, rpc_port_parcel_h parcel, void *user_data) +{ + rpc_port_stub_vc_context_h context_ = user_data; + rpc_port_parcel_header_h header_; + int seq_num_ = -1; + rpc_port_h callback_port_; + int ret_; + int pid = -1; + int rate = -1; + int channel = -1; + int audio_type = -1; + rpc_port_parcel_h parcel_; + int res_ = -1; + + ret_ = rpc_port_stub_get_port(__vc.stub, RPC_PORT_PORT_CALLBACK, context_->instance, &callback_port_); + if (ret_ != RPC_PORT_ERROR_NONE) { + _E("Failed to get callback port. error(%d)", ret_); + goto out; + } + + rpc_port_parcel_get_header(parcel, &header_); + rpc_port_parcel_header_get_seq_num(header_, &seq_num_); + _W("[Sequence] %d", seq_num_); + + rpc_port_parcel_read_int32(parcel, &pid); + + if (context_->callback.get_tts_audio_format) + res_ = context_->callback.get_tts_audio_format(context_, pid, &rate, &channel, &audio_type, context_->user_data); + + ret_ = rpc_port_parcel_create(&parcel_); + if (ret_ != RPC_PORT_ERROR_NONE) { + _E("Failed to create parcel handle. error(%d)", ret_); + goto out; + } + + rpc_port_parcel_get_header(parcel_, &header_); + rpc_port_parcel_header_set_tag(header_, TIDL_VERSION); + rpc_port_parcel_header_set_seq_num(header_, seq_num_); + + rpc_port_parcel_write_int32(parcel_, RPC_PORT_STUB_VC_METHOD_RESULT_); + + rpc_port_parcel_write_int32(parcel_, rate); + + rpc_port_parcel_write_int32(parcel_, channel); + + rpc_port_parcel_write_int32(parcel_, audio_type); + + rpc_port_parcel_write_int32(parcel_, res_); + + ret_ = rpc_port_parcel_send(parcel_, port); + rpc_port_parcel_destroy(parcel_); + +out: + + return ret_; +} + +static rpc_port_stub_method_handler __vc_method_table[] = { + [RPC_PORT_STUB_VC_METHOD_REGISTER_NOTIFY_CB] = __rpc_port_stub_vc_method_register_notify_cb_handler, + [RPC_PORT_STUB_VC_METHOD_REGISTER_NOTIFY_CB_SYNC] = __rpc_port_stub_vc_method_register_notify_cb_sync_handler, + [RPC_PORT_STUB_VC_METHOD_REGISTER_FEEDBACK_CB] = __rpc_port_stub_vc_method_register_feedback_cb_handler, + [RPC_PORT_STUB_VC_METHOD_REGISTER_FEEDBACK_CB_SYNC] = __rpc_port_stub_vc_method_register_feedback_cb_sync_handler, + [RPC_PORT_STUB_VC_METHOD_INITIALIZE] = __rpc_port_stub_vc_method_initialize_handler, + [RPC_PORT_STUB_VC_METHOD_FINALIZE] = __rpc_port_stub_vc_method_finalize_handler, + [RPC_PORT_STUB_VC_METHOD_SET_COMMAND] = __rpc_port_stub_vc_method_set_command_handler, + [RPC_PORT_STUB_VC_METHOD_UNSET_COMMAND] = __rpc_port_stub_vc_method_unset_command_handler, + [RPC_PORT_STUB_VC_METHOD_SET_FOREGROUND] = __rpc_port_stub_vc_method_set_foreground_handler, + [RPC_PORT_STUB_VC_METHOD_SET_SERVER_DIALOG] = __rpc_port_stub_vc_method_set_server_dialog_handler, + [RPC_PORT_STUB_VC_METHOD_REQUEST_DIALOG] = __rpc_port_stub_vc_method_request_dialog_handler, + [RPC_PORT_STUB_VC_METHOD_IS_SYSTEM_COMMAND_VALID] = __rpc_port_stub_vc_method_is_system_command_valid_handler, + [RPC_PORT_STUB_VC_METHOD_AUTH_ENABLE] = __rpc_port_stub_vc_method_auth_enable_handler, + [RPC_PORT_STUB_VC_METHOD_AUTH_DISABLE] = __rpc_port_stub_vc_method_auth_disable_handler, + [RPC_PORT_STUB_VC_METHOD_AUTH_START] = __rpc_port_stub_vc_method_auth_start_handler, + [RPC_PORT_STUB_VC_METHOD_AUTH_STOP] = __rpc_port_stub_vc_method_auth_stop_handler, + [RPC_PORT_STUB_VC_METHOD_AUTH_CANCEL] = __rpc_port_stub_vc_method_auth_cancel_handler, + [RPC_PORT_STUB_VC_METHOD_REQUEST_TTS] = __rpc_port_stub_vc_method_request_tts_handler, + [RPC_PORT_STUB_VC_METHOD_CANCEL_TTS] = __rpc_port_stub_vc_method_cancel_tts_handler, + [RPC_PORT_STUB_VC_METHOD_GET_TTS_AUDIO_FORMAT] = __rpc_port_stub_vc_method_get_tts_audio_format_handler, +}; + +static int __rpc_port_stub_vc_context_handle_request(rpc_port_stub_vc_context_h h, rpc_port_parcel_h parcel) +{ + int ret = RPC_PORT_ERROR_NONE; + int cmd = -1; + + rpc_port_parcel_read_int32(parcel, &cmd); + if (cmd > 1 && cmd < ARRAY_SIZE(__vc_method_table)) { + if (__vc_method_table[cmd]) + ret = __vc_method_table[cmd](h->port, parcel, h); + } else { + _W("Invalid protocol. cmd(%d)", cmd); + ret = RPC_PORT_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +#ifdef TIDL_THREAD_ENABLE +static int __rpc_port_stub_vc_context_push(rpc_port_stub_vc_context_h h, rpc_port_parcel_h parcel) +{ + g_mutex_lock(&h->mutex); + g_queue_push_tail(h->queue, parcel); + g_cond_signal(&h->cond); + g_mutex_unlock(&h->mutex); + + return 0; +} + +static rpc_port_parcel_h __rpc_port_stub_vc_context_wait_and_pop(rpc_port_stub_vc_context_h h) +{ + rpc_port_parcel_h parcel; + + g_mutex_lock(&h->mutex); + while (g_queue_is_empty(h->queue) && !h->done) + g_cond_wait(&h->cond, &h->mutex); + + parcel = g_queue_pop_head(h->queue); + g_mutex_unlock(&h->mutex); + + return parcel; +} + +static gpointer __rpc_port_stub_vc_context_thread_cb(gpointer user_data) +{ + rpc_port_stub_vc_context_h h = user_data; + rpc_port_parcel_h parcel; + + _W("START"); + while (!h->done) { + parcel = __rpc_port_stub_vc_context_wait_and_pop(h); + if (parcel) { + __rpc_port_stub_vc_context_handle_request(h, parcel); + rpc_port_parcel_destroy(parcel); + } + } + _W("END"); + + return nullptr; +} +#endif /* TIDL_THREAD_ENABLE */ + +static void __rpc_port_stub_vc_context_destroy(gpointer data) +{ + rpc_port_stub_vc_context_h h = data; +#ifdef TIDL_THREAD_ENABLE + rpc_port_parcel_h parcel; +#endif /* TIDL_THREAD_ENABLE */ + + if (h == nullptr) + return; + +#ifdef TIDL_THREAD_ENABLE + g_mutex_lock(&h->mutex); + h->done = true; + g_cond_signal(&h->cond); + g_mutex_unlock(&h->mutex); + + if (h->thread) { + g_thread_join(h->thread); + g_thread_unref(h->thread); + } + + g_mutex_clear(&h->mutex); + g_cond_clear(&h->cond); + + if (h->queue) { + while (!g_queue_is_empty(h->queue)) { + parcel = g_queue_pop_head(h->queue); + rpc_port_parcel_destroy(parcel); + } + + g_queue_free(h->queue); + } +#endif /* TIDL_THREAD_ENABLE */ + + if (h->instance) + free(h->instance); + + if (h->sender) + free(h->sender); + + free(h); +} + +static rpc_port_stub_vc_context_h __rpc_port_stub_vc_context_create(const char *sender, const char *instance, rpc_port_h callback_port) +{ + rpc_port_stub_vc_context_t *handle; + + if (sender == nullptr || instance == nullptr || callback_port == nullptr) { + _E("Invalid parameter"); + return nullptr; + } + + handle = calloc(1, sizeof(rpc_port_stub_vc_context_t)); + if (handle == nullptr) { + _E("Out of memory"); + return nullptr; + } + + handle->sender = strdup(sender); + if (handle->sender == nullptr) { + _E("Failed to duplicate sender"); + __rpc_port_stub_vc_context_destroy(handle); + return nullptr; + } + + handle->instance = strdup(instance); + if (handle->instance == nullptr) { + _E("Failed to duplicate instance"); + __rpc_port_stub_vc_context_destroy(handle); + return nullptr; + } + +#ifdef TIDL_THREAD_ENABLE + g_mutex_init(&handle->mutex); + g_cond_init(&handle->cond); + + handle->queue = g_queue_new(); + if (handle->queue == nullptr) { + _E("Failed to create queue"); + __rpc_port_stub_vc_context_destroy(handle); + return nullptr; + } + + handle->thread = g_thread_new(instance, __rpc_port_stub_vc_context_thread_cb, handle); + if (handle->thread == nullptr) { + _E("Failed to create thread"); + __rpc_port_stub_vc_context_destroy(handle); + return nullptr; + } +#endif /* TIDL_THREAD_ENABLE */ + + handle->callback_port = callback_port; + handle->callback = __vc.callback; + handle->user_data = __vc.user_data; + + return handle; +} + +int rpc_port_stub_vc_context_set_tag(rpc_port_stub_vc_context_h context, void *tag) +{ + if (context == nullptr) { + _E("Invalid parameter"); + return RPC_PORT_ERROR_INVALID_PARAMETER; + } + + context->tag = tag; + + return RPC_PORT_ERROR_NONE; +} + +int rpc_port_stub_vc_context_get_tag(rpc_port_stub_vc_context_h context, void **tag) +{ + if (context == nullptr || tag == nullptr) { + _E("Invalid parameter"); + return RPC_PORT_ERROR_INVALID_PARAMETER; + } + + *tag = context->tag; + + return RPC_PORT_ERROR_NONE; +} + +int rpc_port_stub_vc_context_get_sender(rpc_port_stub_vc_context_h context, char **sender) +{ + char *value; + + if (context == nullptr || sender == nullptr) { + _E("Invalid parameter"); + return RPC_PORT_ERROR_INVALID_PARAMETER; + } + + value = strdup(context->sender); + if (value == nullptr) { + _E("Failed to duplicate sender"); + return RPC_PORT_ERROR_OUT_OF_MEMORY; + } + + *sender = value; + + return RPC_PORT_ERROR_NONE; +} + +int rpc_port_stub_vc_context_get_instance(rpc_port_stub_vc_context_h context, char **instance) +{ + char *value; + + if (context == nullptr || instance == nullptr) { + _E("Invalid parameter"); + return RPC_PORT_ERROR_INVALID_PARAMETER; + } + + value = strdup(context->instance); + if (value == nullptr) { + _E("Failed to duplicate instance"); + return RPC_PORT_ERROR_OUT_OF_MEMORY; + } + + *instance = value; + + return RPC_PORT_ERROR_NONE; +} + +int rpc_port_stub_vc_context_disconnect(rpc_port_stub_vc_context_h context) +{ + int ret; + + if (context == nullptr) { + _E("Invalid parameter"); + return RPC_PORT_ERROR_INVALID_PARAMETER; + } + + g_rec_mutex_lock(&__vc.mutex); + + ret = rpc_port_disconnect(context->callback_port); + if (ret != RPC_PORT_ERROR_NONE) + _E("Failed to disconnect. error(%d)", ret); + + g_rec_mutex_unlock(&__vc.mutex); + + return ret; +} + +static rpc_port_stub_vc_context_h __rpc_port_stub_vc_find_context(const char *instance) +{ + rpc_port_stub_vc_context_h context; + GList *iter; + + g_rec_mutex_lock(&__vc.mutex); + iter = __vc.contexts; + while (iter) { + context = iter->data; + if (!strcmp(context->instance, instance)) { + g_rec_mutex_unlock(&__vc.mutex); + return context; + } + + iter = g_list_next(iter); + } + g_rec_mutex_unlock(&__vc.mutex); + + return nullptr; +} + +static void __rpc_port_stub_vc_add_context(rpc_port_stub_vc_context_h context) +{ + g_rec_mutex_lock(&__vc.mutex); + __vc.contexts = g_list_append(__vc.contexts, context); + g_rec_mutex_unlock(&__vc.mutex); +} + +static void __rpc_port_stub_vc_remove_context(rpc_port_stub_vc_context_h context) +{ + g_rec_mutex_lock(&__vc.mutex); + __vc.contexts = g_list_remove(__vc.contexts, context); + g_rec_mutex_unlock(&__vc.mutex); +} + +static bool __rpc_port_stub_vc_exist_callback_port(rpc_port_h callback_port) +{ + rpc_port_h port; + GList *iter; + + g_rec_mutex_lock(&__vc.mutex); + iter = __vc.callback_ports; + while (iter) { + port = iter->data; + if (port == callback_port) { + g_rec_mutex_unlock(&__vc.mutex); + return true; + } + + iter = g_list_next(iter); + } + g_rec_mutex_unlock(&__vc.mutex); + + return false; +} + +static void __rpc_port_stub_vc_add_callback_port(rpc_port_h callback_port) +{ + g_rec_mutex_lock(&__vc.mutex); + __vc.callback_ports = g_list_append(__vc.callback_ports, callback_port); + g_rec_mutex_unlock(&__vc.mutex); +} + +static void __rpc_port_stub_vc_remove_callback_port(rpc_port_h callback_port) +{ + g_rec_mutex_lock(&__vc.mutex); + __vc.callback_ports = g_list_remove(__vc.callback_ports, callback_port); + g_rec_mutex_unlock(&__vc.mutex); +} + +static void __rpc_port_stub_vc_connected_event_cb(const char *sender, const char *instance, void *user_data) +{ + rpc_port_stub_vc_context_h context; + rpc_port_h callback_port = nullptr; + int ret; + + _W("sender(%s), instance(%s)", sender, instance); + ret = rpc_port_stub_get_port(__vc.stub, RPC_PORT_PORT_CALLBACK, instance, &callback_port); + if (ret != RPC_PORT_ERROR_NONE) { + _E("Failed to get callback port. error(%d)", ret); + return; + } + + context = __rpc_port_stub_vc_context_create(sender, instance, callback_port); + if (context == nullptr) + return; + + __rpc_port_stub_vc_add_context(context); + __rpc_port_stub_vc_add_callback_port(context->callback_port); + context->callback.create(context, context->user_data); +} + +static void __rpc_port_stub_vc_disconnected_event_cb(const char *sender, const char *instance, void *user_data) +{ + rpc_port_stub_vc_context_h context; + + _W("sender(%s), instance(%s)", sender, instance); + context = __rpc_port_stub_vc_find_context(instance); + if (context == nullptr) + return; + + __rpc_port_stub_vc_remove_callback_port(context->callback_port); + context->callback.terminate(context, context->user_data); + __rpc_port_stub_vc_remove_context(context); + __rpc_port_stub_vc_context_destroy(context); +} + +static int __rpc_port_stub_vc_received_event_cb(const char *sender, const char *instance, rpc_port_h port, void *user_data) +{ + rpc_port_stub_vc_context_h context; + rpc_port_parcel_h parcel; + int ret; + + _W("sender(%s), instance(%s)", sender, instance); + context = __rpc_port_stub_vc_find_context(instance); + if (context == nullptr) { + _E("Failed to find context. instance(%s)", instance); + return RPC_PORT_ERROR_INVALID_PARAMETER; + } + + context->port = port; + ret = rpc_port_parcel_create_from_port(&parcel, port); + if (ret != RPC_PORT_ERROR_NONE) { + _E("Failed to create parcel handle from port. error(%d)", ret); + return ret; + } + +#ifdef TIDL_THREAD_ENABLE + ret = __rpc_port_stub_vc_context_push(context, parcel); +#else + ret = __rpc_port_stub_vc_context_handle_request(context, parcel); + rpc_port_parcel_destroy(parcel); +#endif /* TIDL_THREAD_ENABLE */ + + return ret; +} + +static int __rpc_port_stub_vc_set_access_control(void) +{ + int ret = RPC_PORT_ERROR_NONE; + + return ret; +} + +int rpc_port_stub_vc_register(rpc_port_stub_vc_callback_s *callback, void *user_data) +{ + int ret; + + if (callback == nullptr || callback->create == nullptr || callback->terminate == nullptr) { + _E("Invalid parameter"); + return RPC_PORT_ERROR_INVALID_PARAMETER; + } + + if (__vc.stub) { + _E("Already exists"); + return RPC_PORT_ERROR_NONE; + } + + g_rec_mutex_init(&__vc.mutex); + __vc.callback = *callback; + __vc.user_data = user_data; + + ret = rpc_port_stub_create(&__vc.stub, "vc"); + if (ret != RPC_PORT_ERROR_NONE) { + _E("Failed to create stub handle. error(%d)", ret); + g_rec_mutex_clear(&__vc.mutex); + return ret; + } + + ret = rpc_port_stub_add_received_event_cb(__vc.stub, __rpc_port_stub_vc_received_event_cb, &__vc); + if (ret != RPC_PORT_ERROR_NONE) { + _E("Failed to add received event callback"); + rpc_port_stub_vc_unregister(); + return ret; + } + + ret = rpc_port_stub_add_connected_event_cb(__vc.stub, __rpc_port_stub_vc_connected_event_cb, &__vc); + if (ret != RPC_PORT_ERROR_NONE) { + _E("Failed to add connected event callback"); + rpc_port_stub_vc_unregister(); + return ret; + } + + ret = rpc_port_stub_add_disconnected_event_cb(__vc.stub, __rpc_port_stub_vc_disconnected_event_cb, &__vc); + if (ret != RPC_PORT_ERROR_NONE) { + _E("Failed to add disconnected event callback"); + rpc_port_stub_vc_unregister(); + return ret; + } + + ret = __rpc_port_stub_vc_set_access_control(); + if (ret != RPC_PORT_ERROR_NONE) { + _E("Failed to add privileges"); + rpc_port_stub_vc_unregister(); + return ret; + } + + ret = rpc_port_stub_listen(__vc.stub); + if (ret != RPC_PORT_ERROR_NONE) { + _E("Failed to listen events. error(%d)", ret); + rpc_port_stub_vc_unregister(); + return ret; + } + + return RPC_PORT_ERROR_NONE; +} + +int rpc_port_stub_vc_unregister(void) +{ + if (__vc.stub == nullptr) + return RPC_PORT_ERROR_NONE; + + g_rec_mutex_lock(&__vc.mutex); + g_rec_mutex_unlock(&__vc.mutex); + g_rec_mutex_clear(&__vc.mutex); + + if (__vc.contexts) { + g_list_free_full(__vc.contexts, __rpc_port_stub_vc_context_destroy); + __vc.contexts = nullptr; + } + + if (__vc.stub) { + rpc_port_stub_destroy(__vc.stub); + __vc.stub = nullptr; + } + + return RPC_PORT_ERROR_NONE; +} + +int rpc_port_stub_vc_foreach_context(rpc_port_stub_vc_context_cb callback, void *user_data) +{ + rpc_port_stub_vc_context_h context; + GList *iter; + + if (callback == nullptr) { + _E("Invalid parameter"); + return RPC_PORT_ERROR_INVALID_PARAMETER; + } + + g_rec_mutex_lock(&__vc.mutex); + iter = __vc.contexts; + while (iter) { + context = iter->data; + if (!callback(context, user_data)) + break; + + iter = g_list_next(iter); + } + g_rec_mutex_unlock(&__vc.mutex); + + return RPC_PORT_ERROR_NONE; +} + +int rpc_port_stub_vc_get_client_number(unsigned int *client_number) +{ + if (client_number == nullptr) { + _E("Invalid parameter"); + return RPC_PORT_ERROR_INVALID_PARAMETER; + } + + if (__vc.stub == nullptr) { + _E("Invalid context"); + return RPC_PORT_ERROR_INVALID_PARAMETER; + } + + g_rec_mutex_lock(&__vc.mutex); + *client_number = g_list_length(__vc.contexts); + g_rec_mutex_unlock(&__vc.mutex); + + return RPC_PORT_ERROR_NONE; +} diff --git a/server/vcd_stub.h b/server/vcd_stub.h new file mode 100755 index 0000000..70c5013 --- /dev/null +++ b/server/vcd_stub.h @@ -0,0 +1,680 @@ +/* + * Generated by tidlc 1.8.1. + */ + +#pragma once + +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief The rpc_port_stub_array_char handle. + */ +typedef struct rpc_port_stub_array_char_s *rpc_port_stub_array_char_h; + +/** + * @brief The rpc_port_stub_vc_context handle. + */ +typedef struct rpc_port_stub_vc_context_s *rpc_port_stub_vc_context_h; + +/** + * @brief The rpc_port_stub_vc_notify_cb handle. + */ +typedef struct rpc_port_stub_vc_notify_cb_s *rpc_port_stub_vc_notify_cb_h; + +/** + * @brief The rpc_port_stub_vc_feedback_cb handle. + */ +typedef struct rpc_port_stub_vc_feedback_cb_s *rpc_port_stub_vc_feedback_cb_h; + +/** + * @briefs Creates a rpc_port_stub_array_char handle. + * + * @remarks The @a h should be released using the rpc_port_stub_array_char_destroy() + * if it's no longer needed. + * @param[out] h The rpc_port_stub_array_char handle that is newly created + * @return @c 0 on success, + * otherwise a negative error value + * @retval #RPC_PORT_ERROR_NONE Successful + * @retval #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #RPC_PORT_ERROR_OUT_OF_MEMORY Out of memory + * @see rpc_port_stub_array_char_destroy() + */ +int rpc_port_stub_array_char_create(rpc_port_stub_array_char_h *h); + +/** + * @brief Destroys the rpc_port_stub_array_char handle. + * + * @param[in] h The rpc_port_stub_array_char handle + * @return @c 0 on success, + * otherwise a negative error value + * @retval #RPC_PORT_ERROR_NONE Successful + * @retval #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter + * @see rpc_port_stub_array_char_create() + */ +int rpc_port_stub_array_char_destroy(rpc_port_stub_array_char_h h); + +/** + * @brief Creates and returns a copy of the given rpc_port_stub_array_char handle. + * + * @remarks A new created rpc_port_stub_array_char should be released using + * the rpc_port_stub_array_char_destroy() if it's no longer needed. + * @param[in] h The rpc_port_stub_array_char handle + * @param[out] clone If successful, a new created rpc_port_stub_array_char handle will be returned + * @return @c 0 on success, + * otherwise a negative error value + * @retval #RPC_PORT_ERROR_NONE Successful + * @retval #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #RPC_PORT_ERROR_OUT_OF_MEMORY Out of memory + * @see rpc_port_stub_array_char_destroy() + */ +int rpc_port_stub_array_char_clone(rpc_port_stub_array_char_h h, rpc_port_stub_array_char_h *clone); + +/** + * @brief Sets the value to the rpc_port_stub_array_char handle. + * + * @remarks The value is internally copied and stored. + * You should release it if it's allocaed when it's no longer needed, + * @param[in] h The rpc_port_stub_array_char handle + * @param[in] value The array value + * @param[in] size The size of the array + * @return @c 0 on success, + * otherwise a negative error value + * @retval #RPC_PORT_ERROR_NONE Successful + * @retval #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #RPC_PORT_ERROR_OUT_OF_MEMORY Out of memory + * @see rpc_port_stub_array_char_get() + */ +int rpc_port_stub_array_char_set(rpc_port_stub_array_char_h h, char *value, int size); + +/** + * @brief Gets the value from the rpc_port_stub_array_char handle. + * + * @remarks A new created value should be released if it's no longer needed. + * @param[in] h The rpc_port_stub_array_char handle + * @param[out] value The array value + * @param[out] size The size of the array + * @return @c 0 on success, + * otherwise a negative error value + * @retval #RPC_PORT_ERROR_NONE Successful + * @retval #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #RPC_PORT_ERROR_OUT_OF_MEMORY Out of memory + * @see rpc_port_stub_array_char_set() + */ +int rpc_port_stub_array_char_get(rpc_port_stub_array_char_h h, char **value, int *size); + +/** + * @brief Called when the proxy is connected. + * @details The callback function is called when the proxy is connected to the stub. + * + * @param[in] context The context handle + * @param[in] user_data The user data passed from the registration function + * @see #rpc_port_stub_vc_callback_s + */ +typedef void (*rpc_port_stub_vc_create_cb)(rpc_port_stub_vc_context_h context, void *user_data); + +/** + * @brief Called when the proxy is disconnected. + * @details The callback function is called when the proxy is disconnected from the stub. + * + * @param[in] context The context handle + * @param[in] user_data The user data passed from the registration function + * @see #rpc_port_stub_vc_callback_s + */ +typedef void (*rpc_port_stub_vc_terminate_cb)(rpc_port_stub_vc_context_h context, void *user_data); + +/** + * @brief Called to get the proxy context once for each connected proxy. + * + * @param[in] context The context handle + * @param[in] user_data The user data passed from the registration function + * @return @c true to continue with the next iteration of the loop, + * otherwise @c false to break out of the loop + * @pre rpc_port_stub_vc_foreach_context() will invoke this callback. + * @see rpc_port_stub_vc_foreach_context() + */ +typedef bool (*rpc_port_stub_vc_context_cb)(rpc_port_stub_vc_context_h context, void *user_data); + +/** + * @brief Called when the request of the proxy is delivered. + * + * @param[in] context The context handle + * @param[in] user_data The user data passed from the registration function + * @see #rpc_port_stub_vc_callback_s; + */ +typedef void (*rpc_port_stub_vc_register_notify_cb_cb)(rpc_port_stub_vc_context_h context, int pid, rpc_port_stub_vc_notify_cb_h callback, void *user_data); + +/** + * @brief Called when the request of the proxy is delivered. + * + * @param[in] context The context handle + * @param[in] user_data The user data passed from the registration function + * @see #rpc_port_stub_vc_callback_s; + */ +typedef int (*rpc_port_stub_vc_register_notify_cb_sync_cb)(rpc_port_stub_vc_context_h context, int pid, rpc_port_stub_vc_notify_cb_h callback, void *user_data); + +/** + * @brief Called when the request of the proxy is delivered. + * + * @param[in] context The context handle + * @param[in] user_data The user data passed from the registration function + * @see #rpc_port_stub_vc_callback_s; + */ +typedef void (*rpc_port_stub_vc_register_feedback_cb_cb)(rpc_port_stub_vc_context_h context, int pid, rpc_port_stub_vc_feedback_cb_h callback, void *user_data); + +/** + * @brief Called when the request of the proxy is delivered. + * + * @param[in] context The context handle + * @param[in] user_data The user data passed from the registration function + * @see #rpc_port_stub_vc_callback_s; + */ +typedef int (*rpc_port_stub_vc_register_feedback_cb_sync_cb)(rpc_port_stub_vc_context_h context, int pid, rpc_port_stub_vc_feedback_cb_h callback, void *user_data); + +/** + * @brief Called when the request of the proxy is delivered. + * + * @param[in] context The context handle + * @param[in] user_data The user data passed from the registration function + * @see #rpc_port_stub_vc_callback_s; + */ +typedef int (*rpc_port_stub_vc_initialize_cb)(rpc_port_stub_vc_context_h context, int pid, int *mgr_pid, int *service_state, int *daemon_pid, void *user_data); + +/** + * @brief Called when the request of the proxy is delivered. + * + * @param[in] context The context handle + * @param[in] user_data The user data passed from the registration function + * @see #rpc_port_stub_vc_callback_s; + */ +typedef int (*rpc_port_stub_vc_finalize_cb)(rpc_port_stub_vc_context_h context, int pid, void *user_data); + +/** + * @brief Called when the request of the proxy is delivered. + * + * @param[in] context The context handle + * @param[in] user_data The user data passed from the registration function + * @see #rpc_port_stub_vc_callback_s; + */ +typedef int (*rpc_port_stub_vc_set_command_cb)(rpc_port_stub_vc_context_h context, int pid, int cmd_type, void *user_data); + +/** + * @brief Called when the request of the proxy is delivered. + * + * @param[in] context The context handle + * @param[in] user_data The user data passed from the registration function + * @see #rpc_port_stub_vc_callback_s; + */ +typedef int (*rpc_port_stub_vc_unset_command_cb)(rpc_port_stub_vc_context_h context, int pid, int cmd_type, void *user_data); + +/** + * @brief Called when the request of the proxy is delivered. + * + * @param[in] context The context handle + * @param[in] user_data The user data passed from the registration function + * @see #rpc_port_stub_vc_callback_s; + */ +typedef int (*rpc_port_stub_vc_set_foreground_cb)(rpc_port_stub_vc_context_h context, int pid, bool value, void *user_data); + +/** + * @brief Called when the request of the proxy is delivered. + * + * @param[in] context The context handle + * @param[in] user_data The user data passed from the registration function + * @see #rpc_port_stub_vc_callback_s; + */ +typedef int (*rpc_port_stub_vc_set_server_dialog_cb)(rpc_port_stub_vc_context_h context, int pid, const char *app_id, const char *credential, void *user_data); + +/** + * @brief Called when the request of the proxy is delivered. + * + * @param[in] context The context handle + * @param[in] user_data The user data passed from the registration function + * @see #rpc_port_stub_vc_callback_s; + */ +typedef int (*rpc_port_stub_vc_request_dialog_cb)(rpc_port_stub_vc_context_h context, int pid, const char *disp_text, const char *utt_text, bool continuous, void *user_data); + +/** + * @brief Called when the request of the proxy is delivered. + * + * @param[in] context The context handle + * @param[in] user_data The user data passed from the registration function + * @see #rpc_port_stub_vc_callback_s; + */ +typedef int (*rpc_port_stub_vc_is_system_command_valid_cb)(rpc_port_stub_vc_context_h context, int pid, bool *is_sys_cmd_valid, void *user_data); + +/** + * @brief Called when the request of the proxy is delivered. + * + * @param[in] context The context handle + * @param[in] user_data The user data passed from the registration function + * @see #rpc_port_stub_vc_callback_s; + */ +typedef int (*rpc_port_stub_vc_auth_enable_cb)(rpc_port_stub_vc_context_h context, int pid, int mgr_pid, void *user_data); + +/** + * @brief Called when the request of the proxy is delivered. + * + * @param[in] context The context handle + * @param[in] user_data The user data passed from the registration function + * @see #rpc_port_stub_vc_callback_s; + */ +typedef int (*rpc_port_stub_vc_auth_disable_cb)(rpc_port_stub_vc_context_h context, int pid, int mgr_pid, void *user_data); + +/** + * @brief Called when the request of the proxy is delivered. + * + * @param[in] context The context handle + * @param[in] user_data The user data passed from the registration function + * @see #rpc_port_stub_vc_callback_s; + */ +typedef int (*rpc_port_stub_vc_auth_start_cb)(rpc_port_stub_vc_context_h context, int pid, int mgr_pid, void *user_data); + +/** + * @brief Called when the request of the proxy is delivered. + * + * @param[in] context The context handle + * @param[in] user_data The user data passed from the registration function + * @see #rpc_port_stub_vc_callback_s; + */ +typedef int (*rpc_port_stub_vc_auth_stop_cb)(rpc_port_stub_vc_context_h context, int pid, int mgr_pid, void *user_data); + +/** + * @brief Called when the request of the proxy is delivered. + * + * @param[in] context The context handle + * @param[in] user_data The user data passed from the registration function + * @see #rpc_port_stub_vc_callback_s; + */ +typedef int (*rpc_port_stub_vc_auth_cancel_cb)(rpc_port_stub_vc_context_h context, int pid, int mgr_pid, void *user_data); + +/** + * @brief Called when the request of the proxy is delivered. + * + * @param[in] context The context handle + * @param[in] user_data The user data passed from the registration function + * @see #rpc_port_stub_vc_callback_s; + */ +typedef int (*rpc_port_stub_vc_request_tts_cb)(rpc_port_stub_vc_context_h context, int pid, const char *text, const char *lang, bool to_vcm, int *utt_id, void *user_data); + +/** + * @brief Called when the request of the proxy is delivered. + * + * @param[in] context The context handle + * @param[in] user_data The user data passed from the registration function + * @see #rpc_port_stub_vc_callback_s; + */ +typedef int (*rpc_port_stub_vc_cancel_tts_cb)(rpc_port_stub_vc_context_h context, int pid, int utt_id, void *user_data); + +/** + * @brief Called when the request of the proxy is delivered. + * + * @param[in] context The context handle + * @param[in] user_data The user data passed from the registration function + * @see #rpc_port_stub_vc_callback_s; + */ +typedef int (*rpc_port_stub_vc_get_tts_audio_format_cb)(rpc_port_stub_vc_context_h context, int pid, int *rate, int *channel, int *audio_type, void *user_data); + +/** + * @brief Sets the tag to the context handle. + * + * @param[in] context The context handle + * @param[in] tag The tag + * @return @c 0 on success, + * otherwise a negative error value + * @retval #RPC_PORT_ERROR_NONE Successful + * @retval #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter + * @see rpc_port_stub_vc_context_get_tag() + */ +int rpc_port_stub_vc_context_set_tag(rpc_port_stub_vc_context_h context, void *tag); + +/** + * @brief Gets the tag from the context handle. + * + * @param[in] context The context handle + * @param[out] tag The tag + * @return @c 0 on success, + * otherwise a negative error value + * @retval #RPC_PORT_ERROR_NONE Successful + * @retval #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter + * @see rpc_port_stub_vc_context_set_tag() + */ +int rpc_port_stub_vc_context_get_tag(rpc_port_stub_vc_context_h context, void **tag); + +/** + * @brief Gets the sender ID from the context handle. + * @details The @a sender should be released using free(). + * + * @param[in] context The context handle + * @param[out] sender The sender ID of the context handle + * @return @c 0 on success, + * otherwise a negative error value + * @retval #RPC_PORT_ERROR_NONE Successful + * @retval #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #RPC_PORT_ERROR_OUT_OF_MEMORY Out of memory + */ +int rpc_port_stub_vc_context_get_sender(rpc_port_stub_vc_context_h context, char **sender); + +/** + * @brief Gets the instance ID from the context handle. + * @details The @a instance should be released using free(). + * + * @param[in] context The context handle + * @param[out] instance The instance ID of the context handle + * @return @c 0 on success, + * otherwise a negative error value + * @retval #RPC_PORT_ERROR_NONE Successful + * @retval #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #RPC_PORT_ERROR_OUT_OF_MEMORY Out of memory + */ +int rpc_port_stub_vc_context_get_instance(rpc_port_stub_vc_context_h context, char **instance); + +/** + * @brief Disconnects from the proxy. + * + * @param[in] context The context handle + * @return @c 0 on success, + * otherwise a negative error value + * @retval #RPC_PORT_ERROR_NONE Successful + * @retval #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter + */ +int rpc_port_stub_vc_context_disconnect(rpc_port_stub_vc_context_h context); + +/** + * @brief Creates a rpc_port_stub_vc_notify_cb handle. + * + * @param[out] h The rpc_port_stub_vc_notify_cb handle + * @return @c 0 on success, + * otherwise a negative error value + * @retval #RPC_PORT_ERROR_NONE Successful + * @retval #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #RPC_PORT_ERROR_OUT_OF_MEMORY Out of memory + * @see rpc_port_stub_vc_notify_cb_destroy() + */ +int rpc_port_stub_vc_notify_cb_create(rpc_port_stub_vc_notify_cb_h *h); + +/** + * @brief Destroys the rpc_port_stub_vc_notify_cb handle. + * + * @param[in] h The rpc_port_stub_vc_notify_cb handle + * @return @c 0 on success, + * otherwise a negative error value + * @retval #RPC_PORT_ERROR_NONE Successful + * @retval #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter + * @see rpc_port_stub_vc_notify_cb_clone() + */ +int rpc_port_stub_vc_notify_cb_destroy(rpc_port_stub_vc_notify_cb_h h); + +/** + * @brief Creates and returns a copy of the given rpc_port_stub_vc_notify_cb handle. + * + * @remarks A new created rpc_port_stub_vc_notify_cb should be released using + * the rpc_port_stub_vc_notify_cb_destroy() if it's no longer needed. + * @param[in] h The rpc_port_stub_vc_notify_cb handle + * @param[out] clone If successful, a new created rpc_port_stub_vc_notify_cb handle will be returned + * @return @c 0 on success, + * otherwise a negative error value + * @retval #RPC_PORT_ERROR_NONE Successful + * @retval #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #RPC_PORT_ERROR_OUT_OF_MEMORY Out of memory + * @see rpc_port_stub_vc_notify_cb_destroy() + */ +int rpc_port_stub_vc_notify_cb_clone(rpc_port_stub_vc_notify_cb_h h, rpc_port_stub_vc_notify_cb_h *clone); + +/** + * @brief Gets the ID of the rpc_port_stub_vc_notify_cb handle. + * + * @param[in] h The rpc_port_stub_vc_notify_cb handle + * @param[out] id The ID + * @return @c 0 on success, + * otherwise a negative error value + * @retval #RPC_PORT_ERROR_NONE Successful + * @retval #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter + */ +int rpc_port_stub_vc_notify_cb_get_id(rpc_port_stub_vc_notify_cb_h h, int *id); + +/** + * @brief Gets the sequence ID of the rpc_port_stub_vc_notify_cb handle. + * + * @param[in] h The rpc_port_stub_vc_notify_cb handle + * @param[out] seq_id The Sequence ID + * @return @c 0 on success, + * otherwise a negative error value + * @retval #RPC_PORT_ERROR_NONE Successful + * @retval #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter + */ +int rpc_port_stub_vc_notify_cb_get_seq_id(rpc_port_stub_vc_notify_cb_h h, int *seq_id); + +/** + * @brief Checks whether the delegate is for one-time or not. + * + * @param[in] h The rpc_port_stub_vc_notify_cb handle + * @param[out] once The flag, it's true, the handle is for one-time + * @return @c 0 on success, + * otherwise a negative error value + * @retval #RPC_PORT_ERROR_NONE Successful + * @retval #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter + */ +int rpc_port_stub_vc_notify_cb_is_once(rpc_port_stub_vc_notify_cb_h h, bool *once); + +/** + * @brief Gets the tag from the rpc_port_stub_vc_notify_cb handle. + * + * @remarks The @a tag should be released using free(). + * @param[in] h The rpc_port_stub_vc_notify_cb handle + * @param[out] tag The tag + * @return @c 0 on success, + * otherwise a negative error value + * @retval #RPC_PORT_ERROR_NONE Successful + * @retval #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #RPC_PORT_ERROR_OUT_OF_MEMORY Out of memory + */ +int rpc_port_stub_vc_notify_cb_get_tag(rpc_port_stub_vc_notify_cb_h h, char **tag); + +/** + * @brief Invokes the callback function of the rpc_port_stub_vc_notify_cb handle. + * + * @param[in] h The rpc_port_stub_vc_notify_cb handle + * @param[in] ... + * @return @c 0 on success, + * otherwise a negative error value + * @retval #RPC_PORT_ERROR_NONE Successful + * @retval #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #RPC_PORT_ERROR_OUT_OF_MEMORY Out of memory + * @retval #RPC_PORT_ERROR_IO_ERROR I/O error + */ +int rpc_port_stub_vc_notify_cb_invoke(rpc_port_stub_vc_notify_cb_h h, int pid, bundle *msg); + +/** + * @brief Creates a rpc_port_stub_vc_feedback_cb handle. + * + * @param[out] h The rpc_port_stub_vc_feedback_cb handle + * @return @c 0 on success, + * otherwise a negative error value + * @retval #RPC_PORT_ERROR_NONE Successful + * @retval #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #RPC_PORT_ERROR_OUT_OF_MEMORY Out of memory + * @see rpc_port_stub_vc_feedback_cb_destroy() + */ +int rpc_port_stub_vc_feedback_cb_create(rpc_port_stub_vc_feedback_cb_h *h); + +/** + * @brief Destroys the rpc_port_stub_vc_feedback_cb handle. + * + * @param[in] h The rpc_port_stub_vc_feedback_cb handle + * @return @c 0 on success, + * otherwise a negative error value + * @retval #RPC_PORT_ERROR_NONE Successful + * @retval #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter + * @see rpc_port_stub_vc_feedback_cb_clone() + */ +int rpc_port_stub_vc_feedback_cb_destroy(rpc_port_stub_vc_feedback_cb_h h); + +/** + * @brief Creates and returns a copy of the given rpc_port_stub_vc_feedback_cb handle. + * + * @remarks A new created rpc_port_stub_vc_feedback_cb should be released using + * the rpc_port_stub_vc_feedback_cb_destroy() if it's no longer needed. + * @param[in] h The rpc_port_stub_vc_feedback_cb handle + * @param[out] clone If successful, a new created rpc_port_stub_vc_feedback_cb handle will be returned + * @return @c 0 on success, + * otherwise a negative error value + * @retval #RPC_PORT_ERROR_NONE Successful + * @retval #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #RPC_PORT_ERROR_OUT_OF_MEMORY Out of memory + * @see rpc_port_stub_vc_feedback_cb_destroy() + */ +int rpc_port_stub_vc_feedback_cb_clone(rpc_port_stub_vc_feedback_cb_h h, rpc_port_stub_vc_feedback_cb_h *clone); + +/** + * @brief Gets the ID of the rpc_port_stub_vc_feedback_cb handle. + * + * @param[in] h The rpc_port_stub_vc_feedback_cb handle + * @param[out] id The ID + * @return @c 0 on success, + * otherwise a negative error value + * @retval #RPC_PORT_ERROR_NONE Successful + * @retval #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter + */ +int rpc_port_stub_vc_feedback_cb_get_id(rpc_port_stub_vc_feedback_cb_h h, int *id); + +/** + * @brief Gets the sequence ID of the rpc_port_stub_vc_feedback_cb handle. + * + * @param[in] h The rpc_port_stub_vc_feedback_cb handle + * @param[out] seq_id The Sequence ID + * @return @c 0 on success, + * otherwise a negative error value + * @retval #RPC_PORT_ERROR_NONE Successful + * @retval #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter + */ +int rpc_port_stub_vc_feedback_cb_get_seq_id(rpc_port_stub_vc_feedback_cb_h h, int *seq_id); + +/** + * @brief Checks whether the delegate is for one-time or not. + * + * @param[in] h The rpc_port_stub_vc_feedback_cb handle + * @param[out] once The flag, it's true, the handle is for one-time + * @return @c 0 on success, + * otherwise a negative error value + * @retval #RPC_PORT_ERROR_NONE Successful + * @retval #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter + */ +int rpc_port_stub_vc_feedback_cb_is_once(rpc_port_stub_vc_feedback_cb_h h, bool *once); + +/** + * @brief Gets the tag from the rpc_port_stub_vc_feedback_cb handle. + * + * @remarks The @a tag should be released using free(). + * @param[in] h The rpc_port_stub_vc_feedback_cb handle + * @param[out] tag The tag + * @return @c 0 on success, + * otherwise a negative error value + * @retval #RPC_PORT_ERROR_NONE Successful + * @retval #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #RPC_PORT_ERROR_OUT_OF_MEMORY Out of memory + */ +int rpc_port_stub_vc_feedback_cb_get_tag(rpc_port_stub_vc_feedback_cb_h h, char **tag); + +/** + * @brief Invokes the callback function of the rpc_port_stub_vc_feedback_cb handle. + * + * @param[in] h The rpc_port_stub_vc_feedback_cb handle + * @param[in] ... + * @return @c 0 on success, + * otherwise a negative error value + * @retval #RPC_PORT_ERROR_NONE Successful + * @retval #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #RPC_PORT_ERROR_OUT_OF_MEMORY Out of memory + * @retval #RPC_PORT_ERROR_IO_ERROR I/O error + */ +int rpc_port_stub_vc_feedback_cb_invoke(rpc_port_stub_vc_feedback_cb_h h, int utt_id, int event, rpc_port_stub_array_char_h pcm_data, int len); + +/** + * @brief The structure type containing the set of callback functions for handling stub events. + * @details It is one of the input parameters of the rpc_port_stub_vc_register() function. + * + * @see rpc_port_stub_vc_create_cb + * @see rpc_port_stub_vc_terminate_cb + */ +typedef struct { + rpc_port_stub_vc_create_cb create; /**< This callback function is invoked when the proxy is connected. */ + rpc_port_stub_vc_terminate_cb terminate; /**< This callback function is invoked when the proxy is disconnected. */ + rpc_port_stub_vc_register_notify_cb_cb register_notify_cb; /**< This callback function is invoked when the register_notify_cb request is delivered. */ + rpc_port_stub_vc_register_notify_cb_sync_cb register_notify_cb_sync; /**< This callback function is invoked when the register_notify_cb_sync request is delivered. */ + rpc_port_stub_vc_register_feedback_cb_cb register_feedback_cb; /**< This callback function is invoked when the register_feedback_cb request is delivered. */ + rpc_port_stub_vc_register_feedback_cb_sync_cb register_feedback_cb_sync; /**< This callback function is invoked when the register_feedback_cb_sync request is delivered. */ + rpc_port_stub_vc_initialize_cb initialize; /**< This callback function is invoked when the initialize request is delivered. */ + rpc_port_stub_vc_finalize_cb finalize; /**< This callback function is invoked when the finalize request is delivered. */ + rpc_port_stub_vc_set_command_cb set_command; /**< This callback function is invoked when the set_command request is delivered. */ + rpc_port_stub_vc_unset_command_cb unset_command; /**< This callback function is invoked when the unset_command request is delivered. */ + rpc_port_stub_vc_set_foreground_cb set_foreground; /**< This callback function is invoked when the set_foreground request is delivered. */ + rpc_port_stub_vc_set_server_dialog_cb set_server_dialog; /**< This callback function is invoked when the set_server_dialog request is delivered. */ + rpc_port_stub_vc_request_dialog_cb request_dialog; /**< This callback function is invoked when the request_dialog request is delivered. */ + rpc_port_stub_vc_is_system_command_valid_cb is_system_command_valid; /**< This callback function is invoked when the is_system_command_valid request is delivered. */ + rpc_port_stub_vc_auth_enable_cb auth_enable; /**< This callback function is invoked when the auth_enable request is delivered. */ + rpc_port_stub_vc_auth_disable_cb auth_disable; /**< This callback function is invoked when the auth_disable request is delivered. */ + rpc_port_stub_vc_auth_start_cb auth_start; /**< This callback function is invoked when the auth_start request is delivered. */ + rpc_port_stub_vc_auth_stop_cb auth_stop; /**< This callback function is invoked when the auth_stop request is delivered. */ + rpc_port_stub_vc_auth_cancel_cb auth_cancel; /**< This callback function is invoked when the auth_cancel request is delivered. */ + rpc_port_stub_vc_request_tts_cb request_tts; /**< This callback function is invoked when the request_tts request is delivered. */ + rpc_port_stub_vc_cancel_tts_cb cancel_tts; /**< This callback function is invoked when the cancel_tts request is delivered. */ + rpc_port_stub_vc_get_tts_audio_format_cb get_tts_audio_format; /**< This callback function is invoked when the get_tts_audio_format request is delivered. */ +} rpc_port_stub_vc_callback_s; + +/** + * @brief Registers the set of the callback functions and the port. + * @details This function registers the set of the callback functions to handle stub events. + * And, the rpc_port_stub_listen() is called internally to handle events. + * + * @param[in] callback The set of callback functions to handle stub events + * @param[in] user_data The user data to be passed to the callback function + * @return @c 0 on success, + * otherwise a negative error value + * @retval #RPC_PORT_ERROR_NONE Successful + * @retval #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #RPC_PORT_ERROR_OUT_OF_MEMORY Out of memory + * @retval #RPC_PORT_ERROR_IO_ERROR I/O error + * @retval #RPC_PORT_ERROR_PERMISSION_DENIED Permission denied + * @see rpc_port_stub_vc_unregister() + * @see #rpc_port_stub_vc_callback_s + */ +int rpc_port_stub_vc_register(rpc_port_stub_vc_callback_s *callback, void *user_data); + +/** + * @brief Unregisters the registered port. + */ +int rpc_port_stub_vc_unregister(void); + +/** + * @brief Retrieves the connected context handles. + * + * @param[in] callback The callback function + * @param[in] user_data The user data to be passed to the callback function + * @return @c 0 on success, + * otherwise a negative error value + * @retval #RPC_PORT_ERROR_NONE Successful + * @retval #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter + * @see rpc_port_stub_vc_context_cb() + */ +int rpc_port_stub_vc_foreach_context(rpc_port_stub_vc_context_cb callback, void *user_data); + +/** + * @brief Gets the number of connected clients. + * + * @param[out] client_number The client number + * @return @c 0 on success, + * otherwise a negative error value + * @retval #RPC_PORT_ERROR_NONE Successful + * @retval #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter + */ +int rpc_port_stub_vc_get_client_number(unsigned int *client_number); + +#ifdef __cplusplus +} +#endif diff --git a/server/vcd_tidl.c b/server/vcd_tidl.c index 784f9c0..c81e81c 100644 --- a/server/vcd_tidl.c +++ b/server/vcd_tidl.c @@ -20,11 +20,13 @@ #include "vcd_config.h" #include "vcd_tidl.h" +#include "vcd_stub.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; @@ -33,6 +35,8 @@ static rpc_port_stub_vc_widget_callback_s g_widget_callback; static pthread_mutex_t g_widget_tidl_info_mutex = PTHREAD_MUTEX_INITIALIZER; +static rpc_port_stub_vc_callback_s g_vc_callback; + static int g_volume_count = 0; int vcd_mgr_tidl_open_connection(); @@ -309,6 +313,497 @@ void __send_signal(bundle* msg) pthread_mutex_unlock(&g_widget_tidl_info_mutex); } +/** + * TIDL functions for VC client + */ + +static void __vc_create_cb(rpc_port_stub_vc_context_h context, void *user_data) +{ + SLOG(LOG_INFO, TAG_VCD, "[TIDL] __vc_create_cb"); + + char *sender = NULL; + + rpc_port_stub_SamsungAIAppPort_context_get_sender(context, &sender); + if (!sender) { + SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Sender is NULL"); + return ; + } + + SLOG(LOG_INFO, TAG_VCD, "[TIDL] sender(%s)", sender); // sender (app_id) + free(sender); +} + +static void __vc_terminate_cb(rpc_port_stub_vc_context_h context, void *user_data) +{ + SLOG(LOG_INFO, TAG_VCD, "[TIDL] __vc_terminate_cb"); +} + +static void __vc_register_notify_cb_cb(rpc_port_stub_vc_context_h context, int pid, rpc_port_stub_vc_notify_cb_h callback, void *user_data) +{ + SLOG(LOG_INFO, TAG_VCD, "[TIDL] __vc_register_notify_cb_cb. pid(%d)", pid); + + if (NULL == callback) { + SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] callback is null."); + return ; + } + + int ret = -1; + ret = vcd_client_add_ipc_info(pid); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to add ipc info."); + return ; + } + + ret = vcd_client_set_ipc_notify_cb(pid, callback, user_data); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to set notify callback."); + } else { + SLOG(LOG_INFO, TAG_VCD, "[TIDL] Succeed to set notify callback."); + } +} + +static int __vc_register_notify_cb_sync_cb(rpc_port_stub_vc_context_h context, int pid, rpc_port_stub_vc_notify_cb_h callback, void *user_data) +{ + SLOG(LOG_INFO, TAG_VCD, "[TIDL] __vc_register_notify_cb_sync_cb. pid(%d)", pid); + + if (NULL == callback) { + SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] callback is null."); + return VCD_ERROR_INVALID_PARAMETER; + } + + int ret = -1; + ret = vcd_client_add_ipc_info(pid); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to add ipc info."); + return ret; + } + + ret = vcd_client_set_ipc_notify_cb(pid, callback, user_data); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to set notify callback."); + } else { + SLOG(LOG_INFO, TAG_VCD, "[TIDL] Succeed to set notify callback."); + } + + return ret; +} + +static void __vc_register_feedback_cb_cb(rpc_port_stub_vc_context_h context, int pid, rpc_port_stub_vc_feedback_cb_h callback, void *user_data) +{ + SLOG(LOG_INFO, TAG_VCD, "[TIDL] __vc_register_feedback_cb_cb. pid(%d)", pid); + + if (NULL == callback) { + SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] callback is null."); + return ; + } + + int ret = -1; + ret = vcd_client_add_ipc_info(pid); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to add ipc info."); + return ; + } + + ret = vcd_client_set_ipc_feedback_cb(pid, callback, user_data); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to set feedback callback."); + } else { + SLOG(LOG_INFO, TAG_VCD, "[TIDL] Succeed to set feedback callback."); + } +} + +static int __vc_register_feedback_cb_sync_cb(rpc_port_stub_vc_context_h context, int pid, rpc_port_stub_vc_feedback_cb_h callback, void *user_data) +{ + SLOG(LOG_INFO, TAG_VCD, "[TIDL] __vc_register_feedback_cb_sync_cb. pid(%d)", pid); + + if (NULL == callback) { + SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] callback is null."); + return VCD_ERROR_INVALID_PARAMETER; + } + + int ret = -1; + ret = vcd_client_add_ipc_info(pid); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to add ipc info."); + return ret; + } + + ret = vcd_client_set_ipc_feedback_cb(pid, callback, user_data); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to set feedback callback."); + } else { + SLOG(LOG_INFO, TAG_VCD, "[TIDL] Succeed to set feedback callback."); + } + + return ret; +} + +static int __vc_initialize_cb(rpc_port_stub_vc_context_h context, int pid, int *mgr_pid, int *service_state, int *daemon_pid, void *user_data) +{ + SLOG(LOG_INFO, TAG_VCD, "[TIDL] __vc_initialize_cb. pid(%d)", pid); + + int ret = VCD_ERROR_OPERATION_FAILED; + + ret = vcd_server_initialize(pid); + *service_state = vcd_server_get_service_state(); + *daemon_pid = getpid(); + *mgr_pid = vcd_client_manager_get_pid(); + + if (VCD_ERROR_NONE == ret) { + SLOG(LOG_INFO, TAG_VCD, "[IN] vcd initialize : pid(%d) daemon_pid(%d)", pid, daemon_pid); + } else { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to vcd initialize : pid(%d) daemon_pid(%d) ret(%d)", pid, daemon_pid, ret); + } + + return ret; +} + +static int __vc_finalize_cb(rpc_port_stub_vc_context_h context, int pid, void *user_data) +{ + SLOG(LOG_INFO, TAG_VCD, "[TIDL] __vc_finalize_cb"); + + int ret = VCD_ERROR_OPERATION_FAILED; + + ret = vcd_server_finalize(pid); + if (VCD_ERROR_NONE == ret) { + SLOG(LOG_INFO, TAG_VCD, "[IN] vcd finalize : pid(%d)", pid); + } else { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to vcd finalize : pid(%d) ret(%d)", pid, ret); + } + + return ret; +} + +static int __vc_set_command_cb(rpc_port_stub_vc_context_h context, int pid, int cmd_type, void *user_data) +{ + SLOG(LOG_INFO, TAG_VCD, "[TIDL] __vc_set_command_cb"); + + int ret = VCD_ERROR_OPERATION_FAILED; + + ret = vcd_server_set_command(pid, (vc_cmd_type_e)cmd_type); + if (VCD_ERROR_NONE == ret) { + SLOG(LOG_INFO, TAG_VCD, "[IN] vcd set command : pid(%d), cmd_type(%d)", pid, cmd_type); + } else { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to vcd set command : pid(%d), cmd_type(%d) ret(%d)", pid, cmd_type, ret); + } + + return ret; +} + +static int __vc_unset_command_cb(rpc_port_stub_vc_context_h context, int pid, int cmd_type, void *user_data) +{ + SLOG(LOG_INFO, TAG_VCD, "[TIDL] __vc_unset_command_cb"); + + int ret = VCD_ERROR_OPERATION_FAILED; + + ret = vcd_server_unset_command(pid, (vc_cmd_type_e)cmd_type); + if (VCD_ERROR_NONE == ret) { + SLOG(LOG_INFO, TAG_VCD, "[IN] vcd unset command : pid(%d), cmd_type(%d)", pid, cmd_type); + } else { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to vcd unset command : pid(%d), cmd_type(%d) ret(%d)", pid, cmd_type, ret); + } + + return ret; +} + +static int __vc_set_foreground_cb(rpc_port_stub_vc_context_h context, int pid, bool value, void *user_data) +{ + // check more... + SLOG(LOG_INFO, TAG_VCD, "[TIDL] __vc_set_foreground_cb"); + + int ret = VCD_ERROR_OPERATION_FAILED; + + ret = vcd_server_set_foreground(pid, value); + if (VCD_ERROR_NONE == ret) { + SLOG(LOG_INFO, TAG_VCD, "[IN] vcd set foreground : pid(%d)", pid); + } else { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to vcd set foreground : pid(%d) ret(%d)", pid, ret); + } + + return ret; +} + +static int __vc_set_server_dialog_cb(rpc_port_stub_vc_context_h context, int pid, const char *app_id, const char *credential, void *user_data) +{ + SLOG(LOG_INFO, TAG_VCD, "[TIDL] __vc_set_server_dialog_cb"); + + int ret = VCD_ERROR_OPERATION_FAILED; + + ret = vcd_server_set_server_dialog(pid, app_id, credential); + if (VCD_ERROR_NONE == ret) { + SLOG(LOG_INFO, TAG_VCD, "[IN] vcd set server dialog : pid(%d), app_id(%s)", pid, app_id); + } else { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to vcd set server dialog : pid(%d), app_id(%s) ret(%d)", pid, app_id, ret); + } + + return ret; +} + +static int __vc_request_dialog_cb(rpc_port_stub_vc_context_h context, int pid, const char *disp_text, const char *utt_text, bool continuous, void *user_data) +{ + SLOG(LOG_INFO, TAG_VCD, "[TIDL] __vc_request_dialog_cb"); + + int ret = VCD_ERROR_OPERATION_FAILED; + + ret = vcd_server_dialog(pid, disp_text, utt_text, continuous); + if (VCD_ERROR_NONE == ret) { + SLOG(LOG_INFO, TAG_VCD, "[IN] vcd request dialog : pid(%d), disp_text(%s), utt_text(%s), continuous(%d)", pid, disp_text, utt_text, continuous); + } else { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to vcd request dialog : pid(%d), disp_text(%s), utt_text(%s), continuous(%d), ret(%d)", pid, disp_text, utt_text, continuous, ret(%d)); + } + + return ret; +} + +static int __vc_is_system_command_valid_cb(rpc_port_stub_vc_context_h context, int pid, bool *is_sys_cmd_valid, void *user_data) +{ + SLOG(LOG_INFO, TAG_VCD, "[TIDL] __vc_is_system_command_valid_cb"); + + int ret = VCD_ERROR_OPERATION_FAILED; + + ret = vcd_server_is_system_command_valid(pid, &is_sys_cmd_valid); + if (VCD_ERROR_NONE == ret) { + SLOG(LOG_INFO, TAG_VCD, "[IN] vcd check system command is valid : pid(%d), is_sys_cmd_valid(%d)", pid, *is_sys_cmd_valid); + } else { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to vcd check system command is valid : pid(%d), ret(%d)", pid, ret); + } + + return ret; +} + +static int __vc_auth_enable_cb(rpc_port_stub_vc_context_h context, int pid, int mgr_pid, void *user_data) +{ + SLOG(LOG_INFO, TAG_VCD, "[TIDL] __vc_auth_enable_cb"); + +} + +static int __vc_auth_disable_cb(rpc_port_stub_vc_context_h context, int pid, int mgr_pid, void *user_data) +{ + SLOG(LOG_INFO, TAG_VCD, "[TIDL] __vc_auth_disable_cb"); +} + +static int __vc_auth_start_cb(rpc_port_stub_vc_context_h context, int pid, int mgr_pid, void *user_data) +{ + SLOG(LOG_INFO, TAG_VCD, "[TIDL] __vc_auth_start_cb"); +} + +static int __vc_auth_stop_cb(rpc_port_stub_vc_context_h context, int pid, int mgr_pid, void *user_data) +{ + SLOG(LOG_INFO, TAG_VCD, "[TIDL] __vc_auth_stop_cb"); +} + +static int __vc_auth_cancel_cb(rpc_port_stub_vc_context_h context, int pid, int mgr_pid, void *user_data) +{ + SLOG(LOG_INFO, TAG_VCD, "[TIDL] __vc_auth_cancel_cb"); +} + +static int __vc_request_tts_cb(rpc_port_stub_vc_context_h context, int pid, const char *text, const char *lang, bool to_vcm, int *utt_id, void *user_data) +{ + SLOG(LOG_INFO, TAG_VCD, "[TIDL] __vc_request_tts_cb"); + + int ret = VCD_ERROR_OPERATION_FAILED; + + ret = vcd_server_request_tts(pid, text, lang, to_vcm, &utt_id); + if (VCD_ERROR_NONE == ret) { + SLOG(LOG_INFO, TAG_VCD, "[IN] vcd request tts : pid(%d), text(%s), language(%s), to_vcm(%d)", pid, text, lang, to_vcm); + } else { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to vcd request tts : pid(%d), text(%s), language(%s), to_vcm(%d), ret(%d)", pid, text, lang, to_vcm, ret); + } + + return ret; +} + +static int __vc_cancel_tts_cb(rpc_port_stub_vc_context_h context, int pid, int utt_id, void *user_data) +{ + SLOG(LOG_INFO, TAG_VCD, "[TIDL] __vc_cancel_tts_cb"); + + int ret = VCD_ERROR_OPERATION_FAILED; + + ret = vcd_server_cancel_tts(pid, utt_id); + if (VCD_ERROR_NONE == ret) { + SLOG(LOG_INFO, TAG_VCD, "[IN] vcd cancel tts : pid(%d), utt_id(%d)", pid, utt_id); + } else { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to vcd cancel tts : pid(%d), utt_id(%d), ret(%d)", pid, utt_id, ret); + } + + return ret; +} + +static int __vc_get_tts_audio_format_cb(rpc_port_stub_vc_context_h context, int pid, int *rate, int *channel, int *audio_type, void *user_data) +{ + SLOG(LOG_INFO, TAG_VCD, "[TIDL] __vc_get_tts_audio_format_cb"); + + int ret = VCD_ERROR_OPERATION_FAILED; + + ret = vcd_server_get_tts_audio_format(pid, &rate, &channel, &audio_type); + if (VCD_ERROR_NONE == ret) { + SLOG(LOG_INFO, TAG_VCD, "[IN] vcd get tts audio format : pid(%d), rate(%d), channel(%d), audio_type(%d)", pid, *rate, *channel, *audio_type); + } else { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to vcd get tts audio format : pid(%d) ret(%d)", pid, ret); + } + + return ret; +} + +int vcd_tidl_open_connection() +{ + SLOG(LOG_INFO, TAG_VCD, "[TIDL] vcd_tidl_open_connection"); + + g_vc_callback.create = __vc_create_cb; + g_vc_callback.terminate = __vc_terminate_cb; + g_vc_callback.register_notify_cb = __vc_register_notify_cb_cb; + g_vc_callback.register_notify_cb_sync = __vc_register_notify_cb_sync_cb; + g_vc_callback.register_feedback_cb = __vc_register_feedback_cb_cb; + g_vc_callback.register_feedback_cb_sync = __vc_register_feedback_cb_sync_cb; + g_vc_callback.initialize = __vc_initialize_cb; + g_vc_callback.finalize = __vc_finalize_cb; + g_vc_callback.set_command = __vc_set_command_cb; + g_vc_callback.unset_command = __vc_unset_command_cb; + g_vc_callback.set_foreground = __vc_set_foreground_cb; + g_vc_callback.set_server_dialog = __vc_set_server_dialog_cb; + g_vc_callback.request_dialog = __vc_request_dialog_cb; + g_vc_callback.is_system_command_valid = __vc_is_system_command_valid_cb; + g_vc_callback.auth_enable = __vc_auth_enable_cb; + g_vc_callback.auth_disable = __vc_auth_disable_cb; + g_vc_callback.auth_start = __vc_auth_start_cb; + g_vc_callback.auth_stop = __vc_auth_stop_cb; + g_vc_callback.auth_cancel = __vc_auth_cancel_cb; + g_vc_callback.request_tts = __vc_request_tts_cb; + g_vc_callback.cancel_tts = __vc_cancel_tts_cb; + g_vc_callback.get_tts_audio_format = __vc_get_tts_audio_format_cb; + + int ret = -1; + ret = rpc_port_stub_vc_register(&g_vc_callback, NULL); + if (VCD_ERROR_NONE != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to register TIDL callbacks. ret(%d)", ret); + return VCD_ERROR_OPERATION_FAILED; + } + + return VCD_ERROR_NONE; +} + +int vcd_tidl_close_connection() +{ + SLOG(LOG_INFO, TAG_VCD, "[TIDL] vcd_tidl_close_connection"); + rpc_port_stub_vc_unregister(); + + return VCD_ERROR_NONE; +} + +int vcdc_send_result(int pid, int manager_pid, int cmd_type) +{ + client_ipc_info_s* info = vcd_client_get_ipc_info(pid); + if (NULL == info) { + SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to get ipc info. pid(%d)", pid); + return VCD_ERROR_INVALID_PARAMETER; + } + + bundle* bundle_data = bundle_create(); + if (NULL == bundle_data) { + SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to create bundle data"); + return VCD_ERROR_OUT_OF_MEMORY; + } + + SLOG(LOG_INFO, TAG_VCD, "[TIDL] Result command type(%d)", cmd_type); + + char pid_char[10] = {0}; + snprintf(pid_char, 10, "%d", pid); + bundle_add_str(bundle_data, VC_BUNDLE_PID, pid_char); + + switch (cmd_type) { + case VC_COMMAND_TYPE_FOREGROUND: + case VC_COMMAND_TYPE_BACKGROUND: + if (pid == manager_pid) { + bundle_add_str(bundle_data, VC_BUNDLE_METHOD, VCD_MANAGER_METHOD_RESULT); + } else { + bundle_add_str(bundle_data, VC_BUNDLE_METHOD, VCD_METHOD_RESULT); + } + break; + case VC_COMMAND_TYPE_WIDGET: + bundle_add_str(bundle_data, VC_BUNDLE_METHOD, VCD_WIDGET_METHOD_RESULT); + break; + case VC_COMMAND_TYPE_SYSTEM: + case VC_COMMAND_TYPE_SYSTEM_BACKGROUND: + case VC_COMMAND_TYPE_EXCLUSIVE: + bundle_add_str(bundle_data, VC_BUNDLE_METHOD, VCD_MANAGER_METHOD_RESULT); + break; + + default: + SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Command type is NOT valid(%d)", cmd_type); + return -1; + } + + rpc_port_stub_vc_notify_cb_invoke(info->notify_cb, pid, bundle_data); + + return VCD_ERROR_NONE; +} + +int vcdc_send_error_signal_to_app(int pid, int reason, char *err_msg) +{ + if (NULL == err_msg) { + SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Input parameter is NULL"); + return VCD_ERROR_INVALID_PARAMETER; + } + + client_ipc_info_s* info = vcd_client_get_ipc_info(pid); + if (NULL == info) { + SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to get ipc info. pid(%d)", pid); + return VCD_ERROR_INVALID_PARAMETER; + } + + bundle* bundle_data = bundle_create(); + if (NULL == bundle_data) { + SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to create bundle data"); + return VCD_ERROR_OUT_OF_MEMORY; + } + + SLOG(LOG_INFO, TAG_VCD, "[TIDL] Send error signal to app(%d)", pid); + + char pid_char[10] = {0}; + char reason_char[10] = {0}; + snprintf(pid_char, 10, "%d", pid); + snprintf(reason_char, 10, "%d", reason); + + bundle_add_str(bundle_data, VC_BUNDLE_METHOD, VCD_METHOD_ERROR_TO_APP); + bundle_add_str(bundle_data, VC_BUNDLE_PID, pid_char); + bundle_add_str(bundle_data, VC_BUNDLE_REASON, reason_char); + bundle_add_str(bundle_data, VC_BUNDLE_ERR_MSG, err_msg); + + rpc_port_stub_vc_notify_cb_invoke(info->notify_cb, pid, bundle_data); + + return VCD_ERROR_NONE; +} + +int vcdc_send_feedback_streaming(int pid, int utt_id, vc_feedback_event_e event, char* buffer, int len) +{ + if (NULL == buffer || 0 >= len) { + SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Invalid parameter"); + return VCD_ERROR_INVALID_PARAMETER; + } + + client_ipc_info_s* info = vcd_client_get_ipc_info(pid); + if (NULL == info) { + SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to get ipc info. pid(%d)", pid); + return VCD_ERROR_INVALID_PARAMETER; + } + + bundle* bundle_data = bundle_create(); + if (NULL == bundle_data) { + SLOG(LOG_ERROR, TAG_VCD, "[TIDL ERROR] Fail to create bundle data"); + return VCD_ERROR_OUT_OF_MEMORY; + } + + SLOG(LOG_INFO, TAG_VCD, "[TIDL] Send feedback streaming to app(%d), utt_id(%d), event(%d), length(%d)", pid, utt_id, event, len); + + rpc_port_stub_array_char_h arr_char = NULL; + rpc_port_stub_array_char_create(&arr_char); + rpc_port_stub_array_char_set(arr_char, buffer, len); + + rpc_port_stub_vc_feedback_cb_invoke(info->feedback_cb, utt_id, event, arr_char, len); + + return VCD_ERROR_NONE; +} + // TODO: remove _tidl after all dbus removed int vcdc_tidl_send_hello(int pid, vcd_client_type_e type) { diff --git a/server/vcd_tidl.h b/server/vcd_tidl.h index 84e61f8..a4cd96e 100644 --- a/server/vcd_tidl.h +++ b/server/vcd_tidl.h @@ -30,6 +30,7 @@ extern "C" { // VCD_CLIENT_TYPE_MANAGER // } vcd_client_type_e; + int vcd_tidl_open_connection(); int vcd_tidl_close_connection(); @@ -69,9 +70,18 @@ int vcdc_send_feedback_audio_format_to_manager(int manager_pid, int rate, vc_aud 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_result(int pid, int manager_pid, int cmd_type); + +int vcdc_send_error_signal_to_app(int pid, int reason, char *err_msg); + +int vcdc_send_feedback_streaming(int pid, int utt_id, vc_feedback_event_e event, char* buffer, int len); #ifdef __cplusplus } #endif +<<<<<<< HEAD +#endif /* __VCD_TIDL_h__ */ +======= #endif /* __VCD_TIDL_h__ */ +>>>>>>> Replace IPC (VCC) from dbus to tidl diff --git a/tidl/vc.tidl b/tidl/vc.tidl new file mode 100755 index 0000000..41348c6 --- /dev/null +++ b/tidl/vc.tidl @@ -0,0 +1,28 @@ +interface vc { + void notify_cb(int pid, bundle msg) delegate; + void feedback_cb(int utt_id, int event, array pcm_data, int len) delegate; + + void register_notify_cb(int pid, notify_cb callback) async; + int register_notify_cb_sync(int pid, notify_cb callback); + void register_feedback_cb(int pid, feedback_cb callback) async; + int register_feedback_cb_sync(int pid, feedback_cb callback); + + int initialize(in int pid, out int mgr_pid, out int service_state, out int daemon_pid); + int finalize(in int pid); + int set_command(in int pid, in int cmd_type); + int unset_command(in int pid, in int cmd_type); + int set_foreground(in int pid, in bool value); + int set_server_dialog(in int pid, in string app_id, in string credential); + int request_dialog(in int pid, in string disp_text, in string utt_text, in bool continuous); + int is_system_command_valid(in int pid, out bool is_sys_cmd_valid); + + int auth_enable(in int pid, in int mgr_pid); + int auth_disable(in int pid, in int mgr_pid); + int auth_start(in int pid, in int mgr_pid); + int auth_stop(in int pid, in int mgr_pid); + int auth_cancel(in int pid, in int mgr_pid); + + int request_tts(in int pid, string text, string lang, bool to_vcm, out int utt_id); + int cancel_tts(in int pid, in int utt_id); + int get_tts_audio_format(in int pid, out int rate, out int channel, out int audio_type); +} -- 2.7.4