Add internal API prototype 09/267909/2
authortaemin.yeom <taemin.yeom@samsung.com>
Mon, 13 Dec 2021 07:24:20 +0000 (16:24 +0900)
committertaemin.yeom <taemin.yeom@samsung.com>
Mon, 13 Dec 2021 08:49:14 +0000 (17:49 +0900)
-sensor_util_set_attribute_int
-sensor_util_get_attribute_int
-enum sensor_Attribute_internal_e

Change-Id: I1ef8cfc7eae5b2f6c0338367256d8a6cdb64d173
Signed-off-by: taemin.yeom <taemin.yeom@samsung.com>
CMakeLists.txt
include/sensor-internal.h [new file with mode: 0644]
src/sensor-internal.cpp [new file with mode: 0644]

index e1c6c3e..c214b74 100644 (file)
@@ -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 (file)
index 0000000..14d553c
--- /dev/null
@@ -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 <sensor.h>
+
+#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 (file)
index 0000000..11e1356
--- /dev/null
@@ -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 <sensor-internal.h>
+
+#include <errno.h>
+#include <sensor.h>
+#include <sensor_internal.h>
+
+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;
+}