Merge "Remove unnecessary timer" into tizen
[platform/core/uifw/tts.git] / client / tts.c
index 3abdc43..08e8d9a 100644 (file)
@@ -37,6 +37,9 @@ static bool g_err_callback_status = false;
 
 static int g_max_text_size = -1;
 
+static Ecore_Timer* g_check_state_timer = NULL;
+
+
 /* for repetition */
 static char* g_language = NULL;
 
@@ -380,6 +383,12 @@ int tts_destroy(tts_h tts)
                g_language = NULL;
        }
 
+       /* Delete state timer before destroying handle */
+       if (NULL != g_check_state_timer) {
+               ecore_timer_del(g_check_state_timer);
+               g_check_state_timer = NULL;
+       }
+
        tts = NULL;
 
        SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
@@ -638,7 +647,10 @@ static Eina_Bool __tts_connect_daemon(void *data)
                client->utt_id = -1;
 
                ecore_timer_add(0, __tts_notify_error, (void*)client->tts);
-               client->conn_timer = NULL;
+               if (client->conn_timer) {
+                       ecore_timer_del(client->conn_timer);
+                       client->conn_timer = NULL;
+               }
                return EINA_FALSE;
 
        } else if (TTS_ERROR_PERMISSION_DENIED == ret) {
@@ -648,7 +660,10 @@ static Eina_Bool __tts_connect_daemon(void *data)
                client->utt_id = -1;
 
                ecore_timer_add(0, __tts_notify_error, (void*)client->tts);
-               client->conn_timer = NULL;
+               if (client->conn_timer) {
+                       ecore_timer_del(client->conn_timer);
+                       client->conn_timer = NULL;
+               }
                return EINA_FALSE;
 
        } else if (TTS_ERROR_NONE != ret) {
@@ -661,7 +676,10 @@ static Eina_Bool __tts_connect_daemon(void *data)
                SLOG(LOG_ERROR, TAG_TTSC, "Supported options : credential(%s)", credential_needed ? "need" : "no need");
        }
 
-       client->conn_timer = NULL;
+       if (client->conn_timer) {
+               ecore_timer_del(client->conn_timer);
+               client->conn_timer = NULL;
+       }
 
        client = tts_client_get(tts);
        /* check handle */
@@ -711,6 +729,10 @@ int tts_prepare(tts_h tts)
        }
 
        ecore_thread_main_loop_begin();
+       if (client->conn_timer) {
+               ecore_timer_del(client->conn_timer);
+               client->conn_timer = NULL;
+       }
        client->conn_timer = ecore_timer_add(0.02, __tts_connect_daemon, (void*)tts);
        ecore_thread_main_loop_end();
 
@@ -1804,7 +1826,7 @@ int tts_set_private_data(tts_h tts, const char* key, const char* data)
        SLOG(LOG_INFO, TAG_TTSC, "@@@ Set private data, key(%s), data(%s)", key, data);
 
        if (NULL == tts) {
-               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Input handle isnull");
+               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Input handle is null");
                return TTS_ERROR_INVALID_PARAMETER;
        }
 
@@ -2084,7 +2106,11 @@ int __tts_cb_set_state(int uid, int state)
        }
 
        if (NULL != client->state_changed_cb) {
-               ecore_timer_add(0, __tts_notify_state_changed, client->tts);
+               if (NULL != g_check_state_timer) {
+                       ecore_timer_del(g_check_state_timer);
+                       g_check_state_timer = NULL;
+               }
+               g_check_state_timer = ecore_timer_add(0, __tts_notify_state_changed, client->tts);
        } else {
                SLOG(LOG_WARN, TAG_TTSC, "[WARNING] State changed callback is null");
        }
@@ -2205,6 +2231,11 @@ int tts_unset_state_changed_cb(tts_h tts)
        client->state_changed_cb = NULL;
        client->state_changed_user_data = NULL;
 
+       if (NULL != g_check_state_timer) {
+               ecore_timer_del(g_check_state_timer);
+               g_check_state_timer = NULL;
+       }
+
        SLOG(LOG_DEBUG, TAG_TTSC, "[SUCCESS] Unset state changed cb");
 
        return 0;