Update log level for information
[platform/core/uifw/tts.git] / client / tts.c
index 09f3892..ac1ad4f 100644 (file)
@@ -152,6 +152,33 @@ void _tts_config_engine_changed_cb(const char* engine_id, const char* setting, c
        if (NULL != language)   SLOG(LOG_DEBUG, TAG_TTSC, "Language(%s)", language);
        SLOG(LOG_DEBUG, TAG_TTSC, "Voice type(%d), Auto voice(%s), Credential(%s)", voice_type, auto_voice ? "on" : "off", need_credential ? "need" : "no need");
 
+       /* When the default engine is changed, please unload the old engine and load the new one. */
+       int ret = -1;
+
+       if (TTS_STATE_PLAYING == client->current_state || TTS_STATE_PAUSED == client->current_state) {
+               ret = tts_stop(tts);
+               if (0 != ret) {
+                       SLOG(LOG_DEBUG, TAG_TTSC, "[DEBUG] TTS client stopping...");
+               }
+               ret = tts_unprepare(tts);
+               if (0 != ret) {
+                       SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to unprepare for setting a new engine... (%d)", ret);
+               }
+               ret = tts_prepare(tts);
+               if (0 != ret) {
+                       SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to prepare for setting a new engine... (%d)", ret);
+               }
+       } else if (TTS_STATE_READY == client->current_state) {
+               ret = tts_unprepare(tts);
+               if (0 != ret) {
+                       SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to unprepare for setting a new engine... (%d)", ret);
+               }
+               ret = tts_prepare(tts);
+               if (0 != ret) {
+                       SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to prepare for setting a new engine... (%d)", ret);
+               }
+       }
+
        /* call callback function */
        if (NULL != client->engine_changed_cb) {
                client->engine_changed_cb(tts, engine_id, language, voice_type, need_credential, client->engine_changed_user_data);
@@ -167,7 +194,7 @@ int tts_create(tts_h* tts)
                return TTS_ERROR_NOT_SUPPORTED;
        }
 
-       SLOG(LOG_DEBUG, TAG_TTSC, "===== Create TTS");
+       SLOG(LOG_INFO, TAG_TTSC, "===== Create TTS");
 
        /* check param */
        if (NULL == tts) {
@@ -221,7 +248,7 @@ int tts_destroy(tts_h tts)
                return TTS_ERROR_NOT_SUPPORTED;
        }
 
-       SLOG(LOG_DEBUG, TAG_TTSC, "===== Destroy TTS");
+       SLOG(LOG_INFO, TAG_TTSC, "===== Destroy TTS");
 
        if (NULL == tts) {
                SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Input handle is null");
@@ -316,7 +343,7 @@ int tts_set_mode(tts_h tts, tts_mode_e mode)
                return TTS_ERROR_NOT_SUPPORTED;
        }
 
-       SLOG(LOG_DEBUG, TAG_TTSC, "===== Set TTS mode");
+       SLOG(LOG_INFO, TAG_TTSC, "===== Set TTS mode(%d)", mode);
 
        tts_client_s* client = tts_client_get(tts);
 
@@ -445,7 +472,7 @@ int tts_set_server_tts(tts_h tts, const char* credential)
                return TTS_ERROR_NOT_SUPPORTED;
        }
 
-       if (NULL == tts || NULL == credential) {
+       if (NULL == tts) {
                SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Input parameter is null");
                return TTS_ERROR_INVALID_PARAMETER;
        }
@@ -467,19 +494,20 @@ int tts_set_server_tts(tts_h tts, const char* credential)
                client->credential = NULL;
        }
 
-       client->credential = strdup(credential);
-       if (NULL == client->credential) {
-               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to allocate memory");
-               return TTS_ERROR_OUT_OF_MEMORY;
-       }
-
        client->internal = true;
 
        char* key = NULL;
-       if (NULL != credential)
+       if (NULL != credential) {
                key = strdup("EnableServerTTS");
-       else
+               client->credential = strdup(credential);
+               if (NULL == client->credential) {
+                       SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to allocate memory");
+                       return TTS_ERROR_OUT_OF_MEMORY;
+               }
+       } else {
                key = strdup("DisableServerTTS");
+       }
+
        if (NULL == key) {
                SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to allocate memory");
                return TTS_ERROR_OUT_OF_MEMORY;
@@ -530,7 +558,7 @@ static Eina_Bool __tts_connect_daemon(void *data)
                return EINA_TRUE;
        }
 
-       SLOG(LOG_DEBUG, TAG_TTSC, "===== Connect daemon");
+       SLOG(LOG_INFO, TAG_TTSC, "===== Connect daemon");
 
        /* do request initialize */
        int ret = -1;
@@ -590,7 +618,7 @@ int tts_prepare(tts_h tts)
                return TTS_ERROR_NOT_SUPPORTED;
        }
 
-       SLOG(LOG_DEBUG, TAG_TTSC, "===== Prepare TTS");
+       SLOG(LOG_INFO, TAG_TTSC, "===== Prepare TTS");
 
        tts_client_s* client = tts_client_get(tts);
 
@@ -624,7 +652,7 @@ int tts_unprepare(tts_h tts)
                return TTS_ERROR_NOT_SUPPORTED;
        }
 
-       SLOG(LOG_DEBUG, TAG_TTSC, "===== Unprepare TTS");
+       SLOG(LOG_INFO, TAG_TTSC, "===== Unprepare TTS");
 
        tts_client_s* client = tts_client_get(tts);
 
@@ -913,7 +941,7 @@ int tts_get_error_message(tts_h tts, char** err_msg)
 
 int tts_add_text(tts_h tts, const char* text, const char* language, int voice_type, int speed, int* utt_id)
 {
-       SLOG(LOG_DEBUG, TAG_TTSC, "[DEBUG] Add text: text(%s), language(%s), type(%d)", (NULL == text) ? "NULL" : text, (NULL == language) ? "NULL" : language, voice_type);
+       SLOG(LOG_INFO, TAG_TTSC, "[DEBUG] Add text: text(%s), language(%s), type(%d)", (NULL == text) ? "NULL" : text, (NULL == language) ? "NULL" : language, voice_type);
 
        if (0 != __tts_get_feature_enabled()) {
                return TTS_ERROR_NOT_SUPPORTED;
@@ -1162,7 +1190,7 @@ int tts_play(tts_h tts)
                return TTS_ERROR_NOT_SUPPORTED;
        }
 
-       SLOG(LOG_DEBUG, TAG_TTSC, "===== Play tts");
+       SLOG(LOG_INFO, TAG_TTSC, "===== Play tts");
 
        if (NULL == tts) {
                SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Input handle is null.");
@@ -1336,7 +1364,7 @@ int tts_stop(tts_h tts)
                return TTS_ERROR_NOT_SUPPORTED;
        }
 
-       SLOG(LOG_DEBUG, TAG_TTSC, "===== Stop tts");
+       SLOG(LOG_INFO, TAG_TTSC, "===== Stop tts");
 
        if (NULL == tts) {
                SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Input handle is null");
@@ -1507,7 +1535,7 @@ int tts_pause(tts_h tts)
                return TTS_ERROR_NOT_SUPPORTED;
        }
 
-       SLOG(LOG_DEBUG, TAG_TTSC, "===== Pause tts");
+       SLOG(LOG_INFO, TAG_TTSC, "===== Pause tts");
 
        if (NULL == tts) {
                SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Input handle is null");
@@ -1579,10 +1607,10 @@ int tts_set_private_data(tts_h tts, const char* key, const char* data)
                return TTS_ERROR_NOT_SUPPORTED;
        }
 
-       SLOG(LOG_DEBUG, TAG_TTSC, "===== Set private 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 is null");
+               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Input handle isnull");
                return TTS_ERROR_INVALID_PARAMETER;
        }
 
@@ -1640,7 +1668,7 @@ int tts_get_private_data(tts_h tts, const char* key, char** data)
                return TTS_ERROR_NOT_SUPPORTED;
        }
 
-       SLOG(LOG_DEBUG, TAG_TTSC, "===== Get private data");
+       SLOG(LOG_INFO, TAG_TTSC, "===== Get private data, key(%s)", key);
 
        if (NULL == tts) {
                SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Input handle is null");
@@ -1725,34 +1753,80 @@ static Eina_Bool __tts_notify_error(void *data)
 
 int __tts_cb_error(int uid, tts_error_e reason, int utt_id, char* err_msg)
 {
-       tts_client_s* client = tts_client_get_by_uid(uid);
+       if (-1 == uid) {
+               GList* client_list = NULL;
+               client_list = tts_client_get_client_list();
 
-       if (NULL == client) {
-               SLOG(LOG_WARN, TAG_TTSC, "[WARNING] A handle is not valid");
-               return TTS_ERROR_INVALID_PARAMETER;
-       }
+               GList *iter = NULL;
+               tts_client_s *data = NULL;
 
-       client->utt_id = utt_id;
-       client->reason = reason;
-       if (NULL != client->err_msg) {
-               free(client->err_msg);
-               client->err_msg = NULL;
-       }
-       client->err_msg = strdup(err_msg);
+               if (g_list_length(client_list) > 0) {
+                       /* Get a first item */
+                       iter = g_list_first(client_list);
 
-       /* call callback function */
-       if (NULL != client->error_cb) {
-               ecore_timer_add(0, __tts_notify_error, client->tts);
+                       while (NULL != iter) {
+                               data = iter->data;
+
+                               data->utt_id = utt_id;
+                               data->reason = reason;
+                               if (NULL != data->err_msg) {
+                                       free(data->err_msg);
+                                       data->err_msg = NULL;
+                               }
+                               if (NULL != err_msg)
+                                       data->err_msg = strdup(err_msg);
+
+                               /* call callback function */
+                               if (NULL != data->error_cb) {
+                                       ecore_timer_add(0, __tts_notify_error, data->tts);
+                               } else {
+                                       SLOG(LOG_WARN, TAG_TTSC, "No registered callback function of error ");
+                               }
+
+                               if (TTS_ERROR_SERVICE_RESET == reason) {
+                                       SLOG(LOG_WARN, TAG_TTSC, "[WARNING] Service Reset");
+
+                                       data->current_state = TTS_STATE_CREATED;
+                                       if (0 != tts_prepare(data->tts)) {
+                                               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to prepare");
+                                       }
+                               }
+
+                               /* Next item */
+                               iter = g_list_next(iter);
+                       }
+               }
        } else {
-               SLOG(LOG_WARN, TAG_TTSC, "No registered callback function of error ");
-       }
+               tts_client_s* client = tts_client_get_by_uid(uid);
+
+               if (NULL == client) {
+                       SLOG(LOG_WARN, TAG_TTSC, "[WARNING] A handle is not valid");
+                       return TTS_ERROR_INVALID_PARAMETER;
+               }
 
-       if (TTS_ERROR_SERVICE_RESET == reason) {
-               SLOG(LOG_WARN, TAG_TTSC, "[WARNING] Service Reset");
+               client->utt_id = utt_id;
+               client->reason = reason;
+               if (NULL != client->err_msg) {
+                       free(client->err_msg);
+                       client->err_msg = NULL;
+               }
+               if (NULL != err_msg)
+                       client->err_msg = strdup(err_msg);
 
-               client->current_state = TTS_STATE_CREATED;
-               if (0 != tts_prepare(client->tts)) {
-                       SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to prepare");
+               /* call callback function */
+               if (NULL != client->error_cb) {
+                       ecore_timer_add(0, __tts_notify_error, client->tts);
+               } else {
+                       SLOG(LOG_WARN, TAG_TTSC, "No registered callback function of error ");
+               }
+
+               if (TTS_ERROR_SERVICE_RESET == reason) {
+                       SLOG(LOG_WARN, TAG_TTSC, "[WARNING] Service Reset");
+
+                       client->current_state = TTS_STATE_CREATED;
+                       if (0 != tts_prepare(client->tts)) {
+                               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to prepare");
+                       }
                }
        }
 
@@ -1819,7 +1893,7 @@ int __tts_cb_utt_started(int uid, int utt_id)
                return TTS_ERROR_INVALID_PARAMETER;
        }
 
-       SLOG(LOG_DEBUG, TAG_TTSC, "utterance started : utt id(%d) ", utt_id);
+       SLOG(LOG_INFO, TAG_TTSC, "utterance started : utt id(%d) ", utt_id);
 
        client->utt_id = utt_id;
 
@@ -1845,7 +1919,7 @@ int __tts_cb_utt_completed(int uid, int utt_id)
                return TTS_ERROR_INVALID_PARAMETER;
        }
 
-       SLOG(LOG_DEBUG, TAG_TTSC, "utterance completed : uttid(%d) ", utt_id);
+       SLOG(LOG_INFO, TAG_TTSC, "utterance completed : uttid(%d) ", utt_id);
 
        client->utt_id = utt_id;
 
@@ -1888,7 +1962,7 @@ int tts_set_state_changed_cb(tts_h tts, tts_state_changed_cb callback, void* use
        client->state_changed_cb = callback;
        client->state_changed_user_data = user_data;
 
-       SLOG(LOG_DEBUG, TAG_TTSC, "[SUCCESS] Set state changed cb");
+       SLOG(LOG_INFO, TAG_TTSC, "[SUCCESS] Set state changed cb");
 
        return 0;
 }