/*
-* 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
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);
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");
* Daemon function
*/
+static void __sig_handler(int signo)
+{
+ /* restore signal handler */
+ signal(signo, SIG_DFL);
+
+ /* Send error signal to clients */
+ int* client_list = NULL;
+ int client_count = 0;
+ int i = 0;
+ if (0 != sttd_client_get_list(&client_list, &client_count)) {
+ if (NULL != client_list)
+ free(client_list);
+ }
+
+ if (NULL != client_list) {
+ for (i = 0; i < client_count; i++) {
+ sttdc_send_error_signal(client_list[i], STTD_ERROR_SERVICE_RESET, "Service Reset");
+ }
+ free(client_list);
+ }
+
+ /* invoke signal again */
+ raise(signo);
+}
+
+static void __register_sig_handler()
+{
+ signal(SIGSEGV, __sig_handler);
+ signal(SIGABRT, __sig_handler);
+ signal(SIGTERM, __sig_handler);
+ signal(SIGINT, __sig_handler);
+ signal(SIGQUIT, __sig_handler);
+}
+
int sttd_initialize()
{
int ret = 0;
- if( 0 != pthread_mutex_init(&sttpe_result_mutex, NULL)) {
+ __register_sig_handler();
+
+ 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.");
}
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 */
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.");
}
__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");
* 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 */
}
}
+ int ret = STTD_ERROR_NONE;
+
/* check if uid is valid */
app_state_e state;
if (0 == sttd_client_get_state(uid, &state)) {
}
/* 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;
/* 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);
}
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;
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;
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;
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) {
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");
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");
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 */
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;
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;
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;
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) {
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");
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) {
}
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)) {
/* 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;
}
/* 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();
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 */
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);
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 {
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 */
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 */
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;
}
}
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 */