From 548ca54f709a1eaeea9f87531be95fbe728fd537 Mon Sep 17 00:00:00 2001 From: Suyeon Hwang Date: Thu, 8 Dec 2022 16:57:47 +0900 Subject: [PATCH] Cleanup vc_config_mgr Change-Id: Ic8723697a0ec4a408c3778b17e1d78c7c8260e1e Signed-off-by: Suyeon Hwang --- common/vc_config_mgr.cpp | 149 ++++++++++++++++++--------------------- 1 file changed, 70 insertions(+), 79 deletions(-) diff --git a/common/vc_config_mgr.cpp b/common/vc_config_mgr.cpp index ba2bb00..2ee8af5 100644 --- a/common/vc_config_mgr.cpp +++ b/common/vc_config_mgr.cpp @@ -149,7 +149,7 @@ static void __finalize_config_info() int vc_config_convert_error_code(vc_config_error_e code) { - if (code == VC_CONFIG_ERROR_NONE) return VC_ERROR_NONE; + if (code == VC_CONFIG_ERROR_NONE) return VC_CONFIG_ERROR_NONE; if (code == VC_CONFIG_ERROR_OPERATION_FAILED) return VC_ERROR_OPERATION_FAILED; if (code == VC_CONFIG_ERROR_INVALID_PARAMETER) return VC_ERROR_INVALID_PARAMETER; if (code == VC_CONFIG_ERROR_ENGINE_NOT_FOUND) return VC_ERROR_ENGINE_NOT_FOUND; @@ -161,7 +161,7 @@ int vc_config_convert_error_code(vc_config_error_e code) return VC_CONFIG_ERROR_NONE; } -int __vc_config_mgr_check_and_set_default_engine_id(const char* engine_id) +static 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"); @@ -183,14 +183,14 @@ int __vc_config_mgr_check_and_set_default_engine_id(const char* engine_id) SLOG(LOG_DEBUG, vc_config_tag(), "Default engine is changed : %s", engineId.c_str()); if (0 != vc_parser_set_engine(engineId.c_str())) { SLOG(LOG_ERROR, vc_config_tag(), "[ERROR] Fail to save config"); - return -1; + return VC_CONFIG_ERROR_OPERATION_FAILED; } g_VoiceControlConfig->setEngineId(engineId.c_str()); - return VC_ERROR_NONE; + return VC_CONFIG_ERROR_NONE; } -bool __vc_config_mgr_check_lang_is_valid(const char* engine_id, const char* language) +static bool __vc_config_mgr_check_lang_is_valid(const char* engine_id, const char* language) { if (NULL == engine_id || NULL == language) { SLOG(LOG_ERROR, vc_config_tag(), "[ERROR] Input parameter is NULL"); @@ -209,7 +209,7 @@ bool __vc_config_mgr_check_lang_is_valid(const char* engine_id, const char* lang return is_language_valid; } -int __vc_config_mgr_select_lang(const char* engine_id, char** language) +static int __vc_config_mgr_select_lang(const char* engine_id, char** language) { if (NULL == engine_id || NULL == language) { SLOG(LOG_ERROR, vc_config_tag(), "[ERROR] Input parameter is NULL"); @@ -248,7 +248,7 @@ void __vc_config_release_engine() g_VoiceControlEngines = nullptr; } -int __vc_config_mgr_get_engine_info() +static int __vc_config_mgr_get_engine_info() { DIR *dp = NULL; struct dirent *dirp = NULL; @@ -286,7 +286,7 @@ int __vc_config_mgr_get_engine_info() if (filesize >= 512) { SECURE_SLOG(LOG_ERROR, vc_config_tag(), "[CONFIG ERROR] File path is too long : %s", dirp->d_name); closedir(dp); - return -1; + return VC_CONFIG_ERROR_OPERATION_FAILED; } memset(filepath, '\0', 512); @@ -324,7 +324,7 @@ int __vc_config_mgr_get_engine_info() if (filesize >= 512) { SECURE_SLOG(LOG_ERROR, vc_config_tag(), "[CONFIG ERROR] File path is too long : %s", dirp->d_name); closedir(dp); - return -1; + return VC_CONFIG_ERROR_OPERATION_FAILED; } memset(filepath, '\0', 512); @@ -348,10 +348,10 @@ int __vc_config_mgr_get_engine_info() if (g_VoiceControlEngines->isEngineEmpty()) { SLOG(LOG_ERROR, vc_config_tag(), "[ERROR] No engine"); - return -1; + return VC_CONFIG_ERROR_OPERATION_FAILED; } - return VC_ERROR_NONE; + return VC_CONFIG_ERROR_NONE; } static Eina_Bool __vc_config_mgr_engine_config_inotify_event_callback(void* data, Ecore_Fd_Handler *fd_handler) @@ -418,14 +418,14 @@ static int __vc_config_mgr_register_engine_config_updated_event(const char* path { if (NULL == path) { SLOG(LOG_ERROR, vc_config_tag(), "[ERROR] Path is NULL"); - return -1; + return VC_CONFIG_ERROR_INVALID_PARAMETER; } /* For engine directory monitoring */ vc_engine_inotify_s *ino = (vc_engine_inotify_s *)calloc(1, sizeof(vc_engine_inotify_s)); if (NULL == ino) { SLOG(LOG_ERROR, vc_config_tag(), "[ERROR] Fail to allocate memory"); - return -1; + return VC_CONFIG_ERROR_OUT_OF_MEMORY; } ino->dir_fd = inotify_init(); @@ -434,7 +434,7 @@ static int __vc_config_mgr_register_engine_config_updated_event(const char* path free(ino); ino = NULL; - return -1; + return VC_CONFIG_ERROR_OPERATION_FAILED; } ino->dir_wd = inotify_add_watch(ino->dir_fd, path, IN_CLOSE_WRITE); @@ -443,7 +443,7 @@ static int __vc_config_mgr_register_engine_config_updated_event(const char* path SLOG(LOG_ERROR, vc_config_tag(), "[ERROR] Fail to add watch"); free(ino); ino = NULL; - return -1; + return VC_CONFIG_ERROR_OPERATION_FAILED; } ino->dir_fd_handler = ecore_main_fd_handler_add(ino->dir_fd, ECORE_FD_READ, (Ecore_Fd_Cb)__vc_config_mgr_engine_config_inotify_event_callback, (void *)ino, NULL, NULL); @@ -451,7 +451,7 @@ static int __vc_config_mgr_register_engine_config_updated_event(const char* path SLOG(LOG_ERROR, vc_config_tag(), "[ERROR] Fail to add fd handler"); free(ino); ino = NULL; - return -1; + return VC_CONFIG_ERROR_OPERATION_FAILED; } /* Set non-blocking mode of file */ @@ -466,7 +466,7 @@ static int __vc_config_mgr_register_engine_config_updated_event(const char* path unique_lock lock(g_ino_list_mutex); g_ino_list = g_list_append(g_ino_list, ino); - return VC_ERROR_NONE; + return VC_CONFIG_ERROR_NONE; } static int __vc_config_mgr_unregister_engine_config_updated_event() @@ -494,10 +494,10 @@ static int __vc_config_mgr_unregister_engine_config_updated_event() iter = g_list_first(g_ino_list); } } - return VC_ERROR_NONE; + return VC_CONFIG_ERROR_NONE; } -Eina_Bool vc_config_mgr_inotify_event_cb(void* data, Ecore_Fd_Handler *fd_handler) +static Eina_Bool __vc_config_mgr_inotify_event_cb(void* data, Ecore_Fd_Handler *fd_handler) { SLOG(LOG_DEBUG, vc_config_tag(), "@@@ Config changed callback event"); @@ -576,7 +576,7 @@ int __vc_config_set_auto_language() value = vconf_get_str(VCONFKEY_LANGSET); if (NULL == value) { SLOG(LOG_ERROR, vc_config_tag(), "[Config ERROR] Fail to get display language"); - return -1; + return VC_CONFIG_ERROR_OPERATION_FAILED; } strncpy(candidate_lang, value, 5); @@ -588,7 +588,7 @@ int __vc_config_set_auto_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; + return VC_CONFIG_ERROR_NONE; } string default_engine_id = g_VoiceControlConfig->getEngineId(); @@ -597,7 +597,7 @@ int __vc_config_set_auto_language() 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; + return VC_CONFIG_ERROR_OPERATION_FAILED; } g_VoiceControlConfig->setCurrentLanguage(candidate_lang); @@ -611,19 +611,19 @@ int __vc_config_set_auto_language() char* tmp_language = NULL; 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 VC_CONFIG_ERROR_OPERATION_FAILED; } if (NULL == tmp_language) { SLOG(LOG_ERROR, vc_config_tag(), "[ERROR] Selected language is NULL"); - return -1; + return VC_CONFIG_ERROR_OPERATION_FAILED; } 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; + return VC_CONFIG_ERROR_OPERATION_FAILED; } g_VoiceControlConfig->setCurrentLanguage(tmp_language); @@ -635,10 +635,10 @@ int __vc_config_set_auto_language() free(tmp_language); } - return VC_ERROR_NONE; + return VC_CONFIG_ERROR_NONE; } -void __vc_config_language_changed_cb(keynode_t *key, void *data) +static void __vc_config_language_changed_cb(keynode_t *key, void *data) { if (g_VoiceControlConfig->isAutoLanguageEnabled()) { /* Get voice input vconf key */ @@ -788,7 +788,7 @@ int vc_config_mgr_initialize(unsigned int uid) ecore_thread_main_loop_end(); SLOG(LOG_DEBUG, vc_config_tag(), "[WARNING] Leave critical section"); - return VC_ERROR_NONE; + return VC_CONFIG_ERROR_NONE; } int vc_config_mgr_finalize(unsigned int uid) @@ -797,7 +797,7 @@ int vc_config_mgr_finalize(unsigned int uid) if (0 < g_VoiceControlClients->removeClient(uid)) { SLOG(LOG_DEBUG, vc_config_tag(), "[WARNING] Leave critical section"); - return VC_ERROR_NONE; + return VC_CONFIG_ERROR_NONE; } delete g_VoiceControlClients; @@ -814,11 +814,11 @@ int vc_config_mgr_finalize(unsigned int uid) g_config_mgr_initialized = false; SLOG(LOG_DEBUG, vc_config_tag(), "[Success] Finalize config"); - return VC_ERROR_NONE; + return VC_CONFIG_ERROR_NONE; } -int __vc_config_mgr_register_lang_event() +static int __vc_config_mgr_register_lang_event() { if (0 == g_lang_ref_count) { /* get file notification handler */ @@ -828,17 +828,17 @@ int __vc_config_mgr_register_lang_event() fd = inotify_init(); if (fd < 0) { SLOG(LOG_ERROR, vc_config_tag(), "[ERROR] Fail get inotify fd"); - return -1; + return VC_CONFIG_ERROR_OPERATION_FAILED; } g_fd_lang = fd; wd = inotify_add_watch(fd, VC_CONFIG, IN_CLOSE_WRITE); g_wd_lang = wd; - g_fd_handler_lang = ecore_main_fd_handler_add(fd, ECORE_FD_READ, (Ecore_Fd_Cb)vc_config_mgr_inotify_event_cb, NULL, NULL, NULL); + g_fd_handler_lang = ecore_main_fd_handler_add(fd, ECORE_FD_READ, (Ecore_Fd_Cb)__vc_config_mgr_inotify_event_cb, NULL, NULL, NULL); if (NULL == g_fd_handler_lang) { SLOG(LOG_ERROR, vc_config_tag(), "[ERROR] Fail to get handler_noti"); - return -1; + return VC_CONFIG_ERROR_OPERATION_FAILED; } /* Set non-blocking mode of file */ @@ -852,10 +852,10 @@ int __vc_config_mgr_register_lang_event() } g_lang_ref_count++; - return VC_ERROR_NONE; + return VC_CONFIG_ERROR_NONE; } -int __vc_config_mgr_unregister_config_event() +static int __vc_config_mgr_unregister_config_event() { if (0 == g_lang_ref_count) { SLOG(LOG_ERROR, vc_config_tag(), "[ERROR] Lang ref count is 0"); @@ -874,7 +874,7 @@ int __vc_config_mgr_unregister_config_event() vconf_ignore_key_changed(VCONFKEY_LANGSET, __vc_config_language_changed_cb); } - return VC_ERROR_NONE; + return VC_CONFIG_ERROR_NONE; } int vc_config_mgr_set_engine_cb(unsigned int uid, vc_config_engine_changed_cb engine_cb) @@ -984,29 +984,29 @@ int vc_config_mgr_get_auto_language(bool* value) { if (g_config_mgr_initialized.load() == false) { SLOG(LOG_ERROR, vc_config_tag(), "[ERROR] Not initialized"); - return -1; + return VC_CONFIG_ERROR_INVALID_STATE; } if (NULL == value) { - return -1; + return VC_ERROR_INVALID_PARAMETER; } *value = g_VoiceControlConfig->isAutoLanguageEnabled(); - return VC_ERROR_NONE; + return VC_CONFIG_ERROR_NONE; } int vc_config_mgr_set_auto_language(bool value) { if (g_config_mgr_initialized.load() == false) { SLOG(LOG_ERROR, vc_config_tag(), "[ERROR] Not initialized"); - return -1; + return VC_CONFIG_ERROR_INVALID_STATE; } 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"); - return -1; + return VC_CONFIG_ERROR_OPERATION_FAILED; } g_VoiceControlConfig->setAutoLanguageEnabled(value); @@ -1015,7 +1015,7 @@ int vc_config_mgr_set_auto_language(bool value) } } - return VC_ERROR_NONE; + return VC_CONFIG_ERROR_NONE; } int vc_config_mgr_get_engine_list(vc_config_supported_engine_cb callback, void* user_data) @@ -1075,7 +1075,7 @@ int vc_config_mgr_get_engine(char** engine) return VC_CONFIG_ERROR_NONE; } -int __vc_config_set_buxtonkey(const char* engine) +static int __vc_config_set_buxtonkey(const char* engine) { /* Set vconfkey */ struct buxton_client * bux_cli; @@ -1192,7 +1192,7 @@ int vc_config_mgr_get_language_list(vc_supported_language_cb callback, void* use { if (g_config_mgr_initialized.load() == false) { SLOG(LOG_ERROR, vc_config_tag(), "[ERROR] Not initialized"); - return -1; + return VC_CONFIG_ERROR_INVALID_STATE; } if (nullptr == callback) { @@ -1200,16 +1200,11 @@ int vc_config_mgr_get_language_list(vc_supported_language_cb callback, void* use return VC_CONFIG_ERROR_INVALID_PARAMETER; } - if (g_VoiceControlEngines->isEngineEmpty()) { - SLOG(LOG_ERROR, vc_config_tag(), "[ERROR] There is no engine"); - return -1; - } - string default_engine_id = g_VoiceControlConfig->getEngineId(); shared_ptr 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()); - return VC_CONFIG_ERROR_NONE; + return VC_CONFIG_ERROR_ENGINE_NOT_FOUND; } /* Get a first item */ @@ -1227,55 +1222,55 @@ int vc_config_mgr_get_language_list(vc_supported_language_cb callback, void* use } } - return VC_ERROR_NONE; + return VC_CONFIG_ERROR_NONE; } int vc_config_mgr_get_default_language(char** language) { if (g_config_mgr_initialized.load() == false) { SLOG(LOG_ERROR, vc_config_tag(), "[ERROR] Not initialized"); - return -1; + return VC_CONFIG_ERROR_INVALID_STATE; } if (NULL == language) { - return -1; + return VC_CONFIG_ERROR_INVALID_PARAMETER; } string default_language = g_VoiceControlConfig->getCurrentLanguage(); if (default_language.empty()) { SLOG(LOG_ERROR, vc_config_tag(), "[ERROR] language is NULL"); - return -1; + return VC_CONFIG_ERROR_OPERATION_FAILED; } *language = strdup(default_language.c_str()); - return VC_ERROR_NONE; + return VC_CONFIG_ERROR_NONE; } static int __vc_config_mgr_set_default_language(const char* language) { if (g_config_mgr_initialized.load() == false) { SLOG(LOG_ERROR, vc_config_tag(), "[ERROR] Not initialized"); - return -1; + return VC_CONFIG_ERROR_INVALID_STATE; } if (NULL == language) { - return -1; + return VC_CONFIG_ERROR_INVALID_PARAMETER; } /* Check language is valid */ string default_language = g_VoiceControlConfig->getCurrentLanguage(); if (default_language.empty()) { SLOG(LOG_ERROR, vc_config_tag(), "[ERROR] language is NULL"); - return -1; + return VC_CONFIG_ERROR_OPERATION_FAILED; } if (0 != vc_parser_set_language(language)) { SLOG(LOG_ERROR, vc_config_tag(), "[ERROR] Fail to save engine id"); - return -1; + return VC_CONFIG_ERROR_OPERATION_FAILED; } g_VoiceControlConfig->setCurrentLanguage(language); - return VC_ERROR_NONE; + return VC_CONFIG_ERROR_NONE; } int vc_config_mgr_set_default_language(const char* language) @@ -1288,44 +1283,44 @@ int vc_config_mgr_get_enabled(bool* value) { if (g_config_mgr_initialized.load() == false) { SLOG(LOG_ERROR, vc_config_tag(), "[ERROR] Not initialized"); - return -1; + return VC_CONFIG_ERROR_INVALID_STATE; } if (NULL == value) { - return -1; + return VC_CONFIG_ERROR_INVALID_PARAMETER; } *value = g_VoiceControlConfig->isEnabled(); - return VC_ERROR_NONE; + return VC_CONFIG_ERROR_NONE; } int vc_config_mgr_set_enabled(bool value) { if (g_config_mgr_initialized.load() == false) { SLOG(LOG_ERROR, vc_config_tag(), "[ERROR] Not initialized"); - return -1; + return VC_CONFIG_ERROR_INVALID_STATE; } if (0 != vc_parser_set_enabled(value)) { SLOG(LOG_ERROR, vc_config_tag(), "[ERROR] Fail to set enabled"); - return -1; + return VC_CONFIG_ERROR_OPERATION_FAILED; } g_VoiceControlConfig->setEnabled(value); - return VC_ERROR_NONE; + return VC_CONFIG_ERROR_NONE; } int vc_config_mgr_get_nonfixed_support(bool* value) { if (g_config_mgr_initialized.load() == false) { SLOG(LOG_ERROR, vc_config_tag(), "[ERROR] Not initialized"); - return -1; + return VC_CONFIG_ERROR_INVALID_STATE; } if (NULL == value) { SLOG(LOG_ERROR, vc_config_tag(), "[ERROR] Input parameter is NULL"); - return -1; + return VC_CONFIG_ERROR_INVALID_PARAMETER; } string default_engine_id = g_VoiceControlConfig->getEngineId(); @@ -1336,29 +1331,25 @@ int vc_config_mgr_get_nonfixed_support(bool* value) }; *value = engineInfo->isNonFixedSupported(); - return VC_ERROR_NONE; + return VC_CONFIG_ERROR_NONE; } bool vc_config_check_default_engine_is_valid(const char* engine) { if (g_config_mgr_initialized.load() == false) { SLOG(LOG_ERROR, vc_config_tag(), "[ERROR] Not initialized"); - return -1; - } - - if (NULL == engine) { return false; } - bool is_valid = g_VoiceControlEngines->isEngineIdValid(engine); - return is_valid; + bool is_engine_valid = g_VoiceControlEngines->isEngineIdValid(engine); + return is_engine_valid; } bool vc_config_check_default_language_is_valid(const char* language) { if (g_config_mgr_initialized.load() == false) { SLOG(LOG_ERROR, vc_config_tag(), "[ERROR] Not initialized"); - return -1; + return false; } if (NULL == language) { @@ -1382,7 +1373,7 @@ int vc_config_mgr_set_foreground(int pid, bool value) { if (g_config_mgr_initialized.load() == false) { SLOG(LOG_ERROR, vc_config_tag(), "[ERROR] Not initialized"); - return -1; + return VC_CONFIG_ERROR_INVALID_STATE; } return vc_parser_set_foreground(pid, value); @@ -1392,7 +1383,7 @@ int vc_config_mgr_get_foreground(int* pid) { if (g_config_mgr_initialized.load() == false) { SLOG(LOG_ERROR, vc_config_tag(), "[ERROR] Not initialized"); - return -1; + return VC_CONFIG_ERROR_INVALID_STATE; } return vc_parser_get_foreground(pid); -- 2.34.1