From: pr.jung Date: Wed, 21 Dec 2016 07:15:12 +0000 (+0900) Subject: haptic: Do not check handle value on emulator X-Git-Tag: submit/tizen_3.0/20161222.072356~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=c070415ffb2959cf508cfdb7857a528498b13e2e;p=platform%2Fcore%2Fapi%2Fdevice.git haptic: Do not check handle value on emulator - deviced-vibrator always returns same handle on Emulator Change-Id: I27541c9e6776599e419a459a87d8679fe6075945 Signed-off-by: pr.jung --- diff --git a/src/common.c b/src/common.c index 4936577..40e8516 100644 --- a/src/common.c +++ b/src/common.c @@ -17,6 +17,8 @@ #include #include #include +#include +#include #include "common.h" #define MAX_LINE 128 @@ -25,6 +27,9 @@ #define NEWLINE "\n\r" #define COMMENT '#' +#define MODEL_NAME "http://tizen.org/system/model_name" +#define MODEL_EMULATOR "Emulator" + static inline char *trim_str(char *s) { char *t; @@ -126,3 +131,28 @@ error: _E("Failed to read %s:%d!", file_name, lineno); return ret; } + +bool is_emulator(void) +{ + int ret; + char *model_name = NULL; + static bool emul = false; + static int set = 0; + + if (set) + return emul; + + ret = system_info_get_platform_string(MODEL_NAME, &model_name); + if (ret < 0) { + _E("Cannot get model name(%d)", ret); + return emul; + } + + if (!strncmp(MODEL_EMULATOR, model_name, strlen(model_name) + 1)) + emul = true; + + set = 1; + free(model_name); + + return emul; +} diff --git a/src/common.h b/src/common.h index 1f8a96c..e1bdcc6 100644 --- a/src/common.h +++ b/src/common.h @@ -66,4 +66,6 @@ int config_parse(const char *file_name, int cb(struct parse_result *result, void *data), void *user_data); +bool is_emulator(void); + #endif /* __COMMON_H__ */ diff --git a/src/haptic.c b/src/haptic.c index 2fcf096..2d80445 100644 --- a/src/haptic.c +++ b/src/haptic.c @@ -127,11 +127,13 @@ int device_haptic_open(int device_index, haptic_device_h *device_handle) if (ret < 0) return errno_to_device_error(ret); //LCOV_EXCL_LINE System Error - DD_LIST_FOREACH(handle_list, elem, temp) { - if (temp->handle == ret) { - found = true; - temp->index = device_index; - break; + if (!is_emulator()) { + DD_LIST_FOREACH(handle_list, elem, temp) { + if (temp->handle == ret) { + found = true; + temp->index = device_index; + break; + } } } @@ -142,6 +144,7 @@ int device_haptic_open(int device_index, haptic_device_h *device_handle) DD_LIST_APPEND(handle_list, handle); *device_handle = (haptic_device_h)handle; } + if (DD_LIST_LENGTH(handle_list) == 1) { ret = register_signal_handler(); if (ret < 0) @@ -164,15 +167,19 @@ int device_haptic_close(haptic_device_h device_handle) if (!device_handle) return DEVICE_ERROR_INVALID_PARAMETER; - DD_LIST_FOREACH(handle_list, elem, temp) { - if (temp->handle != handle->handle) - continue; - found = true; - break; + if (!is_emulator()) { + + DD_LIST_FOREACH(handle_list, elem, temp) { + if (temp->handle != handle->handle) + continue; + found = true; + break; + } + + if (!found) + return DEVICE_ERROR_OPERATION_FAILED; } - if (!found) - return DEVICE_ERROR_OPERATION_FAILED; DD_LIST_REMOVE(handle_list, handle); snprintf(str_handle, sizeof(str_handle), "%u", (unsigned int)handle->handle); free(handle);