summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJiyoung Yun <jy910.yun@samsung.com>2015-06-09 17:59:30 +0900
committerJung <pr.jung@samsung.com>2015-11-10 20:58:47 -0800
commitf9339fef0fcbda01541abcf38f04073911155254 (patch)
tree08f11b2c0ed3f73e3bc7894faa459a137f7e1f0e /src
parent9301bd23d4846ae5fcfe80c337a64238b939ed7d (diff)
downloadlibsvi-f9339fef0fcbda01541abcf38f04073911155254.tar.gz
libsvi-f9339fef0fcbda01541abcf38f04073911155254.tar.bz2
libsvi-f9339fef0fcbda01541abcf38f04073911155254.zip
feedback: Use configuration file instead of xml
This patch remove dependency to libxml. Instead of xml, libfeedback will use configuration file for initial configuration. And this patch diminishes static variable sizes by using dynamic allocation. . Signed-off-by: Jiyoung Yun <jy910.yun@samsung.com> Change-Id: I173ab419ab29dca34fb84fabef1c96cdca91b8a1
Diffstat (limited to 'src')
-rw-r--r--src/parser.c212
-rw-r--r--src/parser.h35
-rw-r--r--src/sound.c179
-rw-r--r--src/vibrator.c181
-rw-r--r--src/xmlparser.c172
-rw-r--r--src/xmlparser.h47
6 files changed, 450 insertions, 376 deletions
diff --git a/src/parser.c b/src/parser.c
new file mode 100644
index 0000000..5202cf9
--- /dev/null
+++ b/src/parser.c
@@ -0,0 +1,212 @@
+/*
+ * 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 <stdlib.h>
+#include <errno.h>
+
+#include "parser.h"
+#include "profiles.h"
+#include "log.h"
+
+#define MAX_DATA 256
+#define MAX_LINE 256
+#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 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);
+ 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);
+ 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 i;
+
+ 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;
+
+ for (i = 0; i < profile->max_pattern; i++) {
+ if (!MATCH(name, (char *)profile->str_pattern[i]))
+ continue;
+
+ info->data[i].origin = strdup(value);
+ if (!info->data[i].origin)
+ _E("fail to copy %s sound data",
+ profile->str_pattern[i]);
+ break;
+ }
+
+ return 0;
+}
+
+int feedback_load_config(const char *path,
+ struct feedback_config_info *info)
+{
+ int ret;
+
+ if (!path || !info)
+ return -EINVAL;
+
+ info->data = calloc(1,
+ sizeof(struct feedback_data) * profile->max_pattern);
+ if (!info->data) {
+ _E("fail to allocate %s data", path);
+ return -ENOMEM;
+ }
+
+ ret = config_parse(path, load_config, info);
+ if (ret < 0)
+ _E("Failed to load %s, %d Use default value!",
+ path, ret);
+
+ return ret;
+}
+
+void feedback_free_config(struct feedback_config_info *info)
+{
+ int i;
+
+ for (i = 0; i < profile->max_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);
+}
diff --git a/src/parser.h b/src/parser.h
new file mode 100644
index 0000000..108e625
--- /dev/null
+++ b/src/parser.h
@@ -0,0 +1,35 @@
+/*
+ * 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 {
+ 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
diff --git a/src/sound.c b/src/sound.c
index 49fba53..b6f7fe4 100644
--- a/src/sound.c
+++ b/src/sound.c
@@ -17,6 +17,7 @@
#include <stdio.h>
+#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <unistd.h>
@@ -31,9 +32,9 @@
#include "profiles.h"
#include "devices.h"
#include "log.h"
-#include "xmlparser.h"
+#include "parser.h"
-#define SOUND_XML "/usr/share/feedback/sound.xml"
+#define SOUND_CONF_FILE "/usr/share/feedback/sound.conf"
/* Temporary keys */
#ifndef VCONFKEY_SETAPPL_BUTTON_SOUNDS_BOOL
@@ -43,10 +44,25 @@
static int sndstatus;
static int touch_sndstatus;
static int keytone_sndstatus;
+static struct feedback_config_info sound_info = {
+ .name = "Sound",
+};
+
+static char *get_data(feedback_pattern_e pattern)
+{
+ char *data;
-static xmlDocPtr v_doc;
+ if (pattern <= FEEDBACK_PATTERN_NONE ||
+ pattern >= profile->max_pattern)
+ return NULL;
-static char sound_file[FEEDBACK_PATTERN_END][PATH_MAX];
+ if (sound_info.data[pattern].changed)
+ data = sound_info.data[pattern].changed;
+ else
+ data = sound_info.data[pattern].origin;
+
+ return data;
+}
inline int is_sound_mode(void)
{
@@ -73,43 +89,10 @@ static void feedback_keytone_sndstatus_cb(keynode_t *key, void* data)
keytone_sndstatus = vconf_keynode_get_bool(key);
}
-static int get_xml_data(xmlDocPtr doc, feedback_pattern_e pattern, struct xmlData **data)
-{
- xmlNodePtr cur;
- struct xmlData *retData;
-
- cur = xml_find(doc, SOUND_STR,
- (const xmlChar*)profile->str_pattern[pattern]);
- /* This pattern does not have sound file to play */
- if (cur == NULL)
- return -ENOENT;
-
- retData = xml_parse(doc, cur);
- if (retData == NULL) {
- _E("xml_parse fail");
- return -EPERM;
- }
-
- *data = retData;
- return 0;
-}
-
-static void release_xml_data(struct xmlData *data)
-{
- if (data == NULL)
- return;
-
- xml_free(data);
-}
-
static void sound_init(void)
{
- /* xml Init */
- v_doc = xml_open(SOUND_XML);
- if (v_doc == NULL) {
- _E("xml_open(%s) fail", SOUND_XML);
- return;
- }
+ /* get sound data */
+ feedback_load_config(SOUND_CONF_FILE, &sound_info);
/* check sound status */
if (vconf_get_bool(VCONFKEY_SETAPPL_TOUCH_SOUNDS_BOOL, &touch_sndstatus) < 0)
@@ -129,10 +112,8 @@ static void sound_exit(void)
vconf_ignore_key_changed(VCONFKEY_SETAPPL_TOUCH_SOUNDS_BOOL, feedback_touch_sndstatus_cb);
vconf_ignore_key_changed(VCONFKEY_SETAPPL_BUTTON_SOUNDS_BOOL, feedback_keytone_sndstatus_cb);
- if (v_doc) {
- xml_close(v_doc);
- v_doc = NULL;
- }
+ /* free sound data */
+ feedback_free_config(&sound_info);
}
static int sound_play(feedback_pattern_e pattern)
@@ -140,14 +121,8 @@ static int sound_play(feedback_pattern_e pattern)
struct stat buf;
int retry = FEEDBACK_RETRY_CNT, ret;
char *path;
- struct xmlData *data = NULL;
int level;
- if (!v_doc) {
- _E("Not initialize");
- return -EPERM;
- }
-
if (vconf_get_bool(VCONFKEY_SETAPPL_SOUND_STATUS_BOOL, &sndstatus) < 0) {
_D("fail to get sound status, will work as turning off");
sndstatus = 0;
@@ -165,33 +140,10 @@ static int sound_play(feedback_pattern_e pattern)
return 0;
}
- /* check whether there is a user defined file */
- path = sound_file[pattern];
-
- /* if not */
- if (!(*path)) {
- ret = get_xml_data(v_doc, pattern, &data);
- if (ret == -ENOENT) {
- _E("No sound case(%s)", profile->str_pattern[pattern]);
- return -ENOTSUP;
- }
-
- if (ret < 0) {
- _E("get_xml_data fail");
- return -EPERM;
- }
-
- if (!data->data) {
- _E("No sound case(%s)", profile->str_pattern[pattern]);
- release_xml_data(data);
- return -ENOTSUP;
- }
-
- path = data->data;
- }
-
- if (stat(path, &buf)) {
- _E("%s is not presents", path);
+ /* get sound file path */
+ path = get_data(pattern);
+ if (!path || stat(path, &buf)) {
+ _E("Not supported sound pattern");
return -ENOTSUP;
}
@@ -205,13 +157,11 @@ static int sound_play(feedback_pattern_e pattern)
ret = mm_sound_play_keysound(path, level);
if (ret == MM_ERROR_NONE) {
_D("Play success! SND filename is %s", path);
- release_xml_data(data);
return 0;
}
_E("mm_sound_play_keysound() returned error(%d)", ret);
} while(retry--);
- release_xml_data(data);
return -EPERM;
}
@@ -219,59 +169,21 @@ static int sound_is_supported(feedback_pattern_e pattern, bool *supported)
{
struct stat buf;
char *path;
- struct xmlData *data = NULL;
- int ret;
+ bool ret = true;
if (!supported) {
_E("Invalid parameter : supported(NULL)");
return -EINVAL;
}
- if (!v_doc) {
- _E("Not initialize");
- return -EPERM;
- }
-
- /* check whether there is a user defined file */
- path = sound_file[pattern];
-
- /* if not */
- if (!(*path)) {
- ret = get_xml_data(v_doc, pattern, &data);
- if (ret == -ENOENT) {
- _D("No sound case(%s)", profile->str_pattern[pattern]);
- goto out;
- }
-
- if (ret < 0) {
- _E("get_xml_data fail");
- return -EPERM;
- }
-
- if (!data->data) {
- _D("No sound case(%s)", profile->str_pattern[pattern]);
- goto out;
- }
-
- path = data->data;
- }
-
- if (stat(path, &buf)) {
+ /* get sound file path */
+ path = get_data(pattern);
+ if (!path || stat(path, &buf)) {
_E("%s is not presents", path);
- release_xml_data(data);
- return -ENOENT;
+ ret = false;
}
- release_xml_data(data);
-
- *supported = true;
- return 0;
-
-out:
- if (data)
- release_xml_data(data);
-
- *supported = false;
+ *supported = ret;
return 0;
}
@@ -279,18 +191,12 @@ static int sound_get_path(feedback_pattern_e pattern, char *buf, unsigned int bu
{
char *cur_path;
int ret = 0;
- struct xmlData *data = NULL;
if (!buf || buflen <= 0)
return -EINVAL;
- cur_path = sound_file[pattern];
- if (!cur_path) {
- ret = get_xml_data(v_doc, pattern, &data);
- if (ret >= 0 && data && data->data)
- cur_path = (char*)data->data;
- }
-
+ /* get sound file path */
+ cur_path = get_data(pattern);
if (!cur_path) {
_E("This pattern(%s) in sound type is not supported to play",
profile->str_pattern[pattern]);
@@ -299,14 +205,12 @@ static int sound_get_path(feedback_pattern_e pattern, char *buf, unsigned int bu
}
snprintf(buf, buflen, "%s", cur_path);
- release_xml_data(data);
- return 0;
+ return ret;
}
static int sound_set_path(feedback_pattern_e pattern, char *path)
{
struct stat buf;
- char *ppath;
/*
* check the path is valid
@@ -317,13 +221,14 @@ static int sound_set_path(feedback_pattern_e pattern, char *path)
return -errno;
}
- ppath = sound_file[pattern];
+ if (sound_info.data[pattern].changed) {
+ free(sound_info.data[pattern].changed);
+ sound_info.data[pattern].changed = NULL;
+ }
/* if path is NULL, this pattern set to default file */
if (path)
- snprintf(ppath, NAME_MAX, "%s", path);
- else
- memset(ppath, 0, NAME_MAX);
+ sound_info.data[pattern].changed = strdup(path);
_D("The file of pattern(%s) is changed to [%s]",
profile->str_pattern[pattern], path);
diff --git a/src/vibrator.c b/src/vibrator.c
index 8aae412..f09b224 100644
--- a/src/vibrator.c
+++ b/src/vibrator.c
@@ -17,6 +17,7 @@
#include <stdio.h>
+#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <errno.h>
@@ -27,6 +28,7 @@
#include "feedback-ids.h"
#include "profiles.h"
+#include "parser.h"
#include "devices.h"
#include "log.h"
#include "dbus.h"
@@ -46,20 +48,37 @@ enum haptic_iteration
HAPTIC_ITERATION_INFINITE = 256,
};
-#define VIBRATION_XML "/usr/share/feedback/vibration.xml"
+#define VIBRATION_CONF_FILE "/usr/share/feedback/vibration.conf"
#define METHOD_OPEN "OpenDevice"
#define METHOD_CLOSE "CloseDevice"
#define METHOD_VIBRATE_MONOTONE "VibrateMonotone"
+#define METHOD_VIBRATE_BUFFER "VibrateBuffer"
#define METHOD_STOP "StopDevice"
#define DEFAULT_DURATION 100
static int vibstatus;
-
static unsigned int v_handle;
+static struct feedback_config_info vib_info = {
+ .name = "Vibration",
+};
+
+static char *get_data(feedback_pattern_e pattern)
+{
+ char *data;
-static char haptic_file[FEEDBACK_PATTERN_END][NAME_MAX];
+ if (pattern <= FEEDBACK_PATTERN_NONE ||
+ pattern >= profile->max_pattern)
+ return NULL;
+
+ if (vib_info.data[pattern].changed)
+ data = vib_info.data[pattern].changed;
+ else
+ data = vib_info.data[pattern].origin;
+
+ return data;
+}
inline int is_vibration_mode(void)
{
@@ -92,6 +111,37 @@ static int haptic_close(unsigned int handle)
"u", arr);
}
+static int haptic_vibrate_buffer(unsigned int handle,
+ const unsigned char *buffer,
+ int size,
+ int iteration,
+ int feedback,
+ int priority)
+{
+ char *arr[6];
+ char buf_handle[32];
+ char buf_iteration[32];
+ char buf_feedback[32];
+ char buf_priority[32];
+ struct dbus_byte bytes;
+
+ snprintf(buf_handle, sizeof(buf_handle), "%u", handle);
+ arr[0] = buf_handle;
+ bytes.size = size;
+ bytes.data = buffer;
+ arr[2] = (char *)&bytes;
+ snprintf(buf_iteration, sizeof(buf_iteration), "%d", iteration);
+ arr[3] = buf_iteration;
+ snprintf(buf_feedback, sizeof(buf_feedback), "%d", feedback);
+ arr[4] = buf_feedback;
+ snprintf(buf_priority, sizeof(buf_priority), "%d", priority);
+ arr[5] = buf_priority;
+
+ return dbus_method_sync(DEVICED_BUS_NAME, DEVICED_PATH_HAPTIC,
+ DEVICED_INTERFACE_HAPTIC, METHOD_VIBRATE_BUFFER,
+ "uayiii", arr);
+}
+
static int haptic_vibrate_monotone(unsigned int handle,
int duration,
int feedback,
@@ -130,6 +180,53 @@ static int haptic_vibrate_stop(unsigned int handle)
"u", arr);
}
+static unsigned char *convert_file_to_buffer(const char *file_name, int *size)
+{
+ FILE *pf;
+ long file_size;
+ unsigned char *pdata = NULL;
+
+ if (!file_name)
+ return NULL;
+
+ /* Get File Stream Pointer */
+ pf = fopen(file_name, "rb");
+ if (!pf) {
+ _E("fopen failed : %s", strerror(errno));
+ return NULL;
+ }
+
+ if (fseek(pf, 0, SEEK_END))
+ goto error;
+
+ file_size = ftell(pf);
+ if (fseek(pf, 0, SEEK_SET))
+ goto error;
+
+ if (file_size < 0)
+ goto error;
+
+ pdata = (unsigned char *)malloc(file_size);
+ if (!pdata)
+ goto error;
+
+ if (fread(pdata, 1, file_size, pf) != file_size)
+ goto err_free;
+
+ fclose(pf);
+ *size = file_size;
+ return pdata;
+
+err_free:
+ free(pdata);
+
+error:
+ fclose(pf);
+
+ _E("failed to convert file to buffer (%s)", strerror(errno));
+ return NULL;
+}
+
static int get_priority(feedback_pattern_e pattern)
{
if (pattern >= FEEDBACK_PATTERN_TAP && pattern <= FEEDBACK_PATTERN_HW_HOLD)
@@ -152,6 +249,9 @@ static void vibrator_init(void)
/* Set vibration handle */
v_handle = (unsigned int)ret;
+
+ /* get vibration data */
+ feedback_load_config(VIBRATION_CONF_FILE, &vib_info);
}
static void vibrator_exit(void)
@@ -164,10 +264,17 @@ static void vibrator_exit(void)
_E("haptic_close is failed : %d", ret);
v_handle = 0;
}
+
+ /* free vibration data */
+ feedback_free_config(&vib_info);
}
static int vibrator_play(feedback_pattern_e pattern)
{
+ struct stat buf;
+ char *data;
+ unsigned char *pbuf;
+ int size;
int ret;
int level;
@@ -203,15 +310,36 @@ static int vibrator_play(feedback_pattern_e pattern)
else
level = DEFAULT_VIB_LEVEL * HAPTIC_FEEDBACK_STEP;
- ret = haptic_vibrate_monotone(v_handle, DEFAULT_DURATION,
- level, get_priority(pattern));
+ /* get vibration data */
+ data = get_data(pattern);
+ if (!data) {
+ _E("Not supported vibration pattern");
+ return -ENOTSUP;
+ }
+
+ /* if it has a file path */
+ if (!stat(data, &buf)) {
+ pbuf = convert_file_to_buffer(data, &size);
+ if (!pbuf) {
+ _E("fail to convert file to buffer");
+ return -EPERM;
+ }
+
+ ret = haptic_vibrate_buffer(v_handle, pbuf, size,
+ HAPTIC_ITERATION_ONCE,
+ level, get_priority(pattern));
+ } else
+ ret = haptic_vibrate_monotone(v_handle, DEFAULT_DURATION,
+ level, get_priority(pattern));
+
if (ret < 0) {
- _E("haptic_vibrate_monotone is failed");
+ _E("fail to play vibration");
if (ret == -ECOMM)
return ret;
return -EPERM;
}
+ _D("Play success! Data is %s", data);
return 0;
}
@@ -243,6 +371,9 @@ static int vibrator_stop(void)
static int vibrator_is_supported(int pattern, bool *supported)
{
+ char *data;
+ bool ret = true;
+
if (!supported) {
_E("Invalid parameter : supported(NULL)");
return -EINVAL;
@@ -259,32 +390,41 @@ static int vibrator_is_supported(int pattern, bool *supported)
return 0;
}
- *supported = true;
+ /* get vibration data */
+ data = get_data(pattern);
+ if (!data) {
+ _E("Not supported vibration pattern");
+ ret = false;
+ }
+
+ *supported = ret;
return 0;
}
static int vibrator_get_path(feedback_pattern_e pattern, char *buf, unsigned int buflen)
{
- const char *cur_path;
+ char *data;
+ int ret = 0;
- assert(buf != NULL && buflen > 0);
+ if (!buf || buflen <= 0)
+ return -EINVAL;
- cur_path = haptic_file[pattern];
- if (*cur_path) {
+ /* get vibration data */
+ data = get_data(pattern);
+ if (!data) {
_E("This pattern(%s) in vibrator type is not supported to play",
profile->str_pattern[pattern]);
- snprintf(buf, buflen, "NULL");
- return -ENOENT;
+ data = "NULL";
+ ret = -ENOENT;
}
- snprintf(buf, buflen, "%s", cur_path);
- return 0;
+ snprintf(buf, buflen, "%s", data);
+ return ret;
}
static int vibrator_set_path(feedback_pattern_e pattern, char *path)
{
struct stat buf;
- char *ppath;
/*
* check the path is valid
@@ -295,13 +435,14 @@ static int vibrator_set_path(feedback_pattern_e pattern, char *path)
return -errno;
}
- ppath = haptic_file[pattern];
+ if (vib_info.data[pattern].changed) {
+ free(vib_info.data[pattern].changed);
+ vib_info.data[pattern].changed = NULL;
+ }
/* if path is NULL, this pattern set to default file */
if (path)
- snprintf(ppath, NAME_MAX, "%s", path);
- else
- memset(ppath, 0, NAME_MAX);
+ vib_info.data[pattern].changed = strdup(path);
_D("The file of pattern(%s) is changed to [%s]",
profile->str_pattern[pattern], path);
diff --git a/src/xmlparser.c b/src/xmlparser.c
deleted file mode 100644
index e2b09d2..0000000
--- a/src/xmlparser.c
+++ /dev/null
@@ -1,172 +0,0 @@
-/*
- * libfeedback
- * Copyright (c) 2012 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 <assert.h>
-#include <errno.h>
-#include <glib.h>
-
-#include "xmlparser.h"
-#include "log.h"
-
-static const char* data_str[] = {
- [XML_LABEL] = "label",
- [XML_DATA] = "data",
-};
-
-xmlDocPtr xml_open(const char *xml)
-{
- xmlDocPtr doc;
-
- doc = xmlReadFile(xml, NULL, 0);
- if (doc == NULL) {
- _E("xmlReadFile fail");
- return NULL;
- }
-
- return doc;
-}
-
-void xml_close(xmlDocPtr doc)
-{
- xmlFreeDoc(doc);
-}
-
-static int xml_compare(xmlDocPtr doc, xmlNodePtr cur, const xmlChar* expr)
-{
- xmlNodePtr node;
- xmlChar *key;
- int r;
-
- assert(doc);
- assert(cur);
- assert(expr);
-
- for (node = cur->children; node != NULL; node = node->next) {
- if (xmlStrcmp(node->name, (const xmlChar*)data_str[XML_LABEL]))
- continue;
-
- key = xmlNodeListGetString(doc, node->children, 1);
- r = xmlStrcmp(key, expr);
- xmlFree(key);
-
- if (r == 0)
- return 1;
-
- break;
- }
-
- return 0;
-}
-
-xmlNodePtr xml_find(xmlDocPtr doc, const char *label, const xmlChar* expr)
-{
- xmlNodePtr root;
- xmlNodePtr cur;
-
- assert(doc);
- assert(expr);
-
- root = xmlDocGetRootElement(doc);
- if (root == NULL) {
- _E("xmlDocGetRootElement fail");
- return NULL;
- }
-
- for (cur = root->children; cur != NULL; cur = cur->next) {
- if (xmlStrcmp(cur->name, (const xmlChar*)label))
- continue;
-
- if (!xml_compare(doc, cur, expr))
- continue;
-
- return cur;
- }
-
- return NULL;
-}
-
-struct xmlData *xml_parse(xmlDocPtr doc, xmlNodePtr cur)
-{
- xmlNodePtr node;
- struct xmlData *data;
-
- assert(doc);
- assert(cur);
-
- data = (struct xmlData*)malloc(sizeof(struct xmlData));
- if (data == NULL) {
- _E("out of memory");
- return NULL;
- }
-
- memset(data, 0, sizeof(struct xmlData));
- for (node = cur->children; node != NULL; node = node->next) {
- if (!xmlStrcmp(node->name, (const xmlChar*)data_str[XML_LABEL])) {
- data->label = (char*)xmlNodeListGetString(doc, node->children, 1);
- _D("label : %s", data->label);
- } else if (!xmlStrcmp(node->name, (const xmlChar*)data_str[XML_DATA])) {
- data->data = (char*)xmlNodeListGetString(doc, node->children, 1);
- data->size = strlen(data->data);
- }
- }
-
- return data;
-}
-
-int xml_decode_data(struct xmlData *data)
-{
- char *decode;
- gsize len;
-
- if (!data || !data->data)
- return -EINVAL;
-
- _D("b64_data : %s", data->data);
- decode = (char*)g_base64_decode(data->data, &len);
- free(data->data);
-
- data->data = decode;
- data->size = (unsigned int)len;
- return 0;
-}
-
-int xml_save(xmlDocPtr doc, const char *path)
-{
- int r;
-
- assert(doc);
- assert(path);
-
- r = xmlSaveFile(path, doc);
- if (r < 0) {
- _E("xmlSaveFile fail");
- return -1;
- }
-
- return 0;
-}
-
-void xml_free(struct xmlData* data)
-{
- assert(data);
-
- free(data->label);
- free(data->data);
- free(data);
-}
diff --git a/src/xmlparser.h b/src/xmlparser.h
deleted file mode 100644
index 0c38672..0000000
--- a/src/xmlparser.h
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * libfeedback
- * Copyright (c) 2012 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 __XMLPARSER_H__
-#define __XMLPARSER_H__
-
-#include <libxml/parser.h>
-
-struct xmlData {
- char *label;
- char *data;
- int size;
-};
-
-enum xmlType {
- XML_LABEL = 0,
- XML_DATA,
-};
-
-#define VIBRATION_STR "vibration"
-#define SOUND_STR "sound"
-
-xmlDocPtr xml_open(const char *xml);
-void xml_close(xmlDocPtr doc);
-
-xmlNodePtr xml_find(xmlDocPtr doc, const char *label, const xmlChar* expr);
-struct xmlData *xml_parse(xmlDocPtr doc, xmlNodePtr cur);
-int xml_decode_data(struct xmlData *data);
-int xml_save(xmlDocPtr doc, const char *path);
-void xml_free(struct xmlData* data);
-
-#endif //__XMLPARSER_H__