From 47588a17e1ca454ee01cd8eef53c4c56a6bace89 Mon Sep 17 00:00:00 2001 From: "taemin.yeom" Date: Mon, 13 Dec 2021 16:24:20 +0900 Subject: [PATCH] Add internal API prototype -sensor_util_set_attribute_int -sensor_util_get_attribute_int -enum sensor_Attribute_internal_e Change-Id: I1ef8cfc7eae5b2f6c0338367256d8a6cdb64d173 Signed-off-by: taemin.yeom --- CMakeLists.txt | 3 +- include/sensor-internal.h | 57 +++++++++++++++++++++++++++++++++ src/sensor-internal.cpp | 80 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 139 insertions(+), 1 deletion(-) create mode 100644 include/sensor-internal.h create mode 100644 src/sensor-internal.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index e1c6c3e..c214b74 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -39,6 +39,7 @@ SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -Wl,--rpath=${LIB_INSTALL_DIR}") # Compile Source files SET(SOURCES src/sensor.cpp src/sensor_provider.cpp + src/sensor-internal.cpp src/geomagnetic_field.c src/fusion_util.c) @@ -54,7 +55,7 @@ TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${${PROJECT_NAME}_LDFLAGS}) SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES VERSION ${FULLVER} SOVERSION ${MAJORVER} CLEAN_DIRECT_OUTPUT 1) CONFIGURE_FILE(${PROJECT_NAME}.pc.in ${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}.pc @ONLY) INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) -INSTALL(FILES include/sensor.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/sensor) +INSTALL(FILES include/sensor.h include/sensor-internal.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/sensor) INSTALL(TARGETS ${PROJECT_NAME} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}) ADD_SUBDIRECTORY(test/stress_test) diff --git a/include/sensor-internal.h b/include/sensor-internal.h new file mode 100644 index 0000000..14d553c --- /dev/null +++ b/include/sensor-internal.h @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2021 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. + */ + +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + +typedef enum { + SENSOR_ATTRIBUTE_INTERNAL_START = 10000, + SENSOR_ATTRIBUTE_POWER_STATE, +} sensor_attribute_internal_e; + +/** + * @brief Set the attribute to a connected sensor + * + * @param[in] type a sensor type of represensting a connected sensor + * @param[in] attribute an attribute to change + * @param[in] value an attribute value + * @return 0 on success, otherwise a negative error value + * @retval 0 Successful + * @retval -EINVAL Invalid parameter + * @retval -EPERM Operation not permitted + */ +int sensor_util_set_attribute_int(sensor_type_e type, sensor_attribute_internal_e attr, int value); + +/** + * @brief Get the attribute to a connected sensor + * + * @param[in] type a sensor type of represensting a connected sensor + * @param[in] attribute an attribute to get value + * @param[out] value an attribute value + * @return 0 on success, otherwise a negative error value + * @retval 0 Successful + * @retval -EINVAL Invalid parameter + * @retval -EPERM Operation not permitted + */ +int sensor_util_get_attribute_int(sensor_type_e type, sensor_attribute_internal_e attr, int *value); + +#ifdef __cplusplus +} +#endif diff --git a/src/sensor-internal.cpp b/src/sensor-internal.cpp new file mode 100644 index 0000000..11e1356 --- /dev/null +++ b/src/sensor-internal.cpp @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2021 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. + */ + +#include + +#include +#include +#include + +int sensor_util_set_attribute_int(sensor_type_e type, sensor_attribute_internal_e attr, int value) +{ + sensor_t sensor; + int ret = 0; + int handle = 0; + ret = sensord_get_default_sensor((sensor_type_t) type, &sensor); + if (ret < 0) { + return ret; + } + + handle = sensord_connect(sensor); + if (handle < 0) { + return handle; + } + + ret = sensord_set_attribute_int(handle, attr, value); + if (ret < 0) { + return ret; + } + + ret = sensord_disconnect(handle); + if (ret < 0) { + return ret; + } + + return 0; +} + +int sensor_util_get_attribute_int(sensor_type_e type, sensor_attribute_internal_e attr, int *value) +{ + if (!value) + return -EINVAL; + + sensor_t sensor; + int ret = 0; + int handle = 0; + ret = sensord_get_default_sensor((sensor_type_t) type, &sensor); + if (ret < 0) { + return ret; + } + + handle = sensord_connect(sensor); + if (handle < 0) { + return handle; + } + + ret = sensord_get_attribute_int(handle, attr, value); + if (ret < 0) { + return ret; + } + + ret = sensord_disconnect(handle); + if (ret < 0) { + return ret; + } + + return 0; +} -- 2.7.4