From c40356bcb837cd6daef3cb9b0feb261219745c9b Mon Sep 17 00:00:00 2001 From: TaeminYeom Date: Tue, 17 Jan 2023 16:56:21 +0900 Subject: [PATCH] listener: Add getter listener attribute There is a setter attribute int in public API. But there is no getter, so it is needed. API function -sensor_listener_get_attribute_int : get listener attribute int Change-Id: Id8b3a7610d5533e93bb3212fc81df3ce8162929d Signed-off-by: TaeminYeom --- include/private/sensor-private.h | 2 ++ include/sensor-internal.h | 21 ++++++++++++++++++++ src/api/api-sensor-internal.cpp | 42 ++++++++++++++++++++++++++++++++++++++++ src/api/api-sensor.cpp | 1 - 4 files changed, 65 insertions(+), 1 deletion(-) diff --git a/include/private/sensor-private.h b/include/private/sensor-private.h index 7d99272..0133ea9 100644 --- a/include/private/sensor-private.h +++ b/include/private/sensor-private.h @@ -17,6 +17,8 @@ #ifndef __SENSOR_PRIVATE_H__ #define __SENSOR_PRIVATE_H__ +#define SENSOR_LISTENER_MAGIC 0xCAFECAFE + struct sensor_listener_s { int id; int type; diff --git a/include/sensor-internal.h b/include/sensor-internal.h index adea3d3..6c45fc0 100644 --- a/include/sensor-internal.h +++ b/include/sensor-internal.h @@ -61,6 +61,27 @@ int sensor_util_set_attribute_int(sensor_type_e type, sensor_attribute_e attr, i */ int sensor_util_get_attribute_int(sensor_type_e type, sensor_attribute_e attr, int *value); +/** + * @brief Gets an attribute to control the behavior of a sensor listener. + * @details Applications can change the behavior of a sensor listener, for example, + * what is the reference coordinate of the sensor values, + * and when the system is allowed to turn off the sensor implicitly to reduce the power consumption. + * See #sensor_attribute_e for more details about the available control parameters. + * @since_tizen 7.0 + * + * @param[in] listener A listener handle + * @param[in] attribute An attribute to change. + * It should be in the range each sensor_attribute_e, + * or should be fixed enum value such as sensor_axis_e or sensor_pause_e. + * @param[out] value An attribute value + * + * @return #SENSOR_ERROR_NONE on success, otherwise a negative error value + * @retval #SENSOR_ERROR_NONE Successful + * @retval #SENSOR_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #SENSOR_ERROR_OPERATION_FAILED Operation failed + */ +int sensor_listener_get_attribute_int(sensor_listener_h listener, sensor_attribute_e attribute, int *value); + #ifdef __cplusplus } #endif diff --git a/src/api/api-sensor-internal.cpp b/src/api/api-sensor-internal.cpp index afb7643..cedab98 100644 --- a/src/api/api-sensor-internal.cpp +++ b/src/api/api-sensor-internal.cpp @@ -19,6 +19,8 @@ #include #include #include +#include +#include int sensor_util_set_attribute_int(sensor_type_e type, sensor_attribute_e attr, int value) { @@ -78,3 +80,43 @@ int sensor_util_get_attribute_int(sensor_type_e type, sensor_attribute_e attr, i return 0; } + +static bool is_supported_sensor_listener_attribute(sensor_attribute_e attribute) +{ + switch (attribute) { + case SENSOR_ATTRIBUTE_AXIS_ORIENTATION: + case SENSOR_ATTRIBUTE_PAUSE_POLICY: + return true; + default: + return false; + } +} + +int sensor_listener_get_attribute_int(sensor_listener_h listener, sensor_attribute_e attribute, int *value) +{ + if (!value) { + _E("Failed to validate the parameter"); + return SENSOR_ERROR_INVALID_PARAMETER; + } + + if (!listener || listener->magic != SENSOR_LISTENER_MAGIC) { + _E("Invalid sensor listener"); + return SENSOR_ERROR_INVALID_PARAMETER; + } + + if (!is_supported_sensor_listener_attribute(attribute)) { + _E("Invalid sensor listener attribute"); + return SENSOR_ERROR_INVALID_PARAMETER; + } + + int ret = sensord_listener_get_attribute_int(listener->id, (int)attribute, value); + if (ret == -EINVAL) { + _E("Failed to validate the parameter"); + return SENSOR_ERROR_INVALID_PARAMETER; + } else if (ret != SENSOR_ERROR_NONE) { + _E("Failed to get listener attribute"); + return SENSOR_ERROR_OPERATION_FAILED; + } + + return SENSOR_ERROR_NONE; +} diff --git a/src/api/api-sensor.cpp b/src/api/api-sensor.cpp index 08814c9..b084409 100644 --- a/src/api/api-sensor.cpp +++ b/src/api/api-sensor.cpp @@ -29,7 +29,6 @@ #define SENSOR_SHIFT_TYPE 16 #define SENSOR_UNDEFINED_ID -1 -#define SENSOR_LISTENER_MAGIC 0xCAFECAFE #define RAD2DEGREE (180/M_PI) #define CONVERT_AXIS_ENUM(X) ((X) < 3 ? (X) + 0x81 : (X) - 2) -- 2.7.4