3 * Copyright (c) 2023 Samsung Electronics Co., Ltd.
5 * Licensed under the Apache License, Version 2.0 (the License);
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
20 #include <libsyscommon/list.h>
22 #include "feedback-config.h"
26 #define SOUND_NAME "Sound"
28 struct sound_theme_element {
30 struct feedback_config_info *sound_info;
33 static unsigned int default_sound_theme_id;
34 static GList *g_sound_theme_list;
36 bool sound_thememan_is_sound_theme_id_exist(unsigned int sound_theme_id)
38 struct sound_theme_element *sound_theme_elem = NULL;
39 GList *temp_glist = NULL;
41 SYS_G_LIST_FOREACH(g_sound_theme_list, temp_glist, sound_theme_elem) {
42 if (sound_theme_elem->id == sound_theme_id) {
50 void sound_thememan_set_default_sound_theme_id(unsigned int sound_theme_id)
52 default_sound_theme_id = sound_theme_id;
55 void sound_thememan_get_default_sound_theme_id(unsigned int *sound_theme_id)
57 *sound_theme_id = default_sound_theme_id;
60 int sound_thememan_get_number_of_theme(unsigned int *number_of_theme)
62 if (!number_of_theme) {
63 _E("Invalid parameter: number_of_theme(NULL)");
67 *number_of_theme = (unsigned int)g_list_length(g_sound_theme_list);
71 int sound_thememan_get_sound_theme_info(unsigned int sound_theme_id, void *sound_info)
73 struct sound_theme_element *sound_theme_elem = NULL;
74 GList *temp_glist = NULL;
78 _E("Invalid parameter: sound_info(NULL)");
82 SYS_G_LIST_FOREACH(g_sound_theme_list, temp_glist, sound_theme_elem) {
83 if (sound_theme_elem->id == sound_theme_id) {
84 *(struct feedback_config_info**)sound_info = sound_theme_elem->sound_info;
96 int sound_thememan_add_sound_theme(unsigned int sound_theme_id, const char* conf_file_path)
98 struct sound_theme_element *sound_theme_elem = NULL;
99 struct feedback_config_info *sound_info = NULL;
102 sound_theme_elem = (struct sound_theme_element*)calloc(1, sizeof(struct sound_theme_element));
103 if (!sound_theme_elem) {
104 _E("Failed to allocate memory for sound_theme_elem.");
108 sound_info = (struct feedback_config_info*)calloc(1, sizeof(struct feedback_config_info));
110 _E("Failed to allocate memory for sound_info.");
111 free(sound_theme_elem);
115 sound_info->name = SOUND_NAME;
116 ret = feedback_load_config(conf_file_path, sound_info);
118 _E("Failed to load config file %s", conf_file_path);
119 feedback_free_config(sound_info);
120 free(sound_theme_elem);
124 sound_theme_elem->id = sound_theme_id;
125 sound_theme_elem->sound_info = sound_info;
126 g_sound_theme_list = g_list_append(g_sound_theme_list, sound_theme_elem);
130 int sound_thememan_get_sound_theme_ids(unsigned int *count_of_theme, unsigned int **sound_theme_ids)
133 unsigned int *temp_sound_theme_ids = NULL;
134 struct sound_theme_element* sound_theme_elem = NULL;
135 GList *temp_glist = NULL;
137 sound_thememan_get_number_of_theme(count_of_theme);
139 temp_sound_theme_ids = calloc(*count_of_theme, sizeof(unsigned int));
140 if (!temp_sound_theme_ids)
143 SYS_G_LIST_FOREACH(g_sound_theme_list, temp_glist, sound_theme_elem) {
144 temp_sound_theme_ids[index++] = sound_theme_elem->id;
147 *sound_theme_ids = g_steal_pointer(&temp_sound_theme_ids);
151 static void cleanup_sound_theme_element(gpointer data)
153 struct sound_theme_element *sound_theme_elem = NULL;
158 sound_theme_elem = data;
159 sound_theme_elem->sound_info->name = NULL;
160 feedback_free_config(sound_theme_elem->sound_info);
161 free(sound_theme_elem);
164 int sound_thememan_init(void)
166 g_sound_theme_list = NULL;
170 void sound_thememan_exit(void)
172 if (g_sound_theme_list)
173 g_list_free_full(g_steal_pointer(&g_sound_theme_list), cleanup_sound_theme_element);