#include "ttsd_config.h"
#include "ttsd_data.h"
-#include "ttsd_dbus.h"
-#include "ttsd_dbus_server.h"
#include "ttsd_ipc.h"
#include "ttsd_engine_agent.h"
#include "ttsd_main.h"
#include "ttsd_player.h"
+#include "ttsd_state.h"
#include "ttsd_server.h"
static GList *g_proc_list = NULL;
-static bool g_is_paused;
-
static bool g_is_terminated = false;
+static int g_activated_mode = 0;
/* Function definitions */
+static int __stop_and_send_ready_state(unsigned int uid)
+{
+ int ret = ttsd_server_stop(uid);
+ if (TTSD_ERROR_NONE != ret) {
+ SLOG(LOG_WARN, tts_tag(), "[Server ERROR] Fail to ttsd_server_stop() : uid(%u). ret(%d)", uid, ret);
+ return ret;
+ }
+
+ int pid = ttsd_data_get_pid(uid);
+ if (pid <= 0) {
+ SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to get pid. uid(%u)", uid);
+ return TTSD_ERROR_OPERATION_FAILED;
+ } else {
+ ttsdc_ipc_send_set_state_message(pid, uid, APP_STATE_READY);
+ }
+
+ return ret;
+}
+
static void __synthesis(unsigned int uid);
static Eina_Bool __wait_synthesis(void *data)
unsigned int uid = ttsd_data_get_current_playing();
if (uid > 0) {
- ttsd_synthesis_control_e synth_control = ttsd_get_synth_control();
+ ttsd_synthesis_control_e synth_control = ttsd_data_get_synth_control();
if (TTSD_SYNTHESIS_CONTROL_DOING == synth_control) {
return EINA_TRUE;
} else {
if (NULL == speak_data->lang || NULL == speak_data->text) {
SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Current data is NOT valid");
- ttsd_server_stop(uid);
- ttsdc_ipc_send_set_state_message(pid, uid, APP_STATE_READY);
+ __stop_and_send_ready_state(uid);
ttsd_data_destroy_speak_data(speak_data);
speak_data = NULL;
return;
SLOG(LOG_INFO, tts_tag(), "Credential : %s", credential);
SLOG(LOG_INFO, tts_tag(), "-----------------------------------------------------------");
- ttsd_set_synth_control(TTSD_SYNTHESIS_CONTROL_DOING);
+ ttsd_data_set_synth_control(TTSD_SYNTHESIS_CONTROL_DOING);
ret = ttsd_engine_start_synthesis(speak_data->lang, speak_data->vctype, speak_data->text, speak_data->speed, appid, credential, NULL);
if (TTSD_ERROR_NONE != ret) {
SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] * FAIL to start SYNTHESIS !!!! * ");
- ttsd_set_synth_control(TTSD_SYNTHESIS_CONTROL_DONE);
- ttsd_server_stop(uid);
-
- int pid = ttsd_data_get_pid(uid);
- if (pid <= 0) {
- SLOG(LOG_WARN, tts_tag(), "[Server WARNING] Fail to send set_state_message. uid(%u)", uid);
- } else {
- ttsdc_ipc_send_set_state_message(pid, uid, APP_STATE_READY);
- }
+ ttsd_data_set_synth_control(TTSD_SYNTHESIS_CONTROL_DONE);
+ __stop_and_send_ready_state(uid);
} else {
g_wait_timer = ecore_timer_add(0.05, __wait_synthesis, (void*)credential);
}
+ if (ttsd_data_get_synth_control() == TTSD_SYNTHESIS_CONTROL_DOING && ttsd_state_get_state() == TTSD_STATE_READY) {
+ ttsd_state_set_state(TTSD_STATE_SYNTHESIZING);
+ }
+
free(credential);
credential = NULL;
ttsd_data_destroy_speak_data(speak_data);
SLOG(LOG_ERROR, tts_tag(), "[SERVER ERROR] Error msg from engine, pid(%d), uid(%u), uttid(%d), error(%d), msg(%s)", tmp_pid, uid, uttid, error, (NULL == msg ? "NULL" : msg));
- ttsd_set_synth_control(TTSD_SYNTHESIS_CONTROL_EXPIRED);
-
- if (0 != ttsd_player_clear(uid))
- SLOG(LOG_WARN, tts_tag(), "[Server] Fail to ttsd_player_clear()");
+ ttsd_data_set_synth_control(TTSD_SYNTHESIS_CONTROL_EXPIRED);
if (0 != ttsd_data_clear_data(uid))
SLOG(LOG_WARN, tts_tag(), "[Server] Fail to ttsd_data_clear_data()");
int uttid = g_utt.uttid;
if (false == ttsd_data_is_uttid_valid(uid, uttid)) {
- ttsd_set_synth_control(TTSD_SYNTHESIS_CONTROL_DONE);
+ ttsd_data_set_synth_control(TTSD_SYNTHESIS_CONTROL_DONE);
SLOG(LOG_ERROR, tts_tag(), "[SERVER ERROR] uttid is NOT valid !!!! - uid(%u), uttid(%d)", uid, uttid);
SLOG(LOG_DEBUG, tts_tag(), "@@@");
return TTSD_ERROR_INVALID_PARAMETER;
if (TTSE_RESULT_EVENT_START > event || TTSE_RESULT_EVENT_FINISH < event) {
SLOG(LOG_DEBUG, tts_tag(), "[SERVER] Event : TTSE_RESULT_EVENT_ERROR");
- ttsd_set_synth_control(TTSD_SYNTHESIS_CONTROL_EXPIRED);
+ ttsd_data_set_synth_control(TTSD_SYNTHESIS_CONTROL_EXPIRED);
return TTSD_ERROR_INVALID_PARAMETER;
}
if (rate <= 0 || audio_type < 0 || audio_type > TTSE_AUDIO_TYPE_MAX) {
- ttsd_set_synth_control(TTSD_SYNTHESIS_CONTROL_DONE);
+ ttsd_data_set_synth_control(TTSD_SYNTHESIS_CONTROL_DONE);
SLOG(LOG_ERROR, tts_tag(), "[SERVER ERROR] audio data is invalid");
SLOG(LOG_DEBUG, tts_tag(), "@@@");
return TTSD_ERROR_INVALID_PARAMETER;
}
/* check the current state */
- app_tts_state_e state;
- if (0 > ttsd_data_get_client_state(uid, &state)) {
- ttsd_set_synth_control(TTSD_SYNTHESIS_CONTROL_DONE);
+ app_tts_state_e state = ttsd_data_get_client_state(uid);
+ if (APP_STATE_NONE == state) {
+ ttsd_data_set_synth_control(TTSD_SYNTHESIS_CONTROL_DONE);
SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] uid is not valid");
return TTSD_ERROR_INVALID_PARAMETER;
}
SLOG(LOG_INFO, tts_tag(), "[Server] uid(%u), current state(%d)", uid, state);
if (APP_STATE_CREATED == state || APP_STATE_READY == state) {
- ttsd_set_synth_control(TTSD_SYNTHESIS_CONTROL_DONE);
+ ttsd_data_set_synth_control(TTSD_SYNTHESIS_CONTROL_DONE);
SLOG(LOG_WARN, tts_tag(), "[SERVER WARNING] Current state is %d. The synthesized result is ignored.", state);
return TTSD_ERROR_NONE;
}
}
if (event == TTSE_RESULT_EVENT_FINISH) {
- ttsd_set_synth_control(TTSD_SYNTHESIS_CONTROL_DONE);
+ ttsd_data_set_synth_control(TTSD_SYNTHESIS_CONTROL_DONE);
}
return TTSD_ERROR_NONE;
}
-bool __get_client_cb(int pid, unsigned int uid, app_tts_state_e state, void* user_data)
+static bool __get_client_cb(int pid, unsigned int uid, app_tts_state_e state, void* user_data)
{
+ if (0 > ttsd_data_is_client(uid)) {
+ SLOG(LOG_ERROR, tts_tag(), "[Server] Client(%d) is not valid.", uid);
+ ttsd_data_delete_client(uid);
+ return true;
+ }
+
/* clear client data */
ttsd_data_clear_data(uid);
if (APP_STATE_READY != state) {
ttsd_data_set_client_state(uid, APP_STATE_READY);
-
- /* send message */
- if (0 != ttsdc_ipc_send_set_state_message(pid, uid, APP_STATE_READY)) {
- /* remove client */
- ttsd_data_delete_client(uid);
- }
+ ttsdc_ipc_send_set_state_message(pid, uid, APP_STATE_READY);
}
return true;
}
-void __config_changed_cb(tts_config_type_e type, const char* str_param, int int_param, double double_param)
+static void __stop_all_client()
+{
+ SLOG(LOG_INFO, tts_tag(), "[Server] Send to stop all requests");
+
+ ttsd_engine_cancel_synthesis();
+ ttsd_data_set_synth_control(TTSD_SYNTHESIS_CONTROL_EXPIRED);
+
+ /* stop all player */
+ ttsd_player_all_stop();
+
+ /* send interrupt message to all clients */
+ ttsd_data_foreach_clients(__get_client_cb, NULL);
+}
+
+static void __config_changed_cb(tts_config_type_e type, const char* str_param, int int_param, double double_param)
{
switch (type) {
case TTS_CONFIG_TYPE_ENGINE:
return;
}
- /* stop all player */
- ttsd_player_all_stop();
-
- /* send interrupt message to all clients */
- ttsd_data_foreach_clients(__get_client_cb, NULL);
-
- ttsd_engine_cancel_synthesis();
-
+ __stop_all_client();
break;
}
return;
}
-int ttsd_send_all_stop()
+static void __read_proc()
{
- SLOG(LOG_INFO, tts_tag(), "[Server] Send to stop all requests");
+ DIR *dp = NULL;
+ struct dirent *dirp = NULL;
+ int tmp;
- /* stop all player */
- ttsd_player_all_stop();
+ GList *iter = NULL;
+ if (0 < g_list_length(g_proc_list)) {
+ iter = g_list_first(g_proc_list);
+ while (NULL != iter) {
+ g_proc_list = g_list_remove_link(g_proc_list, iter);
+ g_list_free(iter);
+ iter = g_list_first(g_proc_list);
+ }
+ }
- /* send interrupt message to all clients */
- ttsd_data_foreach_clients(__get_client_cb, NULL);
+ dp = opendir("/proc");
+ if (NULL == dp) {
+ SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to open proc");
+ } else {
+ do {
+ dirp = readdir(dp);
- return TTSD_ERROR_NONE;
+ if (NULL != dirp) {
+ tmp = atoi(dirp->d_name);
+ if (0 >= tmp) continue;
+ g_proc_list = g_list_append(g_proc_list, GINT_TO_POINTER(tmp));
+ }
+ } while (NULL != dirp);
+ closedir(dp);
+ }
+ return;
+}
+
+bool __get_client_for_clean_up(int pid, unsigned int uid, app_tts_state_e state, void* user_data)
+{
+ bool exist = false;
+ int i = 0;
+
+ GList *iter = NULL;
+ for (i = 0; i < g_list_length(g_proc_list); i++) {
+ iter = g_list_nth(g_proc_list, i);
+ if (NULL != iter) {
+ if (pid == GPOINTER_TO_INT(iter->data)) {
+ SLOG(LOG_DEBUG, tts_tag(), "uid (%u) is running", uid);
+ exist = true;
+ break;
+ }
+ }
+ }
+
+ if (false == exist) {
+ SLOG(LOG_ERROR, tts_tag(), "uid (%u) should be removed", uid);
+ ttsd_server_finalize(uid);
+ }
+
+ return true;
+}
+
+static Eina_Bool __cleanup_client(void *data)
+{
+ SLOG(LOG_DEBUG, tts_tag(), "@@@ CLEAN UP CLIENT START");
+ __read_proc();
+
+ if (0 < ttsd_data_get_client_count()) {
+ ttsd_data_foreach_clients(__get_client_for_clean_up, NULL);
+ } else {
+ if (NULL == g_quit_loop_timer) {
+ SLOG(LOG_INFO, tts_tag(), "[Server] Add a timer __quit_ecore_loop");
+ g_quit_loop_timer = ecore_timer_add(0, __quit_ecore_loop, NULL);
+ }
+ SLOG(LOG_ERROR, tts_tag(), "[Server] Deleted timer");
+ g_check_client_timer = NULL;
+ return EINA_FALSE;
+ }
+
+ SLOG(LOG_DEBUG, tts_tag(), "@@@");
+
+ return EINA_TRUE;
}
/*
SLOG(LOG_ERROR, tts_tag(), "[Server WARNING] Fail to initialize config.");
}
+ if (TTSD_ERROR_NONE != ttsd_state_initialize(NULL)) {
+ SLOG(LOG_ERROR, tts_tag(), "[Server WARNING] Fail to initialize state.");
+ }
+
/* player init */
if (ttsd_player_init()) {
SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to initialize player init.");
}
/* Engine Agent initialize */
- if (0 != ttsd_engine_agent_init()) {
+ if (TTSD_ERROR_NONE != ttsd_engine_agent_init(callback)) {
SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to engine agent initialize.");
return TTSD_ERROR_OPERATION_FAILED;
}
- /* set current engine */
- //if (0 != ttsd_engine_agent_initialize_current_engine(callback)) {
- // SLOG(LOG_WARN, tts_tag(), "[Server WARNING] No Engine !!!" );
- // g_is_engine = false;
- //} else
- // g_is_engine = true;
-
- if (0 != ttsd_engine_agent_load_current_engine(callback)) {
- SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to load current engine");
- return TTSD_ERROR_OPERATION_FAILED;
- }
-
- ttsd_set_synth_control(TTSD_SYNTHESIS_CONTROL_EXPIRED);
-
-// if (TTSD_MODE_SCREEN_READER == ttsd_get_mode()) {
- ttsd_config_set_screen_reader_callback(__screen_reader_changed_cb);
-// }
+ ttsd_data_set_synth_control(TTSD_SYNTHESIS_CONTROL_EXPIRED);
+ ttsd_config_set_screen_reader_callback(__screen_reader_changed_cb);
- g_check_client_timer = ecore_timer_add(CLIENT_CLEAN_UP_TIME, ttsd_cleanup_client, NULL);
+ g_check_client_timer = ecore_timer_add(CLIENT_CLEAN_UP_TIME, __cleanup_client, NULL);
if (NULL == g_check_client_timer) {
SLOG(LOG_WARN, tts_tag(), "[WARNING] Fail to create timer");
}
+ g_activated_mode = 0;
+
return TTSD_ERROR_NONE;
}
}
ttsd_config_finalize();
+ ttsd_state_finalize();
int ret = TTSD_ERROR_NONE;
ret = ttsd_player_release();
return TTSD_ERROR_NONE;
}
-int ttsd_server_initialize(int pid, unsigned int uid, tts_ipc_method_e method, bool* credential_needed)
+static void __set_and_notify_activated_mode()
{
- SLOG(LOG_INFO, tts_tag(), "[Server] Server initialize");
-
- if (-1 != ttsd_data_is_client(uid)) {
- SLOG(LOG_WARN, tts_tag(), "[Server WARNING] Uid has already been registered");
- return TTSD_ERROR_NONE;
+ int activated_mode = ttsd_data_get_activated_mode();
+ if (g_activated_mode == activated_mode) {
+ return;
}
- if (0 != ttsd_engine_agent_is_credential_needed(uid, credential_needed)) {
- SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to get credential necessity");
- return TTSD_ERROR_OPERATION_FAILED;
- }
+ SLOG(LOG_INFO, tts_tag(), "[Server] Activated mode is changed from(%d) to (%d)", g_activated_mode, activated_mode);
- if (true == *credential_needed) {
- char* appid = NULL;
- if (0 != app_manager_get_app_id(pid, &appid)) {
- SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to get app id, pid(%d)", pid);
- }
- bool is_agreed = false;
- if (0 != ttsd_engine_check_app_agreed(appid, &is_agreed)) {
- SLOG(LOG_ERROR, tts_tag(), "Server ERROR] Fail to check app agreed");
- if (!appid)
- free(appid);
- return TTSD_ERROR_OPERATION_FAILED;
- }
- if (!appid)
- free(appid);
-
- if (false == is_agreed) {
- SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] App is not agreed");
- return TTSD_ERROR_PERMISSION_DENIED;
- }
+ g_activated_mode = activated_mode;
+ int ret = ttsd_engine_notify_activated_mode_changed(g_activated_mode);
+ if (TTSD_ERROR_NONE != ret) {
+ SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to notify activated mode changed event.(%d)", ret);
}
+}
- if (0 != ttsd_data_new_client(pid, uid)) {
- SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to add client info");
- return TTSD_ERROR_OPERATION_FAILED;
+static int __check_app_agreed(int pid, unsigned int uid, bool credential_needed)
+{
+ if (false == credential_needed) {
+ return TTSD_ERROR_NONE;
}
- if (0 != ttsd_data_set_ipc_method(uid, method)) {
- SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to set ipc method");
- return TTSD_ERROR_OPERATION_FAILED;
+ char* appid = NULL;
+ if (APP_MANAGER_ERROR_NONE != app_manager_get_app_id(pid, &appid)) {
+ SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to get app id, pid(%d)", pid);
}
- if (0 != ttsd_player_create_instance(uid)) {
- SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to create player");
+ bool is_agreed = false;
+ int ret = ttsd_engine_check_app_agreed(appid, &is_agreed);
+ free(appid);
+ appid = NULL;
+
+ if (TTSD_ERROR_NONE != ret) {
+ SLOG(LOG_ERROR, tts_tag(), "Server ERROR] Fail to check app agreed");
return TTSD_ERROR_OPERATION_FAILED;
}
- g_file_num = 0;
- g_min_latency = 10000.0;
- g_max_latency = 0.0;
- g_avg_latency = 0.0;
-
+ if (false == is_agreed) {
+ SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] App is not agreed");
+ return TTSD_ERROR_PERMISSION_DENIED;
+ }
return TTSD_ERROR_NONE;
}
-static void __read_proc()
+int ttsd_server_initialize(int pid, unsigned int uid, ttsd_mode_e mode, tts_ipc_method_e method, bool* credential_needed)
{
- DIR *dp = NULL;
- struct dirent *dirp = NULL;
- int tmp;
-
- GList *iter = NULL;
- if (0 < g_list_length(g_proc_list)) {
- iter = g_list_first(g_proc_list);
- while (NULL != iter) {
- g_proc_list = g_list_remove_link(g_proc_list, iter);
- g_list_free(iter);
- iter = g_list_first(g_proc_list);
- }
- }
-
- dp = opendir("/proc");
- if (NULL == dp) {
- SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to open proc");
- } else {
- do {
- dirp = readdir(dp);
+ SLOG(LOG_INFO, tts_tag(), "[Server] Server initialize");
- if (NULL != dirp) {
- tmp = atoi(dirp->d_name);
- if (0 >= tmp) continue;
- g_proc_list = g_list_append(g_proc_list, GINT_TO_POINTER(tmp));
- }
- } while (NULL != dirp);
- closedir(dp);
+ if (-1 != ttsd_data_is_client(uid)) {
+ SLOG(LOG_WARN, tts_tag(), "[Server WARNING] Uid has already been registered");
+ return TTSD_ERROR_NONE;
}
- return;
-}
-bool __get_client_for_clean_up(int pid, unsigned int uid, app_tts_state_e state, void* user_data)
-{
- bool exist = false;
- int i = 0;
-
- GList *iter = NULL;
- for (i = 0; i < g_list_length(g_proc_list); i++) {
- iter = g_list_nth(g_proc_list, i);
- if (NULL != iter) {
- if (pid == GPOINTER_TO_INT(iter->data)) {
- SLOG(LOG_DEBUG, tts_tag(), "uid (%u) is running", uid);
- exist = true;
- break;
- }
- }
+ if (TTSD_ERROR_NONE != ttsd_data_new_client(pid, uid, mode, method)) {
+ SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to add client info");
+ return TTSD_ERROR_OPERATION_FAILED;
}
- if (false == exist) {
- SLOG(LOG_ERROR, tts_tag(), "uid (%u) should be removed", uid);
- ttsd_server_finalize(uid);
- }
+ __set_and_notify_activated_mode();
- return true;
-#if 0
- char appid[1024] = {0, };
- if (0 != aul_app_get_appid_bypid(pid, appid, sizeof(appid) - 1)) {
- SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to get app id");
+ if (TTSD_ERROR_NONE != ttsd_engine_agent_load_current_engine()) {
+ SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to load current engine");
+ ttsd_data_delete_client(uid);
+ return TTSD_ERROR_OPERATION_FAILED;
}
- if (0 < strlen(appid)) {
- SLOG(LOG_DEBUG, tts_tag(), "[%d] is running app - %s", pid, appid);
- } else {
- SLOG(LOG_DEBUG, tts_tag(), "[%d] is daemon or no_running app", pid);
-
- int result = 1;
- result = ttsdc_send_hello(pid, uid);
-
- if (0 == result) {
- SLOG(LOG_DEBUG, tts_tag(), "[Server] uid(%u) should be removed.", uid);
- ttsd_server_finalize(uid);
- } else if (-1 == result) {
- SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Hello result has error");
- }
+ bool is_needed = false;
+ if (TTSD_ERROR_NONE != ttsd_engine_agent_is_credential_needed(uid, &is_needed)) {
+ SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to get credential necessity");
+ ttsd_data_delete_client(uid);
+ return TTSD_ERROR_OPERATION_FAILED;
}
- return true;
-#endif
-}
-
-Eina_Bool ttsd_cleanup_client(void *data)
-{
- SLOG(LOG_DEBUG, tts_tag(), "@@@ CLEAN UP CLIENT START");
- __read_proc();
-
- if (0 < ttsd_data_get_client_count()) {
- ttsd_data_foreach_clients(__get_client_for_clean_up, NULL);
- } else {
- if (NULL == g_quit_loop_timer) {
- SLOG(LOG_INFO, tts_tag(), "[Server] Add a timer __quit_ecore_loop");
- g_quit_loop_timer = ecore_timer_add(0, __quit_ecore_loop, NULL);
- }
- SLOG(LOG_ERROR, tts_tag(), "[Server] Deleted timer");
- g_check_client_timer = NULL;
- return EINA_FALSE;
+ int ret = __check_app_agreed(pid, uid, is_needed);
+ if (TTSD_ERROR_NONE != ret) {
+ SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Checking credential is finished(%d)", ret);
+ ttsd_data_delete_client(uid);
+ return ret;
}
- SLOG(LOG_DEBUG, tts_tag(), "@@@");
+ *credential_needed = is_needed;
- return EINA_TRUE;
+ return TTSD_ERROR_NONE;
}
void __used_voice_cb(const char* lang, int type)
SLOG(LOG_INFO, tts_tag(), "[Server] Server finalize");
SLOG(LOG_INFO, tts_tag(), "[Server] File num(%d), Avg Latency(%lf), Min(%lf), Max(%lf)", g_file_num, (g_avg_latency / (double)g_file_num), g_min_latency, g_max_latency);
- app_tts_state_e state;
- if (0 > ttsd_data_get_client_state(uid, &state)) {
+ if (0 > ttsd_data_is_client(uid)) {
SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] ttsd_server_finalize : uid is not valid");
}
- ttsd_server_stop(uid);
- ttsd_player_clear(uid);
-
- ttsd_player_destroy_instance(uid);
+ int ret = ttsd_server_stop(uid);
+ if (TTSD_ERROR_NONE != ret) {
+ SLOG(LOG_ERROR, tts_tag(), "[ERROR] TTS server top(%u) fail (%d/%s) <<<<<", uid, ret, get_error_message(ret));
+ }
/* Need to unload voice when used voice is unregistered */
if (0 != ttsd_data_reset_used_voice(uid, __used_voice_cb)) {
}
ttsd_data_delete_client(uid);
+ __set_and_notify_activated_mode();
/* unload engine, if ref count of client is 0 */
if (0 == ttsd_data_get_client_count()) {
return TTSD_ERROR_NONE;
}
-int ttsd_server_set_mode(unsigned int uid, ttsd_mode_e mode)
-{
- app_tts_state_e state;
- if (0 > ttsd_data_get_client_state(uid, &state)) {
- SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] uid(%u) is NOT valid", uid);
- return TTSD_ERROR_INVALID_PARAMETER;
- }
-
- if (APP_STATE_READY != state) {
- SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Current state(%d) is NOT 'READY'", uid);
- return TTSD_ERROR_INVALID_STATE;
- }
-
- int ret = ttsd_data_set_mode(uid, mode);
- if (0 != ret) {
- SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to set mode : ret(%d)", ret);
- } else {
- SLOG(LOG_DEBUG, tts_tag(), "[Server] Set mode. uid(%u), mode(%d)", uid, mode);
- }
-
- return ret;
-}
-
static bool __is_connected_to_network()
{
/* Check network */
return true;
}
-int ttsd_server_add_queue(unsigned int uid, const char* text, const char* lang, int voice_type, int speed, int utt_id, const char* credential)
+int ttsd_server_add_text(unsigned int uid, const char* text, const char* lang, int voice_type, int speed, int utt_id, const char* credential)
{
- app_tts_state_e state;
- if (0 > ttsd_data_get_client_state(uid, &state)) {
- SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] ttsd_server_add_queue : uid is not valid");
+ app_tts_state_e state = ttsd_data_get_client_state(uid);
+ if (APP_STATE_NONE == state) {
+ SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] ttsd_server_add_text : uid is not valid");
return TTSD_ERROR_INVALID_PARAMETER;
}
ttsd_data_set_credential(uid, credential);
/* Check whether tts-engine is running or not */
- ttsd_synthesis_control_e synth_control = ttsd_get_synth_control();
+ ttsd_synthesis_control_e synth_control = ttsd_data_get_synth_control();
SLOG(LOG_INFO, tts_tag(), "[Server INFO] synth_control(%d)", synth_control);
if (TTSD_SYNTHESIS_CONTROL_DOING == synth_control) {
SLOG(LOG_WARN, tts_tag(), "[Server WARNING] Engine has already been running.");
return TTSD_ERROR_NONE;
}
-static int __pause_client(unsigned int uid)
+static int __interrupt_player_by_policy(unsigned int request_app_uid)
{
- int ret = ttsd_data_set_client_state(uid, APP_STATE_PAUSED);
- if (TTSD_ERROR_NONE != ret) {
- SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail set pause state() : ret(%d)", ret);
- return TTSD_ERROR_OPERATION_FAILED;
+ unsigned int playing_app_uid = ttsd_data_get_current_playing();
+ if (0 > ttsd_data_is_client(playing_app_uid)) {
+ SLOG(LOG_INFO, tts_tag(), "[Server] There is no app which is in 'Play' state");
+ return TTSD_ERROR_NONE;
}
- ret = ttsd_player_pause(uid);
- if (TTSD_ERROR_NONE != ret) {
- SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail player_pause() : ret(%d)", ret);
- return TTSD_ERROR_OPERATION_FAILED;
+ if (request_app_uid == playing_app_uid) {
+ SLOG(LOG_WARN, tts_tag(), "[Server] This is played uid. Skip policy behavior");
+ return TTSD_ERROR_NONE;
}
- return TTSD_ERROR_NONE;
-}
-
-void __send_interrupt_client(unsigned int uid)
-{
- SLOG(LOG_INFO, tts_tag(), "[Server] Send new state by policy. uid(%u)", uid);
- int pid = ttsd_data_get_pid(uid);
- if (pid <= 0) {
- SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to get pid. uid(%u), pid(%d)", uid, pid);
- return;
- }
+ ttsd_mode_e request_app_mode = ttsd_data_get_mode(request_app_uid);
+ ttsd_mode_e playing_app_mode = ttsd_data_get_mode(playing_app_uid);
+ switch (playing_app_mode) {
+ case TTSD_MODE_DEFAULT:
+ case TTSD_MODE_NOTIFICATION:
+ case TTSD_MODE_SCREEN_READER:
+ SLOG(LOG_DEBUG, tts_tag(), "[Server] Played client(%u) will be interrupted into 'Stop' state", playing_app_uid);
+ __stop_and_send_ready_state(playing_app_uid);
+ break;
- app_tts_state_e state = APP_STATE_CREATED;
+ case TTSD_MODE_INTERRUPT:
+ if (TTSD_MODE_INTERRUPT != request_app_mode) {
+ SLOG(LOG_WARN, tts_tag(), "[Server] Current play mode is Interrupt. Default, Screen reader, and Noti are prohibitted.");
+ return TTSD_ERROR_AUDIO_POLICY_BLOCKED;
+ }
- if (0 != ttsd_data_get_client_state(uid, &state)) {
- SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to get state. uid(%u), pid(%d)", uid, pid);
- return;
+ SLOG(LOG_DEBUG, tts_tag(), "[Server] Played client(%u) will be interrupted into 'Stop' state", playing_app_uid);
+ __stop_and_send_ready_state(playing_app_uid);
+ break;
}
- ttsdc_ipc_send_set_state_message(pid, uid, state);
- SLOG(LOG_INFO, tts_tag(), "[Server] Finish to send new state by policy. uid(%u)", uid);
- return;
+ return TTSD_ERROR_NONE;
}
int ttsd_server_play(unsigned int uid, const char* credential)
{
- app_tts_state_e state;
- if (0 > ttsd_data_get_client_state(uid, &state)) {
+ app_tts_state_e state = ttsd_data_get_client_state(uid);
+ if (APP_STATE_NONE == state) {
SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] uid(%u) is NOT valid", uid);
return TTSD_ERROR_INVALID_PARAMETER;
}
}
}
- /* check the current playback focus */
- if (TTSD_MODE_INTERRUPT != ttsd_get_mode() && ttsd_player_does_interrupt_have_playback_focus()) {
- SLOG(LOG_WARN, tts_tag(), "[Server WARNING] Current playback focus is set on Interrupt mode. Cannot play default, screen reader, and noti modes.");
- ttsd_data_clear_data(uid);
- return TTSD_ERROR_AUDIO_POLICY_BLOCKED;
- }
-
- unsigned int current_uid = ttsd_data_get_current_playing();
- SLOG(LOG_INFO, tts_tag(), "[Server] playing uid (%u)", current_uid);
-
- if (uid != current_uid && 0 <= ttsd_data_is_client(current_uid)) {
- if (TTSD_MODE_DEFAULT != ttsd_data_get_mode(current_uid)) {
- /* Send interrupt message */
- SLOG(LOG_DEBUG, tts_tag(), "[Server] Old uid(%u) will be interrupted into 'Stop' state ", current_uid);
-
- /* stop player */
- if (0 != ttsd_server_stop(current_uid)) {
- SLOG(LOG_WARN, tts_tag(), "[Server ERROR] Fail to stop server and player : uid (%u)", current_uid);
- }
- } else {
- /* Default mode policy of interrupt is "Pause" */
-
- /* Send interrupt message */
- SLOG(LOG_DEBUG, tts_tag(), "[Server] Old uid(%u) will be interrupted into 'Pause' state ", current_uid);
-
- /* pause player */
- if (0 != __pause_client(current_uid)) {
- SLOG(LOG_WARN, tts_tag(), "[Server ERROR] Fail to ttsd_server_pause() : uid (%u)", current_uid);
- }
- }
-
- __send_interrupt_client(current_uid);
+ int ret = __interrupt_player_by_policy(uid);
+ if (TTSD_ERROR_NONE != ret) {
+ SLOG(LOG_WARN, tts_tag(), "[Server] Current play mode is Interrupt. Cannot play default, screen reader, and noti modes.");
+ return ret;
}
/* Change current play */
return TTSD_ERROR_OPERATION_FAILED;
}
- int ret = TTSD_ERROR_NONE;
- if (APP_STATE_PAUSED == state) {
- SLOG(LOG_DEBUG, tts_tag(), "[Server] uid(%u) is 'Pause' state : resume player", uid);
- g_is_paused = false;
- ret = ttsd_player_resume(uid);
- } else {
- SLOG(LOG_DEBUG, tts_tag(), "[Server] Play player. uid(%u)", uid);
- ret = ttsd_player_play(uid);
- }
-
+ SLOG(LOG_DEBUG, tts_tag(), "[Server] Play player. uid(%u)", uid);
+ ret = ttsd_player_play(uid);
if (TTSD_ERROR_NONE != ret) {
SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to play sound : uid(%u)", uid);
ttsd_data_set_client_state(uid, state);
/* Check whether tts-engine is running or not */
clock_gettime(CLOCK_MONOTONIC_RAW, &g_request_playing);
- ttsd_synthesis_control_e synth_control = ttsd_get_synth_control();
+ ttsd_synthesis_control_e synth_control = ttsd_data_get_synth_control();
SLOG(LOG_INFO, tts_tag(), "[Server INFO] synth_control(%d)", synth_control);
if (TTSD_SYNTHESIS_CONTROL_DOING == synth_control) {
SLOG(LOG_WARN, tts_tag(), "[Server WARNING] Engine has already been running.");
} else {
__synthesis(uid);
}
+ ttsd_data_set_play_type(uid, TTS_APP_PLAY_TYPE_SYNTH);
return TTSD_ERROR_NONE;
}
+static void __stop_engine_synthesis(unsigned int uid)
+{
+ ttsd_synthesis_control_e synth_control = ttsd_data_get_synth_control();
+ SLOG(LOG_INFO, tts_tag(), "[Server INFO] synth_control(%d)", synth_control);
+
+ if (TTSD_SYNTHESIS_CONTROL_DOING == synth_control && uid == ttsd_data_get_current_playing()) {
+ SLOG(LOG_DEBUG, tts_tag(), "[Server] TTS-engine is running");
+
+ int ret = ttsd_engine_cancel_synthesis();
+ if (TTSD_ERROR_NONE != ret)
+ SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to cancel synthesis : ret(%d)", ret);
+ }
+
+ ttsd_data_set_synth_control(TTSD_SYNTHESIS_CONTROL_EXPIRED);
+}
+
int ttsd_server_stop(unsigned int uid)
{
- app_tts_state_e state;
- if (0 > ttsd_data_get_client_state(uid, &state)) {
+ app_tts_state_e state = ttsd_data_get_client_state(uid);
+ if (APP_STATE_NONE == state) {
SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] uid is not valid");
return TTSD_ERROR_INVALID_PARAMETER;
}
SLOG(LOG_INFO, tts_tag(), "[Server] server stop, uid(%d), state(%d)", uid, state);
if (APP_STATE_PLAYING == state || APP_STATE_PAUSED == state) {
- ttsd_synthesis_control_e synth_control = ttsd_get_synth_control();
- SLOG(LOG_INFO, tts_tag(), "[Server INFO] synth_control(%d)", synth_control);
- if (TTSD_SYNTHESIS_CONTROL_DOING == synth_control && uid == ttsd_data_get_current_playing()) {
- SLOG(LOG_DEBUG, tts_tag(), "[Server] TTS-engine is running");
-
- int ret = ttsd_engine_cancel_synthesis();
- if (TTSD_ERROR_NONE != ret)
- SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to cancel synthesis : ret(%d)", ret);
+ if (TTS_APP_PLAY_TYPE_SYNTH == ttsd_data_get_play_type(uid)) {
+ __stop_engine_synthesis(uid);
}
- ttsd_set_synth_control(TTSD_SYNTHESIS_CONTROL_EXPIRED);
/* stop player */
ttsd_data_set_client_state(uid, APP_STATE_READY);
/* Reset all data */
ttsd_data_clear_data(uid);
- g_is_paused = false;
return TTSD_ERROR_NONE;
}
-int ttsd_server_pause(unsigned int uid, int* utt_id)
+int ttsd_server_pause(unsigned int uid)
{
- app_tts_state_e state;
- if (0 > ttsd_data_get_client_state(uid, &state)) {
+ app_tts_state_e state = ttsd_data_get_client_state(uid);
+ if (APP_STATE_NONE == state) {
SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] ttsd_server_pause : uid is not valid");
return TTSD_ERROR_INVALID_PARAMETER;
}
return TTSD_ERROR_INVALID_STATE;
}
- g_is_paused = true;
-
- *utt_id = g_utt.uttid;
- SLOG(LOG_INFO, tts_tag(), "[Server] server pause, uid(%u), g_uid(%u), utt_id(%d)", uid, g_utt.uid, *utt_id);
+ int ret = ttsd_data_set_client_state(uid, APP_STATE_PAUSED);
+ if (TTSD_ERROR_NONE != ret) {
+ SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail set pause state() : ret(%d)", ret);
+ return TTSD_ERROR_OPERATION_FAILED;
+ }
- int ret = __pause_client(uid);
+ ret = ttsd_player_pause(uid);
if (TTSD_ERROR_NONE != ret) {
- SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to pause player : ret(%d)", ret);
+ SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail player_pause() : ret(%d)", ret);
return TTSD_ERROR_OPERATION_FAILED;
}
int ttsd_server_get_support_voices(unsigned int uid, GList** voice_list)
{
- app_tts_state_e state;
- if (0 > ttsd_data_get_client_state(uid, &state)) {
+ if (0 > ttsd_data_is_client(uid)) {
SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] uid is not valid");
return TTSD_ERROR_INVALID_PARAMETER;
}
int ttsd_server_get_current_voice(unsigned int uid, char** language, int* voice_type)
{
- app_tts_state_e state;
- if (0 > ttsd_data_get_client_state(uid, &state)) {
+ if (0 > ttsd_data_is_client(uid)) {
SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] ttsd_server_get_current_voice : uid is not valid");
return TTSD_ERROR_INVALID_PARAMETER;
}
int ttsd_server_set_private_data(unsigned int uid, const char* key, const char* data)
{
- app_tts_state_e state;
- if (0 > ttsd_data_get_client_state(uid, &state)) {
+ app_tts_state_e state = ttsd_data_get_client_state(uid);
+ if (APP_STATE_NONE == state) {
SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] uid(%u) is NOT valid", uid);
return TTSD_ERROR_INVALID_PARAMETER;
}
int ttsd_server_get_private_data(unsigned int uid, const char* key, char** data)
{
- app_tts_state_e state;
- if (0 > ttsd_data_get_client_state(uid, &state)) {
+ app_tts_state_e state = ttsd_data_get_client_state(uid);
+ if (APP_STATE_NONE == state) {
SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] uid(%u) is NOT valid", uid);
return TTSD_ERROR_INVALID_PARAMETER;
}
return TTSD_ERROR_INVALID_STATE;
}
- int ret = ttsd_engine_get_private_data(key, data);
+ char* temp_data = NULL;
+ int ret = ttsd_engine_get_private_data(key, &temp_data);
if (0 != ret) {
SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to get private data : ret(%d)", ret);
} else {
SLOG(LOG_DEBUG, tts_tag(), "[Server] Get private data, key(%s), data(%s)", key, *data);
}
+ if (NULL == temp_data) {
+ temp_data = strdup("NULL");
+ }
+ *data = temp_data;
+
return ret;
}
return ret;
}
+int ttsd_get_activated_mode(int* activated_mode)
+{
+ if (NULL == activated_mode) {
+ return TTSD_ERROR_INVALID_PARAMETER;
+ }
+
+ *activated_mode = ttsd_data_get_activated_mode();
+ return TTSD_ERROR_NONE;
+}
+
+int ttsd_set_activated_mode_changed_cb(ttse_activated_mode_changed_cb callback)
+{
+ int ret = ttsd_engine_agent_set_activated_mode_changed_cb(callback);
+ if (TTSD_ERROR_NONE != ret) {
+ SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to set private data requested cb : ret(%d)", ret);
+ }
+
+ return ret;
+}
+
int ttsd_server_play_pcm(unsigned int uid)
{
- app_tts_state_e state;
- if (0 > ttsd_data_get_client_state(uid, &state)) {
+ app_tts_state_e state = ttsd_data_get_client_state(uid);
+ if (APP_STATE_NONE == state) {
SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] uid(%u) is NOT valid", uid);
return TTSD_ERROR_INVALID_PARAMETER;
}
return TTSD_ERROR_NONE;
}
- unsigned int current_uid = ttsd_data_get_current_playing();
- SLOG(LOG_INFO, tts_tag(), "[Server] playing uid (%u)", current_uid);
-
- if (uid != current_uid && 0 <= ttsd_data_is_client(current_uid)) {
- if (TTSD_MODE_DEFAULT != ttsd_data_get_mode(current_uid)) {
- /* Send interrupt message */
- SLOG(LOG_DEBUG, tts_tag(), "[Server] Old uid(%u) will be interrupted into 'Stop' state ", current_uid);
-
- /* stop player */
- if (0 != ttsd_server_stop(current_uid)) {
- SLOG(LOG_WARN, tts_tag(), "[Server ERROR] Fail to stop server and player : uid (%u)", current_uid);
- }
- } else {
- /* Default mode policy of interrupt is "Pause" */
-
- /* Send interrupt message */
- SLOG(LOG_DEBUG, tts_tag(), "[Server] Old uid(%u) will be interrupted into 'Pause' state ", current_uid);
-
- /* pause player */
- if (0 != __pause_client(current_uid)) {
- SLOG(LOG_WARN, tts_tag(), "[Server ERROR] Fail to ttsd_server_pause() : uid (%u)", current_uid);
- }
- }
-
- __send_interrupt_client(current_uid);
+ int ret = __interrupt_player_by_policy(uid);
+ if (TTSD_ERROR_NONE != ret) {
+ SLOG(LOG_WARN, tts_tag(), "[Server] Current play mode is Interrupt. Cannot play default, screen reader, and noti modes.");
+ return ret;
}
/* Change current play */
return TTSD_ERROR_OPERATION_FAILED;
}
- int ret = TTSD_ERROR_NONE;
- if (APP_STATE_PAUSED == state) {
- SLOG(LOG_DEBUG, tts_tag(), "[Server] uid(%u) is 'Pause' state : resume player", uid);
- g_is_paused = false;
- ret = ttsd_player_resume(uid);
- } else {
- SLOG(LOG_DEBUG, tts_tag(), "[Server] Play player. uid(%u)", uid);
- ret = ttsd_player_play(uid);
- }
-
+ SLOG(LOG_DEBUG, tts_tag(), "[Server] Play player. uid(%u)", uid);
+ ret = ttsd_player_play(uid);
if (TTSD_ERROR_NONE != ret) {
SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to play sound : uid(%u)", uid);
ttsd_data_set_client_state(uid, state);
return TTSD_ERROR_OPERATION_FAILED;
}
- return TTSD_ERROR_NONE;
-}
-
-int ttsd_server_stop_pcm(unsigned int uid)
-{
- app_tts_state_e state;
- if (0 > ttsd_data_get_client_state(uid, &state)) {
- SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] uid is not valid");
- return TTSD_ERROR_INVALID_PARAMETER;
- }
-
- SLOG(LOG_INFO, tts_tag(), "[Server] server stop, state(%d)", state);
-
- if (APP_STATE_PLAYING == state || APP_STATE_PAUSED == state || APP_STATE_READY == state) {
- ttsd_data_set_client_state(uid, APP_STATE_READY);
- }
-
- /* Reset all data */
- ttsd_data_clear_data(uid);
-
- ttsd_player_stop(uid);
-
+ ttsd_data_set_play_type(uid, TTS_APP_PLAY_TYPE_PCM);
return TTSD_ERROR_NONE;
}
return TTSD_ERROR_NONE;
}
+
+int ttsd_server_get_service_state(unsigned int uid, int* service_state)
+{
+ if (0 > ttsd_data_is_client(uid)) {
+ SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] ttsd_server_get_service_state : uid is not valid");
+ return TTSD_ERROR_INVALID_PARAMETER;
+ }
+
+ *service_state = (int)ttsd_state_get_state();
+ SLOG(LOG_DEBUG, tts_tag(), "[Server] Get current service state. service state(%d) ", *service_state);
+
+ return TTSD_ERROR_NONE;
+}