haptic: Do not check handle value on emulator 63/106263/1
authorpr.jung <pr.jung@samsung.com>
Wed, 21 Dec 2016 07:15:12 +0000 (16:15 +0900)
committerpr.jung <pr.jung@samsung.com>
Wed, 21 Dec 2016 07:15:12 +0000 (16:15 +0900)
- deviced-vibrator always returns same handle on Emulator

Change-Id: I27541c9e6776599e419a459a87d8679fe6075945
Signed-off-by: pr.jung <pr.jung@samsung.com>
src/common.c
src/common.h
src/haptic.c

index 4936577..40e8516 100644 (file)
@@ -17,6 +17,8 @@
 #include <stdio.h>
 #include <string.h>
 #include <errno.h>
+#include <stdlib.h>
+#include <system_info.h>
 #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;
+}
index 1f8a96c..e1bdcc6 100644 (file)
@@ -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__ */
index 2fcf096..2d80445 100644 (file)
@@ -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);