src/sound.c
src/vibrator.c
src/devices.c
- src/parser.c
+ src/feedback-config.c
src/feedback.c
src/check.c)
#include <stdio.h>
+#include <stdlib.h>
+#include <limits.h>
#include <vconf.h>
#include <system_info.h>
#include <sys/stat.h>
#define __DESTRUCTOR__ __attribute__ ((destructor))
#endif
-#ifndef __DD_LIST__
-#define __DD_LIST__
-#include <glib.h>
-typedef GList dd_list;
-#define DD_LIST_PREPEND(a, b) \
- a = g_list_prepend(a, b)
-#define DD_LIST_APPEND(a, b) \
- a = g_list_append(a, b)
-#define DD_LIST_REMOVE(a, b) \
- a = g_list_remove(a, b)
-#define DD_LIST_FOREACH(head, elem, node) \
- for (elem = head; elem && ((node = elem->data) != NULL); elem = elem->next, node = NULL)
-#define DD_LIST_FOREACH_SAFE(head, elem, elem_next, node) \
- for (elem = head, elem_next=g_list_next(elem), node = NULL; \
- elem && ((node = elem->data) != NULL); \
- elem = elem_next, elem_next = g_list_next(elem), node=NULL)
-#endif
-
-#define FEEDBACK_DATA_DIR FEEDBACK_SYS_SHARE"/feedback"
+#define FEEDBACK_DATA_DIR FEEDBACK_SYS_SHARE"/feedback"
#define FEEDBACK_ORIGIN_DATA_DIR FEEDBACK_SYS_RO_SHARE"/feedback"
#define FEEDBACK_RETRY_CNT 1
#include <stdio.h>
+#include <libsyscommon/list.h>
#include "feedback-ids.h"
#include "devices.h"
#include "log.h"
-static dd_list *dev_head;
+static list *dev_head;
void add_device(const struct device_ops *dev)
{
- DD_LIST_APPEND(dev_head, (struct device_ops*)dev);
+ LIST_APPEND(dev_head, (struct device_ops*)dev);
}
//LCOV_EXCL_START System Error
void remove_device(const struct device_ops *dev)
{
- DD_LIST_REMOVE(dev_head, (struct device_ops*)dev);
+ LIST_REMOVE(dev_head, (struct device_ops*)dev);
}
//LCOV_EXCL_STOP
const struct device_ops *find_device(int type)
{
- dd_list *elem;
+ list *elem;
const struct device_ops *dev;
- DD_LIST_FOREACH(dev_head, elem, dev) {
+ LIST_FOREACH(dev_head, elem, dev) {
if (dev->type == type)
return dev;
}
void devices_init(void)
{
- dd_list *elem;
+ list *elem;
const struct device_ops *dev;
- DD_LIST_FOREACH(dev_head, elem, dev) {
+ LIST_FOREACH(dev_head, elem, dev) {
_D("[%s] initialize", dev->name);
if (dev->init)
dev->init();
void devices_exit(void)
{
- dd_list *elem;
+ list *elem;
const struct device_ops *dev;
- DD_LIST_FOREACH(dev_head, elem, dev) {
+ LIST_FOREACH(dev_head, elem, dev) {
_D("[%s] deinitialize", dev->name);
if (dev->exit)
dev->exit();
int devices_play(int pattern, bool always)
{
- dd_list *elem;
+ list *elem;
const struct device_ops *dev;
int ret, prev = -EPERM;
- DD_LIST_FOREACH(dev_head, elem, dev) {
+ LIST_FOREACH(dev_head, elem, dev) {
if (dev->play) {
ret = dev->play(pattern, always);
if ((prev < 0 && ret == 0) ||
int devices_play_soundpath(int pattern, const char *soundpath, bool always)
{
- dd_list *elem;
+ list *elem;
const struct device_ops *dev;
int ret, prev = -EPERM;
- DD_LIST_FOREACH(dev_head, elem, dev) {
+ LIST_FOREACH(dev_head, elem, dev) {
if (dev->type == FEEDBACK_TYPE_SOUND) {
if (dev->play_path)
ret = dev->play_path(pattern, soundpath, always);
int devices_stop(void)
{
- dd_list *elem;
+ list *elem;
const struct device_ops *dev;
int ret = -ENOTSUP;
- DD_LIST_FOREACH(dev_head, elem, dev) {
+ LIST_FOREACH(dev_head, elem, dev) {
if (dev->stop)
ret = dev->stop();
}
--- /dev/null
+/*
+ * libfeedback
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <stdio.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <libsyscommon/ini-parser.h>
+
+#include "feedback-config.h"
+#include "profiles.h"
+#include "log.h"
+
+#define MAX_DATA 256
+
+#define MATCH(a, b) (!strncmp(a, b, strlen(a)))
+#define SET_CONF(a, b) (a = (b > 0.0 ? b : a))
+
+static int load_config_index = 0;
+
+static int load_config(struct parse_result *result, void *user_data)
+{
+ struct feedback_config_info *info = (struct feedback_config_info *)user_data;
+ char *name;
+ char *value;
+ int pattern;
+
+ if (!info)
+ return -EINVAL;
+
+ if (!MATCH(result->section, info->name))
+ return -ENOENT;
+
+ if (!result->name || !result->value)
+ return -ENOENT;
+
+ name = result->name;
+ value = result->value;
+
+ pattern = profile->get_pattern_enum(name);
+ if (pattern < 0 || pattern >= profile->max_pattern)
+ return -EINVAL;
+
+ info->data[load_config_index].pattern = pattern;
+
+ info->data[load_config_index].origin = strdup(value);
+ if (!info->data[load_config_index].origin)
+ _E("fail to copy %d sound data", //LCOV_EXCL_LINE
+ pattern);
+ load_config_index++;
+
+ return 0;
+}
+
+int feedback_load_config(const char *path,
+ struct feedback_config_info *info)
+{
+ int ret;
+ int i;
+
+ if (!path || !info)
+ return -EINVAL;
+
+ info->data = calloc(1,
+ sizeof(struct feedback_data) * profile->get_num_of_pattern());
+ if (!info->data) {
+ _E("fail to allocate %s data", path); //LCOV_EXCL_LINE
+ return -ENOMEM; //LCOV_EXCL_LINE System Error
+ }
+
+ for (i = 0; i < profile->get_num_of_pattern(); i++)
+ info->data[i].pattern = -1;
+
+ ret = config_parse(path, load_config, info);
+ if (ret < 0)
+ _E("Failed to load %s, %d Use default value!", //LCOV_EXCL_LINE
+ path, ret);
+
+ return ret;
+}
+
+void feedback_free_config(struct feedback_config_info *info)
+{
+ int i;
+
+ if (!info || !(info->data))
+ return;
+
+ if (!profile)
+ return;
+
+ for (i = 0; i < profile->get_num_of_pattern(); i++) {
+ if (info->data[i].origin) {
+ free(info->data[i].origin);
+ info->data[i].origin = NULL;
+ }
+ if (info->data[i].changed) {
+ free(info->data[i].changed);
+ info->data[i].changed = NULL;
+ }
+ }
+
+ free(info->data);
+ info->data = NULL;
+ load_config_index = 0;
+}
--- /dev/null
+/*
+ * libfeedback
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __PARSER_H__
+#define __PARSER_H__
+
+struct feedback_data {
+ int pattern;
+ char *origin;
+ char *changed;
+};
+
+struct feedback_config_info {
+ char *name;
+ struct feedback_data *data;
+};
+
+int feedback_load_config(const char *path,
+ struct feedback_config_info *info);
+void feedback_free_config(struct feedback_config_info *info);
+
+#endif
+++ /dev/null
-/*
- * libfeedback
- * Copyright (c) 2015 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the License);
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <stdio.h>
-#include <errno.h>
-
-#include "parser.h"
-#include "profiles.h"
-#include "log.h"
-
-#define MAX_DATA 256
-#define MAX_LINE 512
-#define MAX_SECTION 64
-#define WHITESPACE " \t"
-#define NEWLINE "\n\r"
-#define COMMENT '#'
-
-#define MATCH(a, b) (!strncmp(a, b, strlen(a)))
-#define SET_CONF(a, b) (a = (b > 0.0 ? b : a))
-
-struct parse_result {
- char *section;
- char *name;
- char *value;
-};
-
-static int load_config_index = 0;
-
-static inline char *trim_str(char *s)
-{
- char *t;
- /* left trim */
- s += strspn(s, WHITESPACE);
-
- /* right trim */
- for (t = strchr(s, 0); t > s; t--)
- if (!strchr(WHITESPACE, t[-1]))
- break;
- *t = 0;
- return s;
-}
-
-static int config_parse(const char *file_name,
- int cb(struct parse_result *result, void *user_data),
- void *user_data)
-{
- FILE *f = NULL;
- struct parse_result result;
- /* use stack for parsing */
- char line[MAX_LINE];
- char section[MAX_SECTION];
- char *start, *end, *name, *value;
- int lineno = 0, ret = 0;
-
- if (!file_name || !cb) {
- ret = -EINVAL;
- goto error;
- }
-
- /* open conf file */
- f = fopen(file_name, "r");
- if (!f) {
- _E("Failed to open file %s", file_name); //LCOV_EXCL_LINE
- ret = -EIO;
- goto error;
- }
-
- /* parsing line by line */
- while (fgets(line, MAX_LINE, f) != NULL) {
- lineno++;
-
- start = line;
- start[strcspn(start, NEWLINE)] = '\0';
- start = trim_str(start);
-
- if (*start == COMMENT) {
- continue;
- } else if (*start == '[') {
- /* parse section */
- end = strchr(start, ']');
- if (!end || *end != ']') {
- ret = -EBADMSG;
- goto error;
- }
-
- *end = '\0';
- strncpy(section, start + 1, sizeof(section));
- section[MAX_SECTION-1] = '\0';
- } else if (*start) {
- /* parse name & value */
- end = strchr(start, '=');
- if (!end || *end != '=') {
- ret = -EBADMSG;
- goto error;
- }
- *end = '\0';
- name = trim_str(start);
- value = trim_str(end + 1);
- end = strchr(value, COMMENT);
- if (end && *end == COMMENT) {
- *end = '\0';
- value = trim_str(value);
- }
-
- result.section = section;
- result.name = name;
- result.value = value;
- /* callback with parse result */
- ret = cb(&result, user_data);
- if (ret < 0) {
- ret = -EBADMSG;
- goto error;
- }
- }
- }
- _D("Success to load %s", file_name);
- fclose(f);
- return 0;
-
-error:
- if (f)
- fclose(f);
- _E("Failed to read %s:%d!", file_name, lineno); //LCOV_EXCL_LINE
- return ret;
-}
-
-static int load_config(struct parse_result *result, void *user_data)
-{
- struct feedback_config_info *info = (struct feedback_config_info *)user_data;
- char *name;
- char *value;
- int pattern;
-
- if (!info)
- return -EINVAL;
-
- if (!MATCH(result->section, info->name))
- return -ENOENT;
-
- if (!result->name || !result->value)
- return -ENOENT;
-
- name = result->name;
- value = result->value;
-
- pattern = profile->get_pattern_enum(name);
- if (pattern < 0 || pattern >= profile->max_pattern)
- return -EINVAL;
-
- info->data[load_config_index].pattern = pattern;
-
- info->data[load_config_index].origin = strdup(value);
- if (!info->data[load_config_index].origin)
- _E("fail to copy %d sound data", //LCOV_EXCL_LINE
- pattern);
- load_config_index++;
-
- return 0;
-}
-
-int feedback_load_config(const char *path,
- struct feedback_config_info *info)
-{
- int ret;
- int i;
-
- if (!path || !info)
- return -EINVAL;
-
- info->data = calloc(1,
- sizeof(struct feedback_data) * profile->get_num_of_pattern());
- if (!info->data) {
- _E("fail to allocate %s data", path); //LCOV_EXCL_LINE
- return -ENOMEM; //LCOV_EXCL_LINE System Error
- }
-
- for (i = 0; i < profile->get_num_of_pattern(); i++)
- info->data[i].pattern = -1;
-
- ret = config_parse(path, load_config, info);
- if (ret < 0)
- _E("Failed to load %s, %d Use default value!", //LCOV_EXCL_LINE
- path, ret);
-
- return ret;
-}
-
-void feedback_free_config(struct feedback_config_info *info)
-{
- int i;
-
- if (!info || !(info->data))
- return;
-
- if (!profile)
- return;
-
- for (i = 0; i < profile->get_num_of_pattern(); i++) {
- if (info->data[i].origin) {
- free(info->data[i].origin);
- info->data[i].origin = NULL;
- }
- if (info->data[i].changed) {
- free(info->data[i].changed);
- info->data[i].changed = NULL;
- }
- }
-
- free(info->data);
- info->data = NULL;
- load_config_index = 0;
-}
+++ /dev/null
-/*
- * libfeedback
- * Copyright (c) 2015 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the License);
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef __PARSER_H__
-#define __PARSER_H__
-
-struct feedback_data {
- int pattern;
- char *origin;
- char *changed;
-};
-
-struct feedback_config_info {
- char *name;
- struct feedback_data *data;
-};
-
-int feedback_load_config(const char *path,
- struct feedback_config_info *info);
-void feedback_free_config(struct feedback_config_info *info);
-
-#endif
#include <unistd.h>
#include <sys/stat.h>
#include <errno.h>
+#include <stdlib.h>
#include <assert.h>
#include <limits.h>
#include <vconf.h>
#include "profiles.h"
#include "devices.h"
#include "log.h"
-#include "parser.h"
+#include "feedback-config.h"
#define SOUND_CONF_FILE FEEDBACK_SYS_RO_SHARE"/feedback/sound.conf"
#include "feedback.h"
#include "profiles.h"
-#include "parser.h"
+#include "feedback-config.h"
#include "devices.h"
#include "log.h"