X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;ds=sidebyside;f=client%2Fstt.c;h=fa4dd9cff6ee1a8783ddc2d55d01a149956c9591;hb=9f0d6944789b66589ea71c0a6209eb0bb16fd758;hp=0b42088f33857b93df5260dacfd90385d036ee51;hpb=854562a21f7bc212fe4fc9d3134a4e9a842fdee3;p=platform%2Fcore%2Fuifw%2Fstt.git diff --git a/client/stt.c b/client/stt.c index 0b42088..fa4dd9c 100644 --- a/client/stt.c +++ b/client/stt.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 @@ -12,6 +12,9 @@ */ #include +#include +#include +#include #include #include #include @@ -29,18 +32,125 @@ #include "stt_main.h" -static Ecore_Timer* g_connect_timer = NULL; - static void __stt_notify_state_changed(void *data); static Eina_Bool __stt_notify_error(void *data); -static int g_count_check_daemon = 0; +static Ecore_Timer* g_connect_timer = NULL; +static float g_volume_db = 0; + +static int g_feature_enabled = -1; + +static int g_privilege_allowed = -1; +static cynara *p_cynara = NULL; + +static bool g_err_callback_status = false; const char* stt_tag() { return "sttc"; } +static int __stt_get_feature_enabled() +{ + if (0 == g_feature_enabled) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] STT NOT supported"); + return STT_ERROR_NOT_SUPPORTED; + } else if (-1 == g_feature_enabled) { + bool stt_supported = false; + bool mic_supported = false; + if (0 == system_info_get_platform_bool(STT_FEATURE_PATH, &stt_supported)) { + if (0 == system_info_get_platform_bool(STT_MIC_FEATURE_PATH, &mic_supported)) { + if (false == stt_supported || false == mic_supported) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] STT NOT supported"); + g_feature_enabled = 0; + return STT_ERROR_NOT_SUPPORTED; + } + + g_feature_enabled = 1; + } else { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to get feature value"); + return STT_ERROR_NOT_SUPPORTED; + } + } else { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to get feature value"); + return STT_ERROR_NOT_SUPPORTED; + } + } + + return 0; +} + +static int __check_privilege_initialize() +{ + int ret = cynara_initialize(&p_cynara, NULL); + if (CYNARA_API_SUCCESS != ret) + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] fail to initialize"); + + return ret == CYNARA_API_SUCCESS; +} + +static int __check_privilege(const char* uid, const char * privilege) +{ + FILE *fp = NULL; + char smack_label[1024] = "/proc/self/attr/current"; + + if (!p_cynara) { + return false; + } + + fp = fopen(smack_label, "r"); + if (fp != NULL) { + if (fread(smack_label, 1, sizeof(smack_label), fp) <= 0) + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] fail to fread"); + + fclose(fp); + } + + pid_t pid = getpid(); + char *session = cynara_session_from_pid(pid); + int ret = cynara_check(p_cynara, smack_label, session, uid, privilege); + SLOG(LOG_DEBUG, TAG_STTC, "[Client]cynara_check returned %d(%s)", ret, (CYNARA_API_ACCESS_ALLOWED == ret) ? "Allowed" : "Denied"); + if (session) + free(session); + + if (ret != CYNARA_API_ACCESS_ALLOWED) + return false; + return true; +} + +static void __check_privilege_deinitialize() +{ + if (p_cynara) + cynara_finish(p_cynara); + p_cynara = NULL; +} + +static int __stt_check_privilege() +{ + char uid[16]; + + if (0 == g_privilege_allowed) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Permission is denied"); + return STT_ERROR_PERMISSION_DENIED; + } else if (-1 == g_privilege_allowed) { + if (false == __check_privilege_initialize()){ + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] privilege initialize is failed"); + return STT_ERROR_PERMISSION_DENIED; + } + snprintf(uid, 16, "%d", getuid()); + if (false == __check_privilege(uid, STT_PRIVILEGE)) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Permission is denied"); + g_privilege_allowed = 0; + __check_privilege_deinitialize(); + return STT_ERROR_PERMISSION_DENIED; + } + __check_privilege_deinitialize(); + } + + g_privilege_allowed = 1; + return STT_ERROR_NONE; +} + static const char* __stt_get_error_code(stt_error_e err) { switch (err) { @@ -81,7 +191,7 @@ static int __stt_convert_config_error_code(stt_config_error_e code) void __stt_config_lang_changed_cb(const char* before_language, const char* current_language, void* user_data) { - SECURE_SLOG(LOG_DEBUG, TAG_STTC, "Language changed : Before lang(%s) Current lang(%s)", + SLOG(LOG_DEBUG, TAG_STTC, "Language changed : Before lang(%s) Current lang(%s)", before_language, current_language); if (0 == strcmp(before_language, current_language)) { @@ -101,8 +211,8 @@ void __stt_config_lang_changed_cb(const char* before_language, const char* curre while (NULL != iter) { data = iter->data; if (NULL != data->default_lang_changed_cb) { - SECURE_SLOG(LOG_DEBUG, TAG_STTC, "Call default language changed callback : uid(%d)", data->uid); - data->default_lang_changed_cb(data->stt, before_language, current_language, + SLOG(LOG_DEBUG, TAG_STTC, "Call default language changed callback : uid(%d)", data->uid); + data->default_lang_changed_cb(data->stt, before_language, current_language, data->default_lang_changed_user_data); } @@ -114,17 +224,57 @@ void __stt_config_lang_changed_cb(const char* before_language, const char* curre return; } +void __stt_config_engine_changed_cb(const char* engine_id, const char* setting, const char* language, bool support_silence, bool need_credential, void* user_data) +{ + stt_h stt = (stt_h)user_data; + + stt_client_s* client = stt_client_get(stt); + if (NULL == client) { + SLOG(LOG_ERROR, TAG_STTC, "[WARNING] A handle is not valid"); + return; + } + + if (NULL != engine_id) SLOG(LOG_DEBUG, TAG_STTC, "Engine id(%s)", engine_id); + if (NULL != setting) SLOG(LOG_DEBUG, TAG_STTC, "Engine setting(%s)", setting); + if (NULL != language) SLOG(LOG_DEBUG, TAG_STTC, "Language(%s)", language); + SLOG(LOG_DEBUG, TAG_STTC, "Silence(%s), Credential(%s)", support_silence ? "on" : "off", need_credential ? "need" : "no need"); + + /* call callback function */ + if (NULL != client->engine_changed_cb) { + client->engine_changed_cb(stt, engine_id, language, support_silence, need_credential, client->engine_changed_user_data); + } else { + SLOG(LOG_WARN, TAG_STTC, "No registered callback function of supported languages"); + } + return; +} + +static int __stt_check_handle(stt_h stt, stt_client_s** client) +{ + if (NULL == stt) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input handle is null"); + return STT_ERROR_INVALID_PARAMETER; + } + + stt_client_s* temp = NULL; + temp = stt_client_get(stt); + + /* check handle */ + if (NULL == temp) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] A handle is not available"); + return STT_ERROR_INVALID_PARAMETER; + } + *client = temp; + + return STT_ERROR_NONE; +} + int stt_create(stt_h* stt) { - bool stt_supported = false; - bool mic_supported = false; - if (0 == system_info_get_platform_bool(STT_FEATURE_PATH, &stt_supported)) { - if (0 == system_info_get_platform_bool(STT_MIC_FEATURE_PATH, &mic_supported)) { - if (false == stt_supported || false == mic_supported) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] STT NOT supported"); - return STT_ERROR_NOT_SUPPORTED; - } - } + if (0 != __stt_get_feature_enabled()) { + return STT_ERROR_NOT_SUPPORTED; + } + if (0 != __stt_check_privilege()) { + return STT_ERROR_PERMISSION_DENIED; } SLOG(LOG_DEBUG, TAG_STTC, "===== Create STT"); @@ -161,7 +311,7 @@ int stt_create(stt_h* stt) return ret; } - ret = stt_config_mgr_set_callback(client->uid, NULL, __stt_config_lang_changed_cb, NULL, NULL); + ret = stt_config_mgr_set_callback(client->uid, __stt_config_engine_changed_cb, __stt_config_lang_changed_cb, NULL, client->stt); ret = __stt_convert_config_error_code(ret); if (0 != ret) { SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to set config changed : %s", __stt_get_error_code(ret)); @@ -169,7 +319,7 @@ int stt_create(stt_h* stt) return ret; } - SECURE_SLOG(LOG_DEBUG, TAG_STTC, "[Success] uid(%d)", (*stt)->handle); + SLOG(LOG_DEBUG, TAG_STTC, "[Success] uid(%d)", (*stt)->handle); SLOG(LOG_DEBUG, TAG_STTC, "====="); SLOG(LOG_DEBUG, TAG_STTC, " "); @@ -179,34 +329,19 @@ int stt_create(stt_h* stt) int stt_destroy(stt_h stt) { - bool stt_supported = false; - bool mic_supported = false; - if (0 == system_info_get_platform_bool(STT_FEATURE_PATH, &stt_supported)) { - if (0 == system_info_get_platform_bool(STT_MIC_FEATURE_PATH, &mic_supported)) { - if (false == stt_supported || false == mic_supported) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] STT NOT supported"); - return STT_ERROR_NOT_SUPPORTED; - } - } + stt_client_s* client = NULL; + if (0 != __stt_get_feature_enabled()) { + return STT_ERROR_NOT_SUPPORTED; } - - SLOG(LOG_DEBUG, TAG_STTC, "===== Destroy STT"); - - if (NULL == stt) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input handle is null"); - SLOG(LOG_DEBUG, TAG_STTC, "====="); - SLOG(LOG_DEBUG, TAG_STTC, " "); - return STT_ERROR_INVALID_PARAMETER; + if (0 != __stt_check_privilege()) { + return STT_ERROR_PERMISSION_DENIED; } - - stt_client_s* client = stt_client_get(stt); - - /* check handle */ - if (NULL == client) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] A handle is not available"); + if (0 != __stt_check_handle(stt, &client)) { return STT_ERROR_INVALID_PARAMETER; } + SLOG(LOG_DEBUG, TAG_STTC, "===== Destroy STT"); + /* check used callback */ if (0 != stt_client_get_use_callback(client)) { SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Cannot destroy in Callback function"); @@ -254,7 +389,7 @@ int stt_destroy(stt_h stt) return STT_ERROR_NONE; } -bool __stt_config_supported_engine_cb(const char* engine_id, const char* engine_name, +bool __stt_config_supported_engine_cb(const char* engine_id, const char* engine_name, const char* setting, bool support_silence, void* user_data) { stt_h stt = (stt_h)user_data; @@ -277,40 +412,26 @@ bool __stt_config_supported_engine_cb(const char* engine_id, const char* engine_ int stt_foreach_supported_engines(stt_h stt, stt_supported_engine_cb callback, void* user_data) { - bool stt_supported = false; - bool mic_supported = false; - if (0 == system_info_get_platform_bool(STT_FEATURE_PATH, &stt_supported)) { - if (0 == system_info_get_platform_bool(STT_MIC_FEATURE_PATH, &mic_supported)) { - if (false == stt_supported || false == mic_supported) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] STT NOT supported"); - return STT_ERROR_NOT_SUPPORTED; - } - } + stt_client_s* client = NULL; + if (0 != __stt_get_feature_enabled()) { + return STT_ERROR_NOT_SUPPORTED; } - - SLOG(LOG_DEBUG, TAG_STTC, "===== Foreach Supported engine"); - - if (NULL == stt || NULL == callback) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL"); - SLOG(LOG_DEBUG, TAG_STTC, "====="); - SLOG(LOG_DEBUG, TAG_STTC, " "); + if (0 != __stt_check_privilege()) { + return STT_ERROR_PERMISSION_DENIED; + } + if (0 != __stt_check_handle(stt, &client)) { return STT_ERROR_INVALID_PARAMETER; } - stt_client_s* client = stt_client_get(stt); + SLOG(LOG_DEBUG, TAG_STTC, "===== Foreach Supported engine"); - /* check handle */ - if (NULL == client) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] A handle is not available"); - SLOG(LOG_DEBUG, TAG_STTC, "====="); - SLOG(LOG_DEBUG, TAG_STTC, " "); + if (NULL == callback) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL"); return STT_ERROR_INVALID_PARAMETER; } if (client->current_state != STT_STATE_CREATED) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State: Current state is not CREATE"); - SLOG(LOG_DEBUG, TAG_STTC, "====="); - SLOG(LOG_DEBUG, TAG_STTC, " "); + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State: Current state(%d) is not CREATED", client->current_state); return STT_ERROR_INVALID_STATE; } @@ -335,50 +456,43 @@ int stt_foreach_supported_engines(stt_h stt, stt_supported_engine_cb callback, v int stt_get_engine(stt_h stt, char** engine_id) { - bool stt_supported = false; - bool mic_supported = false; - if (0 == system_info_get_platform_bool(STT_FEATURE_PATH, &stt_supported)) { - if (0 == system_info_get_platform_bool(STT_MIC_FEATURE_PATH, &mic_supported)) { - if (false == stt_supported || false == mic_supported) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] STT NOT supported"); - return STT_ERROR_NOT_SUPPORTED; - } - } + stt_client_s* client = NULL; + if (0 != __stt_get_feature_enabled()) { + return STT_ERROR_NOT_SUPPORTED; } - - SLOG(LOG_DEBUG, TAG_STTC, "===== Get current engine"); - - if (NULL == stt || NULL == engine_id) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL"); - SLOG(LOG_DEBUG, TAG_STTC, "====="); - SLOG(LOG_DEBUG, TAG_STTC, " "); + if (0 != __stt_check_privilege()) { + return STT_ERROR_PERMISSION_DENIED; + } + if (0 != __stt_check_handle(stt, &client)) { return STT_ERROR_INVALID_PARAMETER; } - stt_client_s* client = stt_client_get(stt); + SLOG(LOG_DEBUG, TAG_STTC, "===== Get current engine"); - /* check handle */ - if (NULL == client) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] A handle is not available"); - SLOG(LOG_DEBUG, TAG_STTC, "====="); - SLOG(LOG_DEBUG, TAG_STTC, " "); + if (NULL == engine_id) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL"); return STT_ERROR_INVALID_PARAMETER; } if (client->current_state != STT_STATE_CREATED) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State: Current state is not CREATE"); - SLOG(LOG_DEBUG, TAG_STTC, "====="); - SLOG(LOG_DEBUG, TAG_STTC, " "); + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State: Current state(%d) is not CREATED", client->current_state); return STT_ERROR_INVALID_STATE; } int ret = 0; - ret = stt_config_mgr_get_engine(engine_id); - ret = __stt_convert_config_error_code(ret); - if (0 != ret) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to request get current engine : %s", __stt_get_error_code(ret)); + + if (NULL != client->current_engine_id) { + *engine_id = strdup(client->current_engine_id); + SLOG(LOG_DEBUG, TAG_STTC, "[SUCCESS] Current engine uuid = %s", *engine_id); } else { - SECURE_SLOG(LOG_DEBUG, TAG_STTC, "[SUCCESS] Current engine uuid = %s", *engine_id); + + ret = stt_config_mgr_get_engine(engine_id); + ret = __stt_convert_config_error_code(ret); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to request get current engine : %s", __stt_get_error_code(ret)); + } else { + SLOG(LOG_DEBUG, TAG_STTC, "[SUCCESS] Current engine uuid = %s", *engine_id); + } } SLOG(LOG_DEBUG, TAG_STTC, "====="); @@ -389,41 +503,27 @@ int stt_get_engine(stt_h stt, char** engine_id) int stt_set_engine(stt_h stt, const char* engine_id) { - bool stt_supported = false; - bool mic_supported = false; - if (0 == system_info_get_platform_bool(STT_FEATURE_PATH, &stt_supported)) { - if (0 == system_info_get_platform_bool(STT_MIC_FEATURE_PATH, &mic_supported)) { - if (false == stt_supported || false == mic_supported) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] STT NOT supported"); - return STT_ERROR_NOT_SUPPORTED; - } - } + stt_client_s* client = NULL; + if (0 != __stt_get_feature_enabled()) { + return STT_ERROR_NOT_SUPPORTED; } - - SLOG(LOG_DEBUG, TAG_STTC, "===== Set current engine"); - - if (NULL == stt || NULL == engine_id) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL"); - SLOG(LOG_DEBUG, TAG_STTC, "====="); - SLOG(LOG_DEBUG, TAG_STTC, " "); + if (0 != __stt_check_privilege()) { + return STT_ERROR_PERMISSION_DENIED; + } + if (0 != __stt_check_handle(stt, &client)) { return STT_ERROR_INVALID_PARAMETER; } - stt_client_s* client = stt_client_get(stt); + SLOG(LOG_DEBUG, TAG_STTC, "===== Set current engine"); - /* check handle */ - if (NULL == client) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] A handle is not available"); - SLOG(LOG_DEBUG, TAG_STTC, "====="); - SLOG(LOG_DEBUG, TAG_STTC, " "); + if (NULL == engine_id) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL"); return STT_ERROR_INVALID_PARAMETER; } /* check state */ if (client->current_state != STT_STATE_CREATED) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State: Current state is not CREATE"); - SLOG(LOG_DEBUG, TAG_STTC, "====="); - SLOG(LOG_DEBUG, TAG_STTC, " "); + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State: Current state(%d) is not CREATED", client->current_state); return STT_ERROR_INVALID_STATE; } @@ -439,20 +539,160 @@ int stt_set_engine(stt_h stt, const char* engine_id) return 0; } +int stt_set_credential(stt_h stt, const char* credential) +{ + 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, "===== Set credential"); + + if (NULL == credential) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL"); + return STT_ERROR_INVALID_PARAMETER; + } + + /* check state */ + if (client->current_state != STT_STATE_CREATED && client->current_state != STT_STATE_READY) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State: Current state(%d) is not CREATED or READY", client->current_state); + return STT_ERROR_INVALID_STATE; + } + + client->credential = strdup(credential); + + SLOG(LOG_DEBUG, TAG_STTC, "====="); + SLOG(LOG_DEBUG, TAG_STTC, " "); + + return STT_ERROR_NONE; +} + +int stt_set_private_data(stt_h stt, const char* key, const char* data) +{ + 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, "===== Set private data"); + + if (NULL == key || NULL == data) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid parameter"); + return STT_ERROR_INVALID_PARAMETER; + } + + /* check state */ + if (STT_STATE_READY != client->current_state) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State: Current state(%d) is not READY", client->current_state); + return STT_ERROR_INVALID_STATE; + } + + int ret = -1; + int count = 0; + while (0 != ret) { + ret = stt_dbus_request_set_private_data(client->uid, key, data); + if (0 != ret) { + if (STT_ERROR_TIMED_OUT != ret) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to set private data : %s", __stt_get_error_code(ret)); + return ret; + } else { + SLOG(LOG_WARN, TAG_STTC, "[WARNING] retry : %s", __stt_get_error_code(ret)); + usleep(10000); + count++; + if (STT_RETRY_COUNT == count) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to request"); + return ret; + } + } + } + } + + SLOG(LOG_DEBUG, TAG_STTC, "====="); + SLOG(LOG_DEBUG, TAG_STTC, ""); + + return STT_ERROR_NONE; + +} +int stt_get_private_data(stt_h stt, const char* key, char** data) +{ + 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, "===== Get private data"); + + if (NULL == key || NULL == data) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid parameter"); + return STT_ERROR_INVALID_PARAMETER; + } + + /* check state */ + if (STT_STATE_READY != client->current_state) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State: Current state(%d) is not READY", client->current_state); + return STT_ERROR_INVALID_STATE; + } + + int ret = -1; + int count = 0; + while (0 != ret) { + ret = stt_dbus_request_get_private_data(client->uid, key, data); + if (0 != ret) { + if (STT_ERROR_TIMED_OUT != ret) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to get private data : %s", __stt_get_error_code(ret)); + return ret; + } else { + SLOG(LOG_WARN, TAG_STTC, "[WARNING] retry : %s", __stt_get_error_code(ret)); + usleep(10000); + count++; + if (STT_RETRY_COUNT == count) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to request"); + return ret; + } + } + } + } + + SLOG(LOG_DEBUG, TAG_STTC, "====="); + SLOG(LOG_DEBUG, TAG_STTC, ""); + + return STT_ERROR_NONE; +} static Eina_Bool __stt_connect_daemon(void *data) { stt_client_s* client = (stt_client_s*)data; if (NULL == client) { SLOG(LOG_ERROR, TAG_STTC, "[ERROR] A handle is not available"); + g_connect_timer = NULL; return EINA_FALSE; } /* Send hello */ int ret = -1; ret = stt_dbus_request_hello(); + if (0 != ret) { if (STT_ERROR_INVALID_STATE == ret) { + g_connect_timer = NULL; return EINA_FALSE; } return EINA_TRUE; @@ -462,10 +702,10 @@ static Eina_Bool __stt_connect_daemon(void *data) SLOG(LOG_DEBUG, TAG_STTC, "===== Connect daemon"); /* request initialization */ - bool silence_supported = false; + bool credential_needed = false; - ret = stt_dbus_request_initialize(client->uid, &silence_supported); + ret = stt_dbus_request_initialize(client->uid, &silence_supported, &credential_needed); if (STT_ERROR_ENGINE_NOT_FOUND == ret) { SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to initialize : %s", __stt_get_error_code(ret)); @@ -481,15 +721,17 @@ static Eina_Bool __stt_connect_daemon(void *data) } else { /* success to connect stt-daemon */ client->silence_supported = silence_supported; - SECURE_SLOG(LOG_DEBUG, TAG_STTC, "Supported options : silence(%s)", silence_supported ? "true" : "false"); + client->credential_needed = credential_needed; + SLOG(LOG_DEBUG, TAG_STTC, "Supported options : silence(%s), credential(%s)", silence_supported ? "support" : "no support", credential_needed ? "need" : "no need"); } if (NULL != client->current_engine_id) { ret = -1; int count = 0; silence_supported = false; + credential_needed = false; while (0 != ret) { - ret = stt_dbus_request_set_current_engine(client->uid, client->current_engine_id, &silence_supported); + ret = stt_dbus_request_set_current_engine(client->uid, client->current_engine_id, &silence_supported, &credential_needed); if (0 != ret) { if (STT_ERROR_TIMED_OUT != ret) { SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to set current engine : %s", __stt_get_error_code(ret)); @@ -508,20 +750,20 @@ static Eina_Bool __stt_connect_daemon(void *data) /* success to change engine */ client->silence_supported = silence_supported; - SLOG(LOG_DEBUG, TAG_STTC, "Supported options : silence(%s)", silence_supported ? "true" : "false"); + SLOG(LOG_DEBUG, TAG_STTC, "Supported options : silence(%s), credential(%s)", silence_supported ? "support" : "no support", credential_needed ? "need" : "no need"); } } } - SECURE_SLOG(LOG_DEBUG, TAG_STTC, "[SUCCESS] uid(%d)", client->uid); + SLOG(LOG_DEBUG, TAG_STTC, "[SUCCESS] uid(%d)", client->uid); client->before_state = client->current_state; client->current_state = STT_STATE_READY; if (NULL != client->state_changed_cb) { stt_client_use_callback(client); - client->state_changed_cb(client->stt, client->before_state, - client->current_state, client->state_changed_user_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"); } else { @@ -536,38 +778,23 @@ static Eina_Bool __stt_connect_daemon(void *data) int stt_prepare(stt_h stt) { - bool stt_supported = false; - bool mic_supported = false; - if (0 == system_info_get_platform_bool(STT_FEATURE_PATH, &stt_supported)) { - if (0 == system_info_get_platform_bool(STT_MIC_FEATURE_PATH, &mic_supported)) { - if (false == stt_supported || false == mic_supported) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] STT NOT supported"); - return STT_ERROR_NOT_SUPPORTED; - } - } + stt_client_s* client = NULL; + if (0 != __stt_get_feature_enabled()) { + return STT_ERROR_NOT_SUPPORTED; } - - SLOG(LOG_DEBUG, TAG_STTC, "===== Prepare STT"); - - stt_client_s* client = stt_client_get(stt); - - /* check handle */ - if (NULL == client) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] A handle is not available"); - SLOG(LOG_DEBUG, TAG_STTC, "====="); - SLOG(LOG_DEBUG, TAG_STTC, " "); + if (0 != __stt_check_privilege()) { + return STT_ERROR_PERMISSION_DENIED; + } + if (0 != __stt_check_handle(stt, &client)) { return STT_ERROR_INVALID_PARAMETER; } /* check state */ if (client->current_state != STT_STATE_CREATED) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State: Current state is not 'CREATED'"); - SLOG(LOG_DEBUG, TAG_STTC, "====="); - SLOG(LOG_DEBUG, TAG_STTC, " "); + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State: Current state(%d) is not 'CREATED'", client->current_state); return STT_ERROR_INVALID_STATE; } - g_count_check_daemon = 0; g_connect_timer = ecore_timer_add(0, __stt_connect_daemon, (void*)client); SLOG(LOG_DEBUG, TAG_STTC, "====="); @@ -578,32 +805,22 @@ int stt_prepare(stt_h stt) int stt_unprepare(stt_h stt) { - bool stt_supported = false; - bool mic_supported = false; - if (0 == system_info_get_platform_bool(STT_FEATURE_PATH, &stt_supported)) { - if (0 == system_info_get_platform_bool(STT_MIC_FEATURE_PATH, &mic_supported)) { - if (false == stt_supported || false == mic_supported) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] STT NOT supported"); - return STT_ERROR_NOT_SUPPORTED; - } - } + stt_client_s* client = NULL; + if (0 != __stt_get_feature_enabled()) { + return STT_ERROR_NOT_SUPPORTED; } - - SLOG(LOG_DEBUG, TAG_STTC, "===== Unprepare STT"); - - stt_client_s* client = stt_client_get(stt); - - /* check handle */ - if (NULL == client) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] A handle is not available"); + 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, "===== Unprepare STT"); + /* check state */ if (client->current_state != STT_STATE_READY) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State: Current state is not 'READY'"); - SLOG(LOG_DEBUG, TAG_STTC, "====="); - SLOG(LOG_DEBUG, TAG_STTC, " "); + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State: Current state(%d) is not 'READY'", client->current_state); return STT_ERROR_INVALID_STATE; } @@ -634,13 +851,18 @@ int stt_unprepare(stt_h stt) if (NULL != client->state_changed_cb) { stt_client_use_callback(client); - client->state_changed_cb(client->stt, client->before_state, - client->current_state, client->state_changed_user_data); + client->state_changed_cb(client->stt, client->before_state, + client->current_state, client->state_changed_user_data); stt_client_not_use_callback(client); } else { SLOG(LOG_WARN, TAG_STTC, "[WARNING] State changed callback is null"); } + if (g_connect_timer) { + ecore_timer_del(g_connect_timer); + g_connect_timer = NULL; + } + SLOG(LOG_DEBUG, TAG_STTC, "====="); SLOG(LOG_DEBUG, TAG_STTC, " "); @@ -669,33 +891,21 @@ bool __stt_config_supported_language_cb(const char* engine_id, const char* langu int stt_foreach_supported_languages(stt_h stt, stt_supported_language_cb callback, void* user_data) { - bool stt_supported = false; - bool mic_supported = false; - if (0 == system_info_get_platform_bool(STT_FEATURE_PATH, &stt_supported)) { - if (0 == system_info_get_platform_bool(STT_MIC_FEATURE_PATH, &mic_supported)) { - if (false == stt_supported || false == mic_supported) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] STT NOT supported"); - return STT_ERROR_NOT_SUPPORTED; - } - } + stt_client_s* client = NULL; + if (0 != __stt_get_feature_enabled()) { + return STT_ERROR_NOT_SUPPORTED; } - - SLOG(LOG_DEBUG, TAG_STTC, "===== Foreach Supported Language"); - - if (NULL == stt || NULL == callback) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL"); - SLOG(LOG_DEBUG, TAG_STTC, "====="); - SLOG(LOG_DEBUG, TAG_STTC, " "); + if (0 != __stt_check_privilege()) { + return STT_ERROR_PERMISSION_DENIED; + } + if (0 != __stt_check_handle(stt, &client)) { return STT_ERROR_INVALID_PARAMETER; } - stt_client_s* client = stt_client_get(stt); + SLOG(LOG_DEBUG, TAG_STTC, "===== Foreach Supported Language"); - /* check handle */ - if (NULL == client) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] A handle is not available"); - SLOG(LOG_DEBUG, TAG_STTC, "====="); - SLOG(LOG_DEBUG, TAG_STTC, " "); + if (NULL == callback) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL"); return STT_ERROR_INVALID_PARAMETER; } @@ -741,33 +951,21 @@ int stt_foreach_supported_languages(stt_h stt, stt_supported_language_cb callbac int stt_get_default_language(stt_h stt, char** language) { - bool stt_supported = false; - bool mic_supported = false; - if (0 == system_info_get_platform_bool(STT_FEATURE_PATH, &stt_supported)) { - if (0 == system_info_get_platform_bool(STT_MIC_FEATURE_PATH, &mic_supported)) { - if (false == stt_supported || false == mic_supported) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] STT NOT supported"); - return STT_ERROR_NOT_SUPPORTED; - } - } + stt_client_s* client = NULL; + if (0 != __stt_get_feature_enabled()) { + return STT_ERROR_NOT_SUPPORTED; } - - SLOG(LOG_DEBUG, TAG_STTC, "===== Get Default Language"); - - if (NULL == stt || NULL == language) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL"); - SLOG(LOG_DEBUG, TAG_STTC, "====="); - SLOG(LOG_DEBUG, TAG_STTC, " "); + if (0 != __stt_check_privilege()) { + return STT_ERROR_PERMISSION_DENIED; + } + if (0 != __stt_check_handle(stt, &client)) { return STT_ERROR_INVALID_PARAMETER; } - stt_client_s* client = stt_client_get(stt); + SLOG(LOG_DEBUG, TAG_STTC, "===== Get Default Language"); - /* check handle */ - if (NULL == client) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] A handle is not available"); - SLOG(LOG_DEBUG, TAG_STTC, "====="); - SLOG(LOG_DEBUG, TAG_STTC, " "); + if (NULL == language) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL"); return STT_ERROR_INVALID_PARAMETER; } @@ -788,70 +986,92 @@ int stt_get_default_language(stt_h stt, char** language) int stt_get_state(stt_h stt, stt_state_e* state) { - bool stt_supported = false; - bool mic_supported = false; - if (0 == system_info_get_platform_bool(STT_FEATURE_PATH, &stt_supported)) { - if (0 == system_info_get_platform_bool(STT_MIC_FEATURE_PATH, &mic_supported)) { - if (false == stt_supported || false == mic_supported) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] STT NOT supported"); - return STT_ERROR_NOT_SUPPORTED; - } - } + stt_client_s* client = NULL; + if (0 != __stt_get_feature_enabled()) { + return STT_ERROR_NOT_SUPPORTED; } - - if (NULL == stt || NULL == state) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL"); + if (0 != __stt_check_privilege()) { + return STT_ERROR_PERMISSION_DENIED; + } + if (0 != __stt_check_handle(stt, &client)) { return STT_ERROR_INVALID_PARAMETER; } - stt_client_s* client = stt_client_get(stt); - - if (NULL == client) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Get state : A handle is not valid"); + if (NULL == state) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL"); return STT_ERROR_INVALID_PARAMETER; } *state = client->current_state; switch (*state) { - case STT_STATE_CREATED: SLOG(LOG_DEBUG, TAG_STTC, "Current state is 'CREATED'"); break; - case STT_STATE_READY: SLOG(LOG_DEBUG, TAG_STTC, "Current state is 'Ready'"); break; - case STT_STATE_RECORDING: SLOG(LOG_DEBUG, TAG_STTC, "Current state is 'Recording'"); break; - case STT_STATE_PROCESSING: SLOG(LOG_DEBUG, TAG_STTC, "Current state is 'Processing'"); break; - default: SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid value"); break; + case STT_STATE_CREATED: SLOG(LOG_DEBUG, TAG_STTC, "Current state is 'CREATED'"); break; + case STT_STATE_READY: SLOG(LOG_DEBUG, TAG_STTC, "Current state is 'Ready'"); break; + case STT_STATE_RECORDING: SLOG(LOG_DEBUG, TAG_STTC, "Current state is 'Recording'"); break; + case STT_STATE_PROCESSING: SLOG(LOG_DEBUG, TAG_STTC, "Current state is 'Processing'"); break; + default: SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid value"); break; } return STT_ERROR_NONE; } -int stt_is_recognition_type_supported(stt_h stt, const char* type, bool* support) +int stt_get_error_message(stt_h stt, char** err_msg) { - bool stt_supported = false; - bool mic_supported = false; - if (0 == system_info_get_platform_bool(STT_FEATURE_PATH, &stt_supported)) { - if (0 == system_info_get_platform_bool(STT_MIC_FEATURE_PATH, &mic_supported)) { - if (false == stt_supported || false == mic_supported) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] STT NOT supported"); - return STT_ERROR_NOT_SUPPORTED; - } - } + 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 == stt || NULL == type || NULL == support) { + if (NULL == err_msg) { SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL"); return STT_ERROR_INVALID_PARAMETER; } - stt_client_s* client = stt_client_get(stt); + if (false == g_err_callback_status) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] This callback should be called during an err_callback"); + return STT_ERROR_OPERATION_FAILED; + } - if (NULL == client) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] A handle is not valid"); + if (NULL != client->err_msg) { + *err_msg = strdup(client->err_msg); + SLOG(LOG_DEBUG, TAG_STTC, "[SUCCESS] Error msg (%s)", *err_msg); + } else { + SLOG(LOG_DEBUG, TAG_STTC, "[SUCCESS] Error msg (NULL)"); + } + + SLOG(LOG_DEBUG, TAG_STTC, "====="); + SLOG(LOG_DEBUG, TAG_STTC, " "); + + return STT_ERROR_NONE; +} + +int stt_is_recognition_type_supported(stt_h stt, const char* type, bool* support) +{ + 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 == type || NULL == support) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL"); return STT_ERROR_INVALID_PARAMETER; } /* check state */ if (client->current_state != STT_STATE_READY) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State: Current state is not READY"); + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State: Current state(%d) is not READY", client->current_state); return STT_ERROR_INVALID_STATE; } @@ -873,7 +1093,7 @@ int stt_is_recognition_type_supported(stt_h stt, const char* type, bool* support } } } else { - SECURE_SLOG(LOG_DEBUG, TAG_STTC, "[SUCCESS] recognition type is %s", *support ? "true " : "false"); + SLOG(LOG_DEBUG, TAG_STTC, "[SUCCESS] recognition type is %s", *support ? "true " : "false"); break; } } @@ -883,32 +1103,20 @@ int stt_is_recognition_type_supported(stt_h stt, const char* type, bool* support int stt_set_silence_detection(stt_h stt, stt_option_silence_detection_e type) { - bool stt_supported = false; - bool mic_supported = false; - if (0 == system_info_get_platform_bool(STT_FEATURE_PATH, &stt_supported)) { - if (0 == system_info_get_platform_bool(STT_MIC_FEATURE_PATH, &mic_supported)) { - if (false == stt_supported || false == mic_supported) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] STT NOT supported"); - return STT_ERROR_NOT_SUPPORTED; - } - } + stt_client_s* client = NULL; + if (0 != __stt_get_feature_enabled()) { + return STT_ERROR_NOT_SUPPORTED; } - - if (NULL == stt) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL"); - return STT_ERROR_INVALID_PARAMETER; + if (0 != __stt_check_privilege()) { + return STT_ERROR_PERMISSION_DENIED; } - - stt_client_s* client = stt_client_get(stt); - - if (NULL == client) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Get state : A handle is not valid"); + if (0 != __stt_check_handle(stt, &client)) { return STT_ERROR_INVALID_PARAMETER; } /* check state */ if (client->current_state != STT_STATE_READY) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State: Current state is not READY"); + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State: Current state(%d) is not READY", client->current_state); return STT_ERROR_INVALID_STATE; } @@ -928,20 +1136,20 @@ int stt_set_silence_detection(stt_h stt, stt_option_silence_detection_e type) int stt_set_start_sound(stt_h stt, const char* filename) { - bool stt_supported = false; - bool mic_supported = false; - if (0 == system_info_get_platform_bool(STT_FEATURE_PATH, &stt_supported)) { - if (0 == system_info_get_platform_bool(STT_MIC_FEATURE_PATH, &mic_supported)) { - if (false == stt_supported || false == mic_supported) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] STT NOT supported"); - return STT_ERROR_NOT_SUPPORTED; - } - } + 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 SET START SOUND"); - if (NULL == stt || NULL == filename) { + if (NULL == filename) { SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL"); return STT_ERROR_INVALID_PARAMETER; } @@ -951,15 +1159,9 @@ int stt_set_start_sound(stt_h stt, const char* filename) return STT_ERROR_INVALID_PARAMETER; } - stt_client_s* client = stt_client_get(stt); - if (NULL == client) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Get state : A handle is not valid"); - return STT_ERROR_INVALID_PARAMETER; - } - /* check state */ if (client->current_state != STT_STATE_READY) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State: Current state is not READY"); + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State: Current state(%d) is not READY", client->current_state); return STT_ERROR_INVALID_STATE; } @@ -981,7 +1183,7 @@ int stt_set_start_sound(stt_h stt, const char* filename) } } } else { - SECURE_SLOG(LOG_DEBUG, TAG_STTC, "[SUCCESS] Set start sound : %s", filename); + SLOG(LOG_DEBUG, TAG_STTC, "[SUCCESS] Set start sound : %s", filename); break; } } @@ -991,34 +1193,22 @@ int stt_set_start_sound(stt_h stt, const char* filename) int stt_unset_start_sound(stt_h stt) { - bool stt_supported = false; - bool mic_supported = false; - if (0 == system_info_get_platform_bool(STT_FEATURE_PATH, &stt_supported)) { - if (0 == system_info_get_platform_bool(STT_MIC_FEATURE_PATH, &mic_supported)) { - if (false == stt_supported || false == mic_supported) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] STT NOT supported"); - return STT_ERROR_NOT_SUPPORTED; - } - } + stt_client_s* client = NULL; + if (0 != __stt_get_feature_enabled()) { + return STT_ERROR_NOT_SUPPORTED; } - - SLOG(LOG_DEBUG, TAG_STTC, "===== STT UNSET START SOUND"); - - if (NULL == stt) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL"); - return STT_ERROR_INVALID_PARAMETER; + if (0 != __stt_check_privilege()) { + return STT_ERROR_PERMISSION_DENIED; } - - stt_client_s* client = stt_client_get(stt); - - if (NULL == client) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Get state : A handle is not valid"); + if (0 != __stt_check_handle(stt, &client)) { return STT_ERROR_INVALID_PARAMETER; } + SLOG(LOG_DEBUG, TAG_STTC, "===== STT UNSET START SOUND"); + /* check state */ if (client->current_state != STT_STATE_READY) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State: Current state is not READY"); + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State: Current state(%d) is not READY", client->current_state); return STT_ERROR_INVALID_STATE; } @@ -1040,7 +1230,7 @@ int stt_unset_start_sound(stt_h stt) } } } else { - SECURE_SLOG(LOG_DEBUG, TAG_STTC, "[SUCCESS] Unset start sound"); + SLOG(LOG_DEBUG, TAG_STTC, "[SUCCESS] Unset start sound"); break; } } @@ -1050,20 +1240,20 @@ int stt_unset_start_sound(stt_h stt) int stt_set_stop_sound(stt_h stt, const char* filename) { - bool stt_supported = false; - bool mic_supported = false; - if (0 == system_info_get_platform_bool(STT_FEATURE_PATH, &stt_supported)) { - if (0 == system_info_get_platform_bool(STT_MIC_FEATURE_PATH, &mic_supported)) { - if (false == stt_supported || false == mic_supported) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] STT NOT supported"); - return STT_ERROR_NOT_SUPPORTED; - } - } + 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 SET STOP SOUND"); - if (NULL == stt || NULL == filename) { + if (NULL == filename) { SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL"); return STT_ERROR_INVALID_PARAMETER; } @@ -1073,16 +1263,9 @@ int stt_set_stop_sound(stt_h stt, const char* filename) return STT_ERROR_INVALID_PARAMETER; } - stt_client_s* client = stt_client_get(stt); - - if (NULL == client) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Get state : A handle is not valid"); - return STT_ERROR_INVALID_PARAMETER; - } - /* check state */ if (client->current_state != STT_STATE_READY) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State: Current state is not READY"); + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State: Current state(%d) is not READY", client->current_state); return STT_ERROR_INVALID_STATE; } @@ -1104,7 +1287,7 @@ int stt_set_stop_sound(stt_h stt, const char* filename) } } } else { - SECURE_SLOG(LOG_DEBUG, TAG_STTC, "[SUCCESS] Set stop sound : %s", filename); + SLOG(LOG_DEBUG, TAG_STTC, "[SUCCESS] Set stop sound : %s", filename); break; } } @@ -1114,34 +1297,22 @@ int stt_set_stop_sound(stt_h stt, const char* filename) int stt_unset_stop_sound(stt_h stt) { - bool stt_supported = false; - bool mic_supported = false; - if (0 == system_info_get_platform_bool(STT_FEATURE_PATH, &stt_supported)) { - if (0 == system_info_get_platform_bool(STT_MIC_FEATURE_PATH, &mic_supported)) { - if (false == stt_supported || false == mic_supported) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] STT NOT supported"); - return STT_ERROR_NOT_SUPPORTED; - } - } + stt_client_s* client = NULL; + if (0 != __stt_get_feature_enabled()) { + return STT_ERROR_NOT_SUPPORTED; } - - SLOG(LOG_DEBUG, TAG_STTC, "===== STT UNSET STOP SOUND"); - - if (NULL == stt) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL"); - return STT_ERROR_INVALID_PARAMETER; + if (0 != __stt_check_privilege()) { + return STT_ERROR_PERMISSION_DENIED; } - - stt_client_s* client = stt_client_get(stt); - - if (NULL == client) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Get state : A handle is not valid"); + if (0 != __stt_check_handle(stt, &client)) { return STT_ERROR_INVALID_PARAMETER; } + SLOG(LOG_DEBUG, TAG_STTC, "===== STT UNSET STOP SOUND"); + /* check state */ if (client->current_state != STT_STATE_READY) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State: Current state is not READY"); + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State: Current state(%d) is not READY", client->current_state); return STT_ERROR_INVALID_STATE; } @@ -1163,7 +1334,7 @@ int stt_unset_stop_sound(stt_h stt) } } } else { - SECURE_SLOG(LOG_DEBUG, TAG_STTC, "[SUCCESS] Unset stop sound"); + SLOG(LOG_DEBUG, TAG_STTC, "[SUCCESS] Unset stop sound"); break; } } @@ -1173,49 +1344,28 @@ int stt_unset_stop_sound(stt_h stt) int stt_start(stt_h stt, const char* language, const char* type) { - bool stt_supported = false; - bool mic_supported = false; - if (0 == system_info_get_platform_bool(STT_FEATURE_PATH, &stt_supported)) { - if (0 == system_info_get_platform_bool(STT_MIC_FEATURE_PATH, &mic_supported)) { - if (false == stt_supported || false == mic_supported) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] STT NOT supported"); - return STT_ERROR_NOT_SUPPORTED; - } - } + stt_client_s* client = NULL; + if (0 != __stt_get_feature_enabled()) { + return STT_ERROR_NOT_SUPPORTED; } - - SLOG(LOG_DEBUG, TAG_STTC, "===== STT START"); - - if (NULL == stt) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL"); - SLOG(LOG_DEBUG, TAG_STTC, "====="); - SLOG(LOG_DEBUG, TAG_STTC, " "); - return STT_ERROR_INVALID_PARAMETER; + if (0 != __stt_check_privilege()) { + return STT_ERROR_PERMISSION_DENIED; } - - stt_client_s* client = stt_client_get(stt); - - /* check handle */ - if (NULL == client) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] A handle is not available"); - SLOG(LOG_DEBUG, TAG_STTC, "====="); - SLOG(LOG_DEBUG, TAG_STTC, " "); + if (0 != __stt_check_handle(stt, &client)) { return STT_ERROR_INVALID_PARAMETER; } + SLOG(LOG_DEBUG, TAG_STTC, "===== STT START"); + /* check state */ if (client->current_state != STT_STATE_READY) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State: Current state is not READY"); - SLOG(LOG_DEBUG, TAG_STTC, "====="); - SLOG(LOG_DEBUG, TAG_STTC, " "); + 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); - SLOG(LOG_DEBUG, TAG_STTC, "====="); - SLOG(LOG_DEBUG, TAG_STTC, " "); - return STT_ERROR_INVALID_STATE; + return STT_ERROR_IN_PROGRESS_TO_RECORDING; } int ret = -1; @@ -1235,53 +1385,21 @@ int stt_start(stt_h stt, const char* language, const char* type) temp = strdup(language); } - ret = -1; - /* do request */ - int count = 0; - while (0 != ret) { - ret = stt_dbus_request_start(client->uid, temp, type, client->silence, appid); - if (0 > ret) { - /* Failure */ - if (STT_ERROR_TIMED_OUT != ret) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to start : %s", __stt_get_error_code(ret)); - if (NULL != temp) free(temp); - return ret; - } else { - SLOG(LOG_WARN, TAG_STTC, "[WARNING] retry to start"); - usleep(10000); - count++; - if (STT_RETRY_COUNT == count) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to request"); - if (NULL != temp) free(temp); - return ret; - } - } - } else { - /* Success */ - if (NULL != temp) free(temp); - - if (STT_RESULT_STATE_DONE == ret) { - SLOG(LOG_DEBUG, TAG_STTC, "[SUCCESS] Start is done : %d", ret); - client->before_state = client->current_state; - client->current_state = STT_STATE_RECORDING; - - if (NULL != client->state_changed_cb) { - ecore_main_loop_thread_safe_call_async(__stt_notify_state_changed, client); - } else { - SLOG(LOG_WARN, TAG_STTC, "[WARNING] State changed callback is null"); - } - } else if (STT_RESULT_STATE_NOT_DONE == ret) { - SLOG(LOG_DEBUG, TAG_STTC, "[SUCCESS] Start is not done : %d", ret); - client->internal_state = STT_INTERNAL_STATE_STARTING; - } else { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid result : %d", ret); - } + 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); + return STT_ERROR_PERMISSION_DENIED; + } - ret = STT_ERROR_NONE; - break; - } + ret = stt_dbus_request_start(client->uid, temp, type, client->silence, appid, client->credential); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to start : %s", __stt_get_error_code(ret)); + } else { + SLOG(LOG_DEBUG, TAG_STTC, "[SUCCESS] Start is successful but not done"); + client->internal_state = STT_INTERNAL_STATE_STARTING; } + if (NULL != temp) free(temp); + SLOG(LOG_DEBUG, TAG_STTC, "====="); SLOG(LOG_DEBUG, TAG_STTC, " "); @@ -1289,92 +1407,44 @@ int stt_start(stt_h stt, const char* language, const char* type) } int stt_stop(stt_h stt) -{ - bool stt_supported = false; - bool mic_supported = false; - if (0 == system_info_get_platform_bool(STT_FEATURE_PATH, &stt_supported)) { - if (0 == system_info_get_platform_bool(STT_MIC_FEATURE_PATH, &mic_supported)) { - if (false == stt_supported || false == mic_supported) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] STT NOT supported"); - return STT_ERROR_NOT_SUPPORTED; - } - } - } - - SLOG(LOG_DEBUG, TAG_STTC, "===== STT STOP"); - - if (NULL == stt) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL"); - SLOG(LOG_DEBUG, TAG_STTC, "====="); - SLOG(LOG_DEBUG, TAG_STTC, " "); - return STT_ERROR_INVALID_PARAMETER; - } - - stt_client_s* client = stt_client_get(stt); - - /* check handle */ - if (NULL == client) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] A handle is not available"); - SLOG(LOG_DEBUG, TAG_STTC, "====="); - SLOG(LOG_DEBUG, TAG_STTC, " "); +{ + 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 STOP"); + /* check state */ if (client->current_state != STT_STATE_RECORDING) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State : Current state is NOT RECORDING"); - SLOG(LOG_DEBUG, TAG_STTC, "====="); - SLOG(LOG_DEBUG, TAG_STTC, " "); + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State : Current state(%d) is NOT RECORDING", 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); - SLOG(LOG_DEBUG, TAG_STTC, "====="); - SLOG(LOG_DEBUG, TAG_STTC, " "); - 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_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; + } 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; } - int ret = -1; - /* do request */ - int count = 0; - while (0 != ret) { - ret = stt_dbus_request_stop(client->uid); - if (0 > ret) { - /* Failure */ - if (STT_ERROR_TIMED_OUT != ret) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to stop : %s", __stt_get_error_code(ret)); - return ret; - } else { - SLOG(LOG_WARN, TAG_STTC, "[WARNING] retry stop"); - usleep(10000); - count++; - if (STT_RETRY_COUNT == count) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to request"); - return ret; - } - } - } else { - if (STT_RESULT_STATE_DONE == ret) { - SLOG(LOG_DEBUG, TAG_STTC, "[SUCCESS] Stop is done : %d", ret); - client->before_state = client->current_state; - client->current_state = STT_STATE_PROCESSING; - - if (NULL != client->state_changed_cb) { - ecore_main_loop_thread_safe_call_async(__stt_notify_state_changed, client); - SLOG(LOG_DEBUG, TAG_STTC, "State changed callback is called"); - } else { - SLOG(LOG_WARN, TAG_STTC, "[WARNING] State changed callback is null"); - } - } else if (STT_RESULT_STATE_NOT_DONE == ret) { - SLOG(LOG_DEBUG, TAG_STTC, "[SUCCESS] Stop is not done : %d", ret); - client->internal_state = STT_INTERNAL_STATE_STOPING; - } else { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid result : %d", ret); - } - ret = STT_ERROR_NONE; - break; - } + int ret = stt_dbus_request_stop(client->uid); + + if (0 != ret) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to stop : %s", __stt_get_error_code(ret)); + } else { + SLOG(LOG_DEBUG, TAG_STTC, "[SUCCESS] Stop is successful but not done"); + client->internal_state = STT_INTERNAL_STATE_STOPPING; } SLOG(LOG_DEBUG, TAG_STTC, "====="); @@ -1386,85 +1456,42 @@ int stt_stop(stt_h stt) int stt_cancel(stt_h stt) { - bool stt_supported = false; - bool mic_supported = false; - if (0 == system_info_get_platform_bool(STT_FEATURE_PATH, &stt_supported)) { - if (0 == system_info_get_platform_bool(STT_MIC_FEATURE_PATH, &mic_supported)) { - if (false == stt_supported || false == mic_supported) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] STT NOT supported"); - return STT_ERROR_NOT_SUPPORTED; - } - } + stt_client_s* client = NULL; + if (0 != __stt_get_feature_enabled()) { + return STT_ERROR_NOT_SUPPORTED; } - - SLOG(LOG_DEBUG, TAG_STTC, "===== STT CANCEL"); - - if (NULL == stt) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input handle is null"); - SLOG(LOG_DEBUG, TAG_STTC, "====="); - SLOG(LOG_DEBUG, TAG_STTC, " "); - return STT_ERROR_INVALID_PARAMETER; + if (0 != __stt_check_privilege()) { + return STT_ERROR_PERMISSION_DENIED; } - - stt_client_s* client = stt_client_get(stt); - - /* check handle */ - if (NULL == client) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] A handle is not available"); - SLOG(LOG_DEBUG, TAG_STTC, "====="); - SLOG(LOG_DEBUG, TAG_STTC, " "); + if (0 != __stt_check_handle(stt, &client)) { return STT_ERROR_INVALID_PARAMETER; } + SLOG(LOG_DEBUG, TAG_STTC, "===== STT CANCEL"); + /* 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 is 'Ready'"); - SLOG(LOG_DEBUG, TAG_STTC, "====="); - SLOG(LOG_DEBUG, TAG_STTC, " "); + 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_NONE != client->internal_state) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State : Internal state is NOT none : %d", client->internal_state); - SLOG(LOG_DEBUG, TAG_STTC, "====="); - SLOG(LOG_DEBUG, TAG_STTC, " "); - 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; } - int ret = -1; - /* do request */ - int count = 0; - while (0 != ret) { - ret = stt_dbus_request_cancel(client->uid); - if (0 != ret) { - /* Failure */ - if (STT_ERROR_TIMED_OUT != ret) { - SLOG(LOG_DEBUG, TAG_STTC, "[ERROR] Fail to cancel : %s", __stt_get_error_code(ret)); - return ret; - } else { - SLOG(LOG_WARN, TAG_STTC, "[WARNING] retry"); - usleep(10000); - count++; - if (STT_RETRY_COUNT == count) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to request"); - return ret; - } - } - } else { - SLOG(LOG_DEBUG, TAG_STTC, "[SUCCESS]"); - - client->before_state = client->current_state; - client->current_state = STT_STATE_READY; - - if (NULL != client->state_changed_cb) { - ecore_main_loop_thread_safe_call_async(__stt_notify_state_changed, client); - SLOG(LOG_DEBUG, TAG_STTC, "State changed callback is called"); - } else { - SLOG(LOG_WARN, TAG_STTC, "[WARNING] State changed callback is null"); - } - ret = STT_ERROR_NONE; - break; - } + int ret = stt_dbus_request_cancel(client->uid); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to cancel : %s", __stt_get_error_code(ret)); + } else { + SLOG(LOG_DEBUG, TAG_STTC, "[SUCCESS] Cancel is successful but not done"); + client->internal_state = STT_INTERNAL_STATE_CANCELING; } SLOG(LOG_DEBUG, TAG_STTC, "====="); @@ -1473,60 +1500,51 @@ int stt_cancel(stt_h stt) return ret; } -static int __stt_get_audio_volume(float* volume) +int __stt_cb_set_volume(int uid, float volume) { - FILE* fp = fopen(STT_AUDIO_VOLUME_PATH, "rb"); - if (!fp) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to open Volume File"); - return STT_ERROR_OPERATION_FAILED; + stt_client_s* client = NULL; + + client = stt_client_get_by_uid(uid); + if (NULL == client) { + SLOG(LOG_ERROR, TAG_STTC, "Handle is NOT valid"); + return STT_ERROR_INVALID_PARAMETER; } - int readlen = fread((void*)volume, sizeof(*volume), 1, fp); - fclose(fp); + if (STT_STATE_RECORDING != client->current_state) { + SLOG(LOG_DEBUG, TAG_STTC, "[ERROR] Invalid state : NO 'Recording' state, cur(%d)", client->current_state); + return STT_ERROR_INVALID_STATE; + } - if (0 == readlen) - *volume = 0.0f; + g_volume_db = volume; + SLOG(LOG_DEBUG, TAG_STTC, "Set volume (%f)", g_volume_db); return 0; } int stt_get_recording_volume(stt_h stt, float* volume) { - bool stt_supported = false; - bool mic_supported = false; - if (0 == system_info_get_platform_bool(STT_FEATURE_PATH, &stt_supported)) { - if (0 == system_info_get_platform_bool(STT_MIC_FEATURE_PATH, &mic_supported)) { - if (false == stt_supported || false == mic_supported) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] STT NOT supported"); - return STT_ERROR_NOT_SUPPORTED; - } - } + stt_client_s* client = NULL; + if (0 != __stt_get_feature_enabled()) { + return STT_ERROR_NOT_SUPPORTED; } - - if (NULL == stt || NULL == volume) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL"); + if (0 != __stt_check_privilege()) { + return STT_ERROR_PERMISSION_DENIED; + } + if (0 != __stt_check_handle(stt, &client)) { return STT_ERROR_INVALID_PARAMETER; } - stt_client_s* client = stt_client_get(stt); - - /* check handle */ - if (NULL == client) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] A handle is not available"); + if (NULL == volume) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL"); return STT_ERROR_INVALID_PARAMETER; } if (STT_STATE_RECORDING != client->current_state) { - SLOG(LOG_DEBUG, TAG_STTC, "[ERROR] Invalid state : NO 'Recording' state"); + SLOG(LOG_DEBUG, TAG_STTC, "[ERROR] Invalid state : NO 'Recording' state, cur(%d)", client->current_state); return STT_ERROR_INVALID_STATE; } - int ret = 0; - ret = __stt_get_audio_volume(volume); - if (0 != ret) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to get audio volume : %s", __stt_get_error_code(ret)); - return STT_ERROR_OPERATION_FAILED; - } + *volume = g_volume_db; return STT_ERROR_NONE; } @@ -1544,7 +1562,7 @@ bool __stt_result_time_cb(int index, int event, const char* text, long start_tim if (NULL != client->result_time_cb) { SLOG(LOG_DEBUG, TAG_STTC, "(%d) event(%d) text(%s) start(%ld) end(%ld)", index, event, text, start_time, end_time); - client->result_time_cb(client->stt, index, (stt_result_time_event_e)event, + client->result_time_cb(client->stt, index, (stt_result_time_event_e)event, text, start_time, end_time, client->result_time_user_data); } else { SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Callback is NULL"); @@ -1556,15 +1574,15 @@ bool __stt_result_time_cb(int index, int event, const char* text, long start_tim int stt_foreach_detailed_result(stt_h stt, stt_result_time_cb callback, void* user_data) { - bool stt_supported = false; - bool mic_supported = false; - if (0 == system_info_get_platform_bool(STT_FEATURE_PATH, &stt_supported)) { - if (0 == system_info_get_platform_bool(STT_MIC_FEATURE_PATH, &mic_supported)) { - if (false == stt_supported || false == mic_supported) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] STT NOT supported"); - return STT_ERROR_NOT_SUPPORTED; - } - } + 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 FOREACH DETAILED RESULT"); @@ -1574,14 +1592,6 @@ int stt_foreach_detailed_result(stt_h stt, stt_result_time_cb callback, void* us return STT_ERROR_INVALID_PARAMETER; } - stt_client_s* client = stt_client_get(stt); - - /* check handle */ - if (NULL == client) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail : A handle is not valid"); - return STT_ERROR_INVALID_PARAMETER; - } - client->result_time_cb = callback; client->result_time_user_data = user_data; @@ -1605,6 +1615,8 @@ static Eina_Bool __stt_notify_error(void *data) { stt_client_s* client = (stt_client_s*)data; + SLOG(LOG_WARN, TAG_STTC, "[WARNING] Error from sttd"); + /* check handle */ if (NULL == client) { SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to notify error : A handle is not valid"); @@ -1616,9 +1628,11 @@ static Eina_Bool __stt_notify_error(void *data) if (NULL != client->error_cb) { stt_client_use_callback(client); + g_err_callback_status = true; client->error_cb(client->stt, client->reason, client->error_user_data); + g_err_callback_status = false; stt_client_not_use_callback(client); - SLOG(LOG_DEBUG, TAG_STTC, "Error callback is called"); + SLOG(LOG_WARN, TAG_STTC, "[WARNING] Error callback is called : reason [%d]", client->reason); } else { SLOG(LOG_WARN, TAG_STTC, "[WARNING] Error callback is null"); } @@ -1626,15 +1640,23 @@ static Eina_Bool __stt_notify_error(void *data) return EINA_FALSE; } -int __stt_cb_error(int uid, int reason) +int __stt_cb_error(int uid, int reason, char* err_msg) { stt_client_s* client = stt_client_get_by_uid(uid); if (NULL == client) { - SLOG(LOG_ERROR, TAG_STTC, "Handle not found\n"); + SLOG(LOG_ERROR, TAG_STTC, "Handle not found"); return -1; } client->reason = reason; + client->internal_state = STT_INTERNAL_STATE_NONE; + if (NULL != client->err_msg) { + free(client->err_msg); + client->err_msg = NULL; + } + client->err_msg = strdup(err_msg); + + SLOG(LOG_INFO, TAG_STTC, "internal state is initialized to 0"); if (NULL != client->error_cb) { ecore_timer_add(0, __stt_notify_error, client); @@ -1661,16 +1683,19 @@ static void __stt_notify_state_changed(void *data) if (STT_INTERNAL_STATE_STARTING == client->internal_state && STT_STATE_RECORDING == client->current_state) { client->internal_state = STT_INTERNAL_STATE_NONE; - SLOG(LOG_DEBUG, TAG_STTC, "Internal state change NULL"); - } else if (STT_INTERNAL_STATE_STOPING == client->internal_state && STT_STATE_PROCESSING == client->current_state) { + SLOG(LOG_DEBUG, TAG_STTC, "Internal state change to NONE"); + } else if (STT_INTERNAL_STATE_STOPPING == client->internal_state && STT_STATE_PROCESSING == client->current_state) { + client->internal_state = STT_INTERNAL_STATE_NONE; + SLOG(LOG_DEBUG, TAG_STTC, "Internal state change to NONE"); + } else if (STT_INTERNAL_STATE_CANCELING == client->internal_state && STT_STATE_READY == client->current_state) { client->internal_state = STT_INTERNAL_STATE_NONE; - SLOG(LOG_DEBUG, TAG_STTC, "Internal state change NULL"); + SLOG(LOG_DEBUG, TAG_STTC, "Internal state change to NONE"); } if (NULL != client->state_changed_cb) { stt_client_use_callback(client); - client->state_changed_cb(client->stt, client->before_state, - client->current_state, client->state_changed_user_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"); } else { @@ -1696,7 +1721,7 @@ static Eina_Bool __stt_notify_result(void *data) if (NULL != client->recognition_result_cb) { stt_client_use_callback(client); - client->recognition_result_cb(client->stt, client->event, (const char**)client->data_list, client->data_count, + client->recognition_result_cb(client->stt, client->event, (const char**)client->data_list, client->data_count, client->msg, client->recognition_result_user_data); stt_client_not_use_callback(client); SLOG(LOG_DEBUG, TAG_STTC, "client recognition result callback called"); @@ -1754,11 +1779,13 @@ int __stt_cb_result(int uid, int event, char** data, int data_count, const char* return STT_ERROR_INVALID_PARAMETER; } - if (NULL != msg) SLOG(LOG_DEBUG, TAG_STTC, "Recognition Result Message = %s", msg); + if (NULL != msg) + SLOG(LOG_DEBUG, TAG_STTC, "Recognition Result Message = %s", msg); int i = 0; for (i = 0; i < data_count; i++) { - if (NULL != data[i]) SECURE_SLOG(LOG_DEBUG, TAG_STTC, "Recognition Result[%d] = %s", i, data[i]); + if (NULL != data[i]) + SLOG(LOG_DEBUG, TAG_STTC, "Recognition Result[%d] = %s", i, data[i]); } if (NULL != client->recognition_result_cb) { @@ -1819,30 +1846,22 @@ int __stt_cb_set_state(int uid, int state) int stt_set_recognition_result_cb(stt_h stt, stt_recognition_result_cb callback, void* user_data) { - bool stt_supported = false; - bool mic_supported = false; - if (0 == system_info_get_platform_bool(STT_FEATURE_PATH, &stt_supported)) { - if (0 == system_info_get_platform_bool(STT_MIC_FEATURE_PATH, &mic_supported)) { - if (false == stt_supported || false == mic_supported) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] STT NOT supported"); - return STT_ERROR_NOT_SUPPORTED; - } - } + stt_client_s* client = NULL; + if (0 != __stt_get_feature_enabled()) { + return STT_ERROR_NOT_SUPPORTED; } - - if (stt == NULL || callback == NULL) + if (0 != __stt_check_privilege()) { + return STT_ERROR_PERMISSION_DENIED; + } + if (0 != __stt_check_handle(stt, &client)) { return STT_ERROR_INVALID_PARAMETER; + } - stt_client_s* client = stt_client_get(stt); - - /* check handle */ - if (NULL == client) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] A handle is not available"); + if (callback == NULL) return STT_ERROR_INVALID_PARAMETER; - } if (STT_STATE_CREATED != client->current_state) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Current state is not 'ready'"); + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Current state(%d) is not 'Created'", client->current_state); return STT_ERROR_INVALID_STATE; } @@ -1854,30 +1873,19 @@ int stt_set_recognition_result_cb(stt_h stt, stt_recognition_result_cb callback, int stt_unset_recognition_result_cb(stt_h stt) { - bool stt_supported = false; - bool mic_supported = false; - if (0 == system_info_get_platform_bool(STT_FEATURE_PATH, &stt_supported)) { - if (0 == system_info_get_platform_bool(STT_MIC_FEATURE_PATH, &mic_supported)) { - if (false == stt_supported || false == mic_supported) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] STT NOT supported"); - return STT_ERROR_NOT_SUPPORTED; - } - } + stt_client_s* client = NULL; + if (0 != __stt_get_feature_enabled()) { + return STT_ERROR_NOT_SUPPORTED; } - - if (NULL == stt) - return STT_ERROR_INVALID_PARAMETER; - - stt_client_s* client = stt_client_get(stt); - - /* check handle */ - if (NULL == client) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] A handle is not available"); + if (0 != __stt_check_privilege()) { + return STT_ERROR_PERMISSION_DENIED; + } + if (0 != __stt_check_handle(stt, &client)) { return STT_ERROR_INVALID_PARAMETER; } if (STT_STATE_CREATED != client->current_state) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Current state is not 'ready'"); + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Current state(%d) is not 'Created'", client->current_state); return STT_ERROR_INVALID_STATE; } @@ -1889,30 +1897,22 @@ int stt_unset_recognition_result_cb(stt_h stt) int stt_set_state_changed_cb(stt_h stt, stt_state_changed_cb callback, void* user_data) { - bool stt_supported = false; - bool mic_supported = false; - if (0 == system_info_get_platform_bool(STT_FEATURE_PATH, &stt_supported)) { - if (0 == system_info_get_platform_bool(STT_MIC_FEATURE_PATH, &mic_supported)) { - if (false == stt_supported || false == mic_supported) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] STT NOT supported"); - return STT_ERROR_NOT_SUPPORTED; - } - } + stt_client_s* client = NULL; + if (0 != __stt_get_feature_enabled()) { + return STT_ERROR_NOT_SUPPORTED; } - - if (NULL == stt || NULL == callback) + if (0 != __stt_check_privilege()) { + return STT_ERROR_PERMISSION_DENIED; + } + if (0 != __stt_check_handle(stt, &client)) { return STT_ERROR_INVALID_PARAMETER; + } - stt_client_s* client = stt_client_get(stt); - - /* check handle */ - if (NULL == client) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] A handle is not available"); + if (NULL == callback) return STT_ERROR_INVALID_PARAMETER; - } if (STT_STATE_CREATED != client->current_state) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Current state is not 'ready'"); + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Current state(%d) is not 'Created'", client->current_state); return STT_ERROR_INVALID_STATE; } @@ -1924,30 +1924,19 @@ int stt_set_state_changed_cb(stt_h stt, stt_state_changed_cb callback, void* use int stt_unset_state_changed_cb(stt_h stt) { - bool stt_supported = false; - bool mic_supported = false; - if (0 == system_info_get_platform_bool(STT_FEATURE_PATH, &stt_supported)) { - if (0 == system_info_get_platform_bool(STT_MIC_FEATURE_PATH, &mic_supported)) { - if (false == stt_supported || false == mic_supported) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] STT NOT supported"); - return STT_ERROR_NOT_SUPPORTED; - } - } + stt_client_s* client = NULL; + if (0 != __stt_get_feature_enabled()) { + return STT_ERROR_NOT_SUPPORTED; } - - if (NULL == stt) - return STT_ERROR_INVALID_PARAMETER; - - stt_client_s* client = stt_client_get(stt); - - /* check handle */ - if (NULL == client) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] A handle is not available"); + if (0 != __stt_check_privilege()) { + return STT_ERROR_PERMISSION_DENIED; + } + if (0 != __stt_check_handle(stt, &client)) { return STT_ERROR_INVALID_PARAMETER; } if (STT_STATE_CREATED != client->current_state) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Current state is not 'ready'"); + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Current state(%d) is not 'Created'", client->current_state); return STT_ERROR_INVALID_STATE; } @@ -1959,30 +1948,22 @@ int stt_unset_state_changed_cb(stt_h stt) int stt_set_error_cb(stt_h stt, stt_error_cb callback, void* user_data) { - bool stt_supported = false; - bool mic_supported = false; - if (0 == system_info_get_platform_bool(STT_FEATURE_PATH, &stt_supported)) { - if (0 == system_info_get_platform_bool(STT_MIC_FEATURE_PATH, &mic_supported)) { - if (false == stt_supported || false == mic_supported) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] STT NOT supported"); - return STT_ERROR_NOT_SUPPORTED; - } - } + stt_client_s* client = NULL; + if (0 != __stt_get_feature_enabled()) { + return STT_ERROR_NOT_SUPPORTED; } - - if (NULL == stt || NULL == callback) + if (0 != __stt_check_privilege()) { + return STT_ERROR_PERMISSION_DENIED; + } + if (0 != __stt_check_handle(stt, &client)) { return STT_ERROR_INVALID_PARAMETER; + } - stt_client_s* client = stt_client_get(stt); - - /* check handle */ - if (NULL == client) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] A handle is not available"); + if (NULL == callback) return STT_ERROR_INVALID_PARAMETER; - } if (STT_STATE_CREATED != client->current_state) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Current state is not 'ready'"); + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Current state(%d) is not 'Created'", client->current_state); return STT_ERROR_INVALID_STATE; } @@ -1994,30 +1975,19 @@ int stt_set_error_cb(stt_h stt, stt_error_cb callback, void* user_data) int stt_unset_error_cb(stt_h stt) { - bool stt_supported = false; - bool mic_supported = false; - if (0 == system_info_get_platform_bool(STT_FEATURE_PATH, &stt_supported)) { - if (0 == system_info_get_platform_bool(STT_MIC_FEATURE_PATH, &mic_supported)) { - if (false == stt_supported || false == mic_supported) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] STT NOT supported"); - return STT_ERROR_NOT_SUPPORTED; - } - } + stt_client_s* client = NULL; + if (0 != __stt_get_feature_enabled()) { + return STT_ERROR_NOT_SUPPORTED; } - - if (NULL == stt) - return STT_ERROR_INVALID_PARAMETER; - - stt_client_s* client = stt_client_get(stt); - - /* check handle */ - if (NULL == client) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] A handle is not available"); + if (0 != __stt_check_privilege()) { + return STT_ERROR_PERMISSION_DENIED; + } + if (0 != __stt_check_handle(stt, &client)) { return STT_ERROR_INVALID_PARAMETER; } if (STT_STATE_CREATED != client->current_state) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Current state is not 'ready'"); + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Current state(%d) is not 'Created'", client->current_state); return STT_ERROR_INVALID_STATE; } @@ -2029,30 +1999,22 @@ int stt_unset_error_cb(stt_h stt) int stt_set_default_language_changed_cb(stt_h stt, stt_default_language_changed_cb callback, void* user_data) { - bool stt_supported = false; - bool mic_supported = false; - if (0 == system_info_get_platform_bool(STT_FEATURE_PATH, &stt_supported)) { - if (0 == system_info_get_platform_bool(STT_MIC_FEATURE_PATH, &mic_supported)) { - if (false == stt_supported || false == mic_supported) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] STT NOT supported"); - return STT_ERROR_NOT_SUPPORTED; - } - } + stt_client_s* client = NULL; + if (0 != __stt_get_feature_enabled()) { + return STT_ERROR_NOT_SUPPORTED; } - - if (NULL == stt || NULL == callback) + if (0 != __stt_check_privilege()) { + return STT_ERROR_PERMISSION_DENIED; + } + if (0 != __stt_check_handle(stt, &client)) { return STT_ERROR_INVALID_PARAMETER; + } - stt_client_s* client = stt_client_get(stt); - - /* check handle */ - if (NULL == client) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] A handle is not available"); + if (NULL == callback) return STT_ERROR_INVALID_PARAMETER; - } if (STT_STATE_CREATED != client->current_state) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Current state is not 'ready'"); + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Current state(%d) is not 'Created'", client->current_state); return STT_ERROR_INVALID_STATE; } @@ -2064,35 +2026,75 @@ int stt_set_default_language_changed_cb(stt_h stt, stt_default_language_changed_ int stt_unset_default_language_changed_cb(stt_h stt) { - bool stt_supported = false; - bool mic_supported = false; - if (0 == system_info_get_platform_bool(STT_FEATURE_PATH, &stt_supported)) { - if (0 == system_info_get_platform_bool(STT_MIC_FEATURE_PATH, &mic_supported)) { - if (false == stt_supported || false == mic_supported) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] STT NOT supported"); - return STT_ERROR_NOT_SUPPORTED; - } - } + 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 (STT_STATE_CREATED != client->current_state) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Current state(%d) is not 'Created'", client->current_state); + return STT_ERROR_INVALID_STATE; } - if (NULL == stt) + client->default_lang_changed_cb = NULL; + client->default_lang_changed_user_data = NULL; + + return 0; +} + +int stt_set_engine_changed_cb(stt_h stt, stt_engine_changed_cb callback, void* user_data) +{ + 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; + } - stt_client_s* client = stt_client_get(stt); + if (NULL == callback) + return STT_ERROR_INVALID_PARAMETER; - /* check handle */ - if (NULL == client) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] A handle is not available"); + if (STT_STATE_CREATED != client->current_state) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Current state(%d) is not 'Created'", client->current_state); + return STT_ERROR_INVALID_STATE; + } + + client->engine_changed_cb = callback; + client->engine_changed_user_data = user_data; + + return 0; +} + +int stt_unset_engine_changed_cb(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; } if (STT_STATE_CREATED != client->current_state) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Current state is not 'ready'"); + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Current state(%d) is not 'Created'", client->current_state); return STT_ERROR_INVALID_STATE; } - client->default_lang_changed_cb = NULL; - client->default_lang_changed_user_data = NULL; + client->engine_changed_cb = NULL; + client->engine_changed_user_data = NULL; return 0; }