# [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.
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;
}
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;
}
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 = libsys_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 = libsys_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 = libsys_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)