#include "ttsd_engine_agent.h"
#include "ttsd_main.h"
#include "ttsd_player.h"
+#include "ttsd_state.h"
#include "ttsd_server.h"
static bool g_is_terminated = false;
+static int g_activated_mode = 0;
/* Function definitions */
static int __stop_and_send_ready_state(unsigned int uid)
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 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;
}
- 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_data_set_synth_control(TTSD_SYNTHESIS_CONTROL_EXPIRED);
ttsd_config_set_screen_reader_callback(__screen_reader_changed_cb);
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;
}
+static void __set_and_notify_activated_mode()
+{
+ int activated_mode = ttsd_data_get_activated_mode();
+ if (g_activated_mode == activated_mode) {
+ return;
+ }
+
+ SLOG(LOG_INFO, tts_tag(), "[Server] Activated mode is changed from(%d) to (%d)", g_activated_mode, activated_mode);
+
+ 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);
+ }
+}
+
+static int __check_app_agreed(int pid, unsigned int uid, bool credential_needed)
+{
+ if (false == credential_needed) {
+ return TTSD_ERROR_NONE;
+ }
+
+ 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);
+ }
+
+ 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;
+ }
+
+ if (false == is_agreed) {
+ SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] App is not agreed");
+ return TTSD_ERROR_PERMISSION_DENIED;
+ }
+
+ return TTSD_ERROR_NONE;
+}
+
int ttsd_server_initialize(int pid, unsigned int uid, ttsd_mode_e mode, tts_ipc_method_e method, bool* credential_needed)
{
SLOG(LOG_INFO, tts_tag(), "[Server] Server initialize");
return TTSD_ERROR_NONE;
}
- if (0 != ttsd_engine_agent_is_credential_needed(uid, credential_needed)) {
- SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to get credential necessity");
+ 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 (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);
+ __set_and_notify_activated_mode();
- if (false == is_agreed) {
- SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] App is not agreed");
- return TTSD_ERROR_PERMISSION_DENIED;
- }
+ 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 != ttsd_data_new_client(pid, uid, mode, method)) {
- SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to add client info");
+ 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;
}
+ 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;
+ }
+
+ *credential_needed = is_needed;
+
return TTSD_ERROR_NONE;
}
}
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 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 = ttsd_data_get_client_state(uid);
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;
+}