From: Suyeon Hwang Date: Wed, 12 May 2021 07:07:57 +0000 (+0900) Subject: Create data structure for saving tidl proxy information X-Git-Tag: submit/tizen/20210628.060348~5 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F10%2F260010%2F4;p=platform%2Fcore%2Fuifw%2Ftts.git Create data structure for saving tidl proxy information Change-Id: I00a4583cd8b62527e3da5eddfd62951b72d5cad1 Signed-off-by: Suyeon Hwang --- diff --git a/server/ttsd_data.cpp b/server/ttsd_data.cpp index c61cf45d..6ba43497 100644 --- a/server/ttsd_data.cpp +++ b/server/ttsd_data.cpp @@ -18,7 +18,6 @@ #include "ttsd_main.h" #include "ttsd_data.h" -#include "ttsd_stub.h" using namespace std; @@ -39,7 +38,6 @@ typedef struct std::list m_wav_data; std::list m_used_voice; - rpc_port_tts_notify_cb_h notify_cb_h; tts_ipc_method_e ipc_method; } app_data_s; @@ -166,7 +164,6 @@ int ttsd_data_new_client(int pid, int uid) app.uid = uid; app.utt_id_stopped = 0; app.state = APP_STATE_READY; - app.notify_cb_h = NULL; app.ipc_method = TTS_IPC_METHOD_UNDEFINED; g_app_list.insert(g_app_list.end(), app); @@ -270,48 +267,6 @@ tts_ipc_method_e ttsd_data_get_ipc_method(int uid) return g_app_list[index].ipc_method; } -int ttsd_data_set_notify_h(int uid, rpc_port_tts_notify_cb_h handle, void* user_data) -{ - int index = ttsd_data_is_client(uid); - - if (index < 0) { - SECURE_SLOG(LOG_ERROR, tts_tag(), "[DATA ERROR] uid is not valid (%d)", uid); - return TTSD_ERROR_INVALID_PARAMETER; - } - - if (rpc_port_tts_notify_cb_clone(handle, &(g_app_list[index].notify_cb_h)) != 0) { - return TTSD_ERROR_OPERATION_FAILED; - } - - return TTSD_ERROR_NONE; -} - -rpc_port_tts_notify_cb_h ttsd_data_get_notify_handle(int uid) -{ - int index = ttsd_data_is_client(uid); - SLOG(LOG_DEBUG, tts_tag(), "ttsd_data_is_client : index(%d)", index); - if (index < 0) { - SECURE_SLOG(LOG_ERROR, tts_tag(), "[DATA ERROR] uid is not valid (%d)", uid); - return NULL; - } - return g_app_list[index].notify_cb_h; -} - -int ttsd_data_unset_notify_h(int uid) -{ - int index = ttsd_data_is_client(uid); - - if (index < 0) { - SECURE_SLOG(LOG_ERROR, tts_tag(), "[DATA ERROR] uid is not valid (%d)", uid); - return TTSD_ERROR_INVALID_PARAMETER; - } - - g_app_list[index].notify_cb_h = NULL; - SLOG(LOG_DEBUG, tts_tag(), "[DATA] uid(%d) callback is unseted", g_app_list[index].uid); - - return TTSD_ERROR_NONE; -} - int ttsd_data_get_speak_data_size(int uid) { int index = 0; diff --git a/server/ttsd_data.h b/server/ttsd_data.h index c127d840..f5899fff 100644 --- a/server/ttsd_data.h +++ b/server/ttsd_data.h @@ -76,12 +76,6 @@ int ttsd_data_set_ipc_method(int uid, tts_ipc_method_e method); tts_ipc_method_e ttsd_data_get_ipc_method(int uid); -int ttsd_data_set_notify_h(int uid, rpc_port_tts_notify_cb_h handle, void* user_data); - -int ttsd_data_unset_notify_h(int uid); - -rpc_port_tts_notify_cb_h ttsd_data_get_notify_handle(int uid); - /* speak data */ int ttsd_data_add_speak_data(int uid, speak_data_s* data); diff --git a/server/ttsd_tidl.c b/server/ttsd_tidl.c index 6a787eef..f3680210 100644 --- a/server/ttsd_tidl.c +++ b/server/ttsd_tidl.c @@ -19,16 +19,50 @@ #include "ttsd_tidl.h" +typedef struct { + int uid; + rpc_port_tts_notify_cb_h notify_cb_h; +} tts_tidl_proxy_info_s; + +static GList* g_tidl_proxy_infos = NULL; + rpc_port_stub_tts_callback_s g_callback; +static tts_tidl_proxy_info_s* __get_tidl_proxy_info_s(int uid) +{ + GList* iter = NULL; + tts_tidl_proxy_info_s* info = NULL; + + if (g_list_length(g_tidl_proxy_infos) > 0) { + /* Get a first item */ + iter = g_list_first(g_tidl_proxy_infos); + + while (NULL != iter) { + info = iter->data; + if (info->uid == uid) { + return info; + } + + /* Next item */ + iter = g_list_next(iter); + } + } + + return NULL; +} + void __send_msg(int pid, int uid, bundle* msg) { SLOG(LOG_INFO, tts_tag(), "[TIDL] start : send msg : pid(%d), uid(%d)", pid, uid); - rpc_port_tts_notify_cb_h handle; + tts_tidl_proxy_info_s* info = __get_tidl_proxy_info_s(uid); + if (NULL == info) { + SLOG(LOG_ERROR, tts_tag(), "[TIDL] Uid is not valid. pid(%d), uid(%d)", pid, uid); + return; + } - handle = ttsd_data_get_notify_handle(uid); - if (!handle) { - SLOG(LOG_INFO, tts_tag(), "ttsd_data_get_notify_handle handle null"); + rpc_port_tts_notify_cb_h handle = info->notify_cb_h; + if (NULL == handle) { + SLOG(LOG_INFO, tts_tag(), "notify callback handle null"); return; } @@ -83,11 +117,21 @@ static void __register_cb(rpc_port_stub_tts_context_h context, int pid, int uid, credential_needed = TTS_CREDENTIAL_NEEDED_ALREADY_INITIALIZED; } - if (0 != ttsd_data_set_notify_h(uid, callback, NULL)) { - SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to set notify callback"); + tts_tidl_proxy_info_s* info = (tts_tidl_proxy_info_s*)calloc(1, sizeof(tts_tidl_proxy_info_s)); + if (NULL == info) { + SLOG(LOG_ERROR, tts_tag(), "[TIDL ERROR] Fail to allocate memory for tidl proxy"); return; } + if (0 != rpc_port_tts_notify_cb_clone(callback, &info->notify_cb_h)) { + SLOG(LOG_ERROR, tts_tag(), "[TIDL ERROR] Fail to set notify callback"); + free(info); + return; + } + + info->uid = uid; + g_tidl_proxy_infos = g_list_append(g_tidl_proxy_infos, info); + SLOG(LOG_INFO, tts_tag(), "create player instance"); ttsdc_tidl_send_hello(pid, uid, ret, credential_needed); @@ -99,11 +143,22 @@ static void __register_cb(rpc_port_stub_tts_context_h context, int pid, int uid, static int __register_cb_sync(rpc_port_stub_tts_context_h context, int pid, int uid, rpc_port_tts_notify_cb_h callback, void* user_data) { SLOG(LOG_DEBUG, tts_tag(), ">>>>> TTS REGISTER CALLBACK synchronously uid(%d)", uid); - if (0 != ttsd_data_set_notify_h(uid, callback, NULL)) { - SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to set notify callback"); + + tts_tidl_proxy_info_s* info = (tts_tidl_proxy_info_s*)calloc(1, sizeof(tts_tidl_proxy_info_s)); + if (NULL == info) { + SLOG(LOG_ERROR, tts_tag(), "[TIDL ERROR] Fail to allocate memory for tidl proxy"); + return TTSD_ERROR_OPERATION_FAILED; + } + + if (0 != rpc_port_tts_notify_cb_clone(callback, &info->notify_cb_h)) { + SLOG(LOG_ERROR, tts_tag(), "[TIDL ERROR] Fail to set notify callback"); + free(info); return TTSD_ERROR_OPERATION_FAILED; } + info->uid = uid; + g_tidl_proxy_infos = g_list_append(g_tidl_proxy_infos, info); + SLOG(LOG_ERROR, tts_tag(), "<<<<<<<<<<<"); return TTSE_ERROR_NONE; @@ -162,6 +217,19 @@ static int __finalize_cb(rpc_port_stub_tts_context_h context, int uid, void *use if (0 != ttsd_server_finalize(uid)) { return -1; } + + tts_tidl_proxy_info_s* info = __get_tidl_proxy_info_s(uid); + if (NULL == info) { + SLOG(LOG_ERROR, tts_tag(), "[TIDL ERROR] Fail to set notify callback"); + return TTSD_ERROR_INVALID_PARAMETER; + } + + rpc_port_tts_notify_cb_destroy(info->notify_cb_h); + info->notify_cb_h = NULL; + + g_tidl_proxy_infos = g_list_remove(g_tidl_proxy_infos, info); + free(info); + SLOG(LOG_DEBUG, tts_tag(), "<<<<<"); return TTSE_ERROR_NONE;