}
}
- client->before_state = client->current_state;
- client->current_state = TTS_STATE_CREATED;
+ tts_client_set_current_state(client, TTS_STATE_CREATED);
case TTS_STATE_CREATED:
/* Unset registered callbacks */
if (0 != ret) {
//LCOV_EXCL_START
if (TTS_ERROR_INVALID_PARAMETER == ret && false == is_prepared) {
- client->current_state = TTS_STATE_CREATED;
+ tts_client_set_current_state(client, TTS_STATE_CREATED);
if (0 == tts_core_prepare_sync(client)) {
is_prepared = true;
SLOG(LOG_INFO, TAG_TTSC, "[INFO] Success tts_prepare_sync");
ret = tts_ipc_request_play(client->uid, client->credential);
if (0 != ret) {
if (TTS_ERROR_INVALID_PARAMETER == ret && false == is_prepared) {
- client->current_state = TTS_STATE_CREATED;
+ tts_client_set_current_state(client, TTS_STATE_CREATED);
if (0 == tts_core_prepare_sync(client)) {
is_prepared = true;
SLOG(LOG_INFO, TAG_TTSC, "[INFO] Success tts_prepare_sync");
return;
}
- client->before_state = client->current_state;
- client->current_state = TTS_STATE_PLAYING;
- tts_core_notify_state_changed(client, client->before_state, client->current_state);
+ tts_core_set_current_state(client, TTS_STATE_PLAYING);
SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
-
return;
}
if (0 != ret) {
//LCOV_EXCL_START
if (TTS_ERROR_INVALID_PARAMETER == ret && false == is_prepared) {
- client->current_state = TTS_STATE_CREATED;
+ tts_client_set_current_state(client, TTS_STATE_CREATED);
if (0 == tts_core_prepare_sync(client)) {
is_prepared = true;
SLOG(LOG_INFO, TAG_TTSC, "[INFO] Success tts_prepare_sync");
}
}
- client->before_state = client->current_state;
- client->current_state = TTS_STATE_PLAYING;
- tts_core_notify_state_changed(client, client->before_state, client->current_state);
+ tts_core_set_current_state(client, TTS_STATE_PLAYING);
SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
-
return TTS_ERROR_NONE;
}
+
//LCOV_EXCL_START
static void __tts_stop_async(void *data)
{
ret = tts_ipc_request_stop(client->uid);
if (0 != ret) {
if (TTS_ERROR_INVALID_PARAMETER == ret && false == is_prepared) {
- client->current_state = TTS_STATE_CREATED;
+ tts_client_set_current_state(client, TTS_STATE_CREATED);
if (0 == tts_core_prepare_sync(client)) {
is_prepared = true;
SLOG(LOG_INFO, TAG_TTSC, "[INFO] Success tts_prepare_sync");
return;
}
- client->before_state = client->current_state;
- client->current_state = TTS_STATE_READY;
- tts_core_notify_state_changed(client, client->before_state, client->current_state);
+ tts_core_set_current_state(client, TTS_STATE_READY);
SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
-
return;
}
if (0 != ret) {
//LCOV_EXCL_START
if (TTS_ERROR_INVALID_PARAMETER == ret && false == is_prepared) {
- client->current_state = TTS_STATE_CREATED;
+ tts_client_set_current_state(client, TTS_STATE_CREATED);
if (0 == tts_core_prepare_sync(client)) {
is_prepared = true;
SLOG(LOG_INFO, TAG_TTSC, "[INFO] Success tts_prepare_sync");
}
}
- client->before_state = client->current_state;
- client->current_state = TTS_STATE_READY;
- tts_core_notify_state_changed(client, client->before_state, client->current_state);
+ tts_core_set_current_state(client, TTS_STATE_READY);
SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
-
return TTS_ERROR_NONE;
}
//LCOV_EXCL_START
ret = tts_ipc_request_pause(client->uid);
if (0 != ret) {
if (TTS_ERROR_INVALID_PARAMETER == ret && false == is_prepared) {
- client->current_state = TTS_STATE_CREATED;
+ tts_client_set_current_state(client, TTS_STATE_CREATED);
if (0 == tts_core_prepare_sync(client)) {
is_prepared = true;
SLOG(LOG_INFO, TAG_TTSC, "[INFO] Success tts_prepare_sync");
return;
}
- client->before_state = client->current_state;
- client->current_state = TTS_STATE_PAUSED;
- tts_core_notify_state_changed(client, client->before_state, client->current_state);
+ tts_core_set_current_state(client, TTS_STATE_PAUSED);
SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
-
return;
}
if (0 != ret) {
//LCOV_EXCL_START
if (TTS_ERROR_INVALID_PARAMETER == ret && false == is_prepared) {
- client->current_state = TTS_STATE_CREATED;
+ tts_client_set_current_state(client, TTS_STATE_CREATED);
if (0 == tts_core_prepare_sync(client)) {
is_prepared = true;
SLOG(LOG_INFO, TAG_TTSC, "[INFO] Success tts_prepare_sync");
}
}
- client->before_state = client->current_state;
- client->current_state = TTS_STATE_PAUSED;
- tts_core_notify_state_changed(client, client->before_state, client->current_state);
+ tts_core_set_current_state(client, TTS_STATE_PAUSED);
SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
-
return TTS_ERROR_NONE;
}
if (0 != ret) {
//LCOV_EXCL_START
if (TTS_ERROR_INVALID_PARAMETER == ret && false == is_prepared) {
- client->current_state = TTS_STATE_CREATED;
+ tts_client_set_current_state(client, TTS_STATE_CREATED);
if (0 == tts_core_prepare_sync(client)) {
is_prepared = true;
SLOG(LOG_INFO, TAG_TTSC, "[INFO] Success tts_prepare_sync");
if (0 != ret) {
//LCOV_EXCL_START
if (TTS_ERROR_INVALID_PARAMETER == ret && false == is_prepared) {
- client->current_state = TTS_STATE_CREATED;
+ tts_client_set_current_state(client, TTS_STATE_CREATED);
if (0 == tts_core_prepare_sync(client)) {
is_prepared = true;
SLOG(LOG_INFO, TAG_TTSC, "[INFO] Success tts_prepare_sync");
ret = tts_ipc_request_add_pcm(client->uid, event, data, data_size, audio_type, rate);
if (0 != ret) {
if (TTS_ERROR_INVALID_PARAMETER == ret && false == is_prepared) {
- client->current_state = TTS_STATE_CREATED;
+ tts_client_set_current_state(client, TTS_STATE_CREATED);
if (0 == tts_core_prepare_sync(client)) {
is_prepared = true;
SLOG(LOG_INFO, TAG_TTSC, "[INFO] Success tts_prepare_sync");
ret = tts_ipc_request_play_pcm(client->uid);
if (0 != ret) {
if (TTS_ERROR_INVALID_PARAMETER == ret && false == is_prepared) {
- client->current_state = TTS_STATE_CREATED;
+ tts_client_set_current_state(client, TTS_STATE_CREATED);
if (0 == tts_core_prepare_sync(client)) {
is_prepared = true;
SLOG(LOG_INFO, TAG_TTSC, "[INFO] Success tts_prepare_sync");
}
}
- client->before_state = client->current_state;
- client->current_state = TTS_STATE_PLAYING;
- tts_core_notify_state_changed(client, client->before_state, client->current_state);
+ tts_core_set_current_state(client, TTS_STATE_PLAYING);
SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
-
return TTS_ERROR_NONE;
}
ret = tts_ipc_request_stop_pcm(client->uid);
if (0 != ret) {
if (TTS_ERROR_INVALID_PARAMETER == ret && false == is_prepared) {
- client->current_state = TTS_STATE_CREATED;
+ tts_client_set_current_state(client, TTS_STATE_CREATED);
if (0 == tts_core_prepare_sync(client)) {
is_prepared = true;
SLOG(LOG_INFO, TAG_TTSC, "[INFO] Success tts_prepare_sync");
}
}
- client->before_state = client->current_state;
- client->current_state = TTS_STATE_READY;
- tts_core_notify_state_changed(client, client->before_state, client->current_state);
+ tts_core_set_current_state(client, TTS_STATE_READY);
SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
-
return TTS_ERROR_NONE;
}
//LCOV_EXCL_STOP
return NULL;
}
+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";
+ }
+
+ return "Invalid state";
+}
+
static char* __get_engine_appid(int mode) {
char* appid = NULL;
appid = (char*)calloc(sizeof(char), 256);
void* data = tts_client_get_state_changed_user_data(client);
if (NULL != callback) {
- SLOG(LOG_DEBUG, TAG_TTSC, "Notify state changed");
+ SLOG(LOG_DEBUG, TAG_TTSC, "State changed data : before_state(%s) curret_state(%s)", __convert_state(before_state), __convert_state(current_state));
tts_client_use_callback(client);
callback(tts_client_get_handle(client), before_state, current_state, data);
tts_client_not_use_callback(client);
cnt++;
/* Checking thread is canceled or not */
- if (ecore_thread_check(thread)) {
+ if (ecore_thread_check(g_reprepare_thread)) {
SLOG(LOG_WARN, TAG_TTSC, "[WARNING] client thread is canceled. Exit");
return;
}
usleep(200000);
/* Checking thread is canceled or not */
- if (ecore_thread_check(thread)) {
+ if (ecore_thread_check(g_reprepare_thread)) {
SLOG(LOG_WARN, TAG_TTSC, "[WARNING] client thread is canceled. Exit");
return;
}
}
// TODO: make function duplicated block
- client->before_state = client->current_state;
- client->current_state = TTS_STATE_READY;
- __client_state_changed_cb(client, client->before_state, client->current_state);
+ tts_core_set_current_state(client, TTS_STATE_READY);
SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
return EINA_FALSE;
return TTS_ERROR_INVALID_PARAMETER;
}
- SLOG(LOG_DEBUG, TAG_TTSC, "State changed data : before_state(%d) curret_state(%d)", before_state, current_state);
__client_state_changed_cb(client, before_state, current_state);
return TTS_ERROR_NONE;
return TTS_ERROR_INVALID_PARAMETER;
}
- SLOG(LOG_DEBUG, TAG_TTSC, "State changed data : before_state(%d) curret_state(%d)", before_state, current_state);
- client->before_state = before_state;
- client->current_state = current_state;
-
SLOG(LOG_DEBUG, TAG_TTSC, "Notify state changed asynchronously");
+ tts_client_set_current_state(client, current_state);
if (NULL != client->notify_state_timer) {
ecore_timer_del(client->notify_state_timer);
}
return TTS_ERROR_NONE;
}
+int tts_core_set_current_state(tts_client_s* client, tts_state_e state)
+{
+ /* check handle */
+ if (NULL == client || false == tts_client_is_valid(client)) {
+ SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Handle is not valid.");
+ return TTS_ERROR_INVALID_PARAMETER;
+ }
+
+ tts_state_e before_state = TTS_STATE_CREATED;
+ if (0 != tts_client_get_current_state(client, &before_state)) {
+ SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to get before state.");
+ return TTS_ERROR_OPERATION_FAILED;
+ }
+
+ SLOG(LOG_DEBUG, TAG_TTSC, "State changed to (%s).", __convert_state(state));
+ tts_client_set_current_state(client, state);
+ __client_state_changed_cb(client, before_state, state);
+
+ 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);
if (0 != ret) {
//LCOV_EXCL_START
if (TTS_ERROR_INVALID_PARAMETER == ret && false == is_prepared) {
- client->current_state = TTS_STATE_CREATED;
+ tts_client_set_current_state(client, TTS_STATE_CREATED);
if (0 == tts_core_prepare_sync(client)) {
SLOG(LOG_INFO, TAG_TTSC, "[INFO] Success tts_prepare_sync");
is_prepared = true;
} while (0 != ret);
}
- // TODO: make function like tts_core_set_state()
- client->before_state = client->current_state;
- client->current_state = TTS_STATE_CREATED;
- __client_state_changed_cb(client, client->before_state, client->current_state);
- // TODO: make function like tts_core_set_state()
+ tts_core_set_current_state(client, TTS_STATE_CREATED);
return TTS_ERROR_NONE;
}
while (NULL != iter) {
tts_client_s* client = iter->data;
if (NULL != client && tts_client_is_valid(client->uid)) {
- client->current_state = TTS_STATE_CREATED;
+ tts_client_set_current_state(client, TTS_STATE_CREATED);
client->reason = TTS_ERROR_NONE;
}