+ 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;
+ }
+ }
+ }
+ }
+
+ if (0 == strncmp(*data, "NULL", strlen(*data))) {
+ free(*data);
+ *data = NULL;
+ }
+
+ SLOG(LOG_DEBUG, TAG_STTC, "=====");
+ SLOG(LOG_DEBUG, TAG_STTC, "");
+
+ return STT_ERROR_NONE;
+}
+
+int stt_set_server_stt(stt_h stt, const char* key, char* user_data)
+{
+ int ret = -1;
+ 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 STT server");
+
+ if (NULL == key || NULL == user_data) {
+ SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid parameter");
+ return STT_ERROR_INVALID_PARAMETER;
+ }
+
+ if (STT_STATE_CREATED != client->current_state && STT_STATE_READY != client->current_state) {
+ SLOG(LOG_ERROR, TAG_STTC, "[ERROR] The current state is invalid (%d).", client->current_state);
+ return STT_ERROR_INVALID_STATE;
+ }
+
+
+ client->internal = true;
+
+ char* private_key = NULL;
+ private_key = strdup(key);
+ if (NULL == private_key) {
+ SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to allocate memory(private_key)");
+ return STT_ERROR_OUT_OF_MEMORY;
+ }
+
+ char* data = NULL;
+ data = strdup(user_data);
+ if (NULL == data) {
+ SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to allocate memory(data)");
+ free(private_key);
+ private_key = NULL;
+ return STT_ERROR_OUT_OF_MEMORY;
+ }
+
+ ret = stt_set_private_data(stt, private_key, data);
+ if (0 != ret) {
+ SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to set private data, ret(%d), key(%s)", ret, private_key);
+ }
+
+ free(data);
+ data = NULL;
+ free(private_key);
+ private_key = NULL;
+
+ SLOG(LOG_DEBUG, TAG_STTC, "======");
+ SLOG(LOG_DEBUG, TAG_STTC, " ");
+
+ return ret;
+}
+
+static Eina_Bool __stt_connect_daemon(void *data)
+{
+ stt_client_s* client = (stt_client_s*)data;
+ int ret = -1;
+
+ if (NULL == client) {
+ SLOG(LOG_ERROR, TAG_STTC, "[ERROR] A handle is not available");
+ g_connect_timer = NULL;
+ return EINA_FALSE;
+ }
+
+ if (0 == stt_client_get_size() || NULL == stt_client_get_by_uid(client->uid)) {
+ SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Client has been already destroyed");
+ return EINA_FALSE;
+ }
+
+ /* Check and Set vconfkey of custom engine before sending hello */
+ if (1 == g_privilege_applaunch_allowed && NULL != client->current_engine_id) {
+ /* Set vconfkey */
+ ret = __stt_set_buxtonkey(client->current_engine_id);
+ if (0 != ret) {
+ SLOG(LOG_DEBUG, TAG_STTC, "[DEBUG] set buxtonkey Failed!!! (inside __stt_connect_daemon)");
+ return EINA_TRUE;
+ }
+ }
+
+ /* Send hello */
+ ret = stt_dbus_request_hello(client->uid);
+
+ if (0 != ret) {
+ if (STT_ERROR_INVALID_STATE == ret) {
+ g_connect_timer = NULL;
+ return EINA_FALSE;
+ }
+ return EINA_TRUE;
+ }
+
+ g_connect_timer = NULL;
+ SLOG(LOG_DEBUG, TAG_STTC, "===== Connect stt-service");
+
+ /* request initialization */
+ bool silence_supported = false;
+ bool credential_needed = false;
+
+ 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));
+
+ client->reason = STT_ERROR_ENGINE_NOT_FOUND;
+ ecore_main_loop_thread_safe_call_async(__stt_notify_error, (void*)client);
+
+ return EINA_FALSE;
+
+ } else if (STT_ERROR_NONE != ret) {
+ SLOG(LOG_ERROR, TAG_STTC, "[WARNING] Fail to connection. Retry to connect");
+ return EINA_TRUE;
+ } else {
+ /* success to connect stt-service */
+ client->silence_supported = silence_supported;
+ 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");
+ }
+
+#ifdef __UNUSED_CODES__
+ if (NULL != client->current_engine_id) {
+ ret = -1;
+ int count = 0;
+ silence_supported = false;
+ credential_needed = false;
+ SLOG(LOG_DEBUG, TAG_STTC, "[WARNING] current_engine_id(%s)", client->current_engine_id);
+
+ while (0 != ret) {
+ 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));
+ 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;
+ }