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];
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;
}
#include "core/list.h"
#include "haptic.h"
-#define DEFAULT_EFFECT_HANDLE 0xFFFA
-
static dd_list *handle_list;
static int unique_number = 0;
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;
if (!elem)
return -EINVAL;
- if (effect_handle)
- *effect_handle = DEFAULT_EFFECT_HANDLE;
-
return 0;
}
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;
}
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;
}
_D("device handle %d %dms", handle, duration);
- if (e_handle)
- *e_handle = handle;
-
return 0;
}
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);
int priority;
};
+struct vibrate_monotone_info {
+ unsigned int handle;
+ int duration;
+ int level;
+ int priority;
+};
+
/* for playing */
static int g_handle;
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);
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;
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);
}
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);
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();
}
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);
gpointer data)
{
int type = POWER_OFF_NONE;
- int e_handle, ret;
+ int ret;
struct timespec time = {0,};
g_variant_get(param, "(i)", &type);
_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;
#ifndef __FEEDBACKD_HAPTIC_H__
#define __FEEDBACKD_HAPTIC_H__
+#include <device/power.h>
#include <stdbool.h>
#include "core/common.h"
#include "core/list.h"
#include <fcntl.h>
#include <stdlib.h>
#include <stdbool.h>
-#include <device/power.h>
#include "core/log.h"
#include "core/list.h"
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;
}
#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);
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;
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));
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;
}
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 */
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);
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;
}
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;
}
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;
}
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");
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