+ 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;
+}
+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;
+ }
+
+ 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_timer_add(0, __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;
+ }
+ }
+ } else {
+ SLOG(LOG_DEBUG, TAG_STTC, "[SUCCESS] Current engine uuid = %s", client->current_engine_id);
+
+ /* success to change engine */
+ client->silence_supported = silence_supported;
+ SLOG(LOG_DEBUG, TAG_STTC, "Supported options : silence(%s), credential(%s)", silence_supported ? "support" : "no support", credential_needed ? "need" : "no need");
+ }
+ }
+ }
+#endif
+ 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);
+ stt_client_not_use_callback(client);
+ SLOG(LOG_DEBUG, TAG_STTC, "State changed callback is called");
+ } else {
+ SLOG(LOG_WARN, TAG_STTC, "[WARNING] State changed callback is null");
+ }
+
+ SLOG(LOG_DEBUG, TAG_STTC, "=====");
+ SLOG(LOG_DEBUG, TAG_STTC, " ");
+
+ return EINA_FALSE;
+}
+
+int stt_prepare(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;
+ }
+
+ /* check state */
+ if (client->current_state != STT_STATE_CREATED) {
+ SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State: Current state(%d) is not 'CREATED'", client->current_state);
+ return STT_ERROR_INVALID_STATE;
+ }
+
+ g_connect_timer = ecore_timer_add(0, __stt_connect_daemon, (void*)client);
+
+ SLOG(LOG_DEBUG, TAG_STTC, "=====");
+ SLOG(LOG_DEBUG, TAG_STTC, " ");
+
+ return STT_ERROR_NONE;
+}
+
+int stt_unprepare(stt_h stt)
+{
+ stt_client_s* client = NULL;
+ if (0 != __stt_get_feature_enabled()) {
+ return STT_ERROR_NOT_SUPPORTED;
+ }
+ if (0 != __stt_check_privilege()) {
+ return STT_ERROR_PERMISSION_DENIED;
+ }
+ if (0 != __stt_check_handle(stt, &client)) {
+ return STT_ERROR_INVALID_PARAMETER;
+ }
+
+ SLOG(LOG_DEBUG, TAG_STTC, "===== Unprepare STT");
+
+ /* check state */
+ if (client->current_state != STT_STATE_READY) {
+ SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State: Current state(%d) is not 'READY'", client->current_state);
+ return STT_ERROR_INVALID_STATE;
+ }
+
+ int ret = -1;
+ int count = 0;
+ while (0 != ret) {
+ ret = stt_dbus_request_finalize(client->uid);
+ if (0 != ret) {
+ if (STT_ERROR_TIMED_OUT != ret) {
+ SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to request finalize : %s", __stt_get_error_code(ret));
+ break;
+ } 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");
+ break;
+ }
+ }
+ }
+ }
+
+ client->internal_state = STT_INTERNAL_STATE_NONE;
+
+ client->before_state = client->current_state;
+ client->current_state = STT_STATE_CREATED;
+
+ 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);
+ 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, " ");
+
+ return STT_ERROR_NONE;
+}
+
+bool __stt_config_supported_language_cb(const char* engine_id, const char* language, 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 false;
+ }
+
+ /* call callback function */
+ if (NULL != client->supported_lang_cb) {
+ return client->supported_lang_cb(stt, language, client->supported_lang_user_data);
+ } else {
+ SLOG(LOG_WARN, TAG_STTC, "No registered callback function of supported languages");
+ }
+
+ return false;
+}
+
+int stt_foreach_supported_languages(stt_h stt, stt_supported_language_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;
+ }
+
+ SLOG(LOG_DEBUG, TAG_STTC, "===== Foreach Supported Language");
+
+ if (NULL == callback) {
+ SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL");
+ return STT_ERROR_INVALID_PARAMETER;
+ }
+
+ int ret;
+ char* current_engine_id = NULL;
+
+ if (NULL == client->current_engine_id) {
+ ret = stt_config_mgr_get_engine(¤t_engine_id);
+ ret = __stt_convert_config_error_code(ret);
+ if (0 != ret) {
+ SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to get default engine id : %s", __stt_get_error_code(ret));
+ return ret;
+ }
+ } else {
+ current_engine_id = strdup(client->current_engine_id);
+ if (NULL == current_engine_id) {
+ SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to allocate memory");
+ return STT_ERROR_OUT_OF_MEMORY;
+ }
+ }
+
+ client->supported_lang_cb = callback;
+ client->supported_lang_user_data = user_data;
+
+ ret = stt_config_mgr_get_language_list(current_engine_id, __stt_config_supported_language_cb, client->stt);
+ ret = __stt_convert_config_error_code(ret);
+ if (0 != ret) {
+ SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to get languages : %s", __stt_get_error_code(ret));
+ }
+
+ if (NULL != current_engine_id) {
+ free(current_engine_id);
+ current_engine_id = NULL;
+ }
+
+ client->supported_lang_cb = NULL;
+ client->supported_lang_user_data = NULL;
+
+ SLOG(LOG_DEBUG, TAG_STTC, "=====");
+ SLOG(LOG_DEBUG, TAG_STTC, " ");
+
+ return ret;
+}
+
+int stt_get_default_language(stt_h stt, char** language)
+{
+ 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 Default Language");
+
+ if (NULL == language) {
+ SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL");
+ return STT_ERROR_INVALID_PARAMETER;
+ }
+
+ int ret = 0;
+ ret = stt_config_mgr_get_default_language(language);
+ ret = __stt_convert_config_error_code(ret);
+ if (0 != ret) {
+ SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to get default language : %s", __stt_get_error_code(ret));
+ } else {