From e040170ea3d3acf78d9b9dad421e6e44cd638941 Mon Sep 17 00:00:00 2001 From: Suyeon Hwang Date: Mon, 1 Aug 2022 17:35:07 +0900 Subject: [PATCH] Implement behavior of new APIs This patch is for implementing new APIs introduced from previous commit. Change-Id: Iaa157ffd229bf39f2a20754dfb641ea943c2e532 Signed-off-by: Suyeon Hwang --- server/ttsd_engine_agent.c | 30 +++++++++++++ server/ttsd_engine_agent.h | 3 ++ server/ttsd_main.h | 1 + server/ttsd_server.c | 104 +++++++++++++++++++++++++++++++++++---------- server/ttsd_server.h | 3 ++ server/ttse.c | 26 ++++++++++-- 6 files changed, 140 insertions(+), 27 deletions(-) diff --git a/server/ttsd_engine_agent.c b/server/ttsd_engine_agent.c index 37046ac..eed66c6 100644 --- a/server/ttsd_engine_agent.c +++ b/server/ttsd_engine_agent.c @@ -189,6 +189,7 @@ static int __set_engine_callback(ttse_request_callback_s* callback, ttsengine_in engine_info->callbacks->private_data_set = NULL; engine_info->callbacks->private_data_requested = NULL; + engine_info->callbacks->activated_mode_changed = NULL; SLOG(LOG_DEBUG, tts_tag(), "--- Valid Engine ---"); SLOG(LOG_DEBUG, tts_tag(), "Engine uuid : %s", engine_info->engine_uuid); @@ -1154,6 +1155,23 @@ int ttsd_engine_check_app_agreed(const char* appid, bool* is_agreed) return ret; } +int ttsd_engine_notify_activated_mode_changed(int activated_mode) +{ + if (false == __is_agent_initialized()) { + SLOG(LOG_ERROR, tts_tag(), "[Engine Agent ERROR] Not Initialized"); + return TTSD_ERROR_INVALID_STATE; + } + + if (NULL == g_engine_info->callbacks->activated_mode_changed) { + SLOG(LOG_ERROR, tts_tag(), "[Engine Agent ERROR] Not supported feature"); + return TTSD_ERROR_NOT_SUPPORTED_FEATURE; + } + + g_engine_info->callbacks->activated_mode_changed(activated_mode); + + return TTSD_ERROR_NONE; +} + void __free_voice_list(GList* voice_list) { GList *iter = NULL; @@ -1249,3 +1267,15 @@ int ttsd_engine_agent_set_private_data_requested_cb(ttse_private_data_requested_ return TTSD_ERROR_NONE; } + +int ttsd_engine_agent_set_activated_mode_changed_cb(ttse_activated_mode_changed_cb callback) +{ + if (false == __is_agent_initialized()) { + SLOG(LOG_ERROR, tts_tag(), "[Engine Agent ERROR] Not Initialized"); + return TTSD_ERROR_INVALID_STATE; + } + + g_engine_info->callbacks->activated_mode_changed = callback; + + return TTSD_ERROR_NONE; +} diff --git a/server/ttsd_engine_agent.h b/server/ttsd_engine_agent.h index e258448..29a4fe8 100644 --- a/server/ttsd_engine_agent.h +++ b/server/ttsd_engine_agent.h @@ -39,6 +39,7 @@ int ttsd_engine_agent_load_current_engine(); /** Set callbacks of the current engine */ int ttsd_engine_agent_set_private_data_set_cb(ttse_private_data_set_cb callback); int ttsd_engine_agent_set_private_data_requested_cb(ttse_private_data_requested_cb callback); +int ttsd_engine_agent_set_activated_mode_changed_cb(ttse_activated_mode_changed_cb callback); /** Unload current engine */ int ttsd_engine_agent_unload_current_engine(); @@ -67,6 +68,8 @@ int ttsd_engine_get_private_data(const char* key, char** data); int ttsd_engine_check_app_agreed(const char* appid, bool* is_agreed); +int ttsd_engine_notify_activated_mode_changed(int activated_mode); + /* * TTS Engine Interfaces for client */ diff --git a/server/ttsd_main.h b/server/ttsd_main.h index 4aef762..d35def8 100644 --- a/server/ttsd_main.h +++ b/server/ttsd_main.h @@ -98,6 +98,7 @@ typedef struct { ttse_need_app_credential_cb need_app_credential; ttse_private_data_set_cb private_data_set; ttse_private_data_requested_cb private_data_requested; + ttse_activated_mode_changed_cb activated_mode_changed; } tts_engine_callback_s; diff --git a/server/ttsd_server.c b/server/ttsd_server.c index 76c9659..f515c33 100644 --- a/server/ttsd_server.c +++ b/server/ttsd_server.c @@ -55,6 +55,7 @@ static GList *g_proc_list = NULL; static bool g_is_terminated = false; +static int g_activated_mode = 0; /* Function definitions */ static int __stop_and_send_ready_state(unsigned int uid) @@ -586,6 +587,8 @@ int ttsd_initialize(ttse_request_callback_s *callback) SLOG(LOG_WARN, tts_tag(), "[WARNING] Fail to create timer"); } + g_activated_mode = 0; + return TTSD_ERROR_NONE; } @@ -672,6 +675,51 @@ int ttsd_server_is_already_initialized(int pid, unsigned int uid, bool* is_initi return TTSD_ERROR_NONE; } +static void __set_and_notify_activated_mode() +{ + int activated_mode = ttsd_data_get_activated_mode(); + if (g_activated_mode == activated_mode) { + return; + } + + SLOG(LOG_INFO, tts_tag(), "[Server] Activated mode is changed from(%d) to (%d)", g_activated_mode, activated_mode); + + g_activated_mode = activated_mode; + int ret = ttsd_engine_notify_activated_mode_changed(g_activated_mode); + if (TTSD_ERROR_NONE != ret) { + SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to notify activated mode changed event.(%d)", ret); + } +} + +static int __check_app_agreed(int pid, unsigned int uid, bool credential_needed) +{ + if (false == credential_needed) { + return TTSD_ERROR_NONE; + } + + char* appid = NULL; + if (APP_MANAGER_ERROR_NONE != app_manager_get_app_id(pid, &appid)) { + SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to get app id, pid(%d)", pid); + } + + bool is_agreed = false; + int ret = ttsd_engine_check_app_agreed(appid, &is_agreed); + free(appid); + appid = NULL; + + if (TTSD_ERROR_NONE != ret) { + SLOG(LOG_ERROR, tts_tag(), "Server ERROR] Fail to check app agreed"); + return TTSD_ERROR_OPERATION_FAILED; + } + + if (false == is_agreed) { + SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] App is not agreed"); + return TTSD_ERROR_PERMISSION_DENIED; + } + + return TTSD_ERROR_NONE; +} + int ttsd_server_initialize(int pid, unsigned int uid, ttsd_mode_e mode, tts_ipc_method_e method, bool* credential_needed) { SLOG(LOG_INFO, tts_tag(), "[Server] Server initialize"); @@ -681,46 +729,35 @@ int ttsd_server_initialize(int pid, unsigned int uid, ttsd_mode_e mode, tts_ipc_ return TTSD_ERROR_NONE; } - if (0 != ttsd_data_new_client(pid, uid, mode, method)) { + if (TTSD_ERROR_NONE != ttsd_data_new_client(pid, uid, mode, method)) { SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to add client info"); return TTSD_ERROR_OPERATION_FAILED; } + __set_and_notify_activated_mode(); + if (TTSD_ERROR_NONE != ttsd_engine_agent_load_current_engine()) { SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to load current engine"); ttsd_data_delete_client(uid); return TTSD_ERROR_OPERATION_FAILED; } - if (0 != ttsd_engine_agent_is_credential_needed(uid, credential_needed)) { + bool is_needed = false; + if (TTSD_ERROR_NONE != ttsd_engine_agent_is_credential_needed(uid, &is_needed)) { SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to get credential necessity"); ttsd_data_delete_client(uid); return TTSD_ERROR_OPERATION_FAILED; } - if (true == *credential_needed) { - char* appid = NULL; - if (0 != app_manager_get_app_id(pid, &appid)) { - SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to get app id, pid(%d)", pid); - } - bool is_agreed = false; - if (0 != ttsd_engine_check_app_agreed(appid, &is_agreed)) { - SLOG(LOG_ERROR, tts_tag(), "Server ERROR] Fail to check app agreed"); - if (!appid) - free(appid); - ttsd_data_delete_client(uid); - return TTSD_ERROR_OPERATION_FAILED; - } - if (!appid) - free(appid); - - if (false == is_agreed) { - SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] App is not agreed"); - ttsd_data_delete_client(uid); - return TTSD_ERROR_PERMISSION_DENIED; - } + int ret = __check_app_agreed(pid, uid, is_needed); + if (TTSD_ERROR_NONE != ret) { + SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Checking credential is finished(%d)", ret); + ttsd_data_delete_client(uid); + return ret; } + *credential_needed = is_needed; + return TTSD_ERROR_NONE; } @@ -753,6 +790,7 @@ int ttsd_server_finalize(unsigned int uid) } ttsd_data_delete_client(uid); + __set_and_notify_activated_mode(); /* unload engine, if ref count of client is 0 */ if (0 == ttsd_data_get_client_count()) { @@ -1164,6 +1202,26 @@ int ttsd_set_private_data_requested_cb(ttse_private_data_requested_cb callback) return ret; } +int ttsd_get_activated_mode(int* activated_mode) +{ + if (NULL == activated_mode) { + return TTSD_ERROR_INVALID_PARAMETER; + } + + *activated_mode = ttsd_data_get_activated_mode(); + return TTSD_ERROR_NONE; +} + +int ttsd_set_activated_mode_changed_cb(ttse_activated_mode_changed_cb callback) +{ + int ret = ttsd_engine_agent_set_activated_mode_changed_cb(callback); + if (TTSD_ERROR_NONE != ret) { + SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to set private data requested cb : ret(%d)", ret); + } + + return ret; +} + int ttsd_server_play_pcm(unsigned int uid) { app_tts_state_e state = ttsd_data_get_client_state(uid); diff --git a/server/ttsd_server.h b/server/ttsd_server.h index 271a8eb..bf52d15 100644 --- a/server/ttsd_server.h +++ b/server/ttsd_server.h @@ -40,6 +40,9 @@ int ttsd_send_error(ttse_error_e error, const char* msg); int ttsd_set_private_data_set_cb(ttse_private_data_set_cb callback); int ttsd_set_private_data_requested_cb(ttse_private_data_requested_cb callback); +int ttsd_get_activated_mode(int* activated_mode); +int ttsd_set_activated_mode_changed_cb(ttse_activated_mode_changed_cb callback); + /* * Server API for client */ diff --git a/server/ttse.c b/server/ttse.c index a04fc84..e9b8c36 100755 --- a/server/ttse.c +++ b/server/ttse.c @@ -248,8 +248,17 @@ int ttse_get_activated_mode(int* activated_mode) return TTSE_ERROR_INVALID_PARAMETER; } - // TODO: Implement function - return TTSE_ERROR_NONE; + if (g_is_terminated) { + SLOG(LOG_ERROR, tts_tag(), "[ERROR] Service engine is terminated."); + return TTSE_ERROR_INVALID_STATE; + } + + int ret = ttsd_get_activated_mode(activated_mode); + if (TTSD_ERROR_NONE != ret) { + SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to get activated mode. ret(%d/%s)", ret, get_error_message(ret)); + } + + return ret; } int ttse_set_activated_mode_changed_cb(ttse_activated_mode_changed_cb callback) @@ -259,6 +268,15 @@ int ttse_set_activated_mode_changed_cb(ttse_activated_mode_changed_cb callback) return TTSE_ERROR_INVALID_PARAMETER; } - // TODO: Implement function - return TTSE_ERROR_NONE; + if (g_is_terminated) { + SLOG(LOG_ERROR, tts_tag(), "[ERROR] Service engine is terminated."); + return TTSE_ERROR_INVALID_STATE; + } + + int ret = ttsd_set_activated_mode_changed_cb(callback); + if (TTSD_ERROR_NONE != ret) { + SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to set activated mode changed cb. ret(%d/%s)", ret, get_error_message(ret)); + } + + return ret; } -- 2.7.4