diff --git a/client/update_client.cpp b/client/update_client.cpp index 5ecaaec99b459a3e355db98825096bf9f1ebd48c..2341feae26aef3058b5da5bc36f7d9cea26357ab 100644 --- a/client/update_client.cpp +++ b/client/update_client.cpp @@ -239,7 +239,7 @@ 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 +270,7 @@ 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 +289,7 @@ 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 +311,7 @@ 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 +338,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 +426,7 @@ 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 +451,7 @@ 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 +469,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 +503,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 +541,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 +600,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 +635,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 +644,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 +743,7 @@ 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 +849,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 +866,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 05ec74a8a8f8669ebfe710e92210f3d33844bb1f..c92333abfa09c89534ca02c15736cacf8d08c099 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 3f8f9bebf75943ea607c331102e3d71882ca3c09..4d509b1c0c2f356eab05c203d9f7b83f1fbbe1e4 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.cpp b/client/update_session.cpp index 0c3afaf701a6f9d689fdf0161ad1fa4eda3dc0d8..776321d43ada0917d56004e0119c7ea69f1fb6de 100644 --- a/client/update_session.cpp +++ b/client/update_session.cpp @@ -96,7 +96,7 @@ napi_value UpdateAsyncession::StartWork(napi_env env, size_t startIndex, const n CLIENT_CHECK_NAPI_CALL(env, workName != nullptr, return nullptr, "Failed to worker name"); // Check whether a callback exists. Only one callback is allowed. - for (size_t i = 0; (i < (totalArgc_ - startIndex)) && (i < callbackNumber_); i++) { + for (size_t i = 0; (i < (size_t)(totalArgc_ - startIndex)) && (i < callbackNumber_); i++) { CLIENT_LOGI("CreateReference index:%u", static_cast(i + startIndex)); int32_t ret = CreateReference(env, args[i + startIndex], 1, callbackRef_[i]); CLIENT_CHECK_NAPI_CALL(env, ret == napi_ok, return nullptr, "Failed to create reference"); diff --git a/client/update_session.h b/client/update_session.h index cb8f64bd95550263569c8b89068deb0def3f5659..2cd6990de222f57fe60409bcd9f4590cfeb37fab 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_;