2 * Copyright (c) 2011-2016 Samsung Electronics Co., Ltd All Rights Reserved
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 * http://www.apache.org/licenses/LICENSE-2.0
7 * Unless required by applicable law or agreed to in writing, software
8 * distributed under the License is distributed on an "AS IS" BASIS,
9 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 * See the License for the specific language governing permissions and
11 * limitations under the License.
15 #include <cynara-client.h>
16 #include <cynara-error.h>
17 #include <cynara-session.h>
23 #include <sys/types.h>
25 #include <system_info.h>
30 #include "stt_client.h"
32 #include "stt_config_mgr.h"
33 #include "stt_internal.h"
37 static void __stt_notify_state_changed(void *data);
38 static Eina_Bool __stt_notify_error(void *data);
40 static Ecore_Timer* g_connect_timer = NULL;
41 static float g_volume_db = 0;
43 static int g_feature_enabled = -1;
45 static int g_privilege_allowed = -1;
46 static int g_privilege_applaunch_allowed = -1;
48 static cynara *p_cynara = NULL;
50 static bool g_err_callback_status = false;
57 static int __stt_get_feature_enabled()
59 if (0 == g_feature_enabled) {
60 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] STT NOT supported");
61 return STT_ERROR_NOT_SUPPORTED;
62 } else if (-1 == g_feature_enabled) {
63 bool stt_supported = false;
64 bool mic_supported = false;
65 if (0 == system_info_get_platform_bool(STT_FEATURE_PATH, &stt_supported)) {
66 if (0 == system_info_get_platform_bool(STT_MIC_FEATURE_PATH, &mic_supported)) {
67 if (false == stt_supported || false == mic_supported) {
68 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] STT NOT supported");
69 g_feature_enabled = 0;
70 return STT_ERROR_NOT_SUPPORTED;
73 g_feature_enabled = 1;
75 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to get feature value");
76 return STT_ERROR_NOT_SUPPORTED;
79 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to get feature value");
80 return STT_ERROR_NOT_SUPPORTED;
87 static int __check_privilege_initialize()
89 int ret = cynara_initialize(&p_cynara, NULL);
90 if (CYNARA_API_SUCCESS != ret)
91 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] fail to initialize");
93 return ret == CYNARA_API_SUCCESS;
96 static bool __check_privilege(const char* uid, const char * privilege)
99 char label_path[1024] = "/proc/self/attr/current";
100 char smack_label[1024] = {'\0',};
106 fp = fopen(label_path, "r");
108 if (fread(smack_label, 1, sizeof(smack_label), fp) <= 0)
109 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] fail to fread");
114 pid_t pid = getpid();
115 char *session = cynara_session_from_pid(pid);
116 int ret = cynara_check(p_cynara, smack_label, session, uid, privilege);
117 SLOG(LOG_DEBUG, TAG_STTC, "[Client]cynara_check returned %d(%s)", ret, (CYNARA_API_ACCESS_ALLOWED == ret) ? "Allowed" : "Denied");
123 if (ret != CYNARA_API_ACCESS_ALLOWED)
128 static void __check_privilege_deinitialize()
131 cynara_finish(p_cynara);
135 static int __stt_check_privilege()
139 if (0 == g_privilege_allowed) {
140 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Permission is denied");
141 return STT_ERROR_PERMISSION_DENIED;
142 } else if (-1 == g_privilege_allowed) {
143 if (false == __check_privilege_initialize()) {
144 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] privilege initialize is failed");
145 return STT_ERROR_PERMISSION_DENIED;
147 snprintf(uid, 16, "%d", getuid());
148 if (false == __check_privilege(uid, STT_PRIVILEGE_RECORDER)) {
149 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Permission is denied");
150 g_privilege_allowed = 0;
151 __check_privilege_deinitialize();
152 return STT_ERROR_PERMISSION_DENIED;
154 __check_privilege_deinitialize();
157 g_privilege_allowed = 1;
158 return STT_ERROR_NONE;
161 static int __stt_check_privilege_for_applaunch()
165 if (0 == g_privilege_applaunch_allowed) {
166 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Permission for applaunch is denied");
167 return STT_ERROR_PERMISSION_DENIED;
168 } else if (-1 == g_privilege_applaunch_allowed) {
169 if (false == __check_privilege_initialize()) {
170 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] privilege initialize is failed (applaunch)");
171 return STT_ERROR_PERMISSION_DENIED;
173 snprintf(uid, 16, "%d", getuid());
174 if (false == __check_privilege(uid, STT_PRIVILEGE_APPLAUNCH)) {
175 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Permission is denied : appmanager.launch");
176 g_privilege_applaunch_allowed = 0;
177 __check_privilege_deinitialize();
178 return STT_ERROR_PERMISSION_DENIED;
180 __check_privilege_deinitialize();
183 g_privilege_applaunch_allowed = 1;
184 return STT_ERROR_NONE;
187 static const char* __stt_get_error_code(stt_error_e err)
190 case STT_ERROR_NONE: return "STT_ERROR_NONE";
191 case STT_ERROR_OUT_OF_MEMORY: return "STT_ERROR_OUT_OF_MEMORY";
192 case STT_ERROR_IO_ERROR: return "STT_ERROR_IO_ERROR";
193 case STT_ERROR_INVALID_PARAMETER: return "STT_ERROR_INVALID_PARAMETER";
194 case STT_ERROR_TIMED_OUT: return "STT_ERROR_TIMED_OUT";
195 case STT_ERROR_RECORDER_BUSY: return "STT_ERROR_RECORDER_BUSY";
196 case STT_ERROR_OUT_OF_NETWORK: return "STT_ERROR_OUT_OF_NETWORK";
197 case STT_ERROR_PERMISSION_DENIED: return "STT_ERROR_PERMISSION_DENIED";
198 case STT_ERROR_NOT_SUPPORTED: return "STT_ERROR_NOT_SUPPORTED";
199 case STT_ERROR_INVALID_STATE: return "STT_ERROR_INVALID_STATE";
200 case STT_ERROR_INVALID_LANGUAGE: return "STT_ERROR_INVALID_LANGUAGE";
201 case STT_ERROR_ENGINE_NOT_FOUND: return "STT_ERROR_ENGINE_NOT_FOUND";
202 case STT_ERROR_OPERATION_FAILED: return "STT_ERROR_OPERATION_FAILED";
203 case STT_ERROR_NOT_SUPPORTED_FEATURE: return "STT_ERROR_NOT_SUPPORTED_FEATURE";
204 case STT_ERROR_SERVICE_RESET: return "STT_ERROR_SERVICE_RESET";
206 return "Invalid error code";
210 static int __stt_convert_config_error_code(stt_config_error_e code)
212 if (code == STT_CONFIG_ERROR_NONE) return STT_ERROR_NONE;
213 if (code == STT_CONFIG_ERROR_OUT_OF_MEMORY) return STT_ERROR_OUT_OF_MEMORY;
214 if (code == STT_CONFIG_ERROR_IO_ERROR) return STT_ERROR_IO_ERROR;
215 if (code == STT_CONFIG_ERROR_INVALID_PARAMETER) return STT_ERROR_INVALID_PARAMETER;
216 if (code == STT_CONFIG_ERROR_PERMISSION_DENIED) return STT_ERROR_PERMISSION_DENIED;
217 if (code == STT_CONFIG_ERROR_NOT_SUPPORTED) return STT_ERROR_NOT_SUPPORTED;
218 if (code == STT_CONFIG_ERROR_INVALID_STATE) return STT_ERROR_INVALID_STATE;
219 if (code == STT_CONFIG_ERROR_INVALID_LANGUAGE) return STT_ERROR_INVALID_LANGUAGE;
220 if (code == STT_CONFIG_ERROR_ENGINE_NOT_FOUND) return STT_ERROR_ENGINE_NOT_FOUND;
221 if (code == STT_CONFIG_ERROR_OPERATION_FAILED) return STT_ERROR_OPERATION_FAILED;
226 void __stt_config_lang_changed_cb(const char* before_language, const char* current_language, void* user_data)
228 SLOG(LOG_DEBUG, TAG_STTC, "Language changed : Before lang(%s) Current lang(%s)",
229 before_language, current_language);
231 if (0 == strcmp(before_language, current_language)) {
235 GList* client_list = NULL;
236 client_list = stt_client_get_client_list();
239 stt_client_s *data = NULL;
241 if (g_list_length(client_list) > 0) {
242 /* Get a first item */
243 iter = g_list_first(client_list);
245 while (NULL != iter) {
247 if (NULL != data->default_lang_changed_cb) {
248 SLOG(LOG_DEBUG, TAG_STTC, "Call default language changed callback : uid(%d)", data->uid);
249 data->default_lang_changed_cb(data->stt, before_language, current_language,
250 data->default_lang_changed_user_data);
254 iter = g_list_next(iter);
261 static Eina_Bool __reconnect_by_engine_changed(void *data)
263 stt_h stt = (stt_h)data;
265 stt_client_s* client = stt_client_get(stt);
266 if (NULL == client) {
267 SLOG(LOG_ERROR, TAG_STTC, "[WARNING] A handle is not valid");
271 if (STT_STATE_READY != client->current_state) {
276 int ret = stt_unprepare(stt);
278 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to prepare for setting a new engine... (%d)", ret);
280 ret = stt_prepare(stt);
282 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to prepare for setting a new engine... (%d)", ret);
288 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)
290 stt_h stt = (stt_h)user_data;
292 stt_client_s* client = stt_client_get(stt);
293 if (NULL == client) {
294 SLOG(LOG_ERROR, TAG_STTC, "[WARNING] A handle is not valid");
298 if (NULL != engine_id) SLOG(LOG_DEBUG, TAG_STTC, "Engine id(%s)", engine_id);
299 if (NULL != setting) SLOG(LOG_DEBUG, TAG_STTC, "Engine setting(%s)", setting);
300 if (NULL != language) SLOG(LOG_DEBUG, TAG_STTC, "Language(%s)", language);
301 SLOG(LOG_DEBUG, TAG_STTC, "Silence(%s), Credential(%s)", support_silence ? "on" : "off", need_credential ? "need" : "no need");
303 /* When the default engine is changed, please unload the old engine and load the new one. */
306 if (NULL == client->current_engine_id) {
307 if (STT_STATE_RECORDING == client->current_state || STT_STATE_PROCESSING == client->current_state) {
308 ret = stt_cancel(stt);
310 SLOG(LOG_DEBUG, TAG_STTC, "[DEBUG] STT client canceling...");
313 ecore_idler_add(__reconnect_by_engine_changed, (void*)stt);
314 } else if (STT_STATE_READY == client->current_state) {
315 ret = stt_unprepare(stt);
317 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to prepare for setting a new engine... (%d)", ret);
319 ret = stt_prepare(stt);
321 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to prepare for setting a new engine... (%d)", ret);
326 /* call callback function */
327 if (NULL != client->engine_changed_cb) {
328 client->engine_changed_cb(stt, engine_id, language, support_silence, need_credential, client->engine_changed_user_data);
330 SLOG(LOG_WARN, TAG_STTC, "No registered callback function for engine change");
335 static int __stt_check_handle(stt_h stt, stt_client_s** client)
338 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input handle is null");
339 return STT_ERROR_INVALID_PARAMETER;
342 stt_client_s* temp = NULL;
343 temp = stt_client_get(stt);
347 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] A handle is not available");
348 return STT_ERROR_INVALID_PARAMETER;
352 return STT_ERROR_NONE;
355 int stt_create(stt_h* stt)
357 if (0 != __stt_get_feature_enabled()) {
358 return STT_ERROR_NOT_SUPPORTED;
360 if (0 != __stt_check_privilege()) {
361 return STT_ERROR_PERMISSION_DENIED;
364 SLOG(LOG_DEBUG, TAG_STTC, "===== Create STT");
367 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] A handle is null");
368 return STT_ERROR_INVALID_PARAMETER;
371 if (0 == stt_client_get_size()) {
372 if (0 != stt_dbus_open_connection()) {
373 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to open connection");
374 return STT_ERROR_OPERATION_FAILED;
378 if (0 != stt_client_new(stt)) {
379 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to create client!");
380 return STT_ERROR_OUT_OF_MEMORY;
383 stt_client_s* client = stt_client_get(*stt);
384 if (NULL == client) {
385 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to create client");
386 stt_client_destroy(*stt);
387 return STT_ERROR_OPERATION_FAILED;
390 int ret = stt_config_mgr_initialize(client->uid);
391 ret = __stt_convert_config_error_code(ret);
393 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to init config manager : %s", __stt_get_error_code(ret));
394 stt_client_destroy(*stt);
398 ret = stt_config_mgr_set_callback(client->uid, __stt_config_engine_changed_cb, __stt_config_lang_changed_cb, NULL, client->stt);
399 ret = __stt_convert_config_error_code(ret);
401 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to set config changed : %s", __stt_get_error_code(ret));
402 stt_client_destroy(*stt);
406 SLOG(LOG_DEBUG, TAG_STTC, "[Success] uid(%d)", (*stt)->handle);
408 SLOG(LOG_DEBUG, TAG_STTC, "=====");
409 SLOG(LOG_DEBUG, TAG_STTC, " ");
411 return STT_ERROR_NONE;
414 int stt_destroy(stt_h stt)
416 stt_client_s* client = NULL;
417 if (0 != __stt_get_feature_enabled()) {
418 return STT_ERROR_NOT_SUPPORTED;
420 if (0 != __stt_check_privilege()) {
421 return STT_ERROR_PERMISSION_DENIED;
423 if (0 != __stt_check_handle(stt, &client)) {
424 return STT_ERROR_INVALID_PARAMETER;
427 SLOG(LOG_DEBUG, TAG_STTC, "===== Destroy STT");
429 /* check used callback */
430 if (0 != stt_client_get_use_callback(client)) {
431 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Cannot destroy in Callback function");
432 return STT_ERROR_OPERATION_FAILED;
435 stt_config_mgr_finalize(client->uid);
440 switch (client->current_state) {
441 case STT_STATE_PROCESSING:
442 case STT_STATE_RECORDING:
443 case STT_STATE_READY:
444 ret = stt_dbus_request_finalize(client->uid);
446 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to request finalize : %s", __stt_get_error_code(ret));
448 case STT_STATE_CREATED:
449 if (NULL != g_connect_timer) {
450 SLOG(LOG_DEBUG, TAG_STTC, "Connect Timer is deleted");
451 ecore_timer_del(g_connect_timer);
452 g_connect_timer = NULL;
456 stt_client_destroy(stt);
462 if (0 == stt_client_get_size()) {
463 if (0 != stt_dbus_close_connection()) {
464 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to close connection");
470 SLOG(LOG_DEBUG, TAG_STTC, "=====");
471 SLOG(LOG_DEBUG, TAG_STTC, " ");
473 return STT_ERROR_NONE;
476 bool __stt_config_supported_engine_cb(const char* engine_id, const char* engine_name,
477 const char* setting, bool support_silence, void* user_data)
479 stt_h stt = (stt_h)user_data;
481 stt_client_s* client = stt_client_get(stt);
482 if (NULL == client) {
483 SLOG(LOG_ERROR, TAG_STTC, "[WARNING] A handle is not valid");
487 /* call callback function */
488 if (NULL != client->supported_engine_cb) {
489 return client->supported_engine_cb(stt, engine_id, engine_name, client->supported_engine_user_data);
491 SLOG(LOG_WARN, TAG_STTC, "No registered callback function of supported engine");
497 int stt_foreach_supported_engines(stt_h stt, stt_supported_engine_cb callback, void* user_data)
499 stt_client_s* client = NULL;
500 if (0 != __stt_get_feature_enabled()) {
501 return STT_ERROR_NOT_SUPPORTED;
503 if (0 != __stt_check_privilege()) {
504 return STT_ERROR_PERMISSION_DENIED;
506 if (0 != __stt_check_handle(stt, &client)) {
507 return STT_ERROR_INVALID_PARAMETER;
510 SLOG(LOG_DEBUG, TAG_STTC, "===== Foreach Supported engine");
512 if (NULL == callback) {
513 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL");
514 return STT_ERROR_INVALID_PARAMETER;
517 if (client->current_state != STT_STATE_CREATED) {
518 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State: Current state(%d) is not CREATED", client->current_state);
519 return STT_ERROR_INVALID_STATE;
522 client->supported_engine_cb = callback;
523 client->supported_engine_user_data = user_data;
526 ret = stt_config_mgr_get_engine_list(__stt_config_supported_engine_cb, client->stt);
527 ret = __stt_convert_config_error_code(ret);
529 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to get engines : %s", __stt_get_error_code(ret));
532 client->supported_engine_cb = NULL;
533 client->supported_engine_user_data = NULL;
535 SLOG(LOG_DEBUG, TAG_STTC, "=====");
536 SLOG(LOG_DEBUG, TAG_STTC, " ");
541 int stt_get_engine(stt_h stt, char** engine_id)
543 stt_client_s* client = NULL;
544 if (0 != __stt_get_feature_enabled()) {
545 return STT_ERROR_NOT_SUPPORTED;
547 if (0 != __stt_check_privilege()) {
548 return STT_ERROR_PERMISSION_DENIED;
550 if (0 != __stt_check_handle(stt, &client)) {
551 return STT_ERROR_INVALID_PARAMETER;
554 SLOG(LOG_DEBUG, TAG_STTC, "===== Get current engine");
556 if (NULL == engine_id) {
557 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL");
558 return STT_ERROR_INVALID_PARAMETER;
561 if (client->current_state != STT_STATE_CREATED) {
562 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State: Current state(%d) is not CREATED", client->current_state);
563 return STT_ERROR_INVALID_STATE;
568 if (NULL != client->current_engine_id) {
569 *engine_id = strdup(client->current_engine_id);
570 SLOG(LOG_DEBUG, TAG_STTC, "[SUCCESS] Current engine uuid = %s", *engine_id);
573 ret = stt_config_mgr_get_engine(engine_id);
574 ret = __stt_convert_config_error_code(ret);
576 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to request get current engine : %s", __stt_get_error_code(ret));
578 SLOG(LOG_DEBUG, TAG_STTC, "[SUCCESS] Current engine uuid = %s", *engine_id);
582 SLOG(LOG_DEBUG, TAG_STTC, "=====");
583 SLOG(LOG_DEBUG, TAG_STTC, " ");
588 int __stt_set_buxtonkey(const char* engine_id)
591 struct buxton_client * bux_cli;
592 struct buxton_layer * bux_layer;
593 struct buxton_value * bux_val;
595 int ret = buxton_open(&bux_cli, NULL, NULL);
597 SLOG(LOG_ERROR, stt_tag(), "[DBUS-BUXTON2] Fail to open buxton client");
598 return STT_ERROR_OPERATION_FAILED;
600 SLOG(LOG_DEBUG, stt_tag(), "[DBUS-BUXTON2] buxton_open: %d", ret);
601 bux_layer = buxton_create_layer("system");
602 if (NULL == bux_layer) {
603 SLOG(LOG_ERROR, stt_tag(), "[DBUS-BUXTON2] buxton_create_layer FAIL");
604 buxton_close(bux_cli);
606 return STT_ERROR_OPERATION_FAILED;
608 bux_val = buxton_value_create_string(engine_id);
609 if (NULL == bux_val) {
610 SLOG(LOG_ERROR, stt_tag(), "[DBUS-BUXTON2] buxton_value_create_string FAIL");
611 buxton_free_layer(bux_layer);
612 buxton_close(bux_cli);
615 return STT_ERROR_OPERATION_FAILED;
618 ret = buxton_set_value_sync(bux_cli, bux_layer, STT_ENGINE_DB_CUSTOM, bux_val);
620 SLOG(LOG_ERROR, stt_tag(), "[DBUS-BUXTON2] Fail to set value sync");
621 buxton_value_free(bux_val);
622 buxton_free_layer(bux_layer);
623 buxton_close(bux_cli);
628 return STT_ERROR_OPERATION_FAILED;
630 SLOG(LOG_DEBUG, stt_tag(), "[DBUS-BUXTON2] buxton_set_value_sync: %d, %s", ret, STT_ENGINE_DB_CUSTOM);
632 buxton_value_free(bux_val);
633 buxton_free_layer(bux_layer);
634 buxton_close(bux_cli);
640 return STT_ERROR_NONE;
643 int stt_set_engine(stt_h stt, const char* engine_id)
645 stt_client_s* client = NULL;
646 if (0 != __stt_get_feature_enabled()) {
647 return STT_ERROR_NOT_SUPPORTED;
649 if (0 != __stt_check_privilege()) {
650 return STT_ERROR_PERMISSION_DENIED;
652 if (0 != __stt_check_privilege_for_applaunch()) {
653 return STT_ERROR_PERMISSION_DENIED;
655 if (0 != __stt_check_handle(stt, &client)) {
656 return STT_ERROR_INVALID_PARAMETER;
659 SLOG(LOG_DEBUG, TAG_STTC, "===== Set current engine");
661 if (NULL == engine_id) {
662 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL");
663 return STT_ERROR_INVALID_PARAMETER;
667 if (client->current_state != STT_STATE_CREATED) {
668 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State: Current state(%d) is not CREATED", client->current_state);
669 return STT_ERROR_INVALID_STATE;
672 if (NULL != client->current_engine_id) {
673 free(client->current_engine_id);
674 client->current_engine_id = NULL;
677 SLOG(LOG_DEBUG, TAG_STTC, "===== engined_id(%s)", engine_id);
679 client->current_engine_id = strdup(engine_id);
682 int ret = __stt_set_buxtonkey(engine_id);
684 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] set buxtonkey Failed!!!");
688 SLOG(LOG_DEBUG, TAG_STTC, "=====");
689 SLOG(LOG_DEBUG, TAG_STTC, " ");
694 int stt_set_credential(stt_h stt, const char* credential)
696 stt_client_s* client = NULL;
697 if (0 != __stt_get_feature_enabled()) {
698 return STT_ERROR_NOT_SUPPORTED;
700 if (0 != __stt_check_privilege()) {
701 return STT_ERROR_PERMISSION_DENIED;
703 if (0 != __stt_check_handle(stt, &client)) {
704 return STT_ERROR_INVALID_PARAMETER;
707 SLOG(LOG_DEBUG, TAG_STTC, "===== Set credential");
709 if (NULL == credential) {
710 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL");
711 return STT_ERROR_INVALID_PARAMETER;
715 if (client->current_state != STT_STATE_CREATED && client->current_state != STT_STATE_READY) {
716 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State: Current state(%d) is not CREATED or READY", client->current_state);
717 return STT_ERROR_INVALID_STATE;
720 if (NULL != client->credential) {
721 free(client->credential);
722 client->credential = NULL;
724 client->credential = strdup(credential);
726 SLOG(LOG_DEBUG, TAG_STTC, "=====");
727 SLOG(LOG_DEBUG, TAG_STTC, " ");
729 return STT_ERROR_NONE;
732 int stt_set_private_data(stt_h stt, const char* key, const char* data)
734 stt_client_s* client = NULL;
735 if (0 != __stt_get_feature_enabled()) {
736 return STT_ERROR_NOT_SUPPORTED;
738 if (0 != __stt_check_privilege()) {
739 return STT_ERROR_PERMISSION_DENIED;
741 if (0 != __stt_check_handle(stt, &client)) {
742 return STT_ERROR_INVALID_PARAMETER;
745 SLOG(LOG_DEBUG, TAG_STTC, "===== Set private data");
747 if (NULL == key || NULL == data) {
748 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid parameter");
749 return STT_ERROR_INVALID_PARAMETER;
753 if (STT_STATE_READY != client->current_state) {
754 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State: Current state(%d) is not READY", client->current_state);
755 return STT_ERROR_INVALID_STATE;
758 if (true != client->internal && (0 == strcmp(key, "server") || 0 == strcmp(key, "rampcode") || 0 == strcmp(key, "epd"))) {
759 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] This is not an internal app");
760 return STT_ERROR_INVALID_PARAMETER;
766 ret = stt_dbus_request_set_private_data(client->uid, key, data);
768 if (STT_ERROR_TIMED_OUT != ret) {
769 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to set private data : %s", __stt_get_error_code(ret));
772 SLOG(LOG_WARN, TAG_STTC, "[WARNING] retry : %s", __stt_get_error_code(ret));
775 if (STT_RETRY_COUNT == count) {
776 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to request");
783 SLOG(LOG_DEBUG, TAG_STTC, "=====");
784 SLOG(LOG_DEBUG, TAG_STTC, "");
786 return STT_ERROR_NONE;
789 int stt_get_private_data(stt_h stt, const char* key, char** data)
791 stt_client_s* client = NULL;
792 if (0 != __stt_get_feature_enabled()) {
793 return STT_ERROR_NOT_SUPPORTED;
795 if (0 != __stt_check_privilege()) {
796 return STT_ERROR_PERMISSION_DENIED;
798 if (0 != __stt_check_handle(stt, &client)) {
799 return STT_ERROR_INVALID_PARAMETER;
802 SLOG(LOG_DEBUG, TAG_STTC, "===== Get private data");
804 if (NULL == key || NULL == data) {
805 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid parameter");
806 return STT_ERROR_INVALID_PARAMETER;
810 if (STT_STATE_READY != client->current_state) {
811 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State: Current state(%d) is not READY", client->current_state);
812 return STT_ERROR_INVALID_STATE;
818 ret = stt_dbus_request_get_private_data(client->uid, key, data);
820 if (STT_ERROR_TIMED_OUT != ret) {
821 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to get private data : %s", __stt_get_error_code(ret));
824 SLOG(LOG_WARN, TAG_STTC, "[WARNING] retry : %s", __stt_get_error_code(ret));
827 if (STT_RETRY_COUNT == count) {
828 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to request");
835 if (0 == strncmp(*data, "NULL", strlen(*data))) {
840 SLOG(LOG_DEBUG, TAG_STTC, "=====");
841 SLOG(LOG_DEBUG, TAG_STTC, "");
843 return STT_ERROR_NONE;
846 int stt_set_server_stt(stt_h stt, const char* key, char* user_data)
849 stt_client_s* client = NULL;
851 if (0 != __stt_get_feature_enabled()) {
852 return STT_ERROR_NOT_SUPPORTED;
854 if (0 != __stt_check_privilege()) {
855 return STT_ERROR_PERMISSION_DENIED;
857 if (0 != __stt_check_handle(stt, &client)) {
858 return STT_ERROR_INVALID_PARAMETER;
861 SLOG(LOG_DEBUG, TAG_STTC, "===== Set STT server");
863 if (NULL == key || NULL == user_data) {
864 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid parameter");
865 return STT_ERROR_INVALID_PARAMETER;
868 if (STT_STATE_CREATED != client->current_state && STT_STATE_READY != client->current_state) {
869 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] The current state is invalid (%d).", client->current_state);
870 return STT_ERROR_INVALID_STATE;
874 client->internal = true;
876 char* private_key = NULL;
877 private_key = strdup(key);
878 if (NULL == private_key) {
879 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to allocate memory(private_key)");
880 return STT_ERROR_OUT_OF_MEMORY;
884 data = strdup(user_data);
886 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to allocate memory(data)");
889 return STT_ERROR_OUT_OF_MEMORY;
892 ret = stt_set_private_data(stt, private_key, data);
894 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to set private data, ret(%d), key(%s)", ret, private_key);
902 SLOG(LOG_DEBUG, TAG_STTC, "======");
903 SLOG(LOG_DEBUG, TAG_STTC, " ");
908 static Eina_Bool __stt_connect_daemon(void *data)
910 stt_client_s* client = (stt_client_s*)data;
913 if (NULL == client) {
914 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] A handle is not available");
915 g_connect_timer = NULL;
919 /* Check and Set vconfkey of custom engine before sending hello */
920 if (1 == g_privilege_applaunch_allowed && NULL != client->current_engine_id) {
922 ret = __stt_set_buxtonkey(client->current_engine_id);
924 SLOG(LOG_DEBUG, TAG_STTC, "[DEBUG] set buxtonkey Failed!!! (inside __stt_connect_daemon)");
930 ret = stt_dbus_request_hello(client->uid);
933 if (STT_ERROR_INVALID_STATE == ret) {
934 g_connect_timer = NULL;
940 g_connect_timer = NULL;
941 SLOG(LOG_DEBUG, TAG_STTC, "===== Connect stt-service");
943 /* request initialization */
944 bool silence_supported = false;
945 bool credential_needed = false;
947 ret = stt_dbus_request_initialize(client->uid, &silence_supported, &credential_needed);
949 if (STT_ERROR_ENGINE_NOT_FOUND == ret) {
950 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to initialize : %s", __stt_get_error_code(ret));
952 client->reason = STT_ERROR_ENGINE_NOT_FOUND;
953 ecore_timer_add(0, __stt_notify_error, (void*)client);
957 } else if (STT_ERROR_NONE != ret) {
958 SLOG(LOG_ERROR, TAG_STTC, "[WARNING] Fail to connection. Retry to connect");
961 /* success to connect stt-service */
962 client->silence_supported = silence_supported;
963 client->credential_needed = credential_needed;
964 SLOG(LOG_DEBUG, TAG_STTC, "Supported options : silence(%s), credential(%s)", silence_supported ? "support" : "no support", credential_needed ? "need" : "no need");
967 #ifdef __UNUSED_CODES__
968 if (NULL != client->current_engine_id) {
971 silence_supported = false;
972 credential_needed = false;
973 SLOG(LOG_DEBUG, TAG_STTC, "[WARNING] current_engine_id(%s)", client->current_engine_id);
976 ret = stt_dbus_request_set_current_engine(client->uid, client->current_engine_id, &silence_supported, &credential_needed);
978 if (STT_ERROR_TIMED_OUT != ret) {
979 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to set current engine : %s", __stt_get_error_code(ret));
982 SLOG(LOG_WARN, TAG_STTC, "[WARNING] retry");
985 if (STT_RETRY_COUNT == count) {
986 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to request");
991 SLOG(LOG_DEBUG, TAG_STTC, "[SUCCESS] Current engine uuid = %s", client->current_engine_id);
993 /* success to change engine */
994 client->silence_supported = silence_supported;
995 SLOG(LOG_DEBUG, TAG_STTC, "Supported options : silence(%s), credential(%s)", silence_supported ? "support" : "no support", credential_needed ? "need" : "no need");
1000 SLOG(LOG_DEBUG, TAG_STTC, "[SUCCESS] uid(%d)", client->uid);
1002 client->before_state = client->current_state;
1003 client->current_state = STT_STATE_READY;
1005 if (NULL != client->state_changed_cb) {
1006 stt_client_use_callback(client);
1007 client->state_changed_cb(client->stt, client->before_state,
1008 client->current_state, client->state_changed_user_data);
1009 stt_client_not_use_callback(client);
1010 SLOG(LOG_DEBUG, TAG_STTC, "State changed callback is called");
1012 SLOG(LOG_WARN, TAG_STTC, "[WARNING] State changed callback is null");
1015 SLOG(LOG_DEBUG, TAG_STTC, "=====");
1016 SLOG(LOG_DEBUG, TAG_STTC, " ");
1021 int stt_prepare(stt_h stt)
1023 stt_client_s* client = NULL;
1024 if (0 != __stt_get_feature_enabled()) {
1025 return STT_ERROR_NOT_SUPPORTED;
1027 if (0 != __stt_check_privilege()) {
1028 return STT_ERROR_PERMISSION_DENIED;
1030 if (0 != __stt_check_handle(stt, &client)) {
1031 return STT_ERROR_INVALID_PARAMETER;
1035 if (client->current_state != STT_STATE_CREATED) {
1036 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State: Current state(%d) is not 'CREATED'", client->current_state);
1037 return STT_ERROR_INVALID_STATE;
1040 g_connect_timer = ecore_timer_add(0, __stt_connect_daemon, (void*)client);
1042 SLOG(LOG_DEBUG, TAG_STTC, "=====");
1043 SLOG(LOG_DEBUG, TAG_STTC, " ");
1045 return STT_ERROR_NONE;
1048 int stt_unprepare(stt_h stt)
1050 stt_client_s* client = NULL;
1051 if (0 != __stt_get_feature_enabled()) {
1052 return STT_ERROR_NOT_SUPPORTED;
1054 if (0 != __stt_check_privilege()) {
1055 return STT_ERROR_PERMISSION_DENIED;
1057 if (0 != __stt_check_handle(stt, &client)) {
1058 return STT_ERROR_INVALID_PARAMETER;
1061 SLOG(LOG_DEBUG, TAG_STTC, "===== Unprepare STT");
1064 if (client->current_state != STT_STATE_READY) {
1065 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State: Current state(%d) is not 'READY'", client->current_state);
1066 return STT_ERROR_INVALID_STATE;
1072 ret = stt_dbus_request_finalize(client->uid);
1074 if (STT_ERROR_TIMED_OUT != ret) {
1075 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to request finalize : %s", __stt_get_error_code(ret));
1078 SLOG(LOG_WARN, TAG_STTC, "[WARNING] retry");
1081 if (STT_RETRY_COUNT == count) {
1082 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to request");
1089 client->internal_state = STT_INTERNAL_STATE_NONE;
1091 client->before_state = client->current_state;
1092 client->current_state = STT_STATE_CREATED;
1094 if (NULL != client->state_changed_cb) {
1095 stt_client_use_callback(client);
1096 client->state_changed_cb(client->stt, client->before_state,
1097 client->current_state, client->state_changed_user_data);
1098 stt_client_not_use_callback(client);
1100 SLOG(LOG_WARN, TAG_STTC, "[WARNING] State changed callback is null");
1103 if (g_connect_timer) {
1104 ecore_timer_del(g_connect_timer);
1105 g_connect_timer = NULL;
1108 SLOG(LOG_DEBUG, TAG_STTC, "=====");
1109 SLOG(LOG_DEBUG, TAG_STTC, " ");
1111 return STT_ERROR_NONE;
1114 bool __stt_config_supported_language_cb(const char* engine_id, const char* language, void* user_data)
1116 stt_h stt = (stt_h)user_data;
1118 stt_client_s* client = stt_client_get(stt);
1119 if (NULL == client) {
1120 SLOG(LOG_ERROR, TAG_STTC, "[WARNING] A handle is not valid");
1124 /* call callback function */
1125 if (NULL != client->supported_lang_cb) {
1126 return client->supported_lang_cb(stt, language, client->supported_lang_user_data);
1128 SLOG(LOG_WARN, TAG_STTC, "No registered callback function of supported languages");
1134 int stt_foreach_supported_languages(stt_h stt, stt_supported_language_cb callback, void* user_data)
1136 stt_client_s* client = NULL;
1137 if (0 != __stt_get_feature_enabled()) {
1138 return STT_ERROR_NOT_SUPPORTED;
1140 if (0 != __stt_check_privilege()) {
1141 return STT_ERROR_PERMISSION_DENIED;
1143 if (0 != __stt_check_handle(stt, &client)) {
1144 return STT_ERROR_INVALID_PARAMETER;
1147 SLOG(LOG_DEBUG, TAG_STTC, "===== Foreach Supported Language");
1149 if (NULL == callback) {
1150 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL");
1151 return STT_ERROR_INVALID_PARAMETER;
1155 char* current_engine_id = NULL;
1157 if (NULL == client->current_engine_id) {
1158 ret = stt_config_mgr_get_engine(¤t_engine_id);
1159 ret = __stt_convert_config_error_code(ret);
1161 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to get default engine id : %s", __stt_get_error_code(ret));
1165 current_engine_id = strdup(client->current_engine_id);
1166 if (NULL == current_engine_id) {
1167 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to allocate memory");
1168 return STT_ERROR_OUT_OF_MEMORY;
1172 client->supported_lang_cb = callback;
1173 client->supported_lang_user_data = user_data;
1175 ret = stt_config_mgr_get_language_list(current_engine_id, __stt_config_supported_language_cb, client->stt);
1176 ret = __stt_convert_config_error_code(ret);
1178 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to get languages : %s", __stt_get_error_code(ret));
1181 if (NULL != current_engine_id) {
1182 free(current_engine_id);
1183 current_engine_id = NULL;
1186 client->supported_lang_cb = NULL;
1187 client->supported_lang_user_data = NULL;
1189 SLOG(LOG_DEBUG, TAG_STTC, "=====");
1190 SLOG(LOG_DEBUG, TAG_STTC, " ");
1195 int stt_get_default_language(stt_h stt, char** language)
1197 stt_client_s* client = NULL;
1198 if (0 != __stt_get_feature_enabled()) {
1199 return STT_ERROR_NOT_SUPPORTED;
1201 if (0 != __stt_check_privilege()) {
1202 return STT_ERROR_PERMISSION_DENIED;
1204 if (0 != __stt_check_handle(stt, &client)) {
1205 return STT_ERROR_INVALID_PARAMETER;
1208 SLOG(LOG_DEBUG, TAG_STTC, "===== Get Default Language");
1210 if (NULL == language) {
1211 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL");
1212 return STT_ERROR_INVALID_PARAMETER;
1216 ret = stt_config_mgr_get_default_language(language);
1217 ret = __stt_convert_config_error_code(ret);
1219 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to get default language : %s", __stt_get_error_code(ret));
1221 SLOG(LOG_DEBUG, TAG_STTC, "[SUCCESS] Current language = %s", *language);
1224 SLOG(LOG_DEBUG, TAG_STTC, "=====");
1225 SLOG(LOG_DEBUG, TAG_STTC, " ");
1230 int stt_get_state(stt_h stt, stt_state_e* state)
1232 stt_client_s* client = NULL;
1233 if (0 != __stt_get_feature_enabled()) {
1234 return STT_ERROR_NOT_SUPPORTED;
1236 if (0 != __stt_check_privilege()) {
1237 return STT_ERROR_PERMISSION_DENIED;
1239 if (0 != __stt_check_handle(stt, &client)) {
1240 return STT_ERROR_INVALID_PARAMETER;
1243 if (NULL == state) {
1244 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL");
1245 return STT_ERROR_INVALID_PARAMETER;
1248 *state = client->current_state;
1251 case STT_STATE_CREATED: SLOG(LOG_DEBUG, TAG_STTC, "Current state is 'CREATED'"); break;
1252 case STT_STATE_READY: SLOG(LOG_DEBUG, TAG_STTC, "Current state is 'Ready'"); break;
1253 case STT_STATE_RECORDING: SLOG(LOG_DEBUG, TAG_STTC, "Current state is 'Recording'"); break;
1254 case STT_STATE_PROCESSING: SLOG(LOG_DEBUG, TAG_STTC, "Current state is 'Processing'"); break;
1255 default: SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid value"); break;
1258 return STT_ERROR_NONE;
1261 int stt_get_error_message(stt_h stt, char** err_msg)
1263 stt_client_s* client = NULL;
1264 if (0 != __stt_get_feature_enabled()) {
1265 return STT_ERROR_NOT_SUPPORTED;
1267 if (0 != __stt_check_privilege()) {
1268 return STT_ERROR_PERMISSION_DENIED;
1270 if (0 != __stt_check_handle(stt, &client)) {
1271 return STT_ERROR_INVALID_PARAMETER;
1274 if (NULL == err_msg) {
1275 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL");
1276 return STT_ERROR_INVALID_PARAMETER;
1279 if (false == g_err_callback_status) {
1280 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] This callback should be called during an err_callback");
1281 return STT_ERROR_OPERATION_FAILED;
1284 if (NULL != client->err_msg) {
1285 *err_msg = strdup(client->err_msg);
1286 SLOG(LOG_DEBUG, TAG_STTC, "[SUCCESS] Error msg (%s)", *err_msg);
1288 SLOG(LOG_DEBUG, TAG_STTC, "[SUCCESS] Error msg (NULL)");
1291 SLOG(LOG_DEBUG, TAG_STTC, "=====");
1292 SLOG(LOG_DEBUG, TAG_STTC, " ");
1294 return STT_ERROR_NONE;
1297 int stt_is_recognition_type_supported(stt_h stt, const char* type, bool* support)
1299 stt_client_s* client = NULL;
1300 if (0 != __stt_get_feature_enabled()) {
1301 return STT_ERROR_NOT_SUPPORTED;
1303 if (0 != __stt_check_privilege()) {
1304 return STT_ERROR_PERMISSION_DENIED;
1306 if (0 != __stt_check_handle(stt, &client)) {
1307 return STT_ERROR_INVALID_PARAMETER;
1310 if (NULL == type || NULL == support) {
1311 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL");
1312 return STT_ERROR_INVALID_PARAMETER;
1316 if (client->current_state != STT_STATE_READY) {
1317 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State: Current state(%d) is not READY", client->current_state);
1318 return STT_ERROR_INVALID_STATE;
1324 ret = stt_dbus_request_is_recognition_type_supported(client->uid, type, support);
1326 if (STT_ERROR_TIMED_OUT != ret) {
1327 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to get recognition type supported : %s", __stt_get_error_code(ret));
1330 SLOG(LOG_WARN, TAG_STTC, "[WARNING] retry");
1333 if (STT_RETRY_COUNT == count) {
1334 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to request");
1339 SLOG(LOG_DEBUG, TAG_STTC, "[SUCCESS] recognition type is %s", *support ? "true " : "false");
1344 return STT_ERROR_NONE;
1347 int stt_set_silence_detection(stt_h stt, stt_option_silence_detection_e type)
1349 stt_client_s* client = NULL;
1350 if (0 != __stt_get_feature_enabled()) {
1351 return STT_ERROR_NOT_SUPPORTED;
1353 if (0 != __stt_check_privilege()) {
1354 return STT_ERROR_PERMISSION_DENIED;
1356 if (0 != __stt_check_handle(stt, &client)) {
1357 return STT_ERROR_INVALID_PARAMETER;
1361 if (client->current_state != STT_STATE_READY) {
1362 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State: Current state(%d) is not READY", client->current_state);
1363 return STT_ERROR_INVALID_STATE;
1366 if (true == client->silence_supported) {
1367 if (type >= STT_OPTION_SILENCE_DETECTION_FALSE && type <= STT_OPTION_SILENCE_DETECTION_AUTO) {
1368 client->silence = type;
1370 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Type is invalid");
1371 return STT_ERROR_INVALID_PARAMETER;
1374 return STT_ERROR_NOT_SUPPORTED_FEATURE;
1377 return STT_ERROR_NONE;
1380 int stt_set_start_sound(stt_h stt, const char* filename)
1382 stt_client_s* client = NULL;
1383 if (0 != __stt_get_feature_enabled()) {
1384 return STT_ERROR_NOT_SUPPORTED;
1386 if (0 != __stt_check_privilege()) {
1387 return STT_ERROR_PERMISSION_DENIED;
1389 if (0 != __stt_check_handle(stt, &client)) {
1390 return STT_ERROR_INVALID_PARAMETER;
1393 SLOG(LOG_DEBUG, TAG_STTC, "===== STT SET START SOUND");
1395 if (NULL == filename) {
1396 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL");
1397 return STT_ERROR_INVALID_PARAMETER;
1400 if (0 != access(filename, F_OK)) {
1401 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] File does not exist");
1402 return STT_ERROR_INVALID_PARAMETER;
1406 if (client->current_state != STT_STATE_READY) {
1407 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State: Current state(%d) is not READY", client->current_state);
1408 return STT_ERROR_INVALID_STATE;
1414 ret = stt_dbus_request_set_start_sound(client->uid, filename);
1416 if (STT_ERROR_TIMED_OUT != ret) {
1417 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to set start sound : %s", __stt_get_error_code(ret));
1420 SLOG(LOG_WARN, TAG_STTC, "[WARNING] retry");
1423 if (STT_RETRY_COUNT == count) {
1424 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to request");
1429 SLOG(LOG_DEBUG, TAG_STTC, "[SUCCESS] Set start sound : %s", filename);
1434 return STT_ERROR_NONE;
1437 int stt_unset_start_sound(stt_h stt)
1439 stt_client_s* client = NULL;
1440 if (0 != __stt_get_feature_enabled()) {
1441 return STT_ERROR_NOT_SUPPORTED;
1443 if (0 != __stt_check_privilege()) {
1444 return STT_ERROR_PERMISSION_DENIED;
1446 if (0 != __stt_check_handle(stt, &client)) {
1447 return STT_ERROR_INVALID_PARAMETER;
1450 SLOG(LOG_DEBUG, TAG_STTC, "===== STT UNSET START SOUND");
1453 if (client->current_state != STT_STATE_READY) {
1454 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State: Current state(%d) is not READY", client->current_state);
1455 return STT_ERROR_INVALID_STATE;
1461 ret = stt_dbus_request_unset_start_sound(client->uid);
1463 if (STT_ERROR_TIMED_OUT != ret) {
1464 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to unset start sound : %s", __stt_get_error_code(ret));
1467 SLOG(LOG_WARN, TAG_STTC, "[WARNING] retry");
1470 if (STT_RETRY_COUNT == count) {
1471 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to request");
1476 SLOG(LOG_DEBUG, TAG_STTC, "[SUCCESS] Unset start sound");
1481 return STT_ERROR_NONE;
1484 int stt_set_stop_sound(stt_h stt, const char* filename)
1486 stt_client_s* client = NULL;
1487 if (0 != __stt_get_feature_enabled()) {
1488 return STT_ERROR_NOT_SUPPORTED;
1490 if (0 != __stt_check_privilege()) {
1491 return STT_ERROR_PERMISSION_DENIED;
1493 if (0 != __stt_check_handle(stt, &client)) {
1494 return STT_ERROR_INVALID_PARAMETER;
1497 SLOG(LOG_DEBUG, TAG_STTC, "===== STT SET STOP SOUND");
1499 if (NULL == filename) {
1500 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL");
1501 return STT_ERROR_INVALID_PARAMETER;
1504 if (0 != access(filename, F_OK)) {
1505 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] File does not exist");
1506 return STT_ERROR_INVALID_PARAMETER;
1510 if (client->current_state != STT_STATE_READY) {
1511 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State: Current state(%d) is not READY", client->current_state);
1512 return STT_ERROR_INVALID_STATE;
1518 ret = stt_dbus_request_set_stop_sound(client->uid, filename);
1520 if (STT_ERROR_TIMED_OUT != ret) {
1521 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to set stop sound : %s", __stt_get_error_code(ret));
1524 SLOG(LOG_WARN, TAG_STTC, "[WARNING] retry");
1527 if (STT_RETRY_COUNT == count) {
1528 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to request");
1533 SLOG(LOG_DEBUG, TAG_STTC, "[SUCCESS] Set stop sound : %s", filename);
1538 return STT_ERROR_NONE;
1541 int stt_unset_stop_sound(stt_h stt)
1543 stt_client_s* client = NULL;
1544 if (0 != __stt_get_feature_enabled()) {
1545 return STT_ERROR_NOT_SUPPORTED;
1547 if (0 != __stt_check_privilege()) {
1548 return STT_ERROR_PERMISSION_DENIED;
1550 if (0 != __stt_check_handle(stt, &client)) {
1551 return STT_ERROR_INVALID_PARAMETER;
1554 SLOG(LOG_DEBUG, TAG_STTC, "===== STT UNSET STOP SOUND");
1557 if (client->current_state != STT_STATE_READY) {
1558 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State: Current state(%d) is not READY", client->current_state);
1559 return STT_ERROR_INVALID_STATE;
1565 ret = stt_dbus_request_unset_stop_sound(client->uid);
1567 if (STT_ERROR_TIMED_OUT != ret) {
1568 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to unset stop sound : %s", __stt_get_error_code(ret));
1571 SLOG(LOG_WARN, TAG_STTC, "[WARNING] retry");
1574 if (STT_RETRY_COUNT == count) {
1575 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to request");
1580 SLOG(LOG_DEBUG, TAG_STTC, "[SUCCESS] Unset stop sound");
1585 return STT_ERROR_NONE;
1588 int stt_start(stt_h stt, const char* language, const char* type)
1590 stt_client_s* client = NULL;
1591 if (0 != __stt_get_feature_enabled()) {
1592 return STT_ERROR_NOT_SUPPORTED;
1594 if (0 != __stt_check_privilege()) {
1595 return STT_ERROR_PERMISSION_DENIED;
1597 if (0 != __stt_check_handle(stt, &client)) {
1598 return STT_ERROR_INVALID_PARAMETER;
1601 SLOG(LOG_DEBUG, TAG_STTC, "===== STT START");
1604 if (client->current_state != STT_STATE_READY) {
1605 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State: Current state(%d) is not READY", client->current_state);
1606 return STT_ERROR_INVALID_STATE;
1609 if (STT_INTERNAL_STATE_NONE != client->internal_state) {
1610 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State : Internal state is NOT none : %d", client->internal_state);
1611 return STT_ERROR_IN_PROGRESS_TO_RECORDING;
1615 char appid[128] = {0, };
1616 ret = aul_app_get_appid_bypid(getpid(), appid, sizeof(appid));
1618 if ((AUL_R_OK != ret) || (0 == strlen(appid))) {
1619 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to get application ID");
1621 SLOG(LOG_DEBUG, TAG_STTC, "[DEBUG] Current app id is %s", appid);
1625 if (NULL == language) {
1626 temp = strdup("default");
1628 temp = strdup(language);
1631 if (true == client->credential_needed && NULL == client->credential) {
1632 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Do not have app credential for this engine(%s)", client->current_engine_id);
1633 return STT_ERROR_PERMISSION_DENIED;
1636 client->internal_state = STT_INTERNAL_STATE_STARTING;
1637 ret = stt_dbus_request_start(client->uid, temp, type, client->silence, appid, client->credential);
1639 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to start : %s", __stt_get_error_code(ret));
1640 client->internal_state = STT_INTERNAL_STATE_NONE;
1642 SLOG(LOG_DEBUG, TAG_STTC, "[SUCCESS] Start is successful but not done");
1645 if (NULL != temp) free(temp);
1647 SLOG(LOG_DEBUG, TAG_STTC, "=====");
1648 SLOG(LOG_DEBUG, TAG_STTC, " ");
1653 int stt_stop(stt_h stt)
1655 stt_client_s* client = NULL;
1656 if (0 != __stt_get_feature_enabled()) {
1657 return STT_ERROR_NOT_SUPPORTED;
1659 if (0 != __stt_check_privilege()) {
1660 return STT_ERROR_PERMISSION_DENIED;
1662 if (0 != __stt_check_handle(stt, &client)) {
1663 return STT_ERROR_INVALID_PARAMETER;
1666 SLOG(LOG_DEBUG, TAG_STTC, "===== STT STOP");
1669 if (client->current_state != STT_STATE_RECORDING) {
1670 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State : Current state(%d) is NOT RECORDING", client->current_state);
1671 return STT_ERROR_INVALID_STATE;
1674 if (STT_INTERNAL_STATE_STARTING == client->internal_state) {
1675 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State : Internal state is STARTING : %d", client->internal_state);
1676 return STT_ERROR_IN_PROGRESS_TO_RECORDING;
1677 } else if (STT_INTERNAL_STATE_CANCELING == client->internal_state) {
1678 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State : Internal state is CANCELING : %d", client->internal_state);
1679 return STT_ERROR_IN_PROGRESS_TO_READY;
1680 } else if (STT_INTERNAL_STATE_STOPPING == client->internal_state) {
1681 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State : Internal state is STOPPING : %d", client->internal_state);
1682 return STT_ERROR_IN_PROGRESS_TO_PROCESSING;
1685 client->internal_state = STT_INTERNAL_STATE_STOPPING;
1686 int ret = stt_dbus_request_stop(client->uid);
1688 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to stop : %s", __stt_get_error_code(ret));
1689 client->internal_state = STT_INTERNAL_STATE_NONE;
1691 SLOG(LOG_DEBUG, TAG_STTC, "[SUCCESS] Stop is successful but not done");
1694 SLOG(LOG_DEBUG, TAG_STTC, "=====");
1695 SLOG(LOG_DEBUG, TAG_STTC, " ");
1701 int stt_cancel(stt_h stt)
1703 stt_client_s* client = NULL;
1704 if (0 != __stt_get_feature_enabled()) {
1705 return STT_ERROR_NOT_SUPPORTED;
1707 if (0 != __stt_check_privilege()) {
1708 return STT_ERROR_PERMISSION_DENIED;
1710 if (0 != __stt_check_handle(stt, &client)) {
1711 return STT_ERROR_INVALID_PARAMETER;
1714 SLOG(LOG_DEBUG, TAG_STTC, "===== STT CANCEL");
1717 if (STT_STATE_RECORDING != client->current_state && STT_STATE_PROCESSING != client->current_state) {
1718 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid state : Current state(%d) is 'Ready'", client->current_state);
1719 return STT_ERROR_INVALID_STATE;
1722 if (STT_INTERNAL_STATE_STARTING == client->internal_state) {
1723 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State : Internal state is STARTING : %d", client->internal_state);
1724 return STT_ERROR_IN_PROGRESS_TO_RECORDING;
1725 } else if (STT_INTERNAL_STATE_STOPPING == client->internal_state) {
1726 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State : Internal state is STOPPING : %d", client->internal_state);
1727 return STT_ERROR_IN_PROGRESS_TO_PROCESSING;
1728 } else if (STT_INTERNAL_STATE_CANCELING == client->internal_state) {
1729 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State : Internal state is CANCELING : %d", client->internal_state);
1730 return STT_ERROR_IN_PROGRESS_TO_READY;
1733 client->internal_state = STT_INTERNAL_STATE_CANCELING;
1734 int ret = stt_dbus_request_cancel(client->uid);
1736 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to cancel : %s", __stt_get_error_code(ret));
1737 client->internal_state = STT_INTERNAL_STATE_NONE;
1739 SLOG(LOG_DEBUG, TAG_STTC, "[SUCCESS] Cancel is successful but not done");
1742 SLOG(LOG_DEBUG, TAG_STTC, "=====");
1743 SLOG(LOG_DEBUG, TAG_STTC, " ");
1748 int __stt_cb_set_volume(int uid, float volume)
1750 stt_client_s* client = NULL;
1752 client = stt_client_get_by_uid(uid);
1753 if (NULL == client) {
1754 SLOG(LOG_ERROR, TAG_STTC, "Handle is NOT valid");
1755 return STT_ERROR_INVALID_PARAMETER;
1758 if (STT_STATE_RECORDING != client->current_state) {
1759 SLOG(LOG_DEBUG, TAG_STTC, "[ERROR] Invalid state : NO 'Recording' state, cur(%d)", client->current_state);
1760 return STT_ERROR_INVALID_STATE;
1763 g_volume_db = volume;
1764 SLOG(LOG_DEBUG, TAG_STTC, "Set volume (%f)", g_volume_db);
1769 int stt_get_recording_volume(stt_h stt, float* volume)
1771 stt_client_s* client = NULL;
1772 if (0 != __stt_get_feature_enabled()) {
1773 return STT_ERROR_NOT_SUPPORTED;
1775 if (0 != __stt_check_privilege()) {
1776 return STT_ERROR_PERMISSION_DENIED;
1778 if (0 != __stt_check_handle(stt, &client)) {
1779 return STT_ERROR_INVALID_PARAMETER;
1782 if (NULL == volume) {
1783 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL");
1784 return STT_ERROR_INVALID_PARAMETER;
1787 if (STT_STATE_RECORDING != client->current_state) {
1788 SLOG(LOG_DEBUG, TAG_STTC, "[ERROR] Invalid state : NO 'Recording' state, cur(%d)", client->current_state);
1789 return STT_ERROR_INVALID_STATE;
1792 *volume = g_volume_db;
1794 return STT_ERROR_NONE;
1797 bool __stt_result_time_cb(int index, int event, const char* text, long start_time, long end_time, void* user_data)
1799 stt_client_s* client = (stt_client_s*)user_data;
1802 if (NULL == client) {
1803 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to notify error : A handle is not valid");
1807 if (NULL != client->result_time_cb) {
1808 SLOG(LOG_DEBUG, TAG_STTC, "(%d) event(%d) text(%s) start(%ld) end(%ld)",
1809 index, event, text, start_time, end_time);
1810 client->result_time_cb(client->stt, index, (stt_result_time_event_e)event,
1811 text, start_time, end_time, client->result_time_user_data);
1813 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Callback is NULL");
1820 int stt_foreach_detailed_result(stt_h stt, stt_result_time_cb callback, void* user_data)
1822 stt_client_s* client = NULL;
1823 if (0 != __stt_get_feature_enabled()) {
1824 return STT_ERROR_NOT_SUPPORTED;
1826 if (0 != __stt_check_privilege()) {
1827 return STT_ERROR_PERMISSION_DENIED;
1829 if (0 != __stt_check_handle(stt, &client)) {
1830 return STT_ERROR_INVALID_PARAMETER;
1833 SLOG(LOG_DEBUG, TAG_STTC, "===== STT FOREACH DETAILED RESULT");
1835 if (NULL == callback) {
1836 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL");
1837 return STT_ERROR_INVALID_PARAMETER;
1840 client->result_time_cb = callback;
1841 client->result_time_user_data = user_data;
1844 ret = stt_config_mgr_foreach_time_info(__stt_result_time_cb, client);
1845 ret = __stt_convert_config_error_code(ret);
1847 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to foreach time info : %s", __stt_get_error_code(ret));
1850 client->result_time_cb = NULL;
1851 client->result_time_user_data = NULL;
1853 SLOG(LOG_DEBUG, TAG_STTC, "=====");
1854 SLOG(LOG_DEBUG, TAG_STTC, " ");
1859 static Eina_Bool __stt_notify_error(void *data)
1861 stt_client_s* client = (stt_client_s*)data;
1863 SLOG(LOG_WARN, TAG_STTC, "[WARNING] Error from sttd");
1866 if (NULL == client) {
1867 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to notify error : A handle is not valid");
1871 if (NULL == stt_client_get_by_uid(client->uid))
1874 if (NULL != client->error_cb) {
1875 stt_client_use_callback(client);
1876 g_err_callback_status = true;
1877 client->error_cb(client->stt, client->reason, client->error_user_data);
1878 g_err_callback_status = false;
1879 stt_client_not_use_callback(client);
1880 SLOG(LOG_WARN, TAG_STTC, "[WARNING] Error callback is called : reason [%d]", client->reason);
1882 SLOG(LOG_WARN, TAG_STTC, "[WARNING] Error callback is null");
1888 int __stt_cb_error(int uid, int reason, char* err_msg)
1891 GList* client_list = NULL;
1892 client_list = stt_client_get_client_list();
1895 stt_client_s *data = NULL;
1897 if (g_list_length(client_list) > 0) {
1898 /* Get a first item */
1899 iter = g_list_first(client_list);
1901 while (NULL != iter) {
1904 data->reason = reason;
1905 data->internal_state = STT_INTERNAL_STATE_NONE;
1906 if (NULL != data->err_msg) {
1907 free(data->err_msg);
1908 data->err_msg = NULL;
1910 if (NULL != err_msg)
1911 data->err_msg = strdup(err_msg);
1913 SLOG(LOG_INFO, TAG_STTC, "internal state is initialized to 0");
1915 if (NULL != data->error_cb) {
1916 ecore_timer_add(0, __stt_notify_error, data);
1918 SLOG(LOG_WARN, TAG_STTC, "[WARNING] Error callback is null");
1921 if (STT_ERROR_SERVICE_RESET == reason) {
1922 SLOG(LOG_WARN, TAG_STTC, "[WARNING] Service reset");
1924 data->current_state = STT_STATE_CREATED;
1925 if (0 != stt_prepare(data->stt)) {
1926 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to prepare");
1931 iter = g_list_next(iter);
1935 stt_client_s* client = stt_client_get_by_uid(uid);
1936 if (NULL == client) {
1937 SLOG(LOG_ERROR, TAG_STTC, "Handle not found");
1941 client->reason = reason;
1942 client->internal_state = STT_INTERNAL_STATE_NONE;
1943 if (NULL != client->err_msg) {
1944 free(client->err_msg);
1945 client->err_msg = NULL;
1947 if (NULL != err_msg)
1948 client->err_msg = strdup(err_msg);
1950 SLOG(LOG_INFO, TAG_STTC, "internal state is initialized to 0");
1952 if (NULL != client->error_cb) {
1953 ecore_timer_add(0, __stt_notify_error, client);
1955 SLOG(LOG_WARN, TAG_STTC, "[WARNING] Error callback is null");
1958 if (STT_ERROR_SERVICE_RESET == reason) {
1959 SLOG(LOG_WARN, TAG_STTC, "[WARNING] Service reset");
1961 client->current_state = STT_STATE_CREATED;
1962 if (0 != stt_prepare(client->stt)) {
1963 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to prepare");
1971 static void __stt_notify_state_changed(void *data)
1973 stt_client_s* client = (stt_client_s*)data;
1976 if (NULL == client) {
1977 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to notify error : A handle is not valid");
1981 if (NULL == stt_client_get_by_uid(client->uid)) {
1985 if (STT_INTERNAL_STATE_STARTING == client->internal_state && STT_STATE_RECORDING == client->current_state) {
1986 client->internal_state = STT_INTERNAL_STATE_NONE;
1987 SLOG(LOG_DEBUG, TAG_STTC, "Internal state change to NONE");
1988 } else if (STT_INTERNAL_STATE_STOPPING == client->internal_state && STT_STATE_PROCESSING == client->current_state) {
1989 client->internal_state = STT_INTERNAL_STATE_NONE;
1990 SLOG(LOG_DEBUG, TAG_STTC, "Internal state change to NONE");
1991 } else if (STT_INTERNAL_STATE_CANCELING == client->internal_state && STT_STATE_READY == client->current_state) {
1992 client->internal_state = STT_INTERNAL_STATE_NONE;
1993 SLOG(LOG_DEBUG, TAG_STTC, "Internal state change to NONE");
1996 if (NULL != client->state_changed_cb) {
1997 stt_client_use_callback(client);
1998 client->state_changed_cb(client->stt, client->before_state,
1999 client->current_state, client->state_changed_user_data);
2000 stt_client_not_use_callback(client);
2001 SLOG(LOG_DEBUG, TAG_STTC, "State changed callback is called");
2003 SLOG(LOG_WARN, TAG_STTC, "[WARNING] State changed callback is null");
2009 static Eina_Bool __stt_notify_result(void *data)
2011 stt_client_s* client = (stt_client_s*)data;
2014 if (NULL == client) {
2015 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to notify error : A handle is not valid");
2019 if (NULL == stt_client_get_by_uid(client->uid)) {
2023 if (NULL != client->recognition_result_cb) {
2024 stt_client_use_callback(client);
2025 client->recognition_result_cb(client->stt, client->event, (const char**)client->data_list, client->data_count,
2026 client->msg, client->recognition_result_user_data);
2027 stt_client_not_use_callback(client);
2028 SLOG(LOG_DEBUG, TAG_STTC, "client recognition result callback called");
2030 SLOG(LOG_WARN, TAG_STTC, "[WARNING] User recognition result callback is NULL");
2033 if (NULL != client->msg) {
2038 if (NULL != client->data_list) {
2040 temp = client->data_list;
2043 for (i = 0; i < client->data_count; i++) {
2044 if (NULL != temp[i]) {
2048 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Result data is error");
2051 free(client->data_list);
2052 client->data_list = NULL;
2055 client->data_count = 0;
2057 stt_config_mgr_remove_time_info_file();
2059 if (STT_RESULT_EVENT_FINAL_RESULT == client->event || STT_RESULT_EVENT_ERROR == client->event) {
2060 client->before_state = client->current_state;
2061 client->current_state = STT_STATE_READY;
2063 if (NULL != client->state_changed_cb) {
2064 ecore_main_loop_thread_safe_call_async(__stt_notify_state_changed, client);
2066 SLOG(LOG_WARN, TAG_STTC, "[WARNING] State changed callback is null");
2073 int __stt_cb_result(int uid, int event, char** data, int data_count, const char* msg)
2075 stt_client_s* client = NULL;
2077 client = stt_client_get_by_uid(uid);
2078 if (NULL == client) {
2079 SLOG(LOG_ERROR, TAG_STTC, "Handle is NOT valid");
2080 return STT_ERROR_INVALID_PARAMETER;
2084 SLOG(LOG_DEBUG, TAG_STTC, "Recognition Result Message = %s", msg);
2087 for (i = 0; i < data_count; i++) {
2088 if (NULL != data[i])
2089 SLOG(LOG_DEBUG, TAG_STTC, "Recognition Result[%d] = %s", i, data[i]);
2092 if (NULL != client->recognition_result_cb) {
2093 client->event = event;
2095 client->msg = strdup(msg);
2098 client->data_count = data_count;
2100 if (data_count > 0) {
2102 temp = (char**)calloc(data_count, sizeof(char*));
2104 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to allocate memory");
2105 return STT_ERROR_OUT_OF_MEMORY;
2108 for (i = 0; i < data_count; i++) {
2109 if (NULL != data[i])
2110 temp[i] = strdup(data[i]);
2112 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Result data is error");
2115 client->data_list = temp;
2118 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] User result callback is null");
2121 ecore_timer_add(0, __stt_notify_result, client);
2123 return STT_ERROR_NONE;
2126 int __stt_cb_set_state(int uid, int state)
2128 stt_client_s* client = stt_client_get_by_uid(uid);
2129 if (NULL == client) {
2130 SLOG(LOG_ERROR, TAG_STTC, "Handle not found");
2134 stt_state_e state_from_daemon = (stt_state_e)state;
2136 if (client->current_state == state_from_daemon) {
2137 SLOG(LOG_DEBUG, TAG_STTC, "Current state has already been %d", client->current_state);
2141 client->before_state = client->current_state;
2142 client->current_state = state_from_daemon;
2144 ecore_main_loop_thread_safe_call_async(__stt_notify_state_changed, client);
2148 static void __stt_notify_speech_status(void *data)
2150 stt_client_s* client = (stt_client_s*)data;
2153 if (NULL == client) {
2154 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to notify speech status : A handle is not valid");
2158 if (NULL == stt_client_get_by_uid(client->uid)) {
2162 if (NULL != client->speech_status_cb) {
2163 stt_client_use_callback(client);
2164 client->speech_status_cb(client->stt, client->speech_status, client->speech_status_user_data);
2165 stt_client_not_use_callback(client);
2166 SLOG(LOG_DEBUG, TAG_STTC, "Speech status callback is called");
2168 SLOG(LOG_WARN, TAG_STTC, "[WARNING] Speech status callback is null");
2174 int __stt_cb_speech_status(int uid, int status)
2176 stt_client_s* client = stt_client_get_by_uid(uid);
2177 if (NULL == client) {
2178 SLOG(LOG_ERROR, TAG_STTC, "Handle not found");
2182 client->speech_status = status;
2184 ecore_main_loop_thread_safe_call_async(__stt_notify_speech_status, client);
2188 int stt_set_recognition_result_cb(stt_h stt, stt_recognition_result_cb callback, void* user_data)
2190 stt_client_s* client = NULL;
2191 if (0 != __stt_get_feature_enabled()) {
2192 return STT_ERROR_NOT_SUPPORTED;
2194 if (0 != __stt_check_privilege()) {
2195 return STT_ERROR_PERMISSION_DENIED;
2197 if (0 != __stt_check_handle(stt, &client)) {
2198 return STT_ERROR_INVALID_PARAMETER;
2201 if (callback == NULL)
2202 return STT_ERROR_INVALID_PARAMETER;
2204 if (STT_STATE_CREATED != client->current_state) {
2205 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Current state(%d) is not 'Created'", client->current_state);
2206 return STT_ERROR_INVALID_STATE;
2209 client->recognition_result_cb = callback;
2210 client->recognition_result_user_data = user_data;
2215 int stt_unset_recognition_result_cb(stt_h stt)
2217 stt_client_s* client = NULL;
2218 if (0 != __stt_get_feature_enabled()) {
2219 return STT_ERROR_NOT_SUPPORTED;
2221 if (0 != __stt_check_privilege()) {
2222 return STT_ERROR_PERMISSION_DENIED;
2224 if (0 != __stt_check_handle(stt, &client)) {
2225 return STT_ERROR_INVALID_PARAMETER;
2228 if (STT_STATE_CREATED != client->current_state) {
2229 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Current state(%d) is not 'Created'", client->current_state);
2230 return STT_ERROR_INVALID_STATE;
2233 client->recognition_result_cb = NULL;
2234 client->recognition_result_user_data = NULL;
2239 int stt_set_state_changed_cb(stt_h stt, stt_state_changed_cb callback, void* user_data)
2241 stt_client_s* client = NULL;
2242 if (0 != __stt_get_feature_enabled()) {
2243 return STT_ERROR_NOT_SUPPORTED;
2245 if (0 != __stt_check_privilege()) {
2246 return STT_ERROR_PERMISSION_DENIED;
2248 if (0 != __stt_check_handle(stt, &client)) {
2249 return STT_ERROR_INVALID_PARAMETER;
2252 if (NULL == callback)
2253 return STT_ERROR_INVALID_PARAMETER;
2255 if (STT_STATE_CREATED != client->current_state) {
2256 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Current state(%d) is not 'Created'", client->current_state);
2257 return STT_ERROR_INVALID_STATE;
2260 client->state_changed_cb = callback;
2261 client->state_changed_user_data = user_data;
2266 int stt_unset_state_changed_cb(stt_h stt)
2268 stt_client_s* client = NULL;
2269 if (0 != __stt_get_feature_enabled()) {
2270 return STT_ERROR_NOT_SUPPORTED;
2272 if (0 != __stt_check_privilege()) {
2273 return STT_ERROR_PERMISSION_DENIED;
2275 if (0 != __stt_check_handle(stt, &client)) {
2276 return STT_ERROR_INVALID_PARAMETER;
2279 if (STT_STATE_CREATED != client->current_state) {
2280 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Current state(%d) is not 'Created'", client->current_state);
2281 return STT_ERROR_INVALID_STATE;
2284 client->state_changed_cb = NULL;
2285 client->state_changed_user_data = NULL;
2290 int stt_set_error_cb(stt_h stt, stt_error_cb callback, void* user_data)
2292 stt_client_s* client = NULL;
2293 if (0 != __stt_get_feature_enabled()) {
2294 return STT_ERROR_NOT_SUPPORTED;
2296 if (0 != __stt_check_privilege()) {
2297 return STT_ERROR_PERMISSION_DENIED;
2299 if (0 != __stt_check_handle(stt, &client)) {
2300 return STT_ERROR_INVALID_PARAMETER;
2303 if (NULL == callback)
2304 return STT_ERROR_INVALID_PARAMETER;
2306 if (STT_STATE_CREATED != client->current_state) {
2307 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Current state(%d) is not 'Created'", client->current_state);
2308 return STT_ERROR_INVALID_STATE;
2311 client->error_cb = callback;
2312 client->error_user_data = user_data;
2317 int stt_unset_error_cb(stt_h stt)
2319 stt_client_s* client = NULL;
2320 if (0 != __stt_get_feature_enabled()) {
2321 return STT_ERROR_NOT_SUPPORTED;
2323 if (0 != __stt_check_privilege()) {
2324 return STT_ERROR_PERMISSION_DENIED;
2326 if (0 != __stt_check_handle(stt, &client)) {
2327 return STT_ERROR_INVALID_PARAMETER;
2330 if (STT_STATE_CREATED != client->current_state) {
2331 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Current state(%d) is not 'Created'", client->current_state);
2332 return STT_ERROR_INVALID_STATE;
2335 client->error_cb = NULL;
2336 client->error_user_data = NULL;
2341 int stt_set_default_language_changed_cb(stt_h stt, stt_default_language_changed_cb callback, void* user_data)
2343 stt_client_s* client = NULL;
2344 if (0 != __stt_get_feature_enabled()) {
2345 return STT_ERROR_NOT_SUPPORTED;
2347 if (0 != __stt_check_privilege()) {
2348 return STT_ERROR_PERMISSION_DENIED;
2350 if (0 != __stt_check_handle(stt, &client)) {
2351 return STT_ERROR_INVALID_PARAMETER;
2354 if (NULL == callback)
2355 return STT_ERROR_INVALID_PARAMETER;
2357 if (STT_STATE_CREATED != client->current_state) {
2358 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Current state(%d) is not 'Created'", client->current_state);
2359 return STT_ERROR_INVALID_STATE;
2362 client->default_lang_changed_cb = callback;
2363 client->default_lang_changed_user_data = user_data;
2368 int stt_unset_default_language_changed_cb(stt_h stt)
2370 stt_client_s* client = NULL;
2371 if (0 != __stt_get_feature_enabled()) {
2372 return STT_ERROR_NOT_SUPPORTED;
2374 if (0 != __stt_check_privilege()) {
2375 return STT_ERROR_PERMISSION_DENIED;
2377 if (0 != __stt_check_handle(stt, &client)) {
2378 return STT_ERROR_INVALID_PARAMETER;
2381 if (STT_STATE_CREATED != client->current_state) {
2382 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Current state(%d) is not 'Created'", client->current_state);
2383 return STT_ERROR_INVALID_STATE;
2386 client->default_lang_changed_cb = NULL;
2387 client->default_lang_changed_user_data = NULL;
2392 int stt_set_engine_changed_cb(stt_h stt, stt_engine_changed_cb callback, void* user_data)
2394 stt_client_s* client = NULL;
2395 if (0 != __stt_get_feature_enabled()) {
2396 return STT_ERROR_NOT_SUPPORTED;
2398 if (0 != __stt_check_privilege()) {
2399 return STT_ERROR_PERMISSION_DENIED;
2401 if (0 != __stt_check_handle(stt, &client)) {
2402 return STT_ERROR_INVALID_PARAMETER;
2405 if (NULL == callback)
2406 return STT_ERROR_INVALID_PARAMETER;
2408 if (STT_STATE_CREATED != client->current_state) {
2409 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Current state(%d) is not 'Created'", client->current_state);
2410 return STT_ERROR_INVALID_STATE;
2413 client->engine_changed_cb = callback;
2414 client->engine_changed_user_data = user_data;
2419 int stt_unset_engine_changed_cb(stt_h stt)
2421 stt_client_s* client = NULL;
2422 if (0 != __stt_get_feature_enabled()) {
2423 return STT_ERROR_NOT_SUPPORTED;
2425 if (0 != __stt_check_privilege()) {
2426 return STT_ERROR_PERMISSION_DENIED;
2428 if (0 != __stt_check_handle(stt, &client)) {
2429 return STT_ERROR_INVALID_PARAMETER;
2432 if (STT_STATE_CREATED != client->current_state) {
2433 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Current state(%d) is not 'Created'", client->current_state);
2434 return STT_ERROR_INVALID_STATE;
2437 client->engine_changed_cb = NULL;
2438 client->engine_changed_user_data = NULL;
2443 int stt_set_speech_status_cb(stt_h stt, stt_speech_status_cb callback, void* user_data)
2445 stt_client_s* client = NULL;
2446 if (0 != __stt_get_feature_enabled()) {
2447 return STT_ERROR_NOT_SUPPORTED;
2449 if (0 != __stt_check_privilege()) {
2450 return STT_ERROR_PERMISSION_DENIED;
2452 if (0 != __stt_check_handle(stt, &client)) {
2453 return STT_ERROR_INVALID_PARAMETER;
2456 if (NULL == callback)
2457 return STT_ERROR_INVALID_PARAMETER;
2459 if (STT_STATE_CREATED != client->current_state) {
2460 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Current state(%d) is not 'Created'", client->current_state);
2461 return STT_ERROR_INVALID_STATE;
2464 client->speech_status_cb = callback;
2465 client->speech_status_user_data = user_data;
2470 int stt_unset_speech_status_cb(stt_h stt)
2472 stt_client_s* client = NULL;
2473 if (0 != __stt_get_feature_enabled()) {
2474 return STT_ERROR_NOT_SUPPORTED;
2476 if (0 != __stt_check_privilege()) {
2477 return STT_ERROR_PERMISSION_DENIED;
2479 if (0 != __stt_check_handle(stt, &client)) {
2480 return STT_ERROR_INVALID_PARAMETER;
2483 if (STT_STATE_CREATED != client->current_state) {
2484 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Current state(%d) is not 'Created'", client->current_state);
2485 return STT_ERROR_INVALID_STATE;
2488 client->speech_status_cb = NULL;
2489 client->speech_status_user_data = NULL;