3 * Copyright (c) 2015 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.
21 #include <libsyscommon/ini-parser.h>
23 #include "feedback-config.h"
29 #define MATCH(a, b) (!strncmp(a, b, strlen(a) + 1))
30 #define SET_CONF(a, b) (a = (b > 0.0 ? b : a))
32 static int load_config_index = 0;
34 static int load_config(struct parse_result *result, void *user_data)
36 struct feedback_config_info *info = (struct feedback_config_info *)user_data;
44 if (!MATCH(result->section, info->name))
47 if (!result->name || !result->value)
51 value = result->value;
53 pattern = profile->get_pattern_enum(name);
54 if (pattern < 0 || pattern >= profile->max_pattern)
57 info->data[load_config_index].pattern = pattern;
59 info->data[load_config_index].origin = strdup(value);
60 if (!info->data[load_config_index].origin)
61 _E("fail to copy %d sound data", //LCOV_EXCL_LINE
68 int feedback_load_config(const char *path,
69 struct feedback_config_info *info)
77 info->data = calloc(1,
78 sizeof(struct feedback_data) * profile->get_num_of_pattern());
80 _E("fail to allocate %s data", path); //LCOV_EXCL_LINE
81 return -ENOMEM; //LCOV_EXCL_LINE System Error
84 for (i = 0; i < profile->get_num_of_pattern(); i++)
85 info->data[i].pattern = -1;
87 load_config_index = 0;
88 ret = config_parse(path, load_config, info);
90 _E("Failed to load %s, %d Use default value!", //LCOV_EXCL_LINE
96 void feedback_free_config(struct feedback_config_info *info)
100 if (!info || !(info->data))
106 for (i = 0; i < profile->get_num_of_pattern(); i++) {
107 if (info->data[i].origin) {
108 free(info->data[i].origin);
109 info->data[i].origin = NULL;
111 if (info->data[i].changed) {
112 free(info->data[i].changed);
113 info->data[i].changed = NULL;
119 load_config_index = 0;