X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;ds=sidebyside;f=client%2Fstt.c;h=2035deaba63b0d6021a931ec82cb31b5bad4832a;hb=43ab129d278ae4fe372f4f86e299b9f92bb126a9;hp=fe24360da6475c6ac772832618051ad2c97cfd5f;hpb=aba894d640d2c29be2e639763f68bee2c063d227;p=platform%2Fcore%2Fuifw%2Fstt.git diff --git a/client/stt.c b/client/stt.c index fe24360..2035dea 100644 --- a/client/stt.c +++ b/client/stt.c @@ -100,15 +100,15 @@ static bool __check_privilege(const char* uid, const char * privilege) char smack_label[1024] = {'\0',}; if (!p_cynara) { - return false; + return false; } fp = fopen(label_path, "r"); if (fp != NULL) { - if (fread(smack_label, 1, sizeof(smack_label), fp) <= 0) - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] fail to fread"); + if (sizeof(smack_label) != fread(smack_label, 1, sizeof(smack_label), fp)) + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] fail to fread"); - fclose(fp); + fclose(fp); } pid_t pid = getpid(); @@ -121,7 +121,7 @@ static bool __check_privilege(const char* uid, const char * privilege) } if (ret != CYNARA_API_ACCESS_ALLOWED) - return false; + return false; return true; } @@ -916,6 +916,11 @@ static Eina_Bool __stt_connect_daemon(void *data) return EINA_FALSE; } + if (0 == stt_client_get_size() || NULL == stt_client_get_by_uid(client->uid)) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Client has been already destroyed"); + return EINA_FALSE; + } + /* Check and Set vconfkey of custom engine before sending hello */ if (1 == g_privilege_applaunch_allowed && NULL != client->current_engine_id) { /* Set vconfkey */ @@ -1628,8 +1633,15 @@ int stt_start(stt_h stt, const char* language, const char* type) temp = strdup(language); } + if (NULL == temp) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to allocate memory"); + return STT_ERROR_OUT_OF_MEMORY; + } + if (true == client->credential_needed && NULL == client->credential) { SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Do not have app credential for this engine(%s)", client->current_engine_id); + free(temp); + temp = NULL; return STT_ERROR_PERMISSION_DENIED; } @@ -1642,7 +1654,8 @@ int stt_start(stt_h stt, const char* language, const char* type) SLOG(LOG_DEBUG, TAG_STTC, "[SUCCESS] Start is successful but not done"); } - if (NULL != temp) free(temp); + free(temp); + temp = NULL; SLOG(LOG_DEBUG, TAG_STTC, "====="); SLOG(LOG_DEBUG, TAG_STTC, " "); @@ -1998,9 +2011,9 @@ static void __stt_notify_state_changed(void *data) client->state_changed_cb(client->stt, client->before_state, client->current_state, client->state_changed_user_data); stt_client_not_use_callback(client); - SLOG(LOG_DEBUG, TAG_STTC, "State changed callback is called"); + SLOG(LOG_DEBUG, TAG_STTC, "State changed callback is called, State(%d)", client->current_state); } else { - SLOG(LOG_WARN, TAG_STTC, "[WARNING] State changed callback is null"); + SLOG(LOG_WARN, TAG_STTC, "[WARNING] State changed callback is null, State(%d)", client->current_state); } return; @@ -2490,3 +2503,128 @@ int stt_unset_speech_status_cb(stt_h stt) return 0; } + +int stt_start_file(stt_h stt, const char* language, const char* type, const char* filepath, stt_audio_type_e audio_type, int sample_rate) +{ + stt_client_s* client = NULL; + if (0 != __stt_get_feature_enabled()) { + return STT_ERROR_NOT_SUPPORTED; + } + if (0 != __stt_check_privilege()) { + return STT_ERROR_PERMISSION_DENIED; + } + if (0 != __stt_check_handle(stt, &client)) { + return STT_ERROR_INVALID_PARAMETER; + } + if (NULL == filepath) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL"); + return STT_ERROR_INVALID_PARAMETER; + } + + SLOG(LOG_DEBUG, TAG_STTC, "===== STT START FILE"); + + /* check state */ + if (client->current_state != STT_STATE_READY) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State: Current state(%d) is not READY", client->current_state); + return STT_ERROR_INVALID_STATE; + } + + if (STT_INTERNAL_STATE_NONE != client->internal_state) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State : Internal state is NOT none : %d", client->internal_state); + return STT_ERROR_IN_PROGRESS_TO_RECORDING; + } + + int ret = -1; + char appid[128] = {0, }; + ret = aul_app_get_appid_bypid(getpid(), appid, sizeof(appid)); + + if ((AUL_R_OK != ret) || (0 == strlen(appid))) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to get application ID"); + } else { + SLOG(LOG_DEBUG, TAG_STTC, "[DEBUG] Current app id is %s", appid); + } + + char* temp = NULL; + if (NULL == language) { + temp = strdup("default"); + } else { + temp = strdup(language); + } + + if (NULL == temp) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to allocate memory"); + return STT_ERROR_OUT_OF_MEMORY; + } + + if (true == client->credential_needed && NULL == client->credential) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Do not have app credential for this engine(%s)", client->current_engine_id); + free(temp); + temp = NULL; + return STT_ERROR_PERMISSION_DENIED; + } + + client->internal_state = STT_INTERNAL_STATE_STARTING; + ret = stt_dbus_request_start_file(client->uid, temp, type, client->silence, appid, client->credential, filepath, audio_type, sample_rate); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to start file : %s", __stt_get_error_code(ret)); + client->internal_state = STT_INTERNAL_STATE_NONE; + } else { + SLOG(LOG_DEBUG, TAG_STTC, "[SUCCESS] Start is successful but not done"); + } + + free(temp); + temp = NULL; + + SLOG(LOG_DEBUG, TAG_STTC, "====="); + SLOG(LOG_DEBUG, TAG_STTC, " "); + + return ret; +} + +int stt_cancel_file(stt_h stt) +{ + stt_client_s* client = NULL; + if (0 != __stt_get_feature_enabled()) { + return STT_ERROR_NOT_SUPPORTED; + } + if (0 != __stt_check_privilege()) { + return STT_ERROR_PERMISSION_DENIED; + } + if (0 != __stt_check_handle(stt, &client)) { + return STT_ERROR_INVALID_PARAMETER; + } + + SLOG(LOG_DEBUG, TAG_STTC, "===== STT CANCEL FILE"); + + /* check state */ + if (STT_STATE_RECORDING != client->current_state && STT_STATE_PROCESSING != client->current_state) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid state : Current state(%d) is 'Ready'", client->current_state); + return STT_ERROR_INVALID_STATE; + } + + if (STT_INTERNAL_STATE_STARTING == client->internal_state) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State : Internal state is STARTING : %d", client->internal_state); + return STT_ERROR_IN_PROGRESS_TO_RECORDING; + } else if (STT_INTERNAL_STATE_STOPPING == client->internal_state) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State : Internal state is STOPPING : %d", client->internal_state); + return STT_ERROR_IN_PROGRESS_TO_PROCESSING; + } else if (STT_INTERNAL_STATE_CANCELING == client->internal_state) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State : Internal state is CANCELING : %d", client->internal_state); + return STT_ERROR_IN_PROGRESS_TO_READY; + } + + client->internal_state = STT_INTERNAL_STATE_CANCELING; + int ret = stt_dbus_request_cancel_file(client->uid); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to cancel file : %s", __stt_get_error_code(ret)); + client->internal_state = STT_INTERNAL_STATE_NONE; + } else { + SLOG(LOG_DEBUG, TAG_STTC, "[SUCCESS] Cancel file is successful but not done"); + } + + SLOG(LOG_DEBUG, TAG_STTC, "====="); + SLOG(LOG_DEBUG, TAG_STTC, " "); + + return ret; +} +