From fc41c9fbbe65e69add2f9536f883a5a8a081ad92 Mon Sep 17 00:00:00 2001 From: Wonnam Jang Date: Thu, 2 Jun 2016 18:38:10 +0900 Subject: [PATCH] Add function to set credential Change-Id: Id117adfe5a4730f0b8d5384d72dea891dfa2b6e1 Signed-off-by: Wonnam Jang --- client/tts.c | 58 ++++++++++++++++++++++++++++++++++++++++++---- client/tts_client.h | 4 ++++ client/tts_dbus.c | 51 ++++++++++++++++++++++++++++++++++------ client/tts_dbus.h | 6 ++--- include/tts.h | 23 ++++++++++++++++++ server/ttsd_dbus_server.c | 31 +++++++++++++++++-------- server/ttsd_engine_agent.c | 39 +++++++++++++++++++++++++++---- server/ttsd_engine_agent.h | 4 +++- server/ttsd_server.c | 26 +++++++++++++-------- server/ttsd_server.h | 6 ++--- server/ttsp.h | 37 +++++++++++++++++++++-------- 11 files changed, 232 insertions(+), 53 deletions(-) diff --git a/client/tts.c b/client/tts.c index b37afb9..6fdc4eb 100644 --- a/client/tts.c +++ b/client/tts.c @@ -377,6 +377,37 @@ int tts_get_mode(tts_h tts, tts_mode_e* mode) return TTS_ERROR_NONE; } +int tts_set_credential(tts_h tts, const char* credential) +{ + if(0 != __tts_get_feature_enabled()) { + return TTS_ERROR_NOT_SUPPORTED; + } + + if (NULL == tts || NULL == credential) { + SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Input parameter is null"); + return TTS_ERROR_INVALID_PARAMETER; + } + + tts_client_s* client = tts_client_get(tts); + + if (NULL == client) { + SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Get state : A handle is not valid"); + return TTS_ERROR_INVALID_PARAMETER; + } + + if (TTS_STATE_CREATED != client->current_state && TTS_STATE_READY != client->current_state) { + SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] The current state is invalid (%d).", client->current_state); + return TTS_ERROR_INVALID_STATE; + } + + client->credential = strdup(credential); + + SLOG(LOG_DEBUG, TAG_TTSC, "====="); + SLOG(LOG_DEBUG, TAG_TTSC, " "); + + return TTS_ERROR_NONE; +} + static Eina_Bool __tts_connect_daemon(void *data) { tts_h tts = (tts_h)data; @@ -397,7 +428,9 @@ static Eina_Bool __tts_connect_daemon(void *data) /* do request initialize */ int ret = -1; - ret = tts_dbus_request_initialize(client->uid); + bool credential_needed = false; + + ret = tts_dbus_request_initialize(client->uid, &credential_needed); if (TTS_ERROR_ENGINE_NOT_FOUND == ret) { SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to initialize : %s", __tts_get_error_code(ret)); @@ -415,6 +448,8 @@ static Eina_Bool __tts_connect_daemon(void *data) } else { /* success to connect tts-daemon */ + client->credential_needed = credential_needed; + SLOG(LOG_ERROR, TAG_TTSC, "Supported options : credential(%s)", credential_needed ? "need" : "no need"); } client->conn_timer = NULL; @@ -828,6 +863,11 @@ int tts_add_text(tts_h tts, const char* text, const char* language, int voice_ty return TTS_ERROR_INVALID_STATE; } + if (true == client->credential_needed && NULL == client->credential) { + SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Do not have app credential for this engine"); + return TTS_ERROR_PERMISSION_DENIED; + } + /* check valid utf8 */ iconv_t *ict; ict = iconv_open("utf-8", ""); @@ -877,7 +917,7 @@ int tts_add_text(tts_h tts, const char* text, const char* language, int voice_ty int ret = -1; int count = 0; while (0 != ret) { - ret = tts_dbus_request_add_text(client->uid, out_buf, temp, voice_type, speed, client->current_utt_id); + ret = tts_dbus_request_add_text(client->uid, out_buf, temp, voice_type, speed, client->current_utt_id, client->credential); if (0 != ret) { if (TTS_ERROR_TIMED_OUT != ret) { SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] result : %s", __tts_get_error_code(ret)); @@ -918,7 +958,7 @@ static void __tts_play_async(void *data) int ret = -1; int count = 0; while (0 != ret) { - ret = tts_dbus_request_play(client->uid); + ret = tts_dbus_request_play(client->uid, client->credential); if (0 != ret) { if (TTS_ERROR_TIMED_OUT != ret) { SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] result : %s", __tts_get_error_code(ret)); @@ -995,6 +1035,11 @@ int tts_play_async(tts_h tts) return TTS_ERROR_INVALID_STATE; } + if (true == client->credential_needed && NULL == client->credential) { + SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Do not have app credential for this engine"); + return TTS_ERROR_PERMISSION_DENIED; + } + ecore_main_loop_thread_safe_call_async(__tts_play_async, (void*)tts); SLOG(LOG_DEBUG, TAG_TTSC, "====="); @@ -1037,10 +1082,15 @@ int tts_play(tts_h tts) return TTS_ERROR_INVALID_STATE; } + if (true == client->credential_needed && NULL == client->credential) { + SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Do not have app credential for this engine"); + return TTS_ERROR_PERMISSION_DENIED; + } + int ret = -1; int count = 0; while (0 != ret) { - ret = tts_dbus_request_play(client->uid); + ret = tts_dbus_request_play(client->uid, client->credential); if (0 != ret) { if (TTS_ERROR_TIMED_OUT != ret) { SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] result : %s", __tts_get_error_code(ret)); diff --git a/client/tts_client.h b/client/tts_client.h index 0ffd4b8..388d99a 100644 --- a/client/tts_client.h +++ b/client/tts_client.h @@ -61,6 +61,10 @@ typedef struct { /* connection */ Ecore_Timer* conn_timer; + + /* options */ + char* credential; + bool credential_needed; } tts_client_s; int tts_client_new(tts_h* tts); diff --git a/client/tts_dbus.c b/client/tts_dbus.c index 8c3b60a..3917196 100644 --- a/client/tts_dbus.c +++ b/client/tts_dbus.c @@ -327,7 +327,7 @@ int tts_dbus_request_hello(int uid) return result; } -int tts_dbus_request_initialize(int uid) +int tts_dbus_request_initialize(int uid, bool* credential_needed) { DBusMessage* msg; DBusError err; @@ -360,9 +360,11 @@ int tts_dbus_request_initialize(int uid) dbus_error_free(&err); } + int temp = 0; if (NULL != result_msg) { dbus_message_get_args(result_msg, &err, DBUS_TYPE_INT32, &result, + DBUS_TYPE_INT32, &temp, DBUS_TYPE_INVALID); if (dbus_error_is_set(&err)) { @@ -374,7 +376,8 @@ int tts_dbus_request_initialize(int uid) dbus_message_unref(result_msg); if (0 == result) { - SLOG(LOG_DEBUG, TAG_TTSC, "<<<< tts initialize : result = %d", result); + *credential_needed = (bool)temp; + SLOG(LOG_DEBUG, TAG_TTSC, "<<<< tts initialize : result = %d, credential_needed(%d)", result, *credential_needed); } else { SLOG(LOG_ERROR, TAG_TTSC, "<<<< tts initialize : result = %d", result); } @@ -445,7 +448,7 @@ int tts_dbus_request_finalize(int uid) return result; } -int tts_dbus_request_add_text(int uid, const char* text, const char* lang, int vctype, int speed, int uttid) +int tts_dbus_request_add_text(int uid, const char* text, const char* lang, int vctype, int speed, int uttid, const char* credential) { if (NULL == text || NULL == lang) { SLOG(LOG_ERROR, TAG_TTSC, "Input parameter is NULL"); @@ -462,8 +465,15 @@ int tts_dbus_request_add_text(int uid, const char* text, const char* lang, int v SLOG(LOG_ERROR, TAG_TTSC, ">>>> Request tts add text : Fail to make message"); return TTS_ERROR_OPERATION_FAILED; } else { - SLOG(LOG_DEBUG, TAG_TTSC, ">>>> Request tts add text : uid(%d), text(%s), lang(%s), type(%d), speed(%d), id(%d)", - uid, text, lang, vctype, speed, uttid); + SLOG(LOG_DEBUG, TAG_TTSC, ">>>> Request tts add text : uid(%d), text(%s), lang(%s), type(%d), speed(%d), id(%d), credential(%s)", + uid, text, lang, vctype, speed, uttid, (NULL == credential) ? "NULL" : credential); + } + + char *temp = NULL; + if (NULL == credential) { + temp = strdup("NULL"); + } else { + temp = strdup(credential); } if (true != dbus_message_append_args(msg, @@ -473,10 +483,15 @@ int tts_dbus_request_add_text(int uid, const char* text, const char* lang, int v DBUS_TYPE_INT32, &vctype, DBUS_TYPE_INT32, &speed, DBUS_TYPE_INT32, &uttid, + DBUS_TYPE_STRING, &temp, DBUS_TYPE_INVALID)) { dbus_message_unref(msg); SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to append args"); + if (NULL != temp) { + free(temp); + temp = NULL; + } return TTS_ERROR_OPERATION_FAILED; } @@ -513,6 +528,10 @@ int tts_dbus_request_add_text(int uid, const char* text, const char* lang, int v result = TTS_ERROR_TIMED_OUT; } + if (NULL != temp) { + free(temp); + temp = NULL; + } return result; } @@ -656,7 +675,7 @@ int tts_dbus_request_get_private_data(int uid, const char* key, char** data) return result; } -int tts_dbus_request_play(int uid) +int tts_dbus_request_play(int uid, const char* credential) { DBusMessage* msg; DBusError err; @@ -671,10 +690,24 @@ int tts_dbus_request_play(int uid) SLOG(LOG_DEBUG, TAG_TTSC, ">>>> Request tts play : uid(%d)", uid); } - if (true != dbus_message_append_args(msg, DBUS_TYPE_INT32, &uid, DBUS_TYPE_INVALID)) { + char *temp = NULL; + if (NULL == credential) { + temp = strdup("NULL"); + } else { + temp = strdup(credential); + } + + if (true != dbus_message_append_args(msg, + DBUS_TYPE_INT32, &uid, + DBUS_TYPE_STRING, &temp, + DBUS_TYPE_INVALID)) { dbus_message_unref(msg); SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to append args"); + if (NULL != temp) { + free(temp); + temp = NULL; + } return TTS_ERROR_OPERATION_FAILED; } @@ -711,6 +744,10 @@ int tts_dbus_request_play(int uid) result = TTS_ERROR_TIMED_OUT; } + if (NULL != temp) { + free(temp); + temp = NULL; + } return result; } diff --git a/client/tts_dbus.h b/client/tts_dbus.h index deba016..e9d0a7c 100644 --- a/client/tts_dbus.h +++ b/client/tts_dbus.h @@ -27,16 +27,16 @@ int tts_dbus_close_connection(); int tts_dbus_request_hello(int uid); -int tts_dbus_request_initialize(int uid); +int tts_dbus_request_initialize(int uid, bool* credential_needed); int tts_dbus_request_finalize(int uid); int tts_dbus_set_sound_type(int uid, int type); -int tts_dbus_request_add_text(int uid, const char* text, const char* lang, int vctype, int speed, int uttid); +int tts_dbus_request_add_text(int uid, const char* text, const char* lang, int vctype, int speed, int uttid, const char* credential); -int tts_dbus_request_play(int uid) ; +int tts_dbus_request_play(int uid, const char* credential); int tts_dbus_request_stop(int uid); diff --git a/include/tts.h b/include/tts.h index ed38d87..ac56cf2 100644 --- a/include/tts.h +++ b/include/tts.h @@ -292,6 +292,25 @@ int tts_set_mode(tts_h tts, tts_mode_e mode); int tts_get_mode(tts_h tts, tts_mode_e* mode); /** + * @brief Sets the app credential. + * @since_tizen 3.0 + * @privlevel public + * + * @param[in] tts The TTS handle + * @param[in] credential The app credential + * + * @return 0 on success, otherwise a negative error value + * @retval #TTS_ERROR_NONE Success + * @retval #TTS_ERROR_INVALID_STATE Invalid state + * @retval #TTS_ERROR_INVALID_PARAMETER Invalid parameter + * + * @pre The state should be #TTS_STATE_CREATED or #TTS_STATE_READY. + * + * @see tts_play() +*/ +int tts_set_credential(tts_h tts, const char* credential); + +/** * @brief Connects the daemon asynchronously. * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif * @@ -516,9 +535,11 @@ int tts_get_error_message(tts_h tts, char** err_msg); * @retval #TTS_ERROR_INVALID_VOICE Invalid voice about language, voice type * @retval #TTS_ERROR_OPERATION_FAILED Operation failure * @retval #TTS_ERROR_NOT_SUPPORTED TTS NOT supported + * @retval #TTS_ERROR_PERMISSION_DENIED Permission denied * * @pre The state should be #TTS_STATE_READY, #TTS_STATE_PLAYING or #TTS_STATE_PAUSED. * @see tts_get_max_text_size() + * @see tts_set_credential() */ int tts_add_text(tts_h tts, const char* text, const char* language, int voice_type, int speed, int* utt_id); @@ -535,6 +556,7 @@ int tts_add_text(tts_h tts, const char* text, const char* language, int voice_ty * @retval #TTS_ERROR_INVALID_STATE Invalid state * @retval #TTS_ERROR_OPERATION_FAILED Operation failure * @retval #TTS_ERROR_NOT_SUPPORTED TTS NOT supported + * @retval #TTS_ERROR_PERMISSION_DENIED Permission denied * * @pre The current state should be #TTS_STATE_READY or #TTS_STATE_PAUSED. * @post If this function succeeds, the TTS state will be #TTS_STATE_PLAYING. @@ -545,6 +567,7 @@ int tts_add_text(tts_h tts, const char* text, const char* language, int voice_ty * @see tts_utterance_started_cb() * @see tts_utterance_completed_cb() * @see tts_error_cb() + * @see tts_set_credential() */ int tts_play(tts_h tts); diff --git a/server/ttsd_dbus_server.c b/server/ttsd_dbus_server.c index ed11f5f..5a91bd3 100644 --- a/server/ttsd_dbus_server.c +++ b/server/ttsd_dbus_server.c @@ -49,6 +49,7 @@ int ttsd_dbus_server_initialize(DBusConnection* conn, DBusMessage* msg) dbus_error_init(&err); int pid, uid; + bool credential_needed = 0; int ret = 0; dbus_message_get_args(msg, &err, @@ -65,17 +66,22 @@ int ttsd_dbus_server_initialize(DBusConnection* conn, DBusMessage* msg) } else { SECURE_SLOG(LOG_DEBUG, get_tag(), "[IN] tts initialize : pid(%d), uid(%d)", pid , uid); - ret = ttsd_server_initialize(pid, uid); + ret = ttsd_server_initialize(pid, uid, &credential_needed); } DBusMessage* reply; reply = dbus_message_new_method_return(msg); + int temp = (int)credential_needed; + SLOG(LOG_DEBUG, get_tag(), "[OUT] tts initialize : result(%d), credential_needed(%d)", ret, (int)credential_needed); if (NULL != reply) { - dbus_message_append_args(reply, DBUS_TYPE_INT32, &ret, DBUS_TYPE_INVALID); + dbus_message_append_args(reply, + DBUS_TYPE_INT32, &ret, + DBUS_TYPE_INT32, &temp, + DBUS_TYPE_INVALID); if (0 == ret) { - SLOG(LOG_DEBUG, get_tag(), "[OUT] tts initialize : result(%d)", ret); + SLOG(LOG_DEBUG, get_tag(), "[OUT] tts initialize : result(%d), credential_needed(%d)", ret, credential_needed); } else { SLOG(LOG_ERROR, get_tag(), "[OUT ERROR] tts initialize : result(%d)", ret); } @@ -283,7 +289,7 @@ int ttsd_dbus_server_add_text(DBusConnection* conn, DBusMessage* msg) dbus_error_init(&err); int uid, voicetype, speed, uttid; - char *text, *lang; + char *text, *lang, *credential; int ret = 0; dbus_message_get_args(msg, &err, @@ -293,6 +299,7 @@ int ttsd_dbus_server_add_text(DBusConnection* conn, DBusMessage* msg) DBUS_TYPE_INT32, &voicetype, DBUS_TYPE_INT32, &speed, DBUS_TYPE_INT32, &uttid, + DBUS_TYPE_STRING, &credential, DBUS_TYPE_INVALID); SLOG(LOG_DEBUG, get_tag(), ">>>>> TTS ADD TEXT"); @@ -303,9 +310,9 @@ int ttsd_dbus_server_add_text(DBusConnection* conn, DBusMessage* msg) ret = TTSD_ERROR_OPERATION_FAILED; } else { - SECURE_SLOG(LOG_DEBUG, get_tag(), "[IN] tts add text : uid(%d), text(%s), lang(%s), type(%d), speed(%d), uttid(%d)", - uid, text, lang, voicetype, speed, uttid); - ret = ttsd_server_add_queue(uid, text, lang, voicetype, speed, uttid); + SECURE_SLOG(LOG_DEBUG, get_tag(), "[IN] tts add text : uid(%d), text(%s), lang(%s), type(%d), speed(%d), uttid(%d), credential(%s)", + uid, text, lang, voicetype, speed, uttid, credential); + ret = ttsd_server_add_queue(uid, text, lang, voicetype, speed, uttid, credential); } DBusMessage* reply; @@ -342,9 +349,13 @@ int ttsd_dbus_server_play(DBusConnection* conn, DBusMessage* msg) dbus_error_init(&err); int uid; + char* credential; int ret = 0; - dbus_message_get_args(msg, &err, DBUS_TYPE_INT32, &uid, DBUS_TYPE_INVALID); + dbus_message_get_args(msg, &err, + DBUS_TYPE_INT32, &uid, + DBUS_TYPE_STRING, &credential, + DBUS_TYPE_INVALID); SLOG(LOG_DEBUG, get_tag(), ">>>>> TTS PLAY"); @@ -353,8 +364,8 @@ int ttsd_dbus_server_play(DBusConnection* conn, DBusMessage* msg) dbus_error_free(&err); ret = TTSD_ERROR_OPERATION_FAILED; } else { - SECURE_SLOG(LOG_DEBUG, get_tag(), "[IN] tts play : uid(%d)", uid); - ret = ttsd_server_play(uid); + SECURE_SLOG(LOG_DEBUG, get_tag(), "[IN] tts play : uid(%d), credential(%s)", uid, credential); + ret = ttsd_server_play(uid, credential); } DBusMessage* reply; diff --git a/server/ttsd_engine_agent.c b/server/ttsd_engine_agent.c index c3d794c..2727cc8 100644 --- a/server/ttsd_engine_agent.c +++ b/server/ttsd_engine_agent.c @@ -1281,6 +1281,35 @@ int ttsd_engine_agent_set_default_pitch(int pitch) return 0; } +int ttsd_engine_agent_is_credential_needed(int uid, bool* credential_needed) +{ + if (NULL == credential_needed) { + SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] Invalid Parameter"); + return TTSP_ERROR_INVALID_PARAMETER; + } + + if (false == g_agent_init) { + SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] Not Initialized"); + return TTSD_ERROR_OPERATION_FAILED; + } + + if (false == g_cur_engine.is_loaded) { + SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] Not loaded engine"); + return TTSD_ERROR_OPERATION_FAILED; + } + + if (NULL == g_cur_engine.pefuncs->need_app_credential) { + SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] Not support to check app credential"); + return TTSD_ERROR_OPERATION_FAILED; + } + + bool result = false; + result = g_cur_engine.pefuncs->need_app_credential(); + *credential_needed = result; + + return TTSP_ERROR_NONE; +} + /****************************************************************************************** * TTS Engine Interfaces for client *******************************************************************************************/ @@ -1410,7 +1439,7 @@ int ttsd_engine_unload_voice(const char* lang, const int vctype) return 0; } -int ttsd_engine_start_synthesis(const char* lang, int vctype, const char* text, int speed, void* user_param) +int ttsd_engine_start_synthesis(const char* lang, int vctype, const char* text, int speed, const char* credential, void* user_param) { if (false == g_agent_init) { SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] Not Initialized"); @@ -1430,8 +1459,8 @@ int ttsd_engine_start_synthesis(const char* lang, int vctype, const char* text, if (NULL != temp_lang) free(temp_lang); return TTSD_ERROR_INVALID_VOICE; } else { - SECURE_SLOG(LOG_DEBUG, get_tag(), "[Engine Agent] Start synthesis : language(%s), type(%d), speed(%d), text(%s)", - temp_lang, temp_type, speed, text); + SECURE_SLOG(LOG_DEBUG, get_tag(), "[Engine Agent] Start synthesis : language(%s), type(%d), speed(%d), text(%s), credential(%s)", + temp_lang, temp_type, speed, text, credential); } if (NULL == g_cur_engine.pefuncs->start_synth) { @@ -1450,13 +1479,13 @@ int ttsd_engine_start_synthesis(const char* lang, int vctype, const char* text, /* synthesize text */ int ret = 0; - ret = g_cur_engine.pefuncs->start_synth(temp_lang, temp_type, text, temp_speed, user_param); + ret = g_cur_engine.pefuncs->start_synth(temp_lang, temp_type, text, temp_speed, credential, user_param); if (0 != ret) { SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] ***************************************"); SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] * synthesize error : %s *", __ttsd_get_engine_error_code(ret)); SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] ***************************************"); if (NULL != temp_lang) free(temp_lang); - return TTSD_ERROR_OPERATION_FAILED; + return ret; } if (NULL != temp_lang) free(temp_lang); diff --git a/server/ttsd_engine_agent.h b/server/ttsd_engine_agent.h index 21fac93..abb72a5 100644 --- a/server/ttsd_engine_agent.h +++ b/server/ttsd_engine_agent.h @@ -60,6 +60,8 @@ int ttsd_engine_agent_set_default_speed(int speed); int ttsd_engine_agent_set_default_pitch(int pitch); +int ttsd_engine_agent_is_credential_needed(int uid, bool* credential_needed); + int ttsd_engine_set_private_data(const char* key, const char* data); int ttsd_engine_get_private_data(const char* key, char** data); @@ -72,7 +74,7 @@ int ttsd_engine_load_voice(const char* lang, int vctype); int ttsd_engine_unload_voice(const char* lang, int vctype); -int ttsd_engine_start_synthesis(const char* lang, int vctype, const char* text, int speed, void* user_param); +int ttsd_engine_start_synthesis(const char* lang, int vctype, const char* text, int speed, const char* credential, void* user_param); int ttsd_engine_cancel_synthesis(); diff --git a/server/ttsd_server.c b/server/ttsd_server.c index 5d7f152..24a33a2 100644 --- a/server/ttsd_server.c +++ b/server/ttsd_server.c @@ -50,7 +50,7 @@ static utterance_t g_utt; static GList *g_proc_list = NULL; /* Function definitions */ -static int __synthesis(int uid); +static int __synthesis(int uid, const char* credential); static int __server_set_synth_control(ttsd_synthesis_control_e control) { @@ -66,6 +66,7 @@ static ttsd_synthesis_control_e __server_get_synth_control() static Eina_Bool __wait_synthesis(void *data) { /* get current play */ + char* credential = (char*)data; int uid = ttsd_data_get_current_playing(); if (uid > 0) { @@ -76,7 +77,7 @@ static Eina_Bool __wait_synthesis(void *data) g_wait_timer = NULL; if (TTSD_SYNTHESIS_CONTROL_DONE == __server_get_synth_control()) { /* Start next synthesis */ - __synthesis(uid); + __synthesis(uid, credential); } } } else { @@ -86,7 +87,7 @@ static Eina_Bool __wait_synthesis(void *data) return EINA_FALSE; } -static int __synthesis(int uid) +static int __synthesis(int uid, const char* credential) { SLOG(LOG_DEBUG, get_tag(), "===== SYNTHESIS START"); @@ -124,11 +125,12 @@ static int __synthesis(int uid) SECURE_SLOG(LOG_DEBUG, get_tag(), "ID : uid (%d), uttid(%d) ", g_utt.uid, g_utt.uttid); SECURE_SLOG(LOG_DEBUG, get_tag(), "Voice : langauge(%s), type(%d), speed(%d)", speak_data->lang, speak_data->vctype, speak_data->speed); SECURE_SLOG(LOG_DEBUG, get_tag(), "Text : %s", speak_data->text); + SECURE_SLOG(LOG_DEBUG, get_tag(), "Credential : %s", credential); SLOG(LOG_DEBUG, get_tag(), "-----------------------------------------------------------"); int ret = 0; __server_set_synth_control(TTSD_SYNTHESIS_CONTROL_DOING); - ret = ttsd_engine_start_synthesis(speak_data->lang, speak_data->vctype, speak_data->text, speak_data->speed, NULL); + ret = ttsd_engine_start_synthesis(speak_data->lang, speak_data->vctype, speak_data->text, speak_data->speed, credential, NULL); if (0 != ret) { SLOG(LOG_ERROR, get_tag(), "[Server ERROR] * FAIL to start SYNTHESIS !!!! * "); @@ -139,7 +141,7 @@ static int __synthesis(int uid) int pid = ttsd_data_get_pid(uid); ttsdc_send_set_state_message(pid, uid, APP_STATE_READY); } else { - g_wait_timer = ecore_timer_add(0, __wait_synthesis, NULL); + g_wait_timer = ecore_timer_add(0, __wait_synthesis, (void*)credential); } if (NULL != speak_data) { @@ -565,7 +567,7 @@ Eina_Bool ttsd_cleanup_client(void *data) * TTS Server Functions for Client */ -int ttsd_server_initialize(int pid, int uid) +int ttsd_server_initialize(int pid, int uid, bool* credential_needed) { if (false == g_is_engine) { if (0 != ttsd_engine_agent_initialize_current_engine()) { @@ -590,6 +592,10 @@ int ttsd_server_initialize(int pid, int uid) } } + if (0 != ttsd_engine_agent_is_credential_needed(uid, credential_needed)) { + SLOG(LOG_ERROR, get_tag(), "Server ERROR] Fail to get credential necessity"); + return TTSD_ERROR_OPERATION_FAILED; + } if (0 != ttsd_data_new_client(pid, uid)) { SLOG(LOG_ERROR, get_tag(), "[Server ERROR] Fail to add client info"); return TTSD_ERROR_OPERATION_FAILED; @@ -646,7 +652,7 @@ int ttsd_server_finalize(int uid) return TTSD_ERROR_NONE; } -int ttsd_server_add_queue(int uid, const char* text, const char* lang, int voice_type, int speed, int utt_id) +int ttsd_server_add_queue(int uid, const char* text, const char* lang, int voice_type, int speed, int utt_id, const char* credential) { app_state_e state; if (0 > ttsd_data_get_client_state(uid, &state)) { @@ -725,7 +731,7 @@ int ttsd_server_add_queue(int uid, const char* text, const char* lang, int voice if (TTSD_SYNTHESIS_CONTROL_DOING == __server_get_synth_control()) { SLOG(LOG_WARN, get_tag(), "[Server WARNING] Engine has already been running."); } else { - __synthesis(uid); + __synthesis(uid, credential); } } @@ -749,7 +755,7 @@ Eina_Bool __send_interrupt_client(void *data) return EINA_FALSE; } -int ttsd_server_play(int uid) +int ttsd_server_play(int uid, const char* credential) { app_state_e state; if (0 > ttsd_data_get_client_state(uid, &state)) { @@ -826,7 +832,7 @@ int ttsd_server_play(int uid) if (TTSD_SYNTHESIS_CONTROL_DOING == __server_get_synth_control()) { SLOG(LOG_WARN, get_tag(), "[Server WARNING] Engine has already been running."); } else { - __synthesis(uid); + __synthesis(uid, credential); } return TTSD_ERROR_NONE; diff --git a/server/ttsd_server.h b/server/ttsd_server.h index 5f408a8..642d509 100644 --- a/server/ttsd_server.h +++ b/server/ttsd_server.h @@ -35,7 +35,7 @@ Eina_Bool ttsd_cleanup_client(void *data); * Server API for client */ -int ttsd_server_initialize(int pid, int uid); +int ttsd_server_initialize(int pid, int uid, bool* credential_needed); int ttsd_server_finalize(int uid); @@ -43,9 +43,9 @@ int ttsd_server_get_support_voices(int uid, GList** voice_list); int ttsd_server_get_current_voice(int uid, char** language, int* voice_type); -int ttsd_server_add_queue(int uid, const char* text, const char* lang, int voice_type, int speed, int utt_id); +int ttsd_server_add_queue(int uid, const char* text, const char* lang, int voice_type, int speed, int utt_id, const char* credential); -int ttsd_server_play(int uid); +int ttsd_server_play(int uid, const char* credential); int ttsd_server_stop(int uid); diff --git a/server/ttsp.h b/server/ttsp.h index 911dabb..c3c55f7 100644 --- a/server/ttsp.h +++ b/server/ttsp.h @@ -17,6 +17,7 @@ #include #include +#include /** * @addtogroup TTS_ENGINE_MODULE @@ -28,17 +29,22 @@ extern "C" { #endif /** -* @brief Enumerations of error codes. + * @brief Enumeration for error code. */ typedef enum { - TTSP_ERROR_NONE = 0, /**< Successful */ - TTSP_ERROR_OUT_OF_MEMORY = -ENOMEM, /**< Out of Memory */ - TTSP_ERROR_IO_ERROR = -EIO, /**< I/O error */ - TTSP_ERROR_INVALID_PARAMETER = -EINVAL, /**< Invalid parameter */ - TTSP_ERROR_OUT_OF_NETWORK = -ENETDOWN, /**< Out of network */ - TTSP_ERROR_INVALID_STATE = -0x0100021, /**< Invalid state */ - TTSP_ERROR_INVALID_VOICE = -0x0100022, /**< Invalid voice */ - TTSP_ERROR_OPERATION_FAILED = -0x0100025 /**< Operation failed */ + TTSP_ERROR_NONE = TIZEN_ERROR_NONE, /**< Successful */ + TTSP_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_OUT_OF_MEMORY, /**< Out of Memory */ + TTSP_ERROR_IO_ERROR = TIZEN_ERROR_IO_ERROR, /**< I/O error */ + TTSP_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER,/**< Invalid parameter */ + TTSP_ERROR_OUT_OF_NETWORK = TIZEN_ERROR_NETWORK_DOWN, /**< Network is down */ + TTSP_ERROR_TIMED_OUT = TIZEN_ERROR_TIMED_OUT, /**< No answer from the daemon */ + TTSP_ERROR_PERMISSION_DENIED = TIZEN_ERROR_PERMISSION_DENIED,/**< Permission denied */ + TTSP_ERROR_NOT_SUPPORTED = TIZEN_ERROR_NOT_SUPPORTED, /**< TTS NOT supported */ + TTSP_ERROR_INVALID_STATE = TIZEN_ERROR_TTS | 0x01, /**< Invalid state */ + TTSP_ERROR_INVALID_VOICE = TIZEN_ERROR_TTS | 0x02, /**< Invalid voice */ + TTSP_ERROR_ENGINE_NOT_FOUND = TIZEN_ERROR_TTS | 0x03, /**< No available engine */ + TTSP_ERROR_OPERATION_FAILED = TIZEN_ERROR_TTS | 0x04, /**< Operation failed */ + TTSP_ERROR_AUDIO_POLICY_BLOCKED = TIZEN_ERROR_TTS | 0x05 /**< Audio policy blocked */ } ttsp_error_e; /** @@ -181,6 +187,14 @@ typedef bool (*ttspe_is_valid_voice)(const char* language, int type); typedef int (*ttspe_set_pitch)(int pitch); /** +* @brief Gets credential necessity. +* +* @return @c true to be needed app credential, \n @c false not to be needed app credential. +* +*/ +typedef bool (*ttspe_need_app_credential)(void); + +/** * @brief Load voice of the engine. * * @param[in] language language @@ -222,6 +236,7 @@ typedef int (*ttspe_unload_voice)(const char* language, int type); * @param[in] type A voice type * @param[in] text Texts * @param[in] speed A speaking speed +* @parma[in] credential The app credential to allow recognition * @param[in] user_data The user data to be passed to the callback function * * @return 0 on success, otherwise a negative error value @@ -231,13 +246,14 @@ typedef int (*ttspe_unload_voice)(const char* language, int type); * @retval #TTSP_ERROR_INVALID_VOICE Invalid voice * @retval #TTSP_ERROR_OPERATION_FAILED Operation failed * @retval #TTSP_ERROR_OUT_OF_NETWORK Out of network +* @retval #TTSP_ERROR_PERMISSION_DENIED Permission denied * * @post This function invokes ttspe_result_cb(). * * @see ttspe_result_cb() * @see ttspe_cancel_synthesis() */ -typedef int (*ttspe_start_synthesis)(const char* language, int type, const char* text, int speed, void* user_data); +typedef int (*ttspe_start_synthesis)(const char* language, int type, const char* text, int speed, const char* credential, void* user_data); /** * @brief Cancels voice synthesis. @@ -343,6 +359,7 @@ typedef struct { /* Load / Unload voice */ ttspe_load_voice load_voice; /**< Load voice */ ttspe_unload_voice unload_voice; /**< Unload voice */ + ttspe_need_app_credential need_app_credential; /**< Get app credential necessity*/ /* Control synthesis */ ttspe_start_synthesis start_synth; /**< Start synthesis */ -- 2.7.4