From 5be18b99d609324c3c664fe6b9a7f5c89409b89a Mon Sep 17 00:00:00 2001 From: Wonnam Jang Date: Wed, 18 May 2016 14:22:17 +0900 Subject: [PATCH] Add functions to set credential Change-Id: I7183790bcefb62fea503f7392a1c986b2508a54a Signed-off-by: Wonnam Jang --- client/stt.c | 135 +++++++++++++++++++++++++++++++++++++++++++-- client/stt_client.h | 4 ++ client/stt_dbus.c | 17 +++--- client/stt_dbus.h | 6 +- client/stt_setting.c | 4 +- common/stt_config_mgr.c | 19 +++++-- common/stt_config_mgr.h | 2 +- common/stt_config_parser.c | 67 +++++++++++++++++++++- common/stt_config_parser.h | 6 +- common/stt_engine.c | 35 +++++++++++- common/stt_engine.h | 4 +- include/stt.h | 37 +++++++++++++ server/sttd_config.c | 4 +- server/sttd_config.h | 2 +- server/sttd_dbus_server.c | 24 +++++--- server/sttd_engine_agent.c | 43 ++++++++++++++- server/sttd_engine_agent.h | 4 +- server/sttd_server.c | 20 +++++-- server/sttd_server.h | 6 +- server/sttp.h | 39 +++++++++---- stt-config.xml | 1 + 21 files changed, 413 insertions(+), 66 deletions(-) mode change 100755 => 100644 client/stt_dbus.h mode change 100755 => 100644 common/stt_config_mgr.c mode change 100755 => 100644 common/stt_config_mgr.h mode change 100755 => 100644 common/stt_config_parser.c mode change 100755 => 100644 common/stt_config_parser.h mode change 100755 => 100644 server/sttp.h diff --git a/client/stt.c b/client/stt.c index eddd3fd..9c7523d 100644 --- a/client/stt.c +++ b/client/stt.c @@ -147,6 +147,30 @@ 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; +} + int stt_create(stt_h* stt) { if (0 != __stt_get_feature_enabled()) { @@ -187,7 +211,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)); @@ -424,6 +448,41 @@ int stt_set_engine(stt_h stt, const char* engine_id) return 0; } +int stt_set_credential(stt_h stt, const char* credential) +{ + if (0 != __stt_get_feature_enabled()) { + return STT_ERROR_NOT_SUPPORTED; + } + + SLOG(LOG_DEBUG, TAG_STTC, "===== Set credential"); + + if (NULL == stt || NULL == credential) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL, stt(%s), credential(%a)", stt, credential); + 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"); + 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; +} + static Eina_Bool __stt_connect_daemon(void *data) { stt_client_s* client = (stt_client_s*)data; @@ -451,8 +510,9 @@ static Eina_Bool __stt_connect_daemon(void *data) /* 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)); @@ -468,15 +528,17 @@ static Eina_Bool __stt_connect_daemon(void *data) } else { /* success to connect stt-daemon */ client->silence_supported = silence_supported; - 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)); @@ -495,7 +557,7 @@ 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"); } } } @@ -1196,7 +1258,12 @@ int stt_start(stt_h stt, const char* language, const char* type) } } #else - ret = stt_dbus_request_start(client->uid, temp, type, client->silence, appid); + 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_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 { @@ -1951,3 +2018,59 @@ int stt_unset_default_language_changed_cb(stt_h stt) return 0; } + +int stt_set_engine_changed_cb(stt_h stt, stt_engine_changed_cb callback, void* user_data) +{ + if (0 != __stt_get_feature_enabled()) { + return STT_ERROR_NOT_SUPPORTED; + } + + if (NULL == stt || NULL == callback) + 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"); + 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; + } + + client->engine_changed_cb = callback; + client->engine_changed_user_data = user_data; + + return 0; +} + +int stt_unset_engine_changed_cb(stt_h stt) +{ + 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"); + 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; + } + + client->engine_changed_cb = NULL; + client->engine_changed_user_data = NULL; + + return 0; +} diff --git a/client/stt_client.h b/client/stt_client.h index 2600ce2..ed9803d 100644 --- a/client/stt_client.h +++ b/client/stt_client.h @@ -47,6 +47,8 @@ typedef struct { void* error_user_data; stt_default_language_changed_cb default_lang_changed_cb; void* default_lang_changed_user_data; + stt_engine_changed_cb engine_changed_cb; + void* engine_changed_user_data; stt_supported_engine_cb supported_engine_cb; void* supported_engine_user_data; @@ -54,10 +56,12 @@ typedef struct { void* supported_lang_user_data; char* current_engine_id; + char* credential; /* option */ bool silence_supported; stt_option_silence_detection_e silence; + bool credential_needed; /* state */ stt_state_e before_state; diff --git a/client/stt_dbus.c b/client/stt_dbus.c index fc5d0e5..e6a77ec 100644 --- a/client/stt_dbus.c +++ b/client/stt_dbus.c @@ -466,7 +466,7 @@ int stt_dbus_request_hello() } -int stt_dbus_request_initialize(int uid, bool* silence_supported) +int stt_dbus_request_initialize(int uid, bool* silence_supported, bool* credential_needed) { DBusMessage* msg; @@ -507,6 +507,7 @@ int stt_dbus_request_initialize(int uid, bool* silence_supported) dbus_message_get_args(result_msg, &err, DBUS_TYPE_INT32, &result, DBUS_TYPE_INT32, silence_supported, + DBUS_TYPE_INT32, credential_needed, DBUS_TYPE_INVALID); if (dbus_error_is_set(&err)) { @@ -516,8 +517,8 @@ int stt_dbus_request_initialize(int uid, bool* silence_supported) } if (0 == result) { - SLOG(LOG_DEBUG, TAG_STTC, "<<<< stt initialize : result = %d, silence(%d)", - result, *silence_supported); + SLOG(LOG_DEBUG, TAG_STTC, "<<<< stt initialize : result = %d, silence(%d), credential(%d)", + result, *silence_supported, *credential_needed); } else { SLOG(LOG_ERROR, TAG_STTC, "<<<< stt initialize : result = %d", result); } @@ -595,7 +596,7 @@ int stt_dbus_request_finalize(int uid) return result; } -int stt_dbus_request_set_current_engine(int uid, const char* engine_id, bool* silence_supported) +int stt_dbus_request_set_current_engine(int uid, const char* engine_id, bool* silence_supported, bool* credential_needed) { DBusMessage* msg; @@ -634,6 +635,7 @@ int stt_dbus_request_set_current_engine(int uid, const char* engine_id, bool* si dbus_message_get_args(result_msg, &err, DBUS_TYPE_INT32, &result, DBUS_TYPE_INT32, silence_supported, + DBUS_TYPE_INT32, credential_needed, DBUS_TYPE_INVALID); if (dbus_error_is_set(&err)) { @@ -645,8 +647,8 @@ int stt_dbus_request_set_current_engine(int uid, const char* engine_id, bool* si dbus_message_unref(result_msg); if (0 == result) { - SLOG(LOG_DEBUG, TAG_STTC, "<<<< stt set engine : result = %d , silence(%d)", - result, *silence_supported); + SLOG(LOG_DEBUG, TAG_STTC, "<<<< stt set engine : result = %d , silence(%d), credential(%d)", + result, *silence_supported, *credential_needed); } else { SLOG(LOG_ERROR, TAG_STTC, "<<<< stt set engine : result = %d", result); } @@ -1202,7 +1204,7 @@ int stt_dbus_request_unset_stop_sound(int uid) return result; } -int stt_dbus_request_start(int uid, const char* lang, const char* type, int silence, const char* appid) +int stt_dbus_request_start(int uid, const char* lang, const char* type, int silence, const char* appid, const char* credential) { if (NULL == lang || NULL == type || NULL == appid) { SLOG(LOG_ERROR, TAG_STTC, "Input parameter is NULL"); @@ -1231,6 +1233,7 @@ int stt_dbus_request_start(int uid, const char* lang, const char* type, int sile DBUS_TYPE_STRING, &type, DBUS_TYPE_INT32, &silence, DBUS_TYPE_STRING, &appid, + DBUS_TYPE_STRING, &credential, DBUS_TYPE_INVALID); #if 1 if (g_conn_sender) { diff --git a/client/stt_dbus.h b/client/stt_dbus.h old mode 100755 new mode 100644 index 72ed1a1..d48f773 --- a/client/stt_dbus.h +++ b/client/stt_dbus.h @@ -29,11 +29,11 @@ int stt_dbus_close_connection(); int stt_dbus_request_hello(); -int stt_dbus_request_initialize(int uid, bool* silence_supported); +int stt_dbus_request_initialize(int uid, bool* silence_supported, bool* credential_needed); int stt_dbus_request_finalize(int uid); -int stt_dbus_request_set_current_engine(int uid, const char* engine_id, bool* silence_supported); +int stt_dbus_request_set_current_engine(int uid, const char* engine_id, bool* silence_supported, bool* credential_needed); int stt_dbus_request_check_app_agreed(int uid, const char* appid, bool* value); @@ -52,7 +52,7 @@ int stt_dbus_request_set_stop_sound(int uid, const char* file); int stt_dbus_request_unset_stop_sound(int uid); -int stt_dbus_request_start(int uid, const char* lang, const char* type, int silence, const char* appid); +int stt_dbus_request_start(int uid, const char* lang, const char* type, int silence, const char* appid, const char* credential); int stt_dbus_request_stop(int uid); diff --git a/client/stt_setting.c b/client/stt_setting.c index 974d2b4..118b74a 100644 --- a/client/stt_setting.c +++ b/client/stt_setting.c @@ -39,12 +39,12 @@ const char* stt_tag() return "sttc"; } -void __config_engine_changed_cb(const char* engine_id, const char* setting, const char* language, bool support_silence, void* user_data) +void __config_engine_changed_cb(const char* engine_id, const char* setting, const char* language, bool support_silence, bool need_credential, void* user_data) { if (NULL != engine_id) SECURE_SLOG(LOG_DEBUG, TAG_STTC, "Engine id(%s)", engine_id); if (NULL != setting) SECURE_SLOG(LOG_DEBUG, TAG_STTC, "Engine setting(%s)", setting); if (NULL != language) SECURE_SLOG(LOG_DEBUG, TAG_STTC, "Language(%s)", language); - SECURE_SLOG(LOG_DEBUG, TAG_STTC, "Silence(%s)", support_silence ? "on" : "off"); + SLOG(LOG_DEBUG, TAG_STTC, "Silence(%s), Credential(%s)", support_silence ? "on" : "off", need_credential ? "need" : "no need"); if (NULL != g_config_changed_cb) g_engine_changed_cb(g_config_changed_user_data); diff --git a/common/stt_config_mgr.c b/common/stt_config_mgr.c old mode 100755 new mode 100644 index 4df6b14..1cf7c50 --- a/common/stt_config_mgr.c +++ b/common/stt_config_mgr.c @@ -193,11 +193,12 @@ Eina_Bool stt_config_mgr_inotify_event_cb(void* data, Ecore_Fd_Handler *fd_handl char* lang = NULL; int auto_lang = -1; int silence = -1; + int credential = -1; GSList *iter = NULL; stt_config_client_s* temp_client = NULL; - if (0 != stt_parser_find_config_changed(&engine, &setting, &auto_lang, &lang, &silence)) + if (0 != stt_parser_find_config_changed(&engine, &setting, &auto_lang, &lang, &silence, &credential)) return ECORE_CALLBACK_PASS_ON; /* Engine changed */ @@ -220,6 +221,8 @@ Eina_Bool stt_config_mgr_inotify_event_cb(void* data, Ecore_Fd_Handler *fd_handl if (-1 != silence) g_config_info->silence_detection = silence; + if (-1 != credential) g_config_info->credential = credential; + /* Call all callbacks of client*/ iter = g_slist_nth(g_config_client_list, 0); @@ -229,7 +232,7 @@ Eina_Bool stt_config_mgr_inotify_event_cb(void* data, Ecore_Fd_Handler *fd_handl if (NULL != temp_client) { if (NULL != temp_client->engine_cb) { temp_client->engine_cb(g_config_info->engine_id, g_config_info->setting, g_config_info->language, - g_config_info->silence_detection, temp_client->user_data); + g_config_info->silence_detection, g_config_info->credential, temp_client->user_data); } } @@ -633,9 +636,10 @@ int __stt_config_mgr_check_engine_is_valid(const char* engine_id) SLOG(LOG_DEBUG, stt_tag(), " Setting : %s", g_config_info->setting); SLOG(LOG_DEBUG, stt_tag(), " language : %s", g_config_info->language); SLOG(LOG_DEBUG, stt_tag(), " Silence detection : %s", g_config_info->silence_detection ? "on" : "off"); + SLOG(LOG_DEBUG, stt_tag(), " Credential : %s", g_config_info->credential ? "true" : "false"); if (0 != stt_parser_set_engine(g_config_info->engine_id, g_config_info->setting, g_config_info->language, - g_config_info->silence_detection)) { + g_config_info->silence_detection, g_config_info->credential)) { SLOG(LOG_ERROR, stt_tag(), " Fail to save config"); return STT_CONFIG_ERROR_OPERATION_FAILED; } @@ -783,6 +787,7 @@ int stt_config_mgr_initialize(int uid) SLOG(LOG_DEBUG, stt_tag(), " auto language : %s", g_config_info->auto_lang ? "on" : "off"); SLOG(LOG_DEBUG, stt_tag(), " language : %s", g_config_info->language); SLOG(LOG_DEBUG, stt_tag(), " silence detection : %s", g_config_info->silence_detection ? "on" : "off"); + SLOG(LOG_DEBUG, stt_tag(), " credential : %s", g_config_info->credential ? "true" : "false"); SLOG(LOG_DEBUG, stt_tag(), "==================="); if (0 != __stt_config_mgr_register_config_event()) { @@ -1094,6 +1099,11 @@ int stt_config_mgr_set_engine(const char* engine) g_config_info->silence_detection = false; } + if (false == engine_info->need_credential) { + if (true == g_config_info->credential) + g_config_info->credential = false; + } + is_valid_engine = true; break; } @@ -1104,9 +1114,10 @@ int stt_config_mgr_set_engine(const char* engine) SLOG(LOG_DEBUG, stt_tag(), " Setting : %s", g_config_info->setting); SLOG(LOG_DEBUG, stt_tag(), " language : %s", g_config_info->language); SLOG(LOG_DEBUG, stt_tag(), " Silence detection : %s", g_config_info->silence_detection ? "on" : "off"); + SLOG(LOG_DEBUG, stt_tag(), " Credential : %s", g_config_info->credential ? "true" : "false"); if (0 != stt_parser_set_engine(g_config_info->engine_id, g_config_info->setting, g_config_info->language, - g_config_info->silence_detection)) { + g_config_info->silence_detection, g_config_info->credential)) { SLOG(LOG_ERROR, stt_tag(), " Fail to save config"); return STT_CONFIG_ERROR_OPERATION_FAILED; } diff --git a/common/stt_config_mgr.h b/common/stt_config_mgr.h old mode 100755 new mode 100644 index b6b024e..758662b --- a/common/stt_config_mgr.h +++ b/common/stt_config_mgr.h @@ -42,7 +42,7 @@ typedef bool (*stt_config_supported_engine_cb)(const char* engine_id, const char typedef bool (*stt_config_supported_langauge_cb)(const char* engine_id, const char* language, void* user_data); -typedef void (*stt_config_engine_changed_cb)(const char* engine_id, const char* setting, const char* language, bool support_silence, void* user_data); +typedef 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); typedef void (*stt_config_lang_changed_cb)(const char* before_language, const char* current_language, void* user_data); diff --git a/common/stt_config_parser.c b/common/stt_config_parser.c old mode 100755 new mode 100644 index dadfed4..8116ba4 --- a/common/stt_config_parser.c +++ b/common/stt_config_parser.c @@ -26,6 +26,7 @@ #define STT_TAG_ENGINE_LANGUAGE_SET "languages" #define STT_TAG_ENGINE_LANGUAGE "lang" #define STT_TAG_ENGINE_SILENCE_SUPPORT "silence-detection-support" +#define STT_TAG_ENGINE_CREDENTIAL_NEED "app-credential-need" #define STT_TAG_CONFIG_BASE_TAG "stt-config" #define STT_TAG_CONFIG_ENGINE_ID "engine" @@ -33,6 +34,7 @@ #define STT_TAG_CONFIG_AUTO_LANGUAGE "auto" #define STT_TAG_CONFIG_LANGUAGE "language" #define STT_TAG_CONFIG_SILENCE_DETECTION "silence-detection" +#define STT_TAG_CONFIG_CREDENTIAL "credential" #define STT_TAG_TIME_BASE_TAG "stt-time" @@ -98,6 +100,7 @@ int stt_parser_get_engine_info(const char* path, stt_engine_info_s** engine_info temp->agreement = NULL; temp->languages = NULL; temp->support_silence_detection = false; + temp->need_credential = false; while (cur != NULL) { if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_ENGINE_NAME)) { @@ -175,6 +178,20 @@ int stt_parser_get_engine_info(const char* path, stt_engine_info_s** engine_info } else { SLOG(LOG_ERROR, stt_tag(), "[ERROR] <%s> has no content", STT_TAG_ENGINE_SILENCE_SUPPORT); } + } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_ENGINE_CREDENTIAL_NEED)) { + key = xmlNodeGetContent(cur); + if (NULL != key) { + //SLOG(LOG_DEBUG, stt_tag(), "app-credential-need : %s", (char *)key); + + if (0 == xmlStrcmp(key, (const xmlChar *)"true")) + temp->need_credential = true; + else + temp->need_credential = false; + + xmlFree(key); + } else { + SLOG(LOG_ERROR, stt_tag(), "[ERROR] <%s> has no content", STT_TAG_ENGINE_CREDENTIAL_NEED); + } } else { } @@ -261,6 +278,7 @@ int stt_parser_print_engine_info(stt_engine_info_s* engine_info) SLOG(LOG_ERROR, stt_tag(), " language is NONE"); } SLOG(LOG_DEBUG, stt_tag(), " silence support : %s", engine_info->support_silence_detection ? "true" : "false"); + SLOG(LOG_DEBUG, stt_tag(), " credential need : %s", engine_info->need_credential ? "true" : "false"); SLOG(LOG_DEBUG, stt_tag(), "====================="); return 0; @@ -385,6 +403,20 @@ int stt_parser_load_config(stt_config_s** config_info) } else { SLOG(LOG_ERROR, stt_tag(), "[ERROR] silence-detection is NULL"); } + } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_CONFIG_CREDENTIAL)) { + key = xmlNodeGetContent(cur); + if (NULL != key) { + //SLOG(LOG_DEBUG, stt_tag(), "credential : %s", (char *)key); + + if (0 == xmlStrcmp(key, (const xmlChar *)"true")) + temp->credential = true; + else + temp->credential = false; + + xmlFree(key); + } else { + SLOG(LOG_ERROR, stt_tag(), "[ERROR] credential is NULL"); + } } else { } @@ -415,7 +447,7 @@ int stt_parser_unload_config(stt_config_s* config_info) return 0; } -int stt_parser_set_engine(const char* engine_id, const char* setting, const char* language, bool silence) +int stt_parser_set_engine(const char* engine_id, const char* setting, const char* language, bool silence, bool credential) { if (NULL == g_config_doc || NULL == engine_id) return -1; @@ -458,6 +490,13 @@ int stt_parser_set_engine(const char* engine_id, const char* setting, const char xmlNodeSetContent(cur, (const xmlChar *)"off"); } + if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_CONFIG_CREDENTIAL)) { + if (true == credential) + xmlNodeSetContent(cur, (const xmlChar *)"true"); + else + xmlNodeSetContent(cur, (const xmlChar *)"false"); + } + cur = cur->next; } @@ -589,9 +628,9 @@ int stt_parser_set_silence_detection(bool value) return 0; } -int stt_parser_find_config_changed(char** engine, char** setting, int* auto_lang, char** language, int* silence) +int stt_parser_find_config_changed(char** engine, char** setting, int* auto_lang, char** language, int* silence, int* credential) { - if (NULL == engine || NULL == language || NULL == silence) { + if (NULL == engine || NULL == language || NULL == silence || NULL == credential) { SLOG(LOG_ERROR, stt_tag(), "[ERROR] Input parameter is NULL"); return -1; } @@ -734,6 +773,28 @@ int stt_parser_find_config_changed(char** engine, char** setting, int* auto_lang } else { SLOG(LOG_ERROR, stt_tag(), "[ERROR] old config and new config are different"); } + } else if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)STT_TAG_CONFIG_CREDENTIAL)) { + if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)STT_TAG_CONFIG_CREDENTIAL)) { + key_old = xmlNodeGetContent(cur_old); + if (NULL != key_old) { + key_new = xmlNodeGetContent(cur_new); + if (NULL != key_new) { + if (0 != xmlStrcmp(key_old, key_new)) { + SLOG(LOG_DEBUG, stt_tag(), "Old credential(%s), New credential(%s)", (char*)key_old, (char*)key_new); + if (0 == xmlStrcmp(key_new, (const xmlChar*)"true")) { + *credential = 1; + } else { + *credential = 0; + } + } + xmlFree(key_new); + } + xmlFree(key_old); + } + } else { + SLOG(LOG_ERROR, stt_tag(), "[ERROR] old config and new config are different"); + } + } else { } diff --git a/common/stt_config_parser.h b/common/stt_config_parser.h old mode 100755 new mode 100644 index 81ca0cf..edd7b23 --- a/common/stt_config_parser.h +++ b/common/stt_config_parser.h @@ -30,6 +30,7 @@ typedef struct { char* agreement; GSList* languages; bool support_silence_detection; + bool need_credential; } stt_engine_info_s; typedef struct { @@ -38,6 +39,7 @@ typedef struct { bool auto_lang; char* language; bool silence_detection; + bool credential; } stt_config_s; typedef struct { @@ -58,7 +60,7 @@ int stt_parser_load_config(stt_config_s** config_info); int stt_parser_unload_config(stt_config_s* config_info); -int stt_parser_set_engine(const char* engine_id, const char* setting, const char* language, bool silence); +int stt_parser_set_engine(const char* engine_id, const char* setting, const char* language, bool silence, bool credential); int stt_parser_set_language(const char* language); @@ -66,7 +68,7 @@ int stt_parser_set_auto_lang(bool value); int stt_parser_set_silence_detection(bool value); -int stt_parser_find_config_changed(char** engine, char** setting, int* auto_lang, char** language, int* silence); +int stt_parser_find_config_changed(char** engine, char** setting, int* auto_lang, char** language, int* silence, int* credential); /* Time info */ diff --git a/common/stt_engine.c b/common/stt_engine.c index 3bc518a..8fce3c9 100644 --- a/common/stt_engine.c +++ b/common/stt_engine.c @@ -48,9 +48,14 @@ static const char* __stt_get_engine_error_code(sttp_error_e err) case STTP_ERROR_OUT_OF_MEMORY: return "STTP_ERROR_OUT_OF_MEMORY"; case STTP_ERROR_IO_ERROR: return "STTP_ERROR_IO_ERROR"; case STTP_ERROR_INVALID_PARAMETER: return "STTP_ERROR_INVALID_PARAMETER"; + case STTP_ERROR_TIMED_OUT: return "STTP_ERROR_TIMED_OUT"; + case STTP_ERROR_RECORDER_BUSY: return "STTP_ERROR_RECORDER_BUSY"; case STTP_ERROR_OUT_OF_NETWORK: return "STTP_ERROR_OUT_OF_NETWORK"; + case STTP_ERROR_PERMISSION_DENIED: return "STTP_ERROR_PERMISSION_DENIED"; + case STTP_ERROR_NOT_SUPPORTED: return "STTP_ERROR_NOT_SUPPORTED"; case STTP_ERROR_INVALID_STATE: return "STTP_ERROR_INVALID_STATE"; case STTP_ERROR_INVALID_LANGUAGE: return "STTP_ERROR_INVALID_LANGUAGE"; + case STTP_ERROR_ENGINE_NOT_FOUND: return "STTP_ERROR_ENGINE_NOT_FOUND"; case STTP_ERROR_OPERATION_FAILED: return "STTP_ERROR_OPERATION_FAILED"; case STTP_ERROR_NOT_SUPPORTED_FEATURE: return "STTP_ERROR_NOT_SUPPORTED_FEATURE"; default: @@ -422,6 +427,31 @@ int stt_engine_support_silence(int engine_id, bool* support) return 0; } + +int stt_engine_need_app_credential(int engine_id, bool* need) +{ + if (NULL == need) { + SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] Invalid Parameter"); + return STTP_ERROR_INVALID_PARAMETER; + } + + sttengine_s* engine = NULL; + engine = __get_engine(engine_id); + if (NULL == engine) { + SECURE_SLOG(LOG_WARN, stt_tag(), "[Engine WARNING] engine id(%d) is invalid", engine_id); + return STTP_ERROR_INVALID_PARAMETER; + } + + bool result; + if (NULL != engine->pefuncs->need_app_credential) { + result = engine->pefuncs->need_app_credential(); + *need = result; + return STTP_ERROR_NONE; + } + + return STTP_ERROR_OPERATION_FAILED; +} + int stt_engine_support_recognition_type(int engine_id, const char* type, bool* support) { if (NULL == type || NULL == support) { @@ -518,7 +548,7 @@ int stt_engine_check_app_agreed(int engine_id, const char* appid, bool* value) } /* Recognition */ -int stt_engine_recognize_start(int engine_id, const char* lang, const char* recognition_type, void* user_param) +int stt_engine_recognize_start(int engine_id, const char* lang, const char* recognition_type, const char* credential, void* user_param) { if (NULL == lang || NULL == recognition_type) { SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] Invalid Parameter"); @@ -532,9 +562,10 @@ int stt_engine_recognize_start(int engine_id, const char* lang, const char* reco return STTP_ERROR_INVALID_PARAMETER; } - int ret = engine->pefuncs->start(lang, recognition_type, user_param); + int ret = engine->pefuncs->start(lang, recognition_type, credential, user_param); if (0 != ret) { SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] Fail to start recognition : %s", __stt_get_engine_error_code(ret)); + SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] Fail to start recognition : lang(%s), recognition_type(%s), credential(%s)", lang, recognition_type, credential); return STTP_ERROR_OPERATION_FAILED; } diff --git a/common/stt_engine.h b/common/stt_engine.h index 2e80eb1..d386bf0 100644 --- a/common/stt_engine.h +++ b/common/stt_engine.h @@ -49,6 +49,8 @@ int stt_engine_get_first_language(int engine_id, char** language); int stt_engine_support_silence(int engine_id, bool* support); +int stt_engine_need_app_credential(int engine_id, bool* need); + int stt_engine_support_recognition_type(int engine_id, const char* type, bool* support); int stt_engine_get_audio_type(int engine_id, sttp_audio_type_e* types, int* rate, int* channels); @@ -60,7 +62,7 @@ int stt_engine_set_silence_detection(int engine_id, bool value); int stt_engine_check_app_agreed(int engine_id, const char* appid, bool* value); /* Recognition */ -int stt_engine_recognize_start(int engine_id, const char* lang, const char* recognition_type, void* user_param); +int stt_engine_recognize_start(int engine_id, const char* lang, const char* recognition_type, const char* credential, void* user_param); int stt_engine_set_recording_data(int engine_id, const void* data, unsigned int length); diff --git a/include/stt.h b/include/stt.h index 6e8a4a9..219ddda 100644 --- a/include/stt.h +++ b/include/stt.h @@ -296,6 +296,22 @@ typedef void (*stt_default_language_changed_cb)(stt_h stt, const char* previous_ const char* current_language, void* user_data); /** + * @brief Called when the engine is changed. + * @since_tizen 3.0 + * + * @param[in] stt The STT handle + * @param[in] engine_id Engine id + * @param[in] language The default language + * @param[in] support_silence support silence detection + * @param[in] need_credential necessity of credential + * @param[in] user_data The user data passed from the callback registration function + * + * @see stt_set_engine_changed_cb() +*/ +typedef bool (*stt_engine_changed_cb)(stt_h stt, const char* engine_id, const char* language, + bool support_silence, bool need_credential, void* user_data); + +/** * @brief Creates a STT handle. * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif * @privlevel public @@ -407,6 +423,27 @@ int stt_get_engine(stt_h stt, char** engine_id); int stt_set_engine(stt_h stt, const char* engine_id); /** + * @brief Sets the app credential. + * @since_tizen 3.0 + * @privlevel public + * @privilege %http://tizen.org/privilege/recorder + * + * @param[in] stt The STT handle + * @param[in] credential The app credential + * + * @return 0 on success, otherwise a negative error value + * @retval #STT_ERROR_NONE Success + * @retval #STT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #STT_ERROR_NOT_SUPPORTED STT NOT supported + * + * @pre The state should be #STT_STATE_CREATED or #STT_STATE_READY. + * + * @see stt_start() +*/ + +int stt_set_credential(stt_h stt, const char* credential); + +/** * @brief Connects the daemon asynchronously. * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif * @privlevel public diff --git a/server/sttd_config.c b/server/sttd_config.c index 229a087..71af39d 100644 --- a/server/sttd_config.c +++ b/server/sttd_config.c @@ -32,7 +32,7 @@ const char* stt_tag() } -void __sttd_config_engine_changed_cb(const char* engine_id, const char* setting, const char* language, bool support_silence, void* user_data) +void __sttd_config_engine_changed_cb(const char* engine_id, const char* setting, const char* language, bool support_silence, bool need_credential, void* user_data) { /* Need to check engine is valid */ if (false == stt_config_check_default_engine_is_valid(engine_id)) { @@ -41,7 +41,7 @@ void __sttd_config_engine_changed_cb(const char* engine_id, const char* setting, } if (NULL != g_engine_cb) - g_engine_cb(engine_id, language, support_silence, g_user_data); + g_engine_cb(engine_id, language, support_silence, need_credential, g_user_data); else SLOG(LOG_ERROR, TAG_STTD, "Engine changed callback is NULL"); } diff --git a/server/sttd_config.h b/server/sttd_config.h index c14a6f0..1f58534 100644 --- a/server/sttd_config.h +++ b/server/sttd_config.h @@ -19,7 +19,7 @@ extern "C" { #endif -typedef void (*sttd_config_engine_changed_cb)(const char* engine_id, const char* language, bool support_silence, void* user_data); +typedef void (*sttd_config_engine_changed_cb)(const char* engine_id, const char* language, bool support_silence, bool need_credential, void* user_data); typedef void (*sttd_config_language_changed_cb)(const char* language, void* user_data); diff --git a/server/sttd_dbus_server.c b/server/sttd_dbus_server.c index c693317..39d6f4f 100644 --- a/server/sttd_dbus_server.c +++ b/server/sttd_dbus_server.c @@ -54,6 +54,7 @@ int sttd_dbus_server_initialize(DBusConnection* conn, DBusMessage* msg) int pid; int uid; bool silence_supported = false; + bool credential_needed = false; int ret = STTD_ERROR_OPERATION_FAILED; @@ -70,7 +71,7 @@ int sttd_dbus_server_initialize(DBusConnection* conn, DBusMessage* msg) ret = STTD_ERROR_OPERATION_FAILED; } else { SLOG(LOG_DEBUG, TAG_STTD, "[IN] stt initialize : pid(%d), uid(%d)", pid , uid); - ret = sttd_server_initialize(pid, uid, &silence_supported); + ret = sttd_server_initialize(pid, uid, &silence_supported, &credential_needed); } DBusMessage* reply; @@ -80,11 +81,12 @@ int sttd_dbus_server_initialize(DBusConnection* conn, DBusMessage* msg) dbus_message_append_args(reply, DBUS_TYPE_INT32, &ret, DBUS_TYPE_INT32, &silence_supported, + DBUS_TYPE_INT32, &credential_needed, DBUS_TYPE_INVALID); if (0 == ret) { - SLOG(LOG_DEBUG, TAG_STTD, "[OUT SUCCESS] Result(%d), silence(%d)", - ret, silence_supported); + SLOG(LOG_DEBUG, TAG_STTD, "[OUT SUCCESS] Result(%d), silence(%d), credential(%d)", + ret, silence_supported, credential_needed); } else { SLOG(LOG_ERROR, TAG_STTD, "[OUT ERROR] Result(%d)", ret); } @@ -256,6 +258,7 @@ int sttd_dbus_server_set_current_engine(DBusConnection* conn, DBusMessage* msg) int uid; char* engine_id; bool silence_supported = false; + bool credential_needed = false; int ret = STTD_ERROR_OPERATION_FAILED; dbus_message_get_args(msg, &err, @@ -271,7 +274,7 @@ int sttd_dbus_server_set_current_engine(DBusConnection* conn, DBusMessage* msg) ret = STTD_ERROR_OPERATION_FAILED; } else { SLOG(LOG_DEBUG, TAG_STTD, "[IN] stt set current engine : uid(%d)", uid); - ret = sttd_server_set_current_engine(uid, engine_id, &silence_supported); + ret = sttd_server_set_current_engine(uid, engine_id, &silence_supported, &credential_needed); } DBusMessage* reply; @@ -281,11 +284,12 @@ int sttd_dbus_server_set_current_engine(DBusConnection* conn, DBusMessage* msg) dbus_message_append_args(reply, DBUS_TYPE_INT32, &ret, DBUS_TYPE_INT32, &silence_supported, + DBUS_TYPE_INT32, &credential_needed, DBUS_TYPE_INVALID); if (0 == ret) { - SLOG(LOG_DEBUG, TAG_STTD, "[OUT SUCCESS] Result(%d), silence(%d)", - ret, silence_supported); + SLOG(LOG_DEBUG, TAG_STTD, "[OUT SUCCESS] Result(%d), silence(%d), credential(%d)", + ret, silence_supported, credential_needed); } else { SLOG(LOG_ERROR, TAG_STTD, "[OUT ERROR] Result(%d) ", ret); } @@ -834,6 +838,7 @@ int sttd_dbus_server_start(DBusConnection* conn, DBusMessage* msg) char* type; char* appid; int silence; + char* credential; int ret = STTD_ERROR_OPERATION_FAILED; dbus_message_get_args(msg, &err, @@ -842,6 +847,7 @@ int sttd_dbus_server_start(DBusConnection* conn, DBusMessage* msg) DBUS_TYPE_STRING, &type, DBUS_TYPE_INT32, &silence, DBUS_TYPE_STRING, &appid, + DBUS_TYPE_STRING, &credential, DBUS_TYPE_INVALID); SLOG(LOG_DEBUG, TAG_STTD, ">>>>> STT Start"); @@ -851,9 +857,9 @@ int sttd_dbus_server_start(DBusConnection* conn, DBusMessage* msg) dbus_error_free(&err); ret = STTD_ERROR_OPERATION_FAILED; } else { - SLOG(LOG_DEBUG, TAG_STTD, "[IN] stt start : uid(%d), lang(%s), type(%s), silence(%d) appid(%s)" - , uid, lang, type, silence, appid); - ret = sttd_server_start(uid, lang, type, silence, appid); + SLOG(LOG_DEBUG, TAG_STTD, "[IN] stt start : uid(%d), lang(%s), type(%s), silence(%d) appid(%s) credential(%s)" + , uid, lang, type, silence, appid, credential); + ret = sttd_server_start(uid, lang, type, silence, appid, credential); } if (0 <= ret) { diff --git a/server/sttd_engine_agent.c b/server/sttd_engine_agent.c index 9f3d4b8..07ac6fd 100644 --- a/server/sttd_engine_agent.c +++ b/server/sttd_engine_agent.c @@ -51,6 +51,7 @@ typedef struct _sttengine_info { char* first_lang; bool silence_detection; bool support_silence_detection; + bool need_credential; } sttengine_info_s; /** stt engine agent init */ @@ -950,6 +951,44 @@ int sttd_engine_agent_get_option_supported(int uid, bool* silence) return 0; } +int sttd_engine_agent_is_credential_needed(int uid, bool* credential) +{ + if (false == g_agent_init) { + SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized"); + return STTD_ERROR_OPERATION_FAILED; + } + + if (NULL == credential) { + SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Invalid Parameter"); + return STTD_ERROR_INVALID_PARAMETER; + } + + sttengine_info_s* engine = NULL; + engine = __engine_agent_get_engine_by_uid(uid); + + if (NULL == engine) { + SECURE_SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] uid(%d) is not valid", uid); + return STTD_ERROR_INVALID_PARAMETER; + } + + if (false == engine->is_loaded) { + SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not loaded engine"); + return STTD_ERROR_OPERATION_FAILED; + } + + bool temp = false; + int ret; + + ret = stt_engine_need_app_credential(engine->engine_id, &temp); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to get to support recognition type : %d", ret); + return STTD_ERROR_OPERATION_FAILED; + } + + *credential = temp; + return 0; +} + int sttd_engine_agent_is_recognition_type_supported(int uid, const char* type, bool* support) { if (false == g_agent_init) { @@ -1026,7 +1065,7 @@ int __set_option(sttengine_info_s* engine, int silence) } int sttd_engine_agent_recognize_start_engine(int uid, const char* lang, const char* recognition_type, - int silence, void* user_param) + int silence, const char* credential, void* user_param) { if (false == g_agent_init) { SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized"); @@ -1080,7 +1119,7 @@ int sttd_engine_agent_recognize_start_engine(int uid, const char* lang, const ch SLOG(LOG_DEBUG, TAG_STTD, "[Engine Agent] Start engine"); - ret = stt_engine_recognize_start(engine->engine_id, temp, recognition_type, user_param); + ret = stt_engine_recognize_start(engine->engine_id, temp, recognition_type, credential, user_param); if (NULL != temp) free(temp); if (0 != ret) { SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Recognition start error(%d)", ret); diff --git a/server/sttd_engine_agent.h b/server/sttd_engine_agent.h index dc2ebf2..4447110 100644 --- a/server/sttd_engine_agent.h +++ b/server/sttd_engine_agent.h @@ -75,6 +75,8 @@ int sttd_engine_agent_get_default_lang(int uid, char** lang); int sttd_engine_agent_get_option_supported(int uid, bool* silence); +int sttd_engine_agent_is_credential_needed(int uid, bool* credential); + int sttd_engine_agent_is_recognition_type_supported(int uid, const char* type, bool* support); int sttd_engine_agent_set_default_engine(const char* engine_uuid); @@ -87,7 +89,7 @@ int sttd_engine_agent_check_app_agreed(int uid, const char* appid, bool* result) /** Control engine */ int sttd_engine_agent_recognize_start_engine(int uid, const char* lang, const char* recognition_type, - int silence, void* user_param); + int silence, const char* credential, void* user_param); int sttd_engine_agent_recognize_start_recorder(int uid); diff --git a/server/sttd_server.c b/server/sttd_server.c index c1b9b1c..cdf7afc 100644 --- a/server/sttd_server.c +++ b/server/sttd_server.c @@ -349,7 +349,7 @@ void __server_silence_dectection_callback(sttp_silence_type_e type, void *user_p return; } -void __sttd_server_engine_changed_cb(const char* engine_id, const char* language, bool support_silence, void* user_data) +void __sttd_server_engine_changed_cb(const char* engine_id, const char* language, bool support_silence, bool need_credential, void* user_data) { if (NULL == engine_id) { SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Engine id is NULL"); @@ -603,7 +603,7 @@ Eina_Bool sttd_cleanup_client(void *data) * STT Server Functions for Client */ -int sttd_server_initialize(int pid, int uid, bool* silence) +int sttd_server_initialize(int pid, int uid, bool* silence, bool* credential) { if (false == sttd_engine_agent_is_default_engine()) { /* Update installed engine */ @@ -633,6 +633,11 @@ int sttd_server_initialize(int pid, int uid, bool* silence) return STTD_ERROR_OPERATION_FAILED; } + if (0 != sttd_engine_agent_is_credential_needed(uid, credential)) { + SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to get credential necessity"); + return STTD_ERROR_OPERATION_FAILED; + } + /* Add client information to client manager */ if (0 != sttd_client_add(pid, uid)) { SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to add client info"); @@ -723,7 +728,7 @@ int sttd_server_get_supported_engines(int uid, GSList** engine_list) 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; @@ -751,6 +756,11 @@ int sttd_server_set_current_engine(int uid, const char* engine_id, bool* silence return STTD_ERROR_OPERATION_FAILED; } + if (0 != sttd_engine_agent_is_credential_needed(uid, credential)) { + SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to get credential necessity"); + return STTD_ERROR_OPERATION_FAILED; + } + return STTD_ERROR_NONE; } @@ -1017,7 +1027,7 @@ void __sttd_start_sound_completed_cb(int id, void *user_data) return; } -int sttd_server_start(int uid, const char* lang, const char* recognition_type, int silence, const char* appid) +int sttd_server_start(int uid, const char* lang, const char* recognition_type, int silence, const char* appid, const char* credential) { if (NULL == lang || NULL == recognition_type) { SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Input parameter is NULL"); @@ -1107,7 +1117,7 @@ int sttd_server_start(int uid, const char* lang, const char* recognition_type, i } /* 3. Create recorder & engine initialize */ - ret = sttd_engine_agent_recognize_start_engine(uid, lang, recognition_type, silence, NULL); + ret = sttd_engine_agent_recognize_start_engine(uid, lang, recognition_type, silence, credential, NULL); if (0 != ret) { stt_client_unset_current_recognition(); sttd_recorder_unset_audio_session(); diff --git a/server/sttd_server.h b/server/sttd_server.h index 8f6e1e7..5978f17 100644 --- a/server/sttd_server.h +++ b/server/sttd_server.h @@ -38,13 +38,13 @@ Eina_Bool sttd_get_daemon_exist(); * API for client */ -int sttd_server_initialize(int pid, int uid, bool* silence); +int sttd_server_initialize(int pid, int uid, bool* silence, bool* credential); int sttd_server_finalize(int uid); int sttd_server_get_supported_engines(int uid, GSList** engine_list); -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); int sttd_server_get_current_engine(int uid, char** engine_id); @@ -65,7 +65,7 @@ int sttd_server_set_stop_sound(int uid, const char* file); int sttd_server_get_audio_volume(int uid, float* current_volume); -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); int sttd_server_stop(int uid); diff --git a/server/sttp.h b/server/sttp.h old mode 100755 new mode 100644 index cd20c6b..9d9b0c1 --- a/server/sttp.h +++ b/server/sttp.h @@ -14,7 +14,7 @@ #ifndef __STTP_H__ #define __STTP_H__ -#include +#include #include /** @@ -30,16 +30,21 @@ extern "C" { * @brief Enumerations of error codes. */ typedef enum { - STTP_ERROR_NONE = 0, /**< Successful */ - STTP_ERROR_OUT_OF_MEMORY = -ENOMEM, /**< Out of Memory */ - STTP_ERROR_IO_ERROR = -EIO, /**< I/O error */ - STTP_ERROR_INVALID_PARAMETER = -EINVAL, /**< Invalid parameter */ - STTP_ERROR_OUT_OF_NETWORK = -ENETDOWN, /**< Out of network */ - STTP_ERROR_INVALID_STATE = -0x0100031, /**< Invalid state */ - STTP_ERROR_INVALID_LANGUAGE = -0x0100032, /**< Invalid language */ - STTP_ERROR_OPERATION_FAILED = -0x0100034, /**< Operation failed */ - STTP_ERROR_NOT_SUPPORTED_FEATURE = -0x0100035 /**< Not supported feature */ -} sttp_error_e; + STTP_ERROR_NONE = TIZEN_ERROR_NONE, /**< Successful */ + STTP_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_OUT_OF_MEMORY, /**< Out of Memory */ + STTP_ERROR_IO_ERROR = TIZEN_ERROR_IO_ERROR, /**< I/O error */ + STTP_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER,/**< Invalid parameter */ + STTP_ERROR_TIMED_OUT = TIZEN_ERROR_TIMED_OUT, /**< No answer from the daemon */ + STTP_ERROR_RECORDER_BUSY = TIZEN_ERROR_RESOURCE_BUSY, /**< Device or resource busy */ + STTP_ERROR_OUT_OF_NETWORK = TIZEN_ERROR_NETWORK_DOWN, /**< Network is down */ + STTP_ERROR_PERMISSION_DENIED = TIZEN_ERROR_PERMISSION_DENIED,/**< Permission denied */ + STTP_ERROR_NOT_SUPPORTED = TIZEN_ERROR_NOT_SUPPORTED, /**< STT NOT supported */ + STTP_ERROR_INVALID_STATE = TIZEN_ERROR_STT | 0x01, /**< Invalid state */ + STTP_ERROR_INVALID_LANGUAGE = TIZEN_ERROR_STT | 0x02, /**< Invalid language */ + STTP_ERROR_ENGINE_NOT_FOUND = TIZEN_ERROR_STT | 0x03, /**< No available engine */ + STTP_ERROR_OPERATION_FAILED = TIZEN_ERROR_STT | 0x04, /**< Operation failed */ + STTP_ERROR_NOT_SUPPORTED_FEATURE = TIZEN_ERROR_STT | 0x05 /**< Not supported feature of current engine */ +}sttp_error_e; /** * @brief Enumerations of audio type. @@ -265,6 +270,14 @@ typedef bool (*sttpe_is_valid_language)(const char* language); typedef bool (*sttpe_support_silence_detection)(void); /** +* @brief Gets credential necessity. +* +* @return @c true to be needed app credential, \n @c false not to be needed app credential. +* +*/ +typedef bool (* sttpe_need_app_credential)(void); + +/** * @brief Gets supporting recognition type. * * @return @c true to support recognition type, \n @c false not to support recognition type. @@ -333,6 +346,7 @@ typedef int (*sttpe_foreach_result_time)(void* time_info, sttpe_result_time_cb c * * @param[in] language A language. * @param[in] type A recognition type. (e.g. #STTP_RECOGNITION_TYPE_FREE, #STTP_RECOGNITION_TYPE_WEB_SEARCH) +* @parma[in] credential The app credential to allow recognition * @param[in] user_data The user data to be passed to the callback function. * * @return 0 on success, otherwise a negative error value @@ -349,7 +363,7 @@ typedef int (*sttpe_foreach_result_time)(void* time_info, sttpe_result_time_cb c * @see sttpe_stop() * @see sttpe_cancel() */ -typedef int (*sttpe_start)(const char* language, const char* type, void *user_data); +typedef int (* sttpe_start)(const char* language, const char* type, const char* credential, void *user_data); /** * @brief Sets recording data for speech recognition from recorder. @@ -458,6 +472,7 @@ typedef struct { sttpe_is_valid_language is_valid_lang; /**< Check language */ sttpe_support_silence_detection support_silence; /**< Get silence detection support */ sttpe_support_recognition_type support_recognition_type; /**< Get recognition type support */ + sttpe_need_app_credential need_app_credential; /**< Get app credential necessity*/ sttpe_get_recording_format get_audio_format; /**< Get audio format */ sttpe_foreach_result_time foreach_result_time; /**< Foreach result time */ diff --git a/stt-config.xml b/stt-config.xml index 5f4108e..fc667d0 100644 --- a/stt-config.xml +++ b/stt-config.xml @@ -5,4 +5,5 @@ on en_US on + false -- 2.7.4