return 0;
}
-static int vibrate_buffer(int device_handle, const unsigned char *vibe_buffer, int iteration, int feedback, int priority, int *effect_handle)
-{
- _E("Not support feature");
- return -EACCES;
-}
-
static int stop_device(int device_handle)
{
int ret;
*effect_state = state;
return 0;
}
-
-static int create_effect(unsigned char *vibe_buffer, int max_bufsize, const haptic_module_effect_element *elem_arr, int max_elemcnt)
-{
- _E("Not support feature");
- return -EACCES;
-}
-
-static int get_buffer_duration(int device_handle, const unsigned char *vibe_buffer, int *buffer_duration)
-{
- _E("Not support feature");
- return -EACCES;
-}
-
-static int convert_binary(const unsigned char *vibe_buffer, int max_bufsize, const char *file_path)
-{
- _E("Not support feature");
- return -EACCES;
-}
/* END: Haptic Module APIs */
static const struct haptic_plugin_ops default_plugin = {
.open_device = open_device,
.close_device = close_device,
.vibrate_monotone = vibrate_monotone,
- .vibrate_buffer = vibrate_buffer,
.vibrate_effect = standard_vibrate_effect,
.is_supported = standard_is_supported,
.stop_device = stop_device,
.get_device_state = get_device_state,
- .create_effect = create_effect,
- .get_buffer_duration = get_buffer_duration,
- .convert_binary = convert_binary,
};
static bool is_valid(void)
return 0;
}
-static int vibrate_buffer(int device_handle, const unsigned char *vibe_buffer, int iteration, int feedback, int priority, int *effect_handle)
-{
- dd_list *elem;
-
- elem = DD_LIST_FIND(handle_list, (gpointer)(long)device_handle);
- if (!elem)
- return -EINVAL;
-
- if (effect_handle)
- *effect_handle = DEFAULT_EFFECT_HANDLE;
-
- return 0;
-}
-
static int vibrate_effect(int device_handle, const char *pattern, int feedback, int priority)
{
dd_list *elem;
return 0;
}
-static int create_effect(unsigned char *vibe_buffer, int max_bufsize, const haptic_module_effect_element *elem_arr, int max_elemcnt)
-{
- _E("Not support feature");
- return -EACCES;
-}
-
-static int get_buffer_duration(int device_handle, const unsigned char *vibe_buffer, int *buffer_duration)
-{
- dd_list *elem;
-
- elem = DD_LIST_FIND(handle_list, (gpointer)(long)device_handle);
- if (!elem)
- return -EINVAL;
-
- _E("Not support feature");
- return -EACCES;
-}
-
-static int convert_binary(const unsigned char *vibe_buffer, int max_bufsize, const char *file_path)
-{
- _E("Not support feature");
- return -EACCES;
-}
/* END: Haptic Module APIs */
static const struct haptic_plugin_ops default_plugin = {
.open_device = open_device,
.close_device = close_device,
.vibrate_monotone = vibrate_monotone,
- .vibrate_buffer = vibrate_buffer,
.vibrate_effect = vibrate_effect,
.is_supported = is_supported,
.stop_device = stop_device,
.get_device_state = get_device_state,
- .create_effect = create_effect,
- .get_buffer_duration = get_buffer_duration,
- .convert_binary = convert_binary,
};
static bool is_valid(void)
*effect_state = state;
return 0;
}
-
-static int gpio_haptic_vibrate_buffer(int handle, const unsigned char *vibe_buffer, int iteration, int feedback, int priority, int *effect_handle)
-{
- _E("Not support feature");
- return -EACCES;
-}
-
-static int gpio_haptic_create_effect(unsigned char *vibe_buffer, int max_bufsize, const haptic_module_effect_element *elem_arr, int max_elemcnt)
-{
- _E("Not support feature");
- return -EACCES;
-}
-
-static int gpio_haptic_get_buffer_duration(int handle, const unsigned char *vibe_buffer, int *buffer_duration)
-{
- _E("Not support feature");
- return -EACCES;
-}
-
-static int gpio_haptic_convert_binary(const unsigned char *vibe_buffer, int max_bufsize, const char *file_path)
-{
- _E("Not support feature");
- return -EACCES;
-}
/* END: Haptic Module APIs */
static const struct haptic_plugin_ops default_plugin = {
.open_device = gpio_haptic_open_device,
.close_device = gpio_haptic_close_device,
.vibrate_monotone = gpio_haptic_vibrate_monotone,
- .vibrate_buffer = gpio_haptic_vibrate_buffer,
.vibrate_effect = standard_vibrate_effect,
.is_supported = standard_is_supported,
.stop_device = gpio_haptic_stop_device,
.get_device_state = gpio_haptic_get_device_state,
- .create_effect = gpio_haptic_create_effect,
- .get_buffer_duration = gpio_haptic_get_buffer_duration,
- .convert_binary = gpio_haptic_convert_binary,
};
static bool is_valid(void)
int (*open_device) (int, int*);
int (*close_device) (int);
int (*vibrate_monotone) (int, int, int, int, int*);
- int (*vibrate_buffer) (int, const unsigned char*, int, int, int, int*);
int (*vibrate_effect) (int, const char*, int, int);
int (*is_supported) (const char*);
int (*stop_device) (int);
int (*get_device_state) (int, int*);
- int (*create_effect) (unsigned char*, int, const haptic_module_effect_element*, int);
- int (*get_buffer_duration) (int, const unsigned char*, int*);
- int (*convert_binary) (const unsigned char*, int, const char*);
};
const struct haptic_plugin_ops *get_haptic_plugin_interface();
return g_variant_new("(i)", ret);
}
-GVariant *hdbus_vibrate_buffer(GDBusConnection *conn,
- const gchar *sender, const gchar *path, const gchar *iface, const gchar *name,
- GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data)
-{
- unsigned int handle;
- const unsigned char *data = NULL;
- GVariant *pvar = NULL;
- gsize size = 0;
- int iteration, level, priority, e_handle, ret = 0;
-
- if (!CHECK_VALID_OPS(h_ops, ret))
- goto exit;
-
- if (haptic_disabled)
- goto exit;
-
- g_variant_get(param, "(u@ayiii)", &handle, &pvar, &iteration, &level, &priority);
- data = g_variant_get_fixed_array(pvar, &size, sizeof(char));
- g_variant_unref(pvar);
-
- /* convert as per conf value */
- level = convert_magnitude_by_conf(level);
- if (level < 0) {
- ret = -EINVAL;
- goto exit;
- }
-
- ret = h_ops->vibrate_buffer(handle, data, iteration, level, priority, &e_handle);
- if (ret >= 0)
- ret = e_handle;
-
-exit:
- return g_variant_new("(i)", ret);
-}
-
static void vibrate_effect_idler_cb(void *data)
{
struct vibrate_effect_info *vibrate_info = (struct vibrate_effect_info *)data;
return g_variant_new("(i)", ret);
}
-GVariant *hdbus_create_effect(GDBusConnection *conn,
- const gchar *sender, const gchar *path, const gchar *iface, const gchar *name,
- GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data)
-{
- static unsigned char data[MAX_EFFECT_BUFFER];
- //static unsigned char *p = data;
- const haptic_module_effect_element *elem_arr;
- int i, cnt, ret, bufsize = sizeof(data);
- GVariant *pvar = NULL;
- gsize size = 0;
-
- if (!CHECK_VALID_OPS(h_ops, ret))
- goto exit;
-
- g_variant_get(param, "(i@ayi)", &bufsize, &pvar, &cnt);
- elem_arr = g_variant_get_fixed_array(pvar, &size, sizeof(char));
- g_variant_unref(pvar);
-
- if (bufsize > MAX_EFFECT_BUFFER) {
- ret = -ENOMEM;
- goto exit;
- }
-
- for (i = 0; i < cnt; ++i)
- _D("[%2d] %d %d", i, elem_arr[i].haptic_duration, elem_arr[i].haptic_level);
-
- memset(data, 0, MAX_EFFECT_BUFFER);
- ret = h_ops->create_effect(data, bufsize, elem_arr, cnt);
-
-exit:
- pvar = g_variant_new_fixed_array(G_VARIANT_TYPE_BYTE, data, sizeof(data), sizeof(char));
- return g_variant_new("(@ayi)", pvar, ret);
-}
-
-GVariant *hdbus_get_duration(GDBusConnection *conn,
- const gchar *sender, const gchar *path, const gchar *iface, const gchar *name,
- GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data)
-{
- unsigned int handle;
- const unsigned char *data;
- int duration, ret;
- GVariant *pvar = NULL;
- gsize size = 0;
-
- if (!CHECK_VALID_OPS(h_ops, ret))
- goto exit;
-
- g_variant_get(param, "(u@ay)", &handle, &pvar);
- data = g_variant_get_fixed_array(pvar, &size, sizeof(char));
- g_variant_unref(pvar);
-
- ret = h_ops->get_buffer_duration(handle, data, &duration);
- if (ret >= 0)
- ret = duration;
-
-exit:
- return g_variant_new("(i)", ret);
-}
-
-GVariant *hdbus_save_binary(GDBusConnection *conn,
- const gchar *sender, const gchar *path, const gchar *iface, const gchar *name,
- GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data)
-
-{
- const unsigned char *data = NULL;
- char *file_path = NULL;
- int ret;
- GVariant *pvar;
- gsize size = 0;
-
- if (!CHECK_VALID_OPS(h_ops, ret))
- goto exit;
-
- g_variant_get(param, "(@ays)", &pvar, &file_path);
- data = g_variant_get_fixed_array(pvar, &size, sizeof(char));
- g_variant_unref(pvar);
-
- _D("file path : %s", file_path);
- ret = h_ops->convert_binary(data, size, file_path);
-
-exit:
- g_free(file_path);
- return g_variant_new("(i)", ret);
-}
-
GVariant *hdbus_show_handle_list(GDBusConnection *conn,
const gchar *sender, const gchar *path, const gchar *iface, const gchar *name,
GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data)
{ "CloseDevice", "u", "i", hdbus_close_device },
{ "StopDevice", "u", "i", hdbus_stop_device },
{ "VibrateMonotone", "uiii", "i", hdbus_vibrate_monotone },
- { "VibrateBuffer", "uayiii", "i", hdbus_vibrate_buffer },
{ "VibrateEffect", "usii", "i", hdbus_vibrate_effect },
{ "GetState", "i", "i", hdbus_get_state },
- { "GetDuration", "uay", "i", hdbus_get_duration },
- { "CreateEffect", "iayi", "ayi", hdbus_create_effect },
- { "SaveBinary", "ays", "i", hdbus_save_binary },
{ "ShowHandleList", NULL, NULL, hdbus_show_handle_list },
{ "IsSupported", "s", "i", hdbus_pattern_is_supported },
/* Add methods here */
}
if (!packed || !val || !pattern_duration || !update) {
- _E("Invalid paramger");
+ _E("Invalid parameter: %p %p %p %p", packed, val, pattern_duration, update);
return -EINVAL;
}
return 0;
}
-static gboolean _buffer_play(void *cbdata)
-{
- struct ff_info *info = (struct ff_info *)cbdata;
- struct ff_info_header *header = &info->ffinfobuffer->header;
- struct ff_info_data *data = info->ffinfobuffer->data;
- int index = info->currentindex;
- int play_type = (index < header->ff_info_data_count) ? data[index].type : 0;
- int length = (index < header->ff_info_data_count) ? data[index].length : 1;
- int ret;
-
- ff_set_effect(&info->effect, length, 1);
- if (play_type != 0) {
- _D("Going to play for %d ms", length);
- ret = ff_play(ff_fd, &info->effect);
- if (ret < 0)
- _D("Failed to play the effect %d", ret);
- } else {
- _D("Going to stop for %d ms", length);
- ret = ff_stop(ff_fd, &info->effect);
- if (ret < 0)
- _D("Failed to stop the effect %d", ret);
- }
-
- if (info->currentindex < header->ff_info_data_count) {
- info->currentindex++;
- info->timer = g_timeout_add(length, _buffer_play, info);
- } else {
- --header->iteration;
- if (header->iteration > 0) {
- info->currentindex = 0;
- info->timer = g_timeout_add(0, _buffer_play, info);
- } else
- info->timer = 0;
- }
-
- return G_SOURCE_REMOVE;
-}
-
-static void print_buffer(const unsigned char *vibe_buffer)
-{
- struct ff_info_buffer fb;
- int i = 0;
- memcpy(&fb.header, vibe_buffer, sizeof(struct ff_info_header));
- memcpy(&fb.data, (unsigned char *)vibe_buffer+sizeof(struct ff_info_header),
- sizeof(struct ff_info_data) * fb.header.ff_info_data_count);
- _D("\nMagic %x\niteration %d\ncount %d\n", fb.header.magic,
- fb.header.iteration, fb.header.ff_info_data_count);
-
- for (i = 0; i < fb.header.ff_info_data_count; i++)
- _D("type %d\nmagn 0x%x\nlen %d\n", fb.data[i].type,
- fb.data[i].magnitude, fb.data[i].length);
-}
-
-static int vibrate_custom_buffer(int device_handle, const unsigned char *vibe_buffer, int iteration, int feedback, int priority, int *effect_handle)
-{
- struct ff_info *info;
- struct ff_info_header *header;
- struct ff_info_data *data;
-
- info = read_from_list(device_handle);
- if (!info)
- return -EINVAL;
-
- if (!check_valid_handle(info))
- return -EINVAL;
-
- if (!check_fd(&ff_fd))
- return -ENODEV;
-
- if (!info->ffinfobuffer)
- info->ffinfobuffer = (struct ff_info_buffer *)calloc(sizeof(struct ff_info_buffer), 1);
- if (!info->ffinfobuffer)
- return -ENOMEM;
-
- header = &info->ffinfobuffer->header;
- data = info->ffinfobuffer->data;
-
- memcpy(header, vibe_buffer, sizeof(struct ff_info_header));
- if (header->ff_info_data_count < 0 || header->ff_info_data_count > MAX_DATA)
- return -EINVAL;
-
- memcpy(data, vibe_buffer+sizeof(struct ff_info_header), sizeof(struct ff_info_data) * header->ff_info_data_count);
-
- info->currentindex = 0;
- if (info->timer)
- g_source_remove(info->timer);
-
- if (header->iteration > 0)
- _buffer_play(info);
-
- return 0;
-}
-
-static int vibrate_buffer(int device_handle, const unsigned char *vibe_buffer, int iteration, int feedback, int priority, int *effect_handle)
-{
- int magic = 0;
-
- if (!device_handle)
- return -EINVAL;
-
- if (vibe_buffer)
- magic = *(int *)vibe_buffer;
-
- if (magic == FF_INFO_MAGIC) {
- print_buffer(vibe_buffer);
- return vibrate_custom_buffer(device_handle, vibe_buffer, iteration, feedback, priority, effect_handle);
- } else
- return vibrate_monotone(device_handle, 300, feedback, priority, effect_handle);
-}
-
static int stop_device(int device_handle)
{
struct ff_info *info;
*effect_state = status;
return 0;
}
-
-static int create_effect(unsigned char *vibe_buffer, int max_bufsize, const haptic_module_effect_element *elem_arr, int max_elemcnt)
-{
- _E("Not support feature");
- return -EACCES;
-}
-
-static int get_buffer_duration(int device_handle, const unsigned char *vibe_buffer, int *buffer_duration)
-{
- _E("Not support feature");
- return -EACCES;
-}
-
-static int convert_binary(const unsigned char *vibe_buffer, int max_bufsize, const char *file_path)
-{
- _E("Not support feature");
- return -EACCES;
-}
/* END: Haptic Module APIs */
static const struct haptic_plugin_ops default_plugin = {
.open_device = open_device,
.close_device = close_device,
.vibrate_monotone = vibrate_monotone,
- .vibrate_buffer = vibrate_buffer,
.vibrate_effect = standard_vibrate_effect,
.is_supported = standard_is_supported,
.stop_device = stop_device,
.get_device_state = get_device_state,
- .create_effect = create_effect,
- .get_buffer_duration = get_buffer_duration,
- .convert_binary = convert_binary,
};
static bool is_valid(void)