From 5576a733cb5e46641e031392d2d73ad02305ee4d Mon Sep 17 00:00:00 2001 From: Boram Bae Date: Thu, 14 Jan 2021 18:33:02 +0900 Subject: Use hal-api-sensor instead of legacy interface * This change is for Tizen Next-HAL * Now, all implementations of sensor device inherit sensor device interface of the hal-api-sensor * sensor_{device}_create replaces create, see hal-backend-sensor.cpp * The hal-backend implementation must define hal_backend_sensor_data Change-Id: Ib9a9d96a3ea0ddaa40b6bc9aff1ac0edc2609944 Signed-off-by: Boram Bae --- CMakeLists.txt | 13 +++-- packaging/sensor-hal-tw3.spec | 10 ++-- src/accel/accel_device.h | 2 +- src/create.cpp | 61 ----------------------- src/gyro/gyro_device.h | 2 +- src/hal-backend-sensor.cpp | 91 +++++++++++++++++++++++++++++++++++ src/hrm/hrm_device.h | 2 +- src/hrm_raw/hrm_raw_device.h | 2 +- src/light/light_device.h | 2 +- src/pressure/pressure_device.h | 2 +- src/sensorhub/hrm_batch.cpp | 2 +- src/sensorhub/hrm_led_green_batch.cpp | 2 +- src/sensorhub/sensorhub.h | 2 +- src/sensorhub/sensorhub_controller.h | 2 +- 14 files changed, 115 insertions(+), 80 deletions(-) delete mode 100644 src/create.cpp create mode 100644 src/hal-backend-sensor.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index b899200..3ca4ffd 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,9 +1,13 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.6) PROJECT(sensor-hal-tw3 CXX) INCLUDE(GNUInstallDirs) + +SET(LIBRARY_NAME "hal-backend-sensor") SET(PREFIX ${CMAKE_INSTALL_PREFIX}) +SET(HAL_LIBDIR ${CMAKE_HAL_LIBDIR_PREFIX}) +SET(HAL_LICENSEDIR ${CMAKE_HAL_LICENSEDIR_PREFIX}) SET(BINDIR "${PREFIX}/bin") -SET(DEPENDENTS "dlog") +SET(DEPENDENTS "dlog hal-api-common hal-api-sensor") SET(ACCEL "ON") SET(GYRO "ON") @@ -133,9 +137,10 @@ ADD_DEFINITIONS(-DENABLE_SENSORHUB) ENDIF() MESSAGE("Sources: ${SRCS}") -ADD_LIBRARY(${PROJECT_NAME} SHARED ${SRCS}) -TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${HAL_PKGS_LDFLAGS}) +ADD_LIBRARY(${LIBRARY_NAME} SHARED ${SRCS}) +TARGET_LINK_LIBRARIES(${LIBRARY_NAME} ${HAL_PKGS_LDFLAGS}) -INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${CMAKE_INSTALL_LIBDIR}/sensor) +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/LICENSE.APLv2 DESTINATION ${HAL_LICENSEDIR}/${PROJECT_NAME}) +INSTALL(TARGETS ${LIBRARY_NAME} DESTINATION ${HAL_LIBDIR} COMPONENT RuntimeLibraries) ADD_SUBDIRECTORY(testcase) diff --git a/packaging/sensor-hal-tw3.spec b/packaging/sensor-hal-tw3.spec index e7c2905..5d1375c 100755 --- a/packaging/sensor-hal-tw3.spec +++ b/packaging/sensor-hal-tw3.spec @@ -15,8 +15,8 @@ BuildRequires: pkgconfig(dlog) BuildRequires: pkgconfig(glib-2.0) BuildRequires: pkgconfig(gio-2.0) BuildRequires: pkgconfig(gmock) -BuildRequires: sensor-hal-devel - +BuildRequires: pkgconfig(hal-api-common) +BuildRequires: pkgconfig(hal-api-sensor) %description TW3 Sensor HAL @@ -33,7 +33,7 @@ Sensor Device HAL(Hardware Abstraction Layer) Test Cases %setup -q %build -%cmake . +%cmake . -DCMAKE_HAL_LIBDIR_PREFIX=%{_hal_libdir} -DCMAKE_HAL_LICENSEDIR_PREFIX=%{_hal_licensedir} make %{?_smp_mflags} %install @@ -54,8 +54,8 @@ install -m 0644 %SOURCE2 %{buildroot}%{_libdir}/udev/rules.d %manifest packaging/%{name}.manifest %{_libdir}/udev/rules.d/99-sensor.rules %{_libdir}/udev/rules.d/99-sensorhub.rules -%{_libdir}/sensor/*.so -%license LICENSE.APLv2 +%{_hal_libdir}/*.so* +%{_hal_licensedir}/%{name}/LICENSE.APLv2 %files haltests %manifest packaging/%{name}.manifest diff --git a/src/accel/accel_device.h b/src/accel/accel_device.h index 34770be..7b7ab25 100755 --- a/src/accel/accel_device.h +++ b/src/accel/accel_device.h @@ -18,7 +18,7 @@ #ifndef __ACCEL_DEVICE_H__ #define __ACCEL_DEVICE_H__ -#include +#include #include #include diff --git a/src/create.cpp b/src/create.cpp deleted file mode 100644 index 9246692..0000000 --- a/src/create.cpp +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright (c) 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 "accel/accel_device.h" -#include "gyro/gyro_device.h" -#include "pressure/pressure_device.h" -#include "light/light_device.h" -#include "hrm_raw/hrm_raw_device.h" -#include "hrm/hrm_device.h" -#include "sensorhub/sensorhub.h" - -static std::vector devs; - -template -void create_sensor(const char *name) -{ - sensor_device *instance = NULL; - try { - instance = new _sensor; - } catch (std::exception &e) { - ERR("Failed to create %s sensor device, exception: %s", name, e.what()); - return; - } catch (int err) { - _ERRNO(err, _E, "Failed to create %s sensor device", name); - return; - } - - devs.push_back(instance); -} - -extern "C" int create(sensor_device_t **devices) -{ - create_sensor("Accelerometer"); - create_sensor("Gyroscope"); - create_sensor("Pressure"); - create_sensor("Light"); - create_sensor("HRM Raw"); - create_sensor("HRM"); - create_sensor("Sensorhub"); - - *devices = &devs[0]; - return devs.size(); -} diff --git a/src/gyro/gyro_device.h b/src/gyro/gyro_device.h index 9c86499..d0ea338 100644 --- a/src/gyro/gyro_device.h +++ b/src/gyro/gyro_device.h @@ -18,7 +18,7 @@ #ifndef __GYRO_DEVICE_H__ #define __GYRO_DEVICE_H__ -#include +#include #include #include diff --git a/src/hal-backend-sensor.cpp b/src/hal-backend-sensor.cpp new file mode 100644 index 0000000..ad0a238 --- /dev/null +++ b/src/hal-backend-sensor.cpp @@ -0,0 +1,91 @@ +/* + * Copyright (c) 2021 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 "accel/accel_device.h" +#include "gyro/gyro_device.h" +#include "hrm/hrm_device.h" +#include "hrm_raw/hrm_raw_device.h" +#include "light/light_device.h" +#include "pressure/pressure_device.h" +#include "sensorhub/sensorhub.h" + +static std::vector devs; + +template +void create_sensor(const char *name) { + sensor_device *instance = NULL; + try { + instance = new _sensor; + } catch (std::exception &e) { + ERR("Failed to create %s sensor device, exception: %s", name, e.what()); + return; + } catch (int err) { + _ERRNO(err, _E, "Failed to create %s sensor device", name); + return; + } + + devs.push_back(instance); +} + +static int sensor_tw3_create(sensor_device_t **devices) { + create_sensor("Accelerometer"); + create_sensor("Gyroscope"); + create_sensor("Pressure"); + create_sensor("Light"); + create_sensor("HRM Raw"); + create_sensor("HRM"); + create_sensor("Sensorhub"); + + *devices = &devs[0]; + return devs.size(); +} + +static int sensor_tw3_init(void **data) { + _I("init hal backend sensor"); + hal_backend_sensor_funcs *funcs; + + funcs = + (hal_backend_sensor_funcs *)calloc(1, sizeof(hal_backend_sensor_funcs)); + if (!funcs) return -ENOMEM; + + funcs->create = sensor_tw3_create; + + *data = (void *)funcs; + + return 0; +} + +static int sensor_tw3_exit(void *data) { + if (!data) return -EINVAL; + free(data); + + return 0; +} + +extern "C" hal_backend hal_backend_sensor_data = { + .name = "sensor-tw3", + .vendor = "Tizen", + .abi_version = HAL_ABI_VERSION_TIZEN_6_5, + .init = sensor_tw3_init, + .exit = sensor_tw3_exit, +}; diff --git a/src/hrm/hrm_device.h b/src/hrm/hrm_device.h index d3067f1..04bc907 100644 --- a/src/hrm/hrm_device.h +++ b/src/hrm/hrm_device.h @@ -18,7 +18,7 @@ #ifndef __HRM_DEVICE_H__ #define __HRM_DEVICE_H__ -#include +#include #include #include diff --git a/src/hrm_raw/hrm_raw_device.h b/src/hrm_raw/hrm_raw_device.h index bb10530..b32cbc8 100755 --- a/src/hrm_raw/hrm_raw_device.h +++ b/src/hrm_raw/hrm_raw_device.h @@ -18,7 +18,7 @@ #ifndef __HRM_RAW_DEVICE_H__ #define __HRM_RAW_DEVICE_H__ -#include +#include #include #include diff --git a/src/light/light_device.h b/src/light/light_device.h index 2a29dd7..4b65d52 100644 --- a/src/light/light_device.h +++ b/src/light/light_device.h @@ -18,7 +18,7 @@ #ifndef __LIGHT_DEVICE_H__ #define __LIGHT_DEVICE_H__ -#include +#include #include #include diff --git a/src/pressure/pressure_device.h b/src/pressure/pressure_device.h index 114523d..f3ae65f 100644 --- a/src/pressure/pressure_device.h +++ b/src/pressure/pressure_device.h @@ -18,7 +18,7 @@ #ifndef __PRESSURE_DEVICE_H__ #define __PRESSURE_DEVICE_H__ -#include +#include #include #include diff --git a/src/sensorhub/hrm_batch.cpp b/src/sensorhub/hrm_batch.cpp index b4d9fa9..b9feb73 100644 --- a/src/sensorhub/hrm_batch.cpp +++ b/src/sensorhub/hrm_batch.cpp @@ -17,7 +17,7 @@ #include #include -#include +#include #include #include #include diff --git a/src/sensorhub/hrm_led_green_batch.cpp b/src/sensorhub/hrm_led_green_batch.cpp index 41d63aa..53f8ca8 100644 --- a/src/sensorhub/hrm_led_green_batch.cpp +++ b/src/sensorhub/hrm_led_green_batch.cpp @@ -17,7 +17,7 @@ #include #include -#include +#include #include #include diff --git a/src/sensorhub/sensorhub.h b/src/sensorhub/sensorhub.h index eceb5ad..2b80dbd 100644 --- a/src/sensorhub/sensorhub.h +++ b/src/sensorhub/sensorhub.h @@ -19,7 +19,7 @@ #define _SENSORHUB_DEVICE_H_ #include -#include +#include #include "sensorhub_controller.h" #include "sensorhub_manager.h" diff --git a/src/sensorhub/sensorhub_controller.h b/src/sensorhub/sensorhub_controller.h index 40bf786..bb206d3 100644 --- a/src/sensorhub/sensorhub_controller.h +++ b/src/sensorhub/sensorhub_controller.h @@ -18,7 +18,7 @@ #ifndef _SENSORHUB_CONTROLLER_H_ #define _SENSORHUB_CONTROLLER_H_ -#include +#include class sensorhub_controller { public: -- cgit v1.2.3