diff options
author | Yunhee Seo <yuni.seo@samsung.com> | 2023-08-17 14:55:16 +0900 |
---|---|---|
committer | Yunhee Seo <yuni.seo@samsung.com> | 2023-08-21 14:30:51 +0900 |
commit | 513f9e2d31a13ca76b9670f527b4a33c88e591cb (patch) | |
tree | 0a4ade13b0ef2194c04509a77bf1e84691140150 | |
parent | c4df1938229e90d794ea139c2369a717975ca7f1 (diff) | |
download | libsvi-513f9e2d31a13ca76b9670f527b4a33c88e591cb.tar.gz libsvi-513f9e2d31a13ca76b9670f527b4a33c88e591cb.tar.bz2 libsvi-513f9e2d31a13ca76b9670f527b4a33c88e591cb.zip |
sound: Fix multi-theme start index with 0
In the previous multi-theme support implementation,
default index was different according to multi-theme or single theme.
However default sound theme index should start with 0 to maintain consistency.
User should use index "1~N", and that index will be converted to 0~N-1 in intenral implementation.
Start index will be 0 in terms of implementation.
Change-Id: I8549d2039c399e875ace7c06303bb4d1fd10febb
Signed-off-by: Yunhee Seo <yuni.seo@samsung.com>
-rw-r--r-- | common/data/sound.conf | 4 | ||||
-rwxr-xr-x | include/feedback-internal.h | 2 | ||||
-rw-r--r-- | src/sound.c | 36 |
3 files changed, 29 insertions, 13 deletions
diff --git a/common/data/sound.conf b/common/data/sound.conf index 5e896b3..4f4c93c 100644 --- a/common/data/sound.conf +++ b/common/data/sound.conf @@ -16,10 +16,14 @@ # The N number range=1~N # [SoundThemeN] # - This section determines that the file is defined as the Nth theme. +# The N number range=1~N # file_path_of_theme=string # - Defines the path of the corresponding number file. # In this file, [Sound] section and new patterns, new files should be defined. # +# When you use SoundMultiTheme, You should follow the accurate range of number according to above description. +# If you do not follow above description, the conf file parsing will be fail. +# # Example # [SoundMultiTheme] # number_of_theme=2 diff --git a/include/feedback-internal.h b/include/feedback-internal.h index 559196e..c7b03da 100755 --- a/include/feedback-internal.h +++ b/include/feedback-internal.h @@ -192,6 +192,8 @@ int feedback_get_theme_index_internal(feedback_type_e feedback_type, unsigned in /** * @brief Sets the current index of theme. * @details This function sets the index of theme. + * The range of theme index will be 1~N according to conf file. + * Please put the accurate index_of_theme value. * @since_tizen 8.0 * @param[in] type The feedback type * @param[in] index_of_theme The index of theme will be selected diff --git a/src/sound.c b/src/sound.c index ee577a2..c4421f0 100644 --- a/src/sound.c +++ b/src/sound.c @@ -133,6 +133,7 @@ static int feedback_parse_sound_multi_theme_section(const struct parse_result *r sscanf(extracted_section_prop->value, "%d", &number_of_theme); } else if (MATCH("name_of_default_theme", extracted_section_prop->key)) { sscanf(extracted_section_prop->value, "SoundTheme%d", ¤t_theme_index); + current_theme_index--; } else { _E("Failed to parse SoundMultiTheme section. Please check your config file, \ check the value or typo of key value"); @@ -140,7 +141,7 @@ static int feedback_parse_sound_multi_theme_section(const struct parse_result *r } } - if (number_of_theme < current_theme_index) { + if (number_of_theme <= current_theme_index) { _E("Failed to parse SoundMultiTheme section. Please check your config file, \ default theme number cannot be greater then the number of theme"); return -EINVAL; @@ -183,12 +184,19 @@ static int feedback_parse_multi_theme_conf_path_section(const struct parse_resul if (ret == EOF) return 0; - if (multi_theme_index < 0 || multi_theme_index > number_of_theme) - return 0; + if (multi_theme_index <= 0) { + _E("Failed to parse SoundThemeN section, you should check range of SoundThemeN(1~N)"); + return -EINVAL; + } + + if (multi_theme_index > number_of_theme) { + _E("Failed to parse SoundThemeN section, you cannot put N value over number_of_theme value"); + return -EINVAL; + } SYS_G_LIST_FOREACH(result->props, temp_glist, extracted_section_prop) { if (MATCH("file_path_of_theme", extracted_section_prop->key)) { - feedback_load_config(extracted_section_prop->value, &sound_info[multi_theme_index]); + feedback_load_config(extracted_section_prop->value, &sound_info[multi_theme_index-1]); } else { _E("Failed to parse SoundThemeN section, Please check your config file, \ check the value or typo of key value"); @@ -216,14 +224,16 @@ static int sound_get_config(void) bool is_support_multi_theme = false; is_support_multi_theme = feedback_is_multi_theme_support(SOUND_CONF_FILE); + if (!is_support_multi_theme) + number_of_theme++; - sound_info = (struct feedback_config_info*)calloc(number_of_theme+1, sizeof(struct feedback_config_info)); + sound_info = (struct feedback_config_info*)calloc(number_of_theme, sizeof(struct feedback_config_info)); if (!sound_info) { _E("Failed to allocate memory for sound_info."); return -ENOMEM; } - for (int i = 0; i <= number_of_theme; i++) + for (int i = 0; i < number_of_theme; i++) sound_info[i].name = SOUND_NAME; if (is_support_multi_theme) { @@ -240,6 +250,9 @@ static void sound_init(void) { int ret = 0; + number_of_theme = 0; + current_theme_index = 0; + ret = sound_get_config(); if (ret < 0) _W("Failed to load configuration file(%s): %d", SOUND_CONF_FILE, ret); @@ -274,7 +287,7 @@ static void sound_put_config(void) return; /* free sound data */ - for (int i = 0; i <= number_of_theme; i++) { + for (int i = 0; i < number_of_theme; i++) { feedback_free_config(&sound_info[i]); } sound_info = NULL; @@ -595,20 +608,17 @@ static int sound_get_theme_index(unsigned int *index_of_theme) if (!index_of_theme) return -EINVAL; - *index_of_theme = current_theme_index; + *index_of_theme = current_theme_index + 1; return 0; } static int sound_set_theme_index(unsigned int index_of_theme) { - if (index_of_theme > number_of_theme) - return -EINVAL; - - if (number_of_theme > 0 && index_of_theme == 0) + if (index_of_theme > number_of_theme || index_of_theme <= 0) return -EINVAL; - current_theme_index = index_of_theme; + current_theme_index = index_of_theme - 1; return 0; } |