return;
}
-int sttd_server_start(unsigned int uid, const char* lang, const char* recognition_type, int silence, const char* appid, const char* credential)
+static int __sttd_server_check_precondition_to_start(unsigned int uid, const char* appid)
{
- if (NULL == lang || NULL == recognition_type) {
- SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Input parameter is NULL");
- return STTD_ERROR_INVALID_PARAMETER;
- }
-
/* check if uid is valid */
app_state_e state;
if (0 != sttd_client_get_state(uid, &state)) {
return STTD_ERROR_INVALID_STATE;
}
- int ret = 0;
+ int ret = STTD_ERROR_NONE;
if (false == stt_client_get_app_agreed(uid)) {
bool temp = false;
ret = sttd_engine_agent_check_app_agreed(appid, &temp);
return STTD_ERROR_OUT_OF_NETWORK;
}
}
+ return ret;
+}
+
+int sttd_server_start(unsigned 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");
+ return STTD_ERROR_INVALID_PARAMETER;
+ }
+
+ int ret = __sttd_server_check_precondition_to_start(uid, appid);
+ if (0 != ret) {
+ SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to satisfy preconditions, ret(0x%x)", ret);
+ return ret;
+ }
if (NULL != g_recording_timer) {
ecore_timer_del(g_recording_timer);
return STTD_ERROR_NONE;
}
-int sttd_server_cancel(unsigned int uid)
+static int __sttd_server_cancel(unsigned int uid)
{
- SLOG(LOG_INFO, TAG_STTD, "[Server INFO] Enter sttd_server_cancel");
-
/* check if uid is valid */
app_state_e state;
if (0 != sttd_client_get_state(uid, &state)) {
/* Notify uid state change */
sttdc_send_set_state(uid, APP_STATE_READY);
- SLOG(LOG_INFO, TAG_STTD, "[Server INFO] End sttd_server_cancel");
+ return ret;
+}
- return STTD_ERROR_NONE;
+int sttd_server_cancel(unsigned int uid)
+{
+ SLOG(LOG_INFO, TAG_STTD, "[Server INFO] Enter sttd_server_cancel");
+
+ int ret = __sttd_server_cancel(uid);
+ if (0 != ret) {
+ SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to cancel : result(0x%x)", ret);
+ }
+
+ SLOG(LOG_INFO, TAG_STTD, "[Server INFO] End sttd_server_cancel");
+ return ret;
}
int sttd_server_start_file(unsigned int uid, const char* lang, const char* recognition_type, int silence, const char* appid, const char* credential,
return STTD_ERROR_INVALID_PARAMETER;
}
- /* 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;
- }
-
- /* check uid state */
- if (APP_STATE_READY != state) {
- SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] sttd_server_start : current state is not ready");
- return STTD_ERROR_INVALID_STATE;
- }
-
- int ret = 0;
- if (false == stt_client_get_app_agreed(uid)) {
- bool temp = false;
- ret = sttd_engine_agent_check_app_agreed(appid, &temp);
- if (0 != ret) {
- SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to get engine available : %d", ret);
- return ret;
- }
-
- if (false == temp) {
- SLOG(LOG_ERROR, TAG_STTD, "[Server] App(%s) NOT confirmed that engine is available", appid);
- return STTD_ERROR_PERMISSION_DENIED;
- }
-
- stt_client_set_app_agreed(uid);
- }
-
- /* check if engine use network */
- if (true == sttd_engine_agent_need_network()) {
- if (false == stt_network_is_connected()) {
- SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Disconnect network. Current engine needs to network connection.");
- return STTD_ERROR_OUT_OF_NETWORK;
- }
+ int ret = __sttd_server_check_precondition_to_start(uid, appid);
+ if (0 != ret) {
+ SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to satisfy preconditions, ret(0x%x)", ret);
+ return ret;
}
if (0 != stt_client_set_current_recognition(uid)) {
int sttd_server_cancel_file(unsigned int uid)
{
- /* 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;
- }
+ SLOG(LOG_INFO, TAG_STTD, "[Server INFO] Enter sttd_server_cancel_file");
- /* check uid state */
- if (APP_STATE_READY == state) {
- SLOG(LOG_WARN, TAG_STTD, "[Server WARNING] Current state is ready");
- return STTD_ERROR_NONE;
- }
-
- stt_client_unset_current_recognition();
-
- if (NULL != g_recording_timer) {
- ecore_timer_del(g_recording_timer);
- g_recording_timer = NULL;
- }
-
- if (NULL != g_processing_timer) {
- SLOG(LOG_INFO, TAG_STTD, "[INFO] Delete g_processing_timer");
- ecore_timer_del(g_processing_timer);
- g_processing_timer = NULL;
- }
-
- if (APP_STATE_RECORDING == state) {
- /* Unset audio session */
- int ret = sttd_recorder_unset_audio_session();
- if (0 != ret) {
- SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to unset session : %d", ret);
- return ret;
- }
- }
-
- /* change uid state */
- sttd_client_set_state(uid, APP_STATE_READY);
-
- /* cancel engine recognition */
- int ret = sttd_engine_agent_recognize_cancel();
+ int ret = __sttd_server_cancel(uid);
if (0 != ret) {
- SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to cancel : result(%d)", ret);
- return ret;
+ SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to cancel file : result(0x%x)", ret);
}
- /* Notify uid state change */
- sttdc_send_set_state(uid, APP_STATE_READY);
-
- return STTD_ERROR_NONE;
-}
-
+ SLOG(LOG_INFO, TAG_STTD, "[Server INFO] End sttd_server_cancel_file");
+ return ret;
+}
\ No newline at end of file