#include <libsyscommon/list.h>
#include "log.h"
+#include "profiles.h"
#include "sound-theme-manager.h"
#define INITIAL_DEFAULT_SOUND_THEME_ID -1
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 = libsys_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
#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;
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)
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);
}
#ifndef __SOUND_THEME_MANAGER_H__
#define __SOUND_THEME_MANAGER_H__
+#include "feedback-ids.h"
+
bool sound_thememan_is_sound_theme_id_exist(unsigned int sound_theme_id);
void sound_thememan_set_default_sound_theme_id(unsigned int sound_theme_id);
void sound_thememan_get_default_sound_theme_id(unsigned int *sound_theme_id);
-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);
int sound_thememan_get_number_of_theme(unsigned int *number_of_theme);
int sound_thememan_add_sound_theme(unsigned int sound_theme_id, const char* conf_file_path);
int sound_thememan_get_sound_theme_ids(unsigned int *count_of_theme, unsigned int **sound_theme_ids);
static char *get_data(feedback_pattern_e pattern)
{
char *data;
- int i;
- int index = -1;
- int ret = 0;
- struct feedback_config_info *sound_info = NULL;
if (pattern <= FEEDBACK_PATTERN_NONE ||
pattern >= profile->max_pattern)
if (data)
return data;
- ret = sound_thememan_get_sound_theme_info(current_theme_id, &sound_info);
- if (ret < 0)
- return NULL;
-
- for (i = 0; i < profile->get_num_of_pattern(); i++) {
- if (pattern == sound_info->data[i].pattern) {
- index = i;
- break;
- }
- }
- if (index < 0) {
+ data = sound_thememan_get_pattern_sound_path(current_theme_id, pattern);
+ if (!data)
_E("Not supported pattern : %d", pattern);
- return NULL;
- }
-
- if (sound_info->data[index].origin)
- data = sound_info->data[index].origin;
return data;
}