From: Yunhee Seo Date: Thu, 30 Nov 2023 01:36:34 +0000 (+0900) Subject: sound: Support sound conf file parsing existing rule X-Git-Tag: accepted/tizen/unified/20231211.171503^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=f0e8657b3de270221e73385f95601478dd9cb018;p=platform%2Fcore%2Fsystem%2Flibsvi.git sound: Support sound conf file parsing existing rule Previously, [Sound] section parsing was supported in sound.conf file. However, as sound theme handling rule is changed to id-base, it was omitted. If [Sound] section is used in sound.conf, default theme id will be set to 0. Basically, it operates as follows. 1. When section [Sound] is found, sound-parser parses feedback pattern immediately. - This is origin sound.conf parsing style. 2. When section [SoundTheme] is found, sound-parser supports multiple sound theme usage. - This is new sound.conf parsing style as support multiple theme. Thus, do not try to [Sound] and [SoundTheme] section at the same time in the sound.conf Only one of the two styles may be selected and used. Detailed description is added to common/data/sound.conf file. Change-Id: I6f9274e91eb062898d45413f2b674663a7d4e30d Signed-off-by: Yunhee Seo --- diff --git a/common/data/sound.conf b/common/data/sound.conf index b9d947a..2ec9dfe 100644 --- a/common/data/sound.conf +++ b/common/data/sound.conf @@ -1,10 +1,13 @@ # [SoundTheme] # - As put this section, conf file and id can be matched one-on-one. -# This section and [Sound] cannot be defined together , so put [Sound] section to another conf files alone. -# Furthermore, this section must be located sound.conf(default file). +# This section must be located sound.conf(default file). # If you define this section to another file, it will be not work properly. # Only one default file must be set otherwise conf file parsing will fail. -# And also [Sound] will be parsed and used like the existing operation. +# Please refer to file sound-theme1.conf for understanding. +# Also, [Sound] section can be used without [SoundTheme] section as existing usage. +# If you use [Sound] section in this file, default theme id will be set to 0 automatically. +# However, do not try to put [Sound] and [SoundTheme] section simultaneously, +# choose either origin style or new [SoundTheme] style. # SoundThemeId=unsigned integer # - Define an positive number to use specific conf file. # The SoundThemeId should be set by positive value. diff --git a/src/sound-parser.c b/src/sound-parser.c index ba3c865..e33a29a 100644 --- a/src/sound-parser.c +++ b/src/sound-parser.c @@ -32,24 +32,29 @@ static int default_sound_theme_id = INITIAL_DEFAULT_SOUND_THEME_ID; -static GHashTable *g_hash_table_to_check_id_duplicated; - struct sound_theme_info { int id; int is_default; char *conf_file_path; }; -static bool is_sound_theme_id_duplicated(int sound_theme_id) +static void destroy_hash_table(void *hash_table) +{ + if (hash_table) + g_hash_table_destroy(g_steal_pointer((GHashTable**)hash_table)); +} + +static bool is_sound_theme_id_duplicated(int sound_theme_id, void *data) { + GHashTable *hash_table_to_check_id_duplicated = (GHashTable *)data; gint *hash_key = g_new(gint, 1); *hash_key = sound_theme_id; - if (g_hash_table_contains(g_hash_table_to_check_id_duplicated, hash_key)) { + if (g_hash_table_contains(hash_table_to_check_id_duplicated, hash_key)) { g_free(hash_key); return true; } - g_hash_table_insert(g_hash_table_to_check_id_duplicated, hash_key, NULL); + g_hash_table_insert(hash_table_to_check_id_duplicated, hash_key, NULL); return false; } @@ -109,7 +114,7 @@ static int parse_sound_theme_section(const struct parse_result *result, void *da goto out_parsing_fail; } - if (is_sound_theme_id_duplicated(sound_theme_elem.id)) { + if (is_sound_theme_id_duplicated(sound_theme_elem.id, data)) { _E("Failed to parse sound conf file, sound theme id is duplicated."); goto out_parsing_fail; } @@ -138,27 +143,56 @@ out_parsing_fail: return -EPERM; } +static int parse_sound_section(const struct parse_result *result, void *data) +{ + if (!result || !result->props) + return 0; + + if (MATCH(result->section, "Sound")) { + if (is_default_theme_id_set()) { + _E("Failed to parse sound conf file, please check conf file description and follow the rules"); + return -EINVAL; + } + default_sound_theme_id = 0; + sound_thememan_add_sound_theme(default_sound_theme_id, SOUND_CONF_FILE); + return 0; + } + + return 0; +} + int sound_parser_init(void) { int ret = 0; + GHashTable *hash_table_to_check_id_duplicated; - g_hash_table_to_check_id_duplicated = g_hash_table_new_full(g_int_hash, g_int_equal, - g_free, g_free); + ret = syscommon_config_parse_by_section(SOUND_CONF_FILE, parse_sound_section, NULL); + if (ret < 0) { + _E("Failed to parse sound conf file. [Sound] section parsing failed."); + return ret; + } - ret = syscommon_config_parse_by_section(SOUND_CONF_FILE, parse_sound_theme_section, NULL); + if (is_default_theme_id_set()) + return 0; + + hash_table_to_check_id_duplicated = g_hash_table_new_full(g_int_hash, g_int_equal, + g_free, g_free); + ret = syscommon_config_parse_by_section(SOUND_CONF_FILE, parse_sound_theme_section, hash_table_to_check_id_duplicated); + if (ret < 0) { + _E("Failed to parse sound conf file. [SoundTheme] section parsing failed."); + goto destroy_hash_table; + } if (!is_default_theme_id_set()) { _E("Failed to parse sound conf file. There is no default sound theme id"); ret = -EPERM; + goto destroy_hash_table; } - if (g_hash_table_to_check_id_duplicated) - g_hash_table_destroy(g_steal_pointer(&g_hash_table_to_check_id_duplicated)); - - if (ret < 0) - return ret; +destroy_hash_table: + destroy_hash_table(&hash_table_to_check_id_duplicated); - return 0; + return ret; } void sound_parser_exit(void)