From 36dcbb8ec4d32d12d21d1e44f966d5a9b6b85a8c Mon Sep 17 00:00:00 2001 From: Suyeon Hwang Date: Mon, 17 Jul 2023 11:16:12 +0900 Subject: [PATCH] Assign return values to individual variables - Issue: One variable is used as return value for many functions and they have different purpose. - Solution: vconf_str is used for return values of many vconf_get_str(). It is very common usesage, but it also cause misuse because developer can not directly know the meaning of value from the name of variable. So this patch makes variables for return value of each vconf_get_str() calling and names them more meaningful name. Change-Id: I69eb1314795e569d0dc10444aa299380e6412237 Signed-off-by: Suyeon Hwang --- plugins/wakeup-manager/src/wakeup_settings.cpp | 55 +++++++++++++------------- 1 file changed, 27 insertions(+), 28 deletions(-) diff --git a/plugins/wakeup-manager/src/wakeup_settings.cpp b/plugins/wakeup-manager/src/wakeup_settings.cpp index 327e07c..fea630d 100644 --- a/plugins/wakeup-manager/src/wakeup_settings.cpp +++ b/plugins/wakeup-manager/src/wakeup_settings.cpp @@ -175,26 +175,25 @@ static void wakeup_setting_enabled_wake_word_detection_changed_cb(keynode_t* nod void CWakeupSettings::initialize(map custom_keys) { int vconf_ret; - char *vconf_str; int vconf_bool; double vconf_double; mCustomVconfKeys.clear(); mCustomVconfKeys = custom_keys; - vconf_str = vconf_get_str(mCustomVconfKeys[WAKEUP_SETTINGS_KEY_DEFAULT_ASSISTANT_APPID].c_str()); - if (vconf_str) { - mDefaultAssistantAppid = vconf_str; + char *default_assistant_appid = vconf_get_str(mCustomVconfKeys[WAKEUP_SETTINGS_KEY_DEFAULT_ASSISTANT_APPID].c_str()); + if (default_assistant_appid) { + mDefaultAssistantAppid = default_assistant_appid; MWR_LOGD("default_assistant_appid : %s", mDefaultAssistantAppid.c_str()); for (const auto& observer : mObservers) { if (observer) { - if (!observer->on_default_assistant_appid_changed(vconf_str)) { + if (!observer->on_default_assistant_appid_changed(default_assistant_appid)) { LOGW("[Settings WARNING] One of the observer returned false"); } } } - free(vconf_str); - vconf_str = nullptr; + free(default_assistant_appid); + default_assistant_appid = nullptr; } vconf_ret = vconf_get_bool(WAKEUP_SETTINGS_KEY_UI_PANEL_ENABLED, &vconf_bool); if (0 == vconf_ret) { @@ -212,10 +211,10 @@ void CWakeupSettings::initialize(map custom_keys) MWR_LOGD("multiple_mode : %s", (mMultipleMode ? "true" : "false")); } if (true == mMultipleMode) { - vconf_str = vconf_get_str(mCustomVconfKeys[WAKEUP_SETTINGS_KEY_ENABLED_ASSISTANTS].c_str()); - if (vconf_str) { + char *enabled_assistants = vconf_get_str(mCustomVconfKeys[WAKEUP_SETTINGS_KEY_ENABLED_ASSISTANTS].c_str()); + if (enabled_assistants) { string token; - istringstream iss(vconf_str); + istringstream iss(enabled_assistants); mEnabledAssistants.clear(); while (getline(iss, token, ';')) { mEnabledAssistants.push_back(token); @@ -228,16 +227,16 @@ void CWakeupSettings::initialize(map custom_keys) } } } - free(vconf_str); - vconf_str = nullptr; + free(enabled_assistants); + enabled_assistants = nullptr; } } - vconf_str = vconf_get_str(mCustomVconfKeys[WAKEUP_SETTINGS_KEY_WAKE_WORD_DETECTION_ENABLED].c_str()); - if (vconf_str) { + char *wakeword_detection_enabled = vconf_get_str(mCustomVconfKeys[WAKEUP_SETTINGS_KEY_WAKE_WORD_DETECTION_ENABLED].c_str()); + if (wakeword_detection_enabled) { Json::Reader reader; Json::Value root; mWakeWordDisabledAssistants.clear(); - if (!reader.parse(vconf_str, root)) { + if (!reader.parse(wakeword_detection_enabled, root)) { LOGW("[Settings WARNING] Failed to parse Json : %s", reader.getFormattedErrorMessages().c_str()); } else { auto member = root.getMemberNames(); @@ -248,25 +247,25 @@ void CWakeupSettings::initialize(map custom_keys) } } } - free(vconf_str); - vconf_str = nullptr; + free(wakeword_detection_enabled); + wakeword_detection_enabled = nullptr; } vconf_ret = vconf_get_dbl(WAKEUP_SETTINGS_KEY_WAKEUP_POLICY_DELAY, &vconf_double); if (0 == vconf_ret) { mWakeupPolicyDelay = vconf_double; MWR_LOGD("conversation_timeout : %f", mWakeupPolicyDelay); } - vconf_str = vconf_get_str(WAKEUP_SETTINGS_KEY_WAKEUP_POLICY_PRIORITY); - if (vconf_str) { + char *wakeup_policy_priority = vconf_get_str(WAKEUP_SETTINGS_KEY_WAKEUP_POLICY_PRIORITY); + if (wakeup_policy_priority) { string token; - istringstream iss(vconf_str); + istringstream iss(wakeup_policy_priority); mWakeupPolicyPriority.clear(); while (getline(iss, token, ';')) { mWakeupPolicyPriority.push_back(token); MWR_LOGD("wakeup_policy_priority : %s", token.c_str()); } - free(vconf_str); - vconf_str = nullptr; + free(wakeup_policy_priority); + wakeup_policy_priority = nullptr; } vconf_ret = vconf_get_dbl(WAKEUP_SETTINGS_KEY_STREAMING_DURATION_MAX, &vconf_double); if (0 == vconf_ret) { @@ -274,19 +273,19 @@ void CWakeupSettings::initialize(map custom_keys) MWR_LOGD("streaming_duration_max : %f", mStreamingDurationMax); } #ifdef ENABLE_VOICE_INPUT_LANGUAGE_SETTINGS - vconf_str = vconf_get_str(WAKEUP_SETTINGS_KEY_VOICE_INPUT_LANGUAGE); - if (vconf_str) { - mVoiceInputLanguage = vconf_str; + char *voice_input_language = vconf_get_str(WAKEUP_SETTINGS_KEY_VOICE_INPUT_LANGUAGE); + if (voice_input_language) { + mVoiceInputLanguage = voice_input_language; MWR_LOGD("voice input language : %s", mVoiceInputLanguage.c_str()); for (const auto& observer : mObservers) { if (observer) { - if (!observer->on_voice_input_language_changed(vconf_str)) { + if (!observer->on_voice_input_language_changed(voice_input_language)) { LOGW("[Settings WARNING] One of the observer returned false"); } } } - free(vconf_str); - vconf_str = nullptr; + free(voice_input_language); + voice_input_language = nullptr; } #endif -- 2.7.4