From aeb5e1c1e789a78c3530fc15d6e466616c864e8b Mon Sep 17 00:00:00 2001 From: hellohyh001 Date: Tue, 28 Nov 2023 07:50:58 +0000 Subject: [PATCH 01/16] upadte Signed-off-by: hellohyh001 Change-Id: I1074affba63c64a780326bd7f318cf158a30b4ef --- bundle.json | 12 + frameworks/native/BUILD.gn | 47 +- .../native/include/native_sensor_impl.h | 61 +++ frameworks/native/src/native_sensor.cpp | 361 +++++++++++++ interfaces/kits/c/BUILD.gn | 35 ++ interfaces/kits/c/libsensor.ndk.json | 83 +++ interfaces/kits/c/native_sensor.h | 79 +++ interfaces/kits/c/native_sensor_type.h | 488 ++++++++++++++++++ test/unittest/interfaces/kits/BUILD.gn | 49 ++ .../interfaces/kits/sensor_native_test.cpp | 414 +++++++++++++++ 10 files changed, 1626 insertions(+), 3 deletions(-) create mode 100644 frameworks/native/include/native_sensor_impl.h create mode 100644 frameworks/native/src/native_sensor.cpp create mode 100644 interfaces/kits/c/BUILD.gn create mode 100644 interfaces/kits/c/libsensor.ndk.json create mode 100644 interfaces/kits/c/native_sensor.h create mode 100644 interfaces/kits/c/native_sensor_type.h create mode 100644 test/unittest/interfaces/kits/BUILD.gn create mode 100755 test/unittest/interfaces/kits/sensor_native_test.cpp diff --git a/bundle.json b/bundle.json index 94ec4a33..baf2e157 100755 --- a/bundle.json +++ b/bundle.json @@ -40,6 +40,7 @@ "fwk_group": [ "//base/sensors/sensor/frameworks/js/napi:sensor_js_target", "//base/sensors/sensor/frameworks/native:sensor_target", + "//base/sensors/sensor/frameworks/native:sensor_native", "//base/sensors/sensor/utils:sensor_utils_target" ], "service_group": [ @@ -57,10 +58,21 @@ ], "header_base": "//base/sensors/sensor/interfaces/inner_api" } + }, + { + "name": "//base/sensors/sensor/interfaces/kits/c:libsensor_ndk", + "header": { + "header_files": [ + "native_sensor_type.h", + "native_sensor.h" + ], + "header_base": "//base/sensors/sensor/interfaces/kits/c" + } } ], "test": [ "//base/sensors/sensor/test/unittest/interfaces/js:unittest", + "//base/sensors/sensor/test/unittest/interfaces/kits:unittest", "//base/sensors/sensor/test/fuzztest/interfaces:fuzztest", "//base/sensors/sensor/test/unittest/interfaces/inner_api:unittest", "//base/sensors/sensor/test/fuzztest/services:fuzztest" diff --git a/frameworks/native/BUILD.gn b/frameworks/native/BUILD.gn index d93289d1..8f62ccc5 100644 --- a/frameworks/native/BUILD.gn +++ b/frameworks/native/BUILD.gn @@ -14,7 +14,7 @@ import("//build/ohos.gni") import("./../../sensor.gni") -ohos_shared_library("libsensor_native") { +ohos_shared_library("libsensor_client") { sources = [ "src/fd_listener.cpp", "src/sensor_agent_proxy.cpp", @@ -102,7 +102,7 @@ ohos_shared_library("sensor_interface_native") { } deps = [ - "$SUBSYSTEM_DIR/frameworks/native:libsensor_native", + "$SUBSYSTEM_DIR/frameworks/native:libsensor_client", "$SUBSYSTEM_DIR/frameworks/native:libsensor_ndk", ] @@ -119,9 +119,50 @@ ohos_shared_library("sensor_interface_native") { subsystem_name = "sensors" } +config("sensor_native_public_config") { + include_dirs = [ + "$SUBSYSTEM_DIR/interfaces/kits/c", + ] +} + +ohos_shared_library("sensor_native") { + sources = [ "src/native_sensor.cpp" ] + + defines = [ "API_EXPORT=__attribute__((visibility (\"default\")))" ] + + configs = [ ":sensor_private_config" ] + public_configs = [ ":sensor_native_public_config" ] + + branch_protector_ret = "pac_ret" + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } + + deps = [ + "$SUBSYSTEM_DIR/frameworks/native:libsensor_client", + "$SUBSYSTEM_DIR/frameworks/native:libsensor_ndk", + "$SUBSYSTEM_DIR/frameworks/native:sensor_interface_native", + "$SUBSYSTEM_DIR/utils/ipc:libsensor_ipc", + ] + + external_deps = [ + "c_utils:utils", + "eventhandler:libeventhandler", + "hilog:libhilog", + "ipc:ipc_core", + "safwk:system_ability_fwk", + ] + + relative_install_dir = "ndk" + part_name = "sensor" + subsystem_name = "sensors" +} + group("sensor_target") { deps = [ - ":libsensor_native", + ":libsensor_client", ":sensor_interface_native", ] } diff --git a/frameworks/native/include/native_sensor_impl.h b/frameworks/native/include/native_sensor_impl.h new file mode 100644 index 00000000..e2c88327 --- /dev/null +++ b/frameworks/native/include/native_sensor_impl.h @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2021-2022 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. + */ + +#ifndef NATIVE_SENSOR_IMPL +#define NATIVE_SENSOR_IMPL + +#include "native_sensor.h" +#include "sensor_agent_type.h" + +struct Sensor_Sensor { + char sensorName[NAME_MAX_LEN]; /**< Sensor name */ + char vendorName[NAME_MAX_LEN]; /**< Sensor vendor */ + char firmwareVersion[VERSION_MAX_LEN]; /**< Sensor firmware version */ + char hardwareVersion[VERSION_MAX_LEN]; /**< Sensor hardware version */ + int32_t sensorTypeId = -1; /**< Sensor type ID */ + int32_t sensorId = -1; /**< Sensor ID */ + float maxRange = 0.0; /**< Maximum measurement range of the sensor */ + float precision = 0.0; /**< Sensor accuracy */ + float power = 0.0; /**< Sensor power */ + int64_t minSamplePeriod = -1; /**< Minimum sample period allowed, in ns */ + int64_t maxSamplePeriod = -1; /**< Maximum sample period allowed, in ns */ +}; + +struct Sensor_SubscribeAttribute { + int64_t samplingInterval = -1; + int64_t reportInterval = -1; +}; + +struct Sensor_SensorSubscribeId { + int32_t sensorType = -1; +}; + +struct Sensor_SubscribeUser { + char name[NAME_MAX_LEN]; + Sensor_RecordSensorCallback callback; + UserData *userData = nullptr; +}; + +struct Sensor_SensorEvent { + int32_t sensorTypeId = -1; + int32_t version = -1; + int64_t timestamp = -1; + int32_t option = -1; + int32_t mode = -1; + uint8_t *data = nullptr; + uint32_t dataLen = 0; +}; +#endif // NATIVE_SENSOR_IMPL + diff --git a/frameworks/native/src/native_sensor.cpp b/frameworks/native/src/native_sensor.cpp new file mode 100644 index 00000000..91274d7c --- /dev/null +++ b/frameworks/native/src/native_sensor.cpp @@ -0,0 +1,361 @@ +/* + * Copyright (c) 2021-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. + */ + +#include "native_sensor.h" + +#include "i_sensor_service.h" +#include "native_sensor_impl.h" +#include "securec.h" +#include "sensor_agent.h" +#include "sensor_errors.h" + +using OHOS::HiviewDFX::HiLog; +using OHOS::HiviewDFX::HiLogLabel; +namespace { +const HiLogLabel LABEL = {LOG_CORE, OHOS::Sensors::SENSOR_LOG_DOMAIN, "SensorCapiAPI"}; +const uint32_t FLOAT_SIZE= 4; +} + +Sensor_Result OH_Sensor_GetAllSensors(Sensor_Sensor **sensors, uint32_t *count) +{ + if (count == nullptr) { + SEN_HILOGE("Parameter error"); + return SENSOR_PARAMETER_ERROR; + } + SensorInfo *sensorInfo = nullptr; + int32_t sensorCount = -1; + int32_t ret = GetAllSensors(&sensorInfo, &sensorCount); + if (ret != SENSOR_SUCCESS || sensorCount < 0) { + SEN_HILOGE("GetAllSensors fail"); + return SENSOR_SERVICE_EXCEPTION; + } + if (sensors == nullptr) { + *count = static_cast(sensorCount); + SEN_HILOGD("Sensor count: %{public}d", *count); + return SENSOR_SUCCESS; + } + if (static_cast(sensorCount) != *count) { + SEN_HILOGE("Count:%{public}d is invalid, should be:%{public}d", *count, sensorCount); + return SENSOR_PARAMETER_ERROR; + } + for (int32_t i = 0; i < sensorCount; ++i) { + if (sensors[i] == nullptr) { + SEN_HILOGE("Sensor is null, i:%{public}d", i); + return SENSOR_PARAMETER_ERROR; + } + errno_t result = strcpy_s(sensors[i]->sensorName, NAME_MAX_LEN, sensorInfo[i].sensorName); + CHKCR(result == EOK, SENSOR_SERVICE_EXCEPTION); + result = strcpy_s(sensors[i]->vendorName, NAME_MAX_LEN, sensorInfo[i].vendorName); + CHKCR(result == EOK, SENSOR_SERVICE_EXCEPTION); + result = strcpy_s(sensors[i]->firmwareVersion, VERSION_MAX_LEN, sensorInfo[i].firmwareVersion); + CHKCR(result == EOK, SENSOR_SERVICE_EXCEPTION); + result = strcpy_s(sensors[i]->hardwareVersion, VERSION_MAX_LEN, sensorInfo[i].hardwareVersion); + CHKCR(result == EOK, SENSOR_SERVICE_EXCEPTION); + sensors[i]->sensorTypeId = sensorInfo[i].sensorTypeId; + sensors[i]->sensorId = sensorInfo[i].sensorId; + sensors[i]->maxRange = sensorInfo[i].maxRange; + sensors[i]->precision = sensorInfo[i].precision; + sensors[i]->power = sensorInfo[i].power; + sensors[i]->minSamplePeriod = sensorInfo[i].minSamplePeriod; + sensors[i]->maxSamplePeriod = sensorInfo[i].maxSamplePeriod; + } + return SENSOR_SUCCESS; +} + +Sensor_Sensor **OH_Sensor_CreateSensors(uint32_t count) +{ + auto sensors = new Sensor_Sensor *[count]; + for (uint32_t i = 0; i < count; ++i) { + sensors[i] = new Sensor_Sensor(); + } + return sensors; +} + +int32_t OH_Sensor_DestroySensors(Sensor_Sensor **sensors, uint32_t count) +{ + for (uint32_t i = 0; i < count; ++i) { + delete sensors[i]; + } + delete[] sensors; + sensors = nullptr; + return SENSOR_SUCCESS; +} + +int32_t OH_Sensor_GetSensorName(Sensor_Sensor* sensor, char *sensorName, uint32_t *length) +{ + if (sensor == nullptr || sensorName == nullptr || length == nullptr) { + SEN_HILOGE("Parameter error"); + return SENSOR_PARAMETER_ERROR; + } + uint32_t nameLen = strlen(sensor->sensorName); + if (nameLen == 0 || *length <= nameLen) { + SEN_HILOGE("Parameter error, length:%{public}d is small, should big than:%{public}d", *length, nameLen); + return SENSOR_PARAMETER_ERROR; + } + errno_t result = strcpy_s(sensorName, *length, sensor->sensorName); + if (result != EOK) { + SEN_HILOGE("strcpy_s failed, result is %{public}d", result); + return SENSOR_SERVICE_EXCEPTION; + } + return SENSOR_SUCCESS; +} + +int32_t OH_Sensor_GetVendorName(Sensor_Sensor* sensor, char *vendorName, uint32_t *length) +{ + if (sensor == nullptr || vendorName == nullptr || length == nullptr) { + SEN_HILOGE("Parameter error"); + return SENSOR_PARAMETER_ERROR; + } + uint32_t nameLen = strlen(sensor->vendorName); + if (nameLen == 0 || *length <= nameLen) { + SEN_HILOGE("Parameter error, length:%{public}d is small, should big than:%{public}d", *length, nameLen); + return SENSOR_PARAMETER_ERROR; + } + errno_t result = strcpy_s(vendorName, *length, sensor->vendorName); + if (result != EOK) { + SEN_HILOGE("strcpy_s failed, result is %{public}d", result); + return SENSOR_SERVICE_EXCEPTION; + } + return SENSOR_SUCCESS; +} + +int32_t OH_Sensor_GetSensorType(Sensor_Sensor* sensor, Sensor_SensorType *sensorType) +{ + if (sensor == nullptr || sensorType == nullptr) { + SEN_HILOGE("Parameter error"); + return SENSOR_PARAMETER_ERROR; + } + *sensorType = static_cast(sensor->sensorTypeId); + return SENSOR_SUCCESS; +} + +int32_t OH_Sensor_GetSensorResolution(Sensor_Sensor* sensor, float *resolution) +{ + if (sensor == nullptr || resolution == nullptr) { + SEN_HILOGE("Parameter error"); + return SENSOR_PARAMETER_ERROR; + } + *resolution = sensor->precision; + return SENSOR_SUCCESS; +} + +int32_t OH_Sensor_GetSensorMinSamplePeriod(Sensor_Sensor* sensor, int64_t *minSamplePeriod) +{ + if (sensor == nullptr || minSamplePeriod == nullptr) { + SEN_HILOGE("Parameter error"); + return SENSOR_PARAMETER_ERROR; + } + *minSamplePeriod = sensor->minSamplePeriod; + return SENSOR_SUCCESS; +} + +int32_t OH_Sensor_GetSensorMaxSamplePeriod(Sensor_Sensor* sensor, int64_t *maxSamplePeriod) +{ + if (sensor == nullptr || maxSamplePeriod == nullptr) { + SEN_HILOGE("Parameter error"); + return SENSOR_PARAMETER_ERROR; + } + *maxSamplePeriod = sensor->maxSamplePeriod; + return SENSOR_SUCCESS; +} + +Sensor_Result OH_Sensor_SubscribeSensor(const Sensor_SensorSubscribeId *id, + const Sensor_SubscribeAttribute *attribute, const Sensor_SubscribeUser *user) +{ + if (id == nullptr || attribute == nullptr || user == nullptr) { + SEN_HILOGE("Parameter error"); + return SENSOR_PARAMETER_ERROR; + } + const SensorUser *sensorUser = reinterpret_cast(user); + int32_t sensorType = id->sensorType; + int32_t ret = SubscribeSensor(sensorType, sensorUser); + if (ret != SENSOR_SUCCESS) { + SEN_HILOGE("SubscribeSensor failed, %{public}d", ret); + return SENSOR_SERVICE_EXCEPTION; + } + int64_t samplingInterval = attribute->samplingInterval; + ret = SetBatch(sensorType, sensorUser, samplingInterval, samplingInterval); + if (ret != SENSOR_SUCCESS) { + SEN_HILOGE("SetBatch failed, %{public}d", ret); + return SENSOR_SERVICE_EXCEPTION; + } + return static_cast(ActivateSensor(sensorType, sensorUser)); +} + +Sensor_Result OH_Sensor_UnsubscribeSensor(const Sensor_SensorSubscribeId *subscribeId, + const Sensor_SubscribeUser *user) +{ + if (subscribeId == nullptr || user == nullptr) { + SEN_HILOGE("Parameter error"); + return SENSOR_PARAMETER_ERROR; + } + const SensorUser *sensorUser = reinterpret_cast(user); + int32_t sensorType = subscribeId->sensorType; + int32_t ret = DeactivateSensor(sensorType, sensorUser); + if (ret != SENSOR_SUCCESS) { + SEN_HILOGE("SetBatch failed, %{public}d", ret); + return SENSOR_SERVICE_EXCEPTION; + } + return static_cast(UnsubscribeSensor(sensorType, sensorUser)); +} + +int32_t OH_Sensor_GetEventSensorType(Sensor_SensorEvent* sensorEvent, Sensor_SensorType *sensorType) +{ + if (sensorEvent == nullptr || sensorType == nullptr) { + SEN_HILOGE("Parameter error"); + return SENSOR_PARAMETER_ERROR; + } + *sensorType = static_cast(sensorEvent->sensorTypeId); + return SENSOR_SUCCESS; +} + +int32_t OH_Sensor_GetEventTimestamp(Sensor_SensorEvent* sensorEvent, int64_t *timestamp) +{ + if (sensorEvent == nullptr || timestamp == nullptr) { + SEN_HILOGE("Parameter error"); + return SENSOR_PARAMETER_ERROR; + } + *timestamp = sensorEvent->timestamp; + return SENSOR_SUCCESS; +} + +int32_t OH_Sensor_GetEventAccuracy(Sensor_SensorEvent* sensorEvent, Sensor_SensorAccuracy *accuracy) +{ + if (sensorEvent == nullptr || accuracy == nullptr) { + SEN_HILOGE("Parameter error"); + return SENSOR_PARAMETER_ERROR; + } + *accuracy = static_cast(sensorEvent->option); + return SENSOR_SUCCESS; +} + +int32_t OH_Sensor_GetSensorData(Sensor_SensorEvent* sensorEvent, float **data, uint32_t *length) +{ + if (sensorEvent == nullptr || data == nullptr || length == nullptr) { + SEN_HILOGE("Parameter error"); + return SENSOR_PARAMETER_ERROR; + } + *data = reinterpret_cast(sensorEvent->data); + *length = sensorEvent->dataLen / FLOAT_SIZE; + return SENSOR_SUCCESS; +} + +int32_t OH_Sensor_GetSubscribeSensorType(Sensor_SensorSubscribeId* subscribeId, Sensor_SensorType *sensorType) +{ + if (subscribeId == nullptr || sensorType == nullptr) { + SEN_HILOGE("Parameter error"); + return SENSOR_PARAMETER_ERROR; + } + *sensorType = static_cast(subscribeId->sensorType); + return SENSOR_SUCCESS; +} + +int32_t OH_Sensor_SetSubscribeSensorType(Sensor_SensorSubscribeId* subscribeId, const Sensor_SensorType sensorType) +{ + if (subscribeId == nullptr) { + SEN_HILOGE("Parameter error"); + return SENSOR_PARAMETER_ERROR; + } + subscribeId->sensorType = sensorType; + return SENSOR_SUCCESS; +} + +int32_t OH_Sensor_SetSamplingInterval(Sensor_SubscribeAttribute* attribute, const int64_t samplingInterval) +{ + if (attribute == nullptr || samplingInterval < 0) { + SEN_HILOGE("Parameter error"); + return SENSOR_PARAMETER_ERROR; + } + attribute->samplingInterval = samplingInterval; + return SENSOR_SUCCESS; +} + +int32_t OH_Sensor_GetSamplingInterval(Sensor_SubscribeAttribute* attribute, int64_t *samplingInterval) +{ + if (attribute == nullptr || samplingInterval == nullptr) { + SEN_HILOGE("Parameter error"); + return SENSOR_PARAMETER_ERROR; + } + *samplingInterval = attribute->samplingInterval; + return SENSOR_SUCCESS; +} + +int32_t OH_Sensor_SetSensorCallback(Sensor_SubscribeUser* user, const Sensor_RecordSensorCallback callback) +{ + if (user == nullptr || callback == nullptr) { + SEN_HILOGE("Parameter error"); + return SENSOR_PARAMETER_ERROR; + } + user->callback = callback; + return SENSOR_SUCCESS; +} + +int32_t OH_Sensor_GetSensorCallback(Sensor_SubscribeUser* user, Sensor_RecordSensorCallback *callback) +{ + if (user == nullptr || callback == nullptr) { + SEN_HILOGE("Parameter error"); + return SENSOR_PARAMETER_ERROR; + } + *callback = user->callback; + return SENSOR_SUCCESS; +} + +Sensor_SensorSubscribeId *OH_Sensor_CreateSubscribeId() +{ + return new (std::nothrow) Sensor_SensorSubscribeId(); +} + +int32_t OH_Sensor_DestroySubscribeId(Sensor_SensorSubscribeId *subscribeId) +{ + if (subscribeId == nullptr) { + SEN_HILOGE("Parameter error"); + return SENSOR_PARAMETER_ERROR; + } + delete subscribeId; + subscribeId = nullptr; + return SENSOR_SUCCESS; +} + +Sensor_SubscribeAttribute *OH_Sensor_CreateAttribute() +{ + return new (std::nothrow) Sensor_SubscribeAttribute(); +} + +int32_t OH_Sensor_DestroyAttribute(Sensor_SubscribeAttribute *attribute) +{ + if (attribute == nullptr) { + SEN_HILOGE("Parameter error"); + return SENSOR_PARAMETER_ERROR; + } + delete attribute; + attribute = nullptr; + return SENSOR_SUCCESS; +} + +Sensor_SubscribeUser *OH_Sensor_CreateUser() +{ + return new (std::nothrow) Sensor_SubscribeUser(); +} + +int32_t OH_Sensor_DestroyUser(Sensor_SubscribeUser *user) +{ + if (user == nullptr) { + SEN_HILOGE("Parameter error"); + return SENSOR_PARAMETER_ERROR; + } + delete user; + user = nullptr; + return SENSOR_SUCCESS; +} \ No newline at end of file diff --git a/interfaces/kits/c/BUILD.gn b/interfaces/kits/c/BUILD.gn new file mode 100644 index 00000000..b8b2a373 --- /dev/null +++ b/interfaces/kits/c/BUILD.gn @@ -0,0 +1,35 @@ +# Copyright (C) 2022 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") +import("./../../../sensor.gni") + +ohos_ndk_headers("sensor_ndk_header") { + dest_dir = "$ndk_headers_out_dir/sensors/sensor" + sources = [ + "./native_sensor.h", + "./native_sensor_type.h", + ] +} + +ohos_ndk_library("libsensor_ndk") { + ndk_description_file = "./libsensor.ndk.json" + output_name = "sensor_native" + min_compact_version = "11" + system_capability = "SystemCapability.Sensors.Sensor" + system_capability_headers = [ + "$ndk_headers_out_dir/sensor/native_sensor.h", + "$ndk_headers_out_dir/sensor/native_sensor_type.h", + ] +} \ No newline at end of file diff --git a/interfaces/kits/c/libsensor.ndk.json b/interfaces/kits/c/libsensor.ndk.json new file mode 100644 index 00000000..98f99149 --- /dev/null +++ b/interfaces/kits/c/libsensor.ndk.json @@ -0,0 +1,83 @@ +[ + { + "name": "OH_Sensor_GetAllSensors" + }, + { + "name": "OH_Sensor_SubscribeSensor" + }, + { + "name": "OH_Sensor_UnsubscribeSensor" + }, + { + "name": "OH_Sensor_GetSensorName" + }, + { + "name": "OH_Sensor_GetVendorName" + }, + { + "name": "OH_Sensor_GetSensorType" + }, + { + "name": "OH_Sensor_GetSensorResolution" + }, + { + "name": "OH_Sensor_GetSensorMinSamplePeriod" + }, + { + "name": "OH_Sensor_GetSensorMaxSamplePeriod" + }, + { + "name": "OH_Sensor_GetEventSensorType" + }, + { + "name": "OH_Sensor_GetEventTimestamp" + }, + { + "name": "OH_Sensor_GetEventAccuracy" + }, + { + "name": "OH_Sensor_GetSensorData" + }, + { + "name": "OH_Sensor_GetSubscribeSensorType" + }, + { + "name": "OH_Sensor_SetSubscribeSensorType" + }, + { + "name": "OH_Sensor_SetSamplingInterval" + }, + { + "name": "OH_Sensor_GetSamplingInterval" + }, + { + "name": "OH_Sensor_SetSensorCallback" + }, + { + "name": "OH_Sensor_GetSensorCallback" + }, + { + "name": "OH_Sensor_CreateSensors" + }, + { + "name": "OH_Sensor_DestroySensors" + }, + { + "name": "OH_Sensor_CreateSubscribeId" + }, + { + "name": "OH_Sensor_DestroySubscribeId" + }, + { + "name": "OH_Sensor_CreateAttribute" + }, + { + "name": "OH_Sensor_DestroyAttribute" + }, + { + "name": "OH_Sensor_CreateUser" + }, + { + "name": "OH_Sensor_DestroyUser" + } +] \ No newline at end of file diff --git a/interfaces/kits/c/native_sensor.h b/interfaces/kits/c/native_sensor.h new file mode 100644 index 00000000..b46ae7fe --- /dev/null +++ b/interfaces/kits/c/native_sensor.h @@ -0,0 +1,79 @@ +/* + * 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 为您提供标准的开放api,以使用传感器的常用功能。比如,您可以调用这些api来获取传感器属性信息、订阅或取消订阅传感器数据等。 + * @since 11 + */ +/** + * @file sensor.h + * + * @brief 声明操作传感器的常用api,用于获取传感器信息、订阅或取消订阅传感器数据等。 + * @library libsensor_native.z.so + * @syscap SystemCapability.Sensors.Sensor + * @since 11 + */ + +#ifndef OH_NATIVE_SENSOR_H +#define OH_NATIVE_SENSOR_H + +#include + +#include "native_sensor_type.h" + +#ifdef __cplusplus +extern "C" { +#endif +/** + * @brief 获取设备上的所有传感器信息。 + * + * @param sensorInfo - 出参,返回设备上的所有传感器信息,详情请参见{@Link Sensor_Sensor}。 + * @param count - 出参,返回设备上的传感器数量。 + * @return 成功返回SENSOR_SUCCESS,否则返回对应的错误码,详情请参见{@Link Sensor_Result}。 + * + * @since 11 + */ +Sensor_Result OH_Sensor_GetAllSensors(Sensor_Sensor **sensors, uint32_t *count); + +/** + * @brief 订阅传感器数据,系统将按照用户指定的上报频率向用户报告传感器数据。 + * + * @param id - 标识要订阅的传感器, 详情请参见{@link Sensor_SensorSubscribeId}。 + * @param attribute - 订阅属性,可用于指定传感器的上报频率等,详情请参见{@Link Sensor_SubscribeAttribute}。 + * @param user - 订阅者信息,用于指定传感器数据回调函数等,详情请参见{@Link Sensor_SubscribeUser}。 + * @return 成功返回SENSOR_SUCCESS,否则返回对应的错误码,详情请参见{@Link Sensor_Result}。 + * + * @since 11 + */ +Sensor_Result OH_Sensor_SubscribeSensor(const Sensor_SensorSubscribeId *subscribeId, const Sensor_SubscribeAttribute *attribute, + const Sensor_SubscribeUser *user); + +/** + * @brief 取消订阅传感器数据。 + * + * @param id - 标识要订阅的传感器, 详情请参见{@link Sensor_SensorSubscribeId}。 + * @param user - 订阅者信息,用于指定传感器数据回调函数等,详情请参见{@Link Sensor_SubscribeUser}。 + * @return 成功返回SENSOR_SUCCESS,否则返回对应的错误码,详情请参见{@Link Sensor_Result}。 + * + * @since 11 + */ +Sensor_Result OH_Sensor_UnsubscribeSensor(const Sensor_SensorSubscribeId *subscribeId, const Sensor_SubscribeUser *user); +#ifdef __cplusplus +} +#endif +#endif // OH_NATIVE_SENSOR_H \ No newline at end of file diff --git a/interfaces/kits/c/native_sensor_type.h b/interfaces/kits/c/native_sensor_type.h new file mode 100644 index 00000000..09ce91ef --- /dev/null +++ b/interfaces/kits/c/native_sensor_type.h @@ -0,0 +1,488 @@ +/* + * 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 为您提供标准的开放api,定义常用传感器属性。 + * + * @since 11 + */ + +/** + * @file native_sensor_type.h + * + * @brief 定义常用传感器属性。 + * @library libohsensor.z.so + * @syscap SystemCapability.Sensors.Sensor + * + * @since 11 + */ + +#ifndef OH_NATIVE_SENSOR_TYPE_H +#define OH_NATIVE_SENSOR_TYPE_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief 传感器类型。 + * @syscap SystemCapability.Sensors.Sensor + * + * @since 11 + */ +typedef enum Sensor_SensorType { + /** + * 加速度传感器 + * @syscap SystemCapability.Sensors.Sensor + * @since 11 + */ + SENSOR_TYPE_ACCELEROMETER = 1, + /** + * 陀螺仪传感测器 + * @syscap SystemCapability.Sensors.Sensor + * @since 11 + */ + SENSOR_TYPE_GYROSCOPE = 2, + /** + * 环境光传感器 + * @syscap SystemCapability.Sensors.Sensor + * @since 11 + */ + SENSOR_TYPE_AMBIENT_LIGHT = 5, + /** + * 地磁传感器 + * @syscap SystemCapability.Sensors.Sensor + * @since 11 + */ + SENSOR_TYPE_MAGNETIC_FIELD = 6, + /** + * 气压计传感器 + * @syscap SystemCapability.Sensors.Sensor + * @since 11 + */ + SENSOR_TYPE_BAROMETER = 8, + /** + * 霍尔传感器 + * @syscap SystemCapability.Sensors.Sensor + * @since 11 + */ + SENSOR_TYPE_HALL = 10, + /** + * 接近光传感器 + * @syscap SystemCapability.Sensors.Sensor + * @since 11 + */ + SENSOR_TYPE_PROXIMITY = 12, + /** + * 方向传感器 + * @syscap SystemCapability.Sensors.Sensor + * @since 11 + */ + SENSOR_TYPE_ORIENTATION = 256, + /** + * 重力传感器 + * @syscap SystemCapability.Sensors.Sensor + * @since 11 + */ + SENSOR_TYPE_GRAVITY = 257, + /** + * 旋转矢量传感器 + * @syscap SystemCapability.Sensors.Sensor + * @since 11 + */ + SENSOR_TYPE_ROTATION_VECTOR = 259, + /** + * 计步器检测传感器 + * @syscap SystemCapability.Sensors.Sensor + * @since 11 + */ + SENSOR_TYPE_PEDOMETER_DETECTION = 265, + /** + * 计步器传感器 + * @syscap SystemCapability.Sensors.Sensor + * @since 11 + */ + SENSOR_TYPE_PEDOMETER = 266, + /** + * 心率传感器 + * @syscap SystemCapability.Sensors.Sensor + * @since 11 + */ + SENSOR_TYPE_HEART_RATE = 278, +} Sensor_SensorType; + +/** + * @brief 定义传感器错误码。 + * @syscap SystemCapability.Sensors.Sensor + * + * @since 11 + */ +typedef enum Sensor_Result { + /** + * 操作成功。 + * @syscap SystemCapability.Sensors.Sensor + * @since 11 + */ + SENSOR_SUCCESS = 0, + /** + * Permission verification failed. + * @syscap SystemCapability.Sensors.Sensor + * @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. + * @syscap SystemCapability.Sensors.Sensor + * @since 11 + */ + SENSOR_PARAMETER_ERROR = 401, + /** + * 传感器服务异常。 + * @syscap SystemCapability.Sensors.Sensor + * @since 11 + */ + SENSOR_SERVICE_EXCEPTION = 14500101, +} Sensor_Result; + +/** + * @brief Enumerates the accuracy levels of data reported by a sensor. + * @syscap SystemCapability.Sensors.Sensor + * + * @since 11 + */ +typedef enum Sensor_SensorAccuracy { + /** + * The sensor data is unreliable. It is possible that the sensor does not contact with the device to measure. + * @syscap SystemCapability.Sensors.Sensor + * @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. + * @syscap SystemCapability.Sensors.Sensor + * @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. + * @syscap SystemCapability.Sensors.Sensor + * @since 11 + */ + SENSOR_ACCURACY_MEDIUM = 2, + /** + * The sensor data is at a high accuracy level. The data can be used directly. + * @syscap SystemCapability.Sensors.Sensor + * @since 11 + */ + SENSOR_ACCURACY_HIGH = 3 +} Sensor_SensorAccuracy; + +/** + * @brief 传感器信息。 + * @syscap SystemCapability.Sensors.Sensor + * @since 11 + */ +typedef struct Sensor_Sensor Sensor_Sensor; + +/** + * @brief 创建给定个数{@link Sensor_Sensor}实例的数组。 + * + * @param count - 表示要创建{@link Sensor_Sensor}实例的个数. + * @return 如果创建成功,则返回{@link Sensor_Sensor}实例的数组,否则返回 NULL。。 + * @since 11 + */ +Sensor_Sensor **OH_Sensor_CreateSensors(uint32_t count); + +/** + * @brief 销毁{@link Sensor_Sensor}实例的数组并回收内存。 + * + * @param sensors - 表示要销毁的{@link Sensor_Sensor}实例的数组. + * @param count - 表示要销毁的{@link Sensor_Sensor}实例的个数. + * @return 成功返回SENSOR_SUCCESS,否则返回对应的错误码,详情请参见{@Link Sensor_Result}。 + * @since 11 + */ +int32_t OH_Sensor_DestroySensors(Sensor_Sensor **sensors, uint32_t count); + +/** + * @brief 获取传感器名称. + * + * @param sensor - 传感器信息. + * @param sensorName - 出参,传感器名称. + * @param length - 出参,字节数. + * @return 成功返回SENSOR_SUCCESS,否则返回对应的错误码,详情请参见{@Link Sensor_Result}。 + * @since 11 + */ +int32_t OH_Sensor_GetSensorName(Sensor_Sensor* sensor, char *sensorName, uint32_t *length); + +/** + * @brief 获取传感器厂商名称. + * + * @param sensor - 传感器信息. + * @param vendorName - 出参,厂商名称. + * @param length - 出参,字节数. + * @return 成功返回SENSOR_SUCCESS,否则返回对应的错误码,详情请参见{@Link Sensor_Result}。 + * @since 11 + */ +int32_t OH_Sensor_GetVendorName(Sensor_Sensor* sensor, char *vendorName, uint32_t *length); + +/** + * @brief 获取传感器类型。 + * + * @param sensor - 传感器信息。 + * @param sensorType - 出参,传感器类型。 + * @return 成功返回SENSOR_SUCCESS,否则返回对应的错误码,详情请参见{@Link Sensor_Result}。 + * @since 11 + */ +int32_t OH_Sensor_GetSensorType(Sensor_Sensor* sensor, Sensor_SensorType *sensorType); + +/** + * @brief 获取传感器分辨率。 + * + * @param sensor - 传感器信息。 + * @param resolution - 出参,传感器分辨率。 + * @return 成功返回SENSOR_SUCCESS,否则返回对应的错误码,详情请参见{@Link Sensor_Result}。 + * @since 11 + */ +int32_t OH_Sensor_GetSensorResolution(Sensor_Sensor* sensor, float *resolution); + +/** + * @brief 获取传感器最小上报时间间隔。 + * + * @param sensor - 传感器信息。 + * @param minSamplePeriod - 出参,传感器最小上报时间间隔,单位纳秒。 + * @return 成功返回SENSOR_SUCCESS,否则返回对应的错误码,详情请参见{@Link Sensor_Result}。 + * @since 11 + */ +int32_t OH_Sensor_GetSensorMinSamplePeriod(Sensor_Sensor* sensor, int64_t *minSamplePeriod); + +/** + * @brief 获取传感器最大上报时间间隔。 + * + * @param sensor - 传感器信息。 + * @param maxSamplePeriod - 出参,传感器最大上报时间间隔,单位纳秒。 + * @return 成功返回SENSOR_SUCCESS,否则返回对应的错误码,详情请参见{@Link Sensor_Result}。 + * @since 11 + */ +int32_t OH_Sensor_GetSensorMaxSamplePeriod(Sensor_Sensor* sensor, int64_t *maxSamplePeriod); + +/** + * @brief 传感器数据信息。 + * @syscap SystemCapability.Sensors.Sensor + * @since 11 + */ +typedef struct Sensor_SensorEvent Sensor_SensorEvent; + +/** + * @brief 获取传感器类型。 + * + * @param sensor - 传感器数据信息。 + * @param sensorType - 出参,传感器类型。 + * @return 成功返回SENSOR_SUCCESS,否则返回对应的错误码,详情请参见{@Link Sensor_Result}。 + * @since 11 + */ +int32_t OH_Sensor_GetEventSensorType(Sensor_SensorEvent* sensorEvent, Sensor_SensorType *sensorType); + +/** + * @brief 获取时间戳。 + * + * @param sensor - 传感器数据信息。 + * @param timestamp - 出参,时间戳。 + * @return 成功返回SENSOR_SUCCESS,否则返回对应的错误码,详情请参见{@Link Sensor_Result}。 + * @since 11 + */ +int32_t OH_Sensor_GetEventTimestamp(Sensor_SensorEvent* sensorEvent, int64_t *timestamp); + +/** + * @brief 获取传感器数据精度。 + * + * @param sensor - 传感器数据信息。 + * @param accuracy - 出参,传感器数据精度。 + * @return 成功返回SENSOR_SUCCESS,否则返回对应的错误码,详情请参见{@Link Sensor_Result}。 + * @since 11 + */ +int32_t OH_Sensor_GetEventAccuracy(Sensor_SensorEvent* sensorEvent, Sensor_SensorAccuracy *accuracy); + +/** + * @brief 获取传感器数据。数据的长度和内容依赖于监听的传感器类型,传感器上报的数据格式如下: + * SENSOR_TYPE_ACCELEROMETER: data[0]、data[1]、data[2]分别表示设备x、y、z轴的加速度分量,单位m/s2; + * SENSOR_TYPE_GYROSCOPE: data[0]、data[1]、data[2]分别表示设备x、y、z轴的旋转角速度,单位弧度/s; + * SENSOR_TYPE_AMBIENT_LIGHT: data[0]表示环境光强度,in lux; + * SENSOR_TYPE_MAGNETIC_FIELD: data[0]、data[1]、data[2]分别表示设备x、y、z轴的地磁分量,单位微特斯拉; + * SENSOR_TYPE_BAROMETER:data[0]表示气压值,单位hPa; + * SENSOR_TYPE_HALL: data[0]表示皮套吸合状态,0表示打开,大于0表示吸附; + * SENSOR_TYPE_PROXIMITY:data[0]表示接近状态,0表示接近,大于0表示远离; + * SENSOR_TYPE_ORIENTATION:data[0]、data[1]、data[2]分别表示设备绕z、x、y轴的角度,单位度; + * SENSOR_TYPE_GRAVITY:data[0]、data[1]、data[2]分别表示设备x、y、z轴的重力加速度分量,单位m/s2; + * SENSOR_TYPE_ROTATION_VECTOR:data[0]、data[1]、data[2]分别表示设备x、y、z轴的旋转角度,单位度,data[3]表示旋转向量元素; + * SENSOR_TYPE_PEDOMETER_DETECTION:data[0]表示几步检测状态,1表示检测到了步数变化 + * SENSOR_TYPE_PEDOMETER:data[0]表示步数; + * SENSOR_TYPE_HEART_RATE:data[0]表示心率数值; + * + * @param sensor - 传感器数据信息。 + * @param data - 出参,传感器数据。 + * @param length - 出参,数组长度。 + * @return 成功返回SENSOR_SUCCESS,否则返回对应的错误码,详情请参见{@Link Sensor_Result}。 + * @since 11 + */ +int32_t OH_Sensor_GetSensorData(Sensor_SensorEvent* sensorEvent, float **data, uint32_t *length); + +/** + * @brief 传感器订阅Id,唯一标识传感器。 + * @syscap SystemCapability.Sensors.Sensor + * @since 11 + */ +typedef struct Sensor_SensorSubscribeId Sensor_SensorSubscribeId; + +/** + * @brief 创建指向{@link Sensor_SensorSubscribeId}实例的指针。 + * + * @return 如果创建成功,则返回指向{@link Sensor_SensorSubscribeId} 结构实例的指针,否则返回NULL. + * @since 11 + */ +Sensor_SensorSubscribeId *OH_Sensor_CreateSubscribeId(); + +/** + * @brief 销毁{@link Sensor_SensorSubscribeId}实例并回收内存。 + * + * @param subscribeId - 表示指向 {@link Sensor_SensorSubscribeId} 实例的指针. + * @return 成功返回SENSOR_SUCCESS,否则返回对应的错误码,详情请参见{@Link Sensor_Result}。 + * @since 11 + */ +int32_t OH_Sensor_DestroySubscribeId(Sensor_SensorSubscribeId *subscribeId); + +/** + * @brief 获取传感器类型。 + * + * @param subscribeId - 传感器订阅Id。 + * @param sensorType - 出参,传感器类型。 + * @return 成功返回SENSOR_SUCCESS,否则返回对应的错误码,详情请参见{@Link Sensor_Result}。 + * @since 11 + */ +int32_t OH_Sensor_GetSubscribeSensorType(Sensor_SensorSubscribeId* subscribeId, Sensor_SensorType *sensorType); + +/** + * @brief 设置传感器类型。 + * + * @param subscribeId - 传感器订阅Id。 + * @param sensorType - 传感器类型。 + * @return 成功返回SENSOR_SUCCESS,否则返回对应的错误码,详情请参见{@Link Sensor_Result}。 + * @since 11 + */ +int32_t OH_Sensor_SetSubscribeSensorType(Sensor_SensorSubscribeId* subscribeId, const Sensor_SensorType sensorType); + +/** + * @brief 传感器订阅属性。 + * @syscap SystemCapability.Sensors.Sensor + * @since 11 + */ +typedef struct Sensor_SubscribeAttribute Sensor_SubscribeAttribute; + +/** + * @brief 创建指向{@link Sensor_SubscribeAttribute}实例的指针。 + * + * @return 如果创建成功,则返回指向{@link Sensor_SubscribeAttribute} 结构实例的指针,否则返回NULL. + * @since 11 + */ +Sensor_SubscribeAttribute *OH_Sensor_CreateAttribute(); + +/** + * @brief 销毁{@link Sensor_SubscribeAttribute}实例并回收内存。 + * + * @param attribute - 表示指向 {@link Sensor_SubscribeAttribute} 实例的指针. + * @return 成功返回SENSOR_SUCCESS,否则返回对应的错误码,详情请参见{@Link Sensor_Result}。 + * @since 11 + */ +int32_t OH_Sensor_DestroyAttribute(Sensor_SubscribeAttribute *attribute); + +/** + * @brief 设置上报时间间隔。 + * + * @param attribute - 传感器订阅属性。 + * @param samplingInterval - 上报时间间隔,单位ns。 + * @return 成功返回SENSOR_SUCCESS,否则返回对应的错误码,详情请参见{@Link Sensor_Result}。 + * @since 11 + */ +int32_t OH_Sensor_SetSamplingInterval(Sensor_SubscribeAttribute* attribute, const int64_t samplingInterval); + +/** + * @brief 获取上报时间间隔。 + * + * @param attribute - 传感器订阅属性。 + * @param samplingInterval - 出参,上报时间间隔,单位ns。 + * @return 成功返回SENSOR_SUCCESS,否则返回对应的错误码,详情请参见{@Link Sensor_Result}。 + * @since 11 + */ +int32_t OH_Sensor_GetSamplingInterval(Sensor_SubscribeAttribute* attribute, int64_t *samplingInterval); + +/** + * @brief 传感器数据的回调函数。 + * @syscap SystemCapability.Sensors.Sensor + * @since 11 + */ +typedef void (*Sensor_RecordSensorCallback)(Sensor_SensorEvent *event); + +/** + * @brief 传感器订阅者信息。 + * @syscap SystemCapability.Sensors.Sensor + * @since 11 + */ +typedef struct Sensor_SubscribeUser Sensor_SubscribeUser; + +/** + * @brief 创建指向{@link Sensor_SubscribeUser}实例的指针。 + * + * @return 如果创建成功,则返回指向{@link Sensor_SubscribeUser} 结构实例的指针,否则返回NULL. + * @since 11 + */ +Sensor_SubscribeUser *OH_Sensor_CreateUser(); + +/** + * @brief 销毁{@link Sensor_SubscribeUser}实例并回收内存。 + * + * @param user - 表示指向{@link Sensor_SubscribeUser}实例的指针. + * @return 成功返回SENSOR_SUCCESS,否则返回对应的错误码,详情请参见{@Link Sensor_Result}。 + * @since 11 + */ +int32_t OH_Sensor_DestroyUser(Sensor_SubscribeUser *user); + +/** + * @brief 设置传感器数据的回调函数。 + * + * @param user - 传感器订阅者信息。 + * @param callback - 传感器数据的回调函数。 + * @return 成功返回SENSOR_SUCCESS,否则返回对应的错误码,详情请参见{@Link Sensor_Result}。 + * @since 11 + */ +int32_t OH_Sensor_SetSensorCallback(Sensor_SubscribeUser* user, const Sensor_RecordSensorCallback callback); + +/** + * @brief 获取传感器数据的回调函数。 + * + * @param user - 传感器订阅者信息。 + * @param callback - 出参,传感器数据的回调函数。 + * @return 成功返回SENSOR_SUCCESS,否则返回对应的错误码,详情请参见{@Link Sensor_Result}。 + * @since 11 + */ +int32_t OH_Sensor_GetSensorCallback(Sensor_SubscribeUser* user, Sensor_RecordSensorCallback *callback); +#ifdef __cplusplus +} +#endif +#endif // OH_NATIVE_SENSOR_TYPE_H \ No newline at end of file diff --git a/test/unittest/interfaces/kits/BUILD.gn b/test/unittest/interfaces/kits/BUILD.gn new file mode 100644 index 00000000..daac8acd --- /dev/null +++ b/test/unittest/interfaces/kits/BUILD.gn @@ -0,0 +1,49 @@ +# Copyright (c) 2021-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/test.gni") +import("./../../../../sensor.gni") + +ohos_unittest("SensorNativeTest") { + module_out_path = "sensor/interfaces" + + sources = [ "$SUBSYSTEM_DIR/test/unittest/interfaces/kits/sensor_native_test.cpp" ] + + include_dirs = [ + "$SUBSYSTEM_DIR/utils/common/include", + "$SUBSYSTEM_DIR/interfaces/kits/c", + "$SUBSYSTEM_DIR/frameworks/native/include", + ] + + deps = [ + "$SUBSYSTEM_DIR/frameworks/native:sensor_native", + "$SUBSYSTEM_DIR/utils/common:libsensor_utils", + "//third_party/googletest:gmock_main", + "//third_party/googletest:gtest_main", + ] + + external_deps = [ + "c_utils:utils", + "hilog:libhilog", + "ipc:ipc_core", + "access_token:libaccesstoken_sdk", + "access_token:libnativetoken", + "access_token:libtoken_setproc", + ] +} +group("unittest") { + testonly = true + deps = [ + ":SensorNativeTest" + ] +} diff --git a/test/unittest/interfaces/kits/sensor_native_test.cpp b/test/unittest/interfaces/kits/sensor_native_test.cpp new file mode 100755 index 00000000..033c76b8 --- /dev/null +++ b/test/unittest/interfaces/kits/sensor_native_test.cpp @@ -0,0 +1,414 @@ +/* + * Copyright (c) 2021 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. + */ + +#include +#include +#include +#include + +#include "accesstoken_kit.h" +#include "nativetoken_kit.h" +#include "token_setproc.h" + +#include "native_sensor.h" +#include "sensor_errors.h" + +namespace OHOS { +namespace Sensors { +using namespace testing::ext; +using namespace OHOS::HiviewDFX; +using namespace Security::AccessToken; +using Security::AccessToken::AccessTokenID; + +namespace { +constexpr HiLogLabel LABEL = { LOG_CORE, OHOS::Sensors::SENSOR_LOG_DOMAIN, "SensorAgentTest" }; +constexpr Sensor_SensorType SENSOR_ID { SENSOR_TYPE_ACCELEROMETER }; + +PermissionDef g_infoManagerTestPermDef = { + .permissionName = "ohos.permission.ACCELEROMETER", + .bundleName = "accesstoken_test", + .grantMode = 1, + .availableLevel = APL_NORMAL, + .label = "label", + .labelId = 1, + .description = "test sensor agent", + .descriptionId = 1 +}; + +PermissionStateFull g_infoManagerTestState = { + .permissionName = "ohos.permission.ACCELEROMETER", + .isGeneral = true, + .resDeviceID = {"local"}, + .grantStatus = {PermissionState::PERMISSION_GRANTED}, + .grantFlags = {1} +}; + +HapPolicyParams g_infoManagerTestPolicyPrams = { + .apl = APL_NORMAL, + .domain = "test.domain", + .permList = {g_infoManagerTestPermDef}, + .permStateList = {g_infoManagerTestState} +}; + +HapInfoParams g_infoManagerTestInfoParms = { + .userID = 1, + .bundleName = "sensoragent_test", + .instIndex = 0, + .appIDDesc = "sensorAgentTest" +}; + +Sensor_SubscribeUser *g_user = nullptr; +} // namespace + +class SensorAgentTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + void SetUp(); + void TearDown(); +private: + static AccessTokenID tokenID_; +}; + +AccessTokenID SensorAgentTest::tokenID_ = 0; + +void SensorAgentTest::SetUpTestCase() +{ + AccessTokenIDEx tokenIdEx = {0}; + tokenIdEx = AccessTokenKit::AllocHapToken(g_infoManagerTestInfoParms, g_infoManagerTestPolicyPrams); + tokenID_ = tokenIdEx.tokenIdExStruct.tokenID; + ASSERT_NE(0, tokenID_); + ASSERT_EQ(0, SetSelfTokenID(tokenID_)); +} + +void SensorAgentTest::TearDownTestCase() +{ + int32_t ret = AccessTokenKit::DeleteToken(tokenID_); + if (tokenID_ != 0) { + ASSERT_EQ(RET_SUCCESS, ret); + } +} + +void SensorAgentTest::SetUp() +{} + +void SensorAgentTest::TearDown() +{} + +void SensorDataCallbackImpl(Sensor_SensorEvent *event) +{ + if (event == nullptr) { + SEN_HILOGE("event is null"); + return; + } + int64_t timestamp = -1; + int32_t ret = OH_Sensor_GetEventTimestamp(event, ×tamp); + ASSERT_EQ(ret, SENSOR_SUCCESS); + Sensor_SensorType sensorType; + ret = OH_Sensor_GetEventSensorType(event, &sensorType); + ASSERT_EQ(ret, SENSOR_SUCCESS); + Sensor_SensorAccuracy accuracy = SENSOR_ACCURACY_UNRELIABLE; + ret = OH_Sensor_GetEventAccuracy(event, &accuracy); + ASSERT_EQ(ret, SENSOR_SUCCESS); + float *data = nullptr; + size_t length = 0; + ret = OH_Sensor_GetSensorData(event, &data, &length); + ASSERT_EQ(ret, SENSOR_SUCCESS); + SEN_HILOGI("sensorType:%{public}d, dataLen:%{public}d, accuracy:%{public}d", + sensorType, length, accuracy); + SEN_HILOGI("x:%{public}f, y:%{public}f, z:%{public}f", data[0], data[1], data[2]); +} + +HWTEST_F(SensorAgentTest, OH_Sensor_GetAllSensors_001, TestSize.Level1) +{ + SEN_HILOGI("OH_Sensor_GetAllSensors_001 in"); + uint32_t count = 0; + int32_t ret = OH_Sensor_GetAllSensors(nullptr, &count); + ASSERT_EQ(ret, SENSOR_SUCCESS); + Sensor_Sensor **sensors = OH_Sensor_CreateSensors(count); + ASSERT_NE(sensors, nullptr); + ret = OH_Sensor_GetAllSensors(sensors, &count); + ASSERT_EQ(ret, SENSOR_SUCCESS); + for (uint32_t i = 0; i < count; ++i) { + char sensorName[64] = {}; + size_t length = 64; + ret = OH_Sensor_GetSensorName(sensors[i], sensorName, &length); + ASSERT_EQ(ret, SENSOR_SUCCESS); + char vendorName[64] = {}; + length = 64; + ret = OH_Sensor_GetVendorName(sensors[i], vendorName, &length); + ASSERT_EQ(ret, SENSOR_SUCCESS); + Sensor_SensorType sensorType; + ret = OH_Sensor_GetSensorType(sensors[i], &sensorType); + ASSERT_EQ(ret, SENSOR_SUCCESS); + float resolution = -1.0F; + ret = OH_Sensor_GetSensorResolution(sensors[i], &resolution); + ASSERT_EQ(ret, SENSOR_SUCCESS); + int64_t minSamplePeriod = -1; + ret = OH_Sensor_GetSensorMinSamplePeriod(sensors[i], &minSamplePeriod); + ASSERT_EQ(ret, SENSOR_SUCCESS); + int64_t maxSamplePeriod = -1; + ret = OH_Sensor_GetSensorMaxSamplePeriod(sensors[i], &maxSamplePeriod); + ASSERT_EQ(ret, SENSOR_SUCCESS); + SEN_HILOGI("sensorType:%{public}d, sensorName:%{public}s, vendorName:%{public}s," + "resolution:%{public}f, minSamplePeriod:%{public}" PRId64 "maxSamplePeriod:%{public}" PRId64, + static_cast(sensorType), sensorName, vendorName, + resolution, minSamplePeriod, maxSamplePeriod); + } + ret = OH_Sensor_DestroySensors(sensors, count); + ASSERT_EQ(ret, SENSOR_SUCCESS); +} + +HWTEST_F(SensorAgentTest, OH_Sensor_GetAllSensors_002, TestSize.Level1) +{ + SEN_HILOGI("OH_Sensor_GetAllSensors_002 in"); + uint32_t count = 0; + int32_t ret = OH_Sensor_GetAllSensors(nullptr, &count); + ASSERT_NE(ret, SENSOR_SUCCESS); +} + +HWTEST_F(SensorAgentTest, OH_Sensor_GetAllSensors_003, TestSize.Level1) +{ + SEN_HILOGI("OH_Sensor_GetAllSensors_003 in"); + Sensor_Sensor *sensors { nullptr }; + int32_t ret = OH_Sensor_GetAllSensors(&sensors, nullptr); + ASSERT_NE(ret, SENSOR_SUCCESS); +} + +HWTEST_F(SensorAgentTest, OH_Sensor_SubscribeSensor_001, TestSize.Level1) +{ + SEN_HILOGI("OH_Sensor_SubscribeSensor_001 in"); + g_user = OH_Sensor_CreateUser(); + int32_t ret = OH_Sensor_SetSensorCallback(g_user, SensorDataCallbackImpl); + ASSERT_EQ(ret, SENSOR_SUCCESS); + + Sensor_SensorSubscribeId *id = OH_Sensor_CreateSubscribeId(); + ret = OH_Sensor_SetSubscribeSensorType(id, SENSOR_ID); + ASSERT_EQ(ret, SENSOR_SUCCESS); + + Sensor_SubscribeAttribute *attr = OH_Sensor_CreateAttribute(); + ret = OH_Sensor_SetSamplingInterval(attr, 200000000); + ASSERT_EQ(ret, SENSOR_SUCCESS); + + ret = OH_Sensor_SubscribeSensor(id, attr, g_user); + ASSERT_EQ(ret, SENSOR_SUCCESS); + + std::this_thread::sleep_for(std::chrono::milliseconds(1000)); + ret = OH_Sensor_UnsubscribeSensor(id, g_user); + ASSERT_EQ(ret, SENSOR_SUCCESS); + if (id != nullptr) { + OH_Sensor_DestroySubscribeId(id); + } + if (attr != nullptr) { + OH_Sensor_DestroyAttribute(attr); + } + if (g_user != nullptr) { + OH_Sensor_DestroyUser(g_user); + g_user = nullptr; + } +} + +HWTEST_F(SensorAgentTest, OH_Sensor_SubscribeSensor_002, TestSize.Level1) +{ + SEN_HILOGI("OH_Sensor_SubscribeSensor_002 in"); + Sensor_SensorSubscribeId *id = OH_Sensor_CreateSubscribeId(); + int32_t ret = OH_Sensor_SetSubscribeSensorType(id, SENSOR_ID); + ASSERT_EQ(ret, SENSOR_SUCCESS); + + Sensor_SubscribeAttribute *attr = OH_Sensor_CreateAttribute(); + ret = OH_Sensor_SetSamplingInterval(attr, 200000000); + ASSERT_EQ(ret, SENSOR_SUCCESS); + + ret = OH_Sensor_SubscribeSensor(id, attr, nullptr); + ASSERT_EQ(ret, SENSOR_PARAMETER_ERROR); + if (id != nullptr) { + OH_Sensor_DestroySubscribeId(id); + } + if (attr != nullptr) { + OH_Sensor_DestroyAttribute(attr); + } +} + +HWTEST_F(SensorAgentTest, OH_Sensor_SubscribeSensor_003, TestSize.Level1) +{ + SEN_HILOGI("OH_Sensor_SubscribeSensor_003 in"); + g_user = OH_Sensor_CreateUser(); + int32_t ret = OH_Sensor_SetSensorCallback(g_user, SensorDataCallbackImpl); + ASSERT_EQ(ret, SENSOR_SUCCESS); + + Sensor_SubscribeAttribute *attr = OH_Sensor_CreateAttribute(); + ret = OH_Sensor_SetSamplingInterval(attr, 200000000); + ASSERT_EQ(ret, SENSOR_SUCCESS); + + ret = OH_Sensor_SubscribeSensor(nullptr, attr, g_user); + ASSERT_EQ(ret, SENSOR_PARAMETER_ERROR); + if (attr != nullptr) { + OH_Sensor_DestroyAttribute(attr); + } + if (g_user != nullptr) { + OH_Sensor_DestroyUser(g_user); + g_user = nullptr; + } +} + +HWTEST_F(SensorAgentTest, OH_Sensor_SubscribeSensor_004, TestSize.Level1) +{ + SEN_HILOGI("OH_Sensor_SubscribeSensor_004 in"); + g_user = OH_Sensor_CreateUser(); + int32_t ret = OH_Sensor_SetSensorCallback(g_user, SensorDataCallbackImpl); + ASSERT_EQ(ret, SENSOR_SUCCESS); + + Sensor_SensorSubscribeId *id = OH_Sensor_CreateSubscribeId(); + ret = OH_Sensor_SetSubscribeSensorType(id, SENSOR_ID); + ASSERT_EQ(ret, SENSOR_SUCCESS); + + ret = OH_Sensor_SubscribeSensor(id, nullptr, g_user); + ASSERT_EQ(ret, SENSOR_PARAMETER_ERROR); + if (id != nullptr) { + OH_Sensor_DestroySubscribeId(id); + } + if (g_user != nullptr) { + OH_Sensor_DestroyUser(g_user); + g_user = nullptr; + } +} + +HWTEST_F(SensorAgentTest, OH_Sensor_UnsubscribeSensor_001, TestSize.Level1) +{ + SEN_HILOGI("OH_Sensor_UnsubscribeSensor_001 in"); + g_user = OH_Sensor_CreateUser(); + int32_t ret = OH_Sensor_SetSensorCallback(g_user, SensorDataCallbackImpl); + ASSERT_EQ(ret, SENSOR_SUCCESS); + + ret = OH_Sensor_UnsubscribeSensor(nullptr, g_user); + ASSERT_EQ(ret, SENSOR_PARAMETER_ERROR); + if (g_user != nullptr) { + OH_Sensor_DestroyUser(g_user); + g_user = nullptr; + } +} + +HWTEST_F(SensorAgentTest, OH_Sensor_UnsubscribeSensor_002, TestSize.Level1) +{ + SEN_HILOGI("OH_Sensor_UnsubscribeSensor_002 in"); + Sensor_SensorSubscribeId *id = OH_Sensor_CreateSubscribeId(); + int32_t ret = OH_Sensor_SetSubscribeSensorType(id, SENSOR_ID); + ASSERT_EQ(ret, SENSOR_SUCCESS); + + ret = OH_Sensor_UnsubscribeSensor(id, nullptr); + ASSERT_EQ(ret, SENSOR_PARAMETER_ERROR); + if (id != nullptr) { + OH_Sensor_DestroySubscribeId(id); + } +} + +HWTEST_F(SensorAgentTest, OH_Sensor_SetSubscribeSensorType_001, TestSize.Level1) +{ + SEN_HILOGI("OH_Sensor_SetSubscribeSensorType_001 in"); + int32_t ret = OH_Sensor_SetSubscribeSensorType(nullptr, SENSOR_ID); + ASSERT_EQ(ret, SENSOR_PARAMETER_ERROR); +} + +HWTEST_F(SensorAgentTest, OH_Sensor_GetSubscribeSensorType_001, TestSize.Level1) +{ + SEN_HILOGI("OH_Sensor_GetSubscribeSensorType_001 in"); + Sensor_SensorType type; + int32_t ret = OH_Sensor_GetSubscribeSensorType(nullptr, &type); + ASSERT_EQ(ret, SENSOR_PARAMETER_ERROR); +} + +HWTEST_F(SensorAgentTest, OH_Sensor_GetSubscribeSensorType_002, TestSize.Level1) +{ + SEN_HILOGI("OH_Sensor_GetSubscribeSensorType_002 in"); + Sensor_SensorSubscribeId *id = OH_Sensor_CreateSubscribeId(); + int32_t ret = OH_Sensor_GetSubscribeSensorType(id, nullptr); + ASSERT_EQ(ret, SENSOR_PARAMETER_ERROR); + if (id != nullptr) { + OH_Sensor_DestroySubscribeId(id); + } +} + +HWTEST_F(SensorAgentTest, OH_Sensor_SetSamplingInterval_001, TestSize.Level1) +{ + SEN_HILOGI("OH_Sensor_SetSamplingInterval_001 in"); + int32_t ret = OH_Sensor_SetSamplingInterval(nullptr, 2000000000); + ASSERT_EQ(ret, SENSOR_PARAMETER_ERROR); +} + +HWTEST_F(SensorAgentTest, OH_Sensor_SetSamplingInterval_002, TestSize.Level1) +{ + SEN_HILOGI("OH_Sensor_SetSamplingInterval_002 in"); + Sensor_SubscribeAttribute *attr = OH_Sensor_CreateAttribute(); + int32_t ret = OH_Sensor_SetSamplingInterval(attr, -1); + ASSERT_EQ(ret, SENSOR_PARAMETER_ERROR); + if (attr != nullptr) { + OH_Sensor_DestroyAttribute(attr); + } +} + +HWTEST_F(SensorAgentTest, OH_Sensor_GetSamplingInterval_001, TestSize.Level1) +{ + SEN_HILOGI("OH_Sensor_GetSamplingInterval_001 in"); + int64_t samplingInterval = 0; + int32_t ret = OH_Sensor_GetSamplingInterval(nullptr, &samplingInterval); + ASSERT_EQ(ret, SENSOR_PARAMETER_ERROR); +} + +HWTEST_F(SensorAgentTest, OH_Sensor_GetSamplingInterval_002, TestSize.Level1) +{ + SEN_HILOGI("OH_Sensor_GetSamplingInterval_002 in"); + Sensor_SubscribeAttribute *attr = OH_Sensor_CreateAttribute(); + int32_t ret = OH_Sensor_GetSamplingInterval(attr, nullptr); + ASSERT_EQ(ret, SENSOR_PARAMETER_ERROR); + if (attr != nullptr) { + OH_Sensor_DestroyAttribute(attr); + } +} + +HWTEST_F(SensorAgentTest, OH_Sensor_SetSensorCallback_001, TestSize.Level1) +{ + SEN_HILOGI("OH_Sensor_SetSensorCallback_001 in"); + int32_t ret = OH_Sensor_SetSensorCallback(nullptr, SensorDataCallbackImpl); + ASSERT_EQ(ret, SENSOR_PARAMETER_ERROR); +} + +HWTEST_F(SensorAgentTest, OH_Sensor_SetSensorCallback_002, TestSize.Level1) +{ + SEN_HILOGI("OH_Sensor_SetSensorCallback_002 in"); + g_user = OH_Sensor_CreateUser(); + int32_t ret = OH_Sensor_SetSensorCallback(g_user, nullptr); + ASSERT_EQ(ret, SENSOR_PARAMETER_ERROR); +} + +HWTEST_F(SensorAgentTest, OH_Sensor_GetSensorCallback_001, TestSize.Level1) +{ + SEN_HILOGI("OH_Sensor_GetSensorCallback_001 in"); + Sensor_RecordSensorCallback callback; + int32_t ret = OH_Sensor_GetSensorCallback(nullptr, &callback); + ASSERT_EQ(ret, SENSOR_PARAMETER_ERROR); +} + +HWTEST_F(SensorAgentTest, OH_Sensor_GetSensorCallback_002, TestSize.Level1) +{ + SEN_HILOGI("OH_Sensor_GetSensorCallback_002 in"); + g_user = OH_Sensor_CreateUser(); + int32_t ret = OH_Sensor_GetSensorCallback(g_user, nullptr); + ASSERT_EQ(ret, SENSOR_PARAMETER_ERROR); + if (g_user != nullptr) { + OH_Sensor_DestroyUser(g_user); + } +} +} // namespace Sensors +} // namespace OHOS -- Gitee From ddd8bfab220f852c98abac133ab49c3b6225f507 Mon Sep 17 00:00:00 2001 From: hellohyh001 Date: Tue, 28 Nov 2023 08:57:26 +0000 Subject: [PATCH 02/16] update Signed-off-by: hellohyh001 Change-Id: Ia11b7fc76b25eac724d69fb6f0559ffdfce1c04c --- frameworks/native/BUILD.gn | 4 +--- interfaces/kits/c/BUILD.gn | 2 +- test/unittest/interfaces/kits/BUILD.gn | 13 ++++++------- 3 files changed, 8 insertions(+), 11 deletions(-) diff --git a/frameworks/native/BUILD.gn b/frameworks/native/BUILD.gn index 8f62ccc5..a56646a4 100644 --- a/frameworks/native/BUILD.gn +++ b/frameworks/native/BUILD.gn @@ -120,9 +120,7 @@ ohos_shared_library("sensor_interface_native") { } config("sensor_native_public_config") { - include_dirs = [ - "$SUBSYSTEM_DIR/interfaces/kits/c", - ] + include_dirs = [ "$SUBSYSTEM_DIR/interfaces/kits/c" ] } ohos_shared_library("sensor_native") { diff --git a/interfaces/kits/c/BUILD.gn b/interfaces/kits/c/BUILD.gn index b8b2a373..48c15b15 100644 --- a/interfaces/kits/c/BUILD.gn +++ b/interfaces/kits/c/BUILD.gn @@ -32,4 +32,4 @@ ohos_ndk_library("libsensor_ndk") { "$ndk_headers_out_dir/sensor/native_sensor.h", "$ndk_headers_out_dir/sensor/native_sensor_type.h", ] -} \ No newline at end of file +} diff --git a/test/unittest/interfaces/kits/BUILD.gn b/test/unittest/interfaces/kits/BUILD.gn index daac8acd..de799c21 100644 --- a/test/unittest/interfaces/kits/BUILD.gn +++ b/test/unittest/interfaces/kits/BUILD.gn @@ -17,7 +17,8 @@ import("./../../../../sensor.gni") ohos_unittest("SensorNativeTest") { module_out_path = "sensor/interfaces" - sources = [ "$SUBSYSTEM_DIR/test/unittest/interfaces/kits/sensor_native_test.cpp" ] + sources = + [ "$SUBSYSTEM_DIR/test/unittest/interfaces/kits/sensor_native_test.cpp" ] include_dirs = [ "$SUBSYSTEM_DIR/utils/common/include", @@ -33,17 +34,15 @@ ohos_unittest("SensorNativeTest") { ] external_deps = [ - "c_utils:utils", - "hilog:libhilog", - "ipc:ipc_core", "access_token:libaccesstoken_sdk", "access_token:libnativetoken", "access_token:libtoken_setproc", + "c_utils:utils", + "hilog:libhilog", + "ipc:ipc_core", ] } group("unittest") { testonly = true - deps = [ - ":SensorNativeTest" - ] + deps = [ ":SensorNativeTest" ] } -- Gitee From 7e8ee5a8528446c96e0361730a4246f6c07139f7 Mon Sep 17 00:00:00 2001 From: hellohyh001 Date: Tue, 28 Nov 2023 13:22:07 +0000 Subject: [PATCH 03/16] update Signed-off-by: hellohyh001 Change-Id: I44005b5bebe1599077590341a8a623a5475a359a --- interfaces/kits/c/native_sensor.h | 47 +++-- interfaces/kits/c/native_sensor_type.h | 273 ++++++++++++------------- 2 files changed, 161 insertions(+), 159 deletions(-) diff --git a/interfaces/kits/c/native_sensor.h b/interfaces/kits/c/native_sensor.h index b46ae7fe..c9985ed9 100644 --- a/interfaces/kits/c/native_sensor.h +++ b/interfaces/kits/c/native_sensor.h @@ -17,13 +17,15 @@ * @addtogroup Sensor * @{ * - * @brief 为您提供标准的开放api,以使用传感器的常用功能。比如,您可以调用这些api来获取传感器属性信息、订阅或取消订阅传感器数据等。 + * @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 sensor.h + * @file native_sensor.h * - * @brief 声明操作传感器的常用api,用于获取传感器信息、订阅或取消订阅传感器数据等。 + * @brief Declares the APIs for operating sensors, including obtaining sensor information and subscribing to or + * unsubscribing from sensor data. * @library libsensor_native.z.so * @syscap SystemCapability.Sensors.Sensor * @since 11 @@ -32,47 +34,52 @@ #ifndef OH_NATIVE_SENSOR_H #define OH_NATIVE_SENSOR_H -#include - #include "native_sensor_type.h" #ifdef __cplusplus extern "C" { #endif /** - * @brief 获取设备上的所有传感器信息。 + * @brief Obtains information about all sensors on the device. * - * @param sensorInfo - 出参,返回设备上的所有传感器信息,详情请参见{@Link Sensor_Sensor}。 - * @param count - 出参,返回设备上的传感器数量。 - * @return 成功返回SENSOR_SUCCESS,否则返回对应的错误码,详情请参见{@Link Sensor_Result}。 + * @param sensors - Double pointer to the information about all sensors on the device. + * For details, see {@link Sensor_Sensor}. + * @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_GetAllSensors(Sensor_Sensor **sensors, uint32_t *count); /** - * @brief 订阅传感器数据,系统将按照用户指定的上报频率向用户报告传感器数据。 + * @brief Subscribes to sensor data. The system will report sensor data to the subscriber at the specified frequency. * - * @param id - 标识要订阅的传感器, 详情请参见{@link Sensor_SensorSubscribeId}。 - * @param attribute - 订阅属性,可用于指定传感器的上报频率等,详情请参见{@Link Sensor_SubscribeAttribute}。 - * @param user - 订阅者信息,用于指定传感器数据回调函数等,详情请参见{@Link Sensor_SubscribeUser}。 - * @return 成功返回SENSOR_SUCCESS,否则返回对应的错误码,详情请参见{@Link Sensor_Result}。 + * @param id - Pointer to the sensor subscription ID. For details, see {@link Sensor_SensorSubscribeId}. + * @param attribute - Pointer to the subscription attribute, which is used to specify the data reporting frequency. + * For details, see {@link Sensor_SubscribeAttribute}. + * @param user - Pointer to the subscriber information, which is used to specify the callback function for reporting + * the sensor data. For details, see {@link Sensor_SubscribeUser}. + * @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_SubscribeSensor(const Sensor_SensorSubscribeId *subscribeId, const Sensor_SubscribeAttribute *attribute, +Sensor_Result OH_Sensor_SubscribeSensor(const Sensor_SensorSubscribeId *id, const Sensor_SubscribeAttribute *attribute, const Sensor_SubscribeUser *user); /** - * @brief 取消订阅传感器数据。 + * @brief Unsubscribes from sensor data. * - * @param id - 标识要订阅的传感器, 详情请参见{@link Sensor_SensorSubscribeId}。 - * @param user - 订阅者信息,用于指定传感器数据回调函数等,详情请参见{@Link Sensor_SubscribeUser}。 - * @return 成功返回SENSOR_SUCCESS,否则返回对应的错误码,详情请参见{@Link Sensor_Result}。 + * @param id - Pointer to the sensor subscription ID. For details, see {@link Sensor_SensorSubscribeId}. + * @param user - Pointer to the subscriber information, which is used to specify the callback function for reporting + * the sensor data. For details, see {@link Sensor_SubscribeUser}. + * @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_UnsubscribeSensor(const Sensor_SensorSubscribeId *subscribeId, const Sensor_SubscribeUser *user); +Sensor_Result OH_Sensor_UnsubscribeSensor(const Sensor_SensorSubscribeId *id, const Sensor_SubscribeUser *user); #ifdef __cplusplus } #endif diff --git a/interfaces/kits/c/native_sensor_type.h b/interfaces/kits/c/native_sensor_type.h index 09ce91ef..3fdadf11 100644 --- a/interfaces/kits/c/native_sensor_type.h +++ b/interfaces/kits/c/native_sensor_type.h @@ -17,7 +17,7 @@ * @addtogroup Sensor * @{ * - * @brief 为您提供标准的开放api,定义常用传感器属性。 + * @brief Provides APIs to define common sensor attributes. * * @since 11 */ @@ -25,9 +25,8 @@ /** * @file native_sensor_type.h * - * @brief 定义常用传感器属性。 - * @library libohsensor.z.so - * @syscap SystemCapability.Sensors.Sensor + * @brief Declares the common sensor attributes. + * @library libsensor_native.z.so * * @since 11 */ @@ -42,121 +41,102 @@ extern "C" { #endif /** - * @brief 传感器类型。 - * @syscap SystemCapability.Sensors.Sensor - * + * @brief Enumerates the sensor types. + * * @since 11 */ typedef enum Sensor_SensorType { /** - * 加速度传感器 - * @syscap SystemCapability.Sensors.Sensor + * Acceleration sensor. * @since 11 */ SENSOR_TYPE_ACCELEROMETER = 1, /** - * 陀螺仪传感测器 - * @syscap SystemCapability.Sensors.Sensor + * Gyroscope sensor. * @since 11 */ SENSOR_TYPE_GYROSCOPE = 2, /** - * 环境光传感器 - * @syscap SystemCapability.Sensors.Sensor + * Ambient light sensor. * @since 11 */ SENSOR_TYPE_AMBIENT_LIGHT = 5, /** - * 地磁传感器 - * @syscap SystemCapability.Sensors.Sensor + * Magnetic field sensor. * @since 11 */ SENSOR_TYPE_MAGNETIC_FIELD = 6, /** - * 气压计传感器 - * @syscap SystemCapability.Sensors.Sensor + * Barometer sensor. * @since 11 */ SENSOR_TYPE_BAROMETER = 8, /** - * 霍尔传感器 - * @syscap SystemCapability.Sensors.Sensor + * Hall effect sensor. * @since 11 */ SENSOR_TYPE_HALL = 10, /** - * 接近光传感器 - * @syscap SystemCapability.Sensors.Sensor + * Proximity sensor. * @since 11 */ SENSOR_TYPE_PROXIMITY = 12, /** - * 方向传感器 - * @syscap SystemCapability.Sensors.Sensor + * Orientation sensor. * @since 11 */ SENSOR_TYPE_ORIENTATION = 256, /** - * 重力传感器 - * @syscap SystemCapability.Sensors.Sensor + * Gravity sensor. * @since 11 */ SENSOR_TYPE_GRAVITY = 257, /** - * 旋转矢量传感器 - * @syscap SystemCapability.Sensors.Sensor + * Rotation vector sensor. * @since 11 */ SENSOR_TYPE_ROTATION_VECTOR = 259, /** - * 计步器检测传感器 - * @syscap SystemCapability.Sensors.Sensor + * Pedometer detection sensor. * @since 11 */ SENSOR_TYPE_PEDOMETER_DETECTION = 265, /** - * 计步器传感器 - * @syscap SystemCapability.Sensors.Sensor + * Pedometer sensor. * @since 11 */ SENSOR_TYPE_PEDOMETER = 266, /** - * 心率传感器 - * @syscap SystemCapability.Sensors.Sensor + * Heart rate sensor. * @since 11 */ SENSOR_TYPE_HEART_RATE = 278, } Sensor_SensorType; /** - * @brief 定义传感器错误码。 - * @syscap SystemCapability.Sensors.Sensor + * @brief Enumerates the sensor result codes. * * @since 11 */ typedef enum Sensor_Result { /** - * 操作成功。 - * @syscap SystemCapability.Sensors.Sensor + * The operation is successful. * @since 11 */ SENSOR_SUCCESS = 0, /** * Permission verification failed. - * @syscap SystemCapability.Sensors.Sensor * @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. - * @syscap SystemCapability.Sensors.Sensor * @since 11 */ SENSOR_PARAMETER_ERROR = 401, /** - * 传感器服务异常。 - * @syscap SystemCapability.Sensors.Sensor + * The sensor service is abnormal. * @since 11 */ SENSOR_SERVICE_EXCEPTION = 14500101, @@ -164,40 +144,34 @@ typedef enum Sensor_Result { /** * @brief Enumerates the accuracy levels of data reported by a sensor. - * @syscap SystemCapability.Sensors.Sensor * * @since 11 */ typedef enum Sensor_SensorAccuracy { /** * The sensor data is unreliable. It is possible that the sensor does not contact with the device to measure. - * @syscap SystemCapability.Sensors.Sensor * @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. - * @syscap SystemCapability.Sensors.Sensor * @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. - * @syscap SystemCapability.Sensors.Sensor * @since 11 */ SENSOR_ACCURACY_MEDIUM = 2, /** * The sensor data is at a high accuracy level. The data can be used directly. - * @syscap SystemCapability.Sensors.Sensor * @since 11 */ SENSOR_ACCURACY_HIGH = 3 } Sensor_SensorAccuracy; /** - * @brief 传感器信息。 - * @syscap SystemCapability.Sensors.Sensor + * @brief Defines the sensor information. * @since 11 */ typedef struct Sensor_Sensor Sensor_Sensor; @@ -222,131 +196,149 @@ Sensor_Sensor **OH_Sensor_CreateSensors(uint32_t count); int32_t OH_Sensor_DestroySensors(Sensor_Sensor **sensors, uint32_t count); /** - * @brief 获取传感器名称. + * @brief Obtains the sensor name. * - * @param sensor - 传感器信息. - * @param sensorName - 出参,传感器名称. - * @param length - 出参,字节数. - * @return 成功返回SENSOR_SUCCESS,否则返回对应的错误码,详情请参见{@Link Sensor_Result}。 + * @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_Sensor_GetSensorName(Sensor_Sensor* sensor, char *sensorName, uint32_t *length); /** - * @brief 获取传感器厂商名称. + * @brief Obtains the sensor's vendor name. * - * @param sensor - 传感器信息. - * @param vendorName - 出参,厂商名称. - * @param length - 出参,字节数. - * @return 成功返回SENSOR_SUCCESS,否则返回对应的错误码,详情请参见{@Link Sensor_Result}。 + * @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_Sensor_GetVendorName(Sensor_Sensor* sensor, char *vendorName, uint32_t *length); /** - * @brief 获取传感器类型。 + * @brief Obtains the sensor type. * - * @param sensor - 传感器信息。 - * @param sensorType - 出参,传感器类型。 - * @return 成功返回SENSOR_SUCCESS,否则返回对应的错误码,详情请参见{@Link Sensor_Result}。 + * @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_Sensor_GetSensorType(Sensor_Sensor* sensor, Sensor_SensorType *sensorType); /** - * @brief 获取传感器分辨率。 + * @brief Obtains the sensor resolution. * - * @param sensor - 传感器信息。 - * @param resolution - 出参,传感器分辨率。 - * @return 成功返回SENSOR_SUCCESS,否则返回对应的错误码,详情请参见{@Link Sensor_Result}。 + * @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_Sensor_GetSensorResolution(Sensor_Sensor* sensor, float *resolution); /** - * @brief 获取传感器最小上报时间间隔。 + * @brief Obtains the minimum data reporting interval of a sensor. * - * @param sensor - 传感器信息。 - * @param minSamplePeriod - 出参,传感器最小上报时间间隔,单位纳秒。 - * @return 成功返回SENSOR_SUCCESS,否则返回对应的错误码,详情请参见{@Link Sensor_Result}。 + * @param sensor - Pointer to the sensor information. + * @param minSamplePeriod - 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_Sensor_GetSensorMinSamplePeriod(Sensor_Sensor* sensor, int64_t *minSamplePeriod); /** - * @brief 获取传感器最大上报时间间隔。 + * @brief Obtains the maximum data reporting interval of a sensor. * - * @param sensor - 传感器信息。 - * @param maxSamplePeriod - 出参,传感器最大上报时间间隔,单位纳秒。 - * @return 成功返回SENSOR_SUCCESS,否则返回对应的错误码,详情请参见{@Link Sensor_Result}。 + * @param sensor - Pointer to the sensor information. + * @param maxSamplePeriod - 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_Sensor_GetSensorMaxSamplePeriod(Sensor_Sensor* sensor, int64_t *maxSamplePeriod); /** - * @brief 传感器数据信息。 - * @syscap SystemCapability.Sensors.Sensor + * @brief Defines the sensor data information. * @since 11 */ typedef struct Sensor_SensorEvent Sensor_SensorEvent; /** - * @brief 获取传感器类型。 + * @brief Obtains the sensor type. * - * @param sensor - 传感器数据信息。 - * @param sensorType - 出参,传感器类型。 - * @return 成功返回SENSOR_SUCCESS,否则返回对应的错误码,详情请参见{@Link Sensor_Result}。 + * @param sensorEvent - 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_Sensor_GetEventSensorType(Sensor_SensorEvent* sensorEvent, Sensor_SensorType *sensorType); /** - * @brief 获取时间戳。 + * @brief Obtains the timestamp of sensor data. * - * @param sensor - 传感器数据信息。 - * @param timestamp - 出参,时间戳。 - * @return 成功返回SENSOR_SUCCESS,否则返回对应的错误码,详情请参见{@Link Sensor_Result}。 + * @param sensorEvent - 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_Sensor_GetEventTimestamp(Sensor_SensorEvent* sensorEvent, int64_t *timestamp); /** - * @brief 获取传感器数据精度。 + * @brief Obtains the accuracy of sensor data. * - * @param sensor - 传感器数据信息。 - * @param accuracy - 出参,传感器数据精度。 - * @return 成功返回SENSOR_SUCCESS,否则返回对应的错误码,详情请参见{@Link Sensor_Result}。 + * @param sensorEvent - 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_Sensor_GetEventAccuracy(Sensor_SensorEvent* sensorEvent, Sensor_SensorAccuracy *accuracy); /** - * @brief 获取传感器数据。数据的长度和内容依赖于监听的传感器类型,传感器上报的数据格式如下: - * SENSOR_TYPE_ACCELEROMETER: data[0]、data[1]、data[2]分别表示设备x、y、z轴的加速度分量,单位m/s2; - * SENSOR_TYPE_GYROSCOPE: data[0]、data[1]、data[2]分别表示设备x、y、z轴的旋转角速度,单位弧度/s; - * SENSOR_TYPE_AMBIENT_LIGHT: data[0]表示环境光强度,in lux; - * SENSOR_TYPE_MAGNETIC_FIELD: data[0]、data[1]、data[2]分别表示设备x、y、z轴的地磁分量,单位微特斯拉; - * SENSOR_TYPE_BAROMETER:data[0]表示气压值,单位hPa; - * SENSOR_TYPE_HALL: data[0]表示皮套吸合状态,0表示打开,大于0表示吸附; - * SENSOR_TYPE_PROXIMITY:data[0]表示接近状态,0表示接近,大于0表示远离; - * SENSOR_TYPE_ORIENTATION:data[0]、data[1]、data[2]分别表示设备绕z、x、y轴的角度,单位度; - * SENSOR_TYPE_GRAVITY:data[0]、data[1]、data[2]分别表示设备x、y、z轴的重力加速度分量,单位m/s2; - * SENSOR_TYPE_ROTATION_VECTOR:data[0]、data[1]、data[2]分别表示设备x、y、z轴的旋转角度,单位度,data[3]表示旋转向量元素; - * SENSOR_TYPE_PEDOMETER_DETECTION:data[0]表示几步检测状态,1表示检测到了步数变化 - * SENSOR_TYPE_PEDOMETER:data[0]表示步数; - * SENSOR_TYPE_HEART_RATE:data[0]表示心率数值; - * - * @param sensor - 传感器数据信息。 - * @param data - 出参,传感器数据。 - * @param length - 出参,数组长度。 - * @return 成功返回SENSOR_SUCCESS,否则返回对应的错误码,详情请参见{@Link Sensor_Result}。 + * @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 sensorEvent - 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_Sensor_GetSensorData(Sensor_SensorEvent* sensorEvent, float **data, uint32_t *length); /** - * @brief 传感器订阅Id,唯一标识传感器。 - * @syscap SystemCapability.Sensors.Sensor + * @brief Defines the sensor subscription ID, which uniquely identifies a sensor. * @since 11 */ typedef struct Sensor_SensorSubscribeId Sensor_SensorSubscribeId; @@ -369,28 +361,29 @@ Sensor_SensorSubscribeId *OH_Sensor_CreateSubscribeId(); int32_t OH_Sensor_DestroySubscribeId(Sensor_SensorSubscribeId *subscribeId); /** - * @brief 获取传感器类型。 + * @brief Obtains the sensor type. * - * @param subscribeId - 传感器订阅Id。 - * @param sensorType - 出参,传感器类型。 - * @return 成功返回SENSOR_SUCCESS,否则返回对应的错误码,详情请参见{@Link Sensor_Result}。 + * @param subscribeId - Pointer to the sensor subscription ID. + * @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_Sensor_GetSubscribeSensorType(Sensor_SensorSubscribeId* subscribeId, Sensor_SensorType *sensorType); /** - * @brief 设置传感器类型。 + * @brief Sets the sensor type. * - * @param subscribeId - 传感器订阅Id。 - * @param sensorType - 传感器类型。 - * @return 成功返回SENSOR_SUCCESS,否则返回对应的错误码,详情请参见{@Link Sensor_Result}。 + * @param subscribeId - 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_Sensor_SetSubscribeSensorType(Sensor_SensorSubscribeId* subscribeId, const Sensor_SensorType sensorType); /** - * @brief 传感器订阅属性。 - * @syscap SystemCapability.Sensors.Sensor + * @brief Defines the sensor subscription attribute. * @since 11 */ typedef struct Sensor_SubscribeAttribute Sensor_SubscribeAttribute; @@ -413,35 +406,35 @@ Sensor_SubscribeAttribute *OH_Sensor_CreateAttribute(); int32_t OH_Sensor_DestroyAttribute(Sensor_SubscribeAttribute *attribute); /** - * @brief 设置上报时间间隔。 + * @brief Sets the sensor data reporting interval. * - * @param attribute - 传感器订阅属性。 - * @param samplingInterval - 上报时间间隔,单位ns。 - * @return 成功返回SENSOR_SUCCESS,否则返回对应的错误码,详情请参见{@Link Sensor_Result}。 + * @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_Sensor_SetSamplingInterval(Sensor_SubscribeAttribute* attribute, const int64_t samplingInterval); /** - * @brief 获取上报时间间隔。 + * @brief Obtains the sensor data reporting interval. * - * @param attribute - 传感器订阅属性。 - * @param samplingInterval - 出参,上报时间间隔,单位ns。 - * @return 成功返回SENSOR_SUCCESS,否则返回对应的错误码,详情请参见{@Link Sensor_Result}。 + * @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_Sensor_GetSamplingInterval(Sensor_SubscribeAttribute* attribute, int64_t *samplingInterval); /** - * @brief 传感器数据的回调函数。 - * @syscap SystemCapability.Sensors.Sensor + * @brief Defines the callback function used to report sensor data. * @since 11 */ typedef void (*Sensor_RecordSensorCallback)(Sensor_SensorEvent *event); /** - * @brief 传感器订阅者信息。 - * @syscap SystemCapability.Sensors.Sensor + * @brief Defines the sensor subscriber information. * @since 11 */ typedef struct Sensor_SubscribeUser Sensor_SubscribeUser; @@ -464,21 +457,23 @@ Sensor_SubscribeUser *OH_Sensor_CreateUser(); int32_t OH_Sensor_DestroyUser(Sensor_SubscribeUser *user); /** - * @brief 设置传感器数据的回调函数。 + * @brief Sets a callback function to report sensor data. * - * @param user - 传感器订阅者信息。 - * @param callback - 传感器数据的回调函数。 - * @return 成功返回SENSOR_SUCCESS,否则返回对应的错误码,详情请参见{@Link Sensor_Result}。 + * @param user - 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_Sensor_SetSensorCallback(Sensor_SubscribeUser* user, const Sensor_RecordSensorCallback callback); /** - * @brief 获取传感器数据的回调函数。 + * @brief Obtains the callback function used to report sensor data. * - * @param user - 传感器订阅者信息。 - * @param callback - 出参,传感器数据的回调函数。 - * @return 成功返回SENSOR_SUCCESS,否则返回对应的错误码,详情请参见{@Link Sensor_Result}。 + * @param user - 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_Sensor_GetSensorCallback(Sensor_SubscribeUser* user, Sensor_RecordSensorCallback *callback); -- Gitee From 1cfd814d73f0d1b4fcaf30a4f2778fa8e96dc98b Mon Sep 17 00:00:00 2001 From: hellohyh001 Date: Wed, 29 Nov 2023 02:32:06 +0000 Subject: [PATCH 04/16] update Signed-off-by: hellohyh001 Change-Id: I10264c562b5dc62c75aec28d8f35a2e6d6d4a93a --- .../interfaces/kits/sensor_native_test.cpp | 39 +++++++++++-------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/test/unittest/interfaces/kits/sensor_native_test.cpp b/test/unittest/interfaces/kits/sensor_native_test.cpp index 033c76b8..8e648fac 100755 --- a/test/unittest/interfaces/kits/sensor_native_test.cpp +++ b/test/unittest/interfaces/kits/sensor_native_test.cpp @@ -35,6 +35,11 @@ using Security::AccessToken::AccessTokenID; namespace { constexpr HiLogLabel LABEL = { LOG_CORE, OHOS::Sensors::SENSOR_LOG_DOMAIN, "SensorAgentTest" }; constexpr Sensor_SensorType SENSOR_ID { SENSOR_TYPE_ACCELEROMETER }; +constexpr uint32_t SENSOR_NAME_LENGTH_MAX = 64; +constexpr int64_t SENSOR_SAMPLE_PERIOD = 200000000; +constexpr int32_t SLEEP_TIME_MS = 1000; +constexpr int64_t INVALID_VALUE = -1; +constexpr float INVALID_RESOLUTION = -1.0F; PermissionDef g_infoManagerTestPermDef = { .permissionName = "ohos.permission.ACCELEROMETER", @@ -113,7 +118,7 @@ void SensorDataCallbackImpl(Sensor_SensorEvent *event) SEN_HILOGE("event is null"); return; } - int64_t timestamp = -1; + int64_t timestamp = INVALID_VALUE; int32_t ret = OH_Sensor_GetEventTimestamp(event, ×tamp); ASSERT_EQ(ret, SENSOR_SUCCESS); Sensor_SensorType sensorType; @@ -126,9 +131,9 @@ void SensorDataCallbackImpl(Sensor_SensorEvent *event) size_t length = 0; ret = OH_Sensor_GetSensorData(event, &data, &length); ASSERT_EQ(ret, SENSOR_SUCCESS); - SEN_HILOGI("sensorType:%{public}d, dataLen:%{public}d, accuracy:%{public}d", - sensorType, length, accuracy); - SEN_HILOGI("x:%{public}f, y:%{public}f, z:%{public}f", data[0], data[1], data[2]); + SEN_HILOGI("sensorType:%{public}d, dataLen:%{public}d, accuracy:%{public}d" + "x:%{public}f, y:%{public}f, z:%{public}f", sensorType, length, accuracy, + data[0], data[1], data[2]); } HWTEST_F(SensorAgentTest, OH_Sensor_GetAllSensors_001, TestSize.Level1) @@ -142,24 +147,24 @@ HWTEST_F(SensorAgentTest, OH_Sensor_GetAllSensors_001, TestSize.Level1) ret = OH_Sensor_GetAllSensors(sensors, &count); ASSERT_EQ(ret, SENSOR_SUCCESS); for (uint32_t i = 0; i < count; ++i) { - char sensorName[64] = {}; - size_t length = 64; + char sensorName[SENSOR_NAME_LENGTH_MAX] = {}; + size_t length = SENSOR_NAME_LENGTH_MAX; ret = OH_Sensor_GetSensorName(sensors[i], sensorName, &length); ASSERT_EQ(ret, SENSOR_SUCCESS); - char vendorName[64] = {}; - length = 64; + char vendorName[SENSOR_NAME_LENGTH_MAX] = {}; + length = SENSOR_NAME_LENGTH_MAX; ret = OH_Sensor_GetVendorName(sensors[i], vendorName, &length); ASSERT_EQ(ret, SENSOR_SUCCESS); Sensor_SensorType sensorType; ret = OH_Sensor_GetSensorType(sensors[i], &sensorType); ASSERT_EQ(ret, SENSOR_SUCCESS); - float resolution = -1.0F; + float resolution = INVALID_RESOLUTION; ret = OH_Sensor_GetSensorResolution(sensors[i], &resolution); ASSERT_EQ(ret, SENSOR_SUCCESS); - int64_t minSamplePeriod = -1; + int64_t minSamplePeriod = INVALID_VALUE; ret = OH_Sensor_GetSensorMinSamplePeriod(sensors[i], &minSamplePeriod); ASSERT_EQ(ret, SENSOR_SUCCESS); - int64_t maxSamplePeriod = -1; + int64_t maxSamplePeriod = INVALID_VALUE; ret = OH_Sensor_GetSensorMaxSamplePeriod(sensors[i], &maxSamplePeriod); ASSERT_EQ(ret, SENSOR_SUCCESS); SEN_HILOGI("sensorType:%{public}d, sensorName:%{public}s, vendorName:%{public}s," @@ -199,13 +204,13 @@ HWTEST_F(SensorAgentTest, OH_Sensor_SubscribeSensor_001, TestSize.Level1) ASSERT_EQ(ret, SENSOR_SUCCESS); Sensor_SubscribeAttribute *attr = OH_Sensor_CreateAttribute(); - ret = OH_Sensor_SetSamplingInterval(attr, 200000000); + ret = OH_Sensor_SetSamplingInterval(attr, SENSOR_SAMPLE_PERIOD); ASSERT_EQ(ret, SENSOR_SUCCESS); ret = OH_Sensor_SubscribeSensor(id, attr, g_user); ASSERT_EQ(ret, SENSOR_SUCCESS); - std::this_thread::sleep_for(std::chrono::milliseconds(1000)); + std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_TIME_MS)); ret = OH_Sensor_UnsubscribeSensor(id, g_user); ASSERT_EQ(ret, SENSOR_SUCCESS); if (id != nullptr) { @@ -228,7 +233,7 @@ HWTEST_F(SensorAgentTest, OH_Sensor_SubscribeSensor_002, TestSize.Level1) ASSERT_EQ(ret, SENSOR_SUCCESS); Sensor_SubscribeAttribute *attr = OH_Sensor_CreateAttribute(); - ret = OH_Sensor_SetSamplingInterval(attr, 200000000); + ret = OH_Sensor_SetSamplingInterval(attr, SENSOR_SAMPLE_PERIOD); ASSERT_EQ(ret, SENSOR_SUCCESS); ret = OH_Sensor_SubscribeSensor(id, attr, nullptr); @@ -249,7 +254,7 @@ HWTEST_F(SensorAgentTest, OH_Sensor_SubscribeSensor_003, TestSize.Level1) ASSERT_EQ(ret, SENSOR_SUCCESS); Sensor_SubscribeAttribute *attr = OH_Sensor_CreateAttribute(); - ret = OH_Sensor_SetSamplingInterval(attr, 200000000); + ret = OH_Sensor_SetSamplingInterval(attr, SENSOR_SAMPLE_PERIOD); ASSERT_EQ(ret, SENSOR_SUCCESS); ret = OH_Sensor_SubscribeSensor(nullptr, attr, g_user); @@ -343,7 +348,7 @@ HWTEST_F(SensorAgentTest, OH_Sensor_GetSubscribeSensorType_002, TestSize.Level1) HWTEST_F(SensorAgentTest, OH_Sensor_SetSamplingInterval_001, TestSize.Level1) { SEN_HILOGI("OH_Sensor_SetSamplingInterval_001 in"); - int32_t ret = OH_Sensor_SetSamplingInterval(nullptr, 2000000000); + int32_t ret = OH_Sensor_SetSamplingInterval(nullptr, SENSOR_SAMPLE_PERIOD); ASSERT_EQ(ret, SENSOR_PARAMETER_ERROR); } @@ -351,7 +356,7 @@ HWTEST_F(SensorAgentTest, OH_Sensor_SetSamplingInterval_002, TestSize.Level1) { SEN_HILOGI("OH_Sensor_SetSamplingInterval_002 in"); Sensor_SubscribeAttribute *attr = OH_Sensor_CreateAttribute(); - int32_t ret = OH_Sensor_SetSamplingInterval(attr, -1); + int32_t ret = OH_Sensor_SetSamplingInterval(attr, INVALID_VALUE); ASSERT_EQ(ret, SENSOR_PARAMETER_ERROR); if (attr != nullptr) { OH_Sensor_DestroyAttribute(attr); -- Gitee From b78107006136bdd28ee48414c6ab9bef7e5f1163 Mon Sep 17 00:00:00 2001 From: hellohyh001 Date: Wed, 29 Nov 2023 06:13:11 +0000 Subject: [PATCH 05/16] update Signed-off-by: hellohyh001 Change-Id: I9f5f59aa85c969f975b5324df6e4b7c67a7065b2 --- test/unittest/interfaces/kits/sensor_native_test.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/unittest/interfaces/kits/sensor_native_test.cpp b/test/unittest/interfaces/kits/sensor_native_test.cpp index 8e648fac..410b8946 100755 --- a/test/unittest/interfaces/kits/sensor_native_test.cpp +++ b/test/unittest/interfaces/kits/sensor_native_test.cpp @@ -128,7 +128,7 @@ void SensorDataCallbackImpl(Sensor_SensorEvent *event) ret = OH_Sensor_GetEventAccuracy(event, &accuracy); ASSERT_EQ(ret, SENSOR_SUCCESS); float *data = nullptr; - size_t length = 0; + uint32_t length = 0; ret = OH_Sensor_GetSensorData(event, &data, &length); ASSERT_EQ(ret, SENSOR_SUCCESS); SEN_HILOGI("sensorType:%{public}d, dataLen:%{public}d, accuracy:%{public}d" @@ -148,7 +148,7 @@ HWTEST_F(SensorAgentTest, OH_Sensor_GetAllSensors_001, TestSize.Level1) ASSERT_EQ(ret, SENSOR_SUCCESS); for (uint32_t i = 0; i < count; ++i) { char sensorName[SENSOR_NAME_LENGTH_MAX] = {}; - size_t length = SENSOR_NAME_LENGTH_MAX; + uint32_t length = SENSOR_NAME_LENGTH_MAX; ret = OH_Sensor_GetSensorName(sensors[i], sensorName, &length); ASSERT_EQ(ret, SENSOR_SUCCESS); char vendorName[SENSOR_NAME_LENGTH_MAX] = {}; -- Gitee From 0695eba38e6bdb475192a8708448449c2a90a768 Mon Sep 17 00:00:00 2001 From: hellohyh001 Date: Wed, 29 Nov 2023 06:39:02 +0000 Subject: [PATCH 06/16] update Signed-off-by: hellohyh001 Change-Id: I1602f71e5472e91c0f5113f8756580cdfe60a236 --- interfaces/kits/c/native_sensor_type.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/interfaces/kits/c/native_sensor_type.h b/interfaces/kits/c/native_sensor_type.h index 3fdadf11..952e5c29 100644 --- a/interfaces/kits/c/native_sensor_type.h +++ b/interfaces/kits/c/native_sensor_type.h @@ -349,7 +349,7 @@ typedef struct Sensor_SensorSubscribeId Sensor_SensorSubscribeId; * @return 如果创建成功,则返回指向{@link Sensor_SensorSubscribeId} 结构实例的指针,否则返回NULL. * @since 11 */ -Sensor_SensorSubscribeId *OH_Sensor_CreateSubscribeId(); +Sensor_SensorSubscribeId *OH_Sensor_CreateSubscribeId(void); /** * @brief 销毁{@link Sensor_SensorSubscribeId}实例并回收内存。 @@ -394,7 +394,7 @@ typedef struct Sensor_SubscribeAttribute Sensor_SubscribeAttribute; * @return 如果创建成功,则返回指向{@link Sensor_SubscribeAttribute} 结构实例的指针,否则返回NULL. * @since 11 */ -Sensor_SubscribeAttribute *OH_Sensor_CreateAttribute(); +Sensor_SubscribeAttribute *OH_Sensor_CreateAttribute(void); /** * @brief 销毁{@link Sensor_SubscribeAttribute}实例并回收内存。 @@ -445,7 +445,7 @@ typedef struct Sensor_SubscribeUser Sensor_SubscribeUser; * @return 如果创建成功,则返回指向{@link Sensor_SubscribeUser} 结构实例的指针,否则返回NULL. * @since 11 */ -Sensor_SubscribeUser *OH_Sensor_CreateUser(); +Sensor_SubscribeUser *OH_Sensor_CreateUser(void); /** * @brief 销毁{@link Sensor_SubscribeUser}实例并回收内存。 -- Gitee From 6617e6283deab1167e8069e9b1dab21931f75eae Mon Sep 17 00:00:00 2001 From: hellohyh001 Date: Wed, 29 Nov 2023 08:15:52 +0000 Subject: [PATCH 07/16] update Signed-off-by: hellohyh001 Change-Id: Id24cae518f967eccb59125a615ac4301618b3f2c --- frameworks/native/src/native_sensor.cpp | 2 +- interfaces/kits/c/native_sensor_type.h | 58 +++++++++++++++---------- 2 files changed, 35 insertions(+), 25 deletions(-) diff --git a/frameworks/native/src/native_sensor.cpp b/frameworks/native/src/native_sensor.cpp index 91274d7c..b5bd0e2b 100644 --- a/frameworks/native/src/native_sensor.cpp +++ b/frameworks/native/src/native_sensor.cpp @@ -25,7 +25,7 @@ using OHOS::HiviewDFX::HiLog; using OHOS::HiviewDFX::HiLogLabel; namespace { const HiLogLabel LABEL = {LOG_CORE, OHOS::Sensors::SENSOR_LOG_DOMAIN, "SensorCapiAPI"}; -const uint32_t FLOAT_SIZE= 4; +const uint32_t FLOAT_SIZE = 4; } Sensor_Result OH_Sensor_GetAllSensors(Sensor_Sensor **sensors, uint32_t *count) diff --git a/interfaces/kits/c/native_sensor_type.h b/interfaces/kits/c/native_sensor_type.h index 952e5c29..71b29b2f 100644 --- a/interfaces/kits/c/native_sensor_type.h +++ b/interfaces/kits/c/native_sensor_type.h @@ -154,12 +154,14 @@ typedef enum Sensor_SensorAccuracy { */ 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. + * 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. + * 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, @@ -177,20 +179,22 @@ typedef enum Sensor_SensorAccuracy { typedef struct Sensor_Sensor Sensor_Sensor; /** - * @brief 创建给定个数{@link Sensor_Sensor}实例的数组。 + * @brief Creates an array of {@link Sensor_Sensor} instances with the given number. * - * @param count - 表示要创建{@link Sensor_Sensor}实例的个数. - * @return 如果创建成功,则返回{@link Sensor_Sensor}实例的数组,否则返回 NULL。。 + * @param count - Number of {@link Sensor_Sensor} instances to create. + * @return Returns the double pointer to the array of {@link Sensor_Sensor} instances if the operation is successful; + * returns NULL otherwise. * @since 11 */ Sensor_Sensor **OH_Sensor_CreateSensors(uint32_t count); /** - * @brief 销毁{@link Sensor_Sensor}实例的数组并回收内存。 + * @brief Destroys an array of {@link Sensor_Sensor} instances and reclaims memory. * - * @param sensors - 表示要销毁的{@link Sensor_Sensor}实例的数组. - * @param count - 表示要销毁的{@link Sensor_Sensor}实例的个数. - * @return 成功返回SENSOR_SUCCESS,否则返回对应的错误码,详情请参见{@Link Sensor_Result}。 + * @param sensors - Double pointer to the array of {@link Sensor_Sensor} instances. + * @param count - Number of {@link Sensor_Sensor} 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_DestroySensors(Sensor_Sensor **sensors, uint32_t count); @@ -344,18 +348,20 @@ int32_t OH_Sensor_GetSensorData(Sensor_SensorEvent* sensorEvent, float **data, u typedef struct Sensor_SensorSubscribeId Sensor_SensorSubscribeId; /** - * @brief 创建指向{@link Sensor_SensorSubscribeId}实例的指针。 + * @brief Creates a {@link Sensor_SensorSubscribeId} instance. * - * @return 如果创建成功,则返回指向{@link Sensor_SensorSubscribeId} 结构实例的指针,否则返回NULL. + * @return Returns the pointer to the {@link Sensor_SensorSubscribeId} instance if the operation is successful; + * returns NULL otherwise. * @since 11 */ Sensor_SensorSubscribeId *OH_Sensor_CreateSubscribeId(void); /** - * @brief 销毁{@link Sensor_SensorSubscribeId}实例并回收内存。 + * @brief Destroys a {@link Sensor_SensorSubscribeId} instance and reclaims memory. * - * @param subscribeId - 表示指向 {@link Sensor_SensorSubscribeId} 实例的指针. - * @return 成功返回SENSOR_SUCCESS,否则返回对应的错误码,详情请参见{@Link Sensor_Result}。 + * @param subscribeId - Pointer to the {@link Sensor_SensorSubscribeId} 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_DestroySubscribeId(Sensor_SensorSubscribeId *subscribeId); @@ -389,18 +395,20 @@ int32_t OH_Sensor_SetSubscribeSensorType(Sensor_SensorSubscribeId* subscribeId, typedef struct Sensor_SubscribeAttribute Sensor_SubscribeAttribute; /** - * @brief 创建指向{@link Sensor_SubscribeAttribute}实例的指针。 + * @brief Creates a {@link Sensor_SubscribeAttribute} instance. * - * @return 如果创建成功,则返回指向{@link Sensor_SubscribeAttribute} 结构实例的指针,否则返回NULL. + * @return Returns the pointer to the {@link Sensor_SubscribeAttribute} instance if the operation is successful; + * returns NULL otherwise. * @since 11 */ Sensor_SubscribeAttribute *OH_Sensor_CreateAttribute(void); /** - * @brief 销毁{@link Sensor_SubscribeAttribute}实例并回收内存。 + * @brief Destroys a {@link Sensor_SubscribeAttribute} instance and reclaims memory. * - * @param attribute - 表示指向 {@link Sensor_SubscribeAttribute} 实例的指针. - * @return 成功返回SENSOR_SUCCESS,否则返回对应的错误码,详情请参见{@Link Sensor_Result}。 + * @param attribute - Pointer to the {@link Sensor_SubscribeAttribute} 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_DestroyAttribute(Sensor_SubscribeAttribute *attribute); @@ -440,18 +448,20 @@ typedef void (*Sensor_RecordSensorCallback)(Sensor_SensorEvent *event); typedef struct Sensor_SubscribeUser Sensor_SubscribeUser; /** - * @brief 创建指向{@link Sensor_SubscribeUser}实例的指针。 + * @brief Creates a {@link Sensor_SubscribeUser} instance. * - * @return 如果创建成功,则返回指向{@link Sensor_SubscribeUser} 结构实例的指针,否则返回NULL. + * @return Returns the pointer to the {@link Sensor_SubscribeUser} instance + * if the operation is successful; returns NULL otherwise. * @since 11 */ Sensor_SubscribeUser *OH_Sensor_CreateUser(void); /** - * @brief 销毁{@link Sensor_SubscribeUser}实例并回收内存。 + * @brief Destroys a {@link Sensor_SubscribeUser} instance and reclaims memory. * - * @param user - 表示指向{@link Sensor_SubscribeUser}实例的指针. - * @return 成功返回SENSOR_SUCCESS,否则返回对应的错误码,详情请参见{@Link Sensor_Result}。 + * @param user - Pointer to the {@link Sensor_SubscribeUser} 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_DestroyUser(Sensor_SubscribeUser *user); -- Gitee From b7a91b7bd18b12af0e61c2ac4639294fbbef48f0 Mon Sep 17 00:00:00 2001 From: hellohyh001 Date: Wed, 29 Nov 2023 09:33:06 +0000 Subject: [PATCH 08/16] update Signed-off-by: hellohyh001 Change-Id: I70677b69f3a5c1906d6d6a68cc9cd6920c293ce8 --- test/unittest/interfaces/kits/sensor_native_test.cpp | 8 -------- 1 file changed, 8 deletions(-) diff --git a/test/unittest/interfaces/kits/sensor_native_test.cpp b/test/unittest/interfaces/kits/sensor_native_test.cpp index 410b8946..8f6e554a 100755 --- a/test/unittest/interfaces/kits/sensor_native_test.cpp +++ b/test/unittest/interfaces/kits/sensor_native_test.cpp @@ -177,14 +177,6 @@ HWTEST_F(SensorAgentTest, OH_Sensor_GetAllSensors_001, TestSize.Level1) } HWTEST_F(SensorAgentTest, OH_Sensor_GetAllSensors_002, TestSize.Level1) -{ - SEN_HILOGI("OH_Sensor_GetAllSensors_002 in"); - uint32_t count = 0; - int32_t ret = OH_Sensor_GetAllSensors(nullptr, &count); - ASSERT_NE(ret, SENSOR_SUCCESS); -} - -HWTEST_F(SensorAgentTest, OH_Sensor_GetAllSensors_003, TestSize.Level1) { SEN_HILOGI("OH_Sensor_GetAllSensors_003 in"); Sensor_Sensor *sensors { nullptr }; -- Gitee From 71215c41934c0df4d9e5ffc9b8759749477e93af Mon Sep 17 00:00:00 2001 From: hellohyh001 Date: Thu, 30 Nov 2023 06:30:37 +0000 Subject: [PATCH 09/16] update Signed-off-by: hellohyh001 Change-Id: I6ca0037e93a4fed90029e19a39c78261dfc1289d --- interfaces/kits/c/native_sensor.h | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/interfaces/kits/c/native_sensor.h b/interfaces/kits/c/native_sensor.h index c9985ed9..753bc2b0 100644 --- a/interfaces/kits/c/native_sensor.h +++ b/interfaces/kits/c/native_sensor.h @@ -54,6 +54,11 @@ Sensor_Result OH_Sensor_GetAllSensors(Sensor_Sensor **sensors, 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_SensorSubscribeId}. * @param attribute - Pointer to the subscription attribute, which is used to specify the data reporting frequency. @@ -62,7 +67,7 @@ Sensor_Result OH_Sensor_GetAllSensors(Sensor_Sensor **sensors, uint32_t *count); * the sensor data. For details, see {@link Sensor_SubscribeUser}. * @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_SubscribeSensor(const Sensor_SensorSubscribeId *id, const Sensor_SubscribeAttribute *attribute, @@ -70,12 +75,18 @@ Sensor_Result OH_Sensor_SubscribeSensor(const Sensor_SensorSubscribeId *id, cons /** * @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_SensorSubscribeId}. * @param user - Pointer to the subscriber information, which is used to specify the callback function for reporting * the sensor data. For details, see {@link Sensor_SubscribeUser}. * @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 */ -- Gitee From fb6e02aab388f8c074f10d4db8f7f54f7358253c Mon Sep 17 00:00:00 2001 From: hellohyh001 Date: Thu, 30 Nov 2023 07:39:15 +0000 Subject: [PATCH 10/16] update Signed-off-by: hellohyh001 Change-Id: Ifb9354b1b007c78e00be69f8d98264d6f9b5b037 --- interfaces/kits/c/native_sensor_type.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interfaces/kits/c/native_sensor_type.h b/interfaces/kits/c/native_sensor_type.h index 71b29b2f..6e849773 100644 --- a/interfaces/kits/c/native_sensor_type.h +++ b/interfaces/kits/c/native_sensor_type.h @@ -27,7 +27,7 @@ * * @brief Declares the common sensor attributes. * @library libsensor_native.z.so - * + * @syscap SystemCapability.Sensors.Sensor * @since 11 */ -- Gitee From 54312d5ac8a9a3fe8ef7a6671ef768b0edf2d949 Mon Sep 17 00:00:00 2001 From: hellohyh001 Date: Thu, 30 Nov 2023 09:46:24 +0000 Subject: [PATCH 11/16] update Signed-off-by: hellohyh001 Change-Id: I55d7eac16cc8a487eb87e92790c1e4b33d3a95a0 --- .../native/include/native_sensor_impl.h | 8 +- frameworks/native/src/native_sensor.cpp | 60 ++++++------- interfaces/kits/c/libsensor.ndk.json | 16 ++-- interfaces/kits/c/native_sensor.h | 20 ++--- interfaces/kits/c/native_sensor_type.h | 74 ++++++++-------- .../interfaces/kits/sensor_native_test.cpp | 86 +++++++++---------- 6 files changed, 132 insertions(+), 132 deletions(-) diff --git a/frameworks/native/include/native_sensor_impl.h b/frameworks/native/include/native_sensor_impl.h index e2c88327..238e3b4c 100644 --- a/frameworks/native/include/native_sensor_impl.h +++ b/frameworks/native/include/native_sensor_impl.h @@ -33,18 +33,18 @@ struct Sensor_Sensor { int64_t maxSamplePeriod = -1; /**< Maximum sample period allowed, in ns */ }; -struct Sensor_SubscribeAttribute { +struct Sensor_SubscriptionAttribute { int64_t samplingInterval = -1; int64_t reportInterval = -1; }; -struct Sensor_SensorSubscribeId { +struct Sensor_SensorSubscriptionId { int32_t sensorType = -1; }; -struct Sensor_SubscribeUser { +struct Sensor_Subscriber { char name[NAME_MAX_LEN]; - Sensor_RecordSensorCallback callback; + Sensor_SensorCallback callback; UserData *userData = nullptr; }; diff --git a/frameworks/native/src/native_sensor.cpp b/frameworks/native/src/native_sensor.cpp index b5bd0e2b..375ae3c1 100644 --- a/frameworks/native/src/native_sensor.cpp +++ b/frameworks/native/src/native_sensor.cpp @@ -151,7 +151,7 @@ int32_t OH_Sensor_GetSensorResolution(Sensor_Sensor* sensor, float *resolution) return SENSOR_SUCCESS; } -int32_t OH_Sensor_GetSensorMinSamplePeriod(Sensor_Sensor* sensor, int64_t *minSamplePeriod) +int32_t OH_Sensor_GetMinSamplingInterval(Sensor_Sensor* sensor, int64_t *minSamplePeriod) { if (sensor == nullptr || minSamplePeriod == nullptr) { SEN_HILOGE("Parameter error"); @@ -161,7 +161,7 @@ int32_t OH_Sensor_GetSensorMinSamplePeriod(Sensor_Sensor* sensor, int64_t *minSa return SENSOR_SUCCESS; } -int32_t OH_Sensor_GetSensorMaxSamplePeriod(Sensor_Sensor* sensor, int64_t *maxSamplePeriod) +int32_t OH_Sensor_GetMaxSamplingInterval(Sensor_Sensor* sensor, int64_t *maxSamplePeriod) { if (sensor == nullptr || maxSamplePeriod == nullptr) { SEN_HILOGE("Parameter error"); @@ -171,8 +171,8 @@ int32_t OH_Sensor_GetSensorMaxSamplePeriod(Sensor_Sensor* sensor, int64_t *maxSa return SENSOR_SUCCESS; } -Sensor_Result OH_Sensor_SubscribeSensor(const Sensor_SensorSubscribeId *id, - const Sensor_SubscribeAttribute *attribute, const Sensor_SubscribeUser *user) +Sensor_Result OH_Sensor_SubscribeSensor(const Sensor_SensorSubscriptionId *id, + const Sensor_SubscriptionAttribute *attribute, const Sensor_Subscriber *user) { if (id == nullptr || attribute == nullptr || user == nullptr) { SEN_HILOGE("Parameter error"); @@ -194,15 +194,15 @@ Sensor_Result OH_Sensor_SubscribeSensor(const Sensor_SensorSubscribeId *id, return static_cast(ActivateSensor(sensorType, sensorUser)); } -Sensor_Result OH_Sensor_UnsubscribeSensor(const Sensor_SensorSubscribeId *subscribeId, - const Sensor_SubscribeUser *user) +Sensor_Result OH_Sensor_UnsubscribeSensor(const Sensor_SensorSubscriptionId *id, + const Sensor_Subscriber *user) { - if (subscribeId == nullptr || user == nullptr) { + if (id == nullptr || user == nullptr) { SEN_HILOGE("Parameter error"); return SENSOR_PARAMETER_ERROR; } const SensorUser *sensorUser = reinterpret_cast(user); - int32_t sensorType = subscribeId->sensorType; + int32_t sensorType = id->sensorType; int32_t ret = DeactivateSensor(sensorType, sensorUser); if (ret != SENSOR_SUCCESS) { SEN_HILOGE("SetBatch failed, %{public}d", ret); @@ -252,27 +252,27 @@ int32_t OH_Sensor_GetSensorData(Sensor_SensorEvent* sensorEvent, float **data, u return SENSOR_SUCCESS; } -int32_t OH_Sensor_GetSubscribeSensorType(Sensor_SensorSubscribeId* subscribeId, Sensor_SensorType *sensorType) +int32_t OH_Sensor_GetSubscriptionSensorType(Sensor_SensorSubscriptionId* id, Sensor_SensorType *sensorType) { - if (subscribeId == nullptr || sensorType == nullptr) { + if (id == nullptr || sensorType == nullptr) { SEN_HILOGE("Parameter error"); return SENSOR_PARAMETER_ERROR; } - *sensorType = static_cast(subscribeId->sensorType); + *sensorType = static_cast(id->sensorType); return SENSOR_SUCCESS; } -int32_t OH_Sensor_SetSubscribeSensorType(Sensor_SensorSubscribeId* subscribeId, const Sensor_SensorType sensorType) +int32_t OH_Sensor_SetSubscriptionSensorType(Sensor_SensorSubscriptionId* id, const Sensor_SensorType sensorType) { - if (subscribeId == nullptr) { + if (id == nullptr) { SEN_HILOGE("Parameter error"); return SENSOR_PARAMETER_ERROR; } - subscribeId->sensorType = sensorType; + id->sensorType = sensorType; return SENSOR_SUCCESS; } -int32_t OH_Sensor_SetSamplingInterval(Sensor_SubscribeAttribute* attribute, const int64_t samplingInterval) +int32_t OH_Sensor_SetSamplingInterval(Sensor_SubscriptionAttribute* attribute, const int64_t samplingInterval) { if (attribute == nullptr || samplingInterval < 0) { SEN_HILOGE("Parameter error"); @@ -282,7 +282,7 @@ int32_t OH_Sensor_SetSamplingInterval(Sensor_SubscribeAttribute* attribute, cons return SENSOR_SUCCESS; } -int32_t OH_Sensor_GetSamplingInterval(Sensor_SubscribeAttribute* attribute, int64_t *samplingInterval) +int32_t OH_Sensor_GetSamplingInterval(Sensor_SubscriptionAttribute* attribute, int64_t *samplingInterval) { if (attribute == nullptr || samplingInterval == nullptr) { SEN_HILOGE("Parameter error"); @@ -292,7 +292,7 @@ int32_t OH_Sensor_GetSamplingInterval(Sensor_SubscribeAttribute* attribute, int6 return SENSOR_SUCCESS; } -int32_t OH_Sensor_SetSensorCallback(Sensor_SubscribeUser* user, const Sensor_RecordSensorCallback callback) +int32_t OH_Sensor_SetSensorCallback(Sensor_Subscriber* user, const Sensor_SensorCallback callback) { if (user == nullptr || callback == nullptr) { SEN_HILOGE("Parameter error"); @@ -302,7 +302,7 @@ int32_t OH_Sensor_SetSensorCallback(Sensor_SubscribeUser* user, const Sensor_Rec return SENSOR_SUCCESS; } -int32_t OH_Sensor_GetSensorCallback(Sensor_SubscribeUser* user, Sensor_RecordSensorCallback *callback) +int32_t OH_Sensor_GetSensorCallback(Sensor_Subscriber* user, Sensor_SensorCallback *callback) { if (user == nullptr || callback == nullptr) { SEN_HILOGE("Parameter error"); @@ -312,28 +312,28 @@ int32_t OH_Sensor_GetSensorCallback(Sensor_SubscribeUser* user, Sensor_RecordSen return SENSOR_SUCCESS; } -Sensor_SensorSubscribeId *OH_Sensor_CreateSubscribeId() +Sensor_SensorSubscriptionId *OH_Sensor_CreateSubscriptionId() { - return new (std::nothrow) Sensor_SensorSubscribeId(); + return new (std::nothrow) Sensor_SensorSubscriptionId(); } -int32_t OH_Sensor_DestroySubscribeId(Sensor_SensorSubscribeId *subscribeId) +int32_t OH_Sensor_DestroySubscriptionId(Sensor_SensorSubscriptionId *id) { - if (subscribeId == nullptr) { + if (id == nullptr) { SEN_HILOGE("Parameter error"); return SENSOR_PARAMETER_ERROR; } - delete subscribeId; - subscribeId = nullptr; + delete id; + id = nullptr; return SENSOR_SUCCESS; } -Sensor_SubscribeAttribute *OH_Sensor_CreateAttribute() +Sensor_SubscriptionAttribute *OH_Sensor_CreateAttribute() { - return new (std::nothrow) Sensor_SubscribeAttribute(); + return new (std::nothrow) Sensor_SubscriptionAttribute(); } -int32_t OH_Sensor_DestroyAttribute(Sensor_SubscribeAttribute *attribute) +int32_t OH_Sensor_DestroyAttribute(Sensor_SubscriptionAttribute *attribute) { if (attribute == nullptr) { SEN_HILOGE("Parameter error"); @@ -344,12 +344,12 @@ int32_t OH_Sensor_DestroyAttribute(Sensor_SubscribeAttribute *attribute) return SENSOR_SUCCESS; } -Sensor_SubscribeUser *OH_Sensor_CreateUser() +Sensor_Subscriber *OH_Sensor_CreateSubscriber() { - return new (std::nothrow) Sensor_SubscribeUser(); + return new (std::nothrow) Sensor_Subscriber(); } -int32_t OH_Sensor_DestroyUser(Sensor_SubscribeUser *user) +int32_t OH_Sensor_DestroySubscriber(Sensor_Subscriber *user) { if (user == nullptr) { SEN_HILOGE("Parameter error"); diff --git a/interfaces/kits/c/libsensor.ndk.json b/interfaces/kits/c/libsensor.ndk.json index 98f99149..8a761a0b 100644 --- a/interfaces/kits/c/libsensor.ndk.json +++ b/interfaces/kits/c/libsensor.ndk.json @@ -21,10 +21,10 @@ "name": "OH_Sensor_GetSensorResolution" }, { - "name": "OH_Sensor_GetSensorMinSamplePeriod" + "name": "OH_Sensor_GetMinSamplingInterval" }, { - "name": "OH_Sensor_GetSensorMaxSamplePeriod" + "name": "OH_Sensor_GetMaxSamplingInterval" }, { "name": "OH_Sensor_GetEventSensorType" @@ -39,10 +39,10 @@ "name": "OH_Sensor_GetSensorData" }, { - "name": "OH_Sensor_GetSubscribeSensorType" + "name": "OH_Sensor_GetSubscriptionSensorType" }, { - "name": "OH_Sensor_SetSubscribeSensorType" + "name": "OH_Sensor_SetSubscriptionSensorType" }, { "name": "OH_Sensor_SetSamplingInterval" @@ -63,10 +63,10 @@ "name": "OH_Sensor_DestroySensors" }, { - "name": "OH_Sensor_CreateSubscribeId" + "name": "OH_Sensor_CreateSubscriptionId" }, { - "name": "OH_Sensor_DestroySubscribeId" + "name": "OH_Sensor_DestroySubscriptionId" }, { "name": "OH_Sensor_CreateAttribute" @@ -75,9 +75,9 @@ "name": "OH_Sensor_DestroyAttribute" }, { - "name": "OH_Sensor_CreateUser" + "name": "OH_Sensor_CreateSubscriber" }, { - "name": "OH_Sensor_DestroyUser" + "name": "OH_Sensor_DestroySubscriber" } ] \ No newline at end of file diff --git a/interfaces/kits/c/native_sensor.h b/interfaces/kits/c/native_sensor.h index 753bc2b0..9c49d660 100644 --- a/interfaces/kits/c/native_sensor.h +++ b/interfaces/kits/c/native_sensor.h @@ -60,18 +60,18 @@ Sensor_Result OH_Sensor_GetAllSensors(Sensor_Sensor **sensors, uint32_t *count); * 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_SensorSubscribeId}. + * @param id - Pointer to the sensor subscription ID. For details, see {@link Sensor_SensorSubscriptionId}. * @param attribute - Pointer to the subscription attribute, which is used to specify the data reporting frequency. - * For details, see {@link Sensor_SubscribeAttribute}. - * @param user - Pointer to the subscriber information, which is used to specify the callback function for reporting - * the sensor data. For details, see {@link Sensor_SubscribeUser}. + * 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_SubscribeSensor(const Sensor_SensorSubscribeId *id, const Sensor_SubscribeAttribute *attribute, - const Sensor_SubscribeUser *user); +Sensor_Result OH_Sensor_SubscribeSensor(const Sensor_SensorSubscriptionId *id, const Sensor_SubscriptionAttribute *attribute, + const Sensor_Subscriber *subscriber); /** * @brief Unsubscribes from sensor data. @@ -81,16 +81,16 @@ Sensor_Result OH_Sensor_SubscribeSensor(const Sensor_SensorSubscribeId *id, cons * 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_SensorSubscribeId}. - * @param user - Pointer to the subscriber information, which is used to specify the callback function for reporting - * the sensor data. For details, see {@link Sensor_SubscribeUser}. + * @param id - Pointer to the sensor subscription ID. For details, see {@link Sensor_SensorSubscriptionId}. + * @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_UnsubscribeSensor(const Sensor_SensorSubscribeId *id, const Sensor_SubscribeUser *user); +Sensor_Result OH_Sensor_UnsubscribeSensor(const Sensor_SensorSubscriptionId *id, const Sensor_Subscriber *subscriber); #ifdef __cplusplus } #endif diff --git a/interfaces/kits/c/native_sensor_type.h b/interfaces/kits/c/native_sensor_type.h index 6e849773..e964765f 100644 --- a/interfaces/kits/c/native_sensor_type.h +++ b/interfaces/kits/c/native_sensor_type.h @@ -249,23 +249,23 @@ int32_t OH_Sensor_GetSensorResolution(Sensor_Sensor* sensor, float *resolution); * @brief Obtains the minimum data reporting interval of a sensor. * * @param sensor - Pointer to the sensor information. - * @param minSamplePeriod - Pointer to the minimum data reporting interval, in nanoseconds. + * @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_Sensor_GetSensorMinSamplePeriod(Sensor_Sensor* sensor, int64_t *minSamplePeriod); +int32_t OH_Sensor_GetMinSamplingInterval(Sensor_Sensor* sensor, int64_t *minSamplingInterval); /** * @brief Obtains the maximum data reporting interval of a sensor. * * @param sensor - Pointer to the sensor information. - * @param maxSamplePeriod - Pointer to the maximum data reporting interval, in nanoseconds. + * @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_Sensor_GetSensorMaxSamplePeriod(Sensor_Sensor* sensor, int64_t *maxSamplePeriod); +int32_t OH_Sensor_GetMaxSamplingInterval(Sensor_Sensor* sensor, int64_t *maxSamplingInterval); /** * @brief Defines the sensor data information. @@ -345,73 +345,73 @@ int32_t OH_Sensor_GetSensorData(Sensor_SensorEvent* sensorEvent, float **data, u * @brief Defines the sensor subscription ID, which uniquely identifies a sensor. * @since 11 */ -typedef struct Sensor_SensorSubscribeId Sensor_SensorSubscribeId; +typedef struct Sensor_SensorSubscriptionId Sensor_SensorSubscriptionId; /** - * @brief Creates a {@link Sensor_SensorSubscribeId} instance. + * @brief Creates a {@link Sensor_SensorSubscriptionId} instance. * - * @return Returns the pointer to the {@link Sensor_SensorSubscribeId} instance if the operation is successful; + * @return Returns the pointer to the {@link Sensor_SensorSubscriptionId} instance if the operation is successful; * returns NULL otherwise. * @since 11 */ -Sensor_SensorSubscribeId *OH_Sensor_CreateSubscribeId(void); +Sensor_SensorSubscriptionId *OH_Sensor_CreateSubscriptionId(void); /** - * @brief Destroys a {@link Sensor_SensorSubscribeId} instance and reclaims memory. + * @brief Destroys a {@link Sensor_SensorSubscriptionId} instance and reclaims memory. * - * @param subscribeId - Pointer to the {@link Sensor_SensorSubscribeId} instance. + * @param id - Pointer to the {@link Sensor_SensorSubscriptionId} 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_DestroySubscribeId(Sensor_SensorSubscribeId *subscribeId); +int32_t OH_Sensor_DestroySubscriptionId(Sensor_SensorSubscriptionId *id); /** * @brief Obtains the sensor type. * - * @param subscribeId - Pointer to the sensor subscription ID. - * @param sensorType - Pointer to 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_Sensor_GetSubscribeSensorType(Sensor_SensorSubscribeId* subscribeId, Sensor_SensorType *sensorType); +int32_t OH_Sensor_GetSubscriptionSensorType(Sensor_SensorSubscriptionId* id, Sensor_SensorType *sensorType); /** * @brief Sets the sensor type. * - * @param subscribeId - Pointer to the sensor subscription ID. + * @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_Sensor_SetSubscribeSensorType(Sensor_SensorSubscribeId* subscribeId, const Sensor_SensorType sensorType); +int32_t OH_Sensor_SetSubscriptionSensorType(Sensor_SensorSubscriptionId* id, const Sensor_SensorType sensorType); /** * @brief Defines the sensor subscription attribute. * @since 11 */ -typedef struct Sensor_SubscribeAttribute Sensor_SubscribeAttribute; +typedef struct Sensor_SubscriptionAttribute Sensor_SubscriptionAttribute; /** - * @brief Creates a {@link Sensor_SubscribeAttribute} instance. + * @brief Creates a {@link Sensor_SubscriptionAttribute} instance. * - * @return Returns the pointer to the {@link Sensor_SubscribeAttribute} instance if the operation is successful; + * @return Returns the pointer to the {@link Sensor_SubscriptionAttribute} instance if the operation is successful; * returns NULL otherwise. * @since 11 */ -Sensor_SubscribeAttribute *OH_Sensor_CreateAttribute(void); +Sensor_SubscriptionAttribute *OH_Sensor_CreateAttribute(void); /** - * @brief Destroys a {@link Sensor_SubscribeAttribute} instance and reclaims memory. + * @brief Destroys a {@link Sensor_SubscriptionAttribute} instance and reclaims memory. * - * @param attribute - Pointer to the {@link Sensor_SubscribeAttribute} instance. + * @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_DestroyAttribute(Sensor_SubscribeAttribute *attribute); +int32_t OH_Sensor_DestroyAttribute(Sensor_SubscriptionAttribute *attribute); /** * @brief Sets the sensor data reporting interval. @@ -422,7 +422,7 @@ int32_t OH_Sensor_DestroyAttribute(Sensor_SubscribeAttribute *attribute); * returns an error code defined in {@link Sensor_Result} otherwise. * @since 11 */ -int32_t OH_Sensor_SetSamplingInterval(Sensor_SubscribeAttribute* attribute, const int64_t samplingInterval); +int32_t OH_Sensor_SetSamplingInterval(Sensor_SubscriptionAttribute* attribute, const int64_t samplingInterval); /** * @brief Obtains the sensor data reporting interval. @@ -433,60 +433,60 @@ int32_t OH_Sensor_SetSamplingInterval(Sensor_SubscribeAttribute* attribute, cons * returns an error code defined in {@link Sensor_Result} otherwise. * @since 11 */ -int32_t OH_Sensor_GetSamplingInterval(Sensor_SubscribeAttribute* attribute, int64_t *samplingInterval); +int32_t OH_Sensor_GetSamplingInterval(Sensor_SubscriptionAttribute* attribute, int64_t *samplingInterval); /** * @brief Defines the callback function used to report sensor data. * @since 11 */ -typedef void (*Sensor_RecordSensorCallback)(Sensor_SensorEvent *event); +typedef void (*Sensor_SensorCallback)(Sensor_SensorEvent *event); /** * @brief Defines the sensor subscriber information. * @since 11 */ -typedef struct Sensor_SubscribeUser Sensor_SubscribeUser; +typedef struct Sensor_Subscriber Sensor_Subscriber; /** - * @brief Creates a {@link Sensor_SubscribeUser} instance. + * @brief Creates a {@link Sensor_Subscriber} instance. * - * @return Returns the pointer to the {@link Sensor_SubscribeUser} instance + * @return Returns the pointer to the {@link Sensor_Subscriber} instance * if the operation is successful; returns NULL otherwise. * @since 11 */ -Sensor_SubscribeUser *OH_Sensor_CreateUser(void); +Sensor_Subscriber *OH_Sensor_CreateSubscriber(void); /** - * @brief Destroys a {@link Sensor_SubscribeUser} instance and reclaims memory. + * @brief Destroys a {@link Sensor_Subscriber} instance and reclaims memory. * - * @param user - Pointer to the {@link Sensor_SubscribeUser} instance. + * @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_DestroyUser(Sensor_SubscribeUser *user); +int32_t OH_Sensor_DestroySubscriber(Sensor_Subscriber *subscriber); /** * @brief Sets a callback function to report sensor data. * - * @param user - Pointer to the sensor subscriber information. + * @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_Sensor_SetSensorCallback(Sensor_SubscribeUser* user, const Sensor_RecordSensorCallback callback); +int32_t OH_Sensor_SetSensorCallback(Sensor_Subscriber* subscriber, const Sensor_SensorCallback callback); /** * @brief Obtains the callback function used to report sensor data. * - * @param user - Pointer to the sensor subscriber information. + * @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_Sensor_GetSensorCallback(Sensor_SubscribeUser* user, Sensor_RecordSensorCallback *callback); +int32_t OH_Sensor_GetSensorCallback(Sensor_Subscriber* subscriber, Sensor_SensorCallback *callback); #ifdef __cplusplus } #endif diff --git a/test/unittest/interfaces/kits/sensor_native_test.cpp b/test/unittest/interfaces/kits/sensor_native_test.cpp index 8f6e554a..aa9369e3 100755 --- a/test/unittest/interfaces/kits/sensor_native_test.cpp +++ b/test/unittest/interfaces/kits/sensor_native_test.cpp @@ -74,7 +74,7 @@ HapInfoParams g_infoManagerTestInfoParms = { .appIDDesc = "sensorAgentTest" }; -Sensor_SubscribeUser *g_user = nullptr; +Sensor_Subscriber *g_user = nullptr; } // namespace class SensorAgentTest : public testing::Test { @@ -162,10 +162,10 @@ HWTEST_F(SensorAgentTest, OH_Sensor_GetAllSensors_001, TestSize.Level1) ret = OH_Sensor_GetSensorResolution(sensors[i], &resolution); ASSERT_EQ(ret, SENSOR_SUCCESS); int64_t minSamplePeriod = INVALID_VALUE; - ret = OH_Sensor_GetSensorMinSamplePeriod(sensors[i], &minSamplePeriod); + ret = OH_Sensor_GetMinSamplingInterval(sensors[i], &minSamplePeriod); ASSERT_EQ(ret, SENSOR_SUCCESS); int64_t maxSamplePeriod = INVALID_VALUE; - ret = OH_Sensor_GetSensorMaxSamplePeriod(sensors[i], &maxSamplePeriod); + ret = OH_Sensor_GetMaxSamplingInterval(sensors[i], &maxSamplePeriod); ASSERT_EQ(ret, SENSOR_SUCCESS); SEN_HILOGI("sensorType:%{public}d, sensorName:%{public}s, vendorName:%{public}s," "resolution:%{public}f, minSamplePeriod:%{public}" PRId64 "maxSamplePeriod:%{public}" PRId64, @@ -187,15 +187,15 @@ HWTEST_F(SensorAgentTest, OH_Sensor_GetAllSensors_002, TestSize.Level1) HWTEST_F(SensorAgentTest, OH_Sensor_SubscribeSensor_001, TestSize.Level1) { SEN_HILOGI("OH_Sensor_SubscribeSensor_001 in"); - g_user = OH_Sensor_CreateUser(); + g_user = OH_Sensor_CreateSubscriber(); int32_t ret = OH_Sensor_SetSensorCallback(g_user, SensorDataCallbackImpl); ASSERT_EQ(ret, SENSOR_SUCCESS); - Sensor_SensorSubscribeId *id = OH_Sensor_CreateSubscribeId(); - ret = OH_Sensor_SetSubscribeSensorType(id, SENSOR_ID); + Sensor_SensorSubscriptionId *id = OH_Sensor_CreateSubscriptionId(); + ret = OH_Sensor_SetSubscriptionSensorType(id, SENSOR_ID); ASSERT_EQ(ret, SENSOR_SUCCESS); - Sensor_SubscribeAttribute *attr = OH_Sensor_CreateAttribute(); + Sensor_SubscriptionAttribute *attr = OH_Sensor_CreateAttribute(); ret = OH_Sensor_SetSamplingInterval(attr, SENSOR_SAMPLE_PERIOD); ASSERT_EQ(ret, SENSOR_SUCCESS); @@ -206,13 +206,13 @@ HWTEST_F(SensorAgentTest, OH_Sensor_SubscribeSensor_001, TestSize.Level1) ret = OH_Sensor_UnsubscribeSensor(id, g_user); ASSERT_EQ(ret, SENSOR_SUCCESS); if (id != nullptr) { - OH_Sensor_DestroySubscribeId(id); + OH_Sensor_DestroySubscriptionId(id); } if (attr != nullptr) { OH_Sensor_DestroyAttribute(attr); } if (g_user != nullptr) { - OH_Sensor_DestroyUser(g_user); + OH_Sensor_DestroySubscriber(g_user); g_user = nullptr; } } @@ -220,18 +220,18 @@ HWTEST_F(SensorAgentTest, OH_Sensor_SubscribeSensor_001, TestSize.Level1) HWTEST_F(SensorAgentTest, OH_Sensor_SubscribeSensor_002, TestSize.Level1) { SEN_HILOGI("OH_Sensor_SubscribeSensor_002 in"); - Sensor_SensorSubscribeId *id = OH_Sensor_CreateSubscribeId(); - int32_t ret = OH_Sensor_SetSubscribeSensorType(id, SENSOR_ID); + Sensor_SensorSubscriptionId *id = OH_Sensor_CreateSubscriptionId(); + int32_t ret = OH_Sensor_SetSubscriptionSensorType(id, SENSOR_ID); ASSERT_EQ(ret, SENSOR_SUCCESS); - Sensor_SubscribeAttribute *attr = OH_Sensor_CreateAttribute(); + Sensor_SubscriptionAttribute *attr = OH_Sensor_CreateAttribute(); ret = OH_Sensor_SetSamplingInterval(attr, SENSOR_SAMPLE_PERIOD); ASSERT_EQ(ret, SENSOR_SUCCESS); ret = OH_Sensor_SubscribeSensor(id, attr, nullptr); ASSERT_EQ(ret, SENSOR_PARAMETER_ERROR); if (id != nullptr) { - OH_Sensor_DestroySubscribeId(id); + OH_Sensor_DestroySubscriptionId(id); } if (attr != nullptr) { OH_Sensor_DestroyAttribute(attr); @@ -241,11 +241,11 @@ HWTEST_F(SensorAgentTest, OH_Sensor_SubscribeSensor_002, TestSize.Level1) HWTEST_F(SensorAgentTest, OH_Sensor_SubscribeSensor_003, TestSize.Level1) { SEN_HILOGI("OH_Sensor_SubscribeSensor_003 in"); - g_user = OH_Sensor_CreateUser(); + g_user = OH_Sensor_CreateSubscriber(); int32_t ret = OH_Sensor_SetSensorCallback(g_user, SensorDataCallbackImpl); ASSERT_EQ(ret, SENSOR_SUCCESS); - Sensor_SubscribeAttribute *attr = OH_Sensor_CreateAttribute(); + Sensor_SubscriptionAttribute *attr = OH_Sensor_CreateAttribute(); ret = OH_Sensor_SetSamplingInterval(attr, SENSOR_SAMPLE_PERIOD); ASSERT_EQ(ret, SENSOR_SUCCESS); @@ -255,7 +255,7 @@ HWTEST_F(SensorAgentTest, OH_Sensor_SubscribeSensor_003, TestSize.Level1) OH_Sensor_DestroyAttribute(attr); } if (g_user != nullptr) { - OH_Sensor_DestroyUser(g_user); + OH_Sensor_DestroySubscriber(g_user); g_user = nullptr; } } @@ -263,21 +263,21 @@ HWTEST_F(SensorAgentTest, OH_Sensor_SubscribeSensor_003, TestSize.Level1) HWTEST_F(SensorAgentTest, OH_Sensor_SubscribeSensor_004, TestSize.Level1) { SEN_HILOGI("OH_Sensor_SubscribeSensor_004 in"); - g_user = OH_Sensor_CreateUser(); + g_user = OH_Sensor_CreateSubscriber(); int32_t ret = OH_Sensor_SetSensorCallback(g_user, SensorDataCallbackImpl); ASSERT_EQ(ret, SENSOR_SUCCESS); - Sensor_SensorSubscribeId *id = OH_Sensor_CreateSubscribeId(); - ret = OH_Sensor_SetSubscribeSensorType(id, SENSOR_ID); + Sensor_SensorSubscriptionId *id = OH_Sensor_CreateSubscriptionId(); + ret = OH_Sensor_SetSubscriptionSensorType(id, SENSOR_ID); ASSERT_EQ(ret, SENSOR_SUCCESS); ret = OH_Sensor_SubscribeSensor(id, nullptr, g_user); ASSERT_EQ(ret, SENSOR_PARAMETER_ERROR); if (id != nullptr) { - OH_Sensor_DestroySubscribeId(id); + OH_Sensor_DestroySubscriptionId(id); } if (g_user != nullptr) { - OH_Sensor_DestroyUser(g_user); + OH_Sensor_DestroySubscriber(g_user); g_user = nullptr; } } @@ -285,14 +285,14 @@ HWTEST_F(SensorAgentTest, OH_Sensor_SubscribeSensor_004, TestSize.Level1) HWTEST_F(SensorAgentTest, OH_Sensor_UnsubscribeSensor_001, TestSize.Level1) { SEN_HILOGI("OH_Sensor_UnsubscribeSensor_001 in"); - g_user = OH_Sensor_CreateUser(); + g_user = OH_Sensor_CreateSubscriber(); int32_t ret = OH_Sensor_SetSensorCallback(g_user, SensorDataCallbackImpl); ASSERT_EQ(ret, SENSOR_SUCCESS); ret = OH_Sensor_UnsubscribeSensor(nullptr, g_user); ASSERT_EQ(ret, SENSOR_PARAMETER_ERROR); if (g_user != nullptr) { - OH_Sensor_DestroyUser(g_user); + OH_Sensor_DestroySubscriber(g_user); g_user = nullptr; } } @@ -300,40 +300,40 @@ HWTEST_F(SensorAgentTest, OH_Sensor_UnsubscribeSensor_001, TestSize.Level1) HWTEST_F(SensorAgentTest, OH_Sensor_UnsubscribeSensor_002, TestSize.Level1) { SEN_HILOGI("OH_Sensor_UnsubscribeSensor_002 in"); - Sensor_SensorSubscribeId *id = OH_Sensor_CreateSubscribeId(); - int32_t ret = OH_Sensor_SetSubscribeSensorType(id, SENSOR_ID); + Sensor_SensorSubscriptionId *id = OH_Sensor_CreateSubscriptionId(); + int32_t ret = OH_Sensor_SetSubscriptionSensorType(id, SENSOR_ID); ASSERT_EQ(ret, SENSOR_SUCCESS); ret = OH_Sensor_UnsubscribeSensor(id, nullptr); ASSERT_EQ(ret, SENSOR_PARAMETER_ERROR); if (id != nullptr) { - OH_Sensor_DestroySubscribeId(id); + OH_Sensor_DestroySubscriptionId(id); } } -HWTEST_F(SensorAgentTest, OH_Sensor_SetSubscribeSensorType_001, TestSize.Level1) +HWTEST_F(SensorAgentTest, OH_Sensor_SetSubscriptionSensorType_001, TestSize.Level1) { - SEN_HILOGI("OH_Sensor_SetSubscribeSensorType_001 in"); - int32_t ret = OH_Sensor_SetSubscribeSensorType(nullptr, SENSOR_ID); + SEN_HILOGI("OH_Sensor_SetSubscriptionSensorType_001 in"); + int32_t ret = OH_Sensor_SetSubscriptionSensorType(nullptr, SENSOR_ID); ASSERT_EQ(ret, SENSOR_PARAMETER_ERROR); } -HWTEST_F(SensorAgentTest, OH_Sensor_GetSubscribeSensorType_001, TestSize.Level1) +HWTEST_F(SensorAgentTest, OH_Sensor_GetSubscriptionSensorType_001, TestSize.Level1) { - SEN_HILOGI("OH_Sensor_GetSubscribeSensorType_001 in"); + SEN_HILOGI("OH_Sensor_GetSubscriptionSensorType_001 in"); Sensor_SensorType type; - int32_t ret = OH_Sensor_GetSubscribeSensorType(nullptr, &type); + int32_t ret = OH_Sensor_GetSubscriptionSensorType(nullptr, &type); ASSERT_EQ(ret, SENSOR_PARAMETER_ERROR); } -HWTEST_F(SensorAgentTest, OH_Sensor_GetSubscribeSensorType_002, TestSize.Level1) +HWTEST_F(SensorAgentTest, OH_Sensor_GetSubscriptionSensorType_002, TestSize.Level1) { - SEN_HILOGI("OH_Sensor_GetSubscribeSensorType_002 in"); - Sensor_SensorSubscribeId *id = OH_Sensor_CreateSubscribeId(); - int32_t ret = OH_Sensor_GetSubscribeSensorType(id, nullptr); + SEN_HILOGI("OH_Sensor_GetSubscriptionSensorType_002 in"); + Sensor_SensorSubscriptionId *id = OH_Sensor_CreateSubscriptionId(); + int32_t ret = OH_Sensor_GetSubscriptionSensorType(id, nullptr); ASSERT_EQ(ret, SENSOR_PARAMETER_ERROR); if (id != nullptr) { - OH_Sensor_DestroySubscribeId(id); + OH_Sensor_DestroySubscriptionId(id); } } @@ -347,7 +347,7 @@ HWTEST_F(SensorAgentTest, OH_Sensor_SetSamplingInterval_001, TestSize.Level1) HWTEST_F(SensorAgentTest, OH_Sensor_SetSamplingInterval_002, TestSize.Level1) { SEN_HILOGI("OH_Sensor_SetSamplingInterval_002 in"); - Sensor_SubscribeAttribute *attr = OH_Sensor_CreateAttribute(); + Sensor_SubscriptionAttribute *attr = OH_Sensor_CreateAttribute(); int32_t ret = OH_Sensor_SetSamplingInterval(attr, INVALID_VALUE); ASSERT_EQ(ret, SENSOR_PARAMETER_ERROR); if (attr != nullptr) { @@ -366,7 +366,7 @@ HWTEST_F(SensorAgentTest, OH_Sensor_GetSamplingInterval_001, TestSize.Level1) HWTEST_F(SensorAgentTest, OH_Sensor_GetSamplingInterval_002, TestSize.Level1) { SEN_HILOGI("OH_Sensor_GetSamplingInterval_002 in"); - Sensor_SubscribeAttribute *attr = OH_Sensor_CreateAttribute(); + Sensor_SubscriptionAttribute *attr = OH_Sensor_CreateAttribute(); int32_t ret = OH_Sensor_GetSamplingInterval(attr, nullptr); ASSERT_EQ(ret, SENSOR_PARAMETER_ERROR); if (attr != nullptr) { @@ -384,7 +384,7 @@ HWTEST_F(SensorAgentTest, OH_Sensor_SetSensorCallback_001, TestSize.Level1) HWTEST_F(SensorAgentTest, OH_Sensor_SetSensorCallback_002, TestSize.Level1) { SEN_HILOGI("OH_Sensor_SetSensorCallback_002 in"); - g_user = OH_Sensor_CreateUser(); + g_user = OH_Sensor_CreateSubscriber(); int32_t ret = OH_Sensor_SetSensorCallback(g_user, nullptr); ASSERT_EQ(ret, SENSOR_PARAMETER_ERROR); } @@ -392,7 +392,7 @@ HWTEST_F(SensorAgentTest, OH_Sensor_SetSensorCallback_002, TestSize.Level1) HWTEST_F(SensorAgentTest, OH_Sensor_GetSensorCallback_001, TestSize.Level1) { SEN_HILOGI("OH_Sensor_GetSensorCallback_001 in"); - Sensor_RecordSensorCallback callback; + Sensor_SensorCallback callback; int32_t ret = OH_Sensor_GetSensorCallback(nullptr, &callback); ASSERT_EQ(ret, SENSOR_PARAMETER_ERROR); } @@ -400,11 +400,11 @@ HWTEST_F(SensorAgentTest, OH_Sensor_GetSensorCallback_001, TestSize.Level1) HWTEST_F(SensorAgentTest, OH_Sensor_GetSensorCallback_002, TestSize.Level1) { SEN_HILOGI("OH_Sensor_GetSensorCallback_002 in"); - g_user = OH_Sensor_CreateUser(); + g_user = OH_Sensor_CreateSubscriber(); int32_t ret = OH_Sensor_GetSensorCallback(g_user, nullptr); ASSERT_EQ(ret, SENSOR_PARAMETER_ERROR); if (g_user != nullptr) { - OH_Sensor_DestroyUser(g_user); + OH_Sensor_DestroySubscriber(g_user); } } } // namespace Sensors -- Gitee From e749f83cc3d2827f0cb5b3b1643fb1a8361b404d Mon Sep 17 00:00:00 2001 From: hellohyh001 Date: Thu, 30 Nov 2023 10:00:49 +0000 Subject: [PATCH 12/16] update Signed-off-by: hellohyh001 Change-Id: Ib3800306075f9ebc31331e979e3a71b3ece62ecb --- interfaces/kits/c/native_sensor.h | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/interfaces/kits/c/native_sensor.h b/interfaces/kits/c/native_sensor.h index 9c49d660..b51f0ebc 100644 --- a/interfaces/kits/c/native_sensor.h +++ b/interfaces/kits/c/native_sensor.h @@ -57,36 +57,38 @@ Sensor_Result OH_Sensor_GetAllSensors(Sensor_Sensor **sensors, uint32_t *count); * 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. + * 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_SensorSubscriptionId}. * @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}. + * @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 + * @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_SubscribeSensor(const Sensor_SensorSubscriptionId *id, const Sensor_SubscriptionAttribute *attribute, - const Sensor_Subscriber *subscriber); +Sensor_Result OH_Sensor_SubscribeSensor(const Sensor_SensorSubscriptionId *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. + * 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_SensorSubscriptionId}. - * @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}. + * @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 + * @permission ohos.permission.ACCELEROMETER or ohos.permission.GYROSCOPE or + * ohos.permission.ACTIVITY_MOTION or ohos.permission.READ_HEALTH_DATA * * @since 11 */ -- Gitee From 643ebbf0a2df947cc5bda0f495559bb776f973b5 Mon Sep 17 00:00:00 2001 From: hellohyh001 Date: Thu, 30 Nov 2023 11:22:14 +0000 Subject: [PATCH 13/16] update Signed-off-by: hellohyh001 Change-Id: Ic68fb75301c55e966780e48b12334d50036f0bcd --- frameworks/native/include/native_sensor_impl.h | 2 +- frameworks/native/src/native_sensor.cpp | 2 +- interfaces/kits/c/BUILD.gn | 2 +- test/unittest/interfaces/kits/BUILD.gn | 2 +- test/unittest/interfaces/kits/sensor_native_test.cpp | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/frameworks/native/include/native_sensor_impl.h b/frameworks/native/include/native_sensor_impl.h index 238e3b4c..f6a49ed3 100644 --- a/frameworks/native/include/native_sensor_impl.h +++ b/frameworks/native/include/native_sensor_impl.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * 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 diff --git a/frameworks/native/src/native_sensor.cpp b/frameworks/native/src/native_sensor.cpp index 375ae3c1..534baefc 100644 --- a/frameworks/native/src/native_sensor.cpp +++ b/frameworks/native/src/native_sensor.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2023 Huawei Device Co., Ltd. + * 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 diff --git a/interfaces/kits/c/BUILD.gn b/interfaces/kits/c/BUILD.gn index 48c15b15..2cc82b7f 100644 --- a/interfaces/kits/c/BUILD.gn +++ b/interfaces/kits/c/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (C) 2022 Huawei Device Co., Ltd. +# 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 diff --git a/test/unittest/interfaces/kits/BUILD.gn b/test/unittest/interfaces/kits/BUILD.gn index de799c21..90cda26e 100644 --- a/test/unittest/interfaces/kits/BUILD.gn +++ b/test/unittest/interfaces/kits/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2021-2023 Huawei Device Co., Ltd. +# 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 diff --git a/test/unittest/interfaces/kits/sensor_native_test.cpp b/test/unittest/interfaces/kits/sensor_native_test.cpp index aa9369e3..740f4dbc 100755 --- a/test/unittest/interfaces/kits/sensor_native_test.cpp +++ b/test/unittest/interfaces/kits/sensor_native_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * 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 -- Gitee From 62db4f9e8d5385d98101568dff5cedfa230aa03e Mon Sep 17 00:00:00 2001 From: hellohyh001 Date: Thu, 30 Nov 2023 14:31:17 +0000 Subject: [PATCH 14/16] update Signed-off-by: hellohyh001 Change-Id: I3af285bc1fad5e435020a73720ff739ca01ee585 --- .../native/include/native_sensor_impl.h | 8 +-- frameworks/native/src/native_sensor.cpp | 56 +++++++-------- interfaces/kits/c/native_sensor.h | 12 ++-- interfaces/kits/c/native_sensor_type.h | 72 +++++++++---------- .../interfaces/kits/sensor_native_test.cpp | 28 ++++---- 5 files changed, 88 insertions(+), 88 deletions(-) diff --git a/frameworks/native/include/native_sensor_impl.h b/frameworks/native/include/native_sensor_impl.h index f6a49ed3..5ac5b71c 100644 --- a/frameworks/native/include/native_sensor_impl.h +++ b/frameworks/native/include/native_sensor_impl.h @@ -19,7 +19,7 @@ #include "native_sensor.h" #include "sensor_agent_type.h" -struct Sensor_Sensor { +struct Sensor_DeviceInfo { char sensorName[NAME_MAX_LEN]; /**< Sensor name */ char vendorName[NAME_MAX_LEN]; /**< Sensor vendor */ char firmwareVersion[VERSION_MAX_LEN]; /**< Sensor firmware version */ @@ -38,17 +38,17 @@ struct Sensor_SubscriptionAttribute { int64_t reportInterval = -1; }; -struct Sensor_SensorSubscriptionId { +struct Sensor_SubscriptionId { int32_t sensorType = -1; }; struct Sensor_Subscriber { char name[NAME_MAX_LEN]; - Sensor_SensorCallback callback; + Sensor_EventCallback callback; UserData *userData = nullptr; }; -struct Sensor_SensorEvent { +struct Sensor_Event { int32_t sensorTypeId = -1; int32_t version = -1; int64_t timestamp = -1; diff --git a/frameworks/native/src/native_sensor.cpp b/frameworks/native/src/native_sensor.cpp index 534baefc..6eb44b9b 100644 --- a/frameworks/native/src/native_sensor.cpp +++ b/frameworks/native/src/native_sensor.cpp @@ -28,7 +28,7 @@ const HiLogLabel LABEL = {LOG_CORE, OHOS::Sensors::SENSOR_LOG_DOMAIN, "SensorCap const uint32_t FLOAT_SIZE = 4; } -Sensor_Result OH_Sensor_GetAllSensors(Sensor_Sensor **sensors, uint32_t *count) +Sensor_Result OH_Sensor_GetAllSensors(Sensor_DeviceInfo **sensors, uint32_t *count) { if (count == nullptr) { SEN_HILOGE("Parameter error"); @@ -74,16 +74,16 @@ Sensor_Result OH_Sensor_GetAllSensors(Sensor_Sensor **sensors, uint32_t *count) return SENSOR_SUCCESS; } -Sensor_Sensor **OH_Sensor_CreateSensors(uint32_t count) +Sensor_DeviceInfo **OH_Sensor_CreateSensors(uint32_t count) { - auto sensors = new Sensor_Sensor *[count]; + auto sensors = new Sensor_DeviceInfo *[count]; for (uint32_t i = 0; i < count; ++i) { - sensors[i] = new Sensor_Sensor(); + sensors[i] = new Sensor_DeviceInfo(); } return sensors; } -int32_t OH_Sensor_DestroySensors(Sensor_Sensor **sensors, uint32_t count) +int32_t OH_Sensor_DestroySensors(Sensor_DeviceInfo **sensors, uint32_t count) { for (uint32_t i = 0; i < count; ++i) { delete sensors[i]; @@ -93,7 +93,7 @@ int32_t OH_Sensor_DestroySensors(Sensor_Sensor **sensors, uint32_t count) return SENSOR_SUCCESS; } -int32_t OH_Sensor_GetSensorName(Sensor_Sensor* sensor, char *sensorName, uint32_t *length) +int32_t OH_Sensor_GetSensorName(Sensor_DeviceInfo* sensor, char *sensorName, uint32_t *length) { if (sensor == nullptr || sensorName == nullptr || length == nullptr) { SEN_HILOGE("Parameter error"); @@ -112,7 +112,7 @@ int32_t OH_Sensor_GetSensorName(Sensor_Sensor* sensor, char *sensorName, uint32_ return SENSOR_SUCCESS; } -int32_t OH_Sensor_GetVendorName(Sensor_Sensor* sensor, char *vendorName, uint32_t *length) +int32_t OH_Sensor_GetVendorName(Sensor_DeviceInfo* sensor, char *vendorName, uint32_t *length) { if (sensor == nullptr || vendorName == nullptr || length == nullptr) { SEN_HILOGE("Parameter error"); @@ -131,17 +131,17 @@ int32_t OH_Sensor_GetVendorName(Sensor_Sensor* sensor, char *vendorName, uint32_ return SENSOR_SUCCESS; } -int32_t OH_Sensor_GetSensorType(Sensor_Sensor* sensor, Sensor_SensorType *sensorType) +int32_t OH_Sensor_GetSensorType(Sensor_DeviceInfo* sensor, Sensor_Type *sensorType) { if (sensor == nullptr || sensorType == nullptr) { SEN_HILOGE("Parameter error"); return SENSOR_PARAMETER_ERROR; } - *sensorType = static_cast(sensor->sensorTypeId); + *sensorType = static_cast(sensor->sensorTypeId); return SENSOR_SUCCESS; } -int32_t OH_Sensor_GetSensorResolution(Sensor_Sensor* sensor, float *resolution) +int32_t OH_Sensor_GetSensorResolution(Sensor_DeviceInfo* sensor, float *resolution) { if (sensor == nullptr || resolution == nullptr) { SEN_HILOGE("Parameter error"); @@ -151,7 +151,7 @@ int32_t OH_Sensor_GetSensorResolution(Sensor_Sensor* sensor, float *resolution) return SENSOR_SUCCESS; } -int32_t OH_Sensor_GetMinSamplingInterval(Sensor_Sensor* sensor, int64_t *minSamplePeriod) +int32_t OH_Sensor_GetMinSamplingInterval(Sensor_DeviceInfo* sensor, int64_t *minSamplePeriod) { if (sensor == nullptr || minSamplePeriod == nullptr) { SEN_HILOGE("Parameter error"); @@ -161,7 +161,7 @@ int32_t OH_Sensor_GetMinSamplingInterval(Sensor_Sensor* sensor, int64_t *minSamp return SENSOR_SUCCESS; } -int32_t OH_Sensor_GetMaxSamplingInterval(Sensor_Sensor* sensor, int64_t *maxSamplePeriod) +int32_t OH_Sensor_GetMaxSamplingInterval(Sensor_DeviceInfo* sensor, int64_t *maxSamplePeriod) { if (sensor == nullptr || maxSamplePeriod == nullptr) { SEN_HILOGE("Parameter error"); @@ -171,7 +171,7 @@ int32_t OH_Sensor_GetMaxSamplingInterval(Sensor_Sensor* sensor, int64_t *maxSamp return SENSOR_SUCCESS; } -Sensor_Result OH_Sensor_SubscribeSensor(const Sensor_SensorSubscriptionId *id, +Sensor_Result OH_Sensor_SubscribeSensor(const Sensor_SubscriptionId *id, const Sensor_SubscriptionAttribute *attribute, const Sensor_Subscriber *user) { if (id == nullptr || attribute == nullptr || user == nullptr) { @@ -194,7 +194,7 @@ Sensor_Result OH_Sensor_SubscribeSensor(const Sensor_SensorSubscriptionId *id, return static_cast(ActivateSensor(sensorType, sensorUser)); } -Sensor_Result OH_Sensor_UnsubscribeSensor(const Sensor_SensorSubscriptionId *id, +Sensor_Result OH_Sensor_UnsubscribeSensor(const Sensor_SubscriptionId *id, const Sensor_Subscriber *user) { if (id == nullptr || user == nullptr) { @@ -211,17 +211,17 @@ Sensor_Result OH_Sensor_UnsubscribeSensor(const Sensor_SensorSubscriptionId *id, return static_cast(UnsubscribeSensor(sensorType, sensorUser)); } -int32_t OH_Sensor_GetEventSensorType(Sensor_SensorEvent* sensorEvent, Sensor_SensorType *sensorType) +int32_t OH_Sensor_GetEventSensorType(Sensor_Event* sensorEvent, Sensor_Type *sensorType) { if (sensorEvent == nullptr || sensorType == nullptr) { SEN_HILOGE("Parameter error"); return SENSOR_PARAMETER_ERROR; } - *sensorType = static_cast(sensorEvent->sensorTypeId); + *sensorType = static_cast(sensorEvent->sensorTypeId); return SENSOR_SUCCESS; } -int32_t OH_Sensor_GetEventTimestamp(Sensor_SensorEvent* sensorEvent, int64_t *timestamp) +int32_t OH_Sensor_GetEventTimestamp(Sensor_Event* sensorEvent, int64_t *timestamp) { if (sensorEvent == nullptr || timestamp == nullptr) { SEN_HILOGE("Parameter error"); @@ -231,17 +231,17 @@ int32_t OH_Sensor_GetEventTimestamp(Sensor_SensorEvent* sensorEvent, int64_t *ti return SENSOR_SUCCESS; } -int32_t OH_Sensor_GetEventAccuracy(Sensor_SensorEvent* sensorEvent, Sensor_SensorAccuracy *accuracy) +int32_t OH_Sensor_GetEventAccuracy(Sensor_Event* sensorEvent, Sensor_DataAccuracy *accuracy) { if (sensorEvent == nullptr || accuracy == nullptr) { SEN_HILOGE("Parameter error"); return SENSOR_PARAMETER_ERROR; } - *accuracy = static_cast(sensorEvent->option); + *accuracy = static_cast(sensorEvent->option); return SENSOR_SUCCESS; } -int32_t OH_Sensor_GetSensorData(Sensor_SensorEvent* sensorEvent, float **data, uint32_t *length) +int32_t OH_Sensor_GetSensorData(Sensor_Event* sensorEvent, float **data, uint32_t *length) { if (sensorEvent == nullptr || data == nullptr || length == nullptr) { SEN_HILOGE("Parameter error"); @@ -252,17 +252,17 @@ int32_t OH_Sensor_GetSensorData(Sensor_SensorEvent* sensorEvent, float **data, u return SENSOR_SUCCESS; } -int32_t OH_Sensor_GetSubscriptionSensorType(Sensor_SensorSubscriptionId* id, Sensor_SensorType *sensorType) +int32_t OH_Sensor_GetSubscriptionSensorType(Sensor_SubscriptionId* id, Sensor_Type *sensorType) { if (id == nullptr || sensorType == nullptr) { SEN_HILOGE("Parameter error"); return SENSOR_PARAMETER_ERROR; } - *sensorType = static_cast(id->sensorType); + *sensorType = static_cast(id->sensorType); return SENSOR_SUCCESS; } -int32_t OH_Sensor_SetSubscriptionSensorType(Sensor_SensorSubscriptionId* id, const Sensor_SensorType sensorType) +int32_t OH_Sensor_SetSubscriptionSensorType(Sensor_SubscriptionId* id, const Sensor_Type sensorType) { if (id == nullptr) { SEN_HILOGE("Parameter error"); @@ -292,7 +292,7 @@ int32_t OH_Sensor_GetSamplingInterval(Sensor_SubscriptionAttribute* attribute, i return SENSOR_SUCCESS; } -int32_t OH_Sensor_SetSensorCallback(Sensor_Subscriber* user, const Sensor_SensorCallback callback) +int32_t OH_Sensor_SetSensorCallback(Sensor_Subscriber* user, const Sensor_EventCallback callback) { if (user == nullptr || callback == nullptr) { SEN_HILOGE("Parameter error"); @@ -302,7 +302,7 @@ int32_t OH_Sensor_SetSensorCallback(Sensor_Subscriber* user, const Sensor_Sensor return SENSOR_SUCCESS; } -int32_t OH_Sensor_GetSensorCallback(Sensor_Subscriber* user, Sensor_SensorCallback *callback) +int32_t OH_Sensor_GetSensorCallback(Sensor_Subscriber* user, Sensor_EventCallback *callback) { if (user == nullptr || callback == nullptr) { SEN_HILOGE("Parameter error"); @@ -312,12 +312,12 @@ int32_t OH_Sensor_GetSensorCallback(Sensor_Subscriber* user, Sensor_SensorCallba return SENSOR_SUCCESS; } -Sensor_SensorSubscriptionId *OH_Sensor_CreateSubscriptionId() +Sensor_SubscriptionId *OH_Sensor_CreateSubscriptionId() { - return new (std::nothrow) Sensor_SensorSubscriptionId(); + return new (std::nothrow) Sensor_SubscriptionId(); } -int32_t OH_Sensor_DestroySubscriptionId(Sensor_SensorSubscriptionId *id) +int32_t OH_Sensor_DestroySubscriptionId(Sensor_SubscriptionId *id) { if (id == nullptr) { SEN_HILOGE("Parameter error"); diff --git a/interfaces/kits/c/native_sensor.h b/interfaces/kits/c/native_sensor.h index b51f0ebc..776847cf 100644 --- a/interfaces/kits/c/native_sensor.h +++ b/interfaces/kits/c/native_sensor.h @@ -43,14 +43,14 @@ extern "C" { * @brief Obtains information about all sensors on the device. * * @param sensors - Double pointer to the information about all sensors on the device. - * For details, see {@link Sensor_Sensor}. + * For details, see {@link Sensor_DeviceInfo}. * @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_GetAllSensors(Sensor_Sensor **sensors, uint32_t *count); +Sensor_Result OH_Sensor_GetAllSensors(Sensor_DeviceInfo **sensors, uint32_t *count); /** * @brief Subscribes to sensor data. The system will report sensor data to the subscriber at the specified frequency. @@ -60,7 +60,7 @@ Sensor_Result OH_Sensor_GetAllSensors(Sensor_Sensor **sensors, uint32_t *count); * 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_SensorSubscriptionId}. + * @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 @@ -71,7 +71,7 @@ Sensor_Result OH_Sensor_GetAllSensors(Sensor_Sensor **sensors, uint32_t *count); * ohos.permission.ACTIVITY_MOTION or ohos.permission.READ_HEALTH_DATA * @since 11 */ -Sensor_Result OH_Sensor_SubscribeSensor(const Sensor_SensorSubscriptionId *id, +Sensor_Result OH_Sensor_SubscribeSensor(const Sensor_SubscriptionId *id, const Sensor_SubscriptionAttribute *attribute, const Sensor_Subscriber *subscriber); /** @@ -82,7 +82,7 @@ Sensor_Result OH_Sensor_SubscribeSensor(const Sensor_SensorSubscriptionId *id, * 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_SensorSubscriptionId}. + * @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; @@ -92,7 +92,7 @@ Sensor_Result OH_Sensor_SubscribeSensor(const Sensor_SensorSubscriptionId *id, * * @since 11 */ -Sensor_Result OH_Sensor_UnsubscribeSensor(const Sensor_SensorSubscriptionId *id, const Sensor_Subscriber *subscriber); +Sensor_Result OH_Sensor_UnsubscribeSensor(const Sensor_SubscriptionId *id, const Sensor_Subscriber *subscriber); #ifdef __cplusplus } #endif diff --git a/interfaces/kits/c/native_sensor_type.h b/interfaces/kits/c/native_sensor_type.h index e964765f..23dbf23b 100644 --- a/interfaces/kits/c/native_sensor_type.h +++ b/interfaces/kits/c/native_sensor_type.h @@ -45,7 +45,7 @@ extern "C" { * * @since 11 */ -typedef enum Sensor_SensorType { +typedef enum Sensor_Type { /** * Acceleration sensor. * @since 11 @@ -111,7 +111,7 @@ typedef enum Sensor_SensorType { * @since 11 */ SENSOR_TYPE_HEART_RATE = 278, -} Sensor_SensorType; +} Sensor_Type; /** * @brief Enumerates the sensor result codes. @@ -147,7 +147,7 @@ typedef enum Sensor_Result { * * @since 11 */ -typedef enum Sensor_SensorAccuracy { +typedef enum Sensor_DataAccuracy { /** * The sensor data is unreliable. It is possible that the sensor does not contact with the device to measure. * @since 11 @@ -170,34 +170,34 @@ typedef enum Sensor_SensorAccuracy { * @since 11 */ SENSOR_ACCURACY_HIGH = 3 -} Sensor_SensorAccuracy; +} Sensor_DataAccuracy; /** * @brief Defines the sensor information. * @since 11 */ -typedef struct Sensor_Sensor Sensor_Sensor; +typedef struct Sensor_DeviceInfo Sensor_DeviceInfo; /** - * @brief Creates an array of {@link Sensor_Sensor} instances with the given number. + * @brief Creates an array of {@link Sensor_DeviceInfo} instances with the given number. * - * @param count - Number of {@link Sensor_Sensor} instances to create. - * @return Returns the double pointer to the array of {@link Sensor_Sensor} instances if the operation is successful; + * @param count - Number of {@link Sensor_DeviceInfo} instances to create. + * @return Returns the double pointer to the array of {@link Sensor_DeviceInfo} instances if the operation is successful; * returns NULL otherwise. * @since 11 */ -Sensor_Sensor **OH_Sensor_CreateSensors(uint32_t count); +Sensor_DeviceInfo **OH_Sensor_CreateSensors(uint32_t count); /** - * @brief Destroys an array of {@link Sensor_Sensor} instances and reclaims memory. + * @brief Destroys an array of {@link Sensor_DeviceInfo} instances and reclaims memory. * - * @param sensors - Double pointer to the array of {@link Sensor_Sensor} instances. - * @param count - Number of {@link Sensor_Sensor} instances to destroy. + * @param sensors - Double pointer to the array of {@link Sensor_DeviceInfo} instances. + * @param count - Number of {@link Sensor_DeviceInfo} 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_DestroySensors(Sensor_Sensor **sensors, uint32_t count); +int32_t OH_Sensor_DestroySensors(Sensor_DeviceInfo **sensors, uint32_t count); /** * @brief Obtains the sensor name. @@ -209,7 +209,7 @@ int32_t OH_Sensor_DestroySensors(Sensor_Sensor **sensors, uint32_t count); * returns an error code defined in {@link Sensor_Result} otherwise. * @since 11 */ -int32_t OH_Sensor_GetSensorName(Sensor_Sensor* sensor, char *sensorName, uint32_t *length); +int32_t OH_Sensor_GetSensorName(Sensor_DeviceInfo* sensor, char *sensorName, uint32_t *length); /** * @brief Obtains the sensor's vendor name. @@ -221,7 +221,7 @@ int32_t OH_Sensor_GetSensorName(Sensor_Sensor* sensor, char *sensorName, uint32_ * returns an error code defined in {@link Sensor_Result} otherwise. * @since 11 */ -int32_t OH_Sensor_GetVendorName(Sensor_Sensor* sensor, char *vendorName, uint32_t *length); +int32_t OH_Sensor_GetVendorName(Sensor_DeviceInfo* sensor, char *vendorName, uint32_t *length); /** * @brief Obtains the sensor type. @@ -232,7 +232,7 @@ int32_t OH_Sensor_GetVendorName(Sensor_Sensor* sensor, char *vendorName, uint32_ * returns an error code defined in {@link Sensor_Result} otherwise. * @since 11 */ -int32_t OH_Sensor_GetSensorType(Sensor_Sensor* sensor, Sensor_SensorType *sensorType); +int32_t OH_Sensor_GetSensorType(Sensor_DeviceInfo* sensor, Sensor_Type *sensorType); /** * @brief Obtains the sensor resolution. @@ -243,7 +243,7 @@ int32_t OH_Sensor_GetSensorType(Sensor_Sensor* sensor, Sensor_SensorType *sensor * returns an error code defined in {@link Sensor_Result} otherwise. * @since 11 */ -int32_t OH_Sensor_GetSensorResolution(Sensor_Sensor* sensor, float *resolution); +int32_t OH_Sensor_GetSensorResolution(Sensor_DeviceInfo* sensor, float *resolution); /** * @brief Obtains the minimum data reporting interval of a sensor. @@ -254,7 +254,7 @@ int32_t OH_Sensor_GetSensorResolution(Sensor_Sensor* sensor, float *resolution); * returns an error code defined in {@link Sensor_Result} otherwise. * @since 11 */ -int32_t OH_Sensor_GetMinSamplingInterval(Sensor_Sensor* sensor, int64_t *minSamplingInterval); +int32_t OH_Sensor_GetMinSamplingInterval(Sensor_DeviceInfo* sensor, int64_t *minSamplingInterval); /** * @brief Obtains the maximum data reporting interval of a sensor. @@ -265,13 +265,13 @@ int32_t OH_Sensor_GetMinSamplingInterval(Sensor_Sensor* sensor, int64_t *minSamp * returns an error code defined in {@link Sensor_Result} otherwise. * @since 11 */ -int32_t OH_Sensor_GetMaxSamplingInterval(Sensor_Sensor* sensor, int64_t *maxSamplingInterval); +int32_t OH_Sensor_GetMaxSamplingInterval(Sensor_DeviceInfo* sensor, int64_t *maxSamplingInterval); /** * @brief Defines the sensor data information. * @since 11 */ -typedef struct Sensor_SensorEvent Sensor_SensorEvent; +typedef struct Sensor_Event Sensor_Event; /** * @brief Obtains the sensor type. @@ -282,7 +282,7 @@ typedef struct Sensor_SensorEvent Sensor_SensorEvent; * returns an error code defined in {@link Sensor_Result} otherwise. * @since 11 */ -int32_t OH_Sensor_GetEventSensorType(Sensor_SensorEvent* sensorEvent, Sensor_SensorType *sensorType); +int32_t OH_Sensor_GetEventSensorType(Sensor_Event* sensorEvent, Sensor_Type *sensorType); /** * @brief Obtains the timestamp of sensor data. @@ -293,7 +293,7 @@ int32_t OH_Sensor_GetEventSensorType(Sensor_SensorEvent* sensorEvent, Sensor_Sen * returns an error code defined in {@link Sensor_Result} otherwise. * @since 11 */ -int32_t OH_Sensor_GetEventTimestamp(Sensor_SensorEvent* sensorEvent, int64_t *timestamp); +int32_t OH_Sensor_GetEventTimestamp(Sensor_Event* sensorEvent, int64_t *timestamp); /** * @brief Obtains the accuracy of sensor data. @@ -304,7 +304,7 @@ int32_t OH_Sensor_GetEventTimestamp(Sensor_SensorEvent* sensorEvent, int64_t *ti * returns an error code defined in {@link Sensor_Result} otherwise. * @since 11 */ -int32_t OH_Sensor_GetEventAccuracy(Sensor_SensorEvent* sensorEvent, Sensor_SensorAccuracy *accuracy); +int32_t OH_Sensor_GetEventAccuracy(Sensor_Event* sensorEvent, Sensor_DataAccuracy *accuracy); /** * @brief Obtains sensor data. The data length and content depend on the sensor type. @@ -339,32 +339,32 @@ int32_t OH_Sensor_GetEventAccuracy(Sensor_SensorEvent* sensorEvent, Sensor_Senso * returns an error code defined in {@link Sensor_Result} otherwise. * @since 11 */ -int32_t OH_Sensor_GetSensorData(Sensor_SensorEvent* sensorEvent, float **data, uint32_t *length); +int32_t OH_Sensor_GetSensorData(Sensor_Event* sensorEvent, float **data, uint32_t *length); /** * @brief Defines the sensor subscription ID, which uniquely identifies a sensor. * @since 11 */ -typedef struct Sensor_SensorSubscriptionId Sensor_SensorSubscriptionId; +typedef struct Sensor_SubscriptionId Sensor_SubscriptionId; /** - * @brief Creates a {@link Sensor_SensorSubscriptionId} instance. + * @brief Creates a {@link Sensor_SubscriptionId} instance. * - * @return Returns the pointer to the {@link Sensor_SensorSubscriptionId} instance if the operation is successful; + * @return Returns the pointer to the {@link Sensor_SubscriptionId} instance if the operation is successful; * returns NULL otherwise. * @since 11 */ -Sensor_SensorSubscriptionId *OH_Sensor_CreateSubscriptionId(void); +Sensor_SubscriptionId *OH_Sensor_CreateSubscriptionId(void); /** - * @brief Destroys a {@link Sensor_SensorSubscriptionId} instance and reclaims memory. + * @brief Destroys a {@link Sensor_SubscriptionId} instance and reclaims memory. * - * @param id - Pointer to the {@link Sensor_SensorSubscriptionId} instance. + * @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_SensorSubscriptionId *id); +int32_t OH_Sensor_DestroySubscriptionId(Sensor_SubscriptionId *id); /** * @brief Obtains the sensor type. @@ -375,7 +375,7 @@ int32_t OH_Sensor_DestroySubscriptionId(Sensor_SensorSubscriptionId *id); * returns an error code defined in {@link Sensor_Result} otherwise. * @since 11 */ -int32_t OH_Sensor_GetSubscriptionSensorType(Sensor_SensorSubscriptionId* id, Sensor_SensorType *sensorType); +int32_t OH_Sensor_GetSubscriptionSensorType(Sensor_SubscriptionId* id, Sensor_Type *sensorType); /** * @brief Sets the sensor type. @@ -386,7 +386,7 @@ int32_t OH_Sensor_GetSubscriptionSensorType(Sensor_SensorSubscriptionId* id, Sen * returns an error code defined in {@link Sensor_Result} otherwise. * @since 11 */ -int32_t OH_Sensor_SetSubscriptionSensorType(Sensor_SensorSubscriptionId* id, const Sensor_SensorType sensorType); +int32_t OH_Sensor_SetSubscriptionSensorType(Sensor_SubscriptionId* id, const Sensor_Type sensorType); /** * @brief Defines the sensor subscription attribute. @@ -439,7 +439,7 @@ int32_t OH_Sensor_GetSamplingInterval(Sensor_SubscriptionAttribute* attribute, i * @brief Defines the callback function used to report sensor data. * @since 11 */ -typedef void (*Sensor_SensorCallback)(Sensor_SensorEvent *event); +typedef void (*Sensor_EventCallback)(Sensor_Event *event); /** * @brief Defines the sensor subscriber information. @@ -475,7 +475,7 @@ int32_t OH_Sensor_DestroySubscriber(Sensor_Subscriber *subscriber); * returns an error code defined in {@link Sensor_Result} otherwise. * @since 11 */ -int32_t OH_Sensor_SetSensorCallback(Sensor_Subscriber* subscriber, const Sensor_SensorCallback callback); +int32_t OH_Sensor_SetSensorCallback(Sensor_Subscriber* subscriber, const Sensor_EventCallback callback); /** * @brief Obtains the callback function used to report sensor data. @@ -486,7 +486,7 @@ int32_t OH_Sensor_SetSensorCallback(Sensor_Subscriber* subscriber, const Sensor_ * returns an error code defined in {@link Sensor_Result} otherwise. * @since 11 */ -int32_t OH_Sensor_GetSensorCallback(Sensor_Subscriber* subscriber, Sensor_SensorCallback *callback); +int32_t OH_Sensor_GetSensorCallback(Sensor_Subscriber* subscriber, Sensor_EventCallback *callback); #ifdef __cplusplus } #endif diff --git a/test/unittest/interfaces/kits/sensor_native_test.cpp b/test/unittest/interfaces/kits/sensor_native_test.cpp index 740f4dbc..1b39509a 100755 --- a/test/unittest/interfaces/kits/sensor_native_test.cpp +++ b/test/unittest/interfaces/kits/sensor_native_test.cpp @@ -34,7 +34,7 @@ using Security::AccessToken::AccessTokenID; namespace { constexpr HiLogLabel LABEL = { LOG_CORE, OHOS::Sensors::SENSOR_LOG_DOMAIN, "SensorAgentTest" }; -constexpr Sensor_SensorType SENSOR_ID { SENSOR_TYPE_ACCELEROMETER }; +constexpr Sensor_Type SENSOR_ID { SENSOR_TYPE_ACCELEROMETER }; constexpr uint32_t SENSOR_NAME_LENGTH_MAX = 64; constexpr int64_t SENSOR_SAMPLE_PERIOD = 200000000; constexpr int32_t SLEEP_TIME_MS = 1000; @@ -112,7 +112,7 @@ void SensorAgentTest::SetUp() void SensorAgentTest::TearDown() {} -void SensorDataCallbackImpl(Sensor_SensorEvent *event) +void SensorDataCallbackImpl(Sensor_Event *event) { if (event == nullptr) { SEN_HILOGE("event is null"); @@ -121,10 +121,10 @@ void SensorDataCallbackImpl(Sensor_SensorEvent *event) int64_t timestamp = INVALID_VALUE; int32_t ret = OH_Sensor_GetEventTimestamp(event, ×tamp); ASSERT_EQ(ret, SENSOR_SUCCESS); - Sensor_SensorType sensorType; + Sensor_Type sensorType; ret = OH_Sensor_GetEventSensorType(event, &sensorType); ASSERT_EQ(ret, SENSOR_SUCCESS); - Sensor_SensorAccuracy accuracy = SENSOR_ACCURACY_UNRELIABLE; + Sensor_DataAccuracy accuracy = SENSOR_ACCURACY_UNRELIABLE; ret = OH_Sensor_GetEventAccuracy(event, &accuracy); ASSERT_EQ(ret, SENSOR_SUCCESS); float *data = nullptr; @@ -142,7 +142,7 @@ HWTEST_F(SensorAgentTest, OH_Sensor_GetAllSensors_001, TestSize.Level1) uint32_t count = 0; int32_t ret = OH_Sensor_GetAllSensors(nullptr, &count); ASSERT_EQ(ret, SENSOR_SUCCESS); - Sensor_Sensor **sensors = OH_Sensor_CreateSensors(count); + Sensor_DeviceInfo **sensors = OH_Sensor_CreateSensors(count); ASSERT_NE(sensors, nullptr); ret = OH_Sensor_GetAllSensors(sensors, &count); ASSERT_EQ(ret, SENSOR_SUCCESS); @@ -155,7 +155,7 @@ HWTEST_F(SensorAgentTest, OH_Sensor_GetAllSensors_001, TestSize.Level1) length = SENSOR_NAME_LENGTH_MAX; ret = OH_Sensor_GetVendorName(sensors[i], vendorName, &length); ASSERT_EQ(ret, SENSOR_SUCCESS); - Sensor_SensorType sensorType; + Sensor_Type sensorType; ret = OH_Sensor_GetSensorType(sensors[i], &sensorType); ASSERT_EQ(ret, SENSOR_SUCCESS); float resolution = INVALID_RESOLUTION; @@ -179,7 +179,7 @@ HWTEST_F(SensorAgentTest, OH_Sensor_GetAllSensors_001, TestSize.Level1) HWTEST_F(SensorAgentTest, OH_Sensor_GetAllSensors_002, TestSize.Level1) { SEN_HILOGI("OH_Sensor_GetAllSensors_003 in"); - Sensor_Sensor *sensors { nullptr }; + Sensor_DeviceInfo *sensors { nullptr }; int32_t ret = OH_Sensor_GetAllSensors(&sensors, nullptr); ASSERT_NE(ret, SENSOR_SUCCESS); } @@ -191,7 +191,7 @@ HWTEST_F(SensorAgentTest, OH_Sensor_SubscribeSensor_001, TestSize.Level1) int32_t ret = OH_Sensor_SetSensorCallback(g_user, SensorDataCallbackImpl); ASSERT_EQ(ret, SENSOR_SUCCESS); - Sensor_SensorSubscriptionId *id = OH_Sensor_CreateSubscriptionId(); + Sensor_SubscriptionId *id = OH_Sensor_CreateSubscriptionId(); ret = OH_Sensor_SetSubscriptionSensorType(id, SENSOR_ID); ASSERT_EQ(ret, SENSOR_SUCCESS); @@ -220,7 +220,7 @@ HWTEST_F(SensorAgentTest, OH_Sensor_SubscribeSensor_001, TestSize.Level1) HWTEST_F(SensorAgentTest, OH_Sensor_SubscribeSensor_002, TestSize.Level1) { SEN_HILOGI("OH_Sensor_SubscribeSensor_002 in"); - Sensor_SensorSubscriptionId *id = OH_Sensor_CreateSubscriptionId(); + Sensor_SubscriptionId *id = OH_Sensor_CreateSubscriptionId(); int32_t ret = OH_Sensor_SetSubscriptionSensorType(id, SENSOR_ID); ASSERT_EQ(ret, SENSOR_SUCCESS); @@ -267,7 +267,7 @@ HWTEST_F(SensorAgentTest, OH_Sensor_SubscribeSensor_004, TestSize.Level1) int32_t ret = OH_Sensor_SetSensorCallback(g_user, SensorDataCallbackImpl); ASSERT_EQ(ret, SENSOR_SUCCESS); - Sensor_SensorSubscriptionId *id = OH_Sensor_CreateSubscriptionId(); + Sensor_SubscriptionId *id = OH_Sensor_CreateSubscriptionId(); ret = OH_Sensor_SetSubscriptionSensorType(id, SENSOR_ID); ASSERT_EQ(ret, SENSOR_SUCCESS); @@ -300,7 +300,7 @@ HWTEST_F(SensorAgentTest, OH_Sensor_UnsubscribeSensor_001, TestSize.Level1) HWTEST_F(SensorAgentTest, OH_Sensor_UnsubscribeSensor_002, TestSize.Level1) { SEN_HILOGI("OH_Sensor_UnsubscribeSensor_002 in"); - Sensor_SensorSubscriptionId *id = OH_Sensor_CreateSubscriptionId(); + Sensor_SubscriptionId *id = OH_Sensor_CreateSubscriptionId(); int32_t ret = OH_Sensor_SetSubscriptionSensorType(id, SENSOR_ID); ASSERT_EQ(ret, SENSOR_SUCCESS); @@ -321,7 +321,7 @@ HWTEST_F(SensorAgentTest, OH_Sensor_SetSubscriptionSensorType_001, TestSize.Leve HWTEST_F(SensorAgentTest, OH_Sensor_GetSubscriptionSensorType_001, TestSize.Level1) { SEN_HILOGI("OH_Sensor_GetSubscriptionSensorType_001 in"); - Sensor_SensorType type; + Sensor_Type type; int32_t ret = OH_Sensor_GetSubscriptionSensorType(nullptr, &type); ASSERT_EQ(ret, SENSOR_PARAMETER_ERROR); } @@ -329,7 +329,7 @@ HWTEST_F(SensorAgentTest, OH_Sensor_GetSubscriptionSensorType_001, TestSize.Leve HWTEST_F(SensorAgentTest, OH_Sensor_GetSubscriptionSensorType_002, TestSize.Level1) { SEN_HILOGI("OH_Sensor_GetSubscriptionSensorType_002 in"); - Sensor_SensorSubscriptionId *id = OH_Sensor_CreateSubscriptionId(); + Sensor_SubscriptionId *id = OH_Sensor_CreateSubscriptionId(); int32_t ret = OH_Sensor_GetSubscriptionSensorType(id, nullptr); ASSERT_EQ(ret, SENSOR_PARAMETER_ERROR); if (id != nullptr) { @@ -392,7 +392,7 @@ HWTEST_F(SensorAgentTest, OH_Sensor_SetSensorCallback_002, TestSize.Level1) HWTEST_F(SensorAgentTest, OH_Sensor_GetSensorCallback_001, TestSize.Level1) { SEN_HILOGI("OH_Sensor_GetSensorCallback_001 in"); - Sensor_SensorCallback callback; + Sensor_EventCallback callback; int32_t ret = OH_Sensor_GetSensorCallback(nullptr, &callback); ASSERT_EQ(ret, SENSOR_PARAMETER_ERROR); } -- Gitee From 60bb70f67a9a7a7ac6a17f6d5f8b664b7dcf86ef Mon Sep 17 00:00:00 2001 From: hellohyh001 Date: Thu, 30 Nov 2023 15:00:15 +0000 Subject: [PATCH 15/16] upate Signed-off-by: hellohyh001 Change-Id: Ie1c09c7d1c2833ed70af6986f1c1ad540cf80150 --- interfaces/kits/c/native_sensor_type.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/interfaces/kits/c/native_sensor_type.h b/interfaces/kits/c/native_sensor_type.h index 23dbf23b..3ea09ae2 100644 --- a/interfaces/kits/c/native_sensor_type.h +++ b/interfaces/kits/c/native_sensor_type.h @@ -182,7 +182,8 @@ typedef struct Sensor_DeviceInfo Sensor_DeviceInfo; * @brief Creates an array of {@link Sensor_DeviceInfo} instances with the given number. * * @param count - Number of {@link Sensor_DeviceInfo} instances to create. - * @return Returns the double pointer to the array of {@link Sensor_DeviceInfo} instances if the operation is successful; + * @return Returns the double pointer to the array of {@link Sensor_DeviceInfo} instances + * if the operation is successful; * returns NULL otherwise. * @since 11 */ -- Gitee From a7f61af962184fce883f4de2c139beb78cef4410 Mon Sep 17 00:00:00 2001 From: hellohyh001 Date: Fri, 1 Dec 2023 06:22:20 +0000 Subject: [PATCH 16/16] update Signed-off-by: hellohyh001 Change-Id: I6abd5b9f2cc5dbbb980646029f0ef4969bb879d9 --- bundle.json | 2 +- frameworks/native/BUILD.gn | 6 +- .../native/include/native_sensor_impl.h | 4 +- frameworks/native/src/native_sensor.cpp | 64 ++--- interfaces/kits/c/BUILD.gn | 12 +- interfaces/kits/c/libsensor.ndk.json | 54 ++-- .../kits/c/{native_sensor.h => oh_sensor.h} | 22 +- ...{native_sensor_type.h => oh_sensor_type.h} | 86 +++---- test/unittest/interfaces/kits/BUILD.gn | 2 +- .../interfaces/kits/sensor_native_test.cpp | 238 +++++++++--------- 10 files changed, 247 insertions(+), 243 deletions(-) rename interfaces/kits/c/{native_sensor.h => oh_sensor.h} (87%) rename interfaces/kits/c/{native_sensor_type.h => oh_sensor_type.h} (82%) diff --git a/bundle.json b/bundle.json index baf2e157..c07c2ce8 100755 --- a/bundle.json +++ b/bundle.json @@ -40,7 +40,7 @@ "fwk_group": [ "//base/sensors/sensor/frameworks/js/napi:sensor_js_target", "//base/sensors/sensor/frameworks/native:sensor_target", - "//base/sensors/sensor/frameworks/native:sensor_native", + "//base/sensors/sensor/frameworks/native:ohsensor", "//base/sensors/sensor/utils:sensor_utils_target" ], "service_group": [ diff --git a/frameworks/native/BUILD.gn b/frameworks/native/BUILD.gn index a56646a4..f77a183b 100644 --- a/frameworks/native/BUILD.gn +++ b/frameworks/native/BUILD.gn @@ -119,17 +119,17 @@ ohos_shared_library("sensor_interface_native") { subsystem_name = "sensors" } -config("sensor_native_public_config") { +config("ohsensor_public_config") { include_dirs = [ "$SUBSYSTEM_DIR/interfaces/kits/c" ] } -ohos_shared_library("sensor_native") { +ohos_shared_library("ohsensor") { sources = [ "src/native_sensor.cpp" ] defines = [ "API_EXPORT=__attribute__((visibility (\"default\")))" ] configs = [ ":sensor_private_config" ] - public_configs = [ ":sensor_native_public_config" ] + public_configs = [ ":ohsensor_public_config" ] branch_protector_ret = "pac_ret" sanitize = { diff --git a/frameworks/native/include/native_sensor_impl.h b/frameworks/native/include/native_sensor_impl.h index 5ac5b71c..22c90acb 100644 --- a/frameworks/native/include/native_sensor_impl.h +++ b/frameworks/native/include/native_sensor_impl.h @@ -16,10 +16,10 @@ #ifndef NATIVE_SENSOR_IMPL #define NATIVE_SENSOR_IMPL -#include "native_sensor.h" +#include "oh_sensor.h" #include "sensor_agent_type.h" -struct Sensor_DeviceInfo { +struct Sensor_Info { char sensorName[NAME_MAX_LEN]; /**< Sensor name */ char vendorName[NAME_MAX_LEN]; /**< Sensor vendor */ char firmwareVersion[VERSION_MAX_LEN]; /**< Sensor firmware version */ diff --git a/frameworks/native/src/native_sensor.cpp b/frameworks/native/src/native_sensor.cpp index 6eb44b9b..22d2572f 100644 --- a/frameworks/native/src/native_sensor.cpp +++ b/frameworks/native/src/native_sensor.cpp @@ -13,7 +13,7 @@ * limitations under the License. */ -#include "native_sensor.h" +#include "oh_sensor.h" #include "i_sensor_service.h" #include "native_sensor_impl.h" @@ -28,7 +28,7 @@ const HiLogLabel LABEL = {LOG_CORE, OHOS::Sensors::SENSOR_LOG_DOMAIN, "SensorCap const uint32_t FLOAT_SIZE = 4; } -Sensor_Result OH_Sensor_GetAllSensors(Sensor_DeviceInfo **sensors, uint32_t *count) +Sensor_Result OH_Sensor_GetInfos(Sensor_Info **sensors, uint32_t *count) { if (count == nullptr) { SEN_HILOGE("Parameter error"); @@ -74,16 +74,16 @@ Sensor_Result OH_Sensor_GetAllSensors(Sensor_DeviceInfo **sensors, uint32_t *cou return SENSOR_SUCCESS; } -Sensor_DeviceInfo **OH_Sensor_CreateSensors(uint32_t count) +Sensor_Info **OH_Sensor_Info_Create(uint32_t count) { - auto sensors = new Sensor_DeviceInfo *[count]; + auto sensors = new Sensor_Info *[count]; for (uint32_t i = 0; i < count; ++i) { - sensors[i] = new Sensor_DeviceInfo(); + sensors[i] = new Sensor_Info(); } return sensors; } -int32_t OH_Sensor_DestroySensors(Sensor_DeviceInfo **sensors, uint32_t count) +int32_t OH_Sensor_Info_Destroy(Sensor_Info **sensors, uint32_t count) { for (uint32_t i = 0; i < count; ++i) { delete sensors[i]; @@ -93,7 +93,7 @@ int32_t OH_Sensor_DestroySensors(Sensor_DeviceInfo **sensors, uint32_t count) return SENSOR_SUCCESS; } -int32_t OH_Sensor_GetSensorName(Sensor_DeviceInfo* sensor, char *sensorName, uint32_t *length) +int32_t OH_Sensor_Info_GetName(Sensor_Info* sensor, char *sensorName, uint32_t *length) { if (sensor == nullptr || sensorName == nullptr || length == nullptr) { SEN_HILOGE("Parameter error"); @@ -112,7 +112,7 @@ int32_t OH_Sensor_GetSensorName(Sensor_DeviceInfo* sensor, char *sensorName, uin return SENSOR_SUCCESS; } -int32_t OH_Sensor_GetVendorName(Sensor_DeviceInfo* sensor, char *vendorName, uint32_t *length) +int32_t OH_Sensor_Info_GetVendorName(Sensor_Info* sensor, char *vendorName, uint32_t *length) { if (sensor == nullptr || vendorName == nullptr || length == nullptr) { SEN_HILOGE("Parameter error"); @@ -131,7 +131,7 @@ int32_t OH_Sensor_GetVendorName(Sensor_DeviceInfo* sensor, char *vendorName, uin return SENSOR_SUCCESS; } -int32_t OH_Sensor_GetSensorType(Sensor_DeviceInfo* sensor, Sensor_Type *sensorType) +int32_t OH_Sensor_Info_GetType(Sensor_Info* sensor, Sensor_Type *sensorType) { if (sensor == nullptr || sensorType == nullptr) { SEN_HILOGE("Parameter error"); @@ -141,7 +141,7 @@ int32_t OH_Sensor_GetSensorType(Sensor_DeviceInfo* sensor, Sensor_Type *sensorTy return SENSOR_SUCCESS; } -int32_t OH_Sensor_GetSensorResolution(Sensor_DeviceInfo* sensor, float *resolution) +int32_t OH_Sensor_Info_GetResolution(Sensor_Info* sensor, float *resolution) { if (sensor == nullptr || resolution == nullptr) { SEN_HILOGE("Parameter error"); @@ -151,7 +151,7 @@ int32_t OH_Sensor_GetSensorResolution(Sensor_DeviceInfo* sensor, float *resoluti return SENSOR_SUCCESS; } -int32_t OH_Sensor_GetMinSamplingInterval(Sensor_DeviceInfo* sensor, int64_t *minSamplePeriod) +int32_t OH_Sensor_Info_GetMinSamplingInterval(Sensor_Info* sensor, int64_t *minSamplePeriod) { if (sensor == nullptr || minSamplePeriod == nullptr) { SEN_HILOGE("Parameter error"); @@ -161,7 +161,7 @@ int32_t OH_Sensor_GetMinSamplingInterval(Sensor_DeviceInfo* sensor, int64_t *min return SENSOR_SUCCESS; } -int32_t OH_Sensor_GetMaxSamplingInterval(Sensor_DeviceInfo* sensor, int64_t *maxSamplePeriod) +int32_t OH_Sensor_Info_GetMaxSamplingInterval(Sensor_Info* sensor, int64_t *maxSamplePeriod) { if (sensor == nullptr || maxSamplePeriod == nullptr) { SEN_HILOGE("Parameter error"); @@ -171,7 +171,7 @@ int32_t OH_Sensor_GetMaxSamplingInterval(Sensor_DeviceInfo* sensor, int64_t *max return SENSOR_SUCCESS; } -Sensor_Result OH_Sensor_SubscribeSensor(const Sensor_SubscriptionId *id, +Sensor_Result OH_Sensor_Subscribe(const Sensor_SubscriptionId *id, const Sensor_SubscriptionAttribute *attribute, const Sensor_Subscriber *user) { if (id == nullptr || attribute == nullptr || user == nullptr) { @@ -194,7 +194,7 @@ Sensor_Result OH_Sensor_SubscribeSensor(const Sensor_SubscriptionId *id, return static_cast(ActivateSensor(sensorType, sensorUser)); } -Sensor_Result OH_Sensor_UnsubscribeSensor(const Sensor_SubscriptionId *id, +Sensor_Result OH_Sensor_Unsubscribe(const Sensor_SubscriptionId *id, const Sensor_Subscriber *user) { if (id == nullptr || user == nullptr) { @@ -211,7 +211,7 @@ Sensor_Result OH_Sensor_UnsubscribeSensor(const Sensor_SubscriptionId *id, return static_cast(UnsubscribeSensor(sensorType, sensorUser)); } -int32_t OH_Sensor_GetEventSensorType(Sensor_Event* sensorEvent, Sensor_Type *sensorType) +int32_t OH_Sensor_Event_GetType(Sensor_Event* sensorEvent, Sensor_Type *sensorType) { if (sensorEvent == nullptr || sensorType == nullptr) { SEN_HILOGE("Parameter error"); @@ -221,7 +221,7 @@ int32_t OH_Sensor_GetEventSensorType(Sensor_Event* sensorEvent, Sensor_Type *sen return SENSOR_SUCCESS; } -int32_t OH_Sensor_GetEventTimestamp(Sensor_Event* sensorEvent, int64_t *timestamp) +int32_t OH_Sensor_Event_GetTimestamp(Sensor_Event* sensorEvent, int64_t *timestamp) { if (sensorEvent == nullptr || timestamp == nullptr) { SEN_HILOGE("Parameter error"); @@ -231,17 +231,17 @@ int32_t OH_Sensor_GetEventTimestamp(Sensor_Event* sensorEvent, int64_t *timestam return SENSOR_SUCCESS; } -int32_t OH_Sensor_GetEventAccuracy(Sensor_Event* sensorEvent, Sensor_DataAccuracy *accuracy) +int32_t OH_Sensor_Event_GetAccuracy(Sensor_Event* sensorEvent, Sensor_Accuracy *accuracy) { if (sensorEvent == nullptr || accuracy == nullptr) { SEN_HILOGE("Parameter error"); return SENSOR_PARAMETER_ERROR; } - *accuracy = static_cast(sensorEvent->option); + *accuracy = static_cast(sensorEvent->option); return SENSOR_SUCCESS; } -int32_t OH_Sensor_GetSensorData(Sensor_Event* sensorEvent, float **data, uint32_t *length) +int32_t OH_Sensor_Event_GetData(Sensor_Event* sensorEvent, float **data, uint32_t *length) { if (sensorEvent == nullptr || data == nullptr || length == nullptr) { SEN_HILOGE("Parameter error"); @@ -252,7 +252,7 @@ int32_t OH_Sensor_GetSensorData(Sensor_Event* sensorEvent, float **data, uint32_ return SENSOR_SUCCESS; } -int32_t OH_Sensor_GetSubscriptionSensorType(Sensor_SubscriptionId* id, Sensor_Type *sensorType) +int32_t OH_Sensor_SubscriptionId_GetType(Sensor_SubscriptionId* id, Sensor_Type *sensorType) { if (id == nullptr || sensorType == nullptr) { SEN_HILOGE("Parameter error"); @@ -262,7 +262,7 @@ int32_t OH_Sensor_GetSubscriptionSensorType(Sensor_SubscriptionId* id, Sensor_Ty return SENSOR_SUCCESS; } -int32_t OH_Sensor_SetSubscriptionSensorType(Sensor_SubscriptionId* id, const Sensor_Type sensorType) +int32_t OH_Sensor_SubscriptionId_SetType(Sensor_SubscriptionId* id, const Sensor_Type sensorType) { if (id == nullptr) { SEN_HILOGE("Parameter error"); @@ -272,7 +272,8 @@ int32_t OH_Sensor_SetSubscriptionSensorType(Sensor_SubscriptionId* id, const Sen return SENSOR_SUCCESS; } -int32_t OH_Sensor_SetSamplingInterval(Sensor_SubscriptionAttribute* attribute, const int64_t samplingInterval) +int32_t OH_Sensor_SubscriptionAttribute_SetSamplingInterval(Sensor_SubscriptionAttribute* attribute, + const int64_t samplingInterval) { if (attribute == nullptr || samplingInterval < 0) { SEN_HILOGE("Parameter error"); @@ -282,7 +283,8 @@ int32_t OH_Sensor_SetSamplingInterval(Sensor_SubscriptionAttribute* attribute, c return SENSOR_SUCCESS; } -int32_t OH_Sensor_GetSamplingInterval(Sensor_SubscriptionAttribute* attribute, int64_t *samplingInterval) +int32_t OH_Sensor_SubscriptionAttribute_GetSamplingInterval(Sensor_SubscriptionAttribute* attribute, + int64_t *samplingInterval) { if (attribute == nullptr || samplingInterval == nullptr) { SEN_HILOGE("Parameter error"); @@ -292,7 +294,7 @@ int32_t OH_Sensor_GetSamplingInterval(Sensor_SubscriptionAttribute* attribute, i return SENSOR_SUCCESS; } -int32_t OH_Sensor_SetSensorCallback(Sensor_Subscriber* user, const Sensor_EventCallback callback) +int32_t OH_Sensor_Subscriber_SetCallback(Sensor_Subscriber* user, const Sensor_EventCallback callback) { if (user == nullptr || callback == nullptr) { SEN_HILOGE("Parameter error"); @@ -302,7 +304,7 @@ int32_t OH_Sensor_SetSensorCallback(Sensor_Subscriber* user, const Sensor_EventC return SENSOR_SUCCESS; } -int32_t OH_Sensor_GetSensorCallback(Sensor_Subscriber* user, Sensor_EventCallback *callback) +int32_t OH_Sensor_Subscriber_GetCallback(Sensor_Subscriber* user, Sensor_EventCallback *callback) { if (user == nullptr || callback == nullptr) { SEN_HILOGE("Parameter error"); @@ -312,12 +314,12 @@ int32_t OH_Sensor_GetSensorCallback(Sensor_Subscriber* user, Sensor_EventCallbac return SENSOR_SUCCESS; } -Sensor_SubscriptionId *OH_Sensor_CreateSubscriptionId() +Sensor_SubscriptionId *OH_Sensor_SubscriptionId_Create() { return new (std::nothrow) Sensor_SubscriptionId(); } -int32_t OH_Sensor_DestroySubscriptionId(Sensor_SubscriptionId *id) +int32_t OH_Sensor_SubscriptionId_Destroy(Sensor_SubscriptionId *id) { if (id == nullptr) { SEN_HILOGE("Parameter error"); @@ -328,12 +330,12 @@ int32_t OH_Sensor_DestroySubscriptionId(Sensor_SubscriptionId *id) return SENSOR_SUCCESS; } -Sensor_SubscriptionAttribute *OH_Sensor_CreateAttribute() +Sensor_SubscriptionAttribute *OH_Sensor_SubscriptionAttribute_Create() { return new (std::nothrow) Sensor_SubscriptionAttribute(); } -int32_t OH_Sensor_DestroyAttribute(Sensor_SubscriptionAttribute *attribute) +int32_t OH_Sensor_SubscriptionAttribute_Destroy(Sensor_SubscriptionAttribute *attribute) { if (attribute == nullptr) { SEN_HILOGE("Parameter error"); @@ -344,12 +346,12 @@ int32_t OH_Sensor_DestroyAttribute(Sensor_SubscriptionAttribute *attribute) return SENSOR_SUCCESS; } -Sensor_Subscriber *OH_Sensor_CreateSubscriber() +Sensor_Subscriber *OH_Sensor_Subscriber_Create() { return new (std::nothrow) Sensor_Subscriber(); } -int32_t OH_Sensor_DestroySubscriber(Sensor_Subscriber *user) +int32_t OH_Sensor_Subscriber_Destroy(Sensor_Subscriber *user) { if (user == nullptr) { SEN_HILOGE("Parameter error"); diff --git a/interfaces/kits/c/BUILD.gn b/interfaces/kits/c/BUILD.gn index 2cc82b7f..3629fa7a 100644 --- a/interfaces/kits/c/BUILD.gn +++ b/interfaces/kits/c/BUILD.gn @@ -13,23 +13,17 @@ import("//build/ohos.gni") import("//build/ohos/ndk/ndk.gni") -import("./../../../sensor.gni") ohos_ndk_headers("sensor_ndk_header") { dest_dir = "$ndk_headers_out_dir/sensors/sensor" sources = [ - "./native_sensor.h", - "./native_sensor_type.h", + "./oh_sensor.h", + "./oh_sensor_type.h", ] } ohos_ndk_library("libsensor_ndk") { ndk_description_file = "./libsensor.ndk.json" - output_name = "sensor_native" + output_name = "ohsensor" min_compact_version = "11" - system_capability = "SystemCapability.Sensors.Sensor" - system_capability_headers = [ - "$ndk_headers_out_dir/sensor/native_sensor.h", - "$ndk_headers_out_dir/sensor/native_sensor_type.h", - ] } diff --git a/interfaces/kits/c/libsensor.ndk.json b/interfaces/kits/c/libsensor.ndk.json index 8a761a0b..eb6d417d 100644 --- a/interfaces/kits/c/libsensor.ndk.json +++ b/interfaces/kits/c/libsensor.ndk.json @@ -1,83 +1,83 @@ [ { - "name": "OH_Sensor_GetAllSensors" + "name": "OH_Sensor_GetInfos" }, { - "name": "OH_Sensor_SubscribeSensor" + "name": "OH_Sensor_Subscribe" }, { - "name": "OH_Sensor_UnsubscribeSensor" + "name": "OH_Sensor_Unsubscribe" }, { - "name": "OH_Sensor_GetSensorName" + "name": "OH_Sensor_Info_GetName" }, { - "name": "OH_Sensor_GetVendorName" + "name": "OH_Sensor_Info_GetVendorName" }, { - "name": "OH_Sensor_GetSensorType" + "name": "OH_Sensor_Info_GetType" }, { - "name": "OH_Sensor_GetSensorResolution" + "name": "OH_Sensor_Info_GetResolution" }, { - "name": "OH_Sensor_GetMinSamplingInterval" + "name": "OH_Sensor_Info_GetMinSamplingInterval" }, { - "name": "OH_Sensor_GetMaxSamplingInterval" + "name": "OH_Sensor_Info_GetMaxSamplingInterval" }, { - "name": "OH_Sensor_GetEventSensorType" + "name": "OH_Sensor_Event_GetType" }, { - "name": "OH_Sensor_GetEventTimestamp" + "name": "OH_Sensor_Event_GetTimestamp" }, { - "name": "OH_Sensor_GetEventAccuracy" + "name": "OH_Sensor_Event_GetAccuracy" }, { - "name": "OH_Sensor_GetSensorData" + "name": "OH_Sensor_Event_GetData" }, { - "name": "OH_Sensor_GetSubscriptionSensorType" + "name": "OH_Sensor_SubscriptionId_GetType" }, { - "name": "OH_Sensor_SetSubscriptionSensorType" + "name": "OH_Sensor_SubscriptionId_SetType" }, { - "name": "OH_Sensor_SetSamplingInterval" + "name": "OH_Sensor_SubscriptionAttribute_SetSamplingInterval" }, { - "name": "OH_Sensor_GetSamplingInterval" + "name": "OH_Sensor_SubscriptionAttribute_GetSamplingInterval" }, { - "name": "OH_Sensor_SetSensorCallback" + "name": "OH_Sensor_Subscriber_SetCallback" }, { - "name": "OH_Sensor_GetSensorCallback" + "name": "OH_Sensor_Subscriber_GetCallback" }, { - "name": "OH_Sensor_CreateSensors" + "name": "OH_Sensor_Info_Create" }, { - "name": "OH_Sensor_DestroySensors" + "name": "OH_Sensor_Info_Destroy" }, { - "name": "OH_Sensor_CreateSubscriptionId" + "name": "OH_Sensor_SubscriptionId_Create" }, { - "name": "OH_Sensor_DestroySubscriptionId" + "name": "OH_Sensor_SubscriptionId_Destroy" }, { - "name": "OH_Sensor_CreateAttribute" + "name": "OH_Sensor_SubscriptionAttribute_Create" }, { - "name": "OH_Sensor_DestroyAttribute" + "name": "OH_Sensor_SubscriptionAttribute_Destroy" }, { - "name": "OH_Sensor_CreateSubscriber" + "name": "OH_Sensor_Subscriber_Create" }, { - "name": "OH_Sensor_DestroySubscriber" + "name": "OH_Sensor_Subscriber_Destroy" } ] \ No newline at end of file diff --git a/interfaces/kits/c/native_sensor.h b/interfaces/kits/c/oh_sensor.h similarity index 87% rename from interfaces/kits/c/native_sensor.h rename to interfaces/kits/c/oh_sensor.h index 776847cf..ee0d78c6 100644 --- a/interfaces/kits/c/native_sensor.h +++ b/interfaces/kits/c/oh_sensor.h @@ -22,19 +22,19 @@ * @since 11 */ /** - * @file native_sensor.h + * @file oh_sensor.h * * @brief Declares the APIs for operating sensors, including obtaining sensor information and subscribing to or * unsubscribing from sensor data. - * @library libsensor_native.z.so + * @library libohsensor.so * @syscap SystemCapability.Sensors.Sensor * @since 11 */ -#ifndef OH_NATIVE_SENSOR_H -#define OH_NATIVE_SENSOR_H +#ifndef OH_SENSOR_H +#define OH_SENSOR_H -#include "native_sensor_type.h" +#include "oh_sensor_type.h" #ifdef __cplusplus extern "C" { @@ -42,15 +42,15 @@ extern "C" { /** * @brief Obtains information about all sensors on the device. * - * @param sensors - Double pointer to the information about all sensors on the device. - * For details, see {@link Sensor_DeviceInfo}. + * @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_GetAllSensors(Sensor_DeviceInfo **sensors, uint32_t *count); +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. @@ -71,7 +71,7 @@ Sensor_Result OH_Sensor_GetAllSensors(Sensor_DeviceInfo **sensors, uint32_t *cou * ohos.permission.ACTIVITY_MOTION or ohos.permission.READ_HEALTH_DATA * @since 11 */ -Sensor_Result OH_Sensor_SubscribeSensor(const Sensor_SubscriptionId *id, +Sensor_Result OH_Sensor_Subscribe(const Sensor_SubscriptionId *id, const Sensor_SubscriptionAttribute *attribute, const Sensor_Subscriber *subscriber); /** @@ -92,8 +92,8 @@ Sensor_Result OH_Sensor_SubscribeSensor(const Sensor_SubscriptionId *id, * * @since 11 */ -Sensor_Result OH_Sensor_UnsubscribeSensor(const Sensor_SubscriptionId *id, const Sensor_Subscriber *subscriber); +Sensor_Result OH_Sensor_Unsubscribe(const Sensor_SubscriptionId *id, const Sensor_Subscriber *subscriber); #ifdef __cplusplus } #endif -#endif // OH_NATIVE_SENSOR_H \ No newline at end of file +#endif // OH_SENSOR_H \ No newline at end of file diff --git a/interfaces/kits/c/native_sensor_type.h b/interfaces/kits/c/oh_sensor_type.h similarity index 82% rename from interfaces/kits/c/native_sensor_type.h rename to interfaces/kits/c/oh_sensor_type.h index 3ea09ae2..61ae622c 100644 --- a/interfaces/kits/c/native_sensor_type.h +++ b/interfaces/kits/c/oh_sensor_type.h @@ -23,16 +23,16 @@ */ /** - * @file native_sensor_type.h + * @file oh_sensor_type.h * * @brief Declares the common sensor attributes. - * @library libsensor_native.z.so + * @library libohsensor.so * @syscap SystemCapability.Sensors.Sensor * @since 11 */ -#ifndef OH_NATIVE_SENSOR_TYPE_H -#define OH_NATIVE_SENSOR_TYPE_H +#ifndef OH_SENSOR_TYPE_H +#define OH_SENSOR_TYPE_H #include @@ -147,7 +147,7 @@ typedef enum Sensor_Result { * * @since 11 */ -typedef enum Sensor_DataAccuracy { +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 @@ -170,35 +170,35 @@ typedef enum Sensor_DataAccuracy { * @since 11 */ SENSOR_ACCURACY_HIGH = 3 -} Sensor_DataAccuracy; +} Sensor_Accuracy; /** * @brief Defines the sensor information. * @since 11 */ -typedef struct Sensor_DeviceInfo Sensor_DeviceInfo; +typedef struct Sensor_Info Sensor_Info; /** - * @brief Creates an array of {@link Sensor_DeviceInfo} instances with the given number. + * @brief Creates an array of {@link Sensor_Info} instances with the given number. * - * @param count - Number of {@link Sensor_DeviceInfo} instances to create. - * @return Returns the double pointer to the array of {@link Sensor_DeviceInfo} instances + * @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_DeviceInfo **OH_Sensor_CreateSensors(uint32_t count); +Sensor_Info **OH_Sensor_Info_Create(uint32_t count); /** - * @brief Destroys an array of {@link Sensor_DeviceInfo} instances and reclaims memory. + * @brief Destroys an array of {@link Sensor_Info} instances and reclaims memory. * - * @param sensors - Double pointer to the array of {@link Sensor_DeviceInfo} instances. - * @param count - Number of {@link Sensor_DeviceInfo} instances to destroy. + * @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_DestroySensors(Sensor_DeviceInfo **sensors, uint32_t count); +int32_t OH_Sensor_Info_Destroy(Sensor_Info **sensors, uint32_t count); /** * @brief Obtains the sensor name. @@ -210,7 +210,7 @@ int32_t OH_Sensor_DestroySensors(Sensor_DeviceInfo **sensors, uint32_t count); * returns an error code defined in {@link Sensor_Result} otherwise. * @since 11 */ -int32_t OH_Sensor_GetSensorName(Sensor_DeviceInfo* sensor, char *sensorName, uint32_t *length); +int32_t OH_Sensor_Info_GetName(Sensor_Info* sensor, char *sensorName, uint32_t *length); /** * @brief Obtains the sensor's vendor name. @@ -222,7 +222,7 @@ int32_t OH_Sensor_GetSensorName(Sensor_DeviceInfo* sensor, char *sensorName, uin * returns an error code defined in {@link Sensor_Result} otherwise. * @since 11 */ -int32_t OH_Sensor_GetVendorName(Sensor_DeviceInfo* sensor, char *vendorName, uint32_t *length); +int32_t OH_Sensor_Info_GetVendorName(Sensor_Info* sensor, char *vendorName, uint32_t *length); /** * @brief Obtains the sensor type. @@ -233,7 +233,7 @@ int32_t OH_Sensor_GetVendorName(Sensor_DeviceInfo* sensor, char *vendorName, uin * returns an error code defined in {@link Sensor_Result} otherwise. * @since 11 */ -int32_t OH_Sensor_GetSensorType(Sensor_DeviceInfo* sensor, Sensor_Type *sensorType); +int32_t OH_Sensor_Info_GetType(Sensor_Info* sensor, Sensor_Type *sensorType); /** * @brief Obtains the sensor resolution. @@ -244,7 +244,7 @@ int32_t OH_Sensor_GetSensorType(Sensor_DeviceInfo* sensor, Sensor_Type *sensorTy * returns an error code defined in {@link Sensor_Result} otherwise. * @since 11 */ -int32_t OH_Sensor_GetSensorResolution(Sensor_DeviceInfo* sensor, float *resolution); +int32_t OH_Sensor_Info_GetResolution(Sensor_Info* sensor, float *resolution); /** * @brief Obtains the minimum data reporting interval of a sensor. @@ -255,7 +255,7 @@ int32_t OH_Sensor_GetSensorResolution(Sensor_DeviceInfo* sensor, float *resoluti * returns an error code defined in {@link Sensor_Result} otherwise. * @since 11 */ -int32_t OH_Sensor_GetMinSamplingInterval(Sensor_DeviceInfo* sensor, int64_t *minSamplingInterval); +int32_t OH_Sensor_Info_GetMinSamplingInterval(Sensor_Info* sensor, int64_t *minSamplingInterval); /** * @brief Obtains the maximum data reporting interval of a sensor. @@ -266,7 +266,7 @@ int32_t OH_Sensor_GetMinSamplingInterval(Sensor_DeviceInfo* sensor, int64_t *min * returns an error code defined in {@link Sensor_Result} otherwise. * @since 11 */ -int32_t OH_Sensor_GetMaxSamplingInterval(Sensor_DeviceInfo* sensor, int64_t *maxSamplingInterval); +int32_t OH_Sensor_Info_GetMaxSamplingInterval(Sensor_Info* sensor, int64_t *maxSamplingInterval); /** * @brief Defines the sensor data information. @@ -277,35 +277,35 @@ typedef struct Sensor_Event Sensor_Event; /** * @brief Obtains the sensor type. * - * @param sensorEvent - Pointer to the sensor data information. + * @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_Sensor_GetEventSensorType(Sensor_Event* sensorEvent, Sensor_Type *sensorType); +int32_t OH_Sensor_Event_GetType(Sensor_Event* Sensor_Event, Sensor_Type *sensorType); /** * @brief Obtains the timestamp of sensor data. * - * @param sensorEvent - Pointer to the sensor data information. + * @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_Sensor_GetEventTimestamp(Sensor_Event* sensorEvent, int64_t *timestamp); +int32_t OH_Sensor_Event_GetTimestamp(Sensor_Event* Sensor_Event, int64_t *timestamp); /** * @brief Obtains the accuracy of sensor data. * - * @param sensorEvent - Pointer to the sensor data information. + * @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_Sensor_GetEventAccuracy(Sensor_Event* sensorEvent, Sensor_DataAccuracy *accuracy); +int32_t OH_Sensor_Event_GetAccuracy(Sensor_Event* Sensor_Event, Sensor_Accuracy *accuracy); /** * @brief Obtains sensor data. The data length and content depend on the sensor type. @@ -333,14 +333,14 @@ int32_t OH_Sensor_GetEventAccuracy(Sensor_Event* sensorEvent, Sensor_DataAccurac * 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 sensorEvent - Pointer to the sensor data information. + * @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_Sensor_GetSensorData(Sensor_Event* sensorEvent, float **data, uint32_t *length); +int32_t OH_Sensor_Event_GetData(Sensor_Event* Sensor_Event, float **data, uint32_t *length); /** * @brief Defines the sensor subscription ID, which uniquely identifies a sensor. @@ -355,7 +355,7 @@ typedef struct Sensor_SubscriptionId Sensor_SubscriptionId; * returns NULL otherwise. * @since 11 */ -Sensor_SubscriptionId *OH_Sensor_CreateSubscriptionId(void); +Sensor_SubscriptionId *OH_Sensor_SubscriptionId_Create(void); /** * @brief Destroys a {@link Sensor_SubscriptionId} instance and reclaims memory. @@ -365,7 +365,7 @@ Sensor_SubscriptionId *OH_Sensor_CreateSubscriptionId(void); * returns an error code defined in {@link Sensor_Result} otherwise. * @since 11 */ -int32_t OH_Sensor_DestroySubscriptionId(Sensor_SubscriptionId *id); +int32_t OH_Sensor_SubscriptionId_Destroy(Sensor_SubscriptionId *id); /** * @brief Obtains the sensor type. @@ -376,7 +376,7 @@ int32_t OH_Sensor_DestroySubscriptionId(Sensor_SubscriptionId *id); * returns an error code defined in {@link Sensor_Result} otherwise. * @since 11 */ -int32_t OH_Sensor_GetSubscriptionSensorType(Sensor_SubscriptionId* id, Sensor_Type *sensorType); +int32_t OH_Sensor_SubscriptionId_GetType(Sensor_SubscriptionId* id, Sensor_Type *sensorType); /** * @brief Sets the sensor type. @@ -387,7 +387,7 @@ int32_t OH_Sensor_GetSubscriptionSensorType(Sensor_SubscriptionId* id, Sensor_Ty * returns an error code defined in {@link Sensor_Result} otherwise. * @since 11 */ -int32_t OH_Sensor_SetSubscriptionSensorType(Sensor_SubscriptionId* id, const Sensor_Type sensorType); +int32_t OH_Sensor_SubscriptionId_SetType(Sensor_SubscriptionId* id, const Sensor_Type sensorType); /** * @brief Defines the sensor subscription attribute. @@ -402,7 +402,7 @@ typedef struct Sensor_SubscriptionAttribute Sensor_SubscriptionAttribute; * returns NULL otherwise. * @since 11 */ -Sensor_SubscriptionAttribute *OH_Sensor_CreateAttribute(void); +Sensor_SubscriptionAttribute *OH_Sensor_SubscriptionAttribute_Create(void); /** * @brief Destroys a {@link Sensor_SubscriptionAttribute} instance and reclaims memory. @@ -412,7 +412,7 @@ Sensor_SubscriptionAttribute *OH_Sensor_CreateAttribute(void); * returns an error code defined in {@link Sensor_Result} otherwise. * @since 11 */ -int32_t OH_Sensor_DestroyAttribute(Sensor_SubscriptionAttribute *attribute); +int32_t OH_Sensor_SubscriptionAttribute_Destroy(Sensor_SubscriptionAttribute *attribute); /** * @brief Sets the sensor data reporting interval. @@ -423,7 +423,8 @@ int32_t OH_Sensor_DestroyAttribute(Sensor_SubscriptionAttribute *attribute); * returns an error code defined in {@link Sensor_Result} otherwise. * @since 11 */ -int32_t OH_Sensor_SetSamplingInterval(Sensor_SubscriptionAttribute* attribute, const int64_t samplingInterval); +int32_t OH_Sensor_SubscriptionAttribute_SetSamplingInterval(Sensor_SubscriptionAttribute* attribute, + const int64_t samplingInterval); /** * @brief Obtains the sensor data reporting interval. @@ -434,7 +435,8 @@ int32_t OH_Sensor_SetSamplingInterval(Sensor_SubscriptionAttribute* attribute, c * returns an error code defined in {@link Sensor_Result} otherwise. * @since 11 */ -int32_t OH_Sensor_GetSamplingInterval(Sensor_SubscriptionAttribute* attribute, int64_t *samplingInterval); +int32_t OH_Sensor_SubscriptionAttribute_GetSamplingInterval(Sensor_SubscriptionAttribute* attribute, + int64_t *samplingInterval); /** * @brief Defines the callback function used to report sensor data. @@ -455,7 +457,7 @@ typedef struct Sensor_Subscriber Sensor_Subscriber; * if the operation is successful; returns NULL otherwise. * @since 11 */ -Sensor_Subscriber *OH_Sensor_CreateSubscriber(void); +Sensor_Subscriber *OH_Sensor_Subscriber_Create(void); /** * @brief Destroys a {@link Sensor_Subscriber} instance and reclaims memory. @@ -465,7 +467,7 @@ Sensor_Subscriber *OH_Sensor_CreateSubscriber(void); * returns an error code defined in {@link Sensor_Result} otherwise. * @since 11 */ -int32_t OH_Sensor_DestroySubscriber(Sensor_Subscriber *subscriber); +int32_t OH_Sensor_Subscriber_Destroy(Sensor_Subscriber *subscriber); /** * @brief Sets a callback function to report sensor data. @@ -476,7 +478,7 @@ int32_t OH_Sensor_DestroySubscriber(Sensor_Subscriber *subscriber); * returns an error code defined in {@link Sensor_Result} otherwise. * @since 11 */ -int32_t OH_Sensor_SetSensorCallback(Sensor_Subscriber* subscriber, const Sensor_EventCallback callback); +int32_t OH_Sensor_Subscriber_SetCallback(Sensor_Subscriber* subscriber, const Sensor_EventCallback callback); /** * @brief Obtains the callback function used to report sensor data. @@ -487,8 +489,8 @@ int32_t OH_Sensor_SetSensorCallback(Sensor_Subscriber* subscriber, const Sensor_ * returns an error code defined in {@link Sensor_Result} otherwise. * @since 11 */ -int32_t OH_Sensor_GetSensorCallback(Sensor_Subscriber* subscriber, Sensor_EventCallback *callback); +int32_t OH_Sensor_Subscriber_GetCallback(Sensor_Subscriber* subscriber, Sensor_EventCallback *callback); #ifdef __cplusplus } #endif -#endif // OH_NATIVE_SENSOR_TYPE_H \ No newline at end of file +#endif // OH_SENSOR_TYPE_H \ No newline at end of file diff --git a/test/unittest/interfaces/kits/BUILD.gn b/test/unittest/interfaces/kits/BUILD.gn index 90cda26e..4ac9e119 100644 --- a/test/unittest/interfaces/kits/BUILD.gn +++ b/test/unittest/interfaces/kits/BUILD.gn @@ -27,7 +27,7 @@ ohos_unittest("SensorNativeTest") { ] deps = [ - "$SUBSYSTEM_DIR/frameworks/native:sensor_native", + "$SUBSYSTEM_DIR/frameworks/native:ohsensor", "$SUBSYSTEM_DIR/utils/common:libsensor_utils", "//third_party/googletest:gmock_main", "//third_party/googletest:gtest_main", diff --git a/test/unittest/interfaces/kits/sensor_native_test.cpp b/test/unittest/interfaces/kits/sensor_native_test.cpp index 1b39509a..824c6b5c 100755 --- a/test/unittest/interfaces/kits/sensor_native_test.cpp +++ b/test/unittest/interfaces/kits/sensor_native_test.cpp @@ -22,7 +22,7 @@ #include "nativetoken_kit.h" #include "token_setproc.h" -#include "native_sensor.h" +#include "oh_sensor.h" #include "sensor_errors.h" namespace OHOS { @@ -119,292 +119,298 @@ void SensorDataCallbackImpl(Sensor_Event *event) return; } int64_t timestamp = INVALID_VALUE; - int32_t ret = OH_Sensor_GetEventTimestamp(event, ×tamp); + int32_t ret = OH_Sensor_Event_GetTimestamp(event, ×tamp); ASSERT_EQ(ret, SENSOR_SUCCESS); Sensor_Type sensorType; - ret = OH_Sensor_GetEventSensorType(event, &sensorType); + ret = OH_Sensor_Event_GetType(event, &sensorType); ASSERT_EQ(ret, SENSOR_SUCCESS); - Sensor_DataAccuracy accuracy = SENSOR_ACCURACY_UNRELIABLE; - ret = OH_Sensor_GetEventAccuracy(event, &accuracy); + Sensor_Accuracy accuracy = SENSOR_ACCURACY_UNRELIABLE; + ret = OH_Sensor_Event_GetAccuracy(event, &accuracy); ASSERT_EQ(ret, SENSOR_SUCCESS); float *data = nullptr; uint32_t length = 0; - ret = OH_Sensor_GetSensorData(event, &data, &length); + ret = OH_Sensor_Event_GetData(event, &data, &length); ASSERT_EQ(ret, SENSOR_SUCCESS); SEN_HILOGI("sensorType:%{public}d, dataLen:%{public}d, accuracy:%{public}d" "x:%{public}f, y:%{public}f, z:%{public}f", sensorType, length, accuracy, data[0], data[1], data[2]); } -HWTEST_F(SensorAgentTest, OH_Sensor_GetAllSensors_001, TestSize.Level1) +HWTEST_F(SensorAgentTest, OH_Sensor_GetInfos_001, TestSize.Level1) { - SEN_HILOGI("OH_Sensor_GetAllSensors_001 in"); + SEN_HILOGI("OH_Sensor_GetInfos_001 in"); uint32_t count = 0; - int32_t ret = OH_Sensor_GetAllSensors(nullptr, &count); + int32_t ret = OH_Sensor_GetInfos(nullptr, &count); ASSERT_EQ(ret, SENSOR_SUCCESS); - Sensor_DeviceInfo **sensors = OH_Sensor_CreateSensors(count); + Sensor_Info **sensors = OH_Sensor_Info_Create(count); ASSERT_NE(sensors, nullptr); - ret = OH_Sensor_GetAllSensors(sensors, &count); + ret = OH_Sensor_GetInfos(sensors, &count); ASSERT_EQ(ret, SENSOR_SUCCESS); for (uint32_t i = 0; i < count; ++i) { char sensorName[SENSOR_NAME_LENGTH_MAX] = {}; uint32_t length = SENSOR_NAME_LENGTH_MAX; - ret = OH_Sensor_GetSensorName(sensors[i], sensorName, &length); + ret = OH_Sensor_Info_GetName(sensors[i], sensorName, &length); ASSERT_EQ(ret, SENSOR_SUCCESS); char vendorName[SENSOR_NAME_LENGTH_MAX] = {}; length = SENSOR_NAME_LENGTH_MAX; - ret = OH_Sensor_GetVendorName(sensors[i], vendorName, &length); + ret = OH_Sensor_Info_GetVendorName(sensors[i], vendorName, &length); ASSERT_EQ(ret, SENSOR_SUCCESS); Sensor_Type sensorType; - ret = OH_Sensor_GetSensorType(sensors[i], &sensorType); + ret = OH_Sensor_Info_GetType(sensors[i], &sensorType); ASSERT_EQ(ret, SENSOR_SUCCESS); float resolution = INVALID_RESOLUTION; - ret = OH_Sensor_GetSensorResolution(sensors[i], &resolution); + ret = OH_Sensor_Info_GetResolution(sensors[i], &resolution); ASSERT_EQ(ret, SENSOR_SUCCESS); int64_t minSamplePeriod = INVALID_VALUE; - ret = OH_Sensor_GetMinSamplingInterval(sensors[i], &minSamplePeriod); + ret = OH_Sensor_Info_GetMinSamplingInterval(sensors[i], &minSamplePeriod); ASSERT_EQ(ret, SENSOR_SUCCESS); int64_t maxSamplePeriod = INVALID_VALUE; - ret = OH_Sensor_GetMaxSamplingInterval(sensors[i], &maxSamplePeriod); + ret = OH_Sensor_Info_GetMaxSamplingInterval(sensors[i], &maxSamplePeriod); ASSERT_EQ(ret, SENSOR_SUCCESS); SEN_HILOGI("sensorType:%{public}d, sensorName:%{public}s, vendorName:%{public}s," "resolution:%{public}f, minSamplePeriod:%{public}" PRId64 "maxSamplePeriod:%{public}" PRId64, static_cast(sensorType), sensorName, vendorName, resolution, minSamplePeriod, maxSamplePeriod); } - ret = OH_Sensor_DestroySensors(sensors, count); + ret = OH_Sensor_Info_Destroy(sensors, count); ASSERT_EQ(ret, SENSOR_SUCCESS); } -HWTEST_F(SensorAgentTest, OH_Sensor_GetAllSensors_002, TestSize.Level1) +HWTEST_F(SensorAgentTest, OH_Sensor_GetInfos_002, TestSize.Level1) { - SEN_HILOGI("OH_Sensor_GetAllSensors_003 in"); - Sensor_DeviceInfo *sensors { nullptr }; - int32_t ret = OH_Sensor_GetAllSensors(&sensors, nullptr); + SEN_HILOGI("OH_Sensor_GetInfos_003 in"); + Sensor_Info *sensors { nullptr }; + int32_t ret = OH_Sensor_GetInfos(&sensors, nullptr); ASSERT_NE(ret, SENSOR_SUCCESS); } -HWTEST_F(SensorAgentTest, OH_Sensor_SubscribeSensor_001, TestSize.Level1) +HWTEST_F(SensorAgentTest, OH_Sensor_Subscribe_001, TestSize.Level1) { - SEN_HILOGI("OH_Sensor_SubscribeSensor_001 in"); - g_user = OH_Sensor_CreateSubscriber(); - int32_t ret = OH_Sensor_SetSensorCallback(g_user, SensorDataCallbackImpl); + SEN_HILOGI("OH_Sensor_Subscribe_001 in"); + g_user = OH_Sensor_Subscriber_Create(); + int32_t ret = OH_Sensor_Subscriber_SetCallback(g_user, SensorDataCallbackImpl); ASSERT_EQ(ret, SENSOR_SUCCESS); - Sensor_SubscriptionId *id = OH_Sensor_CreateSubscriptionId(); - ret = OH_Sensor_SetSubscriptionSensorType(id, SENSOR_ID); + Sensor_SubscriptionId *id = OH_Sensor_SubscriptionId_Create(); + ret = OH_Sensor_SubscriptionId_SetType(id, SENSOR_ID); ASSERT_EQ(ret, SENSOR_SUCCESS); - Sensor_SubscriptionAttribute *attr = OH_Sensor_CreateAttribute(); - ret = OH_Sensor_SetSamplingInterval(attr, SENSOR_SAMPLE_PERIOD); + Sensor_SubscriptionAttribute *attr = OH_Sensor_SubscriptionAttribute_Create(); + ret = OH_Sensor_SubscriptionAttribute_SetSamplingInterval(attr, SENSOR_SAMPLE_PERIOD); ASSERT_EQ(ret, SENSOR_SUCCESS); - ret = OH_Sensor_SubscribeSensor(id, attr, g_user); + ret = OH_Sensor_Subscribe(id, attr, g_user); ASSERT_EQ(ret, SENSOR_SUCCESS); std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_TIME_MS)); - ret = OH_Sensor_UnsubscribeSensor(id, g_user); + ret = OH_Sensor_Unsubscribe(id, g_user); ASSERT_EQ(ret, SENSOR_SUCCESS); if (id != nullptr) { - OH_Sensor_DestroySubscriptionId(id); + OH_Sensor_SubscriptionId_Destroy(id); } if (attr != nullptr) { - OH_Sensor_DestroyAttribute(attr); + OH_Sensor_SubscriptionAttribute_Destroy(attr); } if (g_user != nullptr) { - OH_Sensor_DestroySubscriber(g_user); + OH_Sensor_Subscriber_Destroy(g_user); g_user = nullptr; } } -HWTEST_F(SensorAgentTest, OH_Sensor_SubscribeSensor_002, TestSize.Level1) +HWTEST_F(SensorAgentTest, OH_Sensor_Subscribe_002, TestSize.Level1) { - SEN_HILOGI("OH_Sensor_SubscribeSensor_002 in"); - Sensor_SubscriptionId *id = OH_Sensor_CreateSubscriptionId(); - int32_t ret = OH_Sensor_SetSubscriptionSensorType(id, SENSOR_ID); + SEN_HILOGI("OH_Sensor_Subscribe_002 in"); + Sensor_SubscriptionId *id = OH_Sensor_SubscriptionId_Create(); + int32_t ret = OH_Sensor_SubscriptionId_SetType(id, SENSOR_ID); ASSERT_EQ(ret, SENSOR_SUCCESS); - Sensor_SubscriptionAttribute *attr = OH_Sensor_CreateAttribute(); - ret = OH_Sensor_SetSamplingInterval(attr, SENSOR_SAMPLE_PERIOD); + Sensor_SubscriptionAttribute *attr = OH_Sensor_SubscriptionAttribute_Create(); + ret = OH_Sensor_SubscriptionAttribute_SetSamplingInterval(attr, SENSOR_SAMPLE_PERIOD); ASSERT_EQ(ret, SENSOR_SUCCESS); - ret = OH_Sensor_SubscribeSensor(id, attr, nullptr); + ret = OH_Sensor_Subscribe(id, attr, nullptr); ASSERT_EQ(ret, SENSOR_PARAMETER_ERROR); if (id != nullptr) { - OH_Sensor_DestroySubscriptionId(id); + OH_Sensor_SubscriptionId_Destroy(id); } if (attr != nullptr) { - OH_Sensor_DestroyAttribute(attr); + OH_Sensor_SubscriptionAttribute_Destroy(attr); } } -HWTEST_F(SensorAgentTest, OH_Sensor_SubscribeSensor_003, TestSize.Level1) +HWTEST_F(SensorAgentTest, OH_Sensor_Subscribe_003, TestSize.Level1) { - SEN_HILOGI("OH_Sensor_SubscribeSensor_003 in"); - g_user = OH_Sensor_CreateSubscriber(); - int32_t ret = OH_Sensor_SetSensorCallback(g_user, SensorDataCallbackImpl); + SEN_HILOGI("OH_Sensor_Subscribe_003 in"); + g_user = OH_Sensor_Subscriber_Create(); + int32_t ret = OH_Sensor_Subscriber_SetCallback(g_user, SensorDataCallbackImpl); ASSERT_EQ(ret, SENSOR_SUCCESS); - Sensor_SubscriptionAttribute *attr = OH_Sensor_CreateAttribute(); - ret = OH_Sensor_SetSamplingInterval(attr, SENSOR_SAMPLE_PERIOD); + Sensor_SubscriptionAttribute *attr = OH_Sensor_SubscriptionAttribute_Create(); + ret = OH_Sensor_SubscriptionAttribute_SetSamplingInterval(attr, SENSOR_SAMPLE_PERIOD); ASSERT_EQ(ret, SENSOR_SUCCESS); - ret = OH_Sensor_SubscribeSensor(nullptr, attr, g_user); + ret = OH_Sensor_Subscribe(nullptr, attr, g_user); ASSERT_EQ(ret, SENSOR_PARAMETER_ERROR); if (attr != nullptr) { - OH_Sensor_DestroyAttribute(attr); + OH_Sensor_SubscriptionAttribute_Destroy(attr); } if (g_user != nullptr) { - OH_Sensor_DestroySubscriber(g_user); + OH_Sensor_Subscriber_Destroy(g_user); g_user = nullptr; } } -HWTEST_F(SensorAgentTest, OH_Sensor_SubscribeSensor_004, TestSize.Level1) +HWTEST_F(SensorAgentTest, OH_Sensor_Subscribe_004, TestSize.Level1) { - SEN_HILOGI("OH_Sensor_SubscribeSensor_004 in"); - g_user = OH_Sensor_CreateSubscriber(); - int32_t ret = OH_Sensor_SetSensorCallback(g_user, SensorDataCallbackImpl); + SEN_HILOGI("OH_Sensor_Subscribe_004 in"); + g_user = OH_Sensor_Subscriber_Create(); + int32_t ret = OH_Sensor_Subscriber_SetCallback(g_user, SensorDataCallbackImpl); ASSERT_EQ(ret, SENSOR_SUCCESS); - Sensor_SubscriptionId *id = OH_Sensor_CreateSubscriptionId(); - ret = OH_Sensor_SetSubscriptionSensorType(id, SENSOR_ID); + Sensor_SubscriptionId *id = OH_Sensor_SubscriptionId_Create(); + ret = OH_Sensor_SubscriptionId_SetType(id, SENSOR_ID); ASSERT_EQ(ret, SENSOR_SUCCESS); - ret = OH_Sensor_SubscribeSensor(id, nullptr, g_user); + ret = OH_Sensor_Subscribe(id, nullptr, g_user); ASSERT_EQ(ret, SENSOR_PARAMETER_ERROR); if (id != nullptr) { - OH_Sensor_DestroySubscriptionId(id); + OH_Sensor_SubscriptionId_Destroy(id); } if (g_user != nullptr) { - OH_Sensor_DestroySubscriber(g_user); + OH_Sensor_Subscriber_Destroy(g_user); g_user = nullptr; } } -HWTEST_F(SensorAgentTest, OH_Sensor_UnsubscribeSensor_001, TestSize.Level1) +HWTEST_F(SensorAgentTest, OH_Sensor_Unsubscribe_001, TestSize.Level1) { - SEN_HILOGI("OH_Sensor_UnsubscribeSensor_001 in"); - g_user = OH_Sensor_CreateSubscriber(); - int32_t ret = OH_Sensor_SetSensorCallback(g_user, SensorDataCallbackImpl); + SEN_HILOGI("OH_Sensor_Unsubscribe_001 in"); + g_user = OH_Sensor_Subscriber_Create(); + int32_t ret = OH_Sensor_Subscriber_SetCallback(g_user, SensorDataCallbackImpl); ASSERT_EQ(ret, SENSOR_SUCCESS); - ret = OH_Sensor_UnsubscribeSensor(nullptr, g_user); + ret = OH_Sensor_Unsubscribe(nullptr, g_user); ASSERT_EQ(ret, SENSOR_PARAMETER_ERROR); if (g_user != nullptr) { - OH_Sensor_DestroySubscriber(g_user); + OH_Sensor_Subscriber_Destroy(g_user); g_user = nullptr; } } -HWTEST_F(SensorAgentTest, OH_Sensor_UnsubscribeSensor_002, TestSize.Level1) +HWTEST_F(SensorAgentTest, OH_Sensor_Unsubscribe_002, TestSize.Level1) { - SEN_HILOGI("OH_Sensor_UnsubscribeSensor_002 in"); - Sensor_SubscriptionId *id = OH_Sensor_CreateSubscriptionId(); - int32_t ret = OH_Sensor_SetSubscriptionSensorType(id, SENSOR_ID); + SEN_HILOGI("OH_Sensor_Unsubscribe_002 in"); + Sensor_SubscriptionId *id = OH_Sensor_SubscriptionId_Create(); + int32_t ret = OH_Sensor_SubscriptionId_SetType(id, SENSOR_ID); ASSERT_EQ(ret, SENSOR_SUCCESS); - ret = OH_Sensor_UnsubscribeSensor(id, nullptr); + ret = OH_Sensor_Unsubscribe(id, nullptr); ASSERT_EQ(ret, SENSOR_PARAMETER_ERROR); if (id != nullptr) { - OH_Sensor_DestroySubscriptionId(id); + OH_Sensor_SubscriptionId_Destroy(id); } } -HWTEST_F(SensorAgentTest, OH_Sensor_SetSubscriptionSensorType_001, TestSize.Level1) +HWTEST_F(SensorAgentTest, OH_Sensor_SubscriptionId_SetType_001, TestSize.Level1) { - SEN_HILOGI("OH_Sensor_SetSubscriptionSensorType_001 in"); - int32_t ret = OH_Sensor_SetSubscriptionSensorType(nullptr, SENSOR_ID); + SEN_HILOGI("OH_Sensor_SubscriptionId_SetType_001 in"); + int32_t ret = OH_Sensor_SubscriptionId_SetType(nullptr, SENSOR_ID); ASSERT_EQ(ret, SENSOR_PARAMETER_ERROR); } -HWTEST_F(SensorAgentTest, OH_Sensor_GetSubscriptionSensorType_001, TestSize.Level1) +HWTEST_F(SensorAgentTest, OH_Sensor_SubscriptionId_GetType_001, TestSize.Level1) { - SEN_HILOGI("OH_Sensor_GetSubscriptionSensorType_001 in"); + SEN_HILOGI("OH_Sensor_SubscriptionId_GetType_001 in"); Sensor_Type type; - int32_t ret = OH_Sensor_GetSubscriptionSensorType(nullptr, &type); + int32_t ret = OH_Sensor_SubscriptionId_GetType(nullptr, &type); ASSERT_EQ(ret, SENSOR_PARAMETER_ERROR); } -HWTEST_F(SensorAgentTest, OH_Sensor_GetSubscriptionSensorType_002, TestSize.Level1) +HWTEST_F(SensorAgentTest, OH_Sensor_SubscriptionId_GetType_002, TestSize.Level1) { - SEN_HILOGI("OH_Sensor_GetSubscriptionSensorType_002 in"); - Sensor_SubscriptionId *id = OH_Sensor_CreateSubscriptionId(); - int32_t ret = OH_Sensor_GetSubscriptionSensorType(id, nullptr); + SEN_HILOGI("OH_Sensor_SubscriptionId_GetType_002 in"); + Sensor_SubscriptionId *id = OH_Sensor_SubscriptionId_Create(); + int32_t ret = OH_Sensor_SubscriptionId_GetType(id, nullptr); ASSERT_EQ(ret, SENSOR_PARAMETER_ERROR); if (id != nullptr) { - OH_Sensor_DestroySubscriptionId(id); + OH_Sensor_SubscriptionId_Destroy(id); } } -HWTEST_F(SensorAgentTest, OH_Sensor_SetSamplingInterval_001, TestSize.Level1) +HWTEST_F(SensorAgentTest, OH_Sensor_SubscriptionAttribute_SetSamplingInterval_001, + TestSize.Level1) { - SEN_HILOGI("OH_Sensor_SetSamplingInterval_001 in"); - int32_t ret = OH_Sensor_SetSamplingInterval(nullptr, SENSOR_SAMPLE_PERIOD); + SEN_HILOGI("OH_Sensor_SubscriptionAttribute_SetSamplingInterval_001 in"); + int32_t ret = OH_Sensor_SubscriptionAttribute_SetSamplingInterval(nullptr, + SENSOR_SAMPLE_PERIOD); ASSERT_EQ(ret, SENSOR_PARAMETER_ERROR); } -HWTEST_F(SensorAgentTest, OH_Sensor_SetSamplingInterval_002, TestSize.Level1) +HWTEST_F(SensorAgentTest, OH_Sensor_SubscriptionAttribute_SetSamplingInterval_002, + TestSize.Level1) { - SEN_HILOGI("OH_Sensor_SetSamplingInterval_002 in"); - Sensor_SubscriptionAttribute *attr = OH_Sensor_CreateAttribute(); - int32_t ret = OH_Sensor_SetSamplingInterval(attr, INVALID_VALUE); + SEN_HILOGI("OH_Sensor_SubscriptionAttribute_SetSamplingInterval_002 in"); + Sensor_SubscriptionAttribute *attr = OH_Sensor_SubscriptionAttribute_Create(); + int32_t ret = OH_Sensor_SubscriptionAttribute_SetSamplingInterval(attr, INVALID_VALUE); ASSERT_EQ(ret, SENSOR_PARAMETER_ERROR); if (attr != nullptr) { - OH_Sensor_DestroyAttribute(attr); + OH_Sensor_SubscriptionAttribute_Destroy(attr); } } -HWTEST_F(SensorAgentTest, OH_Sensor_GetSamplingInterval_001, TestSize.Level1) +HWTEST_F(SensorAgentTest, OH_Sensor_SubscriptionAttribute_GetSamplingInterval_001, + TestSize.Level1) { - SEN_HILOGI("OH_Sensor_GetSamplingInterval_001 in"); + SEN_HILOGI("OH_Sensor_SubscriptionAttribute_GetSamplingInterval_001 in"); int64_t samplingInterval = 0; - int32_t ret = OH_Sensor_GetSamplingInterval(nullptr, &samplingInterval); + int32_t ret = OH_Sensor_SubscriptionAttribute_GetSamplingInterval(nullptr, + &samplingInterval); ASSERT_EQ(ret, SENSOR_PARAMETER_ERROR); } -HWTEST_F(SensorAgentTest, OH_Sensor_GetSamplingInterval_002, TestSize.Level1) +HWTEST_F(SensorAgentTest, OH_Sensor_SubscriptionAttribute_GetSamplingInterval_002, + TestSize.Level1) { - SEN_HILOGI("OH_Sensor_GetSamplingInterval_002 in"); - Sensor_SubscriptionAttribute *attr = OH_Sensor_CreateAttribute(); - int32_t ret = OH_Sensor_GetSamplingInterval(attr, nullptr); + SEN_HILOGI("OH_Sensor_SubscriptionAttribute_GetSamplingInterval_002 in"); + Sensor_SubscriptionAttribute *attr = OH_Sensor_SubscriptionAttribute_Create(); + int32_t ret = OH_Sensor_SubscriptionAttribute_GetSamplingInterval(attr, nullptr); ASSERT_EQ(ret, SENSOR_PARAMETER_ERROR); if (attr != nullptr) { - OH_Sensor_DestroyAttribute(attr); + OH_Sensor_SubscriptionAttribute_Destroy(attr); } } -HWTEST_F(SensorAgentTest, OH_Sensor_SetSensorCallback_001, TestSize.Level1) +HWTEST_F(SensorAgentTest, OH_Sensor_Subscriber_SetCallback_001, TestSize.Level1) { - SEN_HILOGI("OH_Sensor_SetSensorCallback_001 in"); - int32_t ret = OH_Sensor_SetSensorCallback(nullptr, SensorDataCallbackImpl); + SEN_HILOGI("OH_Sensor_Subscriber_SetCallback_001 in"); + int32_t ret = OH_Sensor_Subscriber_SetCallback(nullptr, SensorDataCallbackImpl); ASSERT_EQ(ret, SENSOR_PARAMETER_ERROR); } -HWTEST_F(SensorAgentTest, OH_Sensor_SetSensorCallback_002, TestSize.Level1) +HWTEST_F(SensorAgentTest, OH_Sensor_Subscriber_SetCallback_002, TestSize.Level1) { - SEN_HILOGI("OH_Sensor_SetSensorCallback_002 in"); - g_user = OH_Sensor_CreateSubscriber(); - int32_t ret = OH_Sensor_SetSensorCallback(g_user, nullptr); + SEN_HILOGI("OH_Sensor_Subscriber_SetCallback_002 in"); + g_user = OH_Sensor_Subscriber_Create(); + int32_t ret = OH_Sensor_Subscriber_SetCallback(g_user, nullptr); ASSERT_EQ(ret, SENSOR_PARAMETER_ERROR); } -HWTEST_F(SensorAgentTest, OH_Sensor_GetSensorCallback_001, TestSize.Level1) +HWTEST_F(SensorAgentTest, OH_Sensor_Subscriber_GetCallback_001, TestSize.Level1) { - SEN_HILOGI("OH_Sensor_GetSensorCallback_001 in"); + SEN_HILOGI("OH_Sensor_Subscriber_GetCallback_001 in"); Sensor_EventCallback callback; - int32_t ret = OH_Sensor_GetSensorCallback(nullptr, &callback); + int32_t ret = OH_Sensor_Subscriber_GetCallback(nullptr, &callback); ASSERT_EQ(ret, SENSOR_PARAMETER_ERROR); } -HWTEST_F(SensorAgentTest, OH_Sensor_GetSensorCallback_002, TestSize.Level1) +HWTEST_F(SensorAgentTest, OH_Sensor_Subscriber_GetCallback_002, TestSize.Level1) { - SEN_HILOGI("OH_Sensor_GetSensorCallback_002 in"); - g_user = OH_Sensor_CreateSubscriber(); - int32_t ret = OH_Sensor_GetSensorCallback(g_user, nullptr); + SEN_HILOGI("OH_Sensor_Subscriber_GetCallback_002 in"); + g_user = OH_Sensor_Subscriber_Create(); + int32_t ret = OH_Sensor_Subscriber_GetCallback(g_user, nullptr); ASSERT_EQ(ret, SENSOR_PARAMETER_ERROR); if (g_user != nullptr) { - OH_Sensor_DestroySubscriber(g_user); + OH_Sensor_Subscriber_Destroy(g_user); } } } // namespace Sensors -- Gitee