X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=server%2Fsttd_server.c;h=47bea9337b4e7b5db0825f7e7dc08a4ec35e12ab;hb=9f0d6944789b66589ea71c0a6209eb0bb16fd758;hp=62c1d0e81123e7de9f4fca59b72fb70f3d6b5b57;hpb=93fa86f0b8a33a4ea84e2f5761717b3e07a46e7e;p=platform%2Fcore%2Fuifw%2Fstt.git diff --git a/server/sttd_server.c b/server/sttd_server.c index 62c1d0e..47bea93 100644 --- a/server/sttd_server.c +++ b/server/sttd_server.c @@ -1,5 +1,5 @@ /* -* Copyright (c) 2011-2014 Samsung Electronics Co., Ltd All Rights Reserved +* Copyright (c) 2011-2016 Samsung Electronics Co., Ltd All Rights Reserved * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -335,6 +335,9 @@ void __server_silence_dectection_callback(sttp_silence_type_e type, void *user_p if (STTP_SILENCE_TYPE_NO_RECORD_TIMEOUT == type) { SLOG(LOG_DEBUG, TAG_STTD, "Silence Detection type - No Record"); ecore_main_loop_thread_safe_call_async(__cancel_by_no_record, NULL); + if (0 != sttdc_send_error_signal(uid, STTP_ERROR_NO_SPEECH, "No speech while recording")) { + SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] No speech while recording"); + } } else if (STTP_SILENCE_TYPE_END_OF_SPEECH_DETECTED == type) { SLOG(LOG_DEBUG, TAG_STTD, "Silence Detection type - End of Speech"); ecore_main_loop_thread_safe_call_async(__stop_by_silence, NULL); @@ -349,7 +352,7 @@ void __server_silence_dectection_callback(sttp_silence_type_e type, void *user_p return; } -void __sttd_server_engine_changed_cb(const char* engine_id, const char* language, bool support_silence, void* user_data) +void __sttd_server_engine_changed_cb(const char* engine_id, const char* language, bool support_silence, bool need_credential, void* user_data) { if (NULL == engine_id) { SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Engine id is NULL"); @@ -425,11 +428,11 @@ int sttd_initialize() { int ret = 0; - if( 0 != pthread_mutex_init(&sttpe_result_mutex, NULL)) { + if (0 != pthread_mutex_init(&sttpe_result_mutex, NULL)) { SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to initialize sttpe result mutex."); } - if( 0 != pthread_mutex_init(&sttpe_result_time_mutex, NULL)) { + if (0 != pthread_mutex_init(&sttpe_result_time_mutex, NULL)) { SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to initialize sttpe sttpe_result_time_mutex."); } @@ -441,6 +444,7 @@ int sttd_initialize() ret = sttd_recorder_initialize(__server_audio_recorder_callback, __server_audio_interrupt_callback); if (0 != ret) { SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to initialize recorder : result(%d)", ret); + return ret; } /* Engine Agent initialize */ @@ -469,11 +473,11 @@ int sttd_initialize() int sttd_finalize() { - if( 0 != pthread_mutex_destroy(&sttpe_result_mutex)) { + if (0 != pthread_mutex_destroy(&sttpe_result_mutex)) { SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to destroy sttpe result mutex."); } - if( 0 != pthread_mutex_destroy(&sttpe_result_time_mutex)) { + if (0 != pthread_mutex_destroy(&sttpe_result_time_mutex)) { SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to destroy sttpe_result_time_mutex."); } @@ -554,7 +558,7 @@ Eina_Bool sttd_cleanup_client(void *data) __read_proc(); - for (i = 0;i < client_count;i++) { + for (i = 0; i < client_count; i++) { int pid = sttd_client_get_pid(client_list[i]); if (0 > pid) { SLOG(LOG_ERROR, TAG_STTD, "[ERROR] Invalid pid"); @@ -603,7 +607,7 @@ Eina_Bool sttd_cleanup_client(void *data) * STT Server Functions for Client */ -int sttd_server_initialize(int pid, int uid, bool* silence) +int sttd_server_initialize(int pid, int uid, bool* silence, bool* credential) { if (false == sttd_engine_agent_is_default_engine()) { /* Update installed engine */ @@ -615,6 +619,8 @@ int sttd_server_initialize(int pid, int uid, bool* silence) } } + int ret = STTD_ERROR_NONE; + /* check if uid is valid */ app_state_e state; if (0 == sttd_client_get_state(uid, &state)) { @@ -623,20 +629,29 @@ int sttd_server_initialize(int pid, int uid, bool* silence) } /* load engine */ - if (0 != sttd_engine_agent_load_current_engine(uid, NULL)) { + ret = sttd_engine_agent_load_current_engine(uid, NULL); + if (0 != ret) { SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to load default engine"); - return STTD_ERROR_OPERATION_FAILED; + return ret; } - if (0 != sttd_engine_agent_get_option_supported(uid, silence)) { + ret = sttd_engine_agent_get_option_supported(uid, silence); + if (0 != ret) { SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to get engine options supported"); - return STTD_ERROR_OPERATION_FAILED; + return ret; + } + + ret = sttd_engine_agent_is_credential_needed(uid, credential); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to get credential necessity"); + return ret; } /* Add client information to client manager */ - if (0 != sttd_client_add(pid, uid)) { + ret = sttd_client_add(pid, uid); + if (0 != ret) { SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to add client info"); - return STTD_ERROR_OPERATION_FAILED; + return ret; } return STTD_ERROR_NONE; @@ -691,7 +706,7 @@ int sttd_server_finalize(int uid) /* unload engine, if ref count of client is 0 */ if (0 == sttd_client_get_ref_count()) { - sttd_dbus_close_connection(); +// sttd_dbus_close_connection(); ecore_timer_add(0, __quit_ecore_loop, NULL); } @@ -717,13 +732,13 @@ int sttd_server_get_supported_engines(int uid, GSList** engine_list) ret = sttd_engine_agent_get_engine_list(engine_list); if (0 != ret) { SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to get engine list"); - return STTD_ERROR_OPERATION_FAILED; + return ret; } return STTD_ERROR_NONE; } -int sttd_server_set_current_engine(int uid, const char* engine_id, bool* silence) +int sttd_server_set_current_engine(int uid, const char* engine_id, bool* silence, bool* credential) { /* Check if uid is valid */ app_state_e state; @@ -742,13 +757,18 @@ int sttd_server_set_current_engine(int uid, const char* engine_id, bool* silence ret = sttd_engine_agent_load_current_engine(uid, engine_id); if (0 != ret) { SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to set engine : %d", ret); - return STTD_ERROR_OPERATION_FAILED; + return ret; } ret = sttd_engine_agent_get_option_supported(uid, silence); if (0 != ret) { SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to engine options : %d", ret); - return STTD_ERROR_OPERATION_FAILED; + return ret; + } + + if (0 != sttd_engine_agent_is_credential_needed(uid, credential)) { + SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to get credential necessity"); + return ret; } return STTD_ERROR_NONE; @@ -773,7 +793,7 @@ int sttd_server_get_current_engine(int uid, char** engine_id) ret = sttd_engine_agent_get_current_engine(uid, engine_id); if (0 != ret) { SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to get engine : %d", ret); - return STTD_ERROR_OPERATION_FAILED; + return ret; } return STTD_ERROR_NONE; @@ -800,7 +820,7 @@ int sttd_server_check_app_agreed(int uid, const char* appid, bool* available) ret = sttd_engine_agent_check_app_agreed(uid, appid, &temp); if (0 != ret) { SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to get engine available : %d", ret); - return STTD_ERROR_OPERATION_FAILED; + return ret; } if (true == temp) { @@ -827,7 +847,7 @@ int sttd_server_get_supported_languages(int uid, GSList** lang_list) int ret = sttd_engine_agent_supported_langs(uid, lang_list); if (0 != ret) { SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to get supported languages"); - return STTD_ERROR_OPERATION_FAILED; + return ret; } SLOG(LOG_DEBUG, TAG_STTD, "[Server SUCCESS] sttd_server_get_supported_languages"); @@ -853,7 +873,7 @@ int sttd_server_get_current_langauage(int uid, char** current_lang) int ret = sttd_engine_agent_get_default_lang(uid, current_lang); if (0 != ret) { SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to get default language :result(%d)", ret); - return STTD_ERROR_OPERATION_FAILED; + return ret; } SLOG(LOG_DEBUG, TAG_STTD, "[Server SUCCESS] Get default language"); @@ -861,6 +881,60 @@ int sttd_server_get_current_langauage(int uid, char** current_lang) return STTD_ERROR_NONE; } +int sttd_server_set_private_data(int uid, const char* key, const char* data) +{ + /* check if uid is valid */ + app_state_e state; + if (0 != sttd_client_get_state(uid, &state)) { + SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] uid is NOT valid "); + return STTD_ERROR_INVALID_PARAMETER; + } + + if (NULL == key || NULL == data) { + SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Input parameter is NULL"); + return STTD_ERROR_INVALID_PARAMETER; + } + + /* set private data to engine */ + int ret = -1; + ret = sttd_engine_agent_set_private_data(uid, key, data); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to set private data :result(%d)", ret); + return ret; + } + + SLOG(LOG_DEBUG, TAG_STTD, "[Server SUCCESS] Set private data"); + + return STTD_ERROR_NONE; +} + +int sttd_server_get_private_data(int uid, const char* key, char** data) +{ + /* check if uid is valid */ + app_state_e state; + if (0 != sttd_client_get_state(uid, &state)) { + SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] uid is NOT valid "); + return STTD_ERROR_INVALID_PARAMETER; + } + + if (NULL == key || NULL == data) { + SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Input parameter is NULL"); + return STTD_ERROR_INVALID_PARAMETER; + } + + /* get private data to engine */ + int ret = -1; + ret = sttd_engine_agent_get_private_data(uid, key, data); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to get private data :result(%d)", ret); + return ret; + } + + SLOG(LOG_DEBUG, TAG_STTD, "[Server SUCCESS] Get private data"); + + return STTD_ERROR_NONE; +} + int sttd_server_is_recognition_type_supported(int uid, const char* type, int* support) { /* check if uid is valid */ @@ -879,7 +953,7 @@ int sttd_server_is_recognition_type_supported(int uid, const char* type, int* su int ret = sttd_engine_agent_is_recognition_type_supported(uid, type, &temp); if (0 != ret) { SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to get recognition type supported : result(%d)", ret); - return STTD_ERROR_OPERATION_FAILED; + return ret; } *support = (int)temp; @@ -901,7 +975,7 @@ int sttd_server_set_start_sound(int uid, const char* file) int ret = sttd_client_set_start_sound(uid, file); if (0 != ret) { SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to set start sound file : result(%d)", ret); - return STTD_ERROR_OPERATION_FAILED; + return ret; } return 0; @@ -919,7 +993,7 @@ int sttd_server_set_stop_sound(int uid, const char* file) int ret = sttd_client_set_stop_sound(uid, file); if (0 != ret) { SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to set start sound file : result(%d)", ret); - return STTD_ERROR_OPERATION_FAILED; + return ret; } return 0; @@ -984,7 +1058,8 @@ Eina_Bool __stop_by_recording_timeout(void *data) void __sttd_server_recorder_start(void* data) { - int uid = (int)data; + intptr_t puid = (intptr_t)data; + int uid = (int)puid; int current_uid = stt_client_get_current_recognition(); if (uid != current_uid) { @@ -1016,7 +1091,7 @@ void __sttd_start_sound_completed_cb(int id, void *user_data) return; } -int sttd_server_start(int uid, const char* lang, const char* recognition_type, int silence, const char* appid) +int sttd_server_start(int uid, const char* lang, const char* recognition_type, int silence, const char* appid, const char* credential) { if (NULL == lang || NULL == recognition_type) { SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Input parameter is NULL"); @@ -1042,7 +1117,7 @@ int sttd_server_start(int uid, const char* lang, const char* recognition_type, i ret = sttd_engine_agent_check_app_agreed(uid, appid, &temp); if (0 != ret) { SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to get engine available : %d", ret); - return STTD_ERROR_OPERATION_FAILED; + return ret; } if (false == temp) { @@ -1062,9 +1137,10 @@ int sttd_server_start(int uid, const char* lang, const char* recognition_type, i } char* sound = NULL; - if (0 != sttd_client_get_start_sound(uid, &sound)) { + ret = sttd_client_get_start_sound(uid, &sound); + if (0 != ret) { SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to get start beep sound"); - return STTD_ERROR_OPERATION_FAILED; + return ret; } if (0 != stt_client_set_current_recognition(uid)) { @@ -1093,7 +1169,8 @@ int sttd_server_start(int uid, const char* lang, const char* recognition_type, i /* 2. Request wav play */ if (NULL != sound) { int id = 0; - ret = wav_player_start(sound, SOUND_TYPE_MEDIA, __sttd_start_sound_completed_cb, (void*)uid, &id); + intptr_t puid = (intptr_t)uid; + ret = wav_player_start(sound, SOUND_TYPE_MEDIA, __sttd_start_sound_completed_cb, (void*)puid, &id); if (WAV_PLAYER_ERROR_NONE != ret) { SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to play wav"); is_sound_done = true; @@ -1105,7 +1182,7 @@ int sttd_server_start(int uid, const char* lang, const char* recognition_type, i } /* 3. Create recorder & engine initialize */ - ret = sttd_engine_agent_recognize_start_engine(uid, lang, recognition_type, silence, NULL); + ret = sttd_engine_agent_recognize_start_engine(uid, lang, recognition_type, silence, credential, NULL); if (0 != ret) { stt_client_unset_current_recognition(); sttd_recorder_unset_audio_session(); @@ -1135,7 +1212,7 @@ int sttd_server_start(int uid, const char* lang, const char* recognition_type, i sttd_client_set_state(uid, APP_STATE_READY); SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to start recorder : result(%d)", ret); - return STTD_ERROR_OPERATION_FAILED; + return ret; } /* Notify uid state change */ @@ -1184,7 +1261,8 @@ Eina_Bool __time_out_for_processing(void *data) void __sttd_server_engine_stop(void* data) { - int uid = (int)data; + intptr_t puid = (intptr_t)data; + int uid = (int)puid; /* change uid state */ sttd_client_set_state(uid, APP_STATE_PROCESSING); @@ -1257,13 +1335,14 @@ int sttd_server_stop(int uid) SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to cancel recognize"); } if (NULL != sound) free(sound); - return STTD_ERROR_OPERATION_FAILED; + return ret; } /* 2. Request wav play */ if (NULL != sound) { int id = 0; - ret = wav_player_start(sound, SOUND_TYPE_MEDIA, __sttd_stop_sound_completed_cb, (void*)uid, &id); + intptr_t puid = (intptr_t)uid; + ret = wav_player_start(sound, SOUND_TYPE_MEDIA, __sttd_stop_sound_completed_cb, (void*)puid, &id); if (WAV_PLAYER_ERROR_NONE != ret) { SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to play wav"); } else { @@ -1282,7 +1361,7 @@ int sttd_server_stop(int uid) ret = sttd_recorder_unset_audio_session(); if (0 != ret) { SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to unset session : %d", ret); - return STTD_ERROR_OPERATION_FAILED; + return ret; } /* Stop engine */ @@ -1290,7 +1369,7 @@ int sttd_server_stop(int uid) if (0 != ret) { stt_client_unset_current_recognition(); SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to stop engine : result(%d)", ret); - return STTD_ERROR_OPERATION_FAILED; + return ret; } /* change uid state */ @@ -1341,7 +1420,7 @@ int sttd_server_cancel(int uid) int ret = sttd_recorder_unset_audio_session(); if (0 != ret) { SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to unset session : %d", ret); - return STTD_ERROR_OPERATION_FAILED; + return ret; } } @@ -1352,7 +1431,7 @@ int sttd_server_cancel(int uid) int ret = sttd_engine_agent_recognize_cancel(uid); if (0 != ret) { SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to cancel : result(%d)", ret); - return STTD_ERROR_OPERATION_FAILED; + return ret; } /* Notify uid state change */