From: Yunmi Ha Date: Thu, 14 Jan 2021 10:22:09 +0000 (+0900) Subject: haptic: apply next HAL architecture (hal api + backend) X-Git-Tag: submit/tizen/20210607.045509~12 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=c511a48aaf54e15346cfbb2e32dd05cdc2c3eb62;p=platform%2Fhal%2Fbackend%2Femulator%2Fdevice-emulator.git haptic: apply next HAL architecture (hal api + backend) Change-Id: If57e0f96f5dada7567ab803989535e204d9e2627 Signed-off-by: Yunmi Ha --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 42914ba..d55a9a2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -41,3 +41,4 @@ ADD_SUBDIRECTORY(hw/display) ADD_SUBDIRECTORY(hw/external_connection) ADD_SUBDIRECTORY(hw/usb_gadget) ADD_SUBDIRECTORY(hw/usb_client) +ADD_SUBDIRECTORY(hw/haptic) diff --git a/hw/haptic/CMakeLists.txt b/hw/haptic/CMakeLists.txt new file mode 100644 index 0000000..f271572 --- /dev/null +++ b/hw/haptic/CMakeLists.txt @@ -0,0 +1,25 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 2.6) +PROJECT(hal-backend-device-haptic C) + +SET(PREFIX ${CMAKE_INSTALL_PREFIX}) + +INCLUDE_DIRECTORIES(../common) + +INCLUDE(FindPkgConfig) +pkg_check_modules(haptic_pkgs REQUIRED + dlog + glib-2.0 + libsyscommon + capi-system-info) + +FOREACH(flag ${haptic_pkgs_CFLAGS}) + SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") +ENDFOREACH(flag) + +SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fvisibility=hidden") +SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}") + +ADD_LIBRARY(${PROJECT_NAME} MODULE emulator.c) +TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${haptic_pkgs_LDFLAGS}) + +INSTALL(TARGETS ${PROJECT_NAME} DESTINATION /hal/lib COMPONENT RuntimeLibraries) diff --git a/hw/haptic/emulator.c b/hw/haptic/emulator.c new file mode 100644 index 0000000..022ab05 --- /dev/null +++ b/hw/haptic/emulator.c @@ -0,0 +1,164 @@ +/* + * Copyright (c) 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 "common.h" + +static GList *handle_list; +static int unique_number = 0; + +static int get_device_count(int *count) +{ + if (count) + *count = 1; + + return 0; +} + +static int open_device(int *device_handle) +{ + GList *elem; + int handle; + bool found = false; + + if (unique_number == INT_MAX) + unique_number = 0; + + while (found != true) { + ++unique_number; + elem = SYS_G_LIST_FIND(handle_list, (gpointer)(long)unique_number); + if (!elem) + found = true; + } + handle = unique_number; + SYS_G_LIST_APPEND(handle_list, (gpointer)(long)handle); + + if (device_handle) + *device_handle = handle; + + return 0; +} + +static int close_device(int device_handle) +{ + SYS_G_LIST_REMOVE(handle_list, (gpointer)(long)device_handle); + + return 0; +} + +static int vibrate_monotone(int device_handle, int duration, int frequency, int overdrive, int level, int intensity, int priority) +{ + GList *elem; + + elem = SYS_G_LIST_FIND(handle_list, (gpointer)(long)device_handle); + if (!elem) + return -EINVAL; + + return 0; +} + +static int stop_device(int device_handle) +{ + GList *elem; + + elem = SYS_G_LIST_FIND(handle_list, (gpointer)(long)device_handle); + if (!elem) + return -EINVAL; + + return 0; +} + +#define MODEL_NAME "http://tizen.org/system/model_name" +#define MODEL_EMULATOR "Emulator" + +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; +} + +static bool is_valid(void) +{ + if (is_emulator()) { + _I("Support emulator haptic device."); + return true; + } + + _E("Do not support emulator haptic device."); + return false; +} + +static int haptic_init(void **data) +{ + hal_backend_haptic_funcs *haptic_funcs; + + haptic_funcs = calloc(1, sizeof(hal_backend_haptic_funcs)); + if (!haptic_funcs) + return -ENOMEM; + + haptic_funcs->get_device_count = get_device_count; + haptic_funcs->open_device = open_device; + haptic_funcs->close_device = close_device; + haptic_funcs->vibrate_monotone = vibrate_monotone; + haptic_funcs->stop_device = stop_device; + haptic_funcs->is_valid = is_valid; + + *data = (void *)haptic_funcs; + + return 0; +} + +static int haptic_exit(void *data) +{ + if (!data) + return -EINVAL; + + free(data); + return 0; +} + +hal_backend EXPORT hal_backend_device_haptic_data = { + .name = "haptic", + .vendor = "EMUL", + .abi_version = HAL_ABI_VERSION_TIZEN_6_5, + .init = haptic_init, + .exit = haptic_exit, +}; diff --git a/packaging/device-manager-plugin-emul.spec b/packaging/device-manager-plugin-emul.spec index 1854873..c9a9f32 100644 --- a/packaging/device-manager-plugin-emul.spec +++ b/packaging/device-manager-plugin-emul.spec @@ -16,6 +16,7 @@ BuildRequires: pkgconfig(gio-2.0) BuildRequires: pkgconfig(hal-api-common) BuildRequires: pkgconfig(hal-api-device) BuildRequires: pkgconfig(libsyscommon) +BuildRequires: pkgconfig(capi-system-info) %description Emulator plugin for libdevice-node. @@ -44,4 +45,4 @@ make %manifest device-manager-plugin-emul.manifest %{_libdir}/libslp_devman_plugin.so %{_libdir}/hw/*.so -/hal/lib/*.so* \ No newline at end of file +/hal/lib/*.so*