From 7384251532a8c5bc805f4d0033b3466b4bf46707 Mon Sep 17 00:00:00 2001 From: Yunmi Ha Date: Mon, 6 Jul 2020 16:47:19 +0900 Subject: [PATCH 01/16] Remove duplicated code Change-Id: I934f6cf3efc9194333e303cfab156863ae746b89 Signed-off-by: Yunmi Ha --- src/auto-test/haptic.c | 138 ++++++++++++------------------------------------- 1 file changed, 33 insertions(+), 105 deletions(-) diff --git a/src/auto-test/haptic.c b/src/auto-test/haptic.c index c8ec2a8..dbf5872 100644 --- a/src/auto-test/haptic.c +++ b/src/auto-test/haptic.c @@ -27,7 +27,7 @@ #define METHOD_HAPTIC_SHOWHANDLELIST "ShowHandleList" #define METHOD_HAPTIC_ISSUPPORTED "IsSupported" -static bool request_haptic_method(const char *method, GVariant *param) +static bool request_haptic_method(const char *method, GVariant *param, int *return_val) { GVariant *msg; int val; @@ -60,180 +60,108 @@ static bool request_haptic_method(const char *method, GVariant *param) } g_variant_unref(msg); + + if (return_val) + *return_val = val; + return ret; } static bool haptic_getcount() { _D("----------------------------------------------------------------------------------"); - return request_haptic_method(METHOD_HAPTIC_GETCOUNT, NULL); + return request_haptic_method(METHOD_HAPTIC_GETCOUNT, NULL, NULL); } static bool haptic_opendevice(int index) { _D("----------------------------------------------------------------------------------"); - return request_haptic_method(METHOD_HAPTIC_OPENDEVICE, g_variant_new("(i)", index)); + return request_haptic_method(METHOD_HAPTIC_OPENDEVICE, g_variant_new("(i)", index), NULL); } static bool haptic_closedevice() { - GVariant *msg; int handle; bool ret = FALSE; _D("----------------------------------------------------------------------------------"); - msg = dbus_handle_method_sync_with_reply_var(VIBRATOR_BUS_NAME, - VIBRATOR_PATH_HAPTIC, - VIBRATOR_INTERFACE_HAPTIC, - METHOD_HAPTIC_OPENDEVICE, - g_variant_new("(i)", 0)); - - if (!msg) { - _E("Failed to call dbus method(%s): no reply", METHOD_HAPTIC_OPENDEVICE); - return ret; - } - - if (dh_get_param_from_var(msg, "(i)", &handle)) - ret = request_haptic_method(METHOD_HAPTIC_CLOSEDEVICE, g_variant_new("(u)", handle)); + if (request_haptic_method(METHOD_HAPTIC_OPENDEVICE, g_variant_new("(i)", 0), &handle)) + ret = request_haptic_method(METHOD_HAPTIC_CLOSEDEVICE, g_variant_new("(u)", handle), NULL); else _E("Failed to call dbus method(%s): no message", METHOD_HAPTIC_OPENDEVICE); - g_variant_unref(msg); - return ret; } static bool haptic_vibratemonotone(int duration, int level, int priority) { - GVariant *msg; int handle; bool ret = FALSE; _D("----------------------------------------------------------------------------------"); - msg = dbus_handle_method_sync_with_reply_var(VIBRATOR_BUS_NAME, - VIBRATOR_PATH_HAPTIC, - VIBRATOR_INTERFACE_HAPTIC, - METHOD_HAPTIC_OPENDEVICE, - g_variant_new("(i)", 0)); - - if (!msg) { - _E("Failed to call dbus method(%s): no reply", METHOD_HAPTIC_OPENDEVICE); - return ret; - } - - if (dh_get_param_from_var(msg, "(i)", &handle)) - ret = request_haptic_method(METHOD_HAPTIC_VIBRATEMONOTONE, g_variant_new("(uiii)", handle, duration, level, priority)); - else + if (request_haptic_method(METHOD_HAPTIC_OPENDEVICE, g_variant_new("(i)", 0), &handle)) { + ret = request_haptic_method(METHOD_HAPTIC_VIBRATEMONOTONE, g_variant_new("(uiii)", handle, duration, level, priority), NULL); + usleep(duration*1000); + request_haptic_method(METHOD_HAPTIC_CLOSEDEVICE, g_variant_new("(u)", handle), NULL); + } else _E("Failed to call dbus method(%s): no message", METHOD_HAPTIC_OPENDEVICE); - g_variant_unref(msg); - return ret; } static bool haptic_vibratepattern(char *pattern, int level, int priority) { - GVariant *msg; int handle; bool ret = FALSE; _D("----------------------------------------------------------------------------------"); - msg = dbus_handle_method_sync_with_reply_var(VIBRATOR_BUS_NAME, - VIBRATOR_PATH_HAPTIC, - VIBRATOR_INTERFACE_HAPTIC, - METHOD_HAPTIC_OPENDEVICE, - g_variant_new("(i)", 0)); - - if (!msg) { - _E("Failed to call dbus method(%s): no reply", METHOD_HAPTIC_OPENDEVICE); - return ret; - } - - if (dh_get_param_from_var(msg, "(i)", &handle)) - ret = request_haptic_method(METHOD_HAPTIC_VIBRATEEFFECT, g_variant_new("(usii)", handle, pattern, level, priority)); - else + if (request_haptic_method(METHOD_HAPTIC_OPENDEVICE, g_variant_new("(i)", 0), &handle)) { + ret = request_haptic_method(METHOD_HAPTIC_VIBRATEEFFECT, g_variant_new("(usii)", handle, pattern, level, priority), NULL); + usleep(1000*1000); // 1 sec + request_haptic_method(METHOD_HAPTIC_CLOSEDEVICE, g_variant_new("(u)", handle), NULL); + } else _E("Failed to call dbus method(%s): no message", METHOD_HAPTIC_OPENDEVICE); - g_variant_unref(msg); - return ret; } static bool haptic_stopdevice() { - struct timespec time = {0,}; - GVariant *msg; int handle; bool ret = FALSE; _D("----------------------------------------------------------------------------------"); - msg = dbus_handle_method_sync_with_reply_var(VIBRATOR_BUS_NAME, - VIBRATOR_PATH_HAPTIC, - VIBRATOR_INTERFACE_HAPTIC, - METHOD_HAPTIC_OPENDEVICE, - g_variant_new("(i)", 0)); - - if (!msg) { - _E("Failed to call dbus method(%s): no reply", METHOD_HAPTIC_OPENDEVICE); - return ret; - } - - if (!dh_get_param_from_var(msg, "(i)", &handle)) { + if (!request_haptic_method(METHOD_HAPTIC_OPENDEVICE, g_variant_new("(i)", 0), &handle)) { _E("Failed to call dbus method(%s): no message", METHOD_HAPTIC_OPENDEVICE); - g_variant_unref(msg); return ret; } - g_variant_unref(msg); - msg = dbus_handle_method_sync_with_reply_var(VIBRATOR_BUS_NAME, - VIBRATOR_PATH_HAPTIC, - VIBRATOR_INTERFACE_HAPTIC, - METHOD_HAPTIC_VIBRATEMONOTONE, - g_variant_new("(uiii)", handle, 1000, 100, 0)); - - if (!msg) { - _E("Failed to call dbus method(%s): no reply", METHOD_HAPTIC_VIBRATEMONOTONE); - return ret; + if (request_haptic_method(METHOD_HAPTIC_VIBRATEMONOTONE, g_variant_new("(uiii)", handle, 1000, 2, 0), NULL)) { + _D("Sleep 300ms."); + usleep(300*1000); + _D("Wakeup."); + ret = request_haptic_method(METHOD_HAPTIC_STOPDEVICE, g_variant_new("(u)", handle), NULL); } - g_variant_unref(msg); - - _D("Sleep 300ms."); - time.tv_nsec = 300 * NANO_SECOND_MULTIPLIER; - nanosleep(&time, NULL); - _D("Wakeup."); - - return request_haptic_method(METHOD_HAPTIC_STOPDEVICE, g_variant_new("(u)", handle)); + request_haptic_method(METHOD_HAPTIC_CLOSEDEVICE, g_variant_new("(u)", handle), NULL); + return ret; } static bool haptic_getstate(int index) { _D("----------------------------------------------------------------------------------"); - return request_haptic_method(METHOD_HAPTIC_GETSTATE, g_variant_new("(i)", index)); + return request_haptic_method(METHOD_HAPTIC_GETSTATE, g_variant_new("(i)", index), NULL); } static bool haptic_showhandlelist() { - GVariant *msg; - _D("----------------------------------------------------------------------------------"); - msg = dbus_handle_method_sync_with_reply_var(VIBRATOR_BUS_NAME, - VIBRATOR_PATH_HAPTIC, - VIBRATOR_INTERFACE_HAPTIC, - METHOD_HAPTIC_SHOWHANDLELIST, - NULL); - - if (!msg) { - _E("Failed to call dbus method(%s): no reply", METHOD_HAPTIC_OPENDEVICE); - return FALSE; - } - g_variant_unref(msg); - return TRUE; + return request_haptic_method(METHOD_HAPTIC_SHOWHANDLELIST, NULL, NULL); } static bool haptic_issupported(char *pattern) { _D("----------------------------------------------------------------------------------"); - return request_haptic_method(METHOD_HAPTIC_ISSUPPORTED, g_variant_new("(s)", pattern)); + return request_haptic_method(METHOD_HAPTIC_ISSUPPORTED, g_variant_new("(s)", pattern), NULL); } void haptic_test_all(int *success, int *fail) @@ -249,10 +177,10 @@ void haptic_test_all(int *success, int *fail) (haptic_closedevice()) ? s++ : f++; (haptic_stopdevice()) ? s++ : f++; nanosleep(&time, NULL); - (haptic_vibratemonotone(300, 100, 0)) ? s++ : f++; - nanosleep(&time, NULL); + (haptic_vibratemonotone(300, 2, 0)) ? s++ : f++; + //nanosleep(&time, NULL); (haptic_vibratepattern("FEEDBACK_PATTERN_SIP", 2, 0)) ? s++ : f++; - nanosleep(&time, NULL); + //nanosleep(&time, NULL); (haptic_getstate(0)) ? s++ : f++; (haptic_showhandlelist()) ? s++ : f++; (haptic_issupported("FEEDBACK_PATTERN_SIP")) ? s++ : f++; -- 2.7.4 From d0939d866a59e86129df5c77deeff53823ed5457 Mon Sep 17 00:00:00 2001 From: Yunmi Ha Date: Tue, 7 Jul 2020 14:43:13 +0900 Subject: [PATCH 02/16] Add static keyword for global variable Change-Id: I8fba40a7ea69599629d58844efdcd05e502f9748 Signed-off-by: Yunmi Ha --- src/core/log.c | 2 +- src/haptic/haptic.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/core/log.c b/src/core/log.c index 7b9a583..f1c5897 100644 --- a/src/core/log.c +++ b/src/core/log.c @@ -25,7 +25,7 @@ void __cyg_profile_func_enter(void *, void *) void __cyg_profile_func_exit(void *, void *) __attribute__ ((no_instrument_function)); -int g_trace_depth = -2; +static int g_trace_depth = -2; void __cyg_profile_func_enter(void *func, void *caller) { diff --git a/src/haptic/haptic.c b/src/haptic/haptic.c index 2d734a0..5ccf572 100644 --- a/src/haptic/haptic.c +++ b/src/haptic/haptic.c @@ -127,7 +127,7 @@ static int g_handle; /* pattern configuration list */ static dd_list *vib_conf_list; -guint duration_timer; +static guint duration_timer; /* haptic operation variable */ static dd_list *h_head; @@ -1343,7 +1343,7 @@ int haptic_probe(void) return haptic_module_load(); } -guint id_sig_pwr_off_state; +static guint id_sig_pwr_off_state; void haptic_init(void) { -- 2.7.4 From f2a494613beec02d69b116b10149373071b41a29 Mon Sep 17 00:00:00 2001 From: Yunmi Ha Date: Tue, 7 Jul 2020 15:29:13 +0900 Subject: [PATCH 03/16] Move main.c file to haptic folder - 'core' and 'haptic' sub-modules has cycle dependecies cause main function. - For remove this, move main function to haptic sub-module. Change-Id: Ie9e967d2b74694e020a5fccb5881e25248e7897c Signed-off-by: Yunmi Ha --- CMakeLists.txt | 2 +- src/{core => haptic}/main.c | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename src/{core => haptic}/main.c (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index c4ffa35..621d2bf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,7 +8,7 @@ PROJECT(feedbackd C) SET(VERSION 0.1.0) SET(SRCS - src/core/main.c + src/haptic/main.c src/core/common.c src/core/config-parser.c src/core/device-idler.c diff --git a/src/core/main.c b/src/haptic/main.c similarity index 100% rename from src/core/main.c rename to src/haptic/main.c -- 2.7.4 From c4e261706ee734d3942ad34b3c3cf12a304bcdff Mon Sep 17 00:00:00 2001 From: Yunmi Ha Date: Mon, 13 Jul 2020 14:15:10 +0900 Subject: [PATCH 04/16] Fix 'stringop-truncation' build warning Change-Id: Ia532e724a686fd6ced58b1ad7a4fc61680b92a6f Signed-off-by: Yunmi Ha --- src/core/config-parser.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/config-parser.c b/src/core/config-parser.c index 94a8146..013ddbf 100644 --- a/src/core/config-parser.c +++ b/src/core/config-parser.c @@ -85,7 +85,7 @@ int config_parse(const char *file_name, int cb(struct parse_result *result, } *end = '\0'; - strncpy(section, start + 1, sizeof(section)); + strncpy(section, start + 1, sizeof(section)-1); section[MAX_SECTION-1] = '\0'; } else if (*start) { /* parse name & value */ -- 2.7.4 From b8b68c00f5a0266471a86a9b66b3d965c678b99c Mon Sep 17 00:00:00 2001 From: lokilee73 Date: Thu, 10 Sep 2020 16:40:07 +0900 Subject: [PATCH 05/16] Change function name ex) dh_get_param_from_var to g_variant_get_safe Change-Id: I73e92c7b2e87b0b5d26547fa4a3adc69e6451f84 Signed-off-by: lokilee73 --- src/auto-test/haptic.c | 2 +- src/haptic/haptic.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/auto-test/haptic.c b/src/auto-test/haptic.c index dbf5872..0f64299 100644 --- a/src/auto-test/haptic.c +++ b/src/auto-test/haptic.c @@ -43,7 +43,7 @@ static bool request_haptic_method(const char *method, GVariant *param, int *retu return ret; } - if (!dh_get_param_from_var(msg, "(i)", &val)) + if (!g_variant_get_safe(msg, "(i)", &val)) _E("Failed to call %s: no message", method); else { if ((val == -ENOTSUP) || (val == -ENOSYS)) { diff --git a/src/haptic/haptic.c b/src/haptic/haptic.c index 5ccf572..b5b3b93 100644 --- a/src/haptic/haptic.c +++ b/src/haptic/haptic.c @@ -1188,7 +1188,7 @@ static void haptic_poweroff_cb(GDBusConnection *conn, int ret, level; struct timespec time = {0,}; - if (!dh_get_param_from_var(param, "(i)", &type)) { + if (!g_variant_get_safe(param, "(i)", &type)) { _E("Failed to get params from gvariant. expected:%s, type:%s", "(i)", g_variant_get_type_string(param)); return; } -- 2.7.4 From aea3bff6f7eb6085a44a7a969660e8211d880bac Mon Sep 17 00:00:00 2001 From: Yunmi Ha Date: Fri, 13 Nov 2020 17:34:50 +0900 Subject: [PATCH 06/16] Remove unused circle driver Change-Id: I05d45ab0f959f86035892371edb9b15805b383cf Signed-off-by: Yunmi Ha --- CMakeLists.txt | 2 - packaging/feedbackd.spec | 57 +-------- src/haptic/circle.c | 306 ----------------------------------------------- 3 files changed, 5 insertions(+), 360 deletions(-) delete mode 100644 src/haptic/circle.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 621d2bf..fb4d622 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,8 +24,6 @@ ELSEIF(DRIVER STREQUAL gpio) SET(SRCS ${SRCS} src/haptic/gpio_haptic.c) ELSEIF(DRIVER STREQUAL standard) SET(SRCS ${SRCS} src/haptic/standard.c) -ELSEIF(DRIVER STREQUAL circle) - SET(SRCS ${SRCS} src/haptic/circle.c) ENDIF() INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/src) diff --git a/packaging/feedbackd.spec b/packaging/feedbackd.spec index 1917771..75cbd8f 100644 --- a/packaging/feedbackd.spec +++ b/packaging/feedbackd.spec @@ -44,33 +44,30 @@ Group: main feedback daemon. # if driver = external or undefined -%package driver-external +%package driver-external Summary: Feedbackd binaries targeting external plugin Provides: %{name}-compat = %{version}-%{release} Conflicts: %{name}-driver-emulator Conflicts: %{name}-driver-gpio Conflicts: %{name}-driver-standard -Conflicts: %{name}-driver-circle %description driver-external Feedbackd binaries with external plugin. Required by main feedbackd package # if driver = emulator or undefined -%package driver-emulator +%package driver-emulator Summary: Feedbackd binaries targeting emulator plugin Provides: %{name}-compat = %{version}-%{release} Conflicts: %{name}-driver-external Conflicts: %{name}-driver-gpio Conflicts: %{name}-driver-standard -Conflicts: %{name}-driver-circle %description driver-emulator Feedbackd binaries with emulator plugin. Required by main feedbackd package # if driver = gpio or undefined -%package driver-gpio +%package driver-gpio Summary: Feedbackd binaries targeting gpio plugin Provides: %{name}-compat = %{version}-%{release} Conflicts: %{name}-driver-external Conflicts: %{name}-driver-emulator Conflicts: %{name}-driver-standard -Conflicts: %{name}-driver-circle %description driver-gpio Feedbackd binaries with gpio plugin. Required by main feedbackd package # if driver = standard or undefined @@ -80,19 +77,8 @@ Provides: %{name}-compat = %{version}-%{release} Conflicts: %{name}-driver-external Conflicts: %{name}-driver-emulator Conflicts: %{name}-driver-gpio -Conflicts: %{name}-driver-circle %description driver-standard Feedbackd binaries with standard plugin. Required by main feedbackd package -# if driver = circle or undefined -%package driver-circle -Summary: Feedbackd binaries targeting circle plugin -Provides: %{name}-compat = %{version}-%{release} -Conflicts: %{name}-driver-external -Conflicts: %{name}-driver-emulator -Conflicts: %{name}-driver-gpio -Conflicts: %{name}-driver-standard -%description driver-circle -Feedbackd binaries with circle plugin. Required by main feedbackd package %package conf-level3 Summary: Feedbackd level configuration file @@ -118,7 +104,7 @@ This package can be installed optional for auto dbus test. %prep %setup -q -# Build per driver +# Build per driver # if driver = external or undefined mkdir -p build_external pushd build_external @@ -155,19 +141,10 @@ pushd build_standard #eol popd -# if driver = circle or undefined -mkdir -p build_circle -pushd build_circle -%cmake .. \ - -DCMAKE_INSTALL_PREFIX=%{_prefix} \ - -DDRIVER=circle \ - #eol -popd - %build cp %{SOURCE1} . -# Build per driver +# Build per driver # if driver = external or undefined pushd build_external make %{?jobs:-j%jobs} @@ -188,11 +165,6 @@ pushd build_standard make %{?jobs:-j%jobs} popd -# if driver = circle or undefined -pushd build_circle -make %{?jobs:-j%jobs} -popd - %install rm -rf %{buildroot} # Build per driver @@ -216,10 +188,6 @@ pushd build_standard mv %{buildroot}%{_bindir}/feedbackd %{buildroot}%{_bindir}/feedbackd.standard popd -pushd build_circle -%make_install -mv %{buildroot}%{_bindir}/feedbackd %{buildroot}%{_bindir}/feedbackd.circle -popd %install_service delayed.target.wants feedbackd.service @@ -269,16 +237,6 @@ if [ "$1" == "0" ]; then systemctl stop feedbackd.service fi -%post driver-circle -mv %{_bindir}/feedbackd.circle %{_bindir}/feedbackd - -%preun driver-circle -mv %{_bindir}/feedbackd %{_bindir}/feedbackd.circle - -if [ "$1" == "0" ]; then - systemctl stop feedbackd.service -fi - %post conf-level3 mv %{_sysconfdir}/feedbackd/haptic-level3.conf %{_sysconfdir}/feedbackd/haptic.conf @@ -313,11 +271,6 @@ mv %{_sysconfdir}/feedbackd/haptic-level6.conf %{_sysconfdir}/feedbackd/haptic.c %manifest %{name}.manifest %{_bindir}/feedbackd.standard -%files driver-circle -%license LICENSE.Apache-2.0 -%manifest %{name}.manifest -%{_bindir}/feedbackd.circle - %files conf-level3 %license LICENSE.Apache-2.0 %manifest %{name}.manifest diff --git a/src/haptic/circle.c b/src/haptic/circle.c deleted file mode 100644 index 42fa1f7..0000000 --- a/src/haptic/circle.c +++ /dev/null @@ -1,306 +0,0 @@ -/* - * feedbackd - * - * Copyright (c) 2016 - 2017 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 "core/log.h" -#include "core/list.h" -#include "haptic.h" - -#define CIRCLE_ON_PATH "/sys/class/sec/motor/motor_on" -#define CIRCLE_OFF_PATH "/sys/class/sec/motor/motor_off" - -#define BUF_SIZE 8 - -static int fd_play = -1, fd_stop = -1; -static dd_list *handle_list; -static guint stop_timer; -static int unique_number; -static bool state = false; - -static int stop_device(int device_handle); -static bool find_from_list(int handle) -{ - dd_list *elem; - - elem = DD_LIST_FIND(handle_list, (gpointer)(long)handle); - if (elem) - return true; - - return false; -} - -static gboolean timer_cb(void *data) -{ - int device_handle = (int)(long)data; - int ret; - char buf[BUF_SIZE]; - bool found; - - _I("Stop vibration by timer."); - - found = find_from_list(device_handle); - if (!found) - return G_SOURCE_REMOVE; - - /* stop previous vibration */ - if (fd_stop < 0) { - fd_stop = open(CIRCLE_OFF_PATH, O_RDONLY); - if (fd_stop < 0) - return G_SOURCE_REMOVE; - } - ret = read(fd_stop, buf, BUF_SIZE); - if (ret < 0) { - _E("Failed to stop."); - return G_SOURCE_REMOVE; - } - stop_timer = 0; - - return G_SOURCE_REMOVE; -} - -static int get_device_count(int *count) -{ - /* suppose there is just one haptic device */ - if (count) - *count = 1; - - return 0; -} - -static int open_device(int device_index, int *device_handle) -{ - int n; - bool found = false; - dd_list *elem; - - if (!device_handle) - return -EINVAL; - - /* if it is the first element */ - n = DD_LIST_LENGTH(handle_list); - if (n == 0) { - _I("Open."); - if (fd_play < 0) { - fd_play = open(CIRCLE_ON_PATH, O_RDONLY); - if (fd_play < 0) { - _E("Failed to open '%s': %d", CIRCLE_ON_PATH, errno); - return -errno; - } - } - if (fd_stop < 0) { - fd_stop = open(CIRCLE_OFF_PATH, O_RDONLY); - if (fd_stop < 0) { - _E("Failed to open '%s': %d", CIRCLE_OFF_PATH, errno); - return -errno; - } - } - } - - if (unique_number == INT_MAX) - unique_number = 0; - - while (found != true) { - ++unique_number; - elem = DD_LIST_FIND(handle_list, (gpointer)(long)unique_number); - if (!elem) - found = true; - } - - /* add info to local list */ - DD_LIST_APPEND(handle_list, (gpointer)(long)unique_number); - - *device_handle = unique_number; - return 0; -} - -static int close_device(int device_handle) -{ - int r, n; - bool found; - - found = find_from_list(device_handle); - if (!found) { - _E("Handle(%d) fail to check info.", device_handle); - return -EINVAL; - } - - if (fd_stop < 0) { - fd_stop = open(CIRCLE_OFF_PATH, O_RDONLY); - if (fd_stop < 0) { - _E("Handle(%d) fail to check fd.", device_handle); - return -ENODEV; - } - } - - /* stop vibration */ - r = stop_device(device_handle); - if (r < 0) - _I("Handle(%d) already stopped or failed to stop effect: %d", device_handle, r); - - DD_LIST_REMOVE(handle_list, (gpointer)(long)device_handle); - - /* if it is the last element */ - n = DD_LIST_LENGTH(handle_list); - if (n == 0) { - _I("Close."); - if (fd_play > 0) { - close(fd_play); - fd_play = -1; - } - if (fd_stop > 0) { - close(fd_stop); - fd_stop = -1; - } - } - - return 0; -} - -static int vibrate_monotone(int device_handle, int duration, int frequency, int overdrive, int level, int intensity, int priority) -{ - int ret; - char buf[BUF_SIZE]; - bool found; - - found = find_from_list(device_handle); - if (!found) { - _E("Handle(%d) fail to check list.", device_handle); - return -EINVAL; - } - - if (fd_play < 0) { - fd_play = open(CIRCLE_ON_PATH, O_RDONLY); - if (fd_play < 0) { - _E("Handle(%d) fail to check handle.", device_handle); - return -ENODEV; - } - } - - if (duration <= 0) { - _E("Handle(%d) skip requested with 0.", device_handle); - return -EINVAL; - } - - /* Zero(0) is the infinitely vibration value */ - if (duration == HAPTIC_MODULE_DURATION_UNLIMITED) - duration = 0; - - if (stop_timer) - stop_device(device_handle); - - /* play vibration */ - ret = read(fd_play, buf, BUF_SIZE); - if (ret < 0) { - _E("Handle(%d) failed to play.", device_handle); - return -errno; - } - - /* register timer */ - if (duration) { - stop_timer = g_timeout_add(duration, timer_cb, (void *)(long)device_handle); - - if (!stop_timer) - _E("Handle(%d) Failed to add timer callback.", device_handle); - } - - _D("Device handle(%d) %dms.", device_handle, duration); - - return 0; -} - -static int stop_device(int device_handle) -{ - int ret; - char buf[BUF_SIZE]; - bool found; - - found = find_from_list(device_handle); - if (!found) { - _E("Handle(%d) fail to check info.", device_handle); - return -EINVAL; - } - - if (cur_h_data.handle > 0 && cur_h_data.handle != device_handle) { - _E("Only same handle can stop current vibration."); - return -EPERM; - } - - if (fd_stop < 0) { - fd_stop = open(CIRCLE_OFF_PATH, O_RDONLY); - if (fd_stop < 0) { - _E("Handle(%d) fail to check fd.", device_handle); - return -ENODEV; - } - } - ret = read(fd_stop, buf, BUF_SIZE); - if (ret < 0) { - _E("Failed to stop."); - return -errno; - } - if (stop_timer) { - g_source_remove(stop_timer); - stop_timer = 0; - } - - return 0; -} -/* END: Haptic Module APIs */ - -static const struct haptic_plugin_ops default_plugin = { - .get_device_count = get_device_count, - .open_device = open_device, - .close_device = close_device, - .vibrate_monotone = vibrate_monotone, - .stop_device = stop_device, -}; - -static bool is_valid(void) -{ - if ((access(CIRCLE_ON_PATH, R_OK) != 0) || - (access(CIRCLE_OFF_PATH, R_OK) != 0)) { - _E("Do not support wearable haptic device."); - state = false; - return false; - } - - state = true; - _I("Support wearable haptic device."); - return true; -} - -static const struct haptic_plugin_ops *load(void) -{ - return &default_plugin; -} - -static const struct haptic_ops std_ops = { - .type = HAPTIC_STANDARD, - .is_valid = is_valid, - .load = load, -}; - -HAPTIC_OPS_REGISTER(&std_ops) -- 2.7.4 From 7466174ad36d3da309dc18bc006d9138a2750964 Mon Sep 17 00:00:00 2001 From: Yunmi Ha Date: Thu, 19 Nov 2020 17:45:05 +0900 Subject: [PATCH 07/16] Distribute daemon and driver - Feedbackd consists of 3 parts. 1. feedbackd daemon : Main daemon. process dbus connection. 2. haptic-dev library : Load driver module and call device function. (Now, It is included in feedbackd daemon. But it will be separated as library.) 3. driver module : there are three haptic modules. (gpio, emulator, standard) Change-Id: I04450a39bd57a1c04ade4f0d8a0f1f6734debad2 Signed-off-by: Yunmi Ha --- CMakeLists.txt | 65 +++++++---- {scripts => conf}/feedbackd.conf | 0 {src/haptic/conf => conf}/haptic-level3.conf | 0 {src/haptic/conf => conf}/haptic-level6.conf | 0 packaging/feedbackd.spec | 168 ++++++--------------------- src/auto-test/result.c | 2 +- src/auto-test/test.h | 6 +- src/{haptic => core}/main.c | 6 +- src/{haptic => driver}/emulator.c | 9 +- src/{haptic => driver}/external.c | 2 +- src/{haptic => driver}/gpio_haptic.c | 13 +-- src/driver/haptic-dev.c | 166 ++++++++++++++++++++++++++ src/driver/haptic-dev.h | 38 ++++++ src/driver/haptic-interface.h | 69 +++++++++++ src/{haptic => driver}/haptic.c | 132 +++++++-------------- src/{haptic => driver}/haptic.h | 31 +---- src/{haptic => driver}/standard.c | 19 +-- src/haptic/haptic-module.h | 91 --------------- src/haptic/haptic-plugin-intf.h | 35 ------ src/{core => shared}/common.c | 0 src/{core => shared}/common.h | 0 src/{core => shared}/config-parser.c | 0 src/{core => shared}/config-parser.h | 0 src/{core => shared}/device-idler.c | 0 src/{core => shared}/device-idler.h | 0 src/{core => shared}/list.h | 0 src/{core => shared}/log.c | 0 src/{core => shared}/log.h | 0 28 files changed, 416 insertions(+), 436 deletions(-) rename {scripts => conf}/feedbackd.conf (100%) rename {src/haptic/conf => conf}/haptic-level3.conf (100%) rename {src/haptic/conf => conf}/haptic-level6.conf (100%) rename src/{haptic => core}/main.c (96%) rename src/{haptic => driver}/emulator.c (94%) rename src/{haptic => driver}/external.c (98%) rename src/{haptic => driver}/gpio_haptic.c (97%) create mode 100644 src/driver/haptic-dev.c create mode 100644 src/driver/haptic-dev.h create mode 100644 src/driver/haptic-interface.h rename src/{haptic => driver}/haptic.c (92%) rename src/{haptic => driver}/haptic.h (64%) rename src/{haptic => driver}/standard.c (97%) delete mode 100644 src/haptic/haptic-module.h delete mode 100644 src/haptic/haptic-plugin-intf.h rename src/{core => shared}/common.c (100%) rename src/{core => shared}/common.h (100%) rename src/{core => shared}/config-parser.c (100%) rename src/{core => shared}/config-parser.h (100%) rename src/{core => shared}/device-idler.c (100%) rename src/{core => shared}/device-idler.h (100%) rename src/{core => shared}/list.h (100%) rename src/{core => shared}/log.c (100%) rename src/{core => shared}/log.h (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index fb4d622..ce52bc4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,24 +8,15 @@ PROJECT(feedbackd C) SET(VERSION 0.1.0) SET(SRCS - src/haptic/main.c - src/core/common.c - src/core/config-parser.c - src/core/device-idler.c - src/core/log.c - src/haptic/haptic.c + src/core/main.c + src/shared/common.c + src/shared/config-parser.c + src/shared/device-idler.c + src/shared/log.c + src/driver/haptic.c + src/driver/haptic-dev.c ) -IF(DRIVER STREQUAL external) - SET(SRCS ${SRCS} src/haptic/external.c) -ELSEIF(DRIVER STREQUAL emulator) - SET(SRCS ${SRCS} src/haptic/emulator.c) -ELSEIF(DRIVER STREQUAL gpio) - SET(SRCS ${SRCS} src/haptic/gpio_haptic.c) -ELSEIF(DRIVER STREQUAL standard) - SET(SRCS ${SRCS} src/haptic/standard.c) -ENDIF() - INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/src) SET(PKG_MODULES @@ -41,10 +32,6 @@ SET(PKG_MODULES capi-system-device ) -IF(DRIVER STREQUAL gpio) - SET(PKG_MODULES ${PKG_MODULES} capi-system-peripheral-io) -ENDIF() - INCLUDE(FindPkgConfig) pkg_check_modules(pkgs2 REQUIRED ${PKG_MODULES}) @@ -58,17 +45,49 @@ SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -lrt -fPIE") SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pie") ADD_DEFINITIONS("-DDEBUG") +ADD_DEFINITIONS("-DLIBPATH=\"${LIB_INSTALL_DIR}\"") ADD_EXECUTABLE(${PROJECT_NAME} ${SRCS}) TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${pkgs2_LDFLAGS} "-ldl" "-lm") INSTALL(TARGETS ${PROJECT_NAME} DESTINATION bin) -INSTALL(FILES ${CMAKE_SOURCE_DIR}/scripts/feedbackd.conf DESTINATION /etc/dbus-1/system.d) +SET(LIB_PREFIX haptic_) +SET(DRIVER_PKG_MODULES + dlog + capi-system-info + glib-2.0 +) + +INCLUDE(FindPkgConfig) +pkg_check_modules(pkgs_driver REQUIRED ${DRIVER_PKG_MODULES}) + +FOREACH(flag_driver ${pkgs_driver_CFLAGS}) + SET(DRIVER_CFLAGS "${DRIVER_CFLAGS} ${flag_driver}") +ENDFOREACH(flag_driver) + +SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${DRIVER_CFLAGS} -fvisibility=hidden -Werror -g -fno-omit-frame-pointer -finstrument-functions -pie") + +ADD_LIBRARY(emul MODULE src/driver/emulator.c) +TARGET_LINK_LIBRARIES(emul ${pkgs_driver_LDFLAGS} "-ldl") +SET_TARGET_PROPERTIES(emul PROPERTIES PREFIX ${LIB_PREFIX}) +INSTALL(TARGETS emul DESTINATION ${LIB_INSTALL_DIR} COMPONENT RuntimeLibraries) + +ADD_LIBRARY(gpio MODULE src/driver/gpio_haptic.c) +TARGET_LINK_LIBRARIES(gpio ${pkgs_driver_LDFLAGS} "-lcapi-system-peripheral-io -ldl") +SET_TARGET_PROPERTIES(gpio PROPERTIES PREFIX ${LIB_PREFIX}) +INSTALL(TARGETS gpio DESTINATION ${LIB_INSTALL_DIR} COMPONENT RuntimeLibraries) + +ADD_LIBRARY(standard MODULE src/driver/standard.c) +TARGET_LINK_LIBRARIES(standard ${pkgs_driver_LDFLAGS} "-ldl") +SET_TARGET_PROPERTIES(standard PROPERTIES PREFIX ${LIB_PREFIX}) +INSTALL(TARGETS standard DESTINATION ${LIB_INSTALL_DIR} COMPONENT RuntimeLibraries) + +INSTALL(FILES ${CMAKE_SOURCE_DIR}/conf/feedbackd.conf DESTINATION /etc/dbus-1/system.d) INSTALL(DIRECTORY ${CMAKE_SOURCE_DIR}/systemd/ DESTINATION lib/systemd/system FILES_MATCHING PATTERN "feedbackd.service") INSTALL(FILES ${CMAKE_SOURCE_DIR}/systemd/org.tizen.system.vibrator.service DESTINATION /usr/share/dbus-1/system-services) -INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/haptic/conf/haptic-level3.conf DESTINATION /etc/feedbackd) -INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/haptic/conf/haptic-level6.conf DESTINATION /etc/feedbackd) +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/conf/haptic-level3.conf DESTINATION /etc/feedbackd) +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/conf/haptic-level6.conf DESTINATION /etc/feedbackd) ADD_SUBDIRECTORY(src/auto-test) diff --git a/scripts/feedbackd.conf b/conf/feedbackd.conf similarity index 100% rename from scripts/feedbackd.conf rename to conf/feedbackd.conf diff --git a/src/haptic/conf/haptic-level3.conf b/conf/haptic-level3.conf similarity index 100% rename from src/haptic/conf/haptic-level3.conf rename to conf/haptic-level3.conf diff --git a/src/haptic/conf/haptic-level6.conf b/conf/haptic-level6.conf similarity index 100% rename from src/haptic/conf/haptic-level6.conf rename to conf/haptic-level6.conf diff --git a/packaging/feedbackd.spec b/packaging/feedbackd.spec index 75cbd8f..b812d64 100644 --- a/packaging/feedbackd.spec +++ b/packaging/feedbackd.spec @@ -28,7 +28,6 @@ BuildRequires: pkgconfig(capi-system-device) Requires(post): /usr/bin/vconftool Requires: %{name}-compat = %{version}-%{release} -Recommends: %{name}-driver-standard = %{version}-%{release} Requires: configuration-compat = %{version}-%{release} Recommends: %{name}-conf-level6 = %{version}-%{release} @@ -43,42 +42,29 @@ Group: main %description feedbackd feedback daemon. -# if driver = external or undefined -%package driver-external -Summary: Feedbackd binaries targeting external plugin -Provides: %{name}-compat = %{version}-%{release} -Conflicts: %{name}-driver-emulator -Conflicts: %{name}-driver-gpio -Conflicts: %{name}-driver-standard -%description driver-external -Feedbackd binaries with external plugin. Required by main feedbackd package -# if driver = emulator or undefined %package driver-emulator -Summary: Feedbackd binaries targeting emulator plugin +Summary: Haptic driver targeting emulator plugin Provides: %{name}-compat = %{version}-%{release} -Conflicts: %{name}-driver-external Conflicts: %{name}-driver-gpio Conflicts: %{name}-driver-standard %description driver-emulator -Feedbackd binaries with emulator plugin. Required by main feedbackd package -# if driver = gpio or undefined +Emulator device driver. Required by main feedbackd package. + %package driver-gpio -Summary: Feedbackd binaries targeting gpio plugin +Summary: Haptic driver targeting emulator plugin Provides: %{name}-compat = %{version}-%{release} -Conflicts: %{name}-driver-external Conflicts: %{name}-driver-emulator Conflicts: %{name}-driver-standard %description driver-gpio -Feedbackd binaries with gpio plugin. Required by main feedbackd package -# if driver = standard or undefined +Gpio haptic device driver. Required by main feedbackd package. + %package driver-standard -Summary: Feedbackd binaries targeting emulator plugin +Summary: Haptic driver targeting emulator plugin Provides: %{name}-compat = %{version}-%{release} -Conflicts: %{name}-driver-external Conflicts: %{name}-driver-emulator Conflicts: %{name}-driver-gpio %description driver-standard -Feedbackd binaries with standard plugin. Required by main feedbackd package +Standard haptic device driver. Required by main feedbackd package. %package conf-level3 Summary: Feedbackd level configuration file @@ -104,90 +90,16 @@ This package can be installed optional for auto dbus test. %prep %setup -q -# Build per driver -# if driver = external or undefined -mkdir -p build_external -pushd build_external -%cmake .. \ - -DCMAKE_INSTALL_PREFIX=%{_prefix} \ - -DDRIVER=external \ - #eol -popd - -# if driver = emulator or undefined -mkdir -p build_emulator -pushd build_emulator -%cmake .. \ +%cmake . \ -DCMAKE_INSTALL_PREFIX=%{_prefix} \ - -DDRIVER=emulator \ - #eol -popd - -# if driver = gpio or undefined -mkdir -p build_gpio -pushd build_gpio -%cmake .. \ - -DCMAKE_INSTALL_PREFIX=%{_prefix} \ - -DDRIVER=gpio \ - #eol -popd - -# if driver = standard or undefined -mkdir -p build_standard -pushd build_standard -%cmake .. \ - -DCMAKE_INSTALL_PREFIX=%{_prefix} \ - -DDRIVER=standard \ - #eol -popd %build cp %{SOURCE1} . - -# Build per driver -# if driver = external or undefined -pushd build_external -make %{?jobs:-j%jobs} -popd - -# if driver = emulator or undefined -pushd build_emulator -make %{?jobs:-j%jobs} -popd - -# if driver = gpio or undefined -pushd build_gpio make %{?jobs:-j%jobs} -popd - -# if driver = standard or undefined -pushd build_standard -make %{?jobs:-j%jobs} -popd %install rm -rf %{buildroot} -# Build per driver -pushd build_external -%make_install -mv %{buildroot}%{_bindir}/feedbackd %{buildroot}%{_bindir}/feedbackd.external -popd - -pushd build_emulator -%make_install -mv %{buildroot}%{_bindir}/feedbackd %{buildroot}%{_bindir}/feedbackd.emulator -popd - -pushd build_gpio -%make_install -mv %{buildroot}%{_bindir}/feedbackd %{buildroot}%{_bindir}/feedbackd.gpio -popd - -pushd build_standard %make_install -mv %{buildroot}%{_bindir}/feedbackd %{buildroot}%{_bindir}/feedbackd.standard -popd - %install_service delayed.target.wants feedbackd.service @@ -197,52 +109,45 @@ if [ "$1" == "1" ]; then systemctl restart feedbackd.service fi -%post driver-external -mv %{_bindir}/feedbackd.external %{_bindir}/feedbackd +%postun +systemctl daemon-reload -%preun driver-external -mv %{_bindir}/feedbackd %{_bindir}/feedbackd.external +%post driver-emulator +mkdir -p %{_libdir}/feedbackd +mv %{_libdir}/haptic_emul.so %{_libdir}/feedbackd/haptic.so -if [ "$1" == "0" ]; then - systemctl stop feedbackd.service -fi +%post driver-gpio +mkdir -p %{_libdir}/feedbackd +mv %{_libdir}/haptic_gpio.so %{_libdir}/feedbackd/haptic.so -%post driver-emulator -mv %{_bindir}/feedbackd.emulator %{_bindir}/feedbackd +%post driver-standard +mkdir -p %{_libdir}/feedbackd +mv %{_libdir}/haptic_standard.so %{_libdir}/feedbackd/haptic.so -%preun driver-emulator -mv %{_bindir}/feedbackd %{_bindir}/feedbackd.emulator +%post conf-level3 +mv %{_sysconfdir}/feedbackd/haptic-level3.conf %{_sysconfdir}/feedbackd/haptic.conf + +%post conf-level6 +mv %{_sysconfdir}/feedbackd/haptic-level6.conf %{_sysconfdir}/feedbackd/haptic.conf +%preun driver-emulator +mv %{_libdir}/feedbackd/haptic.so %{_libdir}/haptic_emul.so if [ "$1" == "0" ]; then systemctl stop feedbackd.service fi -%post driver-gpio -mv %{_bindir}/feedbackd.gpio %{_bindir}/feedbackd - %preun driver-gpio -mv %{_bindir}/feedbackd %{_bindir}/feedbackd.gpio - +mv %{_libdir}/feedbackd/haptic.so %{_libdir}/haptic_gpio.so if [ "$1" == "0" ]; then systemctl stop feedbackd.service fi -%post driver-standard -mv %{_bindir}/feedbackd.standard %{_bindir}/feedbackd - %preun driver-standard -mv %{_bindir}/feedbackd %{_bindir}/feedbackd.standard - +mv %{_libdir}/feedbackd/haptic.so %{_libdir}/haptic_standard.so if [ "$1" == "0" ]; then systemctl stop feedbackd.service fi -%post conf-level3 -mv %{_sysconfdir}/feedbackd/haptic-level3.conf %{_sysconfdir}/feedbackd/haptic.conf - -%post conf-level6 -mv %{_sysconfdir}/feedbackd/haptic-level6.conf %{_sysconfdir}/feedbackd/haptic.conf - %files -n feedbackd %manifest %{name}.manifest %license LICENSE.Apache-2.0 @@ -250,26 +155,19 @@ mv %{_sysconfdir}/feedbackd/haptic-level6.conf %{_sysconfdir}/feedbackd/haptic.c %{_unitdir}/feedbackd.service %{_unitdir}/delayed.target.wants/feedbackd.service %{_datadir}/dbus-1/system-services/org.tizen.system.vibrator.service - -%files driver-external -%license LICENSE.Apache-2.0 -%manifest %{name}.manifest -%{_bindir}/feedbackd.external +%{_bindir}/feedbackd %files driver-emulator %license LICENSE.Apache-2.0 -%manifest %{name}.manifest -%{_bindir}/feedbackd.emulator +%{_libdir}/haptic_emul.so %files driver-gpio %license LICENSE.Apache-2.0 -%manifest %{name}.manifest -%{_bindir}/feedbackd.gpio +%{_libdir}/haptic_gpio.so %files driver-standard %license LICENSE.Apache-2.0 -%manifest %{name}.manifest -%{_bindir}/feedbackd.standard +%{_libdir}/haptic_standard.so %files conf-level3 %license LICENSE.Apache-2.0 diff --git a/src/auto-test/result.c b/src/auto-test/result.c index c0f07fb..b99e7f5 100644 --- a/src/auto-test/result.c +++ b/src/auto-test/result.c @@ -18,7 +18,7 @@ #include -#include "core/log.h" +#include "shared/log.h" #define BUF_MAX 256 diff --git a/src/auto-test/test.h b/src/auto-test/test.h index a7f8347..2bdbdf6 100644 --- a/src/auto-test/test.h +++ b/src/auto-test/test.h @@ -23,9 +23,9 @@ #include #include -#include "core/list.h" -#include "core/log.h" -#include "core/common.h" +#include "shared/list.h" +#include "shared/log.h" +#include "shared/common.h" #ifdef ENABLE_TEST_DLOG #define ENABLE_DLOG diff --git a/src/haptic/main.c b/src/core/main.c similarity index 96% rename from src/haptic/main.c rename to src/core/main.c index ff068c8..0fe52ca 100644 --- a/src/haptic/main.c +++ b/src/core/main.c @@ -26,9 +26,9 @@ #include #include -#include "core/log.h" -#include "core/common.h" -#include "haptic/haptic.h" +#include "shared/log.h" +#include "shared/common.h" +#include "driver/haptic.h" #define VIBRATION_FEATURE "http://tizen.org/feature/feedback.vibration" diff --git a/src/haptic/emulator.c b/src/driver/emulator.c similarity index 94% rename from src/haptic/emulator.c rename to src/driver/emulator.c index 21b1dee..b04dad7 100644 --- a/src/haptic/emulator.c +++ b/src/driver/emulator.c @@ -20,9 +20,10 @@ #include #include -#include "core/log.h" -#include "core/list.h" -#include "haptic.h" +#include "shared/common.h" +#include "shared/log.h" +#include "shared/list.h" +#include "haptic-dev.h" static dd_list *handle_list; static int unique_number = 0; @@ -119,4 +120,4 @@ static const struct haptic_ops emul_ops = { .load = load, }; -HAPTIC_OPS_REGISTER(&emul_ops) +EXPORT_GET_VAR_HAPTIC_OPS(&emul_ops) diff --git a/src/haptic/external.c b/src/driver/external.c similarity index 98% rename from src/haptic/external.c rename to src/driver/external.c index 5b9e8b7..2c610d2 100644 --- a/src/haptic/external.c +++ b/src/driver/external.c @@ -24,7 +24,7 @@ #include #include -#include "core/log.h" +#include "shared/log.h" #include "haptic.h" #define HAPTIC_MODULE_PATH "/usr/lib/libhaptic-module.so" diff --git a/src/haptic/gpio_haptic.c b/src/driver/gpio_haptic.c similarity index 97% rename from src/haptic/gpio_haptic.c rename to src/driver/gpio_haptic.c index 2ba2b88..6c3b4c1 100644 --- a/src/haptic/gpio_haptic.c +++ b/src/driver/gpio_haptic.c @@ -19,8 +19,10 @@ #include #include -#include "core/log.h" -#include "haptic.h" +#include "shared/common.h" +#include "shared/log.h" +#include "shared/list.h" +#include "haptic-interface.h" #include "peripheral_io.h" #define GPIO_I2C_BUS_INDEX 1 @@ -267,11 +269,6 @@ static int gpio_haptic_stop_device(int handle) if (!found) return -EINVAL; - if (cur_h_data.handle > 0 && cur_h_data.handle != handle) { - _E("Only same handle can stop current vibration."); - return -EPERM; - } - if (device_handle == NULL) { if (peripheral_i2c_open(GPIO_I2C_BUS_INDEX, DRV2605L_DEFAULT_ADDR, &device_handle) < PERIPHERAL_ERROR_NONE) { _E("Failed to open I2C."); @@ -339,4 +336,4 @@ static const struct haptic_ops gpio_haptic_ops = { .load = load, }; -HAPTIC_OPS_REGISTER(&gpio_haptic_ops) +EXPORT_GET_VAR_HAPTIC_OPS(&gpio_haptic_ops) diff --git a/src/driver/haptic-dev.c b/src/driver/haptic-dev.c new file mode 100644 index 0000000..05c4d84 --- /dev/null +++ b/src/driver/haptic-dev.c @@ -0,0 +1,166 @@ +/* + * feedbackd + * + * Copyright (c) 2020 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 + * + * Unlessnn 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 "shared/log.h" +#include "haptic.h" +#include "haptic-dev.h" + +#ifndef LIBPATH +#error LIBPATH is not defined. +#endif +#define HAPTIC_MODULE_PATH LIBPATH"/feedbackd/haptic.so" + +#define CHECK_NO_DEVICE(dev) \ + do { \ + if (!dev) \ + return -ENODEV; \ + }while(0) \ + +/* Haptic Plugin Interface */ +static void *haptic_handle; +static const struct haptic_plugin_ops *plugin_ops; +static const struct haptic_ops *haptic_ops; +static const struct haptic_ops* (*fp_get_var_haptic_ops)(void); + +int haptic_load_device(void) +{ + struct stat buf; + int ret; + + ret = stat(HAPTIC_MODULE_PATH, &buf); + if (ret < 0) { + _E("Failed to stat file(%s): %d", HAPTIC_MODULE_PATH, errno); + goto error; + } + + haptic_handle = dlopen(HAPTIC_MODULE_PATH, RTLD_NOW); + if (!haptic_handle) { + _E("Failed to open file(%s): %s.", HAPTIC_MODULE_PATH, dlerror()); + goto error; + } + + fp_get_var_haptic_ops = dlsym(haptic_handle, "get_var_haptic_ops"); + if (!fp_get_var_haptic_ops) { + _E("Failed to get \'get_var_haptic_ops\' function."); + goto error; + } + + haptic_ops = fp_get_var_haptic_ops(); + if (!haptic_ops) { + _E("Failed to call get_var_haptic_ops"); + goto error; + } + + if (haptic_ops->is_valid && haptic_ops->is_valid()) { + if (haptic_ops->load) + plugin_ops = haptic_ops->load(); + } + + if (!plugin_ops) { + _E("Failed to load haptic device."); + goto error; + } + + return 0; + +error: + if (haptic_handle) { + dlclose(haptic_handle); + haptic_handle = NULL; + haptic_ops = NULL; + } + + return -ENODEV; +} + +void haptic_release_device() +{ + if (haptic_ops) { + if (haptic_ops->is_valid && haptic_ops->is_valid()) { + if (haptic_ops->release) + haptic_ops->release(); + } + } + + if (haptic_handle) + dlclose(haptic_handle); + + haptic_handle = NULL; + haptic_ops = NULL; + plugin_ops = NULL; +} + +int haptic_open_device(int *dev_handle) +{ + CHECK_NO_DEVICE(plugin_ops); + + if (!dev_handle) + return -EINVAL; + + return plugin_ops->open_device(HAPTIC_MODULE_DEVICE_ALL, dev_handle); +} + +int haptic_close_device(int dev_handle) +{ + CHECK_NO_DEVICE(plugin_ops); + + return plugin_ops->close_device(dev_handle); +} + +int haptic_check_device() +{ + CHECK_NO_DEVICE(plugin_ops); + + return 0; +} + +int haptic_vibrate_device(int device_handle, int duration, int frequency, + int overdrive, int level, int intensity, int priority) +{ + CHECK_NO_DEVICE(plugin_ops); + + return plugin_ops->vibrate_monotone(device_handle, duration, frequency, overdrive, + level, intensity, priority); + +} + +int haptic_get_count_device(int *count) +{ + CHECK_NO_DEVICE(plugin_ops); + + if (!count) + return -EINVAL; + + return plugin_ops->get_device_count(count); +} + +int haptic_stop_device(int handle) +{ + CHECK_NO_DEVICE(plugin_ops); + + return plugin_ops->stop_device(handle); +} + diff --git a/src/driver/haptic-dev.h b/src/driver/haptic-dev.h new file mode 100644 index 0000000..979abed --- /dev/null +++ b/src/driver/haptic-dev.h @@ -0,0 +1,38 @@ +/* + * feedbackd + * +i * Copyright (c) 2012 - 2020 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. + */ + + +#ifndef __FEEDBACKD_HAPTIC_DEV_H__ +#define __FEEDBACKD_HAPTIC_DEV_H__ + +#include +#include "shared/list.h" +#include "haptic-interface.h" + +int haptic_load_device(void); +void haptic_release_device(); +int haptic_open_device(int *dev_handle); +int haptic_check_device(); +int haptic_close_device(int dev_handle); + +int haptic_vibrate_device(int device_handle, int duration, int frequency, int overdrive, int level, int intensity, int priority); + +int haptic_get_count_device(int *count); +int haptic_stop_device(int handle); + +#endif /* __FEEDBACKD_HAPTIC_DEV_H__ */ diff --git a/src/driver/haptic-interface.h b/src/driver/haptic-interface.h new file mode 100644 index 0000000..de1d6c4 --- /dev/null +++ b/src/driver/haptic-interface.h @@ -0,0 +1,69 @@ +/* + * deviced + * + * Copyright (c) 2012 - 2017 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. + */ + + +#ifndef __FEEDBACKD_HAPTIC_INTERFACE_H__ +#define __FEEDBACKD_HAPTIC_INTERFACE_H__ + +#include + +enum haptic_type { + HAPTIC_STANDARD, + HAPTIC_EXTERNAL, +}; + +/** + * @brief Enumerations of device id for the Haptic Module API. + * @details We support two motors now. + */ +typedef enum { + HAPTIC_MODULE_DEVICE_0 = 0x0, /**< 1st motor */ + HAPTIC_MODULE_DEVICE_1 = 0x1, /**< 2nd motor */ + HAPTIC_MODULE_DEVICE_ALL = 0x4, /**< both of them */ +} haptic_module_device; + +/** + * @brief Enumerations of unlimited duration for the Haptic Module API. + */ +typedef enum { + HAPTIC_MODULE_DURATION_UNLIMITED = 0x7FFFFFFF, +} haptic_module_duration; + +struct haptic_ops { + enum haptic_type type; + bool (*is_valid)(void); + const struct haptic_plugin_ops *(*load)(void); + void (*release)(void); +}; + +struct haptic_plugin_ops { + int (*get_device_count) (int*); + int (*open_device) (int, int*); + int (*close_device) (int); + int (*vibrate_monotone) (int, int, int, int, int, int, int); + int (*stop_device) (int); +}; + +#define EXPORT_GET_VAR_HAPTIC_OPS(ops) \ +const struct haptic_ops __attribute__((visibility("default")))* get_var_haptic_ops(void) \ +{ \ + return ops; \ +} \ + +const struct haptic_ops *get_var_haptic_ops(); +#endif /* __FEEDBACKD_HAPTIC_INTERFACE_H__ */ diff --git a/src/haptic/haptic.c b/src/driver/haptic.c similarity index 92% rename from src/haptic/haptic.c rename to src/driver/haptic.c index b5b3b93..a9ebe5b 100644 --- a/src/haptic/haptic.c +++ b/src/driver/haptic.c @@ -26,12 +26,13 @@ #include #include -#include "core/log.h" -#include "core/list.h" -#include "core/common.h" -#include "core/device-idler.h" -#include "core/config-parser.h" +#include "shared/log.h" +#include "shared/list.h" +#include "shared/common.h" +#include "shared/device-idler.h" +#include "shared/config-parser.h" #include "haptic.h" +#include "haptic-dev.h" #define FEEDBACK_BASE_PATH "/usr/share/feedback/" #define STANDARD_FILE_PATH FEEDBACK_BASE_PATH"vibration/" @@ -62,7 +63,6 @@ #define VCONFKEY_RECORDER_STATE_RECORDING 2 #endif -#define CHECK_VALID_OPS(ops, r) ((ops) ? true : !(r = -ENODEV)) #define RETRY_CNT 3 #define INTENSITY_BASE_RATE (10000) @@ -130,10 +130,8 @@ static dd_list *vib_conf_list; static guint duration_timer; /* haptic operation variable */ -static dd_list *h_head; static dd_list *haptic_handle_list; -static const struct haptic_plugin_ops *h_ops; -static enum haptic_type h_type; + static bool haptic_disabled; struct haptic_config { @@ -146,21 +144,10 @@ static struct haptic_config haptic_conf; static int haptic_start(void); static int haptic_stop(void); -static int haptic_internal_init(void); static int remove_haptic_info(struct haptic_info *info); struct haptic_data cur_h_data; -void add_haptic(const struct haptic_ops *ops) -{ - DD_LIST_APPEND(h_head, (void *)ops); -} - -void remove_haptic(const struct haptic_ops *ops) -{ - DD_LIST_REMOVE(h_head, (void *)ops); -} - static int insert_conf_data(dd_list **conf_data, struct duration_data *update) { struct duration_data *data; @@ -523,23 +510,13 @@ void pattern_config_parse(void) static int haptic_module_load(void) { - struct haptic_ops *ops; - dd_list *elem; int r; pattern_config_parse(); - /* find valid plugin */ - DD_LIST_FOREACH(h_head, elem, ops) { - if (ops->is_valid && ops->is_valid()) { - if (ops->load) - h_ops = ops->load(); - h_type = ops->type; - break; - } - } - if (!CHECK_VALID_OPS(h_ops, r)) { - _E("Can't find the valid haptic device."); + r = haptic_load_device(); + if (r < 0) { + _E("Failed to load device. ret=%d", r); return r; } @@ -548,7 +525,11 @@ static int haptic_module_load(void) * if the last handle is closed during the playing of vibration, * solution makes unlimited vibration. * so we need at least one handle. */ - haptic_internal_init(); + r = haptic_open_device(&g_handle); + if (r < 0) { + _E("Failed to open device. ret=%d", r); + return r; + } return 0; } @@ -581,10 +562,10 @@ GVariant *hdbus_get_count(GDBusConnection *conn, { int ret, val; - if (!CHECK_VALID_OPS(h_ops, ret)) + if ((ret = haptic_check_device()) < 0) goto exit; - ret = h_ops->get_device_count(&val); + ret = haptic_get_count_device(&val); if (ret >= 0) ret = val; @@ -607,8 +588,8 @@ void haptic_name_owner_changed(GDBusConnection *connection, for (n = info->handle_list; n; n = n->next) { handle = (int)(long)n->data; - h_ops->stop_device(handle); - h_ops->close_device(handle); + haptic_stop_device(handle); + haptic_close_device(handle); } remove_haptic_info(info); @@ -673,13 +654,12 @@ static struct haptic_info *get_matched_haptic_info(const char *sender) GVariant *hdbus_open_device(GDBusConnection *conn, const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) - { int index, handle, ret; struct haptic_info *info; /* Load haptic module before booting done */ - if (!CHECK_VALID_OPS(h_ops, ret)) { + if (haptic_check_device() < 0) { ret = haptic_module_load(); if (ret < 0) goto exit; @@ -687,13 +667,13 @@ GVariant *hdbus_open_device(GDBusConnection *conn, g_variant_get(param, "(i)", &index); - ret = h_ops->open_device(index, &handle); + ret = haptic_open_device(&handle); if (ret < 0) goto exit; if (!sender) { ret = -EPERM; - h_ops->close_device(handle); + haptic_close_device(handle); goto exit; } @@ -703,7 +683,7 @@ GVariant *hdbus_open_device(GDBusConnection *conn, if (!info) { _E("Failed to create haptic information."); ret = -EPERM; - h_ops->close_device(handle); + haptic_close_device(handle); goto exit; } } @@ -739,7 +719,7 @@ GVariant *hdbus_close_device(GDBusConnection *conn, struct haptic_info *info; int cnt; - if (!CHECK_VALID_OPS(h_ops, ret)) + if ((ret = haptic_check_device()) < 0) goto exit; g_variant_get(param, "(u)", &handle); @@ -750,7 +730,7 @@ GVariant *hdbus_close_device(GDBusConnection *conn, goto exit; } - ret = h_ops->close_device(handle); + ret = haptic_close_device(handle); if (ret < 0) goto exit; @@ -824,7 +804,7 @@ static void vibrate_monotone_idler_cb(void *data) vibrate_info->intensity); duration_timer = g_timeout_add(vibrate_info->duration, _cb, NULL); - h_ops->vibrate_monotone(cur_h_data.handle, vibrate_info->duration, 0, 0, cur_h_data.level, vibrate_info->intensity, cur_h_data.priority); + haptic_vibrate_device(cur_h_data.handle, vibrate_info->duration, 0, 0, cur_h_data.level, vibrate_info->intensity, cur_h_data.priority); free(vibrate_info); } @@ -837,7 +817,7 @@ GVariant *hdbus_vibrate_monotone(GDBusConnection *conn, unsigned int handle; int duration, level, intensity, priority, ret = 0; - if (!CHECK_VALID_OPS(h_ops, ret)) + if ((ret = haptic_check_device()) < 0) goto exit; if (haptic_disabled) @@ -933,7 +913,7 @@ static gboolean haptic_duration_play(void *data) duration_timer = g_timeout_add((node->duration + node->wait), haptic_duration_play, (void *)next); - ret = h_ops->vibrate_monotone(cur_h_data.handle, node->duration, node->frequency, node->overdrive, cur_h_data.level, node->intensity, cur_h_data.priority); + ret = haptic_vibrate_device(cur_h_data.handle, node->duration, node->frequency, node->overdrive, cur_h_data.level, node->intensity, cur_h_data.priority); break; } @@ -1021,7 +1001,7 @@ GVariant *hdbus_vibrate_pattern(GDBusConnection *conn, char *pattern = NULL; int level, priority, ret = 0; - if (!CHECK_VALID_OPS(h_ops, ret)) + if ((ret = haptic_check_device()) < 0) goto exit; if (haptic_disabled) @@ -1071,7 +1051,7 @@ GVariant *hdbus_stop_device(GDBusConnection *conn, unsigned int handle; int ret = 0; - if (!CHECK_VALID_OPS(h_ops, ret)) + if ((ret = haptic_check_device()) < 0) goto exit; if (haptic_disabled) { @@ -1086,7 +1066,7 @@ GVariant *hdbus_stop_device(GDBusConnection *conn, goto exit; } - ret = h_ops->stop_device(handle); + ret = haptic_stop_device(handle); _I("Stop the device(handle=%u) :%d", handle, ret); /* Remove duration_timer for vibrate_effect */ @@ -1143,7 +1123,7 @@ GVariant *hdbus_pattern_is_supported(GDBusConnection *conn, char *data = NULL; int ret = 0; - if (!CHECK_VALID_OPS(h_ops, ret)) + if ((ret = haptic_check_device()) < 0) goto exit; if (haptic_disabled) @@ -1160,22 +1140,6 @@ exit: return g_variant_new("(i)", ret); } -static int haptic_internal_init(void) -{ - int r; - if (!CHECK_VALID_OPS(h_ops, r)) - return r; - return h_ops->open_device(HAPTIC_MODULE_DEVICE_ALL, &g_handle); -} - -static int haptic_internal_exit(void) -{ - int r; - if (!CHECK_VALID_OPS(h_ops, r)) - return r; - return h_ops->close_device(g_handle); -} - static void haptic_poweroff_cb(GDBusConnection *conn, const gchar *sender, const gchar *path, @@ -1198,14 +1162,15 @@ static void haptic_poweroff_cb(GDBusConnection *conn, _D("Poweroff: %d", type); - if (!CHECK_VALID_OPS(h_ops, ret)) { - ret = haptic_module_load(); - if (ret < 0) - return; + if (haptic_check_device() < 0) { + if (haptic_module_load() < 0) + return ; } - if (!g_handle) - haptic_internal_init(); + if (!g_handle) { + if (haptic_open_device(&g_handle) < 0) + return ; + } if (vconf_get_int(VCONFKEY_SETAPPL_NOTI_VIBRATION_LEVEL_INT, &level) < 0) { _E("Failed to get '"VCONFKEY_SETAPPL_NOTI_VIBRATION_LEVEL_INT"' vconf value."); @@ -1217,7 +1182,7 @@ static void haptic_poweroff_cb(GDBusConnection *conn, _I("Handle=%d dur=%dms pri=%d level=%d intensity=%d frequency=0", g_handle, POWER_OFF_VIB_DURATION, PRIORITY_HIGH, level, POWER_VIB_FEEDBACK * 100); - ret = h_ops->vibrate_monotone(g_handle, POWER_OFF_VIB_DURATION, 0, 0, + ret = haptic_vibrate_device(g_handle, POWER_OFF_VIB_DURATION, 0, 0, level, POWER_VIB_FEEDBACK * 100, PRIORITY_HIGH); if (ret < 0) { _E("Failed to vibrate_monotone: %d", ret); @@ -1393,8 +1358,6 @@ void haptic_init(void) void haptic_exit(void) { - struct haptic_ops *ops; - dd_list *elem; int r; /* remove watch */ @@ -1410,21 +1373,12 @@ void haptic_exit(void) /* release haptic data memory */ safe_free(haptic_conf.level_arr); - if (!CHECK_VALID_OPS(h_ops, r)) + if (haptic_check_device() < 0) return; /* haptic exit for feedbackd */ - haptic_internal_exit(); - - /* release plugin */ - DD_LIST_FOREACH(h_head, elem, ops) { - if (ops->is_valid && ops->is_valid()) { - if (ops->release) - ops->release(); - h_ops = NULL; - break; - } - } + haptic_close_device(g_handle); + haptic_release_device(); } static int haptic_start(void) diff --git a/src/haptic/haptic.h b/src/driver/haptic.h similarity index 64% rename from src/haptic/haptic.h rename to src/driver/haptic.h index c77d64c..0947494 100644 --- a/src/haptic/haptic.h +++ b/src/driver/haptic.h @@ -22,24 +22,8 @@ #include #include -#include "core/common.h" -#include "core/list.h" -#include "haptic-plugin-intf.h" - -#define HAPTIC_OPS_REGISTER(dev) \ -static void __CONSTRUCTOR__ module_init(void) \ -{ \ - add_haptic(dev); \ -} \ -static void __DESTRUCTOR__ module_exit(void) \ -{ \ - remove_haptic(dev); \ -} - -enum haptic_type { - HAPTIC_STANDARD, - HAPTIC_EXTERNAL, -}; +#include "shared/common.h" +#include "shared/list.h" enum priority_level { PRIORITY_MIN = 0, @@ -48,13 +32,6 @@ enum priority_level { PRIORITY_TOP, }; -struct haptic_ops { - enum haptic_type type; - bool (*is_valid)(void); - const struct haptic_plugin_ops *(*load)(void); - void (*release)(void); -}; - struct haptic_data { dd_list *vibration_data; unsigned int handle; @@ -65,10 +42,6 @@ struct haptic_data { }; #define INVALID_HANDLE 0 -extern struct haptic_data cur_h_data; - -void add_haptic(const struct haptic_ops *ops); -void remove_haptic(const struct haptic_ops *ops); int haptic_probe(void); void haptic_init(void); diff --git a/src/haptic/standard.c b/src/driver/standard.c similarity index 97% rename from src/haptic/standard.c rename to src/driver/standard.c index c8bd450..17a9b23 100644 --- a/src/haptic/standard.c +++ b/src/driver/standard.c @@ -29,9 +29,10 @@ #include #include -#include "core/log.h" -#include "core/list.h" -#include "haptic.h" +#include "shared/common.h" +#include "shared/log.h" +#include "shared/list.h" +#include "haptic-interface.h" #define MAX_MAGNITUDE 0xFFFF #define PERIODIC_MAX_MAGNITUDE 0x7FFF /* 0.5 * MAX_MAGNITUDE */ @@ -500,21 +501,11 @@ static int stop_device(int device_handle) return -ENOENT; /* 2 */ } - if (!check_valid_handle(info)) { - _E("Handle %d fail to check handle", device_handle); - return -EINVAL; /* 22 */ - } - if (!check_fd(&ff_fd)) { _E("Handle %d fail to check fd", device_handle); return -ENODEV; /* 19 */ } - if (cur_h_data.handle > 0 && cur_h_data.handle != info->handle) { - _E("Only same handle can stop current vibration"); - return -EPERM; - } - /* stop effect */ r = ff_stop(ff_fd, &info->effect); if (r < 0) @@ -565,4 +556,4 @@ static const struct haptic_ops std_ops = { .load = load, }; -HAPTIC_OPS_REGISTER(&std_ops) +EXPORT_GET_VAR_HAPTIC_OPS(&std_ops) diff --git a/src/haptic/haptic-module.h b/src/haptic/haptic-module.h deleted file mode 100644 index 9b50bd1..0000000 --- a/src/haptic/haptic-module.h +++ /dev/null @@ -1,91 +0,0 @@ -/* - * deviced - * - * Copyright (c) 2012 - 2017 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. - */ - - -#ifndef __FEEDBACKD_HAPTIC_MODULE_H__ -#define __FEEDBACKD_HAPTIC_MODULE_H__ - -/** - * @brief Enumerations of device id for the Haptic Module API. - * @details We support two motors now. - */ -typedef enum { - HAPTIC_MODULE_DEVICE_0 = 0x0, /**< 1st motor */ - HAPTIC_MODULE_DEVICE_1 = 0x1, /**< 2nd motor */ - HAPTIC_MODULE_DEVICE_ALL = 0x4, /**< both of them */ -} haptic_module_device; - -/** - * @brief Enumerations of priority level for the Haptic Module API. - */ -typedef enum { - HAPTIC_MODULE_PRIORITY_MIN = 0, /**< Minimum effect priority for developers (default) */ - HAPTIC_MODULE_PRIORITY_MIDDLE, /**< Maximum effect priority for developers */ - HAPTIC_MODULE_PRIORITY_HIGH, /**< Maximum effect priority for OEMs */ -} haptic_module_priority; - -/** - * @brief Enumerations of feedback level for the Haptic Module API. - * @details Haptic level means vibration power (intensity). - */ -typedef enum { - HAPTIC_MODULE_FEEDBACK_MIN = 0, - HAPTIC_MODULE_FEEDBACK_MAX = 100, -} haptic_module_feedback; - -/** - * @brief Enumerations of unlimited duration for the Haptic Module API. - */ -typedef enum { - HAPTIC_MODULE_DURATION_UNLIMITED = 0x7FFFFFFF, -} haptic_module_duration; - -/** - * @brief Enumerations of iteration count for the Haptic Module API. - */ -typedef enum { - HAPTIC_MODULE_ITERATION_ONCE = 1, - HAPTIC_MODULE_ITERATION_INFINITE = 256, -} haptic_module_iteration; - -/** - * @brief Enumerations of effect or device state for the Haptic Module API. - */ -typedef enum { - HAPTIC_MODULE_STATE_STOP = 0, - HAPTIC_MODULE_STATE_PLAYING, -} haptic_module_state; - -/* Error and Return value codes */ -#define HAPTIC_MODULE_ERROR_NONE 0 -#define HAPTIC_MODULE_NOT_INITIALIZED -1 -#define HAPTIC_MODULE_ALREADY_INITIALIZED -2 -#define HAPTIC_MODULE_INVALID_ARGUMENT -3 -#define HAPTIC_MODULE_OPERATION_FAILED -4 -#define HAPTIC_MODULE_NOT_SUPPORTED -5 - -/** - * @par Description: - * effect element for haptic module. - */ -typedef struct { - int haptic_duration; /**< Start time of the effect element in millisecond */ - int haptic_level; /**< Duration of the effect element in millisecond */ -} haptic_module_effect_element; - -#endif /* __FEEDBACKD_HAPTIC_MODULE_H__ */ diff --git a/src/haptic/haptic-plugin-intf.h b/src/haptic/haptic-plugin-intf.h deleted file mode 100644 index 119c471..0000000 --- a/src/haptic/haptic-plugin-intf.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - * deviced - * - * Copyright (c) 2012 - 2017 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. - */ - - -#ifndef __FEEDBACKD_HAPTIC_PLUGIN_INTF_H__ -#define __FEEDBACKD_HAPTIC_PLUGIN_INTF_H__ - -#include "haptic-module.h" - -struct haptic_plugin_ops { - int (*get_device_count) (int*); - int (*open_device) (int, int*); - int (*close_device) (int); - int (*vibrate_monotone) (int, int, int, int, int, int, int); - int (*stop_device) (int); -}; - -const struct haptic_plugin_ops *get_haptic_plugin_interface(); - -#endif /* __FEEDBACKD_HAPTIC_PLUGIN_INTF_H__ */ diff --git a/src/core/common.c b/src/shared/common.c similarity index 100% rename from src/core/common.c rename to src/shared/common.c diff --git a/src/core/common.h b/src/shared/common.h similarity index 100% rename from src/core/common.h rename to src/shared/common.h diff --git a/src/core/config-parser.c b/src/shared/config-parser.c similarity index 100% rename from src/core/config-parser.c rename to src/shared/config-parser.c diff --git a/src/core/config-parser.h b/src/shared/config-parser.h similarity index 100% rename from src/core/config-parser.h rename to src/shared/config-parser.h diff --git a/src/core/device-idler.c b/src/shared/device-idler.c similarity index 100% rename from src/core/device-idler.c rename to src/shared/device-idler.c diff --git a/src/core/device-idler.h b/src/shared/device-idler.h similarity index 100% rename from src/core/device-idler.h rename to src/shared/device-idler.h diff --git a/src/core/list.h b/src/shared/list.h similarity index 100% rename from src/core/list.h rename to src/shared/list.h diff --git a/src/core/log.c b/src/shared/log.c similarity index 100% rename from src/core/log.c rename to src/shared/log.c diff --git a/src/core/log.h b/src/shared/log.h similarity index 100% rename from src/core/log.h rename to src/shared/log.h -- 2.7.4 From 031798286019bf4702170f5c062b0760b30c4071 Mon Sep 17 00:00:00 2001 From: Yunmi Ha Date: Tue, 5 Jan 2021 16:59:12 +0900 Subject: [PATCH 08/16] Use libsyscommon for list and ini-parser Change-Id: I6bf9fe57fbd38c0c59b71d30dec4c3b1918fa31f Signed-off-by: Yunmi Ha --- CMakeLists.txt | 2 +- src/auto-test/test.c | 23 ++++---- src/auto-test/test.h | 1 - src/driver/emulator.c | 20 +++---- src/driver/gpio_haptic.c | 20 +++---- src/driver/haptic-dev.h | 1 - src/driver/haptic.c | 64 +++++++++++------------ src/driver/haptic.h | 6 +-- src/driver/standard.c | 30 +++++------ src/shared/config-parser.c | 127 --------------------------------------------- src/shared/config-parser.h | 43 --------------- src/shared/list.h | 60 --------------------- 12 files changed, 83 insertions(+), 314 deletions(-) delete mode 100644 src/shared/config-parser.c delete mode 100644 src/shared/config-parser.h delete mode 100644 src/shared/list.h diff --git a/CMakeLists.txt b/CMakeLists.txt index ce52bc4..61437e4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,7 +10,6 @@ SET(VERSION 0.1.0) SET(SRCS src/core/main.c src/shared/common.c - src/shared/config-parser.c src/shared/device-idler.c src/shared/log.c src/driver/haptic.c @@ -56,6 +55,7 @@ SET(DRIVER_PKG_MODULES dlog capi-system-info glib-2.0 + libsyscommon ) INCLUDE(FindPkgConfig) diff --git a/src/auto-test/test.c b/src/auto-test/test.c index 581d4d0..da61f0e 100644 --- a/src/auto-test/test.c +++ b/src/auto-test/test.c @@ -17,29 +17,30 @@ */ #include +#include #include "test.h" -static dd_list *dd_head; +static list *dd_head; void add_test(const struct test_ops *d) { if (d->priority == TEST_PRIORITY_HIGH) - DD_LIST_PREPEND(dd_head, d); + LIST_PREPEND(dd_head, d); else - DD_LIST_APPEND(dd_head, d); + LIST_APPEND(dd_head, d); } void remove_test(const struct test_ops *d) { - DD_LIST_REMOVE(dd_head, d); + LIST_REMOVE(dd_head, d); } const struct test_ops *find_test(const char *name) { - dd_list *elem; + list *elem; const struct test_ops *d; - DD_LIST_FOREACH(dd_head, elem, d) { + LIST_FOREACH(dd_head, elem, d) { if (!strcasecmp(d->name, name)) return d; } @@ -48,11 +49,11 @@ const struct test_ops *find_test(const char *name) void test_init(void *data) { - dd_list *elem; + list *elem; const struct test_ops *d; - _D("Test module count(%d)", DD_LIST_LENGTH(dd_head)); - DD_LIST_FOREACH(dd_head, elem, d) { + _D("Test module count(%d)", LIST_LENGTH(dd_head)); + LIST_FOREACH(dd_head, elem, d) { _D("'%s' initialize", d->name); if (d->init) d->init(data); @@ -61,10 +62,10 @@ void test_init(void *data) void test_exit(void *data) { - dd_list *elem; + list *elem; const struct test_ops *d; - DD_LIST_FOREACH(dd_head, elem, d) { + LIST_FOREACH(dd_head, elem, d) { _D("'%s' deinitialize", d->name); if (d->exit) d->exit(data); diff --git a/src/auto-test/test.h b/src/auto-test/test.h index 2bdbdf6..e0b93ec 100644 --- a/src/auto-test/test.h +++ b/src/auto-test/test.h @@ -23,7 +23,6 @@ #include #include -#include "shared/list.h" #include "shared/log.h" #include "shared/common.h" diff --git a/src/driver/emulator.c b/src/driver/emulator.c index b04dad7..b2eb229 100644 --- a/src/driver/emulator.c +++ b/src/driver/emulator.c @@ -19,13 +19,13 @@ #include #include +#include #include "shared/common.h" #include "shared/log.h" -#include "shared/list.h" #include "haptic-dev.h" -static dd_list *handle_list; +static list *handle_list; static int unique_number = 0; /* START: Haptic Module APIs */ @@ -39,7 +39,7 @@ static int get_device_count(int *count) static int open_device(int device_index, int *device_handle) { - dd_list *elem; + list *elem; int handle; bool found = false; @@ -48,12 +48,12 @@ static int open_device(int device_index, int *device_handle) while (found != true) { ++unique_number; - elem = DD_LIST_FIND(handle_list, (gpointer)(long)unique_number); + elem = LIST_FIND(handle_list, (gpointer)(long)unique_number); if (!elem) found = true; } handle = unique_number; - DD_LIST_APPEND(handle_list, (gpointer)(long)handle); + LIST_APPEND(handle_list, (gpointer)(long)handle); if (device_handle) *device_handle = handle; @@ -63,16 +63,16 @@ static int open_device(int device_index, int *device_handle) static int close_device(int device_handle) { - DD_LIST_REMOVE(handle_list, (gpointer)(long)device_handle); + 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) { - dd_list *elem; + list *elem; - elem = DD_LIST_FIND(handle_list, (gpointer)(long)device_handle); + elem = LIST_FIND(handle_list, (gpointer)(long)device_handle); if (!elem) return -EINVAL; @@ -81,9 +81,9 @@ static int vibrate_monotone(int device_handle, int duration, int frequency, int static int stop_device(int device_handle) { - dd_list *elem; + list *elem; - elem = DD_LIST_FIND(handle_list, (gpointer)(long)device_handle); + elem = LIST_FIND(handle_list, (gpointer)(long)device_handle); if (!elem) return -EINVAL; diff --git a/src/driver/gpio_haptic.c b/src/driver/gpio_haptic.c index 6c3b4c1..38dba02 100644 --- a/src/driver/gpio_haptic.c +++ b/src/driver/gpio_haptic.c @@ -18,10 +18,10 @@ #include #include +#include #include "shared/common.h" #include "shared/log.h" -#include "shared/list.h" #include "haptic-interface.h" #include "peripheral_io.h" @@ -74,7 +74,7 @@ static peripheral_i2c_h device_handle = NULL; -static dd_list *handle_list; +static list *handle_list; static int unique_number; static bool state = false; @@ -85,9 +85,9 @@ static int gpio_haptic_stop_device(int handle); static bool find_from_list(int handle) { - dd_list *elem; + list *elem; - elem = DD_LIST_FIND(handle_list, (gpointer)(long)handle); + elem = LIST_FIND(handle_list, (gpointer)(long)handle); if (elem) return true; @@ -137,13 +137,13 @@ static int gpio_haptic_open_device(int device_index, int *handle) { int n; bool found = false; - dd_list *elem; + list *elem; if (!handle) return -EINVAL; /* if it is the first element */ - n = DD_LIST_LENGTH(handle_list); + n = LIST_LENGTH(handle_list); if (n == 0) { _I("Peripheral Device Open."); if (device_handle == NULL) { @@ -159,13 +159,13 @@ static int gpio_haptic_open_device(int device_index, int *handle) while (found != true) { ++unique_number; - elem = DD_LIST_FIND(handle_list, (gpointer)(long)unique_number); + elem = LIST_FIND(handle_list, (gpointer)(long)unique_number); if (!elem) found = true; } /* add info to local list */ - DD_LIST_APPEND(handle_list, (gpointer)(long)unique_number); + LIST_APPEND(handle_list, (gpointer)(long)unique_number); *handle = unique_number; return 0; @@ -193,10 +193,10 @@ static int gpio_haptic_close_device(int handle) _I("Already stopped or failed to stop effect: %d", r); _D("Handle(%d) is closed and timer deleted.", handle); - DD_LIST_REMOVE(handle_list, (gpointer)(long)handle); + LIST_REMOVE(handle_list, (gpointer)(long)handle); /* if it is the last element */ - n = DD_LIST_LENGTH(handle_list); + n = LIST_LENGTH(handle_list); if (n == 0) { _I("Peripheral Device Close."); if (device_handle != NULL) { diff --git a/src/driver/haptic-dev.h b/src/driver/haptic-dev.h index 979abed..208a5a1 100644 --- a/src/driver/haptic-dev.h +++ b/src/driver/haptic-dev.h @@ -21,7 +21,6 @@ i * Copyright (c) 2012 - 2020 Samsung Electronics Co., Ltd. #define __FEEDBACKD_HAPTIC_DEV_H__ #include -#include "shared/list.h" #include "haptic-interface.h" int haptic_load_device(void); diff --git a/src/driver/haptic.c b/src/driver/haptic.c index a9ebe5b..3de4aae 100644 --- a/src/driver/haptic.c +++ b/src/driver/haptic.c @@ -25,12 +25,12 @@ #include #include #include +#include +#include #include "shared/log.h" -#include "shared/list.h" #include "shared/common.h" #include "shared/device-idler.h" -#include "shared/config-parser.h" #include "haptic.h" #include "haptic-dev.h" @@ -80,7 +80,7 @@ struct vibration_config { char *pattern; /* pattern name */ char *standard; /* assigned standard pattern name */ - dd_list *data; /* duration_data list */ + list *data; /* duration_data list */ unsigned int pattern_duration; int unlimit; }; @@ -102,7 +102,7 @@ enum poweroff_type { struct haptic_info { char *sender; - dd_list *handle_list; + list *handle_list; guint id_watch; }; @@ -125,12 +125,12 @@ struct vibrate_monotone_info { static int g_handle; /* pattern configuration list */ -static dd_list *vib_conf_list; +static list *vib_conf_list; static guint duration_timer; /* haptic operation variable */ -static dd_list *haptic_handle_list; +static list *haptic_handle_list; static bool haptic_disabled; @@ -148,7 +148,7 @@ static int remove_haptic_info(struct haptic_info *info); struct haptic_data cur_h_data; -static int insert_conf_data(dd_list **conf_data, struct duration_data *update) +static int insert_conf_data(list **conf_data, struct duration_data *update) { struct duration_data *data; @@ -161,7 +161,7 @@ static int insert_conf_data(dd_list **conf_data, struct duration_data *update) /* insert vibration pattern data */ // to debug : // _D("%dD%dI%dF%dO%dW", data->duration, data->intensity, data->frequency, data->overdrive, data->wait); - DD_LIST_APPEND(*conf_data, data); + LIST_APPEND(*conf_data, data); return 0; } @@ -189,7 +189,7 @@ static void get_pattern_property(char **iter, char property, int *value) } /* [A]xxxDxxxIxxxFxxxOxxxW format */ -static int insert_raw_data_format(dd_list **conf_data, char *value) +static int insert_raw_data_format(list **conf_data, char *value) { struct duration_data update = {0, }; char *iter; @@ -372,7 +372,7 @@ static int load_standard_format(const char *pattern) } } close(fd); - DD_LIST_APPEND(vib_conf_list, conf); + LIST_APPEND(vib_conf_list, conf); return ret; error_out: @@ -423,7 +423,7 @@ static int vibration_load_config(struct parse_result *result, void *user_data) if (len == 0) { if (insert_raw_data_format(&conf->data, NULL) < 0) goto error_out; - DD_LIST_APPEND(vib_conf_list, conf); + LIST_APPEND(vib_conf_list, conf); return 0; } @@ -439,7 +439,7 @@ static int vibration_load_config(struct parse_result *result, void *user_data) _E("Failed to copy standard name."); goto error_out; } - DD_LIST_APPEND(vib_conf_list, conf); + LIST_APPEND(vib_conf_list, conf); return 0; } @@ -461,7 +461,7 @@ static int vibration_load_config(struct parse_result *result, void *user_data) goto error_out; } else conf->pattern_duration = duration; - DD_LIST_APPEND(vib_conf_list, conf); + LIST_APPEND(vib_conf_list, conf); return 0; @@ -577,7 +577,7 @@ void haptic_name_owner_changed(GDBusConnection *connection, const gchar *name, gpointer user_data) { - dd_list *n; + list *n; struct haptic_info *info = user_data; int handle; @@ -611,7 +611,7 @@ static struct haptic_info *add_haptic_info(const char *sender) return NULL; } - DD_LIST_APPEND(haptic_handle_list, info); + LIST_APPEND(haptic_handle_list, info); info->id_watch = dbus_handle_watch_name(sender, NULL, haptic_name_owner_changed, info, NULL); @@ -624,8 +624,8 @@ static int remove_haptic_info(struct haptic_info *info) dbus_handle_unwatch_name(info->id_watch); - DD_LIST_REMOVE(haptic_handle_list, info); - DD_LIST_FREE_LIST(info->handle_list); + LIST_REMOVE(haptic_handle_list, info); + LIST_FREE_LIST(info->handle_list); if (info->sender) { free(info->sender); } @@ -636,14 +636,14 @@ static int remove_haptic_info(struct haptic_info *info) static struct haptic_info *get_matched_haptic_info(const char *sender) { - dd_list *n; + list *n; struct haptic_info *info; int len; assert(sender); len = strlen(sender) + 1; - DD_LIST_FOREACH(haptic_handle_list, n, info) { + LIST_FOREACH(haptic_handle_list, n, info) { if (!strncmp(info->sender, sender, len)) return info; } @@ -688,7 +688,7 @@ GVariant *hdbus_open_device(GDBusConnection *conn, } } - DD_LIST_APPEND(info->handle_list, (gpointer)(long)handle); + LIST_APPEND(info->handle_list, (gpointer)(long)handle); ret = handle; @@ -745,8 +745,8 @@ GVariant *hdbus_close_device(GDBusConnection *conn, goto exit; } - DD_LIST_REMOVE(info->handle_list, (gpointer)(long)handle); - cnt = DD_LIST_LENGTH(info->handle_list); + LIST_REMOVE(info->handle_list, (gpointer)(long)handle); + cnt = LIST_LENGTH(info->handle_list); if (cnt == 0) remove_haptic_info(info); @@ -868,7 +868,7 @@ exit: static gboolean haptic_duration_play(void *data) { - dd_list *head, *n, *next; + list *head, *n, *next; struct duration_data *node; int ret = 0; @@ -886,7 +886,7 @@ static gboolean haptic_duration_play(void *data) goto out; } } else - head = (dd_list *)data; + head = (list *)data; if (cur_h_data.stop) { _I("Stop currunt vibration."); @@ -896,7 +896,7 @@ static gboolean haptic_duration_play(void *data) goto out; } - DD_LIST_FOREACH_SAFE(head, n, next, node) { + LIST_FOREACH_SAFE(head, n, next, node) { _I("Handle(%d) play=%dms and Wait=%dms %s type. (level=%d, intensity=%d, frequency=%d)", cur_h_data.handle, node->duration, node->wait, cur_h_data.unlimit ? "Unlimit" : "Once", cur_h_data.level, node->intensity, node->frequency); @@ -928,7 +928,7 @@ out: static void vibrate_pattern_idler_cb(void *data) { struct vibrate_pattern_info *vibrate_info; - dd_list *elem; + list *elem; struct vibration_config *conf; char pattern[PATH_MAX]; int ret; @@ -951,7 +951,7 @@ static void vibrate_pattern_idler_cb(void *data) } snprintf(pattern, sizeof(pattern), "%s", vibrate_info->pattern); - DD_LIST_FOREACH(vib_conf_list, elem, conf) { + LIST_FOREACH(vib_conf_list, elem, conf) { if (!conf->pattern) continue; if (strcmp(conf->pattern, pattern)) @@ -1080,12 +1080,12 @@ 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) { - dd_list *n; - dd_list *elem; + list *n; + list *elem; struct haptic_info *info; _D("Sender Handle"); - DD_LIST_FOREACH(haptic_handle_list, n, info) { + LIST_FOREACH(haptic_handle_list, n, info) { for (elem = info->handle_list; elem; elem = elem->next) _D("%s %d", info->sender, (int)(long)elem->data); } @@ -1095,7 +1095,7 @@ GVariant *hdbus_show_handle_list(GDBusConnection *conn, int pattern_is_supported(const char *pattern) { - dd_list *elem; + list *elem; struct vibration_config *conf; int ret; @@ -1103,7 +1103,7 @@ int pattern_is_supported(const char *pattern) return -EINVAL; ret = 0; - DD_LIST_FOREACH(vib_conf_list, elem, conf) { + LIST_FOREACH(vib_conf_list, elem, conf) { if (!conf->pattern) continue; if (!strcmp(conf->pattern, pattern)) { diff --git a/src/driver/haptic.h b/src/driver/haptic.h index 0947494..7251c8d 100644 --- a/src/driver/haptic.h +++ b/src/driver/haptic.h @@ -20,10 +20,10 @@ #ifndef __FEEDBACKD_HAPTIC_H__ #define __FEEDBACKD_HAPTIC_H__ -#include #include +#include +#include #include "shared/common.h" -#include "shared/list.h" enum priority_level { PRIORITY_MIN = 0, @@ -33,7 +33,7 @@ enum priority_level { }; struct haptic_data { - dd_list *vibration_data; + list *vibration_data; unsigned int handle; int level; int priority; diff --git a/src/driver/standard.c b/src/driver/standard.c index 17a9b23..2ac1271 100644 --- a/src/driver/standard.c +++ b/src/driver/standard.c @@ -28,10 +28,10 @@ #include #include #include +#include #include "shared/common.h" #include "shared/log.h" -#include "shared/list.h" #include "haptic-interface.h" #define MAX_MAGNITUDE 0xFFFF @@ -73,8 +73,8 @@ struct ff_info { }; static int ff_fd; -static dd_list *ff_list; -static dd_list *handle_list; +static list *ff_list; +static list *handle_list; static char ff_path[PATH_MAX]; static int unique_number; static int current_effect_id = -1; @@ -84,9 +84,9 @@ static int stop_device(int device_handle); struct ff_info *read_from_list(int handle) { struct ff_info *temp; - dd_list *elem; + list *elem; - DD_LIST_FOREACH(ff_list, elem, temp) { + LIST_FOREACH(ff_list, elem, temp) { if (temp->handle == handle) return temp; } @@ -96,9 +96,9 @@ struct ff_info *read_from_list(int handle) static bool check_valid_handle(struct ff_info *info) { struct ff_info *temp; - dd_list *elem; + list *elem; - DD_LIST_FOREACH(ff_list, elem, temp) { + LIST_FOREACH(ff_list, elem, temp) { if (temp == info) break; } @@ -336,13 +336,13 @@ static int open_device(int device_index, int *device_handle) struct ff_info *info; int n; bool found = false; - dd_list *elem; + list *elem; if (!device_handle) return -EINVAL; /* if it is the first element */ - n = DD_LIST_LENGTH(ff_list); + n = LIST_LENGTH(ff_list); if (n == 0 && !ff_fd) { _I("First element: open ff driver"); /* open ff driver */ @@ -368,7 +368,7 @@ static int open_device(int device_index, int *device_handle) while (found != true) { ++unique_number; - elem = DD_LIST_FIND(handle_list, (gpointer)(long)unique_number); + elem = LIST_FIND(handle_list, (gpointer)(long)unique_number); if (!elem) found = true; } @@ -376,8 +376,8 @@ static int open_device(int device_index, int *device_handle) info->handle = unique_number; /* add info to local list */ - DD_LIST_APPEND(ff_list, info); - DD_LIST_APPEND(handle_list, (gpointer)(long)info->handle); + LIST_APPEND(ff_list, info); + LIST_APPEND(handle_list, (gpointer)(long)info->handle); *device_handle = info->handle; return 0; @@ -407,15 +407,15 @@ static int close_device(int device_handle) /* stop vibration */ stop_device(device_handle); - DD_LIST_REMOVE(handle_list, (gpointer)(long)info->handle); + LIST_REMOVE(handle_list, (gpointer)(long)info->handle); safe_free(info->ffinfobuffer); /* remove info from local list */ - DD_LIST_REMOVE(ff_list, info); + LIST_REMOVE(ff_list, info); safe_free(info); /* if it is the last element */ - n = DD_LIST_LENGTH(ff_list); + n = LIST_LENGTH(ff_list); if (n == 0 && ff_fd) { _I("Last element: close ff driver"); /* close ff driver */ diff --git a/src/shared/config-parser.c b/src/shared/config-parser.c deleted file mode 100644 index 013ddbf..0000000 --- a/src/shared/config-parser.c +++ /dev/null @@ -1,127 +0,0 @@ -/* - * feedbackd - * - * Copyright (c) 2013 - 2017 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 "log.h" -#include "config-parser.h" - -#define MAX_LINE 512 -#define MAX_SECTION 64 -#define WHITESPACE " \t" -#define NEWLINE "\n\r" -#define COMMENT '#' - -static inline char *trim_str(char *s) -{ - char *t; - /* left trim */ - s += strspn(s, WHITESPACE); - - /* right trim */ - for (t = strchr(s, 0); t > s; t--) - if (!strchr(WHITESPACE, t[-1])) - break; - *t = 0; - return s; -} - -int config_parse(const char *file_name, int cb(struct parse_result *result, - void *user_data), void *user_data) -{ - FILE *f = NULL; - struct parse_result result; - /* use stack for parsing */ - char line[MAX_LINE]; - char section[MAX_SECTION]; - char *start, *end, *name, *value; - int lineno = 0, ret = 0; - - if (!file_name || !cb) { - ret = -EINVAL; - goto error; - } - - /* open conf file */ - f = fopen(file_name, "r"); - if (!f) { - _E("Failed to open file '%s'.", file_name); - ret = -EIO; - goto error; - } - - /* parsing line by line */ - while (fgets(line, MAX_LINE, f) != NULL) { - lineno++; - - start = line; - start[strcspn(start, NEWLINE)] = '\0'; - start = trim_str(start); - - if (*start == COMMENT) { - continue; - } else if (*start == '[') { - /* parse section */ - end = strchr(start, ']'); - if (!end || *end != ']') { - ret = -EBADMSG; - goto error; - } - - *end = '\0'; - strncpy(section, start + 1, sizeof(section)-1); - section[MAX_SECTION-1] = '\0'; - } else if (*start) { - /* parse name & value */ - end = strchr(start, '='); - if (!end || *end != '=') { - ret = -EBADMSG; - goto error; - } - *end = '\0'; - name = trim_str(start); - value = trim_str(end + 1); - end = strchr(value, COMMENT); - if (end && *end == COMMENT) { - *end = '\0'; - value = trim_str(value); - } - - result.section = section; - result.name = name; - result.value = value; - /* callback with parse result */ - ret = cb(&result, user_data); - if (ret < 0) { - ret = -EBADMSG; - goto error; - } - } - } - _D("Success to load '%s'.", file_name); - fclose(f); - return 0; - -error: - if (f) - fclose(f); - _E("Failed to read '%s': %d", file_name, lineno); - return ret; -} - diff --git a/src/shared/config-parser.h b/src/shared/config-parser.h deleted file mode 100644 index 71fa379..0000000 --- a/src/shared/config-parser.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - * feedbackd - * - * Copyright (c) 2013 - 2017 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. - */ - - -#ifndef __FEEDBACKD_CONFIG_PARSER_H__ -#define __FEEDBACKD_CONFIG_PARSER_H__ - -#define MATCH(a, b) (!strncmp(a, b, strlen(a))) -#define SET_CONF(a, b) (a = (b > 0.0 ? b : a)) - -struct parse_result { - char *section; - char *name; - char *value; -}; - -/** - * @brief Parse config file and call callback\n - * @param[in] file_name conf file. - * @param[in] cb cb is called when conf file is parsed line by line. - * @param[in] user_data user data is passed to cb. - * @return 0 on success, negative if failed - */ -int config_parse(const char *file_name, int cb(struct parse_result *result, - void *user_data), void *user_data); - -#endif - diff --git a/src/shared/list.h b/src/shared/list.h deleted file mode 100644 index 1ef40b4..0000000 --- a/src/shared/list.h +++ /dev/null @@ -1,60 +0,0 @@ -/* - * feedbackd - * - * Copyright (c) 2012 - 2017 Samsung Electronics Co., Ltd. All rights reserved. - * - * 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. - */ - -#ifndef __FEEDBACKD_LIST_H__ -#define __FEEDBACKD_LIST_H__ - -#include -typedef GList dd_list; - -#define DD_LIST_PREPEND(a, b) \ - a = g_list_prepend(a, (gpointer)b) -#define DD_LIST_APPEND(a, b) \ - a = g_list_append(a, (gpointer)b) -#define DD_LIST_REMOVE(a, b) \ - a = g_list_remove(a, (gpointer)b) -#define DD_LIST_REMOVE_LIST(a, b) \ - a = g_list_delete_link(a, b) -#define DD_LIST_LENGTH(a) \ - g_list_length(a) -#define DD_LIST_NTH(a, b) \ - g_list_nth_data(a, b) -#define DD_LIST_FIND(a, b) \ - g_list_find(a, (gpointer)b) -#define DD_LIST_FREE_LIST(a) \ - g_list_free(a) -#define DD_LIST_FOREACH(head, elem, node) \ - for (elem = head, node = NULL; \ - elem && ((node = elem->data) != NULL); \ - elem = elem->next, node = NULL) -#define DD_LIST_FOREACH_SAFE(head, elem, elem_next, node) \ - for (elem = head, elem_next = g_list_next(elem), node = NULL; \ - elem && ((node = elem->data) != NULL); \ - elem = elem_next, elem_next = g_list_next(elem), node = NULL) -#define DD_LIST_REVERSE_FOREACH(head, elem, node) \ - for (elem = g_list_last(head), node = NULL; \ - elem && ((node = elem->data) != NULL); \ - elem = g_list_previous(elem), node = NULL) -#define DD_LIST_REVERSE_FOREACH_SAFE(head, elem, elem_next, node) \ - for (elem = g_list_last(head), elem_next = g_list_previous(elem), node = NULL; \ - elem && ((node = elem->data) != NULL); \ - elem = elem_next, elem_next = g_list_previous(elem), node = NULL) -#define DD_LIST_NEXT(a) \ - g_list_next(a) - -#endif -- 2.7.4 From 9117d54a7f9c4c03e9088203eed7a05f8b367a81 Mon Sep 17 00:00:00 2001 From: Yunmi Ha Date: Wed, 6 Jan 2021 16:46:23 +0900 Subject: [PATCH 09/16] Change prefix of list definition - list to SYS_G_LIST Change-Id: I44114cdf425e5d232f0414018c5a3698b881d17c Signed-off-by: Yunmi Ha --- src/auto-test/test.c | 22 +++++++++--------- src/driver/emulator.c | 18 +++++++-------- src/driver/gpio_haptic.c | 18 +++++++-------- src/driver/haptic.c | 60 ++++++++++++++++++++++++------------------------ src/driver/haptic.h | 4 ++-- src/driver/standard.c | 28 +++++++++++----------- 6 files changed, 75 insertions(+), 75 deletions(-) diff --git a/src/auto-test/test.c b/src/auto-test/test.c index da61f0e..f78bb16 100644 --- a/src/auto-test/test.c +++ b/src/auto-test/test.c @@ -20,27 +20,27 @@ #include #include "test.h" -static list *dd_head; +static GList *dd_head; void add_test(const struct test_ops *d) { if (d->priority == TEST_PRIORITY_HIGH) - LIST_PREPEND(dd_head, d); + SYS_G_LIST_PREPEND(dd_head, d); else - LIST_APPEND(dd_head, d); + SYS_G_LIST_APPEND(dd_head, d); } void remove_test(const struct test_ops *d) { - LIST_REMOVE(dd_head, d); + SYS_G_LIST_REMOVE(dd_head, d); } const struct test_ops *find_test(const char *name) { - list *elem; + GList *elem; const struct test_ops *d; - LIST_FOREACH(dd_head, elem, d) { + SYS_G_LIST_FOREACH(dd_head, elem, d) { if (!strcasecmp(d->name, name)) return d; } @@ -49,11 +49,11 @@ const struct test_ops *find_test(const char *name) void test_init(void *data) { - list *elem; + GList *elem; const struct test_ops *d; - _D("Test module count(%d)", LIST_LENGTH(dd_head)); - LIST_FOREACH(dd_head, elem, d) { + _D("Test module count(%d)", SYS_G_LIST_LENGTH(dd_head)); + SYS_G_LIST_FOREACH(dd_head, elem, d) { _D("'%s' initialize", d->name); if (d->init) d->init(data); @@ -62,10 +62,10 @@ void test_init(void *data) void test_exit(void *data) { - list *elem; + GList *elem; const struct test_ops *d; - LIST_FOREACH(dd_head, elem, d) { + SYS_G_LIST_FOREACH(dd_head, elem, d) { _D("'%s' deinitialize", d->name); if (d->exit) d->exit(data); diff --git a/src/driver/emulator.c b/src/driver/emulator.c index b2eb229..bca8790 100644 --- a/src/driver/emulator.c +++ b/src/driver/emulator.c @@ -25,7 +25,7 @@ #include "shared/log.h" #include "haptic-dev.h" -static list *handle_list; +static GList *handle_list; static int unique_number = 0; /* START: Haptic Module APIs */ @@ -39,7 +39,7 @@ static int get_device_count(int *count) static int open_device(int device_index, int *device_handle) { - list *elem; + GList *elem; int handle; bool found = false; @@ -48,12 +48,12 @@ static int open_device(int device_index, int *device_handle) while (found != true) { ++unique_number; - elem = LIST_FIND(handle_list, (gpointer)(long)unique_number); + elem = SYS_G_LIST_FIND(handle_list, (gpointer)(long)unique_number); if (!elem) found = true; } handle = unique_number; - LIST_APPEND(handle_list, (gpointer)(long)handle); + SYS_G_LIST_APPEND(handle_list, (gpointer)(long)handle); if (device_handle) *device_handle = handle; @@ -63,16 +63,16 @@ static int open_device(int device_index, int *device_handle) static int close_device(int device_handle) { - LIST_REMOVE(handle_list, (gpointer)(long)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) { - list *elem; + GList *elem; - elem = LIST_FIND(handle_list, (gpointer)(long)device_handle); + elem = SYS_G_LIST_FIND(handle_list, (gpointer)(long)device_handle); if (!elem) return -EINVAL; @@ -81,9 +81,9 @@ static int vibrate_monotone(int device_handle, int duration, int frequency, int static int stop_device(int device_handle) { - list *elem; + GList *elem; - elem = LIST_FIND(handle_list, (gpointer)(long)device_handle); + elem = SYS_G_LIST_FIND(handle_list, (gpointer)(long)device_handle); if (!elem) return -EINVAL; diff --git a/src/driver/gpio_haptic.c b/src/driver/gpio_haptic.c index 38dba02..fb175cd 100644 --- a/src/driver/gpio_haptic.c +++ b/src/driver/gpio_haptic.c @@ -74,7 +74,7 @@ static peripheral_i2c_h device_handle = NULL; -static list *handle_list; +static GList *handle_list; static int unique_number; static bool state = false; @@ -85,9 +85,9 @@ static int gpio_haptic_stop_device(int handle); static bool find_from_list(int handle) { - list *elem; + GList *elem; - elem = LIST_FIND(handle_list, (gpointer)(long)handle); + elem = SYS_G_LIST_FIND(handle_list, (gpointer)(long)handle); if (elem) return true; @@ -137,13 +137,13 @@ static int gpio_haptic_open_device(int device_index, int *handle) { int n; bool found = false; - list *elem; + GList *elem; if (!handle) return -EINVAL; /* if it is the first element */ - n = LIST_LENGTH(handle_list); + n = SYS_G_LIST_LENGTH(handle_list); if (n == 0) { _I("Peripheral Device Open."); if (device_handle == NULL) { @@ -159,13 +159,13 @@ static int gpio_haptic_open_device(int device_index, int *handle) while (found != true) { ++unique_number; - elem = LIST_FIND(handle_list, (gpointer)(long)unique_number); + elem = SYS_G_LIST_FIND(handle_list, (gpointer)(long)unique_number); if (!elem) found = true; } /* add info to local list */ - LIST_APPEND(handle_list, (gpointer)(long)unique_number); + SYS_G_LIST_APPEND(handle_list, (gpointer)(long)unique_number); *handle = unique_number; return 0; @@ -193,10 +193,10 @@ static int gpio_haptic_close_device(int handle) _I("Already stopped or failed to stop effect: %d", r); _D("Handle(%d) is closed and timer deleted.", handle); - LIST_REMOVE(handle_list, (gpointer)(long)handle); + SYS_G_LIST_REMOVE(handle_list, (gpointer)(long)handle); /* if it is the last element */ - n = LIST_LENGTH(handle_list); + n = SYS_G_LIST_LENGTH(handle_list); if (n == 0) { _I("Peripheral Device Close."); if (device_handle != NULL) { diff --git a/src/driver/haptic.c b/src/driver/haptic.c index 3de4aae..19c4145 100644 --- a/src/driver/haptic.c +++ b/src/driver/haptic.c @@ -80,7 +80,7 @@ struct vibration_config { char *pattern; /* pattern name */ char *standard; /* assigned standard pattern name */ - list *data; /* duration_data list */ + GList *data; /* duration_data list */ unsigned int pattern_duration; int unlimit; }; @@ -102,7 +102,7 @@ enum poweroff_type { struct haptic_info { char *sender; - list *handle_list; + GList *handle_list; guint id_watch; }; @@ -125,12 +125,12 @@ struct vibrate_monotone_info { static int g_handle; /* pattern configuration list */ -static list *vib_conf_list; +static GList *vib_conf_list; static guint duration_timer; /* haptic operation variable */ -static list *haptic_handle_list; +static GList *haptic_handle_list; static bool haptic_disabled; @@ -148,7 +148,7 @@ static int remove_haptic_info(struct haptic_info *info); struct haptic_data cur_h_data; -static int insert_conf_data(list **conf_data, struct duration_data *update) +static int insert_conf_data(GList **conf_data, struct duration_data *update) { struct duration_data *data; @@ -161,7 +161,7 @@ static int insert_conf_data(list **conf_data, struct duration_data *update) /* insert vibration pattern data */ // to debug : // _D("%dD%dI%dF%dO%dW", data->duration, data->intensity, data->frequency, data->overdrive, data->wait); - LIST_APPEND(*conf_data, data); + SYS_G_LIST_APPEND(*conf_data, data); return 0; } @@ -189,7 +189,7 @@ static void get_pattern_property(char **iter, char property, int *value) } /* [A]xxxDxxxIxxxFxxxOxxxW format */ -static int insert_raw_data_format(list **conf_data, char *value) +static int insert_raw_data_format(GList **conf_data, char *value) { struct duration_data update = {0, }; char *iter; @@ -372,7 +372,7 @@ static int load_standard_format(const char *pattern) } } close(fd); - LIST_APPEND(vib_conf_list, conf); + SYS_G_LIST_APPEND(vib_conf_list, conf); return ret; error_out: @@ -423,7 +423,7 @@ static int vibration_load_config(struct parse_result *result, void *user_data) if (len == 0) { if (insert_raw_data_format(&conf->data, NULL) < 0) goto error_out; - LIST_APPEND(vib_conf_list, conf); + SYS_G_LIST_APPEND(vib_conf_list, conf); return 0; } @@ -439,7 +439,7 @@ static int vibration_load_config(struct parse_result *result, void *user_data) _E("Failed to copy standard name."); goto error_out; } - LIST_APPEND(vib_conf_list, conf); + SYS_G_LIST_APPEND(vib_conf_list, conf); return 0; } @@ -461,7 +461,7 @@ static int vibration_load_config(struct parse_result *result, void *user_data) goto error_out; } else conf->pattern_duration = duration; - LIST_APPEND(vib_conf_list, conf); + SYS_G_LIST_APPEND(vib_conf_list, conf); return 0; @@ -577,7 +577,7 @@ void haptic_name_owner_changed(GDBusConnection *connection, const gchar *name, gpointer user_data) { - list *n; + GList *n; struct haptic_info *info = user_data; int handle; @@ -611,7 +611,7 @@ static struct haptic_info *add_haptic_info(const char *sender) return NULL; } - LIST_APPEND(haptic_handle_list, info); + SYS_G_LIST_APPEND(haptic_handle_list, info); info->id_watch = dbus_handle_watch_name(sender, NULL, haptic_name_owner_changed, info, NULL); @@ -624,8 +624,8 @@ static int remove_haptic_info(struct haptic_info *info) dbus_handle_unwatch_name(info->id_watch); - LIST_REMOVE(haptic_handle_list, info); - LIST_FREE_LIST(info->handle_list); + SYS_G_LIST_REMOVE(haptic_handle_list, info); + SYS_G_LIST_FREE_LIST(info->handle_list); if (info->sender) { free(info->sender); } @@ -636,14 +636,14 @@ static int remove_haptic_info(struct haptic_info *info) static struct haptic_info *get_matched_haptic_info(const char *sender) { - list *n; + GList *n; struct haptic_info *info; int len; assert(sender); len = strlen(sender) + 1; - LIST_FOREACH(haptic_handle_list, n, info) { + SYS_G_LIST_FOREACH(haptic_handle_list, n, info) { if (!strncmp(info->sender, sender, len)) return info; } @@ -688,7 +688,7 @@ GVariant *hdbus_open_device(GDBusConnection *conn, } } - LIST_APPEND(info->handle_list, (gpointer)(long)handle); + SYS_G_LIST_APPEND(info->handle_list, (gpointer)(long)handle); ret = handle; @@ -745,8 +745,8 @@ GVariant *hdbus_close_device(GDBusConnection *conn, goto exit; } - LIST_REMOVE(info->handle_list, (gpointer)(long)handle); - cnt = LIST_LENGTH(info->handle_list); + SYS_G_LIST_REMOVE(info->handle_list, (gpointer)(long)handle); + cnt = SYS_G_LIST_LENGTH(info->handle_list); if (cnt == 0) remove_haptic_info(info); @@ -868,7 +868,7 @@ exit: static gboolean haptic_duration_play(void *data) { - list *head, *n, *next; + GList *head, *n, *next; struct duration_data *node; int ret = 0; @@ -886,7 +886,7 @@ static gboolean haptic_duration_play(void *data) goto out; } } else - head = (list *)data; + head = (GList *)data; if (cur_h_data.stop) { _I("Stop currunt vibration."); @@ -896,7 +896,7 @@ static gboolean haptic_duration_play(void *data) goto out; } - LIST_FOREACH_SAFE(head, n, next, node) { + SYS_G_LIST_FOREACH_SAFE(head, n, next, node) { _I("Handle(%d) play=%dms and Wait=%dms %s type. (level=%d, intensity=%d, frequency=%d)", cur_h_data.handle, node->duration, node->wait, cur_h_data.unlimit ? "Unlimit" : "Once", cur_h_data.level, node->intensity, node->frequency); @@ -928,7 +928,7 @@ out: static void vibrate_pattern_idler_cb(void *data) { struct vibrate_pattern_info *vibrate_info; - list *elem; + GList *elem; struct vibration_config *conf; char pattern[PATH_MAX]; int ret; @@ -951,7 +951,7 @@ static void vibrate_pattern_idler_cb(void *data) } snprintf(pattern, sizeof(pattern), "%s", vibrate_info->pattern); - LIST_FOREACH(vib_conf_list, elem, conf) { + SYS_G_LIST_FOREACH(vib_conf_list, elem, conf) { if (!conf->pattern) continue; if (strcmp(conf->pattern, pattern)) @@ -1080,12 +1080,12 @@ 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) { - list *n; - list *elem; + GList *n; + GList *elem; struct haptic_info *info; _D("Sender Handle"); - LIST_FOREACH(haptic_handle_list, n, info) { + SYS_G_LIST_FOREACH(haptic_handle_list, n, info) { for (elem = info->handle_list; elem; elem = elem->next) _D("%s %d", info->sender, (int)(long)elem->data); } @@ -1095,7 +1095,7 @@ GVariant *hdbus_show_handle_list(GDBusConnection *conn, int pattern_is_supported(const char *pattern) { - list *elem; + GList *elem; struct vibration_config *conf; int ret; @@ -1103,7 +1103,7 @@ int pattern_is_supported(const char *pattern) return -EINVAL; ret = 0; - LIST_FOREACH(vib_conf_list, elem, conf) { + SYS_G_LIST_FOREACH(vib_conf_list, elem, conf) { if (!conf->pattern) continue; if (!strcmp(conf->pattern, pattern)) { diff --git a/src/driver/haptic.h b/src/driver/haptic.h index 7251c8d..54b92d5 100644 --- a/src/driver/haptic.h +++ b/src/driver/haptic.h @@ -21,8 +21,8 @@ #define __FEEDBACKD_HAPTIC_H__ #include +#include #include -#include #include "shared/common.h" enum priority_level { @@ -33,7 +33,7 @@ enum priority_level { }; struct haptic_data { - list *vibration_data; + GList *vibration_data; unsigned int handle; int level; int priority; diff --git a/src/driver/standard.c b/src/driver/standard.c index 2ac1271..310bd3e 100644 --- a/src/driver/standard.c +++ b/src/driver/standard.c @@ -73,8 +73,8 @@ struct ff_info { }; static int ff_fd; -static list *ff_list; -static list *handle_list; +static GList *ff_list; +static GList *handle_list; static char ff_path[PATH_MAX]; static int unique_number; static int current_effect_id = -1; @@ -84,9 +84,9 @@ static int stop_device(int device_handle); struct ff_info *read_from_list(int handle) { struct ff_info *temp; - list *elem; + GList *elem; - LIST_FOREACH(ff_list, elem, temp) { + SYS_G_LIST_FOREACH(ff_list, elem, temp) { if (temp->handle == handle) return temp; } @@ -96,9 +96,9 @@ struct ff_info *read_from_list(int handle) static bool check_valid_handle(struct ff_info *info) { struct ff_info *temp; - list *elem; + GList *elem; - LIST_FOREACH(ff_list, elem, temp) { + SYS_G_LIST_FOREACH(ff_list, elem, temp) { if (temp == info) break; } @@ -336,13 +336,13 @@ static int open_device(int device_index, int *device_handle) struct ff_info *info; int n; bool found = false; - list *elem; + GList *elem; if (!device_handle) return -EINVAL; /* if it is the first element */ - n = LIST_LENGTH(ff_list); + n = SYS_G_LIST_LENGTH(ff_list); if (n == 0 && !ff_fd) { _I("First element: open ff driver"); /* open ff driver */ @@ -368,7 +368,7 @@ static int open_device(int device_index, int *device_handle) while (found != true) { ++unique_number; - elem = LIST_FIND(handle_list, (gpointer)(long)unique_number); + elem = SYS_G_LIST_FIND(handle_list, (gpointer)(long)unique_number); if (!elem) found = true; } @@ -376,8 +376,8 @@ static int open_device(int device_index, int *device_handle) info->handle = unique_number; /* add info to local list */ - LIST_APPEND(ff_list, info); - LIST_APPEND(handle_list, (gpointer)(long)info->handle); + SYS_G_LIST_APPEND(ff_list, info); + SYS_G_LIST_APPEND(handle_list, (gpointer)(long)info->handle); *device_handle = info->handle; return 0; @@ -407,15 +407,15 @@ static int close_device(int device_handle) /* stop vibration */ stop_device(device_handle); - LIST_REMOVE(handle_list, (gpointer)(long)info->handle); + SYS_G_LIST_REMOVE(handle_list, (gpointer)(long)info->handle); safe_free(info->ffinfobuffer); /* remove info from local list */ - LIST_REMOVE(ff_list, info); + SYS_G_LIST_REMOVE(ff_list, info); safe_free(info); /* if it is the last element */ - n = LIST_LENGTH(ff_list); + n = SYS_G_LIST_LENGTH(ff_list); if (n == 0 && ff_fd) { _I("Last element: close ff driver"); /* close ff driver */ -- 2.7.4 From c5bd9b009e8860d263d17e3af5e809669b8d9d18 Mon Sep 17 00:00:00 2001 From: Yunmi Ha Date: Wed, 13 Jan 2021 17:23:51 +0900 Subject: [PATCH 10/16] Apply next HAL architecture (hal api + backend) Change-Id: I47a0b94cbf5ed7a5eae45ab06a7d32766c6b64b7 Signed-off-by: Yunmi Ha --- CMakeLists.txt | 38 +-- packaging/feedbackd.spec | 69 +----- src/{driver => core}/haptic.c | 58 ++--- src/{driver => core}/haptic.h | 0 src/core/main.c | 2 +- src/driver/emulator.c | 123 ---------- src/driver/external.c | 101 -------- src/driver/gpio_haptic.c | 339 ------------------------- src/driver/haptic-dev.c | 166 ------------- src/driver/haptic-dev.h | 37 --- src/driver/haptic-interface.h | 69 ------ src/driver/standard.c | 559 ------------------------------------------ 12 files changed, 30 insertions(+), 1531 deletions(-) rename src/{driver => core}/haptic.c (95%) rename src/{driver => core}/haptic.h (100%) delete mode 100644 src/driver/emulator.c delete mode 100644 src/driver/external.c delete mode 100644 src/driver/gpio_haptic.c delete mode 100644 src/driver/haptic-dev.c delete mode 100644 src/driver/haptic-dev.h delete mode 100644 src/driver/haptic-interface.h delete mode 100644 src/driver/standard.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 61437e4..a8ce79a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,11 +9,10 @@ SET(VERSION 0.1.0) SET(SRCS src/core/main.c + src/core/haptic.c src/shared/common.c src/shared/device-idler.c src/shared/log.c - src/driver/haptic.c - src/driver/haptic-dev.c ) INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/src) @@ -29,6 +28,8 @@ SET(PKG_MODULES libsyscommon libsystemd capi-system-device + hal-api-device + hal-api-common ) INCLUDE(FindPkgConfig) @@ -44,44 +45,11 @@ SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -lrt -fPIE") SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pie") ADD_DEFINITIONS("-DDEBUG") -ADD_DEFINITIONS("-DLIBPATH=\"${LIB_INSTALL_DIR}\"") ADD_EXECUTABLE(${PROJECT_NAME} ${SRCS}) TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${pkgs2_LDFLAGS} "-ldl" "-lm") INSTALL(TARGETS ${PROJECT_NAME} DESTINATION bin) -SET(LIB_PREFIX haptic_) -SET(DRIVER_PKG_MODULES - dlog - capi-system-info - glib-2.0 - libsyscommon -) - -INCLUDE(FindPkgConfig) -pkg_check_modules(pkgs_driver REQUIRED ${DRIVER_PKG_MODULES}) - -FOREACH(flag_driver ${pkgs_driver_CFLAGS}) - SET(DRIVER_CFLAGS "${DRIVER_CFLAGS} ${flag_driver}") -ENDFOREACH(flag_driver) - -SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${DRIVER_CFLAGS} -fvisibility=hidden -Werror -g -fno-omit-frame-pointer -finstrument-functions -pie") - -ADD_LIBRARY(emul MODULE src/driver/emulator.c) -TARGET_LINK_LIBRARIES(emul ${pkgs_driver_LDFLAGS} "-ldl") -SET_TARGET_PROPERTIES(emul PROPERTIES PREFIX ${LIB_PREFIX}) -INSTALL(TARGETS emul DESTINATION ${LIB_INSTALL_DIR} COMPONENT RuntimeLibraries) - -ADD_LIBRARY(gpio MODULE src/driver/gpio_haptic.c) -TARGET_LINK_LIBRARIES(gpio ${pkgs_driver_LDFLAGS} "-lcapi-system-peripheral-io -ldl") -SET_TARGET_PROPERTIES(gpio PROPERTIES PREFIX ${LIB_PREFIX}) -INSTALL(TARGETS gpio DESTINATION ${LIB_INSTALL_DIR} COMPONENT RuntimeLibraries) - -ADD_LIBRARY(standard MODULE src/driver/standard.c) -TARGET_LINK_LIBRARIES(standard ${pkgs_driver_LDFLAGS} "-ldl") -SET_TARGET_PROPERTIES(standard PROPERTIES PREFIX ${LIB_PREFIX}) -INSTALL(TARGETS standard DESTINATION ${LIB_INSTALL_DIR} COMPONENT RuntimeLibraries) - INSTALL(FILES ${CMAKE_SOURCE_DIR}/conf/feedbackd.conf DESTINATION /etc/dbus-1/system.d) INSTALL(DIRECTORY ${CMAKE_SOURCE_DIR}/systemd/ DESTINATION lib/systemd/system FILES_MATCHING diff --git a/packaging/feedbackd.spec b/packaging/feedbackd.spec index b812d64..7272b69 100644 --- a/packaging/feedbackd.spec +++ b/packaging/feedbackd.spec @@ -20,10 +20,11 @@ BuildRequires: pkgconfig(gio-2.0) BuildRequires: pkgconfig(glib-2.0) BuildRequires: pkgconfig(gio-unix-2.0) BuildRequires: pkgconfig(capi-system-info) -BuildRequires: pkgconfig(capi-system-peripheral-io) BuildRequires: pkgconfig(libsyscommon) BuildRequires: pkgconfig(libsystemd) BuildRequires: pkgconfig(capi-system-device) +BuildRequires: pkgconfig(hal-api-device) +BuildRequires: pkgconfig(hal-api-common) Requires(post): /usr/bin/vconftool @@ -42,30 +43,6 @@ Group: main %description feedbackd feedback daemon. -%package driver-emulator -Summary: Haptic driver targeting emulator plugin -Provides: %{name}-compat = %{version}-%{release} -Conflicts: %{name}-driver-gpio -Conflicts: %{name}-driver-standard -%description driver-emulator -Emulator device driver. Required by main feedbackd package. - -%package driver-gpio -Summary: Haptic driver targeting emulator plugin -Provides: %{name}-compat = %{version}-%{release} -Conflicts: %{name}-driver-emulator -Conflicts: %{name}-driver-standard -%description driver-gpio -Gpio haptic device driver. Required by main feedbackd package. - -%package driver-standard -Summary: Haptic driver targeting emulator plugin -Provides: %{name}-compat = %{version}-%{release} -Conflicts: %{name}-driver-emulator -Conflicts: %{name}-driver-gpio -%description driver-standard -Standard haptic device driver. Required by main feedbackd package. - %package conf-level3 Summary: Feedbackd level configuration file Provides: configuration-compat = %{version}-%{release} @@ -112,42 +89,12 @@ fi %postun systemctl daemon-reload -%post driver-emulator -mkdir -p %{_libdir}/feedbackd -mv %{_libdir}/haptic_emul.so %{_libdir}/feedbackd/haptic.so - -%post driver-gpio -mkdir -p %{_libdir}/feedbackd -mv %{_libdir}/haptic_gpio.so %{_libdir}/feedbackd/haptic.so - -%post driver-standard -mkdir -p %{_libdir}/feedbackd -mv %{_libdir}/haptic_standard.so %{_libdir}/feedbackd/haptic.so - %post conf-level3 mv %{_sysconfdir}/feedbackd/haptic-level3.conf %{_sysconfdir}/feedbackd/haptic.conf %post conf-level6 mv %{_sysconfdir}/feedbackd/haptic-level6.conf %{_sysconfdir}/feedbackd/haptic.conf -%preun driver-emulator -mv %{_libdir}/feedbackd/haptic.so %{_libdir}/haptic_emul.so -if [ "$1" == "0" ]; then - systemctl stop feedbackd.service -fi - -%preun driver-gpio -mv %{_libdir}/feedbackd/haptic.so %{_libdir}/haptic_gpio.so -if [ "$1" == "0" ]; then - systemctl stop feedbackd.service -fi - -%preun driver-standard -mv %{_libdir}/feedbackd/haptic.so %{_libdir}/haptic_standard.so -if [ "$1" == "0" ]; then - systemctl stop feedbackd.service -fi - %files -n feedbackd %manifest %{name}.manifest %license LICENSE.Apache-2.0 @@ -157,18 +104,6 @@ fi %{_datadir}/dbus-1/system-services/org.tizen.system.vibrator.service %{_bindir}/feedbackd -%files driver-emulator -%license LICENSE.Apache-2.0 -%{_libdir}/haptic_emul.so - -%files driver-gpio -%license LICENSE.Apache-2.0 -%{_libdir}/haptic_gpio.so - -%files driver-standard -%license LICENSE.Apache-2.0 -%{_libdir}/haptic_standard.so - %files conf-level3 %license LICENSE.Apache-2.0 %manifest %{name}.manifest diff --git a/src/driver/haptic.c b/src/core/haptic.c similarity index 95% rename from src/driver/haptic.c rename to src/core/haptic.c index 19c4145..3f955ea 100644 --- a/src/driver/haptic.c +++ b/src/core/haptic.c @@ -27,12 +27,12 @@ #include #include #include +#include #include "shared/log.h" #include "shared/common.h" #include "shared/device-idler.h" #include "haptic.h" -#include "haptic-dev.h" #define FEEDBACK_BASE_PATH "/usr/share/feedback/" #define STANDARD_FILE_PATH FEEDBACK_BASE_PATH"vibration/" @@ -514,7 +514,7 @@ static int haptic_module_load(void) pattern_config_parse(); - r = haptic_load_device(); + r = hal_device_haptic_get_backend(); if (r < 0) { _E("Failed to load device. ret=%d", r); return r; @@ -525,7 +525,7 @@ static int haptic_module_load(void) * if the last handle is closed during the playing of vibration, * solution makes unlimited vibration. * so we need at least one handle. */ - r = haptic_open_device(&g_handle); + r = hal_device_haptic_open_device(&g_handle); if (r < 0) { _E("Failed to open device. ret=%d", r); return r; @@ -562,14 +562,10 @@ GVariant *hdbus_get_count(GDBusConnection *conn, { int ret, val; - if ((ret = haptic_check_device()) < 0) - goto exit; - - ret = haptic_get_count_device(&val); + ret = hal_device_haptic_get_device_count(&val); if (ret >= 0) ret = val; -exit: return g_variant_new("(i)", ret); } @@ -588,8 +584,8 @@ void haptic_name_owner_changed(GDBusConnection *connection, for (n = info->handle_list; n; n = n->next) { handle = (int)(long)n->data; - haptic_stop_device(handle); - haptic_close_device(handle); + hal_device_haptic_stop_device(handle); + hal_device_haptic_close_device(handle); } remove_haptic_info(info); @@ -659,21 +655,21 @@ GVariant *hdbus_open_device(GDBusConnection *conn, struct haptic_info *info; /* Load haptic module before booting done */ - if (haptic_check_device() < 0) { - ret = haptic_module_load(); + if (hal_device_haptic_check_backend() < 0) { + ret = hal_device_haptic_get_backend(); if (ret < 0) goto exit; } g_variant_get(param, "(i)", &index); - ret = haptic_open_device(&handle); + ret = hal_device_haptic_open_device(&handle); if (ret < 0) goto exit; if (!sender) { ret = -EPERM; - haptic_close_device(handle); + hal_device_haptic_close_device(handle); goto exit; } @@ -683,7 +679,7 @@ GVariant *hdbus_open_device(GDBusConnection *conn, if (!info) { _E("Failed to create haptic information."); ret = -EPERM; - haptic_close_device(handle); + hal_device_haptic_close_device(handle); goto exit; } } @@ -719,9 +715,6 @@ GVariant *hdbus_close_device(GDBusConnection *conn, struct haptic_info *info; int cnt; - if ((ret = haptic_check_device()) < 0) - goto exit; - g_variant_get(param, "(u)", &handle); if (!sender) { @@ -730,7 +723,7 @@ GVariant *hdbus_close_device(GDBusConnection *conn, goto exit; } - ret = haptic_close_device(handle); + ret = hal_device_haptic_close_device(handle); if (ret < 0) goto exit; @@ -804,7 +797,7 @@ static void vibrate_monotone_idler_cb(void *data) vibrate_info->intensity); duration_timer = g_timeout_add(vibrate_info->duration, _cb, NULL); - haptic_vibrate_device(cur_h_data.handle, vibrate_info->duration, 0, 0, cur_h_data.level, vibrate_info->intensity, cur_h_data.priority); + hal_device_haptic_vibrate(cur_h_data.handle, vibrate_info->duration, 0, 0, cur_h_data.level, vibrate_info->intensity, cur_h_data.priority); free(vibrate_info); } @@ -817,7 +810,7 @@ GVariant *hdbus_vibrate_monotone(GDBusConnection *conn, unsigned int handle; int duration, level, intensity, priority, ret = 0; - if ((ret = haptic_check_device()) < 0) + if ((ret = hal_device_haptic_check_backend()) < 0) goto exit; if (haptic_disabled) @@ -913,7 +906,7 @@ static gboolean haptic_duration_play(void *data) duration_timer = g_timeout_add((node->duration + node->wait), haptic_duration_play, (void *)next); - ret = haptic_vibrate_device(cur_h_data.handle, node->duration, node->frequency, node->overdrive, cur_h_data.level, node->intensity, cur_h_data.priority); + ret = hal_device_haptic_vibrate(cur_h_data.handle, node->duration, node->frequency, node->overdrive, cur_h_data.level, node->intensity, cur_h_data.priority); break; } @@ -1001,7 +994,7 @@ GVariant *hdbus_vibrate_pattern(GDBusConnection *conn, char *pattern = NULL; int level, priority, ret = 0; - if ((ret = haptic_check_device()) < 0) + if ((ret = hal_device_haptic_check_backend()) < 0) goto exit; if (haptic_disabled) @@ -1051,7 +1044,7 @@ GVariant *hdbus_stop_device(GDBusConnection *conn, unsigned int handle; int ret = 0; - if ((ret = haptic_check_device()) < 0) + if ((ret = hal_device_haptic_check_backend()) < 0) goto exit; if (haptic_disabled) { @@ -1066,7 +1059,7 @@ GVariant *hdbus_stop_device(GDBusConnection *conn, goto exit; } - ret = haptic_stop_device(handle); + ret = hal_device_haptic_stop_device(handle); _I("Stop the device(handle=%u) :%d", handle, ret); /* Remove duration_timer for vibrate_effect */ @@ -1123,7 +1116,7 @@ GVariant *hdbus_pattern_is_supported(GDBusConnection *conn, char *data = NULL; int ret = 0; - if ((ret = haptic_check_device()) < 0) + if ((ret = hal_device_haptic_check_backend()) < 0) goto exit; if (haptic_disabled) @@ -1162,13 +1155,13 @@ static void haptic_poweroff_cb(GDBusConnection *conn, _D("Poweroff: %d", type); - if (haptic_check_device() < 0) { + if (hal_device_haptic_check_backend() < 0) { if (haptic_module_load() < 0) return ; } if (!g_handle) { - if (haptic_open_device(&g_handle) < 0) + if (hal_device_haptic_open_device(&g_handle) < 0) return ; } @@ -1182,7 +1175,7 @@ static void haptic_poweroff_cb(GDBusConnection *conn, _I("Handle=%d dur=%dms pri=%d level=%d intensity=%d frequency=0", g_handle, POWER_OFF_VIB_DURATION, PRIORITY_HIGH, level, POWER_VIB_FEEDBACK * 100); - ret = haptic_vibrate_device(g_handle, POWER_OFF_VIB_DURATION, 0, 0, + ret = hal_device_haptic_vibrate(g_handle, POWER_OFF_VIB_DURATION, 0, 0, level, POWER_VIB_FEEDBACK * 100, PRIORITY_HIGH); if (ret < 0) { _E("Failed to vibrate_monotone: %d", ret); @@ -1373,12 +1366,9 @@ void haptic_exit(void) /* release haptic data memory */ safe_free(haptic_conf.level_arr); - if (haptic_check_device() < 0) - return; - /* haptic exit for feedbackd */ - haptic_close_device(g_handle); - haptic_release_device(); + hal_device_haptic_close_device(g_handle); + hal_device_haptic_put_backend(); } static int haptic_start(void) diff --git a/src/driver/haptic.h b/src/core/haptic.h similarity index 100% rename from src/driver/haptic.h rename to src/core/haptic.h diff --git a/src/core/main.c b/src/core/main.c index 0fe52ca..a6760e9 100644 --- a/src/core/main.c +++ b/src/core/main.c @@ -28,7 +28,7 @@ #include "shared/log.h" #include "shared/common.h" -#include "driver/haptic.h" +#include "haptic.h" #define VIBRATION_FEATURE "http://tizen.org/feature/feedback.vibration" diff --git a/src/driver/emulator.c b/src/driver/emulator.c deleted file mode 100644 index bca8790..0000000 --- a/src/driver/emulator.c +++ /dev/null @@ -1,123 +0,0 @@ -/* - * feedbackd - * - * Copyright (c) 2012 - 2017 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 "shared/common.h" -#include "shared/log.h" -#include "haptic-dev.h" - -static GList *handle_list; -static int unique_number = 0; - -/* START: Haptic Module APIs */ -static int get_device_count(int *count) -{ - if (count) - *count = 1; - - return 0; -} - -static int open_device(int device_index, 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; -} -/* END: Haptic Module APIs */ - -static const struct haptic_plugin_ops default_plugin = { - .get_device_count = get_device_count, - .open_device = open_device, - .close_device = close_device, - .vibrate_monotone = vibrate_monotone, - .stop_device = stop_device, -}; - -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 const struct haptic_plugin_ops *load(void) -{ - return &default_plugin; -} - -static const struct haptic_ops emul_ops = { - .is_valid = is_valid, - .load = load, -}; - -EXPORT_GET_VAR_HAPTIC_OPS(&emul_ops) diff --git a/src/driver/external.c b/src/driver/external.c deleted file mode 100644 index 2c610d2..0000000 --- a/src/driver/external.c +++ /dev/null @@ -1,101 +0,0 @@ -/* - * feedbackd - * - * Copyright (c) 2012 - 2017 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 "shared/log.h" -#include "haptic.h" - -#define HAPTIC_MODULE_PATH "/usr/lib/libhaptic-module.so" - -/* Haptic Plugin Interface */ -static void *dlopen_handle; -static const struct haptic_plugin_ops *plugin_intf; - -static bool is_valid(void) -{ - struct stat buf; - int ret; - const struct haptic_plugin_ops *(*get_haptic_plugin_interface) () = NULL; - - ret = stat(HAPTIC_MODULE_PATH, &buf); - if (ret < 0) { - _E("Failed to stat file(%s): %d", HAPTIC_MODULE_PATH, errno); - goto error; - } - - dlopen_handle = dlopen(HAPTIC_MODULE_PATH, RTLD_NOW); - if (!dlopen_handle) { - _E("Failed to dlopen."); - goto error; - } - - get_haptic_plugin_interface = dlsym(dlopen_handle, "get_haptic_plugin_interface"); - if (!get_haptic_plugin_interface) { - _E("Failed to dlsym."); - goto error; - } - - plugin_intf = get_haptic_plugin_interface(); - if (!plugin_intf) { - _E("Failed to get_haptic_plugin_interface()."); - goto error; - } - - _I("Support external haptic device."); - return true; - -error: - if (dlopen_handle) { - dlclose(dlopen_handle); - dlopen_handle = NULL; - } - - _I("Do not support external haptic device."); - return false; -} - -static const struct haptic_plugin_ops *load(void) -{ - return plugin_intf; -} - -static void release(void) -{ - if (dlopen_handle) { - dlclose(dlopen_handle); - dlopen_handle = NULL; - } - - plugin_intf = NULL; -} - -static const struct haptic_ops ext_ops = { - .type = HAPTIC_EXTERNAL, - .is_valid = is_valid, - .load = load, - .release = release, -}; - -HAPTIC_OPS_REGISTER(&ext_ops) diff --git a/src/driver/gpio_haptic.c b/src/driver/gpio_haptic.c deleted file mode 100644 index fb175cd..0000000 --- a/src/driver/gpio_haptic.c +++ /dev/null @@ -1,339 +0,0 @@ -/* - * feedbackd - * - * Copyright (c) 2016 - 2017 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 "shared/common.h" -#include "shared/log.h" -#include "haptic-interface.h" -#include "peripheral_io.h" - -#define GPIO_I2C_BUS_INDEX 1 -#define MAX_HAPIC 1 -#define DRV2605L_DEFAULT_ADDR 0x5A - -#define START_CMD_CODE 1 -#define STOP_CMD_CODE 0 - -#define DRV2605L_REGISTER_STATUS 0x00 -#define DRV2605L_REGISTER_MODE 0x01 -#define DRV2605L_REGISTER_RTPINPUT 0x02 -#define DRV2605L_REGISTER_LIBRARY 0x03 -#define DRV2605L_REGISTER_WAVESEQ1 0x04 -#define DRV2605L_REGISTER_WAVESEQ2 0x05 -#define DRV2605L_REGISTER_WAVESEQ3 0x06 -#define DRV2605L_REGISTER_WAVESEQ4 0x07 -#define DRV2605L_REGISTER_WAVESEQ5 0x08 -#define DRV2605L_REGISTER_WAVESEQ6 0x09 -#define DRV2605L_REGISTER_WAVESEQ7 0x0A -#define DRV2605L_REGISTER_WAVESEQ8 0x0B -#define DRV2605L_REGISTER_GO 0x0C - -/** - * Mode register - */ -#define MODE_INTERNAL_TRIGGER 0 -#define MODE_EXTERNAL_TRIGGER_EDGE 1 -#define MODE_EXTERNAL_TRIGGER_LEVEL 2 -#define MODE_PWM_INPUT_ANALOG_INPUT 3 -#define MODE_AUDIO_TO_VIBE 4 -#define MODE_REALTIME_PLAYBACK 5 -#define MODE_DIAGNOSTICS 6 -#define MODE_AUTO_CALIBRATION 7 -/** - * Library register - */ -#define EMPTY_LIBRARY 0 -#define TS2200_LIBRARY_A 1 -#define TS2200_LIBRARY_B 2 -#define TS2200_LIBRARY_C 3 -#define TS2200_LIBRARY_D 4 -#define TS2200_LIBRARY_E 5 -#define LRA_LIBRARY_E 6 -#define TS2200_LIBRARY_F 7 - -#define MAX_LEVEL 2 -#define MAX_INTENSITY 10000 - -static peripheral_i2c_h device_handle = NULL; - -static GList *handle_list; -static int unique_number; - -static bool state = false; -//static bool is_playing = false; -static guint stop_timer = 0; - -static int gpio_haptic_stop_device(int handle); - -static bool find_from_list(int handle) -{ - GList *elem; - - elem = SYS_G_LIST_FIND(handle_list, (gpointer)(long)handle); - if (elem) - return true; - - return false; -} - -/* START: Haptic Module APIs */ -static gboolean gpio_haptic_timer_cb(void *data) -{ - int handle = (int)(long)data; - bool found; - - _I("Stop vibration by timer."); - - found = find_from_list(handle); - if (!found) - return G_SOURCE_REMOVE; - - if (device_handle == NULL) { - if (peripheral_i2c_open(GPIO_I2C_BUS_INDEX, DRV2605L_DEFAULT_ADDR, &device_handle) < PERIPHERAL_ERROR_NONE) { - _E("Failed to open I2C."); - return -EIO; - } - } - - /* stop playing */ - peripheral_i2c_write_register_byte(device_handle, DRV2605L_REGISTER_MODE, MODE_INTERNAL_TRIGGER); - - stop_timer = 0; - return G_SOURCE_REMOVE; -} - -static int gpio_haptic_get_device_count(int *count) -{ - _I("HAL: The max number of DRV2605L is %d.", (int)MAX_HAPIC); - if (count) - *count = MAX_HAPIC; - - return 0; -} - -/** - * Only one handle - * return device_handle - */ -static int gpio_haptic_open_device(int device_index, int *handle) -{ - int n; - bool found = false; - GList *elem; - - if (!handle) - return -EINVAL; - - /* if it is the first element */ - n = SYS_G_LIST_LENGTH(handle_list); - if (n == 0) { - _I("Peripheral Device Open."); - if (device_handle == NULL) { - if (peripheral_i2c_open(GPIO_I2C_BUS_INDEX, DRV2605L_DEFAULT_ADDR, &device_handle) < PERIPHERAL_ERROR_NONE) { - _E("Failed to open I2C."); - return -EIO; - } - } - } - - 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; - } - - /* add info to local list */ - SYS_G_LIST_APPEND(handle_list, (gpointer)(long)unique_number); - - *handle = unique_number; - return 0; -} - -static int gpio_haptic_close_device(int handle) -{ - int r, n; - bool found; - - found = find_from_list(handle); - if (!found) - return -EINVAL; - - if (device_handle == NULL) { - if (peripheral_i2c_open(GPIO_I2C_BUS_INDEX, DRV2605L_DEFAULT_ADDR, &device_handle) < PERIPHERAL_ERROR_NONE) { - _E("Failed to open I2C."); - return -EIO; - } - } - - /* stop vibration */ - r = gpio_haptic_stop_device(handle); - if (r < 0) - _I("Already stopped or failed to stop effect: %d", r); - - _D("Handle(%d) is closed and timer deleted.", handle); - SYS_G_LIST_REMOVE(handle_list, (gpointer)(long)handle); - - /* if it is the last element */ - n = SYS_G_LIST_LENGTH(handle_list); - if (n == 0) { - _I("Peripheral Device Close."); - if (device_handle != NULL) { - if (peripheral_i2c_close(device_handle) < PERIPHERAL_ERROR_NONE) { - _E("Failed to close peripheral I2C."); - return -EIO; - } - device_handle = NULL; - } - } - return 0; -} - -static int gpio_haptic_vibrate_monotone(int handle, int duration, int frequency, int overdrive, int level, int intensity, int priority) -{ - bool found; - int feedback; - int max_level; - - if (level <= 0) - return -EINVAL; - - found = find_from_list(handle); - if (!found) - return -EINVAL; - - if (device_handle == NULL) { - if (peripheral_i2c_open(GPIO_I2C_BUS_INDEX, DRV2605L_DEFAULT_ADDR, &device_handle) < PERIPHERAL_ERROR_NONE) { - _E("Failed to open I2C."); - return -EIO; - } - } - - /* Zero(0) is the infinitely vibration value */ - if (duration == HAPTIC_MODULE_DURATION_UNLIMITED) - duration = 0; - - if (stop_timer) - gpio_haptic_stop_device(handle); - - max_level = (level <= MAX_LEVEL)? MAX_LEVEL: level; - if (intensity) - feedback = ((level/max_level) * intensity) / 100; - else - feedback = ((level/max_level) * MAX_INTENSITY) / 100; - - /* play vibration */ - peripheral_i2c_write_register_byte(device_handle, DRV2605L_REGISTER_LIBRARY, TS2200_LIBRARY_A); - /* continuously vibrate*/ - peripheral_i2c_write_register_byte(device_handle, DRV2605L_REGISTER_MODE, MODE_REALTIME_PLAYBACK); - peripheral_i2c_write_register_byte(device_handle, DRV2605L_REGISTER_RTPINPUT, (uint8_t)feedback); - - /* register timer */ - if (duration) { - //stop_timer = ecore_timer_add(duration/1000.f, gpio_haptic_timer_cb, (void *)(long)handle); - stop_timer = g_timeout_add(duration, gpio_haptic_timer_cb, (void *)(long)handle); - if (!stop_timer) - _E("Failed to add timer callback."); - } - _D("Device handle(%d) %dms", handle, duration); - - return 0; -} - -static int gpio_haptic_stop_device(int handle) -{ - bool found; - - found = find_from_list(handle); - if (!found) - return -EINVAL; - - if (device_handle == NULL) { - if (peripheral_i2c_open(GPIO_I2C_BUS_INDEX, DRV2605L_DEFAULT_ADDR, &device_handle) < PERIPHERAL_ERROR_NONE) { - _E("Failed to open I2C."); - return -EIO; - } - } - - /* stop playing */ - peripheral_i2c_write_register_byte(device_handle, DRV2605L_REGISTER_MODE, MODE_INTERNAL_TRIGGER); - - if (stop_timer) { - //ecore_timer_del(stop_timer); - g_source_remove(stop_timer); - stop_timer = 0; - } - - return 0; -} -/* END: Haptic Module APIs */ - -static const struct haptic_plugin_ops default_plugin = { - .get_device_count = gpio_haptic_get_device_count, - .open_device = gpio_haptic_open_device, - .close_device = gpio_haptic_close_device, - .vibrate_monotone = gpio_haptic_vibrate_monotone, - .stop_device = gpio_haptic_stop_device, -}; - -static bool is_valid(void) -{ - uint8_t result; - peripheral_i2c_h handle; - - if (peripheral_i2c_open(GPIO_I2C_BUS_INDEX, DRV2605L_DEFAULT_ADDR, &handle) < PERIPHERAL_ERROR_NONE) { - _E("Failed to open I2C."); - state = false; - return false; - } - if (peripheral_i2c_read_register_byte(handle, DRV2605L_REGISTER_STATUS, &result) < PERIPHERAL_ERROR_NONE) { - _E("Failed to read peripheral I2C."); - if (peripheral_i2c_close(handle) < PERIPHERAL_ERROR_NONE) - _E("Failed to close peripheral I2C."); - state = false; - return false; - } - if (peripheral_i2c_close(handle) < PERIPHERAL_ERROR_NONE) { - _E("Failed to close peripheral I2C."); - state = false; - return false; - } - - state = true; - _I("Support gpio haptic device."); - return true; -} - -static const struct haptic_plugin_ops *load(void) -{ - _I("Gpio haptic device module loaded."); - return &default_plugin; -} - -static const struct haptic_ops gpio_haptic_ops = { - .is_valid = is_valid, - .load = load, -}; - -EXPORT_GET_VAR_HAPTIC_OPS(&gpio_haptic_ops) diff --git a/src/driver/haptic-dev.c b/src/driver/haptic-dev.c deleted file mode 100644 index 05c4d84..0000000 --- a/src/driver/haptic-dev.c +++ /dev/null @@ -1,166 +0,0 @@ -/* - * feedbackd - * - * Copyright (c) 2020 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 - * - * Unlessnn 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 "shared/log.h" -#include "haptic.h" -#include "haptic-dev.h" - -#ifndef LIBPATH -#error LIBPATH is not defined. -#endif -#define HAPTIC_MODULE_PATH LIBPATH"/feedbackd/haptic.so" - -#define CHECK_NO_DEVICE(dev) \ - do { \ - if (!dev) \ - return -ENODEV; \ - }while(0) \ - -/* Haptic Plugin Interface */ -static void *haptic_handle; -static const struct haptic_plugin_ops *plugin_ops; -static const struct haptic_ops *haptic_ops; -static const struct haptic_ops* (*fp_get_var_haptic_ops)(void); - -int haptic_load_device(void) -{ - struct stat buf; - int ret; - - ret = stat(HAPTIC_MODULE_PATH, &buf); - if (ret < 0) { - _E("Failed to stat file(%s): %d", HAPTIC_MODULE_PATH, errno); - goto error; - } - - haptic_handle = dlopen(HAPTIC_MODULE_PATH, RTLD_NOW); - if (!haptic_handle) { - _E("Failed to open file(%s): %s.", HAPTIC_MODULE_PATH, dlerror()); - goto error; - } - - fp_get_var_haptic_ops = dlsym(haptic_handle, "get_var_haptic_ops"); - if (!fp_get_var_haptic_ops) { - _E("Failed to get \'get_var_haptic_ops\' function."); - goto error; - } - - haptic_ops = fp_get_var_haptic_ops(); - if (!haptic_ops) { - _E("Failed to call get_var_haptic_ops"); - goto error; - } - - if (haptic_ops->is_valid && haptic_ops->is_valid()) { - if (haptic_ops->load) - plugin_ops = haptic_ops->load(); - } - - if (!plugin_ops) { - _E("Failed to load haptic device."); - goto error; - } - - return 0; - -error: - if (haptic_handle) { - dlclose(haptic_handle); - haptic_handle = NULL; - haptic_ops = NULL; - } - - return -ENODEV; -} - -void haptic_release_device() -{ - if (haptic_ops) { - if (haptic_ops->is_valid && haptic_ops->is_valid()) { - if (haptic_ops->release) - haptic_ops->release(); - } - } - - if (haptic_handle) - dlclose(haptic_handle); - - haptic_handle = NULL; - haptic_ops = NULL; - plugin_ops = NULL; -} - -int haptic_open_device(int *dev_handle) -{ - CHECK_NO_DEVICE(plugin_ops); - - if (!dev_handle) - return -EINVAL; - - return plugin_ops->open_device(HAPTIC_MODULE_DEVICE_ALL, dev_handle); -} - -int haptic_close_device(int dev_handle) -{ - CHECK_NO_DEVICE(plugin_ops); - - return plugin_ops->close_device(dev_handle); -} - -int haptic_check_device() -{ - CHECK_NO_DEVICE(plugin_ops); - - return 0; -} - -int haptic_vibrate_device(int device_handle, int duration, int frequency, - int overdrive, int level, int intensity, int priority) -{ - CHECK_NO_DEVICE(plugin_ops); - - return plugin_ops->vibrate_monotone(device_handle, duration, frequency, overdrive, - level, intensity, priority); - -} - -int haptic_get_count_device(int *count) -{ - CHECK_NO_DEVICE(plugin_ops); - - if (!count) - return -EINVAL; - - return plugin_ops->get_device_count(count); -} - -int haptic_stop_device(int handle) -{ - CHECK_NO_DEVICE(plugin_ops); - - return plugin_ops->stop_device(handle); -} - diff --git a/src/driver/haptic-dev.h b/src/driver/haptic-dev.h deleted file mode 100644 index 208a5a1..0000000 --- a/src/driver/haptic-dev.h +++ /dev/null @@ -1,37 +0,0 @@ -/* - * feedbackd - * -i * Copyright (c) 2012 - 2020 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. - */ - - -#ifndef __FEEDBACKD_HAPTIC_DEV_H__ -#define __FEEDBACKD_HAPTIC_DEV_H__ - -#include -#include "haptic-interface.h" - -int haptic_load_device(void); -void haptic_release_device(); -int haptic_open_device(int *dev_handle); -int haptic_check_device(); -int haptic_close_device(int dev_handle); - -int haptic_vibrate_device(int device_handle, int duration, int frequency, int overdrive, int level, int intensity, int priority); - -int haptic_get_count_device(int *count); -int haptic_stop_device(int handle); - -#endif /* __FEEDBACKD_HAPTIC_DEV_H__ */ diff --git a/src/driver/haptic-interface.h b/src/driver/haptic-interface.h deleted file mode 100644 index de1d6c4..0000000 --- a/src/driver/haptic-interface.h +++ /dev/null @@ -1,69 +0,0 @@ -/* - * deviced - * - * Copyright (c) 2012 - 2017 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. - */ - - -#ifndef __FEEDBACKD_HAPTIC_INTERFACE_H__ -#define __FEEDBACKD_HAPTIC_INTERFACE_H__ - -#include - -enum haptic_type { - HAPTIC_STANDARD, - HAPTIC_EXTERNAL, -}; - -/** - * @brief Enumerations of device id for the Haptic Module API. - * @details We support two motors now. - */ -typedef enum { - HAPTIC_MODULE_DEVICE_0 = 0x0, /**< 1st motor */ - HAPTIC_MODULE_DEVICE_1 = 0x1, /**< 2nd motor */ - HAPTIC_MODULE_DEVICE_ALL = 0x4, /**< both of them */ -} haptic_module_device; - -/** - * @brief Enumerations of unlimited duration for the Haptic Module API. - */ -typedef enum { - HAPTIC_MODULE_DURATION_UNLIMITED = 0x7FFFFFFF, -} haptic_module_duration; - -struct haptic_ops { - enum haptic_type type; - bool (*is_valid)(void); - const struct haptic_plugin_ops *(*load)(void); - void (*release)(void); -}; - -struct haptic_plugin_ops { - int (*get_device_count) (int*); - int (*open_device) (int, int*); - int (*close_device) (int); - int (*vibrate_monotone) (int, int, int, int, int, int, int); - int (*stop_device) (int); -}; - -#define EXPORT_GET_VAR_HAPTIC_OPS(ops) \ -const struct haptic_ops __attribute__((visibility("default")))* get_var_haptic_ops(void) \ -{ \ - return ops; \ -} \ - -const struct haptic_ops *get_var_haptic_ops(); -#endif /* __FEEDBACKD_HAPTIC_INTERFACE_H__ */ diff --git a/src/driver/standard.c b/src/driver/standard.c deleted file mode 100644 index 310bd3e..0000000 --- a/src/driver/standard.c +++ /dev/null @@ -1,559 +0,0 @@ -/* - * feedbackd - * - * Copyright (c) 2012 - 2017 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 -#include -#include -#include - -#include "shared/common.h" -#include "shared/log.h" -#include "haptic-interface.h" - -#define MAX_MAGNITUDE 0xFFFF -#define PERIODIC_MAX_MAGNITUDE 0x7FFF /* 0.5 * MAX_MAGNITUDE */ -#define RUMBLE_MAX_MAGNITUDE 0xFFFF - -#define DEV_INPUT "/dev/input" -#define EVENT "event" - -#define MAX_DATA 16 -#define FF_INFO_MAGIC 0xDEADFEED - -#define SET_OVERDRIVE_BIT(x,value) (x |= ((value > 0)? 1: 0)<<14) -#define SET_LEVEL_BIT(x,value) (x |= (value<<13)) - -struct ff_info_header { - unsigned int magic; - int iteration; - int ff_info_data_count; -}; - -struct ff_info_data { - int type;/* play, stop etc */ - int magnitude; /* strength */ - int length; /* in ms for stop, play*/ -}; - -struct ff_info_buffer { - struct ff_info_header header; - struct ff_info_data data[MAX_DATA]; -}; - -struct ff_info { - int handle; - guint timer; - struct ff_effect effect; - struct ff_info_buffer *ffinfobuffer; - int currentindex; -}; - -static int ff_fd; -static GList *ff_list; -static GList *handle_list; -static char ff_path[PATH_MAX]; -static int unique_number; -static int current_effect_id = -1; - -static int stop_device(int device_handle); - -struct ff_info *read_from_list(int handle) -{ - struct ff_info *temp; - GList *elem; - - SYS_G_LIST_FOREACH(ff_list, elem, temp) { - if (temp->handle == handle) - return temp; - } - return NULL; -} - -static bool check_valid_handle(struct ff_info *info) -{ - struct ff_info *temp; - GList *elem; - - SYS_G_LIST_FOREACH(ff_list, elem, temp) { - if (temp == info) - break; - } - - if (!temp) - return false; - return true; -} - -static bool check_fd(int *fd) -{ - int ffd; - - if (*fd > 0) - return true; - - ffd = open(ff_path, O_RDWR); - if (ffd < 0) - return false; - - *fd = ffd; - return true; -} - -static int ff_stop(int fd, struct ff_effect *effect); -static gboolean timer_cb(void *data) -{ - struct ff_info *info = (struct ff_info *)data; - - if (!info) { - _E("Failed to check info."); - return G_SOURCE_REMOVE; - } - - if (!check_valid_handle(info)) { - _E("Failed to check valied info."); - return G_SOURCE_REMOVE; - } - - _I("Stop vibration by timer. id(%d)", info->effect.id); - - /* stop previous vibration */ - ff_stop(ff_fd, &info->effect); - - /* reset timer */ - info->timer = 0; - - return G_SOURCE_REMOVE; -} - -static int ff_find_device(void) -{ - DIR *dir; - struct dirent *dent; - char ev_path[PATH_MAX]; - unsigned long features[1+FF_MAX/sizeof(unsigned long)]; - int fd, ret; - - dir = opendir(DEV_INPUT); - if (!dir) - return -errno; - - while (1) { - dent = readdir(dir); - if (dent == NULL) - break; - - if (dent->d_type == DT_DIR || - !strstr(dent->d_name, "event")) - continue; - - snprintf(ev_path, sizeof(ev_path), "%s/%s", DEV_INPUT, dent->d_name); - - fd = open(ev_path, O_RDWR); - if (fd < 0) { - _E("Failed to open '%s'.: %d", ev_path, errno); - continue; - } - - /* get force feedback device */ - memset(features, 0, sizeof(features)); - ret = ioctl(fd, EVIOCGBIT(EV_FF, sizeof(features)), features); - if (ret == -1) { - close(fd); - continue; - } - - if (test_bit(FF_CONSTANT, features)) - _D("'%s' type: constant", ev_path); - if (test_bit(FF_PERIODIC, features)) - _D("'%s' type: periodic", ev_path); - if (test_bit(FF_SPRING, features)) - _D("'%s' type: spring", ev_path); - if (test_bit(FF_FRICTION, features)) - _D("'%s' type: friction", ev_path); - if (test_bit(FF_RUMBLE, features)) - _D("'%s' type: rumble", ev_path); - - if (test_bit(FF_RUMBLE, features)) { - memcpy(ff_path, ev_path, strlen(ev_path)+1); - close(fd); - closedir(dir); - return 0; - } - - close(fd); - } - - closedir(dir); - return -1; -} - -static int ff_init_effect(struct ff_effect *effect) -{ - if (!effect) - return -EINVAL; - - effect->type = FF_RUMBLE; - effect->replay.length = 0; - effect->replay.delay = 0; - effect->id = -1; - effect->u.rumble.strong_magnitude = 0; - effect->u.rumble.weak_magnitude = 0; - - return 0; -} - -static int ff_set_effect(struct ff_effect *effect, int duration, int level, int intensity, int frequency, int overdrive) -{ - if (!effect) { - _E("There is no valid effect."); - return -EINVAL; - } - - /* - __u16 strong_magnitude; // strong_magnitude[15:15] = 0 (Reserved) - // strong_magnitude[14:14] = Overdrive : 0 (Off) or 1 (On) - // strong_magnitude[13:0] = Intensity Value : 0 (Stop) or 1 ~ 10000 (Intensity) - __u16 weak_magnitude; // weak_magnitude[15:13] = Intensity Level : 1 ~ 5 - // weak_magnitude[12:0] = Frequency : 0 ~ 8191 (0 ~ 819.1 Hz) - */ - - effect->u.rumble.strong_magnitude = intensity; - SET_OVERDRIVE_BIT(effect->u.rumble.strong_magnitude, overdrive); - - effect->u.rumble.weak_magnitude = frequency; - SET_LEVEL_BIT(effect->u.rumble.weak_magnitude, level); - - /* set member variables in effect struct */ - effect->replay.length = duration; /* length millisecond */ - - //_D("rumble data: strong_magnitude = 0x%x, weak_magnitude = 0x%x", effect->u.rumble.strong_magnitude, effect->u.rumble.weak_magnitude); - return 0; -} - -static int ff_play(int fd, struct ff_effect *effect) -{ - struct input_event play; - int ret; - - if (fd < 0 || !effect) { - _E("Fd(%d) or effect(%s) is invalid", fd, effect ? "not null" : "null"); - return -EINVAL; - } - - /* upload an effect */ - if (current_effect_id == -1) { - if (ioctl(fd, EVIOCSFF, effect) == -1) { - _E("Failed to ioctl"); - return -errno; - } - current_effect_id = effect->id; - } else - effect->id = current_effect_id; - - /* play vibration*/ - play.type = EV_FF; - play.code = effect->id; - play.value = 1; /* 1 : PLAY, 0 : STOP */ - - ret = write(fd, (const void *)&play, sizeof(play)); - if (ret == -1) { - _E("Failed to write"); - return -errno; - } - - return 0; -} - -static int ff_stop(int fd, struct ff_effect *effect) -{ - struct input_event stop; - int ret; - - if (fd < 0 || !effect) - return -EINVAL; - - if (effect->id == -1) { - if (current_effect_id == -1) - return 0; - effect->id = current_effect_id; - } - - /* Stop vibration */ - stop.type = EV_FF; - stop.code = effect->id; - stop.value = 0; /* 1 : PLAY, 0 : STOP */ - ret = write(fd, (const void *)&stop, sizeof(stop)); - if (ret == -1) - return -errno; - - /* removing an effect from the device */ - if (ioctl(fd, EVIOCRMFF, effect->id) == -1) - return -errno; - - /* reset effect id */ - effect->id = -1; - current_effect_id = -1; - - return 0; -} - -/* START: Haptic Module APIs */ -static int get_device_count(int *count) -{ - /* suppose there is just one haptic device */ - if (count) - *count = 1; - - return 0; -} - -static int open_device(int device_index, int *device_handle) -{ - struct ff_info *info; - int n; - bool found = false; - GList *elem; - - if (!device_handle) - return -EINVAL; - - /* if it is the first element */ - n = SYS_G_LIST_LENGTH(ff_list); - if (n == 0 && !ff_fd) { - _I("First element: open ff driver"); - /* open ff driver */ - ff_fd = open(ff_path, O_RDWR); - if (ff_fd < 0) { - _E("Failed to open %s : %d", ff_path, errno); - return -errno; - } - } - - /* allocate memory */ - info = calloc(sizeof(struct ff_info), 1); - if (!info) { - _E("Failed to allocate memory : %d", errno); - return -errno; - } - - /* initialize ff_effect structure */ - ff_init_effect(&info->effect); - - 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; - } - - info->handle = unique_number; - - /* add info to local list */ - SYS_G_LIST_APPEND(ff_list, info); - SYS_G_LIST_APPEND(handle_list, (gpointer)(long)info->handle); - - *device_handle = info->handle; - return 0; -} - -static int close_device(int device_handle) -{ - struct ff_info *info; - int n; - - info = read_from_list(device_handle); - if (!info) { - _E("Handle %d failed to check info", device_handle); - return -ENOENT; /* 2 */ - } - - if (!check_valid_handle(info)) { - _E("Handle %d failed to check valid handle", device_handle); - return -EINVAL; /* 22 */ - } - - if (!check_fd(&ff_fd)) { - _E("Handle %d failed to check fd", device_handle); - return -ENODEV; /* 19 */ - } - - /* stop vibration */ - stop_device(device_handle); - - SYS_G_LIST_REMOVE(handle_list, (gpointer)(long)info->handle); - - safe_free(info->ffinfobuffer); - /* remove info from local list */ - SYS_G_LIST_REMOVE(ff_list, info); - safe_free(info); - - /* if it is the last element */ - n = SYS_G_LIST_LENGTH(ff_list); - if (n == 0 && ff_fd) { - _I("Last element: close ff driver"); - /* close ff driver */ - close(ff_fd); - ff_fd = 0; - } - - return 0; -} - -static int vibrate_monotone(int device_handle, int duration, int frequency, int overdrive, int level, int intensity, int priority) -{ - struct ff_info *info; - int ret; - - info = read_from_list(device_handle); - if (!info) { - _E("Handle %d failed to check list.", device_handle); - return -EINVAL; - } - - if (!check_valid_handle(info)) { - _E("Handle %d failed to check handle.", device_handle); - return -EINVAL; - } - - if (!check_fd(&ff_fd)) - return -ENODEV; - - if (duration <= 0) { - _I("Handle %d skip requests with duration 0.", device_handle); - return 0; - } - - /* Zero(0) is the infinitely vibration value */ - if (duration == HAPTIC_MODULE_DURATION_UNLIMITED) - duration = 0; - - /* unregister existing timer */ - if (info->timer) { - ff_stop(ff_fd, &info->effect); - g_source_remove(info->timer); - info->timer = 0; - } - - /* set effect as per arguments */ - ff_init_effect(&info->effect); - ret = ff_set_effect(&info->effect, duration, level, intensity, frequency, overdrive); - if (ret < 0) { - _E("Handle %d fail to set effect(duration:%d, level:%d, intensity:%d, frequency:%d, overdrive:%d) : %d", - device_handle, duration, level, intensity, frequency, overdrive, ret); - return ret; - } - - /* play effect as per arguments */ - ret = ff_play(ff_fd, &info->effect); - if (ret < 0) { - _E("Handle %d fail to play haptic effect(fd:%d id:%d) : %d", - device_handle, ff_fd, info->effect.id, ret); - return ret; - } - - _I("Play vibration. Handle %d effect id : %d %dms", device_handle, info->effect.id, duration); - - /* register timer */ - if (duration) { - info->timer = g_timeout_add(duration, timer_cb, info); - if (!info->timer) - _E("Handle %d failed to add timer callback", device_handle); - } - - return 0; -} - -static int stop_device(int device_handle) -{ - struct ff_info *info; - int r; - - info = read_from_list(device_handle); - if (!info) { - _E("Handle %d fail to check info", device_handle); - return -ENOENT; /* 2 */ - } - - if (!check_fd(&ff_fd)) { - _E("Handle %d fail to check fd", device_handle); - return -ENODEV; /* 19 */ - } - - /* stop effect */ - r = ff_stop(ff_fd, &info->effect); - if (r < 0) - _E("failed to stop effect(id:%d) : %d", info->effect.id, r); - else - _I("Stop vibration by request. id(%d)", info->effect.id); - - /* unregister existing timer */ - if (r >= 0 && info->timer) { - g_source_remove(info->timer); - info->timer = 0; - } - - return 0; -} -/* END: Haptic Module APIs */ - -static const struct haptic_plugin_ops default_plugin = { - .get_device_count = get_device_count, - .open_device = open_device, - .close_device = close_device, - .vibrate_monotone = vibrate_monotone, - .stop_device = stop_device, -}; - -static bool is_valid(void) -{ - int ret; - - ret = ff_find_device(); - if (ret < 0) { - _E("Do not support standard haptic device"); - return false; - } - - _I("Support standard haptic device"); - return true; -} - -static const struct haptic_plugin_ops *load(void) -{ - return &default_plugin; -} - -static const struct haptic_ops std_ops = { - .type = HAPTIC_STANDARD, - .is_valid = is_valid, - .load = load, -}; - -EXPORT_GET_VAR_HAPTIC_OPS(&std_ops) -- 2.7.4 From 53fb1df01cd0ab795279973f204d31d2db8efc48 Mon Sep 17 00:00:00 2001 From: Yunmi Ha Date: Wed, 27 Jan 2021 10:59:30 +0900 Subject: [PATCH 11/16] remove checking driver compatibility Change-Id: I734fdfc2461e7c2780c3fd4295fdd2c4230e4490 Signed-off-by: Yunmi Ha --- packaging/feedbackd.spec | 2 -- 1 file changed, 2 deletions(-) diff --git a/packaging/feedbackd.spec b/packaging/feedbackd.spec index 7272b69..3bbc1db 100644 --- a/packaging/feedbackd.spec +++ b/packaging/feedbackd.spec @@ -28,8 +28,6 @@ BuildRequires: pkgconfig(hal-api-common) Requires(post): /usr/bin/vconftool -Requires: %{name}-compat = %{version}-%{release} - Requires: configuration-compat = %{version}-%{release} Recommends: %{name}-conf-level6 = %{version}-%{release} -- 2.7.4 From 17b70df13e40c82228d58c90827ce592b94214e6 Mon Sep 17 00:00:00 2001 From: "taemin.yeom" Date: Tue, 9 Mar 2021 15:40:00 +0900 Subject: [PATCH 12/16] Apply libsyscommon gdbus api improvement on error handling Change-Id: I8a433adcea86b30b3cb044e61bf60b7f7495a907 Signed-off-by: taemin.yeom --- src/auto-test/haptic.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/auto-test/haptic.c b/src/auto-test/haptic.c index 0f64299..866ce6e 100644 --- a/src/auto-test/haptic.c +++ b/src/auto-test/haptic.c @@ -30,15 +30,15 @@ static bool request_haptic_method(const char *method, GVariant *param, int *return_val) { GVariant *msg; - int val; + int val, err; bool ret = FALSE; - msg = dbus_handle_method_sync_with_reply_var(VIBRATOR_BUS_NAME, + err = dbus_handle_method_sync_with_reply_var(VIBRATOR_BUS_NAME, VIBRATOR_PATH_HAPTIC, VIBRATOR_INTERFACE_HAPTIC, - method, param); + method, param, &msg); - if (!msg) { + if (err < 0) { _E("Failed to call %s: no reply", method); return ret; } -- 2.7.4 From 3b1a1a97c5fdef371cdeb8fa395b823af061edbe Mon Sep 17 00:00:00 2001 From: "taemin.yeom" Date: Fri, 12 Mar 2021 10:36:14 +0900 Subject: [PATCH 13/16] Improve variable naming style Change-Id: I7e8166f40624a53ff4add751b9a2d06800b5f285 Signed-off-by: taemin.yeom --- src/auto-test/haptic.c | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/src/auto-test/haptic.c b/src/auto-test/haptic.c index 866ce6e..944f622 100644 --- a/src/auto-test/haptic.c +++ b/src/auto-test/haptic.c @@ -27,42 +27,42 @@ #define METHOD_HAPTIC_SHOWHANDLELIST "ShowHandleList" #define METHOD_HAPTIC_ISSUPPORTED "IsSupported" -static bool request_haptic_method(const char *method, GVariant *param, int *return_val) +static bool request_haptic_method(const char *method, GVariant *param, int *out_val) { - GVariant *msg; - int val, err; + GVariant *reply; + int reply_val, ret_dbus; bool ret = FALSE; - err = dbus_handle_method_sync_with_reply_var(VIBRATOR_BUS_NAME, + ret_dbus = dbus_handle_method_sync_with_reply_var(VIBRATOR_BUS_NAME, VIBRATOR_PATH_HAPTIC, VIBRATOR_INTERFACE_HAPTIC, - method, param, &msg); + method, param, &reply); - if (err < 0) { + if (ret_dbus < 0) { _E("Failed to call %s: no reply", method); return ret; } - if (!g_variant_get_safe(msg, "(i)", &val)) + if (!g_variant_get_safe(reply, "(i)", &reply_val)) _E("Failed to call %s: no message", method); else { - if ((val == -ENOTSUP) || (val == -ENOSYS)) { - _I("Not supported feature(%s): %d", method, val); + if ((reply_val == -ENOTSUP) || (reply_val == -ENOSYS)) { + _I("Not supported feature(%s): %d", method, reply_val); ret = TRUE; - } else if (val == -ENODEV) { - _E("Failed to call %s. Device open fail: %d", method, val); - } else if (val < 0) { - _E("Failed to call %s. Returned fail: %d", method, val); + } else if (reply_val == -ENODEV) { + _E("Failed to call %s. Device open fail: %d", method, reply_val); + } else if (reply_val < 0) { + _E("Failed to call %s. Returned fail: %d", method, reply_val); } else { - _I("Success. %s: %d", method, val); + _I("Success. %s: %d", method, reply_val); ret = TRUE; } } - g_variant_unref(msg); + g_variant_unref(reply); - if (return_val) - *return_val = val; + if (out_val) + *out_val = reply_val; return ret; } -- 2.7.4 From eaaaf8bc1cf76109540fe5f0a489280198971c95 Mon Sep 17 00:00:00 2001 From: "taemin.yeom" Date: Fri, 19 Mar 2021 16:37:47 +0900 Subject: [PATCH 14/16] Change dbus function name Change-Id: Icc25271e356bd4284b6162a4514740b17a54cefd Signed-off-by: taemin.yeom --- src/auto-test/haptic.c | 2 +- src/auto-test/test.h | 2 +- src/core/haptic.c | 14 +++++++------- src/core/main.c | 8 ++++---- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/auto-test/haptic.c b/src/auto-test/haptic.c index 944f622..101f8da 100644 --- a/src/auto-test/haptic.c +++ b/src/auto-test/haptic.c @@ -33,7 +33,7 @@ static bool request_haptic_method(const char *method, GVariant *param, int *out_ int reply_val, ret_dbus; bool ret = FALSE; - ret_dbus = dbus_handle_method_sync_with_reply_var(VIBRATOR_BUS_NAME, + ret_dbus = gdbus_call_sync_with_reply(VIBRATOR_BUS_NAME, VIBRATOR_PATH_HAPTIC, VIBRATOR_INTERFACE_HAPTIC, method, param, &reply); diff --git a/src/auto-test/test.h b/src/auto-test/test.h index e0b93ec..2bd0130 100644 --- a/src/auto-test/test.h +++ b/src/auto-test/test.h @@ -21,7 +21,7 @@ #define FEEDBACKD__TEST_H__ #include #include -#include +#include #include "shared/log.h" #include "shared/common.h" diff --git a/src/core/haptic.c b/src/core/haptic.c index 3f955ea..e644f1c 100644 --- a/src/core/haptic.c +++ b/src/core/haptic.c @@ -24,7 +24,7 @@ #include #include #include -#include +#include #include #include #include @@ -609,7 +609,7 @@ static struct haptic_info *add_haptic_info(const char *sender) SYS_G_LIST_APPEND(haptic_handle_list, info); - info->id_watch = dbus_handle_watch_name(sender, NULL, haptic_name_owner_changed, info, NULL); + info->id_watch = gdbus_watch_name(sender, NULL, haptic_name_owner_changed, info, NULL); return info; } @@ -618,7 +618,7 @@ static int remove_haptic_info(struct haptic_info *info) { assert(info); - dbus_handle_unwatch_name(info->id_watch); + gdbus_unwatch_name(info->id_watch); SYS_G_LIST_REMOVE(haptic_handle_list, info); SYS_G_LIST_FREE_LIST(info->handle_list); @@ -1315,11 +1315,11 @@ void haptic_init(void) } /* init dbus interface */ - r = dbus_handle_register_dbus_object(NULL, VIBRATOR_PATH_HAPTIC, &dbus_interface); + r = gdbus_register_object(NULL, VIBRATOR_PATH_HAPTIC, &dbus_interface); if (r < 0) _E("Failed to init hdbus interface and method: %d", r); - id_sig_pwr_off_state = subscribe_dbus_signal(NULL, + id_sig_pwr_off_state = gdbus_signal_subscribe(NULL, DEVICED_PATH_POWEROFF, DEVICED_INTERFACE_POWEROFF, SIGNAL_POWEROFF_STATE, @@ -1331,7 +1331,7 @@ void haptic_init(void) return; } - dbus_handle_emit_dbus_signal(NULL, + gdbus_signal_emit(NULL, VIBRATOR_PATH_HAPTIC, VIBRATOR_INTERFACE_HAPTIC, SIGNAL_VIBRATOR_INITIATED, @@ -1361,7 +1361,7 @@ void haptic_exit(void) } /* unregister notifier for below each event */ - unsubscribe_dbus_signal(NULL, id_sig_pwr_off_state); + gdbus_signal_unsubscribe(NULL, id_sig_pwr_off_state); /* release haptic data memory */ safe_free(haptic_conf.level_arr); diff --git a/src/core/main.c b/src/core/main.c index a6760e9..c3efc39 100644 --- a/src/core/main.c +++ b/src/core/main.c @@ -24,7 +24,7 @@ #include #include -#include +#include #include "shared/log.h" #include "shared/common.h" @@ -70,7 +70,7 @@ int main(int argc, char **argv) mainloop = g_main_loop_new(NULL, FALSE); - handle = dbus_handle_get_connection(G_BUS_TYPE_SYSTEM, FALSE); + handle = gdbus_get_connection(G_BUS_TYPE_SYSTEM, FALSE); if (!handle) _E("Failed to get dbus connection.");; @@ -82,10 +82,10 @@ int main(int argc, char **argv) } haptic_init(); - ret = dbus_handle_request_bus_name(handle, VIBRATOR_BUS_NAME, dbus_name_acquired, NULL); + ret = gdbus_request_name(handle, VIBRATOR_BUS_NAME, dbus_name_acquired, NULL); if (ret <= 0) { _E("Failed to request bus name."); - dbus_handle_check_owner_name(NULL, VIBRATOR_BUS_NAME); + gdbus_check_name_owner(NULL, VIBRATOR_BUS_NAME); } signal(SIGTERM, sig_quit); -- 2.7.4 From 732f2de08d9ae84545157b25bac5a875437980c4 Mon Sep 17 00:00:00 2001 From: Hyotaek Shim Date: Mon, 3 Jan 2022 13:14:42 +0900 Subject: [PATCH 15/16] Fix Coverity in request_haptic_method() Declaring variable reply_val without initializer. Change-Id: I6ed79e09bc9e84333583afdace2576ae7bf2d44c Signed-off-by: Hyotaek Shim --- src/auto-test/haptic.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/auto-test/haptic.c b/src/auto-test/haptic.c index 101f8da..49cd1ef 100644 --- a/src/auto-test/haptic.c +++ b/src/auto-test/haptic.c @@ -30,7 +30,7 @@ static bool request_haptic_method(const char *method, GVariant *param, int *out_val) { GVariant *reply; - int reply_val, ret_dbus; + int reply_val = 0, ret_dbus; bool ret = FALSE; ret_dbus = gdbus_call_sync_with_reply(VIBRATOR_BUS_NAME, -- 2.7.4 From 2e2e22fad41efb3d6212005319fa450d6de22b59 Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Thu, 26 May 2022 12:06:55 +0900 Subject: [PATCH 16/16] Apply new poweroff handler Change-Id: I6ca6fc17ddcc2c16e98b939604cf93f89e4d8817 Signed-off-by: Youngjae Cho --- src/core/haptic.c | 43 ++++++++++++------------------------------- 1 file changed, 12 insertions(+), 31 deletions(-) diff --git a/src/core/haptic.c b/src/core/haptic.c index e644f1c..4fea07d 100644 --- a/src/core/haptic.c +++ b/src/core/haptic.c @@ -24,6 +24,8 @@ #include #include #include +#include +#include #include #include #include @@ -39,7 +41,6 @@ #define VIBRATION_CONF_PATH FEEDBACK_BASE_PATH"vibration.conf" #define HAPTIC_CONF_PATH "/etc/feedbackd/haptic.conf" -#define SIGNAL_POWEROFF_STATE "ChangeState" #define SIGNAL_VIBRATOR_INITIATED "InitiateVibrator" /* hardkey vibration variable */ @@ -1133,27 +1134,12 @@ exit: return g_variant_new("(i)", ret); } -static void haptic_poweroff_cb(GDBusConnection *conn, - const gchar *sender, - const gchar *path, - const gchar *iface, - const gchar *name, - GVariant *param, - gpointer data) +static void haptic_poweroff_cb(const struct device_change_state_info *info, void *udata) { - int type = POWER_OFF_NONE; int ret, level; struct timespec time = {0,}; - if (!g_variant_get_safe(param, "(i)", &type)) { - _E("Failed to get params from gvariant. expected:%s, type:%s", "(i)", g_variant_get_type_string(param)); - return; - } - - if (type != POWER_OFF_DIRECT && type != POWER_OFF_RESTART) - return; - - _D("Poweroff: %d", type); + _D("Poweroff: %"PRIx64, info->next_state); if (hal_device_haptic_check_backend() < 0) { if (haptic_module_load() < 0) @@ -1185,6 +1171,9 @@ static void haptic_poweroff_cb(GDBusConnection *conn, /* sleep for vibration */ time.tv_nsec = POWER_OFF_VIB_DURATION * NANO_SECOND_MULTIPLIER; nanosleep(&time, NULL); + + device_power_change_state_wait_done(info->id); + return; } @@ -1301,8 +1290,6 @@ int haptic_probe(void) return haptic_module_load(); } -static guint id_sig_pwr_off_state; - void haptic_init(void) { int r; @@ -1319,15 +1306,10 @@ void haptic_init(void) if (r < 0) _E("Failed to init hdbus interface and method: %d", r); - id_sig_pwr_off_state = gdbus_signal_subscribe(NULL, - DEVICED_PATH_POWEROFF, - DEVICED_INTERFACE_POWEROFF, - SIGNAL_POWEROFF_STATE, - haptic_poweroff_cb, - NULL, - NULL); - if (id_sig_pwr_off_state <= 0) { - _E("Failed to register signal handler: %d", r); + r = device_power_add_change_state_wait_callback(POWER_STATE_POWEROFF | POWER_STATE_REBOOT, + haptic_poweroff_cb, NULL); + if (r < 0) { + _E("Failed to register poweroff handler: %d", r); return; } @@ -1360,8 +1342,7 @@ void haptic_exit(void) _W("Remove watch for VCONFKEY_RECORDER_STATE failed."); } - /* unregister notifier for below each event */ - gdbus_signal_unsubscribe(NULL, id_sig_pwr_off_state); + device_power_remove_change_state_wait_callback(POWER_STATE_POWEROFF | POWER_STATE_REBOOT); /* release haptic data memory */ safe_free(haptic_conf.level_arr); -- 2.7.4