Sync internal API behavior with product code 51/234051/1
authorYunmi Ha <yunmi.ha@samsung.com>
Thu, 21 May 2020 09:00:43 +0000 (18:00 +0900)
committerYunmi Ha <yunmi.ha@samsung.com>
Thu, 21 May 2020 09:00:43 +0000 (18:00 +0900)
- Functionalization of duplicated code.
- Always alert when internal api is called.

Change-Id: I871d00c3812a85cb7e98ed48a4fd5183b673ef23
Signed-off-by: Yunmi Ha <yunmi.ha@samsung.com>
src/common.h
src/devices.c
src/devices.h
src/feedback.c
src/sound.c
src/vibrator.c

index 7b05565..650e27a 100644 (file)
@@ -63,6 +63,7 @@ typedef GList dd_list;
 #define HAPTIC_FEEDBACK_STEP    20 /**< feedback max / slider step */
 
 #define ARR_SIZE(arr) (sizeof(arr)/sizeof((arr)[0]))
+#define FEEDBACK_LEVEL(x)   ((x)? ((x/2)+1): 0)
 
 int is_sound_mode(void);
 int is_touch_sndstatus(void);
index fa3f54d..80776d1 100644 (file)
@@ -73,7 +73,7 @@ void devices_exit(void)
        }
 }
 
-int devices_play(int pattern)
+int devices_play(int pattern, bool always)
 {
        dd_list *elem;
        const struct device_ops *dev;
@@ -81,7 +81,7 @@ int devices_play(int pattern)
 
        DD_LIST_FOREACH(dev_head, elem, dev) {
                if (dev->play) {
-                       ret = dev->play(pattern);
+                       ret = dev->play(pattern, always);
                        if ((prev < 0 && ret == 0) ||
                            (prev == 0 && ret < 0))
                                prev = 0;
@@ -96,7 +96,7 @@ int devices_play(int pattern)
        return prev;
 }
 
-int devices_play_soundpath(int pattern, const char *soundpath)
+int devices_play_soundpath(int pattern, const char *soundpath, bool always)
 {
        dd_list *elem;
        const struct device_ops *dev;
@@ -105,12 +105,12 @@ int devices_play_soundpath(int pattern, const char *soundpath)
        DD_LIST_FOREACH(dev_head, elem, dev) {
                if (dev->type == FEEDBACK_TYPE_SOUND) {
                        if (dev->play_path)
-                               ret = dev->play_path(pattern, soundpath);
+                               ret = dev->play_path(pattern, soundpath, always);
                        else
                                continue;       //LCOV_EXCL_LINE
                } else {
                        if (dev->play)
-                               ret = dev->play(pattern);
+                               ret = dev->play(pattern, always);
                        else
                                continue;       //LCOV_EXCL_LINE
                }
index 898b975..0e8cb61 100644 (file)
@@ -28,8 +28,8 @@ struct device_ops {
        const char *name;
        void (*init) (void);
        void (*exit) (void);
-       int (*play) (int);
-       int (*play_path) (int, const char *);
+       int (*play) (int, bool);
+       int (*play_path) (int, const char *, bool);
        int (*stop) (void);
        int (*is_supported) (int, bool *);
        int (*get_path) (int, char *, unsigned int);
@@ -38,8 +38,8 @@ struct device_ops {
 
 void devices_init(void);
 void devices_exit(void);
-int devices_play(int pattern);
-int devices_play_soundpath(int pattern, const char *soundpath);
+int devices_play(int pattern, bool always);
+int devices_play_soundpath(int pattern, const char *soundpath, bool always);
 int devices_stop(void);
 
 #define DEVICE_OPS_REGISTER(dev)       \
index ab72a02..02e083a 100644 (file)
@@ -112,11 +112,32 @@ API int feedback_deinitialize(void)
        return FEEDBACK_ERROR_NONE;
 }
 
+static feedback_pattern_e check_pattern(feedback_type_e type, feedback_pattern_e pattern, const char *func)
+{
+    feedback_pattern_e switched = pattern;
+    bool result = false;
+
+    if (type < FEEDBACK_TYPE_NONE || type >= FEEDBACK_TYPE_END)
+        type = FEEDBACK_TYPE_NONE;
+
+    /* if you need to switch pattern */
+    if (profile->get_switched_pattern)
+        result = profile->get_switched_pattern(pattern, &switched);
+
+    if (pattern != switched && result)
+        _W("pattern is changed : %s %s(%d) -> %s(%d) by %s", //LCOV_EXCL_LINE
+                profile->str_type[type],
+                profile->str_pattern(pattern), pattern , profile->str_pattern(switched), switched, func);
+    else
+        _W("pattern is : %s %s(%d) by %s", //LCOV_EXCL_LINE
+                profile->str_type[type],
+                profile->str_pattern(pattern), pattern, func);
+    return switched;
+}
+
 API int feedback_play(feedback_pattern_e pattern)
 {
        int err;
-       bool result;
-       int switched;
 
        /* check initialize */
        pthread_mutex_lock(&fmutex);
@@ -133,18 +154,9 @@ API int feedback_play(feedback_pattern_e pattern)
                return FEEDBACK_ERROR_INVALID_PARAMETER;
        }
 
-       /* if you need to switch pattern */
-       if (profile->get_switched_pattern) {
-               result = profile->get_switched_pattern(pattern, &switched);
-               if (result) {
-                       _W("pattern is changed : (%s) -> (%s)", //LCOV_EXCL_LINE
-                                       profile->str_pattern(pattern), profile->str_pattern(switched));
-                       pattern = switched;
-               }
-       }
-
+       _D("request all type with pattern %s(%d)", profile->str_pattern(pattern), pattern);
        /* play all device */
-       err = devices_play(pattern);
+       err = devices_play(check_pattern(FEEDBACK_TYPE_NONE, pattern, __func__), false);
        /**
         * devices_play() returns error even if all devices are failed.
         * It means if to play anything is successful,
@@ -162,8 +174,6 @@ API int feedback_play_type(feedback_type_e type, feedback_pattern_e pattern)
 {
        const struct device_ops *dev;
        int err;
-       bool result;
-       int switched;
 
        /* check initialize */
        pthread_mutex_lock(&fmutex);
@@ -186,16 +196,6 @@ API int feedback_play_type(feedback_type_e type, feedback_pattern_e pattern)
                return FEEDBACK_ERROR_INVALID_PARAMETER;
        }
 
-       /* if you need to switch pattern */
-       if (profile->get_switched_pattern) {
-               result = profile->get_switched_pattern(pattern, &switched);
-               if (result) {
-                       _W("pattern is changed : (%s) -> (%s)", //LCOV_EXCL_LINE
-                                       profile->str_pattern(pattern), profile->str_pattern(switched));
-                       pattern = switched;
-               }
-       }
-
        /* play proper device */
        dev = find_device(type);
        if (!dev) {
@@ -203,7 +203,7 @@ API int feedback_play_type(feedback_type_e type, feedback_pattern_e pattern)
                return FEEDBACK_ERROR_NOT_SUPPORTED;
        }
 
-       err = dev->play(pattern);
+       err = dev->play(check_pattern(type, pattern, __func__), false);
        if (err == -ENOTSUP)
                return FEEDBACK_ERROR_NOT_SUPPORTED;
        else if (err == -ECOMM || err == -EACCES)
@@ -244,8 +244,6 @@ API int feedback_is_supported_pattern(feedback_type_e type, feedback_pattern_e p
        const struct device_ops *dev;
        bool supported;
        int err;
-       bool result;
-       int switched;
 
        /* check initialize */
        pthread_mutex_lock(&fmutex);
@@ -273,16 +271,6 @@ API int feedback_is_supported_pattern(feedback_type_e type, feedback_pattern_e p
                return FEEDBACK_ERROR_INVALID_PARAMETER;
        }
 
-       /* if you need to switch pattern */
-       if (profile->get_switched_pattern) {
-               result = profile->get_switched_pattern(pattern, &switched);
-               if (result) {
-                       _W("pattern is changed : (%s) -> (%s)", //LCOV_EXCL_LINE
-                                       profile->str_pattern(pattern), profile->str_pattern(switched));
-                       pattern = switched;
-               }
-       }
-
        /* play proper device */
        dev = find_device(type);
        if (!dev) {
@@ -290,7 +278,7 @@ API int feedback_is_supported_pattern(feedback_type_e type, feedback_pattern_e p
                return FEEDBACK_ERROR_NOT_SUPPORTED;
        }
 
-       err = dev->is_supported(pattern, &supported);
+       err = dev->is_supported(check_pattern(type, pattern, __func__), &supported);
        if (err == -ENOTSUP)
                return FEEDBACK_ERROR_NOT_SUPPORTED; //LCOV_EXCL_LINE System Error
        else if (err == -ECOMM || err == -EACCES)
@@ -346,8 +334,6 @@ API int feedback_play_type_by_name(char *type, char *pattern)
 API int feedback_play_internal(feedback_pattern_internal_e pattern)
 {
        int err;
-       bool result;
-       int switched;
 
        /* check initialize */
        pthread_mutex_lock(&fmutex);
@@ -364,18 +350,9 @@ API int feedback_play_internal(feedback_pattern_internal_e pattern)
                return FEEDBACK_ERROR_INVALID_PARAMETER;
        }
 
-       /* if you need to switch pattern */
-       if (profile->get_switched_pattern) {
-               result = profile->get_switched_pattern(pattern, &switched);
-               if (result) {
-                       _W("pattern is changed : (%s) -> (%s)", //LCOV_EXCL_LINE
-                                       profile->str_pattern(pattern), profile->str_pattern(switched));
-                       pattern = switched;
-               }
-       }
-
+       _D("request all type with pattern %s(%d)", profile->str_pattern(pattern), pattern);
        /* play all device */
-       err = devices_play(pattern);
+       err = devices_play(check_pattern(FEEDBACK_TYPE_NONE, pattern, __func__), true);
        /**
         * devices_play() returns error even if all devices are failed.
         * It means if to play anything is successful,
@@ -393,8 +370,6 @@ API int feedback_play_type_internal(feedback_type_e type, feedback_pattern_inter
 {
        const struct device_ops *dev;
        int err;
-       bool result;
-       int switched;
 
        /* check initialize */
        pthread_mutex_lock(&fmutex);
@@ -417,24 +392,14 @@ API int feedback_play_type_internal(feedback_type_e type, feedback_pattern_inter
                return FEEDBACK_ERROR_INVALID_PARAMETER;
        }
 
-       /* if you need to switch pattern */
-       if (profile->get_switched_pattern) {
-               result = profile->get_switched_pattern(pattern, &switched);
-               if (result) {
-                       _W("pattern is changed : (%s) -> (%s)", //LCOV_EXCL_LINE
-                                       profile->str_pattern(pattern), profile->str_pattern(switched));
-                       pattern = switched;
-               }
-       }
-
        /* play proper device */
        dev = find_device(type);
        if (!dev) {
                _E("Not supported device : type(%s)", profile->str_type[type]); //LCOV_EXCL_LINE
                return FEEDBACK_ERROR_NOT_SUPPORTED;
        }
-
-       err = dev->play(pattern);
+       _D("request type %s with pattern %s(%d)", profile->str_type[type], profile->str_pattern(pattern), pattern);
+       err = dev->play(check_pattern(type, pattern, __func__), true);
        if (err == -ENOTSUP)
                return FEEDBACK_ERROR_NOT_SUPPORTED;
        else if (err == -ECOMM || err == -EACCES)
@@ -448,8 +413,6 @@ API int feedback_play_type_internal(feedback_type_e type, feedback_pattern_inter
 API int feedback_play_soundpath_internal(feedback_pattern_internal_e internal_pattern, const char *soundpath)
 {
        int err;
-       bool result;
-       int switched;
        feedback_pattern_e pattern = (feedback_pattern_e)internal_pattern;
 
        /* check initialize */
@@ -472,19 +435,9 @@ API int feedback_play_soundpath_internal(feedback_pattern_internal_e internal_pa
                return FEEDBACK_ERROR_INVALID_PARAMETER;
        }
 
-       /* if you need to switch pattern */
-       if (profile->get_switched_pattern) {
-               result = profile->get_switched_pattern(pattern, &switched);
-               if (result) {
-                       _W("pattern is changed : (%s) -> (%s)", //LCOV_EXCL_LINE
-                                       profile->str_pattern(pattern), profile->str_pattern(switched));
-                       pattern = switched;
-               }
-       }
-
        _D("request all type with pattern %s(%d), soundpath %s", profile->str_pattern(pattern), pattern, soundpath);
        /* play all device */
-       err = devices_play_soundpath(pattern, soundpath);
+       err = devices_play_soundpath(check_pattern(FEEDBACK_TYPE_NONE, pattern, __func__), soundpath, true);
        /**
         * devices_play() returns error even if all devices are failed.
         * It means if to play anything is successful,
@@ -502,8 +455,6 @@ API int feedback_play_type_soundpath_internal(feedback_type_e type, feedback_pat
 {
        const struct device_ops *dev;
        int err;
-       bool result;
-       int switched;
        feedback_pattern_e pattern = (feedback_pattern_e)internal_pattern;
 
        /* check initialize */
@@ -532,16 +483,6 @@ API int feedback_play_type_soundpath_internal(feedback_type_e type, feedback_pat
                return FEEDBACK_ERROR_INVALID_PARAMETER;
        }
 
-       /* if you need to switch pattern */
-       if (profile->get_switched_pattern) {
-               result = profile->get_switched_pattern(pattern, &switched);
-               if (result) {
-                       _W("pattern is changed : (%s) -> (%s)", //LCOV_EXCL_LINE
-                                       profile->str_pattern(pattern), profile->str_pattern(switched));
-                       pattern = switched;
-               }
-       }
-
        /* play proper device */
        dev = find_device(type);
        if (!dev) {
@@ -551,12 +492,12 @@ API int feedback_play_type_soundpath_internal(feedback_type_e type, feedback_pat
        _D("request type %s with pattern(%s), soundpath(%s)", profile->str_type[type], profile->str_pattern(pattern), soundpath?soundpath:"NULL");
        if (type == FEEDBACK_TYPE_SOUND) {
                if (dev->play_path)
-                       err = dev->play_path(pattern, soundpath);
+                       err = dev->play_path(check_pattern(type, pattern, __func__), soundpath, true);
                else
                        err = -ENOTSUP; //LCOV_EXCL_LINE
        } else {
                if (dev->play)
-                       err = dev->play(pattern);
+                       err = dev->play(check_pattern(type, pattern, __func__), true);
                else
                        err = -ENOTSUP; //LCOV_EXCL_LINE
        }
index 55235cb..5bbb77f 100644 (file)
@@ -148,7 +148,7 @@ static void sound_exit(void)
        feedback_free_config(&sound_info);
 }
 
-static int sound_play(feedback_pattern_e pattern)
+static int sound_play(feedback_pattern_e pattern, bool always)
 {
        struct stat buf;
        int retry = FEEDBACK_RETRY_CNT, ret;
@@ -160,6 +160,11 @@ static int sound_play(feedback_pattern_e pattern)
                sndstatus = 0;
        }
 
+       if (always) {
+               _W("Always on condition(pattern %s)", profile->str_pattern(pattern)); //LCOV_EXCL_LINE
+               goto check_pattern;
+       }
+
        if (sndstatus == 0 && profile->get_always_alert_case &&
            !profile->get_always_alert_case(FEEDBACK_TYPE_SOUND, pattern)) {
                _D("Sound condition is OFF (sndstatus : %d)", sndstatus); //LCOV_EXCL_LINE
@@ -172,6 +177,7 @@ static int sound_play(feedback_pattern_e pattern)
                return 0;
        }
 
+check_pattern:
        /* get sound file path */
        path = get_data(pattern);
        if (!path || stat(path, &buf)) {
@@ -197,7 +203,7 @@ static int sound_play(feedback_pattern_e pattern)
        return -EPERM;
 }
 
-static int sound_play_path(feedback_pattern_e pattern, const char *soundpath)
+static int sound_play_path(feedback_pattern_e pattern, const char *soundpath, bool always)
 {
        struct stat buf;
        int retry = FEEDBACK_RETRY_CNT, ret;
@@ -217,6 +223,11 @@ static int sound_play_path(feedback_pattern_e pattern, const char *soundpath)
                sndstatus = 0;
        }
 
+       if (always) {
+               _W("Always on condition(pattern %s)", profile->str_pattern(pattern)); //LCOV_EXCL_LINE
+               goto check_pattern;
+       }
+
        if (sndstatus == 0 && profile->get_always_alert_case &&
            !profile->get_always_alert_case(FEEDBACK_TYPE_SOUND, pattern)) {
                _D("Sound condition is OFF (sndstatus : %d)", sndstatus); //LCOV_EXCL_LINE
@@ -229,6 +240,7 @@ static int sound_play_path(feedback_pattern_e pattern, const char *soundpath)
                return 0;
        }
 
+check_pattern:
        /* play sound file */
        do {
                if (profile->get_strength_type)
index 15ffd42..835c6db 100644 (file)
@@ -165,7 +165,7 @@ static void vibrator_exit(void)
 
 }
 
-static int vibrator_play(feedback_pattern_e pattern)
+static int vibrator_play(feedback_pattern_e pattern, bool always)
 {
        char *temp;
        char *data;
@@ -186,6 +186,11 @@ static int vibrator_play(feedback_pattern_e pattern)
                vibstatus = 0;
        }
 
+       if (always) {
+               _W("Always on condition(pattern %s)", profile->str_pattern(pattern)); //LCOV_EXCL_LINE
+               goto check_pattern;
+       }
+
        if (vibstatus == 0 && profile->get_always_alert_case &&
            !profile->get_always_alert_case(FEEDBACK_TYPE_VIBRATION, pattern))  {
                _D("Vibration condition is OFF (vibstatus : %d)", vibstatus); //LCOV_EXCL_LINE
@@ -198,6 +203,7 @@ static int vibrator_play(feedback_pattern_e pattern)
                return 0;
        }
 
+check_pattern:
        if (pattern <= FEEDBACK_PATTERN_NONE ||
            pattern >= profile->max_pattern) {
                _E("Not supported vibration pattern"); //LCOV_EXCL_LINE
@@ -207,7 +213,7 @@ static int vibrator_play(feedback_pattern_e pattern)
        if (profile->get_strength_type)
                level = profile->get_strength_type(FEEDBACK_TYPE_VIBRATION, pattern);
        else
-               level = (DEFAULT_VIB_LEVEL? (DEFAULT_VIB_LEVEL/2 + 1): 0);
+               level = FEEDBACK_LEVEL(DEFAULT_VIB_LEVEL);
 
        temp = strdup(profile->str_pattern(pattern));
        data = trim_str(temp);