feedback: Change feedback pattern data from list to GHashTable
[platform/core/system/libsvi.git] / src / sound-theme-manager.c
index 0147ca1..7cea4b4 100644 (file)
 #include "feedback-config.h"
 #include "profiles.h"
 #include "log.h"
+#include "sound-parser.h"
+#include "sound-theme-manager.h"
 
 #define SOUND_NAME                             "Sound"
 
 struct sound_theme_element {
        unsigned int id;
-       struct feedback_config_info *sound_info;
+       GHashTable *sound_info;
 };
 
 static unsigned int default_sound_theme_id;
@@ -68,63 +70,57 @@ int sound_thememan_get_number_of_theme(unsigned int *number_of_theme)
        return 0;
 }
 
-int sound_thememan_get_sound_theme_info(unsigned int sound_theme_id, void *sound_info)
+const char* sound_thememan_get_pattern_sound_path(unsigned int sound_theme_id, feedback_pattern_e pattern)
 {
        struct sound_theme_element *sound_theme_elem = NULL;
        GList *temp_glist = NULL;
-       int find_flag = 0;
-
-       if (!sound_info) {
-               _E("Invalid parameter: sound_info(NULL)");
-               return -EINVAL;
-       }
 
        SYS_G_LIST_FOREACH(g_sound_theme_list, temp_glist, sound_theme_elem) {
-               if (sound_theme_elem->id == sound_theme_id) {
-                       *(struct feedback_config_info**)sound_info = sound_theme_elem->sound_info;
-                       find_flag = 1;
-                       break;
-               }
+               if (sound_theme_elem->id == sound_theme_id)
+                       return g_hash_table_lookup(sound_theme_elem->sound_info, GINT_TO_POINTER(pattern));
        }
 
-       if (!find_flag)
-               return -EPERM;
-
-       return 0;
+       return NULL;
 }
 
 int sound_thememan_add_sound_theme(unsigned int sound_theme_id, const char* conf_file_path)
 {
        struct sound_theme_element *sound_theme_elem = NULL;
-       struct feedback_config_info *sound_info = NULL;
        int ret = 0;
+       GHashTable *sound_info = g_hash_table_new_full(g_direct_hash, g_direct_equal,
+                                                               NULL, g_free);
 
-       sound_theme_elem = (struct sound_theme_element*)calloc(1, sizeof(struct sound_theme_element));
-       if (!sound_theme_elem) {
-               _E("Failed to allocate memory for sound_theme_elem.");
-               return -ENOMEM;
-       }
-
-       sound_info = (struct feedback_config_info*)calloc(1, sizeof(struct feedback_config_info));
        if (!sound_info) {
                _E("Failed to allocate memory for sound_info.");
-               free(sound_theme_elem);
                return -ENOMEM;
        }
 
-       sound_info->name = SOUND_NAME;
-       ret = feedback_load_config(conf_file_path, sound_info);
+       sound_theme_elem = (struct sound_theme_element*)calloc(1, sizeof(struct sound_theme_element));
+       if (!sound_theme_elem) {
+               _E("Failed to allocate memory for sound_theme_elem.");
+               ret = -ENOMEM;
+               goto out_add_sound_theme_fail;
+       }
+
+       ret = sound_parser_get_config_info(conf_file_path, sound_info);
        if (ret < 0) {
                _E("Failed to load config file %s", conf_file_path);
-               feedback_free_config(sound_info);
-               free(sound_theme_elem);
-               return ret;
+               goto out_add_sound_theme_fail;
        }
 
        sound_theme_elem->id = sound_theme_id;
        sound_theme_elem->sound_info = sound_info;
        g_sound_theme_list = g_list_append(g_sound_theme_list, sound_theme_elem);
        return 0;
+
+out_add_sound_theme_fail:
+       if (sound_info)
+               g_hash_table_destroy(g_steal_pointer(&sound_info));
+
+       if (sound_theme_elem)
+               free(sound_theme_elem);
+
+       return ret;
 }
 
 int sound_thememan_get_sound_theme_ids(unsigned int *count_of_theme, unsigned int **sound_theme_ids)
@@ -156,8 +152,9 @@ static void cleanup_sound_theme_element(gpointer data)
                return;
 
        sound_theme_elem = data;
-       sound_theme_elem->sound_info->name = NULL;
-       feedback_free_config(sound_theme_elem->sound_info);
+       if (sound_theme_elem->sound_info)
+               g_hash_table_destroy(g_steal_pointer(&sound_theme_elem->sound_info));
+
        free(sound_theme_elem);
 }