SLOG(LOG_INFO, TAG_TTSC, "@@@ Set TTS mode(%d)", mode);
+ if (TTS_MODE_DEFAULT > mode || TTS_MODE_INTERRUPT < mode) {
+ SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] mode is not valid : %d", mode);
+ return TTS_ERROR_INVALID_PARAMETER;
+ }
+
tts_client_s* client = tts_client_get(tts);
if (NULL == client) {
SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] A handle is not valid. tts(%p)", tts);
return TTS_ERROR_INVALID_STATE;
}
- if (TTS_MODE_DEFAULT <= mode && mode <= TTS_MODE_INTERRUPT) {
- client->mode = mode;
- } else {
- SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] mode is not valid : %d", mode);
- SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
- SLOG(LOG_DEBUG, TAG_TTSC, " ");
- return TTS_ERROR_INVALID_PARAMETER;
- }
+ client->mode = mode;
if (TTS_MODE_SCREEN_READER == mode) {
int ret;
SLOG(LOG_DEBUG, TAG_TTSC, "@@@ Get TTS mode");
+ if (NULL == mode) {
+ SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Input parameter(mode) is NULL");
+ return TTS_ERROR_INVALID_PARAMETER;
+ }
+
tts_client_s* client = tts_client_get(tts);
if (NULL == client) {
SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] A handle is not valid. tts(%p)", tts);
return TTS_ERROR_INVALID_STATE;
}
- if (NULL == mode) {
- SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Input parameter(mode) is NULL");
- return TTS_ERROR_INVALID_PARAMETER;
- }
-
*mode = client->mode;
SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
- SLOG(LOG_DEBUG, TAG_TTSC, " ");
-
return TTS_ERROR_NONE;
}
return TTS_ERROR_INVALID_PARAMETER;
}
+ if (NULL == text || false == tts_core_is_valid_text(text)) {
+ SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Input text is invalid");
+ return TTS_ERROR_INVALID_PARAMETER;
+ }
+
tts_client_s* client = tts_client_get(tts);
if (NULL == client) {
SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] A handle is not valid. tts(%p)", tts);
return TTS_ERROR_PERMISSION_DENIED;
}
- // TODO: move up to parameter check
- /* check valid utf8 */
- bool valid = false;
-
- DBusError err;
- dbus_error_init(&err);
-
- valid = dbus_validate_utf8(text, &err);
- if (dbus_error_is_set(&err)) {
- SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Dbus Error(%s), text(%s)", err.message, text);
- dbus_error_free(&err);
- return TTS_ERROR_INVALID_PARAMETER;
- }
-
- if (valid != true) {
- SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Text is invalid - '%s'", text);
- return TTS_ERROR_INVALID_PARAMETER;
- }
-
- /* check text size */
- if (-1 == g_max_text_size) {
- SLOG(LOG_DEBUG, TAG_TTSC, "[DEBUG] g_max_text_size is %d byte", g_max_text_size);
- if (0 != tts_config_mgr_get_max_text_size((unsigned int*)&g_max_text_size)) {
- SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to get max text size");
- // TODO: fix to operation failed
- return TTS_ERROR_INVALID_PARAMETER;
- }
- }
- // TODO: move up to parameter check
-
- if (0 == g_max_text_size) {
- if (strlen(text) <= 0) {
- SLOG(LOG_DEBUG, TAG_TTSC, "[DEBUG] Max Text Size is %d byte", g_max_text_size);
- SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Input text size is invalid. (max text size is unlimited.)");
- SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
- return TTS_ERROR_INVALID_PARAMETER;
- }
- } else {
- SLOG(LOG_DEBUG, TAG_TTSC, "[DEBUG] g_max_text_size is %d byte", g_max_text_size);
- if (g_max_text_size < strlen(text) || strlen(text) <= 0) {
- SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Input text size is invalid. current text_size(%zu byte)", strlen(text));
- SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
- return TTS_ERROR_INVALID_PARAMETER;
- }
- }
-
SLOG(LOG_DEBUG, TAG_TTSC, "Text is valid - text(%zu byte) is '%s'", strlen(text), text);
/* save texts for repetition */
#include "tts_client.h"
-/* Max number of handle */
-static const int g_max_handle = 999;
+/* Constant value */
+static const int MAX_HANDLE_NUM = 999;
+static const int INVALID_HANDLE = -1;
+
/* allocated handle */
static int g_allocated_handle = 0;
/* client list */
pthread_mutex_lock(&g_allocated_handle_mutex);
g_allocated_handle++;
- if (g_allocated_handle > g_max_handle) {
+ if (g_allocated_handle > MAX_HANDLE_NUM) {
g_allocated_handle = 1;
}
client->supported_voice_user_data = user_data;
}
-int tts_client_new(tts_h* tts)
-{
- tts_client_s* client = NULL;
- client = (tts_client_s*)calloc(1, sizeof(tts_client_s));
- if (NULL == client) {
- SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to allocate memory");
- return TTS_ERROR_OUT_OF_MEMORY;
- }
- tts_h temp = (tts_h)calloc(1, sizeof(struct tts_s));
- if (NULL == temp) {
- SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to allocate memory");
- free(client);
- return TTS_ERROR_OUT_OF_MEMORY;
- }
- temp->handle = __client_generate_uid(getpid());
- temp->connected = false;
-
- /* initialize client data */
- client->tts = temp;
- client->pid = getpid();
- client->uid = temp->handle;
+static inline void __reset_client_data(tts_client_s* client) {
+ client->tts = NULL;
+ client->pid = INVALID_HANDLE;
+ client->uid = INVALID_HANDLE;
client->current_utt_id = 0;
client->state_changed_cb = NULL;
client->notify_error_timer = NULL;
client->notify_state_timer = NULL;
+}
+
+int tts_client_new(tts_h* tts)
+{
+ tts_client_s* client = NULL;
+ client = (tts_client_s*)calloc(1, sizeof(tts_client_s));
+ if (NULL == client) {
+ SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to allocate memory");
+ return TTS_ERROR_OUT_OF_MEMORY;
+ }
+ tts_h temp = (tts_h)calloc(1, sizeof(struct tts_s));
+ if (NULL == temp) {
+ SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to allocate memory");
+ free(client);
+ return TTS_ERROR_OUT_OF_MEMORY;
+ }
+ temp->handle = __client_generate_uid(getpid());
+ temp->connected = false;
+
+ /* initialize client data */
+ __reset_client_data(client);
+ client->tts = temp;
+ client->pid = getpid();
+ client->uid = temp->handle;
pthread_mutex_lock(&g_client_list_mutex);
g_client_list = g_list_append(g_client_list, client);
while (NULL != iter) {
data = iter->data;
if (tts->handle == data->tts->handle) {
+ tts->handle = INVALID_HANDLE;
g_client_list = g_list_remove_link(g_client_list, iter);
while (0 != data->cb_ref_count) {
if (NULL != data->err_msg) {
free(data->err_msg);
- data->err_msg = NULL;
}
if (NULL != data->credential) {
free(data->credential);
- data->credential = NULL;
}
if (NULL != data->text_repeat) {
free(data->text_repeat);
- data->text_repeat = NULL;
}
+ __reset_client_data(data);
int uid = data->uid;
free(data);
free(tts);
static const char* __convert_state(tts_state_e state)
{
switch (state) {
- case TTS_STATE_CREATED: return "Created";
- case TTS_STATE_READY: return "Ready";
- case TTS_STATE_PLAYING: return "Playing";
- case TTS_STATE_PAUSED: return "Paused";
+ case TTS_STATE_CREATED: return "Created";
+ case TTS_STATE_READY: return "Ready";
+ case TTS_STATE_PLAYING: return "Playing";
+ case TTS_STATE_PAUSED: return "Paused";
}
return "Invalid state";
return TTS_ERROR_INVALID_PARAMETER;
}
- if (NULL == before_lang || NULL == language) {
- SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Invalid parameter.");
- return TTS_ERROR_INVALID_PARAMETER;
- }
-
SLOG(LOG_DEBUG, TAG_TTSC, "Default voice changed data : before_lang(%s), before_voice_type(%d), language(%s), voice_type(%d)",
before_lang, before_voice_type, language, voice_type);
return TTS_ERROR_INVALID_PARAMETER;
}
- if (NULL == engine_id || NULL == language) {
- SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Invalid parameter.");
- return TTS_ERROR_INVALID_PARAMETER;
- }
-
SLOG(LOG_DEBUG, TAG_TTSC, "Engine changed data : engine_id(%s) language(%s), voicd_type(%d), need_credential(%d)",
engine_id, language, voice_type, need_credential);
return TTS_ERROR_NONE;
}
+bool tts_core_is_valid_text(const char* text)
+{
+ if (NULL == text) {
+ return false;
+ }
+
+ /* check valid utf8 */
+ DBusError err;
+ dbus_error_init(&err);
+ bool valid = dbus_validate_utf8(text, &err);
+ if (dbus_error_is_set(&err)) {
+ SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Dbus Error(%s), text(%s)", err.message, text);
+ dbus_error_free(&err);
+ return false;
+ }
+
+ if (false == valid) {
+ SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Text is invalid - '%s'", text);
+ return false;
+ }
+
+ if (strlen(text) <= 0) {
+ SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Input text size is invalid.");
+ return false;
+ }
+
+ unsigned int max_text_size = 0;
+ /* check text size */
+ if (0 != tts_config_mgr_get_max_text_size(&max_text_size)) {
+ SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to get max text size");
+ return false;
+ }
+
+ SLOG(LOG_DEBUG, TAG_TTSC, "[DEBUG] max_text_size is %d byte", max_text_size);
+ if (0 < max_text_size && max_text_size < strlen(text)) {
+ SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Input text size is bigger than maximum test size. text_size(%zu byte)", strlen(text));
+ return false;
+ }
+
+ return true;
+}
+
int tts_core_receive_hello(int uid, int ret, int credential_needed)
{
tts_client_s* client = tts_client_get_by_uid(uid);
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_set_current_state(tts_client_s* client, tts_state_e state);
+bool tts_core_is_valid_text(const char* text);
// called by tts.c
int tts_core_initialize();