Pass return value of supported_voice_cb to tts_config_mgr_get_voice_list 95/248495/6
authorSuyeon Hwang <stom.hwang@samsung.com>
Wed, 11 Nov 2020 08:23:43 +0000 (17:23 +0900)
committerSuyeon Hwang <stom.hwang@samsung.com>
Thu, 18 Mar 2021 07:58:30 +0000 (16:58 +0900)
Change-Id: I746702455b9bd1ba71a52019c6da0437593eca1b
Signed-off-by: Suyeon Hwang <stom.hwang@samsung.com>
client/tts.c
client/tts_core.c
client/tts_core.h

index 95429d779a40ced493761860cd30905e94e226ec..2629dbfeeba2001cb5240160e1295d7375e03247 100644 (file)
@@ -804,16 +804,6 @@ int tts_unprepare(tts_h tts)
        return TTS_ERROR_NONE;
 }
 
-static bool __tts_supported_voice_cb(const char* engine_id, const char* language, int type, void* user_data)
-{
-       tts_client_s* client = (tts_client_s*)user_data;
-
-       /* call callback function */
-       // TODO: pass return value of callback
-       tts_core_notify_supported_voice(client, language, type);
-       return false;
-}
-
 int tts_foreach_supported_voices(tts_h tts, tts_supported_voice_cb callback, void* user_data)
 {
        if (0 != __tts_get_feature_enabled()) {
@@ -838,14 +828,12 @@ int tts_foreach_supported_voices(tts_h tts, tts_supported_voice_cb callback, voi
        int ret = 0;
        char* current_engine = NULL;
        ret = tts_config_mgr_get_engine(&current_engine);
-       if (0 != ret) {
+       if (0 != ret || NULL == current_engine) {
                SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to get current engine : %d", ret);
                return __tts_convert_config_error_code(ret);
        }
 
-       tts_client_set_supported_voice_cb(client, callback, user_data);
-       ret = tts_config_mgr_get_voice_list(current_engine, __tts_supported_voice_cb, client);
-       tts_client_set_supported_voice_cb(client, NULL, NULL);
+       ret = tts_core_foreach_supported_voices(client, current_engine, callback, user_data);
 
        if (NULL != current_engine) {
                free(current_engine);
@@ -854,11 +842,9 @@ int tts_foreach_supported_voices(tts_h tts, tts_supported_voice_cb callback, voi
 
        if (0 != ret) {
                SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Result : %d", ret);
-               ret = TTS_ERROR_OPERATION_FAILED;
        }
 
        SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
-
        return ret;
 }
 
index 27c17ce3465375422c1a7c589d2da50355eb7213..ef533f563febc1a5af95ea23a7ff16e455121af1 100644 (file)
@@ -571,6 +571,25 @@ static void __engine_changed_cb(keynode_t* key, void* data)
        return;
 }
 
+static bool __supported_voice_cb(const char* engine_id, const char* language, int type, void* user_data)
+{
+       int uid = (int)user_data;
+       tts_client_s* client = tts_client_get_by_uid(uid);
+       if (NULL == client) {
+               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Uid is not valid. (%d)", uid);
+               return false;
+       }
+
+       /* call callback function */
+       tts_supported_voice_cb callback = tts_client_get_supported_voice_cb(client);
+       void* data = tts_client_get_supported_voice_user_data(client);
+
+       if (NULL != callback) {
+               return callback(tts_client_get_handle(client), language, type, data);
+       }
+
+       return false;
+}
 
 /* Public functions */
 int tts_core_initialize()
@@ -800,33 +819,6 @@ int tts_core_notify_engine_changed(tts_client_s* client, const char* engine_id,
        return TTS_ERROR_NONE;
 }
 
-int tts_core_notify_supported_voice(tts_client_s* client, const char* language, int voice_type)
-{
-       /* check handle */
-       if (NULL == client || false == tts_client_is_valid(client->uid)) {
-               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Handle is not valid.");
-               return TTS_ERROR_INVALID_PARAMETER;
-       }
-
-       if (NULL == language) {
-               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Invalid parameter.");
-               return TTS_ERROR_INVALID_PARAMETER;
-       }
-
-       SLOG(LOG_DEBUG, TAG_TTSC, "Supported voice data : language(%s), voicd_type(%d)", language, voice_type);
-
-       if (NULL != client->supported_voice_cb) {
-               SLOG(LOG_DEBUG, TAG_TTSC, "Notify supported voice");
-               tts_client_use_callback(client);
-               client->supported_voice_cb(tts_client_get_handle(client), language, voice_type, client->supported_voice_user_data);
-               tts_client_not_use_callback(client);
-       } else {
-               SLOG(LOG_WARN, TAG_TTSC, "No registered callback(supported_voice)");
-       }
-
-       return TTS_ERROR_NONE;
-}
-
 int tts_core_receive_hello(int uid, int ret, int credential_needed)
 {
        tts_client_s* client = tts_client_get_by_uid(uid);
@@ -1015,3 +1007,17 @@ int tts_core_reprepare()
 
        return TTS_ERROR_NONE;
 }
+
+int tts_core_foreach_supported_voices(tts_client_s* client, const char* engine_id, tts_supported_voice_cb callback, void* user_data)
+{
+       tts_client_set_supported_voice_cb(client, callback, user_data);
+       int ret = tts_config_mgr_get_voice_list(engine_id, __supported_voice_cb, (void*)client->uid);
+       tts_client_set_supported_voice_cb(client, NULL, NULL);
+
+       if (0 != ret) {
+               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to get voice list");
+               return TTS_ERROR_OPERATION_FAILED;
+       }
+
+       return TTS_ERROR_NONE;
+}
index 5bbdf3085f4af2882a0e4e3ade9e55634419ee4b..a8fa4fd63e705c2d65f9571d2b46932c93b12140 100644 (file)
@@ -30,7 +30,6 @@ int tts_core_notify_error(tts_client_s* client, int utt_id, tts_error_e reason);
 int tts_core_notify_error_async(tts_client_s* client, int utt_id, tts_error_e reason);
 int tts_core_notify_default_voice_changed(tts_client_s* client, const char* before_lang, int before_voice_type, const char* language, int voice_type);
 int tts_core_notify_engine_changed(tts_client_s* client, const char* engine_id, const char* language, int voice_type, bool need_credential);
-int tts_core_notify_supported_voice(tts_client_s* client, const char* language, int voice_type);
 
 // called by tts.c
 int tts_core_initialize();
@@ -42,6 +41,8 @@ int tts_core_prepare_sync(tts_client_s* client);
 int tts_core_unprepare(tts_client_s* client, bool is_screen_reader_on);
 int tts_core_reprepare();
 
+int tts_core_foreach_supported_voices(tts_client_s* client, const char* engine_id, tts_supported_voice_cb callback, void* user_data);
+
 // called by tts_dbus.c
 int tts_core_receive_hello(int uid, int ret, int credential_needed);