}
}
-int __tts_config_release_client(unsigned int uid)
+static inline void free_config_client(tts_config_client_s* client)
{
- GSList *iter = NULL;
- tts_config_client_s* temp_client = NULL;
+ if (NULL != client) {
+ client->uid = TTS_INVALID_UID;
+ client->engine_cb = NULL;
+ client->voice_cb = NULL;
+ client->speech_cb = NULL;
+ client->screen_cb = NULL;
+ client->pitch_cb = NULL;
+ client->bg_volume_ratio_cb = NULL;
+ client->user_data = NULL;
+ client->screen_user_data = NULL;
+
+ free(client);
+ }
+}
- if (0 < g_slist_length(g_config_client_list)) {
- /* Check uid */
- iter = g_slist_nth(g_config_client_list, 0);
+static gint compare_config_client_and_uid(gconstpointer a, gconstpointer b)
+{
+ const tts_config_client_s *client = (const tts_config_client_s *)a;
+ const unsigned int *uid = (const unsigned int *)b;
- while (NULL != iter) {
- temp_client = iter->data;
-
- if (NULL != temp_client) {
- if (uid == temp_client->uid) {
- g_config_client_list = g_slist_remove(g_config_client_list, temp_client);
- free(temp_client);
- temp_client = NULL;
- break;
- }
- }
+ if (NULL != client && NULL != uid && client->uid == *uid) {
+ return 0;
+ }
- iter = g_slist_next(iter);
- }
+ return -1;
+}
+
+static int release_config_client(unsigned int uid)
+{
+ GSList *iter = g_slist_find_custom(g_config_client_list, &uid, compare_config_client_and_uid);
+ if (NULL != iter) {
+ tts_config_client_s *client = (tts_config_client_s *)iter->data;
+ g_config_client_list = g_slist_delete_link(g_config_client_list, iter);
+
+ free_config_client(client);
}
SLOG(LOG_DEBUG, TAG_TTSCONFIG, "Client count (%d)", g_slist_length(g_config_client_list));
-
return g_slist_length(g_config_client_list);
}
return TTS_CONFIG_ERROR_OUT_OF_MEMORY;
}
new_client->uid = uid;
- new_client->engine_cb = NULL;
- new_client->voice_cb = NULL;
- new_client->speech_cb = NULL;
- new_client->pitch_cb = NULL;
- new_client->screen_cb = NULL;
- new_client->bg_volume_ratio_cb = NULL;
- new_client->user_data = NULL;
- new_client->screen_user_data = NULL;
g_config_client_list = g_slist_append(g_config_client_list, new_client);
-
return TTS_CONFIG_ERROR_NONE;
}
if (0 != access(TTS_CONFIG_BASE, F_OK)) {
if (0 != mkdir(TTS_CONFIG_BASE, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)) {
SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to make directory : %s", TTS_CONFIG_BASE);
- __tts_config_release_client(uid);
+ release_config_client(uid);
return TTS_CONFIG_ERROR_OPERATION_FAILED;
} else {
SLOG(LOG_DEBUG, TAG_TTSCONFIG, "Success to make directory : %s", TTS_CONFIG_BASE);
if (0 != access(TTS_HOME, F_OK)) {
if (0 != mkdir(TTS_HOME, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)) {
SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to make directory : %s", TTS_HOME);
- __tts_config_release_client(uid);
+ release_config_client(uid);
return TTS_CONFIG_ERROR_OPERATION_FAILED;
} else {
SLOG(LOG_DEBUG, TAG_TTSCONFIG, "Success to make directory : %s", TTS_HOME);
if (0 != access(TTS_DOWNLOAD_BASE, F_OK)) {
if (0 != mkdir(TTS_DOWNLOAD_BASE, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)) {
SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to make directory : %s", TTS_DOWNLOAD_BASE);
- __tts_config_release_client(uid);
+ release_config_client(uid);
return TTS_CONFIG_ERROR_OPERATION_FAILED;
} else {
SLOG(LOG_DEBUG, TAG_TTSCONFIG, "Success to make directory : %s", TTS_DOWNLOAD_BASE);
if (0 != access(TTS_DOWNLOAD_ENGINE_INFO, F_OK)) {
if (0 != mkdir(TTS_DOWNLOAD_ENGINE_INFO, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)) {
SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to make directory : %s", TTS_DOWNLOAD_ENGINE_INFO);
- __tts_config_release_client(uid);
+ release_config_client(uid);
return TTS_CONFIG_ERROR_OPERATION_FAILED;
} else {
SLOG(LOG_DEBUG, TAG_TTSCONFIG, "Success to make directory : %s", TTS_DOWNLOAD_ENGINE_INFO);
if (0 != __tts_config_mgr_get_engine_info()) {
SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to get engine info");
- __tts_config_release_client(uid);
+ release_config_client(uid);
__tts_config_release_engine();
return TTS_CONFIG_ERROR_ENGINE_NOT_FOUND;
}
if (0 != tts_parser_load_config()) {
SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to parse configure information");
- __tts_config_release_client(uid);
+ release_config_client(uid);
__tts_config_release_engine();
return TTS_CONFIG_ERROR_OPERATION_FAILED;
}
tts_config_s config_info;
if (0 != tts_parser_get_config_info(&config_info)) {
SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to get configure information");
- __tts_config_release_client(uid);
+ release_config_client(uid);
__tts_config_release_engine();
return TTS_CONFIG_ERROR_OPERATION_FAILED;
}
/* Check whether engine id is valid */
if (0 != __tts_config_mgr_check_engine_is_valid(config_info.engine_id)) {
SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to get default engine");
- __tts_config_release_client(uid);
+ release_config_client(uid);
__tts_config_release_engine();
tts_parser_unload_config();
return TTS_CONFIG_ERROR_ENGINE_NOT_FOUND;
int tmp_type = -1;
if (0 != __tts_config_mgr_select_lang(config_info.engine_id, &tmp_language, &tmp_type)) {
SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to select language");
- __tts_config_release_client(uid);
+ release_config_client(uid);
__tts_config_release_engine();
tts_parser_unload_config();
return TTS_CONFIG_ERROR_OPERATION_FAILED;
if (__is_client_type(TTS_CONFIG_CLIENT_TYPE_SETTING | TTS_CONFIG_CLIENT_TYPE_SERVER | TTS_CONFIG_CLIENT_TYPE_INTERRUPT)) {
if (0 != tts_parser_set_voice(config_info.language, config_info.type)) {
SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to save config");
- __tts_config_release_client(uid);
+ release_config_client(uid);
__tts_config_release_engine();
tts_parser_unload_config();
return TTS_CONFIG_ERROR_OPERATION_FAILED;
if (0 != __tts_config_mgr_register_config_event()) {
SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to register config event");
- __tts_config_release_client(uid);
+ release_config_client(uid);
__tts_config_release_engine();
tts_parser_unload_config();
return TTS_CONFIG_ERROR_OPERATION_FAILED;
/* For engine directory monitoring */
//if (0 != __tts_config_mgr_register_engine_config_updated_event()) {
// SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to register engine config updated event");
- // __tts_config_release_client(uid);
+ // release_config_client(uid);
// __tts_config_release_engine();
// tts_parser_unload_config();
// __tts_config_mgr_unregister_config_event();
int tts_config_mgr_finalize(unsigned int uid, tts_config_client_type_e client_type)
{
- if (0 < __tts_config_release_client(uid)) {
+ if (0 < release_config_client(uid)) {
g_client_type &= ~client_type;
return TTS_CONFIG_ERROR_NONE;
}
SLOG(LOG_INFO, TAG_TTSCONFIG, "Client type : %d", client_type);
g_client_type &= ~client_type;
- tts_config_mgr_unset_callback(uid);
-
__tts_config_release_engine();
tts_parser_unload_config();
return TTS_CONFIG_ERROR_NONE;
}
-int tts_config_mgr_unset_callback(unsigned int uid)
-{
- GSList *iter = NULL;
- tts_config_client_s* temp_client = NULL;
-
- /* Call all callbacks of client*/
- iter = g_slist_nth(g_config_client_list, 0);
-
- while (NULL != iter) {
- temp_client = iter->data;
-
- if (NULL != temp_client) {
- if (uid == temp_client->uid) {
- temp_client->engine_cb = NULL;
- temp_client->voice_cb = NULL;
- temp_client->speech_cb = NULL;
- temp_client->pitch_cb = NULL;
- temp_client->bg_volume_ratio_cb = NULL;
- temp_client->user_data = NULL;
- }
- }
-
- iter = g_slist_next(iter);
- }
-
- return TTS_CONFIG_ERROR_NONE;
-}
-
int tts_config_mgr_set_screen_reader_callback(unsigned int uid, tts_config_screen_reader_changed_cb callback, void* user_data)
{
if (NULL == callback) {