Use hal-api-sensor instead of legacy interface
authorBoram Bae <boram21.bae@samsung.com>
Thu, 14 Jan 2021 09:33:02 +0000 (18:33 +0900)
committerBoram Bae <boram21.bae@samsung.com>
Wed, 27 Jan 2021 05:48:30 +0000 (14:48 +0900)
* 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 <boram21.bae@samsung.com>
14 files changed:
CMakeLists.txt
packaging/sensor-hal-tw3.spec
src/accel/accel_device.h
src/create.cpp [deleted file]
src/gyro/gyro_device.h
src/hal-backend-sensor.cpp [new file with mode: 0644]
src/hrm/hrm_device.h
src/hrm_raw/hrm_raw_device.h
src/light/light_device.h
src/pressure/pressure_device.h
src/sensorhub/hrm_batch.cpp
src/sensorhub/hrm_led_green_batch.cpp
src/sensorhub/sensorhub.h
src/sensorhub/sensorhub_controller.h

index b89920085c909fb356bc8d8dfcfd4d08870c6b3b..3ca4ffda2357b37325caf9efadbfdbb4d01bb32f 100755 (executable)
@@ -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)
index e7c290594b24beb3b46055527be4397d86802661..5d1375cb9906a019d56053fa7025676ca7489fea 100755 (executable)
@@ -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
index 34770be368f83a5082d6bf64fff08000a3880633..7b7ab2550ca6d83027c4cc1f8d7c7526bd5040d8 100755 (executable)
@@ -18,7 +18,7 @@
 #ifndef __ACCEL_DEVICE_H__
 #define __ACCEL_DEVICE_H__
 
-#include <sensor/sensor_hal.h>
+#include <hal/hal-sensor-interface.h>
 #include <string>
 #include <vector>
 
diff --git a/src/create.cpp b/src/create.cpp
deleted file mode 100644 (file)
index 9246692..0000000
+++ /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 <sensor/sensor_hal.h>
-#include <sensor_log.h>
-#include <vector>
-
-#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<sensor_device_t> devs;
-
-template<typename _sensor>
-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<accel_device>("Accelerometer");
-       create_sensor<gyro_device>("Gyroscope");
-       create_sensor<pressure_device>("Pressure");
-       create_sensor<light_device>("Light");
-       create_sensor<hrm_raw_device>("HRM Raw");
-       create_sensor<hrm_device>("HRM");
-       create_sensor<sensorhub_device>("Sensorhub");
-
-       *devices = &devs[0];
-       return devs.size();
-}
index 9c8649936557dfa099828da0d2a4160ab7e91823..d0ea33873a0c13f218a7957008efaefd94f8c662 100644 (file)
@@ -18,7 +18,7 @@
 #ifndef __GYRO_DEVICE_H__
 #define __GYRO_DEVICE_H__
 
-#include <sensor/sensor_hal.h>
+#include <hal/hal-sensor-interface.h>
 #include <string>
 #include <vector>
 
diff --git a/src/hal-backend-sensor.cpp b/src/hal-backend-sensor.cpp
new file mode 100644 (file)
index 0000000..ad0a238
--- /dev/null
@@ -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 <errno.h>
+#include <hal/hal-sensor-interface.h>
+#include <sensor_log.h>
+#include <stdlib.h>
+
+#include <vector>
+
+#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<sensor_device_t> devs;
+
+template <typename _sensor>
+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<accel_device>("Accelerometer");
+  create_sensor<gyro_device>("Gyroscope");
+  create_sensor<pressure_device>("Pressure");
+  create_sensor<light_device>("Light");
+  create_sensor<hrm_raw_device>("HRM Raw");
+  create_sensor<hrm_device>("HRM");
+  create_sensor<sensorhub_device>("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,
+};
index d3067f19f9b1db2f6f2129b483ead5d8fc9323fe..04bc907f6c2eaaf7dee4f77d4f90dc8718bf1f79 100644 (file)
@@ -18,7 +18,7 @@
 #ifndef __HRM_DEVICE_H__
 #define __HRM_DEVICE_H__
 
-#include <sensor/sensor_hal.h>
+#include <hal/hal-sensor-interface.h>
 #include <string>
 #include <vector>
 
index bb105300e57a02bcf5f59b63c69df0547b129c7a..b32cbc8a76648784591941c47ad1b077eed7a982 100755 (executable)
@@ -18,7 +18,7 @@
 #ifndef __HRM_RAW_DEVICE_H__
 #define __HRM_RAW_DEVICE_H__
 
-#include <sensor/sensor_hal.h>
+#include <hal/hal-sensor-interface.h>
 #include <string>
 #include <vector>
 
index 2a29dd752ea22119578c627202194c9f862dd595..4b65d52e43e2bec558f970dddcece769ff35adeb 100644 (file)
@@ -18,7 +18,7 @@
 #ifndef __LIGHT_DEVICE_H__
 #define __LIGHT_DEVICE_H__
 
-#include <sensor/sensor_hal.h>
+#include <hal/hal-sensor-interface.h>
 #include <string>
 #include <vector>
 
index 114523daeaf265a01be00dd25e488fdd4f5040d7..f3ae65f69bde3d37d16cd6225e4cae205f207f02 100644 (file)
@@ -18,7 +18,7 @@
 #ifndef __PRESSURE_DEVICE_H__
 #define __PRESSURE_DEVICE_H__
 
-#include <sensor/sensor_hal.h>
+#include <hal/hal-sensor-interface.h>
 #include <string>
 #include <vector>
 
index b4d9fa95b4e4165d1116bbfd5441916819f898da..b9feb73f6a5e7ac93ba31841fc742e069dcfcdf7 100644 (file)
@@ -17,7 +17,7 @@
 
 #include <stdlib.h>
 #include <sensor_common.h>
-#include <sensor/sensor_hal.h>
+#include <hal/hal-sensor-interface.h>
 #include <sensor_log.h>
 #include <deque>
 #include <util.h>
index 41d63aa927f2830df042d590e76ff8cbd04ba55a..53f8ca85b713879852e083d5ff9a64ac8acd37e4 100644 (file)
@@ -17,7 +17,7 @@
 
 #include <stdlib.h>
 #include <sensor_common.h>
-#include <sensor/sensor_hal.h>
+#include <hal/hal-sensor-interface.h>
 #include <sensor_log.h>
 #include <util.h>
 
index eceb5ad44bddb9f805ac9a575a7ed4e7f358bef2..2b80dbdba753a69d9364e463cf01197c94321aa7 100644 (file)
@@ -19,7 +19,7 @@
 #define _SENSORHUB_DEVICE_H_
 
 #include <vector>
-#include <sensor/sensor_hal.h>
+#include <hal/hal-sensor-interface.h>
 
 #include "sensorhub_controller.h"
 #include "sensorhub_manager.h"
index 40bf786c57e5968e8940a5d2f0afc0e0e8fb58c3..bb206d3fb33b5b58838d4b432d475d107246e8bb 100644 (file)
@@ -18,7 +18,7 @@
 #ifndef _SENSORHUB_CONTROLLER_H_
 #define _SENSORHUB_CONTROLLER_H_
 
-#include <sensor/sensor_hal.h>
+#include <hal/hal-sensor-interface.h>
 
 class sensorhub_controller {
 public: