From 4b3066240ea114924d9c62464d76096ecbee2ef8 Mon Sep 17 00:00:00 2001 From: "pr.jung" Date: Mon, 14 Jan 2019 16:45:07 +0900 Subject: [PATCH 01/16] Delete unused dbus methods - Delete "SaveBinary" - Delete "CreateEffect" Change-Id: I72674cb67ad7dd8cb5b8dd4beec36a2f805e4884 Signed-off-by: pr.jung --- src/haptic/circle.c | 28 --------- src/haptic/emulator.c | 41 ------------- src/haptic/gpio_haptic.c | 28 --------- src/haptic/haptic-plugin-intf.h | 4 -- src/haptic/haptic.c | 124 ------------------------------------- src/haptic/standard-vibcore.c | 2 +- src/haptic/standard.c | 132 ---------------------------------------- 7 files changed, 1 insertion(+), 358 deletions(-) diff --git a/src/haptic/circle.c b/src/haptic/circle.c index aa1b7a5..30d3d0d 100644 --- a/src/haptic/circle.c +++ b/src/haptic/circle.c @@ -222,12 +222,6 @@ static int vibrate_monotone(int device_handle, int duration, int feedback, int p return 0; } -static int vibrate_buffer(int device_handle, const unsigned char *vibe_buffer, int iteration, int feedback, int priority, int *effect_handle) -{ - _E("Not support feature"); - return -EACCES; -} - static int stop_device(int device_handle) { int ret; @@ -272,24 +266,6 @@ static int get_device_state(int device_index, int *effect_state) *effect_state = state; return 0; } - -static int create_effect(unsigned char *vibe_buffer, int max_bufsize, const haptic_module_effect_element *elem_arr, int max_elemcnt) -{ - _E("Not support feature"); - return -EACCES; -} - -static int get_buffer_duration(int device_handle, const unsigned char *vibe_buffer, int *buffer_duration) -{ - _E("Not support feature"); - return -EACCES; -} - -static int convert_binary(const unsigned char *vibe_buffer, int max_bufsize, const char *file_path) -{ - _E("Not support feature"); - return -EACCES; -} /* END: Haptic Module APIs */ static const struct haptic_plugin_ops default_plugin = { @@ -297,14 +273,10 @@ static const struct haptic_plugin_ops default_plugin = { .open_device = open_device, .close_device = close_device, .vibrate_monotone = vibrate_monotone, - .vibrate_buffer = vibrate_buffer, .vibrate_effect = standard_vibrate_effect, .is_supported = standard_is_supported, .stop_device = stop_device, .get_device_state = get_device_state, - .create_effect = create_effect, - .get_buffer_duration = get_buffer_duration, - .convert_binary = convert_binary, }; static bool is_valid(void) diff --git a/src/haptic/emulator.c b/src/haptic/emulator.c index 4548952..fdcc2e2 100644 --- a/src/haptic/emulator.c +++ b/src/haptic/emulator.c @@ -83,20 +83,6 @@ static int vibrate_monotone(int device_handle, int duration, int feedback, int p return 0; } -static int vibrate_buffer(int device_handle, const unsigned char *vibe_buffer, int iteration, int feedback, int priority, int *effect_handle) -{ - dd_list *elem; - - elem = DD_LIST_FIND(handle_list, (gpointer)(long)device_handle); - if (!elem) - return -EINVAL; - - if (effect_handle) - *effect_handle = DEFAULT_EFFECT_HANDLE; - - return 0; -} - static int vibrate_effect(int device_handle, const char *pattern, int feedback, int priority) { dd_list *elem; @@ -132,29 +118,6 @@ static int get_device_state(int device_index, int *effect_state) return 0; } -static int create_effect(unsigned char *vibe_buffer, int max_bufsize, const haptic_module_effect_element *elem_arr, int max_elemcnt) -{ - _E("Not support feature"); - return -EACCES; -} - -static int get_buffer_duration(int device_handle, const unsigned char *vibe_buffer, int *buffer_duration) -{ - dd_list *elem; - - elem = DD_LIST_FIND(handle_list, (gpointer)(long)device_handle); - if (!elem) - return -EINVAL; - - _E("Not support feature"); - return -EACCES; -} - -static int convert_binary(const unsigned char *vibe_buffer, int max_bufsize, const char *file_path) -{ - _E("Not support feature"); - return -EACCES; -} /* END: Haptic Module APIs */ static const struct haptic_plugin_ops default_plugin = { @@ -162,14 +125,10 @@ static const struct haptic_plugin_ops default_plugin = { .open_device = open_device, .close_device = close_device, .vibrate_monotone = vibrate_monotone, - .vibrate_buffer = vibrate_buffer, .vibrate_effect = vibrate_effect, .is_supported = is_supported, .stop_device = stop_device, .get_device_state = get_device_state, - .create_effect = create_effect, - .get_buffer_duration = get_buffer_duration, - .convert_binary = convert_binary, }; static bool is_valid(void) diff --git a/src/haptic/gpio_haptic.c b/src/haptic/gpio_haptic.c index c495d6c..da213a3 100644 --- a/src/haptic/gpio_haptic.c +++ b/src/haptic/gpio_haptic.c @@ -292,30 +292,6 @@ static int gpio_haptic_get_device_state(int index, int *effect_state) *effect_state = state; return 0; } - -static int gpio_haptic_vibrate_buffer(int handle, const unsigned char *vibe_buffer, int iteration, int feedback, int priority, int *effect_handle) -{ - _E("Not support feature"); - return -EACCES; -} - -static int gpio_haptic_create_effect(unsigned char *vibe_buffer, int max_bufsize, const haptic_module_effect_element *elem_arr, int max_elemcnt) -{ - _E("Not support feature"); - return -EACCES; -} - -static int gpio_haptic_get_buffer_duration(int handle, const unsigned char *vibe_buffer, int *buffer_duration) -{ - _E("Not support feature"); - return -EACCES; -} - -static int gpio_haptic_convert_binary(const unsigned char *vibe_buffer, int max_bufsize, const char *file_path) -{ - _E("Not support feature"); - return -EACCES; -} /* END: Haptic Module APIs */ static const struct haptic_plugin_ops default_plugin = { @@ -323,14 +299,10 @@ static const struct haptic_plugin_ops default_plugin = { .open_device = gpio_haptic_open_device, .close_device = gpio_haptic_close_device, .vibrate_monotone = gpio_haptic_vibrate_monotone, - .vibrate_buffer = gpio_haptic_vibrate_buffer, .vibrate_effect = standard_vibrate_effect, .is_supported = standard_is_supported, .stop_device = gpio_haptic_stop_device, .get_device_state = gpio_haptic_get_device_state, - .create_effect = gpio_haptic_create_effect, - .get_buffer_duration = gpio_haptic_get_buffer_duration, - .convert_binary = gpio_haptic_convert_binary, }; static bool is_valid(void) diff --git a/src/haptic/haptic-plugin-intf.h b/src/haptic/haptic-plugin-intf.h index 3565d71..f3d0e11 100644 --- a/src/haptic/haptic-plugin-intf.h +++ b/src/haptic/haptic-plugin-intf.h @@ -27,14 +27,10 @@ struct haptic_plugin_ops { int (*open_device) (int, int*); int (*close_device) (int); int (*vibrate_monotone) (int, int, int, int, int*); - int (*vibrate_buffer) (int, const unsigned char*, int, int, int, int*); int (*vibrate_effect) (int, const char*, int, int); int (*is_supported) (const char*); int (*stop_device) (int); int (*get_device_state) (int, int*); - int (*create_effect) (unsigned char*, int, const haptic_module_effect_element*, int); - int (*get_buffer_duration) (int, const unsigned char*, int*); - int (*convert_binary) (const unsigned char*, int, const char*); }; const struct haptic_plugin_ops *get_haptic_plugin_interface(); diff --git a/src/haptic/haptic.c b/src/haptic/haptic.c index 30cbaeb..148d63f 100644 --- a/src/haptic/haptic.c +++ b/src/haptic/haptic.c @@ -373,41 +373,6 @@ exit: return g_variant_new("(i)", ret); } -GVariant *hdbus_vibrate_buffer(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - unsigned int handle; - const unsigned char *data = NULL; - GVariant *pvar = NULL; - gsize size = 0; - int iteration, level, priority, e_handle, ret = 0; - - if (!CHECK_VALID_OPS(h_ops, ret)) - goto exit; - - if (haptic_disabled) - goto exit; - - g_variant_get(param, "(u@ayiii)", &handle, &pvar, &iteration, &level, &priority); - data = g_variant_get_fixed_array(pvar, &size, sizeof(char)); - g_variant_unref(pvar); - - /* convert as per conf value */ - level = convert_magnitude_by_conf(level); - if (level < 0) { - ret = -EINVAL; - goto exit; - } - - ret = h_ops->vibrate_buffer(handle, data, iteration, level, priority, &e_handle); - if (ret >= 0) - ret = e_handle; - -exit: - return g_variant_new("(i)", ret); -} - static void vibrate_effect_idler_cb(void *data) { struct vibrate_effect_info *vibrate_info = (struct vibrate_effect_info *)data; @@ -511,91 +476,6 @@ exit: return g_variant_new("(i)", ret); } -GVariant *hdbus_create_effect(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - static unsigned char data[MAX_EFFECT_BUFFER]; - //static unsigned char *p = data; - const haptic_module_effect_element *elem_arr; - int i, cnt, ret, bufsize = sizeof(data); - GVariant *pvar = NULL; - gsize size = 0; - - if (!CHECK_VALID_OPS(h_ops, ret)) - goto exit; - - g_variant_get(param, "(i@ayi)", &bufsize, &pvar, &cnt); - elem_arr = g_variant_get_fixed_array(pvar, &size, sizeof(char)); - g_variant_unref(pvar); - - if (bufsize > MAX_EFFECT_BUFFER) { - ret = -ENOMEM; - goto exit; - } - - for (i = 0; i < cnt; ++i) - _D("[%2d] %d %d", i, elem_arr[i].haptic_duration, elem_arr[i].haptic_level); - - memset(data, 0, MAX_EFFECT_BUFFER); - ret = h_ops->create_effect(data, bufsize, elem_arr, cnt); - -exit: - pvar = g_variant_new_fixed_array(G_VARIANT_TYPE_BYTE, data, sizeof(data), sizeof(char)); - return g_variant_new("(@ayi)", pvar, ret); -} - -GVariant *hdbus_get_duration(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - unsigned int handle; - const unsigned char *data; - int duration, ret; - GVariant *pvar = NULL; - gsize size = 0; - - if (!CHECK_VALID_OPS(h_ops, ret)) - goto exit; - - g_variant_get(param, "(u@ay)", &handle, &pvar); - data = g_variant_get_fixed_array(pvar, &size, sizeof(char)); - g_variant_unref(pvar); - - ret = h_ops->get_buffer_duration(handle, data, &duration); - if (ret >= 0) - ret = duration; - -exit: - return g_variant_new("(i)", ret); -} - -GVariant *hdbus_save_binary(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) - -{ - const unsigned char *data = NULL; - char *file_path = NULL; - int ret; - GVariant *pvar; - gsize size = 0; - - if (!CHECK_VALID_OPS(h_ops, ret)) - goto exit; - - g_variant_get(param, "(@ays)", &pvar, &file_path); - data = g_variant_get_fixed_array(pvar, &size, sizeof(char)); - g_variant_unref(pvar); - - _D("file path : %s", file_path); - ret = h_ops->convert_binary(data, size, file_path); - -exit: - g_free(file_path); - return g_variant_new("(i)", ret); -} - GVariant *hdbus_show_handle_list(GDBusConnection *conn, const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) @@ -825,12 +705,8 @@ static const dbus_method_s hdbus_methods[] = { { "CloseDevice", "u", "i", hdbus_close_device }, { "StopDevice", "u", "i", hdbus_stop_device }, { "VibrateMonotone", "uiii", "i", hdbus_vibrate_monotone }, - { "VibrateBuffer", "uayiii", "i", hdbus_vibrate_buffer }, { "VibrateEffect", "usii", "i", hdbus_vibrate_effect }, { "GetState", "i", "i", hdbus_get_state }, - { "GetDuration", "uay", "i", hdbus_get_duration }, - { "CreateEffect", "iayi", "ayi", hdbus_create_effect }, - { "SaveBinary", "ays", "i", hdbus_save_binary }, { "ShowHandleList", NULL, NULL, hdbus_show_handle_list }, { "IsSupported", "s", "i", hdbus_pattern_is_supported }, /* Add methods here */ diff --git a/src/haptic/standard-vibcore.c b/src/haptic/standard-vibcore.c index 09ae445..3f4d851 100644 --- a/src/haptic/standard-vibcore.c +++ b/src/haptic/standard-vibcore.c @@ -159,7 +159,7 @@ static int get_config_data(int count, bool *packed, char *val, unsigned int *pat } if (!packed || !val || !pattern_duration || !update) { - _E("Invalid paramger"); + _E("Invalid parameter: %p %p %p %p", packed, val, pattern_duration, update); return -EINVAL; } diff --git a/src/haptic/standard.c b/src/haptic/standard.c index d43f965..c73840f 100644 --- a/src/haptic/standard.c +++ b/src/haptic/standard.c @@ -455,116 +455,6 @@ static int vibrate_monotone(int device_handle, int duration, int feedback, int p return 0; } -static gboolean _buffer_play(void *cbdata) -{ - struct ff_info *info = (struct ff_info *)cbdata; - struct ff_info_header *header = &info->ffinfobuffer->header; - struct ff_info_data *data = info->ffinfobuffer->data; - int index = info->currentindex; - int play_type = (index < header->ff_info_data_count) ? data[index].type : 0; - int length = (index < header->ff_info_data_count) ? data[index].length : 1; - int ret; - - ff_set_effect(&info->effect, length, 1); - if (play_type != 0) { - _D("Going to play for %d ms", length); - ret = ff_play(ff_fd, &info->effect); - if (ret < 0) - _D("Failed to play the effect %d", ret); - } else { - _D("Going to stop for %d ms", length); - ret = ff_stop(ff_fd, &info->effect); - if (ret < 0) - _D("Failed to stop the effect %d", ret); - } - - if (info->currentindex < header->ff_info_data_count) { - info->currentindex++; - info->timer = g_timeout_add(length, _buffer_play, info); - } else { - --header->iteration; - if (header->iteration > 0) { - info->currentindex = 0; - info->timer = g_timeout_add(0, _buffer_play, info); - } else - info->timer = 0; - } - - return G_SOURCE_REMOVE; -} - -static void print_buffer(const unsigned char *vibe_buffer) -{ - struct ff_info_buffer fb; - int i = 0; - memcpy(&fb.header, vibe_buffer, sizeof(struct ff_info_header)); - memcpy(&fb.data, (unsigned char *)vibe_buffer+sizeof(struct ff_info_header), - sizeof(struct ff_info_data) * fb.header.ff_info_data_count); - _D("\nMagic %x\niteration %d\ncount %d\n", fb.header.magic, - fb.header.iteration, fb.header.ff_info_data_count); - - for (i = 0; i < fb.header.ff_info_data_count; i++) - _D("type %d\nmagn 0x%x\nlen %d\n", fb.data[i].type, - fb.data[i].magnitude, fb.data[i].length); -} - -static int vibrate_custom_buffer(int device_handle, const unsigned char *vibe_buffer, int iteration, int feedback, int priority, int *effect_handle) -{ - struct ff_info *info; - struct ff_info_header *header; - struct ff_info_data *data; - - info = read_from_list(device_handle); - if (!info) - return -EINVAL; - - if (!check_valid_handle(info)) - return -EINVAL; - - if (!check_fd(&ff_fd)) - return -ENODEV; - - if (!info->ffinfobuffer) - info->ffinfobuffer = (struct ff_info_buffer *)calloc(sizeof(struct ff_info_buffer), 1); - if (!info->ffinfobuffer) - return -ENOMEM; - - header = &info->ffinfobuffer->header; - data = info->ffinfobuffer->data; - - memcpy(header, vibe_buffer, sizeof(struct ff_info_header)); - if (header->ff_info_data_count < 0 || header->ff_info_data_count > MAX_DATA) - return -EINVAL; - - memcpy(data, vibe_buffer+sizeof(struct ff_info_header), sizeof(struct ff_info_data) * header->ff_info_data_count); - - info->currentindex = 0; - if (info->timer) - g_source_remove(info->timer); - - if (header->iteration > 0) - _buffer_play(info); - - return 0; -} - -static int vibrate_buffer(int device_handle, const unsigned char *vibe_buffer, int iteration, int feedback, int priority, int *effect_handle) -{ - int magic = 0; - - if (!device_handle) - return -EINVAL; - - if (vibe_buffer) - magic = *(int *)vibe_buffer; - - if (magic == FF_INFO_MAGIC) { - print_buffer(vibe_buffer); - return vibrate_custom_buffer(device_handle, vibe_buffer, iteration, feedback, priority, effect_handle); - } else - return vibrate_monotone(device_handle, 300, feedback, priority, effect_handle); -} - static int stop_device(int device_handle) { struct ff_info *info; @@ -624,24 +514,6 @@ static int get_device_state(int device_index, int *effect_state) *effect_state = status; return 0; } - -static int create_effect(unsigned char *vibe_buffer, int max_bufsize, const haptic_module_effect_element *elem_arr, int max_elemcnt) -{ - _E("Not support feature"); - return -EACCES; -} - -static int get_buffer_duration(int device_handle, const unsigned char *vibe_buffer, int *buffer_duration) -{ - _E("Not support feature"); - return -EACCES; -} - -static int convert_binary(const unsigned char *vibe_buffer, int max_bufsize, const char *file_path) -{ - _E("Not support feature"); - return -EACCES; -} /* END: Haptic Module APIs */ static const struct haptic_plugin_ops default_plugin = { @@ -649,14 +521,10 @@ static const struct haptic_plugin_ops default_plugin = { .open_device = open_device, .close_device = close_device, .vibrate_monotone = vibrate_monotone, - .vibrate_buffer = vibrate_buffer, .vibrate_effect = standard_vibrate_effect, .is_supported = standard_is_supported, .stop_device = stop_device, .get_device_state = get_device_state, - .create_effect = create_effect, - .get_buffer_duration = get_buffer_duration, - .convert_binary = convert_binary, }; static bool is_valid(void) -- 2.7.4 From 879053e9b3e1b4b2bf571811fe8deb8ebcb7edf5 Mon Sep 17 00:00:00 2001 From: "pr.jung" Date: Mon, 14 Jan 2019 17:37:24 +0900 Subject: [PATCH 02/16] Vibrate when poweroff_type is POWER_OFF_DIRECT or POWER_OFF_RESTART Change-Id: Ia7f222768ffc6c3413a00f90e4d40e3302802450 Signed-off-by: pr.jung --- src/haptic/haptic.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/src/haptic/haptic.c b/src/haptic/haptic.c index 148d63f..4a60b85 100644 --- a/src/haptic/haptic.c +++ b/src/haptic/haptic.c @@ -41,7 +41,6 @@ /* hardkey vibration variable */ #define HARDKEY_VIB_ITERATION 1 #define HARDKEY_VIB_FEEDBACK 3 -#define HARDKEY_VIB_PRIORITY 2 #define HARDKEY_VIB_DURATION 30 #define HAPTIC_FEEDBACK_STEP 20 #define DEFAULT_FEEDBACK_LEVEL 3 @@ -63,6 +62,13 @@ #define CHECK_VALID_OPS(ops, r) ((ops) ? true : !(r = -ENODEV)) #define RETRY_CNT 3 +enum poweroff_type { + POWER_OFF_NONE = 0, + POWER_OFF_POPUP, + POWER_OFF_DIRECT, + POWER_OFF_RESTART, +}; + struct haptic_info { char *sender; dd_list *handle_list; @@ -573,7 +579,7 @@ static void haptic_hardkey_changed_cb(GDBusConnection *conn, } ret = h_ops->vibrate_monotone(g_handle, HARDKEY_VIB_DURATION, - level*HAPTIC_FEEDBACK_STEP, HARDKEY_VIB_PRIORITY, &e_handle); + level*HAPTIC_FEEDBACK_STEP, PRIORITY_HIGH, &e_handle); if (ret < 0) _E("fail to vibrate buffer : %d", ret); @@ -588,9 +594,17 @@ static void haptic_poweroff_cb(GDBusConnection *conn, GVariant *param, gpointer data) { + int type = POWER_OFF_NONE; int e_handle, ret; struct timespec time = {0,}; + g_variant_get(param, "(i)", &type); + + if (type != POWER_OFF_DIRECT && type != POWER_OFF_RESTART) + return; + + _D("Poweroff: %d", type); + if (!CHECK_VALID_OPS(h_ops, ret)) { ret = haptic_module_load(); if (ret < 0) @@ -601,8 +615,10 @@ static void haptic_poweroff_cb(GDBusConnection *conn, haptic_internal_init(); /* power off vibration */ + _I("Handle %d dur %dms pri %d level %d", + g_handle, POWER_OFF_VIB_DURATION, PRIORITY_HIGH, POWER_VIB_FEEDBACK); ret = h_ops->vibrate_monotone(g_handle, POWER_OFF_VIB_DURATION, - POWER_VIB_FEEDBACK, HARDKEY_VIB_PRIORITY, &e_handle); + POWER_VIB_FEEDBACK, PRIORITY_HIGH, &e_handle); if (ret < 0) { _E("fail to vibrate_monotone : %d", ret); return; -- 2.7.4 From 2ac7e22abdf003279401415233c4b3af6598d003 Mon Sep 17 00:00:00 2001 From: "pr.jung" Date: Wed, 16 Jan 2019 15:30:24 +0900 Subject: [PATCH 03/16] Use idler callback for VibrateMonotone - Return immdiately after parameters checked Change-Id: I21b37f0eeb7c7a99454039a8004a97724c064c43 Signed-off-by: pr.jung --- src/haptic/circle.c | 6 +-- src/haptic/emulator.c | 7 +-- src/haptic/external.c | 6 ++- src/haptic/gpio_haptic.c | 5 +- src/haptic/haptic-plugin-intf.h | 2 +- src/haptic/haptic.c | 61 ++++++++++++++++++++---- src/haptic/haptic.h | 1 + src/haptic/standard-vibcore.c | 3 +- src/haptic/standard-vibcore.h | 2 +- src/haptic/standard.c | 102 +++++++++++++++++++++++++--------------- 10 files changed, 128 insertions(+), 67 deletions(-) diff --git a/src/haptic/circle.c b/src/haptic/circle.c index 30d3d0d..f17007a 100644 --- a/src/haptic/circle.c +++ b/src/haptic/circle.c @@ -177,7 +177,7 @@ static int close_device(int device_handle) return 0; } -static int vibrate_monotone(int device_handle, int duration, int feedback, int priority, int *effect_handle) +static int vibrate_monotone(int device_handle, int duration, int feedback, int priority) { int ret; char buf[BUF_SIZE]; @@ -212,12 +212,10 @@ static int vibrate_monotone(int device_handle, int duration, int feedback, int p stop_timer = g_timeout_add(duration, timer_cb, (void *)(long)device_handle); if (!stop_timer) - _E("Failed to add timer callback"); + _E("Handle %d Failed to add timer callback", device_handle); } _D("device handle %d %dms", device_handle, duration); - if (effect_handle) - *effect_handle = device_handle; return 0; } diff --git a/src/haptic/emulator.c b/src/haptic/emulator.c index fdcc2e2..326444c 100644 --- a/src/haptic/emulator.c +++ b/src/haptic/emulator.c @@ -24,8 +24,6 @@ #include "core/list.h" #include "haptic.h" -#define DEFAULT_EFFECT_HANDLE 0xFFFA - static dd_list *handle_list; static int unique_number = 0; @@ -69,7 +67,7 @@ static int close_device(int device_handle) return 0; } -static int vibrate_monotone(int device_handle, int duration, int feedback, int priority, int *effect_handle) +static int vibrate_monotone(int device_handle, int duration, int feedback, int priority) { dd_list *elem; @@ -77,9 +75,6 @@ static int vibrate_monotone(int device_handle, int duration, int feedback, int p if (!elem) return -EINVAL; - if (effect_handle) - *effect_handle = DEFAULT_EFFECT_HANDLE; - return 0; } diff --git a/src/haptic/external.c b/src/haptic/external.c index 32eb6b3..3e4b4e0 100644 --- a/src/haptic/external.c +++ b/src/haptic/external.c @@ -36,10 +36,12 @@ static const struct haptic_plugin_ops *plugin_intf; static bool is_valid(void) { struct stat buf; + int ret; const struct haptic_plugin_ops *(*get_haptic_plugin_interface) () = NULL; - if (stat(HAPTIC_MODULE_PATH, &buf)) { - _E("file(%s) is not presents", HAPTIC_MODULE_PATH); + ret = stat(HAPTIC_MODULE_PATH, &buf); + if (ret < 0) { + _E("stat file(%s) error : %d", HAPTIC_MODULE_PATH, errno); goto error; } diff --git a/src/haptic/gpio_haptic.c b/src/haptic/gpio_haptic.c index da213a3..8b7ff7b 100644 --- a/src/haptic/gpio_haptic.c +++ b/src/haptic/gpio_haptic.c @@ -206,7 +206,7 @@ static int gpio_haptic_close_device(int handle) return 0; } -static int gpio_haptic_vibrate_monotone(int handle, int duration, int level, int priority, int *e_handle) +static int gpio_haptic_vibrate_monotone(int handle, int duration, int level, int priority) { bool found; @@ -243,9 +243,6 @@ static int gpio_haptic_vibrate_monotone(int handle, int duration, int level, int } _D("device handle %d %dms", handle, duration); - if (e_handle) - *e_handle = handle; - return 0; } diff --git a/src/haptic/haptic-plugin-intf.h b/src/haptic/haptic-plugin-intf.h index f3d0e11..cd6c6bf 100644 --- a/src/haptic/haptic-plugin-intf.h +++ b/src/haptic/haptic-plugin-intf.h @@ -26,7 +26,7 @@ struct haptic_plugin_ops { int (*get_device_count) (int*); int (*open_device) (int, int*); int (*close_device) (int); - int (*vibrate_monotone) (int, int, int, int, int*); + int (*vibrate_monotone) (int, int, int, int); int (*vibrate_effect) (int, const char*, int, int); int (*is_supported) (const char*); int (*stop_device) (int); diff --git a/src/haptic/haptic.c b/src/haptic/haptic.c index 4a60b85..b01cd96 100644 --- a/src/haptic/haptic.c +++ b/src/haptic/haptic.c @@ -82,6 +82,13 @@ struct vibrate_effect_info { int priority; }; +struct vibrate_monotone_info { + unsigned int handle; + int duration; + int level; + int priority; +}; + /* for playing */ static int g_handle; @@ -219,6 +226,11 @@ static struct haptic_info *add_haptic_info(const char *sender) return NULL; info->sender = strdup(sender); + if (!info->sender) { + free(info); + return NULL; + } + DD_LIST_APPEND(haptic_handle_list, info); info->id_watch = dbus_handle_watch_name(sender, NULL, haptic_name_owner_changed, info, NULL); @@ -344,12 +356,26 @@ exit: return g_variant_new("(i)", ret); } +static void vibrate_monotone_idler_cb(void *data) +{ + struct vibrate_monotone_info *vibrate_info = (struct vibrate_monotone_info *)data; + int ret; + + ret = device_power_request_lock(POWER_LOCK_CPU, vibrate_info->duration); + if (ret != DEVICE_ERROR_NONE) + _E("Failed to request power lock"); + h_ops->vibrate_monotone(vibrate_info->handle, vibrate_info->duration, + vibrate_info->level, vibrate_info->priority); + free(vibrate_info); +} + GVariant *hdbus_vibrate_monotone(GDBusConnection *conn, const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) { + struct vibrate_monotone_info *vibrate_info; unsigned int handle; - int duration, level, priority, e_handle, ret = 0; + int duration, level, priority, ret = 0; if (!CHECK_VALID_OPS(h_ops, ret)) goto exit; @@ -371,10 +397,25 @@ GVariant *hdbus_vibrate_monotone(GDBusConnection *conn, else if (priority > PRIORITY_TOP) priority = PRIORITY_TOP; - ret = h_ops->vibrate_monotone(handle, duration, level, priority, &e_handle); - if (ret >= 0) - ret = e_handle; + if (duration <= 0) { + _E("Skip vibrate handle %d requested less than 0", handle); + ret = -EINVAL; + goto exit; + } + + vibrate_info = calloc(1, sizeof(struct vibrate_monotone_info)); + if (!vibrate_info) { + _E("failed to allocate memory for vibrate_info"); + ret = -errno; + goto exit; + } + + vibrate_info->handle = handle; + vibrate_info->duration = duration; + vibrate_info->level = level; + vibrate_info->priority = priority; + ret = add_idle_request(vibrate_monotone_idler_cb, (void *)vibrate_info); exit: return g_variant_new("(i)", ret); } @@ -452,8 +493,10 @@ GVariant *hdbus_stop_device(GDBusConnection *conn, if (!CHECK_VALID_OPS(h_ops, ret)) goto exit; - if (haptic_disabled) + if (haptic_disabled) { + _I("Haptic disabled"); goto exit; + } g_variant_get(param, "(u)", &handle); @@ -548,7 +591,7 @@ static void haptic_hardkey_changed_cb(GDBusConnection *conn, GVariant *param, gpointer data) { - int level, status, e_handle, ret; + int level, status, ret; if (!CHECK_VALID_OPS(h_ops, ret)) { ret = haptic_module_load(); @@ -579,7 +622,7 @@ static void haptic_hardkey_changed_cb(GDBusConnection *conn, } ret = h_ops->vibrate_monotone(g_handle, HARDKEY_VIB_DURATION, - level*HAPTIC_FEEDBACK_STEP, PRIORITY_HIGH, &e_handle); + level*HAPTIC_FEEDBACK_STEP, PRIORITY_HIGH); if (ret < 0) _E("fail to vibrate buffer : %d", ret); @@ -595,7 +638,7 @@ static void haptic_poweroff_cb(GDBusConnection *conn, gpointer data) { int type = POWER_OFF_NONE; - int e_handle, ret; + int ret; struct timespec time = {0,}; g_variant_get(param, "(i)", &type); @@ -618,7 +661,7 @@ static void haptic_poweroff_cb(GDBusConnection *conn, _I("Handle %d dur %dms pri %d level %d", g_handle, POWER_OFF_VIB_DURATION, PRIORITY_HIGH, POWER_VIB_FEEDBACK); ret = h_ops->vibrate_monotone(g_handle, POWER_OFF_VIB_DURATION, - POWER_VIB_FEEDBACK, PRIORITY_HIGH, &e_handle); + POWER_VIB_FEEDBACK, PRIORITY_HIGH); if (ret < 0) { _E("fail to vibrate_monotone : %d", ret); return; diff --git a/src/haptic/haptic.h b/src/haptic/haptic.h index 7951d4b..c77d64c 100644 --- a/src/haptic/haptic.h +++ b/src/haptic/haptic.h @@ -20,6 +20,7 @@ #ifndef __FEEDBACKD_HAPTIC_H__ #define __FEEDBACKD_HAPTIC_H__ +#include #include #include "core/common.h" #include "core/list.h" diff --git a/src/haptic/standard-vibcore.c b/src/haptic/standard-vibcore.c index 3f4d851..3e7d0d1 100644 --- a/src/haptic/standard-vibcore.c +++ b/src/haptic/standard-vibcore.c @@ -21,7 +21,6 @@ #include #include #include -#include #include "core/log.h" #include "core/list.h" @@ -479,7 +478,7 @@ static gboolean haptic_duration_play(void *data) duration_timer = g_timeout_add((node->duration + node->wait), haptic_duration_play, (void *)next); - ret = real_vibrate_monotone(cur_h_data.handle, node->duration, level, cur_h_data.priority, NULL); + ret = real_vibrate_monotone(cur_h_data.handle, node->duration, level, cur_h_data.priority); break; } diff --git a/src/haptic/standard-vibcore.h b/src/haptic/standard-vibcore.h index 0d4f254..5f731ba 100644 --- a/src/haptic/standard-vibcore.h +++ b/src/haptic/standard-vibcore.h @@ -20,7 +20,7 @@ #ifndef __FEEDBACKD_STANDARD_VIBCORE_H__ #define __FEEDBACKD_STANDARD_VIBCORE_H__ -typedef int (*t_vibrate_monotone)(int device_handle, int duration, int feedback, int priority, int *effect_handle); +typedef int (*t_vibrate_monotone)(int device_handle, int duration, int feedback, int priority); void standard_config_parse(void); int standard_is_supported(const char *pattern); diff --git a/src/haptic/standard.c b/src/haptic/standard.c index c73840f..4831c06 100644 --- a/src/haptic/standard.c +++ b/src/haptic/standard.c @@ -119,21 +119,25 @@ static bool check_fd(int *fd) return true; } -static int ff_stop(int fd, struct ff_effect *effect); +static int ff_stop(const char *func, int fd, struct ff_effect *effect); static gboolean timer_cb(void *data) { struct ff_info *info = (struct ff_info *)data; - if (!info) + if (!info) { + _E("Failed to check info"); return G_SOURCE_REMOVE; + } - if (!check_valid_handle(info)) + if (!check_valid_handle(info)) { + _E("Failed to check valied info"); return G_SOURCE_REMOVE; + } _I("stop vibration by timer : id(%d)", info->effect.id); /* stop previous vibration */ - ff_stop(ff_fd, &info->effect); + ff_stop(__func__, ff_fd, &info->effect); /* reset timer */ info->timer = 0; @@ -165,8 +169,10 @@ static int ff_find_device(void) snprintf(ev_path, sizeof(ev_path), "%s/%s", DEV_INPUT, dent->d_name); fd = open(ev_path, O_RDWR); - if (fd < 0) + if (fd < 0) { + _E("Failed to open %s(%d)", ev_path, errno); continue; + } /* get force feedback device */ memset(features, 0, sizeof(features)); @@ -236,22 +242,22 @@ static int ff_set_effect(struct ff_effect *effect, int length, int level) return 0; } -static int ff_play(int fd, struct ff_effect *effect) +static int ff_play(const char *func, int fd, struct ff_effect *effect) { struct input_event play; int ret; if (fd < 0 || !effect) { if (fd < 0) - _E("fail to check fd"); + _E("%s: failed to check fd", func); else - _E("fail to check effect"); + _E("%s: failed to check effect", func); return -EINVAL; } /* upload an effect */ if (ioctl(fd, EVIOCSFF, effect) == -1) { - _E("fail to ioctl"); + _E("%s: failed to ioctl", func); return -errno; } @@ -262,19 +268,19 @@ static int ff_play(int fd, struct ff_effect *effect) ret = write(fd, (const void *)&play, sizeof(play)); if (ret == -1) { - _E("fail to write"); + _E("%s: failed to write", func); return -errno; } return 0; } -static int ff_stop(int fd, struct ff_effect *effect) +static int ff_stop(const char *func, int fd, struct ff_effect *effect) { struct input_event stop; int ret; - if (fd < 0) + if (fd < 0 || !effect) return -EINVAL; /* Stop vibration */ @@ -363,14 +369,20 @@ static int close_device(int device_handle) int n; info = read_from_list(device_handle); - if (!info) - return -EINVAL; + if (!info) { + _E("Handle %d failed to check info", device_handle); + return -ENOENT; /* 2 */ + } - if (!check_valid_handle(info)) - return -EINVAL; + if (!check_valid_handle(info)) { + _E("Handle %d failed to check valid handle", device_handle); + return -EINVAL; /* 22 */ + } - if (!check_fd(&ff_fd)) - return -ENODEV; + if (!check_fd(&ff_fd)) { + _E("Handle %d failed to check fd", device_handle); + return -ENODEV; /* 19 */ + } /* stop vibration */ stop_device(device_handle); @@ -394,32 +406,42 @@ static int close_device(int device_handle) return 0; } -static int vibrate_monotone(int device_handle, int duration, int feedback, int priority, int *effect_handle) +static int vibrate_monotone(int device_handle, int duration, int feedback, int priority) { struct ff_info *info; int ret; + if (priority < cur_h_data.priority) { + _I("Handle %d skip low priority(pre:%d now:%d)", device_handle, cur_h_data.priority, priority); + return 0; + } + info = read_from_list(device_handle); if (!info) { - _E("fail to check list"); + _E("Handle %d failed to check list", device_handle); return -EINVAL; } if (!check_valid_handle(info)) { - _E("fail to check handle"); + _E("Handle %d failed to check handle", device_handle); return -EINVAL; } if (!check_fd(&ff_fd)) return -ENODEV; + if (duration <= 0) { + _I("Handle %d skip requests with duration 0", device_handle); + return 0; + } + /* Zero(0) is the infinitely vibration value */ if (duration == HAPTIC_MODULE_DURATION_UNLIMITED) duration = 0; /* unregister existing timer */ if (info->timer) { - ff_stop(ff_fd, &info->effect); + ff_stop(__func__, ff_fd, &info->effect); g_source_remove(info->timer); info->timer = 0; } @@ -428,16 +450,16 @@ static int vibrate_monotone(int device_handle, int duration, int feedback, int p ff_init_effect(&info->effect); ret = ff_set_effect(&info->effect, duration, feedback); if (ret < 0) { - _E("failed to set effect(duration:%d, feedback:%d) : %d", - duration, feedback, ret); + _E("Handle %d fail to set effect(duration:%d, feedback:%d) : %d", + device_handle, duration, feedback, ret); return ret; } /* play effect as per arguments */ - ret = ff_play(ff_fd, &info->effect); + ret = ff_play(__func__, ff_fd, &info->effect); if (ret < 0) { - _E("failed to play haptic effect(fd:%d id:%d) : %d", - ff_fd, info->effect.id, ret); + _E("Handle %d fail to play haptic effect(fd:%d id:%d) : %d", + device_handle, ff_fd, info->effect.id, ret); return ret; } @@ -445,12 +467,10 @@ static int vibrate_monotone(int device_handle, int duration, int feedback, int p if (duration) { info->timer = g_timeout_add(duration, timer_cb, info); if (!info->timer) - _E("Failed to add timer callback"); + _E("Handle %d failed to add timer callback", device_handle); } - _D("device handle %d effect id : %d %dms", device_handle, info->effect.id, duration); - if (effect_handle) - *effect_handle = info->effect.id; + _D("Handle %d effect id : %d %dms", device_handle, info->effect.id, duration); return 0; } @@ -461,14 +481,20 @@ static int stop_device(int device_handle) int r; info = read_from_list(device_handle); - if (!info) - return -EINVAL; + if (!info) { + _E("Handle %d fail to check info", device_handle); + return -ENOENT; /* 2 */ + } - if (!check_valid_handle(info)) - return -EINVAL; + if (!check_valid_handle(info)) { + _E("Handle %d fail to check handle", device_handle); + return -EINVAL; /* 22 */ + } - if (!check_fd(&ff_fd)) - return -ENODEV; + if (!check_fd(&ff_fd)) { + _E("Handle %d fail to check fd", device_handle); + return -ENODEV; /* 19 */ + } if (cur_h_data.handle > 0 && cur_h_data.handle != info->handle) { _E("Only same handle can stop current vibration"); @@ -479,7 +505,7 @@ static int stop_device(int device_handle) standard_vibrate_close(); /* stop effect */ - r = ff_stop(ff_fd, &info->effect); + r = ff_stop(__func__, ff_fd, &info->effect); if (r < 0) _E("failed to stop effect(id:%d) : %d", info->effect.id, r); else -- 2.7.4 From 84ee93d4d1827004b4bc03b67881f1dcc26fc8c5 Mon Sep 17 00:00:00 2001 From: "pr.jung" Date: Fri, 18 Jan 2019 14:32:07 +0900 Subject: [PATCH 04/16] Check priority for VibrateMonotone and add debug logs Change-Id: Iacb4241abf39503476b4a02c35a726de6124e868 Signed-off-by: pr.jung --- src/haptic/circle.c | 37 +++++++++++++++++++++++++++---------- src/haptic/gpio_haptic.c | 2 +- src/haptic/haptic.c | 23 +++++++++++++++++------ src/haptic/standard-vibcore.c | 28 ++++++++++++++++++++++++++-- src/haptic/standard-vibcore.h | 1 + src/haptic/standard.c | 37 +++++++++++++++---------------------- 6 files changed, 87 insertions(+), 41 deletions(-) diff --git a/src/haptic/circle.c b/src/haptic/circle.c index f17007a..5cb570e 100644 --- a/src/haptic/circle.c +++ b/src/haptic/circle.c @@ -144,19 +144,23 @@ static int close_device(int device_handle) bool found; found = find_from_list(device_handle); - if (!found) + if (!found) { + _E("Handle %d fail to check info", device_handle); return -EINVAL; + } if (fd_stop < 0) { fd_stop = open(CIRCLE_OFF_PATH, O_RDONLY); - if (fd_stop < 0) + if (fd_stop < 0) { + _E("Handle %d fail to check fd", device_handle); return -ENODEV; + } } /* stop vibration */ r = stop_device(device_handle); if (r < 0) - _I("already stopped or failed to stop effect : %d", r); + _I("Handle %d already stopped or failed to stop effect : %d", device_handle, r); DD_LIST_REMOVE(handle_list, (gpointer)(long)device_handle); @@ -184,13 +188,22 @@ static int vibrate_monotone(int device_handle, int duration, int feedback, int p bool found; found = find_from_list(device_handle); - if (!found) + if (!found) { + _E("Handle %d fail to check list", device_handle); return -EINVAL; + } if (fd_play < 0) { fd_play = open(CIRCLE_ON_PATH, O_RDONLY); - if (fd_play < 0) + if (fd_play < 0) { + _E("Handle %d fail to check handle", device_handle); return -ENODEV; + } + } + + if (duration <= 0) { + _E("handle %d skip requested with 0", device_handle); + return -EINVAL; } /* Zero(0) is the infinitely vibration value */ @@ -203,7 +216,7 @@ static int vibrate_monotone(int device_handle, int duration, int feedback, int p /* play vibration */ ret = read(fd_play, buf, BUF_SIZE); if (ret < 0) { - _E("failed to play"); + _E("Handle %d failed to play", device_handle); return -errno; } @@ -227,8 +240,10 @@ static int stop_device(int device_handle) bool found; found = find_from_list(device_handle); - if (!found) + if (!found) { + _E("Handle %d fail to check info", device_handle); return -EINVAL; + } if (cur_h_data.handle > 0 && cur_h_data.handle != device_handle) { _E("Only same handle can stop current vibration"); @@ -240,12 +255,14 @@ static int stop_device(int device_handle) if (fd_stop < 0) { fd_stop = open(CIRCLE_OFF_PATH, O_RDONLY); - if (fd_stop < 0) + if (fd_stop < 0) { + _E("Handle %d fail to check fd", device_handle); return -ENODEV; + } } ret = read(fd_stop, buf, BUF_SIZE); if (ret < 0) { - _E("failed to stop"); + _E("Failed to stop"); return -errno; } if (stop_timer) { @@ -270,7 +287,7 @@ static const struct haptic_plugin_ops default_plugin = { .get_device_count = get_device_count, .open_device = open_device, .close_device = close_device, - .vibrate_monotone = vibrate_monotone, + .vibrate_monotone = standard_vibrate_monotone, .vibrate_effect = standard_vibrate_effect, .is_supported = standard_is_supported, .stop_device = stop_device, diff --git a/src/haptic/gpio_haptic.c b/src/haptic/gpio_haptic.c index 8b7ff7b..c448fee 100644 --- a/src/haptic/gpio_haptic.c +++ b/src/haptic/gpio_haptic.c @@ -295,7 +295,7 @@ static const struct haptic_plugin_ops default_plugin = { .get_device_count = gpio_haptic_get_device_count, .open_device = gpio_haptic_open_device, .close_device = gpio_haptic_close_device, - .vibrate_monotone = gpio_haptic_vibrate_monotone, + .vibrate_monotone = standard_vibrate_monotone, .vibrate_effect = standard_vibrate_effect, .is_supported = standard_is_supported, .stop_device = gpio_haptic_stop_device, diff --git a/src/haptic/haptic.c b/src/haptic/haptic.c index b01cd96..95e4d5b 100644 --- a/src/haptic/haptic.c +++ b/src/haptic/haptic.c @@ -358,12 +358,13 @@ exit: static void vibrate_monotone_idler_cb(void *data) { - struct vibrate_monotone_info *vibrate_info = (struct vibrate_monotone_info *)data; - int ret; + struct vibrate_monotone_info *vibrate_info; + + if (!data) + return; + + vibrate_info = (struct vibrate_monotone_info *)data; - ret = device_power_request_lock(POWER_LOCK_CPU, vibrate_info->duration); - if (ret != DEVICE_ERROR_NONE) - _E("Failed to request power lock"); h_ops->vibrate_monotone(vibrate_info->handle, vibrate_info->duration, vibrate_info->level, vibrate_info->priority); free(vibrate_info); @@ -422,7 +423,12 @@ exit: static void vibrate_effect_idler_cb(void *data) { - struct vibrate_effect_info *vibrate_info = (struct vibrate_effect_info *)data; + struct vibrate_effect_info *vibrate_info; + + if (!data) + return; + + vibrate_info = (struct vibrate_effect_info *)data; h_ops->vibrate_effect(vibrate_info->handle, vibrate_info->pattern, vibrate_info->level, vibrate_info->priority); @@ -500,6 +506,11 @@ GVariant *hdbus_stop_device(GDBusConnection *conn, g_variant_get(param, "(u)", &handle); + if (cur_h_data.handle != handle) { + _D("Not the request from current vibration handle :%d. Skip", handle); + goto exit; + } + ret = h_ops->stop_device(handle); exit: diff --git a/src/haptic/standard-vibcore.c b/src/haptic/standard-vibcore.c index 3e7d0d1..66e3eae 100644 --- a/src/haptic/standard-vibcore.c +++ b/src/haptic/standard-vibcore.c @@ -496,6 +496,30 @@ int standard_set_vib_function(t_vibrate_monotone func) return 0; } +int standard_vibrate_monotone(int device_handle, int duration, int feedback, int priority) +{ + int ret; + + if (priority < cur_h_data.priority) { + _I("Handle %d skip low priority(pre:%d now:%d)", device_handle, cur_h_data.priority, priority); + return 0; + } + + cur_h_data.vibration_data = NULL; + cur_h_data.handle = device_handle; + cur_h_data.level = feedback; + cur_h_data.priority = priority; + cur_h_data.stop = false; + cur_h_data.unlimit = false; + + ret = device_power_request_lock(POWER_LOCK_CPU, duration); + if (ret != DEVICE_ERROR_NONE) + _E("Failed to request power lock"); + real_vibrate_monotone(cur_h_data.handle, duration, cur_h_data.level, cur_h_data.priority); + + return 0; +} + int standard_vibrate_effect(int device_handle, const char *requested_pattern, int feedback, int priority) { dd_list *elem; @@ -509,8 +533,8 @@ int standard_vibrate_effect(int device_handle, const char *requested_pattern, in /* Same or higher priority pattern should be played */ if (priority < cur_h_data.priority) { - _E("Priority of new request is lower than old request"); - return -EPERM; + _I("Handle %d skip low priority(pre:%d now:%d)", device_handle, cur_h_data.priority, priority); + return 0; } snprintf(pattern, sizeof(pattern), "%s", requested_pattern); diff --git a/src/haptic/standard-vibcore.h b/src/haptic/standard-vibcore.h index 5f731ba..dd0c071 100644 --- a/src/haptic/standard-vibcore.h +++ b/src/haptic/standard-vibcore.h @@ -24,6 +24,7 @@ typedef int (*t_vibrate_monotone)(int device_handle, int duration, int feedback, void standard_config_parse(void); int standard_is_supported(const char *pattern); +int standard_vibrate_monotone(int device_handle, int duration, int feedback, int priority); int standard_vibrate_effect(int device_handle, const char *pattern, int feedback, int priority); int standard_set_vib_function(t_vibrate_monotone func); int standard_vibrate_close(void); diff --git a/src/haptic/standard.c b/src/haptic/standard.c index 4831c06..f370614 100644 --- a/src/haptic/standard.c +++ b/src/haptic/standard.c @@ -119,7 +119,7 @@ static bool check_fd(int *fd) return true; } -static int ff_stop(const char *func, int fd, struct ff_effect *effect); +static int ff_stop(int fd, struct ff_effect *effect); static gboolean timer_cb(void *data) { struct ff_info *info = (struct ff_info *)data; @@ -137,7 +137,7 @@ static gboolean timer_cb(void *data) _I("stop vibration by timer : id(%d)", info->effect.id); /* stop previous vibration */ - ff_stop(__func__, ff_fd, &info->effect); + ff_stop(ff_fd, &info->effect); /* reset timer */ info->timer = 0; @@ -217,8 +217,7 @@ static int ff_init_effect(struct ff_effect *effect) effect->replay.length = 0; effect->replay.delay = 10; effect->id = -1; - effect->u.rumble.strong_magnitude = 0x8000; - effect->u.rumble.weak_magnitude = 0xc000; + effect->u.rumble.strong_magnitude = 0; return 0; } @@ -227,8 +226,10 @@ static int ff_set_effect(struct ff_effect *effect, int length, int level) { double magnitude; - if (!effect) + if (!effect) { + _E("There is no valid effect"); return -EINVAL; + } magnitude = (double)level/HAPTIC_MODULE_FEEDBACK_MAX; magnitude *= RUMBLE_MAX_MAGNITUDE; @@ -242,22 +243,19 @@ static int ff_set_effect(struct ff_effect *effect, int length, int level) return 0; } -static int ff_play(const char *func, int fd, struct ff_effect *effect) +static int ff_play(int fd, struct ff_effect *effect) { struct input_event play; int ret; if (fd < 0 || !effect) { - if (fd < 0) - _E("%s: failed to check fd", func); - else - _E("%s: failed to check effect", func); + _E("Fd(%d) or effect(%s) is invalid", fd, effect ? "not null" : "null"); return -EINVAL; } /* upload an effect */ if (ioctl(fd, EVIOCSFF, effect) == -1) { - _E("%s: failed to ioctl", func); + _E("Failed to ioctl"); return -errno; } @@ -268,14 +266,14 @@ static int ff_play(const char *func, int fd, struct ff_effect *effect) ret = write(fd, (const void *)&play, sizeof(play)); if (ret == -1) { - _E("%s: failed to write", func); + _E("Failed to write"); return -errno; } return 0; } -static int ff_stop(const char *func, int fd, struct ff_effect *effect) +static int ff_stop(int fd, struct ff_effect *effect) { struct input_event stop; int ret; @@ -411,11 +409,6 @@ static int vibrate_monotone(int device_handle, int duration, int feedback, int p struct ff_info *info; int ret; - if (priority < cur_h_data.priority) { - _I("Handle %d skip low priority(pre:%d now:%d)", device_handle, cur_h_data.priority, priority); - return 0; - } - info = read_from_list(device_handle); if (!info) { _E("Handle %d failed to check list", device_handle); @@ -441,7 +434,7 @@ static int vibrate_monotone(int device_handle, int duration, int feedback, int p /* unregister existing timer */ if (info->timer) { - ff_stop(__func__, ff_fd, &info->effect); + ff_stop(ff_fd, &info->effect); g_source_remove(info->timer); info->timer = 0; } @@ -456,7 +449,7 @@ static int vibrate_monotone(int device_handle, int duration, int feedback, int p } /* play effect as per arguments */ - ret = ff_play(__func__, ff_fd, &info->effect); + ret = ff_play(ff_fd, &info->effect); if (ret < 0) { _E("Handle %d fail to play haptic effect(fd:%d id:%d) : %d", device_handle, ff_fd, info->effect.id, ret); @@ -505,7 +498,7 @@ static int stop_device(int device_handle) standard_vibrate_close(); /* stop effect */ - r = ff_stop(__func__, ff_fd, &info->effect); + r = ff_stop(ff_fd, &info->effect); if (r < 0) _E("failed to stop effect(id:%d) : %d", info->effect.id, r); else @@ -546,7 +539,7 @@ static const struct haptic_plugin_ops default_plugin = { .get_device_count = get_device_count, .open_device = open_device, .close_device = close_device, - .vibrate_monotone = vibrate_monotone, + .vibrate_monotone = standard_vibrate_monotone, .vibrate_effect = standard_vibrate_effect, .is_supported = standard_is_supported, .stop_device = stop_device, -- 2.7.4 From 980ce7b4881208c5feb45a8ceabe535d94a1731a Mon Sep 17 00:00:00 2001 From: "pr.jung" Date: Thu, 31 Jan 2019 17:37:36 +0900 Subject: [PATCH 05/16] Remove unused files and method Change-Id: I4fead9e8fce2375669a224321731be5d1aa2b064 Signed-off-by: pr.jung --- src/core/edbus-handler.c | 837 ---------------------------------------- src/core/edbus-handler.h | 50 --- src/haptic/circle.c | 10 - src/haptic/emulator.c | 10 - src/haptic/gpio_haptic.c | 10 - src/haptic/haptic-plugin-intf.h | 1 - src/haptic/haptic.c | 19 - src/haptic/standard.c | 22 -- 8 files changed, 959 deletions(-) delete mode 100644 src/core/edbus-handler.c delete mode 100644 src/core/edbus-handler.h diff --git a/src/core/edbus-handler.c b/src/core/edbus-handler.c deleted file mode 100644 index fff5a4c..0000000 --- a/src/core/edbus-handler.c +++ /dev/null @@ -1,837 +0,0 @@ -/* - * feedbackd - * - * Copyright (c) 2016 - 2017 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 -#include - -#include "core/log.h" -#include "core/common.h" -#include "core/device-idler.h" -#include "core/list.h" -#include "edbus-handler.h" - -#define EDBUS_INIT_RETRY_COUNT 5 -#define NAME_OWNER_CHANGED "NameOwnerChanged" -#define NAME_OWNER_MATCH "type='signal',sender='org.freedesktop.DBus'," \ - "path='/org/freedesktop/DBus',interface='org.freedesktop.DBus'," \ - "member='NameOwnerChanged',arg0='%s'" - -/* -1 is a default timeout value, it's converted to 25*1000 internally. */ -#define DBUS_REPLY_TIMEOUT (-1) -#define RETRY_MAX 5 - -struct edbus_list { - char *signal_name; - E_DBus_Signal_Handler *handler; -}; - -static struct edbus_object { - char *path; - char *interface; - E_DBus_Object *obj; - E_DBus_Interface *iface; -} edbus_objects[] = { - { VIBRATOR_PATH_CORE, VIBRATOR_INTERFACE_CORE, NULL, NULL }, - /* Add new object & interface here*/ -}; - -struct watch_func_info { - bool deleted; - void (*func)(const char *sender, void *data); - void *data; -}; - -struct watch_info { - bool deleted; - char *sender; - dd_list *func_list; -}; - -static dd_list *edbus_object_list; -//static dd_list *edbus_owner_list; -static dd_list *edbus_handler_list; -static dd_list *edbus_watch_list; -static int edbus_init_val; -static DBusConnection *conn; -static E_DBus_Connection *edbus_conn; -static DBusPendingCall *edbus_request_name; - -static DBusHandlerResult message_filter(DBusConnection *connection, - DBusMessage *message, void *data); -static int register_edbus_interface(struct edbus_object *object) -{ - if (!object) { - _E("object is invalid value!"); - return -1; - } - - object->obj = e_dbus_object_add(edbus_conn, object->path, NULL); - if (!object->obj) { - _E("fail to add edbus obj"); - return -1; - } - - object->iface = e_dbus_interface_new(object->interface); - if (!object->iface) { - _E("fail to add edbus interface"); - return -1; - } - - e_dbus_object_interface_attach(object->obj, object->iface); - - return 0; -} - -E_DBus_Interface *get_edbus_interface(const char *path) -{ - struct edbus_object *obj; - dd_list *elem; - int i; - - for (i = 0; i < ARRAY_SIZE(edbus_objects); i++) - if (!strcmp(path, edbus_objects[i].path)) - return edbus_objects[i].iface; - - /* find matched obj */ - DD_LIST_FOREACH(edbus_object_list, elem, obj) { - if (strncmp(obj->path, path, strlen(obj->path)) == 0) - return obj->iface; - } - - return NULL; -} - -static void unregister_edbus_signal_handle(void) -{ - dd_list *tmp, *next; - struct edbus_list *entry; - - DD_LIST_FOREACH_SAFE(edbus_handler_list, tmp, next, entry) { - if (!entry->handler) - continue; - e_dbus_signal_handler_del(edbus_conn, entry->handler); - DD_LIST_REMOVE(edbus_handler_list, entry); - free(entry->signal_name); - free(entry); - } -} - -int register_edbus_signal_handler(const char *path, const char *interface, - const char *name, E_DBus_Signal_Cb cb) -{ - dd_list *tmp; - struct edbus_list *entry; - E_DBus_Signal_Handler *handler; - - DD_LIST_FOREACH(edbus_handler_list, tmp, entry) { - if (strncmp(entry->signal_name, name, strlen(name)) == 0) - return -EEXIST; - } - - handler = e_dbus_signal_handler_add(edbus_conn, NULL, path, - interface, name, cb, NULL); - - if (!handler) { - _E("fail to add edbus handler"); - return -ENOMEM; - } - - entry = malloc(sizeof(struct edbus_list)); - - if (!entry) { - e_dbus_signal_handler_del(edbus_conn, handler); - _E("Malloc failed"); - return -ENOMEM; - } - - entry->signal_name = strndup(name, strlen(name)); - - if (!entry->signal_name) { - _E("Malloc failed"); - e_dbus_signal_handler_del(edbus_conn, handler); - free(entry); - return -ENOMEM; - } - - entry->handler = handler; - DD_LIST_PREPEND(edbus_handler_list, entry); - if (!edbus_handler_list) { - _E("dd_list_prepend failed"); - e_dbus_signal_handler_del(edbus_conn, handler); - free(entry->signal_name); - free(entry); - return -ENOMEM; - } - return 0; -} - -int unregister_edbus_signal_handler(const char *path, const char *interface, - const char *name) -{ - dd_list *tmp, *next; - struct edbus_list *entry; - - DD_LIST_FOREACH_SAFE(edbus_handler_list, tmp, next, entry) { - if (strncmp(entry->signal_name, name, strlen(name) + 1) == 0) { - e_dbus_signal_handler_del(edbus_conn, entry->handler); - DD_LIST_REMOVE(edbus_handler_list, entry); - free(entry->signal_name); - free(entry); - return 0; - } - } - - return -1; -} - -int broadcast_edbus_signal(const char *path, const char *interface, - const char *name, const char *sig, char *param[]) -{ - DBusMessage *msg; - DBusMessageIter iter; - int r; - - msg = dbus_message_new_signal(path, interface, name); - if (!msg) { - _E("fail to allocate new %s.%s signal", interface, name); - return -EPERM; - } - - dbus_message_iter_init_append(msg, &iter); - r = append_variant(&iter, sig, param); - if (r < 0) { - _E("append_variant error(%d)", r); - return -EPERM; - } - - r = dbus_connection_send(conn, msg, NULL); - dbus_message_unref(msg); - - if (r != TRUE) { - _E("dbus_connection_send error(%s:%s-%s)", - path, interface, name); - return -ECOMM; - } - - return 0; -} - -static void print_watch_item(void) -{ - struct watch_info *watch; - struct watch_func_info *finfo; - dd_list *n; - dd_list *e; - - DD_LIST_FOREACH(edbus_watch_list, n, watch) { - _D("watch sender : %s, deleted : %d", - watch->sender, watch->deleted); - DD_LIST_FOREACH(watch->func_list, e, finfo) - _D("\tfunc : %p, deleted : %d", - finfo->func, finfo->deleted); - } -} - -static bool get_valid_watch_item(void) -{ - struct watch_info *watch; - dd_list *elem; - - DD_LIST_FOREACH(edbus_watch_list, elem, watch) { - if (!watch->deleted) - return true; - } - - return false; -} - -static void watch_idler_cb(void *data) -{ - struct watch_info *watch; - struct watch_func_info *finfo; - dd_list *n; - dd_list *next; - dd_list *elem; - dd_list *enext; - char match[256]; - - DD_LIST_FOREACH_SAFE(edbus_watch_list, n, next, watch) { - if (!watch->deleted) - continue; - - /* remove dbus match */ - snprintf(match, sizeof(match), NAME_OWNER_MATCH, watch->sender); - dbus_bus_remove_match(conn, match, NULL); - - _I("%s is not watched by dbus!", watch->sender); - - /* remove watch func list */ - DD_LIST_FOREACH_SAFE(watch->func_list, elem, enext, finfo) - free(finfo); - - /* remove watch item */ - DD_LIST_FREE_LIST(watch->func_list); - DD_LIST_REMOVE_LIST(edbus_watch_list, n); - free(watch->sender); - free(watch); - } - - /* if the last request, remove message filter */ - if (!get_valid_watch_item()) - dbus_connection_remove_filter(conn, message_filter, NULL); -} - -static DBusHandlerResult message_filter(DBusConnection *connection, - DBusMessage *message, void *data) -{ - int ret; - const char *iface, *member; - const char *sender; - struct watch_info *watch; - struct watch_func_info *finfo; - dd_list *n; - int len; - - if (dbus_message_get_type(message) != DBUS_MESSAGE_TYPE_SIGNAL) - return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; - - iface = dbus_message_get_interface(message); - member = dbus_message_get_member(message); - - if (strncmp(iface, DBUS_INTERFACE_DBUS, - sizeof(DBUS_INTERFACE_DBUS))) - return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; - - if (strncmp(member, NAME_OWNER_CHANGED, - sizeof(NAME_OWNER_CHANGED))) - return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; - - ret = dbus_message_get_args(message, NULL, - DBUS_TYPE_STRING, &sender, - DBUS_TYPE_INVALID); - if (!ret) { - _E("no message"); - return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; - } - - len = strlen(sender) + 1; - DD_LIST_FOREACH(edbus_watch_list, n, watch) { - if (!watch->deleted && - !strncmp(watch->sender, sender, len)) - break; - } - - if (!watch) - return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; - - DD_LIST_FOREACH(watch->func_list, n, finfo) { - if (!finfo->deleted && - finfo->func) - finfo->func(watch->sender, finfo->data); - } - - /* no interest in this item anymore */ - watch->deleted = true; - - print_watch_item(); - add_idle_request(watch_idler_cb, NULL); - return DBUS_HANDLER_RESULT_HANDLED; -} - -static struct watch_info *get_matched_watch_item(const char *sender) -{ - int len; - dd_list *n; - struct watch_info *watch; - - if (!sender) - return NULL; - - len = strlen(sender) + 1; - /* check the sender&type is already registered */ - DD_LIST_FOREACH(edbus_watch_list, n, watch) { - if (!watch->deleted && - !strncmp(watch->sender, sender, len)) - return watch; - } - - return NULL; -} - -static struct watch_info *add_watch_item(const char *sender) -{ - DBusError err; - struct watch_info *watch; - char match[256]; - int ret; - - if (!sender) - return NULL; - - watch = calloc(1, sizeof(struct watch_info)); - if (!watch) - return NULL; - - watch->sender = strdup(sender); - if (!watch->sender) - goto out; - - dbus_error_init(&err); - /* add name owner changed match string */ - snprintf(match, sizeof(match), NAME_OWNER_MATCH, watch->sender); - dbus_bus_add_match(conn, match, &err); - - if (dbus_error_is_set(&err)) { - _E("fail to add match for %s [%s:%s]", - sender, err.name, err.message); - dbus_error_free(&err); - goto out; - } - - /* if the first request, add message filter */ - if (!get_valid_watch_item()) { - ret = dbus_connection_add_filter(conn, - message_filter, NULL, NULL); - if (!ret) { - _E("fail to add message filter!"); - dbus_bus_remove_match(conn, match, NULL); - goto out; - } - _I("success to add message filter!"); - } - - /* Add watch to watch list */ - DD_LIST_APPEND(edbus_watch_list, watch); - _I("%s is watched by dbus!", sender); - return watch; - -out: - if (watch) { - free(watch->sender); - free(watch); - } - - return NULL; -} - -int register_edbus_watch(const char *sender, - void (*func)(const char *sender, void *data), void *data) -{ - struct watch_info *watch; - struct watch_func_info *finfo; - dd_list *elem; - bool isnew = false; - - if (!sender || !func) { - _E("invalid argument : sender(NULL) || func(NULL)"); - return -EINVAL; - } - - watch = get_matched_watch_item(sender); - if (!watch) { - /* create new watch item */ - watch = add_watch_item(sender); - if (!watch) { - _E("fail to add watch item"); - return -EPERM; - } - isnew = true; - } - - /* find the same callback */ - DD_LIST_FOREACH(watch->func_list, elem, finfo) { - if (finfo->func == func) { - _E("there is already the same callback"); - goto out; - } - } - - finfo = calloc(1, sizeof(struct watch_func_info)); - if (!finfo) { - _E("fail to allocate watch func info"); - goto out; - } - - finfo->func = func; - finfo->data = data; - - /* add callback function to the watch list */ - DD_LIST_APPEND(watch->func_list, finfo); - - _I("register watch func(%p) of %s", func, sender); - return 0; -out: - if (isnew) - watch->deleted = true; - - return -EPERM; -} - -int unregister_edbus_watch(const char *sender, - void (*func)(const char *sender, void *data)) -{ - struct watch_info *watch; - struct watch_func_info *finfo; - dd_list *elem; - bool matched = false; - - if (!sender || !func) { - _E("invalid argument : sender(NULL) || func(NULL)"); - return -EINVAL; - } - - watch = get_matched_watch_item(sender); - if (!watch) { - _E("fail to get matched watch item"); - return -ENODEV; - } - - /* check the no interest function */ - DD_LIST_FOREACH(watch->func_list, elem, finfo) { - if (finfo->func == func) - finfo->deleted = true; - if (!finfo->deleted) - matched = true; - } - - /* if it is the last item */ - if (!matched) - watch->deleted = true; - - _I("unregister watch func(%p) of %s", func, sender); - return 0; -} - -static void unregister_edbus_watch_all(void) -{ - dd_list *n, *next; - struct watch_info *watch; - - DD_LIST_FOREACH_SAFE(edbus_watch_list, n, next, watch) - watch->deleted = true; - - add_idle_request(watch_idler_cb, NULL); -} - -static int register_method(E_DBus_Interface *iface, - const struct edbus_method *edbus_methods, int size) -{ - int ret; - int i; - - assert(iface); - assert(edbus_methods); - - for (i = 0; i < size; i++) { - ret = e_dbus_interface_method_add(iface, - edbus_methods[i].member, - edbus_methods[i].signature, - edbus_methods[i].reply_signature, - edbus_methods[i].func); - if (!ret) { - _E("fail to add method %s!", edbus_methods[i].member); - return -EINVAL; - } - } - - return 0; -} - -int register_edbus_interface_and_method(const char *path, - const char *interface, - const struct edbus_method *edbus_methods, int size) -{ - struct edbus_object *obj; - dd_list *elem; - int ret; - - if (!path || !interface || !edbus_methods || size < 1) { - _E("invalid parameter"); - return -EINVAL; - } - - /* find matched obj */ - DD_LIST_FOREACH(edbus_object_list, elem, obj) { - if (strncmp(obj->path, path, strlen(obj->path)) == 0 && - strncmp(obj->interface, interface, strlen(obj->interface)) == 0) { - _I("found matched item : obj(%p)", obj); - break; - } - } - - /* if there is no matched obj */ - if (!obj) { - obj = malloc(sizeof(struct edbus_object)); - if (!obj) { - _E("fail to allocate %s interface", path); - return -ENOMEM; - } - - obj->path = strdup(path); - obj->interface = strdup(interface); - - ret = register_edbus_interface(obj); - if (ret < 0) { - _E("fail to register %s interface(%d)", obj->path, ret); - free(obj->path); - free(obj->interface); - free(obj); - return ret; - } - - DD_LIST_APPEND(edbus_object_list, obj); - } - - ret = register_method(obj->iface, edbus_methods, size); - if (ret < 0) { - _E("fail to register %s method(%d)", obj->path, ret); - return ret; - } - - return 0; -} - -int unregister_edbus_interface_all(void) -{ - struct edbus_object *obj; - dd_list *elem, *n; - - DD_LIST_FOREACH_SAFE(edbus_object_list, elem, n, obj) { - DD_LIST_REMOVE(edbus_object_list, obj); - free(obj->path); - free(obj->interface); - free(obj); - } - - return 0; -} - -int register_edbus_method(const char *path, const struct edbus_method *edbus_methods, int size) -{ - E_DBus_Interface *iface; - int ret; - - if (!path || !edbus_methods || size < 1) { - _E("invalid parameter"); - return -EINVAL; - } - - iface = get_edbus_interface(path); - if (!iface) { - _E("fail to get edbus interface!"); - return -ENODEV; - } - - ret = register_method(iface, edbus_methods, size); - if (ret < 0) { - _E("fail to register %s method(%d)", path, ret); - return ret; - } - - return 0; -} - -static void request_name_cb(void *data, DBusMessage *msg, DBusError *error) -{ - DBusError err; - unsigned int val; - int r; - - if (!msg) { - _D("invalid DBusMessage!"); - return; - } - - dbus_error_init(&err); - r = dbus_message_get_args(msg, &err, DBUS_TYPE_UINT32, &val, DBUS_TYPE_INVALID); - if (!r) { - _E("no message : [%s:%s]", err.name, err.message); - dbus_error_free(&err); - return; - } - - _I("Request Name reply : %d", val); -} - -static void check_owner_name(void) -{ -// DBusError err; -// DBusMessage *msg; -// DBusMessageIter iter; -// char *pa[1]; -// char exe_name[PATH_MAX]; -// char *entry; -// dd_list *n; -// int pid; -// -// DD_LIST_FOREACH(edbus_owner_list, n, entry) { -// pa[0] = entry; -// msg = dbus_method_sync_with_reply(E_DBUS_FDO_BUS, -// E_DBUS_FDO_PATH, -// E_DBUS_FDO_INTERFACE, -// "GetConnectionUnixProcessID", "s", pa); -// -// if (!msg) { -// _E("invalid DBusMessage!"); -// return; -// } -// -// dbus_error_init(&err); -// dbus_message_iter_init(msg, &iter); -// -// dbus_message_iter_get_basic(&iter, &pid); -// if (get_cmdline_name(pid, exe_name, PATH_MAX) != 0) -// goto out; -// _I("%s(%d)", exe_name, pid); -// -//out: -// dbus_message_unref(msg); -// dbus_error_free(&err); -// } -} - -static void check_owner_list(void) -{ -// DBusError err; -// DBusMessage *msg; -// DBusMessageIter array, item; -// char *pa[1]; -// char *name; -// char *entry; -// -// pa[0] = VIBRATOR_BUS_NAME; -// msg = dbus_method_sync_with_reply(E_DBUS_FDO_BUS, -// E_DBUS_FDO_PATH, -// E_DBUS_FDO_INTERFACE, -// "ListQueuedOwners", "s", pa); -// -// if (!msg) { -// _E("invalid DBusMessage!"); -// return; -// } -// -// dbus_error_init(&err); -// dbus_message_iter_init(msg, &array); -// -// if (dbus_message_iter_get_arg_type(&array) != DBUS_TYPE_ARRAY) -// goto out; -// dbus_message_iter_recurse(&array, &item); -// while (dbus_message_iter_get_arg_type(&item) == DBUS_TYPE_STRING) { -// dbus_message_iter_get_basic(&item, &name); -// entry = strndup(name, strlen(name)); -// DD_LIST_APPEND(edbus_owner_list, entry); -// if (!edbus_owner_list) { -// _E("append failed"); -// free(entry); -// goto out; -// } -// dbus_message_iter_next(&item); -// } -// -//out: -// dbus_message_unref(msg); -// dbus_error_free(&err); -} - -void edbus_init(void *data) -{ - DBusError error; - int retry = 0; - int i, ret; - - dbus_threads_init_default(); - dbus_error_init(&error); - - do { - edbus_init_val = e_dbus_init(); - if (edbus_init_val) - break; - if (retry == EDBUS_INIT_RETRY_COUNT) { - _E("fail to init edbus"); - return; - } - retry++; - } while (retry <= EDBUS_INIT_RETRY_COUNT); - - retry = 0; - do { - conn = dbus_bus_get(DBUS_BUS_SYSTEM, &error); - if (conn) - break; - if (retry == EDBUS_INIT_RETRY_COUNT) { - _E("fail to get dbus"); - goto out1; - } - retry++; - } while (retry <= EDBUS_INIT_RETRY_COUNT); - - retry = 0; - do { - edbus_conn = e_dbus_connection_setup(conn); - if (edbus_conn) - break; - if (retry == EDBUS_INIT_RETRY_COUNT) { - _E("fail to get edbus"); - goto out2; - } - retry++; - } while (retry <= EDBUS_INIT_RETRY_COUNT); - - retry = 0; - do { - edbus_request_name = e_dbus_request_name(edbus_conn, VIBRATOR_BUS_NAME, - DBUS_NAME_FLAG_REPLACE_EXISTING, request_name_cb, NULL); - if (edbus_request_name) - break; - if (retry == EDBUS_INIT_RETRY_COUNT) { - _E("fail to request edbus name"); - goto out3; - } - retry++; - } while (retry <= EDBUS_INIT_RETRY_COUNT); - - for (i = 0; i < ARRAY_SIZE(edbus_objects); i++) { - ret = register_edbus_interface(&edbus_objects[i]); - if (ret < 0) { - _E("fail to add obj & interface for %s", - edbus_objects[i].interface); - return; - } - _D("add new obj for %s", edbus_objects[i].interface); - } - check_owner_list(); - check_owner_name(); - return; - -out3: - e_dbus_connection_close(edbus_conn); -out2: - dbus_connection_set_exit_on_disconnect(conn, FALSE); -out1: - e_dbus_shutdown(); -} - -void edbus_exit(void *data) -{ - unregister_edbus_signal_handle(); - unregister_edbus_watch_all(); - unregister_edbus_interface_all(); - e_dbus_connection_close(edbus_conn); - e_dbus_shutdown(); -} diff --git a/src/core/edbus-handler.h b/src/core/edbus-handler.h deleted file mode 100644 index cdd5571..0000000 --- a/src/core/edbus-handler.h +++ /dev/null @@ -1,50 +0,0 @@ -/* - * feedbackd - * - * Copyright (c) 2016 - 2017 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 __FEEDBACKD_EDBUS_HANDLE_H__ -#define __FEEDBACKD_EDBUS_HANDLE_H__ - -#include - -struct edbus_method { - const char *member; - const char *signature; - const char *reply_signature; - E_DBus_Method_Cb func; -}; -int register_edbus_interface_and_method(const char *path, - const char *interface, - const struct edbus_method *edbus_methods, int size); -int register_edbus_method(const char *path, const struct edbus_method *edbus_methods, int size); -int register_edbus_signal_handler(const char *path, const char *interface, - const char *name, E_DBus_Signal_Cb cb); -int unregister_edbus_signal_handler(const char *path, const char *interface, - const char *name); -E_DBus_Interface *get_edbus_interface(const char *path); -int broadcast_edbus_signal(const char *path, const char *interface, - const char *name, const char *sig, char *param[]); -int register_edbus_watch(const char *sender, - void (*func)(const char *sender, void *data), void *data); -int unregister_edbus_watch(const char *sender, - void (*func)(const char *sender, void *data)); - -void edbus_init(void *data); -void edbus_exit(void *data); - -#endif /* __FEEDBACKD_EDBUS_HANDLE_H__ */ diff --git a/src/haptic/circle.c b/src/haptic/circle.c index 5cb570e..7fd46f1 100644 --- a/src/haptic/circle.c +++ b/src/haptic/circle.c @@ -272,15 +272,6 @@ static int stop_device(int device_handle) return 0; } - -static int get_device_state(int device_index, int *effect_state) -{ - if (!effect_state) - return -EINVAL; - - *effect_state = state; - return 0; -} /* END: Haptic Module APIs */ static const struct haptic_plugin_ops default_plugin = { @@ -291,7 +282,6 @@ static const struct haptic_plugin_ops default_plugin = { .vibrate_effect = standard_vibrate_effect, .is_supported = standard_is_supported, .stop_device = stop_device, - .get_device_state = get_device_state, }; static bool is_valid(void) diff --git a/src/haptic/emulator.c b/src/haptic/emulator.c index 326444c..6807391 100644 --- a/src/haptic/emulator.c +++ b/src/haptic/emulator.c @@ -104,15 +104,6 @@ static int is_supported(const char *pattern) { return 0; } - -static int get_device_state(int device_index, int *effect_state) -{ - if (effect_state) - *effect_state = 0; - - return 0; -} - /* END: Haptic Module APIs */ static const struct haptic_plugin_ops default_plugin = { @@ -123,7 +114,6 @@ static const struct haptic_plugin_ops default_plugin = { .vibrate_effect = vibrate_effect, .is_supported = is_supported, .stop_device = stop_device, - .get_device_state = get_device_state, }; static bool is_valid(void) diff --git a/src/haptic/gpio_haptic.c b/src/haptic/gpio_haptic.c index c448fee..2334598 100644 --- a/src/haptic/gpio_haptic.c +++ b/src/haptic/gpio_haptic.c @@ -280,15 +280,6 @@ static int gpio_haptic_stop_device(int handle) return 0; } - -static int gpio_haptic_get_device_state(int index, int *effect_state) -{ - if (!effect_state) - return -EINVAL; - - *effect_state = state; - return 0; -} /* END: Haptic Module APIs */ static const struct haptic_plugin_ops default_plugin = { @@ -299,7 +290,6 @@ static const struct haptic_plugin_ops default_plugin = { .vibrate_effect = standard_vibrate_effect, .is_supported = standard_is_supported, .stop_device = gpio_haptic_stop_device, - .get_device_state = gpio_haptic_get_device_state, }; static bool is_valid(void) diff --git a/src/haptic/haptic-plugin-intf.h b/src/haptic/haptic-plugin-intf.h index cd6c6bf..9d11f62 100644 --- a/src/haptic/haptic-plugin-intf.h +++ b/src/haptic/haptic-plugin-intf.h @@ -30,7 +30,6 @@ struct haptic_plugin_ops { int (*vibrate_effect) (int, const char*, int, int); int (*is_supported) (const char*); int (*stop_device) (int); - int (*get_device_state) (int, int*); }; const struct haptic_plugin_ops *get_haptic_plugin_interface(); diff --git a/src/haptic/haptic.c b/src/haptic/haptic.c index 95e4d5b..38d3cdc 100644 --- a/src/haptic/haptic.c +++ b/src/haptic/haptic.c @@ -517,25 +517,6 @@ exit: return g_variant_new("(i)", ret); } -GVariant *hdbus_get_state(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - int index, state, ret; - - if (!CHECK_VALID_OPS(h_ops, ret)) - goto exit; - - g_variant_get(param, "(i)", &index); - - ret = h_ops->get_device_state(index, &state); - if (ret >= 0) - ret = state; - -exit: - return g_variant_new("(i)", ret); -} - GVariant *hdbus_show_handle_list(GDBusConnection *conn, const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) diff --git a/src/haptic/standard.c b/src/haptic/standard.c index f370614..f5e43b4 100644 --- a/src/haptic/standard.c +++ b/src/haptic/standard.c @@ -512,27 +512,6 @@ static int stop_device(int device_handle) return 0; } - -static int get_device_state(int device_index, int *effect_state) -{ - struct ff_info *info; - dd_list *elem; - int status = false; - - if (!effect_state) - return -EINVAL; - - /* suppose there is just one haptic device */ - DD_LIST_FOREACH(ff_list, elem, info) { - if (info->effect.id >= 0) { - status = true; - break; - } - } - - *effect_state = status; - return 0; -} /* END: Haptic Module APIs */ static const struct haptic_plugin_ops default_plugin = { @@ -543,7 +522,6 @@ static const struct haptic_plugin_ops default_plugin = { .vibrate_effect = standard_vibrate_effect, .is_supported = standard_is_supported, .stop_device = stop_device, - .get_device_state = get_device_state, }; static bool is_valid(void) -- 2.7.4 From 16ea28dd2d743a5a1d54474f9c24f90ccad74dca Mon Sep 17 00:00:00 2001 From: "pr.jung" Date: Fri, 8 Feb 2019 13:28:23 +0900 Subject: [PATCH 06/16] Fix build error Change-Id: I600a814975ad96aef8b0518c726bd5d4bce47fba Signed-off-by: pr.jung --- src/haptic/haptic.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/haptic/haptic.c b/src/haptic/haptic.c index 38d3cdc..f1cdc8a 100644 --- a/src/haptic/haptic.c +++ b/src/haptic/haptic.c @@ -757,7 +757,6 @@ static const dbus_method_s hdbus_methods[] = { { "StopDevice", "u", "i", hdbus_stop_device }, { "VibrateMonotone", "uiii", "i", hdbus_vibrate_monotone }, { "VibrateEffect", "usii", "i", hdbus_vibrate_effect }, - { "GetState", "i", "i", hdbus_get_state }, { "ShowHandleList", NULL, NULL, hdbus_show_handle_list }, { "IsSupported", "s", "i", hdbus_pattern_is_supported }, /* Add methods here */ -- 2.7.4 From 97f5aad633293463b764b179a0593cfd27afc4cc Mon Sep 17 00:00:00 2001 From: "pr.jung" Date: Mon, 18 Feb 2019 15:59:24 +0900 Subject: [PATCH 07/16] Remove standard-vibcore.c Change-Id: I6a8eb297a6b3cb10637b763c5615c75d9bbc82ad Signed-off-by: pr.jung --- CMakeLists.txt | 6 +- src/haptic/circle.c | 11 +- src/haptic/emulator.c | 18 -- src/haptic/gpio_haptic.c | 11 +- src/haptic/haptic-plugin-intf.h | 2 - src/haptic/haptic.c | 564 +++++++++++++++++++++++++++++++++++++- src/haptic/standard-vibcore.c | 593 ---------------------------------------- src/haptic/standard-vibcore.h | 32 --- src/haptic/standard.c | 11 +- 9 files changed, 565 insertions(+), 683 deletions(-) delete mode 100644 src/haptic/standard-vibcore.c delete mode 100644 src/haptic/standard-vibcore.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 8950c06..45ecc01 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,11 +21,11 @@ IF(DRIVER STREQUAL external) ELSEIF(DRIVER STREQUAL emulator) SET(SRCS ${SRCS} src/haptic/emulator.c) ELSEIF(DRIVER STREQUAL gpio) - SET(SRCS ${SRCS} src/haptic/gpio_haptic.c src/haptic/standard-vibcore.c) + SET(SRCS ${SRCS} src/haptic/gpio_haptic.c) ELSEIF(DRIVER STREQUAL standard) - SET(SRCS ${SRCS} src/haptic/standard.c src/haptic/standard-vibcore.c) + SET(SRCS ${SRCS} src/haptic/standard.c) ELSEIF(DRIVER STREQUAL circle) - SET(SRCS ${SRCS} src/haptic/circle.c src/haptic/standard-vibcore.c) + SET(SRCS ${SRCS} src/haptic/circle.c) ENDIF() INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/src) diff --git a/src/haptic/circle.c b/src/haptic/circle.c index 7fd46f1..a4af20f 100644 --- a/src/haptic/circle.c +++ b/src/haptic/circle.c @@ -29,7 +29,6 @@ #include "core/log.h" #include "core/list.h" #include "haptic.h" -#include "standard-vibcore.h" #define CIRCLE_ON_PATH "/sys/class/sec/motor/motor_on" #define CIRCLE_OFF_PATH "/sys/class/sec/motor/motor_off" @@ -250,9 +249,6 @@ static int stop_device(int device_handle) return -EPERM; } - /* Remove duration_timer for vibrate_effect */ - standard_vibrate_close(); - if (fd_stop < 0) { fd_stop = open(CIRCLE_OFF_PATH, O_RDONLY); if (fd_stop < 0) { @@ -278,9 +274,7 @@ static const struct haptic_plugin_ops default_plugin = { .get_device_count = get_device_count, .open_device = open_device, .close_device = close_device, - .vibrate_monotone = standard_vibrate_monotone, - .vibrate_effect = standard_vibrate_effect, - .is_supported = standard_is_supported, + .vibrate_monotone = vibrate_monotone, .stop_device = stop_device, }; @@ -293,8 +287,6 @@ static bool is_valid(void) return false; } - standard_config_parse(); - state = true; _I("Support wearable haptic device"); return true; @@ -302,7 +294,6 @@ static bool is_valid(void) static const struct haptic_plugin_ops *load(void) { - standard_set_vib_function(&vibrate_monotone); return &default_plugin; } diff --git a/src/haptic/emulator.c b/src/haptic/emulator.c index 6807391..fe40435 100644 --- a/src/haptic/emulator.c +++ b/src/haptic/emulator.c @@ -78,17 +78,6 @@ static int vibrate_monotone(int device_handle, int duration, int feedback, int p return 0; } -static int vibrate_effect(int device_handle, const char *pattern, int feedback, int priority) -{ - dd_list *elem; - - elem = DD_LIST_FIND(handle_list, (gpointer)(long)device_handle); - if (!elem) - return -EINVAL; - - return 0; -} - static int stop_device(int device_handle) { dd_list *elem; @@ -99,11 +88,6 @@ static int stop_device(int device_handle) return 0; } - -static int is_supported(const char *pattern) -{ - return 0; -} /* END: Haptic Module APIs */ static const struct haptic_plugin_ops default_plugin = { @@ -111,8 +95,6 @@ static const struct haptic_plugin_ops default_plugin = { .open_device = open_device, .close_device = close_device, .vibrate_monotone = vibrate_monotone, - .vibrate_effect = vibrate_effect, - .is_supported = is_supported, .stop_device = stop_device, }; diff --git a/src/haptic/gpio_haptic.c b/src/haptic/gpio_haptic.c index 2334598..a188b10 100644 --- a/src/haptic/gpio_haptic.c +++ b/src/haptic/gpio_haptic.c @@ -22,7 +22,6 @@ #include "core/log.h" #include "haptic.h" #include "peripheral_io.h" -#include "standard-vibcore.h" #define GPIO_I2C_BUS_INDEX 1 #define MAX_HAPIC 1 @@ -259,9 +258,6 @@ static int gpio_haptic_stop_device(int handle) return -EPERM; } - /* Remove duration_timer for vibrate_effect */ - standard_vibrate_close(); - if (device_handle == NULL) { if (peripheral_i2c_open(GPIO_I2C_BUS_INDEX, DRV2605L_DEFAULT_ADDR, &device_handle) < PERIPHERAL_ERROR_NONE) { _E("Failed to open I2C"); @@ -286,9 +282,7 @@ static const struct haptic_plugin_ops default_plugin = { .get_device_count = gpio_haptic_get_device_count, .open_device = gpio_haptic_open_device, .close_device = gpio_haptic_close_device, - .vibrate_monotone = standard_vibrate_monotone, - .vibrate_effect = standard_vibrate_effect, - .is_supported = standard_is_supported, + .vibrate_monotone = gpio_haptic_vibrate_monotone, .stop_device = gpio_haptic_stop_device, }; @@ -315,8 +309,6 @@ static bool is_valid(void) return false; } - standard_config_parse(); - state = true; _I("Support gpio haptic device"); return true; @@ -325,7 +317,6 @@ static bool is_valid(void) static const struct haptic_plugin_ops *load(void) { _I("gpio haptic device module loaded"); - standard_set_vib_function(&gpio_haptic_vibrate_monotone); return &default_plugin; } diff --git a/src/haptic/haptic-plugin-intf.h b/src/haptic/haptic-plugin-intf.h index 9d11f62..4c039a7 100644 --- a/src/haptic/haptic-plugin-intf.h +++ b/src/haptic/haptic-plugin-intf.h @@ -27,8 +27,6 @@ struct haptic_plugin_ops { int (*open_device) (int, int*); int (*close_device) (int); int (*vibrate_monotone) (int, int, int, int); - int (*vibrate_effect) (int, const char*, int, int); - int (*is_supported) (const char*); int (*stop_device) (int); }; diff --git a/src/haptic/haptic.c b/src/haptic/haptic.c index f1cdc8a..d253225 100644 --- a/src/haptic/haptic.c +++ b/src/haptic/haptic.c @@ -33,6 +33,10 @@ #include "core/config-parser.h" #include "haptic.h" +#define FEEDBACK_BASE_PATH "/usr/share/feedback/" +#define STANDARD_FILE_PATH FEEDBACK_BASE_PATH"vibration/" +#define VIBRATION_CONF_PATH FEEDBACK_BASE_PATH"vibration.conf" + #define HAPTIC_CONF_PATH "/etc/feedbackd/haptic.conf" #define SIGNAL_CHANGE_HARDKEY "ChangeHardkey" #define SIGNAL_POWEROFF_STATE "ChangeState" @@ -62,6 +66,32 @@ #define CHECK_VALID_OPS(ops, r) ((ops) ? true : !(r = -ENODEV)) #define RETRY_CNT 3 +#define INTENSITY_BASE_RATE (10000) +#define VALUE_MAX_LEN 10 +#define VIB_LOCK_TIMEOUT_MAX (300000) /* 5minutes */ + +/* + 1,A_W or A,A_W or 250D250W250D750W + + 85,10000, + 90,0, + 105,10000, + 0,end +*/ +struct vibration_config { + char *pattern; /* pattern name */ + char *standard; /* assigned standard pattern name */ + dd_list *data; /* duration_data list */ + unsigned int pattern_duration; + int unlimit; +}; + +struct duration_data { + int duration; + int intensity; + int wait; +}; + enum poweroff_type { POWER_OFF_NONE = 0, POWER_OFF_POPUP, @@ -92,6 +122,11 @@ struct vibrate_monotone_info { /* for playing */ static int g_handle; +/* pattern configuration list */ +static dd_list *vib_conf_list; + +guint duration_timer; + /* haptic operation variable */ static dd_list *h_head; static dd_list *haptic_handle_list; @@ -124,12 +159,353 @@ void remove_haptic(const struct haptic_ops *ops) DD_LIST_REMOVE(h_head, (void *)ops); } +static int insert_conf_data(dd_list **conf_data, struct duration_data *update) +{ + struct duration_data *data; + + data = (struct duration_data *)calloc(1, sizeof(struct duration_data)); + if (!data) { + _E("not enough memory"); + return -ENOMEM; + } + memcpy(data, update, sizeof(struct duration_data)); + /* insert vibration pattern data */ + // to debug : + // _D("%dD%dI%dF%dO%dW", data->duration, data->intensity, data->frequency, data->overdriving, data->wait); + DD_LIST_APPEND(*conf_data, data); + return 0; +} + +static void get_pattern_property(char **iter, char property, int *value) +{ + char *check; + unsigned long int val; + + check = strchr(*iter, property); + if (!check) + return; + + *check = '\0'; + val = strtoul(*iter, NULL, 10); + if (errno == EINVAL || errno == ERANGE) { + val = 0; + _E("Failed to get value of %s: %d", *iter, errno); + } + if (val > VIB_LOCK_TIMEOUT_MAX) + val = VIB_LOCK_TIMEOUT_MAX; + + *value = (int)val; + + *iter = check + 1; +} + +/* [A]xxxDxxxIxxxFxxxOxxxW format */ +static int insert_raw_data_format(dd_list **conf_data, char *value) +{ + struct duration_data update = {0, }; + char *iter; + char *end; + int pattern_duration = 0; + + if (!value) + return insert_conf_data(conf_data, &update); + if (!conf_data) { + _E("Invalid parameter: Configuration list is null"); + return -EINVAL; + } + + iter = value; + end = iter + strlen(iter); + while (iter < end) { + memset(&update, 0, sizeof(struct duration_data)); + + get_pattern_property(&iter, 'D', &update.duration); + get_pattern_property(&iter, 'I', &update.intensity); + if (update.intensity > INTENSITY_BASE_RATE) + update.intensity = INTENSITY_BASE_RATE; + get_pattern_property(&iter, 'W', &update.wait); + + if (update.duration == 0 && update.wait == 0) { + _D("Pattern duration is zero."); + break; + } + + pattern_duration += (update.duration + update.wait); + if (pattern_duration > VIB_LOCK_TIMEOUT_MAX) { + _D("Max pattern duration"); + pattern_duration = VIB_LOCK_TIMEOUT_MAX; + } + + if (insert_conf_data(conf_data, &update) < 0) + return -EINVAL; + } + + return pattern_duration; +} + +static int get_config_data(int count, bool *packed, char *val, unsigned int *pattern_duration, struct duration_data *update) +{ + static int duration = 0; + int value; + + if (count > 2 || count <= 0) { + _E("Invalid parameter: count is invalid"); + return -EINVAL; + } + + if (!packed || !val || !pattern_duration || !update) { + _E("Invalid parameter: %p %p %p %p", packed, val, pattern_duration, update); + return -EINVAL; + } + + get_pattern_property(&val, 'C', &value); + + if (count == 1) { + duration = value; + *pattern_duration += duration; + if (*pattern_duration > VIB_LOCK_TIMEOUT_MAX) { + _D("Max pattern duration"); + *pattern_duration = VIB_LOCK_TIMEOUT_MAX; + + } + return count; + } + + if (value > INTENSITY_BASE_RATE) + value = INTENSITY_BASE_RATE; + if (*packed == false) { + update->duration = duration; + update->intensity = value; + *packed = true; + return 0; + } + if (value == 0) + update->wait = duration; + else + update->wait = 0; + *packed = false; + duration = 0; + + return -1; +} + +/* + duration, intensity, frequency, overdriving + waiting duration, intensity=0, frequency, overdriving + 85,10000, + 90,0, + 105,10000, + 0,end +*/ +static int load_standard_format(const char *pattern) +{ + struct duration_data update = {0, }; + bool packed = false; + struct vibration_config *conf; + int ret = 0, count = 0, end = 2; + int index = 0; + int fd; + char path[PATH_MAX], elem, val[VALUE_MAX_LEN] = {0, }; + + snprintf(path, sizeof(path), STANDARD_FILE_PATH"%s", pattern); + fd = open(path, O_RDONLY); + if (fd < 0) + return -ENOENT; + + conf = (struct vibration_config *)calloc(1, sizeof(struct vibration_config)); + if (!conf) { + _E("fail to alloc"); + ret = -errno; + goto error_out; + } + + conf->pattern = strdup(pattern); + if (!conf->pattern) { + _E("fail to copy %s pattern data", pattern); + ret = -errno; + goto error_out; + } + + /* make feedback pattern(xDxIxFxOxW) format from d,i,f,o, */ + while (read(fd, &elem, 1) != 0) { + if (end == 0) { + if (insert_conf_data(&conf->data, &update) < 0) + goto error_out; + break; + } + if (elem == 'e' || elem == 'n' || elem == 'd') { + end--; + continue; + } + if (elem == '\n') { + count = 0; + continue; + } + if (elem == ',') { + count++; + val[index] = 'C'; + index = 0; + + ret = get_config_data(count, &packed, val, &(conf->pattern_duration), &update); + if (ret < 0) { + if (ret == -EINVAL) + break; + if (insert_conf_data(&conf->data, &update) < 0) + goto error_out; + memset(&update, 0, sizeof(struct duration_data)); + } else + count = ret; + } else { + if (index < (VALUE_MAX_LEN - 2)) /* Temporal limit */ + val[index++] = elem; + else + _E("Pattern %s is out of bound: %s", pattern, val); + } + } + close(fd); + DD_LIST_APPEND(vib_conf_list, conf); + return ret; + +error_out: + if (fd >= 0) + close(fd); + if (conf) { + if (conf->pattern) + free(conf->pattern); + free(conf); + } + return -ENOENT; +} + +static int vibration_load_config(struct parse_result *result, void *user_data) +{ + struct vibration_config *conf; + char *value; + char *check; + int len; + int duration; + + if (!result) + return 0; + + if (!MATCH(result->section, "Vibration")) + return 0; + + + if (!result->name || !result->value) + return 0; + + conf = (struct vibration_config *)calloc(1, sizeof(struct vibration_config)); + if (!conf) { + _E("fail to alloc"); + return -ENOMEM; + } + + conf->pattern_duration = 0; + conf->pattern = strdup(result->name); + if (!conf->pattern) { + _E("fail to copy %s pattern data", result->name); + goto error_out; + } + + value = result->value; + len = strlen(value); + + if (len == 0) { + if (insert_raw_data_format(&conf->data, NULL) < 0) + goto error_out; + DD_LIST_APPEND(vib_conf_list, conf); + return 0; + } + + /* Load Standard Pattern Name */ + /* value: 1,A_W or A,A_W */ + if ((check = strchr(value, ','))) { + *check = '\0'; + if (strncmp(value, "A", 1) == 0) + conf->unlimit = 1; + value = check + 1; + conf->standard = strdup(value); + if (!conf->standard) { + _E("fail to copy standard name"); + goto error_out; + } + DD_LIST_APPEND(vib_conf_list, conf); + return 0; + } + + /* value : A100D or 100D0W or 250D250W250D750W */ + /* Load Vibration Pattern Data */ + check = strchr(value, 'A'); + if (check) { + *check = '\0'; + conf->unlimit = 1; + if (!value) + len = len - 1; + else + len = len - strlen(value) - 1; + value = check + 1; + } + duration = insert_raw_data_format(&conf->data, value); + if (duration < 0) { + conf->pattern_duration = 0; + goto error_out; + } else + conf->pattern_duration = duration; + DD_LIST_APPEND(vib_conf_list, conf); + + return 0; + +error_out: + if (conf) { + if (conf->pattern) + free(conf->pattern); + if (conf->standard) + free(conf->standard); + } + return -ENOMEM; +} + +static void load_standard_vibration_patterns(void) +{ + DIR *dir; + struct dirent *dent; + int ret; + + dir = opendir(STANDARD_FILE_PATH); + if (!dir) { + _E("Failed to load %s Use default value!", STANDARD_FILE_PATH); + return; + } + while ((dent = readdir(dir))) { + if (dent->d_type == DT_DIR) + continue; + ret = load_standard_format(dent->d_name); + if (ret < 0) + _E("Failed to parse %s: %d", dent->d_name, ret); + } + closedir(dir); + _D("Success to load %s", STANDARD_FILE_PATH); +} + +void pattern_config_parse(void) +{ + int ret; + + ret = config_parse(VIBRATION_CONF_PATH, vibration_load_config, NULL); + if (ret < 0) + _E("Failed to load %s, %d Use default value!", VIBRATION_CONF_PATH, ret); + + load_standard_vibration_patterns(); +} + static int haptic_module_load(void) { struct haptic_ops *ops; dd_list *elem; int r; + pattern_config_parse(); /* find valid plugin */ DD_LIST_FOREACH(h_head, elem, ops) { if (ops->is_valid && ops->is_valid()) { @@ -317,6 +693,20 @@ exit: return g_variant_new("(i)", ret); } +int clear_current_data(void) +{ + cur_h_data.handle = INVALID_HANDLE; + cur_h_data.priority = PRIORITY_MIN; + + if (duration_timer) { + _I("Remove duration_timer"); + g_source_remove(duration_timer); + duration_timer = 0; + } + + return 0; +} + GVariant *hdbus_close_device(GDBusConnection *conn, const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) @@ -341,6 +731,11 @@ GVariant *hdbus_close_device(GDBusConnection *conn, if (ret < 0) goto exit; + if (cur_h_data.handle == handle) { + /* Remove duration_timer for vibrate_effect */ + clear_current_data(); + } + info = get_matched_haptic_info(sender); if (!info) { _E("fail to find the matched haptic info."); @@ -359,14 +754,31 @@ exit: static void vibrate_monotone_idler_cb(void *data) { struct vibrate_monotone_info *vibrate_info; + int ret; if (!data) return; vibrate_info = (struct vibrate_monotone_info *)data; - h_ops->vibrate_monotone(vibrate_info->handle, vibrate_info->duration, - vibrate_info->level, vibrate_info->priority); + if (vibrate_info->priority < cur_h_data.priority) { + _I("Handle %d skip low priority(pre:%d now:%d)", vibrate_info->handle, cur_h_data.priority, vibrate_info->priority); + free(vibrate_info); + return; + } + + cur_h_data.vibration_data = NULL; + cur_h_data.handle = vibrate_info->handle; + cur_h_data.level = vibrate_info->level; + cur_h_data.priority = vibrate_info->priority; + cur_h_data.stop = false; + cur_h_data.unlimit = false; + + ret = device_power_request_lock(POWER_LOCK_CPU, vibrate_info->duration); + if (ret != DEVICE_ERROR_NONE) + _E("Failed to request power lock"); + h_ops->vibrate_monotone(cur_h_data.handle, vibrate_info->duration, cur_h_data.level, cur_h_data.priority); + free(vibrate_info); } @@ -421,17 +833,134 @@ exit: return g_variant_new("(i)", ret); } +static gboolean haptic_duration_play(void *data) +{ + dd_list *head, *n, *next; + struct duration_data *node; + int level; + int ret = 0; + + if (duration_timer) { + g_source_remove(duration_timer); + duration_timer = 0; + } + + if (!data) { + if (cur_h_data.unlimit) /* In case of unlimit pattern, do not stop */ + head = cur_h_data.vibration_data; + else { + cur_h_data.handle = INVALID_HANDLE; + cur_h_data.priority = PRIORITY_MIN; + goto out; + } + } else + head = (dd_list *)data; + + if (cur_h_data.stop) { + _I("Stop currunt vibration"); + cur_h_data.stop = false; + cur_h_data.handle = INVALID_HANDLE; + cur_h_data.priority = PRIORITY_MIN; + goto out; + } + + DD_LIST_FOREACH_SAFE(head, n, next, node) { + _D("Handle %d play: %dms and Wait: %dms %s type", + cur_h_data.handle, node->duration, node->wait, + cur_h_data.unlimit ? "Unlimit" : "Once"); + if ((node->duration + node->wait) <= 0) { + if (!cur_h_data.unlimit) { + cur_h_data.handle = INVALID_HANDLE; + cur_h_data.priority = PRIORITY_MIN; + break; + } else { + next = cur_h_data.vibration_data; + continue; + } + } + + if (node->intensity) + level = (cur_h_data.level * node->intensity) / INTENSITY_BASE_RATE; + else + level = cur_h_data.level; + + duration_timer = g_timeout_add((node->duration + node->wait), haptic_duration_play, (void *)next); + + ret = h_ops->vibrate_monotone(cur_h_data.handle, node->duration, level, cur_h_data.priority); + + break; + } + if (ret != 0) { + _D("auto stop vibration"); + cur_h_data.stop = true; + } +out: + return G_SOURCE_REMOVE; +} + static void vibrate_effect_idler_cb(void *data) { struct vibrate_effect_info *vibrate_info; + dd_list *elem; + struct vibration_config *conf; + char pattern[PATH_MAX]; + int ret; + int unlimit = 0; if (!data) return; vibrate_info = (struct vibrate_effect_info *)data; - h_ops->vibrate_effect(vibrate_info->handle, vibrate_info->pattern, - vibrate_info->level, vibrate_info->priority); + if (!(vibrate_info->pattern)) { + free(vibrate_info); + return; + } + + /* Same or higher priority pattern should be played */ + if (vibrate_info->priority < cur_h_data.priority) { + _I("Handle %d skip low priority(pre:%d now:%d)", vibrate_info->handle, cur_h_data.priority, vibrate_info->priority); + goto out; + } + + snprintf(pattern, sizeof(pattern), "%s", vibrate_info->pattern); + DD_LIST_FOREACH(vib_conf_list, elem, conf) { + if (!conf->pattern) + continue; + if (strcmp(conf->pattern, pattern)) + continue; + if (conf->standard) { + unlimit = conf->unlimit; + snprintf(pattern, sizeof(pattern), "%s", conf->standard); + continue; + } + + if (unlimit) + cur_h_data.unlimit = unlimit; + else + cur_h_data.unlimit = conf->unlimit; + cur_h_data.vibration_data = conf->data; + cur_h_data.handle = vibrate_info->handle; + cur_h_data.level = vibrate_info->level; + cur_h_data.priority = vibrate_info->priority; + cur_h_data.stop = false; + _I("Handle %d play %s pri %d %s", cur_h_data.handle, conf->pattern, cur_h_data.priority, + cur_h_data.unlimit ? "Unlimit" : "Once"); + + if (conf->pattern_duration <= 0) + break; + + if (!cur_h_data.unlimit && conf->pattern_duration > 0) { + ret = device_power_request_lock(POWER_LOCK_CPU, (int)conf->pattern_duration); + if (ret != DEVICE_ERROR_NONE) + _E("Failed to request power lock"); + } + haptic_duration_play((void *)cur_h_data.vibration_data); + goto out; + } + _E("Handle %d %s is not supported", vibrate_info->handle, pattern); + +out: free(vibrate_info->pattern); free(vibrate_info); } @@ -513,6 +1042,9 @@ GVariant *hdbus_stop_device(GDBusConnection *conn, ret = h_ops->stop_device(handle); + /* Remove duration_timer for vibrate_effect */ + clear_current_data(); + exit: return g_variant_new("(i)", ret); } @@ -534,6 +1066,28 @@ GVariant *hdbus_show_handle_list(GDBusConnection *conn, return g_variant_new_tuple(NULL, 0); } +int pattern_is_supported(const char *pattern) +{ + dd_list *elem; + struct vibration_config *conf; + int ret; + + if (!pattern) + return -EINVAL; + + ret = 0; + DD_LIST_FOREACH(vib_conf_list, elem, conf) { + if (!conf->pattern) + continue; + if (!strcmp(conf->pattern, pattern)) { + ret = true; + break; + } + } + + return ret; +} + GVariant *hdbus_pattern_is_supported(GDBusConnection *conn, const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) @@ -550,7 +1104,7 @@ GVariant *hdbus_pattern_is_supported(GDBusConnection *conn, g_variant_get(param, "(s)", &data); - ret = h_ops->is_supported(data); + ret = pattern_is_supported(data); _I("%s is supported : %d", data, ret); diff --git a/src/haptic/standard-vibcore.c b/src/haptic/standard-vibcore.c deleted file mode 100644 index 66e3eae..0000000 --- a/src/haptic/standard-vibcore.c +++ /dev/null @@ -1,593 +0,0 @@ -/* - * feedbackd - * - * Copyright (c) 2016 - 2017 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 -#include -#include -#include -#include - -#include "core/log.h" -#include "core/list.h" -#include "core/config-parser.h" -#include "haptic.h" -#include "standard-vibcore.h" - -#define FEEDBACK_BASE_PATH "/usr/share/feedback/" -#define STANDARD_FILE_PATH FEEDBACK_BASE_PATH"vibration/" -#define VIBRATION_CONF_PATH FEEDBACK_BASE_PATH"vibration.conf" - -#define INTENSITY_BASE_RATE (10000) -#define VALUE_MAX_LEN 10 -#define VIB_LOCK_TIMEOUT_MAX (300000) /* 5minutes */ - -/* - 1,A_W or A,A_W or 250D250W250D750W - - 85,10000, - 90,0, - 105,10000, - 0,end -*/ -struct vibration_config { - char *pattern; /* pattern name */ - char *standard; /* assigned standard pattern name */ - dd_list *data; /* duration_data list */ - unsigned int pattern_duration; - int unlimit; -}; - -struct duration_data { - int duration; - int intensity; - int wait; -}; - -static dd_list *vib_conf_list; -static guint duration_timer; - -static t_vibrate_monotone real_vibrate_monotone; - -static int insert_conf_data(dd_list **conf_data, struct duration_data *update) -{ - struct duration_data *data; - - data = (struct duration_data *)calloc(1, sizeof(struct duration_data)); - if (!data) { - _E("not enough memory"); - return -ENOMEM; - } - memcpy(data, update, sizeof(struct duration_data)); - /* insert vibration pattern data */ - // to debug : - // _D("%dD%dI%dF%dO%dW", data->duration, data->intensity, data->frequency, data->overdriving, data->wait); - DD_LIST_APPEND(*conf_data, data); - return 0; -} - -static void get_pattern_property(char **iter, char property, int *value) -{ - char *check; - unsigned long int val; - - check = strchr(*iter, property); - if (!check) - return; - - *check = '\0'; - val = strtoul(*iter, NULL, 10); - if (errno == EINVAL || errno == ERANGE) { - val = 0; - _E("Failed to get value of %s: %d", *iter, errno); - } - if (val > VIB_LOCK_TIMEOUT_MAX) - val = VIB_LOCK_TIMEOUT_MAX; - - *value = (int)val; - - *iter = check + 1; -} - -/* [A]xxxDxxxIxxxFxxxOxxxW format */ -static int insert_raw_data_format(dd_list **conf_data, char *value) -{ - struct duration_data update = {0, }; - char *iter; - char *end; - int pattern_duration = 0; - - if (!value) - return insert_conf_data(conf_data, &update); - if (!conf_data) { - _E("Invalid parameter: Configuration list is null"); - return -EINVAL; - } - - iter = value; - end = iter + strlen(iter); - while (iter < end) { - memset(&update, 0, sizeof(struct duration_data)); - - get_pattern_property(&iter, 'D', &update.duration); - get_pattern_property(&iter, 'I', &update.intensity); - if (update.intensity > INTENSITY_BASE_RATE) - update.intensity = INTENSITY_BASE_RATE; - get_pattern_property(&iter, 'W', &update.wait); - - if (update.duration == 0 && update.wait == 0) { - _D("Pattern duration is zero."); - break; - } - - pattern_duration += (update.duration + update.wait); - if (pattern_duration > VIB_LOCK_TIMEOUT_MAX) { - _D("Max pattern duration"); - pattern_duration = VIB_LOCK_TIMEOUT_MAX; - } - - if (insert_conf_data(conf_data, &update) < 0) - return -EINVAL; - } - - return pattern_duration; -} - -static int get_config_data(int count, bool *packed, char *val, unsigned int *pattern_duration, struct duration_data *update) -{ - static int duration = 0; - int value; - - if (count > 2 || count <= 0) { - _E("Invalid parameter: count is invalid"); - return -EINVAL; - } - - if (!packed || !val || !pattern_duration || !update) { - _E("Invalid parameter: %p %p %p %p", packed, val, pattern_duration, update); - return -EINVAL; - } - - get_pattern_property(&val, 'C', &value); - - if (count == 1) { - duration = value; - *pattern_duration += duration; - if (*pattern_duration > VIB_LOCK_TIMEOUT_MAX) { - _D("Max pattern duration"); - *pattern_duration = VIB_LOCK_TIMEOUT_MAX; - - } - return count; - } - - if (value > INTENSITY_BASE_RATE) - value = INTENSITY_BASE_RATE; - if (*packed == false) { - update->duration = duration; - update->intensity = value; - *packed = true; - return 0; - } - if (value == 0) - update->wait = duration; - else - update->wait = 0; - *packed = false; - duration = 0; - - return -1; -} - -/* - duration, intensity, frequency, overdriving - waiting duration, intensity=0, frequency, overdriving - 85,10000, - 90,0, - 105,10000, - 0,end -*/ -static int load_standard_format(const char *pattern) -{ - struct duration_data update = {0, }; - bool packed = false; - struct vibration_config *conf; - int ret = 0, count = 0, end = 2; - int index = 0; - int fd; - char path[PATH_MAX], elem, val[VALUE_MAX_LEN] = {0, }; - - snprintf(path, sizeof(path), STANDARD_FILE_PATH"%s", pattern); - fd = open(path, O_RDONLY); - if (fd < 0) - return -ENOENT; - - conf = (struct vibration_config *)calloc(1, sizeof(struct vibration_config)); - if (!conf) { - _E("fail to alloc"); - ret = -errno; - goto error_out; - } - - conf->pattern = strdup(pattern); - if (!conf->pattern) { - _E("fail to copy %s pattern data", pattern); - ret = -errno; - goto error_out; - } - - /* make feedback pattern(xDxIxFxOxW) format from d,i,f,o, */ - while (read(fd, &elem, 1) != 0) { - if (end == 0) { - if (insert_conf_data(&conf->data, &update) < 0) - goto error_out; - break; - } - if (elem == 'e' || elem == 'n' || elem == 'd') { - end--; - continue; - } - if (elem == '\n') { - count = 0; - continue; - } - if (elem == ',') { - count++; - val[index] = 'C'; - index = 0; - - ret = get_config_data(count, &packed, val, &(conf->pattern_duration), &update); - if (ret < 0) { - if (ret == -EINVAL) - break; - if (insert_conf_data(&conf->data, &update) < 0) - goto error_out; - memset(&update, 0, sizeof(struct duration_data)); - } else - count = ret; - } else { - if (index < (VALUE_MAX_LEN - 2)) /* Temporal limit */ - val[index++] = elem; - else - _E("Pattern %s is out of bound: %s", pattern, val); - } - } - close(fd); - DD_LIST_APPEND(vib_conf_list, conf); - return ret; - -error_out: - if (fd >= 0) - close(fd); - if (conf) { - if (conf->pattern) - free(conf->pattern); - free(conf); - } - return -ENOENT; -} - -static int vibration_load_config(struct parse_result *result, void *user_data) -{ - struct vibration_config *conf; - char *value; - char *check; - int len; - int duration; - - if (!result) - return 0; - - if (!MATCH(result->section, "Vibration")) - return 0; - - - if (!result->name || !result->value) - return 0; - - conf = (struct vibration_config *)calloc(1, sizeof(struct vibration_config)); - if (!conf) { - _E("fail to alloc"); - return -ENOMEM; - } - - conf->pattern_duration = 0; - conf->pattern = strdup(result->name); - if (!conf->pattern) { - _E("fail to copy %s pattern data", result->name); - goto error_out; - } - - value = result->value; - len = strlen(value); - - if (len == 0) { - if (insert_raw_data_format(&conf->data, NULL) < 0) - goto error_out; - DD_LIST_APPEND(vib_conf_list, conf); - return 0; - } - - /* Load Standard Pattern Name */ - /* value: 1,A_W or A,A_W */ - if ((check = strchr(value, ','))) { - *check = '\0'; - if (strncmp(value, "A", 1) == 0) - conf->unlimit = 1; - value = check + 1; - conf->standard = strdup(value); - if (!conf->standard) { - _E("fail to copy standard name"); - goto error_out; - } - DD_LIST_APPEND(vib_conf_list, conf); - return 0; - } - - /* value : A100D or 100D0W or 250D250W250D750W */ - /* Load Vibration Pattern Data */ - check = strchr(value, 'A'); - if (check) { - *check = '\0'; - conf->unlimit = 1; - if (!value) - len = len - 1; - else - len = len - strlen(value) - 1; - value = check + 1; - } - duration = insert_raw_data_format(&conf->data, value); - if (duration < 0) { - conf->pattern_duration = 0; - goto error_out; - } else - conf->pattern_duration = duration; - DD_LIST_APPEND(vib_conf_list, conf); - - return 0; - -error_out: - if (conf) { - if (conf->pattern) - free(conf->pattern); - if (conf->standard) - free(conf->standard); - } - return -ENOMEM; -} - -static void load_standard_vibration_patterns(void) -{ - DIR *dir; - struct dirent *dent; - int ret; - - dir = opendir(STANDARD_FILE_PATH); - if (!dir) { - _E("Failed to load %s Use default value!", STANDARD_FILE_PATH); - return; - } - while ((dent = readdir(dir))) { - if (dent->d_type == DT_DIR) - continue; - ret = load_standard_format(dent->d_name); - if (ret < 0) - _E("Failed to parse %s: %d", dent->d_name, ret); - } - closedir(dir); - _D("Success to load %s", STANDARD_FILE_PATH); -} - -void standard_config_parse(void) -{ - int ret; - - ret = config_parse(VIBRATION_CONF_PATH, vibration_load_config, NULL); - if (ret < 0) - _E("Failed to load %s, %d Use default value!", VIBRATION_CONF_PATH, ret); - - load_standard_vibration_patterns(); -} - -int standard_is_supported(const char *pattern) -{ - dd_list *elem; - struct vibration_config *conf; - int ret; - - if (!pattern) - return -EINVAL; - - ret = 0; - DD_LIST_FOREACH(vib_conf_list, elem, conf) { - if (!conf->pattern) - continue; - if (!strcmp(conf->pattern, pattern)) { - ret = true; - break; - } - } - - return ret; -} - -static gboolean haptic_duration_play(void *data) -{ - dd_list *head, *n, *next; - struct duration_data *node; - int level; - int ret = 0; - - if (duration_timer) { - g_source_remove(duration_timer); - duration_timer = 0; - } - - if (!data) { - if (cur_h_data.unlimit) /* In case of unlimit pattern, do not stop */ - head = cur_h_data.vibration_data; - else { - cur_h_data.handle = INVALID_HANDLE; - cur_h_data.priority = PRIORITY_MIN; - goto out; - } - } else - head = (dd_list *)data; - - if (cur_h_data.stop) { - _I("Stop currunt vibration"); - cur_h_data.stop = false; - cur_h_data.handle = INVALID_HANDLE; - cur_h_data.priority = PRIORITY_MIN; - goto out; - } - - DD_LIST_FOREACH_SAFE(head, n, next, node) { - _D("Handle %d play: %dms and Wait: %dms %s type", - cur_h_data.handle, node->duration, node->wait, - cur_h_data.unlimit ? "Unlimit" : "Once"); - if ((node->duration + node->wait) <= 0) { - if (!cur_h_data.unlimit) { - cur_h_data.handle = INVALID_HANDLE; - cur_h_data.priority = PRIORITY_MIN; - break; - } else { - next = cur_h_data.vibration_data; - continue; - } - } - - if (node->intensity) - level = (cur_h_data.level * node->intensity) / INTENSITY_BASE_RATE; - else - level = cur_h_data.level; - - duration_timer = g_timeout_add((node->duration + node->wait), haptic_duration_play, (void *)next); - - ret = real_vibrate_monotone(cur_h_data.handle, node->duration, level, cur_h_data.priority); - - break; - } - if (ret != 0) { - _D("auto stop vibration"); - cur_h_data.stop = true; - } -out: - return G_SOURCE_REMOVE; -} - -int standard_set_vib_function(t_vibrate_monotone func) -{ - real_vibrate_monotone = func; - return 0; -} - -int standard_vibrate_monotone(int device_handle, int duration, int feedback, int priority) -{ - int ret; - - if (priority < cur_h_data.priority) { - _I("Handle %d skip low priority(pre:%d now:%d)", device_handle, cur_h_data.priority, priority); - return 0; - } - - cur_h_data.vibration_data = NULL; - cur_h_data.handle = device_handle; - cur_h_data.level = feedback; - cur_h_data.priority = priority; - cur_h_data.stop = false; - cur_h_data.unlimit = false; - - ret = device_power_request_lock(POWER_LOCK_CPU, duration); - if (ret != DEVICE_ERROR_NONE) - _E("Failed to request power lock"); - real_vibrate_monotone(cur_h_data.handle, duration, cur_h_data.level, cur_h_data.priority); - - return 0; -} - -int standard_vibrate_effect(int device_handle, const char *requested_pattern, int feedback, int priority) -{ - dd_list *elem; - struct vibration_config *conf; - char pattern[PATH_MAX]; - int ret; - int unlimit = 0; - - if (device_handle < 0 || !requested_pattern) - return -EINVAL; - - /* Same or higher priority pattern should be played */ - if (priority < cur_h_data.priority) { - _I("Handle %d skip low priority(pre:%d now:%d)", device_handle, cur_h_data.priority, priority); - return 0; - } - - snprintf(pattern, sizeof(pattern), "%s", requested_pattern); - DD_LIST_FOREACH(vib_conf_list, elem, conf) { - if (!conf->pattern) - continue; - if (strcmp(conf->pattern, pattern)) - continue; - if (conf->standard) { - unlimit = conf->unlimit; - snprintf(pattern, sizeof(pattern), "%s", conf->standard); - continue; - } - - if (unlimit) - cur_h_data.unlimit = unlimit; - else - cur_h_data.unlimit = conf->unlimit; - cur_h_data.vibration_data = conf->data; - cur_h_data.handle = device_handle; - cur_h_data.level = feedback; - cur_h_data.priority = priority; - cur_h_data.stop = false; - _I("Handle %d play %s pri %d %s", cur_h_data.handle, conf->pattern, cur_h_data.priority, - cur_h_data.unlimit ? "Unlimit" : "Once"); - - if (conf->pattern_duration <= 0) - break; - - if (!cur_h_data.unlimit && conf->pattern_duration > 0) { - ret = device_power_request_lock(POWER_LOCK_CPU, (int)conf->pattern_duration); - if (ret != DEVICE_ERROR_NONE) - _E("Failed to request power lock"); - } - haptic_duration_play((void *)cur_h_data.vibration_data); - return 0; - } - _E("Handld %d %s is not supported", device_handle, pattern); - - return 0; -} - -int standard_vibrate_close(void) -{ - cur_h_data.handle = INVALID_HANDLE; - cur_h_data.priority = PRIORITY_MIN; - - if (duration_timer) { - _I("Remove duration_timer"); - g_source_remove(duration_timer); - duration_timer = 0; - } - - return 0; -} - diff --git a/src/haptic/standard-vibcore.h b/src/haptic/standard-vibcore.h deleted file mode 100644 index dd0c071..0000000 --- a/src/haptic/standard-vibcore.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * feedbackd - * - * Copyright (c) 2016 - 2017 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 __FEEDBACKD_STANDARD_VIBCORE_H__ -#define __FEEDBACKD_STANDARD_VIBCORE_H__ - -typedef int (*t_vibrate_monotone)(int device_handle, int duration, int feedback, int priority); - -void standard_config_parse(void); -int standard_is_supported(const char *pattern); -int standard_vibrate_monotone(int device_handle, int duration, int feedback, int priority); -int standard_vibrate_effect(int device_handle, const char *pattern, int feedback, int priority); -int standard_set_vib_function(t_vibrate_monotone func); -int standard_vibrate_close(void); - -#endif /* __FEEDBACKD_STANDARD_VIBCORE_H__ */ diff --git a/src/haptic/standard.c b/src/haptic/standard.c index f5e43b4..871fd2c 100644 --- a/src/haptic/standard.c +++ b/src/haptic/standard.c @@ -32,7 +32,6 @@ #include "core/log.h" #include "core/list.h" #include "haptic.h" -#include "standard-vibcore.h" #define MAX_MAGNITUDE 0xFFFF #define PERIODIC_MAX_MAGNITUDE 0x7FFF /* 0.5 * MAX_MAGNITUDE */ @@ -494,9 +493,6 @@ static int stop_device(int device_handle) return -EPERM; } - /* Remove duration_timer for vibrate_effect */ - standard_vibrate_close(); - /* stop effect */ r = ff_stop(ff_fd, &info->effect); if (r < 0) @@ -518,9 +514,7 @@ static const struct haptic_plugin_ops default_plugin = { .get_device_count = get_device_count, .open_device = open_device, .close_device = close_device, - .vibrate_monotone = standard_vibrate_monotone, - .vibrate_effect = standard_vibrate_effect, - .is_supported = standard_is_supported, + .vibrate_monotone = vibrate_monotone, .stop_device = stop_device, }; @@ -534,15 +528,12 @@ static bool is_valid(void) return false; } - standard_config_parse(); - _I("Support standard haptic device"); return true; } static const struct haptic_plugin_ops *load(void) { - standard_set_vib_function(&vibrate_monotone); return &default_plugin; } -- 2.7.4 From 97153a8ef269c3590bd8926c26d3c9de242b36be Mon Sep 17 00:00:00 2001 From: "pr.jung" Date: Thu, 21 Feb 2019 17:47:42 +0900 Subject: [PATCH 08/16] Initialize current vibration handle and priority when vibration is done Change-Id: I26221add67c70cab7dc0e09948f03903d6060a4c Signed-off-by: pr.jung --- src/haptic/haptic.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/haptic/haptic.c b/src/haptic/haptic.c index d253225..fa030ea 100644 --- a/src/haptic/haptic.c +++ b/src/haptic/haptic.c @@ -751,6 +751,19 @@ exit: return g_variant_new("(i)", ret); } +static gboolean _cb(void *data) +{ + if (duration_timer) { + g_source_remove(duration_timer); + duration_timer = 0; + } + + cur_h_data.handle = INVALID_HANDLE; + cur_h_data.priority = PRIORITY_MIN; + + return G_SOURCE_REMOVE; +} + static void vibrate_monotone_idler_cb(void *data) { struct vibrate_monotone_info *vibrate_info; @@ -767,6 +780,11 @@ static void vibrate_monotone_idler_cb(void *data) return; } + if (duration_timer) { + g_source_remove(duration_timer); + duration_timer = 0; + } + cur_h_data.vibration_data = NULL; cur_h_data.handle = vibrate_info->handle; cur_h_data.level = vibrate_info->level; @@ -777,6 +795,8 @@ static void vibrate_monotone_idler_cb(void *data) ret = device_power_request_lock(POWER_LOCK_CPU, vibrate_info->duration); if (ret != DEVICE_ERROR_NONE) _E("Failed to request power lock"); + + duration_timer = g_timeout_add(vibrate_info->duration, _cb, NULL); h_ops->vibrate_monotone(cur_h_data.handle, vibrate_info->duration, cur_h_data.level, cur_h_data.priority); free(vibrate_info); -- 2.7.4 From 95e586c318acf27066a59a1136f7af1398110bef Mon Sep 17 00:00:00 2001 From: Yunmi Ha Date: Tue, 26 Feb 2019 15:41:29 +0900 Subject: [PATCH 09/16] Apply consistent log messages. 1. First letter to uppercase. 2. Period at the end. 3. Rearrange parameters. Change-Id: I2619def99f7a1eb80020894a27f7d0d39232eda7 Signed-off-by: Yunmi Ha --- src/auto-test/haptic.c | 48 ++++++++++----------- src/auto-test/main.c | 4 +- src/auto-test/test.c | 6 +-- src/core/common.c | 2 +- src/core/config-parser.c | 6 +-- src/core/device-idler.c | 6 +-- src/core/main.c | 12 +++--- src/haptic/circle.c | 42 +++++++++--------- src/haptic/emulator.c | 4 +- src/haptic/external.c | 12 +++--- src/haptic/gpio_haptic.c | 42 +++++++++--------- src/haptic/haptic.c | 110 +++++++++++++++++++++++------------------------ src/haptic/standard.c | 22 +++++----- 13 files changed, 158 insertions(+), 158 deletions(-) mode change 100644 => 100755 src/auto-test/haptic.c mode change 100644 => 100755 src/auto-test/main.c mode change 100644 => 100755 src/auto-test/test.c mode change 100644 => 100755 src/core/common.c mode change 100644 => 100755 src/core/config-parser.c mode change 100644 => 100755 src/core/device-idler.c mode change 100644 => 100755 src/core/main.c mode change 100644 => 100755 src/haptic/circle.c mode change 100644 => 100755 src/haptic/emulator.c mode change 100644 => 100755 src/haptic/external.c mode change 100644 => 100755 src/haptic/gpio_haptic.c mode change 100644 => 100755 src/haptic/haptic.c mode change 100644 => 100755 src/haptic/standard.c diff --git a/src/auto-test/haptic.c b/src/auto-test/haptic.c old mode 100644 new mode 100755 index 004d72a..fb9195f --- a/src/auto-test/haptic.c +++ b/src/auto-test/haptic.c @@ -39,22 +39,22 @@ static bool request_haptic_method(const char *method, GVariant *param) method, param); if (!msg) { - _E("fail (%s): no reply", method); + _E("Failed to call %s: no reply", method); return ret; } if (!dh_get_param_from_var(msg, "(i)", &val)) - _E("fail (%s): no message", method); + _E("Failed to call %s: no message", method); else { if ((val == -ENOTSUP) || (val == -ENOSYS)) { - _I("Not supported feature! (%s): %d", method, val); + _I("Not supported feature(%s): %d", method, val); ret = TRUE; } else if (val == -ENODEV) { - _E("fail (%s): device open fail (%d)", method, val); + _E("Failed to call %s. Device open fail: %d", method, val); } else if (val < 0) { - _E("fail (%s): returned fail (%d)", method, val); + _E("Failed to call %s. Returned fail: %d", method, val); } else { - _I("success (%s): %d", method, val); + _I("Success. %s: %d", method, val); ret = TRUE; } } @@ -89,12 +89,12 @@ static bool haptic_closedevice() g_variant_new("(i)", 0)); if (!msg) { - _E("fail (%s): no reply", METHOD_HAPTIC_OPENDEVICE); + _E("Failed to call dbus method(%s): no reply", METHOD_HAPTIC_OPENDEVICE); return ret; } if (!dh_get_param_from_var(msg, "(i)", &handle)) { - _E("fail (%s): no message", METHOD_HAPTIC_OPENDEVICE); + _E("Failed to call dbus method(%s): no message", METHOD_HAPTIC_OPENDEVICE); return ret; } g_variant_unref(msg); @@ -116,12 +116,12 @@ static bool haptic_vibratemonotone(int duration, int level, int priority) g_variant_new("(i)", 0)); if (!msg) { - _E("fail (%s): no reply", METHOD_HAPTIC_OPENDEVICE); + _E("Failed to call dbus method(%s): no reply", METHOD_HAPTIC_OPENDEVICE); return ret; } if (!dh_get_param_from_var(msg, "(i)", &handle)) { - _E("fail (%s): no message", METHOD_HAPTIC_OPENDEVICE); + _E("Failed to call dbus method(%s): no message", METHOD_HAPTIC_OPENDEVICE); return ret; } g_variant_unref(msg); @@ -143,12 +143,12 @@ static bool haptic_vibrateeffect(char *pattern, int level, int priority) g_variant_new("(i)", 0)); if (!msg) { - _E("fail (%s): no reply", METHOD_HAPTIC_OPENDEVICE); + _E("Failed to call dbus method(%s): no reply", METHOD_HAPTIC_OPENDEVICE); return ret; } if (!dh_get_param_from_var(msg, "(i)", &handle)) { - _E("fail (%s): no message", METHOD_HAPTIC_OPENDEVICE); + _E("Failed to call dbus method(%s): no message", METHOD_HAPTIC_OPENDEVICE); return ret; } g_variant_unref(msg); @@ -171,12 +171,12 @@ static bool haptic_stopdevice() g_variant_new("(i)", 0)); if (!msg) { - _E("fail (%s): no reply", METHOD_HAPTIC_OPENDEVICE); + _E("Failed to call dbus method(%s): no reply", METHOD_HAPTIC_OPENDEVICE); return ret; } if (!dh_get_param_from_var(msg, "(i)", &handle)) { - _E("fail (%s): no message", METHOD_HAPTIC_OPENDEVICE); + _E("Failed to call dbus method(%s): no message", METHOD_HAPTIC_OPENDEVICE); return ret; } g_variant_unref(msg); @@ -188,14 +188,14 @@ static bool haptic_stopdevice() g_variant_new("(uiii)", handle, 1000, 100, 0)); if (!msg) { - _E("fail (%s): no reply", METHOD_HAPTIC_VIBRATEMONOTONE); + _E("Failed to call dbus method(%s): no reply", METHOD_HAPTIC_VIBRATEMONOTONE); return ret; } - _D("sleep 300ms"); + _D("Sleep 300ms."); time.tv_nsec = 300 * NANO_SECOND_MULTIPLIER; nanosleep(&time, NULL); - _D("wakeup"); + _D("Wakeup."); return request_haptic_method(METHOD_HAPTIC_STOPDEVICE, g_variant_new("(u)", handle)); } @@ -218,7 +218,7 @@ static bool haptic_showhandlelist() NULL); if (!msg) { - _E("fail (%s): no reply", METHOD_HAPTIC_OPENDEVICE); + _E("Failed to call dbus method(%s): no reply", METHOD_HAPTIC_OPENDEVICE); return FALSE; } g_variant_unref(msg); @@ -262,16 +262,16 @@ static void haptic_init(void *data) int success = 0; int fail = 0; - _I("start test"); + _I("Start test."); haptic_test_all(&success, &fail); - _I("Total: %d, Success: %d, Fail: %d", success+fail, success, fail); + _I("Total=%d Success=%d Fail=%d", success+fail, success, fail); } static void haptic_exit(void *data) { - _I("end test"); + _I("End test."); } static int haptic_unit(int argc, char **argv) @@ -282,9 +282,9 @@ static int haptic_unit(int argc, char **argv) int success = 0; int fail = 0; - _I("start test"); + _I("Start test."); haptic_test_all(&success, &fail); - _I("Total: %d, Success: %d, Fail: %d", success+fail, success, fail); + _I("Total=%d Success=%d Fail=%d", success+fail, success, fail); } else if (0 == strcasecmp(argv[1], METHOD_HAPTIC_GETCOUNT)) { haptic_getcount(); } else if (0 == strcasecmp(argv[1], METHOD_HAPTIC_OPENDEVICE)) { @@ -310,7 +310,7 @@ static int haptic_unit(int argc, char **argv) } else if (0 == strcasecmp(argv[1], METHOD_HAPTIC_ISSUPPORTED)) { haptic_issupported(argv[2]); } else { - _E("Unknown test case!!!"); + _E("Unknown test case."); } return 0; diff --git a/src/auto-test/main.c b/src/auto-test/main.c old mode 100644 new mode 100755 index 85148c8..5c98fe9 --- a/src/auto-test/main.c +++ b/src/auto-test/main.c @@ -20,7 +20,7 @@ static void test_main(int argc, char **argv) { - _I("auto test all"); + _I("Auto test all."); test_init((void *)NULL); test_exit((void *)NULL); } @@ -31,7 +31,7 @@ static void unit_test(int argc, char **argv) ops = find_test("haptic"); if (!ops) { - _E("there is no test ops : haptic"); + _E("There is no test ops: haptic"); return; } ops->unit(argc, argv); diff --git a/src/auto-test/test.c b/src/auto-test/test.c old mode 100644 new mode 100755 index bf0985c..581d4d0 --- a/src/auto-test/test.c +++ b/src/auto-test/test.c @@ -51,9 +51,9 @@ void test_init(void *data) dd_list *elem; const struct test_ops *d; - _D("test module count(%d)", DD_LIST_LENGTH(dd_head)); + _D("Test module count(%d)", DD_LIST_LENGTH(dd_head)); DD_LIST_FOREACH(dd_head, elem, d) { - _D("[%s] initialize", d->name); + _D("'%s' initialize", d->name); if (d->init) d->init(data); } @@ -65,7 +65,7 @@ void test_exit(void *data) const struct test_ops *d; DD_LIST_FOREACH(dd_head, elem, d) { - _D("[%s] deinitialize", d->name); + _D("'%s' deinitialize", d->name); if (d->exit) d->exit(data); } diff --git a/src/core/common.c b/src/core/common.c old mode 100644 new mode 100755 index 4bd4be8..f58019e --- a/src/core/common.c +++ b/src/core/common.c @@ -90,7 +90,7 @@ bool is_emulator(void) ret = system_info_get_platform_string(MODEL_NAME, &model_name); if (ret < 0) { - _E("Cannot get model name(%d)", ret); + _E("Cannot get model name: %d", ret); return emul; } diff --git a/src/core/config-parser.c b/src/core/config-parser.c old mode 100644 new mode 100755 index ca88496..94a8146 --- a/src/core/config-parser.c +++ b/src/core/config-parser.c @@ -61,7 +61,7 @@ int config_parse(const char *file_name, int cb(struct parse_result *result, /* open conf file */ f = fopen(file_name, "r"); if (!f) { - _E("Failed to open file %s", file_name); + _E("Failed to open file '%s'.", file_name); ret = -EIO; goto error; } @@ -114,14 +114,14 @@ int config_parse(const char *file_name, int cb(struct parse_result *result, } } } - _D("Success to load %s", file_name); + _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); + _E("Failed to read '%s': %d", file_name, lineno); return ret; } diff --git a/src/core/device-idler.c b/src/core/device-idler.c old mode 100644 new mode 100755 index d3bbec9..1931df7 --- a/src/core/device-idler.c +++ b/src/core/device-idler.c @@ -74,7 +74,7 @@ static void process_next_request_in_idle(void) * so it just prints out error log. */ if (!idler) - _E("fail to add request to idler"); + _E("Failed to add request to idler."); } int add_idle_request(void (*func)(void *data), void *data) @@ -82,13 +82,13 @@ int add_idle_request(void (*func)(void *data), void *data) struct device_request *req; if (!func) { - _E("invalid argumet : func(NULL)"); + _E("Invalid argumet: func(NULL)"); return -EINVAL; } req = calloc(1, sizeof(struct device_request)); if (!req) { - _E("fail to allocate request : %d", errno); + _E("Failed to allocate request: %d", errno); return -errno; } diff --git a/src/core/main.c b/src/core/main.c old mode 100644 new mode 100755 index 92fddc8..b6823f8 --- a/src/core/main.c +++ b/src/core/main.c @@ -32,12 +32,12 @@ static GMainLoop *mainloop = NULL; static void sig_quit(int signo) { - _D("received SIGTERM signal %d", signo); + _D("Received SIGTERM signal(%d)", signo); } static void sig_usr1(int signo) { - _D("received SIGUSR1 signal %d, feedbackd'll be finished!", signo); + _D("Received SIGUSR1 signal(%d), feedbackd'll be finished.", signo); if (mainloop) { if (g_main_loop_is_running(mainloop)) @@ -61,18 +61,18 @@ int main(int argc, char **argv) handle = dbus_handle_get_connection(G_BUS_TYPE_SYSTEM, FALSE); if (!handle) - _E("Fail to get dbus connection");; + _E("Failed to get dbus connection.");; ret = haptic_probe(); if (ret != 0) { - _E("[haptic] probe fail"); + _E("'Haptic' probe fail."); return ret; } haptic_init(); ret = dbus_handle_request_bus_name(handle, VIBRATOR_BUS_NAME, dbus_name_acquired, NULL); if (ret <= 0) { - _E("Fail to request bus name"); + _E("Failed to request bus name."); dbus_handle_check_owner_name(NULL, VIBRATOR_BUS_NAME); } @@ -82,7 +82,7 @@ int main(int argc, char **argv) /* g_main_loop */ g_main_loop_run(mainloop); - _D("[haptic] deinitialize"); + _D("'Haptic' deinitialize."); haptic_exit(); g_main_loop_unref(mainloop); mainloop = NULL; diff --git a/src/haptic/circle.c b/src/haptic/circle.c old mode 100644 new mode 100755 index a4af20f..02a8760 --- a/src/haptic/circle.c +++ b/src/haptic/circle.c @@ -60,7 +60,7 @@ static gboolean timer_cb(void *data) char buf[BUF_SIZE]; bool found; - _I("stop vibration by timer"); + _I("Stop vibration by timer."); found = find_from_list(device_handle); if (!found) @@ -74,7 +74,7 @@ static gboolean timer_cb(void *data) } ret = read(fd_stop, buf, BUF_SIZE); if (ret < 0) { - _E("failed to stop"); + _E("Failed to stop."); return G_SOURCE_REMOVE; } stop_timer = 0; @@ -103,18 +103,18 @@ static int open_device(int device_index, int *device_handle) /* if it is the first element */ n = DD_LIST_LENGTH(handle_list); if (n == 0) { - _I("Open"); + _I("Open."); if (fd_play < 0) { fd_play = open(CIRCLE_ON_PATH, O_RDONLY); if (fd_play < 0) { - _E("Failed to open %s : %d", CIRCLE_ON_PATH, errno); + _E("Failed to open '%s': %d", CIRCLE_ON_PATH, errno); return -errno; } } if (fd_stop < 0) { fd_stop = open(CIRCLE_OFF_PATH, O_RDONLY); if (fd_stop < 0) { - _E("Failed to open %s : %d", CIRCLE_OFF_PATH, errno); + _E("Failed to open '%s': %d", CIRCLE_OFF_PATH, errno); return -errno; } } @@ -144,14 +144,14 @@ static int close_device(int device_handle) found = find_from_list(device_handle); if (!found) { - _E("Handle %d fail to check info", device_handle); + _E("Handle(%d) fail to check info.", device_handle); return -EINVAL; } if (fd_stop < 0) { fd_stop = open(CIRCLE_OFF_PATH, O_RDONLY); if (fd_stop < 0) { - _E("Handle %d fail to check fd", device_handle); + _E("Handle(%d) fail to check fd.", device_handle); return -ENODEV; } } @@ -159,14 +159,14 @@ static int close_device(int device_handle) /* stop vibration */ r = stop_device(device_handle); if (r < 0) - _I("Handle %d already stopped or failed to stop effect : %d", device_handle, r); + _I("Handle(%d) already stopped or failed to stop effect: %d", device_handle, r); DD_LIST_REMOVE(handle_list, (gpointer)(long)device_handle); /* if it is the last element */ n = DD_LIST_LENGTH(handle_list); if (n == 0) { - _I("Close"); + _I("Close."); if (fd_play > 0) { close(fd_play); fd_play = -1; @@ -188,20 +188,20 @@ static int vibrate_monotone(int device_handle, int duration, int feedback, int p found = find_from_list(device_handle); if (!found) { - _E("Handle %d fail to check list", device_handle); + _E("Handle(%d) fail to check list.", device_handle); return -EINVAL; } if (fd_play < 0) { fd_play = open(CIRCLE_ON_PATH, O_RDONLY); if (fd_play < 0) { - _E("Handle %d fail to check handle", device_handle); + _E("Handle(%d) fail to check handle.", device_handle); return -ENODEV; } } if (duration <= 0) { - _E("handle %d skip requested with 0", device_handle); + _E("Handle(%d) skip requested with 0.", device_handle); return -EINVAL; } @@ -215,7 +215,7 @@ static int vibrate_monotone(int device_handle, int duration, int feedback, int p /* play vibration */ ret = read(fd_play, buf, BUF_SIZE); if (ret < 0) { - _E("Handle %d failed to play", device_handle); + _E("Handle(%d) failed to play.", device_handle); return -errno; } @@ -224,10 +224,10 @@ static int vibrate_monotone(int device_handle, int duration, int feedback, int p stop_timer = g_timeout_add(duration, timer_cb, (void *)(long)device_handle); if (!stop_timer) - _E("Handle %d Failed to add timer callback", device_handle); + _E("Handle(%d) Failed to add timer callback.", device_handle); } - _D("device handle %d %dms", device_handle, duration); + _D("Device handle(%d) %dms.", device_handle, duration); return 0; } @@ -240,25 +240,25 @@ static int stop_device(int device_handle) found = find_from_list(device_handle); if (!found) { - _E("Handle %d fail to check info", device_handle); + _E("Handle(%d) fail to check info.", device_handle); return -EINVAL; } if (cur_h_data.handle > 0 && cur_h_data.handle != device_handle) { - _E("Only same handle can stop current vibration"); + _E("Only same handle can stop current vibration."); return -EPERM; } if (fd_stop < 0) { fd_stop = open(CIRCLE_OFF_PATH, O_RDONLY); if (fd_stop < 0) { - _E("Handle %d fail to check fd", device_handle); + _E("Handle(%d) fail to check fd.", device_handle); return -ENODEV; } } ret = read(fd_stop, buf, BUF_SIZE); if (ret < 0) { - _E("Failed to stop"); + _E("Failed to stop."); return -errno; } if (stop_timer) { @@ -282,13 +282,13 @@ static bool is_valid(void) { if ((access(CIRCLE_ON_PATH, R_OK) != 0) || (access(CIRCLE_OFF_PATH, R_OK) != 0)) { - _E("Do not support wearable haptic device"); + _E("Do not support wearable haptic device."); state = false; return false; } state = true; - _I("Support wearable haptic device"); + _I("Support wearable haptic device."); return true; } diff --git a/src/haptic/emulator.c b/src/haptic/emulator.c old mode 100644 new mode 100755 index fe40435..31496e9 --- a/src/haptic/emulator.c +++ b/src/haptic/emulator.c @@ -101,11 +101,11 @@ static const struct haptic_plugin_ops default_plugin = { static bool is_valid(void) { if (is_emulator()) { - _I("Support emulator haptic device"); + _I("Support emulator haptic device."); return true; } - _E("Do not support emulator haptic device"); + _E("Do not support emulator haptic device."); return false; } diff --git a/src/haptic/external.c b/src/haptic/external.c old mode 100644 new mode 100755 index 3e4b4e0..5b9e8b7 --- a/src/haptic/external.c +++ b/src/haptic/external.c @@ -41,29 +41,29 @@ static bool is_valid(void) ret = stat(HAPTIC_MODULE_PATH, &buf); if (ret < 0) { - _E("stat file(%s) error : %d", HAPTIC_MODULE_PATH, errno); + _E("Failed to stat file(%s): %d", HAPTIC_MODULE_PATH, errno); goto error; } dlopen_handle = dlopen(HAPTIC_MODULE_PATH, RTLD_NOW); if (!dlopen_handle) { - _E("dlopen failed"); + _E("Failed to dlopen."); goto error; } get_haptic_plugin_interface = dlsym(dlopen_handle, "get_haptic_plugin_interface"); if (!get_haptic_plugin_interface) { - _E("dlsym failed"); + _E("Failed to dlsym."); goto error; } plugin_intf = get_haptic_plugin_interface(); if (!plugin_intf) { - _E("get_haptic_plugin_interface() failed"); + _E("Failed to get_haptic_plugin_interface()."); goto error; } - _I("Support external haptic device"); + _I("Support external haptic device."); return true; error: @@ -72,7 +72,7 @@ error: dlopen_handle = NULL; } - _I("Do not support external haptic device"); + _I("Do not support external haptic device."); return false; } diff --git a/src/haptic/gpio_haptic.c b/src/haptic/gpio_haptic.c old mode 100644 new mode 100755 index a188b10..29b8134 --- a/src/haptic/gpio_haptic.c +++ b/src/haptic/gpio_haptic.c @@ -95,7 +95,7 @@ static gboolean gpio_haptic_timer_cb(void *data) int handle = (int)(long)data; bool found; - _I("stop vibration by timer"); + _I("Stop vibration by timer."); found = find_from_list(handle); if (!found) @@ -103,7 +103,7 @@ static gboolean gpio_haptic_timer_cb(void *data) if (device_handle == NULL) { if (peripheral_i2c_open(GPIO_I2C_BUS_INDEX, DRV2605L_DEFAULT_ADDR, &device_handle) < PERIPHERAL_ERROR_NONE) { - _E("Failed to open I2C"); + _E("Failed to open I2C."); return -EIO; } } @@ -117,7 +117,7 @@ static gboolean gpio_haptic_timer_cb(void *data) static int gpio_haptic_get_device_count(int *count) { - _I("HAL: The max number of DRV2605L is %d", (int)MAX_HAPIC); + _I("HAL: The max number of DRV2605L is %d.", (int)MAX_HAPIC); if (count) *count = MAX_HAPIC; @@ -140,10 +140,10 @@ static int gpio_haptic_open_device(int device_index, int *handle) /* if it is the first element */ n = DD_LIST_LENGTH(handle_list); if (n == 0) { - _I("Peripheral Device Open"); + _I("Peripheral Device Open."); if (device_handle == NULL) { if (peripheral_i2c_open(GPIO_I2C_BUS_INDEX, DRV2605L_DEFAULT_ADDR, &device_handle) < PERIPHERAL_ERROR_NONE) { - _E("Failed to open I2C"); + _E("Failed to open I2C."); return -EIO; } } @@ -177,7 +177,7 @@ static int gpio_haptic_close_device(int handle) if (device_handle == NULL) { if (peripheral_i2c_open(GPIO_I2C_BUS_INDEX, DRV2605L_DEFAULT_ADDR, &device_handle) < PERIPHERAL_ERROR_NONE) { - _E("Failed to open I2C"); + _E("Failed to open I2C."); return -EIO; } } @@ -185,18 +185,18 @@ static int gpio_haptic_close_device(int handle) /* stop vibration */ r = gpio_haptic_stop_device(handle); if (r < 0) - _I("already stopped or failed to stop effect : %d", r); + _I("Already stopped or failed to stop effect: %d", r); - _D("handle %d is closed and timer deleted", handle); + _D("Handle(%d) is closed and timer deleted.", handle); DD_LIST_REMOVE(handle_list, (gpointer)(long)handle); /* if it is the last element */ n = DD_LIST_LENGTH(handle_list); if (n == 0) { - _I("Peripheral Device Close"); + _I("Peripheral Device Close."); if (device_handle != NULL) { if (peripheral_i2c_close(device_handle) < PERIPHERAL_ERROR_NONE) { - _E("Failed to close peripheral I2C"); + _E("Failed to close peripheral I2C."); return -EIO; } device_handle = NULL; @@ -215,7 +215,7 @@ static int gpio_haptic_vibrate_monotone(int handle, int duration, int level, int if (device_handle == NULL) { if (peripheral_i2c_open(GPIO_I2C_BUS_INDEX, DRV2605L_DEFAULT_ADDR, &device_handle) < PERIPHERAL_ERROR_NONE) { - _E("Failed to open I2C"); + _E("Failed to open I2C."); return -EIO; } } @@ -238,9 +238,9 @@ static int gpio_haptic_vibrate_monotone(int handle, int duration, int level, int //stop_timer = ecore_timer_add(duration/1000.f, gpio_haptic_timer_cb, (void *)(long)handle); stop_timer = g_timeout_add(duration, gpio_haptic_timer_cb, (void *)(long)handle); if (!stop_timer) - _E("Failed to add timer callback"); + _E("Failed to add timer callback."); } - _D("device handle %d %dms", handle, duration); + _D("Device handle(%d) %dms", handle, duration); return 0; } @@ -254,13 +254,13 @@ static int gpio_haptic_stop_device(int handle) return -EINVAL; if (cur_h_data.handle > 0 && cur_h_data.handle != handle) { - _E("Only same handle can stop current vibration"); + _E("Only same handle can stop current vibration."); return -EPERM; } if (device_handle == NULL) { if (peripheral_i2c_open(GPIO_I2C_BUS_INDEX, DRV2605L_DEFAULT_ADDR, &device_handle) < PERIPHERAL_ERROR_NONE) { - _E("Failed to open I2C"); + _E("Failed to open I2C."); return -EIO; } } @@ -292,31 +292,31 @@ static bool is_valid(void) peripheral_i2c_h handle; if (peripheral_i2c_open(GPIO_I2C_BUS_INDEX, DRV2605L_DEFAULT_ADDR, &handle) < PERIPHERAL_ERROR_NONE) { - _E("Failed to open I2C"); + _E("Failed to open I2C."); state = false; return false; } if (peripheral_i2c_read_register_byte(handle, DRV2605L_REGISTER_STATUS, &result) < PERIPHERAL_ERROR_NONE) { - _E("Failed to read peripheral I2C"); + _E("Failed to read peripheral I2C."); if (peripheral_i2c_close(handle) < PERIPHERAL_ERROR_NONE) - _E("Failed to close peripheral I2C"); + _E("Failed to close peripheral I2C."); state = false; return false; } if (peripheral_i2c_close(handle) < PERIPHERAL_ERROR_NONE) { - _E("Failed to close peripheral I2C"); + _E("Failed to close peripheral I2C."); state = false; return false; } state = true; - _I("Support gpio haptic device"); + _I("Support gpio haptic device."); return true; } static const struct haptic_plugin_ops *load(void) { - _I("gpio haptic device module loaded"); + _I("Gpio haptic device module loaded."); return &default_plugin; } diff --git a/src/haptic/haptic.c b/src/haptic/haptic.c old mode 100644 new mode 100755 index fa030ea..a473ac0 --- a/src/haptic/haptic.c +++ b/src/haptic/haptic.c @@ -165,7 +165,7 @@ static int insert_conf_data(dd_list **conf_data, struct duration_data *update) data = (struct duration_data *)calloc(1, sizeof(struct duration_data)); if (!data) { - _E("not enough memory"); + _E("Not enough memory."); return -ENOMEM; } memcpy(data, update, sizeof(struct duration_data)); @@ -232,7 +232,7 @@ static int insert_raw_data_format(dd_list **conf_data, char *value) pattern_duration += (update.duration + update.wait); if (pattern_duration > VIB_LOCK_TIMEOUT_MAX) { - _D("Max pattern duration"); + _D("Max pattern duration."); pattern_duration = VIB_LOCK_TIMEOUT_MAX; } @@ -264,7 +264,7 @@ static int get_config_data(int count, bool *packed, char *val, unsigned int *pat duration = value; *pattern_duration += duration; if (*pattern_duration > VIB_LOCK_TIMEOUT_MAX) { - _D("Max pattern duration"); + _D("Max pattern duration."); *pattern_duration = VIB_LOCK_TIMEOUT_MAX; } @@ -314,14 +314,14 @@ static int load_standard_format(const char *pattern) conf = (struct vibration_config *)calloc(1, sizeof(struct vibration_config)); if (!conf) { - _E("fail to alloc"); + _E("Failed to alloc."); ret = -errno; goto error_out; } conf->pattern = strdup(pattern); if (!conf->pattern) { - _E("fail to copy %s pattern data", pattern); + _E("Failed to copy pattern data(%s).", pattern); ret = -errno; goto error_out; } @@ -359,7 +359,7 @@ static int load_standard_format(const char *pattern) if (index < (VALUE_MAX_LEN - 2)) /* Temporal limit */ val[index++] = elem; else - _E("Pattern %s is out of bound: %s", pattern, val); + _E("Pattern(%s) is out of bound: %s", pattern, val); } } close(fd); @@ -397,14 +397,14 @@ static int vibration_load_config(struct parse_result *result, void *user_data) conf = (struct vibration_config *)calloc(1, sizeof(struct vibration_config)); if (!conf) { - _E("fail to alloc"); + _E("Failed to alloc."); return -ENOMEM; } conf->pattern_duration = 0; conf->pattern = strdup(result->name); if (!conf->pattern) { - _E("fail to copy %s pattern data", result->name); + _E("Failed to copy pattern data(%s).", result->name); goto error_out; } @@ -427,7 +427,7 @@ static int vibration_load_config(struct parse_result *result, void *user_data) value = check + 1; conf->standard = strdup(value); if (!conf->standard) { - _E("fail to copy standard name"); + _E("Failed to copy standard name."); goto error_out; } DD_LIST_APPEND(vib_conf_list, conf); @@ -474,7 +474,7 @@ static void load_standard_vibration_patterns(void) dir = opendir(STANDARD_FILE_PATH); if (!dir) { - _E("Failed to load %s Use default value!", STANDARD_FILE_PATH); + _E("Failed to load '%s' Use default value.", STANDARD_FILE_PATH); return; } while ((dent = readdir(dir))) { @@ -485,7 +485,7 @@ static void load_standard_vibration_patterns(void) _E("Failed to parse %s: %d", dent->d_name, ret); } closedir(dir); - _D("Success to load %s", STANDARD_FILE_PATH); + _D("Success to load '%s'", STANDARD_FILE_PATH); } void pattern_config_parse(void) @@ -494,7 +494,7 @@ void pattern_config_parse(void) ret = config_parse(VIBRATION_CONF_PATH, vibration_load_config, NULL); if (ret < 0) - _E("Failed to load %s, %d Use default value!", VIBRATION_CONF_PATH, ret); + _E("Failed to load '%s'. Use default value: %d", VIBRATION_CONF_PATH, ret); load_standard_vibration_patterns(); } @@ -517,7 +517,7 @@ static int haptic_module_load(void) } if (!CHECK_VALID_OPS(h_ops, r)) { - _E("Can't find the valid haptic device"); + _E("Can't find the valid haptic device."); return r; } @@ -543,12 +543,12 @@ static int convert_magnitude_by_conf(int level) step = 100 / (haptic_conf.level-1); for (i = 0; i < haptic_conf.level; ++i) { if (level <= i*step) { - _D("Level changed : %d -> %d", level, haptic_conf.level_arr[i]); + _D("Level changed. %d -> %d", level, haptic_conf.level_arr[i]); return haptic_conf.level_arr[i]; } } - _D("Play default level"); + _D("Play default level."); return DEFAULT_FEEDBACK_LEVEL * HAPTIC_FEEDBACK_STEP; } @@ -577,7 +577,7 @@ void haptic_name_owner_changed(GDBusConnection *connection, struct haptic_info *info = user_data; int handle; - _I("%s (sender:%s)", __func__, name); + _I("%s (sender=%s)", __func__, name); if (!info) return; @@ -678,7 +678,7 @@ GVariant *hdbus_open_device(GDBusConnection *conn, if (!info) { info = add_haptic_info(sender); if (!info) { - _E("fail to create haptic information"); + _E("Failed to create haptic information."); ret = -EPERM; h_ops->close_device(handle); goto exit; @@ -699,7 +699,7 @@ int clear_current_data(void) cur_h_data.priority = PRIORITY_MIN; if (duration_timer) { - _I("Remove duration_timer"); + _I("Remove duration_timer."); g_source_remove(duration_timer); duration_timer = 0; } @@ -722,7 +722,7 @@ GVariant *hdbus_close_device(GDBusConnection *conn, g_variant_get(param, "(u)", &handle); if (!sender) { - _E("fail to get sender from dbus message"); + _E("Failed to get sender from dbus message."); ret = -EPERM; goto exit; } @@ -738,7 +738,7 @@ GVariant *hdbus_close_device(GDBusConnection *conn, info = get_matched_haptic_info(sender); if (!info) { - _E("fail to find the matched haptic info."); + _E("Failed to find the matched haptic info."); goto exit; } @@ -775,7 +775,7 @@ static void vibrate_monotone_idler_cb(void *data) vibrate_info = (struct vibrate_monotone_info *)data; if (vibrate_info->priority < cur_h_data.priority) { - _I("Handle %d skip low priority(pre:%d now:%d)", vibrate_info->handle, cur_h_data.priority, vibrate_info->priority); + _I("Handle(%d) skip low priority. pre=%d now=%d", vibrate_info->handle, cur_h_data.priority, vibrate_info->priority); free(vibrate_info); return; } @@ -794,7 +794,7 @@ static void vibrate_monotone_idler_cb(void *data) ret = device_power_request_lock(POWER_LOCK_CPU, vibrate_info->duration); if (ret != DEVICE_ERROR_NONE) - _E("Failed to request power lock"); + _E("Failed to request power lock."); duration_timer = g_timeout_add(vibrate_info->duration, _cb, NULL); h_ops->vibrate_monotone(cur_h_data.handle, vibrate_info->duration, cur_h_data.level, cur_h_data.priority); @@ -831,14 +831,14 @@ GVariant *hdbus_vibrate_monotone(GDBusConnection *conn, priority = PRIORITY_TOP; if (duration <= 0) { - _E("Skip vibrate handle %d requested less than 0", handle); + _E("Skip vibrate handle(%d) requested less than 0.", handle); ret = -EINVAL; goto exit; } vibrate_info = calloc(1, sizeof(struct vibrate_monotone_info)); if (!vibrate_info) { - _E("failed to allocate memory for vibrate_info"); + _E("Failed to allocate memory for vibrate_info."); ret = -errno; goto exit; } @@ -877,7 +877,7 @@ static gboolean haptic_duration_play(void *data) head = (dd_list *)data; if (cur_h_data.stop) { - _I("Stop currunt vibration"); + _I("Stop currunt vibration."); cur_h_data.stop = false; cur_h_data.handle = INVALID_HANDLE; cur_h_data.priority = PRIORITY_MIN; @@ -885,7 +885,7 @@ static gboolean haptic_duration_play(void *data) } DD_LIST_FOREACH_SAFE(head, n, next, node) { - _D("Handle %d play: %dms and Wait: %dms %s type", + _D("Handle(%d) play=%dms and Wait=%dms %s type.", cur_h_data.handle, node->duration, node->wait, cur_h_data.unlimit ? "Unlimit" : "Once"); if ((node->duration + node->wait) <= 0) { @@ -911,7 +911,7 @@ static gboolean haptic_duration_play(void *data) break; } if (ret != 0) { - _D("auto stop vibration"); + _D("Auto stop vibration."); cur_h_data.stop = true; } out: @@ -939,7 +939,7 @@ static void vibrate_effect_idler_cb(void *data) /* Same or higher priority pattern should be played */ if (vibrate_info->priority < cur_h_data.priority) { - _I("Handle %d skip low priority(pre:%d now:%d)", vibrate_info->handle, cur_h_data.priority, vibrate_info->priority); + _I("Handle(%d) skip low priority. pre=%d now=%d", vibrate_info->handle, cur_h_data.priority, vibrate_info->priority); goto out; } @@ -964,7 +964,7 @@ static void vibrate_effect_idler_cb(void *data) cur_h_data.level = vibrate_info->level; cur_h_data.priority = vibrate_info->priority; cur_h_data.stop = false; - _I("Handle %d play %s pri %d %s", cur_h_data.handle, conf->pattern, cur_h_data.priority, + _I("Handle(%d) play=%s pri=%d %s", cur_h_data.handle, conf->pattern, cur_h_data.priority, cur_h_data.unlimit ? "Unlimit" : "Once"); if (conf->pattern_duration <= 0) @@ -973,12 +973,12 @@ static void vibrate_effect_idler_cb(void *data) if (!cur_h_data.unlimit && conf->pattern_duration > 0) { ret = device_power_request_lock(POWER_LOCK_CPU, (int)conf->pattern_duration); if (ret != DEVICE_ERROR_NONE) - _E("Failed to request power lock"); + _E("Failed to request power lock."); } haptic_duration_play((void *)cur_h_data.vibration_data); goto out; } - _E("Handle %d %s is not supported", vibrate_info->handle, pattern); + _E("Handle(%d) %s is not supported.", vibrate_info->handle, pattern); out: free(vibrate_info->pattern); @@ -1015,7 +1015,7 @@ GVariant *hdbus_vibrate_effect(GDBusConnection *conn, vibrate_info = calloc(1, sizeof(struct vibrate_effect_info)); if (!vibrate_info) { - _E("failed to allocate memory for vibrate_info"); + _E("Failed to allocate memory for vibrate_info."); ret = -errno; goto exit; } @@ -1023,7 +1023,7 @@ GVariant *hdbus_vibrate_effect(GDBusConnection *conn, vibrate_info->pattern = pattern; pattern = NULL; if (!vibrate_info->pattern) { - _E("failed to allocate memory for pattern"); + _E("Failed to allocate memory for pattern."); ret = -errno; free(vibrate_info); goto exit; @@ -1049,14 +1049,14 @@ GVariant *hdbus_stop_device(GDBusConnection *conn, goto exit; if (haptic_disabled) { - _I("Haptic disabled"); + _I("Haptic disabled."); goto exit; } g_variant_get(param, "(u)", &handle); if (cur_h_data.handle != handle) { - _D("Not the request from current vibration handle :%d. Skip", handle); + _D("Not the request from current vibration handle(%d). Skip.", handle); goto exit; } @@ -1077,10 +1077,10 @@ GVariant *hdbus_show_handle_list(GDBusConnection *conn, dd_list *elem; struct haptic_info *info; - _D("sender handle"); + _D("Sender Handle"); DD_LIST_FOREACH(haptic_handle_list, n, info) { for (elem = info->handle_list; elem; elem = elem->next) - _D("%s %d", info->sender, (int)(long)elem->data); + _D("%s %d", info->sender, (int)(long)elem->data); } return g_variant_new_tuple(NULL, 0); @@ -1126,7 +1126,7 @@ GVariant *hdbus_pattern_is_supported(GDBusConnection *conn, ret = pattern_is_supported(data); - _I("%s is supported : %d", data, ret); + _I("%s is supported: %d", data, ret); exit: g_free(data); @@ -1173,7 +1173,7 @@ static void haptic_hardkey_changed_cb(GDBusConnection *conn, return; if (vconf_get_bool(VCONFKEY_SETAPPL_VIBRATION_STATUS_BOOL, &status) < 0) { - _E("fail to get VCONFKEY_SETAPPL_VIBRATION_STATUS_BOOL"); + _E("Failed to get VCONFKEY_SETAPPL_VIBRATION_STATUS_BOOL."); status = 1; } @@ -1183,14 +1183,14 @@ static void haptic_hardkey_changed_cb(GDBusConnection *conn, ret = vconf_get_int(VCONFKEY_SETAPPL_TOUCH_FEEDBACK_VIBRATION_LEVEL_INT, &level); if (ret < 0) { - _E("fail to get VCONFKEY_SETAPPL_TOUCH_FEEDBACK_VIBRATION_LEVEL_INT"); + _E("Failed to get VCONFKEY_SETAPPL_TOUCH_FEEDBACK_VIBRATION_LEVEL_INT."); level = HARDKEY_VIB_FEEDBACK; } ret = h_ops->vibrate_monotone(g_handle, HARDKEY_VIB_DURATION, level*HAPTIC_FEEDBACK_STEP, PRIORITY_HIGH); if (ret < 0) - _E("fail to vibrate buffer : %d", ret); + _E("Failed to vibrate buffer: %d", ret); return; } @@ -1224,12 +1224,12 @@ static void haptic_poweroff_cb(GDBusConnection *conn, haptic_internal_init(); /* power off vibration */ - _I("Handle %d dur %dms pri %d level %d", + _I("Handle=%d dur=%dms pri=%d level=%d", g_handle, POWER_OFF_VIB_DURATION, PRIORITY_HIGH, POWER_VIB_FEEDBACK); ret = h_ops->vibrate_monotone(g_handle, POWER_OFF_VIB_DURATION, POWER_VIB_FEEDBACK, PRIORITY_HIGH); if (ret < 0) { - _E("fail to vibrate_monotone : %d", ret); + _E("Failed to vibrate_monotone: %d", ret); return; } @@ -1267,12 +1267,12 @@ static int parse_section(struct parse_result *result, void *user_data, int index } else if (MATCH(result->name, "level")) { conf->level = atoi(result->value); if (conf->level < 0 || conf->level >= INT_MAX - 1) { - _E("You must set level with positive number in integer range"); + _E("You must set level with positive number in integer range."); return -EINVAL; } conf->level_arr = calloc(sizeof(int), conf->level); if (!conf->level_arr) { - _E("failed to allocate memory for level"); + _E("Failed to allocate memory for level."); return -errno; } } else if (MATCH(result->name, "value")) { @@ -1301,7 +1301,7 @@ static int haptic_load_config(struct parse_result *result, void *user_data) if (MATCH(result->section, "Haptic")) { ret = parse_section(result, user_data, -1); if (ret < 0) { - _E("failed to parse [Haptic] section : %d", ret); + _E("Failed to parse 'Haptic' section: %d", ret); return ret; } goto out; @@ -1313,7 +1313,7 @@ static int haptic_load_config(struct parse_result *result, void *user_data) if (MATCH(result->section, name)) { ret = parse_section(result, user_data, index); if (ret < 0) { - _E("failed to parse [level] section : %d", ret); + _E("Failed to parse 'level' section: %d", ret); return ret; } goto out; @@ -1362,25 +1362,25 @@ void haptic_init(void) /* get haptic data from configuration file */ r = config_parse(HAPTIC_CONF_PATH, haptic_load_config, &haptic_conf); if (r < 0) { - _E("failed to load configuration file(%s) : %d", HAPTIC_CONF_PATH, r); + _E("Failed to load configuration file(%s): %d", HAPTIC_CONF_PATH, r); safe_free(haptic_conf.level_arr); } /* init dbus interface */ r = dbus_handle_register_dbus_object(NULL, VIBRATOR_PATH_HAPTIC, &dbus_interface); if (r < 0) - _E("fail to init hdbus interface and method(%d)", r); + _E("Failed to init hdbus interface and method: %d", r); /* register notifier for below each event */ id_sig_change_hardkey = subscribe_dbus_signal(NULL, DEVICED_PATH_KEY, DEVICED_INTERFACE_KEY, SIGNAL_CHANGE_HARDKEY, haptic_hardkey_changed_cb, NULL, NULL); if (id_sig_change_hardkey <= 0) { - _E("Failed to register signal handler! %d", r); + _E("Failed to register signal handler: %d", r); return; } id_sig_pwr_off_state = subscribe_dbus_signal(NULL, DEVICED_PATH_POWEROFF, DEVICED_INTERFACE_POWEROFF, SIGNAL_POWEROFF_STATE, haptic_poweroff_cb, NULL, NULL); if (id_sig_pwr_off_state <= 0) { - _E("Failed to register signal handler! %d", r); + _E("Failed to register signal handler: %d", r); return; } @@ -1393,7 +1393,7 @@ void haptic_init(void) if (haptic_conf.sound_capture) { r = vconf_notify_key_changed(VCONFKEY_RECORDER_STATE, sound_capturing_cb, NULL); if (r != 0) - _W("Add watch for VCONFKEY_RECORDER_STATE failed"); + _W("Add watch for VCONFKEY_RECORDER_STATE failed."); } /* Initialize vibration_handle (Use vibration now) */ @@ -1411,7 +1411,7 @@ void haptic_exit(void) if (haptic_conf.sound_capture) { r = vconf_ignore_key_changed(VCONFKEY_RECORDER_STATE, sound_capturing_cb); if (r != 0) - _W("Remove watch for VCONFKEY_RECORDER_STATE failed"); + _W("Remove watch for VCONFKEY_RECORDER_STATE failed."); } /* unregister notifier for below each event */ @@ -1440,14 +1440,14 @@ void haptic_exit(void) static int haptic_start(void) { - _I("start"); + _I("Start"); haptic_disabled = false; return 0; } static int haptic_stop(void) { - _I("stop"); + _I("Stop"); haptic_disabled = true; return 0; } diff --git a/src/haptic/standard.c b/src/haptic/standard.c old mode 100644 new mode 100755 index 871fd2c..af43425 --- a/src/haptic/standard.c +++ b/src/haptic/standard.c @@ -124,16 +124,16 @@ static gboolean timer_cb(void *data) struct ff_info *info = (struct ff_info *)data; if (!info) { - _E("Failed to check info"); + _E("Failed to check info."); return G_SOURCE_REMOVE; } if (!check_valid_handle(info)) { - _E("Failed to check valied info"); + _E("Failed to check valied info."); return G_SOURCE_REMOVE; } - _I("stop vibration by timer : id(%d)", info->effect.id); + _I("Stop vibration by timer. id(%d)", info->effect.id); /* stop previous vibration */ ff_stop(ff_fd, &info->effect); @@ -169,7 +169,7 @@ static int ff_find_device(void) fd = open(ev_path, O_RDWR); if (fd < 0) { - _E("Failed to open %s(%d)", ev_path, errno); + _E("Failed to open '%s'.: %d", ev_path, errno); continue; } @@ -182,15 +182,15 @@ static int ff_find_device(void) } if (test_bit(FF_CONSTANT, features)) - _D("%s type : constant", ev_path); + _D("'%s' type: constant", ev_path); if (test_bit(FF_PERIODIC, features)) - _D("%s type : periodic", ev_path); + _D("'%s' type: periodic", ev_path); if (test_bit(FF_SPRING, features)) - _D("%s type : spring", ev_path); + _D("'%s' type: spring", ev_path); if (test_bit(FF_FRICTION, features)) - _D("%s type : friction", ev_path); + _D("'%s' type: friction", ev_path); if (test_bit(FF_RUMBLE, features)) - _D("%s type : rumble", ev_path); + _D("'%s' type: rumble", ev_path); if (test_bit(FF_RUMBLE, features)) { memcpy(ff_path, ev_path, strlen(ev_path)); @@ -226,14 +226,14 @@ static int ff_set_effect(struct ff_effect *effect, int length, int level) double magnitude; if (!effect) { - _E("There is no valid effect"); + _E("There is no valid effect."); return -EINVAL; } magnitude = (double)level/HAPTIC_MODULE_FEEDBACK_MAX; magnitude *= RUMBLE_MAX_MAGNITUDE; - _I("info : magnitude(%d) length(%d)", (int)magnitude, length); + _I("magnitude=%d length=%d", (int)magnitude, length); /* set member variables in effect struct */ effect->u.rumble.strong_magnitude = (int)magnitude; -- 2.7.4 From 368876009085fa8f2e45ee122d769109c56f12c5 Mon Sep 17 00:00:00 2001 From: Yunmi Ha Date: Tue, 26 Feb 2019 18:30:43 +0900 Subject: [PATCH 10/16] Restore permission of source files. Change-Id: I88ee8c455aa7457a46b3cfdc3fb09de6bf236a59 Signed-off-by: Yunmi Ha --- src/auto-test/haptic.c | 0 src/auto-test/main.c | 0 src/auto-test/test.c | 0 src/core/common.c | 0 src/core/config-parser.c | 0 src/core/device-idler.c | 0 src/core/main.c | 0 src/haptic/circle.c | 0 src/haptic/emulator.c | 0 src/haptic/external.c | 0 src/haptic/gpio_haptic.c | 0 src/haptic/haptic.c | 0 src/haptic/standard.c | 0 13 files changed, 0 insertions(+), 0 deletions(-) mode change 100755 => 100644 src/auto-test/haptic.c mode change 100755 => 100644 src/auto-test/main.c mode change 100755 => 100644 src/auto-test/test.c mode change 100755 => 100644 src/core/common.c mode change 100755 => 100644 src/core/config-parser.c mode change 100755 => 100644 src/core/device-idler.c mode change 100755 => 100644 src/core/main.c mode change 100755 => 100644 src/haptic/circle.c mode change 100755 => 100644 src/haptic/emulator.c mode change 100755 => 100644 src/haptic/external.c mode change 100755 => 100644 src/haptic/gpio_haptic.c mode change 100755 => 100644 src/haptic/haptic.c mode change 100755 => 100644 src/haptic/standard.c diff --git a/src/auto-test/haptic.c b/src/auto-test/haptic.c old mode 100755 new mode 100644 diff --git a/src/auto-test/main.c b/src/auto-test/main.c old mode 100755 new mode 100644 diff --git a/src/auto-test/test.c b/src/auto-test/test.c old mode 100755 new mode 100644 diff --git a/src/core/common.c b/src/core/common.c old mode 100755 new mode 100644 diff --git a/src/core/config-parser.c b/src/core/config-parser.c old mode 100755 new mode 100644 diff --git a/src/core/device-idler.c b/src/core/device-idler.c old mode 100755 new mode 100644 diff --git a/src/core/main.c b/src/core/main.c old mode 100755 new mode 100644 diff --git a/src/haptic/circle.c b/src/haptic/circle.c old mode 100755 new mode 100644 diff --git a/src/haptic/emulator.c b/src/haptic/emulator.c old mode 100755 new mode 100644 diff --git a/src/haptic/external.c b/src/haptic/external.c old mode 100755 new mode 100644 diff --git a/src/haptic/gpio_haptic.c b/src/haptic/gpio_haptic.c old mode 100755 new mode 100644 diff --git a/src/haptic/haptic.c b/src/haptic/haptic.c old mode 100755 new mode 100644 diff --git a/src/haptic/standard.c b/src/haptic/standard.c old mode 100755 new mode 100644 -- 2.7.4 From 8a8e76de7f8d311b13b99a4571548c174eceb4e9 Mon Sep 17 00:00:00 2001 From: "pr.jung" Date: Thu, 31 Jan 2019 17:18:59 +0900 Subject: [PATCH 11/16] Change VibrateEffect to VibratePattern Change-Id: Id4c49bd11dc0e68af709930dfcba3bbbf658d939 Signed-off-by: pr.jung --- src/auto-test/haptic.c | 8 ++++---- src/auto-test/main.c | 2 +- src/haptic/haptic.c | 30 +++++++++++++++--------------- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/auto-test/haptic.c b/src/auto-test/haptic.c index fb9195f..bca8159 100644 --- a/src/auto-test/haptic.c +++ b/src/auto-test/haptic.c @@ -22,7 +22,7 @@ #define METHOD_HAPTIC_CLOSEDEVICE "CloseDevice" #define METHOD_HAPTIC_STOPDEVICE "StopDevice" #define METHOD_HAPTIC_VIBRATEMONOTONE "VibrateMonotone" -#define METHOD_HAPTIC_VIBRATEEFFECT "VibrateEffect" +#define METHOD_HAPTIC_VIBRATEEFFECT "VibratePattern" #define METHOD_HAPTIC_GETSTATE "GetState" #define METHOD_HAPTIC_SHOWHANDLELIST "ShowHandleList" #define METHOD_HAPTIC_ISSUPPORTED "IsSupported" @@ -129,7 +129,7 @@ static bool haptic_vibratemonotone(int duration, int level, int priority) return request_haptic_method(METHOD_HAPTIC_VIBRATEMONOTONE, g_variant_new("(uiii)", handle, duration, level, priority)); } -static bool haptic_vibrateeffect(char *pattern, int level, int priority) +static bool haptic_vibratepattern(char *pattern, int level, int priority) { GVariant *msg; int handle; @@ -246,7 +246,7 @@ void haptic_test_all(int *success, int *fail) nanosleep(&time, NULL); (haptic_vibratemonotone(300, 100, 0)) ? s++ : f++; nanosleep(&time, NULL); - (haptic_vibrateeffect("FEEDBACK_PATTERN_SIP", 100, 0)) ? s++ : f++; + (haptic_vibratepattern("FEEDBACK_PATTERN_SIP", 100, 0)) ? s++ : f++; nanosleep(&time, NULL); (haptic_getstate(0)) ? s++ : f++; (haptic_showhandlelist()) ? s++ : f++; @@ -300,7 +300,7 @@ static int haptic_unit(int argc, char **argv) time.tv_sec = 1 + (atoi(argv[2]) / 1000); nanosleep(&time, NULL); } else if (0 == strcasecmp(argv[1], METHOD_HAPTIC_VIBRATEEFFECT)) { - haptic_vibrateeffect(argv[2], atoi(argv[3]), atoi(argv[4])); + haptic_vibratepattern(argv[2], atoi(argv[3]), atoi(argv[4])); time.tv_sec = 2; nanosleep(&time, NULL); } else if (0 == strcasecmp(argv[1], METHOD_HAPTIC_GETSTATE)) { diff --git a/src/auto-test/main.c b/src/auto-test/main.c index 5c98fe9..069528f 100644 --- a/src/auto-test/main.c +++ b/src/auto-test/main.c @@ -48,7 +48,7 @@ void show_usage() printf("CloseDevice 0\n"); printf("StopDevice 0\n"); printf("VibrateMonotone duration, level, priority\n"); - printf("VibrateEffect pattern string, level, priority\n"); + printf("VibratePattern pattern string, level, priority\n"); printf("GetState 0\n"); printf("ShowHandleList 0\n"); printf("IsSupported pattern string\n"); diff --git a/src/haptic/haptic.c b/src/haptic/haptic.c index a473ac0..6fad15b 100644 --- a/src/haptic/haptic.c +++ b/src/haptic/haptic.c @@ -105,7 +105,7 @@ struct haptic_info { guint id_watch; }; -struct vibrate_effect_info { +struct vibrate_pattern_info { unsigned int handle; char *pattern; int level; @@ -918,9 +918,9 @@ out: return G_SOURCE_REMOVE; } -static void vibrate_effect_idler_cb(void *data) +static void vibrate_pattern_idler_cb(void *data) { - struct vibrate_effect_info *vibrate_info; + struct vibrate_pattern_info *vibrate_info; dd_list *elem; struct vibration_config *conf; char pattern[PATH_MAX]; @@ -930,7 +930,7 @@ static void vibrate_effect_idler_cb(void *data) if (!data) return; - vibrate_info = (struct vibrate_effect_info *)data; + vibrate_info = (struct vibrate_pattern_info *)data; if (!(vibrate_info->pattern)) { free(vibrate_info); @@ -985,11 +985,11 @@ out: free(vibrate_info); } -GVariant *hdbus_vibrate_effect(GDBusConnection *conn, +GVariant *hdbus_vibrate_pattern(GDBusConnection *conn, const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) { - struct vibrate_effect_info *vibrate_info; + struct vibrate_pattern_info *vibrate_info; unsigned int handle; char *pattern = NULL; int level, priority, ret = 0; @@ -1013,7 +1013,7 @@ GVariant *hdbus_vibrate_effect(GDBusConnection *conn, else if (priority > PRIORITY_TOP) priority = PRIORITY_TOP; - vibrate_info = calloc(1, sizeof(struct vibrate_effect_info)); + vibrate_info = calloc(1, sizeof(struct vibrate_pattern_info)); if (!vibrate_info) { _E("Failed to allocate memory for vibrate_info."); ret = -errno; @@ -1031,7 +1031,7 @@ GVariant *hdbus_vibrate_effect(GDBusConnection *conn, vibrate_info->level = level; vibrate_info->priority = priority; - ret = add_idle_request(vibrate_effect_idler_cb, (void *)vibrate_info); + ret = add_idle_request(vibrate_pattern_idler_cb, (void *)vibrate_info); exit: g_free(pattern); @@ -1325,14 +1325,14 @@ out: } static const dbus_method_s hdbus_methods[] = { - { "GetCount", NULL, "i", hdbus_get_count }, - { "OpenDevice", "i", "i", hdbus_open_device }, - { "CloseDevice", "u", "i", hdbus_close_device }, - { "StopDevice", "u", "i", hdbus_stop_device }, - { "VibrateMonotone", "uiii", "i", hdbus_vibrate_monotone }, - { "VibrateEffect", "usii", "i", hdbus_vibrate_effect }, + { "GetCount", NULL, "i", hdbus_get_count }, // device_haptic_get_count + { "OpenDevice", "i", "i", hdbus_open_device }, // device_haptic_open, feedback_initialize + { "CloseDevice", "u", "i", hdbus_close_device }, // device_haptic_close, feedback_deinitialize + { "StopDevice", "u", "i", hdbus_stop_device }, // device_haptic_stop, feedback_stop + { "VibrateMonotone", "uiii", "i", hdbus_vibrate_monotone }, // device_haptic_vibrate + { "VibratePattern", "usii", "i", hdbus_vibrate_pattern }, // feedback_play* { "ShowHandleList", NULL, NULL, hdbus_show_handle_list }, - { "IsSupported", "s", "i", hdbus_pattern_is_supported }, + { "IsSupported", "s", "i", hdbus_pattern_is_supported }, // feedback_is_supported_pattern /* Add methods here */ }; -- 2.7.4 From ce3c02768845f256ca780782bff248c59e85bcd2 Mon Sep 17 00:00:00 2001 From: Yunmi Ha Date: Wed, 10 Apr 2019 17:23:47 +0900 Subject: [PATCH 12/16] Change libgdbus library name to libsyscommon. Change-Id: I287ef4437674a52b2fe02fdd0e4fb044d97178aa Signed-off-by: Yunmi Ha --- CMakeLists.txt | 2 +- packaging/feedbackd.spec | 2 +- src/auto-test/test.h | 2 +- src/core/main.c | 2 +- src/haptic/haptic.c | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 45ecc01..c4ffa35 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -38,7 +38,7 @@ SET(PKG_MODULES gio-2.0 gio-unix-2.0 capi-system-info - libgdbus + libsyscommon libsystemd capi-system-device ) diff --git a/packaging/feedbackd.spec b/packaging/feedbackd.spec index 6b801fc..408e120 100644 --- a/packaging/feedbackd.spec +++ b/packaging/feedbackd.spec @@ -21,7 +21,7 @@ BuildRequires: pkgconfig(glib-2.0) BuildRequires: pkgconfig(gio-unix-2.0) BuildRequires: pkgconfig(capi-system-info) BuildRequires: pkgconfig(capi-system-peripheral-io) -BuildRequires: pkgconfig(libgdbus) +BuildRequires: pkgconfig(libsyscommon) BuildRequires: pkgconfig(libsystemd) BuildRequires: pkgconfig(capi-system-device) diff --git a/src/auto-test/test.h b/src/auto-test/test.h index 4454d1a..a7f8347 100644 --- a/src/auto-test/test.h +++ b/src/auto-test/test.h @@ -21,7 +21,7 @@ #define FEEDBACKD__TEST_H__ #include #include -#include +#include #include "core/list.h" #include "core/log.h" diff --git a/src/core/main.c b/src/core/main.c index b6823f8..3134e63 100644 --- a/src/core/main.c +++ b/src/core/main.c @@ -21,7 +21,7 @@ #include #include #include -#include +#include #include #include "core/log.h" diff --git a/src/haptic/haptic.c b/src/haptic/haptic.c index 6fad15b..8a100fe 100644 --- a/src/haptic/haptic.c +++ b/src/haptic/haptic.c @@ -24,7 +24,7 @@ #include #include #include -#include +#include #include "core/log.h" #include "core/list.h" -- 2.7.4 From 7f4de5ecc4c2b5fb8b95b1394a3eb012b986324b Mon Sep 17 00:00:00 2001 From: "sanghyeok.oh" Date: Mon, 27 May 2019 15:42:22 +0900 Subject: [PATCH 13/16] dbus-policy: modified to use default deny - allow signal Change-Id: Iee05626d085aa84c7d48e16c68b6379fb34fe8d6 Signed-off-by: sanghyeok.oh --- scripts/feedbackd.conf | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/scripts/feedbackd.conf b/scripts/feedbackd.conf index 2ded9e1..f3194b1 100755 --- a/scripts/feedbackd.conf +++ b/scripts/feedbackd.conf @@ -13,8 +13,7 @@ - - + -- 2.7.4 From 5e2cd8d2d6f7adde087b023f37685179bfbf90b5 Mon Sep 17 00:00:00 2001 From: "sanghyeok.oh" Date: Wed, 29 May 2019 18:06:28 +0900 Subject: [PATCH 14/16] dbus-policy: fix bug Change-Id: I5f610397bec9f39d047b29a95a5413f59471269b Signed-off-by: sanghyeok.oh --- scripts/feedbackd.conf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/feedbackd.conf b/scripts/feedbackd.conf index f3194b1..4433fb6 100755 --- a/scripts/feedbackd.conf +++ b/scripts/feedbackd.conf @@ -13,7 +13,7 @@ - + -- 2.7.4 From c49cbe71e7f8358b84b6665bfdd99e5dc01c5032 Mon Sep 17 00:00:00 2001 From: INSUN PYO Date: Tue, 25 Jun 2019 14:27:58 +0900 Subject: [PATCH 15/16] Remove unnecessary dependency from feedbackd.service Change-Id: Ic0137662cee492cf69d8df217e0652604c3670d1 --- systemd/feedbackd.service | 1 - 1 file changed, 1 deletion(-) diff --git a/systemd/feedbackd.service b/systemd/feedbackd.service index 5b412e6..c76326f 100644 --- a/systemd/feedbackd.service +++ b/systemd/feedbackd.service @@ -1,6 +1,5 @@ [Unit] Description=System Vibrator Daemon -After=deviced.service [Service] Type=notify -- 2.7.4 From e23e33c65a60da56c88cd54df94919c77caa3e41 Mon Sep 17 00:00:00 2001 From: INSUN PYO Date: Mon, 8 Jul 2019 20:24:37 +0900 Subject: [PATCH 16/16] Delete meaningless configuration Change-Id: I473df7df364d8d12c24b934eb9a5e7dfed3900ba --- systemd/org.tizen.system.vibrator.service | 1 - 1 file changed, 1 deletion(-) diff --git a/systemd/org.tizen.system.vibrator.service b/systemd/org.tizen.system.vibrator.service index d3c99bf..cac9f64 100644 --- a/systemd/org.tizen.system.vibrator.service +++ b/systemd/org.tizen.system.vibrator.service @@ -1,5 +1,4 @@ [D-BUS Service] Name=org.tizen.system.vibrator Exec=/bin/false -User=system_fw SystemdService=feedbackd.service -- 2.7.4