revise vibrate buffer problem 58/15158/1
authorjy910.yun <jy910.yun@samsung.com>
Thu, 30 May 2013 09:38:25 +0000 (18:38 +0900)
committerKrzysztof Sasiak <k.sasiak@samsung.com>
Thu, 16 Jan 2014 13:37:25 +0000 (14:37 +0100)
Change-Id: I1373e7a404323628e1dcbbd1f25fdc3b9d7a0996
Signed-off-by: jy910.yun <jy910.yun@samsung.com>
src/deviced/dd-haptic.h
src/haptic/haptic.c
src/shared/haptic.c

index 0cdf5d6..48aff31 100644 (file)
@@ -412,6 +412,62 @@ int haptic_vibrate_buffers_with_detail(haptic_device_h device_handle,
                                       haptic_effect_h *effect_handle);
 
 /**
+ * @param[out] effect_handle   Pointer to the variable that will receive a handle to the playing effect
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #HAPTIC_ERROR_NONE                  Successful
+ * @retval #HAPTIC_ERROR_INVALID_PARAMETER     Invalid parameter
+ * @retval #HAPTIC_ERROR_NOT_INITIALIZED       Not initialized
+ * @retval #HAPTIC_ERROR_OPERATION_FAILED      Operation failed
+ * @retval #HAPTIC_ERROR_NOT_SUPPORTED_DEVICE  Not supported device
+ *
+ * @see haptic_vibrate_buffer_with_detail()
+ * @see haptic_vibrate_monotone()
+ * @see haptic_vibrate_file()
+ * @see haptic_get_count()
+ */
+int haptic_vibrate_buffers(haptic_device_h device_handle,
+                                                       const unsigned char *vibe_buffer,
+                                                       int size,
+                                                       haptic_effect_h *effect_handle);
+
+/**
+ * @brief Vibrates a predefined rhythmic haptic-vibration pattern buffer.
+ * @details
+ * This function can be used to play a haptic-vibration pattern buffer.
+ *
+ * @remark
+ * If you don't use th api regarding effect_handle, you can pass in a NULL value to last parameter.
+ *
+ * @param[in] device_handle    The device handle from haptic_open()
+ * @param[in] vibe_buffer      Pointer to the vibration pattern
+ * @param[in] size              Size to the vibration pattern
+ * @param[in] iteration        The number of times to repeat the effect
+ * @param[in] feedback         The amount of the intensity variation
+ * @param[in] priority         The priority from HAPTIC_PRIORITY_MIN to HAPTIC_PRIORITY_HIGH
+ * @param[out] effect_handle   Pointer to the variable that will receive a handle to the playing effect
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #HAPTIC_ERROR_NONE                  Successful
+ * @retval #HAPTIC_ERROR_INVALID_PARAMETER     Invalid parameter
+ * @retval #HAPTIC_ERROR_NOT_INITIALIZED       Not initialized
+ * @retval #HAPTIC_ERROR_OPERATION_FAILED      Operation failed
+ * @retval #HAPTIC_ERROR_NOT_SUPPORTED_DEVICE  Not supported device
+ *
+ * @see haptic_vibrate_buffer()
+ * @see haptic_vibrate_monotone_with_detail()
+ * @see haptic_vibrate_file_with_detail()
+ * @see haptic_get_count()
+ */
+int haptic_vibrate_buffers_with_detail(haptic_device_h device_handle,
+                                      const unsigned char *vibe_buffer,
+                                                                         int size,
+                                      haptic_iteration_e iteration,
+                                      haptic_feedback_e feedback,
+                                      haptic_priority_e priority,
+                                      haptic_effect_h *effect_handle);
+
+/**
  * @brief Stops the current vibration effect which is being played.
  * @details This function can be used to stop each effect started by haptic_vibrate_xxx().
  *
index 128f243..b14df05 100644 (file)
@@ -147,7 +147,7 @@ static DBusMessage *edbus_stop_device(E_DBus_Object *obj, DBusMessage *msg)
        if (ret < 0)
                _E("fail to stop device : %d", ret);
 
-       _D("haptic close %d", ret);
+       _D("haptic stop %d", ret);
 
 exit:
        reply = dbus_message_new_method_return(msg);
@@ -178,13 +178,14 @@ static DBusMessage *edbus_vibrate_monotone(E_DBus_Object *obj, DBusMessage *msg)
                goto exit;
        }
 
+       _D("haptic vibrate monotone (h:%d, d:%d, f:%d, p:%d)", handle, duration, feedback, priority);
        ret = plugin_intf->vibrate_monotone(handle, duration, feedback, priority, &e_handle);
        if (ret < 0)
                _E("fail to vibrate monotone : %d", ret);
        else
                ret = e_handle;
 
-       _D("haptic vibrate monotone %d(h:%d, d:%d, f:%d, p:%d)", ret, handle, duration, feedback, priority);
+       _D("haptic vibrate monotone %d", ret);
 
 exit:
        reply = dbus_message_new_method_return(msg);
@@ -218,14 +219,14 @@ static DBusMessage *edbus_vibrate_buffer(E_DBus_Object *obj, DBusMessage *msg)
                goto exit;
        }
 
+       _D("haptic vibrate buffer (h:%d, s:%d, i:%d, f:%d, p:%d)", handle, size, iteration, feedback, priority);
        ret = plugin_intf->vibrate_buffer(handle, data, iteration, feedback, priority, &e_handle);
        if (ret < 0)
                _E("fail to vibrate buffer : %d", ret);
        else
                ret = e_handle;
 
-       _D("haptic vibrate buffer %d(h:%d, s:%d, i:%d, f:%d, p:%d)",
-                       ret, handle, size, iteration, feedback, priority);
+       _D("haptic vibrate buffer %d", ret);
 
 exit:
        reply = dbus_message_new_method_return(msg);
@@ -319,7 +320,7 @@ static DBusMessage *edbus_get_duration(E_DBus_Object *obj, DBusMessage *msg)
        DBusError err;
        unsigned int handle;
        unsigned char *data;
-       int duration, ret;
+       int size, duration, ret;
 
        if (!plugin_intf || !plugin_intf->get_buffer_duration) {
                ret = -EFAULT;
@@ -328,7 +329,8 @@ static DBusMessage *edbus_get_duration(E_DBus_Object *obj, DBusMessage *msg)
 
        dbus_error_init(&err);
        if (!dbus_message_get_args(msg, &err, DBUS_TYPE_UINT32, &handle,
-                               DBUS_TYPE_STRING, &data, DBUS_TYPE_INVALID)) {
+                               DBUS_TYPE_ARRAY, DBUS_TYPE_BYTE, &data, &size,
+                               DBUS_TYPE_INVALID)) {
                ret = -EINVAL;
                goto exit;
        }
@@ -448,7 +450,7 @@ static struct edbus_method {
        { "VibrateMonotone", "uiii",   "i", edbus_vibrate_monotone },
        { "VibrateBuffer", "uayiii",   "i", edbus_vibrate_buffer },
        { "GetState",           "u",   "i", edbus_get_state },
-       { "GetDuration",       "us",   "i", edbus_get_duration },
+       { "GetDuration",      "uay",   "i", edbus_get_duration },
        { "CreateEffect",    "sisi",   "i", edbus_create_effect },
        { "SaveBinary",       "sis",   "i", edbus_save_binary },
        /* Add methods here */
index a09d090..7874749 100644 (file)
@@ -234,10 +234,10 @@ API int haptic_open(haptic_device_e device_index, haptic_device_h *device_handle
        dbus_message_unref(msg);
        dbus_error_free(&err);
 
-       _D("%s-%s : %d(%d)", DEVICED_INTERFACE_HAPTIC, METHOD_OPEN_DEVICE, ret_val, (unsigned int)ret_val);
+       _D("%s-%s : %d", DEVICED_INTERFACE_HAPTIC, METHOD_OPEN_DEVICE, ret_val);
 
        *device_handle = (haptic_device_h)ret_val;
-       return ret;
+       return 0;
 }
 
 API int haptic_close(haptic_device_h device_handle)
@@ -276,7 +276,7 @@ API int haptic_close(haptic_device_h device_handle)
 
        _D("%s-%s : %d", DEVICED_INTERFACE_HAPTIC, METHOD_CLOSE_DEVICE, ret_val);
 
-       return ret;
+       return 0;
 }
 
 API int haptic_vibrate_monotone(haptic_device_h device_handle, int duration, haptic_effect_h *effect_handle)
@@ -360,93 +360,7 @@ API int haptic_vibrate_monotone_with_detail(haptic_device_h device_handle,
        if (effect_handle != NULL)
                *effect_handle = (haptic_effect_h)ret_val;
 
-       return ret;
-}
-
-static int haptic_vibrate_buffer_with_detail_size(haptic_device_h device_handle,
-                                      const unsigned char *vibe_buffer,
-                                                                         int size,
-                                      haptic_iteration_e iteration,
-                                      haptic_feedback_e feedback,
-                                      haptic_priority_e priority,
-                                      haptic_effect_h *effect_handle)
-{
-       DBusError err;
-       DBusMessage *msg;
-       char str_handle[32];
-       char str_iteration[32];
-       char str_feedback[32];
-       char str_priority[32];
-       char *arr[6];
-       int ret, ret_val;
-       struct dbus_byte byte;
-
-       /* check if handle is valid */
-       if (device_handle < 0) {
-               _E("Invalid parameter : device_handle(%d)", device_handle);
-               return HAPTIC_ERROR_INVALID_PARAMETER;
-       }
-
-       /* check if passed arguments are valid */
-       if (vibe_buffer == NULL) {
-               _E("Invalid parameter : vibe_buffer(NULL)");
-               return HAPTIC_ERROR_INVALID_PARAMETER;
-       }
-
-       if (iteration < HAPTIC_ITERATION_ONCE || iteration > HAPTIC_ITERATION_INFINITE) {
-               _E("Invalid parameter : iteration(%d)", iteration);
-               return HAPTIC_ERROR_INVALID_PARAMETER;
-       }
-
-       if (feedback < HAPTIC_FEEDBACK_0 || feedback > HAPTIC_FEEDBACK_AUTO) {
-               _E("Invalid parameter : feedback(%d)", feedback);
-               return HAPTIC_ERROR_INVALID_PARAMETER;
-       }
-
-       if (priority < HAPTIC_PRIORITY_MIN || priority > HAPTIC_PRIORITY_HIGH) {
-               _E("Invalid parameter : priority(%d)", priority);
-               return HAPTIC_ERROR_INVALID_PARAMETER;
-       }
-
-       /* in case of FEEDBACK_AUTO, should be converted */
-       if (feedback == HAPTIC_FEEDBACK_AUTO)
-               feedback = convert_setting_to_module_level();
-
-       snprintf(str_handle, sizeof(str_handle), "%u", device_handle);
-       arr[0] = str_handle;
-       byte.size = size;
-       byte.data = vibe_buffer;
-       arr[2] = &byte;
-       snprintf(str_iteration, sizeof(str_iteration), "%d", iteration);
-       arr[3] = str_iteration;
-       snprintf(str_feedback, sizeof(str_feedback), "%d", feedback);
-       arr[4] = str_feedback;
-       snprintf(str_priority, sizeof(str_priority), "%d", priority);
-       arr[5] = str_priority;
-
-       /* request to deviced to open haptic device */
-       msg = deviced_dbus_method_sync(BUS_NAME, DEVICED_PATH_HAPTIC, DEVICED_INTERFACE_HAPTIC,
-                       METHOD_VIBRATE_BUFFER, "uayiii", arr);
-       if (!msg)
-               return HAPTIC_ERROR_OPERATION_FAILED;
-
-       dbus_error_init(&err);
-
-       ret = dbus_message_get_args(msg, &err, DBUS_TYPE_INT32, &ret_val, DBUS_TYPE_INVALID);
-       if (!ret) {
-               _E("no message : [%s:%s]", err.name, err.message);
-               ret = HAPTIC_ERROR_OPERATION_FAILED;
-       }
-
-       dbus_message_unref(msg);
-       dbus_error_free(&err);
-
-       _D("%s-%s : %d", DEVICED_INTERFACE_HAPTIC, METHOD_VIBRATE_BUFFER, ret_val);
-
-       if (effect_handle != NULL)
-               *effect_handle = (haptic_effect_h)ret_val;
-
-       return ret;
+       return 0;
 }
 
 API int haptic_vibrate_file(haptic_device_h device_handle, const char *file_path, haptic_effect_h *effect_handle)
@@ -460,7 +374,7 @@ API int haptic_vibrate_file(haptic_device_h device_handle, const char *file_path
                return HAPTIC_ERROR_OPERATION_FAILED;
        }
 
-       ret = haptic_vibrate_buffer_with_detail_size(device_handle,
+       ret = haptic_vibrate_buffers_with_detail(device_handle,
                                                                                        vibe_buffer,
                                                                                        size,
                                                                                        HAPTIC_ITERATION_ONCE,
@@ -487,7 +401,7 @@ API int haptic_vibrate_file_with_detail(haptic_device_h device_handle,
                return HAPTIC_ERROR_OPERATION_FAILED;
        }
 
-       ret = haptic_vibrate_buffer_with_detail_size(device_handle,
+       ret = haptic_vibrate_buffers_with_detail(device_handle,
                                                                                        vibe_buffer,
                                                                                        size,
                                                                                        iteration,
@@ -555,7 +469,7 @@ API int haptic_vibrate_buffers_with_detail(haptic_device_h device_handle,
        char str_priority[32];
        char *arr[6];
        int ret, ret_val;
-       struct dbus_byte byte;
+       struct dbus_byte bytes;
 
        /* check if handle is valid */
        if (device_handle < 0) {
@@ -588,21 +502,21 @@ API int haptic_vibrate_buffers_with_detail(haptic_device_h device_handle,
        if (feedback == HAPTIC_FEEDBACK_AUTO)
                feedback = convert_setting_to_module_level();
 
-       _D("data : %s(%d)", vibe_buffer, strlen(vibe_buffer));
-
        snprintf(str_handle, sizeof(str_handle), "%u", device_handle);
        arr[0] = str_handle;
-       arr[1] = vibe_buffer;
+       bytes.size = size;
+       bytes.data = vibe_buffer;
+       arr[2] = &bytes;
        snprintf(str_iteration, sizeof(str_iteration), "%d", iteration);
-       arr[2] = str_iteration;
+       arr[3] = str_iteration;
        snprintf(str_feedback, sizeof(str_feedback), "%d", feedback);
-       arr[3] = str_feedback;
+       arr[4] = str_feedback;
        snprintf(str_priority, sizeof(str_priority), "%d", priority);
-       arr[4] = str_priority;
+       arr[5] = str_priority;
 
        /* request to deviced to open haptic device */
        msg = deviced_dbus_method_sync(BUS_NAME, DEVICED_PATH_HAPTIC, DEVICED_INTERFACE_HAPTIC,
-                       METHOD_VIBRATE_BUFFER, "usiii", arr);
+                       METHOD_VIBRATE_BUFFER, "uayiii", arr);
        if (!msg)
                return HAPTIC_ERROR_OPERATION_FAILED;
 
@@ -622,7 +536,7 @@ API int haptic_vibrate_buffers_with_detail(haptic_device_h device_handle,
        if (effect_handle != NULL)
                *effect_handle = (haptic_effect_h)ret_val;
 
-       return ret;
+       return 0;
 }
 
 API int haptic_stop_effect(haptic_device_h device_handle, haptic_effect_h effect_handle)
@@ -664,7 +578,7 @@ API int haptic_stop_all_effects(haptic_device_h device_handle)
 
        _D("%s-%s : %d", DEVICED_INTERFACE_HAPTIC, METHOD_STOP_DEVICE, ret_val);
 
-       return ret;
+       return 0;
 }
 
 API int haptic_get_effect_state(haptic_device_h device_handle, haptic_effect_h effect_handle, haptic_state_e *effect_state)
@@ -714,7 +628,7 @@ API int haptic_get_effect_state(haptic_device_h device_handle, haptic_effect_h e
        _D("%s-%s : %d", DEVICED_INTERFACE_HAPTIC, METHOD_GET_STATE, ret_val);
 
        *effect_state = (haptic_state_e)ret_val;
-       return ret;
+       return 0;
 }
 
 API int haptic_create_effect(unsigned char *vibe_buffer,
@@ -790,7 +704,7 @@ API int haptic_create_effect(unsigned char *vibe_buffer,
 
        _D("%s-%s : %d", DEVICED_INTERFACE_HAPTIC, METHOD_CREATE_EFFECT, ret_val);
 
-       return ret;
+       return 0;
 }
 
 API int haptic_save_effect(const unsigned char *vibe_buffer,
@@ -838,59 +752,7 @@ API int haptic_save_effect(const unsigned char *vibe_buffer,
        return HAPTIC_ERROR_NONE;
 }
 
-static int haptic_get_buffer_duration_size(haptic_device_h device_handle, const unsigned char *vibe_buffer, int size, int *buffer_duration)
-{
-       DBusError err;
-       DBusMessage *msg;
-       char str_handle[32];
-       char *arr[2];
-       int ret, ret_val;
-
-       /* check if handle is valid */
-       if (device_handle < 0) {
-               _E("Invalid parameter : device_handle(%d)", device_handle);
-               return HAPTIC_ERROR_INVALID_PARAMETER;
-       }
-
-       if (vibe_buffer == NULL) {
-               _E("Invalid parameter : vibe_buffer(NULL)");
-               return HAPTIC_ERROR_INVALID_PARAMETER;
-       }
-
-       /* check if pointer is valid */
-       if (buffer_duration == NULL) {
-               _E("Invalid parameter : buffer_duration(NULL)");
-               return HAPTIC_ERROR_INVALID_PARAMETER;
-       }
-
-       snprintf(str_handle, sizeof(str_handle), "%u", device_handle);
-       arr[0] = str_handle;
-       arr[1] = vibe_buffer;
-
-       /* request to deviced to open haptic device */
-       msg = deviced_dbus_method_sync(BUS_NAME, DEVICED_PATH_HAPTIC, DEVICED_INTERFACE_HAPTIC,
-                       METHOD_GET_DURATION, "us", arr);
-       if (!msg)
-               return HAPTIC_ERROR_OPERATION_FAILED;
-
-       dbus_error_init(&err);
-
-       ret = dbus_message_get_args(msg, &err, DBUS_TYPE_INT32, &ret_val, DBUS_TYPE_INVALID);
-       if (!ret) {
-               _E("no message : [%s:%s]", err.name, err.message);
-               ret = HAPTIC_ERROR_OPERATION_FAILED;
-       }
-
-       dbus_message_unref(msg);
-       dbus_error_free(&err);
-
-       _D("%s-%s : %d", DEVICED_INTERFACE_HAPTIC, METHOD_GET_DURATION, ret_val);
-
-       *buffer_duration = ret_val;
-       return ret;
-}
-
-API int haptic_get_file_duration_size(haptic_device_h device_handle, const char *file_path, int *file_duration)
+API int haptic_get_file_duration(haptic_device_h device_handle, const char *file_path, int *file_duration)
 {
        char *vibe_buffer;
        int size, ret;
@@ -901,7 +763,7 @@ API int haptic_get_file_duration_size(haptic_device_h device_handle, const char
                return HAPTIC_ERROR_OPERATION_FAILED;
        }
 
-       ret = haptic_get_buffer_duration_size(device_handle,
+       ret = haptic_get_buffers_duration(device_handle,
                                                                         vibe_buffer,
                                                                         size,
                                                                         file_duration);
@@ -922,8 +784,9 @@ API int haptic_get_buffers_duration(haptic_device_h device_handle, const unsigne
        DBusError err;
        DBusMessage *msg;
        char str_handle[32];
-       char *arr[2];
+       char *arr[3];
        int ret, ret_val;
+       struct dbus_byte bytes;
 
        /* check if handle is valid */
        if (device_handle < 0) {
@@ -944,11 +807,13 @@ API int haptic_get_buffers_duration(haptic_device_h device_handle, const unsigne
 
        snprintf(str_handle, sizeof(str_handle), "%u", device_handle);
        arr[0] = str_handle;
-       arr[1] = vibe_buffer;
+       bytes.size = size;
+       bytes.data = vibe_buffer;
+       arr[2] = &bytes;
 
        /* request to deviced to open haptic device */
        msg = deviced_dbus_method_sync(BUS_NAME, DEVICED_PATH_HAPTIC, DEVICED_INTERFACE_HAPTIC,
-                       METHOD_GET_DURATION, "us", arr);
+                       METHOD_GET_DURATION, "uay", arr);
        if (!msg)
                return HAPTIC_ERROR_OPERATION_FAILED;
 
@@ -966,7 +831,7 @@ API int haptic_get_buffers_duration(haptic_device_h device_handle, const unsigne
        _D("%s-%s : %d", DEVICED_INTERFACE_HAPTIC, METHOD_GET_DURATION, ret_val);
 
        *buffer_duration = ret_val;
-       return ret;
+       return 0;
 }
 
 API int haptic_save_led(const unsigned char *vibe_buffer, int max_bufsize, const char *file_path)
@@ -1024,5 +889,5 @@ API int haptic_save_led(const unsigned char *vibe_buffer, int max_bufsize, const
 
        _D("%s-%s : %d", DEVICED_INTERFACE_HAPTIC, METHOD_SAVE_BINARY, ret_val);
 
-       return ret;
+       return 0;
 }