Add feedback_play_internal and feedback_play_type_internal API 47/141647/3 accepted/tizen/4.0/unified/20170829.015749 accepted/tizen/unified/20170808.171140 submit/tizen/20170807.071226 submit/tizen_4.0/20170828.100004 submit/tizen_4.0/20170828.110004
authorpr.jung <pr.jung@samsung.com>
Tue, 1 Aug 2017 08:02:10 +0000 (17:02 +0900)
committerpr.jung <pr.jung@samsung.com>
Mon, 7 Aug 2017 03:29:52 +0000 (12:29 +0900)
- Add an internal API
- Receive feedback_pattern_internal_e as parameter

Change-Id: Ic09612993d4130dfb3445c0d39c08e348a884935
Signed-off-by: pr.jung <pr.jung@samsung.com>
include/feedback-internal.h
src/feedback.c

index 5e06f9e..91d8eaa 100644 (file)
@@ -57,6 +57,54 @@ extern "C" {
 int feedback_play_type_by_name(char *type, char *pattern);
 
 /**
+ * @brief Plays various types of reactions that are pre-defined.
+ * @details This function can be used to react to pre-defined actions. \n
+ *          It play various types of system pre-defined media or vibration patterns.
+ * @since_tizen 4.0
+ * @remarks Currently, there are two types of reactions: sound and vibration. \n
+ *          Depending on the settings, some types cannot operate.
+ *          For example, when set to silent mode, the device doesn't produce any sound.
+ *          If to play one of the devices is successful, this function regards as success.
+ *          And for controlling haptic device, the privilege should be set to, %http://tizen.org/privilege/haptic.
+ *          If you don't have the haptic privilege, it only works sound operation.
+ *          It does not return any error in this case.
+ * @param[in] pattern The pre-defined internal pattern
+ * @return @c 0 on success,
+ *         otherwise a negative error value
+ * @retval #FEEDBACK_ERROR_NONE Successful
+ * @retval #FEEDBACK_ERROR_OPERATION_FAILED Operation not permitted
+ * @retval #FEEDBACK_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #FEEDBACK_ERROR_NOT_SUPPORTED Not supported device
+ * @retval #FEEDBACK_ERROR_NOT_INITIALIZED Not initialized
+ * @pre feedback_initialize()
+ */
+int feedback_play_internal(feedback_pattern_internal_e pattern);
+
+/**
+ * @brief Plays specific type of reactions that are pre-defined.
+ * @details This function can be used to react to pre-defined actions. \n
+ *          It play specific type of system pre-defined pattern.
+ * @since_tizen 4.0
+ * @remarks Currently, there are two types of reactions: sound and vibration. \n
+ *          Depending on the settings, some types cannot operate.
+ *          For example, when set to silent mode, the device doesn't produce any sound.
+ *          And for controlling haptic device, the privilege should be set to, %http://tizen.org/privilege/haptic.
+ *          If you don't have the haptic privilege, it returns FEEDBACK_ERROR_PERMISSION_DENIED error.
+ * @param[in] type The pattern type
+ * @param[in] pattern The pre-defined internal pattern
+ * @return @c 0 on success,
+ *         otherwise a negative error value
+ * @retval #FEEDBACK_ERROR_NONE Successful
+ * @retval #FEEDBACK_ERROR_OPERATION_FAILED Operation not permitted
+ * @retval #FEEDBACK_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #FEEDBACK_ERROR_NOT_SUPPORTED Not supported device
+ * @retval #FEEDBACK_ERROR_PERMISSION_DENIED Permission denied
+ * @retval #FEEDBACK_ERROR_NOT_INITIALIZED Not initialized
+ * @pre feedback_initialize()
+ */
+int feedback_play_type_internal(feedback_type_e type, feedback_pattern_internal_e pattern);
+
+/**
  * @brief Gets the file path of resource for the given feedback type and pattern.
  * @details
  * Depending on the type of each pattern resouorce has a different format. \n
index b0eb6e4..f6bb4d2 100644 (file)
@@ -340,6 +340,108 @@ API int feedback_play_type_by_name(char *type, char *pattern)
        return feedback_play_type(etype, epattern);
 }
 
+API int feedback_play_internal(feedback_pattern_internal_e pattern)
+{
+       int err;
+       bool result;
+       int switched;
+
+       /* check initialize */
+       pthread_mutex_lock(&fmutex);
+       if (!init_cnt) {
+               _E("Not initialized"); //LCOV_EXCL_LINE
+               pthread_mutex_unlock(&fmutex);
+               return FEEDBACK_ERROR_NOT_INITIALIZED;
+       }
+       pthread_mutex_unlock(&fmutex);
+
+       if (pattern <= FEEDBACK_PATTERN_NONE ||
+           pattern >= profile->max_pattern) {
+               _E("Invalid parameter : pattern(%d)", 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 all device */
+       err = devices_play(pattern);
+       /**
+        * devices_play() returns error even if all devices are failed.
+        * It means if to play anything is successful,
+        * this function regards as success.
+        */
+       if (err == -ENOTSUP)
+               return FEEDBACK_ERROR_NOT_SUPPORTED;
+       else if (err < 0)
+               return FEEDBACK_ERROR_OPERATION_FAILED;
+
+       return FEEDBACK_ERROR_NONE;
+}
+
+API int feedback_play_type_internal(feedback_type_e type, feedback_pattern_internal_e pattern)
+{
+       const struct device_ops *dev;
+       int err;
+       bool result;
+       int switched;
+
+       /* check initialize */
+       pthread_mutex_lock(&fmutex);
+       if (!init_cnt) {
+               _E("Not initialized"); //LCOV_EXCL_LINE
+               pthread_mutex_unlock(&fmutex);
+               return FEEDBACK_ERROR_NOT_INITIALIZED;
+       }
+       pthread_mutex_unlock(&fmutex);
+
+       if (type <= FEEDBACK_TYPE_NONE ||
+           type >= profile->max_type) {
+               _E("Invalid parameter : type(%d)", type);
+               return FEEDBACK_ERROR_INVALID_PARAMETER;
+       }
+
+       if (pattern <= FEEDBACK_PATTERN_INTERNAL_NONE ||
+           pattern >= profile->max_pattern) {
+               _E("Invalid parameter : pattern(%d)", 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) {
+               _E("Not supported device : type(%s)", profile->str_type[type]); //LCOV_EXCL_LINE
+               return FEEDBACK_ERROR_NOT_SUPPORTED;
+       }
+
+       err = dev->play(pattern);
+       if (err == -ENOTSUP)
+               return FEEDBACK_ERROR_NOT_SUPPORTED;
+       else if (err == -ECOMM || err == -EACCES)
+               return FEEDBACK_ERROR_PERMISSION_DENIED;
+       else if (err < 0)
+               return FEEDBACK_ERROR_OPERATION_FAILED;
+
+       return FEEDBACK_ERROR_NONE;
+}
+
 API int feedback_get_resource_path(feedback_type_e type, feedback_pattern_e pattern, char** path)
 {
        const struct device_ops *dev;