feedback: Change feedback pattern data from list to GHashTable
[platform/core/system/libsvi.git] / src / sound-parser.c
index e33a29a..9ccadd2 100644 (file)
@@ -25,6 +25,7 @@
 #include <libsyscommon/list.h>
 
 #include "log.h"
+#include "profiles.h"
 #include "sound-theme-manager.h"
 
 #define INITIAL_DEFAULT_SOUND_THEME_ID                         -1
@@ -198,4 +199,50 @@ destroy_hash_table:
 void sound_parser_exit(void)
 {
        default_sound_theme_id = INITIAL_DEFAULT_SOUND_THEME_ID;
+}
+
+static int parse_sound_property(const struct parse_result *result, void *data)
+{
+       struct section_property *extracted_section_prop = NULL;
+       GList *temp_glist = NULL;
+       int pattern = 0;
+       GHashTable *sound_config_info;
+
+       if (!result || !result->props)
+               return 0;
+
+       if (!data)
+               return -EINVAL;
+
+       if (!MATCH(result->section, "Sound"))
+               return 0;
+
+       sound_config_info = (GHashTable*)data;
+
+       SYS_G_LIST_FOREACH(result->props, temp_glist, extracted_section_prop) {
+               pattern = profile->get_pattern_enum(extracted_section_prop->key);
+               if (pattern < 0 || pattern >= profile->max_pattern)
+                       return -EINVAL;
+               g_hash_table_insert(sound_config_info, GINT_TO_POINTER(pattern),
+                                       g_strdup(extracted_section_prop->value));
+       }
+       return 0;
+}
+
+int sound_parser_get_config_info(const char *file_path, void *config_info)
+{
+       int ret = 0;
+       GHashTable *sound_info;
+
+       if (!file_path || !config_info)
+               return -EINVAL;
+
+       sound_info = (GHashTable*)config_info;
+       ret = syscommon_config_parse_by_section(file_path, parse_sound_property, sound_info);
+       if (ret < 0) {
+               _E("Failed to parse sound conf feedback pattern.");
+               return -EPERM;
+       }
+
+       return 0;
 }
\ No newline at end of file