Merge "Remove unnecessary timer" into tizen
[platform/core/uifw/tts.git] / client / tts.c
index 188af5b..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;
 
@@ -117,6 +120,7 @@ static int __tts_convert_config_error_code(tts_config_error_e code)
        return code;
 }
 
+//LCOV_EXCL_START
 void __tts_config_voice_changed_cb(const char* before_lang, int before_voice_type, const char* language, int voice_type, bool auto_voice, void* user_data)
 {
        SLOG(LOG_DEBUG, TAG_TTSC, "Voice changed : Before lang(%s) type(%d) , Current lang(%s), type(%d)",
@@ -227,6 +231,7 @@ void _tts_config_engine_changed_cb(const char* engine_id, const char* setting, c
        }
        return;
 }
+//LCOV_EXCL_STOP
 
 int tts_create(tts_h* tts)
 {
@@ -330,6 +335,7 @@ int tts_destroy(tts_h tts)
                        do {
                                ret = tts_dbus_request_finalize(client->uid);
                                if (0 != ret) {
+                                       //LCOV_EXCL_START
                                        if (TTS_ERROR_TIMED_OUT != ret) {
                                                SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] result : %s", __tts_get_error_code(ret));
                                                break;
@@ -342,6 +348,7 @@ int tts_destroy(tts_h tts)
                                                        break;
                                                }
                                        }
+                                       //LCOV_EXCL_STOP
                                }
                        } while (0 != ret);
                } else {
@@ -376,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, "@@@");
@@ -383,10 +396,12 @@ int tts_destroy(tts_h tts)
        return TTS_ERROR_NONE;
 }
 
+//LCOV_EXCL_START
 void __tts_screen_reader_changed_cb(bool value)
 {
        g_screen_reader = value;
 }
+//LCOV_EXCL_STOP
 
 int tts_set_mode(tts_h tts, tts_mode_e mode)
 {
@@ -632,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) {
@@ -642,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) {
@@ -655,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 */
@@ -705,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();
 
@@ -793,6 +821,7 @@ int tts_unprepare(tts_h tts)
                do {
                        ret = tts_dbus_request_finalize(client->uid);
                        if (0 != ret) {
+                               //LCOV_EXCL_START
                                if (TTS_ERROR_INVALID_PARAMETER == ret && false == is_prepared) {
                                        client->current_state = TTS_STATE_CREATED;
                                        if (0 == tts_prepare_sync(tts)) {
@@ -811,6 +840,7 @@ int tts_unprepare(tts_h tts)
                                                break;
                                        }
                                }
+                               //LCOV_EXCL_STOP
                        }
                } while (0 != ret);
        } else {
@@ -1204,6 +1234,7 @@ int tts_add_text(tts_h tts, const char* text, const char* language, int voice_ty
        while (0 != ret) {
                ret = tts_dbus_request_add_text(client->uid, text, temp, voice_type, speed, client->current_utt_id, client->credential);
                if (0 != ret) {
+                       //LCOV_EXCL_START
                        if (TTS_ERROR_INVALID_PARAMETER == ret && false == is_prepared) {
                                client->current_state = TTS_STATE_CREATED;
                                if (0 == tts_prepare_sync(tts)) {
@@ -1222,6 +1253,7 @@ int tts_add_text(tts_h tts, const char* text, const char* language, int voice_ty
                                        break;
                                }
                        }
+                       //LCOV_EXCL_STOP
                } else {
                        *utt_id = client->current_utt_id;
                }
@@ -1389,6 +1421,7 @@ int tts_play(tts_h tts)
        while (0 != ret) {
                ret = tts_dbus_request_play(client->uid, client->credential);
                if (0 != ret) {
+                       //LCOV_EXCL_START
                        if (TTS_ERROR_INVALID_PARAMETER == ret && false == is_prepared) {
                                client->current_state = TTS_STATE_CREATED;
                                if (0 == tts_prepare_sync(tts)) {
@@ -1407,6 +1440,7 @@ int tts_play(tts_h tts)
                                        return ret;
                                }
                        }
+                       //LCOV_EXCL_STOP
                }
        }
 
@@ -1565,6 +1599,7 @@ int tts_stop(tts_h tts)
        while (0 != ret) {
                ret = tts_dbus_request_stop(client->uid);
                if (0 != ret) {
+                       //LCOV_EXCL_START
                        if (TTS_ERROR_INVALID_PARAMETER == ret && false == is_prepared) {
                                client->current_state = TTS_STATE_CREATED;
                                if (0 == tts_prepare_sync(tts)) {
@@ -1583,6 +1618,7 @@ int tts_stop(tts_h tts)
                                        return ret;
                                }
                        }
+                       //LCOV_EXCL_STOP
                }
        }
 
@@ -1743,6 +1779,7 @@ int tts_pause(tts_h tts)
        while (0 != ret) {
                ret = tts_dbus_request_pause(client->uid);
                if (0 != ret) {
+                       //LCOV_EXCL_START
                        if (TTS_ERROR_INVALID_PARAMETER == ret && false == is_prepared) {
                                client->current_state = TTS_STATE_CREATED;
                                if (0 == tts_prepare_sync(tts)) {
@@ -1761,6 +1798,7 @@ int tts_pause(tts_h tts)
                                        return ret;
                                }
                        }
+                       //LCOV_EXCL_STOP
                }
        }
 
@@ -1788,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;
        }
 
@@ -1820,6 +1858,7 @@ int tts_set_private_data(tts_h tts, const char* key, const char* data)
        while (0 != ret) {
                ret = tts_dbus_request_set_private_data(client->uid, key, data);
                if (0 != ret) {
+                       //LCOV_EXCL_START
                        if (TTS_ERROR_INVALID_PARAMETER == ret && false == is_prepared) {
                                client->current_state = TTS_STATE_CREATED;
                                if (0 == tts_prepare_sync(tts)) {
@@ -1838,6 +1877,7 @@ int tts_set_private_data(tts_h tts, const char* key, const char* data)
                                        return ret;
                                }
                        }
+                       //LCOV_EXCL_STOP
                }
        }
 
@@ -1882,6 +1922,7 @@ int tts_get_private_data(tts_h tts, const char* key, char** data)
        while (0 != ret) {
                ret = tts_dbus_request_get_private_data(client->uid, key, data);
                if (0 != ret) {
+                       //LCOV_EXCL_START
                        if (TTS_ERROR_INVALID_PARAMETER == ret && false == is_prepared) {
                                client->current_state = TTS_STATE_CREATED;
                                if (0 == tts_prepare_sync(tts)) {
@@ -1900,6 +1941,7 @@ int tts_get_private_data(tts_h tts, const char* key, char** data)
                                        return ret;
                                }
                        }
+                       //LCOV_EXCL_STOP
                }
        }
 
@@ -1913,6 +1955,7 @@ int tts_get_private_data(tts_h tts, const char* key, char** data)
        return 0;
 }
 
+//LCOV_EXCL_START
 static Eina_Bool __tts_notify_error(void *data)
 {
        tts_h tts = (tts_h)data;
@@ -2063,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");
        }
@@ -2073,6 +2120,7 @@ int __tts_cb_set_state(int uid, int state)
 
        return 0;
 }
+//LCOV_EXCL_STOP
 
 int __tts_cb_utt_started(int uid, int utt_id)
 {
@@ -2183,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;
@@ -2709,6 +2762,7 @@ int tts_stop_pcm(tts_h tts)
 
        return TTS_ERROR_NONE;
 }
+//LCOV_EXCL_STOP
 
 int tts_repeat(tts_h tts, char** text_repeat, int* utt_id)
 {
@@ -2802,4 +2856,3 @@ int tts_repeat(tts_h tts, char** text_repeat, int* utt_id)
 
        return TTS_ERROR_NONE;
 }
-//LCOV_EXCL_STOP