haptic: Play higher priority pattern when there are more than one vibration requests 49/135949/7
authorpr.jung <pr.jung@samsung.com>
Tue, 27 Jun 2017 11:44:04 +0000 (20:44 +0900)
committerJung <pr.jung@samsung.com>
Fri, 30 Jun 2017 07:25:49 +0000 (07:25 +0000)
Change-Id: I1a5d25e0bfa31581b25636e8f62c6c952d05d417
Signed-off-by: pr.jung <pr.jung@samsung.com>
src/haptic/circle.c
src/haptic/haptic.c
src/haptic/haptic.h
src/haptic/standard-vibcore.c
src/haptic/standard.c

index c0737e3..ec00101 100644 (file)
@@ -247,7 +247,7 @@ static int stop_device(int device_handle)
        if (!found)
                return -EINVAL;
 
-       if (vibration_handle > 0 && vibration_handle != device_handle) {
+       if (cur_h_data.handle > 0 && cur_h_data.handle != device_handle) {
                _E("Only same handle can stop current vibration");
                return -EPERM;
        }
index 2f52e62..d9521a5 100644 (file)
@@ -371,6 +371,10 @@ static DBusMessage *edbus_vibrate_monotone(E_DBus_Object *obj, DBusMessage *msg)
                ret = -EINVAL;
                goto exit;
        }
+       if (priority < PRIORITY_MIN)
+               priority = PRIORITY_MIN;
+       else if (priority > PRIORITY_TOP)
+               priority = PRIORITY_TOP;
 
        ret = h_ops->vibrate_monotone(handle, duration, level, priority, &e_handle);
        if (ret >= 0)
@@ -464,6 +468,10 @@ static DBusMessage *edbus_vibrate_effect(E_DBus_Object *obj, DBusMessage *msg)
                ret = -EINVAL;
                goto exit;
        }
+       if (priority < PRIORITY_MIN)
+               priority = PRIORITY_MIN;
+       else if (priority > PRIORITY_TOP)
+               priority = PRIORITY_TOP;
 
        vibrate_info = calloc(1, sizeof(struct vibrate_effect_info));
        if (!vibrate_info) {
@@ -920,7 +928,8 @@ void haptic_init(void)
                vconf_notify_key_changed(VCONFKEY_RECORDER_STATE, sound_capturing_cb, NULL);
 
        /* Initialize vibration_handle (Use vibration now) */
-       vibration_handle = INVALID_HANDLE;
+       cur_h_data.handle = INVALID_HANDLE;
+       cur_h_data.priority = PRIORITY_MIN;
 }
 
 void haptic_exit(void)
index 7ab6a7f..3f57723 100644 (file)
@@ -22,6 +22,7 @@
 
 #include <stdbool.h>
 #include "core/common.h"
+#include "core/list.h"
 #include "haptic-plugin-intf.h"
 
 #define HAPTIC_OPS_REGISTER(dev)       \
@@ -39,6 +40,13 @@ enum haptic_type {
        HAPTIC_EXTERNAL,
 };
 
+enum priority_level {
+       PRIORITY_MIN = 0,
+       PRIORITY_MIDDLE,
+       PRIORITY_HIGH,
+       PRIORITY_TOP,
+};
+
 struct haptic_ops {
        enum haptic_type type;
        bool (*is_valid)(void);
@@ -46,9 +54,16 @@ struct haptic_ops {
        void (*release)(void);
 };
 
-#define INVALID_HANDLE -1
+struct haptic_data {
+       dd_list *vibration_data;
+       unsigned int handle;
+       int level;
+       int priority;
+       bool stop;
+};
 
-int vibration_handle;
+#define INVALID_HANDLE 0
+extern struct haptic_data cur_h_data;
 
 void add_haptic(const struct haptic_ops *ops);
 void remove_haptic(const struct haptic_ops *ops);
index 3a828b1..df6278e 100644 (file)
@@ -39,19 +39,13 @@ struct duration_data {
        int wait;
 };
 
-struct haptic_data {
-       dd_list *vibration_data;
-       unsigned int handle;
-       int level;
-       int priority;
-       bool stop;
-};
-
 static dd_list *vib_conf_list;
 static Ecore_Timer *duration_timer;
 
 static t_vibrate_monotone real_vibrate_monotone;
 
+struct haptic_data cur_h_data;
+
 static int vibration_load_config(struct parse_result *result, void *user_data)
 {
        struct vibration_config *conf;
@@ -186,14 +180,16 @@ static Eina_Bool haptic_duration_play(void *data)
        }
 
        if (!data) {
-               vibration_handle = INVALID_HANDLE;
+               cur_h_data.handle = INVALID_HANDLE;
+               cur_h_data.priority = PRIORITY_MIN;
                goto out;
        }
 
        h_data = (struct haptic_data *)data;
        if (h_data->stop) {
                h_data->stop = false;
-               free(h_data);
+               cur_h_data.handle = INVALID_HANDLE;
+               cur_h_data.priority = PRIORITY_MIN;
                goto out;
        }
 
@@ -201,7 +197,8 @@ static Eina_Bool haptic_duration_play(void *data)
        DD_LIST_FOREACH_SAFE(head, n, next, node) {
                _D("Play: %dms and Wait: %dms", node->duration, node->wait);
                if (!node->duration) {
-                       free(h_data);
+                       cur_h_data.handle = INVALID_HANDLE;
+                       cur_h_data.priority = PRIORITY_MIN;
                        break;
                }
 
@@ -213,7 +210,6 @@ static Eina_Bool haptic_duration_play(void *data)
 
                ret = real_vibrate_monotone(h_data->handle, node->duration, h_data->level, h_data->priority, NULL);
                if (!next) {
-                       free(h_data);
                        goto out;
                }
                break;
@@ -237,12 +233,17 @@ int standard_vibrate_effect(int device_handle, const char *pattern, int feedback
 {
        dd_list *elem;
        struct vibration_config *conf;
-       struct haptic_data *data;
        size_t len;
 
        if (device_handle < 0)
                return -EINVAL;
 
+       /* 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;
+       }
+
        len = strlen(pattern) + 1;
        DD_LIST_FOREACH(vib_conf_list, elem, conf) {
                if (!conf->pattern)
@@ -250,19 +251,13 @@ int standard_vibrate_effect(int device_handle, const char *pattern, int feedback
                if (strncmp(conf->pattern, pattern, len))
                        continue;
 
-               data = (struct haptic_data *)malloc(sizeof(struct haptic_data));
-               if (!data) {
-                       _E("fail to alloc");
-                       return -ENOMEM;
-               }
-               data->vibration_data = conf->data;
-               data->handle = device_handle;
-               data->level = feedback;
-               data->priority = priority;
-               data->stop = false;
-               vibration_handle = device_handle;
+               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;
                _D("Play %s", conf->pattern);
-               haptic_duration_play((void *)data);
+               haptic_duration_play((void *)&cur_h_data);
                break;
        }
 
@@ -271,7 +266,8 @@ int standard_vibrate_effect(int device_handle, const char *pattern, int feedback
 
 int standard_vibrate_close()
 {
-       vibration_handle = INVALID_HANDLE;
+       cur_h_data.handle = INVALID_HANDLE;
+       cur_h_data.priority = PRIORITY_MIN;
 
        if (duration_timer) {
                _I("Remove duration_timer");
index 74658d0..21bd343 100644 (file)
@@ -590,7 +590,7 @@ static int stop_device(int device_handle)
        if (!check_fd(&ff_fd))
                return -ENODEV;
 
-       if (vibration_handle > 0 && vibration_handle != info->handle) {
+       if (cur_h_data.handle > 0 && cur_h_data.handle != info->handle) {
                _E("Only same handle can stop current vibration");
                return -EPERM;
        }