static GList* g_ino_list = nullptr;
static mutex g_ino_list_mutex;
-static pthread_mutex_t vc_config_mgr_mutex = PTHREAD_MUTEX_INITIALIZER;
-
static int __vc_config_mgr_register_engine_config_updated_event(const char* path);
static int __vc_config_mgr_unregister_engine_config_updated_event();
static int __vc_config_mgr_set_default_language(const char* language);
{
SLOG(LOG_DEBUG, vc_config_tag(), "@@@ Engine config updated callback event");
ecore_thread_main_loop_begin();
- pthread_mutex_lock(&vc_config_mgr_mutex);
vc_engine_inotify_s *ino = (vc_engine_inotify_s *)data;
int dir_fd = ino->dir_fd;
if (0 > length) {
SLOG(LOG_ERROR, vc_config_tag(), "[ERROR] Empty Inotify event");
SLOG(LOG_DEBUG, vc_config_tag(), "@@@");
- pthread_mutex_unlock(&vc_config_mgr_mutex);
ecore_thread_main_loop_end();
return ECORE_CALLBACK_DONE;
}
SLOG(LOG_DEBUG, vc_config_tag(), "@@@");
- pthread_mutex_unlock(&vc_config_mgr_mutex);
ecore_thread_main_loop_end();
return ECORE_CALLBACK_PASS_ON;
}
void __vc_config_language_changed_cb(keynode_t *key, void *data)
{
- pthread_mutex_lock(&vc_config_mgr_mutex);
if (g_VoiceControlConfig->isAutoLanguageEnabled()) {
/* Get voice input vconf key */
__vc_config_set_auto_language();
}
-
- pthread_mutex_unlock(&vc_config_mgr_mutex);
- return;
}
static int __initialize_vc_config_mgr()
{
SLOG(LOG_INFO, vc_config_tag(), "[WARNING] Enter critical section");
ecore_thread_main_loop_begin();
- pthread_mutex_lock(&vc_config_mgr_mutex);
int ret = __initialize_vc_config_mgr();
if (VC_CONFIG_ERROR_NONE != ret) {
SLOG(LOG_ERROR, vc_config_tag(), "[ERROR] Fail to initialize vc_config_mgr");
- pthread_mutex_unlock(&vc_config_mgr_mutex);
ecore_thread_main_loop_end();
SLOG(LOG_DEBUG, vc_config_tag(), "[WARNING] Leave critical section");
return ret;
/* Check uid */
if (g_VoiceControlClients->isUidValid(uid)) {
SLOG(LOG_WARN, vc_config_tag(), "[CONFIG] uid(%u) has already registered", uid);
- pthread_mutex_unlock(&vc_config_mgr_mutex);
ecore_thread_main_loop_end();
SLOG(LOG_DEBUG, vc_config_tag(), "[WARNING] Leave critical section");
return VC_CONFIG_ERROR_NONE;
g_VoiceControlClients->printOutClients();
- pthread_mutex_unlock(&vc_config_mgr_mutex);
ecore_thread_main_loop_end();
SLOG(LOG_DEBUG, vc_config_tag(), "[WARNING] Leave critical section");
return VC_ERROR_NONE;
{
SLOG(LOG_INFO, vc_config_tag(), "[WARNING] Enter critical section");
- pthread_mutex_lock(&vc_config_mgr_mutex);
-
if (0 < g_VoiceControlClients->removeClient(uid)) {
- pthread_mutex_unlock(&vc_config_mgr_mutex);
SLOG(LOG_DEBUG, vc_config_tag(), "[WARNING] Leave critical section");
-
return VC_ERROR_NONE;
}
vconf_ignore_key_changed(VCONFKEY_LANGSET, __vc_config_language_changed_cb);
__finalize_config_info();
- pthread_mutex_unlock(&vc_config_mgr_mutex);
SLOG(LOG_DEBUG, vc_config_tag(), "[WARNING] Leave critical section");
g_config_mgr_initialized = false;
int vc_config_mgr_get_auto_language(bool* value)
{
- pthread_mutex_lock(&vc_config_mgr_mutex);
-
if (g_config_mgr_initialized.load() == false) {
SLOG(LOG_ERROR, vc_config_tag(), "[ERROR] Not initialized");
- pthread_mutex_unlock(&vc_config_mgr_mutex);
return -1;
}
if (NULL == value) {
- pthread_mutex_unlock(&vc_config_mgr_mutex);
return -1;
}
*value = g_VoiceControlConfig->isAutoLanguageEnabled();
- pthread_mutex_unlock(&vc_config_mgr_mutex);
-
return VC_ERROR_NONE;
}
int vc_config_mgr_set_auto_language(bool value)
{
- pthread_mutex_lock(&vc_config_mgr_mutex);
-
if (g_config_mgr_initialized.load() == false) {
SLOG(LOG_ERROR, vc_config_tag(), "[ERROR] Not initialized");
- pthread_mutex_unlock(&vc_config_mgr_mutex);
return -1;
}
/* 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);
}
}
- pthread_mutex_unlock(&vc_config_mgr_mutex);
return VC_ERROR_NONE;
}
int vc_config_mgr_get_engine_list(vc_config_supported_engine_cb callback, void* user_data)
{
- pthread_mutex_lock(&vc_config_mgr_mutex);
-
if (g_config_mgr_initialized.load() == false) {
SLOG(LOG_ERROR, vc_config_tag(), "Not initialized");
- pthread_mutex_unlock(&vc_config_mgr_mutex);
return VC_CONFIG_ERROR_INVALID_STATE;
}
if (NULL == callback) {
SLOG(LOG_ERROR, vc_config_tag(), " callback is NULL");
- pthread_mutex_unlock(&vc_config_mgr_mutex);
return VC_CONFIG_ERROR_INVALID_PARAMETER;
}
if (g_VoiceControlEngines->isEngineEmpty()) {
SLOG(LOG_WARN, vc_config_tag(), "[ERROR] Engine list is NULL");
- pthread_mutex_unlock(&vc_config_mgr_mutex);
return VC_CONFIG_ERROR_ENGINE_NOT_FOUND;
}
}
}
- pthread_mutex_unlock(&vc_config_mgr_mutex);
return VC_CONFIG_ERROR_NONE;
}
int vc_config_mgr_get_engine(char** engine)
{
- pthread_mutex_lock(&vc_config_mgr_mutex);
if (g_config_mgr_initialized.load() == false) {
SLOG(LOG_ERROR, vc_config_tag(), "Not initialized"); //LCOV_EXCL_LINE
- pthread_mutex_unlock(&vc_config_mgr_mutex);
return VC_CONFIG_ERROR_INVALID_STATE;
}
if (NULL == engine) {
SLOG(LOG_ERROR, vc_config_tag(), "Parameter is NULL");
- pthread_mutex_unlock(&vc_config_mgr_mutex);
return VC_CONFIG_ERROR_INVALID_PARAMETER;
}
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;
}
int vc_config_mgr_set_engine(const char* engine)
{
- pthread_mutex_lock(&vc_config_mgr_mutex);
if (g_config_mgr_initialized.load() == false) {
SLOG(LOG_ERROR, vc_config_tag(), "Not initialized");
- pthread_mutex_unlock(&vc_config_mgr_mutex);
return VC_CONFIG_ERROR_INVALID_STATE;
}
if (NULL == engine) {
- pthread_mutex_unlock(&vc_config_mgr_mutex);
return VC_CONFIG_ERROR_INVALID_PARAMETER;
}
/* Check current engine id with new engine id */
string default_engine_id = g_VoiceControlConfig->getEngineId();
if (0 == default_engine_id.compare(engine)) {
- pthread_mutex_unlock(&vc_config_mgr_mutex);
return VC_CONFIG_ERROR_NONE;
}
int ret = __vc_config_set_buxtonkey(engine);
if (0 != ret) {
SLOG(LOG_ERROR, vc_config_tag(), "[ERROR] set buxtonkey Failed!!!");
- pthread_mutex_unlock(&vc_config_mgr_mutex);
return ret;
}
shared_ptr<VoiceControlEngineInfo> engineInfo = g_VoiceControlEngines->getEngineInfo(engine);
if (nullptr == engineInfo) {
SLOG(LOG_ERROR, vc_config_tag(), "[ERROR] There is no engine with id (%s)!!", engine);
- pthread_mutex_unlock(&vc_config_mgr_mutex);
return VC_CONFIG_ERROR_INVALID_PARAMETER;
}
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);
auto languages = engineInfo->getSupportedLanguages();
if (languages.empty()) {
SLOG(LOG_ERROR, vc_config_tag(), "[ERROR] Fail to get default language. Engine id(%s) is not valid", engine);
- pthread_mutex_unlock(&vc_config_mgr_mutex);
return VC_CONFIG_ERROR_OPERATION_FAILED;
}
SLOG(LOG_DEBUG, vc_config_tag(), "[Config] Engine changed");
g_VoiceControlConfig->printOutConfig();
-
- pthread_mutex_unlock(&vc_config_mgr_mutex);
return VC_CONFIG_ERROR_NONE;
}
int vc_config_mgr_get_language_list(vc_supported_language_cb callback, void* user_data)
{
- pthread_mutex_lock(&vc_config_mgr_mutex);
if (g_config_mgr_initialized.load() == false) {
SLOG(LOG_ERROR, vc_config_tag(), "[ERROR] Not initialized");
- pthread_mutex_unlock(&vc_config_mgr_mutex);
return -1;
}
if (nullptr == callback) {
SLOG(LOG_ERROR, vc_config_tag(), "[ERROR] Callback is null");
- pthread_mutex_unlock(&vc_config_mgr_mutex);
return VC_CONFIG_ERROR_INVALID_PARAMETER;
}
if (g_VoiceControlEngines->isEngineEmpty()) {
SLOG(LOG_ERROR, vc_config_tag(), "[ERROR] There is no engine");
- pthread_mutex_unlock(&vc_config_mgr_mutex);
return -1;
}
shared_ptr<VoiceControlEngineInfo> engineInfo = g_VoiceControlEngines->getEngineInfo(default_engine_id);
if (nullptr == engineInfo) {
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;
}
}
}
- pthread_mutex_unlock(&vc_config_mgr_mutex);
return VC_ERROR_NONE;
}
int vc_config_mgr_get_default_language(char** language)
{
- pthread_mutex_lock(&vc_config_mgr_mutex);
if (g_config_mgr_initialized.load() == false) {
SLOG(LOG_ERROR, vc_config_tag(), "[ERROR] Not initialized");
- pthread_mutex_unlock(&vc_config_mgr_mutex);
return -1;
}
if (NULL == language) {
- pthread_mutex_unlock(&vc_config_mgr_mutex);
return -1;
}
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;
}
int vc_config_mgr_set_default_language(const char* language)
{
- pthread_mutex_lock(&vc_config_mgr_mutex);
int ret = __vc_config_mgr_set_default_language(language);
- pthread_mutex_unlock(&vc_config_mgr_mutex);
-
return ret;
}
int vc_config_mgr_get_enabled(bool* value)
{
- pthread_mutex_lock(&vc_config_mgr_mutex);
if (g_config_mgr_initialized.load() == false) {
SLOG(LOG_ERROR, vc_config_tag(), "[ERROR] Not initialized");
- pthread_mutex_unlock(&vc_config_mgr_mutex);
return -1;
}
if (NULL == value) {
- pthread_mutex_unlock(&vc_config_mgr_mutex);
return -1;
}
*value = g_VoiceControlConfig->isEnabled();
-
- pthread_mutex_unlock(&vc_config_mgr_mutex);
return VC_ERROR_NONE;
}
int vc_config_mgr_set_enabled(bool value)
{
- pthread_mutex_lock(&vc_config_mgr_mutex);
if (g_config_mgr_initialized.load() == false) {
SLOG(LOG_ERROR, vc_config_tag(), "[ERROR] Not initialized");
- pthread_mutex_unlock(&vc_config_mgr_mutex);
return -1;
}
if (0 != vc_parser_set_enabled(value)) {
SLOG(LOG_ERROR, vc_config_tag(), "[ERROR] Fail to set enabled");
- pthread_mutex_unlock(&vc_config_mgr_mutex);
return -1;
}
g_VoiceControlConfig->setEnabled(value);
- pthread_mutex_unlock(&vc_config_mgr_mutex);
return VC_ERROR_NONE;
}
int vc_config_mgr_get_nonfixed_support(bool* value)
{
- pthread_mutex_lock(&vc_config_mgr_mutex);
if (g_config_mgr_initialized.load() == false) {
SLOG(LOG_ERROR, vc_config_tag(), "[ERROR] Not initialized");
- pthread_mutex_unlock(&vc_config_mgr_mutex);
return -1;
}
if (NULL == value) {
SLOG(LOG_ERROR, vc_config_tag(), "[ERROR] Input parameter is NULL");
- pthread_mutex_unlock(&vc_config_mgr_mutex);
return -1;
}
shared_ptr<VoiceControlEngineInfo> engineInfo = g_VoiceControlEngines->getEngineInfo(default_engine_id);
if (nullptr == engineInfo) {
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;
};
*value = engineInfo->isNonFixedSupported();
-
- pthread_mutex_unlock(&vc_config_mgr_mutex);
return VC_ERROR_NONE;
}
bool vc_config_check_default_engine_is_valid(const char* engine)
{
- pthread_mutex_lock(&vc_config_mgr_mutex);
if (g_config_mgr_initialized.load() == false) {
SLOG(LOG_ERROR, vc_config_tag(), "[ERROR] Not initialized");
- pthread_mutex_unlock(&vc_config_mgr_mutex);
return -1;
}
if (NULL == engine) {
- pthread_mutex_unlock(&vc_config_mgr_mutex);
return false;
}
bool is_valid = g_VoiceControlEngines->isEngineIdValid(engine);
- pthread_mutex_unlock(&vc_config_mgr_mutex);
return is_valid;
}
int vc_config_mgr_set_foreground(int pid, bool value)
{
- pthread_mutex_lock(&vc_config_mgr_mutex);
if (g_config_mgr_initialized.load() == false) {
SLOG(LOG_ERROR, vc_config_tag(), "[ERROR] Not initialized");
- pthread_mutex_unlock(&vc_config_mgr_mutex);
return -1;
}
- pthread_mutex_unlock(&vc_config_mgr_mutex);
return vc_parser_set_foreground(pid, value);
}
int vc_config_mgr_get_foreground(int* pid)
{
- pthread_mutex_lock(&vc_config_mgr_mutex);
if (g_config_mgr_initialized.load() == false) {
SLOG(LOG_ERROR, vc_config_tag(), "[ERROR] Not initialized");
- pthread_mutex_unlock(&vc_config_mgr_mutex);
return -1;
}
- pthread_mutex_unlock(&vc_config_mgr_mutex);
return vc_parser_get_foreground(pid);
}