From 3316a23870a9049c641c9a2ec077e4401827445a Mon Sep 17 00:00:00 2001 From: li-yaoyao777 Date: Wed, 16 Mar 2022 10:30:28 +0800 Subject: [PATCH 1/7] sensor_js.cpp Signed-off-by: li-yaoyao777 --- interfaces/plugin/src/sensor_js.cpp | 30 ++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/interfaces/plugin/src/sensor_js.cpp b/interfaces/plugin/src/sensor_js.cpp index d70df4a5..331beb0e 100644 --- a/interfaces/plugin/src/sensor_js.cpp +++ b/interfaces/plugin/src/sensor_js.cpp @@ -48,7 +48,7 @@ static void DataCallbackImpl(SensorEvent *event) { HiLog::Info(LABEL, "%{public}s in", __func__); if (event == nullptr) { - HiLog::Error(LABEL, "%{public}s event is null!", __func__); + HiLog::Error(LABEL, "%{public}s event is null", __func__); return; } int32_t sensorTypeId = event->sensorTypeId; @@ -226,7 +226,7 @@ static napi_value On(napi_env env, napi_callback_info info) if (argc == 3) { napi_value value = NapiGetNamedProperty(args[2], "interval", env); if (!IsMatchType(env, value, napi_number)) { - HiLog::Error(LABEL, "%{public}s argument should be napi_number type!", __func__); + HiLog::Error(LABEL, "%{public}s argument should be napi_number type", __func__); return nullptr; } interval = GetCppInt64(value, env); @@ -258,7 +258,7 @@ 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++) { + for (iter = callbackInfos.begin(); iter != callbackInfos.end(); ++iter) { napi_value sensorCallback = nullptr; napi_get_reference_value(env, (*iter)->callback[0], &sensorCallback); if (IsNapiValueSame(env, callback, sensorCallback)) { @@ -285,7 +285,7 @@ static napi_value Off(napi_env env, napi_callback_info info) napi_value thisVar = nullptr; NAPI_CALL(env, napi_get_cb_info(env, info, &argc, args, &thisVar, NULL)); if (argc < 1 || argc > 2 || !IsMatchType(env, args[0], napi_number)) { - HiLog::Error(LABEL, "%{public}s Invalid input.", __func__); + HiLog::Error(LABEL, "%{public}s Invalid input", __func__); return nullptr; } int32_t sensorTypeId = GetCppInt32(args[0], env); @@ -316,11 +316,11 @@ static napi_value GetGeomagneticField(napi_env env, napi_callback_info info) napi_value thisVar = nullptr; NAPI_CALL(env, napi_get_cb_info(env, info, &argc, args, &thisVar, nullptr)); if (argc < 2 || argc > 3) { - HiLog::Error(LABEL, "%{public}s the number of input parameters does not match.", __func__); + HiLog::Error(LABEL, "%{public}s the number of input parameters does not match", __func__); return nullptr; } if (!IsMatchType(env, args[0], napi_object) || !IsMatchType(env, args[1], napi_number)) { - HiLog::Error(LABEL, "%{public}s argument is invalid.", __func__); + HiLog::Error(LABEL, "%{public}s argument is invalid", __func__); return nullptr; } napi_value napiLatitude = NapiGetNamedProperty(args[0], "latitude", env); @@ -384,7 +384,7 @@ static napi_value TransformCoordinateSystem(napi_env env, napi_callback_info inf napi_value napiAxisX = NapiGetNamedProperty(args[1], "axisX", env); napi_value napiAxisY = NapiGetNamedProperty(args[1], "axisY", env); if ((!IsMatchType(env, napiAxisX, napi_number)) || (!IsMatchType(env, napiAxisY, napi_number))) { - HiLog::Error(LABEL, "%{public}s argument should be napi_number type!", __func__); + HiLog::Error(LABEL, "%{public}s argument should be napi_number type", __func__); return nullptr; } int32_t axisX = GetCppInt32(napiAxisX, env); @@ -418,7 +418,7 @@ static napi_value TransformCoordinateSystem(napi_env env, napi_callback_info inf return promise; } if (!IsMatchType(env, args[2], napi_function)) { - HiLog::Error(LABEL, "%{public}s argument should be napi_function type!", __func__); + HiLog::Error(LABEL, "%{public}s argument should be napi_function type", __func__); delete asyncCallbackInfo; asyncCallbackInfo = nullptr; return nullptr; @@ -517,7 +517,7 @@ static napi_value GetDirection(napi_env env, napi_callback_info info) return promise; } if (!IsMatchType(env, args[1], napi_function)) { - HiLog::Error(LABEL, "%{public}s argument should be napi_function type!", __func__); + HiLog::Error(LABEL, "%{public}s argument should be napi_function type", __func__); napi_value result; napi_get_undefined(env, &result); delete asyncCallbackInfo; @@ -536,7 +536,7 @@ static napi_value CreateQuaternion(napi_env env, napi_callback_info info) napi_value thisVar = nullptr; NAPI_CALL(env, napi_get_cb_info(env, info, &argc, args, &thisVar, nullptr)); if (argc < 1 || argc > 2 || !IsMatchArrayType(env, args[0])) { - HiLog::Error(LABEL, "%{public}s argument error!", __func__); + HiLog::Error(LABEL, "%{public}s argument error", __func__); return nullptr; } AsyncCallbackInfo *asyncCallbackInfo = new AsyncCallbackInfo { @@ -568,7 +568,7 @@ static napi_value CreateQuaternion(napi_env env, napi_callback_info info) return promise; } if (!IsMatchType(env, args[1], napi_function)) { - HiLog::Error(LABEL, "%{public}s argument should be function!", __func__); + HiLog::Error(LABEL, "%{public}s argument should be function", __func__); delete asyncCallbackInfo; asyncCallbackInfo = nullptr; return nullptr; @@ -586,7 +586,7 @@ static napi_value GetAltitude(napi_env env, napi_callback_info info) NAPI_CALL(env, napi_get_cb_info(env, info, &argc, args, &thisVar, nullptr)); if (argc < 2 || argc > 3 || !IsMatchType(env, args[0], napi_number) || !IsMatchType(env, args[1], napi_number)) { - HiLog::Error(LABEL, "%{public}s Invalid input.", __func__); + HiLog::Error(LABEL, "%{public}s Invalid input", __func__); return nullptr; } AsyncCallbackInfo *asyncCallbackInfo = new AsyncCallbackInfo { @@ -633,7 +633,7 @@ static napi_value GetGeomagneticDip(napi_env env, napi_callback_info info) napi_value thisVar = nullptr; NAPI_CALL(env, napi_get_cb_info(env, info, &argc, args, &thisVar, nullptr)); if (argc < 1 || argc > 2 || !IsMatchArrayType(env, args[0])) { - HiLog::Error(LABEL, "%{public}s Invalid input.", __func__); + HiLog::Error(LABEL, "%{public}s Invalid input", __func__); return nullptr; } AsyncCallbackInfo *asyncCallbackInfo = new AsyncCallbackInfo { @@ -662,7 +662,7 @@ static napi_value GetGeomagneticDip(napi_env env, napi_callback_info info) return promise; } if (!IsMatchType(env, args[1], napi_function)) { - HiLog::Error(LABEL, "%{public}s argument should be function!", __func__); + HiLog::Error(LABEL, "%{public}s argument should be function", __func__); delete asyncCallbackInfo; asyncCallbackInfo = nullptr; return nullptr; @@ -847,7 +847,7 @@ static napi_value GetSingleSensor(napi_env env, napi_callback_info info) return promise; } if (!IsMatchType(env, args[1], napi_function)) { - HiLog::Error(LABEL, "%{public}s argument should be napi_function type!", __func__); + HiLog::Error(LABEL, "%{public}s argument should be napi_function type", __func__); delete asyncCallbackInfo; asyncCallbackInfo = nullptr; return nullptr; -- Gitee From 332a4df799a665587d668f639417ba0a3683e7a7 Mon Sep 17 00:00:00 2001 From: li-yaoyao777 Date: Wed, 16 Mar 2022 15:38:44 +0800 Subject: [PATCH 2/7] sensor_js.cpp Signed-off-by: li-yaoyao777 --- interfaces/plugin/src/sensor_js.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/interfaces/plugin/src/sensor_js.cpp b/interfaces/plugin/src/sensor_js.cpp index 331beb0e..f4329af0 100644 --- a/interfaces/plugin/src/sensor_js.cpp +++ b/interfaces/plugin/src/sensor_js.cpp @@ -258,7 +258,11 @@ 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) { + for (iter = callbackInfos.begin(); iter != callbackInfos.end();) { + if (*iter == nullptr || (*iter)->callback[0] == nullptr) { + HiLog::Error(LABEL, "%{public}s arg is null", __func__); + continue; + } napi_value sensorCallback = nullptr; napi_get_reference_value(env, (*iter)->callback[0], &sensorCallback); if (IsNapiValueSame(env, callback, sensorCallback)) { @@ -266,11 +270,13 @@ static uint32_t RemoveCallback(napi_env env, int32_t sensorTypeId, napi_value ca (*iter)->callback[0] = nullptr; delete *iter; *iter = nullptr; - callbackInfos.erase(iter); + callbackInfos.erase(++iter); if (callbackInfos.empty()) { g_onCallbackInfos.erase(sensorTypeId); return 0; } + } else { + ++iter; } } g_onCallbackInfos[sensorTypeId] = callbackInfos; -- Gitee From 9631858b6322ff44a1041546f1ccf6f06916e43f Mon Sep 17 00:00:00 2001 From: li-yaoyao777 Date: Wed, 16 Mar 2022 16:03:51 +0800 Subject: [PATCH 3/7] sensor_js.cpp Signed-off-by: li-yaoyao777 --- interfaces/plugin/src/sensor_js.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interfaces/plugin/src/sensor_js.cpp b/interfaces/plugin/src/sensor_js.cpp index f4329af0..b21bcf24 100644 --- a/interfaces/plugin/src/sensor_js.cpp +++ b/interfaces/plugin/src/sensor_js.cpp @@ -270,7 +270,7 @@ static uint32_t RemoveCallback(napi_env env, int32_t sensorTypeId, napi_value ca (*iter)->callback[0] = nullptr; delete *iter; *iter = nullptr; - callbackInfos.erase(++iter); + iter = callbackInfos.erase(iter); if (callbackInfos.empty()) { g_onCallbackInfos.erase(sensorTypeId); return 0; -- Gitee From 0595320e7d61f3e0b2928c15d6b5f22d9371af7b Mon Sep 17 00:00:00 2001 From: li-yaoyao777 Date: Wed, 16 Mar 2022 17:22:46 +0800 Subject: [PATCH 4/7] sensor_js.cpp Signed-off-by: li-yaoyao777 --- interfaces/plugin/src/sensor_js.cpp | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/interfaces/plugin/src/sensor_js.cpp b/interfaces/plugin/src/sensor_js.cpp index b21bcf24..77c7fe74 100644 --- a/interfaces/plugin/src/sensor_js.cpp +++ b/interfaces/plugin/src/sensor_js.cpp @@ -258,11 +258,7 @@ 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();) { - if (*iter == nullptr || (*iter)->callback[0] == nullptr) { - HiLog::Error(LABEL, "%{public}s arg is null", __func__); - continue; - } + for (iter = callbackInfos.begin(); iter != callbackInfos.end(); iter++) { napi_value sensorCallback = nullptr; napi_get_reference_value(env, (*iter)->callback[0], &sensorCallback); if (IsNapiValueSame(env, callback, sensorCallback)) { @@ -270,13 +266,11 @@ static uint32_t RemoveCallback(napi_env env, int32_t sensorTypeId, napi_value ca (*iter)->callback[0] = nullptr; delete *iter; *iter = nullptr; - iter = callbackInfos.erase(iter); + callbackInfos.erase(iter); if (callbackInfos.empty()) { g_onCallbackInfos.erase(sensorTypeId); return 0; } - } else { - ++iter; } } g_onCallbackInfos[sensorTypeId] = callbackInfos; -- Gitee From b004ec807efe024f1d7e7e08045bbeac13061472 Mon Sep 17 00:00:00 2001 From: li-yaoyao777 Date: Wed, 16 Mar 2022 17:27:42 +0800 Subject: [PATCH 5/7] sensor_js.cpp Signed-off-by: li-yaoyao777 --- interfaces/plugin/src/sensor_js.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/interfaces/plugin/src/sensor_js.cpp b/interfaces/plugin/src/sensor_js.cpp index 77c7fe74..8fd21f7c 100644 --- a/interfaces/plugin/src/sensor_js.cpp +++ b/interfaces/plugin/src/sensor_js.cpp @@ -258,7 +258,7 @@ 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++) { + for (iter = callbackInfos.begin(); iter != callbackInfos.end();) { napi_value sensorCallback = nullptr; napi_get_reference_value(env, (*iter)->callback[0], &sensorCallback); if (IsNapiValueSame(env, callback, sensorCallback)) { @@ -266,7 +266,7 @@ static uint32_t RemoveCallback(napi_env env, int32_t sensorTypeId, napi_value ca (*iter)->callback[0] = nullptr; delete *iter; *iter = nullptr; - callbackInfos.erase(iter); + callbackInfos.erase(iter++); if (callbackInfos.empty()) { g_onCallbackInfos.erase(sensorTypeId); return 0; -- Gitee From a1b228b805925894325e7d009bb4b06e7a2c3b7a Mon Sep 17 00:00:00 2001 From: li-yaoyao777 Date: Wed, 16 Mar 2022 17:38:38 +0800 Subject: [PATCH 6/7] sensor_js.cpp Signed-off-by: li-yaoyao777 --- interfaces/plugin/src/sensor_js.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/interfaces/plugin/src/sensor_js.cpp b/interfaces/plugin/src/sensor_js.cpp index 8fd21f7c..6bfc3711 100644 --- a/interfaces/plugin/src/sensor_js.cpp +++ b/interfaces/plugin/src/sensor_js.cpp @@ -258,7 +258,11 @@ 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();) { + for (iter = callbackInfos.begin(); iter != callbackInfos.end(); iter++) { + if (*iter == nullptr || (*iter)->callback[0] == nullptr) { + HiLog::Error(LABEL, "%{public}s arg is null", __func__); + continue; + } napi_value sensorCallback = nullptr; napi_get_reference_value(env, (*iter)->callback[0], &sensorCallback); if (IsNapiValueSame(env, callback, sensorCallback)) { @@ -271,6 +275,8 @@ static uint32_t RemoveCallback(napi_env env, int32_t sensorTypeId, napi_value ca g_onCallbackInfos.erase(sensorTypeId); return 0; } + } else { + ++iter; } } g_onCallbackInfos[sensorTypeId] = callbackInfos; -- Gitee From 760b8f890728026888e86cb546bca1af3337fbd7 Mon Sep 17 00:00:00 2001 From: li-yaoyao777 Date: Wed, 16 Mar 2022 18:08:19 +0800 Subject: [PATCH 7/7] sensor_js.cpp Signed-off-by: li-yaoyao777 --- interfaces/plugin/src/sensor_js.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interfaces/plugin/src/sensor_js.cpp b/interfaces/plugin/src/sensor_js.cpp index 6bfc3711..43dd065c 100644 --- a/interfaces/plugin/src/sensor_js.cpp +++ b/interfaces/plugin/src/sensor_js.cpp @@ -258,7 +258,7 @@ 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++) { + for (iter = callbackInfos.begin(); iter != callbackInfos.end();) { if (*iter == nullptr || (*iter)->callback[0] == nullptr) { HiLog::Error(LABEL, "%{public}s arg is null", __func__); continue; -- Gitee