diff options
author | Boram Bae <boram21.bae@samsung.com> | 2021-01-26 15:42:27 +0900 |
---|---|---|
committer | Boram Bae <boram21.bae@samsung.com> | 2021-01-27 14:49:04 +0900 |
commit | a1c726a007201178086e816821023ac504342ac4 (patch) | |
tree | 84f66fa1e976f33b33d4b69a7c59e23fc76c553a /src | |
parent | b2e6cdea9f86b27e3b4d77f379f8966d417d0f13 (diff) | |
download | sensor-tm1-a1c726a007201178086e816821023ac504342ac4.tar.gz sensor-tm1-a1c726a007201178086e816821023ac504342ac4.tar.bz2 sensor-tm1-a1c726a007201178086e816821023ac504342ac4.zip |
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: I0a2a787560e15194c0728c63b9392ad6bf631540
Signed-off-by: Boram Bae <boram21.bae@samsung.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/accel/accel_device.h | 2 | ||||
-rw-r--r-- | src/create.cpp | 59 | ||||
-rw-r--r-- | src/hal-backend-sensor.cpp | 89 | ||||
-rw-r--r-- | src/proxi/proxi_device.h | 2 | ||||
-rw-r--r-- | src/sensorhub/sensorhub.h | 2 | ||||
-rw-r--r-- | src/sensorhub/sensorhub_controller.h | 2 | ||||
-rw-r--r-- | src/sensorhub/wristup.cpp | 2 |
7 files changed, 94 insertions, 64 deletions
diff --git a/src/accel/accel_device.h b/src/accel/accel_device.h index 6c4b02b..0566fd9 100644 --- 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 <sensor/sensor_hal.h> +#include <hal/hal-sensor-interface.h> #include <string> #include <vector> #include <functional> diff --git a/src/create.cpp b/src/create.cpp deleted file mode 100644 index 2e9a2d5..0000000 --- a/src/create.cpp +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright (c) 2016 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 "proxi/proxi_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) -{ -#ifdef ENABLE_ACCEL - create_sensor<accel_device>("Accelerometer"); -#endif -#ifdef ENABLE_PROXIMITY - create_sensor<proxi_device>("Proximity"); -#endif -#ifdef ENABLE_SENSORHUB - create_sensor<sensorhub_device>("Sensorhub"); -#endif - - *devices = &devs[0]; - return devs.size(); -} diff --git a/src/hal-backend-sensor.cpp b/src/hal-backend-sensor.cpp new file mode 100644 index 0000000..3544482 --- /dev/null +++ b/src/hal-backend-sensor.cpp @@ -0,0 +1,89 @@ +/* + * 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 "proxi/proxi_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_tm1_create(sensor_device_t **devices) { +#ifdef ENABLE_ACCEL + create_sensor<accel_device>("Accelerometer"); +#endif +#ifdef ENABLE_PROXIMITY + create_sensor<proxi_device>("Proximity"); +#endif +#ifdef ENABLE_SENSORHUB + create_sensor<sensorhub_device>("Sensorhub"); +#endif + + *devices = &devs[0]; + return devs.size(); +} + +static int sensor_tm1_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_tm1_create; + + *data = (void *)funcs; + + return 0; +} + +static int sensor_tm1_exit(void *data) { + if (!data) return -EINVAL; + free(data); + + return 0; +} + +extern "C" hal_backend hal_backend_sensor_data = { + .name = "sensor-tm1", + .vendor = "Tizen", + .abi_version = HAL_ABI_VERSION_TIZEN_6_5, + .init = sensor_tm1_init, + .exit = sensor_tm1_exit, +}; diff --git a/src/proxi/proxi_device.h b/src/proxi/proxi_device.h index f9cf22b..29114d1 100644 --- a/src/proxi/proxi_device.h +++ b/src/proxi/proxi_device.h @@ -18,7 +18,7 @@ #ifndef _PROXI_DEVICE_H_ #define _PROXI_DEVICE_H_ -#include <sensor/sensor_hal.h> +#include <hal/hal-sensor-interface.h> #include <string> #include <vector> #include <functional> diff --git a/src/sensorhub/sensorhub.h b/src/sensorhub/sensorhub.h index 3a5bbcc..630f304 100644 --- a/src/sensorhub/sensorhub.h +++ b/src/sensorhub/sensorhub.h @@ -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" diff --git a/src/sensorhub/sensorhub_controller.h b/src/sensorhub/sensorhub_controller.h index 0aa5d7c..d4a707e 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 <sensor/sensor_hal.h> +#include <hal/hal-sensor-interface.h> class sensorhub_controller { public: diff --git a/src/sensorhub/wristup.cpp b/src/sensorhub/wristup.cpp index fcbecac..81108b3 100644 --- a/src/sensorhub/wristup.cpp +++ b/src/sensorhub/wristup.cpp @@ -16,7 +16,7 @@ */ #include <algorithm> -#include <sensor/sensor_hal.h> +#include <hal/hal-sensor-interface.h> #include <sensor_log.h> #include "sensorhub_manager.h" |