--- /dev/null
+/*
+* Copyright (c) 2022 Samsung Electronics Co., Ltd All Rights Reserved
+* Licensed under the Apache License, Version 2.0 (the "License")
+{
+
+}
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+* http://www.apache.org/licenses/LICENSE-2.0
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+
+#include <stdexcept>
+#include <dlog.h>
+
+#include "vc_main.h"
+
+#include "VoiceControlConfig.h"
+
+using namespace std;
+
+VoiceControlConfig::VoiceControlConfig()
+{
+ unique_lock<mutex> lock(__configMutex);
+ __config = nullptr;
+
+ if (0 != vc_parser_load_config(&__config)) {
+ SLOG(LOG_ERROR, TAG_VCCONFIG, "[ERROR] Fail to parse configure information");
+ throw new runtime_error("Operation failed");
+ }
+}
+
+VoiceControlConfig::~VoiceControlConfig()
+{
+ unique_lock<mutex> lock(__configMutex);
+ vc_parser_unload_config(__config);
+ __config = nullptr;
+}
+
+void VoiceControlConfig::printOutConfig()
+{
+ unique_lock<mutex> lock(__configMutex);
+ SLOG(LOG_DEBUG, TAG_VCCONFIG, "Engine : %s", __config->engine_id);
+ SLOG(LOG_DEBUG, TAG_VCCONFIG, "Auto lang : %s", __config->auto_lang ? "true" : "false");
+ SLOG(LOG_DEBUG, TAG_VCCONFIG, "Language : %s", __config->language);
+ SLOG(LOG_DEBUG, TAG_VCCONFIG, "Enabled : %s", __config->enabled ? "true" : "false");
+}
+
+void VoiceControlConfig::setEngineId(const std::string engineId)
+{
+ unique_lock<mutex> lock(__configMutex);
+ if (nullptr == __config) {
+ SLOG(LOG_ERROR, TAG_VCCONFIG, "[ERROR] Config info is NULL");
+ return;
+ }
+
+ free(__config->engine_id);
+ if (engineId.empty()) {
+ __config->engine_id = nullptr;
+ } else {
+ __config->engine_id = strdup(engineId.c_str());
+ }
+ SLOG(LOG_ERROR, TAG_VCCONFIG, "Set Engine ID : %s", __config->engine_id);
+}
+
+std::string VoiceControlConfig::getEngineId()
+{
+ unique_lock<mutex> lock(__configMutex);
+ if (nullptr == __config) {
+ SLOG(LOG_ERROR, TAG_VCCONFIG, "[ERROR] Config info is NULL");
+ return "";
+ }
+
+ string result;
+ if (nullptr != __config->engine_id) {
+ result = __config->engine_id;
+ }
+
+ SLOG(LOG_ERROR, TAG_VCCONFIG, "Get Engine ID : %s", result.c_str());
+ return result;
+}
+
+void VoiceControlConfig::setAutoLanguageEnabled(bool isAutoLanguageEnabled)
+{
+ unique_lock<mutex> lock(__configMutex);
+ if (nullptr == __config) {
+ SLOG(LOG_ERROR, TAG_VCCONFIG, "[ERROR] Config info is NULL");
+ return;
+ }
+
+ __config->auto_lang = isAutoLanguageEnabled;
+ SLOG(LOG_ERROR, TAG_VCCONFIG, "Set Auto language : %s", (__config->auto_lang ? "True" : "False"));
+}
+
+bool VoiceControlConfig::isAutoLanguageEnabled()
+{
+ unique_lock<mutex> lock(__configMutex);
+ if (nullptr == __config) {
+ SLOG(LOG_ERROR, TAG_VCCONFIG, "[ERROR] Config info is NULL");
+ return false;
+ }
+
+ SLOG(LOG_ERROR, TAG_VCCONFIG, "Get Auto language : %s", (__config->auto_lang ? "True" : "False"));
+ return __config->auto_lang;
+}
+
+void VoiceControlConfig::setCurrentLanguage(const std::string language)
+{
+ unique_lock<mutex> lock(__configMutex);
+ if (nullptr == __config) {
+ SLOG(LOG_ERROR, TAG_VCCONFIG, "[ERROR] Config info is NULL");
+ return;
+ }
+
+ free(__config->language);
+ if (language.empty()) {
+ __config->language = nullptr;
+ } else {
+ __config->language = strdup(language.c_str());
+ }
+ SLOG(LOG_ERROR, TAG_VCCONFIG, "Set Language : %s", __config->language);
+}
+
+std::string VoiceControlConfig::getCurrentLanguage()
+{
+ unique_lock<mutex> lock(__configMutex);
+ if (nullptr == __config) {
+ SLOG(LOG_ERROR, TAG_VCCONFIG, "[ERROR] Config info is NULL");
+ return "";
+ }
+
+ string result;
+ if (nullptr != __config->language) {
+ result = __config->language;
+ }
+ SLOG(LOG_ERROR, TAG_VCCONFIG, "Get Language : %s", result.c_str());
+ return result;
+}
+
+void VoiceControlConfig::setEnabled(bool isEnabled)
+{
+ unique_lock<mutex> lock(__configMutex);
+ if (nullptr == __config) {
+ SLOG(LOG_ERROR, TAG_VCCONFIG, "[ERROR] Config info is NULL");
+ return;
+ }
+
+ __config->enabled = isEnabled;
+ SLOG(LOG_ERROR, TAG_VCCONFIG, "Set Enabled : %s", (__config->enabled ? "True" : "False"));
+}
+
+bool VoiceControlConfig::isEnabled()
+{
+ unique_lock<mutex> lock(__configMutex);
+ if (nullptr == __config) {
+ SLOG(LOG_ERROR, TAG_VCCONFIG, "[ERROR] Config info is NULL");
+ return false;
+ }
+
+ SLOG(LOG_ERROR, TAG_VCCONFIG, "Get Enabled : %s", (__config->enabled ? "True" : "False"));
+ return __config->enabled;
+}
#include <buxton2.h>
#include <mutex>
#include <atomic>
+#include <string>
+
+#include "VoiceControlConfig.h"
#include "vc_config_mgr.h"
#include "vc_config_parser.h"
static GSList* g_config_client_list = NULL;
-static vc_config_s* g_config_info;
+static VoiceControlConfig *g_VoiceControlConfig = nullptr;
static int g_lang_ref_count;
static Ecore_Fd_Handler* g_fd_handler_lang = NULL;
g_slist_foreach(g_config_client_list, __invoke_enabled_cb_in_client_list, &enabled_cb_parameter);
}
+static int __initialize_config_info()
+{
+ g_VoiceControlConfig = new(nothrow) VoiceControlConfig();
+ if (nullptr == g_VoiceControlConfig) {
+ SLOG(LOG_ERROR, vc_config_tag(), "[ERROR] Fail to construct config");
+ return VC_CONFIG_ERROR_OPERATION_FAILED;
+ }
+
+ return VC_CONFIG_ERROR_NONE;
+}
+
+static void __finalize_config_info()
+{
+ delete g_VoiceControlConfig;
+ g_VoiceControlConfig = nullptr;
+}
+
int vc_config_convert_error_code(vc_config_error_e code)
{
if (code == VC_CONFIG_ERROR_NONE) return VC_ERROR_NONE;
return VC_CONFIG_ERROR_NONE;
}
-int __vc_config_mgr_check_engine_is_valid(const char* engine_id)
+int __vc_config_mgr_check_and_set_default_engine_id(const char* engine_id)
{
if (NULL == engine_id) {
SLOG(LOG_ERROR, vc_config_tag(), "[ERROR] Input parameter is NULL");
return -1;
}
- if (NULL == g_config_info) {
- SLOG(LOG_ERROR, vc_config_tag(), "[ERROR] Config info is NULL");
- return -1;
- }
-
- if (NULL != g_config_info->engine_id)
- free(g_config_info->engine_id);
-
- g_config_info->engine_id = strdup(engine_info->uuid);
-
- SLOG(LOG_DEBUG, vc_config_tag(), "Default engine is changed : %s", g_config_info->engine_id);
- if (0 != vc_parser_set_engine(g_config_info->engine_id)) {
+ SLOG(LOG_DEBUG, vc_config_tag(), "Default engine is changed : %s", engine_info->uuid);
+ if (0 != vc_parser_set_engine(engine_info->uuid)) {
SLOG(LOG_ERROR, vc_config_tag(), "[ERROR] Fail to save config");
return -1;
}
+ g_VoiceControlConfig->setEngineId(engine_info->uuid);
return VC_ERROR_NONE;
}
SLOG(LOG_ERROR, vc_config_tag(), "[ERROR] Fail to get engine info when config updated");
}
__vc_config_mgr_print_engine_info();
- bool is_language_valid = vc_config_check_default_language_is_valid(g_config_info->language);
+ string default_language = g_VoiceControlConfig->getCurrentLanguage();
+ bool is_language_valid = vc_config_check_default_language_is_valid(default_language.c_str());
if (false == is_language_valid) {
SLOG(LOG_DEBUG, vc_config_tag(), "[ERROR] Default language is not valid");
char* temp_lang = NULL;
- ret = __vc_config_mgr_select_lang(g_config_info->engine_id, &temp_lang);
+ string default_engine_id = g_VoiceControlConfig->getEngineId();
+ ret = __vc_config_mgr_select_lang(default_engine_id.c_str(), &temp_lang);
+
if (0 != ret) {
SLOG(LOG_ERROR, vc_config_tag(), "[ERROR] Fail to get language");
}
if (0 != ret) {
SLOG(LOG_ERROR, vc_config_tag(), "[ERROR] Fail to set language");
} else {
- SLOG(LOG_DEBUG, vc_config_tag(), "[DEBUG] Saved default language : lang(%s)", g_config_info->language);
+ SLOG(LOG_DEBUG, vc_config_tag(), "[DEBUG] Saved default language : lang(%s)", default_language.c_str());
}
if (NULL != temp_lang) {
free(temp_lang);
return ECORE_CALLBACK_PASS_ON;
if (-1 != auto_lang) {
- g_config_info->auto_lang = auto_lang;
+ g_VoiceControlConfig->setAutoLanguageEnabled(auto_lang);
}
/* Only language changed */
if (NULL != lang) {
- char* before_lang = NULL;
-
- before_lang = strdup(g_config_info->language);
-
- if (NULL != g_config_info->language) free(g_config_info->language);
- g_config_info->language = strdup(lang);
+ string before_lang = g_VoiceControlConfig->getCurrentLanguage();
+ g_VoiceControlConfig->setCurrentLanguage(lang);
/* Call all callbacks of client*/
- __vc_config_mgr_notify_language_changed(before_lang, lang);
+ __vc_config_mgr_notify_language_changed(before_lang.c_str(), lang);
- if (NULL != before_lang) free(before_lang);
free(lang);
lang = NULL;
}
/* Only Engine changed */
if (NULL != engine) {
-
- if (NULL != g_config_info->engine_id) {
- free(g_config_info->engine_id);
- g_config_info->engine_id = NULL;
- }
- g_config_info->engine_id = strdup(engine);
+ g_VoiceControlConfig->setEngineId(engine);
/* Call all callbacks of client*/
__vc_config_mgr_notify_engine_changed(engine);
}
if (-1 != enabled) {
- g_config_info->enabled = enabled;
+ g_VoiceControlConfig->setEnabled((bool)enabled);
/* Call all callbacks of client*/
__vc_config_mgr_notify_enabled_changed((bool)enabled);
SLOG(LOG_DEBUG, vc_config_tag(), "[Config] Display language : %s", candidate_lang);
- /* Check current config info */
- if (NULL == g_config_info) {
- SLOG(LOG_ERROR, vc_config_tag(), "[ERROR] Current config info is NULL");
- return VC_CONFIG_ERROR_OPERATION_FAILED;
- }
-
/* Check current language */
- if (NULL == g_config_info->language) {
- SLOG(LOG_ERROR, vc_config_tag(), "[ERROR] Current config language is NULL");
- return VC_CONFIG_ERROR_OPERATION_FAILED;
- }
-
- if (0 == strncmp(g_config_info->language, candidate_lang, 5)) {
- SLOG(LOG_DEBUG, vc_config_tag(), "[Config] VC language(%s) is same with display language", g_config_info->language);
+ string default_language = g_VoiceControlConfig->getCurrentLanguage();
+ if (0 == default_language.compare(candidate_lang)) {
+ SLOG(LOG_DEBUG, vc_config_tag(), "[Config] VC language(%s) is same with display language", default_language.c_str());
return VC_ERROR_NONE;
}
- if (true == __vc_config_mgr_check_lang_is_valid(g_config_info->engine_id, candidate_lang)) {
+ string default_engine_id = g_VoiceControlConfig->getEngineId();
+ if (true == __vc_config_mgr_check_lang_is_valid(default_engine_id.c_str(), candidate_lang)) {
/* vc default language change */
- char* before_lang = NULL;
+ string before_language = g_VoiceControlConfig->getCurrentLanguage();
if (0 != vc_parser_set_language(candidate_lang)) {
SLOG(LOG_ERROR, vc_config_tag(), "[ERROR] Fail to save default language");
return -1;
}
-
- before_lang = strdup(g_config_info->language);
-
- free(g_config_info->language);
- g_config_info->language = strdup(candidate_lang);
+ g_VoiceControlConfig->setCurrentLanguage(candidate_lang);
SLOG(LOG_DEBUG, vc_config_tag(), "[Config] Default language change : before(%s) current(%s)",
- before_lang, g_config_info->language);
+ before_language.c_str(), candidate_lang);
/* Call all callbacks of client*/
- __vc_config_mgr_notify_language_changed(before_lang, g_config_info->language);
-
- if (NULL != before_lang) free(before_lang);
+ __vc_config_mgr_notify_language_changed(before_language.c_str(), candidate_lang);
} else {
/* Candidate language is not valid */
char* tmp_language = NULL;
- if (0 != __vc_config_mgr_select_lang(g_config_info->engine_id, &tmp_language)) {
+ if (0 != __vc_config_mgr_select_lang(default_engine_id.c_str(), &tmp_language)) {
SLOG(LOG_ERROR, vc_config_tag(), "[ERROR] Fail to select language");
return -1;
}
return -1;
}
- char* before_lang = NULL;
+ string before_language = g_VoiceControlConfig->getCurrentLanguage();
if (0 != vc_parser_set_language(tmp_language)) {
free(tmp_language);
SLOG(LOG_ERROR, vc_config_tag(), "[ERROR] Fail to save config");
return -1;
}
-
- before_lang = strdup(g_config_info->language);
-
- free(g_config_info->language);
- g_config_info->language = strdup(tmp_language);
- free(tmp_language);
+ g_VoiceControlConfig->setCurrentLanguage(tmp_language);
SLOG(LOG_DEBUG, vc_config_tag(), "[Config] Default language change : before(%s) current(%s)",
- before_lang, g_config_info->language);
+ before_language.c_str(), tmp_language);
/* Call all callbacks of client*/
- __vc_config_mgr_notify_language_changed(before_lang, g_config_info->language);
-
- if (NULL != before_lang) free(before_lang);
+ __vc_config_mgr_notify_language_changed(before_language.c_str(), tmp_language);
+ free(tmp_language);
}
return VC_ERROR_NONE;
void __vc_config_language_changed_cb(keynode_t *key, void *data)
{
pthread_mutex_lock(&vc_config_mgr_mutex);
- if (g_config_info && true == g_config_info->auto_lang) {
+ if (g_VoiceControlConfig->isAutoLanguageEnabled()) {
/* Get voice input vconf key */
__vc_config_set_auto_language();
}
__vc_config_mgr_print_engine_info();
- if (0 != vc_parser_load_config(&g_config_info)) {
+ if (0 != __initialize_config_info()) {
SLOG(LOG_ERROR, vc_config_tag(), "[ERROR] Fail to parse configure information");
__vc_config_release_engine();
return VC_CONFIG_ERROR_OPERATION_FAILED;
}
- if (0 != __vc_config_mgr_check_engine_is_valid(g_config_info->engine_id)) {
- SLOG(LOG_ERROR, vc_config_tag(), "[ERROR] Fail to get default engine");
+ string default_engine_id = g_VoiceControlConfig->getEngineId();
+ if (0 != __vc_config_mgr_check_and_set_default_engine_id(default_engine_id.c_str())) {
+ SLOG(LOG_ERROR, vc_config_tag(), "[ERROR] Fail to set default engine");
__vc_config_release_engine();
- vc_parser_unload_config(g_config_info);
- g_config_info = NULL;
+ __finalize_config_info();
return VC_CONFIG_ERROR_ENGINE_NOT_FOUND;
}
- if (true == g_config_info->auto_lang) {
+ if (g_VoiceControlConfig->isAutoLanguageEnabled()) {
/* Check language with display language */
__vc_config_set_auto_language();
} else {
- if (false == __vc_config_mgr_check_lang_is_valid(g_config_info->engine_id, g_config_info->language)) {
+ string default_language = g_VoiceControlConfig->getCurrentLanguage();
+ if (false == __vc_config_mgr_check_lang_is_valid(default_engine_id.c_str(), default_language.c_str())) {
/* Default language is not valid */
char* tmp_language;
- if (0 != __vc_config_mgr_select_lang(g_config_info->engine_id, &tmp_language)) {
+ if (0 != __vc_config_mgr_select_lang(default_engine_id.c_str(), &tmp_language)) {
SLOG(LOG_ERROR, vc_config_tag(), "[ERROR] Fail to select language");
__vc_config_release_engine();
- vc_parser_unload_config(g_config_info);
- g_config_info = NULL;
+ __finalize_config_info();
return VC_CONFIG_ERROR_OPERATION_FAILED;
}
if (NULL != tmp_language) {
- if (NULL != g_config_info->language) {
- free(g_config_info->language);
- g_config_info->language = strdup(tmp_language);
- }
-
+ g_VoiceControlConfig->setCurrentLanguage(tmp_language);
if (0 != vc_parser_set_language(tmp_language)) {
free(tmp_language);
SLOG(LOG_ERROR, vc_config_tag(), "[ERROR] Fail to save config");
__vc_config_release_engine();
- vc_parser_unload_config(g_config_info);
- g_config_info = NULL;
+ __finalize_config_info();
return VC_CONFIG_ERROR_OPERATION_FAILED;
}
/* print daemon config */
SLOG(LOG_DEBUG, vc_config_tag(), "@ Daemon config @");
- SLOG(LOG_DEBUG, vc_config_tag(), " engine : %s", g_config_info->engine_id);
- SLOG(LOG_DEBUG, vc_config_tag(), " auto language : %s", g_config_info->auto_lang ? "on" : "off");
- SLOG(LOG_DEBUG, vc_config_tag(), " language : %s", g_config_info->language);
+ g_VoiceControlConfig->printOutConfig();
SLOG(LOG_DEBUG, vc_config_tag(), "@@@@");
g_lang_ref_count = 0;
__vc_config_mgr_unregister_engine_config_updated_event();
vconf_ignore_key_changed(VCONFKEY_LANGSET, __vc_config_language_changed_cb);
-
- vc_parser_unload_config(g_config_info);
- g_config_info = NULL;
+ __finalize_config_info();
pthread_mutex_unlock(&vc_config_mgr_mutex);
SLOG(LOG_DEBUG, vc_config_tag(), "[WARNING] Leave critical section");
return -1;
}
- *value = g_config_info->auto_lang;
+ *value = g_VoiceControlConfig->isAutoLanguageEnabled();
pthread_mutex_unlock(&vc_config_mgr_mutex);
return VC_ERROR_NONE;
return -1;
}
- if (g_config_info->auto_lang != value) {
+ if (g_VoiceControlConfig->isAutoLanguageEnabled() != value) {
/* Check language is valid */
if (0 != vc_parser_set_auto_lang(value)) {
SLOG(LOG_ERROR, vc_config_tag(), "[ERROR] Fail to save engine id");
pthread_mutex_unlock(&vc_config_mgr_mutex);
return -1;
}
+ g_VoiceControlConfig->setAutoLanguageEnabled(value);
- g_config_info->auto_lang = value;
-
- if (true == g_config_info->auto_lang) {
+ if (true == value) {
__vc_config_set_auto_language();
}
}
return VC_CONFIG_ERROR_INVALID_PARAMETER;
}
- if (NULL != g_config_info->engine_id) {
- *engine = strdup(g_config_info->engine_id);
- } else {
+ string default_engine_id = g_VoiceControlConfig->getEngineId();
+ if (default_engine_id.empty()) {
SLOG(LOG_ERROR, vc_config_tag(), " Engine id is NULL"); //LCOV_EXCL_LINE
pthread_mutex_unlock(&vc_config_mgr_mutex);
return VC_CONFIG_ERROR_ENGINE_NOT_FOUND;
}
+ *engine = strdup(default_engine_id.c_str());
pthread_mutex_unlock(&vc_config_mgr_mutex);
return VC_CONFIG_ERROR_NONE;
return VC_CONFIG_ERROR_INVALID_STATE;
}
- if (NULL == g_config_info) {
- pthread_mutex_unlock(&vc_config_mgr_mutex);
- return VC_CONFIG_ERROR_OPERATION_FAILED;
- }
-
- if (NULL == engine || NULL == g_config_info->engine_id) {
+ if (NULL == engine) {
pthread_mutex_unlock(&vc_config_mgr_mutex);
return VC_CONFIG_ERROR_INVALID_PARAMETER;
}
/* Check current engine id with new engine id */
- if (0 == strncmp(g_config_info->engine_id, engine, strlen(g_config_info->engine_id))) {
+ string default_engine_id = g_VoiceControlConfig->getEngineId();
+ if (0 == default_engine_id.compare(engine)) {
+ SLOG(LOG_DEBUG, vc_config_tag(), "Engine is not changed : %s", engine);
pthread_mutex_unlock(&vc_config_mgr_mutex);
return VC_CONFIG_ERROR_NONE;
}
return VC_CONFIG_ERROR_INVALID_PARAMETER;
}
- free(g_config_info->engine_id);
- g_config_info->engine_id = strdup(engine_info->uuid);
+ if (0 != vc_parser_set_engine(engine)) {
+ SLOG(LOG_ERROR, vc_config_tag(), " Fail to save config");
+ pthread_mutex_unlock(&vc_config_mgr_mutex);
+ return VC_CONFIG_ERROR_OPERATION_FAILED;
+ }
+ g_VoiceControlConfig->setEngineId(engine);
/* Engine is valid*/
- bool is_language_valid = __is_language_valid(engine_info, g_config_info->language);
- SLOG(LOG_ERROR, vc_config_tag(), "[INFO] Language(%s), is valid(%d)", (g_config_info->language ? g_config_info->language : "NULL"), (int)is_language_valid);
+ string default_language = g_VoiceControlConfig->getCurrentLanguage();
+ bool is_language_valid = __is_language_valid(engine_info, default_language.c_str());
+ SLOG(LOG_ERROR, vc_config_tag(), "[INFO] Language(%s), is valid(%d)", default_language.c_str(), (int)is_language_valid);
char* lang = NULL;
if (false == is_language_valid) {
- free(g_config_info->language);
- g_config_info->language = NULL;
-
GSList *iter_lang = g_slist_nth(engine_info->languages, 0);
if (NULL == iter_lang || NULL == iter_lang->data) {
SLOG(LOG_ERROR, vc_config_tag(), "[ERROR] Fail to get default language. Engine id(%s) is not valid", engine);
}
lang = static_cast<char *>(iter_lang->data);
- g_config_info->language = strdup(lang);
+ g_VoiceControlConfig->setCurrentLanguage(lang);
}
SLOG(LOG_DEBUG, vc_config_tag(), "[Config] Engine changed");
- SLOG(LOG_DEBUG, vc_config_tag(), "Engine : %s", g_config_info->engine_id);
- SLOG(LOG_DEBUG, vc_config_tag(), "Auto lang : %s", g_config_info->auto_lang ? "true" : "false");
- SLOG(LOG_DEBUG, vc_config_tag(), "Language : %s", g_config_info->language);
- SLOG(LOG_DEBUG, vc_config_tag(), "Enabled : %s", g_config_info->enabled ? "true" : "false");
-
- if (0 != vc_parser_set_engine(g_config_info->engine_id)) {
- SLOG(LOG_ERROR, vc_config_tag(), " Fail to save config");
- pthread_mutex_unlock(&vc_config_mgr_mutex);
- return VC_CONFIG_ERROR_OPERATION_FAILED;
- }
+ g_VoiceControlConfig->printOutConfig();
pthread_mutex_unlock(&vc_config_mgr_mutex);
return VC_CONFIG_ERROR_NONE;
return -1;
}
- vc_engine_info_s *engine_info = __find_engine_info(g_config_info->engine_id);
+ string default_engine_id = g_VoiceControlConfig->getEngineId();
+ vc_engine_info_s *engine_info = __find_engine_info(default_engine_id.c_str());
if (NULL == engine_info) {
- SLOG(LOG_ERROR, vc_config_tag(), "Fail to find engine information : %s", g_config_info->engine_id);
+ SLOG(LOG_ERROR, vc_config_tag(), "Fail to find engine information : %s", default_engine_id.c_str());
pthread_mutex_unlock(&vc_config_mgr_mutex);
return VC_CONFIG_ERROR_NONE;
}
return -1;
}
- if (NULL != g_config_info->language) {
- *language = strdup(g_config_info->language);
- } else {
+ string default_language = g_VoiceControlConfig->getCurrentLanguage();
+ if (default_language.empty()) {
SLOG(LOG_ERROR, vc_config_tag(), "[ERROR] language is NULL");
pthread_mutex_unlock(&vc_config_mgr_mutex);
return -1;
}
+ *language = strdup(default_language.c_str());
pthread_mutex_unlock(&vc_config_mgr_mutex);
return VC_ERROR_NONE;
}
}
/* Check language is valid */
- if (NULL != g_config_info->language) {
- if (0 != vc_parser_set_language(language)) {
- SLOG(LOG_ERROR, vc_config_tag(), "[ERROR] Fail to save engine id");
- return -1;
- }
- free(g_config_info->language);
- g_config_info->language = strdup(language);
- } else {
+ string default_language = g_VoiceControlConfig->getCurrentLanguage();
+ if (default_language.empty()) {
SLOG(LOG_ERROR, vc_config_tag(), "[ERROR] language is NULL");
return -1;
}
+ if (0 != vc_parser_set_language(language)) {
+ SLOG(LOG_ERROR, vc_config_tag(), "[ERROR] Fail to save engine id");
+ return -1;
+ }
+ g_VoiceControlConfig->setCurrentLanguage(language);
+
return VC_ERROR_NONE;
}
return -1;
}
- *value = g_config_info->enabled;
+ *value = g_VoiceControlConfig->isEnabled();
pthread_mutex_unlock(&vc_config_mgr_mutex);
return VC_ERROR_NONE;
return -1;
}
- g_config_info->enabled = value;
+ g_VoiceControlConfig->setEnabled(value);
pthread_mutex_unlock(&vc_config_mgr_mutex);
return VC_ERROR_NONE;
return -1;
}
- if (NULL == g_config_info || NULL == g_config_info->engine_id) {
- SLOG(LOG_ERROR, vc_config_tag(), "[ERROR] Engine ID is not set in global config!!");
- pthread_mutex_unlock(&vc_config_mgr_mutex);
- return VC_CONFIG_ERROR_ENGINE_NOT_FOUND;
- }
-
- vc_engine_info_s *engine_info = __find_engine_info(g_config_info->engine_id);
+ string default_engine_id = g_VoiceControlConfig->getEngineId();
+ vc_engine_info_s *engine_info = __find_engine_info(default_engine_id.c_str());
if (NULL == engine_info) {
- SLOG(LOG_ERROR, vc_config_tag(), "[ERROR] There is no engine with id (%s)!!", g_config_info->engine_id);
+ SLOG(LOG_ERROR, vc_config_tag(), "[ERROR] There is no engine with id (%s)!!", default_engine_id.c_str());
pthread_mutex_unlock(&vc_config_mgr_mutex);
return VC_CONFIG_ERROR_ENGINE_NOT_FOUND;
};
return false;
}
- if (NULL == g_config_info->engine_id) {
- SLOG(LOG_ERROR, vc_config_tag(), "[ERROR] Default engine id is NULL");
- return false;
- }
-
if (0 >= g_slist_length(g_engine_list)) {
return false;
}
- vc_engine_info_s *engine_info = __find_engine_info(g_config_info->engine_id);
+
+ string default_engine_id = g_VoiceControlConfig->getEngineId();
+ vc_engine_info_s *engine_info = __find_engine_info(default_engine_id.c_str());
if (NULL == engine_info) {
- SLOG(LOG_ERROR, vc_config_tag(), "[ERROR] There is no engine with id (%s)!!", g_config_info->engine_id);
+ SLOG(LOG_ERROR, vc_config_tag(), "[ERROR] There is no engine with id (%s)!!", default_engine_id.c_str());
return false;
};