diff --git a/sensors/sensor/BUILD.gn b/sensors/sensor/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..8a12ddf2ac2de2f6337ff8a8620c63858837b280 --- /dev/null +++ b/sensors/sensor/BUILD.gn @@ -0,0 +1,30 @@ +# Copyright (C) 2023 Huawei Device 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. + +import("//build/ohos.gni") +import("//build/ohos/ndk/ndk.gni") + +ohos_ndk_headers("sensor_ndk_header") { + dest_dir = "$ndk_headers_out_dir/sensors" + sources = [ + "./oh_sensor.h", + "./oh_sensor_type.h", + ] +} + +ohos_ndk_library("libsensor_ndk") { + ndk_description_file = "./libsensor.ndk.json" + output_name = "ohsensor" + output_extension = "so" + min_compact_version = "11" +} diff --git a/sensors/sensor/libsensor.ndk.json b/sensors/sensor/libsensor.ndk.json new file mode 100644 index 0000000000000000000000000000000000000000..a3d5e8f8c512116f07cd614b4bb94f20500497f8 --- /dev/null +++ b/sensors/sensor/libsensor.ndk.json @@ -0,0 +1,83 @@ +[ + { + "name": "OH_Sensor_GetInfos" + }, + { + "name": "OH_Sensor_Subscribe" + }, + { + "name": "OH_Sensor_Unsubscribe" + }, + { + "name": "OH_SensorInfo_GetName" + }, + { + "name": "OH_SensorInfo_GetVendorName" + }, + { + "name": "OH_SensorInfo_GetType" + }, + { + "name": "OH_SensorInfo_GetResolution" + }, + { + "name": "OH_SensorInfo_GetMinSamplingInterval" + }, + { + "name": "OH_SensorInfo_GetMaxSamplingInterval" + }, + { + "name": "OH_SensorEvent_GetType" + }, + { + "name": "OH_SensorEvent_GetTimestamp" + }, + { + "name": "OH_SensorEvent_GetAccuracy" + }, + { + "name": "OH_SensorEvent_GetData" + }, + { + "name": "OH_SensorSubscriptionId_GetType" + }, + { + "name": "OH_SensorSubscriptionId_SetType" + }, + { + "name": "OH_SensorSubscriptionAttribute_SetSamplingInterval" + }, + { + "name": "OH_SensorSubscriptionAttribute_GetSamplingInterval" + }, + { + "name": "OH_SensorSubscriber_SetCallback" + }, + { + "name": "OH_SensorSubscriber_GetCallback" + }, + { + "name": "OH_Sensor_CreateInfos" + }, + { + "name": "OH_Sensor_DestroyInfos" + }, + { + "name": "OH_Sensor_CreateSubscriptionId" + }, + { + "name": "OH_Sensor_DestroySubscriptionId" + }, + { + "name": "OH_Sensor_CreateSubscriptionAttribute" + }, + { + "name": "OH_Sensor_DestroySubscriptionAttribute" + }, + { + "name": "OH_Sensor_CreateSubscriber" + }, + { + "name": "OH_Sensor_DestroySubscriber" + } +] \ No newline at end of file diff --git a/sensors/sensor/oh_sensor.h b/sensors/sensor/oh_sensor.h new file mode 100644 index 0000000000000000000000000000000000000000..ee0d78c6a152dc60654614c57ea7a9937da96efc --- /dev/null +++ b/sensors/sensor/oh_sensor.h @@ -0,0 +1,99 @@ +/* + * Copyright (c) 2023 Huawei Device 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. + */ + +/** + * @addtogroup Sensor + * @{ + * + * @brief Provides APIs to use common sensor features. For example, you can call the APIs to obtain sensor information + * and subscribe to or unsubscribe from sensor data. + * @since 11 + */ +/** + * @file oh_sensor.h + * + * @brief Declares the APIs for operating sensors, including obtaining sensor information and subscribing to or + * unsubscribing from sensor data. + * @library libohsensor.so + * @syscap SystemCapability.Sensors.Sensor + * @since 11 + */ + +#ifndef OH_SENSOR_H +#define OH_SENSOR_H + +#include "oh_sensor_type.h" + +#ifdef __cplusplus +extern "C" { +#endif +/** + * @brief Obtains information about all sensors on the device. + * + * @param infos - Double pointer to the information about all sensors on the device. + * For details, see {@link Sensor_Info}. + * @param count - Pointer to the number of sensors on the device. + * @return Returns SENSOR_SUCCESS if the operation is successful; + * returns an error code defined in {@link Sensor_Result} otherwise. + * + * @since 11 + */ +Sensor_Result OH_Sensor_GetInfos(Sensor_Info **infos, uint32_t *count); + +/** + * @brief Subscribes to sensor data. The system will report sensor data to the subscriber at the specified frequency. + * If you need to apply for the ohos.permission.ACCELEROMETER permission when subscribing to the accelerometer sensor, + * you need to apply for the ohos.permission.GYROSCOPE permission when subscribing to the gyroscope sensor, and you need + * to apply for the ohos.permission.ACTIVITY_MOTION permission when subscribing to the pedometer related sensor. Apply + * for ohos.permission.READ_HEALTH_DATA permission when subscribing to health-related sensors, such as heart rate + * sensors, otherwise the subscription fails. Other sensors do not require permissions. + * + * @param id - Pointer to the sensor subscription ID. For details, see {@link Sensor_SubscriptionId}. + * @param attribute - Pointer to the subscription attribute, which is used to specify the data reporting frequency. + * For details, see {@link Sensor_SubscriptionAttribute}. + * @param subscriber - Pointer to the subscriber information, which is used to specify the callback function for + * reporting the sensor data. For details, see {@link Sensor_Subscriber}. + * @return Returns SENSOR_SUCCESS if the operation is successful; + * returns an error code defined in {@link Sensor_Result} otherwise. + * @permission ohos.permission.ACCELEROMETER or ohos.permission.GYROSCOPE or + * ohos.permission.ACTIVITY_MOTION or ohos.permission.READ_HEALTH_DATA + * @since 11 + */ +Sensor_Result OH_Sensor_Subscribe(const Sensor_SubscriptionId *id, + const Sensor_SubscriptionAttribute *attribute, const Sensor_Subscriber *subscriber); + +/** + * @brief Unsubscribes from sensor data. + * If you need to apply for the ohos.permission.ACCELEROMETER permission to unsubscribe from the accelerometer sensor, + * you need to request the ohos.permission.GYROSCOPE permission to unsubscribe from the gyroscope sensor, and you need + * to request the ohos.permission.ACTIVITY_MOTION permission to unsubscribe from the pedometer-related sensor. When you + * unsubscribe from health-related sensors, such as heart rate sensors, apply for ohos.permission.READ_HEALTH_DATA + * permissions, otherwise the subscription will fail. Other sensors do not require permissions. + * + * @param id - Pointer to the sensor subscription ID. For details, see {@link Sensor_SubscriptionId}. + * @param subscriber - Pointer to the subscriber information, which is used to specify the callback function for + * reporting the sensor data. For details, see {@link Sensor_Subscriber}. + * @return Returns SENSOR_SUCCESS if the operation is successful; + * returns an error code defined in {@link Sensor_Result} otherwise. + * @permission ohos.permission.ACCELEROMETER or ohos.permission.GYROSCOPE or + * ohos.permission.ACTIVITY_MOTION or ohos.permission.READ_HEALTH_DATA + * + * @since 11 + */ +Sensor_Result OH_Sensor_Unsubscribe(const Sensor_SubscriptionId *id, const Sensor_Subscriber *subscriber); +#ifdef __cplusplus +} +#endif +#endif // OH_SENSOR_H \ No newline at end of file diff --git a/sensors/sensor/oh_sensor_type.h b/sensors/sensor/oh_sensor_type.h new file mode 100644 index 0000000000000000000000000000000000000000..16f05c98c9d6d707915e8564bc2a7847b6d3743e --- /dev/null +++ b/sensors/sensor/oh_sensor_type.h @@ -0,0 +1,496 @@ +/* + * Copyright (c) 2023 Huawei Device 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. + */ + +/** + * @addtogroup Sensor + * @{ + * + * @brief Provides APIs to define common sensor attributes. + * + * @since 11 + */ + +/** + * @file oh_sensor_type.h + * + * @brief Declares the common sensor attributes. + * @library libohsensor.so + * @syscap SystemCapability.Sensors.Sensor + * @since 11 + */ + +#ifndef OH_SENSOR_TYPE_H +#define OH_SENSOR_TYPE_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Enumerates the sensor types. + * + * @since 11 + */ +typedef enum Sensor_Type { + /** + * Acceleration sensor. + * @since 11 + */ + SENSOR_TYPE_ACCELEROMETER = 1, + /** + * Gyroscope sensor. + * @since 11 + */ + SENSOR_TYPE_GYROSCOPE = 2, + /** + * Ambient light sensor. + * @since 11 + */ + SENSOR_TYPE_AMBIENT_LIGHT = 5, + /** + * Magnetic field sensor. + * @since 11 + */ + SENSOR_TYPE_MAGNETIC_FIELD = 6, + /** + * Barometer sensor. + * @since 11 + */ + SENSOR_TYPE_BAROMETER = 8, + /** + * Hall effect sensor. + * @since 11 + */ + SENSOR_TYPE_HALL = 10, + /** + * Proximity sensor. + * @since 11 + */ + SENSOR_TYPE_PROXIMITY = 12, + /** + * Orientation sensor. + * @since 11 + */ + SENSOR_TYPE_ORIENTATION = 256, + /** + * Gravity sensor. + * @since 11 + */ + SENSOR_TYPE_GRAVITY = 257, + /** + * Rotation vector sensor. + * @since 11 + */ + SENSOR_TYPE_ROTATION_VECTOR = 259, + /** + * Pedometer detection sensor. + * @since 11 + */ + SENSOR_TYPE_PEDOMETER_DETECTION = 265, + /** + * Pedometer sensor. + * @since 11 + */ + SENSOR_TYPE_PEDOMETER = 266, + /** + * Heart rate sensor. + * @since 11 + */ + SENSOR_TYPE_HEART_RATE = 278, +} Sensor_Type; + +/** + * @brief Enumerates the sensor result codes. + * + * @since 11 + */ +typedef enum Sensor_Result { + /** + * The operation is successful. + * @since 11 + */ + SENSOR_SUCCESS = 0, + /** + * Permission verification failed. + * @since 11 + */ + SENSOR_PERMISSION_DENIED = 201, + /** + * Parameter check failed. For example, a mandatory parameter is not passed in, + * or the parameter type passed in is incorrect. + * @since 11 + */ + SENSOR_PARAMETER_ERROR = 401, + /** + * The sensor service is abnormal. + * @since 11 + */ + SENSOR_SERVICE_EXCEPTION = 14500101, +} Sensor_Result; + +/** + * @brief Enumerates the accuracy levels of data reported by a sensor. + * + * @since 11 + */ +typedef enum Sensor_Accuracy { + /** + * The sensor data is unreliable. It is possible that the sensor does not contact with the device to measure. + * @since 11 + */ + SENSOR_ACCURACY_UNRELIABLE = 0, + /** + * The sensor data is at a low accuracy level. The data must be calibrated based on + * the environment before being used. + * @since 11 + */ + SENSOR_ACCURACY_LOW = 1, + /** + * The sensor data is at a medium accuracy level. You are advised to calibrate the data + * based on the environment before using it. + * @since 11 + */ + SENSOR_ACCURACY_MEDIUM = 2, + /** + * The sensor data is at a high accuracy level. The data can be used directly. + * @since 11 + */ + SENSOR_ACCURACY_HIGH = 3 +} Sensor_Accuracy; + +/** + * @brief Defines the sensor information. + * @since 11 + */ +typedef struct Sensor_Info Sensor_Info; + +/** + * @brief Creates an array of {@link Sensor_Info} instances with the given number. + * + * @param count - Number of {@link Sensor_Info} instances to create. + * @return Returns the double pointer to the array of {@link Sensor_Info} instances + * if the operation is successful; + * returns NULL otherwise. + * @since 11 + */ +Sensor_Info **OH_Sensor_CreateInfos(uint32_t count); + +/** + * @brief Destroys an array of {@link Sensor_Info} instances and reclaims memory. + * + * @param sensors - Double pointer to the array of {@link Sensor_Info} instances. + * @param count - Number of {@link Sensor_Info} instances to destroy. + * @return Returns SENSOR_SUCCESS if the operation is successful; + * returns an error code defined in {@link Sensor_Result} otherwise. + * @since 11 + */ +int32_t OH_Sensor_DestroyInfos(Sensor_Info **sensors, uint32_t count); + +/** + * @brief Obtains the sensor name. + * + * @param sensor - Pointer to the sensor information. + * @param sensorName - Pointer to the sensor name. + * @param length - Pointer to the length, in bytes. + * @return Returns SENSOR_SUCCESS if the operation is successful; + * returns an error code defined in {@link Sensor_Result} otherwise. + * @since 11 + */ +int32_t OH_SensorInfo_GetName(Sensor_Info* sensor, char *sensorName, uint32_t *length); + +/** + * @brief Obtains the sensor's vendor name. + * + * @param sensor - Pointer to the sensor information. + * @param vendorName - Pointer to the vendor name. + * @param length - Pointer to the length, in bytes. + * @return Returns SENSOR_SUCCESS if the operation is successful; + * returns an error code defined in {@link Sensor_Result} otherwise. + * @since 11 + */ +int32_t OH_SensorInfo_GetVendorName(Sensor_Info* sensor, char *vendorName, uint32_t *length); + +/** + * @brief Obtains the sensor type. + * + * @param sensor - Pointer to the sensor information. + * @param sensorType - Pointer to the sensor type. + * @return Returns SENSOR_SUCCESS if the operation is successful; + * returns an error code defined in {@link Sensor_Result} otherwise. + * @since 11 + */ +int32_t OH_SensorInfo_GetType(Sensor_Info* sensor, Sensor_Type *sensorType); + +/** + * @brief Obtains the sensor resolution. + * + * @param sensor - Pointer to the sensor information. + * @param resolution - Pointer to the sensor resolution. + * @return Returns SENSOR_SUCCESS if the operation is successful; + * returns an error code defined in {@link Sensor_Result} otherwise. + * @since 11 + */ +int32_t OH_SensorInfo_GetResolution(Sensor_Info* sensor, float *resolution); + +/** + * @brief Obtains the minimum data reporting interval of a sensor. + * + * @param sensor - Pointer to the sensor information. + * @param minSamplingInterval - Pointer to the minimum data reporting interval, in nanoseconds. + * @return Returns SENSOR_SUCCESS if the operation is successful; + * returns an error code defined in {@link Sensor_Result} otherwise. + * @since 11 + */ +int32_t OH_SensorInfo_GetMinSamplingInterval(Sensor_Info* sensor, int64_t *minSamplingInterval); + +/** + * @brief Obtains the maximum data reporting interval of a sensor. + * + * @param sensor - Pointer to the sensor information. + * @param maxSamplingInterval - Pointer to the maximum data reporting interval, in nanoseconds. + * @return Returns SENSOR_SUCCESS if the operation is successful; + * returns an error code defined in {@link Sensor_Result} otherwise. + * @since 11 + */ +int32_t OH_SensorInfo_GetMaxSamplingInterval(Sensor_Info* sensor, int64_t *maxSamplingInterval); + +/** + * @brief Defines the sensor data information. + * @since 11 + */ +typedef struct Sensor_Event Sensor_Event; + +/** + * @brief Obtains the sensor type. + * + * @param Sensor_Event - Pointer to the sensor data information. + * @param sensorType - Pointer to the sensor type. + * @return Returns SENSOR_SUCCESS if the operation is successful; + * returns an error code defined in {@link Sensor_Result} otherwise. + * @since 11 + */ +int32_t OH_SensorEvent_GetType(Sensor_Event* Sensor_Event, Sensor_Type *sensorType); + +/** + * @brief Obtains the timestamp of sensor data. + * + * @param Sensor_Event - Pointer to the sensor data information. + * @param timestamp - Pointer to the timestamp. + * @return Returns SENSOR_SUCCESS if the operation is successful; + * returns an error code defined in {@link Sensor_Result} otherwise. + * @since 11 + */ +int32_t OH_SensorEvent_GetTimestamp(Sensor_Event* Sensor_Event, int64_t *timestamp); + +/** + * @brief Obtains the accuracy of sensor data. + * + * @param Sensor_Event - Pointer to the sensor data information. + * @param accuracy - Pointer to the accuracy. + * @return Returns SENSOR_SUCCESS if the operation is successful; + * returns an error code defined in {@link Sensor_Result} otherwise. + * @since 11 + */ +int32_t OH_SensorEvent_GetAccuracy(Sensor_Event* Sensor_Event, Sensor_Accuracy *accuracy); + +/** + * @brief Obtains sensor data. The data length and content depend on the sensor type. + * The format of the sensor data reported is as follows: + * SENSOR_TYPE_ACCELEROMETER: data[0], data[1], and data[2], indicating the acceleration around + * the x, y, and z axes of the device, respectively, in m/s2. + * SENSOR_TYPE_GYROSCOPE: data[0], data[1], and data[2], indicating the angular velocity of rotation around + * the x, y, and z axes of the device, respectively, in rad/s. + * SENSOR_TYPE_AMBIENT_LIGHT: data[0], indicating the ambient light intensity, in lux. + * SENSOR_TYPE_MAGNETIC_FIELD: data[0], data[1], and data[2], indicating the magnetic field strength around + * the x, y, and z axes of the device, respectively, in μT. + * SENSOR_TYPE_BAROMETER: data[0], indicating the atmospheric pressure, in hPa. + * SENSOR_TYPE_HALL: data[0], indicating the opening/closing state of the flip cover. The value 0 means that + * the flip cover is opened, and a value greater than 0 means that the flip cover is closed. + * SENSOR_TYPE_PROXIMITY: data[0], indicates the approaching state. The value 0 means the two objects are close + * to each other, and a value greater than 0 means that they are far away from each other. + * SENSOR_TYPE_ORIENTATION: data[0], data[1], and data[2], indicating the rotation angles of a device around + * the z, x, and y axes, respectively, in degree. + * SENSOR_TYPE_GRAVITY: data[0], data[1], and data[2], indicating the gravitational acceleration around + * the x, y, and z axes of a device, respectively, in m/s2. + * SENSOR_TYPE_ROTATION_VECTOR: data[0], data[1] and data[2], indicating the rotation angles of a device around + * the x, y, and z axes, respectively, in degree. data[3] indicates the rotation vector. + * SENSOR_TYPE_PEDOMETER_DETECTION: data[0], indicating the pedometer detection status. + * The value 1 means that the number of detected steps changes. + * SENSOR_TYPE_PEDOMETER: data[0], indicating the number of steps a user has walked. + * SENSOR_TYPE_HEART_RATE: data[0], indicating the heart rate value. + * + * @param Sensor_Event - Pointer to the sensor data information. + * @param data - Double pointer to the sensor data. + * @param length - Pointer to the array length. + * @return Returns SENSOR_SUCCESS if the operation is successful; + * returns an error code defined in {@link Sensor_Result} otherwise. + * @since 11 + */ +int32_t OH_SensorEvent_GetData(Sensor_Event* Sensor_Event, float **data, uint32_t *length); + +/** + * @brief Defines the sensor subscription ID, which uniquely identifies a sensor. + * @since 11 + */ +typedef struct Sensor_SubscriptionId Sensor_SubscriptionId; + +/** + * @brief Creates a {@link Sensor_SubscriptionId} instance. + * + * @return Returns the pointer to the {@link Sensor_SubscriptionId} instance if the operation is successful; + * returns NULL otherwise. + * @since 11 + */ +Sensor_SubscriptionId *OH_Sensor_CreateSubscriptionId(void); + +/** + * @brief Destroys a {@link Sensor_SubscriptionId} instance and reclaims memory. + * + * @param id - Pointer to the {@link Sensor_SubscriptionId} instance. + * @return Returns SENSOR_SUCCESS if the operation is successful; + * returns an error code defined in {@link Sensor_Result} otherwise. + * @since 11 + */ +int32_t OH_Sensor_DestroySubscriptionId(Sensor_SubscriptionId *id); + +/** + * @brief Obtains the sensor type. + * + * @param id - Pointer to the sensor subscription ID. + * @param id - Pointer to the sensor type. + * @return Returns SENSOR_SUCCESS if the operation is successful; + * returns an error code defined in {@link Sensor_Result} otherwise. + * @since 11 + */ +int32_t OH_SensorSubscriptionId_GetType(Sensor_SubscriptionId* id, Sensor_Type *sensorType); + +/** + * @brief Sets the sensor type. + * + * @param id - Pointer to the sensor subscription ID. + * @param sensorType - Sensor type to set. + * @return Returns SENSOR_SUCCESS if the operation is successful; + * returns an error code defined in {@link Sensor_Result} otherwise. + * @since 11 + */ +int32_t OH_SensorSubscriptionId_SetType(Sensor_SubscriptionId* id, const Sensor_Type sensorType); + +/** + * @brief Defines the sensor subscription attribute. + * @since 11 + */ +typedef struct Sensor_SubscriptionAttribute Sensor_SubscriptionAttribute; + +/** + * @brief Creates a {@link Sensor_SubscriptionAttribute} instance. + * + * @return Returns the pointer to the {@link Sensor_SubscriptionAttribute} instance if the operation is successful; + * returns NULL otherwise. + * @since 11 + */ +Sensor_SubscriptionAttribute *OH_Sensor_CreateSubscriptionAttribute(void); + +/** + * @brief Destroys a {@link Sensor_SubscriptionAttribute} instance and reclaims memory. + * + * @param attribute - Pointer to the {@link Sensor_SubscriptionAttribute} instance. + * @return Returns SENSOR_SUCCESS if the operation is successful; + * returns an error code defined in {@link Sensor_Result} otherwise. + * @since 11 + */ +int32_t OH_Sensor_DestroySubscriptionAttribute(Sensor_SubscriptionAttribute *attribute); + +/** + * @brief Sets the sensor data reporting interval. + * + * @param attribute - Pointer to the sensor subscription attribute. + * @param samplingInterval - Data reporting interval to set, in nanoseconds. + * @return Returns SENSOR_SUCCESS if the operation is successful; + * returns an error code defined in {@link Sensor_Result} otherwise. + * @since 11 + */ +int32_t OH_SensorSubscriptionAttribute_SetSamplingInterval(Sensor_SubscriptionAttribute* attribute, + const int64_t samplingInterval); + +/** + * @brief Obtains the sensor data reporting interval. + * + * @param attribute - Pointer to the sensor subscription attribute. + * @param samplingInterval - Pointer to the data reporting interval, in nanoseconds. + * @return Returns SENSOR_SUCCESS if the operation is successful; + * returns an error code defined in {@link Sensor_Result} otherwise. + * @since 11 + */ +int32_t OH_SensorSubscriptionAttribute_GetSamplingInterval(Sensor_SubscriptionAttribute* attribute, + int64_t *samplingInterval); + +/** + * @brief Defines the callback function used to report sensor data. + * @since 11 + */ +typedef void (*Sensor_EventCallback)(Sensor_Event *event); + +/** + * @brief Defines the sensor subscriber information. + * @since 11 + */ +typedef struct Sensor_Subscriber Sensor_Subscriber; + +/** + * @brief Creates a {@link Sensor_Subscriber} instance. + * + * @return Returns the pointer to the {@link Sensor_Subscriber} instance + * if the operation is successful; returns NULL otherwise. + * @since 11 + */ +Sensor_Subscriber *OH_Sensor_CreateSubscriber(void); + +/** + * @brief Destroys a {@link Sensor_Subscriber} instance and reclaims memory. + * + * @param subscriber - Pointer to the {@link Sensor_Subscriber} instance. + * @return Returns SENSOR_SUCCESS if the operation is successful; + * returns an error code defined in {@link Sensor_Result} otherwise. + * @since 11 + */ +int32_t OH_Sensor_DestroySubscriber(Sensor_Subscriber *subscriber); + +/** + * @brief Sets a callback function to report sensor data. + * + * @param subscriber - Pointer to the sensor subscriber information. + * @param callback - Callback function to set. + * @return Returns SENSOR_SUCCESS if the operation is successful; + * returns an error code defined in {@link Sensor_Result} otherwise. + * @since 11 + */ +int32_t OH_SensorSubscriber_SetCallback(Sensor_Subscriber* subscriber, const Sensor_EventCallback callback); + +/** + * @brief Obtains the callback function used to report sensor data. + * + * @param subscriber - Pointer to the sensor subscriber information. + * @param callback - Pointer to the callback function. + * @return Returns SENSOR_SUCCESS if the operation is successful; + * returns an error code defined in {@link Sensor_Result} otherwise. + * @since 11 + */ +int32_t OH_SensorSubscriber_GetCallback(Sensor_Subscriber* subscriber, Sensor_EventCallback *callback); +#ifdef __cplusplus +} +#endif +#endif // OH_SENSOR_TYPE_H \ No newline at end of file