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 "stt_config_mgr.h"
16 #include "sttd_config.h"
17 #include "sttd_main.h"
20 static sttd_config_engine_changed_cb g_engine_cb;
22 static sttd_config_language_changed_cb g_lang_cb;
24 static sttd_config_silence_changed_cb g_silence_cb;
26 static void* g_user_data;
35 void __sttd_config_engine_changed_cb(const char* engine_id, const char* setting, const char* language, bool support_silence, bool need_credential, void* user_data)
37 /* Need to check engine is valid */
38 if (false == stt_config_check_default_engine_is_valid(engine_id)) {
39 SECURE_SLOG(LOG_ERROR, TAG_STTD, "Engine id is NOT valid : %s", engine_id);
43 if (NULL != g_engine_cb)
44 g_engine_cb(engine_id, language, support_silence, need_credential, g_user_data);
46 SLOG(LOG_ERROR, TAG_STTD, "Engine changed callback is NULL");
49 void __sttd_config_lang_changed_cb(const char* before_language, const char* current_language, void* user_data)
51 if (false == stt_config_check_default_language_is_valid(current_language)) {
52 SECURE_SLOG(LOG_ERROR, TAG_STTD, "Language is NOT valid : %s", current_language);
56 if (NULL != g_lang_cb)
57 g_lang_cb(current_language, g_user_data);
59 SLOG(LOG_ERROR, TAG_STTD, "Language changed callback is NULL");
62 void __config_bool_changed_cb(stt_config_type_e type, bool bool_value, void* user_data)
64 SECURE_SLOG(LOG_DEBUG, TAG_STTD, " type(%d) bool(%s)", type, bool_value ? "on" : "off");
66 if (STT_CONFIG_TYPE_OPTION_SILENCE_DETECTION == type) {
67 if (NULL != g_silence_cb) {
68 g_silence_cb(bool_value, g_user_data);
69 SLOG(LOG_DEBUG, TAG_STTD, "Call back silence detection changed");
76 int sttd_config_initialize(sttd_config_engine_changed_cb engine_cb,
77 sttd_config_language_changed_cb lang_cb,
78 sttd_config_silence_changed_cb silence_cb,
81 if (NULL == engine_cb || NULL == lang_cb || NULL == silence_cb) {
82 SLOG(LOG_ERROR, TAG_STTD, "[Config] Invalid parameter");
87 ret = stt_config_mgr_initialize(getpid());
89 SLOG(LOG_ERROR, TAG_STTD, "[Config] Fail to initialize config manager");
93 ret = stt_config_mgr_set_callback(getpid(), __sttd_config_engine_changed_cb, __sttd_config_lang_changed_cb,
94 __config_bool_changed_cb, NULL);
96 SLOG(LOG_ERROR, TAG_STTD, "[ERROR] Fail to set config changed : %d", ret);
100 g_engine_cb = engine_cb;
102 g_silence_cb = silence_cb;
103 g_user_data = user_data;
108 int sttd_config_finalize()
110 stt_config_mgr_finalize(getpid());
115 int sttd_config_get_default_engine(char** engine_id)
117 if (NULL == engine_id)
120 if (0 != stt_config_mgr_get_engine(engine_id)) {
121 SLOG(LOG_ERROR, TAG_STTD, "[Config ERROR] Fail to get engine id");
127 int sttd_config_set_default_engine(const char* engine_id)
129 if (NULL == engine_id)
132 if (0 != stt_config_mgr_set_engine(engine_id)) {
133 SLOG(LOG_ERROR, TAG_STTD, "[Config ERROR] Fail to set engine id");
139 int sttd_config_get_default_language(char** language)
141 if (NULL == language)
144 if (0 != stt_config_mgr_get_default_language(language)) {
145 SLOG(LOG_ERROR, TAG_STTD, "[Config ERROR] Fail to get language");
152 int sttd_config_get_default_silence_detection(int* silence)
158 if (0 != stt_config_mgr_get_silence_detection(&value)) {
159 SLOG(LOG_ERROR, TAG_STTD, "[Config ERROR] Fail to set language");
163 *silence = (int)value;
168 int sttd_config_time_add(int index, int event, const char* text, long start_time, long end_time)
170 return stt_config_mgr_add_time_info(index, event, text, start_time, end_time);
173 int sttd_config_time_save()
175 return stt_config_mgr_save_time_info_file();
178 int sttd_config_time_reset()
180 return stt_config_mgr_reset_time_info();