Added set/unset background volume ratio fucntion.
[platform/core/uifw/tts.git] / client / tts.c
index 3abdc43..67db4b9 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;
 
@@ -230,6 +233,20 @@ void _tts_config_engine_changed_cb(const char* engine_id, const char* setting, c
 }
 //LCOV_EXCL_STOP
 
+void __tts_unset_all_callbacks(tts_h tts)
+{
+       SLOG(LOG_INFO, TAG_TTSC, "@@@ unset all callbacks");
+
+       tts_unset_state_changed_cb(tts);
+       tts_unset_utterance_started_cb(tts);
+       tts_unset_utterance_completed_cb(tts);
+       tts_unset_error_cb(tts);
+       tts_unset_default_voice_changed_cb(tts);
+       tts_unset_engine_changed_cb(tts);
+
+       SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
+}
+
 int tts_create(tts_h* tts)
 {
        if (0 != __tts_get_feature_enabled()) {
@@ -270,7 +287,7 @@ int tts_create(tts_h* tts)
                return __tts_convert_config_error_code(ret);
        }
 
-       ret = tts_config_mgr_set_callback(client->uid, _tts_config_engine_changed_cb, __tts_config_voice_changed_cb, NULL, NULL, client->tts);
+       ret = tts_config_mgr_set_callback(client->uid, _tts_config_engine_changed_cb, __tts_config_voice_changed_cb, NULL, NULL, NULL, client->tts);
        if (0 != ret) {
                SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to set config changed : %d", ret);
                tts_client_destroy(*tts);
@@ -361,6 +378,9 @@ int tts_destroy(tts_h tts)
                        ecore_timer_del(client->conn_timer);
                        client->conn_timer = NULL;
                }
+               /* Unset registered callbacks */
+               __tts_unset_all_callbacks(tts);
+
                /* Free resources */
                tts_client_destroy(tts);
                break;
@@ -380,6 +400,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 +664,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 +677,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 +693,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 +746,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 +1843,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 +2123,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 +2248,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;