From 8d1283b7d93c343c676b3d232f0188c2ea82663d Mon Sep 17 00:00:00 2001 From: Yunmi Ha Date: Wed, 13 Jan 2021 14:53:30 +0900 Subject: [PATCH] haptic: add check backend function Change-Id: I5d463473d2a95d477fb54c6e40340f7641c8b52e Signed-off-by: Yunmi Ha --- hal-api-device.pc.in | 2 +- include/hal-haptic.h | 1 + packaging/hal-api-device.spec | 2 +- src/haptic.c | 18 +++++++++++++++++- 4 files changed, 20 insertions(+), 3 deletions(-) diff --git a/hal-api-device.pc.in b/hal-api-device.pc.in index 30f2af2..739fabd 100644 --- a/hal-api-device.pc.in +++ b/hal-api-device.pc.in @@ -3,7 +3,7 @@ prefix=@PREFIX@ exec_prefix=/usr -libdir=@LIB_INSTALL_DIR@ +libdir=@LIB_INSTALL_DIR@/hal includedir=/usr/include Name: @PC_NAME@ diff --git a/include/hal-haptic.h b/include/hal-haptic.h index dfbeb54..942fca2 100644 --- a/include/hal-haptic.h +++ b/include/hal-haptic.h @@ -26,6 +26,7 @@ extern "C" { int hal_device_haptic_get_backend(void); int hal_device_haptic_put_backend(void); +int hal_device_haptic_check_backend(void); int hal_device_haptic_get_device_count(int *count); int hal_device_haptic_open_device(int *handle); diff --git a/packaging/hal-api-device.spec b/packaging/hal-api-device.spec index c46950c..ceecfaa 100644 --- a/packaging/hal-api-device.spec +++ b/packaging/hal-api-device.spec @@ -42,7 +42,7 @@ MAJORVER=`echo %{version} | awk 'BEGIN {FS="."}{print $1}'` %files %manifest %{name}.manifest %license LICENSE.Apache-2.0 -%{_libdir}/hal/libhal-api-device.so.* +%{_libdir}/hal/libhal-api-device.so* %files devel %manifest %{name}.manifest diff --git a/src/haptic.c b/src/haptic.c index 72ffbbf..cb8d9ae 100644 --- a/src/haptic.c +++ b/src/haptic.c @@ -37,13 +37,21 @@ int hal_device_haptic_get_backend(void) return -ENODEV; } + if (!g_haptic_funcs) + return -ENODEV; + + if (!g_haptic_funcs->is_valid || !(g_haptic_funcs->is_valid())) { + hal_device_haptic_put_backend(); + return -ENODEV; + } + return 0; } int hal_device_haptic_put_backend(void) { if (!g_haptic_funcs) - return 0; + return -ENODEV; hal_common_put_backend(HAL_MODULE_DEVICE_HAPTIC, (void *)g_haptic_funcs); g_haptic_funcs = NULL; @@ -51,6 +59,14 @@ int hal_device_haptic_put_backend(void) return 0; } +int hal_device_haptic_check_backend(void) +{ + if (!g_haptic_funcs) + return -ENODEV; + + return 0; +} + int hal_device_haptic_get_device_count(int *count) { if (!g_haptic_funcs || !g_haptic_funcs->get_device_count) -- 2.7.4