From 60a9a9c7e668416f74ee75dac86cf94d4cd686c5 Mon Sep 17 00:00:00 2001 From: wuzhihuitmac Date: Mon, 18 Aug 2025 18:28:25 +0800 Subject: [PATCH] Revise opinion Signed-off-by: wuzhihuitmac Change-Id: I0ec5af5c87bfe8696957421e93a5057be5cd29a6 --- .../adapter/src/hdi_connection.cpp | 80 ++++++++++--------- 1 file changed, 44 insertions(+), 36 deletions(-) diff --git a/services/hdi_connection/adapter/src/hdi_connection.cpp b/services/hdi_connection/adapter/src/hdi_connection.cpp index bead5ae9..e5873148 100644 --- a/services/hdi_connection/adapter/src/hdi_connection.cpp +++ b/services/hdi_connection/adapter/src/hdi_connection.cpp @@ -61,7 +61,7 @@ int32_t HdiConnection::ConnectHdi() CALL_LOG_ENTER; int32_t retry = 0; while (retry < GET_HDI_SERVICE_COUNT) { - std::lock_guard sensorInterface(g_sensorInterfaceMutex); + std::lock_guard sensorInterfaceLock(g_sensorInterfaceMutex); g_sensorInterface = ISensorInterface::Get(); if (g_sensorInterface != nullptr) { SEN_HILOGI("Connect v3_0 hdi success"); @@ -80,14 +80,14 @@ 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 v3_0 hdi failed"); + SEN_HILOGE("Connect V3_0 hdi failed"); return ERR_NO_INIT; } int32_t HdiConnection::GetSensorList(std::vector &sensorList) { CALL_LOG_ENTER; - std::lock_guard sensorInterface(g_sensorInterfaceMutex); + std::lock_guard sensorInterfaceLock(g_sensorInterfaceMutex); CHKPR(g_sensorInterface, ERR_NO_INIT); std::vector sensorInfos; SensorXcollie sensorXcollie("HdiConnection:GetSensorList", XCOLLIE_TIMEOUT_5S); @@ -132,7 +132,7 @@ int32_t HdiConnection::EnableSensor(const SensorDescription &sensorDesc) { SEN_HILOGI("In, deviceIndex:%{public}d, sensortypeId:%{public}d, sensorId:%{public}d", sensorDesc.deviceId, sensorDesc.sensorType, sensorDesc.sensorId); - std::lock_guard sensorInterface(g_sensorInterfaceMutex); + std::lock_guard sensorInterfaceLock(g_sensorInterfaceMutex); CHKPR(g_sensorInterface, ERR_NO_INIT); SensorXcollie sensorXcollie("HdiConnection:EnableSensor", XCOLLIE_TIMEOUT_5S); int32_t ret = g_sensorInterface->Enable({sensorDesc.deviceId, sensorDesc.sensorType, @@ -155,7 +155,7 @@ int32_t HdiConnection::DisableSensor(const SensorDescription &sensorDesc) { SEN_HILOGI("In, deviceIndex:%{public}d, sensortypeId:%{public}d, sensorId:%{public}d", sensorDesc.deviceId, sensorDesc.sensorType, sensorDesc.sensorId); - std::lock_guard sensorInterface(g_sensorInterfaceMutex); + std::lock_guard sensorInterfaceLock(g_sensorInterfaceMutex); CHKPR(g_sensorInterface, ERR_NO_INIT); SensorXcollie sensorXcollie("HdiConnection:DisableSensor", XCOLLIE_TIMEOUT_5S); int32_t ret = g_sensorInterface->Disable({sensorDesc.deviceId, sensorDesc.sensorType, @@ -176,7 +176,7 @@ int32_t HdiConnection::DisableSensor(const SensorDescription &sensorDesc) int32_t HdiConnection::SetBatch(const SensorDescription &sensorDesc, int64_t samplingInterval, int64_t reportInterval) { - std::lock_guard sensorInterface(g_sensorInterfaceMutex); + std::lock_guard sensorInterfaceLock(g_sensorInterfaceMutex); CHKPR(g_sensorInterface, ERR_NO_INIT); SensorXcollie sensorXcollie("HdiConnection:SetBatch", XCOLLIE_TIMEOUT_5S); int32_t ret = g_sensorInterface->SetBatch({sensorDesc.deviceId, sensorDesc.sensorType, @@ -196,7 +196,7 @@ int32_t HdiConnection::SetBatch(const SensorDescription &sensorDesc, int64_t sam int32_t HdiConnection::SetMode(const SensorDescription &sensorDesc, int32_t mode) { CALL_LOG_ENTER; - std::lock_guard sensorInterface(g_sensorInterfaceMutex); + std::lock_guard sensorInterfaceLock(g_sensorInterfaceMutex); CHKPR(g_sensorInterface, ERR_NO_INIT); SensorXcollie sensorXcollie("HdiConnection:SetMode", XCOLLIE_TIMEOUT_5S); int32_t ret = g_sensorInterface->SetMode({sensorDesc.deviceId, sensorDesc.sensorType, @@ -216,7 +216,7 @@ int32_t HdiConnection::RegisterDataReport(ReportDataCb cb, sptr sensorInterface(g_sensorInterfaceMutex); + std::lock_guard sensorInterfaceLock(g_sensorInterfaceMutex); CHKPR(g_sensorInterface, ERR_NO_INIT); SensorXcollie sensorXcollie("HdiConnection:RegisterDataReport", XCOLLIE_TIMEOUT_5S); int32_t ret = g_sensorInterface->RegisterAsync(0, g_eventCallback); @@ -237,17 +237,20 @@ int32_t HdiConnection::DestroyHdiConnection() { CALL_LOG_ENTER; { - std::lock_guard sensorInterface(g_sensorInterfaceMutex); + std::lock_guard sensorInterfaceLock(g_sensorInterfaceMutex); CHKPR(g_sensorInterface, ERR_NO_INIT); - SensorXcollie unregisterAsyncXcollie("HdiConnection:UnregisterAsync", XCOLLIE_TIMEOUT_5S); - int32_t ret = g_sensorInterface->UnregisterAsync(DEFAULT_GROUP_ID, g_eventCallback); - if (ret != ERR_OK) { + int32_t ret = 0; + { + SensorXcollie unregisterAsyncXcollie("HdiConnection:UnregisterAsync", XCOLLIE_TIMEOUT_5S); + ret = g_sensorInterface->UnregisterAsync(DEFAULT_GROUP_ID, g_eventCallback); + if (ret != ERR_OK) { #ifdef HIVIEWDFX_HISYSEVENT_ENABLE - HiSysEventWrite(HiviewDFX::HiSysEvent::Domain::SENSOR, "HDF_SERVICE_EXCEPTION", - HiSysEvent::EventType::FAULT, "PKG_NAME", "DestroyHdiConnection", "ERROR_CODE", ret); + HiSysEventWrite(HiviewDFX::HiSysEvent::Domain::SENSOR, "HDF_SERVICE_EXCEPTION", + HiSysEvent::EventType::FAULT, "PKG_NAME", "DestroyHdiConnection", "ERROR_CODE", ret); #endif // HIVIEWDFX_HISYSEVENT_ENABLE - SEN_HILOGE("UnregisterAsync is failed"); - return ret; + SEN_HILOGE("UnregisterAsync is failed"); + return ret; + } } SensorXcollie unRegSensorPlugCallBackXcollie("HdiConnection:UnRegSensorPlugCallBack", XCOLLIE_TIMEOUT_5S); ret = g_sensorInterface->UnRegSensorPlugCallBack(g_plugCallback); @@ -270,7 +273,7 @@ int32_t HdiConnection::RegSensorPlugCallback(DevicePlugCallback cb) { CALL_LOG_ENTER; CHKPR(cb, ERR_NO_INIT); - std::lock_guard sensorInterface(g_sensorInterfaceMutex); + std::lock_guard sensorInterfaceLock(g_sensorInterfaceMutex); CHKPR(g_sensorInterface, ERR_NO_INIT); reportPlugDataCb_ = cb; SensorXcollie sensorXcollie("HdiConnection:RegSensorPlugCallback", XCOLLIE_TIMEOUT_5S); @@ -369,7 +372,7 @@ void HdiConnection::RegisterHdiDeathRecipient() void HdiConnection::UnregisterHdiDeathRecipient() { CALL_LOG_ENTER; - std::lock_guard sensorInterface(g_sensorInterfaceMutex); + std::lock_guard sensorInterfaceLock(g_sensorInterfaceMutex); CHKPV(g_sensorInterface); CHKPV(hdiDeathObserver_); SensorXcollie sensorXcollie("HdiConnection:UnregisterHdiDeathRecipient", XCOLLIE_TIMEOUT_5S); @@ -383,7 +386,7 @@ void HdiConnection::ProcessDeathObserver(const wptr &object) CHKPV(hdiService); CHKPV(hdiDeathObserver_); { - std::lock_guard sensorInterface(g_sensorInterfaceMutex); + std::lock_guard sensorInterfaceLock(g_sensorInterfaceMutex); hdiService->RemoveDeathRecipient(hdiDeathObserver_); g_eventCallback = nullptr; } @@ -400,15 +403,18 @@ void HdiConnection::ReEnableSensor() sensorInfo.first.deviceId, sensorInfo.first.sensorType, sensorInfo.first.sensorId); continue; } - SensorXcollie setBatchXcollie("HdiConnection:Reconnect:SetBatch", XCOLLIE_TIMEOUT_5S); - int32_t ret = g_sensorInterface->SetBatch({sensorInfo.first.deviceId, sensorInfo.first.sensorType, - sensorInfo.first.sensorId, sensorInfo.first.location}, - info.GetSamplingPeriodNs(), info.GetMaxReportDelayNs()); - if (ret != ERR_OK) { - SEN_HILOGE("deviceIndex:%{public}d, sensortype:%{public}d, sensorId:%{public}d set batch fail," - "err:%{public}d", sensorInfo.first.deviceId, sensorInfo.first.sensorType, sensorInfo.first.sensorId, - ret); - continue; + int32_t ret = 0; + { + SensorXcollie setBatchXcollie("HdiConnection:Reconnect:SetBatch", XCOLLIE_TIMEOUT_5S); + ret = g_sensorInterface->SetBatch({sensorInfo.first.deviceId, sensorInfo.first.sensorType, + sensorInfo.first.sensorId, sensorInfo.first.location}, + info.GetSamplingPeriodNs(), info.GetMaxReportDelayNs()); + if (ret != ERR_OK) { + SEN_HILOGE("deviceIndex:%{public}d, sensortype:%{public}d, sensorId:%{public}d set batch fail," + "err:%{public}d", sensorInfo.first.deviceId, sensorInfo.first.sensorType, sensorInfo.first.sensorId, + ret); + continue; + } } SensorXcollie enableXcollie("HdiConnection:Reconnect:ReEnable", XCOLLIE_TIMEOUT_5S); ret = g_sensorInterface->Enable({sensorInfo.first.deviceId, sensorInfo.first.sensorType, @@ -430,12 +436,14 @@ void HdiConnection::Reconnect() return; } { - std::lock_guard sensorInterface(g_sensorInterfaceMutex); - SensorXcollie registerXcollie("HdiConnection:Reconnect:RegisterAsync", XCOLLIE_TIMEOUT_5S); - ret = g_sensorInterface->RegisterAsync(DEFAULT_GROUP_ID, g_eventCallback); - if (ret != ERR_OK) { - SEN_HILOGE("RegisterAsync callback fail"); - return; + std::lock_guard sensorInterfaceLock(g_sensorInterfaceMutex); + { + SensorXcollie registerXcollie("HdiConnection:Reconnect:RegisterAsync", XCOLLIE_TIMEOUT_5S); + ret = g_sensorInterface->RegisterAsync(DEFAULT_GROUP_ID, g_eventCallback); + if (ret != ERR_OK) { + SEN_HILOGE("RegisterAsync callback fail"); + return; + } } SensorXcollie regSensorPlugCallBackXcollie("HdiConnection:Reconnect:RegSensorPlugCallBack", XCOLLIE_TIMEOUT_5S); ret = g_sensorInterface->RegSensorPlugCallBack(g_plugCallback); @@ -450,14 +458,14 @@ void HdiConnection::Reconnect() SEN_HILOGE("Get sensor list fail"); return; } - std::lock_guard sensorInterface(g_sensorInterfaceMutex); + std::lock_guard sensorInterfaceLock(g_sensorInterfaceMutex); ReEnableSensor(); } int32_t HdiConnection::GetSensorListByDevice(int32_t deviceId, std::vector &singleDevSensors) { CALL_LOG_ENTER; - std::lock_guard sensorInterface(g_sensorInterfaceMutex); + std::lock_guard sensorInterfaceLock(g_sensorInterfaceMutex); CHKPR(g_sensorInterface, ERR_NO_INIT); std::vector sensorInfos; SensorXcollie sensorXcollie("HdiConnection:GetSensorListByDevice", XCOLLIE_TIMEOUT_5S); -- Gitee