From e80fc1597527b4afaed27dd37d10961a9ed3d81a Mon Sep 17 00:00:00 2001 From: wangqi Date: Fri, 25 Mar 2022 15:14:07 +0800 Subject: [PATCH] =?UTF-8?q?Description:=20Fix=20Problem=20Signed-off-by:?= =?UTF-8?q?=20=E7=8E=8B=E7=90=AA=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/update_client.cpp | 46 +++++++++++++++++++++++----------------- client/update_client.h | 2 ++ client/update_module.cpp | 18 ++++++++-------- client/update_session.h | 6 ++++-- 4 files changed, 42 insertions(+), 30 deletions(-) diff --git a/client/update_client.cpp b/client/update_client.cpp index 5ecaaec9..18f407ee 100644 --- a/client/update_client.cpp +++ b/client/update_client.cpp @@ -239,7 +239,8 @@ napi_value UpdateClient::StartSession(napi_env env, CLIENT_CHECK_NAPI_CALL(env, sess != nullptr, return nullptr, "Failed to create update session"); AddSession(sess); napi_value retValue = sess->StartWork(env, callbackStartIndex, args, function, nullptr); - CLIENT_CHECK(retValue != nullptr, RemoveSession(sess->GetSessionId()); return nullptr, "Failed to start worker."); + CLIENT_CHECK(retValue != nullptr, (void)RemoveSession(sess->GetSessionId()); + return nullptr, "Failed to start worker."); return retValue; } @@ -270,7 +271,8 @@ napi_value UpdateClient::CancelUpgrade(napi_env env, napi_callback_info info) [&](int32_t type, void *context) -> int { return UpdateServiceKits::GetInstance().Cancel(IUpdateService::DOWNLOAD); }, nullptr); - CLIENT_CHECK(retValue != nullptr, RemoveSession(sess->GetSessionId()); return nullptr, "Failed to start worker."); + CLIENT_CHECK(retValue != nullptr, (void)RemoveSession(sess->GetSessionId()); + return nullptr, "Failed to start worker."); return retValue; } @@ -289,7 +291,8 @@ napi_value UpdateClient::DownloadVersion(napi_env env, napi_callback_info info) [&](int32_t type, void *context) -> int { return UpdateServiceKits::GetInstance().DownloadVersion(); }, nullptr); - CLIENT_CHECK(retValue != nullptr, RemoveSession(sess->GetSessionId()); return nullptr, "Failed to start worker."); + CLIENT_CHECK(retValue != nullptr, (void)RemoveSession(sess->GetSessionId()); + return nullptr, "Failed to start worker."); return retValue; } @@ -311,7 +314,8 @@ napi_value UpdateClient::UpgradeVersion(napi_env env, napi_callback_info info) return 0; #endif }, nullptr); - CLIENT_CHECK(retValue != nullptr, RemoveSession(sess->GetSessionId()); return nullptr, "Failed to start worker."); + CLIENT_CHECK(retValue != nullptr, (void)RemoveSession(sess->GetSessionId()); + return nullptr, "Failed to start worker."); return retValue; } @@ -338,7 +342,7 @@ napi_value UpdateClient::SetUpdatePolicy(napi_env env, napi_callback_info info) result_ = UpdateServiceKits::GetInstance().SetUpdatePolicy(updatePolicy_); return result_; }, nullptr); - CLIENT_CHECK(retValue != nullptr, RemoveSession(sess->GetSessionId()); + CLIENT_CHECK(retValue != nullptr, (void)RemoveSession(sess->GetSessionId()); return nullptr, "Failed to SetUpdatePolicy."); return retValue; } @@ -426,7 +430,8 @@ napi_value UpdateClient::VerifyUpdatePackage(napi_env env, napi_callback_info in return result_; }, nullptr); - CLIENT_CHECK(retValue != nullptr, RemoveSession(sess->GetSessionId()); return nullptr, "Failed to start worker."); + CLIENT_CHECK(retValue != nullptr, (void)RemoveSession(sess->GetSessionId()); + return nullptr, "Failed to start worker."); return retValue; } @@ -451,7 +456,8 @@ napi_value UpdateClient::SubscribeEvent(napi_env env, napi_callback_info info) [&](int32_t type, void *context) -> int { return 0; }, nullptr); - CLIENT_CHECK(retValue != nullptr, RemoveSession(sess->GetSessionId()); return nullptr, "Failed to SubscribeEvent."); + CLIENT_CHECK(retValue != nullptr, (void)RemoveSession(sess->GetSessionId()); + return nullptr, "Failed to SubscribeEvent."); return retValue; } @@ -469,7 +475,7 @@ napi_value UpdateClient::UnsubscribeEvent(napi_env env, napi_callback_info info) CLIENT_LOGI("UnsubscribeEvent %s argc %d", eventType.c_str(), static_cast(argc)); if (argc >= MID_ARGC) { napi_valuetype valuetype; - napi_status status = napi_typeof(env, args[1], &valuetype); + status = napi_typeof(env, args[1], &valuetype); CLIENT_CHECK_NAPI_CALL(env, status == napi_ok, return nullptr, "Failed to napi_typeof"); CLIENT_CHECK_NAPI_CALL(env, valuetype == napi_function, return nullptr, "Invalid callback type"); } @@ -503,10 +509,10 @@ int32_t UpdateClient::ProcessUnsubscribe(const std::string &eventType, size_t ar CLIENT_LOGI("ProcessUnsubscribe remove session"); if (argc == 1) { listener->RemoveHandlerRef(env_); - RemoveSession(currSessId); + (void)RemoveSession(currSessId); } else if (listener->CheckEqual(env_, arg, eventType)) { listener->RemoveHandlerRef(env_); - RemoveSession(currSessId); + (void)RemoveSession(currSessId); break; } } @@ -541,7 +547,7 @@ bool UpdateClient::GetNextSessionId(uint32_t &sessionId) { #ifndef UPDATER_API_TEST std::lock_guard guard(sessionMutex_); -#endif +#endif { auto iter = sessions_.find(sessionId); if (iter == sessions_.end()) { @@ -600,7 +606,7 @@ void UpdateClient::PublishToJS(const std::string &type, int32_t retcode, const U listener = static_cast((iter->second).get()); if (listener->IsOnce()) { listener->RemoveHandlerRef(env_); - RemoveSession(currSessId); + (void)RemoveSession(currSessId); } } napi_close_handle_scope(env_, scope); @@ -635,7 +641,7 @@ void UpdateClient::Emit(const std::string &type, int32_t retcode, const UpdateRe CLIENT_CHECK(work != nullptr, freeUpdateResult(res); return, "alloc work failed."); - work->data = (void*)new(std::nothrow) NotifyInput(this, type, retcode, res); + work->data = reinterpret_cast(new(std::nothrow) NotifyInput(this, type, retcode, res)); CLIENT_CHECK(work != nullptr, freeUpdateResult(res); delete work; @@ -644,9 +650,9 @@ void UpdateClient::Emit(const std::string &type, int32_t retcode, const UpdateRe uv_queue_work( loop, work, - [](uv_work_t *work) {}, // run in C++ thread - [](uv_work_t *work, int status) { - NotifyInput *input = (NotifyInput *)work->data; + [](uv_work_t *workCpp) {}, // run in C++ thread + [](uv_work_t *workCpp, int status) { + NotifyInput *input = reinterpret_cast(workCpp->data); input->client->PublishToJS(input->type, input->retcode, *input->result); delete input->result->result.progress; delete input->result; @@ -743,7 +749,8 @@ int32_t UpdateClient::GetStringValue(napi_env env, napi_value arg, std::string & CLIENT_CHECK(valuetype == napi_string, return CLIENT_INVALID_TYPE, "Invalid type"); std::vector buff(CLIENT_STRING_MAX_LENGTH); size_t copied; - status = napi_get_value_string_utf8(env, arg, (char*)buff.data(), CLIENT_STRING_MAX_LENGTH, &copied); + status = napi_get_value_string_utf8(env, arg, reinterpret_cast(buff.data()), + CLIENT_STRING_MAX_LENGTH, &copied); CLIENT_CHECK(status == napi_ok, return CLIENT_INVALID_TYPE, "Error get string"); strValue.assign(buff.data(), copied); return napi_ok; @@ -849,7 +856,8 @@ int32_t UpdateClient::BuildCheckVersionResult(napi_env env, napi_value &obj, con } napi_value checkResults; napi_create_array_with_length(env, sizeof(info->result) / sizeof(info->result[0]), &checkResults); - for (size_t i = 0; i < sizeof(info->result) / sizeof(info->result[0]); i++) { + size_t i; + for (i = 0; i < sizeof(info->result) / sizeof(info->result[0]); i++) { napi_value result; status = napi_create_object(env, &result); @@ -865,7 +873,7 @@ int32_t UpdateClient::BuildCheckVersionResult(napi_env env, napi_value &obj, con napi_value descriptInfos; napi_create_array_with_length(env, sizeof(info->descriptInfo) / sizeof(info->descriptInfo[0]), &descriptInfos); - for (size_t i = 0; i < sizeof(info->descriptInfo) / sizeof(info->descriptInfo[0]); i++) { + for (i = 0; i < sizeof(info->descriptInfo) / sizeof(info->descriptInfo[0]); i++) { napi_value descriptInfo; status = napi_create_object(env, &descriptInfo); SetString(env, descriptInfo, "descriptionId", info->descriptInfo[i].descriptPackageId); diff --git a/client/update_client.h b/client/update_client.h index 05ec74a8..c92333ab 100644 --- a/client/update_client.h +++ b/client/update_client.h @@ -157,6 +157,7 @@ public: return nullptr; } #endif + private: napi_value StartSession(napi_env env, napi_callback_info info, int32_t type, size_t startIndex, DoWorkFunction function); @@ -195,6 +196,7 @@ private: static int32_t BuildProgress(napi_env env, napi_value &obj, const UpdateResult &result); static int32_t BuildUpdatePolicy(napi_env env, napi_value &obj, const UpdateResult &result); static int32_t BuildInt32Status(napi_env env, napi_value &obj, const UpdateResult &result); + private: napi_env env_ {}; napi_ref thisReference_ {}; diff --git a/client/update_module.cpp b/client/update_module.cpp index 3f8f9beb..4d509b1c 100644 --- a/client/update_module.cpp +++ b/client/update_module.cpp @@ -35,9 +35,9 @@ napi_value UpdateClientJSConstructor(napi_env env, napi_callback_info info) napi_wrap(env, thisVar, client, [](napi_env env, void* data, void* hint) { CLIENT_LOGI("UpdateClient Destructor"); - UpdateClient* client = (UpdateClient*)data; - delete client; - client = nullptr; + UpdateClient* clientDel = reinterpret_cast(data); + delete clientDel; + clientDel = nullptr; }, nullptr, nullptr); return thisVar; @@ -52,7 +52,7 @@ UpdateClient *GetAndCreateJsUpdateClient(napi_env env, napi_callback_info info, status = napi_new_instance(env, constructor, 0, nullptr, &obj); CLIENT_CHECK_NAPI_CALL(env, status == napi_ok, return nullptr, "Error get client"); - napi_unwrap(env, obj, (void**)&client); + napi_unwrap(env, obj, reinterpret_cast(&client)); return client; } @@ -65,7 +65,7 @@ UpdateClient *GetUpdateClient(napi_env env, napi_callback_info info) napi_get_cb_info(env, info, &argc, argv, &thisVar, &data); UpdateClient *client = nullptr; - napi_unwrap(env, thisVar, (void**)&client); + napi_unwrap(env, thisVar, reinterpret_cast(&client)); return client; } @@ -83,7 +83,7 @@ napi_value GetUpdater(napi_env env, napi_callback_info info) return obj; } } - napi_remove_wrap(env, obj, (void**)&client); + napi_remove_wrap(env, obj, reinterpret_cast(&client)); delete client; return nullptr; } @@ -97,7 +97,7 @@ napi_value GetUpdaterForOther(napi_env env, napi_callback_info info) napi_value obj = nullptr; client = GetAndCreateJsUpdateClient(env, info, obj); if (client != nullptr) { - client->GetUpdaterForOther(env, info); + (void)client->GetUpdaterForOther(env, info); } return obj; } @@ -111,7 +111,7 @@ napi_value GetUpdaterFromOther(napi_env env, napi_callback_info info) napi_value obj = nullptr; client = GetAndCreateJsUpdateClient(env, info, obj); if (client != nullptr) { - client->GetUpdaterFromOther(env, info); + (void)client->GetUpdaterFromOther(env, info); } return obj; } @@ -266,7 +266,7 @@ static napi_module g_module = { .nm_filename = nullptr, .nm_register_func = UpdateClientInit, .nm_modname = "update", - .nm_priv = ((void*)0), + .nm_priv = (reinterpret_cast(0)), .reserved = { 0 } }; diff --git a/client/update_session.h b/client/update_session.h index cb8f64bd..2cd6990d 100644 --- a/client/update_session.h +++ b/client/update_session.h @@ -39,7 +39,7 @@ public: UpdateSession(UpdateClient *client, int32_t type, size_t argc, size_t callbackNumber); - virtual ~UpdateSession() {}; + virtual ~UpdateSession() {} napi_value StartWork(napi_env env, size_t startIndex, const napi_value *args, UpdateClient::DoWorkFunction worker, void *context); @@ -76,7 +76,7 @@ public: // If the share ptr is used, you can directly remove the share ptr. UpdateClient *client = sess->GetUpdateClient(); if (client != nullptr) { - client->RemoveSession(sess->GetSessionId()); + (void)client->RemoveSession(sess->GetSessionId()); } } @@ -88,6 +88,7 @@ public: CLIENT_CHECK(sess != nullptr, return, "sess is null"); sess->ExecuteWork(env); } + protected: napi_value CreateWorkerName(napi_env env) const; int32_t CreateReference(napi_env env, napi_value arg, uint32_t refcount, napi_ref &reference) const; @@ -170,6 +171,7 @@ public: bool CheckEqual(napi_env env, napi_value handler, const std::string &type); void RemoveHandlerRef(napi_env env); + private: bool isOnce_ = false; std::string eventType_; -- Gitee