Correct to check return of fread
[platform/core/uifw/stt.git] / client / stt.c
index faf821f..8a55d34 100644 (file)
 #include "stt_client.h"
 #include "stt_dbus.h"
 #include "stt_config_mgr.h"
+#include "stt_internal.h"
 #include "stt_main.h"
 
 
 static void __stt_notify_state_changed(void *data);
-static Eina_Bool __stt_notify_error(void *data);
+static void __stt_notify_error(void *data);
 
 static Ecore_Timer* g_connect_timer = NULL;
 static float g_volume_db = 0;
@@ -42,6 +43,8 @@ static float g_volume_db = 0;
 static int g_feature_enabled = -1;
 
 static int g_privilege_allowed = -1;
+static int g_privilege_applaunch_allowed = -1;
+
 static cynara *p_cynara = NULL;
 
 static bool g_err_callback_status = false;
@@ -90,22 +93,22 @@ static int __check_privilege_initialize()
        return ret == CYNARA_API_SUCCESS;
 }
 
-static int __check_privilege(const char* uid, const char * privilege)
+static bool __check_privilege(const char* uid, const char * privilege)
 {
        FILE *fp = NULL;
        char label_path[1024] = "/proc/self/attr/current";
        char smack_label[1024] = {'\0',};
 
        if (!p_cynara) {
-           return false;
+               return false;
        }
 
        fp = fopen(label_path, "r");
        if (fp != NULL) {
-           if (fread(smack_label, 1, sizeof(smack_label), fp) <= 0)
-               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] fail to fread");
+               if (0 >= fread(smack_label, 1, sizeof(smack_label), fp))
+                       SLOG(LOG_ERROR, TAG_STTC, "[ERROR] fail to fread");
 
-           fclose(fp);
+               fclose(fp);
        }
 
        pid_t pid = getpid();
@@ -118,7 +121,7 @@ static int __check_privilege(const char* uid, const char * privilege)
        }
 
        if (ret != CYNARA_API_ACCESS_ALLOWED)
-           return false;
+               return false;
        return true;
 }
 
@@ -142,7 +145,7 @@ static int __stt_check_privilege()
                        return STT_ERROR_PERMISSION_DENIED;
                }
                snprintf(uid, 16, "%d", getuid());
-               if (false == __check_privilege(uid, STT_PRIVILEGE)) {
+               if (false == __check_privilege(uid, STT_PRIVILEGE_RECORDER)) {
                        SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Permission is denied");
                        g_privilege_allowed = 0;
                        __check_privilege_deinitialize();
@@ -155,6 +158,32 @@ static int __stt_check_privilege()
        return STT_ERROR_NONE;
 }
 
+static int __stt_check_privilege_for_applaunch()
+{
+       char uid[16];
+
+       if (0 == g_privilege_applaunch_allowed) {
+               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Permission for applaunch is denied");
+               return STT_ERROR_PERMISSION_DENIED;
+       } else if (-1 == g_privilege_applaunch_allowed) {
+               if (false == __check_privilege_initialize()) {
+                       SLOG(LOG_ERROR, TAG_STTC, "[ERROR] privilege initialize is failed (applaunch)");
+                       return STT_ERROR_PERMISSION_DENIED;
+               }
+               snprintf(uid, 16, "%d", getuid());
+               if (false == __check_privilege(uid, STT_PRIVILEGE_APPLAUNCH)) {
+                       SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Permission is denied : appmanager.launch");
+                       g_privilege_applaunch_allowed = 0;
+                       __check_privilege_deinitialize();
+                       return STT_ERROR_PERMISSION_DENIED;
+               }
+               __check_privilege_deinitialize();
+       }
+
+       g_privilege_applaunch_allowed = 1;
+       return STT_ERROR_NONE;
+}
+
 static const char* __stt_get_error_code(stt_error_e err)
 {
        switch (err) {
@@ -229,6 +258,33 @@ void __stt_config_lang_changed_cb(const char* before_language, const char* curre
        return;
 }
 
+static Eina_Bool __reconnect_by_engine_changed(void *data)
+{
+       stt_h stt = (stt_h)data;
+
+       stt_client_s* client = stt_client_get(stt);
+       if (NULL == client) {
+               SLOG(LOG_ERROR, TAG_STTC, "[WARNING] A handle is not valid");
+               return EINA_FALSE;
+       }
+
+       if (STT_STATE_READY != client->current_state) {
+               usleep(10000);
+               return EINA_TRUE;
+       }
+
+       int ret = stt_unprepare(stt);
+       if (0 != ret) {
+               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to prepare for setting a new engine... (%d)", ret);
+       }
+       ret = stt_prepare(stt);
+       if (0 != ret) {
+               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to prepare for setting a new engine... (%d)", ret);
+       }
+
+       return EINA_FALSE;
+}
+
 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;
@@ -244,6 +300,29 @@ void __stt_config_engine_changed_cb(const char* engine_id, const char* 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");
 
+       /* When the default engine is changed, please unload the old engine and load the new one. */
+       int ret = -1;
+
+       if (NULL == client->current_engine_id) {
+               if (STT_STATE_RECORDING == client->current_state || STT_STATE_PROCESSING == client->current_state) {
+                       ret = stt_cancel(stt);
+                       if (0 != ret) {
+                               SLOG(LOG_DEBUG, TAG_STTC, "[DEBUG] STT client canceling...");
+                       }
+
+                       ecore_idler_add(__reconnect_by_engine_changed, (void*)stt);
+               } else if (STT_STATE_READY == client->current_state) {
+                       ret = stt_unprepare(stt);
+                       if (0 != ret) {
+                               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to prepare for setting a new engine... (%d)", ret);
+                       }
+                       ret = stt_prepare(stt);
+                       if (0 != ret) {
+                               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to prepare for setting a new engine... (%d)", ret);
+                       }
+               }
+       }
+
        /* 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);
@@ -570,6 +649,9 @@ int stt_set_engine(stt_h stt, const char* engine_id)
        if (0 != __stt_check_privilege()) {
                return STT_ERROR_PERMISSION_DENIED;
        }
+       if (0 != __stt_check_privilege_for_applaunch()) {
+               return STT_ERROR_PERMISSION_DENIED;
+       }
        if (0 != __stt_check_handle(stt, &client)) {
                return STT_ERROR_INVALID_PARAMETER;
        }
@@ -673,6 +755,11 @@ int stt_set_private_data(stt_h stt, const char* key, const char* data)
                return STT_ERROR_INVALID_STATE;
        }
 
+       if (true != client->internal && (0 == strcmp(key, "server") || 0 == strcmp(key, "rampcode") || 0 == strcmp(key, "epd"))) {
+               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] This is not an internal app");
+               return STT_ERROR_INVALID_PARAMETER;
+       }
+
        int ret = -1;
        int count = 0;
        while (0 != ret) {
@@ -755,9 +842,73 @@ int stt_get_private_data(stt_h stt, const char* key, char** data)
 
        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");
@@ -765,8 +916,22 @@ static Eina_Bool __stt_connect_daemon(void *data)
                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 */
-       int ret = -1;
        ret = stt_dbus_request_hello(client->uid);
 
        if (0 != ret) {
@@ -790,7 +955,7 @@ static Eina_Bool __stt_connect_daemon(void *data)
                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);
+               ecore_main_loop_thread_safe_call_async(__stt_notify_error, (void*)client);
 
                return EINA_FALSE;
 
@@ -877,7 +1042,7 @@ int stt_prepare(stt_h stt)
                return STT_ERROR_INVALID_STATE;
        }
 
-       g_connect_timer = ecore_timer_add(0, __stt_connect_daemon, (void*)client);
+       g_connect_timer = ecore_timer_add(0.02, __stt_connect_daemon, (void*)client);
 
        SLOG(LOG_DEBUG, TAG_STTC, "=====");
        SLOG(LOG_DEBUG, TAG_STTC, " ");
@@ -1452,8 +1617,8 @@ int stt_start(stt_h stt, const char* language, const char* type)
        }
 
        int ret = -1;
-       char appid[128] = {0, };
-       ret = aul_app_get_appid_bypid(getpid(), appid, sizeof(appid));
+       char appid[1024] = {0, };
+       ret = aul_app_get_appid_bypid(getpid(), appid, sizeof(appid) - 1);
 
        if ((AUL_R_OK != ret) || (0 == strlen(appid))) {
                SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to get application ID");
@@ -1468,20 +1633,29 @@ int stt_start(stt_h stt, const char* language, const char* type)
                temp = strdup(language);
        }
 
+       if (NULL == temp) {
+               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to allocate memory");
+               return STT_ERROR_OUT_OF_MEMORY;
+       }
+
        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);
+               free(temp);
+               temp = NULL;
                return STT_ERROR_PERMISSION_DENIED;
        }
 
+       client->internal_state = STT_INTERNAL_STATE_STARTING;
        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));
+               client->internal_state = STT_INTERNAL_STATE_NONE;
        } 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);
+       free(temp);
+       temp = NULL;
 
        SLOG(LOG_DEBUG, TAG_STTC, "=====");
        SLOG(LOG_DEBUG, TAG_STTC, " ");
@@ -1521,13 +1695,13 @@ int stt_stop(stt_h stt)
                return STT_ERROR_IN_PROGRESS_TO_PROCESSING;
        }
 
+       client->internal_state = STT_INTERNAL_STATE_STOPPING;
        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));
+               client->internal_state = STT_INTERNAL_STATE_NONE;
        } 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, "=====");
@@ -1569,12 +1743,13 @@ int stt_cancel(stt_h stt)
                return STT_ERROR_IN_PROGRESS_TO_READY;
        }
 
+       client->internal_state = STT_INTERNAL_STATE_CANCELING;
        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));
+               client->internal_state = STT_INTERNAL_STATE_NONE;
        } 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, "=====");
@@ -1694,7 +1869,7 @@ int stt_foreach_detailed_result(stt_h stt, stt_result_time_cb callback, void* us
        return ret;
 }
 
-static Eina_Bool __stt_notify_error(void *data)
+static void __stt_notify_error(void *data)
 {
        stt_client_s* client = (stt_client_s*)data;
 
@@ -1703,11 +1878,11 @@ static Eina_Bool __stt_notify_error(void *data)
        /* check handle */
        if (NULL == client) {
                SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to notify error : A handle is not valid");
-               return EINA_FALSE;
+               return;
        }
 
        if (NULL == stt_client_get_by_uid(client->uid))
-               return EINA_FALSE;
+               return;
 
        if (NULL != client->error_cb) {
                stt_client_use_callback(client);
@@ -1720,39 +1895,86 @@ static Eina_Bool __stt_notify_error(void *data)
                SLOG(LOG_WARN, TAG_STTC, "[WARNING] Error callback is null");
        }
 
-       return EINA_FALSE;
+       return;
 }
 
 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");
-               return -1;
-       }
+       if (-1 == uid) {
+               GList* client_list = NULL;
+               client_list = stt_client_get_client_list();
 
-       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);
+               GList *iter = NULL;
+               stt_client_s *data = NULL;
 
-       SLOG(LOG_INFO, TAG_STTC, "internal state is initialized to 0");
+               if (g_list_length(client_list) > 0) {
+                       /* Get a first item */
+                       iter = g_list_first(client_list);
 
-       if (NULL != client->error_cb) {
-               ecore_timer_add(0, __stt_notify_error, client);
+                       while (NULL != iter) {
+                               data = iter->data;
+
+                               data->reason = reason;
+                               data->internal_state = STT_INTERNAL_STATE_NONE;
+                               if (NULL != data->err_msg) {
+                                       free(data->err_msg);
+                                       data->err_msg = NULL;
+                               }
+                               if (NULL != err_msg)
+                                       data->err_msg = strdup(err_msg);
+
+                               SLOG(LOG_INFO, TAG_STTC, "internal state is initialized to 0");
+
+                               if (NULL != data->error_cb) {
+                                       ecore_main_loop_thread_safe_call_async(__stt_notify_error, data);
+                               } else {
+                                       SLOG(LOG_WARN, TAG_STTC, "[WARNING] Error callback is null");
+                               }
+
+                               if (STT_ERROR_SERVICE_RESET == reason) {
+                                       SLOG(LOG_WARN, TAG_STTC, "[WARNING] Service reset");
+
+                                       data->current_state = STT_STATE_CREATED;
+                                       if (0 != stt_prepare(data->stt)) {
+                                               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to prepare");
+                                       }
+                               }
+
+                               /* Next item */
+                               iter = g_list_next(iter);
+                       }
+               }
        } else {
-               SLOG(LOG_WARN, TAG_STTC, "[WARNING] Error callback is null");
-       }
+               stt_client_s* client = stt_client_get_by_uid(uid);
+               if (NULL == client) {
+                       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;
+               }
+               if (NULL != err_msg)
+                       client->err_msg = strdup(err_msg);
+
+               SLOG(LOG_INFO, TAG_STTC, "internal state is initialized to 0");
+
+               if (NULL != client->error_cb) {
+                       ecore_main_loop_thread_safe_call_async(__stt_notify_error, client);
+               } else {
+                       SLOG(LOG_WARN, TAG_STTC, "[WARNING] Error callback is null");
+               }
 
-       if (STT_ERROR_SERVICE_RESET == reason) {
-               SLOG(LOG_WARN, TAG_STTC, "[WARNING] Service reset");
+               if (STT_ERROR_SERVICE_RESET == reason) {
+                       SLOG(LOG_WARN, TAG_STTC, "[WARNING] Service reset");
 
-               client->current_state = STT_STATE_CREATED;
-               if (0 != stt_prepare(client->stt)) {
-                       SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to prepare");
+                       client->current_state = STT_STATE_CREATED;
+                       if (0 != stt_prepare(client->stt)) {
+                               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to prepare");
+                       }
                }
        }
 
@@ -1789,9 +2011,9 @@ static void __stt_notify_state_changed(void *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");
+               SLOG(LOG_DEBUG, TAG_STTC, "State changed callback is called, State(%d)", client->current_state);
        } else {
-               SLOG(LOG_WARN, TAG_STTC, "[WARNING] State changed callback is null");
+               SLOG(LOG_WARN, TAG_STTC, "[WARNING] State changed callback is null, State(%d)", client->current_state);
        }
 
        return;
@@ -1872,12 +2094,12 @@ int __stt_cb_result(int uid, int event, char** data, int data_count, const char*
        }
 
        if (NULL != msg)
-               SLOG(LOG_DEBUG, TAG_STTC, "Recognition Result Message = %s", msg);
+               SECURE_SLOG(LOG_DEBUG, TAG_STTC, "Recognition Result Message = %s", msg);
 
        int i = 0;
        for (i = 0; i < data_count; i++) {
                if (NULL != data[i])
-                       SLOG(LOG_DEBUG, TAG_STTC, "Recognition Result[%d] = %s", i, data[i]);
+                       SECURE_SLOG(LOG_DEBUG, TAG_STTC, "Recognition Result[%d] = %s", i, data[i]);
        }
 
        if (NULL != client->recognition_result_cb) {
@@ -1909,7 +2131,7 @@ int __stt_cb_result(int uid, int event, char** data, int data_count, const char*
                SLOG(LOG_ERROR, TAG_STTC, "[ERROR] User result callback is null");
        }
 
-       ecore_timer_add(0, __stt_notify_result, client);
+       __stt_notify_result(client);
 
        return STT_ERROR_NONE;
 }
@@ -1936,6 +2158,46 @@ int __stt_cb_set_state(int uid, int state)
        return 0;
 }
 
+static void __stt_notify_speech_status(void *data)
+{
+       stt_client_s* client = (stt_client_s*)data;
+
+       /* check handle */
+       if (NULL == client) {
+               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to notify speech status : A handle is not valid");
+               return;
+       }
+
+       if (NULL == stt_client_get_by_uid(client->uid)) {
+               return;
+       }
+
+       if (NULL != client->speech_status_cb) {
+               stt_client_use_callback(client);
+               client->speech_status_cb(client->stt, client->speech_status, client->speech_status_user_data);
+               stt_client_not_use_callback(client);
+               SLOG(LOG_DEBUG, TAG_STTC, "Speech status callback is called");
+       } else {
+               SLOG(LOG_WARN, TAG_STTC, "[WARNING] Speech status callback is null");
+       }
+
+       return;
+}
+
+int __stt_cb_speech_status(int uid, int status)
+{
+       stt_client_s* client = stt_client_get_by_uid(uid);
+       if (NULL == client) {
+               SLOG(LOG_ERROR, TAG_STTC, "Handle not found");
+               return -1;
+       }
+
+       client->speech_status = status;
+
+       ecore_main_loop_thread_safe_call_async(__stt_notify_speech_status, client);
+       return 0;
+}
+
 int stt_set_recognition_result_cb(stt_h stt, stt_recognition_result_cb callback, void* user_data)
 {
        stt_client_s* client = NULL;
@@ -2190,3 +2452,179 @@ int stt_unset_engine_changed_cb(stt_h stt)
 
        return 0;
 }
+
+int stt_set_speech_status_cb(stt_h stt, stt_speech_status_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;
+       }
+
+       if (NULL == callback)
+               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->speech_status_cb = callback;
+       client->speech_status_user_data = user_data;
+
+       return 0;
+}
+
+int stt_unset_speech_status_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(%d) is not 'Created'", client->current_state);
+               return STT_ERROR_INVALID_STATE;
+       }
+
+       client->speech_status_cb = NULL;
+       client->speech_status_user_data = NULL;
+
+       return 0;
+}
+
+int stt_start_file(stt_h stt, const char* language, const char* type, const char* filepath, stt_audio_type_e audio_type, int sample_rate)
+{
+       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 == filepath) {
+               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL");
+               return STT_ERROR_INVALID_PARAMETER;
+       }
+
+       SLOG(LOG_DEBUG, TAG_STTC, "===== STT START FILE");
+
+       /* 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;
+       }
+
+       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);
+               return STT_ERROR_IN_PROGRESS_TO_RECORDING;
+       }
+
+       int ret = -1;
+       char appid[1024] = {0, };
+       ret = aul_app_get_appid_bypid(getpid(), appid, sizeof(appid) - 1);
+
+       if ((AUL_R_OK != ret) || (0 == strlen(appid))) {
+               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to get application ID");
+       } else {
+               SLOG(LOG_DEBUG, TAG_STTC, "[DEBUG] Current app id is %s", appid);
+       }
+
+       char* temp = NULL;
+       if (NULL == language) {
+               temp = strdup("default");
+       } else {
+               temp = strdup(language);
+       }
+
+       if (NULL == temp) {
+               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to allocate memory");
+               return STT_ERROR_OUT_OF_MEMORY;
+       }
+
+       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);
+               free(temp);
+               temp = NULL;
+               return STT_ERROR_PERMISSION_DENIED;
+       }
+
+       client->internal_state = STT_INTERNAL_STATE_STARTING;
+       ret = stt_dbus_request_start_file(client->uid, temp, type, client->silence, appid, client->credential, filepath, audio_type, sample_rate);
+       if (0 != ret) {
+               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to start file : %s", __stt_get_error_code(ret));
+               client->internal_state = STT_INTERNAL_STATE_NONE;
+       } else {
+               SLOG(LOG_DEBUG, TAG_STTC, "[SUCCESS] Start is successful but not done");
+       }
+
+       free(temp);
+       temp = NULL;
+
+       SLOG(LOG_DEBUG, TAG_STTC, "=====");
+       SLOG(LOG_DEBUG, TAG_STTC, " ");
+
+       return ret;
+}
+
+int stt_cancel_file(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, "===== STT CANCEL FILE");
+
+       /* 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(%d) is 'Ready'", client->current_state);
+               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;
+       }
+
+       client->internal_state = STT_INTERNAL_STATE_CANCELING;
+       int ret = stt_dbus_request_cancel_file(client->uid);
+       if (0 != ret) {
+               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to cancel file : %s", __stt_get_error_code(ret));
+               client->internal_state = STT_INTERNAL_STATE_NONE;
+       } else {
+               SLOG(LOG_DEBUG, TAG_STTC, "[SUCCESS] Cancel file is successful but not done");
+       }
+
+       SLOG(LOG_DEBUG, TAG_STTC, "=====");
+       SLOG(LOG_DEBUG, TAG_STTC, " ");
+
+       return ret;
+}
+