Check priority for VibrateMonotone and add debug logs 53/198053/10 accepted/tizen/unified/20190130.151732 submit/tizen/20190129.075918 submit/tizen/20190130.070614
authorpr.jung <pr.jung@samsung.com>
Fri, 18 Jan 2019 05:32:07 +0000 (14:32 +0900)
committerpr.jung <pr.jung@samsung.com>
Tue, 29 Jan 2019 05:57:27 +0000 (14:57 +0900)
Change-Id: Iacb4241abf39503476b4a02c35a726de6124e868
Signed-off-by: pr.jung <pr.jung@samsung.com>
src/haptic/circle.c
src/haptic/gpio_haptic.c
src/haptic/haptic.c
src/haptic/standard-vibcore.c
src/haptic/standard-vibcore.h
src/haptic/standard.c

index f17007a..5cb570e 100644 (file)
@@ -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,
index 8b7ff7b..c448fee 100644 (file)
@@ -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,
index b01cd96..95e4d5b 100644 (file)
@@ -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:
index 3e7d0d1..66e3eae 100644 (file)
@@ -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);
index 5f731ba..dd0c071 100644 (file)
@@ -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);
index 4831c06..f370614 100644 (file)
@@ -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,