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 void __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;
59 static int __stt_get_feature_enabled()
61 if (0 == g_feature_enabled) {
63 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] STT NOT supported");
64 return STT_ERROR_NOT_SUPPORTED;
66 } else if (-1 == g_feature_enabled) {
67 bool stt_supported = false;
68 bool mic_supported = false;
69 if (0 == system_info_get_platform_bool(STT_FEATURE_PATH, &stt_supported)) {
70 if (0 == system_info_get_platform_bool(STT_MIC_FEATURE_PATH, &mic_supported)) {
71 if (false == stt_supported || false == mic_supported) {
73 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] STT NOT supported");
74 g_feature_enabled = 0;
75 return STT_ERROR_NOT_SUPPORTED;
79 g_feature_enabled = 1;
82 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to get feature value");
83 return STT_ERROR_NOT_SUPPORTED;
88 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to get feature value");
89 return STT_ERROR_NOT_SUPPORTED;
97 static int __check_privilege_initialize()
99 int ret = cynara_initialize(&p_cynara, NULL);
100 if (CYNARA_API_SUCCESS != ret)
101 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] fail to initialize"); //LCOV_EXCL_LINE
103 return ret == CYNARA_API_SUCCESS;
106 static bool __check_privilege(const char* uid, const char * privilege)
109 char label_path[1024] = "/proc/self/attr/current";
110 char smack_label[1024] = {'\0',};
116 fp = fopen(label_path, "r");
118 if (0 >= fread(smack_label, 1, sizeof(smack_label), fp))
119 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] fail to fread"); //LCOV_EXCL_LINE
124 pid_t pid = getpid();
125 char *session = cynara_session_from_pid(pid);
126 int ret = cynara_check(p_cynara, smack_label, session, uid, privilege);
127 SLOG(LOG_DEBUG, TAG_STTC, "[Client]cynara_check returned %d(%s)", ret, (CYNARA_API_ACCESS_ALLOWED == ret) ? "Allowed" : "Denied");
133 if (ret != CYNARA_API_ACCESS_ALLOWED)
138 static void __check_privilege_deinitialize()
141 cynara_finish(p_cynara);
145 static int __stt_check_privilege()
149 if (0 == g_privilege_allowed) {
150 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Permission is denied"); //LCOV_EXCL_LINE
151 return STT_ERROR_PERMISSION_DENIED;
152 } else if (-1 == g_privilege_allowed) {
153 if (false == __check_privilege_initialize()) {
154 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] privilege initialize is failed"); //LCOV_EXCL_LINE
155 return STT_ERROR_PERMISSION_DENIED;
157 snprintf(uid, 16, "%d", getuid());
158 if (false == __check_privilege(uid, STT_PRIVILEGE_RECORDER)) {
159 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Permission is denied"); //LCOV_EXCL_LINE
160 g_privilege_allowed = 0;
161 __check_privilege_deinitialize();
162 return STT_ERROR_PERMISSION_DENIED;
164 __check_privilege_deinitialize();
167 g_privilege_allowed = 1;
168 return STT_ERROR_NONE;
171 static int __stt_check_privilege_for_applaunch()
175 if (0 == g_privilege_applaunch_allowed) {
176 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Permission for applaunch is denied"); //LCOV_EXCL_LINE
177 return STT_ERROR_PERMISSION_DENIED;
178 } else if (-1 == g_privilege_applaunch_allowed) {
179 if (false == __check_privilege_initialize()) {
180 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] privilege initialize is failed (applaunch)"); //LCOV_EXCL_LINE
181 return STT_ERROR_PERMISSION_DENIED;
183 snprintf(uid, 16, "%d", getuid());
184 if (false == __check_privilege(uid, STT_PRIVILEGE_APPLAUNCH)) {
185 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Permission is denied : appmanager.launch"); //LCOV_EXCL_LINE
186 g_privilege_applaunch_allowed = 0;
187 __check_privilege_deinitialize();
188 return STT_ERROR_PERMISSION_DENIED;
190 __check_privilege_deinitialize();
193 g_privilege_applaunch_allowed = 1;
194 return STT_ERROR_NONE;
197 static const char* __stt_get_error_code(stt_error_e err)
201 case STT_ERROR_NONE: return "STT_ERROR_NONE";
202 case STT_ERROR_OUT_OF_MEMORY: return "STT_ERROR_OUT_OF_MEMORY";
203 case STT_ERROR_IO_ERROR: return "STT_ERROR_IO_ERROR";
204 case STT_ERROR_INVALID_PARAMETER: return "STT_ERROR_INVALID_PARAMETER";
205 case STT_ERROR_TIMED_OUT: return "STT_ERROR_TIMED_OUT";
206 case STT_ERROR_RECORDER_BUSY: return "STT_ERROR_RECORDER_BUSY";
207 case STT_ERROR_OUT_OF_NETWORK: return "STT_ERROR_OUT_OF_NETWORK";
208 case STT_ERROR_PERMISSION_DENIED: return "STT_ERROR_PERMISSION_DENIED";
209 case STT_ERROR_NOT_SUPPORTED: return "STT_ERROR_NOT_SUPPORTED";
210 case STT_ERROR_INVALID_STATE: return "STT_ERROR_INVALID_STATE";
211 case STT_ERROR_INVALID_LANGUAGE: return "STT_ERROR_INVALID_LANGUAGE";
212 case STT_ERROR_ENGINE_NOT_FOUND: return "STT_ERROR_ENGINE_NOT_FOUND";
213 case STT_ERROR_OPERATION_FAILED: return "STT_ERROR_OPERATION_FAILED";
214 case STT_ERROR_NOT_SUPPORTED_FEATURE: return "STT_ERROR_NOT_SUPPORTED_FEATURE";
215 case STT_ERROR_SERVICE_RESET: return "STT_ERROR_SERVICE_RESET";
217 return "Invalid error code";
222 static int __stt_convert_config_error_code(stt_config_error_e code)
225 if (code == STT_CONFIG_ERROR_NONE) return STT_ERROR_NONE;
226 if (code == STT_CONFIG_ERROR_OUT_OF_MEMORY) return STT_ERROR_OUT_OF_MEMORY;
227 if (code == STT_CONFIG_ERROR_IO_ERROR) return STT_ERROR_IO_ERROR;
228 if (code == STT_CONFIG_ERROR_INVALID_PARAMETER) return STT_ERROR_INVALID_PARAMETER;
229 if (code == STT_CONFIG_ERROR_PERMISSION_DENIED) return STT_ERROR_PERMISSION_DENIED;
230 if (code == STT_CONFIG_ERROR_NOT_SUPPORTED) return STT_ERROR_NOT_SUPPORTED;
231 if (code == STT_CONFIG_ERROR_INVALID_STATE) return STT_ERROR_INVALID_STATE;
232 if (code == STT_CONFIG_ERROR_INVALID_LANGUAGE) return STT_ERROR_INVALID_LANGUAGE;
233 if (code == STT_CONFIG_ERROR_ENGINE_NOT_FOUND) return STT_ERROR_ENGINE_NOT_FOUND;
234 if (code == STT_CONFIG_ERROR_OPERATION_FAILED) return STT_ERROR_OPERATION_FAILED;
240 void __stt_config_lang_changed_cb(const char* before_language, const char* current_language, void* user_data)
242 SLOG(LOG_DEBUG, TAG_STTC, "Language changed : Before lang(%s) Current lang(%s)",
243 before_language, current_language);
245 if (0 == strcmp(before_language, current_language)) {
249 GList* client_list = NULL;
250 client_list = stt_client_get_client_list();
253 stt_client_s *data = NULL;
255 if (g_list_length(client_list) > 0) {
256 /* Get a first item */
257 iter = g_list_first(client_list);
259 while (NULL != iter) {
261 if (NULL != data->default_lang_changed_cb) {
262 SLOG(LOG_DEBUG, TAG_STTC, "Call default language changed callback : uid(%d)", data->uid);
263 data->default_lang_changed_cb(data->stt, before_language, current_language,
264 data->default_lang_changed_user_data);
268 iter = g_list_next(iter);
275 static Eina_Bool __reconnect_by_engine_changed(void *data)
277 stt_h stt = (stt_h)data;
279 stt_client_s* client = stt_client_get(stt);
280 if (NULL == client) {
281 SLOG(LOG_ERROR, TAG_STTC, "[WARNING] A handle is not valid");
285 if (STT_STATE_READY != client->current_state) {
290 int ret = stt_unprepare(stt);
292 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to prepare for setting a new engine... (%d)", ret);
294 ret = stt_prepare(stt);
296 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to prepare for setting a new engine... (%d)", ret);
302 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)
304 stt_h stt = (stt_h)user_data;
306 stt_client_s* client = stt_client_get(stt);
307 if (NULL == client) {
308 SLOG(LOG_ERROR, TAG_STTC, "[WARNING] A handle is not valid");
312 if (NULL != engine_id) SLOG(LOG_DEBUG, TAG_STTC, "Engine id(%s)", engine_id);
313 if (NULL != setting) SLOG(LOG_DEBUG, TAG_STTC, "Engine setting(%s)", setting);
314 if (NULL != language) SLOG(LOG_DEBUG, TAG_STTC, "Language(%s)", language);
315 SLOG(LOG_DEBUG, TAG_STTC, "Silence(%s), Credential(%s)", support_silence ? "on" : "off", need_credential ? "need" : "no need");
317 /* When the default engine is changed, please unload the old engine and load the new one. */
320 if (NULL == client->current_engine_id) {
321 if (STT_STATE_RECORDING == client->current_state || STT_STATE_PROCESSING == client->current_state) {
322 ret = stt_cancel(stt);
324 SLOG(LOG_DEBUG, TAG_STTC, "[DEBUG] STT client canceling...");
327 ecore_idler_add(__reconnect_by_engine_changed, (void*)stt);
328 } else if (STT_STATE_READY == client->current_state) {
329 ret = stt_unprepare(stt);
331 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to prepare for setting a new engine... (%d)", ret);
333 ret = stt_prepare(stt);
335 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to prepare for setting a new engine... (%d)", ret);
340 /* call callback function */
341 if (NULL != client->engine_changed_cb) {
342 client->engine_changed_cb(stt, engine_id, language, support_silence, need_credential, client->engine_changed_user_data);
344 SLOG(LOG_WARN, TAG_STTC, "No registered callback function for engine change");
349 static int __stt_check_handle(stt_h stt, stt_client_s** client)
352 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input handle is null");
353 return STT_ERROR_INVALID_PARAMETER;
356 stt_client_s* temp = NULL;
357 temp = stt_client_get(stt);
361 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] A handle is not available");
362 return STT_ERROR_INVALID_PARAMETER;
366 return STT_ERROR_NONE;
369 int stt_create(stt_h* stt)
371 if (0 != __stt_get_feature_enabled()) {
372 return STT_ERROR_NOT_SUPPORTED;
374 if (0 != __stt_check_privilege()) {
375 return STT_ERROR_PERMISSION_DENIED;
378 SLOG(LOG_DEBUG, TAG_STTC, "===== Create STT");
381 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] A handle is null");
382 return STT_ERROR_INVALID_PARAMETER;
385 if (0 == stt_client_get_size()) {
386 if (0 != stt_dbus_open_connection()) {
388 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to open connection");
389 return STT_ERROR_OPERATION_FAILED;
394 if (0 != stt_client_new(stt)) {
396 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to create client!");
397 return STT_ERROR_OUT_OF_MEMORY;
401 stt_client_s* client = stt_client_get(*stt);
402 if (NULL == client) {
403 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to create client"); //LCOV_EXCL_LINE
404 stt_client_destroy(*stt);
405 return STT_ERROR_OPERATION_FAILED;
408 int ret = stt_config_mgr_initialize(client->uid);
409 ret = __stt_convert_config_error_code(ret);
411 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to init config manager : %s", __stt_get_error_code(ret)); //LCOV_EXCL_LINE
412 stt_client_destroy(*stt);
416 ret = stt_config_mgr_set_callback(client->uid, __stt_config_engine_changed_cb, __stt_config_lang_changed_cb, NULL, client->stt);
417 ret = __stt_convert_config_error_code(ret);
419 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to set config changed : %s", __stt_get_error_code(ret)); //LCOV_EXCL_LINE
420 stt_client_destroy(*stt);
424 SLOG(LOG_DEBUG, TAG_STTC, "[Success] uid(%d)", (*stt)->handle);
426 SLOG(LOG_DEBUG, TAG_STTC, "=====");
427 SLOG(LOG_DEBUG, TAG_STTC, " ");
429 return STT_ERROR_NONE;
432 int stt_destroy(stt_h stt)
434 stt_client_s* client = NULL;
435 if (0 != __stt_get_feature_enabled()) {
436 return STT_ERROR_NOT_SUPPORTED;
438 if (0 != __stt_check_privilege()) {
439 return STT_ERROR_PERMISSION_DENIED;
441 if (0 != __stt_check_handle(stt, &client)) {
442 return STT_ERROR_INVALID_PARAMETER;
445 SLOG(LOG_DEBUG, TAG_STTC, "===== Destroy STT");
447 /* check used callback */
448 if (0 != stt_client_get_use_callback(client)) {
449 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Cannot destroy in Callback function");
450 return STT_ERROR_OPERATION_FAILED;
453 stt_config_mgr_finalize(client->uid);
458 switch (client->current_state) {
459 case STT_STATE_PROCESSING:
460 case STT_STATE_RECORDING:
461 case STT_STATE_READY:
462 ret = stt_dbus_request_finalize(client->uid);
464 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to request finalize : %s", __stt_get_error_code(ret)); //LCOV_EXCL_LINE
466 case STT_STATE_CREATED:
467 if (NULL != g_connect_timer) {
468 SLOG(LOG_DEBUG, TAG_STTC, "Connect Timer is deleted");
469 ecore_timer_del(g_connect_timer);
470 g_connect_timer = NULL;
474 stt_client_destroy(stt);
480 if (0 == stt_client_get_size()) {
481 if (0 != stt_dbus_close_connection()) {
482 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to close connection"); //LCOV_EXCL_LINE
488 SLOG(LOG_DEBUG, TAG_STTC, "=====");
489 SLOG(LOG_DEBUG, TAG_STTC, " ");
491 return STT_ERROR_NONE;
494 bool __stt_config_supported_engine_cb(const char* engine_id, const char* engine_name,
495 const char* setting, bool support_silence, void* user_data)
497 stt_h stt = (stt_h)user_data;
499 stt_client_s* client = stt_client_get(stt);
500 if (NULL == client) {
502 SLOG(LOG_ERROR, TAG_STTC, "[WARNING] A handle is not valid");
507 /* call callback function */
508 if (NULL != client->supported_engine_cb) {
509 return client->supported_engine_cb(stt, engine_id, engine_name, client->supported_engine_user_data);
511 SLOG(LOG_WARN, TAG_STTC, "No registered callback function of supported engine"); //LCOV_EXCL_LINE
517 int stt_foreach_supported_engines(stt_h stt, stt_supported_engine_cb callback, void* user_data)
519 stt_client_s* client = NULL;
520 if (0 != __stt_get_feature_enabled()) {
521 return STT_ERROR_NOT_SUPPORTED;
523 if (0 != __stt_check_privilege()) {
524 return STT_ERROR_PERMISSION_DENIED;
526 if (0 != __stt_check_handle(stt, &client)) {
527 return STT_ERROR_INVALID_PARAMETER;
530 SLOG(LOG_DEBUG, TAG_STTC, "===== Foreach Supported engine");
532 if (NULL == callback) {
533 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL"); //LCOV_EXCL_LINE
534 return STT_ERROR_INVALID_PARAMETER;
537 if (client->current_state != STT_STATE_CREATED) {
538 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State: Current state(%d) is not CREATED", client->current_state);
539 return STT_ERROR_INVALID_STATE;
542 client->supported_engine_cb = callback;
543 client->supported_engine_user_data = user_data;
546 ret = stt_config_mgr_get_engine_list(__stt_config_supported_engine_cb, client->stt);
547 ret = __stt_convert_config_error_code(ret);
549 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to get engines : %s", __stt_get_error_code(ret)); //LCOV_EXCL_LINE
552 client->supported_engine_cb = NULL;
553 client->supported_engine_user_data = NULL;
555 SLOG(LOG_DEBUG, TAG_STTC, "=====");
556 SLOG(LOG_DEBUG, TAG_STTC, " ");
561 int stt_get_engine(stt_h stt, char** engine_id)
563 stt_client_s* client = NULL;
564 if (0 != __stt_get_feature_enabled()) {
565 return STT_ERROR_NOT_SUPPORTED;
567 if (0 != __stt_check_privilege()) {
568 return STT_ERROR_PERMISSION_DENIED;
570 if (0 != __stt_check_handle(stt, &client)) {
571 return STT_ERROR_INVALID_PARAMETER;
574 SLOG(LOG_DEBUG, TAG_STTC, "===== Get current engine");
576 if (NULL == engine_id) {
577 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL"); //LCOV_EXCL_LINE
578 return STT_ERROR_INVALID_PARAMETER;
581 if (client->current_state != STT_STATE_CREATED) {
582 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State: Current state(%d) is not CREATED", client->current_state);
583 return STT_ERROR_INVALID_STATE;
588 if (NULL != client->current_engine_id) {
589 *engine_id = strdup(client->current_engine_id);
590 SLOG(LOG_DEBUG, TAG_STTC, "[SUCCESS] Current engine uuid = %s", *engine_id);
593 ret = stt_config_mgr_get_engine(engine_id);
594 ret = __stt_convert_config_error_code(ret);
596 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to request get current engine : %s", __stt_get_error_code(ret)); //LCOV_EXCL_LINE
598 SLOG(LOG_DEBUG, TAG_STTC, "[SUCCESS] Current engine uuid = %s", *engine_id);
602 SLOG(LOG_DEBUG, TAG_STTC, "=====");
603 SLOG(LOG_DEBUG, TAG_STTC, " ");
608 int __stt_set_buxtonkey(const char* engine_id)
611 struct buxton_client * bux_cli;
612 struct buxton_layer * bux_layer;
613 struct buxton_value * bux_val;
615 int ret = buxton_open(&bux_cli, NULL, NULL);
617 SLOG(LOG_ERROR, stt_tag(), "[DBUS-BUXTON2] Fail to open buxton client"); //LCOV_EXCL_LINE
618 return STT_ERROR_OPERATION_FAILED;
620 SLOG(LOG_DEBUG, stt_tag(), "[DBUS-BUXTON2] buxton_open: %d", ret);
621 bux_layer = buxton_create_layer("system");
622 if (NULL == bux_layer) {
624 SLOG(LOG_ERROR, stt_tag(), "[DBUS-BUXTON2] buxton_create_layer FAIL");
625 buxton_close(bux_cli);
627 return STT_ERROR_OPERATION_FAILED;
630 bux_val = buxton_value_create_string(engine_id);
631 if (NULL == bux_val) {
633 SLOG(LOG_ERROR, stt_tag(), "[DBUS-BUXTON2] buxton_value_create_string FAIL");
634 buxton_free_layer(bux_layer);
635 buxton_close(bux_cli);
638 return STT_ERROR_OPERATION_FAILED;
642 ret = buxton_set_value_sync(bux_cli, bux_layer, STT_ENGINE_DB_CUSTOM, bux_val);
645 SLOG(LOG_ERROR, stt_tag(), "[DBUS-BUXTON2] Fail to set value sync");
646 buxton_value_free(bux_val);
647 buxton_free_layer(bux_layer);
648 buxton_close(bux_cli);
653 return STT_ERROR_OPERATION_FAILED;
656 SLOG(LOG_DEBUG, stt_tag(), "[DBUS-BUXTON2] buxton_set_value_sync: %d, %s", ret, STT_ENGINE_DB_CUSTOM);
658 buxton_value_free(bux_val);
659 buxton_free_layer(bux_layer);
660 buxton_close(bux_cli);
666 return STT_ERROR_NONE;
669 int stt_set_engine(stt_h stt, const char* engine_id)
671 stt_client_s* client = NULL;
672 if (0 != __stt_get_feature_enabled()) {
673 return STT_ERROR_NOT_SUPPORTED;
675 if (0 != __stt_check_privilege()) {
676 return STT_ERROR_PERMISSION_DENIED;
678 if (0 != __stt_check_privilege_for_applaunch()) {
679 return STT_ERROR_PERMISSION_DENIED;
681 if (0 != __stt_check_handle(stt, &client)) {
682 return STT_ERROR_INVALID_PARAMETER;
685 SLOG(LOG_DEBUG, TAG_STTC, "===== Set current engine");
687 if (NULL == engine_id) {
688 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL"); //LCOV_EXCL_LINE
689 return STT_ERROR_INVALID_PARAMETER;
693 if (client->current_state != STT_STATE_CREATED) {
694 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State: Current state(%d) is not CREATED", client->current_state);
695 return STT_ERROR_INVALID_STATE;
698 if (NULL != client->current_engine_id) {
699 free(client->current_engine_id);
700 client->current_engine_id = NULL;
703 SLOG(LOG_DEBUG, TAG_STTC, "===== engined_id(%s)", engine_id);
705 client->current_engine_id = strdup(engine_id);
708 int ret = __stt_set_buxtonkey(engine_id);
710 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] set buxtonkey Failed!!!"); //LCOV_EXCL_LINE
714 SLOG(LOG_DEBUG, TAG_STTC, "=====");
715 SLOG(LOG_DEBUG, TAG_STTC, " ");
720 int stt_set_credential(stt_h stt, const char* credential)
722 stt_client_s* client = NULL;
723 if (0 != __stt_get_feature_enabled()) {
724 return STT_ERROR_NOT_SUPPORTED;
726 if (0 != __stt_check_privilege()) {
727 return STT_ERROR_PERMISSION_DENIED;
729 if (0 != __stt_check_handle(stt, &client)) {
730 return STT_ERROR_INVALID_PARAMETER;
733 SLOG(LOG_DEBUG, TAG_STTC, "===== Set credential");
735 if (NULL == credential) {
736 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL");
737 return STT_ERROR_INVALID_PARAMETER;
741 if (client->current_state != STT_STATE_CREATED && client->current_state != STT_STATE_READY) {
742 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State: Current state(%d) is not CREATED or READY", client->current_state); //LCOV_EXCL_LINE
743 return STT_ERROR_INVALID_STATE;
746 if (NULL != client->credential) {
747 free(client->credential);
748 client->credential = NULL;
750 client->credential = strdup(credential);
752 SLOG(LOG_DEBUG, TAG_STTC, "=====");
753 SLOG(LOG_DEBUG, TAG_STTC, " ");
755 return STT_ERROR_NONE;
758 int stt_set_private_data(stt_h stt, const char* key, const char* data)
760 stt_client_s* client = NULL;
761 if (0 != __stt_get_feature_enabled()) {
762 return STT_ERROR_NOT_SUPPORTED;
764 if (0 != __stt_check_privilege()) {
765 return STT_ERROR_PERMISSION_DENIED;
767 if (0 != __stt_check_handle(stt, &client)) {
768 return STT_ERROR_INVALID_PARAMETER;
771 SLOG(LOG_DEBUG, TAG_STTC, "===== Set private data");
773 if (NULL == key || NULL == data) {
774 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid parameter");
775 return STT_ERROR_INVALID_PARAMETER;
779 if (STT_STATE_READY != client->current_state) {
780 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State: Current state(%d) is not READY", client->current_state);
781 return STT_ERROR_INVALID_STATE;
784 if (true != client->internal && (0 == strcmp(key, "server") || 0 == strcmp(key, "rampcode") || 0 == strcmp(key, "epd"))) {
785 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] This is not an internal app"); //LCOV_EXCL_LINE
786 return STT_ERROR_INVALID_PARAMETER;
792 ret = stt_dbus_request_set_private_data(client->uid, key, data);
795 if (STT_ERROR_TIMED_OUT != ret) {
796 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to set private data : %s", __stt_get_error_code(ret));
799 SLOG(LOG_WARN, TAG_STTC, "[WARNING] retry : %s", __stt_get_error_code(ret));
802 if (STT_RETRY_COUNT == count) {
803 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to request");
811 SLOG(LOG_DEBUG, TAG_STTC, "=====");
812 SLOG(LOG_DEBUG, TAG_STTC, "");
814 return STT_ERROR_NONE;
817 int stt_get_private_data(stt_h stt, const char* key, char** data)
819 stt_client_s* client = NULL;
820 if (0 != __stt_get_feature_enabled()) {
821 return STT_ERROR_NOT_SUPPORTED;
823 if (0 != __stt_check_privilege()) {
824 return STT_ERROR_PERMISSION_DENIED;
826 if (0 != __stt_check_handle(stt, &client)) {
827 return STT_ERROR_INVALID_PARAMETER;
830 SLOG(LOG_DEBUG, TAG_STTC, "===== Get private data");
832 if (NULL == key || NULL == data) {
833 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid parameter");
834 return STT_ERROR_INVALID_PARAMETER;
838 if (STT_STATE_READY != client->current_state) {
839 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State: Current state(%d) is not READY", client->current_state);
840 return STT_ERROR_INVALID_STATE;
846 ret = stt_dbus_request_get_private_data(client->uid, key, data);
849 if (STT_ERROR_TIMED_OUT != ret) {
850 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to get private data : %s", __stt_get_error_code(ret));
853 SLOG(LOG_WARN, TAG_STTC, "[WARNING] retry : %s", __stt_get_error_code(ret));
856 if (STT_RETRY_COUNT == count) {
857 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to request");
865 if (0 == strncmp(*data, "NULL", strlen(*data))) {
870 SLOG(LOG_DEBUG, TAG_STTC, "=====");
871 SLOG(LOG_DEBUG, TAG_STTC, "");
873 return STT_ERROR_NONE;
877 int stt_set_server_stt(stt_h stt, const char* key, char* user_data)
880 stt_client_s* client = NULL;
882 if (0 != __stt_get_feature_enabled()) {
883 return STT_ERROR_NOT_SUPPORTED;
885 if (0 != __stt_check_privilege()) {
886 return STT_ERROR_PERMISSION_DENIED;
888 if (0 != __stt_check_handle(stt, &client)) {
889 return STT_ERROR_INVALID_PARAMETER;
892 SLOG(LOG_DEBUG, TAG_STTC, "===== Set STT server");
894 if (NULL == key || NULL == user_data) {
895 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid parameter");
896 return STT_ERROR_INVALID_PARAMETER;
899 if (STT_STATE_CREATED != client->current_state && STT_STATE_READY != client->current_state) {
900 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] The current state is invalid (%d).", client->current_state);
901 return STT_ERROR_INVALID_STATE;
905 client->internal = true;
907 char* private_key = NULL;
908 private_key = strdup(key);
909 if (NULL == private_key) {
910 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to allocate memory(private_key)");
911 return STT_ERROR_OUT_OF_MEMORY;
915 data = strdup(user_data);
917 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to allocate memory(data)");
920 return STT_ERROR_OUT_OF_MEMORY;
923 ret = stt_set_private_data(stt, private_key, data);
925 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to set private data, ret(%d), key(%s)", ret, private_key);
933 SLOG(LOG_DEBUG, TAG_STTC, "======");
934 SLOG(LOG_DEBUG, TAG_STTC, " ");
940 static Eina_Bool __stt_connect_daemon(void *data)
942 stt_client_s* client = (stt_client_s*)data;
945 if (NULL == client) {
946 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] A handle is not available"); //LCOV_EXCL_LINE
947 g_connect_timer = NULL;
951 if (0 == stt_client_get_size() || NULL == stt_client_get_by_uid(client->uid)) {
952 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Client has been already destroyed"); //LCOV_EXCL_LINE
956 /* Check and Set vconfkey of custom engine before sending hello */
957 if (1 == g_privilege_applaunch_allowed && NULL != client->current_engine_id) {
959 ret = __stt_set_buxtonkey(client->current_engine_id);
962 SLOG(LOG_DEBUG, TAG_STTC, "[DEBUG] set buxtonkey Failed!!! (inside __stt_connect_daemon)");
969 ret = stt_dbus_request_hello(client->uid);
972 if (STT_ERROR_INVALID_STATE == ret) {
973 g_connect_timer = NULL;
979 g_connect_timer = NULL;
980 SLOG(LOG_DEBUG, TAG_STTC, "===== Connect stt-service");
982 /* request initialization */
983 bool silence_supported = false;
984 bool credential_needed = false;
986 ret = stt_dbus_request_initialize(client->uid, &silence_supported, &credential_needed);
988 if (STT_ERROR_ENGINE_NOT_FOUND == ret) {
989 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to initialize : %s", __stt_get_error_code(ret)); //LCOV_EXCL_LINE
991 client->reason = STT_ERROR_ENGINE_NOT_FOUND;
992 ecore_main_loop_thread_safe_call_async(__stt_notify_error, (void*)client);
996 } else if (STT_ERROR_NONE != ret) {
997 SLOG(LOG_ERROR, TAG_STTC, "[WARNING] Fail to connection. Retry to connect"); //LCOV_EXCL_LINE
1000 /* success to connect stt-service */
1001 client->silence_supported = silence_supported;
1002 client->credential_needed = credential_needed;
1003 SLOG(LOG_DEBUG, TAG_STTC, "Supported options : silence(%s), credential(%s)", silence_supported ? "support" : "no support", credential_needed ? "need" : "no need");
1007 #ifdef __UNUSED_CODES__
1008 if (NULL != client->current_engine_id) {
1011 silence_supported = false;
1012 credential_needed = false;
1013 SLOG(LOG_DEBUG, TAG_STTC, "[WARNING] current_engine_id(%s)", client->current_engine_id);
1016 ret = stt_dbus_request_set_current_engine(client->uid, client->current_engine_id, &silence_supported, &credential_needed);
1018 if (STT_ERROR_TIMED_OUT != ret) {
1019 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to set current engine : %s", __stt_get_error_code(ret));
1022 SLOG(LOG_WARN, TAG_STTC, "[WARNING] retry");
1025 if (STT_RETRY_COUNT == count) {
1026 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to request");
1031 SLOG(LOG_DEBUG, TAG_STTC, "[SUCCESS] Current engine uuid = %s", client->current_engine_id);
1033 /* success to change engine */
1034 client->silence_supported = silence_supported;
1035 SLOG(LOG_DEBUG, TAG_STTC, "Supported options : silence(%s), credential(%s)", silence_supported ? "support" : "no support", credential_needed ? "need" : "no need");
1041 SLOG(LOG_DEBUG, TAG_STTC, "[SUCCESS] uid(%d)", client->uid);
1043 client->before_state = client->current_state;
1044 client->current_state = STT_STATE_READY;
1046 if (NULL != client->state_changed_cb) {
1047 stt_client_use_callback(client);
1048 client->state_changed_cb(client->stt, client->before_state,
1049 client->current_state, client->state_changed_user_data);
1050 stt_client_not_use_callback(client);
1051 SLOG(LOG_DEBUG, TAG_STTC, "State changed callback is called");
1053 SLOG(LOG_WARN, TAG_STTC, "[WARNING] State changed callback is null");
1056 SLOG(LOG_DEBUG, TAG_STTC, "=====");
1057 SLOG(LOG_DEBUG, TAG_STTC, " ");
1062 int stt_prepare(stt_h stt)
1064 stt_client_s* client = NULL;
1065 if (0 != __stt_get_feature_enabled()) {
1066 return STT_ERROR_NOT_SUPPORTED;
1068 if (0 != __stt_check_privilege()) {
1069 return STT_ERROR_PERMISSION_DENIED;
1071 if (0 != __stt_check_handle(stt, &client)) {
1072 return STT_ERROR_INVALID_PARAMETER;
1076 if (client->current_state != STT_STATE_CREATED) {
1077 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State: Current state(%d) is not 'CREATED'", client->current_state);
1078 return STT_ERROR_INVALID_STATE;
1081 ecore_thread_main_loop_begin();
1082 g_connect_timer = ecore_timer_add(0.02, __stt_connect_daemon, (void*)client);
1083 ecore_thread_main_loop_end();
1085 SLOG(LOG_DEBUG, TAG_STTC, "=====");
1086 SLOG(LOG_DEBUG, TAG_STTC, " ");
1088 return STT_ERROR_NONE;
1091 int stt_unprepare(stt_h stt)
1093 stt_client_s* client = NULL;
1094 if (0 != __stt_get_feature_enabled()) {
1095 return STT_ERROR_NOT_SUPPORTED;
1097 if (0 != __stt_check_privilege()) {
1098 return STT_ERROR_PERMISSION_DENIED;
1100 if (0 != __stt_check_handle(stt, &client)) {
1101 return STT_ERROR_INVALID_PARAMETER;
1104 SLOG(LOG_DEBUG, TAG_STTC, "===== Unprepare STT");
1107 if (client->current_state != STT_STATE_READY) {
1108 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State: Current state(%d) is not 'READY'", client->current_state);
1109 return STT_ERROR_INVALID_STATE;
1115 ret = stt_dbus_request_finalize(client->uid);
1118 if (STT_ERROR_TIMED_OUT != ret) {
1119 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to request finalize : %s", __stt_get_error_code(ret));
1122 SLOG(LOG_WARN, TAG_STTC, "[WARNING] retry");
1125 if (STT_RETRY_COUNT == count) {
1126 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to request");
1134 client->internal_state = STT_INTERNAL_STATE_NONE;
1136 client->before_state = client->current_state;
1137 client->current_state = STT_STATE_CREATED;
1139 if (NULL != client->state_changed_cb) {
1140 stt_client_use_callback(client);
1141 client->state_changed_cb(client->stt, client->before_state,
1142 client->current_state, client->state_changed_user_data);
1143 stt_client_not_use_callback(client);
1145 SLOG(LOG_WARN, TAG_STTC, "[WARNING] State changed callback is null");
1148 if (g_connect_timer) {
1149 ecore_timer_del(g_connect_timer);
1150 g_connect_timer = NULL;
1153 SLOG(LOG_DEBUG, TAG_STTC, "=====");
1154 SLOG(LOG_DEBUG, TAG_STTC, " ");
1156 return STT_ERROR_NONE;
1159 bool __stt_config_supported_language_cb(const char* engine_id, const char* language, void* user_data)
1161 stt_h stt = (stt_h)user_data;
1163 stt_client_s* client = stt_client_get(stt);
1164 if (NULL == client) {
1165 SLOG(LOG_ERROR, TAG_STTC, "[WARNING] A handle is not valid"); //LCOV_EXCL_LINE
1169 /* call callback function */
1170 if (NULL != client->supported_lang_cb) {
1171 return client->supported_lang_cb(stt, language, client->supported_lang_user_data);
1173 SLOG(LOG_WARN, TAG_STTC, "No registered callback function of supported languages"); //LCOV_EXCL_LINE
1179 int stt_foreach_supported_languages(stt_h stt, stt_supported_language_cb callback, void* user_data)
1181 stt_client_s* client = NULL;
1182 if (0 != __stt_get_feature_enabled()) {
1183 return STT_ERROR_NOT_SUPPORTED;
1185 if (0 != __stt_check_privilege()) {
1186 return STT_ERROR_PERMISSION_DENIED;
1188 if (0 != __stt_check_handle(stt, &client)) {
1189 return STT_ERROR_INVALID_PARAMETER;
1192 SLOG(LOG_DEBUG, TAG_STTC, "===== Foreach Supported Language");
1194 if (NULL == callback) {
1195 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL"); //LCOV_EXCL_LINE
1196 return STT_ERROR_INVALID_PARAMETER;
1200 char* current_engine_id = NULL;
1202 if (NULL == client->current_engine_id) {
1203 ret = stt_config_mgr_get_engine(¤t_engine_id);
1204 ret = __stt_convert_config_error_code(ret);
1206 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to get default engine id : %s", __stt_get_error_code(ret)); //LCOV_EXCL_LINE
1210 current_engine_id = strdup(client->current_engine_id);
1212 if (NULL == current_engine_id) {
1213 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to allocate memory");
1214 return STT_ERROR_OUT_OF_MEMORY;
1219 client->supported_lang_cb = callback;
1220 client->supported_lang_user_data = user_data;
1222 ret = stt_config_mgr_get_language_list(current_engine_id, __stt_config_supported_language_cb, client->stt);
1223 ret = __stt_convert_config_error_code(ret);
1225 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to get languages : %s", __stt_get_error_code(ret)); //LCOV_EXCL_LINE
1228 if (NULL != current_engine_id) {
1229 free(current_engine_id);
1230 current_engine_id = NULL;
1233 client->supported_lang_cb = NULL;
1234 client->supported_lang_user_data = NULL;
1236 SLOG(LOG_DEBUG, TAG_STTC, "=====");
1237 SLOG(LOG_DEBUG, TAG_STTC, " ");
1242 int stt_get_default_language(stt_h stt, char** language)
1244 stt_client_s* client = NULL;
1245 if (0 != __stt_get_feature_enabled()) {
1246 return STT_ERROR_NOT_SUPPORTED;
1248 if (0 != __stt_check_privilege()) {
1249 return STT_ERROR_PERMISSION_DENIED;
1251 if (0 != __stt_check_handle(stt, &client)) {
1252 return STT_ERROR_INVALID_PARAMETER;
1255 SLOG(LOG_DEBUG, TAG_STTC, "===== Get Default Language");
1257 if (NULL == language) {
1258 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL"); //LCOV_EXCL_LINE
1259 return STT_ERROR_INVALID_PARAMETER;
1263 ret = stt_config_mgr_get_default_language(language);
1264 ret = __stt_convert_config_error_code(ret);
1266 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to get default language : %s", __stt_get_error_code(ret)); //LCOV_EXCL_LINE
1268 SLOG(LOG_DEBUG, TAG_STTC, "[SUCCESS] Current language = %s", *language);
1271 SLOG(LOG_DEBUG, TAG_STTC, "=====");
1272 SLOG(LOG_DEBUG, TAG_STTC, " ");
1277 int stt_get_state(stt_h stt, stt_state_e* state)
1279 stt_client_s* client = NULL;
1280 if (0 != __stt_get_feature_enabled()) {
1281 return STT_ERROR_NOT_SUPPORTED;
1283 if (0 != __stt_check_privilege()) {
1284 return STT_ERROR_PERMISSION_DENIED;
1286 if (0 != __stt_check_handle(stt, &client)) {
1287 return STT_ERROR_INVALID_PARAMETER;
1290 if (NULL == state) {
1291 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL"); //LCOV_EXCL_LINE
1292 return STT_ERROR_INVALID_PARAMETER;
1295 *state = client->current_state;
1298 case STT_STATE_CREATED: SLOG(LOG_DEBUG, TAG_STTC, "Current state is 'CREATED'"); break;
1299 case STT_STATE_READY: SLOG(LOG_DEBUG, TAG_STTC, "Current state is 'Ready'"); break;
1300 case STT_STATE_RECORDING: SLOG(LOG_DEBUG, TAG_STTC, "Current state is 'Recording'"); break;
1301 case STT_STATE_PROCESSING: SLOG(LOG_DEBUG, TAG_STTC, "Current state is 'Processing'"); break;
1302 default: SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid value"); break;
1305 return STT_ERROR_NONE;
1308 int stt_get_error_message(stt_h stt, char** err_msg)
1310 stt_client_s* client = NULL;
1311 if (0 != __stt_get_feature_enabled()) {
1312 return STT_ERROR_NOT_SUPPORTED;
1314 if (0 != __stt_check_privilege()) {
1315 return STT_ERROR_PERMISSION_DENIED;
1317 if (0 != __stt_check_handle(stt, &client)) {
1318 return STT_ERROR_INVALID_PARAMETER;
1321 if (NULL == err_msg) {
1322 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL");
1323 return STT_ERROR_INVALID_PARAMETER;
1326 if (false == g_err_callback_status) {
1327 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] This callback should be called during an err_callback");
1328 return STT_ERROR_OPERATION_FAILED;
1331 if (NULL != client->err_msg) {
1332 *err_msg = strdup(client->err_msg);
1333 SLOG(LOG_DEBUG, TAG_STTC, "[SUCCESS] Error msg (%s)", *err_msg); //LCOV_EXCL_LINE
1335 SLOG(LOG_DEBUG, TAG_STTC, "[SUCCESS] Error msg (NULL)"); //LCOV_EXCL_LINE
1338 SLOG(LOG_DEBUG, TAG_STTC, "====="); //LCOV_EXCL_LINE
1339 SLOG(LOG_DEBUG, TAG_STTC, " "); //LCOV_EXCL_LINE
1341 return STT_ERROR_NONE;
1344 int stt_is_recognition_type_supported(stt_h stt, const char* type, bool* support)
1346 stt_client_s* client = NULL;
1347 if (0 != __stt_get_feature_enabled()) {
1348 return STT_ERROR_NOT_SUPPORTED;
1350 if (0 != __stt_check_privilege()) {
1351 return STT_ERROR_PERMISSION_DENIED;
1353 if (0 != __stt_check_handle(stt, &client)) {
1354 return STT_ERROR_INVALID_PARAMETER;
1357 if (NULL == type || NULL == support) {
1358 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL"); //LCOV_EXCL_LINE
1359 return STT_ERROR_INVALID_PARAMETER;
1363 if (client->current_state != STT_STATE_READY) {
1364 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State: Current state(%d) is not READY", client->current_state);
1365 return STT_ERROR_INVALID_STATE;
1371 ret = stt_dbus_request_is_recognition_type_supported(client->uid, type, support);
1374 if (STT_ERROR_TIMED_OUT != ret) {
1375 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to get recognition type supported : %s", __stt_get_error_code(ret));
1378 SLOG(LOG_WARN, TAG_STTC, "[WARNING] retry");
1381 if (STT_RETRY_COUNT == count) {
1382 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to request");
1388 SLOG(LOG_DEBUG, TAG_STTC, "[SUCCESS] recognition type is %s", *support ? "true " : "false");
1393 return STT_ERROR_NONE;
1396 int stt_set_silence_detection(stt_h stt, stt_option_silence_detection_e type)
1398 stt_client_s* client = NULL;
1399 if (0 != __stt_get_feature_enabled()) {
1400 return STT_ERROR_NOT_SUPPORTED;
1402 if (0 != __stt_check_privilege()) {
1403 return STT_ERROR_PERMISSION_DENIED;
1405 if (0 != __stt_check_handle(stt, &client)) {
1406 return STT_ERROR_INVALID_PARAMETER;
1410 if (client->current_state != STT_STATE_READY) {
1411 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State: Current state(%d) is not READY", client->current_state);
1412 return STT_ERROR_INVALID_STATE;
1415 if (true == client->silence_supported) {
1416 if (type >= STT_OPTION_SILENCE_DETECTION_FALSE && type <= STT_OPTION_SILENCE_DETECTION_AUTO) {
1417 client->silence = type;
1419 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Type is invalid");
1420 return STT_ERROR_INVALID_PARAMETER;
1423 return STT_ERROR_NOT_SUPPORTED_FEATURE;
1426 return STT_ERROR_NONE;
1429 int stt_set_start_sound(stt_h stt, const char* filename)
1431 stt_client_s* client = NULL;
1432 if (0 != __stt_get_feature_enabled()) {
1433 return STT_ERROR_NOT_SUPPORTED;
1435 if (0 != __stt_check_privilege()) {
1436 return STT_ERROR_PERMISSION_DENIED;
1438 if (0 != __stt_check_handle(stt, &client)) {
1439 return STT_ERROR_INVALID_PARAMETER;
1442 SLOG(LOG_DEBUG, TAG_STTC, "===== STT SET START SOUND");
1444 if (NULL == filename) {
1445 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL"); //LCOV_EXCL_LINE
1446 return STT_ERROR_INVALID_PARAMETER;
1449 if (0 != access(filename, F_OK)) {
1450 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] File does not exist"); //LCOV_EXCL_LINE
1451 return STT_ERROR_INVALID_PARAMETER;
1455 if (client->current_state != STT_STATE_READY) {
1456 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State: Current state(%d) is not READY", client->current_state); //LCOV_EXCL_LINE
1457 return STT_ERROR_INVALID_STATE;
1463 ret = stt_dbus_request_set_start_sound(client->uid, filename);
1466 if (STT_ERROR_TIMED_OUT != ret) {
1467 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to set start sound : %s", __stt_get_error_code(ret));
1470 SLOG(LOG_WARN, TAG_STTC, "[WARNING] retry");
1473 if (STT_RETRY_COUNT == count) {
1474 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to request");
1480 SLOG(LOG_DEBUG, TAG_STTC, "[SUCCESS] Set start sound : %s", filename);
1485 return STT_ERROR_NONE;
1488 int stt_unset_start_sound(stt_h stt)
1490 stt_client_s* client = NULL;
1491 if (0 != __stt_get_feature_enabled()) {
1492 return STT_ERROR_NOT_SUPPORTED;
1494 if (0 != __stt_check_privilege()) {
1495 return STT_ERROR_PERMISSION_DENIED;
1497 if (0 != __stt_check_handle(stt, &client)) {
1498 return STT_ERROR_INVALID_PARAMETER;
1501 SLOG(LOG_DEBUG, TAG_STTC, "===== STT UNSET START SOUND");
1504 if (client->current_state != STT_STATE_READY) {
1505 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State: Current state(%d) is not READY", client->current_state);
1506 return STT_ERROR_INVALID_STATE;
1512 ret = stt_dbus_request_unset_start_sound(client->uid);
1515 if (STT_ERROR_TIMED_OUT != ret) {
1516 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to unset start sound : %s", __stt_get_error_code(ret));
1519 SLOG(LOG_WARN, TAG_STTC, "[WARNING] retry");
1522 if (STT_RETRY_COUNT == count) {
1523 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to request");
1529 SLOG(LOG_DEBUG, TAG_STTC, "[SUCCESS] Unset start sound");
1534 return STT_ERROR_NONE;
1537 int stt_set_stop_sound(stt_h stt, const char* filename)
1539 stt_client_s* client = NULL;
1540 if (0 != __stt_get_feature_enabled()) {
1541 return STT_ERROR_NOT_SUPPORTED;
1543 if (0 != __stt_check_privilege()) {
1544 return STT_ERROR_PERMISSION_DENIED;
1546 if (0 != __stt_check_handle(stt, &client)) {
1547 return STT_ERROR_INVALID_PARAMETER;
1550 SLOG(LOG_DEBUG, TAG_STTC, "===== STT SET STOP SOUND");
1552 if (NULL == filename) {
1553 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL"); //LCOV_EXCL_LINE
1554 return STT_ERROR_INVALID_PARAMETER;
1557 if (0 != access(filename, F_OK)) {
1558 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] File does not exist"); //LCOV_EXCL_LINE
1559 return STT_ERROR_INVALID_PARAMETER;
1563 if (client->current_state != STT_STATE_READY) {
1564 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State: Current state(%d) is not READY", client->current_state); //LCOV_EXCL_LINE
1565 return STT_ERROR_INVALID_STATE;
1571 ret = stt_dbus_request_set_stop_sound(client->uid, filename);
1574 if (STT_ERROR_TIMED_OUT != ret) {
1575 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to set stop sound : %s", __stt_get_error_code(ret));
1578 SLOG(LOG_WARN, TAG_STTC, "[WARNING] retry");
1581 if (STT_RETRY_COUNT == count) {
1582 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to request");
1588 SLOG(LOG_DEBUG, TAG_STTC, "[SUCCESS] Set stop sound : %s", filename);
1593 return STT_ERROR_NONE;
1596 int stt_unset_stop_sound(stt_h stt)
1598 stt_client_s* client = NULL;
1599 if (0 != __stt_get_feature_enabled()) {
1600 return STT_ERROR_NOT_SUPPORTED;
1602 if (0 != __stt_check_privilege()) {
1603 return STT_ERROR_PERMISSION_DENIED;
1605 if (0 != __stt_check_handle(stt, &client)) {
1606 return STT_ERROR_INVALID_PARAMETER;
1609 SLOG(LOG_DEBUG, TAG_STTC, "===== STT UNSET STOP SOUND");
1612 if (client->current_state != STT_STATE_READY) {
1613 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State: Current state(%d) is not READY", client->current_state);
1614 return STT_ERROR_INVALID_STATE;
1620 ret = stt_dbus_request_unset_stop_sound(client->uid);
1623 if (STT_ERROR_TIMED_OUT != ret) {
1624 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to unset stop sound : %s", __stt_get_error_code(ret));
1627 SLOG(LOG_WARN, TAG_STTC, "[WARNING] retry");
1630 if (STT_RETRY_COUNT == count) {
1631 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to request");
1637 SLOG(LOG_DEBUG, TAG_STTC, "[SUCCESS] Unset stop sound");
1642 return STT_ERROR_NONE;
1645 int stt_start(stt_h stt, const char* language, const char* type)
1647 stt_client_s* client = NULL;
1648 if (0 != __stt_get_feature_enabled()) {
1649 return STT_ERROR_NOT_SUPPORTED;
1651 if (0 != __stt_check_privilege()) {
1652 return STT_ERROR_PERMISSION_DENIED;
1654 if (0 != __stt_check_handle(stt, &client)) {
1655 return STT_ERROR_INVALID_PARAMETER;
1658 SLOG(LOG_DEBUG, TAG_STTC, "===== STT START");
1661 if (client->current_state != STT_STATE_READY) {
1662 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State: Current state(%d) is not READY", client->current_state);
1663 return STT_ERROR_INVALID_STATE;
1666 if (STT_INTERNAL_STATE_NONE != client->internal_state) {
1667 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State : Internal state is NOT none : %d", client->internal_state); //LCOV_EXCL_LINE
1668 return STT_ERROR_IN_PROGRESS_TO_RECORDING;
1672 char appid[1024] = {0, };
1673 ret = aul_app_get_appid_bypid(getpid(), appid, sizeof(appid) - 1);
1675 if ((AUL_R_OK != ret) || (0 == strlen(appid))) {
1676 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to get application ID"); //LCOV_EXCL_LINE
1678 SLOG(LOG_DEBUG, TAG_STTC, "[DEBUG] Current app id is %s", appid);
1682 if (NULL == language) {
1683 temp = strdup("default");
1685 temp = strdup(language);
1689 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to allocate memory");
1690 return STT_ERROR_OUT_OF_MEMORY;
1693 if (true == client->credential_needed && NULL == client->credential) {
1694 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Do not have app credential for this engine(%s)", client->current_engine_id); //LCOV_EXCL_LINE
1697 return STT_ERROR_PERMISSION_DENIED;
1700 client->internal_state = STT_INTERNAL_STATE_STARTING;
1701 ret = stt_dbus_request_start(client->uid, temp, type, client->silence, appid, client->credential);
1703 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to start : %s", __stt_get_error_code(ret)); //LCOV_EXCL_LINE
1704 client->internal_state = STT_INTERNAL_STATE_NONE;
1706 SLOG(LOG_DEBUG, TAG_STTC, "[SUCCESS] Start is successful but not done");
1712 SLOG(LOG_DEBUG, TAG_STTC, "=====");
1713 SLOG(LOG_DEBUG, TAG_STTC, " ");
1718 int stt_stop(stt_h stt)
1720 stt_client_s* client = NULL;
1721 if (0 != __stt_get_feature_enabled()) {
1722 return STT_ERROR_NOT_SUPPORTED;
1724 if (0 != __stt_check_privilege()) {
1725 return STT_ERROR_PERMISSION_DENIED;
1727 if (0 != __stt_check_handle(stt, &client)) {
1728 return STT_ERROR_INVALID_PARAMETER;
1731 SLOG(LOG_DEBUG, TAG_STTC, "===== STT STOP");
1734 if (client->current_state != STT_STATE_RECORDING) {
1735 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State : Current state(%d) is NOT RECORDING", client->current_state); //LCOV_EXCL_LINE
1736 return STT_ERROR_INVALID_STATE;
1739 if (STT_INTERNAL_STATE_STARTING == client->internal_state) {
1740 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State : Internal state is STARTING : %d", client->internal_state); //LCOV_EXCL_LINE
1741 return STT_ERROR_IN_PROGRESS_TO_RECORDING;
1742 } else if (STT_INTERNAL_STATE_CANCELING == client->internal_state) {
1743 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State : Internal state is CANCELING : %d", client->internal_state); //LCOV_EXCL_LINE
1744 return STT_ERROR_IN_PROGRESS_TO_READY;
1745 } else if (STT_INTERNAL_STATE_STOPPING == client->internal_state) {
1746 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State : Internal state is STOPPING : %d", client->internal_state); //LCOV_EXCL_LINE
1747 return STT_ERROR_IN_PROGRESS_TO_PROCESSING;
1750 client->internal_state = STT_INTERNAL_STATE_STOPPING;
1751 int ret = stt_dbus_request_stop(client->uid);
1753 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to stop : %s", __stt_get_error_code(ret)); //LCOV_EXCL_LINE
1754 client->internal_state = STT_INTERNAL_STATE_NONE;
1756 SLOG(LOG_DEBUG, TAG_STTC, "[SUCCESS] Stop is successful but not done");
1759 SLOG(LOG_DEBUG, TAG_STTC, "=====");
1760 SLOG(LOG_DEBUG, TAG_STTC, " ");
1766 int stt_cancel(stt_h stt)
1768 stt_client_s* client = NULL;
1769 if (0 != __stt_get_feature_enabled()) {
1770 return STT_ERROR_NOT_SUPPORTED;
1772 if (0 != __stt_check_privilege()) {
1773 return STT_ERROR_PERMISSION_DENIED;
1775 if (0 != __stt_check_handle(stt, &client)) {
1776 return STT_ERROR_INVALID_PARAMETER;
1779 SLOG(LOG_DEBUG, TAG_STTC, "===== STT CANCEL");
1782 if (STT_STATE_RECORDING != client->current_state && STT_STATE_PROCESSING != client->current_state) {
1783 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid state : Current state(%d) is 'Ready'", client->current_state); //LCOV_EXCL_LINE
1784 return STT_ERROR_INVALID_STATE;
1787 if (STT_INTERNAL_STATE_STARTING == client->internal_state) {
1788 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State : Internal state is STARTING : %d", client->internal_state); //LCOV_EXCL_LINE
1789 return STT_ERROR_IN_PROGRESS_TO_RECORDING;
1790 } else if (STT_INTERNAL_STATE_STOPPING == client->internal_state) {
1791 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State : Internal state is STOPPING : %d", client->internal_state); //LCOV_EXCL_LINE
1792 return STT_ERROR_IN_PROGRESS_TO_PROCESSING;
1793 } else if (STT_INTERNAL_STATE_CANCELING == client->internal_state) {
1794 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State : Internal state is CANCELING : %d", client->internal_state); //LCOV_EXCL_LINE
1795 return STT_ERROR_IN_PROGRESS_TO_READY;
1798 client->internal_state = STT_INTERNAL_STATE_CANCELING;
1799 int ret = stt_dbus_request_cancel(client->uid);
1801 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to cancel : %s", __stt_get_error_code(ret)); //LCOV_EXCL_LINE
1802 client->internal_state = STT_INTERNAL_STATE_NONE;
1804 SLOG(LOG_DEBUG, TAG_STTC, "[SUCCESS] Cancel is successful but not done");
1807 SLOG(LOG_DEBUG, TAG_STTC, "=====");
1808 SLOG(LOG_DEBUG, TAG_STTC, " ");
1813 int __stt_cb_set_volume(int uid, float volume)
1815 stt_client_s* client = NULL;
1817 client = stt_client_get_by_uid(uid);
1818 if (NULL == client) {
1820 SLOG(LOG_ERROR, TAG_STTC, "Handle is NOT valid");
1821 return STT_ERROR_INVALID_PARAMETER;
1825 if (STT_STATE_RECORDING != client->current_state) {
1827 SLOG(LOG_DEBUG, TAG_STTC, "[ERROR] Invalid state : NO 'Recording' state, cur(%d)", client->current_state);
1828 return STT_ERROR_INVALID_STATE;
1832 g_volume_db = volume;
1833 SLOG(LOG_DEBUG, TAG_STTC, "Set volume (%f)", g_volume_db);
1838 int stt_get_recording_volume(stt_h stt, float* volume)
1840 stt_client_s* client = NULL;
1841 if (0 != __stt_get_feature_enabled()) {
1842 return STT_ERROR_NOT_SUPPORTED;
1844 if (0 != __stt_check_privilege()) {
1845 return STT_ERROR_PERMISSION_DENIED;
1847 if (0 != __stt_check_handle(stt, &client)) {
1848 return STT_ERROR_INVALID_PARAMETER;
1851 if (NULL == volume) {
1852 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL"); //LCOV_EXCL_LINE
1853 return STT_ERROR_INVALID_PARAMETER;
1856 if (STT_STATE_RECORDING != client->current_state) {
1857 SLOG(LOG_DEBUG, TAG_STTC, "[ERROR] Invalid state : NO 'Recording' state, cur(%d)", client->current_state); //LCOV_EXCL_LINE
1858 return STT_ERROR_INVALID_STATE;
1861 *volume = g_volume_db;
1863 return STT_ERROR_NONE;
1867 bool __stt_result_time_cb(int index, int event, const char* text, long start_time, long end_time, void* user_data)
1869 stt_client_s* client = (stt_client_s*)user_data;
1872 if (NULL == client) {
1873 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to notify error : A handle is not valid");
1877 if (NULL != client->result_time_cb) {
1878 SLOG(LOG_DEBUG, TAG_STTC, "(%d) event(%d) text(%s) start(%ld) end(%ld)",
1879 index, event, text, start_time, end_time);
1880 client->result_time_cb(client->stt, index, (stt_result_time_event_e)event,
1881 text, start_time, end_time, client->result_time_user_data);
1883 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Callback is NULL");
1891 int stt_foreach_detailed_result(stt_h stt, stt_result_time_cb callback, void* user_data)
1893 stt_client_s* client = NULL;
1894 if (0 != __stt_get_feature_enabled()) {
1895 return STT_ERROR_NOT_SUPPORTED;
1897 if (0 != __stt_check_privilege()) {
1898 return STT_ERROR_PERMISSION_DENIED;
1900 if (0 != __stt_check_handle(stt, &client)) {
1901 return STT_ERROR_INVALID_PARAMETER;
1904 SLOG(LOG_DEBUG, TAG_STTC, "===== STT FOREACH DETAILED RESULT");
1906 if (NULL == callback) {
1907 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL"); //LCOV_EXCL_LINE
1908 return STT_ERROR_INVALID_PARAMETER;
1911 client->result_time_cb = callback;
1912 client->result_time_user_data = user_data;
1915 ret = stt_config_mgr_foreach_time_info(__stt_result_time_cb, client);
1916 ret = __stt_convert_config_error_code(ret);
1918 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to foreach time info : %s", __stt_get_error_code(ret)); //LCOV_EXCL_LINE
1921 client->result_time_cb = NULL;
1922 client->result_time_user_data = NULL;
1924 SLOG(LOG_DEBUG, TAG_STTC, "=====");
1925 SLOG(LOG_DEBUG, TAG_STTC, " ");
1930 static void __stt_notify_error(void *data)
1932 stt_client_s* client = (stt_client_s*)data;
1934 SLOG(LOG_WARN, TAG_STTC, "[WARNING] Error from sttd");
1937 if (NULL == client) {
1938 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to notify error : A handle is not valid"); //LCOV_EXCL_LINE
1942 if (NULL == stt_client_get_by_uid(client->uid))
1945 if (NULL != client->error_cb) {
1946 stt_client_use_callback(client);
1947 g_err_callback_status = true;
1948 client->error_cb(client->stt, client->reason, client->error_user_data);
1949 g_err_callback_status = false;
1950 stt_client_not_use_callback(client);
1951 SLOG(LOG_WARN, TAG_STTC, "[WARNING] Error callback is called : reason [%d]", client->reason);
1953 SLOG(LOG_WARN, TAG_STTC, "[WARNING] Error callback is null"); //LCOV_EXCL_LINE
1959 int __stt_cb_error(int uid, int reason, char* err_msg)
1963 GList* client_list = NULL;
1964 client_list = stt_client_get_client_list();
1967 stt_client_s *data = NULL;
1969 if (g_list_length(client_list) > 0) {
1970 /* Get a first item */
1971 iter = g_list_first(client_list);
1973 while (NULL != iter) {
1976 data->reason = reason;
1977 data->internal_state = STT_INTERNAL_STATE_NONE;
1978 if (NULL != data->err_msg) {
1979 free(data->err_msg);
1980 data->err_msg = NULL;
1982 if (NULL != err_msg)
1983 data->err_msg = strdup(err_msg);
1985 SLOG(LOG_INFO, TAG_STTC, "internal state is initialized to 0");
1987 if (NULL != data->error_cb) {
1988 ecore_main_loop_thread_safe_call_async(__stt_notify_error, data);
1990 SLOG(LOG_WARN, TAG_STTC, "[WARNING] Error callback is null");
1993 if (STT_ERROR_SERVICE_RESET == reason) {
1994 SLOG(LOG_WARN, TAG_STTC, "[WARNING] Service reset");
1996 data->current_state = STT_STATE_CREATED;
1997 if (0 != stt_prepare(data->stt)) {
1998 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to prepare");
2003 iter = g_list_next(iter);
2008 stt_client_s* client = stt_client_get_by_uid(uid);
2009 if (NULL == client) {
2010 SLOG(LOG_ERROR, TAG_STTC, "Handle not found"); //LCOV_EXCL_LINE
2014 client->reason = reason;
2015 client->internal_state = STT_INTERNAL_STATE_NONE;
2016 if (NULL != client->err_msg) {
2017 free(client->err_msg);
2018 client->err_msg = NULL;
2020 if (NULL != err_msg)
2021 client->err_msg = strdup(err_msg);
2023 SLOG(LOG_INFO, TAG_STTC, "internal state is initialized to 0");
2025 if (NULL != client->error_cb) {
2026 ecore_main_loop_thread_safe_call_async(__stt_notify_error, client);
2028 SLOG(LOG_WARN, TAG_STTC, "[WARNING] Error callback is null");
2031 if (STT_ERROR_SERVICE_RESET == reason) {
2032 SLOG(LOG_WARN, TAG_STTC, "[WARNING] Service reset"); //LCOV_EXCL_LINE
2034 client->current_state = STT_STATE_CREATED;
2035 if (0 != stt_prepare(client->stt)) {
2036 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to prepare"); //LCOV_EXCL_LINE
2044 static void __stt_notify_state_changed(void *data)
2046 stt_client_s* client = (stt_client_s*)data;
2049 if (NULL == client) {
2050 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to notify error : A handle is not valid"); //LCOV_EXCL_LINE
2054 if (NULL == stt_client_get_by_uid(client->uid)) {
2058 if (STT_INTERNAL_STATE_STARTING == client->internal_state && STT_STATE_RECORDING == client->current_state) {
2059 client->internal_state = STT_INTERNAL_STATE_NONE;
2060 SLOG(LOG_DEBUG, TAG_STTC, "Internal state change to NONE");
2061 } else if (STT_INTERNAL_STATE_STOPPING == client->internal_state && STT_STATE_PROCESSING == client->current_state) {
2062 client->internal_state = STT_INTERNAL_STATE_NONE;
2063 SLOG(LOG_DEBUG, TAG_STTC, "Internal state change to NONE");
2064 } else if (STT_INTERNAL_STATE_CANCELING == client->internal_state && STT_STATE_READY == client->current_state) {
2065 client->internal_state = STT_INTERNAL_STATE_NONE;
2066 SLOG(LOG_DEBUG, TAG_STTC, "Internal state change to NONE");
2069 if (NULL != client->state_changed_cb) {
2070 stt_client_use_callback(client);
2071 client->state_changed_cb(client->stt, client->before_state,
2072 client->current_state, client->state_changed_user_data);
2073 stt_client_not_use_callback(client);
2074 SLOG(LOG_DEBUG, TAG_STTC, "State changed callback is called, State(%d)", client->current_state);
2076 SLOG(LOG_WARN, TAG_STTC, "[WARNING] State changed callback is null, State(%d)", client->current_state); //LCOV_EXCL_LINE
2082 static Eina_Bool __stt_notify_result(void *data)
2084 stt_client_s* client = (stt_client_s*)data;
2087 if (NULL == client) {
2088 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to notify error : A handle is not valid"); //LCOV_EXCL_LINE
2092 if (NULL == stt_client_get_by_uid(client->uid)) {
2096 if (NULL != client->recognition_result_cb) {
2097 stt_client_use_callback(client);
2098 client->recognition_result_cb(client->stt, client->event, (const char**)client->data_list, client->data_count,
2099 client->msg, client->recognition_result_user_data);
2100 stt_client_not_use_callback(client);
2101 SLOG(LOG_DEBUG, TAG_STTC, "client recognition result callback called");
2103 SLOG(LOG_WARN, TAG_STTC, "[WARNING] User recognition result callback is NULL");
2106 if (NULL != client->msg) {
2111 if (NULL != client->data_list) {
2113 temp = client->data_list;
2116 for (i = 0; i < client->data_count; i++) {
2117 if (NULL != temp[i]) {
2121 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Result data is error"); //LCOV_EXCL_LINE
2124 free(client->data_list);
2125 client->data_list = NULL;
2128 client->data_count = 0;
2130 stt_config_mgr_remove_time_info_file();
2132 if (STT_RESULT_EVENT_FINAL_RESULT == client->event || STT_RESULT_EVENT_ERROR == client->event) {
2133 client->before_state = client->current_state;
2134 client->current_state = STT_STATE_READY;
2136 if (NULL != client->state_changed_cb) {
2137 ecore_main_loop_thread_safe_call_async(__stt_notify_state_changed, client);
2139 SLOG(LOG_WARN, TAG_STTC, "[WARNING] State changed callback is null"); //LCOV_EXCL_LINE
2146 int __stt_cb_result(int uid, int event, char** data, int data_count, const char* msg)
2148 stt_client_s* client = NULL;
2150 client = stt_client_get_by_uid(uid);
2151 if (NULL == client) {
2152 SLOG(LOG_ERROR, TAG_STTC, "Handle is NOT valid"); //LCOV_EXCL_LINE
2153 return STT_ERROR_INVALID_PARAMETER;
2157 SECURE_SLOG(LOG_DEBUG, TAG_STTC, "Recognition Result Message = %s", msg);
2160 for (i = 0; i < data_count; i++) {
2161 if (NULL != data[i])
2162 SECURE_SLOG(LOG_DEBUG, TAG_STTC, "Recognition Result[%d] = %s", i, data[i]);
2165 if (NULL != client->recognition_result_cb) {
2166 client->event = event;
2168 client->msg = strdup(msg);
2171 client->data_count = data_count;
2173 if (data_count > 0) {
2175 temp = (char**)calloc(data_count, sizeof(char*));
2177 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to allocate memory"); //LCOV_EXCL_LINE
2178 return STT_ERROR_OUT_OF_MEMORY;
2181 for (i = 0; i < data_count; i++) {
2182 if (NULL != data[i])
2183 temp[i] = strdup(data[i]);
2185 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Result data is error"); //LCOV_EXCL_LINE
2188 client->data_list = temp;
2191 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] User result callback is null");
2194 __stt_notify_result(client);
2196 return STT_ERROR_NONE;
2199 int __stt_cb_set_state(int uid, int state)
2201 stt_client_s* client = stt_client_get_by_uid(uid);
2202 if (NULL == client) {
2203 SLOG(LOG_ERROR, TAG_STTC, "Handle not found"); //LCOV_EXCL_LINE
2207 stt_state_e state_from_daemon = (stt_state_e)state;
2209 if (client->current_state == state_from_daemon) {
2210 SLOG(LOG_DEBUG, TAG_STTC, "Current state has already been %d", client->current_state);
2214 client->before_state = client->current_state;
2215 client->current_state = state_from_daemon;
2217 ecore_main_loop_thread_safe_call_async(__stt_notify_state_changed, client);
2221 static void __stt_notify_speech_status(void *data)
2223 stt_client_s* client = (stt_client_s*)data;
2226 if (NULL == client) {
2227 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to notify speech status : A handle is not valid"); //LCOV_EXCL_LINE
2231 if (NULL == stt_client_get_by_uid(client->uid)) {
2235 if (NULL != client->speech_status_cb) {
2236 stt_client_use_callback(client);
2237 client->speech_status_cb(client->stt, client->speech_status, client->speech_status_user_data);
2238 stt_client_not_use_callback(client);
2239 SLOG(LOG_DEBUG, TAG_STTC, "Speech status callback is called"); //LCOV_EXCL_LINE
2241 SLOG(LOG_WARN, TAG_STTC, "[WARNING] Speech status callback is null"); //LCOV_EXCL_LINE
2247 int __stt_cb_speech_status(int uid, int status)
2249 stt_client_s* client = stt_client_get_by_uid(uid);
2250 if (NULL == client) {
2251 SLOG(LOG_ERROR, TAG_STTC, "Handle not found"); //LCOV_EXCL_LINE
2255 client->speech_status = status;
2257 ecore_main_loop_thread_safe_call_async(__stt_notify_speech_status, client);
2261 int stt_set_recognition_result_cb(stt_h stt, stt_recognition_result_cb callback, void* user_data)
2263 stt_client_s* client = NULL;
2264 if (0 != __stt_get_feature_enabled()) {
2265 return STT_ERROR_NOT_SUPPORTED;
2267 if (0 != __stt_check_privilege()) {
2268 return STT_ERROR_PERMISSION_DENIED;
2270 if (0 != __stt_check_handle(stt, &client)) {
2271 return STT_ERROR_INVALID_PARAMETER;
2274 if (callback == NULL)
2275 return STT_ERROR_INVALID_PARAMETER;
2277 if (STT_STATE_CREATED != client->current_state) {
2278 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Current state(%d) is not 'Created'", client->current_state);
2279 return STT_ERROR_INVALID_STATE;
2282 client->recognition_result_cb = callback;
2283 client->recognition_result_user_data = user_data;
2288 int stt_unset_recognition_result_cb(stt_h stt)
2290 stt_client_s* client = NULL;
2291 if (0 != __stt_get_feature_enabled()) {
2292 return STT_ERROR_NOT_SUPPORTED;
2294 if (0 != __stt_check_privilege()) {
2295 return STT_ERROR_PERMISSION_DENIED;
2297 if (0 != __stt_check_handle(stt, &client)) {
2298 return STT_ERROR_INVALID_PARAMETER;
2301 if (STT_STATE_CREATED != client->current_state) {
2302 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Current state(%d) is not 'Created'", client->current_state);
2303 return STT_ERROR_INVALID_STATE;
2306 client->recognition_result_cb = NULL;
2307 client->recognition_result_user_data = NULL;
2312 int stt_set_state_changed_cb(stt_h stt, stt_state_changed_cb callback, void* user_data)
2314 stt_client_s* client = NULL;
2315 if (0 != __stt_get_feature_enabled()) {
2316 return STT_ERROR_NOT_SUPPORTED;
2318 if (0 != __stt_check_privilege()) {
2319 return STT_ERROR_PERMISSION_DENIED;
2321 if (0 != __stt_check_handle(stt, &client)) {
2322 return STT_ERROR_INVALID_PARAMETER;
2325 if (NULL == callback)
2326 return STT_ERROR_INVALID_PARAMETER;
2328 if (STT_STATE_CREATED != client->current_state) {
2329 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Current state(%d) is not 'Created'", client->current_state);
2330 return STT_ERROR_INVALID_STATE;
2333 client->state_changed_cb = callback;
2334 client->state_changed_user_data = user_data;
2339 int stt_unset_state_changed_cb(stt_h stt)
2341 stt_client_s* client = NULL;
2342 if (0 != __stt_get_feature_enabled()) {
2343 return STT_ERROR_NOT_SUPPORTED;
2345 if (0 != __stt_check_privilege()) {
2346 return STT_ERROR_PERMISSION_DENIED;
2348 if (0 != __stt_check_handle(stt, &client)) {
2349 return STT_ERROR_INVALID_PARAMETER;
2352 if (STT_STATE_CREATED != client->current_state) {
2353 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Current state(%d) is not 'Created'", client->current_state);
2354 return STT_ERROR_INVALID_STATE;
2357 client->state_changed_cb = NULL;
2358 client->state_changed_user_data = NULL;
2363 int stt_set_error_cb(stt_h stt, stt_error_cb callback, void* user_data)
2365 stt_client_s* client = NULL;
2366 if (0 != __stt_get_feature_enabled()) {
2367 return STT_ERROR_NOT_SUPPORTED;
2369 if (0 != __stt_check_privilege()) {
2370 return STT_ERROR_PERMISSION_DENIED;
2372 if (0 != __stt_check_handle(stt, &client)) {
2373 return STT_ERROR_INVALID_PARAMETER;
2376 if (NULL == callback)
2377 return STT_ERROR_INVALID_PARAMETER;
2379 if (STT_STATE_CREATED != client->current_state) {
2380 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Current state(%d) is not 'Created'", client->current_state);
2381 return STT_ERROR_INVALID_STATE;
2384 client->error_cb = callback;
2385 client->error_user_data = user_data;
2390 int stt_unset_error_cb(stt_h stt)
2392 stt_client_s* client = NULL;
2393 if (0 != __stt_get_feature_enabled()) {
2394 return STT_ERROR_NOT_SUPPORTED;
2396 if (0 != __stt_check_privilege()) {
2397 return STT_ERROR_PERMISSION_DENIED;
2399 if (0 != __stt_check_handle(stt, &client)) {
2400 return STT_ERROR_INVALID_PARAMETER;
2403 if (STT_STATE_CREATED != client->current_state) {
2404 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Current state(%d) is not 'Created'", client->current_state);
2405 return STT_ERROR_INVALID_STATE;
2408 client->error_cb = NULL;
2409 client->error_user_data = NULL;
2414 int stt_set_default_language_changed_cb(stt_h stt, stt_default_language_changed_cb callback, void* user_data)
2416 stt_client_s* client = NULL;
2417 if (0 != __stt_get_feature_enabled()) {
2418 return STT_ERROR_NOT_SUPPORTED;
2420 if (0 != __stt_check_privilege()) {
2421 return STT_ERROR_PERMISSION_DENIED;
2423 if (0 != __stt_check_handle(stt, &client)) {
2424 return STT_ERROR_INVALID_PARAMETER;
2427 if (NULL == callback)
2428 return STT_ERROR_INVALID_PARAMETER;
2430 if (STT_STATE_CREATED != client->current_state) {
2431 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Current state(%d) is not 'Created'", client->current_state);
2432 return STT_ERROR_INVALID_STATE;
2435 client->default_lang_changed_cb = callback;
2436 client->default_lang_changed_user_data = user_data;
2441 int stt_unset_default_language_changed_cb(stt_h stt)
2443 stt_client_s* client = NULL;
2444 if (0 != __stt_get_feature_enabled()) {
2445 return STT_ERROR_NOT_SUPPORTED;
2447 if (0 != __stt_check_privilege()) {
2448 return STT_ERROR_PERMISSION_DENIED;
2450 if (0 != __stt_check_handle(stt, &client)) {
2451 return STT_ERROR_INVALID_PARAMETER;
2454 if (STT_STATE_CREATED != client->current_state) {
2455 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Current state(%d) is not 'Created'", client->current_state);
2456 return STT_ERROR_INVALID_STATE;
2459 client->default_lang_changed_cb = NULL;
2460 client->default_lang_changed_user_data = NULL;
2465 int stt_set_engine_changed_cb(stt_h stt, stt_engine_changed_cb callback, void* user_data)
2467 stt_client_s* client = NULL;
2468 if (0 != __stt_get_feature_enabled()) {
2469 return STT_ERROR_NOT_SUPPORTED;
2471 if (0 != __stt_check_privilege()) {
2472 return STT_ERROR_PERMISSION_DENIED;
2474 if (0 != __stt_check_handle(stt, &client)) {
2475 return STT_ERROR_INVALID_PARAMETER;
2478 if (NULL == callback)
2479 return STT_ERROR_INVALID_PARAMETER;
2481 if (STT_STATE_CREATED != client->current_state) {
2482 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Current state(%d) is not 'Created'", client->current_state);
2483 return STT_ERROR_INVALID_STATE;
2486 client->engine_changed_cb = callback;
2487 client->engine_changed_user_data = user_data;
2492 int stt_unset_engine_changed_cb(stt_h stt)
2494 stt_client_s* client = NULL;
2495 if (0 != __stt_get_feature_enabled()) {
2496 return STT_ERROR_NOT_SUPPORTED;
2498 if (0 != __stt_check_privilege()) {
2499 return STT_ERROR_PERMISSION_DENIED;
2501 if (0 != __stt_check_handle(stt, &client)) {
2502 return STT_ERROR_INVALID_PARAMETER;
2505 if (STT_STATE_CREATED != client->current_state) {
2506 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Current state(%d) is not 'Created'", client->current_state);
2507 return STT_ERROR_INVALID_STATE;
2510 client->engine_changed_cb = NULL;
2511 client->engine_changed_user_data = NULL;
2517 int stt_set_speech_status_cb(stt_h stt, stt_speech_status_cb callback, void* user_data)
2519 stt_client_s* client = NULL;
2520 if (0 != __stt_get_feature_enabled()) {
2521 return STT_ERROR_NOT_SUPPORTED;
2523 if (0 != __stt_check_privilege()) {
2524 return STT_ERROR_PERMISSION_DENIED;
2526 if (0 != __stt_check_handle(stt, &client)) {
2527 return STT_ERROR_INVALID_PARAMETER;
2530 if (NULL == callback)
2531 return STT_ERROR_INVALID_PARAMETER;
2533 if (STT_STATE_CREATED != client->current_state) {
2534 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Current state(%d) is not 'Created'", client->current_state);
2535 return STT_ERROR_INVALID_STATE;
2538 client->speech_status_cb = callback;
2539 client->speech_status_user_data = user_data;
2544 int stt_unset_speech_status_cb(stt_h stt)
2546 stt_client_s* client = NULL;
2547 if (0 != __stt_get_feature_enabled()) {
2548 return STT_ERROR_NOT_SUPPORTED;
2550 if (0 != __stt_check_privilege()) {
2551 return STT_ERROR_PERMISSION_DENIED;
2553 if (0 != __stt_check_handle(stt, &client)) {
2554 return STT_ERROR_INVALID_PARAMETER;
2557 if (STT_STATE_CREATED != client->current_state) {
2558 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Current state(%d) is not 'Created'", client->current_state);
2559 return STT_ERROR_INVALID_STATE;
2562 client->speech_status_cb = NULL;
2563 client->speech_status_user_data = NULL;
2568 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)
2570 stt_client_s* client = NULL;
2571 if (0 != __stt_get_feature_enabled()) {
2572 return STT_ERROR_NOT_SUPPORTED;
2574 if (0 != __stt_check_privilege()) {
2575 return STT_ERROR_PERMISSION_DENIED;
2577 if (0 != __stt_check_handle(stt, &client)) {
2578 return STT_ERROR_INVALID_PARAMETER;
2580 if (NULL == filepath) {
2581 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL");
2582 return STT_ERROR_INVALID_PARAMETER;
2585 SLOG(LOG_DEBUG, TAG_STTC, "===== STT START FILE");
2588 if (client->current_state != STT_STATE_READY) {
2589 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State: Current state(%d) is not READY", client->current_state);
2590 return STT_ERROR_INVALID_STATE;
2593 if (STT_INTERNAL_STATE_NONE != client->internal_state) {
2594 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State : Internal state is NOT none : %d", client->internal_state);
2595 return STT_ERROR_IN_PROGRESS_TO_RECORDING;
2599 char appid[1024] = {0, };
2600 ret = aul_app_get_appid_bypid(getpid(), appid, sizeof(appid) - 1);
2602 if ((AUL_R_OK != ret) || (0 == strlen(appid))) {
2603 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to get application ID");
2605 SLOG(LOG_DEBUG, TAG_STTC, "[DEBUG] Current app id is %s", appid);
2609 if (NULL == language) {
2610 temp = strdup("default");
2612 temp = strdup(language);
2616 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to allocate memory");
2617 return STT_ERROR_OUT_OF_MEMORY;
2620 if (true == client->credential_needed && NULL == client->credential) {
2621 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Do not have app credential for this engine(%s)", client->current_engine_id);
2624 return STT_ERROR_PERMISSION_DENIED;
2627 client->internal_state = STT_INTERNAL_STATE_STARTING;
2628 ret = stt_dbus_request_start_file(client->uid, temp, type, client->silence, appid, client->credential, filepath, audio_type, sample_rate);
2630 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to start file : %s", __stt_get_error_code(ret));
2631 client->internal_state = STT_INTERNAL_STATE_NONE;
2633 SLOG(LOG_DEBUG, TAG_STTC, "[SUCCESS] Start is successful but not done");
2639 SLOG(LOG_DEBUG, TAG_STTC, "=====");
2640 SLOG(LOG_DEBUG, TAG_STTC, " ");
2645 int stt_cancel_file(stt_h stt)
2647 stt_client_s* client = NULL;
2648 if (0 != __stt_get_feature_enabled()) {
2649 return STT_ERROR_NOT_SUPPORTED;
2651 if (0 != __stt_check_privilege()) {
2652 return STT_ERROR_PERMISSION_DENIED;
2654 if (0 != __stt_check_handle(stt, &client)) {
2655 return STT_ERROR_INVALID_PARAMETER;
2658 SLOG(LOG_DEBUG, TAG_STTC, "===== STT CANCEL FILE");
2661 if (STT_STATE_RECORDING != client->current_state && STT_STATE_PROCESSING != client->current_state) {
2662 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid state : Current state(%d) is 'Ready'", client->current_state);
2663 return STT_ERROR_INVALID_STATE;
2666 if (STT_INTERNAL_STATE_STARTING == client->internal_state) {
2667 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State : Internal state is STARTING : %d", client->internal_state);
2668 return STT_ERROR_IN_PROGRESS_TO_RECORDING;
2669 } else if (STT_INTERNAL_STATE_STOPPING == client->internal_state) {
2670 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State : Internal state is STOPPING : %d", client->internal_state);
2671 return STT_ERROR_IN_PROGRESS_TO_PROCESSING;
2672 } else if (STT_INTERNAL_STATE_CANCELING == client->internal_state) {
2673 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State : Internal state is CANCELING : %d", client->internal_state);
2674 return STT_ERROR_IN_PROGRESS_TO_READY;
2677 client->internal_state = STT_INTERNAL_STATE_CANCELING;
2678 int ret = stt_dbus_request_cancel_file(client->uid);
2680 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to cancel file : %s", __stt_get_error_code(ret));
2681 client->internal_state = STT_INTERNAL_STATE_NONE;
2683 SLOG(LOG_DEBUG, TAG_STTC, "[SUCCESS] Cancel file is successful but not done");
2686 SLOG(LOG_DEBUG, TAG_STTC, "=====");
2687 SLOG(LOG_DEBUG, TAG_STTC, " ");