From 7845abdaa3246b36550de0c7fc0c65582728e392 Mon Sep 17 00:00:00 2001 From: Seongmin Park Date: Fri, 29 Apr 2022 02:57:40 +0000 Subject: [PATCH] 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.34.1