From 8e97721014d0720e535aff44aed8bc99f33cbd34 Mon Sep 17 00:00:00 2001 From: SUE Date: Thu, 17 Mar 2022 06:44:47 +0000 Subject: [PATCH] Signed-off-by:hellohyh001 --- interfaces/plugin/src/sensor_js.cpp | 12 ++++++++---- .../hdi_connection/adapter/src/hdi_connection.cpp | 4 ++-- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/interfaces/plugin/src/sensor_js.cpp b/interfaces/plugin/src/sensor_js.cpp index 02c4c67f..64f6a848 100644 --- a/interfaces/plugin/src/sensor_js.cpp +++ b/interfaces/plugin/src/sensor_js.cpp @@ -256,6 +256,9 @@ static uint32_t RemoveCallback(napi_env env, int32_t sensorTypeId, napi_value ca std::vector callbackInfos = g_onCallbackInfos[sensorTypeId]; std::vector::iterator iter; for (iter = callbackInfos.begin(); iter != callbackInfos.end(); iter++) { + if (*iter == nullptr || (*iter)->callback[0] == nullptr) { + continue; + } napi_value sensorCallback = nullptr; napi_get_reference_value(env, (*iter)->callback[0], &sensorCallback); if (IsNapiValueSame(env, callback, sensorCallback)) { @@ -264,12 +267,13 @@ static uint32_t RemoveCallback(napi_env env, int32_t sensorTypeId, napi_value ca delete *iter; *iter = nullptr; callbackInfos.erase(iter); - if (callbackInfos.empty()) { - g_onCallbackInfos.erase(sensorTypeId); - return 0; - } + break; } } + if (callbackInfos.empty()) { + g_onCallbackInfos.erase(sensorTypeId); + return 0; + } g_onCallbackInfos[sensorTypeId] = callbackInfos; return callbackInfos.size(); } diff --git a/services/sensor/hdi_connection/adapter/src/hdi_connection.cpp b/services/sensor/hdi_connection/adapter/src/hdi_connection.cpp index bc9c43cc..9b3e1bf3 100644 --- a/services/sensor/hdi_connection/adapter/src/hdi_connection.cpp +++ b/services/sensor/hdi_connection/adapter/src/hdi_connection.cpp @@ -35,8 +35,8 @@ sptr sensorInterface_ = nullptr; sptr eventCallback_ = nullptr; std::map sensorBasicInfoMap_; std::mutex sensorBasicInfoMutex_; -constexpr int32_t GET_HDI_SERVICE_COUNT = 10; -constexpr uint32_t WAIT_MS = 100; +constexpr int32_t GET_HDI_SERVICE_COUNT = 30; +constexpr uint32_t WAIT_MS = 200; } ZReportDataCb HdiConnection::reportDataCb_ = nullptr; -- Gitee