From c2f113e2821389eb888d8a2f37bdc75d53ac1eec Mon Sep 17 00:00:00 2001 From: Suyeon Hwang Date: Mon, 24 Jan 2022 14:54:52 +0900 Subject: [PATCH] Clean up header files Change-Id: I87127a6429e4396dfaf5492c06eba9a6cbb230b2 Signed-off-by: Suyeon Hwang --- server/ttsd_data.cpp | 4 +- server/ttsd_data.h | 5 +- server/ttsd_dbus.c | 2 +- server/ttsd_dbus.h | 2 +- server/ttsd_dbus_server.c | 2 +- server/ttsd_player.cpp | 2 +- server/ttsd_server.c | 227 ++++++++++++++++++++-------------------------- server/ttsd_server.h | 4 - 8 files changed, 107 insertions(+), 141 deletions(-) diff --git a/server/ttsd_data.cpp b/server/ttsd_data.cpp index 367f60a..6262194 100644 --- a/server/ttsd_data.cpp +++ b/server/ttsd_data.cpp @@ -130,14 +130,14 @@ static void __data_show_used_voice_list(app_data_s& app_data) * ttsd data functions */ -int ttsd_set_synth_control(ttsd_synthesis_control_e control) +int ttsd_data_set_synth_control(ttsd_synthesis_control_e control) { SLOG(LOG_INFO, tts_tag(), "[DATA INFO] set synth_control(%d)", control); g_synth_control = control; return 0; } -ttsd_synthesis_control_e ttsd_get_synth_control() +ttsd_synthesis_control_e ttsd_data_get_synth_control() { return g_synth_control.load(); } diff --git a/server/ttsd_data.h b/server/ttsd_data.h index feff8d7..d59b311 100644 --- a/server/ttsd_data.h +++ b/server/ttsd_data.h @@ -63,9 +63,10 @@ typedef struct { int channels; } sound_data_s; -int ttsd_set_synth_control(ttsd_synthesis_control_e control); -ttsd_synthesis_control_e ttsd_get_synth_control(); +int ttsd_data_set_synth_control(ttsd_synthesis_control_e control); + +ttsd_synthesis_control_e ttsd_data_get_synth_control(); typedef void (* ttsd_used_voice_cb)(const char* lang, int type); diff --git a/server/ttsd_dbus.c b/server/ttsd_dbus.c index 57ced0b..f639b53 100644 --- a/server/ttsd_dbus.c +++ b/server/ttsd_dbus.c @@ -54,7 +54,7 @@ const char* __ttsd_get_error_code(ttsd_error_e err) return NULL; } -int ttsdc_send_hello(int pid, unsigned int uid, int ret, int credential_needed) +int ttsdc_dbus_send_hello(int pid, unsigned int uid, int ret, int credential_needed) { if (NULL == g_conn_sender) { SLOG(LOG_ERROR, tts_tag(), "[Dbus ERROR] Dbus connection is not available"); diff --git a/server/ttsd_dbus.h b/server/ttsd_dbus.h index bb21615..0d9cd9c 100644 --- a/server/ttsd_dbus.h +++ b/server/ttsd_dbus.h @@ -23,7 +23,7 @@ int ttsd_dbus_open_connection(); int ttsd_dbus_close_connection(); -int ttsdc_send_hello(int pid, unsigned int uid, int ret, int credential_needed); +int ttsdc_dbus_send_hello(int pid, unsigned int uid, int ret, int credential_needed); int ttsdc_dbus_send_utt_start_message(int pid, unsigned int uid, int uttid); diff --git a/server/ttsd_dbus_server.c b/server/ttsd_dbus_server.c index 0b9fddf..82e41df 100644 --- a/server/ttsd_dbus_server.c +++ b/server/ttsd_dbus_server.c @@ -61,7 +61,7 @@ int ttsd_dbus_server_hello(DBusConnection* conn, DBusMessage* msg) } SLOG(LOG_INFO, tts_tag(), "[INFO] send_hello. pid(%d), uid(%u), ret(%d), credential_needed(%d)", pid, uid, ret, credential_needed); - ttsdc_send_hello(pid, uid, ret, credential_needed); + ttsdc_dbus_send_hello(pid, uid, ret, credential_needed); } return 0; diff --git a/server/ttsd_player.cpp b/server/ttsd_player.cpp index 05c12c9..1bdd4f2 100644 --- a/server/ttsd_player.cpp +++ b/server/ttsd_player.cpp @@ -260,7 +260,7 @@ static void __wait_sound_data(PlayerThread* player, unsigned int uid) } /* If engine is not on processing */ - ttsd_synthesis_control_e synth_control = ttsd_get_synth_control(); + ttsd_synthesis_control_e synth_control = ttsd_data_get_synth_control(); if (TTSD_SYNTHESIS_CONTROL_DOING != synth_control) { SLOG(LOG_INFO, tts_tag(), "[Server INFO] synth_control(%d)", synth_control); if (AudioStream::AUDIO_STATE_PLAY == g_audio_stream->getState()) { diff --git a/server/ttsd_server.c b/server/ttsd_server.c index 7cb042a..e3ebd8b 100644 --- a/server/ttsd_server.c +++ b/server/ttsd_server.c @@ -84,7 +84,7 @@ static Eina_Bool __wait_synthesis(void *data) unsigned int uid = ttsd_data_get_current_playing(); if (uid > 0) { - ttsd_synthesis_control_e synth_control = ttsd_get_synth_control(); + ttsd_synthesis_control_e synth_control = ttsd_data_get_synth_control(); if (TTSD_SYNTHESIS_CONTROL_DOING == synth_control) { return EINA_TRUE; } else { @@ -147,12 +147,12 @@ static void __synthesis(unsigned int uid) SLOG(LOG_INFO, tts_tag(), "Credential : %s", credential); SLOG(LOG_INFO, tts_tag(), "-----------------------------------------------------------"); - ttsd_set_synth_control(TTSD_SYNTHESIS_CONTROL_DOING); + ttsd_data_set_synth_control(TTSD_SYNTHESIS_CONTROL_DOING); ret = ttsd_engine_start_synthesis(speak_data->lang, speak_data->vctype, speak_data->text, speak_data->speed, appid, credential, NULL); if (TTSD_ERROR_NONE != ret) { SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] * FAIL to start SYNTHESIS !!!! * "); - ttsd_set_synth_control(TTSD_SYNTHESIS_CONTROL_DONE); + ttsd_data_set_synth_control(TTSD_SYNTHESIS_CONTROL_DONE); __stop_and_send_ready_state(uid); } else { g_wait_timer = ecore_timer_add(0.05, __wait_synthesis, (void*)credential); @@ -178,7 +178,7 @@ int ttsd_send_error(ttse_error_e error, const char* msg) SLOG(LOG_ERROR, tts_tag(), "[SERVER ERROR] Error msg from engine, pid(%d), uid(%u), uttid(%d), error(%d), msg(%s)", tmp_pid, uid, uttid, error, (NULL == msg ? "NULL" : msg)); - ttsd_set_synth_control(TTSD_SYNTHESIS_CONTROL_EXPIRED); + ttsd_data_set_synth_control(TTSD_SYNTHESIS_CONTROL_EXPIRED); if (0 != ttsd_data_clear_data(uid)) SLOG(LOG_WARN, tts_tag(), "[Server] Fail to ttsd_data_clear_data()"); @@ -206,7 +206,7 @@ int ttsd_send_result(ttse_result_event_e event, const void* data, unsigned int d int uttid = g_utt.uttid; if (false == ttsd_data_is_uttid_valid(uid, uttid)) { - ttsd_set_synth_control(TTSD_SYNTHESIS_CONTROL_DONE); + ttsd_data_set_synth_control(TTSD_SYNTHESIS_CONTROL_DONE); SLOG(LOG_ERROR, tts_tag(), "[SERVER ERROR] uttid is NOT valid !!!! - uid(%u), uttid(%d)", uid, uttid); SLOG(LOG_DEBUG, tts_tag(), "@@@"); return TTSD_ERROR_INVALID_PARAMETER; @@ -214,12 +214,12 @@ int ttsd_send_result(ttse_result_event_e event, const void* data, unsigned int d if (TTSE_RESULT_EVENT_START > event || TTSE_RESULT_EVENT_FINISH < event) { SLOG(LOG_DEBUG, tts_tag(), "[SERVER] Event : TTSE_RESULT_EVENT_ERROR"); - ttsd_set_synth_control(TTSD_SYNTHESIS_CONTROL_EXPIRED); + ttsd_data_set_synth_control(TTSD_SYNTHESIS_CONTROL_EXPIRED); return TTSD_ERROR_INVALID_PARAMETER; } if (rate <= 0 || audio_type < 0 || audio_type > TTSE_AUDIO_TYPE_MAX) { - ttsd_set_synth_control(TTSD_SYNTHESIS_CONTROL_DONE); + ttsd_data_set_synth_control(TTSD_SYNTHESIS_CONTROL_DONE); SLOG(LOG_ERROR, tts_tag(), "[SERVER ERROR] audio data is invalid"); SLOG(LOG_DEBUG, tts_tag(), "@@@"); return TTSD_ERROR_INVALID_PARAMETER; @@ -228,14 +228,14 @@ int ttsd_send_result(ttse_result_event_e event, const void* data, unsigned int d /* check the current state */ app_tts_state_e state = ttsd_data_get_client_state(uid); if (APP_STATE_NONE == state) { - ttsd_set_synth_control(TTSD_SYNTHESIS_CONTROL_DONE); + ttsd_data_set_synth_control(TTSD_SYNTHESIS_CONTROL_DONE); SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] uid is not valid"); return TTSD_ERROR_INVALID_PARAMETER; } SLOG(LOG_INFO, tts_tag(), "[Server] uid(%u), current state(%d)", uid, state); if (APP_STATE_CREATED == state || APP_STATE_READY == state) { - ttsd_set_synth_control(TTSD_SYNTHESIS_CONTROL_DONE); + ttsd_data_set_synth_control(TTSD_SYNTHESIS_CONTROL_DONE); SLOG(LOG_WARN, tts_tag(), "[SERVER WARNING] Current state is %d. The synthesized result is ignored.", state); return TTSD_ERROR_NONE; } @@ -278,7 +278,7 @@ int ttsd_send_result(ttse_result_event_e event, const void* data, unsigned int d } if (event == TTSE_RESULT_EVENT_FINISH) { - ttsd_set_synth_control(TTSD_SYNTHESIS_CONTROL_DONE); + ttsd_data_set_synth_control(TTSD_SYNTHESIS_CONTROL_DONE); } return TTSD_ERROR_NONE; @@ -308,7 +308,7 @@ static void __stop_all_client() SLOG(LOG_INFO, tts_tag(), "[Server] Send to stop all requests"); ttsd_engine_cancel_synthesis(); - ttsd_set_synth_control(TTSD_SYNTHESIS_CONTROL_EXPIRED); + ttsd_data_set_synth_control(TTSD_SYNTHESIS_CONTROL_EXPIRED); /* stop all player */ ttsd_player_all_stop(); @@ -462,6 +462,87 @@ void __screen_reader_changed_cb(bool value) return; } +static void __read_proc() +{ + DIR *dp = NULL; + struct dirent *dirp = NULL; + int tmp; + + GList *iter = NULL; + if (0 < g_list_length(g_proc_list)) { + iter = g_list_first(g_proc_list); + while (NULL != iter) { + g_proc_list = g_list_remove_link(g_proc_list, iter); + g_list_free(iter); + iter = g_list_first(g_proc_list); + } + } + + dp = opendir("/proc"); + if (NULL == dp) { + SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to open proc"); + } else { + do { + dirp = readdir(dp); + + if (NULL != dirp) { + tmp = atoi(dirp->d_name); + if (0 >= tmp) continue; + g_proc_list = g_list_append(g_proc_list, GINT_TO_POINTER(tmp)); + } + } while (NULL != dirp); + closedir(dp); + } + return; +} + +bool __get_client_for_clean_up(int pid, unsigned int uid, app_tts_state_e state, void* user_data) +{ + bool exist = false; + int i = 0; + + GList *iter = NULL; + for (i = 0; i < g_list_length(g_proc_list); i++) { + iter = g_list_nth(g_proc_list, i); + if (NULL != iter) { + if (pid == GPOINTER_TO_INT(iter->data)) { + SLOG(LOG_DEBUG, tts_tag(), "uid (%u) is running", uid); + exist = true; + break; + } + } + } + + if (false == exist) { + SLOG(LOG_ERROR, tts_tag(), "uid (%u) should be removed", uid); + ttsd_server_finalize(uid); + } + + return true; +} + +static Eina_Bool __cleanup_client(void *data) +{ + SLOG(LOG_DEBUG, tts_tag(), "@@@ CLEAN UP CLIENT START"); + __read_proc(); + + if (0 < ttsd_data_get_client_count()) { + ttsd_data_foreach_clients(__get_client_for_clean_up, NULL); + } else { + if (NULL == g_quit_loop_timer) { + SLOG(LOG_INFO, tts_tag(), "[Server] Add a timer __quit_ecore_loop"); + g_quit_loop_timer = ecore_timer_add(0, __quit_ecore_loop, NULL); + } + SLOG(LOG_ERROR, tts_tag(), "[Server] Deleted timer"); + g_check_client_timer = NULL; + return EINA_FALSE; + } + + SLOG(LOG_DEBUG, tts_tag(), "@@@"); + + return EINA_TRUE; +} + /* * Server APIs */ @@ -497,22 +578,15 @@ int ttsd_initialize(ttse_request_callback_s *callback) return TTSD_ERROR_OPERATION_FAILED; } - /* set current engine */ - //if (0 != ttsd_engine_agent_initialize_current_engine(callback)) { - // SLOG(LOG_WARN, tts_tag(), "[Server WARNING] No Engine !!!" ); - // g_is_engine = false; - //} else - // g_is_engine = true; - if (0 != ttsd_engine_agent_load_current_engine(callback)) { SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to load current engine"); return TTSD_ERROR_OPERATION_FAILED; } - ttsd_set_synth_control(TTSD_SYNTHESIS_CONTROL_EXPIRED); + ttsd_data_set_synth_control(TTSD_SYNTHESIS_CONTROL_EXPIRED); ttsd_config_set_screen_reader_callback(__screen_reader_changed_cb); - g_check_client_timer = ecore_timer_add(CLIENT_CLEAN_UP_TIME, ttsd_cleanup_client, NULL); + g_check_client_timer = ecore_timer_add(CLIENT_CLEAN_UP_TIME, __cleanup_client, NULL); if (NULL == g_check_client_timer) { SLOG(LOG_WARN, tts_tag(), "[WARNING] Fail to create timer"); } @@ -651,111 +725,6 @@ int ttsd_server_initialize(int pid, unsigned int uid, tts_ipc_method_e method, b return TTSD_ERROR_NONE; } -static void __read_proc() -{ - DIR *dp = NULL; - struct dirent *dirp = NULL; - int tmp; - - GList *iter = NULL; - if (0 < g_list_length(g_proc_list)) { - iter = g_list_first(g_proc_list); - while (NULL != iter) { - g_proc_list = g_list_remove_link(g_proc_list, iter); - g_list_free(iter); - iter = g_list_first(g_proc_list); - } - } - - dp = opendir("/proc"); - if (NULL == dp) { - SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to open proc"); - } else { - do { - dirp = readdir(dp); - - if (NULL != dirp) { - tmp = atoi(dirp->d_name); - if (0 >= tmp) continue; - g_proc_list = g_list_append(g_proc_list, GINT_TO_POINTER(tmp)); - } - } while (NULL != dirp); - closedir(dp); - } - return; -} - -bool __get_client_for_clean_up(int pid, unsigned int uid, app_tts_state_e state, void* user_data) -{ - bool exist = false; - int i = 0; - - GList *iter = NULL; - for (i = 0; i < g_list_length(g_proc_list); i++) { - iter = g_list_nth(g_proc_list, i); - if (NULL != iter) { - if (pid == GPOINTER_TO_INT(iter->data)) { - SLOG(LOG_DEBUG, tts_tag(), "uid (%u) is running", uid); - exist = true; - break; - } - } - } - - if (false == exist) { - SLOG(LOG_ERROR, tts_tag(), "uid (%u) should be removed", uid); - ttsd_server_finalize(uid); - } - - return true; -#if 0 - char appid[1024] = {0, }; - if (0 != aul_app_get_appid_bypid(pid, appid, sizeof(appid) - 1)) { - SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to get app id"); - } - - if (0 < strlen(appid)) { - SLOG(LOG_DEBUG, tts_tag(), "[%d] is running app - %s", pid, appid); - } else { - SLOG(LOG_DEBUG, tts_tag(), "[%d] is daemon or no_running app", pid); - - int result = 1; - result = ttsdc_send_hello(pid, uid); - - if (0 == result) { - SLOG(LOG_DEBUG, tts_tag(), "[Server] uid(%u) should be removed.", uid); - ttsd_server_finalize(uid); - } else if (-1 == result) { - SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Hello result has error"); - } - } - return true; -#endif -} - - -Eina_Bool ttsd_cleanup_client(void *data) -{ - SLOG(LOG_DEBUG, tts_tag(), "@@@ CLEAN UP CLIENT START"); - __read_proc(); - - if (0 < ttsd_data_get_client_count()) { - ttsd_data_foreach_clients(__get_client_for_clean_up, NULL); - } else { - if (NULL == g_quit_loop_timer) { - SLOG(LOG_INFO, tts_tag(), "[Server] Add a timer __quit_ecore_loop"); - g_quit_loop_timer = ecore_timer_add(0, __quit_ecore_loop, NULL); - } - SLOG(LOG_ERROR, tts_tag(), "[Server] Deleted timer"); - g_check_client_timer = NULL; - return EINA_FALSE; - } - - SLOG(LOG_DEBUG, tts_tag(), "@@@"); - - return EINA_TRUE; -} - void __used_voice_cb(const char* lang, int type) { SLOG(LOG_DEBUG, tts_tag(), "[Server] Request to unload voice (%s,%d)", lang, type); @@ -918,7 +887,7 @@ int ttsd_server_add_text(unsigned int uid, const char* text, const char* lang, i ttsd_data_set_credential(uid, credential); /* Check whether tts-engine is running or not */ - ttsd_synthesis_control_e synth_control = ttsd_get_synth_control(); + ttsd_synthesis_control_e synth_control = ttsd_data_get_synth_control(); SLOG(LOG_INFO, tts_tag(), "[Server INFO] synth_control(%d)", synth_control); if (TTSD_SYNTHESIS_CONTROL_DOING == synth_control) { SLOG(LOG_WARN, tts_tag(), "[Server WARNING] Engine has already been running."); @@ -1016,7 +985,7 @@ int ttsd_server_play(unsigned int uid, const char* credential) /* Check whether tts-engine is running or not */ clock_gettime(CLOCK_MONOTONIC_RAW, &g_request_playing); - ttsd_synthesis_control_e synth_control = ttsd_get_synth_control(); + ttsd_synthesis_control_e synth_control = ttsd_data_get_synth_control(); SLOG(LOG_INFO, tts_tag(), "[Server INFO] synth_control(%d)", synth_control); if (TTSD_SYNTHESIS_CONTROL_DOING == synth_control) { SLOG(LOG_WARN, tts_tag(), "[Server WARNING] Engine has already been running."); @@ -1030,7 +999,7 @@ int ttsd_server_play(unsigned int uid, const char* credential) static void __stop_engine_synthesis(unsigned int uid) { - ttsd_synthesis_control_e synth_control = ttsd_get_synth_control(); + ttsd_synthesis_control_e synth_control = ttsd_data_get_synth_control(); SLOG(LOG_INFO, tts_tag(), "[Server INFO] synth_control(%d)", synth_control); if (TTSD_SYNTHESIS_CONTROL_DOING == synth_control && uid == ttsd_data_get_current_playing()) { @@ -1041,7 +1010,7 @@ static void __stop_engine_synthesis(unsigned int uid) SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to cancel synthesis : ret(%d)", ret); } - ttsd_set_synth_control(TTSD_SYNTHESIS_CONTROL_EXPIRED); + ttsd_data_set_synth_control(TTSD_SYNTHESIS_CONTROL_EXPIRED); } int ttsd_server_stop(unsigned int uid) diff --git a/server/ttsd_server.h b/server/ttsd_server.h index ee9c120..ca5ae12 100644 --- a/server/ttsd_server.h +++ b/server/ttsd_server.h @@ -34,10 +34,6 @@ int ttsd_finalize(); int ttsd_terminate(); -Eina_Bool ttsd_cleanup_client(void *data); - -Eina_Bool ttsd_get_daemon_exist(); - int ttsd_send_result(ttse_result_event_e event, const void* data, unsigned int data_size, ttse_audio_type_e audio_type, int rate, void* user_data); int ttsd_send_error(ttse_error_e error, const char* msg); -- 2.7.4