diff --git a/services/BUILD.gn b/services/BUILD.gn index 76ac52e87472510e4fdba90ac7b5c6ce0dd1fbf5..10ab7bcc6847e73568f020ec2c1f039f9bbc7e5d 100644 --- a/services/BUILD.gn +++ b/services/BUILD.gn @@ -104,7 +104,7 @@ ohos_shared_library("libsensor_service") { [ "$SUBSYSTEM_DIR/services/hdi_connection/hardware/include" ] } - external_deps += [ "drivers_interface_sensor:libsensor_proxy_2.0" ] + external_deps += [ "drivers_interface_sensor:libsensor_proxy_2.1" ] } shlib_type = "sa" @@ -203,7 +203,7 @@ ohos_static_library("libsensor_service_static") { [ "$SUBSYSTEM_DIR/services/hdi_connection/hardware/include" ] } - external_deps += [ "drivers_interface_sensor:libsensor_proxy_2.0" ] + external_deps += [ "drivers_interface_sensor:libsensor_proxy_2.1" ] } part_name = "sensor" diff --git a/services/hdi_connection/adapter/include/sensor_event_callback.h b/services/hdi_connection/adapter/include/sensor_event_callback.h index 2d81cb858aec85f741810e9361766b1c84ee8a09..90ce52fe3c2fbf579504d32007df35f5106dbd2d 100644 --- a/services/hdi_connection/adapter/include/sensor_event_callback.h +++ b/services/hdi_connection/adapter/include/sensor_event_callback.h @@ -16,13 +16,13 @@ #ifndef SENSOR_EVENT_CALLBACK_H #define SENSOR_EVENT_CALLBACK_H -#include "v2_0/isensor_callback.h" -#include "v2_0/sensor_types.h" +#include "v2_1/isensor_callback.h" +#include "v2_1/sensor_types.h" #include "sensor_data_event.h" -using OHOS::HDI::Sensor::V2_0::HdfSensorEvents; -using OHOS::HDI::Sensor::V2_0::ISensorCallback; +using OHOS::HDI::Sensor::V2_1::HdfSensorEvents; +using OHOS::HDI::Sensor::V2_1::ISensorCallback; namespace OHOS { namespace Sensors { @@ -30,6 +30,7 @@ class SensorEventCallback : public ISensorCallback { public: virtual ~SensorEventCallback() {} int32_t OnDataEvent(const HdfSensorEvents &event) override; + int32_t OnDataEventAsync(const std::vector &events) override; }; } // namespace Sensors } // namespace OHOS diff --git a/services/hdi_connection/adapter/src/hdi_connection.cpp b/services/hdi_connection/adapter/src/hdi_connection.cpp index 27cb4a71915b740413a9dec2a2023e2e63bc1f80..a30e0c34d2d50d1f3416a34147719745022c17a4 100644 --- a/services/hdi_connection/adapter/src/hdi_connection.cpp +++ b/services/hdi_connection/adapter/src/hdi_connection.cpp @@ -22,7 +22,7 @@ #include "hisysevent.h" #endif // HIVIEWDFX_HISYSEVENT_ENABLE #include "iproxy_broker.h" -#include "v2_0/isensor_interface.h" +#include "v2_1/isensor_interface.h" #include "sensor_agent_type.h" #include "sensor_errors.h" @@ -34,9 +34,9 @@ namespace OHOS { namespace Sensors { using namespace OHOS::HiviewDFX; -using OHOS::HDI::Sensor::V2_0::ISensorInterface; -using OHOS::HDI::Sensor::V2_0::ISensorCallback; -using OHOS::HDI::Sensor::V2_0::HdfSensorInformation; +using OHOS::HDI::Sensor::V2_1::ISensorInterface; +using OHOS::HDI::Sensor::V2_1::ISensorCallback; +using OHOS::HDI::Sensor::V2_1::HdfSensorInformation; namespace { sptr g_sensorInterface = nullptr; sptr g_eventCallback = nullptr; @@ -57,7 +57,7 @@ int32_t HdiConnection::ConnectHdi() while (retry < GET_HDI_SERVICE_COUNT) { g_sensorInterface = ISensorInterface::Get(); if (g_sensorInterface != nullptr) { - SEN_HILOGI("Connect V2_0 hdi success"); + SEN_HILOGI("Connect v2_1 hdi success"); g_eventCallback = new (std::nothrow) SensorEventCallback(); CHKPR(g_eventCallback, ERR_NO_INIT); RegisterHdiDeathRecipient(); @@ -71,7 +71,7 @@ int32_t HdiConnection::ConnectHdi() HiSysEventWrite(HiviewDFX::HiSysEvent::Domain::SENSOR, "HDF_SERVICE_EXCEPTION", HiSysEvent::EventType::FAULT, "PKG_NAME", "ConnectHdi", "ERROR_CODE", CONNECT_SENSOR_HDF_ERR); #endif // HIVIEWDFX_HISYSEVENT_ENABLE - SEN_HILOGE("Connect V2_0 hdi failed"); + SEN_HILOGE("Connect v2_1 hdi failed"); return ERR_NO_INIT; } @@ -125,7 +125,7 @@ int32_t HdiConnection::EnableSensor(int32_t sensorId) HiSysEventWrite(HiviewDFX::HiSysEvent::Domain::SENSOR, "HDF_SERVICE_EXCEPTION", HiSysEvent::EventType::FAULT, "PKG_NAME", "EnableSensor", "ERROR_CODE", ret); #endif // HIVIEWDFX_HISYSEVENT_ENABLE - SEN_HILOGE("Connect V2_0 hdi failed"); + SEN_HILOGE("Connect v2_1 hdi failed"); return ret; } SetSensorBasicInfoState(sensorId, true); @@ -188,13 +188,13 @@ int32_t HdiConnection::RegisterDataReport(ReportDataCb cb, sptrRegister(0, g_eventCallback); + int32_t ret = g_sensorInterface->RegisterAsync(0, g_eventCallback); if (ret != 0) { #ifdef HIVIEWDFX_HISYSEVENT_ENABLE HiSysEventWrite(HiviewDFX::HiSysEvent::Domain::SENSOR, "HDF_SERVICE_EXCEPTION", HiSysEvent::EventType::FAULT, "PKG_NAME", "RegisterDataReport", "ERROR_CODE", ret); #endif // HIVIEWDFX_HISYSEVENT_ENABLE - SEN_HILOGE("Register is failed"); + SEN_HILOGE("RegisterAsync is failed"); return ret; } reportDataCb_ = cb; @@ -206,13 +206,13 @@ int32_t HdiConnection::DestroyHdiConnection() { CALL_LOG_ENTER; CHKPR(g_sensorInterface, ERR_NO_INIT); - int32_t ret = g_sensorInterface->Unregister(0, g_eventCallback); + int32_t ret = g_sensorInterface->UnregisterAsync(0, g_eventCallback); if (ret != 0) { #ifdef HIVIEWDFX_HISYSEVENT_ENABLE HiSysEventWrite(HiviewDFX::HiSysEvent::Domain::SENSOR, "HDF_SERVICE_EXCEPTION", HiSysEvent::EventType::FAULT, "PKG_NAME", "DestroyHdiConnection", "ERROR_CODE", ret); #endif // HIVIEWDFX_HISYSEVENT_ENABLE - SEN_HILOGE("Unregister is failed"); + SEN_HILOGE("UnregisterAsync is failed"); return ret; } g_eventCallback = nullptr; diff --git a/services/hdi_connection/adapter/src/sensor_event_callback.cpp b/services/hdi_connection/adapter/src/sensor_event_callback.cpp index 85ed1e9c330015a9be430a47bb40908894d8b6fa..091af57c3534d1bf5fc29751fbcea2875e591eae 100644 --- a/services/hdi_connection/adapter/src/sensor_event_callback.cpp +++ b/services/hdi_connection/adapter/src/sensor_event_callback.cpp @@ -41,54 +41,61 @@ const std::set g_sensorTypeTrigger = { } // namespace int32_t SensorEventCallback::OnDataEvent(const HdfSensorEvents &event) +{ + return ERR_OK; +} + +int32_t SensorEventCallback::OnDataEventAsync(const std::vector &events) { ReportDataCb reportDataCb_ = HdiConnection_->GetReportDataCb(); sptr reportDataCallback_ = HdiConnection_->GetReportDataCallback(); CHKPR(reportDataCb_, ERR_NO_INIT); CHKPR(reportDataCallback_, ERR_NO_INIT); - int32_t dataSize = static_cast(event.data.size()); - if (dataSize == 0) { - SEN_HILOGI("Data is empty"); - return ERR_INVALID_VALUE; - } - SensorData sensorData = { - .sensorTypeId = event.sensorId, - .version = event.version, - .timestamp = event.timestamp, - .option = event.option, - .mode = event.mode, - .dataLen = event.dataLen - }; - if (g_sensorTypeTrigger.find(sensorData.sensorTypeId) != g_sensorTypeTrigger.end()) { - sensorData.mode = SENSOR_ON_CHANGE; - } - CHKPR(sensorData.data, ERR_NO_INIT); - if (sensorData.sensorTypeId == SENSOR_TYPE_ID_HEADPOSTURE) { - sensorData.dataLen = HEADPOSTURE_DATA_SIZE; - const float *inputFloatPtr = reinterpret_cast(event.data.data()); - float *outputFloatPtr = reinterpret_cast(sensorData.data); - int32_t *outputIntPtr = reinterpret_cast(sensorData.data); - outputIntPtr[0] = static_cast(*(inputFloatPtr + 1)); - if (outputIntPtr[0] < 0) { - SEN_HILOGE("The order of head posture sensor is invalid"); + for (const auto &event : events) { + int32_t dataSize = static_cast(event.data.size()); + if (dataSize == 0) { + SEN_HILOGI("Data is empty"); + return ERR_INVALID_VALUE; } - outputFloatPtr[1] = *(inputFloatPtr + 3); - outputFloatPtr[2] = *(inputFloatPtr + 4); - outputFloatPtr[3] = *(inputFloatPtr + 5); - outputFloatPtr[4] = *(inputFloatPtr + 6); - } else { - for (int32_t i = 0; i < dataSize; i++) { - sensorData.data[i] = event.data[i]; + SensorData sensorData = { + .sensorTypeId = event.sensorId, + .version = event.version, + .timestamp = event.timestamp, + .option = event.option, + .mode = event.mode, + .dataLen = event.dataLen + }; + if (g_sensorTypeTrigger.find(sensorData.sensorTypeId) != g_sensorTypeTrigger.end()) { + sensorData.mode = SENSOR_ON_CHANGE; } + CHKPR(sensorData.data, ERR_NO_INIT); + if (sensorData.sensorTypeId == SENSOR_TYPE_ID_HEADPOSTURE) { + sensorData.dataLen = HEADPOSTURE_DATA_SIZE; + const float *inputFloatPtr = reinterpret_cast(event.data.data()); + float *outputFloatPtr = reinterpret_cast(sensorData.data); + int32_t *outputIntPtr = reinterpret_cast(sensorData.data); + outputIntPtr[0] = static_cast(*(inputFloatPtr + 1)); + if (outputIntPtr[0] < 0) { + SEN_HILOGE("The order of head posture sensor is invalid"); + } + outputFloatPtr[1] = *(inputFloatPtr + 3); + outputFloatPtr[2] = *(inputFloatPtr + 4); + outputFloatPtr[3] = *(inputFloatPtr + 5); + outputFloatPtr[4] = *(inputFloatPtr + 6); + } else { + for (int32_t i = 0; i < dataSize; i++) { + sensorData.data[i] = event.data[i]; + } + } + PrintSensorData::GetInstance().ControlSensorHdiPrint(sensorData); + std::unique_lock lk(ISensorHdiConnection::dataMutex_); + (void)(reportDataCallback_->*(reportDataCb_))(&sensorData, reportDataCallback_); + if (sensorData.sensorTypeId == SENSOR_TYPE_ID_HALL_EXT) { + SEN_HILOGI("dataCondition notify one sensorId: %{public}d", sensorData.sensorTypeId); + } + ISensorHdiConnection::dataReady_.store(true); + ISensorHdiConnection::dataCondition_.notify_one(); } - PrintSensorData::GetInstance().ControlSensorHdiPrint(sensorData); - std::unique_lock lk(ISensorHdiConnection::dataMutex_); - (void)(reportDataCallback_->*(reportDataCb_))(&sensorData, reportDataCallback_); - if (sensorData.sensorTypeId == SENSOR_TYPE_ID_HALL_EXT) { - SEN_HILOGI("dataCondition notify one sensorId: %{public}d", sensorData.sensorTypeId); - } - ISensorHdiConnection::dataReady_.store(true); - ISensorHdiConnection::dataCondition_.notify_one(); return ERR_OK; } } // namespace Sensors