Merge "Fix memory leak of ecore timer" into tizen
authorWonnam Jang <wn.jang@samsung.com>
Tue, 7 Mar 2017 11:55:57 +0000 (03:55 -0800)
committerGerrit Code Review <gerrit@review.vlan103.tizen.org>
Tue, 7 Mar 2017 11:55:57 +0000 (03:55 -0800)
1  2 
server/ttsd_server.c

diff --combined server/ttsd_server.c
@@@ -25,6 -25,9 +25,9 @@@
  #include "ttsd_server.h"
  
  
+ #define CLIENT_CLEAN_UP_TIME 500
  typedef enum {
        TTSD_SYNTHESIS_CONTROL_DOING    = 0,
        TTSD_SYNTHESIS_CONTROL_DONE     = 1,
@@@ -42,6 -45,7 +45,7 @@@ typedef struct 
  /* If engine is running */
  static ttsd_synthesis_control_e       g_synth_control;
  
+ static Ecore_Timer* g_check_client_timer = NULL;
  static Ecore_Timer* g_wait_timer = NULL;
  
  static utterance_t g_utt;
@@@ -93,7 -97,6 +97,7 @@@ static int __synthesis(int uid, const c
        speak_data_s* speak_data = NULL;
        if (0 == ttsd_data_get_speak_data(uid, &speak_data)) {
                if (NULL == speak_data) {
 +                      SLOG(LOG_WARN, tts_tag(), "[Server] speak data is null");
                        return 0;
                }
  
                g_utt.uid = uid;
                g_utt.uttid = speak_data->utt_id;
  
 -              SLOG(LOG_DEBUG, tts_tag(), "-----------------------------------------------------------");
 -              SECURE_SLOG(LOG_DEBUG, tts_tag(), "ID : uid (%d), uttid(%d) ", g_utt.uid, g_utt.uttid);
 -              SECURE_SLOG(LOG_DEBUG, tts_tag(), "Voice : langauge(%s), type(%d), speed(%d)", speak_data->lang, speak_data->vctype, speak_data->speed);
 -              SECURE_SLOG(LOG_DEBUG, tts_tag(), "Text : %s", speak_data->text);
 -              SECURE_SLOG(LOG_DEBUG, tts_tag(), "Credential : %s", credential);
 -              SLOG(LOG_DEBUG, tts_tag(), "-----------------------------------------------------------");
 +              SLOG(LOG_INFO, tts_tag(), "-----------------------------------------------------------");
 +              SLOG(LOG_INFO, tts_tag(), "ID : uid (%d), uttid(%d) ", g_utt.uid, g_utt.uttid);
 +              SLOG(LOG_INFO, tts_tag(), "Voice : langauge(%s), type(%d), speed(%d)", speak_data->lang, speak_data->vctype, speak_data->speed);
 +              SLOG(LOG_INFO, tts_tag(), "Text : %s", speak_data->text);
 +              SLOG(LOG_INFO, tts_tag(), "Credential : %s", credential);
 +              SLOG(LOG_INFO, tts_tag(), "-----------------------------------------------------------");
  
                int ret = 0;
                __server_set_synth_control(TTSD_SYNTHESIS_CONTROL_DOING);
@@@ -199,7 -202,6 +203,6 @@@ int ttsd_send_error(ttse_error_e error
  }
  
  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)
  {
        SLOG(LOG_DEBUG, tts_tag(), "===== SEND SYNTHESIS RESULT START");
  
        /* Synthesis is success */
        if (TTSE_RESULT_EVENT_START == event || TTSE_RESULT_EVENT_CONTINUE == event || TTSE_RESULT_EVENT_FINISH == event) {
                if (TTSE_RESULT_EVENT_START == event) {
 -                      SLOG(LOG_DEBUG, tts_tag(), "[SERVER] Event : TTSE_RESULT_EVENT_START");
 +                      SLOG(LOG_INFO, tts_tag(), "[SERVER] Event : TTSE_RESULT_EVENT_START");
                        SECURE_SLOG(LOG_DEBUG, tts_tag(), "[SERVER] Result Info : uid(%d), utt(%d), data(%p), data size(%d) audiotype(%d) rate(%d)", 
                                uid, uttid, data, data_size, audio_type, rate);
                } else if (TTSE_RESULT_EVENT_FINISH == event) {
 -                      SLOG(LOG_DEBUG, tts_tag(), "[SERVER] Event : TTSE_RESULT_EVENT_FINISH");
 +                      SLOG(LOG_INFO, tts_tag(), "[SERVER] Event : TTSE_RESULT_EVENT_FINISH");
                        SECURE_SLOG(LOG_DEBUG, tts_tag(), "[SERVER] Result Info : uid(%d), utt(%d), data(%p), data size(%d) audiotype(%d) rate(%d)", 
                                uid, uttid, data, data_size, audio_type, rate);
                } else {
                        if (NULL != temp_sound_data->data) {
                                memcpy(temp_sound_data->data, data, data_size);
                                temp_sound_data->data_size = data_size;
 -                              SLOG(LOG_ERROR, tts_tag(), "[DEBUG][free] uid(%d), event(%d) sound_data(%p) data(%p) size(%d)", 
 +                              SLOG(LOG_INFO, tts_tag(), "[DEBUG][memcpy] uid(%d), event(%d) sound_data(%p) data(%p) size(%d)", 
                                        uid, event, temp_sound_data, temp_sound_data->data, temp_sound_data->data_size);
                        } else {
                                SLOG(LOG_ERROR, tts_tag(), "Fail to allocate memory");
@@@ -406,7 -408,7 +409,7 @@@ void __config_changed_cb(tts_config_typ
  
  bool __terminate_client(int pid, int uid, app_state_e state, void* user_data)
  {
 -      SLOG(LOG_DEBUG, tts_tag(), "=== Start to terminate client [%d] ===", uid);
 +      SLOG(LOG_INFO, tts_tag(), "=== Start to terminate client [%d] ===", uid);
        ttsd_server_finalize(uid);
        return true;
  }
@@@ -420,7 -422,7 +423,7 @@@ Eina_Bool ttsd_terminate_daemon(void *d
  void __screen_reader_changed_cb(bool value)
  {
        if (TTSD_MODE_SCREEN_READER == ttsd_get_mode() && false == value) {
 -              SLOG(LOG_DEBUG, tts_tag(), "[Server] Screen reader is OFF. Start to terminate tts daemon");
 +              SLOG(LOG_INFO, tts_tag(), "[Server] Screen reader is OFF. Start to terminate tts daemon");
                ecore_timer_add(1, ttsd_terminate_daemon, NULL);
        } else {
                SLOG(LOG_DEBUG, tts_tag(), "[Server] Screen reader is %s", value ? "ON" : "OFF");
  */
  int ttsd_initialize(ttse_request_callback_s *callback)
  {
 +      SLOG(LOG_INFO, tts_tag(), "[Server] Initialize");
 +
        if (ttsd_config_initialize(__config_changed_cb)) {
                SLOG(LOG_ERROR, tts_tag(), "[Server WARNING] Fail to initialize config.");
        }
                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);
+       if (NULL == g_check_client_timer) {
+               SLOG(LOG_WARN, tts_tag(), "[WARNING] Fail to create timer");
+       }
        return TTSD_ERROR_NONE;
  }
  
  int ttsd_finalize()
  {
 +      SLOG(LOG_INFO, tts_tag(), "[Server] Finalize");
 +
        GList *iter = NULL;
        if (0 < g_list_length(g_proc_list)) {
                iter = g_list_first(g_proc_list);
  
        ttsd_engine_agent_release();
  
+       if (NULL != g_check_client_timer) {
+               ecore_timer_del(g_check_client_timer);
+               g_check_client_timer = NULL;
+               SLOG(LOG_INFO, tts_tag(), "[INFO] Delete ecore timer handle");
+       }
        return TTSD_ERROR_NONE;
  }
  
  
  int ttsd_server_initialize(int pid, int uid, bool* credential_needed)
  {
 +      SLOG(LOG_INFO, tts_tag(), "[Server] Server initialize");
 +
        if (-1 != ttsd_data_is_client(uid)) {
                SLOG(LOG_WARN, tts_tag(), "[Server WARNING] Uid has already been registered");
                return TTSD_ERROR_NONE;
  static Eina_Bool __quit_ecore_loop(void *data)
  {
        ttsd_dbus_close_connection();
        ttsd_network_finalize();
        ttsd_finalize();
        ecore_main_loop_quit();
        return EINA_FALSE;
  }
  
@@@ -627,8 -633,8 +640,8 @@@ Eina_Bool ttsd_cleanup_client(void *dat
        __read_proc();
  
        if (0 < ttsd_data_get_client_count()) {
 -      ttsd_data_foreach_clients(__get_client_for_clean_up, NULL);
 -              } else {
 +              ttsd_data_foreach_clients(__get_client_for_clean_up, NULL);
 +      } else {
                ecore_timer_add(0, __quit_ecore_loop, NULL);
        }
  
@@@ -648,8 -654,6 +661,8 @@@ void __used_voice_cb(const char* lang, 
  
  int ttsd_server_finalize(int uid)
  {
 +      SLOG(LOG_INFO, tts_tag(), "[Server] Server finalize");
 +
        app_state_e state;
        if (0 > ttsd_data_get_client_state(uid, &state)) {
                SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] ttsd_server_finalize : uid is not valid");
@@@ -715,8 -719,6 +728,8 @@@ int ttsd_server_add_queue(int uid, cons
  
        speak_data->text = strdup(text);
  
 +      SLOG(LOG_INFO, tts_tag(), "[Server] Add queue, lang(%s), vctype(%d), speed(%d), uttid(%d), credential(%s)", lang, voice_type, speed, utt_id, credential);
 +
        /* if state is APP_STATE_READY , APP_STATE_PAUSED , only need to add speak data to queue*/
        if (0 != ttsd_data_add_speak_data(uid, speak_data)) {
                SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to add speak data");
@@@ -804,7 -806,7 +817,7 @@@ int ttsd_server_play(int uid, const cha
        }
  
        int current_uid = ttsd_data_get_current_playing();
 -      SLOG(LOG_ERROR, tts_tag(), "[Server] playing uid (%d)", current_uid);
 +      SLOG(LOG_INFO, tts_tag(), "[Server] playing uid (%d)", current_uid);
  
        if (uid != current_uid && -1 != current_uid) {
                if (TTSD_MODE_DEFAULT != ttsd_get_mode()) {
@@@ -874,8 -876,6 +887,8 @@@ int ttsd_server_stop(int uid
                return TTSD_ERROR_INVALID_PARAMETER;
        }
  
 +      SLOG(LOG_INFO, tts_tag(), "[Server] server stop, state(%d)", state);
 +
        if (APP_STATE_PLAYING == state || APP_STATE_PAUSED == state) {
                if (TTSD_SYNTHESIS_CONTROL_DOING == __server_get_synth_control()) {
                        SLOG(LOG_DEBUG, tts_tag(), "[Server] TTS-engine is running");
@@@ -913,8 -913,6 +926,8 @@@ int ttsd_server_pause(int uid, int* utt
                return TTSD_ERROR_INVALID_STATE;
        }
  
 +      SLOG(LOG_INFO, tts_tag(), "[Server] server pause, uid(%d), utt_id(%d)", uid, utt_id);
 +
        int ret = 0;
        ret = ttsd_player_pause(uid);
        if (0 != ret) {
@@@ -984,7 -982,7 +997,7 @@@ int ttsd_server_set_private_data(int ui
        if (0 != ret) {
                SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to set private data : ret(%d)", ret);
        } else {
 -              SLOG(LOG_DEBUG, tts_tag(), "[Server] Set private data");
 +              SLOG(LOG_DEBUG, tts_tag(), "[Server] Set private data, key(%s), data(%s)", key, data);
        }
  
        return ret;
@@@ -1007,7 -1005,7 +1020,7 @@@ int ttsd_server_get_private_data(int ui
        if (0 != ret) {
                SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to get private data : ret(%d)", ret);
        } else {
 -              SLOG(LOG_DEBUG, tts_tag(), "[Server] Get private data");
 +              SLOG(LOG_DEBUG, tts_tag(), "[Server] Get private data, key(%s), data(%s)", key, *data);
        }
  
        return ret;