From 27eadda0d8475576f474062bf24129a64fb55bff Mon Sep 17 00:00:00 2001 From: Wonnam Jang Date: Fri, 27 May 2016 19:38:15 +0900 Subject: [PATCH] Add get/set private data function Change-Id: Ia1257edbe35b249382a1153d65d2539d6bda5057 Signed-off-by: Wonnam Jang --- client/stt.c | 125 ++++++++++++++++++++++++++++++++++++++ client/stt_dbus.c | 148 +++++++++++++++++++++++++++++++++++++++++++++ client/stt_dbus.h | 4 ++ common/stt_defs.h | 2 + common/stt_engine.c | 48 ++++++++++++++- common/stt_engine.h | 4 ++ include/stt.h | 44 ++++++++++++++ server/sttd_dbus.c | 6 ++ server/sttd_dbus_server.c | 115 +++++++++++++++++++++++++++++++++++ server/sttd_dbus_server.h | 4 ++ server/sttd_engine_agent.c | 72 ++++++++++++++++++++++ server/sttd_engine_agent.h | 4 ++ server/sttd_server.c | 54 +++++++++++++++++ server/sttd_server.h | 4 ++ server/sttp.h | 36 +++++++++++ 15 files changed, 669 insertions(+), 1 deletion(-) diff --git a/client/stt.c b/client/stt.c index f3af501..19e7cb1 100644 --- a/client/stt.c +++ b/client/stt.c @@ -248,6 +248,26 @@ void __stt_config_engine_changed_cb(const char* engine_id, const char* setting, 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) { if (0 != __stt_get_feature_enabled()) { @@ -575,6 +595,111 @@ int stt_set_credential(stt_h stt, const char* credential) 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; diff --git a/client/stt_dbus.c b/client/stt_dbus.c index 5a8f2f4..ee14cd8 100644 --- a/client/stt_dbus.c +++ b/client/stt_dbus.c @@ -889,6 +889,154 @@ int stt_dbus_request_get_default_lang(int uid, char** language) return result; } +int stt_dbus_request_set_private_data(int uid, const char* key, const char* data) +{ + if (NULL == key || NULL == data) { + SLOG(LOG_ERROR, TAG_STTC, "Input parameter is NULL"); + return STT_ERROR_INVALID_PARAMETER; + } + + DBusMessage* msg; + + msg = dbus_message_new_method_call( + STT_SERVER_SERVICE_NAME, + STT_SERVER_SERVICE_OBJECT_PATH, + STT_SERVER_SERVICE_INTERFACE, + STT_METHOD_SET_PRIVATE_DATA); + + if (NULL == msg) { + SLOG(LOG_ERROR, TAG_STTC, ">>>> stt set private data : Fail to make message"); + return STT_ERROR_OPERATION_FAILED; + } else { + SLOG(LOG_DEBUG, TAG_STTC, ">>>> stt set private data : uid(%d)", uid); + } + + if (true != dbus_message_append_args(msg, + DBUS_TYPE_INT32, &uid, + DBUS_TYPE_STRING, &key, + DBUS_TYPE_STRING, &data, + DBUS_TYPE_INVALID)) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to append args"); + return STT_ERROR_OPERATION_FAILED; + } + + DBusError err; + dbus_error_init(&err); + + DBusMessage* result_msg; + int result = STT_ERROR_OPERATION_FAILED; + + result_msg = dbus_connection_send_with_reply_and_block(g_conn_sender, msg, g_waiting_time, &err); + dbus_message_unref(msg); + if (dbus_error_is_set(&err)) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Send Error (%s)", err.message); + dbus_error_free(&err); + } + + if (NULL != result_msg) { + dbus_message_get_args(result_msg, &err, + DBUS_TYPE_INT32, &result, + DBUS_TYPE_INVALID); + + if (dbus_error_is_set(&err)) { + SLOG(LOG_ERROR, TAG_STTC, "<<<< Get arguments error (%s)", err.message); + dbus_error_free(&err); + result = STT_ERROR_OPERATION_FAILED; + } + dbus_message_unref(result_msg); + + if (0 == result) { + SLOG(LOG_DEBUG, TAG_STTC, "<<<< stt set private data : result = %d", result); + } else { + SLOG(LOG_ERROR, TAG_STTC, "<<<< stt set private data : result = %d", result); + } + } else { + SLOG(LOG_ERROR, TAG_STTC, "<<<< Result message is NULL"); + stt_dbus_reconnect(); + result = STT_ERROR_TIMED_OUT; + } + + return result; +} + +int stt_dbus_request_get_private_data(int uid, const char* key, char** data) +{ + if (NULL == key || NULL == data) { + SLOG(LOG_ERROR, TAG_STTC, "Input parameter is NULL"); + return STT_ERROR_INVALID_PARAMETER; + } + + DBusMessage* msg; + + msg = dbus_message_new_method_call( + STT_SERVER_SERVICE_NAME, + STT_SERVER_SERVICE_OBJECT_PATH, + STT_SERVER_SERVICE_INTERFACE, + STT_METHOD_GET_PRIVATE_DATA); + + if (NULL == msg) { + SLOG(LOG_ERROR, TAG_STTC, ">>>> stt get private data : Fail to make message"); + return STT_ERROR_OPERATION_FAILED; + } else { + SLOG(LOG_DEBUG, TAG_STTC, ">>>> stt get private data : uid(%d)", uid); + } + + if (true != dbus_message_append_args(msg, + DBUS_TYPE_INT32, &uid, + DBUS_TYPE_STRING, &key, + DBUS_TYPE_INVALID)) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to append args"); + return STT_ERROR_OPERATION_FAILED; + } + + DBusError err; + dbus_error_init(&err); + + DBusMessage* result_msg; + int result = STT_ERROR_OPERATION_FAILED; + + result_msg = dbus_connection_send_with_reply_and_block(g_conn_sender, msg, g_waiting_time, &err); + dbus_message_unref(msg); + if (dbus_error_is_set(&err)) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Send Error (%s)", err.message); + dbus_error_free(&err); + } + + char* temp = NULL; + if (NULL != result_msg) { + dbus_message_get_args(result_msg, &err, + DBUS_TYPE_INT32, &result, + DBUS_TYPE_STRING, &temp, + DBUS_TYPE_INVALID); + + if (dbus_error_is_set(&err)) { + SLOG(LOG_ERROR, TAG_STTC, "<<<< Get arguments error (%s)", err.message); + dbus_error_free(&err); + result = STT_ERROR_OPERATION_FAILED; + } + dbus_message_unref(result_msg); + + if (0 == result) { + SLOG(LOG_DEBUG, TAG_STTC, "<<<< stt get private data : result = %d", result); + if (NULL != temp) { + *data = strdup(temp); + free(temp); + temp = NULL; + } + } else { + SLOG(LOG_ERROR, TAG_STTC, "<<<< stt get private data : result = %d", result); + } + } else { + SLOG(LOG_ERROR, TAG_STTC, "<<<< Result message is NULL"); + stt_dbus_reconnect(); + result = STT_ERROR_TIMED_OUT; + } + + return result; +} + + + int stt_dbus_request_is_recognition_type_supported(int uid, const char* type, bool* support) { if (NULL == support || NULL == type) { diff --git a/client/stt_dbus.h b/client/stt_dbus.h index d48f773..8485e95 100644 --- a/client/stt_dbus.h +++ b/client/stt_dbus.h @@ -41,6 +41,10 @@ int stt_dbus_request_get_support_langs(int uid, stt_h stt, stt_supported_languag int stt_dbus_request_get_default_lang(int uid, char** language); +int stt_dbus_request_set_private_data(int uid, const char* key, const char* data); + +int stt_dbus_request_get_private_data(int uid, const char* key, char** data); + int stt_dbus_request_is_recognition_type_supported(int uid, const char* type, bool* support); int stt_dbus_request_set_start_sound(int uid, const char* file); diff --git a/common/stt_defs.h b/common/stt_defs.h index 4f7fc95..d37769c 100644 --- a/common/stt_defs.h +++ b/common/stt_defs.h @@ -46,6 +46,8 @@ extern "C" { #define STT_METHOD_GET_CURRENT_LANG "stt_method_get_current_lang" #define STT_METHOD_IS_TYPE_SUPPORTED "stt_method_is_recognition_type_supported" #define STT_METHOD_CHECK_APP_AGREED "stt_method_check_app_agreed" +#define STT_METHOD_SET_PRIVATE_DATA "stt_method_set_private_data" +#define STT_METHOD_GET_PRIVATE_DATA "stt_method_get_private_data" #define STT_METHOD_SET_START_SOUND "stt_method_set_start_sound" #define STT_METHOD_UNSET_START_SOUND "stt_method_unset_start_sound" diff --git a/common/stt_engine.c b/common/stt_engine.c index c2a8e16..e644512 100644 --- a/common/stt_engine.c +++ b/common/stt_engine.c @@ -350,6 +350,52 @@ int stt_engine_is_valid_language(int engine_id, const char* language, bool *is_v return 0; } +int stt_engine_set_private_data(int engine_id, const char* key, const char* data) +{ + if (NULL == key || NULL == data) { + 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; + } + + int ret = engine->pefuncs->set_private_data(key, data); + if (0 != ret) { + SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] Fail to set private data(%d)", ret); + } + return STTP_ERROR_NONE; +} + +int stt_engine_get_private_data(int engine_id, const char* key, char** data) +{ + if (NULL == key || NULL == data) { + 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; + } + + char* temp = NULL; + int ret = engine->pefuncs->get_private_data(key, &temp); + if (0 != ret) { + SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] Fail to set private data(%d)", ret); + } + + *data = strdup(temp); + + return STTP_ERROR_NONE; +} + int stt_engine_get_first_language(int engine_id, char** language) { if (NULL == language) { @@ -699,4 +745,4 @@ int stt_engine_recognize_cancel_file(int engine_id) } return 0; -} \ No newline at end of file +} diff --git a/common/stt_engine.h b/common/stt_engine.h index d386bf0..3b47936 100644 --- a/common/stt_engine.h +++ b/common/stt_engine.h @@ -45,6 +45,10 @@ int stt_engine_get_supported_langs(int engine_id, GSList** lang_list); int stt_engine_is_valid_language(int engine_id, const char* language, bool *is_valid); +int stt_engine_set_private_data(int engine_id, const char* key, const char* data); + +int stt_engine_get_private_data(int engine_id, const char* key, char** data); + int stt_engine_get_first_language(int engine_id, char** language); int stt_engine_support_silence(int engine_id, bool* support); diff --git a/include/stt.h b/include/stt.h index 0a83898..30b3ff7 100644 --- a/include/stt.h +++ b/include/stt.h @@ -445,6 +445,50 @@ int stt_set_engine(stt_h stt, const char* engine_id); int stt_set_credential(stt_h stt, const char* credential); /** + * @brief Sets the private data to stt engine. + * @since_tizen 3.0 + * + * @param[in] stt The STT handle + * @param[in] key The field name of private data + * @param[in] data The data for set + * + * @return 0 on success, otherwise a negative error value + * @retval #STT_ERROR_NONE Successful + * @retval #STT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #STT_ERROR_INVALID_STATE Invalid state + * @retval #STT_ERROR_PERMISSION_DENIED Permission denied + * @retval #STT_ERROR_NOT_SUPPORTED STT NOT supported + * @retval #STT_ERROR_TIMED_OUT No answer from the daemon + * + * @pre The state should be #STT_STATE_READY. + * + * @see stt_get_private_data() +*/ +int stt_set_private_data(stt_h stt, const char* key, const char* data); + +/** + * @brief Gets the private data from stt engine. + * @since_tizen 3.0 + * + * @param[in] stt The STT handle + * @param[in] key The field name of private data + * @param[out] data The data + * + * @return 0 on success, otherwise a negative error value + * @retval #STT_ERROR_NONE Successful + * @retval #STT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #STT_ERROR_INVALID_STATE Invalid state + * @retval #STT_ERROR_PERMISSION_DENIED Permission denied + * @retval #STT_ERROR_NOT_SUPPORTED STT NOT supported + * @retval #STT_ERROR_TIMED_OUT No answer from the daemon + * + * @pre The state should be #STT_STATE_READY. + * + * @see stt_set_private_data() +*/ +int stt_get_private_data(stt_h stt, const char* key, char** data); + +/** * @brief Connects the daemon asynchronously. * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif * @privlevel public diff --git a/server/sttd_dbus.c b/server/sttd_dbus.c index 86dd165..73646d8 100644 --- a/server/sttd_dbus.c +++ b/server/sttd_dbus.c @@ -384,6 +384,12 @@ static Eina_Bool listener_event_callback(void* data, Ecore_Fd_Handler *fd_handle else if (dbus_message_is_method_call(msg, STT_SERVER_SERVICE_INTERFACE, STT_METHOD_GET_CURRENT_LANG)) sttd_dbus_server_get_default_lang(g_conn_listener, msg); + else if (dbus_message_is_method_call(msg, STT_SERVER_SERVICE_INTERFACE, STT_METHOD_SET_PRIVATE_DATA)) + sttd_dbus_server_set_private_data(g_conn_listener, msg); + + else if (dbus_message_is_method_call(msg, STT_SERVER_SERVICE_INTERFACE, STT_METHOD_GET_PRIVATE_DATA)) + sttd_dbus_server_get_private_data(g_conn_listener, msg); + else if (dbus_message_is_method_call(msg, STT_SERVER_SERVICE_INTERFACE, STT_METHOD_IS_TYPE_SUPPORTED)) sttd_dbus_server_is_recognition_type_supported(g_conn_listener, msg); diff --git a/server/sttd_dbus_server.c b/server/sttd_dbus_server.c index 39d6f4f..47aa97b 100644 --- a/server/sttd_dbus_server.c +++ b/server/sttd_dbus_server.c @@ -563,6 +563,121 @@ int sttd_dbus_server_get_default_lang(DBusConnection* conn, DBusMessage* msg) return 0; } +int sttd_dbus_server_set_private_data(DBusConnection* conn, DBusMessage* msg) +{ + DBusError err; + dbus_error_init(&err); + + int uid; + char* key; + char* data; + int ret = 0; + dbus_message_get_args(msg, &err, + DBUS_TYPE_INT32, &uid, + DBUS_TYPE_STRING, &key, + DBUS_TYPE_STRING, &data, + DBUS_TYPE_INVALID); + + SLOG(LOG_DEBUG, TAG_STTD, ">>>>> STT Set private data"); + + if (dbus_error_is_set(&err)) { + SLOG(LOG_ERROR, TAG_STTD, "[IN ERROR] stt set private data : get arguments error (%s)", err.message); + dbus_error_free(&err); + ret = STTD_ERROR_OPERATION_FAILED; + } else { + SLOG(LOG_DEBUG, TAG_STTD, "[IN] stt set private data : uid(%d)", uid); + ret = sttd_server_set_private_data(uid, key, data); + } + + DBusMessage* reply; + reply = dbus_message_new_method_return(msg); + + if (NULL != reply) { + dbus_message_append_args(reply, + DBUS_TYPE_INT32, &ret, + DBUS_TYPE_INVALID); + + if (0 == ret) { + SLOG(LOG_DEBUG, TAG_STTD, "[OUT SUCCESS] Result(%d)", ret); + } else { + SLOG(LOG_ERROR, TAG_STTD, "[OUT ERROR] Result(%d)", ret); + } + + if (!dbus_connection_send(conn, reply, NULL)) { + SLOG(LOG_ERROR, TAG_STTD, "[OUT ERROR] Fail to send reply"); + } + + dbus_connection_flush(conn); + dbus_message_unref(reply); + } else { + SLOG(LOG_ERROR, TAG_STTD, "[OUT ERROR] Fail to create reply message!!"); + } + + SLOG(LOG_DEBUG, TAG_STTD, "<<<<<"); + SLOG(LOG_DEBUG, TAG_STTD, " "); + + return 0; +} + +int sttd_dbus_server_get_private_data(DBusConnection* conn, DBusMessage* msg) +{ + DBusError err; + dbus_error_init(&err); + + int uid; + char* key; + char* data; + int ret = 0; + dbus_message_get_args(msg, &err, + DBUS_TYPE_INT32, &uid, + DBUS_TYPE_STRING, &key, + DBUS_TYPE_INVALID); + + SLOG(LOG_DEBUG, TAG_STTD, ">>>>> STT Get private data"); + + if (dbus_error_is_set(&err)) { + SLOG(LOG_ERROR, TAG_STTD, "[IN ERROR] stt get private data : get arguments error (%s)", err.message); + dbus_error_free(&err); + ret = STTD_ERROR_OPERATION_FAILED; + } else { + SLOG(LOG_DEBUG, TAG_STTD, "[IN] stt get private data : uid(%d)", uid); + ret = sttd_server_get_private_data(uid, key, &data); + } + + DBusMessage* reply; + reply = dbus_message_new_method_return(msg); + + if (NULL != reply) { + /* Append result and private data */ + dbus_message_append_args(reply, + DBUS_TYPE_INT32, &ret, + DBUS_TYPE_STRING, &data, + DBUS_TYPE_INVALID); + + if (0 == ret) { + SLOG(LOG_DEBUG, TAG_STTD, "[OUT SUCCESS] Result(%d)", ret); + } else { + SLOG(LOG_ERROR, TAG_STTD, "[OUT ERROR] Result(%d)", ret); + } + + if (!dbus_connection_send(conn, reply, NULL)) { + SLOG(LOG_ERROR, TAG_STTD, "[OUT ERROR] Fail to send reply"); + } + + dbus_connection_flush(conn); + dbus_message_unref(reply); + } else { + SLOG(LOG_ERROR, TAG_STTD, "[OUT ERROR] Fail to create reply message!!"); + } + + if (NULL != data) free(data); + + SLOG(LOG_DEBUG, TAG_STTD, "<<<<<"); + SLOG(LOG_DEBUG, TAG_STTD, " "); + + return 0; +} + int sttd_dbus_server_is_recognition_type_supported(DBusConnection* conn, DBusMessage* msg) { DBusError err; diff --git a/server/sttd_dbus_server.h b/server/sttd_dbus_server.h index 68425ad..34210f7 100644 --- a/server/sttd_dbus_server.h +++ b/server/sttd_dbus_server.h @@ -46,6 +46,10 @@ int sttd_dbus_server_get_support_lang(DBusConnection* conn, DBusMessage* msg); int sttd_dbus_server_get_default_lang(DBusConnection* conn, DBusMessage* msg); +int sttd_dbus_server_set_private_data(DBusConnection* conn, DBusMessage* msg); + +int sttd_dbus_server_get_private_data(DBusConnection* conn, DBusMessage* msg); + int sttd_dbus_server_is_recognition_type_supported(DBusConnection* conn, DBusMessage* msg); diff --git a/server/sttd_engine_agent.c b/server/sttd_engine_agent.c index 8d91eb1..b316993 100644 --- a/server/sttd_engine_agent.c +++ b/server/sttd_engine_agent.c @@ -923,6 +923,78 @@ int sttd_engine_agent_get_default_lang(int uid, char** lang) return 0; } +int sttd_engine_agent_set_private_data(int uid, const char* key, const char* data) +{ + if (false == g_agent_init) { + SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized"); + return STTD_ERROR_OPERATION_FAILED; + } + + if (NULL == key || NULL == data) { + 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] The engine of 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; + } + + /* set private data */ + int ret = -1; + ret = stt_engine_set_private_data(engine->engine_id, key, data); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to set private data"); + return ret; + } + + return 0; +} + +int sttd_engine_agent_get_private_data(int uid, const char* key, char** data) +{ + if (false == g_agent_init) { + SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized"); + return STTD_ERROR_OPERATION_FAILED; + } + + if (NULL == key || NULL == data) { + 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] The engine of 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; + } + + /* get default language */ + int ret = -1; + ret = stt_engine_get_private_data(engine->engine_id, key, data); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to get private data"); + return ret; + } + + return 0; +} + int sttd_engine_agent_get_option_supported(int uid, bool* silence) { if (false == g_agent_init) { diff --git a/server/sttd_engine_agent.h b/server/sttd_engine_agent.h index 4447110..35e93cc 100644 --- a/server/sttd_engine_agent.h +++ b/server/sttd_engine_agent.h @@ -73,6 +73,10 @@ int sttd_engine_agent_supported_langs(int uid, GSList** lang_list); int sttd_engine_agent_get_default_lang(int uid, char** lang); +int sttd_engine_agent_set_private_data(int uid, const char* key, const char* data); + +int sttd_engine_agent_get_private_data(int uid, const char* key, char** data); + int sttd_engine_agent_get_option_supported(int uid, bool* silence); int sttd_engine_agent_is_credential_needed(int uid, bool* credential); diff --git a/server/sttd_server.c b/server/sttd_server.c index b201cba..8ea0fd2 100644 --- a/server/sttd_server.c +++ b/server/sttd_server.c @@ -881,6 +881,60 @@ int sttd_server_get_current_langauage(int uid, char** current_lang) return STTD_ERROR_NONE; } +int sttd_server_set_private_data(int uid, const char* key, const char* data) +{ + /* check if uid is valid */ + app_state_e state; + if (0 != sttd_client_get_state(uid, &state)) { + SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] uid is NOT valid "); + return STTD_ERROR_INVALID_PARAMETER; + } + + if (NULL == key || NULL == data) { + SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Input parameter is NULL"); + return STTD_ERROR_INVALID_PARAMETER; + } + + /* set private data to engine */ + int ret = -1; + ret = sttd_engine_agent_set_private_data(uid, key, data); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to set private data :result(%d)", ret); + return ret; + } + + SLOG(LOG_DEBUG, TAG_STTD, "[Server SUCCESS] Set private data"); + + return STTD_ERROR_NONE; +} + +int sttd_server_get_private_data(int uid, const char* key, char** data) +{ + /* check if uid is valid */ + app_state_e state; + if (0 != sttd_client_get_state(uid, &state)) { + SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] uid is NOT valid "); + return STTD_ERROR_INVALID_PARAMETER; + } + + if (NULL == key || NULL == data) { + SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Input parameter is NULL"); + return STTD_ERROR_INVALID_PARAMETER; + } + + /* get private data to engine */ + int ret = -1; + ret = sttd_engine_agent_get_private_data(uid, key, data); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to get private data :result(%d)", ret); + return ret; + } + + SLOG(LOG_DEBUG, TAG_STTD, "[Server SUCCESS] Get private data"); + + return STTD_ERROR_NONE; +} + int sttd_server_is_recognition_type_supported(int uid, const char* type, int* support) { /* check if uid is valid */ diff --git a/server/sttd_server.h b/server/sttd_server.h index 5978f17..91a3899 100644 --- a/server/sttd_server.h +++ b/server/sttd_server.h @@ -54,6 +54,10 @@ int sttd_server_get_supported_languages(int uid, GSList** lang_list); int sttd_server_get_current_langauage(int uid, char** current_lang); +int sttd_server_set_private_data(int uid, const char* key, const char* data); + +int sttd_server_get_private_data(int uid, const char* key, char** data); + int sttd_server_set_engine_data(int uid, const char* key, const char* value); int sttd_server_is_recognition_type_supported(int uid, const char* type, int* support); diff --git a/server/sttp.h b/server/sttp.h index c20a310..e1f7032 100644 --- a/server/sttp.h +++ b/server/sttp.h @@ -459,6 +459,38 @@ typedef int (*sttpe_start_file)(const char* language, const char* type, const ch typedef int (*sttpe_cancel_file)(void); /** +* @brief Set private data. +* @since_tizen 3.0 +* +* @param[in] key Key field of private data. +* @param[in] data Data field of private data. +* +* @return 0 on success, otherwise a negative error value +* @retval #STTP_ERROR_NONE Successful +* @retval #STTP_ERROR_INVALID_PARAMETER Invalid parameter +* @retval #STTP_ERROR_OPERATION_FAILED Operation failed +* +* @see sttpe_get_private_data() +*/ +typedef int (* sttpe_set_private_data)(const char* key, const char* data); + +/** +* @brief Get private data. +* @since_tizen 3.0 +* +* @param[out] key Key field of private data. +* @param[out] data Data field of private data. +* +* @return 0 on success, otherwise a negative error value +* @retval #STTP_ERROR_NONE Successful +* @retval #STTP_ERROR_INVALID_PARAMETER Invalid parameter +* @retval #STTP_ERROR_OPERATION_FAILED Operation failed +* +* @see sttpe_set_private_data() +*/ +typedef int (* sttpe_get_private_data)(const char* key, char** data); + +/** * @brief A structure of the engine functions. */ typedef struct { @@ -492,6 +524,10 @@ typedef struct { /* Control file recognition */ sttpe_start_file start_file; /**< Start recognition */ sttpe_cancel_file cancel_file; /**< Cancel recognition */ + + /* Set/Get private data */ + sttpe_set_private_data set_private_data; /**< Set private data */ + sttpe_get_private_data get_private_data; /**< Get private data */ } sttpe_funcs_s; /** -- 2.7.4