listener: Add getter listener attribute 48/286948/7
authorTaeminYeom <taemin.yeom@samsung.com>
Tue, 17 Jan 2023 07:56:21 +0000 (16:56 +0900)
committerTaeminYeom <taemin.yeom@samsung.com>
Thu, 26 Jan 2023 09:20:33 +0000 (18:20 +0900)
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 <taemin.yeom@samsung.com>
include/private/sensor-private.h
include/sensor-internal.h
src/api/api-sensor-internal.cpp
src/api/api-sensor.cpp

index 7d99272..0133ea9 100644 (file)
@@ -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;
index adea3d3..6c45fc0 100644 (file)
@@ -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
index afb7643..cedab98 100644 (file)
@@ -19,6 +19,8 @@
 #include <errno.h>
 #include <sensor.h>
 #include <sensor_internal.h>
+#include <sensor-private.h>
+#include <sensor-log-private.h>
 
 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;
+}
index 08814c9..b084409 100644 (file)
@@ -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)