From 672bf127a4207f6c3becf5fd73b5d4c1c3c576b2 Mon Sep 17 00:00:00 2001 From: Jinkun Jang Date: Sat, 16 Mar 2013 01:18:03 +0900 Subject: [PATCH] merge with master --- packaging/haptic-module-tizen.spec | 4 +- test/test.c | 120 ++++++ tizen/DEVICE/CMakeLists.txt | 16 +- .../haptic_file.h => tizen/DEVICE/include/file.h | 10 +- tizen/DEVICE/src/{haptic_module_file.c => file.c} | 71 ++-- tizen/DEVICE/src/haptic_module_internal.c | 449 +++++++++++---------- tizen/DEVICE/src/sysnoti.c | 173 ++++++++ tizen/SIMULATOR/CMakeLists.txt | 2 +- tizen/SIMULATOR/src/haptic_module_internal.c | 95 ++--- 9 files changed, 645 insertions(+), 295 deletions(-) create mode 100644 test/test.c rename include/haptic_file.h => tizen/DEVICE/include/file.h (95%) rename tizen/DEVICE/src/{haptic_module_file.c => file.c} (80%) create mode 100644 tizen/DEVICE/src/sysnoti.c diff --git a/packaging/haptic-module-tizen.spec b/packaging/haptic-module-tizen.spec index 0d7437e..24472ae 100644 --- a/packaging/haptic-module-tizen.spec +++ b/packaging/haptic-module-tizen.spec @@ -2,7 +2,7 @@ Name: haptic-module-tizen Summary: Haptic Module library Version: 0.1.0 -Release: 4 +Release: 8 Group: System/Libraries License: APLv2 Source0: %{name}-%{version}.tar.gz @@ -10,7 +10,7 @@ BuildRequires: cmake BuildRequires: pkgconfig(dlog) BuildRequires: pkgconfig(vconf) BuildRequires: pkgconfig(haptic-plugin) -BuildRequires: pkgconfig(devman) +BuildRequires: pkgconfig(device-node) Requires(post): /sbin/ldconfig Requires(postun): /sbin/ldconfig diff --git a/test/test.c b/test/test.c new file mode 100644 index 0000000..d677cde --- /dev/null +++ b/test/test.c @@ -0,0 +1,120 @@ +/* + * haptic-module-tizen + * + * Copyright (c) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Jae-young Hwang + * + * PROPRIETARY/CONFIDENTIAL + * + * This software is the confidential and proprietary information of + * SAMSUNG ELECTRONICS ("Confidential Information"). You agree and acknowledge + * that this software is owned by Samsung and you shall not disclose + * such Confidential Information and shall use it only in accordance with the + * terms of the license agreement you entered into with SAMSUNG ELECTRONICS. + * SAMSUNG make no representations or warranties about the suitability + * of the software, either express or implied, including but not limited + * to the implied warranties of merchantability, fitness for a particular + * purpose, + * by licensee arising out of or releated to this software. +*/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#define HAPTIC_MODULE_PATH "/usr/lib/libhaptic-module.so" + +static void *dlopen_handle; +static const haptic_plugin_interface *plugin_intf; + +int main () +{ + char *error = NULL; + + printf("start!\n"); + dlopen_handle = dlopen(HAPTIC_MODULE_PATH, RTLD_NOW); + if (!dlopen_handle) { + printf("fail dlopen\n"); + printf("%s\n", dlerror()); + return -1; + } + + const haptic_plugin_interface *(*get_haptic_plugin_interface) (); + get_haptic_plugin_interface = dlsym(dlopen_handle, "get_haptic_plugin_interface"); + + if ((error = dlerror()) != NULL) { + printf("dlsym error\n"); + printf("%s\n", error); + dlclose(dlopen_handle); + return -1; + } + + plugin_intf = get_haptic_plugin_interface(); + if (!plugin_intf) { + printf("plugin_intf error\n"); + dlclose(dlopen_handle); + return -1; + } + + while (1) + { + char input = -1; + int duration = -1; + int handle = -1; + int status = -1; + + printf ("============================================\n"); + printf ("haptic_internal_vibrate_monotone : a\n"); + printf ("hatpic_internal_stop_all_effects : b\n"); + printf ("Quit : z\n"); + printf ("============================================\n"); + + status = scanf ("%c", &input); + + switch (input) + { + case 'a' : + printf ("Handle : "); + status = scanf ("%d", &handle); + if (status < 0) + return status; + + printf ("Duration : "); + status = scanf ("%d", &duration); + if (status < 0) + return status; + + plugin_intf->haptic_internal_vibrate_monotone(handle, duration, HAPTIC_MODULE_FEEDBACK_MAX, HAPTIC_MODULE_PRIORITY_HIGH, &handle); + break; + + case 'b': + printf ("Handle : "); + status = scanf ("%d", &handle); + if (status < 0) + return status; + plugin_intf->haptic_internal_stop_all_effects(handle); + break; + + case 'c': + break; + + case 'z': + return 0; + } + } + + if (dlopen_handle) { + dlclose(dlopen_handle); + } + + return 0; +} diff --git a/tizen/DEVICE/CMakeLists.txt b/tizen/DEVICE/CMakeLists.txt index f3fa6d6..706764e 100644 --- a/tizen/DEVICE/CMakeLists.txt +++ b/tizen/DEVICE/CMakeLists.txt @@ -1,10 +1,13 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.6) -SET(DEPENDENTS "dlog vconf haptic-plugin devman") - SET(SRCS - src/haptic_module_file.c - src/haptic_module_internal.c) + src/haptic_module_internal.c + src/file.c + src/sysnoti.c) + +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include) + +SET(DEPENDENTS "dlog vconf haptic-plugin device-node") INCLUDE(FindPkgConfig) pkg_check_modules(rpkgs REQUIRED ${DEPENDENTS}) @@ -19,10 +22,9 @@ SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -Wl,--no-as-needed") SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}") -ADD_LIBRARY(${PROJECT_NAME} SHARED ${SRCS}) -TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${rpkgs_LDFLAGS}) - ADD_DEFINITIONS("-DPREFIX=\"${PREFIX}\"") ADD_DEFINITIONS("-DENABLE_DLOG_OUT -DSLP_DEBUG") +ADD_LIBRARY(${PROJECT_NAME} SHARED ${SRCS}) +TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${rpkgs_LDFLAGS}) INSTALL(TARGETS ${PROJECT_NAME} DESTINATION lib) diff --git a/include/haptic_file.h b/tizen/DEVICE/include/file.h similarity index 95% rename from include/haptic_file.h rename to tizen/DEVICE/include/file.h index 4835946..6fa11db 100644 --- a/include/haptic_file.h +++ b/tizen/DEVICE/include/file.h @@ -16,8 +16,8 @@ */ -#ifndef __HAPTIC_FILE_H__ -#define __HAPTIC_FILE_H__ +#ifndef __FILE_H__ +#define __FILE_H__ #define GCC_PACK __attribute__((packed)) @@ -55,8 +55,8 @@ typedef struct _HapticFile { } GCC_PACK HapticFile; typedef struct _HapticElement { - int stime; int duration; + int level; } HapticElement; int GetHapticLevelMax(int *max); @@ -68,8 +68,8 @@ int InitializeHapticBuffer(unsigned char *vibe_buffer, int max_bufsize); int InsertHapticElement(unsigned char *vibe_buffer, int max_bufsize, HapticElement *element); int GetHapticBufferSize(const unsigned char *vibe_buffer, int *size); int GetHapticBufferDuration(const unsigned char *vibe_buffer, int *duration); -int PlayHapticBuffer(const unsigned char *vibe_buffer, int iteration, int *effect_handle); +int PlayHapticBuffer(const unsigned char *vibe_buffer, int iteration, int level, int *effect_handle); int OpenHapticDevice(void); int CloseHapticDevice(void); -#endif // __HAPTIC_FIEL_H__ +#endif // __FIEL_H__ diff --git a/tizen/DEVICE/src/haptic_module_file.c b/tizen/DEVICE/src/file.c similarity index 80% rename from tizen/DEVICE/src/haptic_module_file.c rename to tizen/DEVICE/src/file.c index 7f9f010..98bc613 100644 --- a/tizen/DEVICE/src/haptic_module_file.c +++ b/tizen/DEVICE/src/file.c @@ -21,13 +21,20 @@ #include #include #include -#include +#include +#include "file.h" #include "haptic_module_log.h" -#include "haptic_file.h" -#define BITPERMS 50 -#define DEFAULT_EFFECT_HANDLE 0x02 +#define BITPERMS 50 +#define MAX_LEVEL 255.0f +#define DEFAULT_EFFECT_HANDLE 0x02 + +enum { + PLAY_HAPTIC = 0, + STOP_HAPTIC, + LEVEL_HAPTIC, +}; typedef struct { unsigned char **ppbuffer; @@ -105,7 +112,7 @@ static void __clean_up(void *arg) int i = 0; MODULE_LOG("clean up handler!!! : %d", tid); - SetHapticEnable(0); + __haptic_predefine_action(STOP_HAPTIC, NULL); for (i = 0; i < pbuffer->channels; ++i) { free(pbuffer->ppbuffer[i]); @@ -123,21 +130,24 @@ static void* __play_cb(void *arg) { BUFFER *pbuffer = (BUFFER*)arg; int i = -1, j = -1, k = -1, value = -1; + unsigned char ch; + unsigned char prev = -1; MODULE_LOG("Start thread"); pthread_cleanup_push(__clean_up, arg); + __haptic_predefine_action(PLAY_HAPTIC, NULL); + /* Copy buffer from source buffer */ for (i = 0; i < pbuffer->iteration; i++) { for (j = 0; j < pbuffer->length; ++j) { for (k = 0; k < pbuffer->channels; ++k) { - value = (pbuffer->ppbuffer[k][j] > 0) ? 1 : 0; - if (SetHapticEnable(value) < 0) { - MODULE_ERROR("SetHapticEnable fail"); - pthread_exit((void *)-1); + ch = pbuffer->ppbuffer[k][j]; + if (ch != prev) { + __haptic_predefine_action(LEVEL_HAPTIC, ch); + prev = ch; } - usleep(BITPERMS * 1000); } } @@ -150,7 +160,7 @@ static void* __play_cb(void *arg) int GetHapticLevelMax(int *max) { int status = -1; - status = device_get_property(DEVTYPE_HAPTIC, HAPTIC_PROP_LEVEL_MAX, max); + status = device_get_property(DEVICE_TYPE_VIBRATOR, PROP_VIBRATOR_LEVEL_MAX, max); if (status < 0) { MODULE_ERROR("device_get_property fail : %d", status); return -1; @@ -161,7 +171,7 @@ int GetHapticLevelMax(int *max) int SetHapticEnable(int value) { int status = -1; - status = device_set_property(DEVTYPE_HAPTIC, HAPTIC_PROP_ENABLE, value); + status = device_set_property(DEVICE_TYPE_VIBRATOR, PROP_VIBRATOR_ENABLE, value); if (status < 0) { MODULE_ERROR("device_set_property fail : %d", status); return -1; @@ -172,7 +182,7 @@ int SetHapticEnable(int value) int SetHapticLevel(int value) { int status = -1; - status = device_set_property(DEVTYPE_HAPTIC, HAPTIC_PROP_LEVEL, value); + status = device_set_property(DEVICE_TYPE_VIBRATOR, PROP_VIBRATOR_LEVEL, value); if (status < 0) { MODULE_ERROR("device_set_property fail : %d", status); return -1; @@ -183,7 +193,7 @@ int SetHapticLevel(int value) int SetHapticOneshot(int value) { int status = -1; - status = device_set_property(DEVTYPE_HAPTIC, HAPTIC_PROP_ONESHOT, value); + status = device_set_property(DEVICE_TYPE_VIBRATOR, PROP_VIBRATOR_ONESHOT, value); if (status < 0) { MODULE_ERROR("device_set_property fail : %d", status); return -1; @@ -225,8 +235,9 @@ int InsertHapticElement(unsigned char *vibe_buffer, int max_bufsize, HapticEleme HapticFile *pfile = NULL; int databuf = -1; int needbuf = -1; - int stime, duration; - int i = -1, j = -1; + int duration; + unsigned char level; + int i = -1; pfile = (HapticFile*)vibe_buffer; if (_check_valid_haptic_format(pfile) < 0) { @@ -234,24 +245,24 @@ int InsertHapticElement(unsigned char *vibe_buffer, int max_bufsize, HapticEleme return -1; } - stime = element->stime/BITPERMS; duration = element->duration/BITPERMS; + level = (unsigned char)((unsigned int)element->level*MAX_LEVEL/100); - databuf = max_bufsize-sizeof(HapticFile); - needbuf = (stime+duration)*pfile->fmt.wBlockAlign; - MODULE_LOG("Data buffer size : %d, Need buffer size : %d", databuf, needbuf); + databuf = max_bufsize - sizeof(HapticFile); + needbuf = (pfile->fmt.dwDuration + duration)*pfile->fmt.wBlockAlign; + MODULE_LOG("Need buffer size : %d", needbuf); if (databuf < needbuf) { MODULE_ERROR("buffer lacks a memory : data buf(%d), need buf(%d)", databuf, needbuf); return -1; } - for (i = 0, j = stime; i < duration; ++i, j+=pfile->fmt.wBlockAlign) { - pfile->data.pData[j] = 0xFF; + for (i = pfile->fmt.dwDuration; i < pfile->fmt.dwDuration+duration; i++) { + pfile->data.pData[i] = level; } - pfile->chunkSize = sizeof(HapticFile)+needbuf; - pfile->fmt.dwDuration = element->stime+element->duration; + pfile->chunkSize = sizeof(HapticFile)+needbuf ; + pfile->fmt.dwDuration = pfile->fmt.dwDuration+duration; pfile->data.chunkSize = sizeof(DataChunk)+needbuf; return 0; } @@ -284,11 +295,12 @@ int GetHapticBufferDuration(const unsigned char *vibe_buffer, int *duration) return 0; } -int PlayHapticBuffer(const unsigned char *vibe_buffer, int iteration, int *effect_handle) +int PlayHapticBuffer(const unsigned char *vibe_buffer, int iteration, int level, int *effect_handle) { HapticFile *pfile = NULL; unsigned char **ppbuffer = NULL; - unsigned int channels, length, align, magnitude; + unsigned int channels, length, align; + unsigned char data; int i = -1, j = -1; pfile = (HapticFile*)vibe_buffer; @@ -309,8 +321,7 @@ int PlayHapticBuffer(const unsigned char *vibe_buffer, int iteration, int *effec channels = pfile->fmt.wChannels; align = pfile->fmt.wBlockAlign; length = (pfile->data.chunkSize-8)/align; - magnitude = pfile->fmt.dwMagnitude; - MODULE_LOG("channels : %d, length : %d, align : %d, magnitude : %d", channels, length, align, magnitude); + MODULE_LOG("channels : %d, length : %d, align : %d, level : %d", channels, length, align, level); /* Create buffer */ ppbuffer = (unsigned char**)malloc(sizeof(unsigned char*)*channels); @@ -322,7 +333,9 @@ int PlayHapticBuffer(const unsigned char *vibe_buffer, int iteration, int *effec /* Copy buffer from source buffer */ for (i = 0; i < length; ++i) { for (j = 0; j < channels; ++j) { - ppbuffer[j][i] = (unsigned char)(pfile->data.pData[i*align+j]); + data = (unsigned char)(pfile->data.pData[i*align+j]); + ppbuffer[j][i] = (unsigned char)(data*level/0xFF); + MODULE_LOG("ppbuffer[%2d][%2d] : data(%x) -> (%x)", j, i, data, ppbuffer[j][i]); } } diff --git a/tizen/DEVICE/src/haptic_module_internal.c b/tizen/DEVICE/src/haptic_module_internal.c index 16c15eb..186263c 100644 --- a/tizen/DEVICE/src/haptic_module_internal.c +++ b/tizen/DEVICE/src/haptic_module_internal.c @@ -24,143 +24,224 @@ #include #include #include +#include #include #include "haptic_module_log.h" -#include "haptic_file.h" +#include "file.h" #ifndef EXTAPI #define EXTAPI __attribute__ ((visibility("default"))) #endif -#define DEFAULT_MOTOR_COUNT 1 -#define DEFAULT_DEVICE_HANDLE 0x01 -#define DEFAULT_EFFECT_HANDLE 0x02 - -#define HAPTIC_PLAY_FILE_EXT ".tht" +#define DEFAULT_MOTOR_COUNT 1 +#define DEFAULT_DEVICE_HANDLE 0x01 +#define DEFAULT_EFFECT_HANDLE 0x02 +#define HAPTIC_FEEDBACK_AUTO 101 +#define HAPTIC_PLAY_FILE_EXT ".tht" /* START of Static Function Section */ -static int __feedback_to_tizen_type(int feedback) +static int __to_level(int feedback, int *type) { static int max = -1; - int status = -1; + int t; - if (max < 0) { - status = GetHapticLevelMax(&max); + if (max == -1) { + int status = GetHapticLevelMax(&max); if (status < 0) { MODULE_ERROR("GetHapticLevelMax fail : %d", status); - return -1; + return HAPTIC_MODULE_OPERATION_FAILED; } } - MODULE_LOG("feedback value is changed : %d -> %d", feedback, (int)(feedback*max/HAPTIC_MODULE_FEEDBACK_MAX)); - return (int)(feedback*max/HAPTIC_MODULE_FEEDBACK_MAX); + t = feedback * max / HAPTIC_MODULE_FEEDBACK_MAX; + MODULE_LOG("feedback value is changed : %d -> %d", feedback, t); + + if (type) + *type = t; + + return 0; +} + +static void __trim_name(const char *file_name, char *vibe_buffer, int size) +{ + int length; + + assert(file_name); + assert(vibe_buffer); + assert(size > 0); + + snprintf(vibe_buffer, size, "%s", file_name); + + length = strlen(vibe_buffer); + while (vibe_buffer[--length] == ' '); + vibe_buffer[length + 1] = '\0'; } -static char* __check_file (const char *name) +static int __check_ext(const char *name) { - char *file_full_name = NULL; - int name_length = -1; - char match_ext[4]; - char *file_ext = NULL; + char *ext; assert(name); - assert(*name); - file_full_name = strdup(name); - if (!file_full_name) { - MODULE_ERROR("strdup failed"); - return NULL; + ext = strrchr(name, '.'); + if (ext && !strcmp(ext, HAPTIC_PLAY_FILE_EXT)) + return 1; + + return 0; +} + +static int __get_size(FILE *pf, const char *fname) +{ + int status; + int size; + + assert(pf); + + status = fseek(pf, 0, SEEK_END); + if (status == -1) { + MODULE_ERROR("fseek failed: %s", fname); + return -1; } - name_length = strlen(file_full_name) - 1; - while (file_full_name[name_length] == ' ') - name_length--; - file_full_name[name_length + 1] = '\0'; + size = ftell(pf); - file_ext = strrchr(file_full_name, '.'); - if (!(file_ext && !strcmp(file_ext, HAPTIC_PLAY_FILE_EXT))) { - free(file_full_name); - MODULE_ERROR("Not supported file"); - return NULL; + status = fseek(pf, 0, SEEK_SET); + if (status == -1) { + MODULE_ERROR("fseek failed: %s", fname); + return -1; } - return file_full_name; + return size; } -static unsigned char* __convert_file_to_vibe_buffer(const char *file_name) +static unsigned char *__read_file(const char *fname) { - char *file_full_name; + int status; FILE *pf; - long file_size; - unsigned char* pIVTData; + long size; + unsigned char *vibe_buffer; - if (!file_name) { - MODULE_ERROR("Wrowng file name"); - return NULL; - } + assert(fname); - file_full_name = __check_file(file_name); - if(!file_full_name) { - MODULE_ERROR("__check_file_faild"); - return NULL; - } - - /* Get File Stream Pointer */ - pf = fopen(file_full_name, "rb"); - free(file_full_name); + pf = fopen(fname, "rb"); if (!pf) { - MODULE_ERROR("file open failed"); + MODULE_ERROR("fopen failed: %s", fname); return NULL; } - if (fseek(pf, 0, SEEK_END)) { - MODULE_ERROR("fseek failed"); + size = __get_size(pf, fname); + if (size <= 0) { fclose(pf); return NULL; } - file_size = ftell(pf); - if (file_size < 0) { - MODULE_ERROR("ftell failed"); + vibe_buffer = malloc(size); + if (!vibe_buffer) { fclose(pf); + MODULE_ERROR("buffer alloc failed"); return NULL; } - if (fseek(pf, 0, SEEK_SET)) { - MODULE_ERROR("fseek failed"); - fclose(pf); - return NULL; + status = fread(vibe_buffer, 1, size, pf); + if (status != size) { + MODULE_ERROR("fread failed: expect %d read %d", size, status); + free(vibe_buffer); + vibe_buffer = NULL; } - pIVTData = (unsigned char*)malloc(file_size); - if (!pIVTData) { - fclose(pf); + fclose(pf); + + return vibe_buffer; +} + +static unsigned char* __convert_file_to_buffer(const char *file_name) +{ + char fname[FILENAME_MAX]; + int status; + + __trim_name(file_name, fname, sizeof(fname)); + status = __check_ext(fname); + if (!status) { + MODULE_ERROR("__check_file faild"); return NULL; } - if (fread(pIVTData, 1, file_size, pf) != file_size) { - fclose(pf); - free(pIVTData); - MODULE_ERROR("fread failed"); - return NULL; + return __read_file(fname); +} + +static int __save_file(const unsigned char *vibe_buferf, int size, const char *file_name) +{ + int status; + FILE *pf; + int fd; + + pf = fopen(file_name, "wb+"); + if (pf == NULL) { + MODULE_ERROR("To open file is failed"); + return HAPTIC_MODULE_OPERATION_FAILED; + } + + status = fwrite(vibe_buferf, 1, size, pf); + if (status != size) { + MODULE_ERROR("To write file is failed"); + return HAPTIC_MODULE_OPERATION_FAILED; + } + + fd = fileno(pf); + if (fd == -1) { + MODULE_ERROR("To get file descriptor is failed"); + return HAPTIC_MODULE_OPERATION_FAILED; + } + + status = fsync(fd); + if (status == -1) { + MODULE_ERROR("To be synchronized with the disk is failed"); + return HAPTIC_MODULE_OPERATION_FAILED; } fclose(pf); - return pIVTData; + + return 0; +} + +static int __vibrate(const unsigned char *vibe_buffer, int iteration, int feedback, int priority, int *effect_handle) +{ + int status; + int level; + int handle; + + assert(vibe_buffer); + + status = __to_level(feedback, &level); + if (status != HAPTIC_MODULE_ERROR_NONE) + return status; + + status = PlayHapticBuffer(vibe_buffer, iteration, level, &handle); + if (status < 0) { + MODULE_ERROR("PlayHapticBuffer fail: %d", status); + return HAPTIC_MODULE_OPERATION_FAILED; + } + + if (effect_handle) + *effect_handle = handle; + + return 0; } /* END of Static Function Section */ -int haptic_internal_get_device_count(int *count) + +static int _get_device_count(int *count) { if (count == NULL) return HAPTIC_MODULE_INVALID_ARGUMENT; *count = DEFAULT_MOTOR_COUNT; + return HAPTIC_MODULE_ERROR_NONE; } -int haptic_internal_open_device(int device_index, int *device_handle) +static int _open_device(int device_index, int *device_handle) { if (device_index < HAPTIC_MODULE_DEVICE_0 || device_index > HAPTIC_MODULE_DEVICE_ALL) return HAPTIC_MODULE_INVALID_ARGUMENT; @@ -172,9 +253,9 @@ int haptic_internal_open_device(int device_index, int *device_handle) return HAPTIC_MODULE_ERROR_NONE; } -int haptic_internal_close_device(int device_handle) +static int _close_device(int device_handle) { - int status = -1; + int status; if (device_handle < 0) return HAPTIC_MODULE_INVALID_ARGUMENT; @@ -194,10 +275,10 @@ int haptic_internal_close_device(int device_handle) return HAPTIC_MODULE_ERROR_NONE; } -int haptic_internal_vibrate_monotone(int device_handle, int duration, int feedback, int priority, int *effect_handle) +static int _vibrate_monotone(int device_handle, int duration, int feedback, int priority, int *effect_handle) { - int status = -1; - int input_feedback = -1; + int status; + int input_feedback; if (device_handle < 0) return HAPTIC_MODULE_INVALID_ARGUMENT; @@ -217,9 +298,9 @@ int haptic_internal_vibrate_monotone(int device_handle, int duration, int feedba if (feedback == HAPTIC_MODULE_FEEDBACK_MIN) return HAPTIC_MODULE_ERROR_NONE; - input_feedback = __feedback_to_tizen_type(feedback); - if (input_feedback < 0) - return HAPTIC_MODULE_OPERATION_FAILED; + status = __to_level(feedback, &input_feedback); + if (status != HAPTIC_MODULE_ERROR_NONE) + return status; status = SetHapticLevel(input_feedback); if (status < 0) { @@ -234,16 +315,14 @@ int haptic_internal_vibrate_monotone(int device_handle, int duration, int feedba } *effect_handle = DEFAULT_EFFECT_HANDLE; + return HAPTIC_MODULE_ERROR_NONE; } -int haptic_internal_vibrate_file(int device_handle, const char *file_path, int iteration, int feedback, int priority, int *effect_handle) +static int _vibrate_file(int device_handle, const char *file_path, int iteration, int feedback, int priority, int *effect_handle) { - int status = -1; - unsigned char *vibe_buffer = NULL; - int input_feedback = -1; - int handle = -1; - int i = -1; + int status; + unsigned char *vibe_buffer; if (device_handle < 0) return HAPTIC_MODULE_INVALID_ARGUMENT; @@ -266,41 +345,20 @@ int haptic_internal_vibrate_file(int device_handle, const char *file_path, int i if (feedback == HAPTIC_MODULE_FEEDBACK_MIN) return HAPTIC_MODULE_ERROR_NONE; - input_feedback = __feedback_to_tizen_type(feedback); - if (input_feedback < 0) - return HAPTIC_MODULE_OPERATION_FAILED; - - status = SetHapticLevel(input_feedback); - if (status < 0) { - MODULE_ERROR("SetHapticLevel fail : %d", status); - return HAPTIC_MODULE_OPERATION_FAILED; - } - - vibe_buffer = __convert_file_to_vibe_buffer(file_path); + vibe_buffer = __convert_file_to_buffer(file_path); if (!vibe_buffer) { MODULE_ERROR("File load filed"); return HAPTIC_MODULE_OPERATION_FAILED; } - status = PlayHapticBuffer(vibe_buffer, iteration, &handle); - if (status < 0) { - MODULE_ERROR("PlayHapticBuffer fail: %d", status); - free(vibe_buffer); - return HAPTIC_MODULE_OPERATION_FAILED; - } - - *effect_handle = handle; + status = __vibrate(vibe_buffer, iteration, feedback , priority, effect_handle); free(vibe_buffer); - return HAPTIC_MODULE_ERROR_NONE; + + return status; } -int haptic_internal_vibrate_buffer(int device_handle, const unsigned char *vibe_buffer, int iteration, int feedback, int priority, int *effect_handle) +static int _vibrate_buffer(int device_handle, const unsigned char *vibe_buffer, int iteration, int feedback, int priority, int *effect_handle) { - int status = -1; - int input_feedback = -1; - int handle = -1; - int i = -1; - if (device_handle < 0) return HAPTIC_MODULE_INVALID_ARGUMENT; @@ -322,29 +380,12 @@ int haptic_internal_vibrate_buffer(int device_handle, const unsigned char *vibe_ if (feedback == HAPTIC_MODULE_FEEDBACK_MIN) return HAPTIC_MODULE_ERROR_NONE; - input_feedback = __feedback_to_tizen_type(feedback); - if (input_feedback < 0) - return HAPTIC_MODULE_OPERATION_FAILED; - - status = SetHapticLevel(input_feedback); - if (status < 0) { - MODULE_ERROR("SetHapticLevel fail : %d", status); - return HAPTIC_MODULE_OPERATION_FAILED; - } - - status = PlayHapticBuffer(vibe_buffer, iteration, &handle); - if (status < 0) { - MODULE_ERROR("PlayHapticBuffer fail: %d", status); - return HAPTIC_MODULE_OPERATION_FAILED; - } - - *effect_handle = handle; - return HAPTIC_MODULE_ERROR_NONE; + return __vibrate(vibe_buffer, iteration, feedback, priority, effect_handle); } -int haptic_internal_stop_effect(int device_handle, int effect_handle) +static int _stop_effect(int device_handle, int effect_handle) { - int status = -1; + int status; if (device_handle < 0) return HAPTIC_MODULE_INVALID_ARGUMENT; @@ -361,9 +402,9 @@ int haptic_internal_stop_effect(int device_handle, int effect_handle) return HAPTIC_MODULE_ERROR_NONE; } -int haptic_internal_stop_all_effects(int device_handle) +static int _stop_all_effects(int device_handle) { - int status = -1; + int status; if (device_handle < 0) return HAPTIC_MODULE_INVALID_ARGUMENT; @@ -377,29 +418,50 @@ int haptic_internal_stop_all_effects(int device_handle) return HAPTIC_MODULE_ERROR_NONE; } -int haptic_internal_pause_effect(int device_handle, int effect_handle) +static int _pause_effect(int device_handle, int effect_handle) { + if (device_handle < 0) + return HAPTIC_MODULE_INVALID_ARGUMENT; + + if (effect_handle < 0) + return HAPTIC_MODULE_INVALID_ARGUMENT; + MODULE_ERROR("This device is not supported this function(%s)", __func__); return HAPTIC_MODULE_NOT_SUPPORTED; } -int haptic_internal_resume_effect(int device_handle, int effect_handle) +static int _resume_effect(int device_handle, int effect_handle) { + if (device_handle < 0) + return HAPTIC_MODULE_INVALID_ARGUMENT; + + if (effect_handle < 0) + return HAPTIC_MODULE_INVALID_ARGUMENT; + MODULE_ERROR("This device is not supported this function(%s)", __func__); return HAPTIC_MODULE_NOT_SUPPORTED; } -int haptic_internal_get_effect_state(int device_handle, int effect_handle, int *state) +static int _get_effect_state(int device_handle, int effect_handle, int *state) { + if (device_handle < 0) + return HAPTIC_MODULE_INVALID_ARGUMENT; + + if (effect_handle < 0) + return HAPTIC_MODULE_INVALID_ARGUMENT; + + if (state == NULL) + return HAPTIC_MODULE_INVALID_ARGUMENT; + MODULE_ERROR("This device is not supported this function(%s)", __func__); return HAPTIC_MODULE_NOT_SUPPORTED; } -int haptic_internal_create_effect(unsigned char *vibe_buffer, int max_bufsize, haptic_module_effect_element *elem_arr, int max_element) +static int _create_effect(unsigned char *vibe_buffer, int max_bufsize, haptic_module_effect_element *elem_arr, int max_elemcnt) { - int status = -1; + int status; + int i; HapticElement elem; - int i = -1; if (vibe_buffer == NULL) return HAPTIC_MODULE_INVALID_ARGUMENT; @@ -410,7 +472,7 @@ int haptic_internal_create_effect(unsigned char *vibe_buffer, int max_bufsize, h if (elem_arr == NULL) return HAPTIC_MODULE_INVALID_ARGUMENT; - if (max_element < 0) + if (max_elemcnt < 0) return HAPTIC_MODULE_INVALID_ARGUMENT; status = InitializeHapticBuffer(vibe_buffer, max_bufsize); @@ -419,11 +481,17 @@ int haptic_internal_create_effect(unsigned char *vibe_buffer, int max_bufsize, h return HAPTIC_MODULE_OPERATION_FAILED; } - MODULE_LOG("effect count : %d", max_element); - for (i = 0; i < max_element; ++i) { - elem.stime = elem_arr[i].haptic_stime; + MODULE_LOG("effect count : %d", max_elemcnt); + for (i = 0; i < max_elemcnt; ++i) { elem.duration = elem_arr[i].haptic_duration; - MODULE_LOG("%d) time : %d, duration : %d", i, elem_arr[i].haptic_stime, elem_arr[i].haptic_duration); + if (elem_arr[i].haptic_level == HAPTIC_FEEDBACK_AUTO) { + vconf_get_int(VCONFKEY_SETAPPL_TOUCH_FEEDBACK_VIBRATION_LEVEL_INT, &elem_arr[i].haptic_level); + elem.level = elem_arr[i].haptic_level*20; + } + else { + elem.level = elem_arr[i].haptic_level; + } + MODULE_LOG("%d) duration : %d, level : %d", i, elem_arr[i].haptic_duration, elem_arr[i].haptic_level); status = InsertHapticElement(vibe_buffer, max_bufsize, &elem); if (status < 0) { @@ -435,13 +503,10 @@ int haptic_internal_create_effect(unsigned char *vibe_buffer, int max_bufsize, h return HAPTIC_MODULE_ERROR_NONE; } -int haptic_internal_save_effect(const unsigned char *vibe_buffer, int max_bufsize, const char *file_path) +static int _save_effect(const unsigned char *vibe_buffer, int max_bufsize, const char *file_path) { - int status = -1; - FILE *file = NULL; - int fd = -1; - int size = -1; - int ret; + int status; + int size; if (vibe_buffer == NULL) return HAPTIC_MODULE_INVALID_ARGUMENT; @@ -458,40 +523,13 @@ int haptic_internal_save_effect(const unsigned char *vibe_buffer, int max_bufsiz return HAPTIC_MODULE_OPERATION_FAILED; } - file = fopen(file_path, "wb"); - if (file == NULL) { - MODULE_ERROR("To open file is failed"); - return HAPTIC_MODULE_OPERATION_FAILED; - } - - ret = fwrite(vibe_buffer, 1, size, file); - if (ret != size) { - MODULE_ERROR("To write file is failed"); - fclose(file); - return HAPTIC_MODULE_OPERATION_FAILED; - } - - fd = fileno(file); - if (fd < 0) { - MODULE_ERROR("To get file descriptor is failed"); - fclose(file); - return HAPTIC_MODULE_OPERATION_FAILED; - } - - if (fsync(fd) < 0) { - MODULE_ERROR("To be synchronized with the disk is failed"); - fclose(file); - return HAPTIC_MODULE_OPERATION_FAILED; - } - - fclose(file); - return HAPTIC_MODULE_ERROR_NONE; + return __save_file(vibe_buffer, size, file_path); } -int haptic_internal_get_file_duration(int device_handle, const char *file_path, int *file_duration) +static int _get_file_duration(int device_handle, const char *file_path, int *file_duration) { - int status = -1; - unsigned char *vibe_buffer = NULL; + int status; + unsigned char *vibe_buffer; int duration = -1; if (device_handle < 0) @@ -503,13 +541,14 @@ int haptic_internal_get_file_duration(int device_handle, const char *file_path, if (file_duration == NULL) return HAPTIC_MODULE_INVALID_ARGUMENT; - vibe_buffer = __convert_file_to_vibe_buffer(file_path); + vibe_buffer = __convert_file_to_buffer(file_path); if (!vibe_buffer) { MODULE_ERROR("File load filed"); return HAPTIC_MODULE_OPERATION_FAILED; } status = GetHapticBufferDuration(vibe_buffer, &duration); + free(vibe_buffer); if (status < 0) { MODULE_ERROR("GetHapticBufferDuration fail: %d", status); free(vibe_buffer); @@ -517,14 +556,13 @@ int haptic_internal_get_file_duration(int device_handle, const char *file_path, } *file_duration = duration; - free(vibe_buffer); return HAPTIC_MODULE_ERROR_NONE; } -int haptic_internal_get_buffer_duration(int device_handle, const unsigned char *vibe_buffer, int *buffer_duration) +static int _get_buffer_duration(int device_handle, const unsigned char *vibe_buffer, int *buffer_duration) { - int status = -1; - int duration = -1; + int status; + int duration; if (device_handle < 0) return HAPTIC_MODULE_INVALID_ARGUMENT; @@ -542,36 +580,37 @@ int haptic_internal_get_buffer_duration(int device_handle, const unsigned char * } *buffer_duration = duration; + return HAPTIC_MODULE_ERROR_NONE; } -int haptic_internal_convert_binary (void) +static int _convert_binary (void) { MODULE_ERROR("This device is not supported this function(%s)", __func__); return HAPTIC_MODULE_NOT_SUPPORTED; } -static haptic_plugin_interface haptic_plugin_tizen; +static const haptic_plugin_interface haptic_plugin_tizen = { + .haptic_internal_get_device_count = _get_device_count, + .haptic_internal_open_device = _open_device, + .haptic_internal_close_device = _close_device, + .haptic_internal_vibrate_monotone = _vibrate_monotone, + .haptic_internal_vibrate_file = _vibrate_file, + .haptic_internal_vibrate_buffer = _vibrate_buffer, + .haptic_internal_stop_effect = _stop_effect, + .haptic_internal_stop_all_effects = _stop_all_effects, + .haptic_internal_pause_effect = _pause_effect, + .haptic_internal_resume_effect = _resume_effect, + .haptic_internal_get_effect_state = _get_effect_state, + .haptic_internal_create_effect = _create_effect, + .haptic_internal_save_effect = _save_effect, + .haptic_internal_get_file_duration = _get_file_duration, + .haptic_internal_get_buffer_duration = _get_buffer_duration, + .haptic_internal_convert_binary = _convert_binary, +}; EXTAPI const haptic_plugin_interface *get_haptic_plugin_interface() { - haptic_plugin_tizen.haptic_internal_get_device_count= &haptic_internal_get_device_count; - haptic_plugin_tizen.haptic_internal_open_device = &haptic_internal_open_device; - haptic_plugin_tizen.haptic_internal_close_device = &haptic_internal_close_device; - haptic_plugin_tizen.haptic_internal_vibrate_monotone= &haptic_internal_vibrate_monotone; - haptic_plugin_tizen.haptic_internal_vibrate_file = &haptic_internal_vibrate_file; - haptic_plugin_tizen.haptic_internal_vibrate_buffer = &haptic_internal_vibrate_buffer; - haptic_plugin_tizen.haptic_internal_stop_effect = &haptic_internal_stop_effect; - haptic_plugin_tizen.haptic_internal_stop_all_effects= &haptic_internal_stop_all_effects; - haptic_plugin_tizen.haptic_internal_pause_effect = &haptic_internal_pause_effect; - haptic_plugin_tizen.haptic_internal_resume_effect = &haptic_internal_resume_effect; - haptic_plugin_tizen.haptic_internal_get_effect_state= &haptic_internal_get_effect_state; - haptic_plugin_tizen.haptic_internal_create_effect = &haptic_internal_create_effect; - haptic_plugin_tizen.haptic_internal_save_effect = &haptic_internal_save_effect; - haptic_plugin_tizen.haptic_internal_get_file_duration = &haptic_internal_get_file_duration; - haptic_plugin_tizen.haptic_internal_get_buffer_duration = &haptic_internal_get_buffer_duration; - haptic_plugin_tizen.haptic_internal_convert_binary = &haptic_internal_convert_binary; - return &haptic_plugin_tizen; } diff --git a/tizen/DEVICE/src/sysnoti.c b/tizen/DEVICE/src/sysnoti.c new file mode 100644 index 0000000..55e5a34 --- /dev/null +++ b/tizen/DEVICE/src/sysnoti.c @@ -0,0 +1,173 @@ +/* + * haptic-module-tizen + * Copyright (c) 2012 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "haptic_module_log.h" + +#define HAPTIC_RETRY_READ_COUNT 5 +#define HAPTIC_PARAM_CNT 3 +#define HAPTIC_MAXSTR 100 +#define HAPTIC_MAXARG 16 +#define PREDEF_HAPTIC "haptic" +#define SYSNOTI_SOCKET_PATH "/tmp/sn" + +enum sysnoti_cmd { + ADD_HAPTIC_ACTION, + CALL_HAPTIC_ACTION, +}; + +struct sysnoti_type { + int pid; + int cmd; + char *type; + char *path; + int argc; + char *argv[HAPTIC_MAXARG]; +}; + +static inline int __send_int(int fd, int val) +{ + return write(fd, &val, sizeof(int)); +} + +static inline int __send_str(int fd, char *str) +{ + int len; + int r; + + if (str == NULL) { + len = 0; + r = write(fd, &len, sizeof(int)); + } else { + len = strlen(str); + if (len > HAPTIC_MAXSTR) + len = HAPTIC_MAXSTR; + r = write(fd, &len, sizeof(int)); + r = write(fd, str, len); + } + + return r; +} + +static int __sysnoti_send(struct sysnoti_type *msg) +{ + int sockfd; + int len; + struct sockaddr_un addr; + int retry_cnt; + int ret; + int i; + int r; + + sockfd = socket(AF_UNIX, SOCK_STREAM, 0); + if (sockfd == -1) { + MODULE_ERROR("socket create failed"); + return -1; + } + + bzero(&addr, sizeof(addr)); + addr.sun_family = AF_UNIX; + strncpy(addr.sun_path, SYSNOTI_SOCKET_PATH, sizeof(addr.sun_path) - 1); + len = sizeof(addr); + + if (connect(sockfd, (struct sockaddr *)&addr, len) < 0) { + MODULE_ERROR("connect failed"); + close(sockfd); + return -1; + } + + __send_int(sockfd, msg->pid); + __send_int(sockfd, msg->cmd); + __send_str(sockfd, msg->type); + __send_str(sockfd, msg->path); + __send_int(sockfd, msg->argc); + for (i = 0; i < msg->argc; i++) + __send_str(sockfd, msg->argv[i]); + + retry_cnt = 0; + while ((r = read(sockfd, &ret, sizeof(int))) < 0) { + + if (errno != EINTR) { + MODULE_LOG("read fail : %s(%d)", strerror(errno), errno); + ret = -1; + break; + } + + if (retry_cnt == HAPTIC_RETRY_READ_COUNT) { + MODULE_ERROR("retry(%d) fail", retry_cnt); + ret = -1; + break; + } + + MODULE_ERROR("Re-read for error(EINTR)"); + ++retry_cnt; + } + + close(sockfd); + return ret; +} + +static int __haptic_call_predef_action(const char *type, int num, ...) +{ + struct sysnoti_type msg; + char *args; + va_list argptr; + int i; + + if (type == NULL || num > HAPTIC_MAXARG) { + errno = EINVAL; + return -1; + } + + msg.pid = getpid(); + msg.cmd = CALL_HAPTIC_ACTION; + msg.type = (char *)type; + msg.path = NULL; + msg.argc = num; + + va_start(argptr, num); + for (i = 0; i < num; i++) { + args = va_arg(argptr, char *); + msg.argv[i] = args; + } + va_end(argptr); + + return __sysnoti_send(&msg); +} + +void __haptic_predefine_action(int prop, int val) +{ + char pid_buf[255]; + char prop_buf[255]; + char val_buf[255]; + + snprintf(pid_buf, sizeof(pid_buf), "%d", getpid()); + snprintf(prop_buf, sizeof(prop_buf), "%d", prop); + snprintf(val_buf, sizeof(val_buf), "%d", val); + + MODULE_LOG("pid : %d, type : %d, val : %d", getpid(), prop, val); + __haptic_call_predef_action(PREDEF_HAPTIC, HAPTIC_PARAM_CNT, pid_buf, prop_buf, val_buf); +} diff --git a/tizen/SIMULATOR/CMakeLists.txt b/tizen/SIMULATOR/CMakeLists.txt index 41d821a..9d46f44 100644 --- a/tizen/SIMULATOR/CMakeLists.txt +++ b/tizen/SIMULATOR/CMakeLists.txt @@ -1,6 +1,6 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.6) -SET(DEPENDENTS "dlog vconf haptic-plugin devman") +SET(DEPENDENTS "dlog haptic-plugin") SET(SRCS src/haptic_module_internal.c) diff --git a/tizen/SIMULATOR/src/haptic_module_internal.c b/tizen/SIMULATOR/src/haptic_module_internal.c index 732ba07..eed065f 100644 --- a/tizen/SIMULATOR/src/haptic_module_internal.c +++ b/tizen/SIMULATOR/src/haptic_module_internal.c @@ -1,20 +1,23 @@ /* * haptic-module-tizen - * Copyright (c) 2012 Samsung Electronics Co., Ltd. * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Copyright (c) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved. * - * http://www.apache.org/licenses/LICENSE-2.0 + * Contact: Jae-young Hwang * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - + * PROPRIETARY/CONFIDENTIAL + * + * This software is the confidential and proprietary information of + * SAMSUNG ELECTRONICS ("Confidential Information"). You agree and acknowledge + * that this software is owned by Samsung and you shall not disclose + * such Confidential Information and shall use it only in accordance with the + * terms of the license agreement you entered into with SAMSUNG ELECTRONICS. + * SAMSUNG make no representations or warranties about the suitability + * of the software, either express or implied, including but not limited + * to the implied warranties of merchantability, fitness for a particular + * purpose, + * by licensee arising out of or releated to this software. +*/ #include #include @@ -35,7 +38,7 @@ #define DEFAULT_DEVICE_HANDLE 0x01 #define DEFAULT_EFFECT_HANDLE 0x02 -int haptic_internal_get_device_count(int *count) +static int _get_device_count(int *count) { if (count == NULL) return HAPTIC_MODULE_INVALID_ARGUMENT; @@ -44,7 +47,7 @@ int haptic_internal_get_device_count(int *count) return HAPTIC_MODULE_ERROR_NONE; } -int haptic_internal_open_device(int device_index, int *device_handle) +static int _open_device(int device_index, int *device_handle) { if (device_index < HAPTIC_MODULE_DEVICE_0 || device_index > HAPTIC_MODULE_DEVICE_ALL) return HAPTIC_MODULE_INVALID_ARGUMENT; @@ -56,7 +59,7 @@ int haptic_internal_open_device(int device_index, int *device_handle) return HAPTIC_MODULE_ERROR_NONE; } -int haptic_internal_close_device(int device_handle) +static int _close_device(int device_handle) { if (device_handle < 0) return HAPTIC_MODULE_INVALID_ARGUMENT; @@ -64,7 +67,7 @@ int haptic_internal_close_device(int device_handle) return HAPTIC_MODULE_ERROR_NONE; } -int haptic_internal_vibrate_monotone(int device_handle, int duration, int feedback, int priority, int *effect_handle) +static int _vibrate_monotone(int device_handle, int duration, int feedback, int priority, int *effect_handle) { if (device_handle < 0) return HAPTIC_MODULE_INVALID_ARGUMENT; @@ -90,7 +93,7 @@ int haptic_internal_vibrate_monotone(int device_handle, int duration, int feedba return HAPTIC_MODULE_ERROR_NONE; } -int haptic_internal_vibrate_file(int device_handle, const char *file_path, int iteration, int feedback, int priority, int *effect_handle) +static int _vibrate_file(int device_handle, const char *file_path, int iteration, int feedback, int priority, int *effect_handle) { if (device_handle < 0) return HAPTIC_MODULE_INVALID_ARGUMENT; @@ -119,7 +122,7 @@ int haptic_internal_vibrate_file(int device_handle, const char *file_path, int i return HAPTIC_MODULE_ERROR_NONE; } -int haptic_internal_vibrate_buffer(int device_handle, const unsigned char *vibe_buffer, int iteration, int feedback, int priority, int *effect_handle) +static int _vibrate_buffer(int device_handle, const unsigned char *vibe_buffer, int iteration, int feedback, int priority, int *effect_handle) { if (device_handle < 0) return HAPTIC_MODULE_INVALID_ARGUMENT; @@ -148,7 +151,7 @@ int haptic_internal_vibrate_buffer(int device_handle, const unsigned char *vibe_ return HAPTIC_MODULE_ERROR_NONE; } -int haptic_internal_stop_effect(int device_handle, int effect_handle) +static int _stop_effect(int device_handle, int effect_handle) { if (device_handle < 0) return HAPTIC_MODULE_INVALID_ARGUMENT; @@ -161,7 +164,7 @@ int haptic_internal_stop_effect(int device_handle, int effect_handle) return HAPTIC_MODULE_ERROR_NONE; } -int haptic_internal_stop_all_effects(int device_handle) +static int _stop_all_effects(int device_handle) { if (device_handle < 0) return HAPTIC_MODULE_INVALID_ARGUMENT; @@ -171,7 +174,7 @@ int haptic_internal_stop_all_effects(int device_handle) return HAPTIC_MODULE_ERROR_NONE; } -int haptic_internal_pause_effect(int device_handle, int effect_handle) +static int _pause_effect(int device_handle, int effect_handle) { if (device_handle < 0) return HAPTIC_MODULE_INVALID_ARGUMENT; @@ -184,7 +187,7 @@ int haptic_internal_pause_effect(int device_handle, int effect_handle) return HAPTIC_MODULE_ERROR_NONE; } -int haptic_internal_resume_effect(int device_handle, int effect_handle) +static int _resume_effect(int device_handle, int effect_handle) { if (device_handle < 0) return HAPTIC_MODULE_INVALID_ARGUMENT; @@ -197,7 +200,7 @@ int haptic_internal_resume_effect(int device_handle, int effect_handle) return HAPTIC_MODULE_ERROR_NONE; } -int haptic_internal_get_effect_state(int device_handle, int effect_handle, int *effect_state) +static int _get_effect_state(int device_handle, int effect_handle, int *effect_state) { if (device_handle < 0) return HAPTIC_MODULE_INVALID_ARGUMENT; @@ -213,7 +216,7 @@ int haptic_internal_get_effect_state(int device_handle, int effect_handle, int * return HAPTIC_MODULE_ERROR_NONE; } -int haptic_internal_create_effect(const unsigned char *vibe_buffer, int max_bufsize, haptic_module_effect_element *elem_arr, int max_elemcnt) +static int _create_effect(const unsigned char *vibe_buffer, int max_bufsize, haptic_module_effect_element *elem_arr, int max_elemcnt) { if (vibe_buffer == NULL) return HAPTIC_MODULE_INVALID_ARGUMENT; @@ -232,7 +235,7 @@ int haptic_internal_create_effect(const unsigned char *vibe_buffer, int max_bufs return HAPTIC_MODULE_ERROR_NONE; } -int haptic_internal_save_effect(const unsigned char *vibe_buffer, int max_bufsize, const char *file_path) +static int _save_effect(const unsigned char *vibe_buffer, int max_bufsize, const char *file_path) { if (vibe_buffer == NULL) return HAPTIC_MODULE_INVALID_ARGUMENT; @@ -248,7 +251,7 @@ int haptic_internal_save_effect(const unsigned char *vibe_buffer, int max_bufsiz return HAPTIC_MODULE_ERROR_NONE; } -int haptic_internal_get_file_duration(int device_handle, const char *file_path, int *file_duration) +static int _get_file_duration(int device_handle, const char *file_path, int *file_duration) { if (device_handle < 0) return HAPTIC_MODULE_INVALID_ARGUMENT; @@ -264,7 +267,7 @@ int haptic_internal_get_file_duration(int device_handle, const char *file_path, return HAPTIC_MODULE_ERROR_NONE; } -int haptic_internal_get_buffer_duration(int device_handle, const unsigned char *vibe_buffer, int *buffer_duration) +static int _get_buffer_duration(int device_handle, const unsigned char *vibe_buffer, int *buffer_duration) { if (device_handle < 0) return HAPTIC_MODULE_INVALID_ARGUMENT; @@ -280,33 +283,33 @@ int haptic_internal_get_buffer_duration(int device_handle, const unsigned char * return HAPTIC_MODULE_ERROR_NONE; } -int haptic_internal_convert_binary (void) +static int _convert_binary (void) { MODULE_ERROR("This device is not supported this function(%s)", __func__); return HAPTIC_MODULE_NOT_SUPPORTED; } -static haptic_plugin_interface haptic_plugin_emul; +static haptic_plugin_interface haptic_plugin_emul = { + .haptic_internal_get_device_count = _get_device_count, + .haptic_internal_open_device = _open_device, + .haptic_internal_close_device = _close_device, + .haptic_internal_vibrate_monotone = _vibrate_monotone, + .haptic_internal_vibrate_file = _vibrate_file, + .haptic_internal_vibrate_buffer = _vibrate_buffer, + .haptic_internal_stop_effect = _stop_effect, + .haptic_internal_stop_all_effects = _stop_all_effects, + .haptic_internal_pause_effect = _pause_effect, + .haptic_internal_resume_effect = _resume_effect, + .haptic_internal_get_effect_state = _get_effect_state, + .haptic_internal_create_effect = _create_effect, + .haptic_internal_save_effect = _save_effect, + .haptic_internal_get_file_duration = _get_file_duration, + .haptic_internal_get_buffer_duration = _get_buffer_duration, + .haptic_internal_convert_binary = _convert_binary, +}; EXTAPI const haptic_plugin_interface *get_haptic_plugin_interface() { - haptic_plugin_emul.haptic_internal_get_device_count = &haptic_internal_get_device_count; - haptic_plugin_emul.haptic_internal_open_device = &haptic_internal_open_device; - haptic_plugin_emul.haptic_internal_close_device = &haptic_internal_close_device; - haptic_plugin_emul.haptic_internal_vibrate_monotone = &haptic_internal_vibrate_monotone; - haptic_plugin_emul.haptic_internal_vibrate_file = &haptic_internal_vibrate_file; - haptic_plugin_emul.haptic_internal_vibrate_buffer = &haptic_internal_vibrate_buffer; - haptic_plugin_emul.haptic_internal_stop_effect = &haptic_internal_stop_effect; - haptic_plugin_emul.haptic_internal_stop_all_effects = &haptic_internal_stop_all_effects; - haptic_plugin_emul.haptic_internal_pause_effect = &haptic_internal_pause_effect; - haptic_plugin_emul.haptic_internal_resume_effect = &haptic_internal_resume_effect; - haptic_plugin_emul.haptic_internal_get_effect_state = &haptic_internal_get_effect_state; - haptic_plugin_emul.haptic_internal_create_effect = &haptic_internal_create_effect; - haptic_plugin_emul.haptic_internal_save_effect = &haptic_internal_save_effect; - haptic_plugin_emul.haptic_internal_get_file_duration = &haptic_internal_get_file_duration; - haptic_plugin_emul.haptic_internal_get_buffer_duration = &haptic_internal_get_buffer_duration; - haptic_plugin_emul.haptic_internal_convert_binary = &haptic_internal_convert_binary; - return &haptic_plugin_emul; } -- 2.7.4