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;
30 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)
32 /* Need to check engine is valid */
33 if (false == stt_config_check_default_engine_is_valid(engine_id)) {
34 SECURE_SLOG(LOG_ERROR, TAG_STTD, "Engine id is NOT valid : %s", engine_id);
38 if (NULL != g_engine_cb)
39 g_engine_cb(engine_id, language, support_silence, need_credential, g_user_data);
41 SLOG(LOG_ERROR, TAG_STTD, "Engine changed callback is NULL");
44 void __sttd_config_lang_changed_cb(const char* before_language, const char* current_language, void* user_data)
46 if (false == stt_config_check_default_language_is_valid(current_language)) {
47 SECURE_SLOG(LOG_ERROR, TAG_STTD, "Language is NOT valid : %s", current_language);
51 if (NULL != g_lang_cb)
52 g_lang_cb(current_language, g_user_data);
54 SLOG(LOG_ERROR, TAG_STTD, "Language changed callback is NULL");
57 static void __config_bool_changed_cb(stt_config_type_e type, bool bool_value, void* user_data)
59 SECURE_SLOG(LOG_DEBUG, TAG_STTD, " type(%d) bool(%s)", type, bool_value ? "on" : "off");
61 if (STT_CONFIG_TYPE_OPTION_SILENCE_DETECTION == type) {
62 if (NULL != g_silence_cb) {
63 g_silence_cb(bool_value, g_user_data);
64 SLOG(LOG_DEBUG, TAG_STTD, "Call back silence detection changed");
71 int sttd_config_initialize(sttd_config_engine_changed_cb engine_cb,
72 sttd_config_language_changed_cb lang_cb,
73 sttd_config_silence_changed_cb silence_cb,
76 if (NULL == engine_cb || NULL == lang_cb || NULL == silence_cb) {
77 SLOG(LOG_ERROR, TAG_STTD, "[Config] Invalid parameter");
82 ret = stt_config_mgr_initialize(getpid());
84 SLOG(LOG_ERROR, TAG_STTD, "[Config] Fail to initialize config manager");
88 ret = stt_config_mgr_set_callback(getpid(), __sttd_config_engine_changed_cb, __sttd_config_lang_changed_cb,
89 __config_bool_changed_cb, NULL);
91 SLOG(LOG_ERROR, TAG_STTD, "[ERROR] Fail to set config changed : %d", ret);
95 g_engine_cb = engine_cb;
97 g_silence_cb = silence_cb;
98 g_user_data = user_data;
103 int sttd_config_finalize()
105 stt_config_mgr_finalize(getpid());
110 int sttd_config_get_default_engine(char** engine_id)
112 if (NULL == engine_id)
115 if (0 != stt_config_mgr_get_engine(engine_id)) {
116 SLOG(LOG_ERROR, TAG_STTD, "[Config ERROR] Fail to get engine id");
123 int sttd_config_set_default_engine(const char* engine_id)
125 if (NULL == engine_id)
128 if (0 != stt_config_mgr_set_engine(engine_id)) {
129 SLOG(LOG_ERROR, TAG_STTD, "[Config ERROR] Fail to set engine id");
135 int sttd_config_get_default_language(char** language)
137 if (NULL == language)
140 if (0 != stt_config_mgr_get_default_language(language)) {
141 SLOG(LOG_ERROR, TAG_STTD, "[Config ERROR] Fail to get language");
148 int sttd_config_get_default_silence_detection(int* silence)
154 if (0 != stt_config_mgr_get_silence_detection(&value)) {
155 SLOG(LOG_ERROR, TAG_STTD, "[Config ERROR] Fail to set language");
159 *silence = (int)value;
164 int sttd_config_time_add(int index, int event, const char* text, long start_time, long end_time)
166 return stt_config_mgr_add_time_info(index, event, text, start_time, end_time);
169 int sttd_config_time_save()
171 return stt_config_mgr_save_time_info_file();
174 int sttd_config_time_reset()
176 return stt_config_mgr_reset_time_info();